@recogito/text-annotator 3.4.2 → 3.4.4

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";
6
- 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) => {
1
+ import { UAParser as bt } from "ua-parser-js";
2
+ import { OS as St } from "ua-parser-js/enums";
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";
11
+ import j from "hotkeys-js";
12
+ import { poll as Ht } from "poll";
13
+ const ut = "not-annotatable", W = `.${ut}`, Q = (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(W) : (r = e.parentElement) == null ? void 0 : r.closest(W)) : !0;
16
+ }, _t = (t, e) => {
17
17
  const n = e.commonAncestorContainer;
18
- return !q(t, n);
19
- }, Mt = (t) => t.addEventListener("click", (e) => {
18
+ return !Q(t, n);
19
+ }, Dt = (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(W) && !e.target.closest("a") && e.preventDefault();
22
+ }), et = (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
+ }), G = (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
+ }), Pt = bt(), ft = Pt.os.is(St.MACOS), Ut = (t) => {
65
65
  !t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
66
- }, _t = (t) => {
66
+ }, Kt = (t) => {
67
67
  const e = [], n = document.createNodeIterator(
68
68
  t.commonAncestorContainer,
69
69
  NodeFilter.SHOW_TEXT
@@ -74,322 +74,318 @@ 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
- const f = t.startContainer.childNodes[t.startOffset];
82
- f ? i.setStartBefore(f) : i.setStartAfter(t.startContainer);
81
+ const u = t.startContainer.childNodes[t.startOffset];
82
+ u ? i.setStartBefore(u) : i.setStartAfter(t.startContainer);
83
83
  }
84
84
  const c = document.createRange();
85
- if (c.selectNode(s), t.endContainer.nodeType === Node.TEXT_NODE)
86
- c.setEnd(s, t.endOffset);
85
+ if (c.selectNode(o), t.endContainer.nodeType === Node.TEXT_NODE)
86
+ c.setEnd(o, t.endOffset);
87
87
  else {
88
- const f = t.endContainer.childNodes[t.endOffset];
89
- f ? c.setEndBefore(f) : c.setEndAfter(t.endContainer);
88
+ const u = t.endContainer.childNodes[t.endOffset];
89
+ u ? c.setEndBefore(u) : c.setEndAfter(t.endContainer);
90
90
  }
91
- const d = (f) => {
92
- const p = document.createRange();
93
- return p.selectNode(f), Array.from(p.getClientRects());
91
+ const l = (u) => {
92
+ const h = document.createRange();
93
+ return h.selectNode(u), Array.from(h.getClientRects());
94
94
  };
95
95
  return [
96
96
  ...Array.from(i.getClientRects()),
97
- ...e.slice(1, -1).flatMap(d),
97
+ ...e.slice(1, -1).flatMap(l),
98
98
  ...Array.from(c.getClientRects())
99
99
  ];
100
100
  }
101
- }, Dt = function* (t) {
101
+ }, Wt = 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(ut) && !r.parentElement.closest(W) && 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
+ }, Ft = (t, e) => {
111
+ if (!_t(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 Wt(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
+ }, st = (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(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;
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), gt = /^\s*$/, Vt = (t) => gt.test(t.toString()), He = (t) => gt.test(t.textContent || ""), Yt = (t, e, n, r) => {
137
+ 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
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
+ }, 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);
162
+ return new DOMRect(n, s, r - n, o - s);
163
+ }, zt = (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;
166
+ let o = [...r], i = !1;
167
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;
168
+ const l = Yt(s, c, e, n);
169
+ if (l === "inline-adjacent") {
170
+ o = o.map((u) => u === c ? Xt(s, c) : u), 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((u) => u === c ? s : u), 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 < 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;
180
180
  break;
181
181
  }
182
182
  }
183
- return i ? s : [...s, o];
184
- }, []), ke = (t) => ({
183
+ return i ? o : [...o, s];
184
+ }, []), _e = (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
+ }), qt = (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) => {
212
- var p, u;
213
- const { start: n, end: r } = t, o = t.offsetReference || e, s = document.createNodeIterator(
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
214
  e,
215
215
  NodeFilter.SHOW_TEXT,
216
- (m) => {
217
- var l;
218
- return (l = m.parentElement) != null && l.closest(F) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
216
+ (g) => {
217
+ var v;
218
+ return (v = g.parentElement) != null && v.closest(W) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
219
219
  }
220
220
  );
221
221
  let i = 0;
222
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;
229
- if (i + m > n) {
230
- c.setStart(d, n - i);
223
+ let l = o.nextNode();
224
+ l === null && console.error("Could not revive annotation target. Content missing.");
225
+ let u = !s;
226
+ 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) {
230
+ c.setStart(l, n - i);
231
231
  break;
232
232
  }
233
- i += m;
233
+ i += g;
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;
239
- if (i + m >= r) {
240
- c.setEnd(d, r - i);
237
+ for (; l !== null; ) {
238
+ const g = ((f = l.textContent) == null ? void 0 : f.length) || 0;
239
+ if (i + g >= r) {
240
+ c.setEnd(l, r - i);
241
241
  break;
242
242
  }
243
- i += m, d = s.nextNode();
243
+ i += g, l = o.nextNode();
244
244
  }
245
245
  return {
246
246
  ...t,
247
247
  range: c
248
248
  };
249
- }, j = (t, e) => D(t.selector) ? t : {
249
+ }, Z = (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 : mt(n, e))
252
+ }, nt = (t, e) => H(t.target.selector) ? t : { ...t, target: Z(t.target, e) }, Qt = (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
+ }, pt = (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 : 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);
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;
269
+ return console.warn(`The annotation is missing in the store: ${s}`), !1;
270
270
  const { range: c } = i.target.selector[0];
271
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 = {
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;
275
+ }, _ = {
276
276
  fill: "rgb(0, 128, 255)",
277
277
  fillOpacity: 0.18
278
- }, G = {
278
+ }, J = {
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
+ }, 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) => {
289
285
  let e = /* @__PURE__ */ new Set();
290
286
  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);
