@soomo/text-annotator 3.0.0-staging.38 → 3.0.0-staging.39

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