@soomo/text-annotator 3.2.0-staging.4 → 3.2.0-staging.6

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