287
+ 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);
293
289
  };
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));
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));
300
296
  };
301
- t.addEventListener("pointermove", u);
302
- const m = V((E = !1) => requestAnimationFrame(() => {
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;
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;
306
302
  return {
307
- annotation: M,
308
- rects: I,
309
- state: { selected: H, hovered: _ }
303
+ annotation: p,
304
+ rects: A,
305
+ state: { selected: B, hovered: U }
310
306
  };
311
307
  });
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);
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();
316
+ s.observe(R);
317
+ const S = o.subscribe(() => g()), w = i.subscribe(() => g()), N = () => g(!0);
322
318
  document.addEventListener("scroll", N, { capture: !0, passive: !0 });
323
- const C = V(() => {
324
- o.recalculatePositions(), f == null || f.reset(), m();
319
+ const E = Y(() => {
320
+ s.recalculatePositions(), u == null || u.reset(), g();
325
321
  }, 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);
322
+ window.addEventListener("resize", E);
323
+ 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);
331
327
  }, 150));
332
- return y.observe(document.body, g), {
328
+ return y.observe(document.body, a), {
333
329
  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();
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();
335
331
  },
336
- redraw: m,
337
- setStyle: R,
332
+ redraw: g,
333
+ setStyle: d,
338
334
  setFilter: L,
339
- setPainter: l,
335
+ setPainter: v,
340
336
  setVisible: r.setVisible
341
337
  };
342
- }, Zt = () => {
338
+ }, ee = () => {
343
339
  const t = document.createElement("canvas");
344
340
  return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
345
- }, Jt = (t, e) => {
341
+ }, ne = (t, e) => {
346
342
  t.width = window.innerWidth, t.height = window.innerHeight;
347
- }, te = (t) => {
348
- t.classList.add("r6o-annotatable");
349
- const e = Zt(), n = e.getContext("2d");
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");
350
346
  document.body.appendChild(e);
351
- const r = (c, d, f, p) => requestAnimationFrame(() => {
352
- const { width: u, height: m } = e;
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,
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();
354
+ }).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,
363
359
  width: y,
364
360
  height: b
365
361
  }));
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)
368
- ), A.underlineColor) {
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();
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();
373
369
  });
374
370
  }
375
371
  });
