@recogito/text-annotator 3.4.2 → 3.4.3

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