@soomo/text-annotator 3.2.0-staging.1 → 3.2.0-staging.11

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,165 +1,175 @@
1
- const ue = "not-annotatable", nt = `.${ue}`, rt = (t) => {
2
- var n;
3
- return !!(t instanceof HTMLElement ? t.closest(nt) : (n = t.parentElement) == null ? void 0 : n.closest(nt));
4
- }, Me = (t) => {
5
- const e = t.commonAncestorContainer;
6
- return !rt(e);
7
- }, Be = (t) => t.addEventListener("click", (e) => {
1
+ import Q from "debounce";
2
+ import { colord as nt } from "colord";
3
+ import { dequal as dt } from "dequal/lite";
4
+ import { v4 as ot } from "uuid";
5
+ import { serializeW3CBodies as ut, parseW3CBodies as ft, parseW3CUser as gt, createStore as mt, createSelectionState as pt, createHoverState as ht, createViewportState as yt, Origin as _, createAnonymousGuest as bt, createUndoStack as St, createLifecycleObserver as Ct, createBaseAnnotator as Et } from "@annotorious/core";
6
+ import { Origin as Re, UserSelectAction as Le, createBody as ke } from "@annotorious/core";
7
+ import wt from "rbush";
8
+ import { createNanoEvents as At } from "nanoevents";
9
+ import V from "hotkeys-js";
10
+ import { poll as vt } from "poll";
11
+ const st = "not-annotatable", D = `.${st}`, W = (t) => {
12
+ var e;
13
+ return !!(t instanceof HTMLElement ? t.closest(D) : (e = t.parentElement) == null ? void 0 : e.closest(D));
14
+ }, xt = (t) => {
15
+ const n = t.commonAncestorContainer;
16
+ return !W(n);
17
+ }, Tt = (t) => t.addEventListener("click", (n) => {
8
18
  // Allow clicks within not-annotatable elements
9
- !e.target.closest(nt) && !e.target.closest("a") && e.preventDefault();
10
- }), ke = typeof navigator < "u" && // @ts-ignore
11
- /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform), Ie = (t) => {
19
+ !n.target.closest(D) && !n.target.closest("a") && n.preventDefault();
20
+ }), Rt = typeof navigator < "u" && // @ts-ignore
21
+ /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform), Lt = (t) => {
12
22
  !t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
13
- }, Ne = function* (t) {
14
- const e = document.createNodeIterator(
23
+ }, kt = function* (t) {
24
+ const n = document.createNodeIterator(
15
25
  t.commonAncestorContainer,
16
26
  NodeFilter.SHOW_ELEMENT,
17
- (o) => o instanceof HTMLElement && o.classList.contains(ue) && !o.parentElement.closest(nt) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
27
+ (o) => o instanceof HTMLElement && o.classList.contains(st) && !o.parentElement.closest(D) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
18
28
  );
19
- let n;
20
- for (; n = e.nextNode(); )
21
- n instanceof HTMLElement && (yield n);
22
- }, _e = (t) => {
23
- if (!Me(t)) return [];
24
- const e = [];
25
- let n = null;
26
- for (const o of Ne(t)) {
27
- let i;
28
- n ? (i = document.createRange(), i.setStartAfter(n), i.setEndBefore(o)) : (i = t.cloneRange(), i.setEndBefore(o)), i.collapsed || e.push(i), n = o;
29
- }
30
- if (n) {
29
+ let e;
30
+ for (; e = n.nextNode(); )
31
+ e instanceof HTMLElement && (yield e);
32
+ }, Bt = (t) => {
33
+ if (!xt(t)) return [];
34
+ const n = [];
35
+ let e = null;
36
+ for (const o of kt(t)) {
37
+ let s;
38
+ e ? (s = document.createRange(), s.setStartAfter(e), s.setEndBefore(o)) : (s = t.cloneRange(), s.setEndBefore(o)), s.collapsed || n.push(s), e = o;
39
+ }
40
+ if (e) {
31
41
  const o = t.cloneRange();
32
- o.setStartAfter(n), o.collapsed || e.push(o);
42
+ o.setStartAfter(e), o.collapsed || n.push(o);
33
43
  }
34
- return e.length > 0 ? e : [t];
35
- }, Kt = (t) => {
36
- const e = t.cloneContents();
37
- return e.querySelectorAll(nt).forEach((n) => n.remove()), e;
38
- }, Ue = (t, e, n = 10, o) => {
39
- const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
40
- s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
41
- const a = Kt(s).textContent, r = document.createRange();
42
- r.setStart(t.endContainer, t.endOffset), i === document.body ? r.setEnd(i, i.childNodes.length) : r.setEndAfter(i);
43
- const l = Kt(r).textContent;
44
+ return n.length > 0 ? n : [t];
45
+ }, G = (t) => {
46
+ const n = t.cloneContents();
47
+ return n.querySelectorAll(D).forEach((e) => e.remove()), n;
48
+ }, Nt = (t, n, e = 10, o) => {
49
+ const s = o ? t.startContainer.parentElement.closest(o) : n, i = document.createRange();
50
+ i.setStart(s, 0), i.setEnd(t.startContainer, t.startOffset);
51
+ const a = G(i).textContent, c = document.createRange();
52
+ c.setStart(t.endContainer, t.endOffset), s === document.body ? c.setEnd(s, s.childNodes.length) : c.setEndAfter(s);
53
+ const u = G(c).textContent;
44
54
  return {
45
- prefix: a.substring(a.length - n),
46
- suffix: l.substring(0, n)
47
- };
48
- }, q = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), De = /^\s*$/, Ve = (t) => De.test(t.toString()), Ye = (t, e) => {
49
- const n = (s) => Math.round(s * 10) / 10, o = {
50
- top: n(t.top),
51
- bottom: n(t.bottom),
52
- left: n(t.left),
53
- right: n(t.right)
54
- }, i = {
55
- top: n(e.top),
56
- bottom: n(e.bottom),
57
- left: n(e.left),
58
- right: n(e.right)
59
- };
60
- if (Math.abs(o.top - i.top) < 0.5 && Math.abs(o.bottom - i.bottom) < 0.5) {
61
- if (Math.abs(o.left - i.right) < 0.5 || Math.abs(o.right - i.left) < 0.5)
55
+ prefix: a.substring(a.length - e),
56
+ suffix: u.substring(0, e)
57
+ };
58
+ }, M = (t) => t.every((n) => n.range instanceof Range && !n.range.collapsed), Ot = /^\s*$/, It = (t) => Ot.test(t.toString()), Mt = (t, n) => {
59
+ const e = (i) => Math.round(i * 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)
69
+ };
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)
62
72
  return "inline-adjacent";
63
- if (o.left >= i.left && o.right <= i.right)
73
+ if (o.left >= s.left && o.right <= s.right)
64
74
  return "inline-is-contained";
65
- if (o.left <= i.left && o.right >= i.right)
75
+ if (o.left <= s.left && o.right >= s.right)
66
76
  return "inline-contains";
67
- } else if (o.top <= i.top && o.bottom >= i.bottom) {
68
- if (o.left <= i.left && o.right >= i.right)
77
+ } else if (o.top <= s.top && o.bottom >= s.bottom) {
78
+ if (o.left <= s.left && o.right >= s.right)
69
79
  return "block-contains";
70
- } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
80
+ } else if (o.top >= s.top && o.bottom <= s.bottom && o.left >= s.left && o.right <= s.right)
71
81
  return "block-is-contained";