376
- }), o = V(() => Jt(e), 10);
377
- return window.addEventListener("resize", o), {
372
+ }), s = Y(() => ne(e), 10);
373
+ return window.addEventListener("resize", s), {
378
374
  destroy: () => {
379
- e.remove(), o.clear(), window.removeEventListener("resize", o);
375
+ e.remove(), s.clear(), window.removeEventListener("resize", s);
380
376
  },
381
377
  setVisible: (c) => {
382
378
  console.log("setVisible not implemented on Canvas renderer");
383
379
  },
384
380
  redraw: r
385
381
  };
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()}`,
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()}`,
388
384
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
389
385
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
390
386
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
391
387
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
392
- ].filter(Boolean).join(";"), oe = () => {
388
+ ].filter(Boolean).join(";"), ie = () => {
393
389
  const t = document.createElement("style");
394
390
  document.getElementsByTagName("head")[0].appendChild(t);
395
391
  let e = /* @__PURE__ */ new Set();
@@ -397,29 +393,33 @@ const ct = "not-annotatable", F = `.${ct}`, q = (t, e) => {
397
393
  destroy: () => {
398
394
  CSS.highlights.clear(), t.remove();
399
395
  },
400
- setVisible: (s) => {
396
+ setVisible: (o) => {
401
397
  console.log("setVisible not implemented on CSS Custom Highlights renderer");
402
398
  },
403
- redraw: (s, i, c, d) => {
404
- d && d.clear();
405
- const f = new Set(s.map((u) => u.annotation.id));
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)} }`;
399
+ redraw: (o, i, c, l) => {
400
+ 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)} }`;
411
407
  });
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);
416
- }), e = f;
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;
417
413
  }
418
414
  };
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) => {
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
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);
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);
440
- if (m) {
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);
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);
443
443
  }
444
444
  });
445
445
  }), n = i;
