@recogito/text-annotator 3.4.5 → 3.4.6

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