@recogito/text-annotator 3.1.6 → 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,20 +1,22 @@
1
- import { colord as tt } from "colord";
2
- import { dequal as at } from "dequal/lite";
3
- import { v4 as et } 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 U, 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";
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";
7
9
  import V from "hotkeys-js";
8
- import { poll as Ct } from "poll";
9
- const nt = "not-annotatable", $ = `.${nt}`, F = (t, n) => {
10
- var o;
11
- return t.contains(n) ? !!(n instanceof HTMLElement ? n.closest($) : (o = n.parentElement) == null ? void 0 : o.closest($)) : !0;
12
- }, wt = (t, n) => {
13
- const e = n.commonAncestorContainer;
14
- return !F(t, e);
15
- }, Et = (t) => t.addEventListener("click", (n) => {
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($) && !n.target.closest("a") && n.preventDefault();
19
+ !e.target.closest($) && !e.target.closest("a") && e.preventDefault();
18
20
  }), q = (t) => ({
19
21
  ...t,
20
22
  type: t.type,
@@ -57,831 +59,860 @@ const nt = "not-annotatable", $ = `.${nt}`, 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
- }, Y = (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(nt) && !o.parentElement.closest($) && 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];
112
+ return n.length > 0 ? n : [e];
90
113
  }, G = (t) => {
91
- const n = t.cloneContents();
92
- return n.querySelectorAll($).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 c = G(r).textContent, f = document.createRange();
97
- f.setStart(t.endContainer, t.endOffset), s === document.body ? f.setEnd(s, s.childNodes.length) : f.setEndAfter(s);
98
- const p = G(f).textContent;
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: c.substring(c.length - e),
101
- suffix: p.substring(0, e)
123
+ prefix: i.substring(i.length - n),
124
+ suffix: d.substring(0, n)
102
125
  };