@@ -448,535 +448,543 @@ 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
+ }, 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) => {
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
464
  const c = {
465
- creator: Ct(n),
465
+ creator: wt(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) => {
475
- switch (m.type) {
473
+ for (const l of i) {
474
+ const h = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((f, g) => {
475
+ switch (g.type) {
476
476
  case "TextQuoteSelector":
477
- u.quote = m.exact;
477
+ f.quote = g.exact;
478
478
  break;
479
479
  case "TextPositionSelector":
480
- u.start = m.start, u.end = m.end;
480
+ f.start = g.start, f.end = g.end;
481
481
  break;
482
482
  }
483
- return u;
483
+ return f;
484
484
  }, {});
485
- if (le(p))
485
+ if (ge(h))
486
486
  c.selector.push(
487
487
  {
488
- ...p,
489
- id: d.id,
488
+ ...h,
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 {
495
- const u = [
496
- p.start ? void 0 : "TextPositionSelector",
497
- p.quote ? void 0 : "TextQuoteSelector"
495
+ const f = [
496
+ h.start ? void 0 : "TextPositionSelector",
497
+ h.quote ? void 0 : "TextQuoteSelector"
498
498
  ].filter(Boolean);
499
- return { error: Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`) };
499
+ return { error: Error(`Missing selector types: ${f.join(" and ")} for annotation: ${t.id}`) };
500
500
  }
501
501
  }
502
502
  return { parsed: c };
503
- }, fe = (t) => {
504
- const e = t.id || at(), {
503
+ }, pe = (t) => {
504
+ const e = t.id || dt(), {
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, c = At(o, e), l = me(t);
511
+ return "error" in l ? { error: l.error } : {
512
512
  parsed: {
513
513
  ...i,
514
514
  id: e,
515
515
  bodies: c,
516
- target: d.parsed
516
+ target: l.parsed
517
517
  }
518
518
  };
519
- }, ue = (t, e, n) => {
520
- const { bodies: r, target: o, ...s } = t, {
519
+ }, he = (t, e, n) => {
520
+ const { bodies: r, target: s, ...o } = t, {
521
521
  selector: i,
522
522
  creator: c,
523
- created: d,
524
- updated: f,
525
- ...p
526
- } = o, u = i.map((m) => {
527
- const { id: l, quote: R, start: L, end: S, range: v } = m, A = {
523
+ 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 = {
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: m } = $t(S, n);
533
+ w.prefix = E, w.suffix = m;
534
534
  }
535
535
  const N = {
536
536
  type: "TextPositionSelector",
537
537
  start: L,
538
- end: S
538
+ end: R
539
539
  };
540
540
  return {
541
- ...p,
542
- id: l,
541
+ ...h,
542
+ id: v,
543
543
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
544
- scope: "scope" in m ? m.scope : void 0,
544
+ scope: "scope" in g ? g.scope : void 0,
545
545
  source: e,
546
- selector: [A, N]
546
+ selector: [w, N]
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),
554
+ body: Et(t.bodies),
555
555
  creator: c,
556
- created: d == null ? void 0 : d.toISOString(),
557
- modified: f == null ? void 0 : f.toISOString(),
558
- target: u
556
+ created: l == null ? void 0 : l.toISOString(),
557
+ modified: u == null ? void 0 : u.toISOString(),
558
+ target: f
559
+ };
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");
567
+ 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));
571
+ }), {
572
+ clear: () => {
573
+ const { width: h, height: f } = n;
574
+ r.clearRect(-0.5, -0.5, h + 1, f + 1);
575
+ },
576
+ destroy: () => {
577
+ n.remove();
578
+ },
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
589
+ };
590
+ }
591
+ },
592
+ reset: () => {
593
+ 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);
596
+ }
559
597
  };
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;
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;
568
606
  return {
569
607
  minX: T,
570
608
  minY: x,
571
609
  maxX: T + O,
572
- maxY: x + K,
610
+ maxY: x + P,
573
611
  annotation: {
574
- id: a.annotation,
612
+ id: m.annotation,
575
613
  rects: b
576
614
  }
577
615
  };
578
616
  });
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) => {
590
- g && f();
591
- const y = e.getBoundingClientRect(), b = a.map((T) => ({ target: T, rects: c(T, y) }));
617
+ }, l = () => [...o.values()], u = () => {
618
+ 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) => {
623
+ 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) }));
592
630
  b.forEach(({ target: T, rects: x }) => {
593
- x.length > 0 && s.set(T.annotation, x);
631
+ x.length > 0 && o.set(T.annotation, x);
594
632
  });
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,
600
- minY: g,
601
- maxX: a,
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);
607
- if (g.length === 0)
633
+ const C = b.flatMap(({ rects: T }) => T);
634
+ s.load(C);
635
+ }, d = (m, a, y = !1) => {
636
+ const b = s.search({
637
+ minX: m,
638
+ minY: a,
639
+ maxX: m,
640
+ 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) => {
644
+ const a = R(m);
645
+ if (a.length === 0)
608
646
  return;
609
- let y = g[0].left, b = g[0].top, E = g[0].right, T = g[0].bottom;
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);
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);
613
651
  }
614
- return new DOMRect(y, b, E - y, T - b);
615
- }, S = (a) => {
616
- const g = s.get(a);
617
- return g ? g[0].annotation.rects : [];
652
+ return new DOMRect(y, b, C - y, T - b);
653
+ }, R = (m) => {
654
+ const a = o.get(m);
655
+ return a ? a[0].annotation.rects : [];
618
656
  };
619
657
  return {
620
- all: d,
621
- clear: f,
622
- getAt: R,
658
+ all: l,
659
+ clear: u,
660
+ getAt: d,
623
661
  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));
662
+ 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));
627
665
  return Array.from(T).map((x) => ({
628
666
  annotation: t.getAnnotation(x),
629
- rects: S(x)
667
+ rects: R(x)
630
668
  })).filter((x) => !!x.annotation);
631
669
  },
632
- insert: p,
670
+ insert: h,
633
671
  recalculate: () => {
634
- l(t.all().map((a) => a.target), !0), i.emit("recalculate");
672
+ v(t.all().map((m) => m.target), !0), i.emit("recalculate");
635
673
  },
636
- remove: u,
637
- set: l,
638
- size: () => o.all().length,
639
- update: m,
640
- on: (a, g) => i.on(a, g)
674
+ remove: f,
675
+ set: v,
676
+ size: () => s.all().length,
677
+ update: g,
678
+ on: (m, a) => i.on(m, a)
641
679
  };
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);
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);
654
692
  }), 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);
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);
661
699
  };
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;
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;
664
702
  if (T.length !== 0)
665
- return g ? T : T[0];
703
+ return a ? T : T[0];
666
704
  }
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));
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));
671
709
  }), {
672
710
  store: {
673
711
  ...n,
674
712
  addAnnotation: c,
675
- bulkAddAnnotations: d,
676
- bulkUpdateTargets: u,
677
- bulkUpsertAnnotations: f,
678
- getAnnotationBounds: l,
713
+ bulkAddAnnotations: l,
714
+ bulkUpdateTargets: f,
715
+ bulkUpsertAnnotations: u,
716
+ getAnnotationBounds: v,
679
717
  getAnnotationRects: L,
680
- getIntersecting: R,
681
- getAt: m,
682
- recalculatePositions: S,
683
- onRecalculatePositions: v,
684
- updateTarget: p
718
+ getIntersecting: d,
719
+ getAt: g,
720
+ recalculatePositions: R,
721
+ onRecalculatePositions: S,
722
+ updateTarget: h
685
723
  },
686
- selection: o,
687
- hover: s,
724
+ selection: s,
725
+ hover: o,
688
726
  viewport: i
689
727
  };
690
- }, pe = () => {
691
- const t = document.createElement("canvas");
692
- t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
693
- const e = t.getContext("2d");
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");
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);
699
- return t.on("selectionChange", (p, u) => {
700
- s(p).forEach((l) => o.delete(l)), u && u.forEach((l) => o.set(l, p));
701
- }), {
702
- clear: () => {
703
- const { width: p, height: u } = n;
704
- r.clearRect(-0.5, -0.5, p + 1, u + 1);
705
- },
706
- destroy: () => {
707
- n.remove();
708
- },
709
- paint: (p, u, m) => {
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,
718
- fillOpacity: m ? 0.45 : 0.18
719
- };
720
- }
721
- },
722
- reset: () => {
723
- n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
724
- const p = n.getContext("2d");
725
- p.scale(2, 2), p.translate(0.5, 0.5);
726
- }
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
+ }, 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;
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);
735
+ annotatingEnabled: c,
736
+ offsetReferenceSelector: l,
737
+ selectionMode: u,
738
+ dismissOnNotAnnotatable: h = "NEVER"
739
+ } = 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")
745
+ return !0;
746
+ if (r.allowModifierSelect) {
747
+ const A = p;
748
+ return ft ? A.metaKey : A.ctrlKey;
749
+ } else
750
+ 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);
753
756
  if (B != null && B.target) {
754
- R = B.target, l = {
757
+ L = B.target, d = {
755
758
  annotation: B.id,
756
759
  selector: [],
757
- created: R.created,
758
- creator: R.creator,
760
+ created: L.created,
761
+ creator: L.creator,
759
762
  updated: /* @__PURE__ */ new Date(),
760
- updatedBy: s
763
+ updatedBy: i
761
764
  };
762
765
  return;
763
766
  }
764
767
  }
765
- R = void 0, l = {
766
- annotation: at(),
768
+ L = void 0, d = {
769
+ annotation: dt(),
767
770
  selector: [],
768
771
  created: /* @__PURE__ */ new Date(),
769
- creator: s
772
+ creator: i
770
773
  };
771
- }, a = V((h) => {
772
- if (!v) return;
773
- const w = document.getSelection();
774
- if (!(w != null && w.anchorNode))
774
+ }, b = Y((p) => {
775
+ if (!g) return;
776
+ const A = document.getSelection();
777
+ if (!(A != null && A.anchorNode))
775
778
  return;
776
- const B = Array.from(Array(w.rangeCount).keys()).map((k) => w.getRangeAt(k));
779
+ const B = Array.from(Array(A.rangeCount).keys()).map((k) => A.getRangeAt(k));
777
780
  if (!B.some((k) => k.intersectsNode(t))) {
778
- l = void 0;
781
+ d = void 0;
779
782
  return;
780
783
  }
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));
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));
784
787
  return;
785
788
  }
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);
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);
792
795
  }))) 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)),
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)),
800
803
  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();
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) => {
808
+ 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();
810
813
  return;
811
814
  }
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
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
817
820
  );
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);
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));
821
824
  } else
822
825
  o.clear();
823
826
  };
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();
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();
829
832
  return;
830
833
  }
831
834
  }
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) => {
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) => {
844
- const w = () => setTimeout(() => {
845
- (l == null ? void 0 : l.selector.length) > 0 && (o.clear(), r.addAnnotation({
846
- id: l.annotation,
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,
847
850
  bodies: [],
848
- target: l
849
- }), o.userSelect(l.annotation, z(h))), document.removeEventListener("selectionchange", w);
851
+ target: d
852
+ }), o.userSelect(d.annotation, G(p))), document.removeEventListener("selectionchange", A);
850
853
  }, 100);
851
- document.addEventListener("selectionchange", w), C();
854
+ document.addEventListener("selectionchange", A), y();
852
855
  };
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);
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);
857
860
  });
858
- const O = (h) => {
859
- h.repeat || h.target !== t && h.target !== document.body || (l = void 0, o.clear());
861
+ const z = (p) => {
862
+ p.repeat || p.target !== t && p.target !== document.body || (d = void 0, o.clear());
860
863
  };
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,
864
+ j(ht.join(","), { keydown: !0, keyup: !1 }, z);
865
+ const F = () => {
866
+ const p = s.getAnnotation(d.annotation);
867
+ if (!p) {
868
+ s.addAnnotation({
869
+ id: d.annotation,
867
870
  bodies: [],
868
- target: l
871
+ target: d
869
872
  });
870
873
  return;
871
874
  }
872
- const { target: { updated: w } } = h, { updated: B } = l;
873
- (!w || !B || w < B) && r.updateTarget(l);
875
+ const { target: { updated: A } } = p, { updated: B } = d;
876
+ (!A || !B || A < B) && s.updateTarget(d);
874
877
  };
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), {
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), {
876
879
  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();
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();
878
881
  },
879
- setFilter: m,
880
- setUser: p,
881
- setAnnotatingEnabled: A
882
+ setFilter: E,
883
+ setUser: m,
884
+ setAnnotatingEnabled: w,
885
+ setAnnotatingMode: N
882
886
  };
883
- }, Se = (t, e) => ({
887
+ }, we = (t, e) => ({
884
888
  ...t,
885
889
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
886
890
  user: t.user || e.user
887
- }), it = "SPANS", He = (t, e = {}) => {
888
- Mt(t), Ht(t);
889
- const n = Se(e, {
891
+ }), lt = "SPANS", Ue = (t, e = {}) => {
892
+ Dt(t), Ut(t);
893
+ const n = we(e, {
890
894
  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);
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;
895
- if (!u)
896
- throw `Unknown renderer implementation: ${p}`;
897
- console.debug(`Using ${p} renderer`), n.style && u.setStyle(n.style);
898
- const m = be(t, r, n);
899
- m.setUser(f);
900
- const l = Lt(r, c, n.adapter), R = () => f, L = (a) => {
901
- m.setAnnotatingEnabled(
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)
900
+ 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(
902
906
  a === void 0 ? !0 : a
903
907
  );
908
+ }, R = (a) => {
909
+ g.setAnnotatingMode(a);
904
910
  }, 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()));
911
+ f.setFilter(a), g.setFilter(a);
912
+ }, w = (a) => {
913
+ u = a, g.setUser(a);
910
914
  }, N = (a) => {
911
- a ? o.setSelected(a) : o.clear();
915
+ a && (f.setPainter(be(a, n.presence)), a.on("selectionChange", () => f.redraw()));
916
+ }, E = (a) => {
917
+ a ? s.setSelected(a) : s.clear();
912
918
  };
913
919
  return {
914
- ...l,
920
+ ...v,
915
921
  destroy: () => {
916
- u.destroy(), m.destroy(), c.destroy();
922
+ f.destroy(), g.destroy(), c.destroy();
917
923
  },
918
924
  element: t,
919
- getUser: R,
925
+ getUser: d,
920
926
  setAnnotatingEnabled: L,
927
+ setAnnotatingMode: R,
921
928
  setFilter: S,
922
- setStyle: u.setStyle.bind(u),
923
- redraw: u.redraw.bind(u),
924
- setUser: v,
925
- setSelected: N,
926
- setPresenceProvider: A,
927
- setVisible: u.setVisible.bind(u),
928
- on: d.on,
929
- off: d.off,
930
- scrollIntoView: qt(t, i),
929
+ setStyle: f.setStyle.bind(f),
930
+ redraw: f.redraw.bind(f),
931
+ setUser: w,
932
+ setSelected: E,
933
+ setPresenceProvider: N,
934
+ setVisible: f.setVisible.bind(f),
935
+ on: l.on,
936
+ off: l.off,
937
+ scrollIntoView: Zt(t, i),
931
938
  state: r
932
939
  };
933
940
  };
934
941
  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
942
+ J as DEFAULT_SELECTED_STYLE,
943
+ _ as DEFAULT_STYLE,
944
+ ut as NOT_ANNOTATABLE_CLASS,
945
+ W as NOT_ANNOTATABLE_SELECTOR,
946
+ Fe as Origin,
947
+ $e as UserSelectAction,
948
+ Pe as W3CTextFormat,
949
+ Dt as cancelSingleClickEvents,
950
+ 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,
968
+ 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,
980
+ 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
981
989
  };
982
990
  //# sourceMappingURL=text-annotator.es.js.map