@recogito/text-annotator 3.3.3 → 3.4.0

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