@recogito/text-annotator 4.2.0 → 4.2.2

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,21 @@
1
1
  import { v4 as dt } from "uuid";
2
- import { parseW3CBodies as At, serializeW3CBodies as vt, parseW3CUser as Rt, UserSelectAction as wt, createStore as xt, createSelectionState as Lt, createHoverState as Nt, createViewportState as Ot, Origin as F, createAnonymousGuest as kt, createUndoStack as _t, createLifecycleObserver as Mt, createBaseAnnotator as Bt } from "@annotorious/core";
2
+ import { parseW3CBodies as Tt, serializeW3CBodies as At, parseW3CUser as vt, UserSelectAction as Rt, createStore as wt, createSelectionState as xt, createHoverState as Lt, createViewportState as Nt, Origin as K, createAnonymousGuest as Ot, createUndoStack as kt, createLifecycleObserver as _t, createBaseAnnotator as Mt } from "@annotorious/core";
3
3
  import { Origin as De, UserSelectAction as He, createBody as Pe } from "@annotorious/core";
4
4
  import { createNanoEvents as ut } from "nanoevents";
5
5
  import { colord as ot } from "colord";
6
- import { dequal as It } from "dequal/lite";
7
- import Dt from "rbush";
8
- import Ht from "debounce";
6
+ import { dequal as Bt } from "dequal/lite";
7
+ import It from "rbush";
8
+ import Dt from "debounce";
9
9
  import G from "hotkeys-js";
10
- import { poll as Pt } from "poll";
11
- const Le = (t) => t.target.selector.every(I), ft = (t) => t.selector.every(I);
10
+ import { poll as Ht } from "poll";
11
+ const xe = (t) => t.target.selector.every(I), Le = (t) => t.selector.every(I);
12
12
  function I(t) {
13
13
  return Array.isArray(t) ? t.every((e) => "range" in e && e.range instanceof Range && !e.range.collapsed) : "range" in t && t.range instanceof Range && !t.range.collapsed;
14
14
  }
