@recogito/text-annotator 3.3.3 → 3.4.1

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