@soomo/text-annotator 3.4.10-staging.0 → 3.4.11-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,21 +1,19 @@
1
- import { UAParser as Ee } from "ua-parser-js";
2
- import { OS as Ce } from "ua-parser-js/enums";
3
1
  import le from "debounce";
4
- import { UserSelectAction as Se, serializeW3CBodies as Ae, parseW3CBodies as we, parseW3CUser as Re, createStore as ve, createSelectionState as Te, createHoverState as xe, createViewportState as Le, Origin as K, createAnonymousGuest as Ne, createUndoStack as Oe, createLifecycleObserver as Be, createBaseAnnotator as ke } from "@annotorious/core";
5
- import { Origin as Ft, UserSelectAction as Vt, createBody as Yt } from "@annotorious/core";
2
+ import { UserSelectAction as Ee, serializeW3CBodies as Ce, parseW3CBodies as Se, parseW3CUser as Ae, createStore as we, createSelectionState as Re, createHoverState as Te, createViewportState as ve, Origin as K, createAnonymousGuest as xe, createUndoStack as Le, createLifecycleObserver as Ne, createBaseAnnotator as Oe } from "@annotorious/core";
3
+ import { Origin as Pt, UserSelectAction as Ut, createBody as Kt } from "@annotorious/core";
6
4
  import { colord as ne } from "colord";
7
- import { dequal as Me } from "dequal/lite";
5
+ import { dequal as Be } from "dequal/lite";
8
6
  import { v4 as de } from "uuid";