15
- const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt = "not-annotatable", W = `.${mt}`, Z = (t, e) => t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(W) : e.parentElement?.closest(W)) : !0, pt = (t, e) => {
15
+ const ft = typeof navigator < "u" && navigator.platform.startsWith("Mac"), gt = "not-annotatable", W = `.${gt}`, Z = (t, e) => t.contains(e) ? !!(e instanceof HTMLElement ? e.closest(W) : e.parentElement?.closest(W)) : !0, mt = (t, e) => {
16
16
  const o = e.commonAncestorContainer;
17
17
  return !Z(t, o);
18
- }, ht = /^\s*$/, Ut = (t) => ht.test(t.toString()), Ne = (t) => ht.test(t.textContent || ""), Kt = (t) => {
18
+ }, pt = /^\s*$/, Pt = (t) => pt.test(t.toString()), Ne = (t) => pt.test(t.textContent || ""), Ut = (t) => {
19
19
  if (t.length === 0) return [];
20
20
  if (t.length === 1) return [t[0]];
21
21
  t.sort((s, n) => {
@@ -26,20 +26,20 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
26
26
  return [...i.merged, i.current];
27
27
  }, Ft = (t) => {
28
28
  (!t.hasAttribute("tabindex") || t.tabIndex < -1) && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
29
- }, Wt = function* (t) {
29
+ }, Kt = function* (t) {
30
30
  const e = document.createTreeWalker(
31
31
  t.commonAncestorContainer,
32
32
  NodeFilter.SHOW_ELEMENT,
33
- (i) => i instanceof HTMLElement && i.classList.contains(mt) && !i.parentElement?.closest(W) && t.intersectsNode(i) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
33
+ (i) => i instanceof HTMLElement && i.classList.contains(gt) && !i.parentElement?.closest(W) && t.intersectsNode(i) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
34
34
  );
35
35
  let o;
36
36
  for (; o = e.nextNode(); )
37
37
  o instanceof HTMLElement && (yield o);
38
- }, $t = (t, e) => {
39
- if (!pt(t, e)) return [];
38
+ }, Wt = (t, e) => {
39
+ if (!mt(t, e)) return [];
40
40
  const o = [];
41
41
  let i = null;
42
- for (const s of Wt(e)) {
42
+ for (const s of Kt(e)) {
43
43
  let n;
44
44
  i ? (n = document.createRange(), n.setStartAfter(i), n.setEndBefore(s)) : (n = e.cloneRange(), n.setEndBefore(s)), n.collapsed || o.push(n), i = s;
45
45
  }
@@ -51,10 +51,10 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
51
51
  }, st = (t) => {
52
52
  const e = t.cloneContents();
53
53
  return e.querySelectorAll(W).forEach((o) => o.remove()), e;
54
- }, Yt = (t, e) => {
54
+ }, $t = (t, e) => {
55
55
  const o = t.cloneRange();
56
56
  return e.contains(o.startContainer) || o.setStart(e, 0), e.contains(o.endContainer) || o.setEnd(e, e.childNodes.length), o;
57
- }, it = new Intl.Segmenter(void 0, { granularity: "grapheme" }), Xt = (t, e, o = 10, i) => {
57
+ }, it = new Intl.Segmenter(void 0, { granularity: "grapheme" }), Yt = (t, e, o = 10, i) => {
58
58
  const s = i ? t.startContainer.parentElement.closest(i) : e, n = document.createRange();
59
59
  n.setStart(s, 0), n.setEnd(t.startContainer, t.startOffset);
60
60
  const r = st(n).textContent, a = document.createRange();
@@ -64,12 +64,13 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
64
64
  prefix: m.slice(-o).map((y) => y.segment).join(""),
65
65
  suffix: f.slice(0, o).map((y) => y.segment).join("")
66
66
  };
67
- }, Vt = (t, e, o) => {
67
+ }, Xt = (t, e, o) => {
68
68
  const i = document.createRange(), s = o ? t.startContainer.parentElement.closest(o) : e;
69
69
  i.setStart(s, 0), i.setEnd(t.startContainer, t.startOffset);
70
70
  const n = st(i).textContent, r = t.toString(), a = n.length || 0, c = a + r.length;
71
71
  return o ? { quote: r, start: a, end: c, range: t, offsetReference: s } : { quote: r, start: a, end: c, range: t };
72
- }, yt = (t, e) => {
72
+ }, ht = (t, e) => {
73
+ if (I(t)) return t;
73
74
  const { start: o, end: i } = t, s = t.offsetReference || e, n = document.createTreeWalker(
74
75
  e,
75
76
  NodeFilter.SHOW_TEXT,
@@ -103,19 +104,22 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
103
104
  ...t,
104
105
  range: a
105
106
  };
106
- }, J = (t, e, o = (i, s) => yt(i, s)) => ft(t) ? t : {
107
+ }, J = (t, e, o = (i, s) => ht(i, s)) => ({
108
+ ...t,
109
+ selector: t.selector.map((i) => o(i, e))
110
+ }), tt = (t, e, o) => ({
107
111
  ...t,
108
- selector: t.selector.map((i) => I(i) ? i : o(i, e))
109
- }, tt = (t, e, o) => ft(t.target) ? t : { ...t, target: J(t.target, e, o) }, St = (t) => {
112
+ target: J(t.target, e, o)
113
+ }), yt = (t) => {
110
114
  if (!t)
111
115
  return document.scrollingElement;
112
116
  const { overflowY: e } = window.getComputedStyle(t);
113
- return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : St(t.parentElement);
117
+ return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : yt(t.parentElement);
114
118
  }, at = (t, e, o) => {
115
119
  const i = o.getBoundingClientRect(), s = o.clientHeight, n = o.clientWidth, r = e.selector[0].range.getBoundingClientRect(), { width: a, height: c } = t.getAnnotationBounds(e.annotation), m = r.top - i.top, f = r.left - i.left, y = o.parentElement ? o.scrollTop : 0, g = o.parentElement ? o.scrollLeft : 0, R = m + y - (s - c) / 2, l = f + g - (n - a) / 2;
116
120
  o.scroll({ top: R, left: l, behavior: "smooth" });
117
- }, zt = (t, e) => (o, i) => {
118
- const s = typeof o == "string" ? o : o.id, n = i ? typeof i == "string" ? document.getElementById(i) : i : St(t);
121
+ }, Vt = (t, e) => (o, i) => {
122
+ const s = typeof o == "string" ? o : o.id, n = i ? typeof i == "string" ? document.getElementById(i) : i : yt(t);
119
123
  if (!n)
120
124
  return console.warn(`The scroll parent is missing for the annotation: ${s}`, { container: t }), !1;
121
125
  const r = e.getAnnotation(s);
@@ -127,9 +131,9 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
127
131
  const c = J(r.target, t), { range: m } = c.selector[0];
128
132
  return m && !m.collapsed ? (at(e, c, n), !0) : !1;
129
133
  }, Oe = (t, e) => ({
130
- parse: (o) => Gt(o),
131
- serialize: (o) => Qt(o, t, e)
132
- }), qt = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, jt = (t) => {
134
+ parse: (o) => jt(o),
135
+ serialize: (o) => Gt(o, t, e)
136
+ }), zt = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, qt = (t) => {
133
137
  const {
134
138
  id: e,
135
139
  creator: o,
@@ -140,7 +144,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
140
144
  if (r.length === 0)
141
145
  return { error: Error(`No targets found for annotation: ${t.id}`) };
142
146
  const a = {
143
- creator: Rt(o),
147
+ creator: vt(o),
144
148
  created: i ? new Date(i) : void 0,
145
149
  updated: s ? new Date(s) : void 0,
146
150
  annotation: e,
@@ -160,7 +164,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
160
164
  }
161
165
  return y;
162
166
  }, {});
163
- if (qt(f))
167
+ if (zt(f))
164
168
  a.selector.push(
165
169
  {
166
170
  ...f,
@@ -178,14 +182,14 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
178
182
  }
179
183
  }
180
184
  return { parsed: a };
181
- }, Gt = (t) => {
185
+ }, jt = (t) => {
182
186
  const e = t.id || dt(), {
183
187
  creator: o,
184
188
  created: i,
185
189
  modified: s,
186
190
  body: n,
187
191
  ...r
188
- } = t, a = At(n, e), c = jt(t);
192
+ } = t, a = Tt(n, e), c = qt(t);
189
193
  return "error" in c ? { error: c.error } : {
190
194
  parsed: {
191
195
  ...r,
@@ -194,7 +198,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
194
198
  target: c.parsed
195
199
  }
196
200
  };
197
- }, Qt = (t, e, o) => {
201
+ }, Gt = (t, e, o) => {
198
202
  const { bodies: i, target: s, ...n } = t, {
199
203
  selector: r,
200
204
  creator: a,
@@ -207,7 +211,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
207
211
  exact: l
208
212
  };
209
213
  if (o && "range" in g) {
210
- const { prefix: S, suffix: x } = Xt(g.range, o);
214
+ const { prefix: S, suffix: x } = Yt(g.range, o);
211
215
  L.prefix = S, L.suffix = x;
212
216
  }
213
217
  if (!("start" in g))
@@ -231,13 +235,13 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
231
235
  "@context": "http://www.w3.org/ns/anno.jsonld",
232
236
  id: t.id,
233
237
  type: "Annotation",
234
- body: vt(t.bodies),
238
+ body: At(t.bodies),
235
239
  creator: a,
236
240
  created: c?.toISOString(),
237
241
  modified: m?.toISOString(),
238
242
  target: y
239
243
  };
