@soomo/text-annotator 3.2.0-staging.5 → 3.2.0-staging.7

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