@soomo/text-annotator 3.1.0-staging.2 → 3.1.0-staging.20

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