103
- }, B = (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
- }, Nt = (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 c = Ot(e, r);
136
- if (c === "inline-adjacent") {
137
- o = o.map((f) => f === r ? It(e, r) : f), 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 (c === "inline-contains") {
140
- o = o.map((f) => f === r ? e : f), 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 (c === "inline-is-contained") {
143
- s = !0;
165
+ } else if (d === "inline-is-contained") {
166
+ i = !0;
144
167
  break;
145
- } else if (c === "block-contains" || c === "block-is-contained") {
146
- e.width < r.width && (o = o.map((f) => f === r ? e : f)), 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
- }), Bt = (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 = G(o).textContent, c = t.toString(), f = r.length || 0, p = f + c.length;
162
- return e ? { quote: c, start: f, end: p, range: t, offsetReference: s } : { quote: c, start: f, end: p, range: t };
163
- }, ot = (t, n) => {
164
- var S, 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
- (l) => {
169
- var u;
170
- return (u = l.parentElement) != null && u.closest($) ? 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 c = 0;
174
- const f = document.createRange();
175
- let p = r.nextNode();
176
- p === null && console.error("Could not revive annotation target. Content missing.");
177
- let C = !s;
178
- for (; p !== null; ) {
179
- if (C || (C = typeof (s == null ? void 0 : s.contains) == "function" ? s.contains(p) : !1), C) {
180
- const l = ((S = p.textContent) == null ? void 0 : S.length) || 0;
181
- if (c + l > e) {
182
- f.setStart(p, e - c);
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
- c += l;
208
+ i += c;
186
209
  }
187
- p = r.nextNode();
210
+ d = o.nextNode();
188
211
  }
189
- for (; p !== null; ) {
190
- const l = ((d = p.textContent) == null ? void 0 : d.length) || 0;
191
- if (c + l >= o) {
192
- f.setEnd(p, o - c);
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
- c += l, p = r.nextNode();
218
+ i += c, d = o.nextNode();
196
219
  }
197
220
  return {
198
221
  ...t,
199
- range: f
222
+ range: a
200
223
  };
201
- }, X = (t, n) => B(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 : ot(e, n))
204
- }, j = (t, n) => B(t.target.selector) ? t : { ...t, target: X(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
- }, st = (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 : st(t.parentElement);
212
- }, Mt = (t, n) => (e) => {
213
- const o = typeof e == "string" ? e : e.id, s = (S) => {
214
- const d = r.getBoundingClientRect(), l = r.clientHeight, u = r.clientWidth, v = S.selector[0].range.getBoundingClientRect(), { width: E, height: A } = n.getAnnotationBounds(o), i = v.top - d.top, a = v.left - d.left, y = r.parentElement ? r.scrollTop : 0, b = r.parentElement ? r.scrollLeft : 0, m = i + y - (l - A) / 2, g = a + b - (u - E) / 2;
215
- r.scroll({ top: m, left: g, behavior: "smooth" });
216
- }, r = st(t);
217
- if (!r)
218
- return console.warn(`The scroll parent is missing for the annotation: ${o}`, { container: t }), !1;
219
- const c = n.getAnnotation(o);
220
- if (!c)
221
- return console.warn(`The annotation is missing in the store: ${o}`), !1;
222
- const { range: f } = c.target.selector[0];
223
- if (f && !f.collapsed)
224
- return s(c.target), !0;
225
- const p = X(c.target, t), { range: C } = p.selector[0];
226
- return C && !C.collapsed ? (s(p), !0) : !1;
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;
227
250
  }, P = {
228
251
  fill: "rgb(0, 128, 255)",
229
252
  fillOpacity: 0.18
230
253
  }, z = {
231
254
  fill: "rgb(0, 128, 255)",
232
255
  fillOpacity: 0.45
233
- }, Ht = (t, n, e, o, s) => {
234
- var c, f;
235
- const r = e ? typeof e == "function" ? e(t.annotation, t.state, s) || ((c = t.state) != null && c.selected ? z : P) : e : (f = t.state) != null && f.selected ? z : P;
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, c = -n, f = o - e, p = s - n;
239
- return { top: n, left: e, minX: r, minY: c, maxX: f, maxY: p };
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);
245
- };
246
- }, Q = (t, n, e, o) => {
247
- const { store: s, selection: r, hover: c } = n;
248
- let f, p, C;
249
- const S = Ut(e), d = (L) => {
250
- const { x: K, y: h } = t.getBoundingClientRect(), x = s.getAt(L.clientX - K, L.clientY - h, !1, p);
251
- x ? c.current !== x.id && (t.classList.add("hovered"), c.set(x.id)) : c.current && (t.classList.remove("hovered"), c.set(null));
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);
252
268
  };
253
- t.addEventListener("pointermove", d);
254
- const l = (L = !1) => {
255
- C && C.clear();
256
- const K = Kt(t), { minX: h, minY: x, maxX: k, maxY: O } = K, N = p ? s.getIntersecting(h, x, k, O).filter(({ annotation: T }) => p(T)) : s.getIntersecting(h, x, k, O), I = r.selected.map(({ id: T }) => T), _ = N.map(({ annotation: T, rects: M }) => {
257
- const D = I.includes(T.id), H = T.id === c.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: T,
260
- rects: M,
261
- state: { selected: D, hovered: H }
282
+ annotation: L,
283
+ rects: _,
284
+ state: { selected: M, hovered: Z }
262
285
  };
263
286
  });
264
- o.redraw(_, K, f, C, L), setTimeout(() => S(N.map(({ annotation: T }) => T)), 1);
265
- }, u = (L) => {
266
- C = L, l();
267
- }, v = (L) => {
268
- f = L, l();
269
- }, E = (L) => {
270
- p = L, l(!1);
271
- }, A = () => l();
272
- s.observe(A);
273
- const i = r.subscribe(() => l()), a = c.subscribe(() => l()), y = () => l(!0);
274
- document.addEventListener("scroll", y, { capture: !0, passive: !0 });
275
- const b = Y(() => {
276
- s.recalculatePositions(), C && C.reset(), l();
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();
295
+ s.observe(x);
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", b);
279
- const m = new ResizeObserver(b);
280
- m.observe(t);
281
- const g = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver(Y((L) => {
282
- L.every((h) => h.target === t || t.contains(h.target)) || l(!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, g), {
307
+ return h.observe(document.body, l), {
285
308
  destroy: () => {
286
- t.removeEventListener("pointermove", d), o.destroy(), s.unobserve(A), i(), a(), document.removeEventListener("scroll", y), window.removeEventListener("resize", b), 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: l,
289
- setStyle: v,
290
- setFilter: E,
291
- setPainter: u,
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
- }, Dt = (t, n) => {
320
+ }, Yt = (t, e) => {
298
321
  t.width = window.innerWidth, t.height = window.innerHeight;
299
- }, Ft = (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 = (f, p, C, S) => requestAnimationFrame(() => {
304
- const { width: d, height: l } = n;
305
- e.clearRect(-0.5, -0.5, d + 1, l + 1), S && S.clear();
306
- const { top: u, left: v } = p;
307
- [...f].sort((A, i) => {
308
- const { annotation: { target: { created: a } } } = A, { annotation: { target: { created: y } } } = i;
309
- return a.getTime() - y.getTime();
310
- }).forEach((A) => {
311
- var b;
312
- const i = C ? typeof C == "function" ? C(A.annotation, A.state) : C : (b = A.state) != null && b.selected ? z : P, a = S && S.paint(A, p) || i, y = A.rects.map(({ x: m, y: g, width: w, height: R }) => ({
313
- x: m + v,
314
- y: g + u,
315
- width: w,
316
- height: R
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();
333
+ }).forEach((x) => {
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 = a.fill, e.globalAlpha = a.fillOpacity || 1, y.forEach(
319
- ({ x: m, y: g, width: w, height: R }) => e.fillRect(m, g, w, R)
320
- ), a.underlineColor) {
321
- e.globalAlpha = 1, e.strokeStyle = a.underlineColor, e.lineWidth = a.underlineThickness ?? 1;
322
- const m = a.underlineOffset ?? 0;
323
- y.forEach(({ x: g, y: w, width: R, height: L }) => {
324
- e.beginPath(), e.moveTo(g, w + L + m), e.lineTo(g + R, w + L + 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 = Y(() => {
329
- Dt(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: (f) => {
358
+ setVisible: (a) => {
336
359
  console.log("setVisible not implemented on Canvas renderer");
337
360
  },
338
- redraw: o
361
+ redraw: r
339
362
  };
340
- }, _t = (t, n, e) => Q(t, n, e, Ft(t)), Vt = (t) => [
341
- `background-color:${tt((t == null ? void 0 : t.fill) || P.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? P.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, c, f, p) => {
358
- p && p.clear();
359
- const C = new Set(r.map((d) => d.annotation.id));
360
- Array.from(n).filter((d) => !C.has(d));
361
- const S = r.map((d) => {
362
- var v;
363
- const l = f ? typeof f == "function" ? f(d.annotation, d.state) : f : (v = d.state) != null && v.selected ? z : P, u = p && p.paint(d, c) || l;
364
- return `::highlight(_${d.annotation.id}) { ${Vt(u)} }`;
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 = S.join(`
367
- `), CSS.highlights.clear(), r.forEach(({ annotation: d }) => {
368
- const l = d.target.selector.map((v) => v.range), u = new Highlight(...l);
369
- CSS.highlights.set(`_${d.id}`, u);
370
- }), n = C;
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) => Q(t, n, e, Wt()), Xt = (t, n) => {
374
- const e = (r, c) => r.x <= c.x + c.width && r.x + r.width >= c.x && r.y <= c.y + c.height && r.y + r.height >= c.y, o = (r) => r.rects.reduce((c, f) => c + f.width, 0), s = n.filter(({ rects: r }) => r.some((c) => e(t, c)));
375
- return s.sort((r, c) => o(c) - 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: (c, f, p, C, S) => {
386
- const l = !(at(e, c) && S);
387
- if (!C && !l) return;
388
- l && (n.innerHTML = ""), [...c].sort((v, E) => {
389
- const { annotation: { target: { created: A } } } = v, { annotation: { target: { created: i } } } = E;
390
- return A && i ? A.getTime() - i.getTime() : 0;
391
- }).forEach((v) => {
392
- v.rects.map((E) => {
393
- const A = Xt(E, c), i = Ht(v, f, p, C, A);
394
- if (l) {
395
- const a = document.createElement("span");
396
- a.className = "r6o-annotation", a.dataset.annotation = v.annotation.id, a.style.left = `${E.x}px`, a.style.top = `${E.y}px`, a.style.width = `${E.width}px`, a.style.height = `${E.height}px`, a.style.backgroundColor = tt((i == null ? void 0 : i.fill) || P.fill).alpha((i == null ? void 0 : i.fillOpacity) === void 0 ? P.fillOpacity : i.fillOpacity).toHex(), i.underlineStyle && (a.style.borderStyle = i.underlineStyle), i.underlineColor && (a.style.borderColor = i.underlineColor), i.underlineThickness && (a.style.borderBottomWidth = `${i.underlineThickness}px`), i.underlineOffset && (a.style.paddingBottom = `${i.underlineOffset}px`), n.appendChild(a);
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 = c;
422
+ }), n = i;
400
423
  },
401
- setVisible: (c) => {
402
- c ? 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) => Q(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, c = Array.isArray(r) ? r : [r];
416
- if (c.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 f = {
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 c[0] ? c[0].styleClass : void 0
448
+ styleClass: "styleClass" in i[0] ? i[0].styleClass : void 0
426
449
  };
427
- for (const p of c) {
428
- const S = (Array.isArray(p.selector) ? p.selector : [p.selector]).reduce((d, l) => {
429
- switch (l.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 = l.exact;
454
+ f.quote = c.exact;
432
455
  break;
433
456
  case "TextPositionSelector":
434
- d.start = l.start, d.end = l.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(S))
440
- f.selector.push(
462
+ if (te(b))
463
+ a.selector.push(
441
464
  {
442
- ...S,
443
- id: p.id,
465
+ ...b,
466
+ id: d.id,
444
467
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
445
- scope: p.scope
468
+ scope: d.scope
446
469
  }
447
470
  );
448
471
  else {
449
- const d = [
450
- S.start ? void 0 : "TextPositionSelector",
451
- S.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: f };
457
- }, Qt = (t) => {
458
- const n = t.id || et(), {
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
- ...c
464
- } = t, f = lt(r, n), p = Gt(t);
465
- return "error" in p ? { error: p.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
- ...c,
468
- id: n,
469
- bodies: f,
470
- target: p.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: c,
476
- creator: f,
477
- created: p,
478
- updated: C,
479
- ...S
480
- } = s, d = c.map((l) => {
481
- const { id: u, quote: v, start: E, end: A, range: i } = l, a = {
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: v
506
+ exact: R
484
507
  };
485
- if (e) {
486
- const { prefix: b, suffix: m } = Rt(i, e);
487
- a.prefix = b, a.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 y = {
512
+ const u = {
490
513
  type: "TextPositionSelector",
491
- start: E,
492
- end: A
514
+ start: A,
515
+ end: x
493
516
  };
494
517
  return {
495
- ...S,
496
- id: u,
518
+ ...b,
519
+ id: g,
497
520
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
498
- scope: "scope" in l ? l.scope : void 0,
499
- source: n,
500
- selector: [a, y]
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: f,
510
- created: p == null ? void 0 : p.toISOString(),
511
- modified: C == null ? void 0 : C.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 = (i, a) => {
516
- const y = i.selector.flatMap((m) => {
517
- const g = B([m]) ? m.range : ot(m, n).range;
518
- return Array.from(g.getClientRects());
519
- }), b = Nt(y).map(({ left: m, top: g, right: w, bottom: R }) => new DOMRect(m - a.left, g - a.top, w - m, R - g));
520
- return b.map((m) => {
521
- const { x: g, y: w, width: R, height: L } = 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: g,
524
- minY: w,
525
- maxX: g + R,
526
- maxY: w + L,
546
+ minX: w,
547
+ minY: C,
548
+ maxX: w + N,
549
+ maxY: C + S,
527
550
  annotation: {
528
- id: i.annotation,
529
- rects: b
551
+ id: u.annotation,
552
+ rects: l
530
553
  }
531
554
  };
532
555
  });
533
- }, r = () => [...o.values()], c = () => {
534
- e.clear(), o.clear();
535
- }, f = (i) => {
536
- const a = s(i, n.getBoundingClientRect());
537
- a.length !== 0 && (a.forEach((y) => e.insert(y)), o.set(i.annotation, a));
538
- }, p = (i) => {
539
- const a = o.get(i.annotation);
540
- a && (a.forEach((y) => e.remove(y)), o.delete(i.annotation));
541
- }, C = (i) => {
542
- p(i), f(i);
543
- }, S = (i, a = !0) => {
544
- a && c();
545
- const y = n.getBoundingClientRect(), b = i.map((g) => ({ target: g, rects: s(g, y) }));
546
- b.forEach(({ target: g, rects: w }) => {
547
- w.length > 0 && o.set(g.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 = b.flatMap(({ rects: g }) => g);
550
- e.load(m);
551
- }, d = (i, a, y = !1) => {
552
- const b = e.search({
553
- minX: i,
554
- minY: a,
555
- maxX: i,
556
- maxY: a
557
- }), m = (g) => g.annotation.rects.reduce((w, R) => w + R.width * R.height, 0);
558
- return b.length > 0 ? (b.sort((g, w) => m(g) - m(w)), y ? b.map((g) => g.annotation.id) : [b[0].annotation.id]) : [];
559
- }, l = (i) => {
560
- const a = u(i);
561
- if (a.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 y = a[0].left, b = a[0].top, m = a[0].right, g = a[0].bottom;
564
- for (let w = 1; w < a.length; w++) {
565
- const R = a[w];
566
- y = Math.min(y, R.left), b = Math.min(b, R.top), m = Math.max(m, R.right), g = Math.max(g, R.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(y, b, m - y, g - b);
569
- }, u = (i) => {
570
- const a = o.get(i);
571
- return a ? a[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: c,
576
- getAt: d,
577
- getAnnotationBounds: l,
578
- getAnnotationRects: u,
579
- getIntersecting: (i, a, y, b) => {
580
- const m = e.search({ minX: i, minY: a, maxX: y, maxY: b }), g = new Set(m.map((w) => w.annotation.id));
581
- return Array.from(g).map((w) => ({
582
- annotation: t.getAnnotation(w),
583
- rects: u(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: f,
587
- recalculate: () => S(t.all().map((i) => i.target), !0),
588
- remove: p,
589
- set: S,
590
- size: () => e.all().length,
591
- update: C
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), c = mt(), f = (i, a = U.LOCAL) => {
595
- const y = j(i, t), b = B(y.target.selector);
596
- return b && e.addAnnotation(y, a), b;
597
- }, p = (i, a = !0, y = U.LOCAL) => {
598
- const b = i.map((g) => j(g, t)), m = b.filter((g) => !B(g.target.selector));
599
- return e.bulkAddAnnotations(b, a, y), m;
600
- }, C = (i, a = U.LOCAL) => {
601
- const y = i.map((m) => j(m, t)), b = y.filter((m) => !B(m.target.selector));
602
- return y.forEach((m) => {
603
- e.getAnnotation(m.id) ? e.updateAnnotation(m, a) : e.addAnnotation(m, a);
604
- }), b;
605
- }, S = (i, a = U.LOCAL) => {
606
- const y = X(i, t);
607
- e.updateTarget(y, a);
608
- }, d = (i, a = U.LOCAL) => {
609
- const y = i.map((b) => X(b, t));
610
- e.bulkUpdateTargets(y, a);
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 l(i, a, y, b) {
613
- const m = y || !!b, g = o.getAt(i, a, m).map((R) => e.getAnnotation(R)), w = b ? g.filter(b) : g;
614
- if (w.length !== 0)
615
- return y ? 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 u = (i) => {
618
- if (o.getAnnotationRects(i).length !== 0)
619
- return o.getAnnotationBounds(i);
620
- }, v = (i, a, y, b) => o.getIntersecting(i, a, y, b), E = (i) => o.getAnnotationRects(i), A = () => o.recalculate();
621
- return e.observe(({ changes: i }) => {
622
- const a = (i.deleted || []).filter((m) => B(m.target.selector)), y = (i.created || []).filter((m) => B(m.target.selector)), b = (i.updated || []).filter((m) => B(m.newValue.target.selector));
623
- (a == null ? void 0 : a.length) > 0 && a.forEach((m) => o.remove(m.target)), y.length > 0 && o.set(y.map((m) => m.target), !1), (b == null ? void 0 : b.length) > 0 && b.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: f,
628
- bulkAddAnnotations: p,
629
- bulkUpdateTargets: d,
630
- bulkUpsertAnnotations: C,
631
- getAnnotationBounds: u,
632
- getAnnotationRects: E,
633
- getIntersecting: v,
634
- getAt: l,
635
- recalculatePositions: A,
636
- updateTarget: S
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,
659
+ recalculatePositions: x,
660
+ updateTarget: b
637
661
  },
638
662
  selection: s,
639
- hover: r,
640
- viewport: c
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 = (S) => Array.from(s.entries()).filter(([d, l]) => l.presenceKey === S.presenceKey).map(([d, l]) => d);
651
- return t.on("selectionChange", (S, d) => {
652
- r(S).forEach((u) => s.delete(u)), d && d.forEach((u) => s.set(u, S));
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: S, height: d } = e;
656
- o.clearRect(-0.5, -0.5, S + 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: (S, d, l) => {
662
- n.font && (o.font = n.font);
663
- const u = s.get(S.annotation.id);
664
- if (u) {
665
- const { height: v } = S.rects[0], E = S.rects[0].x + d.left, A = S.rects[0].y + d.top;
666
- o.fillStyle = u.appearance.color, o.fillRect(E - 2, A - 2.5, 2, v + 5);
667
- const i = o.measureText(u.appearance.label), a = i.width + 6, y = i.actualBoundingBoxAscent + i.actualBoundingBoxDescent + 8, b = i.fontBoundingBoxAscent ? 8 : 6.5;
668
- return o.fillRect(E - 2, A - 2.5 - y, a, y), o.fillStyle = "#fff", o.fillText(u.appearance.label, E + 1, A - b), {
669
- fill: u.appearance.color,
670
- fillOpacity: l ? 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 S = e.getContext("2d");
677
- S.scale(2, 2), S.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
- }, Z = 300, rt = ["up", "down", "left", "right"], it = At ? "⌘+a" : "ctrl+a", oe = [
681
- ...rt.map((t) => `shift+${t}`),
682
- it
683
- ], se = (t, n, e) => {
684
- let o;
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;
685
709
  const {
686
710
  annotatingEnabled: s,
687
- offsetReferenceSelector: r,
688
- selectionMode: c,
689
- dismissOnNotAnnotatable: f = "NEVER"
690
- } = e, p = (h) => o = h;
691
- let C;
692
- const S = (h) => C = h, { store: d, selection: l } = n;
693
- let u, v, E;
694
- const A = (h) => {
695
- v !== !1 && (u = F(t, h.target) ? void 0 : {
696
- annotation: et(),
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(),
697
721
  selector: [],
698
- creator: o,
722
+ creator: r,
699
723
  created: /* @__PURE__ */ new Date()
700
724
  });
701
- }, i = Y((h) => {
702
- const x = document.getSelection();
703
- if (!(x != null && x.anchorNode))
725
+ }, E = K((S) => {
726
+ const v = document.getSelection();
727
+ if (!(v != null && v.anchorNode))
704
728
  return;
705
- if (F(t, x.anchorNode)) {
706
- u = void 0;
729
+ if (Y(t, v.anchorNode)) {
730
+ g = void 0;
707
731
  return;
708
732
  }
709
- const k = h.timeStamp - ((E == null ? void 0 : E.timeStamp) || h.timeStamp);
710
- if ((E == null ? void 0 : E.type) === "pointerdown" && (k < 1e3 && !u || x.isCollapsed && k < Z) && A(E || h), !u) return;
711
- if (x.isCollapsed) {
712
- d.getAnnotation(u.annotation) && (l.clear(), d.deleteAnnotation(u.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));
713
737
  return;
714
738
  }
715
- const N = Array.from(Array(x.rangeCount).keys()).map((T) => x.getRangeAt(T)).map((T) => Pt(T, t));
716
- if (N.every((T) => kt(T))) return;
717
- const I = N.flatMap((T) => Tt(t, T.cloneRange()));
718
- (I.length !== u.selector.length || I.some((T, M) => {
719
- var D;
720
- return T.toString() !== ((D = u.selector[M]) == null ? void 0 : D.quote);
721
- })) && (u = {
722
- ...u,
723
- selector: I.map((T) => Bt(T, 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)),
724
748
  updated: /* @__PURE__ */ new Date()
725
- }, d.getAnnotation(u.annotation) ? d.updateTarget(u, U.LOCAL) : l.clear());
726
- }), a = (h) => {
727
- F(t, h.target) || (E = q(h), v = E.button === 0);
728
- }, y = async (h) => {
729
- if (!v) return;
730
- if (F(t, h.target)) {
731
- (typeof f == "function" ? f(h, t) : f === "ALWAYS") && l.clear();
732
- return;
733
- }
734
- const x = () => {
735
- const { x: O, y: N } = t.getBoundingClientRect(), I = h.target instanceof Node && t.contains(h.target) && d.getAt(h.clientX - O, h.clientY - N, c === "all", C);
736
- if (I) {
737
- const { selected: _ } = l, T = new Set(_.map((H) => H.id)), M = Array.isArray(I) ? I.map((H) => H.id) : [I.id];
738
- (T.size !== M.length || !M.every((H) => T.has(H))) && l.userSelect(M, 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);
739
769
  } else
740
- l.clear();
770
+ c.clear();
741
771
  };
742
- if (h.timeStamp - E.timeStamp < Z) {
743
- await b();
744
- const O = document.getSelection();
745
- if (O != null && O.isCollapsed) {
746
- u = void 0, x();
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();
747
777
  return;
748
778
  }
749
779
  }
750
- u && u.selector.length > 0 && (L(), l.userSelect(u.annotation, q(h)));
751
- }, b = async () => {
752
- const h = document.getSelection();
753
- let x = !1, k = h == null ? void 0 : h.isCollapsed;
754
- const O = () => k || x, N = 1;
755
- return setTimeout(() => x = !0, 50), Ct(() => k = h == null ? void 0 : h.isCollapsed, N, O);
756
- }, m = (h) => {
757
- const x = document.getSelection();
758
- x != null && x.isCollapsed || ((!u || u.selector.length === 0) && i(h), u && (L(), l.userSelect(u.annotation, q(h))));
759
- }, g = (h) => {
760
- h.key === "Shift" && u && (document.getSelection().isCollapsed || (L(), l.userSelect(u.annotation, W(h))));
761
- }, w = (h) => {
762
- const x = () => setTimeout(() => {
763
- (u == null ? void 0 : u.selector.length) > 0 && (l.clear(), d.addAnnotation({
764
- id: u.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,
765
795
  bodies: [],
766
- target: u
767
- }), l.userSelect(u.annotation, W(h))), document.removeEventListener("selectionchange", x);
796
+ target: g
797
+ }), c.userSelect(g.annotation, W(S))), document.removeEventListener("selectionchange", v);
768
798
  }, 100);
769
- document.addEventListener("selectionchange", x), A(h);
799
+ document.addEventListener("selectionchange", v), x(S);
770
800
  };
771
- V(oe.join(","), { element: t, keydown: !0, keyup: !1 }, (h) => {
772
- h.repeat || (E = W(h));
773
- }), V(it, { keydown: !0, keyup: !1 }, (h) => {
774
- E = W(h), w(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);
775
805
  });
776
- const R = (h) => {
777
- h.repeat || h.target !== t && h.target !== document.body || (u = void 0, l.clear());
806
+ const w = (S) => {
807
+ S.repeat || S.target !== t && S.target !== document.body || (g = void 0, c.clear());
778
808
  };
779
- V(rt.join(","), { keydown: !0, keyup: !1 }, R);
780
- const L = () => {
781
- const h = d.getAnnotation(u.annotation);
782
- if (!h) {
783
- d.addAnnotation({
784
- id: u.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,
785
815
  bodies: [],
786
- target: u
816
+ target: g
787
817
  });
788
818
  return;
789
819
  }
790
- const { target: { updated: x } } = h, { updated: k } = u;
791
- (!x || !k || x < k) && d.updateTarget(u);
820
+ const { target: { updated: v } } = S, { updated: O } = g;
821
+ (!v || !O || v < O) && f.updateTarget(g);
792
822
  };
793
- return t.addEventListener("pointerdown", a), document.addEventListener("pointerup", y), document.addEventListener("contextmenu", m), s && (t.addEventListener("keyup", g), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", i)), {
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)), {
794
824
  destroy: () => {
795
- t.removeEventListener("pointerdown", a), document.removeEventListener("pointerup", y), document.removeEventListener("contextmenu", m), t.removeEventListener("keyup", g), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", i), V.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();
796
826
  },
797
- setFilter: S,
798
- setUser: p
827
+ setFilter: b,
828
+ setUser: d
799
829
  };
800
- }, re = (t, n) => ({
830
+ }, de = (t, e) => ({
801
831
  ...t,
802
- annotatingEnabled: t.annotatingEnabled ?? n.annotatingEnabled,
803
- user: t.user || n.user
804
- }), J = "SPANS", pe = (t, n = {}) => {
805
- Et(t), xt(t);
806
- 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, {
807
837
  annotatingEnabled: !0,
808
- user: pt()
809
- }), o = te(t, e), { selection: s, viewport: r } = o, c = o.store, f = ht(c), p = yt(o, f, e.adapter);
810
- let C = e.user;
811
- const S = e.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : J : e.renderer || J, d = S === "SPANS" ? qt(t, o, r) : S === "CSS_HIGHLIGHTS" ? Yt(t, o, r) : S === "CANVAS" ? _t(t, o, r) : void 0;
812
- if (!d)
813
- throw `Unknown renderer implementation: ${S}`;
814
- console.debug(`Using ${S} renderer`), e.style && d.setStyle(e.style);
815
- const l = se(t, o, e);
816
- return l.setUser(C), {
817
- ...bt(o, f, 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),
818
848
  destroy: () => {
819
- d.destroy(), l.destroy(), f.destroy();
849
+ f.destroy(), c.destroy(), a.destroy();
820
850
  },
821
851
  element: t,
822
- getUser: () => C,
823
- setFilter: (g) => {
824
- d.setFilter(g), l.setFilter(g);
852
+ getUser: () => p,
853
+ setFilter: (l) => {
854
+ f.setFilter(l), c.setFilter(l);
825
855
  },
826
- setStyle: (g) => d.setStyle(g),
827
- setUser: (g) => {
828
- C = g, l.setUser(g);
856
+ setStyle: (l) => f.setStyle(l),
857
+ setUser: (l) => {
858
+ p = l, c.setUser(l);
829
859
  },
830
- setSelected: (g) => {
831
- g ? s.setSelected(g) : s.clear();
860
+ setSelected: (l) => {
861
+ l ? s.setSelected(l) : s.clear();
832
862
  },
833
- setPresenceProvider: (g) => {
834
- g && (d.setPainter(ne(g, e.presence)), g.on("selectionChange", () => d.redraw()));
863
+ setPresenceProvider: (l) => {
864
+ l && (f.setPainter(ae(l, n.presence)), l.on("selectionChange", () => f.redraw()));
835
865
  },
836
- setVisible: (g) => d.setVisible(g),
837
- on: p.on,
838
- off: p.off,
839
- scrollIntoView: Mt(t, c),
840
- state: o
866
+ setVisible: (l) => f.setVisible(l),
867
+ on: d.on,
868
+ off: d.off,
869
+ scrollIntoView: Kt(t, i),
870
+ state: r
841
871
  };
842
872
  };
843
873
  export {
844
874
  z as DEFAULT_SELECTED_STYLE,
845
875
  P as DEFAULT_STYLE,
846
- nt as NOT_ANNOTATABLE_CLASS,
876
+ ot as NOT_ANNOTATABLE_CLASS,
847
877
  $ as NOT_ANNOTATABLE_SELECTOR,
848
- be as Origin,
849
- se as SelectionHandler,
850
- Se as UserSelectAction,
851
- me as W3CTextFormat,
852
- Et as cancelSingleClickEvents,
878
+ ve as Origin,
879
+ le as SelectionHandler,
880
+ xe as UserSelectAction,
881
+ Ee as W3CTextFormat,
882
+ vt as cancelSingleClickEvents,
853
883
  W as cloneKeyboardEvent,
854
884
  q as clonePointerEvent,
855
- Ce as createBody,
856
- _t as createCanvasRenderer,
857
- Yt as createHighlightsRenderer,
858
- ne as createPresencePainter,
859
- Wt as createRenderer,
860
- qt as createSpansRenderer,
861
- pe as createTextAnnotator,
862
- te as createTextAnnotatorState,
863
- Y as debounce,
864
- re as fillDefaults,
865
- Rt as getQuoteContext,
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,
866
897
  G as getRangeAnnotatableContents,
867
- At as isMac,
868
- F as isNotAnnotatable,
869
- wt as isRangeAnnotatable,
870
- B as isRevived,
871
- kt as isWhitespaceOrEmpty,
872
- Nt as mergeClientRects,
873
- Ht as paint,
874
- Qt as parseW3CTextAnnotation,
875
- xt as programmaticallyFocusable,
876
- Bt as rangeToSelector,
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,
877
908
  j as reviveAnnotation,
878
- ot as reviveSelector,
909
+ st as reviveSelector,
879
910
  X as reviveTarget,
880
- Mt as scrollIntoView,
881
- Zt as serializeW3CTextAnnotation,
882
- Tt as splitAnnotatableRanges,
883
- ge as toDomRectList,
884
- Pt as trimRangeToContainer,
885
- Lt as whitespaceOrEmptyRegex
911
+ Kt as scrollIntoView,
912
+ oe as serializeW3CTextAnnotation,
913
+ kt as splitAnnotatableRanges,
914
+ Ce as toDomRectList,
915
+ Ft as trimRangeToContainer,
916
+ Bt as whitespaceOrEmptyRegex
886
917
  };
887
918
  //# sourceMappingURL=text-annotator.es.js.map