240
- }, Zt = (t) => t.addEventListener("click", (e) => {
244
+ }, Qt = (t) => t.addEventListener("click", (e) => {
241
245
  // Allow clicks within not-annotatable elements
242
246
  !e.target.closest(W) && !e.target.closest("a") && e.preventDefault();
243
247
  }), et = (t) => ({
@@ -287,18 +291,18 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
287
291
  return ((...i) => {
288
292
  clearTimeout(o), o = setTimeout(() => t.apply(void 0, i), e);
289
293
  });
290
- }, Et = (t, e, o, i) => {
294
+ }, St = (t, e, o, i) => {
291
295
  const { store: s, selection: n, hover: r } = o, a = ut();
292
296
  let c;
293
297
  const m = /* @__PURE__ */ new Map();
294
298
  let f;
295
- const y = le(i), g = (T) => {
299
+ const y = ce(i), g = (T) => {
296
300
  const { x: b, y: v } = e.getBoundingClientRect(), k = s.getAt(T.clientX - b, T.clientY - v, !1, f);
297
- k && o.selection.evalSelectAction(k) !== wt.NONE ? r.current !== k.id && (e.classList.add("hovered"), r.set(k.id)) : r.current && (e.classList.remove("hovered"), r.set(null));
301
+ k && o.selection.evalSelectAction(k) !== Rt.NONE ? r.current !== k.id && (e.classList.add("hovered"), r.set(k.id)) : r.current && (e.classList.remove("hovered"), r.set(null));
298
302
  };
299
303
  e.addEventListener("pointermove", g);
300
304
  const R = nt((T = !1) => requestAnimationFrame(() => {
301
- const b = ce(e), { minX: v, minY: k, maxX: K, maxY: z } = b, q = f ? s.getIntersecting(v, k, K, z).filter(({ annotation: u }) => f?.(u)) : s.getIntersecting(v, k, K, z), $ = n.selected.map(({ id: u }) => u), Y = q.map(({ annotation: u, rects: C }) => {
305
+ const b = ae(e), { minX: v, minY: k, maxX: F, maxY: z } = b, q = f ? s.getIntersecting(v, k, F, z).filter(({ annotation: u }) => f?.(u)) : s.getIntersecting(v, k, F, z), $ = n.selected.map(({ id: u }) => u), Y = q.map(({ annotation: u, rects: C }) => {
302
306
  const M = $.includes(u.id), D = u.id === r.current;
303
307
  return {
304
308
  annotation: u,
@@ -350,10 +354,10 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
350
354
  }, rt = {
351
355
  fill: "rgb(0, 128, 255)",
352
356
  fillOpacity: 0.45
353
- }, Jt = (t) => t?.fillOpacity !== void 0 ? ot(t?.fill || U.fill).alpha(t.fillOpacity).toHex() : t?.fill ? t.fill : ot(U.fill).alpha(U.fillOpacity).toHex(), bt = (t, e, o) => e ? typeof e == "function" ? e(t.annotation, t.state, o) || (t.state?.selected ? rt : U) : e : t.state?.selected ? rt : U, te = (t, e) => {
357
+ }, Zt = (t) => t?.fillOpacity !== void 0 ? ot(t?.fill || U.fill).alpha(t.fillOpacity).toHex() : t?.fill ? t.fill : ot(U.fill).alpha(U.fillOpacity).toHex(), Et = (t, e, o) => e ? typeof e == "function" ? e(t.annotation, t.state, o) || (t.state?.selected ? rt : U) : e : t.state?.selected ? rt : U, Jt = (t, e) => {
354
358
  const o = (n, r) => n.x <= r.x + r.width && n.x + n.width >= r.x && n.y <= r.y + r.height && n.y + n.height >= r.y, i = (n) => n.rects.reduce((r, a) => r + a.width, 0), s = e.filter(({ rects: n }) => n.some((r) => o(t, r)));
355
359
  return s.sort((n, r) => i(r) - i(n)), s.findIndex((n) => n.rects.includes(t));
356
- }, ee = (t) => {
360
+ }, te = (t) => {
357
361
  const e = [], o = document.createTreeWalker(
358
362
  t.commonAncestorContainer,
359
363
  NodeFilter.SHOW_TEXT
@@ -392,7 +396,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
392
396
  ...Array.from(c.getClientRects())
393
397
  ];
394
398
  }
395
- }, ne = (t, e, o, i) => {
399
+ }, ee = (t, e, o, i) => {
396
400
  const s = (a) => Math.round(a * 10) / 10, n = {
397
401
  top: s(t.top),
398
402
  bottom: s(t.bottom),
@@ -416,17 +420,17 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
416
420
  return "block-contains";
417
421
  } else if (n.top >= r.top && n.bottom <= r.bottom && n.left >= r.left && n.right <= r.right)
418
422
  return "block-is-contained";
419
- }, oe = (t, e) => {
423
+ }, ne = (t, e) => {
420
424
  const o = Math.min(t.left, e.left), i = Math.max(t.right, e.right), s = Math.min(t.top, e.top), n = Math.max(t.bottom, e.bottom);
421
425
  return new DOMRect(o, s, i - o, n - s);
422
- }, se = (t, e = 0.5, o = 0.5) => t.reduce((i, s) => {
426
+ }, oe = (t, e = 0.5, o = 0.5) => t.reduce((i, s) => {
423
427
  if (s.width === 0 || s.height === 0)
424
428
  return i;
425
429
  let n = [...i], r = !1;
426
430
  for (const a of i) {
427
- const c = ne(s, a, e, o);
431
+ const c = ee(s, a, e, o);
428
432
  if (c === "inline-adjacent") {
429
- n = n.map((m) => m === a ? oe(s, a) : m), r = !0;
433
+ n = n.map((m) => m === a ? ne(s, a) : m), r = !0;
430
434
  break;
431
435
  } else if (c === "inline-contains") {
432
436
  n = n.map((m) => m === a ? s : m), r = !0;
@@ -447,13 +451,13 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
447
451
  for (let e = 0; e < this.length; e++)
448
452
  yield this.item(e);
449
453
  }
450
- }), re = (t, e) => {
454
+ }), se = (t, e) => {
451
455
  const { left: o, top: i, right: s, bottom: n } = t;
452
456
  return new DOMRect(o - e.left, i - e.top, s - o, n - i);
453
457
  }, _e = (t, e) => {
454
458
  const { left: o, top: i, right: s, bottom: n } = t;
455
459
  return new DOMRect(o + e.left, i + e.top, s - o, n - i);
456
- }, ie = (t) => {
460
+ }, re = (t) => {
457
461
  t.classList.add("r6o-annotatable");
458
462
  const e = document.createElement("div");
459
463
  e.className = "r6o-span-highlight-layer", t.appendChild(e);
@@ -463,15 +467,15 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
463
467
  e.remove();
464
468
  },
465
469
  redraw: (r, a, c, m, f) => {
466
- if (!(!It(o, r) || f)) return;
470
+ if (!(!Bt(o, r) || f)) return;
467
471
  e.innerHTML = "", [...r].sort((l, L) => {
468
472
  const { annotation: { target: { created: N } } } = l, { annotation: { target: { created: A } } } = L;
469
473
  return N && A ? N.getTime() - A.getTime() : 0;
470
474
  }).forEach((l) => {
471
475
  const L = m?.get(l.annotation.id) || c;
472
476
  l.rects.map((N) => {
473
- const A = te(N, r), h = bt(l, L, A), S = document.createElement("span");
474
- S.className = "r6o-annotation", S.dataset.annotation = l.annotation.id, S.style.left = `${N.x}px`, S.style.top = `${N.y}px`, S.style.width = `${N.width}px`, S.style.height = `${N.height}px`, S.style.backgroundColor = Jt(h), h.underlineStyle && (S.style.borderStyle = h.underlineStyle), h.underlineColor && (S.style.borderColor = h.underlineColor), h.underlineThickness && (S.style.borderBottomWidth = `${h.underlineThickness}px`), h.underlineOffset && (S.style.paddingBottom = `${h.underlineOffset}px`), e.appendChild(S);
477
+ const A = Jt(N, r), h = Et(l, L, A), S = document.createElement("span");
478
+ S.className = "r6o-annotation", S.dataset.annotation = l.annotation.id, S.style.left = `${N.x}px`, S.style.top = `${N.y}px`, S.style.width = `${N.width}px`, S.style.height = `${N.height}px`, S.style.backgroundColor = Zt(h), h.underlineStyle && (S.style.borderStyle = h.underlineStyle), h.underlineColor && (S.style.borderColor = h.underlineColor), h.underlineThickness && (S.style.borderBottomWidth = `${h.underlineThickness}px`), h.underlineOffset && (S.style.paddingBottom = `${h.underlineOffset}px`), e.appendChild(S);
475
479
  });
476
480
  }), o = r;
477
481
  },
@@ -479,28 +483,28 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
479
483
  r ? e.classList.remove("hidden") : e.classList.add("hidden");
480
484
  }
481
485
  };
482
- }, ae = (t, e, o) => Et(ie(t), t, e, o), ce = (t) => {
486
+ }, ie = (t, e, o) => St(re(t), t, e, o), ae = (t) => {
483
487
  const { top: e, left: o } = t.getBoundingClientRect(), { innerWidth: i, innerHeight: s } = window, n = -o, r = -e, a = i - o, c = s - e;
484
488
  return { top: e, left: o, minX: n, minY: r, maxX: a, maxY: c };
485
- }, le = (t) => {
489
+ }, ce = (t) => {
486
490
  let e = /* @__PURE__ */ new Set();
487
491
  return (i) => {
488
492
  const s = i.map((n) => n.id);
489
493
  (e.size !== s.length || s.some((n) => !e.has(n))) && t.set(s), e = new Set(s);
490
494
  };
491
- }, de = (t, e, o, i, s) => {
492
- const n = new Dt(), r = /* @__PURE__ */ new Map(), a = ut(), c = (d, p) => {
495
+ }, le = (t, e, o, i, s) => {
496
+ const n = new It(), r = /* @__PURE__ */ new Map(), a = ut(), c = (d, p) => {
493
497
  const w = d.selector.flatMap((T) => {
494
- const b = (s ? s(T, e) : yt(T, e))?.range;
495
- return ee(b);
496
- }), O = se(w, o, i).map((T) => re(T, p));
498
+ const b = (s ? s(T, e) : ht(T, e))?.range;
499
+ return te(b);
500
+ }), O = oe(w, o, i).map((T) => se(T, p));
497
501
  return O.map((T) => {
498
- const { x: b, y: v, width: k, height: K } = T;
502
+ const { x: b, y: v, width: k, height: F } = T;
499
503
  return {
500
504
  minX: b,
501
505
  minY: v,
502
506
  maxX: b + k,
503
- maxY: v + K,
507
+ maxY: v + F,
504
508
  annotation: {
505
509
  id: d.annotation,
506
510
  rects: O
@@ -570,28 +574,28 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
570
574
  update: R,
571
575
  on: (d, p) => a.on(d, p)
572
576
  };
573
- }, ue = (t, e) => {
574
- const o = xt(), i = de(
577
+ }, de = (t, e) => {
578
+ const o = wt(), i = le(
575
579
  o,
576
580
  t,
577
581
  e.mergeHighlights?.horizontalTolerance,
578
582
  e.mergeHighlights?.verticalTolerance,
579
583
  e.selectorReviveFn
580
- ), s = Lt(o, e.userSelectAction, e.adapter), n = Nt(o), r = Ot(), a = (h, S = F.LOCAL) => {
584
+ ), s = xt(o, e.userSelectAction, e.adapter), n = Lt(o), r = Nt(), a = (h, S = K.LOCAL) => {
581
585
  const x = tt(h, t, e.selectorReviveFn), E = I(x.target.selector);
582
586
  return E && o.addAnnotation(x, S), E;
583
- }, c = (h, S = !0, x = F.LOCAL) => {
584
- const E = h.map((p) => tt(p, t)), d = E.filter((p) => !I(p.target.selector));
587
+ }, c = (h, S = !0, x = K.LOCAL) => {
588
+ const E = h.map((p) => tt(p, t, e.selectorReviveFn)), d = E.filter((p) => !I(p.target.selector));
585
589
  return o.bulkAddAnnotations(E, S, x), d;
586
- }, m = (h, S = F.LOCAL) => {
587
- const x = h.map((d) => tt(d, t)), E = x.filter((d) => !I(d.target.selector));
590
+ }, m = (h, S = K.LOCAL) => {
591
+ const x = h.map((d) => tt(d, t, e.selectorReviveFn)), E = x.filter((d) => !I(d.target.selector));
588
592
  return x.forEach((d) => {
589
593
  o.getAnnotation(d.id) ? o.updateAnnotation(d, S) : o.addAnnotation(d, S);
590
594
  }), E;
591
- }, f = (h, S = F.LOCAL) => {
595
+ }, f = (h, S = K.LOCAL) => {
592
596
  const x = J(h, t);
593
597
  o.updateTarget(x, S);
594
- }, y = (h, S = F.LOCAL) => {
598
+ }, y = (h, S = K.LOCAL) => {
595
599
  const x = h.map((E) => J(E, t));
596
600
  o.bulkUpdateTargets(x, S);
597
601
  };
@@ -623,10 +627,10 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
623
627
  hover: n,
624
628
  viewport: r
625
629
  };
626
- }, ct = 300, Ct = ["up", "down", "left", "right"], Tt = gt ? "⌘+a" : "ctrl+a", fe = [
627
- ...Ct.map((t) => `shift+${t}`),
628
- Tt
629
- ], ge = (t, e, o, i) => {
630
+ }, ct = 300, bt = ["up", "down", "left", "right"], Ct = ft ? "⌘+a" : "ctrl+a", ue = [
631
+ ...bt.map((t) => `shift+${t}`),
632
+ Ct
633
+ ], fe = (t, e, o, i) => {
630
634
  const { store: s, selection: n } = e;
631
635
  let r;
632
636
  const {
@@ -643,7 +647,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
643
647
  return !0;
644
648
  if (i.allowModifierSelect) {
645
649
  const C = u;
646
- return gt ? C.metaKey : C.ctrlKey;
650
+ return ft ? C.metaKey : C.ctrlKey;
647
651
  } else
648
652
  return !1;
649
653
  }, p = () => {
@@ -669,12 +673,12 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
669
673
  created: /* @__PURE__ */ new Date(),
670
674
  creator: r
671
675
  };
672
- }, w = Ht((u) => {
676
+ }, w = Dt((u) => {
673
677
  if (!g) return;
674
678
  const C = document.getSelection();
675
679
  if (!C?.anchorNode) return;
676
- const D = $().map((_) => Yt(_, t));
677
- if (D.every((_) => !pt(t, _))) {
680
+ const D = $().map((_) => $t(_, t));
681
+ if (D.every((_) => !mt(t, _))) {
678
682
  l = void 0;
679
683
  return;
680
684
  }
@@ -685,18 +689,18 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
685
689
  s.getAnnotation(l.annotation) && !(d(A) || R === "REPLACE_CURRENT") && (n.clear(), s.deleteAnnotation(l.annotation));
686
690
  return;
687
691
  }
688
- if (D.every((_) => Ut(_))) return;
689
- const B = D.flatMap((_) => $t(t, _.cloneRange()));
692
+ if (D.every((_) => Pt(_))) return;
693
+ const B = D.flatMap((_) => Wt(t, _.cloneRange()));
690
694
  if (!(B.length > 0 && !l || B.length !== l.selector.length || B.some((_, X) => _.toString() !== l?.selector[X]?.quote))) return;
691
- const j = d(A) && L ? Kt([
695
+ const j = d(A) && L ? Ut([
692
696
  ...L.selector.map((_) => _.range),
693
697
  ...B
694
698
  ]) : B;
695
699
  l = {
696
700
  ...l,
697
- selector: j.map((_) => Vt(_, t, c)),
701
+ selector: j.map((_) => Xt(_, t, c)),
698
702
  updated: /* @__PURE__ */ new Date()
699
- }, !(d(A) || R === "REPLACE_CURRENT") && (s.getAnnotation(l.annotation) ? s.updateTarget(l, F.LOCAL) : n.clear());
703
+ }, !(d(A) || R === "REPLACE_CURRENT") && (s.getAnnotation(l.annotation) ? s.updateTarget(l, K.LOCAL) : n.clear());
700
704
  }, 10), O = (u) => {
701
705
  A = et(u), N = A.button === 0;
702
706
  }, T = async (u) => {
@@ -732,7 +736,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
732
736
  const u = document.getSelection();
733
737
  let C = !1, M = u?.isCollapsed;
734
738
  const D = () => M || C, H = 1;
735
- return setTimeout(() => C = !0, 50), Pt(() => M = u?.isCollapsed, H, D);
739
+ return setTimeout(() => C = !0, 50), Ht(() => M = u?.isCollapsed, H, D);
736
740
  }, v = (u) => {
737
741
  document.getSelection()?.isCollapsed || ((!l || l.selector.length === 0) && w(u), l && (Y(), n.userSelect(l.annotation, et(u))));
738
742
  }, k = (u) => {
@@ -740,7 +744,7 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
740
744
  const C = document.getSelection();
741
745
  C && !C.isCollapsed && (Y(), n.userSelect(l.annotation, Q(u)));
742
746
  }
743
- }, K = (u) => {
747
+ }, F = (u) => {
744
748
  const C = () => setTimeout(() => {
745
749
  l && (l.selector.length > 0 && (n.clear(), s.addAnnotation({
746
750
  id: l.annotation,
@@ -750,15 +754,15 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
750
754
  }, 100);
751
755
  document.addEventListener("selectionchange", C), p();
752
756
  };
753
- G(fe.join(","), { element: t, keydown: !0, keyup: !1 }, (u) => {
757
+ G(ue.join(","), { element: t, keydown: !0, keyup: !1 }, (u) => {
754
758
  u.repeat || (A = Q(u));
755
- }), G(Tt, { keydown: !0, keyup: !1 }, (u) => {
756
- A = Q(u), K(u);
759
+ }), G(Ct, { keydown: !0, keyup: !1 }, (u) => {
760
+ A = Q(u), F(u);
757
761
  });
758
762
  const z = (u) => {
759
763
  u.repeat || $().length !== 0 && (l = void 0, n.clear());
760
764
  };
761
- G(Ct.join(","), { keydown: !0, keyup: !1 }, z), document.addEventListener("pointerdown", O), document.addEventListener("pointerup", T), document.addEventListener("contextmenu", v), document.addEventListener("keyup", k), t.addEventListener("selectstart", p), document.addEventListener("selectionchange", w);
765
+ G(bt.join(","), { keydown: !0, keyup: !1 }, z), document.addEventListener("pointerdown", O), document.addEventListener("pointerup", T), document.addEventListener("contextmenu", v), document.addEventListener("keyup", k), t.addEventListener("selectstart", p), document.addEventListener("selectionchange", w);
762
766
  const q = () => {
763
767
  l = void 0, L = void 0, N = void 0, A = void 0, w.clear(), document.removeEventListener("pointerdown", O), document.removeEventListener("pointerup", T), document.removeEventListener("contextmenu", v), document.removeEventListener("keyup", k), t.removeEventListener("selectstart", p), document.removeEventListener("selectionchange", w), G.unbind();
764
768
  }, $ = () => {
@@ -785,13 +789,13 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
785
789
  setAnnotatingEnabled: h,
786
790
  setAnnotatingMode: S
787
791
  };
788
- }, me = (t) => [
792
+ }, ge = (t) => [
789
793
  `background-color:${ot(t?.fill || U.fill).alpha(t?.fillOpacity === void 0 ? U.fillOpacity : t.fillOpacity).toHex()}`,
790
794
  t?.underlineThickness ? "text-decoration:underline" : void 0,
791
795
  t?.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
792
796
  t?.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
793
797
  t?.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
794
- ].filter(Boolean).join(";"), pe = () => {
798
+ ].filter(Boolean).join(";"), me = () => {
795
799
  const t = document.createElement("style");
796
800
  document.getElementsByTagName("head")[0].appendChild(t);
797
801
  let e = /* @__PURE__ */ new Set();
@@ -807,8 +811,8 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
807
811
  Array.from(e).filter((g) => !f.has(g));
808
812
  const y = n.map((g) => {
809
813
  a ? typeof a == "function" && a(g.annotation, g.state) : g.state?.selected;
810
- const R = bt(g, a);
811
- return `::highlight(_${g.annotation.id}) { ${me(R)} }`;
814
+ const R = Et(g, a);
815
+ return `::highlight(_${g.annotation.id}) { ${ge(R)} }`;
812
816
  });
813
817
  t.innerHTML = y.join(`
814
818
  `), CSS.highlights.clear(), n.forEach(({ annotation: g }) => {
@@ -817,26 +821,26 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
817
821
  }), e = f;
818
822
  }
819
823
  };
820
- }, he = (t, e, o) => Et(pe(), t, e, o), ye = (t, e) => ({
824
+ }, pe = (t, e, o) => St(me(), t, e, o), he = (t, e) => ({
821
825
  ...t,
822
826
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
823
827
  user: t.user || e.user
824
828
  }), lt = "SPANS", Me = (t, e = {}) => {
825
- Zt(t), Ft(t);
826
- const o = ye(e, {
829
+ Qt(t), Ft(t);
830
+ const o = he(e, {
827
831
  annotatingEnabled: !0,
828
- user: kt()
829
- }), i = ue(t, o), { selection: s, viewport: n } = i, r = i.store, a = _t(r), c = Mt(i, a, o.adapter);
832
+ user: Ot()
833
+ }), i = de(t, o), { selection: s, viewport: n } = i, r = i.store, a = kt(r), c = _t(i, a, o.adapter);
830
834
  let m = o.user;
831
835
  const f = typeof o.renderer != "function" ? o.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : lt : o.renderer || lt : null, y = f === null ? o.renderer(
832
836
  t,
833
837
  i,
834
838
  n
835
- ) : f === "SPANS" ? ae(
839
+ ) : f === "SPANS" ? ie(
836
840
  t,
837
841
  i,
838
842
  n
839
- ) : f === "CSS_HIGHLIGHTS" ? he(
843
+ ) : f === "CSS_HIGHLIGHTS" ? pe(
840
844
  t,
841
845
  i,
842
846
  n
@@ -844,14 +848,14 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
844
848
  if (!y)
845
849
  throw `Unknown renderer implementation: ${o.renderer}`;
846
850
  console.debug(f ? `Using ${f} renderer` : "Using custom renderer implementation"), o.style && y.setStyle(o.style);
847
- const g = ge(
851
+ const g = fe(
848
852
  t,
849
853
  i,
850
854
  c,
851
855
  o
852
856
  );
853
857
  g.setUser(m);
854
- const R = Bt(i, a, o.adapter), l = () => m, L = (E) => {
858
+ const R = Mt(i, a, o.adapter), l = () => m, L = (E) => {
855
859
  g.setAnnotatingEnabled(
856
860
  E === void 0 ? !0 : E
857
861
  );
@@ -881,61 +885,60 @@ const gt = typeof navigator < "u" && navigator.platform.startsWith("Mac"), mt =
881
885
  setVisible: y.setVisible.bind(y),
882
886
  on: c.on,
883
887
  off: c.off,
884
- // @ts-ignore - temporary
885
- scrollIntoView: zt(t, r),
888
+ scrollIntoView: Vt(t, r),
886
889
  state: i
887
890
  };
888
891
  };
889
892
  export {
890
893
  rt as DEFAULT_SELECTED_STYLE,
891
894
  U as DEFAULT_STYLE,
892
- mt as NOT_ANNOTATABLE_CLASS,
895
+ gt as NOT_ANNOTATABLE_CLASS,
893
896
  W as NOT_ANNOTATABLE_SELECTOR,
894
897
  De as Origin,
895
898
  He as UserSelectAction,
896
899
  Oe as W3CTextFormat,
897
- Zt as cancelSingleClickEvents,
900
+ Qt as cancelSingleClickEvents,
898
901
  Q as cloneKeyboardEvent,
899
902
  et as clonePointerEvent,
900
- bt as computeStyle,
901
- te as computeZIndex,
903
+ Et as computeStyle,
904
+ Jt as computeZIndex,
902
905
  Pe as createBody,
903
- Et as createRenderer,
904
- ge as createSelectionHandler,
905
- ae as createSpansRenderer,
906
+ St as createRenderer,
907
+ fe as createSelectionHandler,
908
+ ie as createSpansRenderer,
906
909
  Me as createTextAnnotator,
907
- ue as createTextAnnotatorState,
910
+ de as createTextAnnotatorState,
908
911
  nt as debounce,
909
- ye as fillDefaults,
910
- Jt as getBackgroundColor,
911
- ee as getHighlightClientRects,
912
- Xt as getQuoteContext,
912
+ he as fillDefaults,
913
+ Zt as getBackgroundColor,
914
+ te as getHighlightClientRects,
915
+ Yt as getQuoteContext,
913
916
  st as getRangeAnnotatableContents,
914
- ce as getViewportBounds,
915
- gt as isMac,
917
+ ae as getViewportBounds,
918
+ ft as isMac,
916
919
  Ne as isNodeWhitespaceOrEmpty,
917
920
  Z as isNotAnnotatable,
918
- pt as isRangeAnnotatable,
919
- Ut as isRangeWhitespaceOrEmpty,
921
+ mt as isRangeAnnotatable,
922
+ Pt as isRangeWhitespaceOrEmpty,
920
923
  I as isRevived,
921
- Le as isRevivedAnnotation,
922
- ft as isRevivedTarget,
923
- se as mergeClientRects,
924
- Kt as mergeRanges,
925
- Gt as parseW3CTextAnnotation,
924
+ xe as isRevivedAnnotation,
925
+ Le as isRevivedTarget,
926
+ oe as mergeClientRects,
927
+ Ut as mergeRanges,
928
+ jt as parseW3CTextAnnotation,
926
929
  Ft as programmaticallyFocusable,
927
- Vt as rangeToSelector,
930
+ Xt as rangeToSelector,
928
931
  tt as reviveAnnotation,
929
932
  J as reviveTarget,
930
- yt as reviveTextSelector,
931
- zt as scrollIntoView,
932
- Qt as serializeW3CTextAnnotation,
933
- $t as splitAnnotatableRanges,
933
+ ht as reviveTextSelector,
934
+ Vt as scrollIntoView,
935
+ Gt as serializeW3CTextAnnotation,
936
+ Wt as splitAnnotatableRanges,
934
937
  ke as toDomRectList,
935
- re as toParentBounds,
938
+ se as toParentBounds,
936
939
  _e as toViewportBounds,
937
- le as trackViewport,
938
- Yt as trimRangeToContainer,
939
- ht as whitespaceOrEmptyRegex
940
+ ce as trackViewport,
941
+ $t as trimRangeToContainer,
942
+ pt as whitespaceOrEmptyRegex
940
943
  };
941
944
  //# sourceMappingURL=text-annotator.es.js.map