72
- }, Ke = (t, e) => {
73
- const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
74
- return new DOMRect(n, i, o - n, s - i);
75
- }, Pe = (t) => t.reduce((e, n) => {
76
- if (n.width === 0 || n.height === 0)
77
- return e;
78
- let o = [...e], i = !1;
79
- for (const s of e) {
80
- const a = Ye(n, s);
82
+ }, Ht = (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), i = Math.max(t.bottom, n.bottom);
84
+ return new DOMRect(e, s, o - e, i - s);
85
+ }, Pt = (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 i of n) {
90
+ const a = Mt(e, i);
81
91
  if (a === "inline-adjacent") {
82
- o = o.map((r) => r === s ? Ke(n, s) : r), i = !0;
92
+ o = o.map((c) => c === i ? Ht(e, i) : c), s = !0;
83
93
  break;
84
94
  } else if (a === "inline-contains") {
85
- o = o.map((r) => r === s ? n : r), i = !0;
95
+ o = o.map((c) => c === i ? e : c), s = !0;
86
96
  break;
87
97
  } else if (a === "inline-is-contained") {
88
- i = !0;
98
+ s = !0;
89
99
  break;
90
100
  } else if (a === "block-contains" || a === "block-is-contained") {
91
- n.width < s.width && (o = o.map((r) => r === s ? n : r)), i = !0;
101
+ e.width < i.width && (o = o.map((c) => c === i ? e : c)), s = !0;
92
102
  break;
93
103
  }
94
104
  }
95
- return i ? o : [...o, n];
96
- }, []), Bo = (t) => ({
105
+ return s ? o : [...o, e];
106
+ }, []), Ee = (t) => ({
97
107
  length: t.length,
98
- item: (e) => t[e],
108
+ item: (n) => t[n],
99
109
  [Symbol.iterator]: function* () {
100
- for (let e = 0; e < this.length; e++)
101
- yield this.item(e);
102
- }
103
- }), Xe = (t, e, n) => {
104
- const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
105
- o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
106
- const s = Kt(o).textContent, a = t.toString(), r = s.length || 0, l = r + a.length;
107
- return n ? { quote: a, start: r, end: l, range: t, offsetReference: i } : { quote: a, start: r, end: l, range: t };
108
- }, fe = (t, e) => {
109
- var g, u;
110
- const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
111
- e,
110
+ for (let n = 0; n < this.length; n++)
111
+ yield this.item(n);
112
+ }
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 i = G(o).textContent, a = t.toString(), c = i.length || 0, u = c + a.length;
117
+ return e ? { quote: a, start: c, end: u, range: t, offsetReference: s } : { quote: a, start: c, end: u, range: t };
118
+ }, rt = (t, n) => {
119
+ var y, g;
120
+ const { start: e, end: o } = t, s = t.offsetReference || n, i = document.createNodeIterator(
121
+ n,
112
122
  NodeFilter.SHOW_TEXT,
113
- (h) => {
114
- var x;
115
- return (x = h.parentElement) != null && x.closest(nt) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
123
+ (r) => {
124
+ var A;
125
+ return (A = r.parentElement) != null && A.closest(D) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
116
126
  }
117
127
  );
118
128
  let a = 0;
119
- const r = document.createRange();
120
- let l = s.nextNode();
121
- l === null && console.error("Could not revive annotation target. Content missing.");
122
- let d = !i;
123
- for (; l !== null; ) {
124
- if (d || (d = typeof (i == null ? void 0 : i.contains) == "function" ? i.contains(l) : !1), d) {
125
- const h = ((g = l.textContent) == null ? void 0 : g.length) || 0;
126
- if (a + h > n) {
127
- r.setStart(l, n - a);
129
+ const c = document.createRange();
130
+ let u = i.nextNode();
131
+ u === null && console.error("Could not revive annotation target. Content missing.");
132
+ let b = !s;
133
+ for (; u !== null; ) {
134
+ if (b || (b = typeof (s == null ? void 0 : s.contains) == "function" ? s.contains(u) : !1), b) {
135
+ const r = ((y = u.textContent) == null ? void 0 : y.length) || 0;
136
+ if (a + r > e) {
137
+ c.setStart(u, e - a);
128
138
  break;
129
139
  }
130
- a += h;
140
+ a += r;
131
141
  }
132
- l = s.nextNode();
142
+ u = i.nextNode();
133
143
  }
134
- for (; l !== null; ) {
135
- const h = ((u = l.textContent) == null ? void 0 : u.length) || 0;
136
- if (a + h >= o) {
137
- r.setEnd(l, o - a);
144
+ for (; u !== null; ) {
145
+ const r = ((g = u.textContent) == null ? void 0 : g.length) || 0;
146
+ if (a + r >= o) {
147
+ c.setEnd(u, o - a);
138
148
  break;
139
149
  }
140
- a += h, l = s.nextNode();
150
+ a += r, u = i.nextNode();
141
151
  }
142
152
  return {
143
153
  ...t,
144
- range: r
154
+ range: c
145
155
  };
146
- }, vt = (t, e) => q(t.selector) ? t : {
156
+ }, X = (t, n) => M(t.selector) ? t : {
147
157
  ...t,
148
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : fe(n, e))
149
- }, Lt = (t, e) => q(t.target.selector) ? t : { ...t, target: vt(t.target, e) }, he = (t, e) => {
150
- if (t.isEqualNode(e))
158
+ selector: t.selector.map((e) => e.range instanceof Range && !e.range.collapsed ? e : rt(e, n))
159
+ }, q = (t, n) => M(t.target.selector) ? t : { ...t, target: X(t.target, n) }, it = (t, n) => {
160
+ if (t.isEqualNode(n))
151
161
  return !0;
152
- for (let n of t.childNodes)
153
- if (he(n, e))
162
+ for (let e of t.childNodes)
163
+ if (it(e, n))
154
164
  return !0;
155
165
  return !1;
156
- }, $e = (t, e) => {
157
- const n = t.cloneContents();
158
- return he(n, e);
159
- }, He = (t, e) => {
160
- const n = t.cloneRange(), o = e.contains(n.startContainer), i = e.contains(n.endContainer);
161
- return !o && !i && !$e(n, e) ? (n.collapse(), n) : (o || n.setStart(e, 0), i || n.setEnd(e, e.childNodes.length), n);
162
- }, Tt = (t) => ({
166
+ }, $t = (t, n) => {
167
+ const e = t.cloneContents();
168
+ return it(e, n);
169
+ }, _t = (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);
172
+ }, j = (t) => ({
163
173
  ...t,
164
174
  type: t.type,
165
175
  x: t.x,
@@ -185,7 +195,7 @@ const ue = "not-annotatable", nt = `.${ue}`, rt = (t) => {
185
195
  pointerId: t.pointerId,
186
196
  pointerType: t.pointerType,
187
197
  timeStamp: t.timeStamp
188
- }), pt = (t) => ({
198
+ }), Y = (t) => ({
189
199
  ...t,
190
200
  type: t.type,
191
201
  key: t.key,
@@ -201,2289 +211,695 @@ const ue = "not-annotatable", nt = `.${ue}`, rt = (t) => {
201
211
  defaultPrevented: t.defaultPrevented,
202
212
  detail: t.detail,
203
213
  timeStamp: t.timeStamp
204
- }), je = (t, e) => {
205
- const { left: n, top: o, right: i, bottom: s } = t;
206
- return new DOMRect(n - e.left, o - e.top, i - n, s - o);
207
- }, ko = (t, e) => {
208
- const { left: n, top: o, right: i, bottom: s } = t;
209
- return new DOMRect(n + e.left, o + e.top, i - n, s - o);
210
- }, pe = (t) => {
211
- if (t === null)
214
+ }), Dt = (t, n) => {
215
+ const { left: e, top: o, right: s, bottom: i } = t;
216
+ return new DOMRect(e - n.left, o - n.top, s - e, i - o);
217
+ }, we = (t, n) => {
218
+ const { left: e, top: o, right: s, bottom: i } = t;
219
+ return new DOMRect(e + n.left, o + n.top, s - e, i - o);
220
+ }, at = (t) => {
221
+ if (!t)
212
222
  return document.scrollingElement;
213
- const { overflowY: e } = window.getComputedStyle(t);
214
- return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : pe(t.parentElement);
215
- }, ze = (t, e) => (n) => {
216
- const o = typeof n == "string" ? n : n.id, i = (a) => {
217
- const r = s.getBoundingClientRect(), l = s.clientHeight, d = s.clientWidth, g = a.selector[0].range.getBoundingClientRect(), { width: u, height: h } = e.getAnnotationBounds(o), x = g.top - r.top, p = g.left - r.left, w = s.parentElement ? s.scrollTop : 0, E = s.parentElement ? s.scrollLeft : 0, m = x + w - (l - h) / 2, c = p + E - (d - u) / 2;
218
- s.scroll({ top: m, left: c, behavior: "smooth" });
219
- }, s = pe(t);
220
- if (s) {
221
- const a = e.getAnnotation(o), { range: r } = a.target.selector[0];
222
- if (r && !r.collapsed)
223
- return i(a.target), !0;
224
- {
225
- const l = vt(a.target, t), { range: d } = l.selector[0];
226
- if (d && !d.collapsed)
227
- return i(l), !0;
228
- }
229
- }
230
- return !1;
231
- }, G = {
223
+ const { overflowY: n } = window.getComputedStyle(t);
224
+ return n !== "visible" && n !== "hidden" && t.scrollHeight > t.clientHeight ? t : at(t.parentElement);
225
+ }, J = (t, n, e) => {
226
+ const o = e.getBoundingClientRect(), s = e.clientHeight, i = e.clientWidth, a = n.selector[0].range.getBoundingClientRect(), { width: c, height: u } = t.getAnnotationBounds(n.annotation), b = a.top - o.top, y = a.left - o.left, g = e.parentElement ? e.scrollTop : 0, r = e.parentElement ? e.scrollLeft : 0, A = b + g - (s - u) / 2, S = y + r - (i - c) / 2;
227
+ e.scroll({ top: A, left: S, behavior: "smooth" });
228
+ }, Ft = (t, n) => (e, o) => {
229
+ const s = typeof e == "string" ? e : e.id, i = o ? typeof o == "string" ? document.getElementById(o) : o : at(t);
230
+ if (!i)
231
+ return console.warn(`The scroll parent is missing for the annotation: ${s}`, { container: t }), !1;
232
+ const a = n.getAnnotation(s);
233
+ if (!a)
234
+ return console.warn(`The annotation is missing in the store: ${s}`), !1;
235
+ const { range: c } = a.target.selector[0];
236
+ if (c && !c.collapsed)
237
+ return J(n, a.target, i), !0;
238
+ const u = X(a.target, t), { range: b } = u.selector[0];
239
+ return b && !b.collapsed ? (J(n, u, i), !0) : !1;
240
+ }, K = {
232
241
  fill: "rgb(0, 128, 255)",
233
242
  fillOpacity: 0.18
234
- }, St = {
243
+ }, z = {
235
244
  fill: "rgb(0, 128, 255)",
236
245
  fillOpacity: 0.45
237
- }, Fe = (t, e, n, o, i) => {
238
- var a, r;
239
- const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? St : G) : n : (r = t.state) != null && r.selected ? St : G;
240
- return o && o.paint(t, e) || s;
241
- };
242
- function We(t) {
243
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
244
- }
245
- var gt = { exports: {} }, zt;
246
- function qe() {
247
- if (zt) return gt.exports;
248
- zt = 1;
249
- function t(e, n = 100, o = {}) {
250
- if (typeof e != "function")
251
- throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);
252
- if (n < 0)
253
- throw new RangeError("`wait` must not be negative.");
254
- const { immediate: i } = typeof o == "boolean" ? { immediate: o } : o;
255
- let s, a, r, l, d;
256
- function g() {
257
- const x = s, p = a;
258
- return s = void 0, a = void 0, d = e.apply(x, p), d;
259
- }
260
- function u() {
261
- const x = Date.now() - l;
262
- x < n && x >= 0 ? r = setTimeout(u, n - x) : (r = void 0, i || (d = g()));
263
- }
264
- const h = function(...x) {
265
- if (s && this !== s && Object.getPrototypeOf(this) === Object.getPrototypeOf(s))
266
- throw new Error("Debounced method called with different contexts of the same prototype.");
267
- s = this, a = x, l = Date.now();
268
- const p = i && !r;
269
- return r || (r = setTimeout(u, n)), p && (d = g()), d;
270
- };
271
- return Object.defineProperty(h, "isPending", {
272
- get() {
273
- return r !== void 0;
274
- }
275
- }), h.clear = () => {
276
- r && (clearTimeout(r), r = void 0);
277
- }, h.flush = () => {
278
- r && h.trigger();
279
- }, h.trigger = () => {
280
- d = g(), h.clear();
281
- }, h;
282
- }
283
- return gt.exports.debounce = t, gt.exports = t, gt.exports;
284
- }
285
- var Ge = /* @__PURE__ */ qe();
286
- const Xt = /* @__PURE__ */ We(Ge), Qe = (t) => {
287
- const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n, l = i - e;
288
- return { top: e, left: n, minX: s, minY: a, maxX: r, maxY: l };
289
- }, Je = (t) => {
290
- let e = /* @__PURE__ */ new Set();
246
+ }, Ut = (t, n, e, o, s) => {
247
+ var a, c;
248
+ const i = e ? typeof e == "function" ? e(t.annotation, t.state, s) || ((a = t.state) != null && a.selected ? z : K) : e : (c = t.state) != null && c.selected ? z : K;
249
+ return o && o.paint(t, n) || i;
250
+ }, Wt = (t) => {
251
+ const { top: n, left: e } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: s } = window, i = -e, a = -n, c = o - e, u = s - n;
252
+ return { top: n, left: e, minX: i, minY: a, maxX: c, maxY: u };
253
+ }, Vt = (t) => {
254
+ let n = /* @__PURE__ */ new Set();
291
255
  return (o) => {
292
- const i = o.map((s) => s.id);
293
- (e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
294
- };
295
- }, $t = (t, e, n, o) => {
296
- const { store: i, selection: s, hover: a } = e;
297
- let r, l, d;
298
- const g = Je(n), u = (T) => {
299
- const { x: M, y: _ } = t.getBoundingClientRect(), X = i.getAt(T.clientX - M, T.clientY - _, !1, l);
300
- X ? a.current !== X.id && (t.classList.add("hovered"), a.set(X.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
301
- };
302
- t.addEventListener("pointermove", u);
303
- const h = (T = !1) => {
304
- d && d.clear();
305
- const M = Qe(t), { minX: _, minY: X, maxX: f, maxY: b } = M, A = l ? i.getIntersecting(_, X, f, b).filter(({ annotation: O }) => l(O)) : i.getIntersecting(_, X, f, b), C = s.selected.map(({ id: O }) => O), B = A.map(({ annotation: O, rects: I }) => {
306
- const V = C.includes(O.id), Q = O.id === a.current;
307
- return { annotation: O, rects: I, state: { selected: V, hover: Q } };
256
+ const s = o.map((i) => i.id);
257
+ (n.size !== s.length || s.some((i) => !n.has(i))) && t.set(s), n = new Set(s);
258
+ };
259
+ }, Z = (t, n, e, o) => {
260
+ const { store: s, selection: i, hover: a } = n;
261
+ let c, u, b;
262
+ const y = Vt(e), g = (E) => {
263
+ const { x: L, y: I } = t.getBoundingClientRect(), p = s.getAt(E.clientX - L, E.clientY - I, !1, u);
264
+ p ? a.current !== p.id && (t.classList.add("hovered"), a.set(p.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
265
+ };
266
+ t.addEventListener("pointermove", g);
267
+ const r = (E = !1) => {
268
+ b && b.clear();
269
+ const L = Wt(t), { minX: I, minY: p, maxX: R, maxY: k } = L, B = u ? s.getIntersecting(I, p, R, k).filter(({ annotation: N }) => u(N)) : s.getIntersecting(I, p, R, k), H = i.selected.map(({ id: N }) => N), O = B.map(({ annotation: N, rects: P }) => {
270
+ const $ = H.includes(N.id), F = N.id === a.current;
271
+ return {
272
+ annotation: N,
273
+ rects: P,
274
+ state: { selected: $, hovered: F }
275
+ };
308
276
  });
309
- o.redraw(B, M, r, d, T), setTimeout(() => g(A.map(({ annotation: O }) => O)), 1);
310
- }, x = (T) => {
311
- d = T, h();
312
- }, p = (T) => {
313
- r = T, h();
314
- }, w = (T) => {
315
- l = T, h(!1);
316
- }, E = () => h();
317
- i.observe(E);
318
- const m = s.subscribe(() => h()), c = () => h(!0);
319
- document.addEventListener("scroll", c, { capture: !0, passive: !0 });
320
- const y = Xt(() => {
321
- i.recalculatePositions(), d == null || d.reset(), h();
277
+ o.redraw(O, L, c, b, E), setTimeout(() => y(B.map(({ annotation: N }) => N)), 1);
278
+ }, A = (E) => {
279
+ b = E, r();
280
+ }, S = (E) => {
281
+ c = E, r();
282
+ }, T = (E) => {
283
+ u = E, r(!1);
284
+ }, x = () => r();
285
+ s.observe(x);
286
+ const C = i.subscribe(() => r()), m = a.subscribe(() => r()), d = () => r(!0);
287
+ document.addEventListener("scroll", d, { capture: !0, passive: !0 });
288
+ const f = Q(() => {
289
+ s.recalculatePositions(), b == null || b.reset(), r();
322
290
  }, 10);
323
- window.addEventListener("resize", y);
324
- const S = new ResizeObserver(y);
325
- S.observe(t);
326
- const v = { attributes: !0, childList: !0, subtree: !0 }, L = new MutationObserver((T) => {
327
- T.every((_) => _.target === t || t.contains(_.target)) || h(!0);
291
+ window.addEventListener("resize", f);
292
+ const l = new ResizeObserver(f);
293
+ l.observe(t);
294
+ const h = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver((E) => {
295
+ E.every((I) => I.target === t || t.contains(I.target)) || r(!0);
328
296
  });
329
- return L.observe(document.body, v), {
297
+ return w.observe(document.body, h), {
330
298
  destroy: () => {
331
- t.removeEventListener("pointermove", u), o.destroy(), i.unobserve(E), m(), document.removeEventListener("scroll", c), y.clear(), window.removeEventListener("resize", y), S.disconnect(), L.disconnect();
299
+ t.removeEventListener("pointermove", g), o.destroy(), s.unobserve(x), C(), m(), document.removeEventListener("scroll", d), f.clear(), window.removeEventListener("resize", f), l.disconnect(), w.disconnect();
332
300
  },
333
- redraw: h,
334
- setStyle: p,
335
- setFilter: w,
336
- setPainter: x,
301
+ redraw: r,
302
+ setStyle: S,
303
+ setFilter: T,
304
+ setPainter: A,
337
305
  setVisible: o.setVisible
338
306
  };
339
- }, Ze = () => {
307
+ }, Yt = () => {
340
308
  const t = document.createElement("canvas");
341
309
  return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
342
- }, tn = (t, e) => {
310
+ }, Xt = (t, n) => {
343
311
  t.width = window.innerWidth, t.height = window.innerHeight;
344
- }, en = (t) => {
312
+ }, zt = (t) => {
345
313
  t.classList.add("r6o-annotatable");
346
- const e = Ze(), n = e.getContext("2d");
347
- document.body.appendChild(e);
348
- const o = (r, l, d, g) => requestAnimationFrame(() => {
349
- const { width: u, height: h } = e;
350
- n.clearRect(-0.5, -0.5, u + 1, h + 1), g && g.clear();
351
- const { top: x, left: p } = l;
352
- [...r].sort((E, m) => {
353
- const { annotation: { target: { created: c } } } = E, { annotation: { target: { created: y } } } = m;
354
- return c.getTime() - y.getTime();
355
- }).forEach((E) => {
356
- var S;
357
- const m = d ? typeof d == "function" ? d(E.annotation, E.state) : d : (S = E.state) != null && S.selected ? St : G, c = g && g.paint(E, l) || m, y = E.rects.map(({ x: v, y: L, width: R, height: T }) => ({
358
- x: v + p,
359
- y: L + x,
360
- width: R,
361
- height: T
314
+ const n = Yt(), e = n.getContext("2d");
315
+ document.body.appendChild(n);
316
+ const o = (c, u, b, y) => requestAnimationFrame(() => {
317
+ const { width: g, height: r } = n;
318
+ e.clearRect(-0.5, -0.5, g + 1, r + 1), y && y.clear();
319
+ const { top: A, left: S } = u;
320
+ [...c].sort((x, C) => {
321
+ const { annotation: { target: { created: m } } } = x, { annotation: { target: { created: d } } } = C;
322
+ return m.getTime() - d.getTime();
323
+ }).forEach((x) => {
324
+ var f;
325
+ const C = b ? typeof b == "function" ? b(x.annotation, x.state) : b : (f = x.state) != null && f.selected ? z : K, m = y && y.paint(x, u) || C, d = x.rects.map(({ x: l, y: h, width: w, height: v }) => ({
326
+ x: l + S,
327
+ y: h + A,
328
+ width: w,
329
+ height: v
362
330
  }));
363
- if (n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1, y.forEach(
364
- ({ x: v, y: L, width: R, height: T }) => n.fillRect(v, L, R, T)
365
- ), c.underlineColor) {
366
- n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
367
- const v = c.underlineOffset ?? 0;
368
- y.forEach(({ x: L, y: R, width: T, height: M }) => {
369
- n.beginPath(), n.moveTo(L, R + M + v), n.lineTo(L + T, R + M + v), n.stroke();
331
+ if (e.fillStyle = m.fill, e.globalAlpha = m.fillOpacity || 1, d.forEach(
332
+ ({ x: l, y: h, width: w, height: v }) => e.fillRect(l, h, w, v)
333
+ ), m.underlineColor) {
334
+ e.globalAlpha = 1, e.strokeStyle = m.underlineColor, e.lineWidth = m.underlineThickness ?? 1;
335
+ const l = m.underlineOffset ?? 0;
336
+ d.forEach(({ x: h, y: w, width: v, height: E }) => {
337
+ e.beginPath(), e.moveTo(h, w + E + l), e.lineTo(h + v, w + E + l), e.stroke();
370
338
  });
371
339
  }
372
340
  });
373
- }), i = Xt(() => tn(e), 10);
374
- return window.addEventListener("resize", i), {
341
+ }), s = Q(() => Xt(n), 10);
342
+ return window.addEventListener("resize", s), {
375
343
  destroy: () => {
376
- e.remove(), i.clear(), window.removeEventListener("resize", i);
344
+ n.remove(), s.clear(), window.removeEventListener("resize", s);
377
345
  },
378
- setVisible: (r) => {
346
+ setVisible: (c) => {
379
347
  console.log("setVisible not implemented on Canvas renderer");
380
348
  },
381
349
  redraw: o
382
350
  };
383
- }, nn = (t, e, n) => $t(t, e, n, en(t));
384
- var on = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
385
- return typeof t == "string" ? t.length > 0 : typeof t == "number";
386
- }, D = function(t, e, n) {
387
- return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
388
- }, $ = function(t, e, n) {
389
- return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
390
- }, ge = function(t) {
391
- return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
392
- }, Ft = function(t) {
393
- return { r: $(t.r, 0, 255), g: $(t.g, 0, 255), b: $(t.b, 0, 255), a: $(t.a) };
394
- }, Ot = function(t) {
395
- return { r: D(t.r), g: D(t.g), b: D(t.b), a: D(t.a, 3) };
396
- }, sn = /^#([0-9a-f]{3,8})$/i, mt = function(t) {
397
- var e = t.toString(16);
398
- return e.length < 2 ? "0" + e : e;
399
- }, me = function(t) {
400
- var e = t.r, n = t.g, o = t.b, i = t.a, s = Math.max(e, n, o), a = s - Math.min(e, n, o), r = a ? s === e ? (n - o) / a : s === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
401
- return { h: 60 * (r < 0 ? r + 6 : r), s: s ? a / s * 100 : 0, v: s / 255 * 100, a: i };
402
- }, ye = function(t) {
403
- var e = t.h, n = t.s, o = t.v, i = t.a;
404
- e = e / 360 * 6, n /= 100, o /= 100;
405
- var s = Math.floor(e), a = o * (1 - n), r = o * (1 - (e - s) * n), l = o * (1 - (1 - e + s) * n), d = s % 6;
406
- return { r: 255 * [o, r, a, a, l, o][d], g: 255 * [l, o, o, r, a, a][d], b: 255 * [a, a, l, o, o, r][d], a: i };
407
- }, Wt = function(t) {
408
- return { h: ge(t.h), s: $(t.s, 0, 100), l: $(t.l, 0, 100), a: $(t.a) };
409
- }, qt = function(t) {
410
- return { h: D(t.h), s: D(t.s), l: D(t.l), a: D(t.a, 3) };
411
- }, Gt = function(t) {
412
- return ye((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
413
- var e, n, o;
414
- }, lt = function(t) {
415
- return { h: (e = me(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
416
- var e, n, o, i;
417
- }, rn = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, an = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, cn = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ln = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Qt = { string: [[function(t) {
418
- var e = sn.exec(t);
419
- return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? D(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? D(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
420
- }, "hex"], [function(t) {
421
- var e = cn.exec(t) || ln.exec(t);
422
- return e ? e[2] !== e[4] || e[4] !== e[6] ? null : Ft({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
423
- }, "rgb"], [function(t) {
424
- var e = rn.exec(t) || an.exec(t);
425
- if (!e) return null;
426
- var n, o, i = Wt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (on[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
427
- return Gt(i);
428
- }, "hsl"]], object: [[function(t) {
429
- var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
430
- return F(e) && F(n) && F(o) ? Ft({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
431
- }, "rgb"], [function(t) {
432
- var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
433
- if (!F(e) || !F(n) || !F(o)) return null;
434
- var a = Wt({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
435
- return Gt(a);
436
- }, "hsl"], [function(t) {
437
- var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
438
- if (!F(e) || !F(n) || !F(o)) return null;
439
- var a = function(r) {
440
- return { h: ge(r.h), s: $(r.s, 0, 100), v: $(r.v, 0, 100), a: $(r.a) };
441
- }({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
442
- return ye(a);
443
- }, "hsv"]] }, Jt = function(t, e) {
444
- for (var n = 0; n < e.length; n++) {
445
- var o = e[n][0](t);
446
- if (o) return [o, e[n][1]];
447
- }
448
- return [null, void 0];
449
- }, dn = function(t) {
450
- return typeof t == "string" ? Jt(t.trim(), Qt.string) : typeof t == "object" && t !== null ? Jt(t, Qt.object) : [null, void 0];
451
- }, Rt = function(t, e) {
452
- var n = lt(t);
453
- return { h: n.h, s: $(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
454
- }, Mt = function(t) {
455
- return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
456
- }, Zt = function(t, e) {
457
- var n = lt(t);
458
- return { h: n.h, s: n.s, l: $(n.l + 100 * e, 0, 100), a: n.a };
459
- }, te = function() {
460
- function t(e) {
461
- this.parsed = dn(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
462
- }
463
- return t.prototype.isValid = function() {
464
- return this.parsed !== null;
465
- }, t.prototype.brightness = function() {
466
- return D(Mt(this.rgba), 2);
467
- }, t.prototype.isDark = function() {
468
- return Mt(this.rgba) < 0.5;
469
- }, t.prototype.isLight = function() {
470
- return Mt(this.rgba) >= 0.5;
471
- }, t.prototype.toHex = function() {
472
- return e = Ot(this.rgba), n = e.r, o = e.g, i = e.b, a = (s = e.a) < 1 ? mt(D(255 * s)) : "", "#" + mt(n) + mt(o) + mt(i) + a;
473
- var e, n, o, i, s, a;
474
- }, t.prototype.toRgb = function() {
475
- return Ot(this.rgba);
476
- }, t.prototype.toRgbString = function() {
477
- return e = Ot(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
478
- var e, n, o, i, s;
479
- }, t.prototype.toHsl = function() {
480
- return qt(lt(this.rgba));
481
- }, t.prototype.toHslString = function() {
482
- return e = qt(lt(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
483
- var e, n, o, i, s;
484
- }, t.prototype.toHsv = function() {
485
- return e = me(this.rgba), { h: D(e.h), s: D(e.s), v: D(e.v), a: D(e.a, 3) };
486
- var e;
487
- }, t.prototype.invert = function() {
488
- return j({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
489
- var e;
490
- }, t.prototype.saturate = function(e) {
491
- return e === void 0 && (e = 0.1), j(Rt(this.rgba, e));
492
- }, t.prototype.desaturate = function(e) {
493
- return e === void 0 && (e = 0.1), j(Rt(this.rgba, -e));
494
- }, t.prototype.grayscale = function() {
495
- return j(Rt(this.rgba, -1));
496
- }, t.prototype.lighten = function(e) {
497
- return e === void 0 && (e = 0.1), j(Zt(this.rgba, e));
498
- }, t.prototype.darken = function(e) {
499
- return e === void 0 && (e = 0.1), j(Zt(this.rgba, -e));
500
- }, t.prototype.rotate = function(e) {
501
- return e === void 0 && (e = 15), this.hue(this.hue() + e);
502
- }, t.prototype.alpha = function(e) {
503
- return typeof e == "number" ? j({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : D(this.rgba.a, 3);
504
- var n;
505
- }, t.prototype.hue = function(e) {
506
- var n = lt(this.rgba);
507
- return typeof e == "number" ? j({ h: e, s: n.s, l: n.l, a: n.a }) : D(n.h);
508
- }, t.prototype.isEqual = function(e) {
509
- return this.toHex() === j(e).toHex();
510
- }, t;
511
- }(), j = function(t) {
512
- return t instanceof te ? t : new te(t);
513
- };
514
- const un = (t) => [
515
- `background-color:${j((t == null ? void 0 : t.fill) || G.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? G.fillOpacity : t.fillOpacity).toHex()}`,
351
+ }, qt = (t, n, e) => Z(t, n, e, zt(t)), jt = (t) => [
352
+ `background-color:${nt((t == null ? void 0 : t.fill) || K.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? K.fillOpacity : t.fillOpacity).toHex()}`,
516
353
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
517
354
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
518
355
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
519
356
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
520
- ].filter(Boolean).join(";"), fn = () => {
357
+ ].filter(Boolean).join(";"), Gt = () => {
521
358
  const t = document.createElement("style");
522
359
  document.getElementsByTagName("head")[0].appendChild(t);
523
- let e = /* @__PURE__ */ new Set();
360
+ let n = /* @__PURE__ */ new Set();
524
361
  return {
525
362
  destroy: () => {
526
363
  CSS.highlights.clear(), t.remove();
527
364
  },
528
- setVisible: (s) => {
365
+ setVisible: (i) => {
529
366
  console.log("setVisible not implemented on CSS Custom Highlights renderer");
530
367
  },
531
- redraw: (s, a, r, l) => {
532
- l && l.clear();
533
- const d = new Set(s.map((u) => u.annotation.id));
534
- Array.from(e).filter((u) => !d.has(u));
535
- const g = s.map((u) => {
536
- var p;
537
- const h = r ? typeof r == "function" ? r(u.annotation, u.state) : r : (p = u.state) != null && p.selected ? St : G, x = l && l.paint(u, a) || h;
538
- return `::highlight(_${u.annotation.id}) { ${un(x)} }`;
368
+ redraw: (i, a, c, u) => {
369
+ u && u.clear();
370
+ const b = new Set(i.map((g) => g.annotation.id));
371
+ Array.from(n).filter((g) => !b.has(g));
372
+ const y = i.map((g) => {
373
+ var S;
374
+ const r = c ? typeof c == "function" ? c(g.annotation, g.state) : c : (S = g.state) != null && S.selected ? z : K, A = u && u.paint(g, a) || r;
375
+ return `::highlight(_${g.annotation.id}) { ${jt(A)} }`;
539
376
  });
540
- t.innerHTML = g.join(`
541
- `), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
542
- const h = u.target.selector.map((p) => p.range), x = new Highlight(...h);
543
- CSS.highlights.set(`_${u.id}`, x);
544
- }), e = d;
377
+ t.innerHTML = y.join(`
378
+ `), CSS.highlights.clear(), i.forEach(({ annotation: g }) => {
379
+ const r = g.target.selector.map((S) => S.range), A = new Highlight(...r);
380
+ CSS.highlights.set(`_${g.id}`, A);
381
+ }), n = b;
545
382
  }
546
383
  };
547
- }, hn = (t, e, n) => $t(t, e, n, fn());
548
- var ee = Object.prototype.hasOwnProperty;
549
- function Pt(t, e) {
550
- var n, o;
551
- if (t === e) return !0;
552
- if (t && e && (n = t.constructor) === e.constructor) {
553
- if (n === Date) return t.getTime() === e.getTime();
554
- if (n === RegExp) return t.toString() === e.toString();
555
- if (n === Array) {
556
- if ((o = t.length) === e.length)
557
- for (; o-- && Pt(t[o], e[o]); ) ;
558
- return o === -1;
559
- }
560
- if (!n || typeof t == "object") {
561
- o = 0;
562
- for (n in t)
563
- if (ee.call(t, n) && ++o && !ee.call(e, n) || !(n in e) || !Pt(t[n], e[n])) return !1;
564
- return Object.keys(e).length === o;
565
- }
566
- }
567
- return t !== t && e !== e;
568
- }
569
- const pn = (t, e) => {
570
- const n = (s, a) => s.x <= a.x + a.width && s.x + s.width >= a.x && s.y <= a.y + a.height && s.y + s.height >= a.y, o = (s) => s.rects.reduce((a, r) => a + r.width, 0), i = e.filter(({ rects: s }) => s.some((a) => n(t, a)));
571
- return i.sort((s, a) => o(a) - o(s)), i.findIndex((s) => s.rects.includes(t));
572
- }, gn = (t) => {
384
+ }, Qt = (t, n, e) => Z(t, n, e, Gt()), Zt = (t, n) => {
385
+ const e = (i, a) => i.x <= a.x + a.width && i.x + i.width >= a.x && i.y <= a.y + a.height && i.y + i.height >= a.y, o = (i) => i.rects.reduce((a, c) => a + c.width, 0), s = n.filter(({ rects: i }) => i.some((a) => e(t, a)));
386
+ return s.sort((i, a) => o(a) - o(i)), s.findIndex((i) => i.rects.includes(t));
387
+ }, Jt = (t) => {
573
388
  t.classList.add("r6o-annotatable");
574
- const e = document.createElement("div");
575
- e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
576
- let n = [];
389
+ const n = document.createElement("div");
390
+ n.className = "r6o-span-highlight-layer", t.insertBefore(n, t.firstChild);
391
+ let e = [];
577
392
  return {
578
393
  destroy: () => {
579
- e.remove();
394
+ n.remove();
580
395
  },
581
- redraw: (a, r, l, d, g) => {
582
- const h = !(Pt(n, a) && g);
583
- if (!d && !h) return;
584
- h && (e.innerHTML = ""), [...a].sort((p, w) => {
585
- const { annotation: { target: { created: E } } } = p, { annotation: { target: { created: m } } } = w;
586
- return E && m ? E.getTime() - m.getTime() : 0;
587
- }).forEach((p) => {
588
- p.rects.map((w) => {
589
- const E = pn(w, a), m = Fe(p, r, l, d, E);
590
- if (h) {
591
- const c = document.createElement("span");
592
- c.className = "r6o-annotation", c.dataset.annotation = p.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 = j((m == null ? void 0 : m.fill) || G.fill).alpha((m == null ? void 0 : m.fillOpacity) === void 0 ? G.fillOpacity : m.fillOpacity).toHex(), m.underlineStyle && (c.style.borderStyle = m.underlineStyle), m.underlineColor && (c.style.borderColor = m.underlineColor), m.underlineThickness && (c.style.borderBottomWidth = `${m.underlineThickness}px`), m.underlineOffset && (c.style.paddingBottom = `${m.underlineOffset}px`), e.appendChild(c);
396
+ redraw: (a, c, u, b, y) => {
397
+ const r = !(dt(e, a) && y);
398
+ if (!b && !r) return;
399
+ r && (n.innerHTML = ""), [...a].sort((S, T) => {
400
+ const { annotation: { target: { created: x } } } = S, { annotation: { target: { created: C } } } = T;
401
+ return x && C ? x.getTime() - C.getTime() : 0;
402
+ }).forEach((S) => {
403
+ S.rects.map((T) => {
404
+ const x = Zt(T, a), C = Ut(S, c, u, b, x);
405
+ if (r) {
406
+ const m = document.createElement("span");
407
+ m.className = "r6o-annotation", m.dataset.annotation = S.annotation.id, m.style.left = `${T.x}px`, m.style.top = `${T.y}px`, m.style.width = `${T.width}px`, m.style.height = `${T.height}px`, m.style.backgroundColor = nt((C == null ? void 0 : C.fill) || K.fill).alpha((C == null ? void 0 : C.fillOpacity) === void 0 ? K.fillOpacity : C.fillOpacity).toHex(), C.underlineStyle && (m.style.borderStyle = C.underlineStyle), C.underlineColor && (m.style.borderColor = C.underlineColor), C.underlineThickness && (m.style.borderBottomWidth = `${C.underlineThickness}px`), C.underlineOffset && (m.style.paddingBottom = `${C.underlineOffset}px`), n.appendChild(m);
593
408
  }
594
409
  });
595
- }), n = a;
410
+ }), e = a;
596
411
  },
597
412
  setVisible: (a) => {
598
- a ? e.classList.remove("hidden") : e.classList.add("hidden");
599
- }
600
- };
601
- }, mn = (t, e, n) => $t(t, e, n, gn(t)), Y = [];
602
- for (let t = 0; t < 256; ++t)
603
- Y.push((t + 256).toString(16).slice(1));
604
- function yn(t, e = 0) {
605
- return (Y[t[e + 0]] + Y[t[e + 1]] + Y[t[e + 2]] + Y[t[e + 3]] + "-" + Y[t[e + 4]] + Y[t[e + 5]] + "-" + Y[t[e + 6]] + Y[t[e + 7]] + "-" + Y[t[e + 8]] + Y[t[e + 9]] + "-" + Y[t[e + 10]] + Y[t[e + 11]] + Y[t[e + 12]] + Y[t[e + 13]] + Y[t[e + 14]] + Y[t[e + 15]]).toLowerCase();
606
- }
607
- let Bt;
608
- const bn = new Uint8Array(16);
609
- function wn() {
610
- if (!Bt) {
611
- if (typeof crypto > "u" || !crypto.getRandomValues)
612
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
613
- Bt = crypto.getRandomValues.bind(crypto);
614
- }
615
- return Bt(bn);
616
- }
617
- const An = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ne = { randomUUID: An };
618
- function be(t, e, n) {
619
- var i;
620
- if (ne.randomUUID && !t)
621
- return ne.randomUUID();
622
- t = t || {};
623
- const o = t.random ?? ((i = t.rng) == null ? void 0 : i.call(t)) ?? wn();
624
- if (o.length < 16)
625
- throw new Error("Random bytes length must be >= 16");
626
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, yn(o);
627
- }
628
- var oe = Object.prototype.hasOwnProperty;
629
- function J(t, e) {
630
- var n, o;
631
- if (t === e) return !0;
632
- if (t && e && (n = t.constructor) === e.constructor) {
633
- if (n === Date) return t.getTime() === e.getTime();
634
- if (n === RegExp) return t.toString() === e.toString();
635
- if (n === Array) {
636
- if ((o = t.length) === e.length)
637
- for (; o-- && J(t[o], e[o]); ) ;
638
- return o === -1;
639
- }
640
- if (!n || typeof t == "object") {
641
- o = 0;
642
- for (n in t)
643
- if (oe.call(t, n) && ++o && !oe.call(e, n) || !(n in e) || !J(t[n], e[n])) return !1;
644
- return Object.keys(e).length === o;
413
+ a ? n.classList.remove("hidden") : n.classList.add("hidden");
645
414
  }
646
- }
647
- return t !== t && e !== e;
648
- }
649
- function kt() {
650
- }
651
- function xn(t, e) {
652
- return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
653
- }
654
- const Z = [];
655
- function Ht(t, e = kt) {
656
- let n;
657
- const o = /* @__PURE__ */ new Set();
658
- function i(r) {
659
- if (xn(t, r) && (t = r, n)) {
660
- const l = !Z.length;
661
- for (const d of o)
662
- d[1](), Z.push(d, t);
663
- if (l) {
664
- for (let d = 0; d < Z.length; d += 2)
665
- Z[d][0](Z[d + 1]);
666
- Z.length = 0;
667
- }
668
- }
669
- }
670
- function s(r) {
671
- i(r(t));
672
- }
673
- function a(r, l = kt) {
674
- const d = [r, l];
675
- return o.add(d), o.size === 1 && (n = e(i, s) || kt), r(t), () => {
676
- o.delete(d), o.size === 0 && n && (n(), n = null);
677
- };
678
- }
679
- return { set: i, update: s, subscribe: a };
680
- }
681
- const En = (t) => {
682
- const { subscribe: e, set: n } = Ht();
683
- let o;
684
- return e((i) => o = i), t.observe(({ changes: i }) => {
685
- if (o) {
686
- (i.deleted || []).some((a) => a.id === o) && n(void 0);
687
- const s = (i.updated || []).find(({ oldValue: a }) => a.id === o);
688
- s && n(s.newValue.id);
689
- }
690
- }), {
691
- get current() {
692
- return o;
693
- },
694
- subscribe: e,
695
- set: n
696
- };
697
- };
698
- var vn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(vn || {});
699
- const yt = { selected: [] }, Sn = (t, e, n) => {
700
- const { subscribe: o, set: i } = Ht(yt);
701
- let s = e, a = yt;
702
- o((p) => a = p);
703
- const r = () => {
704
- J(a, yt) || i(yt);
705
- }, l = () => {
706
- var p;
707
- return ((p = a.selected) == null ? void 0 : p.length) === 0;
708
- }, d = (p) => {
709
- if (l())
710
- return !1;
711
- const w = typeof p == "string" ? p : p.id;
712
- return a.selected.some((E) => E.id === w);
713
- }, g = (p, w) => {
714
- let E;
715
- if (Array.isArray(p)) {
716
- if (E = p.map((c) => t.getAnnotation(c)).filter(Boolean), E.length < p.length) {
717
- console.warn("Invalid selection: " + p.filter((c) => !E.some((y) => y.id === c)));
718
- return;
719
- }
720
- } else {
721
- const c = t.getAnnotation(p);
722
- if (!c) {
723
- console.warn("Invalid selection: " + p);
724
- return;
725
- }
726
- E = [c];
727
- }
728
- const m = E.reduce((c, y) => {
729
- const S = ie(y, s, n);
730
- return S === "EDIT" ? [...c, { id: y.id, editable: !0 }] : S === "SELECT" ? [...c, { id: y.id }] : c;
731
- }, []);
732
- i({ selected: m, event: w });
733
- }, u = (p, w) => {
734
- const E = Array.isArray(p) ? p : [p], m = E.map((c) => t.getAnnotation(c)).filter((c) => !!c);
735
- i({
736
- selected: m.map((c) => {
737
- const y = w === void 0 ? ie(c, s, n) === "EDIT" : w;
738
- return { id: c.id, editable: y };
739
- })
740
- }), m.length !== E.length && console.warn("Invalid selection", p);
741
- }, h = (p) => {
742
- if (l())
743
- return !1;
744
- const { selected: w } = a;
745
- w.some(({ id: E }) => p.includes(E)) && i({ selected: w.filter(({ id: E }) => !p.includes(E)) });
746
- }, x = (p) => {
747
- s = p, u(a.selected.map(({ id: w }) => w));
748
- };
749
- return t.observe(
750
- ({ changes: p }) => h((p.deleted || []).map((w) => w.id))
751
- ), {
752
- get event() {
753
- return a ? a.event : null;
754
- },
755
- get selected() {
756
- return a ? [...a.selected] : null;
757
- },
758
- get userSelectAction() {
759
- return s;
760
- },
761
- clear: r,
762
- isEmpty: l,
763
- isSelected: d,
764
- setSelected: u,
765
- setUserSelectAction: x,
766
- subscribe: o,
767
- userSelect: g
768
- };
769
- }, ie = (t, e, n) => {
770
- const o = n ? n.serialize(t) : t;
771
- return typeof e == "function" ? e(o) : e || "EDIT";
772
- }, K = [];
773
- for (let t = 0; t < 256; ++t)
774
- K.push((t + 256).toString(16).slice(1));
775
- function Cn(t, e = 0) {
776
- return (K[t[e + 0]] + K[t[e + 1]] + K[t[e + 2]] + K[t[e + 3]] + "-" + K[t[e + 4]] + K[t[e + 5]] + "-" + K[t[e + 6]] + K[t[e + 7]] + "-" + K[t[e + 8]] + K[t[e + 9]] + "-" + K[t[e + 10]] + K[t[e + 11]] + K[t[e + 12]] + K[t[e + 13]] + K[t[e + 14]] + K[t[e + 15]]).toLowerCase();
777
- }
778
- let It;
779
- const Ln = new Uint8Array(16);
780
- function Tn() {
781
- if (!It) {
782
- if (typeof crypto > "u" || !crypto.getRandomValues)
783
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
784
- It = crypto.getRandomValues.bind(crypto);
785
- }
786
- return It(Ln);
787
- }
788
- const On = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), se = { randomUUID: On };
789
- function we(t, e, n) {
790
- var o;
791
- if (se.randomUUID && !t)
792
- return se.randomUUID();
793
- t = t || {};
794
- const i = t.random ?? ((o = t.rng) == null ? void 0 : o.call(t)) ?? Tn();
795
- if (i.length < 16)
796
- throw new Error("Random bytes length must be >= 16");
797
- return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, Cn(i);
798
- }
799
- const Nt = (t) => {
800
- const e = (n) => {
801
- const o = { ...n };
802
- return n.created && typeof n.created == "string" && (o.created = new Date(n.created)), n.updated && typeof n.updated == "string" && (o.updated = new Date(n.updated)), o;
803
- };
804
- return {
805
- ...t,
806
- bodies: (t.bodies || []).map(e),
807
- target: e(t.target)
808
- };
809
- }, Io = (t, e, n, o) => ({
810
- id: we(),
811
- annotation: typeof t == "string" ? t : t.id,
812
- created: n || /* @__PURE__ */ new Date(),
813
- creator: o,
814
- ...e
815
- }), Rn = (t, e) => {
816
- const n = new Set(t.bodies.map((o) => o.id));
817
- return e.bodies.filter((o) => !n.has(o.id));
818
- }, Mn = (t, e) => {
819
- const n = new Set(e.bodies.map((o) => o.id));
820
- return t.bodies.filter((o) => !n.has(o.id));
821
- }, Bn = (t, e) => e.bodies.map((n) => {
822
- const o = t.bodies.find((i) => i.id === n.id);
823
- return { newBody: n, oldBody: o && !J(o, n) ? o : void 0 };
824
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), kn = (t, e) => !J(t.target, e.target), Ae = (t, e) => {
825
- const n = Rn(t, e), o = Mn(t, e), i = Bn(t, e);
826
- return {
827
- oldValue: t,
828
- newValue: e,
829
- bodiesCreated: n.length > 0 ? n : void 0,
830
- bodiesDeleted: o.length > 0 ? o : void 0,
831
- bodiesUpdated: i.length > 0 ? i : void 0,
832
- targetUpdated: kn(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
833
- };
834
- };
835
- var k = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(k || {});
836
- const In = (t, e) => {
837
- var n, o;
838
- const { changes: i, origin: s } = e;
839
- if (!(t.options.origin ? t.options.origin === s : s !== "SILENT"))
840
- return !1;
841
- if (t.options.ignore) {
842
- const { ignore: a } = t.options, r = (l) => l && l.length > 0;
843
- if (!(r(i.created) || r(i.deleted))) {
844
- const l = (n = i.updated) == null ? void 0 : n.some((g) => r(g.bodiesCreated) || r(g.bodiesDeleted) || r(g.bodiesUpdated)), d = (o = i.updated) == null ? void 0 : o.some((g) => g.targetUpdated);
845
- if (a === "BODY_ONLY" && l && !d || a === "TARGET_ONLY" && d && !l)
846
- return !1;
847
- }
848
- }
849
- if (t.options.annotations) {
850
- const a = /* @__PURE__ */ new Set([
851
- ...(i.created || []).map((r) => r.id),
852
- ...(i.deleted || []).map((r) => r.id),
853
- ...(i.updated || []).map(({ oldValue: r }) => r.id)
854
- ]);
855
- return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((r) => a.has(r));
856
- } else
857
- return !0;
858
- }, Nn = (t, e) => {
859
- const n = new Set((t.created || []).map((u) => u.id)), o = new Set((t.updated || []).map(({ newValue: u }) => u.id)), i = new Set((e.created || []).map((u) => u.id)), s = new Set((e.deleted || []).map((u) => u.id)), a = new Set((e.updated || []).map(({ oldValue: u }) => u.id)), r = new Set((e.updated || []).filter(({ oldValue: u }) => n.has(u.id) || o.has(u.id)).map(({ oldValue: u }) => u.id)), l = [
860
- ...(t.created || []).filter((u) => !s.has(u.id)).map((u) => a.has(u.id) ? e.updated.find(({ oldValue: h }) => h.id === u.id).newValue : u),
861
- ...e.created || []
862
- ], d = [
863
- ...(t.deleted || []).filter((u) => !i.has(u.id)),
864
- ...(e.deleted || []).filter((u) => !n.has(u.id))
865
- ], g = [
866
- ...(t.updated || []).filter(({ newValue: u }) => !s.has(u.id)).map((u) => {
867
- const { oldValue: h, newValue: x } = u;
868
- if (a.has(x.id)) {
869
- const p = e.updated.find((w) => w.oldValue.id === x.id).newValue;
870
- return Ae(h, p);
871
- } else
872
- return u;
873
- }),
874
- ...(e.updated || []).filter(({ oldValue: u }) => !r.has(u.id))
875
- ];
876
- return { created: l, deleted: d, updated: g };
877
- }, bt = (t) => {
878
- const e = t.id === void 0 ? we() : t.id;
879
- return {
880
- ...t,
881
- id: e,
882
- bodies: t.bodies === void 0 ? [] : t.bodies.map((n) => ({
883
- ...n,
884
- annotation: e
885
- })),
886
- target: {
887
- ...t.target,
888
- annotation: e
889
- }
890
- };
891
- }, _n = (t) => t.id !== void 0, Un = () => {
892
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (f, b = {}) => {
893
- n.push({ onChange: f, options: b });
894
- }, i = (f) => {
895
- const b = n.findIndex((A) => A.onChange == f);
896
- b > -1 && n.splice(b, 1);
897
- }, s = (f, b) => {
898
- const A = {
899
- origin: f,
900
- changes: {
901
- created: b.created || [],
902
- updated: b.updated || [],
903
- deleted: b.deleted || []
904
- },
905
- state: [...t.values()]
906
- };
907
- n.forEach((C) => {
908
- In(C, A) && C.onChange(A);
909
- });
910
- }, a = (f, b = k.LOCAL) => {
911
- if (f.id && t.get(f.id))
912
- throw Error(`Cannot add annotation ${f.id} - exists already`);
913
- {
914
- const A = bt(f);
915
- t.set(A.id, A), A.bodies.forEach((C) => e.set(C.id, A.id)), s(b, { created: [A] });
916
- }
917
- }, r = (f, b) => {
918
- const A = bt(typeof f == "string" ? b : f), C = typeof f == "string" ? f : f.id, B = C && t.get(C);
919
- if (B) {
920
- const O = Ae(B, A);
921
- return C === A.id ? t.set(C, A) : (t.delete(C), t.set(A.id, A)), B.bodies.forEach((I) => e.delete(I.id)), A.bodies.forEach((I) => e.set(I.id, A.id)), O;
922
- } else
923
- console.warn(`Cannot update annotation ${C} - does not exist`);
924
- }, l = (f, b = k.LOCAL, A = k.LOCAL) => {
925
- const C = _n(b) ? A : b, B = r(f, b);
926
- B && s(C, { updated: [B] });
927
- }, d = (f, b = k.LOCAL) => {
928
- t.get(f.id) ? l(f, b) : a(f, b);
929
- }, g = (f, b = k.LOCAL) => {
930
- const A = f.reduce((C, B) => {
931
- const O = r(B);
932
- return O ? [...C, O] : C;
933
- }, []);
934
- A.length > 0 && s(b, { updated: A });
935
- }, u = (f, b = k.LOCAL) => {
936
- const A = f.map(bt), { toAdd: C, toUpdate: B } = A.reduce((I, V) => t.get(V.id) ? { ...I, toUpdate: [...I.toUpdate, V] } : { ...I, toAdd: [...I.toAdd, V] }, { toAdd: [], toUpdate: [] }), O = B.map((I) => r(I, b)).filter(Boolean);
937
- C.forEach((I) => {
938
- t.set(I.id, I), I.bodies.forEach((V) => e.set(V.id, I.id));
939
- }), s(b, { created: C, updated: O });
940
- }, h = (f, b = k.LOCAL) => {
941
- const A = t.get(f.annotation);
942
- if (A) {
943
- const C = {
944
- ...A,
945
- bodies: [...A.bodies, f]
946
- };
947
- t.set(A.id, C), e.set(f.id, C.id), s(b, { updated: [{
948
- oldValue: A,
949
- newValue: C,
950
- bodiesCreated: [f]
951
- }] });
952
- } else
953
- console.warn(`Attempt to add body to missing annotation: ${f.annotation}`);
954
- }, x = () => [...t.values()], p = (f = k.LOCAL) => {
955
- const b = [...t.values()];
956
- t.clear(), e.clear(), s(f, { deleted: b });
957
- }, w = (f, b = !0, A = k.LOCAL) => {
958
- const C = f.map(bt);
959
- if (b) {
960
- const B = [...t.values()];
961
- t.clear(), e.clear(), C.forEach((O) => {
962
- t.set(O.id, O), O.bodies.forEach((I) => e.set(I.id, O.id));
963
- }), s(A, { created: C, deleted: B });
964
- } else {
965
- const B = f.reduce((O, I) => {
966
- const V = I.id && t.get(I.id);
967
- return V ? [...O, V] : O;
968
- }, []);
969
- if (B.length > 0)
970
- throw Error(`Bulk insert would overwrite the following annotations: ${B.map((O) => O.id).join(", ")}`);
971
- C.forEach((O) => {
972
- t.set(O.id, O), O.bodies.forEach((I) => e.set(I.id, O.id));
973
- }), s(A, { created: C });
974
- }
975
- }, E = (f) => {
976
- const b = typeof f == "string" ? f : f.id, A = t.get(b);
977
- if (A)
978
- return t.delete(b), A.bodies.forEach((C) => e.delete(C.id)), A;
979
- console.warn(`Attempt to delete missing annotation: ${b}`);
980
- }, m = (f, b = k.LOCAL) => {
981
- const A = E(f);
982
- A && s(b, { deleted: [A] });
983
- }, c = (f, b = k.LOCAL) => {
984
- const A = f.reduce((C, B) => {
985
- const O = E(B);
986
- return O ? [...C, O] : C;
987
- }, []);
988
- A.length > 0 && s(b, { deleted: A });
989
- }, y = (f) => {
990
- const b = t.get(f.annotation);
991
- if (b) {
992
- const A = b.bodies.find((C) => C.id === f.id);
993
- if (A) {
994
- e.delete(A.id);
995
- const C = {
996
- ...b,
997
- bodies: b.bodies.filter((B) => B.id !== f.id)
998
- };
999
- return t.set(b.id, C), {
1000
- oldValue: b,
1001
- newValue: C,
1002
- bodiesDeleted: [A]
1003
- };
1004
- } else
1005
- console.warn(`Attempt to delete missing body ${f.id} from annotation ${f.annotation}`);
1006
- } else
1007
- console.warn(`Attempt to delete body from missing annotation ${f.annotation}`);
1008
- }, S = (f, b = k.LOCAL) => {
1009
- const A = y(f);
1010
- A && s(b, { updated: [A] });
1011
- }, v = (f, b = k.LOCAL) => {
1012
- const A = f.map((C) => y(C)).filter(Boolean);
1013
- A.length > 0 && s(b, { updated: A });
1014
- }, L = (f) => {
1015
- const b = t.get(f);
1016
- return b ? { ...b } : void 0;
1017
- }, R = (f) => {
1018
- const b = e.get(f);
1019
- if (b) {
1020
- const A = L(b).bodies.find((C) => C.id === f);
1021
- if (A)
1022
- return A;
1023
- console.error(`Store integrity error: body ${f} in index, but not in annotation`);
1024
- } else
1025
- console.warn(`Attempt to retrieve missing body: ${f}`);
1026
- }, T = (f, b) => {
1027
- if (f.annotation !== b.annotation)
1028
- throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
1029
- const A = t.get(f.annotation);
1030
- if (A) {
1031
- const C = A.bodies.find((O) => O.id === f.id), B = {
1032
- ...A,
1033
- bodies: A.bodies.map((O) => O.id === C.id ? b : O)
1034
- };
1035
- return t.set(A.id, B), C.id !== b.id && (e.delete(C.id), e.set(b.id, B.id)), {
1036
- oldValue: A,
1037
- newValue: B,
1038
- bodiesUpdated: [{ oldBody: C, newBody: b }]
1039
- };
1040
- } else
1041
- console.warn(`Attempt to add body to missing annotation ${f.annotation}`);
1042
- }, M = (f, b, A = k.LOCAL) => {
1043
- const C = T(f, b);
1044
- C && s(A, { updated: [C] });
1045
- }, _ = (f, b = k.LOCAL) => {
1046
- const A = f.map((C) => T({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
1047
- s(b, { updated: A });
1048
- }, X = (f) => {
1049
- const b = t.get(f.annotation);
1050
- if (b) {
1051
- const A = {
1052
- ...b,
1053
- target: {
1054
- ...b.target,
1055
- ...f
1056
- }
1057
- };
1058
- return t.set(b.id, A), {
1059
- oldValue: b,
1060
- newValue: A,
1061
- targetUpdated: {
1062
- oldTarget: b.target,
1063
- newTarget: f
1064
- }
1065
- };
1066
- } else
1067
- console.warn(`Attempt to update target on missing annotation: ${f.annotation}`);
1068
- };
1069
- return {
1070
- addAnnotation: a,
1071
- addBody: h,
1072
- all: x,
1073
- bulkAddAnnotations: w,
1074
- bulkDeleteAnnotations: c,
1075
- bulkDeleteBodies: v,
1076
- bulkUpdateAnnotations: g,
1077
- bulkUpdateBodies: _,
1078
- bulkUpdateTargets: (f, b = k.LOCAL) => {
1079
- const A = f.map((C) => X(C)).filter(Boolean);
1080
- A.length > 0 && s(b, { updated: A });
1081
- },
1082
- bulkUpsertAnnotations: u,
1083
- clear: p,
1084
- deleteAnnotation: m,
1085
- deleteBody: S,
1086
- getAnnotation: L,
1087
- getBody: R,
1088
- observe: o,
1089
- unobserve: i,
1090
- updateAnnotation: l,
1091
- updateBody: M,
1092
- updateTarget: (f, b = k.LOCAL) => {
1093
- const A = X(f);
1094
- A && s(b, { updated: [A] });
1095
- },
1096
- upsertAnnotation: d
1097
- };
1098
- };
1099
- let Dn = () => ({
1100
- emit(t, ...e) {
1101
- for (let n = this.events[t] || [], o = 0, i = n.length; o < i; o++)
1102
- n[o](...e);
1103
- },
1104
- events: {},
1105
- on(t, e) {
1106
- var n;
1107
- return ((n = this.events)[t] || (n[t] = [])).push(e), () => {
1108
- var o;
1109
- this.events[t] = (o = this.events[t]) == null ? void 0 : o.filter((i) => e !== i);
1110
- };
1111
- }
1112
- });
1113
- const Vn = 250, Yn = (t, e) => {
1114
- const n = Dn(), o = [];
1115
- let i = -1, s = !1, a = 0;
1116
- const r = (p) => {
1117
- if (!s) {
1118
- const { changes: w } = p, E = performance.now();
1119
- if (E - a > Vn)
1120
- o.splice(i + 1), o.push(w), i = o.length - 1;
1121
- else {
1122
- const m = o.length - 1;
1123
- o[m] = Nn(o[m], w);
1124
- }
1125
- a = E;
1126
- }
1127
- s = !1;
1128
- };
1129
- t.observe(r, { origin: k.LOCAL });
1130
- const l = (p) => p && p.length > 0 && t.bulkDeleteAnnotations(p), d = (p) => p && p.length > 0 && t.bulkAddAnnotations(p, !1), g = (p) => p && p.length > 0 && t.bulkUpdateAnnotations(p.map(({ oldValue: w }) => w)), u = (p) => p && p.length > 0 && t.bulkUpdateAnnotations(p.map(({ newValue: w }) => w)), h = (p) => p && p.length > 0 && t.bulkAddAnnotations(p, !1), x = (p) => p && p.length > 0 && t.bulkDeleteAnnotations(p);
1131
- return {
1132
- canRedo: () => o.length - 1 > i,
1133
- canUndo: () => i > -1,
1134
- destroy: () => t.unobserve(r),
1135
- getHistory: () => ({ changes: [...o], pointer: i }),
1136
- on: (p, w) => n.on(p, w),
1137
- redo: () => {
1138
- if (o.length - 1 > i) {
1139
- s = !0;
1140
- const { created: p, updated: w, deleted: E } = o[i + 1];
1141
- d(p), u(w), x(E), n.emit("redo", o[i + 1]), i += 1;
1142
- }
1143
- },
1144
- undo: () => {
1145
- if (i > -1) {
1146
- s = !0;
1147
- const { created: p, updated: w, deleted: E } = o[i];
1148
- l(p), g(w), h(E), n.emit("undo", o[i]), i -= 1;
1149
- }
1150
- }
1151
- };
1152
- }, Kn = () => {
1153
- const { subscribe: t, set: e } = Ht([]);
1154
- return {
1155
- subscribe: t,
1156
- set: e
1157
415
  };
1158
- }, Pn = (t, e, n, o) => {
1159
- const { hover: i, selection: s, store: a, viewport: r } = t, l = /* @__PURE__ */ new Map();
1160
- let d = [], g;
1161
- const u = (w, E) => {
1162
- l.has(w) ? l.get(w).push(E) : l.set(w, [E]);
1163
- }, h = (w, E) => {
1164
- const m = l.get(w);
1165
- if (m) {
1166
- const c = m.indexOf(E);
1167
- c !== -1 && m.splice(c, 1);
1168
- }
1169
- }, x = (w, E, m) => {
1170
- l.has(w) && setTimeout(() => {
1171
- l.get(w).forEach((c) => {
1172
- if (n) {
1173
- const y = Array.isArray(E) ? E.map((v) => n.serialize(v)) : n.serialize(E), S = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
1174
- c(y, S);
1175
- } else
1176
- c(E, m);
1177
- });
1178
- }, 1);
1179
- };
1180
- s.subscribe(({ selected: w }) => {
1181
- if (!(d.length === 0 && w.length === 0)) {
1182
- if (d.length === 0 && w.length > 0)
1183
- d = w.map(({ id: E }) => a.getAnnotation(E));
1184
- else if (d.length > 0 && w.length === 0)
1185
- d.forEach((E) => {
1186
- const m = a.getAnnotation(E.id);
1187
- m && !J(m, E) && x("updateAnnotation", m, E);
1188
- }), d = [];
1189
- else {
1190
- const E = new Set(d.map((c) => c.id)), m = new Set(w.map(({ id: c }) => c));
1191
- d.filter((c) => !m.has(c.id)).forEach((c) => {
1192
- const y = a.getAnnotation(c.id);
1193
- y && !J(y, c) && x("updateAnnotation", y, c);
1194
- }), d = [
1195
- // Remove annotations that were deselected
1196
- ...d.filter((c) => m.has(c.id)),
1197
- // Add editable annotations that were selected
1198
- ...w.filter(({ id: c }) => !E.has(c)).map(({ id: c }) => a.getAnnotation(c))
1199
- ];
1200
- }
1201
- x("selectionChanged", d);
1202
- }
1203
- }), i.subscribe((w) => {
1204
- !g && w ? x("mouseEnterAnnotation", a.getAnnotation(w)) : g && !w ? x("mouseLeaveAnnotation", a.getAnnotation(g)) : g && w && (x("mouseLeaveAnnotation", a.getAnnotation(g)), x("mouseEnterAnnotation", a.getAnnotation(w))), g = w;
1205
- }), r == null || r.subscribe((w) => x("viewportIntersect", w.map((E) => a.getAnnotation(E)))), a.observe((w) => {
1206
- const { created: E, deleted: m } = w.changes;
1207
- (E || []).forEach((c) => x("createAnnotation", c)), (m || []).forEach((c) => x("deleteAnnotation", c)), (w.changes.updated || []).filter((c) => [
1208
- ...c.bodiesCreated || [],
1209
- ...c.bodiesDeleted || [],
1210
- ...c.bodiesUpdated || []
1211
- ].length > 0).forEach(({ oldValue: c, newValue: y }) => {
1212
- const S = d.find((v) => v.id === c.id) || c;
1213
- d = d.map((v) => v.id === c.id ? y : v), x("updateAnnotation", y, S);
1214
- });
1215
- }, { origin: k.LOCAL }), a.observe((w) => {
1216
- if (d) {
1217
- const E = new Set(d.map((c) => c.id)), m = (w.changes.updated || []).filter(({ newValue: c }) => E.has(c.id)).map(({ newValue: c }) => c);
1218
- m.length > 0 && (d = d.map((c) => m.find((S) => S.id === c.id) || c));
1219
- }
1220
- }, { origin: k.REMOTE });
1221
- const p = (w) => (E) => {
1222
- const { updated: m } = E;
1223
- w ? (m || []).forEach((c) => x("updateAnnotation", c.oldValue, c.newValue)) : (m || []).forEach((c) => x("updateAnnotation", c.newValue, c.oldValue));
1224
- };
1225
- return e.on("undo", p(!0)), e.on("redo", p(!1)), { on: u, off: h, emit: x };
1226
- }, Xn = (t) => (e) => e.reduce((n, o) => {
1227
- const { parsed: i, error: s } = t.parse(o);
1228
- return s ? {
1229
- parsed: n.parsed,
1230
- failed: [...n.failed, o]
1231
- } : i ? {
1232
- parsed: [...n.parsed, i],
1233
- failed: n.failed
1234
- } : {
1235
- ...n
1236
- };
1237
- }, { parsed: [], failed: [] }), $n = (t, e, n) => {
1238
- const { store: o, selection: i } = t, s = (m) => {
1239
- if (n) {
1240
- const { parsed: c, error: y } = n.parse(m);
1241
- c ? o.addAnnotation(c, k.REMOTE) : console.error(y);
1242
- } else
1243
- o.addAnnotation(Nt(m), k.REMOTE);
1244
- }, a = () => i.clear(), r = () => o.clear(), l = (m) => {
1245
- const c = o.getAnnotation(m);
1246
- return n && c ? n.serialize(c) : c;
1247
- }, d = () => n ? o.all().map(n.serialize) : o.all(), g = () => {
1248
- var m;
1249
- const c = (((m = i.selected) == null ? void 0 : m.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1250
- return n ? c.map(n.serialize) : c;
1251
- }, u = (m, c = !0) => fetch(m).then((y) => y.json()).then((y) => (x(y, c), y)), h = (m) => {
1252
- if (typeof m == "string") {
1253
- const c = o.getAnnotation(m);
1254
- if (o.deleteAnnotation(m), c)
1255
- return n ? n.serialize(c) : c;
1256
- } else {
1257
- const c = n ? n.parse(m).parsed : m;
1258
- if (c)
1259
- return o.deleteAnnotation(c), m;
1260
- }
1261
- }, x = (m, c = !0) => {
1262
- if (n) {
1263
- const y = n.parseAll || Xn(n), { parsed: S, failed: v } = y(m);
1264
- v.length > 0 && console.warn(`Discarded ${v.length} invalid annotations`, v), o.bulkAddAnnotations(S, c, k.REMOTE);
1265
- } else
1266
- o.bulkAddAnnotations(m.map(Nt), c, k.REMOTE);
1267
- }, p = (m, c) => {
1268
- m ? i.setSelected(m, c) : i.clear();
1269
- }, w = (m) => {
1270
- i.clear(), i.setUserSelectAction(m);
1271
- }, E = (m) => {
1272
- if (n) {
1273
- const c = n.parse(m).parsed, y = n.serialize(o.getAnnotation(c.id));
1274
- return o.updateAnnotation(c), y;
1275
- } else {
1276
- const c = o.getAnnotation(m.id);
1277
- return o.updateAnnotation(Nt(m)), c;
1278
- }
1279
- };
1280
- return {
1281
- addAnnotation: s,
1282
- cancelSelected: a,
1283
- canRedo: e.canRedo,
1284
- canUndo: e.canUndo,
1285
- clearAnnotations: r,
1286
- getAnnotationById: l,
1287
- getAnnotations: d,
1288
- getHistory: e.getHistory,
1289
- getSelected: g,
1290
- loadAnnotations: u,
1291
- redo: e.redo,
1292
- removeAnnotation: h,
1293
- setAnnotations: x,
1294
- setSelected: p,
1295
- setUserSelectAction: w,
1296
- undo: e.undo,
1297
- updateAnnotation: E
1298
- };
1299
- }, Hn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1300
- let jn = (t) => crypto.getRandomValues(new Uint8Array(t)), zn = (t, e, n) => {
1301
- let o = (2 << Math.log2(t.length - 1)) - 1, i = -~(1.6 * o * e / t.length);
1302
- return (s = e) => {
1303
- let a = "";
1304
- for (; ; ) {
1305
- let r = n(i), l = i | 0;
1306
- for (; l--; )
1307
- if (a += t[r[l] & o] || "", a.length >= s) return a;
1308
- }
1309
- };
1310
- }, Fn = (t, e = 21) => zn(t, e | 0, jn), Wn = (t = 21) => {
1311
- let e = "", n = crypto.getRandomValues(new Uint8Array(t |= 0));
1312
- for (; t--; )
1313
- e += Hn[n[t] & 63];
1314
- return e;
1315
- };
1316
- const qn = () => ({ isGuest: !0, id: Fn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Gn = (t) => {
1317
- const e = JSON.stringify(t);
1318
- let n = 0;
1319
- for (let o = 0, i = e.length; o < i; o++) {
1320
- let s = e.charCodeAt(o);
1321
- n = (n << 5) - n + s, n |= 0;
1322
- }
1323
- return `${n}`;
1324
- }, xe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Qn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1325
- const { id: o, type: i, purpose: s, value: a, created: r, modified: l, creator: d, ...g } = n;
1326
- return {
1327
- id: o || `temp-${Gn(n)}`,
1328
- annotation: e,
1329
- type: i,
1330
- purpose: s,
1331
- value: a,
1332
- creator: xe(d),
1333
- created: r ? new Date(r) : void 0,
1334
- updated: l ? new Date(l) : void 0,
1335
- ...g
1336
- };
1337
- }), Jn = (t) => t.map((e) => {
1338
- var n;
1339
- const { annotation: o, created: i, updated: s, ...a } = e, r = {
1340
- ...a,
1341
- created: i == null ? void 0 : i.toISOString(),
1342
- modified: s == null ? void 0 : s.toISOString()
1343
- };
1344
- return (n = r.id) != null && n.startsWith("temp-") && delete r.id, r;
1345
- });
1346
- Wn();
1347
- const No = (t, e) => ({
1348
- parse: (n) => eo(n),
1349
- serialize: (n) => no(n, t, e)
1350
- }), Zn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, to = (t) => {
416
+ }, te = (t, n, e) => Z(t, n, e, Jt(t)), Ae = (t, n) => ({
417
+ parse: (e) => oe(e),
418
+ serialize: (e) => se(e, t, n)
419
+ }), ee = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, ne = (t) => {
1351
420
  const {
1352
- id: e,
1353
- creator: n,
421
+ id: n,
422
+ creator: e,
1354
423
  created: o,
1355
- modified: i,
1356
- target: s
1357
- } = t, a = Array.isArray(s) ? s : [s];
424
+ modified: s,
425
+ target: i
426
+ } = t, a = Array.isArray(i) ? i : [i];
1358
427
  if (a.length === 0)
1359
428
  return { error: Error(`No targets found for annotation: ${t.id}`) };
1360
- const r = {
1361
- creator: xe(n),
429
+ const c = {
430
+ creator: gt(e),
1362
431
  created: o ? new Date(o) : void 0,
1363
- updated: i ? new Date(i) : void 0,
1364
- annotation: e,
432
+ updated: s ? new Date(s) : void 0,
433
+ annotation: n,
1365
434
  selector: [],
1366
435
  // @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
1367
436
  styleClass: "styleClass" in a[0] ? a[0].styleClass : void 0
1368
437
  };
1369
- for (const l of a) {
1370
- const g = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((u, h) => {
1371
- switch (h.type) {
438
+ for (const u of a) {
439
+ const y = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((g, r) => {
440
+ switch (r.type) {
1372
441
  case "TextQuoteSelector":
1373
- u.quote = h.exact;
442
+ g.quote = r.exact;
1374
443
  break;
1375
444
  case "TextPositionSelector":
1376
- u.start = h.start, u.end = h.end;
445
+ g.start = r.start, g.end = r.end;
1377
446
  break;
1378
447
  }
1379
- return u;
448
+ return g;
1380
449
  }, {});
1381
- if (r.outdated || (r.outdated = "outdated" in l ? l.outdated : void 0), Zn(g))
1382
- r.selector.push(
450
+ if (c.outdated || (c.outdated = "outdated" in u ? u.outdated : void 0), ee(y))
451
+ c.selector.push(
1383
452
  {
1384
- ...g,
1385
- id: l.id,
453
+ ...y,
454
+ id: u.id,
1386
455
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1387
- scope: l.scope
456
+ scope: u.scope
1388
457
  }
1389
458
  );
1390
459
  else {
1391
- const u = [
1392
- g.start ? void 0 : "TextPositionSelector",
1393
- g.quote ? void 0 : "TextQuoteSelector"
460
+ const g = [
461
+ y.start ? void 0 : "TextPositionSelector",
462
+ y.quote ? void 0 : "TextQuoteSelector"
1394
463
  ].filter(Boolean);
1395
- return { error: Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`) };
464
+ return { error: Error(`Missing selector types: ${g.join(" and ")} for annotation: ${t.id}`) };
1396
465
  }
1397
466
  }
1398
- return { parsed: r };
1399
- }, eo = (t) => {
1400
- const e = t.id || be(), {
1401
- creator: n,
467
+ return { parsed: c };
468
+ }, oe = (t) => {
469
+ const n = t.id || ot(), {
470
+ creator: e,
1402
471
  created: o,
1403
- modified: i,
1404
- body: s,
472
+ modified: s,
473
+ body: i,
1405
474
  ...a
1406
- } = t, r = Qn(s, e), l = to(t);
1407
- return "error" in l ? { error: l.error } : {
475
+ } = t, c = ft(i, n), u = ne(t);
476
+ return "error" in u ? { error: u.error } : {
1408
477
  parsed: {
1409
478
  ...a,
1410
- id: e,
1411
- bodies: r,
1412
- target: l.parsed
479
+ id: n,
480
+ bodies: c,
481
+ target: u.parsed
1413
482
  }
1414
483
  };
1415
- }, no = (t, e, n) => {
1416
- const { bodies: o, target: i, ...s } = t, {
484
+ }, se = (t, n, e) => {
485
+ const { bodies: o, target: s, ...i } = t, {
1417
486
  selector: a,
1418
- creator: r,
1419
- created: l,
1420
- updated: d,
1421
- ...g
1422
- } = i, u = a.map((h) => {
1423
- const { id: x, quote: p, start: w, end: E, range: m } = h, c = {
487
+ creator: c,
488
+ created: u,
489
+ updated: b,
490
+ ...y
491
+ } = s, g = a.map((r) => {
492
+ const { id: A, quote: S, start: T, end: x, range: C } = r, m = {
1424
493
  type: "TextQuoteSelector",
1425
- exact: p
494
+ exact: S
1426
495
  };
1427
- if (n) {
1428
- const { prefix: S, suffix: v } = Ue(m, n);
1429
- c.prefix = S, c.suffix = v;
496
+ if (e) {
497
+ const { prefix: f, suffix: l } = Nt(C, e);
498
+ m.prefix = f, m.suffix = l;
1430
499
  }
1431
- const y = {
500
+ const d = {
1432
501
  type: "TextPositionSelector",
1433
- start: w,
1434
- end: E
502
+ start: T,
503
+ end: x
1435
504
  };
1436
505
  return {
1437
- ...g,
1438
- id: x,
506
+ ...y,
507
+ id: A,
1439
508
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1440
- scope: "scope" in h ? h.scope : void 0,
1441
- source: e,
1442
- selector: [c, y]
509
+ scope: "scope" in r ? r.scope : void 0,
510
+ source: n,
511
+ selector: [m, d]
1443
512
  };
1444
513
  });
1445
514
  return {
1446
- ...s,
515
+ ...i,
1447
516
  "@context": "http://www.w3.org/ns/anno.jsonld",
1448
517
  id: t.id,
1449
518
  type: "Annotation",
1450
- body: Jn(t.bodies),
1451
- creator: r,
1452
- created: l == null ? void 0 : l.toISOString(),
1453
- modified: d == null ? void 0 : d.toISOString(),
1454
- target: u
1455
- };
1456
- };
1457
- function Ee(t, e, n = 0, o = t.length - 1, i = oo) {
1458
- for (; o > n; ) {
1459
- if (o - n > 600) {
1460
- const l = o - n + 1, d = e - n + 1, g = Math.log(l), u = 0.5 * Math.exp(2 * g / 3), h = 0.5 * Math.sqrt(g * u * (l - u) / l) * (d - l / 2 < 0 ? -1 : 1), x = Math.max(n, Math.floor(e - d * u / l + h)), p = Math.min(o, Math.floor(e + (l - d) * u / l + h));
1461
- Ee(t, e, x, p, i);
1462
- }
1463
- const s = t[e];
1464
- let a = n, r = o;
1465
- for (it(t, n, e), i(t[o], s) > 0 && it(t, n, o); a < r; ) {
1466
- for (it(t, a, r), a++, r--; i(t[a], s) < 0; ) a++;
1467
- for (; i(t[r], s) > 0; ) r--;
1468
- }
1469
- i(t[n], s) === 0 ? it(t, n, r) : (r++, it(t, r, o)), r <= e && (n = r + 1), e <= r && (o = r - 1);
1470
- }
1471
- }
1472
- function it(t, e, n) {
1473
- const o = t[e];
1474
- t[e] = t[n], t[n] = o;
1475
- }
1476
- function oo(t, e) {
1477
- return t < e ? -1 : t > e ? 1 : 0;
1478
- }
1479
- class io {
1480
- constructor(e = 9) {
1481
- this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
1482
- }
1483
- all() {
1484
- return this._all(this.data, []);
1485
- }
1486
- search(e) {
1487
- let n = this.data;
1488
- const o = [];
1489
- if (!At(e, n)) return o;
1490
- const i = this.toBBox, s = [];
1491
- for (; n; ) {
1492
- for (let a = 0; a < n.children.length; a++) {
1493
- const r = n.children[a], l = n.leaf ? i(r) : r;
1494
- At(e, l) && (n.leaf ? o.push(r) : Ut(e, l) ? this._all(r, o) : s.push(r));
1495
- }
1496
- n = s.pop();
1497
- }
1498
- return o;
1499
- }
1500
- collides(e) {
1501
- let n = this.data;
1502
- if (!At(e, n)) return !1;
1503
- const o = [];
1504
- for (; n; ) {
1505
- for (let i = 0; i < n.children.length; i++) {
1506
- const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
1507
- if (At(e, a)) {
1508
- if (n.leaf || Ut(e, a)) return !0;
1509
- o.push(s);
1510
- }
1511
- }
1512
- n = o.pop();
1513
- }
1514
- return !1;
1515
- }
1516
- load(e) {
1517
- if (!(e && e.length)) return this;
1518
- if (e.length < this._minEntries) {
1519
- for (let o = 0; o < e.length; o++)
1520
- this.insert(e[o]);
1521
- return this;
1522
- }
1523
- let n = this._build(e.slice(), 0, e.length - 1, 0);
1524
- if (!this.data.children.length)
1525
- this.data = n;
1526
- else if (this.data.height === n.height)
1527
- this._splitRoot(this.data, n);
1528
- else {
1529
- if (this.data.height < n.height) {
1530
- const o = this.data;
1531
- this.data = n, n = o;
1532
- }
1533
- this._insert(n, this.data.height - n.height - 1, !0);
1534
- }
1535
- return this;
1536
- }
1537
- insert(e) {
1538
- return e && this._insert(e, this.data.height - 1), this;
1539
- }
1540
- clear() {
1541
- return this.data = et([]), this;
1542
- }
1543
- remove(e, n) {
1544
- if (!e) return this;
1545
- let o = this.data;
1546
- const i = this.toBBox(e), s = [], a = [];
1547
- let r, l, d;
1548
- for (; o || s.length; ) {
1549
- if (o || (o = s.pop(), l = s[s.length - 1], r = a.pop(), d = !0), o.leaf) {
1550
- const g = so(e, o.children, n);
1551
- if (g !== -1)
1552
- return o.children.splice(g, 1), s.push(o), this._condense(s), this;
1553
- }
1554
- !d && !o.leaf && Ut(o, i) ? (s.push(o), a.push(r), r = 0, l = o, o = o.children[0]) : l ? (r++, o = l.children[r], d = !1) : o = null;
1555
- }
1556
- return this;
1557
- }
1558
- toBBox(e) {
1559
- return e;
1560
- }
1561
- compareMinX(e, n) {
1562
- return e.minX - n.minX;
1563
- }
1564
- compareMinY(e, n) {
1565
- return e.minY - n.minY;
1566
- }
1567
- toJSON() {
1568
- return this.data;
1569
- }
1570
- fromJSON(e) {
1571
- return this.data = e, this;
1572
- }
1573
- _all(e, n) {
1574
- const o = [];
1575
- for (; e; )
1576
- e.leaf ? n.push(...e.children) : o.push(...e.children), e = o.pop();
1577
- return n;
1578
- }
1579
- _build(e, n, o, i) {
1580
- const s = o - n + 1;
1581
- let a = this._maxEntries, r;
1582
- if (s <= a)
1583
- return r = et(e.slice(n, o + 1)), tt(r, this.toBBox), r;
1584
- i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = et([]), r.leaf = !1, r.height = i;
1585
- const l = Math.ceil(s / a), d = l * Math.ceil(Math.sqrt(a));
1586
- re(e, n, o, d, this.compareMinX);
1587
- for (let g = n; g <= o; g += d) {
1588
- const u = Math.min(g + d - 1, o);
1589
- re(e, g, u, l, this.compareMinY);
1590
- for (let h = g; h <= u; h += l) {
1591
- const x = Math.min(h + l - 1, u);
1592
- r.children.push(this._build(e, h, x, i - 1));
1593
- }
1594
- }
1595
- return tt(r, this.toBBox), r;
1596
- }
1597
- _chooseSubtree(e, n, o, i) {
1598
- for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1599
- let s = 1 / 0, a = 1 / 0, r;
1600
- for (let l = 0; l < n.children.length; l++) {
1601
- const d = n.children[l], g = _t(d), u = co(e, d) - g;
1602
- u < a ? (a = u, s = g < s ? g : s, r = d) : u === a && g < s && (s = g, r = d);
1603
- }
1604
- n = r || n.children[0];
1605
- }
1606
- return n;
1607
- }
1608
- _insert(e, n, o) {
1609
- const i = o ? e : this.toBBox(e), s = [], a = this._chooseSubtree(i, this.data, n, s);
1610
- for (a.children.push(e), ct(a, i); n >= 0 && s[n].children.length > this._maxEntries; )
1611
- this._split(s, n), n--;
1612
- this._adjustParentBBoxes(i, s, n);
1613
- }
1614
- // split overflowed node into two
1615
- _split(e, n) {
1616
- const o = e[n], i = o.children.length, s = this._minEntries;
1617
- this._chooseSplitAxis(o, s, i);
1618
- const a = this._chooseSplitIndex(o, s, i), r = et(o.children.splice(a, o.children.length - a));
1619
- r.height = o.height, r.leaf = o.leaf, tt(o, this.toBBox), tt(r, this.toBBox), n ? e[n - 1].children.push(r) : this._splitRoot(o, r);
1620
- }
1621
- _splitRoot(e, n) {
1622
- this.data = et([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, tt(this.data, this.toBBox);
1623
- }
1624
- _chooseSplitIndex(e, n, o) {
1625
- let i, s = 1 / 0, a = 1 / 0;
1626
- for (let r = n; r <= o - n; r++) {
1627
- const l = at(e, 0, r, this.toBBox), d = at(e, r, o, this.toBBox), g = lo(l, d), u = _t(l) + _t(d);
1628
- g < s ? (s = g, i = r, a = u < a ? u : a) : g === s && u < a && (a = u, i = r);
1629
- }
1630
- return i || o - n;
1631
- }
1632
- // sorts node children by the best axis for split
1633
- _chooseSplitAxis(e, n, o) {
1634
- const i = e.leaf ? this.compareMinX : ro, s = e.leaf ? this.compareMinY : ao, a = this._allDistMargin(e, n, o, i), r = this._allDistMargin(e, n, o, s);
1635
- a < r && e.children.sort(i);
1636
- }
1637
- // total margin of all possible split distributions where each node is at least m full
1638
- _allDistMargin(e, n, o, i) {
1639
- e.children.sort(i);
1640
- const s = this.toBBox, a = at(e, 0, n, s), r = at(e, o - n, o, s);
1641
- let l = wt(a) + wt(r);
1642
- for (let d = n; d < o - n; d++) {
1643
- const g = e.children[d];
1644
- ct(a, e.leaf ? s(g) : g), l += wt(a);
1645
- }
1646
- for (let d = o - n - 1; d >= n; d--) {
1647
- const g = e.children[d];
1648
- ct(r, e.leaf ? s(g) : g), l += wt(r);
1649
- }
1650
- return l;
1651
- }
1652
- _adjustParentBBoxes(e, n, o) {
1653
- for (let i = o; i >= 0; i--)
1654
- ct(n[i], e);
1655
- }
1656
- _condense(e) {
1657
- for (let n = e.length - 1, o; n >= 0; n--)
1658
- e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : tt(e[n], this.toBBox);
1659
- }
1660
- }
1661
- function so(t, e, n) {
1662
- if (!n) return e.indexOf(t);
1663
- for (let o = 0; o < e.length; o++)
1664
- if (n(t, e[o])) return o;
1665
- return -1;
1666
- }
1667
- function tt(t, e) {
1668
- at(t, 0, t.children.length, e, t);
1669
- }
1670
- function at(t, e, n, o, i) {
1671
- i || (i = et(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
1672
- for (let s = e; s < n; s++) {
1673
- const a = t.children[s];
1674
- ct(i, t.leaf ? o(a) : a);
1675
- }
1676
- return i;
1677
- }
1678
- function ct(t, e) {
1679
- return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
1680
- }
1681
- function ro(t, e) {
1682
- return t.minX - e.minX;
1683
- }
1684
- function ao(t, e) {
1685
- return t.minY - e.minY;
1686
- }
1687
- function _t(t) {
1688
- return (t.maxX - t.minX) * (t.maxY - t.minY);
1689
- }
1690
- function wt(t) {
1691
- return t.maxX - t.minX + (t.maxY - t.minY);
1692
- }
1693
- function co(t, e) {
1694
- return (Math.max(e.maxX, t.maxX) - Math.min(e.minX, t.minX)) * (Math.max(e.maxY, t.maxY) - Math.min(e.minY, t.minY));
1695
- }
1696
- function lo(t, e) {
1697
- const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), s = Math.min(t.maxY, e.maxY);
1698
- return Math.max(0, i - n) * Math.max(0, s - o);
1699
- }
1700
- function Ut(t, e) {
1701
- return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1702
- }
1703
- function At(t, e) {
1704
- return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
1705
- }
1706
- function et(t) {
1707
- return {
1708
- children: t,
1709
- height: 1,
1710
- leaf: !0,
1711
- minX: 1 / 0,
1712
- minY: 1 / 0,
1713
- maxX: -1 / 0,
1714
- maxY: -1 / 0
1715
- };
1716
- }
1717
- function re(t, e, n, o, i) {
1718
- const s = [e, n];
1719
- for (; s.length; ) {
1720
- if (n = s.pop(), e = s.pop(), n - e <= o) continue;
1721
- const a = e + Math.ceil((n - e) / o / 2) * o;
1722
- Ee(t, a, e, n, i), s.push(e, a, a, n);
1723
- }
1724
- }
1725
- let uo = () => ({
1726
- emit(t, ...e) {
1727
- for (let n = this.events[t] || [], o = 0, i = n.length; o < i; o++)
1728
- n[o](...e);
1729
- },
1730
- events: {},
1731
- on(t, e) {
1732
- var n;
1733
- return ((n = this.events)[t] || (n[t] = [])).push(e), () => {
1734
- var o;
1735
- this.events[t] = (o = this.events[t]) == null ? void 0 : o.filter((i) => e !== i);
1736
- };
1737
- }
1738
- });
1739
- const fo = (t, e) => {
1740
- const n = new io(), o = /* @__PURE__ */ new Map(), i = uo(), s = (y, S) => {
1741
- const v = y.selector.flatMap((R) => {
1742
- const T = q([R]) ? R.range : fe(R, e).range;
1743
- return Array.from(T.getClientRects());
1744
- }), L = Pe(v).map((R) => je(R, S));
1745
- return L.map((R) => {
1746
- const { x: T, y: M, width: _, height: X } = R;
519
+ body: ut(t.bodies),
520
+ creator: c,
521
+ created: u == null ? void 0 : u.toISOString(),
522
+ modified: b == null ? void 0 : b.toISOString(),
523
+ target: g
524
+ };
525
+ }, re = (t, n) => {
526
+ const e = new wt(), o = /* @__PURE__ */ new Map(), s = At(), i = (d, f) => {
527
+ const l = d.selector.flatMap((w) => {
528
+ const v = M([w]) ? w.range : rt(w, n).range;
529
+ return Array.from(v.getClientRects());
530
+ }), h = Pt(l).map((w) => Dt(w, f));
531
+ return h.map((w) => {
532
+ const { x: v, y: E, width: L, height: I } = w;
1747
533
  return {
1748
- minX: T,
1749
- minY: M,
1750
- maxX: T + _,
1751
- maxY: M + X,
534
+ minX: v,
535
+ minY: E,
536
+ maxX: v + L,
537
+ maxY: E + I,
1752
538
  annotation: {
1753
- id: y.annotation,
1754
- rects: L
539
+ id: d.annotation,
540
+ rects: h
1755
541
  }
1756
542
  };
1757
543
  });
1758
- }, a = () => [...o.values()], r = () => {
1759
- n.clear(), o.clear();
1760
- }, l = (y) => {
1761
- const S = s(y, e.getBoundingClientRect());
1762
- S.length !== 0 && (S.forEach((v) => n.insert(v)), o.set(y.annotation, S));
1763
- }, d = (y) => {
1764
- const S = o.get(y.annotation);
1765
- S && (S.forEach((v) => n.remove(v)), o.delete(y.annotation));
1766
- }, g = (y) => {
1767
- d(y), l(y);
1768
- }, u = (y, S = !0) => {
1769
- S && r();
1770
- const v = e.getBoundingClientRect(), L = y.map((T) => ({ target: T, rects: s(T, v) }));
1771
- L.forEach(({ target: T, rects: M }) => {
1772
- M.length > 0 && o.set(T.annotation, M);
544
+ }, a = () => [...o.values()], c = () => {
545
+ e.clear(), o.clear();
546
+ }, u = (d) => {
547
+ const f = i(d, n.getBoundingClientRect());
548
+ f.length !== 0 && (f.forEach((l) => e.insert(l)), o.set(d.annotation, f));
549
+ }, b = (d) => {
550
+ const f = o.get(d.annotation);
551
+ f && (f.forEach((l) => e.remove(l)), o.delete(d.annotation));
552
+ }, y = (d) => {
553
+ b(d), u(d);
554
+ }, g = (d, f = !0) => {
555
+ f && c();
556
+ const l = n.getBoundingClientRect(), h = d.map((v) => ({ target: v, rects: i(v, l) }));
557
+ h.forEach(({ target: v, rects: E }) => {
558
+ E.length > 0 && o.set(v.annotation, E);
1773
559
  });
1774
- const R = L.flatMap(({ rects: T }) => T);
1775
- n.load(R);
1776
- }, h = (y, S, v = !1) => {
1777
- const L = n.search({
1778
- minX: y,
1779
- minY: S,
1780
- maxX: y,
1781
- maxY: S
1782
- }), R = (T) => T.annotation.rects.reduce((M, _) => M + _.width * _.height, 0);
1783
- return L.length > 0 ? (L.sort((T, M) => R(T) - R(M)), v ? L.map((T) => T.annotation.id) : [L[0].annotation.id]) : [];
1784
- }, x = (y) => {
1785
- const S = p(y);
1786
- if (S.length === 0)
560
+ const w = h.flatMap(({ rects: v }) => v);
561
+ e.load(w);
562
+ }, r = (d, f, l = !1) => {
563
+ const h = e.search({
564
+ minX: d,
565
+ minY: f,
566
+ maxX: d,
567
+ maxY: f
568
+ }), w = (v) => v.annotation.rects.reduce((E, L) => E + L.width * L.height, 0);
569
+ return h.length > 0 ? (h.sort((v, E) => w(v) - w(E)), l ? h.map((v) => v.annotation.id) : [h[0].annotation.id]) : [];
570
+ }, A = (d) => {
571
+ const f = S(d);
572
+ if (f.length === 0)
1787
573
  return;
1788
- let v = S[0].left, L = S[0].top, R = S[0].right, T = S[0].bottom;
1789
- for (let M = 1; M < S.length; M++) {
1790
- const _ = S[M];
1791
- v = Math.min(v, _.left), L = Math.min(L, _.top), R = Math.max(R, _.right), T = Math.max(T, _.bottom);
574
+ let l = f[0].left, h = f[0].top, w = f[0].right, v = f[0].bottom;
575
+ for (let E = 1; E < f.length; E++) {
576
+ const L = f[E];
577
+ l = Math.min(l, L.left), h = Math.min(h, L.top), w = Math.max(w, L.right), v = Math.max(v, L.bottom);
1792
578
  }
1793
- return new DOMRect(v, L, R - v, T - L);
1794
- }, p = (y) => {
1795
- const S = o.get(y);
1796
- return S ? S[0].annotation.rects : [];
579
+ return new DOMRect(l, h, w - l, v - h);
580
+ }, S = (d) => {
581
+ const f = o.get(d);
582
+ return f ? f[0].annotation.rects : [];
1797
583
  };
1798
584
  return {
1799
585
  all: a,
1800
- clear: r,
1801
- getAt: h,
1802
- getAnnotationBounds: x,
1803
- getAnnotationRects: p,
1804
- getIntersecting: (y, S, v, L) => {
1805
- const R = n.search({ minX: y, minY: S, maxX: v, maxY: L }), T = new Set(R.map((M) => M.annotation.id));
1806
- return Array.from(T).map((M) => ({
1807
- annotation: t.getAnnotation(M),
1808
- rects: p(M)
1809
- })).filter((M) => !!M.annotation);
586
+ clear: c,
587
+ getAt: r,
588
+ getAnnotationBounds: A,
589
+ getAnnotationRects: S,
590
+ getIntersecting: (d, f, l, h) => {
591
+ const w = e.search({ minX: d, minY: f, maxX: l, maxY: h }), v = new Set(w.map((E) => E.annotation.id));
592
+ return Array.from(v).map((E) => ({
593
+ annotation: t.getAnnotation(E),
594
+ rects: S(E)
595
+ })).filter((E) => !!E.annotation);
1810
596
  },
1811
- insert: l,
597
+ insert: u,
1812
598
  recalculate: () => {
1813
- u(t.all().map((y) => y.target), !0), i.emit("recalculate");
599
+ g(t.all().map((d) => d.target), !0), s.emit("recalculate");
1814
600
  },
1815
- remove: d,
1816
- set: u,
1817
- size: () => n.all().length,
1818
- update: g,
1819
- on: (y, S) => i.on(y, S)
1820
- };
1821
- }, ho = (t, e) => {
1822
- const n = Un(), o = fo(n, t), i = Sn(n, e.userSelectAction, e.adapter), s = En(n), a = Kn(), r = (c, y = k.LOCAL) => {
1823
- const S = Lt(c, t), v = q(S.target.selector);
1824
- return v && n.addAnnotation(S, y), v;
1825
- }, l = (c, y = !0, S = k.LOCAL) => {
1826
- const v = c.map((R) => Lt(R, t)), L = v.filter((R) => !q(R.target.selector));
1827
- return n.bulkAddAnnotations(v, y, S), L;
1828
- }, d = (c, y = k.LOCAL) => {
1829
- const S = c.map((L) => Lt(L, t)), v = S.filter((L) => !q(L.target.selector));
1830
- return S.forEach((L) => {
1831
- n.getAnnotation(L.id) ? n.updateAnnotation(L, y) : n.addAnnotation(L, y);
1832
- }), v;
1833
- }, g = (c, y = k.LOCAL) => {
1834
- const S = vt(c, t);
1835
- n.updateTarget(S, y);
1836
- }, u = (c, y = k.LOCAL) => {
1837
- const S = c.map((v) => vt(v, t));
1838
- n.bulkUpdateTargets(S, y);
1839
- };
1840
- function h(c, y, S, v) {
1841
- const L = S || !!v, R = o.getAt(c, y, L).map((M) => n.getAnnotation(M)), T = v ? R.filter(v) : R;
1842
- if (T.length !== 0)
1843
- return S ? T : T[0];
1844
- }
1845
- const x = (c) => o.getAnnotationRects(c).length > 0 ? o.getAnnotationBounds(c) : void 0, p = (c, y, S, v) => o.getIntersecting(c, y, S, v), w = (c) => o.getAnnotationRects(c), E = () => o.recalculate(), m = (c) => o.on("recalculate", c);
1846
- return n.observe(({ changes: c }) => {
1847
- const y = (c.deleted || []).filter((L) => q(L.target.selector)), S = (c.created || []).filter((L) => q(L.target.selector)), v = (c.updated || []).filter((L) => q(L.newValue.target.selector));
1848
- (y == null ? void 0 : y.length) > 0 && y.forEach((L) => o.remove(L.target)), S.length > 0 && o.set(S.map((L) => L.target), !1), (v == null ? void 0 : v.length) > 0 && v.forEach(({ newValue: L }) => o.update(L.target));
601
+ remove: b,
602
+ set: g,
603
+ size: () => e.all().length,
604
+ update: y,
605
+ on: (d, f) => s.on(d, f)
606
+ };
607
+ }, ie = (t, n) => {
608
+ const e = mt(), o = re(e, t), s = pt(e, n.userSelectAction, n.adapter), i = ht(e), a = yt(), c = (m, d = _.LOCAL) => {
609
+ const f = q(m, t), l = M(f.target.selector);
610
+ return l && e.addAnnotation(f, d), l;
611
+ }, u = (m, d = !0, f = _.LOCAL) => {
612
+ const l = m.map((w) => q(w, t)), h = l.filter((w) => !M(w.target.selector));
613
+ return e.bulkAddAnnotations(l, d, f), h;
614
+ }, b = (m, d = _.LOCAL) => {
615
+ const f = m.map((h) => q(h, t)), l = f.filter((h) => !M(h.target.selector));
616
+ return f.forEach((h) => {
617
+ e.getAnnotation(h.id) ? e.updateAnnotation(h, d) : e.addAnnotation(h, d);
618
+ }), l;
619
+ }, y = (m, d = _.LOCAL) => {
620
+ const f = X(m, t);
621
+ e.updateTarget(f, d);
622
+ }, g = (m, d = _.LOCAL) => {
623
+ const f = m.map((l) => X(l, t));
624
+ e.bulkUpdateTargets(f, d);
625
+ };
626
+ function r(m, d, f, l) {
627
+ const h = f || !!l, w = o.getAt(m, d, h).map((E) => e.getAnnotation(E)), v = l ? w.filter(l) : w;
628
+ if (v.length !== 0)
629
+ return f ? v : v[0];
630
+ }
631
+ const A = (m) => o.getAnnotationRects(m).length > 0 ? o.getAnnotationBounds(m) : void 0, S = (m, d, f, l) => o.getIntersecting(m, d, f, l), T = (m) => o.getAnnotationRects(m), x = () => o.recalculate(), C = (m) => o.on("recalculate", m);
632
+ return e.observe(({ changes: m }) => {
633
+ const d = (m.deleted || []).filter((h) => M(h.target.selector)), f = (m.created || []).filter((h) => M(h.target.selector)), l = (m.updated || []).filter((h) => M(h.newValue.target.selector));
634
+ (d == null ? void 0 : d.length) > 0 && d.forEach((h) => o.remove(h.target)), f.length > 0 && o.set(f.map((h) => h.target), !1), (l == null ? void 0 : l.length) > 0 && l.forEach(({ newValue: h }) => o.update(h.target));
1849
635
  }), {
1850
636
  store: {
1851
- ...n,
1852
- addAnnotation: r,
1853
- bulkAddAnnotations: l,
1854
- bulkUpdateTargets: u,
1855
- bulkUpsertAnnotations: d,
1856
- getAnnotationBounds: x,
1857
- getAnnotationRects: w,
1858
- getIntersecting: p,
1859
- getAt: h,
1860
- recalculatePositions: E,
1861
- onRecalculatePositions: m,
1862
- updateTarget: g
637
+ ...e,
638
+ addAnnotation: c,
639
+ bulkAddAnnotations: u,
640
+ bulkUpdateTargets: g,
641
+ bulkUpsertAnnotations: b,
642
+ getAnnotationBounds: A,
643
+ getAnnotationRects: T,
644
+ getIntersecting: S,
645
+ getAt: r,
646
+ recalculatePositions: x,
647
+ onRecalculatePositions: C,
648
+ updateTarget: y
1863
649
  },
1864
- selection: i,
1865
- hover: s,
650
+ selection: s,
651
+ hover: i,
1866
652
  viewport: a
1867
653
  };
1868
- }, po = () => {
654
+ }, ae = () => {
1869
655
  const t = document.createElement("canvas");
1870
656
  t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
1871
- const e = t.getContext("2d");
1872
- return e.scale(2, 2), e.translate(0.5, 0.5), t;
1873
- }, go = (t, e = {}) => {
1874
- const n = po(), o = n.getContext("2d");
1875
- document.body.appendChild(n);
1876
- const i = /* @__PURE__ */ new Map(), s = (g) => Array.from(i.entries()).filter(([u, h]) => h.presenceKey === g.presenceKey).map(([u, h]) => u);
1877
- return t.on("selectionChange", (g, u) => {
1878
- s(g).forEach((x) => i.delete(x)), u && u.forEach((x) => i.set(x, g));
657
+ const n = t.getContext("2d");
658
+ return n.scale(2, 2), n.translate(0.5, 0.5), t;
659
+ }, ce = (t, n = {}) => {
660
+ const e = ae(), o = e.getContext("2d");
661
+ document.body.appendChild(e);
662
+ const s = /* @__PURE__ */ new Map(), i = (y) => Array.from(s.entries()).filter(([g, r]) => r.presenceKey === y.presenceKey).map(([g, r]) => g);
663
+ return t.on("selectionChange", (y, g) => {
664
+ i(y).forEach((A) => s.delete(A)), g && g.forEach((A) => s.set(A, y));
1879
665
  }), {
1880
666
  clear: () => {
1881
- const { width: g, height: u } = n;
1882
- o.clearRect(-0.5, -0.5, g + 1, u + 1);
667
+ const { width: y, height: g } = e;
668
+ o.clearRect(-0.5, -0.5, y + 1, g + 1);
1883
669
  },
1884
670
  destroy: () => {
1885
- n.remove();
671
+ e.remove();
1886
672
  },
1887
- paint: (g, u, h) => {
1888
- e.font && (o.font = e.font);
1889
- const x = i.get(g.annotation.id);
1890
- if (x) {
1891
- const { height: p } = g.rects[0], w = g.rects[0].x + u.left, E = g.rects[0].y + u.top;
1892
- o.fillStyle = x.appearance.color, o.fillRect(w - 2, E - 2.5, 2, p + 5);
1893
- const m = o.measureText(x.appearance.label), c = m.width + 6, y = m.actualBoundingBoxAscent + m.actualBoundingBoxDescent + 8, S = m.fontBoundingBoxAscent ? 8 : 6.5;
1894
- return o.fillRect(w - 2, E - 2.5 - y, c, y), o.fillStyle = "#fff", o.fillText(x.appearance.label, w + 1, E - S), {
1895
- fill: x.appearance.color,
1896
- fillOpacity: h ? 0.45 : 0.18
673
+ paint: (y, g, r) => {
674
+ n.font && (o.font = n.font);
675
+ const A = s.get(y.annotation.id);
676
+ if (A) {
677
+ const { height: S } = y.rects[0], T = y.rects[0].x + g.left, x = y.rects[0].y + g.top;
678
+ o.fillStyle = A.appearance.color, o.fillRect(T - 2, x - 2.5, 2, S + 5);
679
+ const C = o.measureText(A.appearance.label), m = C.width + 6, d = C.actualBoundingBoxAscent + C.actualBoundingBoxDescent + 8, f = C.fontBoundingBoxAscent ? 8 : 6.5;
680
+ return o.fillRect(T - 2, x - 2.5 - d, m, d), o.fillStyle = "#fff", o.fillText(A.appearance.label, T + 1, x - f), {
681
+ fill: A.appearance.color,
682
+ fillOpacity: r ? 0.45 : 0.18
1897
683
  };
1898
684
  }
1899
685
  },
1900
686
  reset: () => {
1901
- n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
1902
- const g = n.getContext("2d");
1903
- g.scale(2, 2), g.translate(0.5, 0.5);
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);
1904
690
  }
1905
691
  };
1906
- }, Dt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1907
- function Vt(t, e, n, o) {
1908
- t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
1909
- }
1910
- function st(t, e, n, o) {
1911
- t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
1912
- }
1913
- function ve(t, e) {
1914
- const n = e.slice(0, e.length - 1);
1915
- for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
1916
- return n;
1917
- }
1918
- function Se(t) {
1919
- typeof t != "string" && (t = ""), t = t.replace(/\s/g, "");
1920
- const e = t.split(",");
1921
- let n = e.lastIndexOf("");
1922
- for (; n >= 0; )
1923
- e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
1924
- return e;
1925
- }
1926
- function mo(t, e) {
1927
- const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
1928
- let i = !0;
1929
- for (let s = 0; s < n.length; s++)
1930
- o.indexOf(n[s]) === -1 && (i = !1);
1931
- return i;
1932
- }
1933
- const ut = {
1934
- backspace: 8,
1935
- "⌫": 8,
1936
- tab: 9,
1937
- clear: 12,
1938
- enter: 13,
1939
- "↩": 13,
1940
- return: 13,
1941
- esc: 27,
1942
- escape: 27,
1943
- space: 32,
1944
- left: 37,
1945
- up: 38,
1946
- right: 39,
1947
- down: 40,
1948
- del: 46,
1949
- delete: 46,
1950
- ins: 45,
1951
- insert: 45,
1952
- home: 36,
1953
- end: 35,
1954
- pageup: 33,
1955
- pagedown: 34,
1956
- capslock: 20,
1957
- num_0: 96,
1958
- num_1: 97,
1959
- num_2: 98,
1960
- num_3: 99,
1961
- num_4: 100,
1962
- num_5: 101,
1963
- num_6: 102,
1964
- num_7: 103,
1965
- num_8: 104,
1966
- num_9: 105,
1967
- num_multiply: 106,
1968
- num_add: 107,
1969
- num_enter: 108,
1970
- num_subtract: 109,
1971
- num_decimal: 110,
1972
- num_divide: 111,
1973
- "⇪": 20,
1974
- ",": 188,
1975
- ".": 190,
1976
- "/": 191,
1977
- "`": 192,
1978
- "-": Dt ? 173 : 189,
1979
- "=": Dt ? 61 : 187,
1980
- ";": Dt ? 59 : 186,
1981
- "'": 222,
1982
- "[": 219,
1983
- "]": 221,
1984
- "\\": 220
1985
- }, z = {
1986
- // shiftKey
1987
- "⇧": 16,
1988
- shift: 16,
1989
- // altKey
1990
- "⌥": 18,
1991
- alt: 18,
1992
- option: 18,
1993
- // ctrlKey
1994
- "⌃": 17,
1995
- ctrl: 17,
1996
- control: 17,
1997
- // metaKey
1998
- "⌘": 91,
1999
- cmd: 91,
2000
- command: 91
2001
- }, Et = {
2002
- 16: "shiftKey",
2003
- 18: "altKey",
2004
- 17: "ctrlKey",
2005
- 91: "metaKey",
2006
- shiftKey: 16,
2007
- ctrlKey: 17,
2008
- altKey: 18,
2009
- metaKey: 91
2010
- }, P = {
2011
- 16: !1,
2012
- 18: !1,
2013
- 17: !1,
2014
- 91: !1
2015
- }, U = {};
2016
- for (let t = 1; t < 20; t++)
2017
- ut["f".concat(t)] = 111 + t;
2018
- let N = [], dt = null, Ce = "all";
2019
- const W = /* @__PURE__ */ new Map(), ht = (t) => ut[t.toLowerCase()] || z[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), yo = (t) => Object.keys(ut).find((e) => ut[e] === t), bo = (t) => Object.keys(z).find((e) => z[e] === t);
2020
- function Le(t) {
2021
- Ce = t || "all";
2022
- }
2023
- function ft() {
2024
- return Ce || "all";
2025
- }
2026
- function wo() {
2027
- return N.slice(0);
2028
- }
2029
- function Ao() {
2030
- return N.map((t) => yo(t) || bo(t) || String.fromCharCode(t));
2031
- }
2032
- function xo() {
2033
- const t = [];
2034
- return Object.keys(U).forEach((e) => {
2035
- U[e].forEach((n) => {
2036
- let {
2037
- key: o,
2038
- scope: i,
2039
- mods: s,
2040
- shortcut: a
2041
- } = n;
2042
- t.push({
2043
- scope: i,
2044
- shortcut: a,
2045
- mods: s,
2046
- keys: o.split("+").map((r) => ht(r))
2047
- });
2048
- });
2049
- }), t;
2050
- }
2051
- function Eo(t) {
2052
- const e = t.target || t.srcElement, {
2053
- tagName: n
2054
- } = e;
2055
- let o = !0;
2056
- const i = n === "INPUT" && !["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes(e.type);
2057
- return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = !1), o;
2058
- }
2059
- function vo(t) {
2060
- return typeof t == "string" && (t = ht(t)), N.indexOf(t) !== -1;
2061
- }
2062
- function So(t, e) {
2063
- let n, o;
2064
- t || (t = ft());
2065
- for (const i in U)
2066
- if (Object.prototype.hasOwnProperty.call(U, i))
2067
- for (n = U[i], o = 0; o < n.length; )
2068
- n[o].scope === t ? n.splice(o, 1).forEach((a) => {
2069
- let {
2070
- element: r
2071
- } = a;
2072
- return jt(r);
2073
- }) : o++;
2074
- ft() === t && Le(e || "all");
2075
- }
2076
- function Co(t) {
2077
- let e = t.keyCode || t.which || t.charCode;
2078
- const n = N.indexOf(e);
2079
- if (n >= 0 && N.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && N.splice(0, N.length), (e === 93 || e === 224) && (e = 91), e in P) {
2080
- P[e] = !1;
2081
- for (const o in z) z[o] === e && (H[o] = !1);
2082
- }
2083
- }
2084
- function Te(t) {
2085
- if (typeof t > "u")
2086
- Object.keys(U).forEach((i) => {
2087
- Array.isArray(U[i]) && U[i].forEach((s) => xt(s)), delete U[i];
2088
- }), jt(null);
2089
- else if (Array.isArray(t))
2090
- t.forEach((i) => {
2091
- i.key && xt(i);
2092
- });
2093
- else if (typeof t == "object")
2094
- t.key && xt(t);
2095
- else if (typeof t == "string") {
2096
- for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
2097
- n[o - 1] = arguments[o];
2098
- let [i, s] = n;
2099
- typeof i == "function" && (s = i, i = ""), xt({
2100
- key: t,
2101
- scope: i,
2102
- method: s,
2103
- splitKey: "+"
2104
- });
2105
- }
2106
- }
2107
- const xt = (t) => {
2108
- let {
2109
- key: e,
2110
- scope: n,
2111
- method: o,
2112
- splitKey: i = "+"
2113
- } = t;
2114
- Se(e).forEach((a) => {
2115
- const r = a.split(i), l = r.length, d = r[l - 1], g = d === "*" ? "*" : ht(d);
2116
- if (!U[g]) return;
2117
- n || (n = ft());
2118
- const u = l > 1 ? ve(z, r) : [], h = [];
2119
- U[g] = U[g].filter((x) => {
2120
- const w = (o ? x.method === o : !0) && x.scope === n && mo(x.mods, u);
2121
- return w && h.push(x.element), !w;
2122
- }), h.forEach((x) => jt(x));
2123
- });
2124
- };
2125
- function ae(t, e, n, o) {
2126
- if (e.element !== o)
2127
- return;
692
+ }, tt = 300, ct = ["up", "down", "left", "right"], lt = Rt ? "⌘+a" : "ctrl+a", le = [
693
+ ...ct.map((t) => `shift+${t}`),
694
+ lt
695
+ ], de = (t, n, e) => {
696
+ const { store: o, selection: s } = n;
2128
697
  let i;
2129
- if (e.scope === n || e.scope === "all") {
2130
- i = e.mods.length > 0;
2131
- for (const s in P)
2132
- Object.prototype.hasOwnProperty.call(P, s) && (!P[s] && e.mods.indexOf(+s) > -1 || P[s] && e.mods.indexOf(+s) === -1) && (i = !1);
2133
- (e.mods.length === 0 && !P[16] && !P[18] && !P[17] && !P[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(N), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2134
- }
2135
- }
2136
- function ce(t, e) {
2137
- const n = U["*"];
2138
- let o = t.keyCode || t.which || t.charCode;
2139
- if (!H.filter.call(this, t)) return;
2140
- if ((o === 93 || o === 224) && (o = 91), N.indexOf(o) === -1 && o !== 229 && N.push(o), ["metaKey", "ctrlKey", "altKey", "shiftKey"].forEach((r) => {
2141
- const l = Et[r];
2142
- t[r] && N.indexOf(l) === -1 ? N.push(l) : !t[r] && N.indexOf(l) > -1 ? N.splice(N.indexOf(l), 1) : r === "metaKey" && t[r] && (N = N.filter((d) => d in Et || d === o));
2143
- }), o in P) {
2144
- P[o] = !0;
2145
- for (const r in z)
2146
- z[r] === o && (H[r] = !0);
2147
- if (!n) return;
2148
- }
2149
- for (const r in P)
2150
- Object.prototype.hasOwnProperty.call(P, r) && (P[r] = t[Et[r]]);
2151
- t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (N.indexOf(17) === -1 && N.push(17), N.indexOf(18) === -1 && N.push(18), P[17] = !0, P[18] = !0);
2152
- const i = ft();
2153
- if (n)
2154
- for (let r = 0; r < n.length; r++)
2155
- n[r].scope === i && (t.type === "keydown" && n[r].keydown || t.type === "keyup" && n[r].keyup) && ae(t, n[r], i, e);
2156
- if (!(o in U)) return;
2157
- const s = U[o], a = s.length;
2158
- for (let r = 0; r < a; r++)
2159
- if ((t.type === "keydown" && s[r].keydown || t.type === "keyup" && s[r].keyup) && s[r].key) {
2160
- const l = s[r], {
2161
- splitKey: d
2162
- } = l, g = l.key.split(d), u = [];
2163
- for (let h = 0; h < g.length; h++)
2164
- u.push(ht(g[h]));
2165
- u.sort().join("") === N.sort().join("") && ae(t, l, i, e);
2166
- }
2167
- }
2168
- function H(t, e, n) {
2169
- N = [];
2170
- const o = Se(t);
2171
- let i = [], s = "all", a = document, r = 0, l = !1, d = !0, g = "+", u = !1, h = !1;
2172
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (d = e.keydown), e.capture !== void 0 && (u = e.capture), typeof e.splitKey == "string" && (g = e.splitKey), e.single === !0 && (h = !0)), typeof e == "string" && (s = e), h && Te(t, s); r < o.length; r++)
2173
- t = o[r].split(g), i = [], t.length > 1 && (i = ve(z, t)), t = t[t.length - 1], t = t === "*" ? "*" : ht(t), t in U || (U[t] = []), U[t].push({
2174
- keyup: l,
2175
- keydown: d,
2176
- scope: s,
2177
- mods: i,
2178
- shortcut: o[r],
2179
- method: n,
2180
- key: o[r],
2181
- splitKey: g,
2182
- element: a
2183
- });
2184
- if (typeof a < "u" && window) {
2185
- if (!W.has(a)) {
2186
- const x = function() {
2187
- let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2188
- return ce(w, a);
2189
- }, p = function() {
2190
- let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2191
- ce(w, a), Co(w);
2192
- };
2193
- W.set(a, {
2194
- keydownListener: x,
2195
- keyupListenr: p,
2196
- capture: u
2197
- }), Vt(a, "keydown", x, u), Vt(a, "keyup", p, u);
2198
- }
2199
- if (!dt) {
2200
- const x = () => {
2201
- N = [];
2202
- };
2203
- dt = {
2204
- listener: x,
2205
- capture: u
2206
- }, Vt(window, "focus", x, u);
2207
- }
2208
- }
2209
- }
2210
- function Lo(t) {
2211
- let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
2212
- Object.keys(U).forEach((n) => {
2213
- U[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
2214
- i && i.method && i.method();
2215
- });
2216
- });
2217
- }
2218
- function jt(t) {
2219
- const e = Object.values(U).flat();
2220
- if (e.findIndex((o) => {
2221
- let {
2222
- element: i
2223
- } = o;
2224
- return i === t;
2225
- }) < 0) {
2226
- const {
2227
- keydownListener: o,
2228
- keyupListenr: i,
2229
- capture: s
2230
- } = W.get(t) || {};
2231
- o && i && (st(t, "keyup", i, s), st(t, "keydown", o, s), W.delete(t));
2232
- }
2233
- if ((e.length <= 0 || W.size <= 0) && (Object.keys(W).forEach((i) => {
2234
- const {
2235
- keydownListener: s,
2236
- keyupListenr: a,
2237
- capture: r
2238
- } = W.get(i) || {};
2239
- s && a && (st(i, "keyup", a, r), st(i, "keydown", s, r), W.delete(i));
2240
- }), W.clear(), Object.keys(U).forEach((i) => delete U[i]), dt)) {
2241
- const {
2242
- listener: i,
2243
- capture: s
2244
- } = dt;
2245
- st(window, "focus", i, s), dt = null;
2246
- }
2247
- }
2248
- const Yt = {
2249
- getPressedKeyString: Ao,
2250
- setScope: Le,
2251
- getScope: ft,
2252
- deleteScope: So,
2253
- getPressedKeyCodes: wo,
2254
- getAllKeyCodes: xo,
2255
- isPressed: vo,
2256
- filter: Eo,
2257
- trigger: Lo,
2258
- unbind: Te,
2259
- keyMap: ut,
2260
- modifier: z,
2261
- modifierMap: Et
2262
- };
2263
- for (const t in Yt)
2264
- Object.prototype.hasOwnProperty.call(Yt, t) && (H[t] = Yt[t]);
2265
- if (typeof window < "u") {
2266
- const t = window.hotkeys;
2267
- H.noConflict = (e) => (e && window.hotkeys === H && (window.hotkeys = t), H), window.hotkeys = H;
2268
- }
2269
- async function To(t, e, n = () => !1) {
2270
- do {
2271
- if (await t(), await n()) break;
2272
- const o = e;
2273
- await new Promise((i) => setTimeout(i, Math.max(0, o)));
2274
- } while (!await n());
2275
- }
2276
- const le = 300, Oe = ["up", "down", "left", "right"], Re = ke ? "⌘+a" : "ctrl+a", Oo = [
2277
- ...Oe.map((t) => `shift+${t}`),
2278
- Re
2279
- ], Ro = (t, e, n) => {
2280
- const { store: o, selection: i } = e;
2281
- let s;
2282
- const { annotatingEnabled: a, offsetReferenceSelector: r, selectionMode: l } = n, d = (f) => s = f;
2283
- let g;
2284
- const u = (f) => g = f;
2285
- let h, x, p, w = a;
2286
- const E = (f) => {
2287
- w = f, c.clear(), f || (h = void 0, x = void 0, p = void 0);
2288
- }, m = (f) => {
2289
- w && x !== !1 && (h = rt(f.target) ? void 0 : {
2290
- annotation: be(),
698
+ const { annotatingEnabled: a, offsetReferenceSelector: c, selectionMode: u } = e, b = (p) => i = p;
699
+ let y;
700
+ const g = (p) => y = p;
701
+ let r, A, S, T = a;
702
+ const x = (p) => {
703
+ T = p, m.clear(), p || (r = void 0, A = void 0, S = void 0);
704
+ }, C = (p) => {
705
+ T && A !== !1 && (r = W(p.target) ? void 0 : {
706
+ annotation: ot(),
2291
707
  selector: [],
2292
- creator: s,
708
+ creator: i,
2293
709
  created: /* @__PURE__ */ new Date()
2294
710
  });
2295
- }, c = Xt((f) => {
2296
- if (!w) return;
2297
- const b = document.getSelection();
2298
- if (!(b != null && b.anchorNode))
711
+ }, m = Q((p) => {
712
+ if (!T) return;
713
+ const R = document.getSelection();
714
+ if (!(R != null && R.anchorNode))
2299
715
  return;
2300
- if (rt(b.anchorNode)) {
2301
- h = void 0;
716
+ if (W(R.anchorNode)) {
717
+ r = void 0;
2302
718
  return;
2303
719
  }
2304
- const A = f.timeStamp - ((p == null ? void 0 : p.timeStamp) || f.timeStamp);
2305
- if ((p == null ? void 0 : p.type) === "pointerdown" && (A < 1e3 && !h || b.isCollapsed && A < le) && m(p || f), !h) return;
2306
- if (b.isCollapsed) {
2307
- o.getAnnotation(h.annotation) && (i.clear(), o.deleteAnnotation(h.annotation));
720
+ const k = p.timeStamp - ((S == null ? void 0 : S.timeStamp) || p.timeStamp);
721
+ if ((S == null ? void 0 : S.type) === "pointerdown" && (k < 1e3 && !r || R.isCollapsed && k < tt) && C(S || p), !r) return;
722
+ if (R.isCollapsed) {
723
+ o.getAnnotation(r.annotation) && (s.clear(), o.deleteAnnotation(r.annotation));
2308
724
  return;
2309
725
  }
2310
- const C = b.getRangeAt(0), B = He(C, t);
2311
- if (Ve(B)) return;
2312
- const O = _e(B.cloneRange());
2313
- (O.length !== h.selector.length || O.some((V, Q) => {
2314
- var Ct;
2315
- return V.toString() !== ((Ct = h.selector[Q]) == null ? void 0 : Ct.quote);
2316
- })) && (h = {
2317
- ...h,
2318
- selector: O.map((V) => Xe(V, t, r)),
726
+ const B = R.getRangeAt(0), H = _t(B, t);
727
+ if (It(H)) return;
728
+ const O = Bt(H.cloneRange());
729
+ (O.length !== r.selector.length || O.some((P, $) => {
730
+ var F;
731
+ return P.toString() !== ((F = r.selector[$]) == null ? void 0 : F.quote);
732
+ })) && (r = {
733
+ ...r,
734
+ selector: O.map((P) => Kt(P, t, c)),
2319
735
  updated: /* @__PURE__ */ new Date()
2320
- }, o.getAnnotation(h.annotation) ? o.updateTarget(h, k.LOCAL) : i.clear());
2321
- }, 10), y = (f) => {
2322
- rt(f.target) || (p = Tt(f), x = p.button === 0);
2323
- }, S = async (f) => {
2324
- if (rt(f.target) || !x) return;
2325
- const b = () => {
2326
- const { x: C, y: B } = t.getBoundingClientRect(), O = f.target instanceof Node && t.contains(f.target) && o.getAt(f.clientX - C, f.clientY - B, l === "all", g);
736
+ }, o.getAnnotation(r.annotation) ? o.updateTarget(r, _.LOCAL) : s.clear());
737
+ }, 10), d = (p) => {
738
+ W(p.target) || (S = j(p), A = S.button === 0);
739
+ }, f = async (p) => {
740
+ if (W(p.target) || !A) return;
741
+ const R = () => {
742
+ const { x: B, y: H } = t.getBoundingClientRect(), O = p.target instanceof Node && t.contains(p.target) && o.getAt(p.clientX - B, p.clientY - H, u === "all", y);
2327
743
  if (O) {
2328
- const { selected: I } = i, V = new Set(I.map((ot) => ot.id)), Q = Array.isArray(O) ? O.map((ot) => ot.id) : [O.id];
2329
- (V.size !== Q.length || !Q.every((ot) => V.has(ot))) && i.userSelect(Q, f);
744
+ const { selected: N } = s, P = new Set(N.map((U) => U.id)), $ = Array.isArray(O) ? O.map((U) => U.id) : [O.id];
745
+ (P.size !== $.length || !$.every((U) => P.has(U))) && s.userSelect($, p);
2330
746
  } else
2331
- i.clear();
747
+ s.clear();
2332
748
  };
2333
- if (f.timeStamp - p.timeStamp < le) {
2334
- await v();
2335
- const C = document.getSelection();
2336
- if (C != null && C.isCollapsed) {
2337
- h = void 0, b();
749
+ if (p.timeStamp - S.timeStamp < tt) {
750
+ await l();
751
+ const B = document.getSelection();
752
+ if (B != null && B.isCollapsed) {
753
+ r = void 0, R();
2338
754
  return;
2339
755
  }
2340
756
  }
2341
- h && h.selector.length > 0 && (_(), i.userSelect(h.annotation, Tt(f)));
2342
- }, v = async () => {
2343
- const f = document.getSelection();
2344
- let b = !1, A = f == null ? void 0 : f.isCollapsed;
2345
- const C = () => A || b, B = 1;
2346
- return setTimeout(() => b = !0, 50), To(() => A = f == null ? void 0 : f.isCollapsed, B, C);
2347
- }, L = (f) => {
2348
- const b = document.getSelection();
2349
- b != null && b.isCollapsed || ((!h || h.selector.length === 0) && c(f), _(), i.userSelect(h.annotation, Tt(f)));
2350
- }, R = (f) => {
2351
- w && f.key === "Shift" && h && (document.getSelection().isCollapsed || (_(), i.userSelect(h.annotation, pt(f))));
2352
- }, T = (f) => {
2353
- const b = () => setTimeout(() => {
2354
- (h == null ? void 0 : h.selector.length) > 0 && (i.clear(), o.addAnnotation({
2355
- id: h.annotation,
757
+ r && r.selector.length > 0 && (L(), s.userSelect(r.annotation, j(p)));
758
+ }, l = async () => {
759
+ const p = document.getSelection();
760
+ let R = !1, k = p == null ? void 0 : p.isCollapsed;
761
+ const B = () => k || R, H = 1;
762
+ return setTimeout(() => R = !0, 50), vt(() => k = p == null ? void 0 : p.isCollapsed, H, B);
763
+ }, h = (p) => {
764
+ const R = document.getSelection();
765
+ R != null && R.isCollapsed || ((!r || r.selector.length === 0) && m(p), r && (L(), s.userSelect(r.annotation, j(p))));
766
+ }, w = (p) => {
767
+ T && p.key === "Shift" && r && (document.getSelection().isCollapsed || (L(), s.userSelect(r.annotation, Y(p))));
768
+ }, v = (p) => {
769
+ const R = () => setTimeout(() => {
770
+ (r == null ? void 0 : r.selector.length) > 0 && (s.clear(), o.addAnnotation({
771
+ id: r.annotation,
2356
772
  bodies: [],
2357
- target: h
2358
- }), i.userSelect(h.annotation, pt(f))), document.removeEventListener("selectionchange", b);
773
+ target: r
774
+ }), s.userSelect(r.annotation, Y(p))), document.removeEventListener("selectionchange", R);
2359
775
  }, 100);
2360
- document.addEventListener("selectionchange", b), m(f);
776
+ document.addEventListener("selectionchange", R), C(p);
2361
777
  };
2362
- H(Oo.join(","), { element: t, keydown: !0, keyup: !1 }, (f) => {
2363
- f.repeat || (p = pt(f));
2364
- }), H(Re, { keydown: !0, keyup: !1 }, (f) => {
2365
- p = pt(f), T(f);
778
+ V(le.join(","), { element: t, keydown: !0, keyup: !1 }, (p) => {
779
+ p.repeat || (S = Y(p));
780
+ }), V(lt, { keydown: !0, keyup: !1 }, (p) => {
781
+ S = Y(p), v(p);
2366
782
  });
2367
- const M = (f) => {
2368
- f.repeat || f.target !== t && f.target !== document.body || (h = void 0, i.clear());
783
+ const E = (p) => {
784
+ p.repeat || p.target !== t && p.target !== document.body || (r = void 0, s.clear());
2369
785
  };
2370
- H(Oe.join(","), { keydown: !0, keyup: !1 }, M);
2371
- const _ = () => {
2372
- const f = o.getAnnotation(h.annotation);
2373
- if (!f) {
786
+ V(ct.join(","), { keydown: !0, keyup: !1 }, E);
787
+ const L = () => {
788
+ const p = o.getAnnotation(r.annotation);
789
+ if (!p) {
2374
790
  o.addAnnotation({
2375
- id: h.annotation,
791
+ id: r.annotation,
2376
792
  bodies: [],
2377
- target: h
793
+ target: r
2378
794
  });
2379
795
  return;
2380
796
  }
2381
- const { target: { updated: b } } = f, { updated: A } = h;
2382
- (!b || !A || b < A) && o.updateTarget(h);
797
+ const { target: { updated: R } } = p, { updated: k } = r;
798
+ (!R || !k || R < k) && o.updateTarget(r);
2383
799
  };
2384
- return document.addEventListener("pointerdown", y), document.addEventListener("pointerup", S), document.addEventListener("contextmenu", L), t.addEventListener("keyup", R), t.addEventListener("selectstart", m), document.addEventListener("selectionchange", c), {
800
+ return document.addEventListener("pointerdown", d), document.addEventListener("pointerup", f), document.addEventListener("contextmenu", h), t.addEventListener("keyup", w), t.addEventListener("selectstart", C), document.addEventListener("selectionchange", m), {
2385
801
  destroy: () => {
2386
- h = void 0, x = void 0, p = void 0, c.clear(), document.removeEventListener("pointerdown", y), document.removeEventListener("pointerup", S), document.removeEventListener("contextmenu", L), t.removeEventListener("keyup", R), t.removeEventListener("selectstart", m), document.removeEventListener("selectionchange", c), H.unbind();
802
+ r = void 0, A = void 0, S = void 0, m.clear(), document.removeEventListener("pointerdown", d), document.removeEventListener("pointerup", f), document.removeEventListener("contextmenu", h), t.removeEventListener("keyup", w), t.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", m), V.unbind();
2387
803
  },
2388
- setFilter: u,
2389
- setUser: d,
2390
- setAnnotatingEnabled: E
804
+ setFilter: g,
805
+ setUser: b,
806
+ setAnnotatingEnabled: x
2391
807
  };
2392
- }, Mo = (t, e) => ({
808
+ }, ue = (t, n) => ({
2393
809
  ...t,
2394
- annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
2395
- user: t.user || e.user
2396
- }), de = "SPANS", _o = (t, e = {}) => {
2397
- Be(t), Ie(t);
2398
- const n = Mo(e, {
810
+ annotatingEnabled: t.annotatingEnabled ?? n.annotatingEnabled,
811
+ user: t.user || n.user
812
+ }), et = "SPANS", ve = (t, n = {}) => {
813
+ Tt(t), Lt(t);
814
+ const e = ue(n, {
2399
815
  annotatingEnabled: !0,
2400
- user: qn()
2401
- }), o = ho(t, n), { selection: i, viewport: s } = o, a = o.store, r = Yn(a), l = Pn(o, r, n.adapter);
2402
- let d = n.user;
2403
- const g = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : de : n.renderer || de, u = g === "SPANS" ? mn(t, o, s) : g === "CSS_HIGHLIGHTS" ? hn(t, o, s) : g === "CANVAS" ? nn(t, o, s) : void 0;
2404
- if (!u)
2405
- throw `Unknown renderer implementation: ${g}`;
2406
- console.debug(`Using ${g} renderer`), n.style && u.setStyle(n.style);
2407
- const h = Ro(t, o, n);
2408
- h.setUser(d), h.setAnnotatingEnabled(n.annotatingEnabled);
2409
- const x = $n(o, r, n.adapter), p = () => d, w = (v) => {
2410
- h.setAnnotatingEnabled(
2411
- v === void 0 ? !0 : v
816
+ user: bt()
817
+ }), o = ie(t, e), { selection: s, viewport: i } = o, a = o.store, c = St(a), u = Ct(o, c, e.adapter);
818
+ let b = e.user;
819
+ const y = e.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : et : e.renderer || et, g = y === "SPANS" ? te(t, o, i) : y === "CSS_HIGHLIGHTS" ? Qt(t, o, i) : y === "CANVAS" ? qt(t, o, i) : void 0;
820
+ if (!g)
821
+ throw `Unknown renderer implementation: ${y}`;
822
+ console.debug(`Using ${y} renderer`), e.style && g.setStyle(e.style);
823
+ const r = de(t, o, e);
824
+ r.setUser(b), r.setAnnotatingEnabled(e.annotatingEnabled);
825
+ const A = Et(o, c, e.adapter), S = () => b, T = (l) => {
826
+ r.setAnnotatingEnabled(
827
+ l === void 0 ? !0 : l
2412
828
  );
2413
- }, E = (v) => {
2414
- u.setFilter(v), h.setFilter(v);
2415
- }, m = (v) => {
2416
- d = v, h.setUser(v);
2417
- }, c = (v) => {
2418
- v && (u.setPainter(go(v, n.presence)), v.on("selectionChange", () => u.redraw()));
2419
- }, y = (v) => {
2420
- v ? i.setSelected(v) : i.clear();
829
+ }, x = (l) => {
830
+ g.setFilter(l), r.setFilter(l);
831
+ }, C = (l) => {
832
+ b = l, r.setUser(l);
833
+ }, m = (l) => {
834
+ l && (g.setPainter(ce(l, e.presence)), l.on("selectionChange", () => g.redraw()));
835
+ }, d = (l) => {
836
+ l ? s.setSelected(l) : s.clear();
2421
837
  };
2422
838
  return {
2423
- ...x,
839
+ ...A,
2424
840
  destroy: () => {
2425
- u.destroy(), h.destroy(), r.destroy();
841
+ g.destroy(), r.destroy(), c.destroy();
2426
842
  },
2427
843
  element: t,
2428
- getUser: p,
2429
- setAnnotatingEnabled: w,
2430
- setFilter: E,
2431
- setStyle: u.setStyle.bind(u),
2432
- redraw: u.redraw.bind(u),
2433
- setUser: m,
2434
- setSelected: y,
2435
- setPresenceProvider: c,
2436
- setVisible: u.setVisible.bind(u),
2437
- on: l.on,
2438
- off: l.off,
2439
- scrollIntoView: ze(t, a),
844
+ getUser: S,
845
+ setAnnotatingEnabled: T,
846
+ setFilter: x,
847
+ setStyle: g.setStyle.bind(g),
848
+ redraw: g.redraw.bind(g),
849
+ setUser: C,
850
+ setSelected: d,
851
+ setPresenceProvider: m,
852
+ setVisible: g.setVisible.bind(g),
853
+ on: u.on,
854
+ off: u.off,
855
+ scrollIntoView: Ft(t, a),
2440
856
  state: o
2441
857
  };
2442
858
  };
2443
859
  export {
2444
- St as DEFAULT_SELECTED_STYLE,
2445
- G as DEFAULT_STYLE,
2446
- ue as NOT_ANNOTATABLE_CLASS,
2447
- nt as NOT_ANNOTATABLE_SELECTOR,
2448
- k as Origin,
2449
- vn as UserSelectAction,
2450
- No as W3CTextFormat,
2451
- Be as cancelSingleClickEvents,
2452
- pt as cloneKeyboardEvent,
2453
- Tt as clonePointerEvent,
2454
- Io as createBody,
2455
- nn as createCanvasRenderer,
2456
- hn as createHighlightsRenderer,
2457
- go as createPresencePainter,
2458
- fn as createRenderer,
2459
- Ro as createSelectionHandler,
2460
- mn as createSpansRenderer,
2461
- _o as createTextAnnotator,
2462
- ho as createTextAnnotatorState,
2463
- Mo as fillDefaults,
2464
- Ue as getQuoteContext,
2465
- Kt as getRangeAnnotatableContents,
2466
- ke as isMac,
2467
- rt as isNotAnnotatable,
2468
- Me as isRangeAnnotatable,
2469
- q as isRevived,
2470
- Ve as isWhitespaceOrEmpty,
2471
- Pe as mergeClientRects,
2472
- Fe as paint,
2473
- eo as parseW3CTextAnnotation,
2474
- Ie as programmaticallyFocusable,
2475
- $e as rangeContains,
2476
- Xe as rangeToSelector,
2477
- Lt as reviveAnnotation,
2478
- fe as reviveSelector,
2479
- vt as reviveTarget,
2480
- ze as scrollIntoView,
2481
- no as serializeW3CTextAnnotation,
2482
- _e as splitAnnotatableRanges,
2483
- Bo as toDomRectList,
2484
- je as toParentBounds,
2485
- ko as toViewportBounds,
2486
- He as trimRangeToContainer,
2487
- De as whitespaceOrEmptyRegex
860
+ z as DEFAULT_SELECTED_STYLE,
861
+ K as DEFAULT_STYLE,
862
+ st as NOT_ANNOTATABLE_CLASS,
863
+ D as NOT_ANNOTATABLE_SELECTOR,
864
+ Re as Origin,
865
+ Le as UserSelectAction,
866
+ Ae as W3CTextFormat,
867
+ Tt as cancelSingleClickEvents,
868
+ Y as cloneKeyboardEvent,
869
+ j as clonePointerEvent,
870
+ ke as createBody,
871
+ qt as createCanvasRenderer,
872
+ Qt as createHighlightsRenderer,
873
+ ce as createPresencePainter,
874
+ Gt as createRenderer,
875
+ de as createSelectionHandler,
876
+ te as createSpansRenderer,
877
+ ve as createTextAnnotator,
878
+ ie as createTextAnnotatorState,
879
+ ue as fillDefaults,
880
+ Nt as getQuoteContext,
881
+ G as getRangeAnnotatableContents,
882
+ Rt as isMac,
883
+ W as isNotAnnotatable,
884
+ xt as isRangeAnnotatable,
885
+ M as isRevived,
886
+ It as isWhitespaceOrEmpty,
887
+ Pt as mergeClientRects,
888
+ Ut as paint,
889
+ oe as parseW3CTextAnnotation,
890
+ Lt as programmaticallyFocusable,
891
+ $t as rangeContains,
892
+ Kt as rangeToSelector,
893
+ q as reviveAnnotation,
894
+ rt as reviveSelector,
895
+ X as reviveTarget,
896
+ Ft as scrollIntoView,
897
+ se as serializeW3CTextAnnotation,
898
+ Bt as splitAnnotatableRanges,
899
+ Ee as toDomRectList,
900
+ Dt as toParentBounds,
901
+ we as toViewportBounds,
902
+ _t as trimRangeToContainer,
903
+ Ot as whitespaceOrEmptyRegex
2488
904
  };
2489
905
  //# sourceMappingURL=text-annotator.es.js.map