9
- import Ie from "rbush";
10
- import { createNanoEvents as _e } from "nanoevents";
11
- import q from "hotkeys-js";
12
- import { poll as He } from "poll";
13
- const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t instanceof HTMLElement ? t.closest(W) : t.parentElement?.closest(W)) : !0, fe = (e, t) => {
7
+ import ke from "rbush";
8
+ import { createNanoEvents as Me } from "nanoevents";
9
+ import j from "hotkeys-js";
10
+ import { poll as Ie } from "poll";
11
+ const ue = "not-annotatable", $ = `.${ue}`, W = (e, t) => e.contains(t) ? !!(t instanceof HTMLElement ? t.closest($) : t.parentElement?.closest($)) : !0, fe = (e, t) => {
14
12
  const n = t.commonAncestorContainer;
15
- return !G(e, n);
16
- }, Pe = (e) => e.addEventListener("click", (t) => {
13
+ return !W(e, n);
14
+ }, _e = (e) => e.addEventListener("click", (t) => {
17
15
  // Allow clicks within not-annotatable elements
18
- !t.target.closest(W) && !t.target.closest("a") && t.preventDefault();
16
+ !t.target.closest($) && !t.target.closest("a") && t.preventDefault();
19
17
  }), J = (e) => ({
20
18
  ...e,
21
19
  type: e.type,
@@ -42,7 +40,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
42
40
  pointerId: e.pointerId,
43
41
  pointerType: e.pointerType,
44
42
  timeStamp: e.timeStamp
45
- }), j = (e) => ({
43
+ }), G = (e) => ({
46
44
  ...e,
47
45
  type: e.type,
48
46
  key: e.key,
@@ -63,9 +61,9 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
63
61
  return ((...r) => {
64
62
  clearTimeout(n), n = setTimeout(() => e.apply(void 0, r), t);
65
63
  });
66
- }, De = Ee(), ge = De.os.is(Ce.MACOS), Ue = (e) => {
64
+ }, ge = typeof navigator < "u" && navigator.platform.startsWith("Mac"), He = (e) => {
67
65
  (!e.hasAttribute("tabindex") || e.tabIndex < -1) && e.setAttribute("tabindex", "-1"), e.classList.add("no-focus-outline");
68
- }, Ke = (e) => {
66
+ }, De = (e) => {
69
67
  const t = [], n = document.createNodeIterator(
70
68
  e.commonAncestorContainer,
71
69
  NodeFilter.SHOW_TEXT
@@ -100,20 +98,20 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
100
98
  ...Array.from(c.getClientRects())
101
99
  ];
102
100
  }
103
- }, We = function* (e) {
101
+ }, Pe = function* (e) {
104
102
  const t = document.createNodeIterator(
105
103
  e.commonAncestorContainer,
106
104
  NodeFilter.SHOW_ELEMENT,
107
- (r) => r instanceof HTMLElement && r.classList.contains(ue) && !r.parentElement.closest(W) && e.intersectsNode(r) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
105
+ (r) => r instanceof HTMLElement && r.classList.contains(ue) && !r.parentElement.closest($) && e.intersectsNode(r) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
108
106
  );
109
107
  let n;
110
108
  for (; n = t.nextNode(); )
111
109
  n instanceof HTMLElement && (yield n);
112
- }, $e = (e, t) => {
110
+ }, Ue = (e, t) => {
113
111
  if (!fe(e, t)) return [];
114
112
  const n = [];
115
113
  let r = null;
116
- for (const s of We(t)) {
114
+ for (const s of Pe(t)) {
117
115
  let o;
118
116
  r ? (o = document.createRange(), o.setStartAfter(r), o.setEndBefore(s)) : (o = t.cloneRange(), o.setEndBefore(s)), o.collapsed || n.push(o), r = s;
119
117
  }
@@ -124,8 +122,8 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
124
122
  return n.length > 0 ? n : [t];
125
123
  }, oe = (e) => {
126
124
  const t = e.cloneContents();
127
- return t.querySelectorAll(W).forEach((n) => n.remove()), t;
128
- }, Fe = (e, t, n = 10, r) => {
125
+ return t.querySelectorAll($).forEach((n) => n.remove()), t;
126
+ }, Ke = (e, t, n = 10, r) => {
129
127
  const s = r ? e.startContainer.parentElement.closest(r) : t, o = document.createRange();
130
128
  o.setStart(s, 0), o.setEnd(e.startContainer, e.startOffset);
131
129
  const i = oe(o).textContent, c = document.createRange();
@@ -135,7 +133,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
135
133
  prefix: i.substring(i.length - n),
136
134
  suffix: l.substring(0, n)
137
135
  };
138
- }, I = (e) => e.every((t) => t.range instanceof Range && !t.range.collapsed), me = /^\s*$/, Ve = (e) => me.test(e.toString()), Ht = (e) => me.test(e.textContent || ""), Ye = (e, t, n, r) => {
136
+ }, I = (e) => e.every((t) => t.range instanceof Range && !t.range.collapsed), me = /^\s*$/, We = (e) => me.test(e.toString()), Bt = (e) => me.test(e.textContent || ""), $e = (e, t, n, r) => {
139
137
  const s = (c) => Math.round(c * 10) / 10, o = {
140
138
  top: s(e.top),
141
139
  bottom: s(e.bottom),
@@ -159,17 +157,17 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
159
157
  return "block-contains";
160
158
  } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
161
159
  return "block-is-contained";
162
- }, Xe = (e, t) => {
160
+ }, Fe = (e, t) => {
163
161
  const n = Math.min(e.left, t.left), r = Math.max(e.right, t.right), s = Math.min(e.top, t.top), o = Math.max(e.bottom, t.bottom);
164
162
  return new DOMRect(n, s, r - n, o - s);
165
- }, ze = (e, t = 0.5, n = 0.5) => e.reduce((r, s) => {
163
+ }, Ve = (e, t = 0.5, n = 0.5) => e.reduce((r, s) => {
166
164
  if (s.width === 0 || s.height === 0)
167
165
  return r;
168
166
  let o = [...r], i = !1;
169
167
  for (const c of r) {
170
- const l = Ye(s, c, t, n);
168
+ const l = $e(s, c, t, n);
171
169
  if (l === "inline-adjacent") {
172
- o = o.map((g) => g === c ? Xe(s, c) : g), i = !0;
170
+ o = o.map((g) => g === c ? Fe(s, c) : g), i = !0;
173
171
  break;
174
172
  } else if (l === "inline-contains") {
175
173
  o = o.map((g) => g === c ? s : g), i = !0;
@@ -183,14 +181,14 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
183
181
  }
184
182
  }
185
183
  return i ? o : [...o, s];
186
- }, []), Pt = (e) => ({
184
+ }, []), kt = (e) => ({
187
185
  length: e.length,
188
186
  item: (t) => e[t],
189
187
  [Symbol.iterator]: function* () {
190
188
  for (let t = 0; t < this.length; t++)
191
189
  yield this.item(t);
192
190
  }
193
- }), qe = (e) => {
191
+ }), Ye = (e) => {
194
192
  if (e.length === 0) return [];
195
193
  if (e.length === 1) return [e[0]];
196
194
  e.sort((s, o) => {
@@ -199,22 +197,22 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
199
197
  });
200
198
  const [t, ...n] = e, r = n.reduce((s, o) => s.current.compareBoundaryPoints(Range.START_TO_END, o) >= 0 ? (s.current.compareBoundaryPoints(Range.END_TO_END, o) < 0 && s.current.setEnd(o.endContainer, o.endOffset), s) : (s.merged.push(s.current), s.current = o.cloneRange(), s), { merged: [], current: t.cloneRange() });
201
199
  return [...r.merged, r.current];
202
- }, je = (e, t, n) => {
200
+ }, Xe = (e, t, n) => {
203
201
  const r = document.createRange(), s = n ? e.startContainer.parentElement.closest(n) : t;
204
202
  r.setStart(s, 0), r.setEnd(e.startContainer, e.startOffset);
205
203
  const o = oe(r).textContent, i = e.toString(), c = o.length || 0, l = c + i.length;
206
204
  return n ? { quote: i, start: c, end: l, range: e, offsetReference: s } : { quote: i, start: c, end: l, range: e };
207
- }, Ge = (e, t) => {
205
+ }, ze = (e, t) => {
208
206
  const { left: n, top: r, right: s, bottom: o } = e;
209
207
  return new DOMRect(n - t.left, r - t.top, s - n, o - r);
210
- }, Dt = (e, t) => {
208
+ }, Mt = (e, t) => {
211
209
  const { left: n, top: r, right: s, bottom: o } = e;
212
210
  return new DOMRect(n + t.left, r + t.top, s - n, o - r);
213
211
  }, pe = (e, t) => {
214
212
  const { start: n, end: r } = e, s = e.offsetReference || t, o = document.createNodeIterator(
215
213
  t,
216
214
  NodeFilter.SHOW_TEXT,
217
- (d) => d.parentElement?.closest(W) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT
215
+ (d) => d.parentElement?.closest($) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT
218
216
  );
219
217
  let i = 0;
220
218
  const c = document.createRange();
@@ -247,7 +245,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
247
245
  }, Q = (e, t) => I(e.selector) ? e : {
248
246
  ...e,
249
247
  selector: e.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : pe(n, t))
250
- }, te = (e, t) => I(e.target.selector) ? e : { ...e, target: Q(e.target, t) }, Qe = (e, t) => {
248
+ }, te = (e, t) => I(e.target.selector) ? e : { ...e, target: Q(e.target, t) }, qe = (e, t) => {
251
249
  const n = e.cloneRange();
252
250
  return t.contains(n.startContainer) || n.setStart(t, 0), t.contains(n.endContainer) || n.setEnd(t, t.childNodes.length), n;
253
251
  }, he = (e) => {
@@ -258,7 +256,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
258
256
  }, ie = (e, t, n) => {
259
257
  const r = n.getBoundingClientRect(), s = n.clientHeight, o = n.clientWidth, i = t.selector[0].range.getBoundingClientRect(), { width: c, height: l } = e.getAnnotationBounds(t.annotation), g = i.top - r.top, d = i.left - r.left, u = n.parentElement ? n.scrollTop : 0, y = n.parentElement ? n.scrollLeft : 0, w = g + u - (s - l) / 2, f = d + y - (o - c) / 2;
260
258
  n.scroll({ top: w, left: f, behavior: "smooth" });
261
- }, Ze = (e, t) => (n, r) => {
259
+ }, je = (e, t) => (n, r) => {
262
260
  const s = typeof n == "string" ? n : n.id, o = r ? typeof r == "string" ? document.getElementById(r) : r : he(e);
263
261
  if (!o)
264
262
  return console.warn(`The scroll parent is missing for the annotation: ${s}`, { container: e }), !1;
@@ -276,10 +274,10 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
276
274
  }, Z = {
277
275
  fill: "rgb(0, 128, 255)",
278
276
  fillOpacity: 0.45
279
- }, Je = (e) => {
277
+ }, Ge = (e) => {
280
278
  const { top: t, left: n } = e.getBoundingClientRect(), { innerWidth: r, innerHeight: s } = window, o = -n, i = -t, c = r - n, l = s - t;
281
279
  return { top: t, left: n, minX: o, minY: i, maxX: c, maxY: l };
282
- }, et = (e) => {
280
+ }, Qe = (e) => {
283
281
  let t = /* @__PURE__ */ new Set();
284
282
  return (r) => {
285
283
  const s = r.map((o) => o.id);
@@ -288,22 +286,22 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
288
286
  }, se = (e, t, n, r) => {
289
287
  const { store: s, selection: o, hover: i } = t;
290
288
  let c, l, g;
291
- const d = et(n), u = (A) => {
292
- const { x: T, y: N } = e.getBoundingClientRect(), O = s.getAt(A.clientX - T, A.clientY - N, !1, l);
293
- O && t.selection.evalSelectAction(O) !== Se.NONE ? i.current !== O.id && (e.classList.add("hovered"), i.set(O.id)) : i.current && (e.classList.remove("hovered"), i.set(null));
289
+ const d = Qe(n), u = (A) => {
290
+ const { x: v, y: N } = e.getBoundingClientRect(), O = s.getAt(A.clientX - v, A.clientY - N, !1, l);
291
+ O && t.selection.evalSelectAction(O) !== Ee.NONE ? i.current !== O.id && (e.classList.add("hovered"), i.set(O.id)) : i.current && (e.classList.remove("hovered"), i.set(null));
294
292
  };
295
293
  e.addEventListener("pointermove", u);
296
294
  const y = ee((A = !1) => requestAnimationFrame(() => {
297
295
  g && g.clear();
298
- const T = Je(e), { minX: N, minY: O, maxX: D, maxY: Y } = T, X = l ? s.getIntersecting(N, O, D, Y).filter(({ annotation: h }) => l(h)) : s.getIntersecting(N, O, D, Y), $ = o.selected.map(({ id: h }) => h), re = X.map(({ annotation: h, rects: v }) => {
299
- const k = $.includes(h.id), U = h.id === i.current;
296
+ const v = Ge(e), { minX: N, minY: O, maxX: P, maxY: X } = v, z = l ? s.getIntersecting(N, O, P, X).filter(({ annotation: p }) => l(p)) : s.getIntersecting(N, O, P, X), F = o.selected.map(({ id: p }) => p), re = z.map(({ annotation: p, rects: T }) => {
297
+ const k = F.includes(p.id), U = p.id === i.current;
300
298
  return {
301
- annotation: h,
302
- rects: v,
299
+ annotation: p,
300
+ rects: T,
303
301
  state: { selected: k, hovered: U }
304
302
  };
305
303
  });
306
- r.redraw(re, T, c, g, A), setTimeout(() => d(X.map(({ annotation: h }) => h)), 1);
304
+ r.redraw(re, v, c, g, A), setTimeout(() => d(z.map(({ annotation: p }) => p)), 1);
307
305
  }), 10), w = (A) => {
308
306
  g = A, y();
309
307
  }, f = (A) => {
@@ -312,7 +310,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
312
310
  l = A, y(!1);
313
311
  }, R = () => y();
314
312
  s.observe(R);
315
- const b = o.subscribe(() => y()), p = i.subscribe(() => y()), S = () => y(!0);
313
+ const b = o.subscribe(() => y()), h = i.subscribe(() => y()), S = () => y(!0);
316
314
  document.addEventListener("scroll", S, { capture: !0, passive: !0 });
317
315
  const E = ee(() => {
318
316
  s.recalculatePositions(), g?.reset(), y();
@@ -325,7 +323,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
325
323
  }, 150));
326
324
  return C.observe(document.body, a), {
327
325
  destroy: () => {
328
- e.removeEventListener("pointermove", u), r.destroy(), s.unobserve(R), b(), p(), document.removeEventListener("scroll", S), window.removeEventListener("resize", E), m.disconnect(), C.disconnect();
326
+ e.removeEventListener("pointermove", u), r.destroy(), s.unobserve(R), b(), h(), document.removeEventListener("scroll", S), window.removeEventListener("resize", E), m.disconnect(), C.disconnect();
329
327
  },
330
328
  redraw: y,
331
329
  setStyle: f,
@@ -333,40 +331,40 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
333
331
  setPainter: w,
334
332
  setVisible: r.setVisible
335
333
  };
336
- }, tt = () => {
334
+ }, Ze = () => {
337
335
  const e = document.createElement("canvas");
338
336
  return e.width = window.innerWidth, e.height = window.innerHeight, e.className = "r6o-canvas-highlight-layer bg", e;
339
- }, nt = (e, t) => {
337
+ }, Je = (e, t) => {
340
338
  e.width = window.innerWidth, e.height = window.innerHeight;
341
- }, ot = (e) => {
339
+ }, et = (e) => {
342
340
  console.warn('WARNING! Canvas renderer is deprecated and will be removed in the next major release. Please use the default "SPANS" renderer instead.'), e.classList.add("r6o-annotatable");
343
- const t = tt(), n = t.getContext("2d");
341
+ const t = Ze(), n = t.getContext("2d");
344
342
  document.body.appendChild(t);
345
343
  const r = (c, l, g, d) => requestAnimationFrame(() => {
346
344
  const { width: u, height: y } = t;
347
345
  n.clearRect(-0.5, -0.5, u + 1, y + 1), d && d.clear();
348
346
  const { top: w, left: f } = l;
349
347
  [...c].sort((R, b) => {
350
- const { annotation: { target: { created: p } } } = R, { annotation: { target: { created: S } } } = b;
351
- return p.getTime() - S.getTime();
348
+ const { annotation: { target: { created: h } } } = R, { annotation: { target: { created: S } } } = b;
349
+ return h.getTime() - S.getTime();
352
350
  }).forEach((R) => {
353
- const b = g ? typeof g == "function" ? g(R.annotation, R.state) : g : R.state?.selected ? Z : _, p = d && d.paint(R, l) || b, S = R.rects.map(({ x: E, y: m, width: a, height: C }) => ({
351
+ const b = g ? typeof g == "function" ? g(R.annotation, R.state) : g : R.state?.selected ? Z : _, h = d && d.paint(R, l) || b, S = R.rects.map(({ x: E, y: m, width: a, height: C }) => ({
354
352
  x: E + f,
355
353
  y: m + w,
356
354
  width: a,
357
355
  height: C
358
356
  }));
359
- if (n.fillStyle = p.fill, n.globalAlpha = p.fillOpacity || 1, S.forEach(
357
+ if (n.fillStyle = h.fill, n.globalAlpha = h.fillOpacity || 1, S.forEach(
360
358
  ({ x: E, y: m, width: a, height: C }) => n.fillRect(E, m, a, C)
361
- ), p.underlineColor) {
362
- n.globalAlpha = 1, n.strokeStyle = p.underlineColor, n.lineWidth = p.underlineThickness ?? 1;
363
- const E = p.underlineOffset ?? 0;
359
+ ), h.underlineColor) {
360
+ n.globalAlpha = 1, n.strokeStyle = h.underlineColor, n.lineWidth = h.underlineThickness ?? 1;
361
+ const E = h.underlineOffset ?? 0;
364
362
  S.forEach(({ x: m, y: a, width: C, height: L }) => {
365
363
  n.beginPath(), n.moveTo(m, a + L + E), n.lineTo(m + C, a + L + E), n.stroke();
366
364
  });
367
365
  }
368
366
  });
369
- }), s = le(() => nt(t), 10);
367
+ }), s = le(() => Je(t), 10);
370
368
  return window.addEventListener("resize", s), {
371
369
  destroy: () => {
372
370
  t.remove(), s.clear(), window.removeEventListener("resize", s);
@@ -376,13 +374,13 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
376
374
  },
377
375
  redraw: r
378
376
  };
379
- }, st = (e, t, n) => se(e, t, n, ot(e)), rt = (e) => [
377
+ }, tt = (e, t, n) => se(e, t, n, et(e)), nt = (e) => [
380
378
  `background-color:${ne(e?.fill || _.fill).alpha(e?.fillOpacity === void 0 ? _.fillOpacity : e.fillOpacity).toHex()}`,
381
379
  e?.underlineThickness ? "text-decoration:underline" : void 0,
382
380
  e?.underlineColor ? `text-decoration-color:${e.underlineColor}` : void 0,
383
381
  e?.underlineOffset ? `text-underline-offset:${e.underlineOffset}px` : void 0,
384
382
  e?.underlineThickness ? `text-decoration-thickness:${e.underlineThickness}px` : void 0
385
- ].filter(Boolean).join(";"), it = () => {
383
+ ].filter(Boolean).join(";"), ot = () => {
386
384
  const e = document.createElement("style");
387
385
  document.getElementsByTagName("head")[0].appendChild(e);
388
386
  let t = /* @__PURE__ */ new Set();
@@ -399,7 +397,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
399
397
  Array.from(t).filter((u) => !g.has(u));
400
398
  const d = o.map((u) => {
401
399
  const y = c ? typeof c == "function" ? c(u.annotation, u.state) : c : u.state?.selected ? Z : _, w = l && l.paint(u, i) || y;
402
- return `::highlight(_${u.annotation.id}) { ${rt(w)} }`;
400
+ return `::highlight(_${u.annotation.id}) { ${nt(w)} }`;
403
401
  });
404
402
  e.innerHTML = d.join(`
405
403
  `), CSS.highlights.clear(), o.forEach(({ annotation: u }) => {
@@ -408,13 +406,13 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
408
406
  }), t = g;
409
407
  }
410
408
  };
411
- }, at = (e, t, n) => se(e, t, n, it()), ct = (e) => e?.fillOpacity !== void 0 ? ne(e?.fill || _.fill).alpha(e.fillOpacity).toHex() : e?.fill ? e.fill : ne(_.fill).alpha(_.fillOpacity).toHex(), lt = (e, t, n, r, s) => {
409
+ }, st = (e, t, n) => se(e, t, n, ot()), rt = (e) => e?.fillOpacity !== void 0 ? ne(e?.fill || _.fill).alpha(e.fillOpacity).toHex() : e?.fill ? e.fill : ne(_.fill).alpha(_.fillOpacity).toHex(), it = (e, t, n, r, s) => {
412
410
  const o = n ? typeof n == "function" ? n(e.annotation, e.state, s) || (e.state?.selected ? Z : _) : n : e.state?.selected ? Z : _;
413
411
  return r && r.paint(e, t) || o;
414
- }, dt = (e, t) => {
412
+ }, at = (e, t) => {
415
413
  const n = (o, i) => o.x <= i.x + i.width && o.x + o.width >= i.x && o.y <= i.y + i.height && o.y + o.height >= i.y, r = (o) => o.rects.reduce((i, c) => i + c.width, 0), s = t.filter(({ rects: o }) => o.some((i) => n(e, i)));
416
414
  return s.sort((o, i) => r(i) - r(o)), s.findIndex((o) => o.rects.includes(e));
417
- }, ut = (e) => {
415
+ }, ct = (e) => {
418
416
  e.classList.add("r6o-annotatable");
419
417
  const t = document.createElement("div");
420
418
  t.className = "r6o-span-highlight-layer", e.insertBefore(t, e.firstChild);
@@ -424,17 +422,17 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
424
422
  t.remove();
425
423
  },
426
424
  redraw: (i, c, l, g, d) => {
427
- const y = !(Me(n, i) && d);
425
+ const y = !(Be(n, i) && d);
428
426
  if (!g && !y) return;
429
427
  y && (t.innerHTML = ""), [...i].sort((f, x) => {
430
428
  const { annotation: { target: { created: R } } } = f, { annotation: { target: { created: b } } } = x;
431
429
  return R && b ? R.getTime() - b.getTime() : 0;
432
430
  }).forEach((f) => {
433
431
  f.rects.map((x) => {
434
- const R = dt(x, i), b = lt(f, c, l, g, R);
432
+ const R = at(x, i), b = it(f, c, l, g, R);
435
433
  if (y) {
436
- const p = document.createElement("span");
437
- p.className = "r6o-annotation", p.dataset.annotation = f.annotation.id, p.style.left = `${x.x}px`, p.style.top = `${x.y}px`, p.style.width = `${x.width}px`, p.style.height = `${x.height}px`, p.style.backgroundColor = ct(b), b.underlineStyle && (p.style.borderStyle = b.underlineStyle), b.underlineColor && (p.style.borderColor = b.underlineColor), b.underlineThickness && (p.style.borderBottomWidth = `${b.underlineThickness}px`), b.underlineOffset && (p.style.paddingBottom = `${b.underlineOffset}px`), t.appendChild(p);
434
+ const h = document.createElement("span");
435
+ h.className = "r6o-annotation", h.dataset.annotation = f.annotation.id, h.style.left = `${x.x}px`, h.style.top = `${x.y}px`, h.style.width = `${x.width}px`, h.style.height = `${x.height}px`, h.style.backgroundColor = rt(b), b.underlineStyle && (h.style.borderStyle = b.underlineStyle), b.underlineColor && (h.style.borderColor = b.underlineColor), b.underlineThickness && (h.style.borderBottomWidth = `${b.underlineThickness}px`), b.underlineOffset && (h.style.paddingBottom = `${b.underlineOffset}px`), t.appendChild(h);
438
436
  }
439
437
  });
440
438
  }), n = i;
@@ -443,10 +441,10 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
443
441
  i ? t.classList.remove("hidden") : t.classList.add("hidden");
444
442
  }
445
443
  };
446
- }, ft = (e, t, n) => se(e, t, n, ut(e)), Ut = (e, t) => ({
447
- parse: (n) => pt(n),
448
- serialize: (n) => ht(n, e, t)
449
- }), gt = (e) => e.quote !== void 0 && e.start !== void 0 && e.end !== void 0, mt = (e) => {
444
+ }, lt = (e, t, n) => se(e, t, n, ct(e)), It = (e, t) => ({
445
+ parse: (n) => ft(n),
446
+ serialize: (n) => gt(n, e, t)
447
+ }), dt = (e) => e.quote !== void 0 && e.start !== void 0 && e.end !== void 0, ut = (e) => {
450
448
  const {
451
449
  id: t,
452
450
  creator: n,
@@ -457,7 +455,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
457
455
  if (i.length === 0)
458
456
  return { error: Error(`No targets found for annotation: ${e.id}`) };
459
457
  const c = {
460
- creator: Re(n),
458
+ creator: Ae(n),
461
459
  created: r ? new Date(r) : void 0,
462
460
  updated: s ? new Date(s) : void 0,
463
461
  annotation: t,
@@ -477,7 +475,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
477
475
  }
478
476
  return u;
479
477
  }, {});
480
- if (c.outdated ||= "outdated" in l ? l.outdated : void 0, gt(d))
478
+ if (c.outdated ||= "outdated" in l ? l.outdated : void 0, dt(d))
481
479
  c.selector.push(
482
480
  {
483
481
  ...d,
@@ -495,14 +493,14 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
495
493
  }
496
494
  }
497
495
  return { parsed: c };
498
- }, pt = (e) => {
496
+ }, ft = (e) => {
499
497
  const t = e.id || de(), {
500
498
  creator: n,
501
499
  created: r,
502
500
  modified: s,
503
501
  body: o,
504
502
  ...i
505
- } = e, c = we(o, t), l = mt(e);
503
+ } = e, c = Se(o, t), l = ut(e);
506
504
  return "error" in l ? { error: l.error } : {
507
505
  parsed: {
508
506
  ...i,
@@ -511,7 +509,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
511
509
  target: l.parsed
512
510
  }
513
511
  };
514
- }, ht = (e, t, n) => {
512
+ }, gt = (e, t, n) => {
515
513
  const { bodies: r, target: s, ...o } = e, {
516
514
  selector: i,
517
515
  creator: c,
@@ -519,13 +517,13 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
519
517
  updated: g,
520
518
  ...d
521
519
  } = s, u = i.map((y) => {
522
- const { id: w, quote: f, start: x, end: R, range: b } = y, p = {
520
+ const { id: w, quote: f, start: x, end: R, range: b } = y, h = {
523
521
  type: "TextQuoteSelector",
524
522
  exact: f
525
523
  };
526
524
  if (n) {
527
- const { prefix: E, suffix: m } = Fe(b, n);
528
- p.prefix = E, p.suffix = m;
525
+ const { prefix: E, suffix: m } = Ke(b, n);
526
+ h.prefix = E, h.suffix = m;
529
527
  }
530
528
  const S = {
531
529
  type: "TextPositionSelector",
@@ -538,7 +536,7 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
538
536
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
539
537
  scope: "scope" in y ? y.scope : void 0,
540
538
  source: t,
541
- selector: [p, S]
539
+ selector: [h, S]
542
540
  };
543
541
  });
544
542
  return {
@@ -546,19 +544,19 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
546
544
  "@context": "http://www.w3.org/ns/anno.jsonld",
547
545
  id: e.id,
548
546
  type: "Annotation",
549
- body: Ae(e.bodies),
547
+ body: Ce(e.bodies),
550
548
  creator: c,
551
549
  created: l?.toISOString(),
552
550
  modified: g?.toISOString(),
553
551
  target: u
554
552
  };
555
- }, yt = () => {
553
+ }, mt = () => {
556
554
  const e = document.createElement("canvas");
557
555
  e.width = 2 * window.innerWidth, e.height = 2 * window.innerHeight, e.className = "r6o-presence-layer";
558
556
  const t = e.getContext("2d");
559
557
  return t.scale(2, 2), t.translate(0.5, 0.5), e;
560
- }, bt = (e, t = {}) => {
561
- const n = yt(), r = n.getContext("2d");
558
+ }, pt = (e, t = {}) => {
559
+ const n = mt(), r = n.getContext("2d");
562
560
  document.body.appendChild(n);
563
561
  const s = /* @__PURE__ */ new Map(), o = (d) => Array.from(s.entries()).filter(([u, y]) => y.presenceKey === d.presenceKey).map(([u, y]) => u);
564
562
  return e.on("selectionChange", (d, u) => {
@@ -577,8 +575,8 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
577
575
  if (w) {
578
576
  const { height: f } = d.rects[0], x = d.rects[0].x + u.left, R = d.rects[0].y + u.top;
579
577
  r.fillStyle = w.appearance.color, r.fillRect(x - 2, R - 2.5, 2, f + 5);
580
- const b = r.measureText(w.appearance.label), p = b.width + 6, S = b.actualBoundingBoxAscent + b.actualBoundingBoxDescent + 8, E = b.fontBoundingBoxAscent ? 8 : 6.5;
581
- return r.fillRect(x - 2, R - 2.5 - S, p, S), r.fillStyle = "#fff", r.fillText(w.appearance.label, x + 1, R - E), {
578
+ const b = r.measureText(w.appearance.label), h = b.width + 6, S = b.actualBoundingBoxAscent + b.actualBoundingBoxDescent + 8, E = b.fontBoundingBoxAscent ? 8 : 6.5;
579
+ return r.fillRect(x - 2, R - 2.5 - S, h, S), r.fillStyle = "#fff", r.fillText(w.appearance.label, x + 1, R - E), {
582
580
  fill: w.appearance.color,
583
581
  fillOpacity: y ? 0.45 : 0.18
584
582
  };
@@ -590,19 +588,19 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
590
588
  d.scale(2, 2), d.translate(0.5, 0.5);
591
589
  }
592
590
  };
593
- }, Et = (e, t, n, r) => {
594
- const s = new Ie(), o = /* @__PURE__ */ new Map(), i = _e(), c = (m, a) => {
591
+ }, ht = (e, t, n, r) => {
592
+ const s = new ke(), o = /* @__PURE__ */ new Map(), i = Me(), c = (m, a) => {
595
593
  const C = m.selector.flatMap((A) => {
596
- const T = I([A]) ? A.range : pe(A, t).range;
597
- return Ke(T);
598
- }), L = ze(C, n, r).map((A) => Ge(A, a));
594
+ const v = I([A]) ? A.range : pe(A, t).range;
595
+ return De(v);
596
+ }), L = Ve(C, n, r).map((A) => ze(A, a));
599
597
  return L.map((A) => {
600
- const { x: T, y: N, width: O, height: D } = A;
598
+ const { x: v, y: N, width: O, height: P } = A;
601
599
  return {
602
- minX: T,
600
+ minX: v,
603
601
  minY: N,
604
- maxX: T + O,
605
- maxY: N + D,
602
+ maxX: v + O,
603
+ maxY: N + P,
606
604
  annotation: {
607
605
  id: m.annotation,
608
606
  rects: L
@@ -621,11 +619,11 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
621
619
  u(m), d(m);
622
620
  }, w = (m, a = !0) => {
623
621
  a && g();
624
- const C = t.getBoundingClientRect(), L = m.map((T) => ({ target: T, rects: c(T, C) }));
625
- L.forEach(({ target: T, rects: N }) => {
626
- N.length > 0 && o.set(T.annotation, N);
622
+ const C = t.getBoundingClientRect(), L = m.map((v) => ({ target: v, rects: c(v, C) }));
623
+ L.forEach(({ target: v, rects: N }) => {
624
+ N.length > 0 && o.set(v.annotation, N);
627
625
  });
628
- const A = L.flatMap(({ rects: T }) => T);
626
+ const A = L.flatMap(({ rects: v }) => v);
629
627
  s.load(A);
630
628
  }, f = (m, a, C = !1) => {
631
629
  const L = s.search({
@@ -633,18 +631,18 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
633
631
  minY: a,
634
632
  maxX: m,
635
633
  maxY: a
636
- }), A = (T) => T.annotation.rects.reduce((N, O) => N + O.width * O.height, 0);
637
- return L.length > 0 ? (L.sort((T, N) => A(T) - A(N)), C ? L.map((T) => T.annotation.id) : [L[0].annotation.id]) : [];
634
+ }), A = (v) => v.annotation.rects.reduce((N, O) => N + O.width * O.height, 0);
635
+ return L.length > 0 ? (L.sort((v, N) => A(v) - A(N)), C ? L.map((v) => v.annotation.id) : [L[0].annotation.id]) : [];
638
636
  }, x = (m) => {
639
637
  const a = R(m);
640
638
  if (a.length === 0)
641
639
  return;
642
- let C = a[0].left, L = a[0].top, A = a[0].right, T = a[0].bottom;
640
+ let C = a[0].left, L = a[0].top, A = a[0].right, v = a[0].bottom;
643
641
  for (let N = 1; N < a.length; N++) {
644
642
  const O = a[N];
645
- C = Math.min(C, O.left), L = Math.min(L, O.top), A = Math.max(A, O.right), T = Math.max(T, O.bottom);
643
+ C = Math.min(C, O.left), L = Math.min(L, O.top), A = Math.max(A, O.right), v = Math.max(v, O.bottom);
646
644
  }
647
- return new DOMRect(C, L, A - C, T - L);
645
+ return new DOMRect(C, L, A - C, v - L);
648
646
  }, R = (m) => {
649
647
  const a = o.get(m);
650
648
  return a ? a[0].annotation.rects : [];
@@ -656,8 +654,8 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
656
654
  getAnnotationBounds: x,
657
655
  getAnnotationRects: R,
658
656
  getIntersecting: (m, a, C, L) => {
659
- const A = s.search({ minX: m, minY: a, maxX: C, maxY: L }), T = new Set(A.map((N) => N.annotation.id));
660
- return Array.from(T).map((N) => ({
657
+ const A = s.search({ minX: m, minY: a, maxX: C, maxY: L }), v = new Set(A.map((N) => N.annotation.id));
658
+ return Array.from(v).map((N) => ({
661
659
  annotation: e.getAnnotation(N),
662
660
  rects: R(N)
663
661
  })).filter((N) => !!N.annotation);
@@ -672,33 +670,33 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
672
670
  update: y,
673
671
  on: (m, a) => i.on(m, a)
674
672
  };
675
- }, Ct = (e, t) => {
676
- const n = ve(), r = Et(n, e, t.mergeHighlights?.horizontalTolerance, t.mergeHighlights?.verticalTolerance), s = Te(n, t.userSelectAction, t.adapter), o = xe(n), i = Le(), c = (p, S = K.LOCAL) => {
677
- const E = te(p, e), m = I(E.target.selector);
673
+ }, yt = (e, t) => {
674
+ const n = we(), r = ht(n, e, t.mergeHighlights?.horizontalTolerance, t.mergeHighlights?.verticalTolerance), s = Re(n, t.userSelectAction, t.adapter), o = Te(n), i = ve(), c = (h, S = K.LOCAL) => {
675
+ const E = te(h, e), m = I(E.target.selector);
678
676
  return m && n.addAnnotation(E, S), m;
679
- }, l = (p, S = !0, E = K.LOCAL) => {
680
- const m = p.map((C) => te(C, e)), a = m.filter((C) => !I(C.target.selector));
677
+ }, l = (h, S = !0, E = K.LOCAL) => {
678
+ const m = h.map((C) => te(C, e)), a = m.filter((C) => !I(C.target.selector));
681
679
  return n.bulkAddAnnotations(m, S, E), a;
682
- }, g = (p, S = K.LOCAL) => {
683
- const E = p.map((a) => te(a, e)), m = E.filter((a) => !I(a.target.selector));
680
+ }, g = (h, S = K.LOCAL) => {
681
+ const E = h.map((a) => te(a, e)), m = E.filter((a) => !I(a.target.selector));
684
682
  return E.forEach((a) => {
685
683
  n.getAnnotation(a.id) ? n.updateAnnotation(a, S) : n.addAnnotation(a, S);
686
684
  }), m;
687
- }, d = (p, S = K.LOCAL) => {
688
- const E = Q(p, e);
685
+ }, d = (h, S = K.LOCAL) => {
686
+ const E = Q(h, e);
689
687
  n.updateTarget(E, S);
690
- }, u = (p, S = K.LOCAL) => {
691
- const E = p.map((m) => Q(m, e));
688
+ }, u = (h, S = K.LOCAL) => {
689
+ const E = h.map((m) => Q(m, e));
692
690
  n.bulkUpdateTargets(E, S);
693
691
  };
694
- function y(p, S, E, m) {
695
- const a = E || !!m, C = r.getAt(p, S, a).map((A) => n.getAnnotation(A)), L = m ? C.filter(m) : C;
692
+ function y(h, S, E, m) {
693
+ const a = E || !!m, C = r.getAt(h, S, a).map((A) => n.getAnnotation(A)), L = m ? C.filter(m) : C;
696
694
  if (L.length !== 0)
697
695
  return E ? L : L[0];
698
696
  }
699
- const w = (p) => r.getAnnotationRects(p).length > 0 ? r.getAnnotationBounds(p) : void 0, f = (p, S, E, m) => r.getIntersecting(p, S, E, m), x = (p) => r.getAnnotationRects(p), R = () => r.recalculate(), b = (p) => r.on("recalculate", p);
700
- return n.observe(({ changes: p }) => {
701
- const S = (p.deleted || []).filter((a) => I(a.target.selector)), E = (p.created || []).filter((a) => I(a.target.selector)), m = (p.updated || []).filter((a) => I(a.newValue.target.selector));
697
+ const w = (h) => r.getAnnotationRects(h).length > 0 ? r.getAnnotationBounds(h) : void 0, f = (h, S, E, m) => r.getIntersecting(h, S, E, m), x = (h) => r.getAnnotationRects(h), R = () => r.recalculate(), b = (h) => r.on("recalculate", h);
698
+ return n.observe(({ changes: h }) => {
699
+ const S = (h.deleted || []).filter((a) => I(a.target.selector)), E = (h.created || []).filter((a) => I(a.target.selector)), m = (h.updated || []).filter((a) => I(a.newValue.target.selector));
702
700
  S?.length > 0 && S.forEach((a) => r.remove(a.target)), E.length > 0 && r.set(E.map((a) => a.target), !1), m?.length > 0 && m.forEach(({ newValue: a }) => r.update(a.target));
703
701
  }), {
704
702
  store: {
@@ -719,10 +717,10 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
719
717
  hover: o,
720
718
  viewport: i
721
719
  };
722
- }, ae = 300, ye = ["up", "down", "left", "right"], be = ge ? "⌘+a" : "ctrl+a", St = [
720
+ }, ae = 300, ye = ["up", "down", "left", "right"], be = ge ? "⌘+a" : "ctrl+a", bt = [
723
721
  ...ye.map((e) => `shift+${e}`),
724
722
  be
725
- ], At = (e, t, n, r) => {
723
+ ], Et = (e, t, n, r) => {
726
724
  const { store: s, selection: o } = t;
727
725
  let i;
728
726
  const {
@@ -732,21 +730,21 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
732
730
  dismissOnNotAnnotatable: d = "NEVER"
733
731
  } = r;
734
732
  let u, y = c, w = "CREATE_NEW", f, x, R, b;
735
- const p = (h) => {
736
- y = h, L.clear(), h || (x = void 0, f = void 0, R = void 0, b = void 0);
737
- }, S = (h) => w = h || "CREATE_NEW", E = (h) => u = h, m = (h) => i = h, a = (h) => {
733
+ const h = (p) => {
734
+ y = p, L.clear(), p || (x = void 0, f = void 0, R = void 0, b = void 0);
735
+ }, S = (p) => w = p || "CREATE_NEW", E = (p) => u = p, m = (p) => i = p, a = (p) => {
738
736
  if (w === "ADD_TO_CURRENT")
739
737
  return !0;
740
738
  if (r.allowModifierSelect) {
741
- const v = h;
742
- return ge ? v.metaKey : v.ctrlKey;
739
+ const T = p;
740
+ return ge ? T.metaKey : T.ctrlKey;
743
741
  } else
744
742
  return !1;
745
743
  }, C = () => {
746
744
  if (!y || R === !1) return;
747
- const { selected: h } = o;
748
- if ((a(b) || w === "REPLACE_CURRENT") && h.length === 1 && h[0].editable) {
749
- const k = s.getAnnotation(h[0].id);
745
+ const { selected: p } = o;
746
+ if ((a(b) || w === "REPLACE_CURRENT") && p.length === 1 && p[0].editable) {
747
+ const k = s.getAnnotation(p[0].id);
750
748
  if (k?.target) {
751
749
  x = k.target, f = {
752
750
  annotation: k.id,
@@ -765,134 +763,134 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
765
763
  created: /* @__PURE__ */ new Date(),
766
764
  creator: i
767
765
  };
768
- }, L = le((h) => {
766
+ }, L = le((p) => {
769
767
  if (!y) return;
770
- const v = document.getSelection();
771
- if (!v?.anchorNode) return;
772
- const k = Array.from(Array(v.rangeCount).keys()).map((B) => v.getRangeAt(B));
768
+ const T = document.getSelection();
769
+ if (!T?.anchorNode) return;
770
+ const k = Array.from(Array(T.rangeCount).keys()).map((B) => T.getRangeAt(B));
773
771
  if (k.every((B) => !fe(e, B))) {
774
772
  f = void 0;
775
773
  return;
776
774
  }
777
- const U = h.timeStamp - (b?.timeStamp || h.timeStamp);
778
- if (b?.type === "pointerdown" && (U < 1e3 && !f || v.isCollapsed && U < ae) && C(), !f && (C(), !f))
775
+ const U = p.timeStamp - (b?.timeStamp || p.timeStamp);
776
+ if (b?.type === "pointerdown" && (U < 1e3 && !f || T.isCollapsed && U < ae) && C(), !f && (C(), !f))
779
777
  return;
780
- if (v.isCollapsed) {
778
+ if (T.isCollapsed) {
781
779
  s.getAnnotation(f.annotation) && !(a(b) || w === "REPLACE_CURRENT") && (o.clear(), s.deleteAnnotation(f.annotation));
782
780
  return;
783
781
  }
784
- const H = k.map((B) => Qe(B, e));
785
- if (H.every((B) => Ve(B))) return;
786
- const M = H.flatMap((B) => $e(e, B.cloneRange()));
787
- if (!(M.length > 0 && !f || M.length !== f.selector.length || M.some((B, F) => B.toString() !== f.selector[F]?.quote))) return;
788
- const z = a(b) && x ? qe([
782
+ const H = k.map((B) => qe(B, e));
783
+ if (H.every((B) => We(B))) return;
784
+ const M = H.flatMap((B) => Ue(e, B.cloneRange()));
785
+ if (!(M.length > 0 && !f || M.length !== f.selector.length || M.some((B, V) => B.toString() !== f.selector[V]?.quote))) return;
786
+ const q = a(b) && x ? Ye([
789
787
  ...x.selector.map((B) => B.range),
790
788
  ...M
791
789
  ]) : M;
792
790
  f = {
793
791
  ...f,
794
- selector: z.map((B) => je(B, e, l)),
792
+ selector: q.map((B) => Xe(B, e, l)),
795
793
  updated: /* @__PURE__ */ new Date()
796
794
  }, !(a(b) || w === "REPLACE_CURRENT") && (s.getAnnotation(f.annotation) ? s.updateTarget(f, K.LOCAL) : o.clear());
797
- }, 10), A = (h) => {
798
- b = J(h), R = b.button === 0;
799
- }, T = async (h) => {
795
+ }, 10), A = (p) => {
796
+ b = J(p), R = b.button === 0;
797
+ }, v = async (p) => {
800
798
  if (!R) return;
801
- const v = J(h), k = () => {
799
+ const T = J(p), k = () => {
802
800
  const { x: H, y: M } = e.getBoundingClientRect();
803
- if (G(e, v.target)) {
804
- (typeof d == "function" ? d(v, e) : d === "ALWAYS") && o.clear();
801
+ if (W(e, T.target)) {
802
+ (typeof d == "function" ? d(T, e) : d === "ALWAYS") && o.clear();
805
803
  return;
806
804
  }
807
- const P = v.target instanceof Node && e.contains(v.target) && s.getAt(
808
- v.clientX - H,
809
- v.clientY - M,
805
+ const D = T.target instanceof Node && e.contains(T.target) && s.getAt(
806
+ T.clientX - H,
807
+ T.clientY - M,
810
808
  g === "all",
811
809
  u
812
810
  );
813
- if (P) {
814
- const { selected: z } = o, B = new Set(z.map((V) => V.id)), F = Array.isArray(P) ? P.map((V) => V.id) : [P.id];
815
- (B.size !== F.length || !F.every((V) => B.has(V))) && (n.emit("clickAnnotation", P), o.userSelect(F, v));
811
+ if (D) {
812
+ const { selected: q } = o, B = new Set(q.map((Y) => Y.id)), V = Array.isArray(D) ? D.map((Y) => Y.id) : [D.id];
813
+ (B.size !== V.length || !V.every((Y) => B.has(Y))) && (n.emit("clickAnnotation", D), o.userSelect(V, T));
816
814
  } else
817
815
  o.clear();
818
816
  };
819
- if (v.timeStamp - b.timeStamp < ae) {
817
+ if (T.timeStamp - b.timeStamp < ae) {
820
818
  await N();
821
- const H = document.getSelection(), M = G(e, b.target), P = G(e, v.target);
822
- if (H?.isCollapsed || M && P) {
819
+ const H = document.getSelection(), M = W(e, b.target), D = W(e, T.target);
820
+ if (H?.isCollapsed || M && D) {
823
821
  f = void 0, k();
824
822
  return;
825
823
  }
826
824
  }
827
- f && f.selector.length > 0 && ($(), o.userSelect(f.annotation, v));
825
+ f && f.selector.length > 0 && (F(), o.userSelect(f.annotation, T));
828
826
  }, N = async () => {
829
- const h = document.getSelection();
830
- let v = !1, k = h?.isCollapsed;
831
- const U = () => k || v, H = 1;
832
- return setTimeout(() => v = !0, 50), He(() => k = h?.isCollapsed, H, U);
833
- }, O = (h) => {
834
- document.getSelection()?.isCollapsed || ((!f || f.selector.length === 0) && L(h), f && ($(), o.userSelect(f.annotation, J(h))));
835
- }, D = (h) => {
836
- y && h.key === "Shift" && f && (document.getSelection().isCollapsed || ($(), o.userSelect(f.annotation, j(h))));
837
- }, Y = (h) => {
838
- const v = () => setTimeout(() => {
827
+ const p = document.getSelection();
828
+ let T = !1, k = p?.isCollapsed;
829
+ const U = () => k || T, H = 1;
830
+ return setTimeout(() => T = !0, 50), Ie(() => k = p?.isCollapsed, H, U);
831
+ }, O = (p) => {
832
+ document.getSelection()?.isCollapsed || ((!f || f.selector.length === 0) && L(p), f && (F(), o.userSelect(f.annotation, J(p))));
833
+ }, P = (p) => {
834
+ y && (p.repeat || p.target instanceof Node && W(e, p.target) && p.target !== document.body || p.key === "Shift" && f && (document.getSelection().isCollapsed || (F(), o.userSelect(f.annotation, G(p)))));
835
+ }, X = (p) => {
836
+ const T = () => setTimeout(() => {
839
837
  f?.selector.length > 0 && (o.clear(), s.addAnnotation({
840
838
  id: f.annotation,
841
839
  bodies: [],
842
840
  target: f
843
- }), o.userSelect(f.annotation, j(h))), document.removeEventListener("selectionchange", v);
841
+ }), o.userSelect(f.annotation, G(p))), document.removeEventListener("selectionchange", T);
844
842
  }, 100);
845
- document.addEventListener("selectionchange", v), C();
843
+ document.addEventListener("selectionchange", T), C();
846
844
  };
847
- q(St.join(","), { element: e, keydown: !0, keyup: !1 }, (h) => {
848
- h.repeat || (b = j(h));
849
- }), q(be, { keydown: !0, keyup: !1 }, (h) => {
850
- b = j(h), Y(h);
845
+ j(bt.join(","), { element: e, keydown: !0, keyup: !1 }, (p) => {
846
+ p.repeat || (b = G(p));
847
+ }), j(be, { keydown: !0, keyup: !1 }, (p) => {
848
+ b = G(p), X(p);
851
849
  });
852
- const X = (h) => {
853
- h.repeat || h.target !== e && h.target !== document.body || (f = void 0, o.clear());
850
+ const z = (p) => {
851
+ p.repeat || p.target instanceof Node && W(e, p.target) && p.target !== document.body || (f = void 0, o.clear());
854
852
  };
855
- q(ye.join(","), { keydown: !0, keyup: !1 }, X);
856
- const $ = () => {
857
- const h = s.getAnnotation(f.annotation);
858
- if (!h)
853
+ j(ye.join(","), { keydown: !0, keyup: !1 }, z);
854
+ const F = () => {
855
+ const p = s.getAnnotation(f.annotation);
856
+ if (!p)
859
857
  s.addAnnotation({
860
858
  id: f.annotation,
861
859
  bodies: [],
862
860
  target: f
863
861
  });
864
862
  else {
865
- const { target: { updated: v } } = h, { updated: k } = f;
866
- (!v || !k || v < k) && s.updateTarget(f);
863
+ const { target: { updated: T } } = p, { updated: k } = f;
864
+ (!T || !k || T < k) && s.updateTarget(f);
867
865
  }
868
866
  };
869
- return document.addEventListener("pointerdown", A), document.addEventListener("pointerup", T), document.addEventListener("contextmenu", O), e.addEventListener("keyup", D), e.addEventListener("selectstart", C), document.addEventListener("selectionchange", L), {
867
+ return document.addEventListener("pointerdown", A), document.addEventListener("pointerup", v), document.addEventListener("contextmenu", O), document.addEventListener("keyup", P), e.addEventListener("selectstart", C), document.addEventListener("selectionchange", L), {
870
868
  destroy: () => {
871
- f = void 0, x = void 0, R = void 0, b = void 0, L.clear(), document.removeEventListener("pointerdown", A), document.removeEventListener("pointerup", T), document.removeEventListener("contextmenu", O), e.removeEventListener("keyup", D), e.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", L), q.unbind();
869
+ f = void 0, x = void 0, R = void 0, b = void 0, L.clear(), document.removeEventListener("pointerdown", A), document.removeEventListener("pointerup", v), document.removeEventListener("contextmenu", O), document.removeEventListener("keyup", P), e.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", L), j.unbind();
872
870
  },
873
871
  setFilter: E,
874
872
  setUser: m,
875
- setAnnotatingEnabled: p,
873
+ setAnnotatingEnabled: h,
876
874
  setAnnotatingMode: S
877
875
  };
878
- }, wt = (e, t) => ({
876
+ }, Ct = (e, t) => ({
879
877
  ...e,
880
878
  annotatingEnabled: e.annotatingEnabled ?? t.annotatingEnabled,
881
879
  user: e.user || t.user
882
- }), ce = "SPANS", Kt = (e, t = {}) => {
883
- Pe(e), Ue(e);
884
- const n = wt(t, {
880
+ }), ce = "SPANS", _t = (e, t = {}) => {
881
+ _e(e), He(e);
882
+ const n = Ct(t, {
885
883
  annotatingEnabled: !0,
886
- user: Ne()
887
- }), r = Ct(e, n), { selection: s, viewport: o } = r, i = r.store, c = Oe(i), l = Be(r, c, n.adapter);
884
+ user: xe()
885
+ }), r = yt(e, n), { selection: s, viewport: o } = r, i = r.store, c = Le(i), l = Ne(r, c, n.adapter);
888
886
  let g = n.user;
889
- const d = typeof n.renderer != "function" ? n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ce : n.renderer || ce : null, u = d === null ? n.renderer(e, r, o) : d === "SPANS" ? ft(e, r, o) : d === "CSS_HIGHLIGHTS" ? at(e, r, o) : d === "CANVAS" ? st(e, r, o) : void 0;
887
+ const d = typeof n.renderer != "function" ? n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ce : n.renderer || ce : null, u = d === null ? n.renderer(e, r, o) : d === "SPANS" ? lt(e, r, o) : d === "CSS_HIGHLIGHTS" ? st(e, r, o) : d === "CANVAS" ? tt(e, r, o) : void 0;
890
888
  if (!u)
891
889
  throw `Unknown renderer implementation: ${n.renderer}`;
892
890
  console.debug(d ? `Using ${d} renderer` : "Using custom renderer implementation"), n.style && u.setStyle(n.style);
893
- const y = At(e, r, l, n);
891
+ const y = Et(e, r, l, n);
894
892
  y.setUser(g);
895
- const w = ke(r, c, n.adapter), f = () => g, x = (a) => {
893
+ const w = Oe(r, c, n.adapter), f = () => g, x = (a) => {
896
894
  y.setAnnotatingEnabled(
897
895
  a === void 0 ? !0 : a
898
896
  );
@@ -900,10 +898,10 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
900
898
  y.setAnnotatingMode(a);
901
899
  }, b = (a) => {
902
900
  u.setFilter(a), y.setFilter(a);
903
- }, p = (a) => {
901
+ }, h = (a) => {
904
902
  g = a, y.setUser(a);
905
903
  }, S = (a) => {
906
- a && (u.setPainter(bt(a, n.presence)), a.on("selectionChange", () => u.redraw()));
904
+ a && (u.setPainter(pt(a, n.presence)), a.on("selectionChange", () => u.redraw()));
907
905
  }, E = (a) => {
908
906
  a ? s.setSelected(a) : s.clear();
909
907
  };
@@ -919,13 +917,13 @@ const ue = "not-annotatable", W = `.${ue}`, G = (e, t) => e.contains(t) ? !!(t i
919
917
  setFilter: b,
920
918
  setStyle: u.setStyle.bind(u),
921
919
  redraw: u.redraw.bind(u),
922
- setUser: p,
920
+ setUser: h,
923
921
  setSelected: E,
924
922
  setPresenceProvider: S,
925
923
  setVisible: u.setVisible.bind(u),
926
924
  on: l.on,
927
925
  off: l.off,
928
- scrollIntoView: Ze(e, i),
926
+ scrollIntoView: je(e, i),
929
927
  state: r
930
928
  };
931
929
  };
@@ -933,53 +931,53 @@ export {
933
931
  Z as DEFAULT_SELECTED_STYLE,
934
932
  _ as DEFAULT_STYLE,
935
933
  ue as NOT_ANNOTATABLE_CLASS,
936
- W as NOT_ANNOTATABLE_SELECTOR,
937
- Ft as Origin,
938
- Vt as UserSelectAction,
939
- Ut as W3CTextFormat,
940
- Pe as cancelSingleClickEvents,
941
- j as cloneKeyboardEvent,
934
+ $ as NOT_ANNOTATABLE_SELECTOR,
935
+ Pt as Origin,
936
+ Ut as UserSelectAction,
937
+ It as W3CTextFormat,
938
+ _e as cancelSingleClickEvents,
939
+ G as cloneKeyboardEvent,
942
940
  J as clonePointerEvent,
943
941
  se as createBaseRenderer,
944
- Yt as createBody,
945
- st as createCanvasRenderer,
946
- at as createHighlightsRenderer,
947
- bt as createPresencePainter,
948
- it as createRenderer,
949
- At as createSelectionHandler,
950
- ft as createSpansRenderer,
951
- Kt as createTextAnnotator,
952
- Ct as createTextAnnotatorState,
942
+ Kt as createBody,
943
+ tt as createCanvasRenderer,
944
+ st as createHighlightsRenderer,
945
+ pt as createPresencePainter,
946
+ ot as createRenderer,
947
+ Et as createSelectionHandler,
948
+ lt as createSpansRenderer,
949
+ _t as createTextAnnotator,
950
+ yt as createTextAnnotatorState,
953
951
  ee as debounce,
954
- wt as fillDefaults,
955
- ct as getBackgroundColor,
956
- Ke as getHighlightClientRects,
957
- Fe as getQuoteContext,
952
+ Ct as fillDefaults,
953
+ rt as getBackgroundColor,
954
+ De as getHighlightClientRects,
955
+ Ke as getQuoteContext,
958
956
  oe as getRangeAnnotatableContents,
959
- Je as getViewportBounds,
957
+ Ge as getViewportBounds,
960
958
  ge as isMac,
961
- Ht as isNodeWhitespaceOrEmpty,
962
- G as isNotAnnotatable,
959
+ Bt as isNodeWhitespaceOrEmpty,
960
+ W as isNotAnnotatable,
963
961
  fe as isRangeAnnotatable,
964
- Ve as isRangeWhitespaceOrEmpty,
962
+ We as isRangeWhitespaceOrEmpty,
965
963
  I as isRevived,
966
- ze as mergeClientRects,
967
- qe as mergeRanges,
968
- lt as paint,
969
- pt as parseW3CTextAnnotation,
970
- Ue as programmaticallyFocusable,
971
- je as rangeToSelector,
964
+ Ve as mergeClientRects,
965
+ Ye as mergeRanges,
966
+ it as paint,
967
+ ft as parseW3CTextAnnotation,
968
+ He as programmaticallyFocusable,
969
+ Xe as rangeToSelector,
972
970
  te as reviveAnnotation,
973
971
  pe as reviveSelector,
974
972
  Q as reviveTarget,
975
- Ze as scrollIntoView,
976
- ht as serializeW3CTextAnnotation,
977
- $e as splitAnnotatableRanges,
978
- Pt as toDomRectList,
979
- Ge as toParentBounds,
980
- Dt as toViewportBounds,
981
- et as trackViewport,
982
- Qe as trimRangeToContainer,
973
+ je as scrollIntoView,
974
+ gt as serializeW3CTextAnnotation,
975
+ Ue as splitAnnotatableRanges,
976
+ kt as toDomRectList,
977
+ ze as toParentBounds,
978
+ Mt as toViewportBounds,
979
+ Qe as trackViewport,
980
+ qe as trimRangeToContainer,
983
981
  me as whitespaceOrEmptyRegex
984
982
  };
985
983
  //# sourceMappingURL=text-annotator.es.js.map