@soomo/text-annotator 3.4.0-staging.2 → 3.4.0-staging.3

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