@recogito/text-annotator 3.1.5 → 3.2.0

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