@soomo/text-annotator 3.0.0-staging.59 → 3.0.0-staging.60

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,4 +1,4 @@
1
- const re = "not-annotatable", P = `.${re}`, Se = (t) => {
1
+ const se = "not-annotatable", P = `.${se}`, Se = (t) => {
2
2
  var n;
3
3
  const e = t.commonAncestorContainer;
4
4
  return e instanceof HTMLElement ? !e.closest(P) : !((n = e.parentElement) != null && n.closest(P));
@@ -6,7 +6,7 @@ const re = "not-annotatable", P = `.${re}`, Se = (t) => {
6
6
  const e = document.createNodeIterator(
7
7
  t.commonAncestorContainer,
8
8
  NodeFilter.SHOW_ELEMENT,
9
- (o) => o instanceof HTMLElement && o.classList.contains(re) && !o.parentElement.closest(P) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
9
+ (o) => o instanceof HTMLElement && o.classList.contains(se) && !o.parentElement.closest(P) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
10
10
  );
11
11
  let n;
12
12
  for (; n = e.nextNode(); )
@@ -32,21 +32,21 @@ const re = "not-annotatable", P = `.${re}`, Se = (t) => {
32
32
  !e.target.closest(P) && !e.target.closest("a") && e.preventDefault();
33
33
  }), Te = (t) => {
34
34
  !t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
35
- }, Ao = (t) => {
35
+ }, xo = (t) => {
36
36
  const e = t.cloneContents();
37
37
  return e.querySelectorAll(P).forEach((n) => n.remove()), e;
38
38
  }, Re = (t, e, n = 10, o) => {
39
- const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
40
- r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
41
- const a = It(r).textContent, s = document.createRange();
42
- s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
43
- const c = It(s).textContent;
39
+ const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
40
+ s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
41
+ const r = It(s).textContent, a = document.createRange();
42
+ a.setStart(t.endContainer, t.endOffset), i === document.body ? a.setEnd(i, i.childNodes.length) : a.setEndAfter(i);
43
+ const l = It(a).textContent;
44
44
  return {
45
- prefix: a.substring(a.length - n),
46
- suffix: c.substring(0, n)
45
+ prefix: r.substring(r.length - n),
46
+ suffix: l.substring(0, n)
47
47
  };
48
48
  }, Me = /^\s*$/, Be = (t) => Me.test(t.toString()), W = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ke = (t, e) => {
49
- const n = (r) => Math.round(r * 10) / 10, o = {
49
+ const n = (s) => Math.round(s * 10) / 10, o = {
50
50
  top: n(t.top),
51
51
  bottom: n(t.bottom),
52
52
  left: n(t.left),
@@ -70,25 +70,25 @@ const re = "not-annotatable", P = `.${re}`, Se = (t) => {
70
70
  } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
71
71
  return "block-is-contained";
72
72
  }, Ie = (t, e) => {
73
- const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), r = Math.max(t.bottom, e.bottom);
74
- return new DOMRect(n, i, o - n, r - i);
73
+ const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
74
+ return new DOMRect(n, i, o - n, s - i);
75
75
  }, _e = (t) => t.reduce((e, n) => {
76
76
  if (n.width === 0 || n.height === 0)
77
77
  return e;
78
78
  let o = [...e], i = !1;
79
- for (const r of e) {
80
- const a = ke(n, r);
81
- if (a === "inline-adjacent") {
82
- o = o.map((s) => s === r ? Ie(n, r) : s), i = !0;
79
+ for (const s of e) {
80
+ const r = ke(n, s);
81
+ if (r === "inline-adjacent") {
82
+ o = o.map((a) => a === s ? Ie(n, s) : a), i = !0;
83
83
  break;
84
- } else if (a === "inline-contains") {
85
- o = o.map((s) => s === r ? n : s), i = !0;
84
+ } else if (r === "inline-contains") {
85
+ o = o.map((a) => a === s ? n : a), i = !0;
86
86
  break;
87
- } else if (a === "inline-is-contained") {
87
+ } else if (r === "inline-is-contained") {
88
88
  i = !0;
89
89
  break;
90
- } else if (a === "block-contains" || a === "block-is-contained") {
91
- n.width < r.width && (o = o.map((s) => s === r ? n : s)), i = !0;
90
+ } else if (r === "block-contains" || r === "block-is-contained") {
91
+ n.width < s.width && (o = o.map((a) => a === s ? n : a)), i = !0;
92
92
  break;
93
93
  }
94
94
  }
@@ -103,58 +103,58 @@ const re = "not-annotatable", P = `.${re}`, Se = (t) => {
103
103
  }), Ne = (t, e, n) => {
104
104
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
105
105
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
106
- const r = It(o).textContent, a = t.toString(), s = r.length || 0, c = s + a.length;
107
- return n ? { quote: a, start: s, end: c, range: t, offsetReference: i } : { quote: a, start: s, end: c, range: t };
108
- }, se = (t, e) => {
109
- var h, l;
110
- const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
106
+ const s = It(o).textContent, r = t.toString(), a = s.length || 0, l = a + r.length;
107
+ return n ? { quote: r, start: a, end: l, range: t, offsetReference: i } : { quote: r, start: a, end: l, range: t };
108
+ }, re = (t, e) => {
109
+ var f, c;
110
+ const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
111
111
  e,
112
112
  NodeFilter.SHOW_TEXT,
113
- (p) => {
114
- var d;
115
- return (d = p.parentElement) != null && d.closest(P) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
113
+ (g) => {
114
+ var h;
115
+ return (h = g.parentElement) != null && h.closest(P) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
116
116
  }
117
117
  );
118
- let a = 0;
119
- const s = document.createRange();
120
- let c = r.nextNode();
121
- c === null && console.error("Could not revive annotation target. Content missing.");
122
- let f = !i;
123
- for (; c !== null; ) {
124
- if (f || (f = i == null ? void 0 : i.contains(c)), f) {
125
- const p = ((h = c.textContent) == null ? void 0 : h.length) || 0;
126
- if (a + p > n) {
127
- s.setStart(c, n - a);
118
+ let r = 0;
119
+ const a = document.createRange();
120
+ let l = s.nextNode();
121
+ l === null && console.error("Could not revive annotation target. Content missing.");
122
+ let u = !i;
123
+ for (; l !== null; ) {
124
+ if (u || (u = i == null ? void 0 : i.contains(l)), u) {
125
+ const g = ((f = l.textContent) == null ? void 0 : f.length) || 0;
126
+ if (r + g > n) {
127
+ a.setStart(l, n - r);
128
128
  break;
129
129
  }
130
- a += p;
130
+ r += g;
131
131
  }
132
- c = r.nextNode();
132
+ l = s.nextNode();
133
133
  }
134
- for (; c !== null; ) {
135
- const p = ((l = c.textContent) == null ? void 0 : l.length) || 0;
136
- if (a + p >= o) {
137
- s.setEnd(c, o - a);
134
+ for (; l !== null; ) {
135
+ const g = ((c = l.textContent) == null ? void 0 : c.length) || 0;
136
+ if (r + g >= o) {
137
+ a.setEnd(l, o - r);
138
138
  break;
139
139
  }
140
- a += p, c = r.nextNode();
140
+ r += g, l = s.nextNode();
141
141
  }
142
142
  return {
143
143
  ...t,
144
- range: s
144
+ range: a
145
145
  };
146
146
  }, yt = (t, e) => W(t.selector) ? t : {
147
147
  ...t,
148
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : se(n, e))
148
+ selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : re(n, e))
149
149
  }, wt = (t, e) => W(t.target.selector) ? t : { ...t, target: yt(t.target, e) }, Ue = (t, e) => {
150
150
  const n = t.cloneRange();
151
151
  return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
152
152
  }, Ve = (t, e) => {
153
- const { left: n, top: o, right: i, bottom: r } = t;
154
- return new DOMRect(n - e.left, o - e.top, i - n, r - o);
153
+ const { left: n, top: o, right: i, bottom: s } = t;
154
+ return new DOMRect(n - e.left, o - e.top, i - n, s - o);
155
155
  }, So = (t, e) => {
156
- const { left: n, top: o, right: i, bottom: r } = t;
157
- return new DOMRect(n + e.left, o + e.top, i - n, r - o);
156
+ const { left: n, top: o, right: i, bottom: s } = t;
157
+ return new DOMRect(n + e.left, o + e.top, i - n, s - o);
158
158
  }, De = (t) => ({
159
159
  ...t,
160
160
  type: t.type,
@@ -203,18 +203,18 @@ const re = "not-annotatable", P = `.${re}`, Se = (t) => {
203
203
  const { overflowY: e } = window.getComputedStyle(t);
204
204
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ae(t.parentElement);
205
205
  }, Ye = (t, e) => (n) => {
206
- const o = typeof n == "string" ? n : n.id, i = (a) => {
207
- const s = r.getBoundingClientRect(), c = r.clientHeight, f = r.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: l, height: p } = e.getAnnotationBounds(o), d = h.top - s.top, E = h.left - s.left, b = r.parentElement ? r.scrollTop : 0, C = r.parentElement ? r.scrollLeft : 0, g = d + b - (c - p) / 2, u = E + C - (f - l) / 2;
208
- r.scroll({ top: g, left: u, behavior: "smooth" });
209
- }, r = ae(t);
210
- if (r) {
211
- const a = e.getAnnotation(o), { range: s } = a.target.selector[0];
212
- if (s && !s.collapsed)
213
- return i(a.target), !0;
206
+ const o = typeof n == "string" ? n : n.id, i = (r) => {
207
+ const a = s.getBoundingClientRect(), l = s.clientHeight, u = s.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: c, height: g } = e.getAnnotationBounds(o), h = f.top - a.top, A = f.left - a.left, b = s.parentElement ? s.scrollTop : 0, S = s.parentElement ? s.scrollLeft : 0, p = h + b - (l - g) / 2, d = A + S - (u - c) / 2;
208
+ s.scroll({ top: p, left: d, behavior: "smooth" });
209
+ }, s = ae(t);
210
+ if (s) {
211
+ const r = e.getAnnotation(o), { range: a } = r.target.selector[0];
212
+ if (a && !a.collapsed)
213
+ return i(r.target), !0;
214
214
  {
215
- const c = yt(a.target, t), { range: f } = c.selector[0];
216
- if (f && !f.collapsed)
217
- return i(c), !0;
215
+ const l = yt(r.target, t), { range: u } = l.selector[0];
216
+ if (u && !u.collapsed)
217
+ return i(l), !0;
218
218
  }
219
219
  }
220
220
  return !1;
@@ -225,98 +225,98 @@ const re = "not-annotatable", P = `.${re}`, Se = (t) => {
225
225
  fill: "rgb(0, 128, 255)",
226
226
  fillOpacity: 0.45
227
227
  }, Xe = (t, e, n, o, i) => {
228
- var a, s;
229
- const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? bt : q) : n : (s = t.state) != null && s.selected ? bt : q;
230
- return o && o.paint(t, e) || r;
228
+ var r, a;
229
+ const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((r = t.state) != null && r.selected ? bt : q) : n : (a = t.state) != null && a.selected ? bt : q;
230
+ return o && o.paint(t, e) || s;
231
231
  };
232
232
  function $e(t) {
233
233
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
234
234
  }
235
235
  var Ut = { exports: {} };
236
- function le(t, e = 100, n = {}) {
236
+ function ce(t, e = 100, n = {}) {
237
237
  if (typeof t != "function")
238
238
  throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);
239
239
  if (e < 0)
240
240
  throw new RangeError("`wait` must not be negative.");
241
241
  const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
242
- let i, r, a, s, c;
243
- function f() {
244
- const p = i, d = r;
245
- return i = void 0, r = void 0, c = t.apply(p, d), c;
242
+ let i, s, r, a, l;
243
+ function u() {
244
+ const g = i, h = s;
245
+ return i = void 0, s = void 0, l = t.apply(g, h), l;
246
246
  }
247
- function h() {
248
- const p = Date.now() - s;
249
- p < e && p >= 0 ? a = setTimeout(h, e - p) : (a = void 0, o || (c = f()));
247
+ function f() {
248
+ const g = Date.now() - a;
249
+ g < e && g >= 0 ? r = setTimeout(f, e - g) : (r = void 0, o || (l = u()));
250
250
  }
251
- const l = function(...p) {
251
+ const c = function(...g) {
252
252
  if (i && this !== i && Object.getPrototypeOf(this) === Object.getPrototypeOf(i))
253
253
  throw new Error("Debounced method called with different contexts of the same prototype.");
254
- i = this, r = p, s = Date.now();
255
- const d = o && !a;
256
- return a || (a = setTimeout(h, e)), d && (c = f()), c;
254
+ i = this, s = g, a = Date.now();
255
+ const h = o && !r;
256
+ return r || (r = setTimeout(f, e)), h && (l = u()), l;
257
257
  };
258
- return l.clear = () => {
259
- a && (clearTimeout(a), a = void 0);
260
- }, l.flush = () => {
261
- a && l.trigger();
262
- }, l.trigger = () => {
263
- c = f(), l.clear();
264
- }, l;
258
+ return c.clear = () => {
259
+ r && (clearTimeout(r), r = void 0);
260
+ }, c.flush = () => {
261
+ r && c.trigger();
262
+ }, c.trigger = () => {
263
+ l = u(), c.clear();
264
+ }, c;
265
265
  }
266
- Ut.exports.debounce = le;
267
- Ut.exports = le;
266
+ Ut.exports.debounce = ce;
267
+ Ut.exports = ce;
268
268
  var Pe = Ut.exports;
269
269
  const Vt = /* @__PURE__ */ $e(Pe), je = (t) => {
270
- const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, c = i - e;
271
- return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: c };
270
+ const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, r = -e, a = o - n, l = i - e;
271
+ return { top: e, left: n, minX: s, minY: r, maxX: a, maxY: l };
272
272
  }, He = (t) => {
273
273
  let e = /* @__PURE__ */ new Set();
274
274
  return (o) => {
275
- const i = o.map((r) => r.id);
276
- (e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
275
+ const i = o.map((s) => s.id);
276
+ (e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
277
277
  };
278
278
  }, Dt = (t, e, n, o) => {
279
- const { store: i, selection: r, hover: a } = e;
280
- let s, c, f;
281
- const h = He(n), l = (O) => {
282
- const { x: R, y: m } = t.getBoundingClientRect(), v = i.getAt(O.clientX - R, O.clientY - m, c);
283
- v ? a.current !== v.id && (t.classList.add("hovered"), a.set(v.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
279
+ const { store: i, selection: s, hover: r } = e;
280
+ let a, l, u;
281
+ const f = He(n), c = (O) => {
282
+ const { x: R, y: m } = t.getBoundingClientRect(), v = i.getAt(O.clientX - R, O.clientY - m, l);
283
+ v ? r.current !== v.id && (t.classList.add("hovered"), r.set(v.id)) : r.current && (t.classList.remove("hovered"), r.set(null));
284
284
  };
285
- t.addEventListener("pointermove", l);
286
- const p = (O = !1) => {
287
- f && f.clear();
288
- const R = je(t), { minX: m, minY: v, maxX: x, maxY: L } = R, B = c ? i.getIntersecting(m, v, x, L).filter(({ annotation: Y }) => c(Y)) : i.getIntersecting(m, v, x, L), M = r.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: ct }) => {
289
- const Ae = M.includes(Y.id), Ee = Y.id === a.current;
290
- return { annotation: Y, rects: ct, state: { selected: Ae, hover: Ee } };
285
+ t.addEventListener("pointermove", c);
286
+ const g = (O = !1) => {
287
+ u && u.clear();
288
+ const R = je(t), { minX: m, minY: v, maxX: x, maxY: L } = R, B = l ? i.getIntersecting(m, v, x, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(m, v, x, L), M = s.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: lt }) => {
289
+ const xe = M.includes(Y.id), Ee = Y.id === r.current;
290
+ return { annotation: Y, rects: lt, state: { selected: xe, hover: Ee } };
291
291
  });
292
- o.redraw(K, R, s, f, O), setTimeout(() => h(B.map(({ annotation: Y }) => Y)), 1);
293
- }, d = (O) => {
294
- f = O, p();
295
- }, E = (O) => {
296
- s = O, p();
292
+ o.redraw(K, R, a, u, O), setTimeout(() => f(B.map(({ annotation: Y }) => Y)), 1);
293
+ }, h = (O) => {
294
+ u = O, g();
295
+ }, A = (O) => {
296
+ a = O, g();
297
297
  }, b = (O) => {
298
- c = O, p(!1);
299
- }, C = () => p();
300
- i.observe(C);
301
- const g = r.subscribe(() => p()), u = () => p(!0);
302
- document.addEventListener("scroll", u, { capture: !0, passive: !0 });
298
+ l = O, g(!1);
299
+ }, S = () => g();
300
+ i.observe(S);
301
+ const p = s.subscribe(() => g()), d = () => g(!0);
302
+ document.addEventListener("scroll", d, { capture: !0, passive: !0 });
303
303
  const y = Vt(() => {
304
- i.recalculatePositions(), f == null || f.reset(), p();
304
+ i.recalculatePositions(), u == null || u.reset(), g();
305
305
  }, 10);
306
306
  window.addEventListener("resize", y);
307
- const S = new ResizeObserver(y);
308
- S.observe(t);
309
- const A = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver((O) => {
310
- O.every((m) => m.target === t || t.contains(m.target)) || p(!0);
307
+ const C = new ResizeObserver(y);
308
+ C.observe(t);
309
+ const E = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver((O) => {
310
+ O.every((m) => m.target === t || t.contains(m.target)) || g(!0);
311
311
  });
312
- return w.observe(document.body, A), {
312
+ return w.observe(document.body, E), {
313
313
  destroy: () => {
314
- t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(C), g(), document.removeEventListener("scroll", u), y.clear(), window.removeEventListener("resize", y), S.disconnect(), w.disconnect();
314
+ t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(S), p(), document.removeEventListener("scroll", d), y.clear(), window.removeEventListener("resize", y), C.disconnect(), w.disconnect();
315
315
  },
316
- redraw: p,
317
- setStyle: E,
316
+ redraw: g,
317
+ setStyle: A,
318
318
  setFilter: b,
319
- setPainter: d,
319
+ setPainter: h,
320
320
  setVisible: o.setVisible
321
321
  };
322
322
  }, ze = () => {
@@ -328,28 +328,28 @@ const Vt = /* @__PURE__ */ $e(Pe), je = (t) => {
328
328
  t.classList.add("r6o-annotatable");
329
329
  const e = ze(), n = e.getContext("2d");
330
330
  document.body.appendChild(e);
331
- const o = (s, c, f, h) => requestAnimationFrame(() => {
332
- const { width: l, height: p } = e;
333
- n.clearRect(-0.5, -0.5, l + 1, p + 1), h && h.clear();
334
- const { top: d, left: E } = c;
335
- [...s].sort((C, g) => {
336
- const { annotation: { target: { created: u } } } = C, { annotation: { target: { created: y } } } = g;
337
- return u.getTime() - y.getTime();
338
- }).forEach((C) => {
339
- var S;
340
- const g = f ? typeof f == "function" ? f(C.annotation, C.state) : f : (S = C.state) != null && S.selected ? bt : q, u = h && h.paint(C, c) || g, y = C.rects.map(({ x: A, y: w, width: T, height: O }) => ({
341
- x: A + E,
342
- y: w + d,
331
+ const o = (a, l, u, f) => requestAnimationFrame(() => {
332
+ const { width: c, height: g } = e;
333
+ n.clearRect(-0.5, -0.5, c + 1, g + 1), f && f.clear();
334
+ const { top: h, left: A } = l;
335
+ [...a].sort((S, p) => {
336
+ const { annotation: { target: { created: d } } } = S, { annotation: { target: { created: y } } } = p;
337
+ return d.getTime() - y.getTime();
338
+ }).forEach((S) => {
339
+ var C;
340
+ const p = u ? typeof u == "function" ? u(S.annotation, S.state) : u : (C = S.state) != null && C.selected ? bt : q, d = f && f.paint(S, l) || p, y = S.rects.map(({ x: E, y: w, width: T, height: O }) => ({
341
+ x: E + A,
342
+ y: w + h,
343
343
  width: T,
344
344
  height: O
345
345
  }));
346
- if (n.fillStyle = u.fill, n.globalAlpha = u.fillOpacity || 1, y.forEach(
347
- ({ x: A, y: w, width: T, height: O }) => n.fillRect(A, w, T, O)
348
- ), u.underlineColor) {
349
- n.globalAlpha = 1, n.strokeStyle = u.underlineColor, n.lineWidth = u.underlineThickness ?? 1;
350
- const A = u.underlineOffset ?? 0;
346
+ if (n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1, y.forEach(
347
+ ({ x: E, y: w, width: T, height: O }) => n.fillRect(E, w, T, O)
348
+ ), d.underlineColor) {
349
+ n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
350
+ const E = d.underlineOffset ?? 0;
351
351
  y.forEach(({ x: w, y: T, width: O, height: R }) => {
352
- n.beginPath(), n.moveTo(w, T + R + A), n.lineTo(w + O, T + R + A), n.stroke();
352
+ n.beginPath(), n.moveTo(w, T + R + E), n.lineTo(w + O, T + R + E), n.stroke();
353
353
  });
354
354
  }
355
355
  });
@@ -358,7 +358,7 @@ const Vt = /* @__PURE__ */ $e(Pe), je = (t) => {
358
358
  destroy: () => {
359
359
  e.remove(), i.clear(), window.removeEventListener("resize", i);
360
360
  },
361
- setVisible: (s) => {
361
+ setVisible: (a) => {
362
362
  console.log("setVisible not implemented on Canvas renderer");
363
363
  },
364
364
  redraw: o
@@ -370,7 +370,7 @@ var Ge = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
370
370
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
371
371
  }, X = function(t, e, n) {
372
372
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
373
- }, ce = function(t) {
373
+ }, le = function(t) {
374
374
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
375
375
  }, Xt = function(t) {
376
376
  return { r: X(t.r, 0, 255), g: X(t.g, 0, 255), b: X(t.b, 0, 255), a: X(t.a) };
@@ -380,15 +380,15 @@ var Ge = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
380
380
  var e = t.toString(16);
381
381
  return e.length < 2 ? "0" + e : e;
382
382
  }, de = function(t) {
383
- var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), a = r - Math.min(e, n, o), s = a ? r === e ? (n - o) / a : r === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
384
- return { h: 60 * (s < 0 ? s + 6 : s), s: r ? a / r * 100 : 0, v: r / 255 * 100, a: i };
383
+ var e = t.r, n = t.g, o = t.b, i = t.a, s = Math.max(e, n, o), r = s - Math.min(e, n, o), a = r ? s === e ? (n - o) / r : s === n ? 2 + (o - e) / r : 4 + (e - n) / r : 0;
384
+ return { h: 60 * (a < 0 ? a + 6 : a), s: s ? r / s * 100 : 0, v: s / 255 * 100, a: i };
385
385
  }, ue = function(t) {
386
386
  var e = t.h, n = t.s, o = t.v, i = t.a;
387
387
  e = e / 360 * 6, n /= 100, o /= 100;
388
- var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), c = o * (1 - (1 - e + r) * n), f = r % 6;
389
- return { r: 255 * [o, s, a, a, c, o][f], g: 255 * [c, o, o, s, a, a][f], b: 255 * [a, a, c, o, o, s][f], a: i };
388
+ var s = Math.floor(e), r = o * (1 - n), a = o * (1 - (e - s) * n), l = o * (1 - (1 - e + s) * n), u = s % 6;
389
+ return { r: 255 * [o, a, r, r, l, o][u], g: 255 * [l, o, o, a, r, r][u], b: 255 * [r, r, l, o, o, a][u], a: i };
390
390
  }, $t = function(t) {
391
- return { h: ce(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
391
+ return { h: le(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
392
392
  }, Pt = function(t) {
393
393
  return { h: N(t.h), s: N(t.s), l: N(t.l), a: N(t.a, 3) };
394
394
  }, jt = function(t) {
@@ -409,20 +409,20 @@ var Ge = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
409
409
  var n, o, i = $t({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (Ge[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
410
410
  return jt(i);
411
411
  }, "hsl"]], object: [[function(t) {
412
- var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
413
- return z(e) && z(n) && z(o) ? Xt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
412
+ var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
413
+ return z(e) && z(n) && z(o) ? Xt({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
414
414
  }, "rgb"], [function(t) {
415
- var e = t.h, n = t.s, o = t.l, i = t.a, r = i === void 0 ? 1 : i;
415
+ var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
416
416
  if (!z(e) || !z(n) || !z(o)) return null;
417
- var a = $t({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
418
- return jt(a);
417
+ var r = $t({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
418
+ return jt(r);
419
419
  }, "hsl"], [function(t) {
420
- var e = t.h, n = t.s, o = t.v, i = t.a, r = i === void 0 ? 1 : i;
420
+ var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
421
421
  if (!z(e) || !z(n) || !z(o)) return null;
422
- var a = function(s) {
423
- return { h: ce(s.h), s: X(s.s, 0, 100), v: X(s.v, 0, 100), a: X(s.a) };
424
- }({ h: Number(e), s: Number(n), v: Number(o), a: Number(r) });
425
- return ue(a);
422
+ var r = function(a) {
423
+ return { h: le(a.h), s: X(a.s, 0, 100), v: X(a.v, 0, 100), a: X(a.a) };
424
+ }({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
425
+ return ue(r);
426
426
  }, "hsv"]] }, zt = function(t, e) {
427
427
  for (var n = 0; n < e.length; n++) {
428
428
  var o = e[n][0](t);
@@ -431,10 +431,10 @@ var Ge = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
431
431
  return [null, void 0];
432
432
  }, nn = function(t) {
433
433
  return typeof t == "string" ? zt(t.trim(), Ht.string) : typeof t == "object" && t !== null ? zt(t, Ht.object) : [null, void 0];
434
- }, xt = function(t, e) {
434
+ }, At = function(t, e) {
435
435
  var n = it(t);
436
436
  return { h: n.h, s: X(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
437
- }, At = function(t) {
437
+ }, xt = function(t) {
438
438
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
439
439
  }, Ft = function(t, e) {
440
440
  var n = it(t);
@@ -446,24 +446,24 @@ var Ge = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
446
446
  return t.prototype.isValid = function() {
447
447
  return this.parsed !== null;
448
448
  }, t.prototype.brightness = function() {
449
- return N(At(this.rgba), 2);
449
+ return N(xt(this.rgba), 2);
450
450
  }, t.prototype.isDark = function() {
451
- return At(this.rgba) < 0.5;
451
+ return xt(this.rgba) < 0.5;
452
452
  }, t.prototype.isLight = function() {
453
- return At(this.rgba) >= 0.5;
453
+ return xt(this.rgba) >= 0.5;
454
454
  }, t.prototype.toHex = function() {
455
- return e = vt(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? dt(N(255 * r)) : "", "#" + dt(n) + dt(o) + dt(i) + a;
456
- var e, n, o, i, r, a;
455
+ return e = vt(this.rgba), n = e.r, o = e.g, i = e.b, r = (s = e.a) < 1 ? dt(N(255 * s)) : "", "#" + dt(n) + dt(o) + dt(i) + r;
456
+ var e, n, o, i, s, r;
457
457
  }, t.prototype.toRgb = function() {
458
458
  return vt(this.rgba);
459
459
  }, t.prototype.toRgbString = function() {
460
- return e = vt(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
461
- var e, n, o, i, r;
460
+ return e = vt(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
461
+ var e, n, o, i, s;
462
462
  }, t.prototype.toHsl = function() {
463
463
  return Pt(it(this.rgba));
464
464
  }, t.prototype.toHslString = function() {
465
- return e = Pt(it(this.rgba)), n = e.h, o = e.s, i = e.l, (r = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + r + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
466
- var e, n, o, i, r;
465
+ return e = Pt(it(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
466
+ var e, n, o, i, s;
467
467
  }, t.prototype.toHsv = function() {
468
468
  return e = de(this.rgba), { h: N(e.h), s: N(e.s), v: N(e.v), a: N(e.a, 3) };
469
469
  var e;
@@ -471,11 +471,11 @@ var Ge = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
471
471
  return $({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
472
472
  var e;
473
473
  }, t.prototype.saturate = function(e) {
474
- return e === void 0 && (e = 0.1), $(xt(this.rgba, e));
474
+ return e === void 0 && (e = 0.1), $(At(this.rgba, e));
475
475
  }, t.prototype.desaturate = function(e) {
476
- return e === void 0 && (e = 0.1), $(xt(this.rgba, -e));
476
+ return e === void 0 && (e = 0.1), $(At(this.rgba, -e));
477
477
  }, t.prototype.grayscale = function() {
478
- return $(xt(this.rgba, -1));
478
+ return $(At(this.rgba, -1));
479
479
  }, t.prototype.lighten = function(e) {
480
480
  return e === void 0 && (e = 0.1), $(Ft(this.rgba, e));
481
481
  }, t.prototype.darken = function(e) {
@@ -500,7 +500,7 @@ const on = (t) => [
500
500
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
501
501
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
502
502
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
503
- ].filter(Boolean).join(";"), rn = () => {
503
+ ].filter(Boolean).join(";"), sn = () => {
504
504
  const t = document.createElement("style");
505
505
  document.getElementsByTagName("head")[0].appendChild(t);
506
506
  let e = /* @__PURE__ */ new Set();
@@ -508,26 +508,26 @@ const on = (t) => [
508
508
  destroy: () => {
509
509
  CSS.highlights.clear(), t.remove();
510
510
  },
511
- setVisible: (r) => {
511
+ setVisible: (s) => {
512
512
  console.log("setVisible not implemented on CSS Custom Highlights renderer");
513
513
  },
514
- redraw: (r, a, s, c) => {
515
- c && c.clear();
516
- const f = new Set(r.map((l) => l.annotation.id));
517
- Array.from(e).filter((l) => !f.has(l));
518
- const h = r.map((l) => {
519
- var E;
520
- const p = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (E = l.state) != null && E.selected ? bt : q, d = c && c.paint(l, a) || p;
521
- return `::highlight(_${l.annotation.id}) { ${on(d)} }`;
514
+ redraw: (s, r, a, l) => {
515
+ l && l.clear();
516
+ const u = new Set(s.map((c) => c.annotation.id));
517
+ Array.from(e).filter((c) => !u.has(c));
518
+ const f = s.map((c) => {
519
+ var A;
520
+ const g = a ? typeof a == "function" ? a(c.annotation, c.state) : a : (A = c.state) != null && A.selected ? bt : q, h = l && l.paint(c, r) || g;
521
+ return `::highlight(_${c.annotation.id}) { ${on(h)} }`;
522
522
  });
523
- t.innerHTML = h.join(`
524
- `), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
525
- const p = l.target.selector.map((E) => E.range), d = new Highlight(...p);
526
- CSS.highlights.set(`_${l.id}`, d);
527
- }), e = f;
523
+ t.innerHTML = f.join(`
524
+ `), CSS.highlights.clear(), s.forEach(({ annotation: c }) => {
525
+ const g = c.target.selector.map((A) => A.range), h = new Highlight(...g);
526
+ CSS.highlights.set(`_${c.id}`, h);
527
+ }), e = u;
528
528
  }
529
529
  };
530
- }, sn = (t, e, n) => Dt(t, e, n, rn());
530
+ }, rn = (t, e, n) => Dt(t, e, n, sn());
531
531
  var qt = Object.prototype.hasOwnProperty;
532
532
  function _t(t, e) {
533
533
  var n, o;
@@ -550,9 +550,9 @@ function _t(t, e) {
550
550
  return t !== t && e !== e;
551
551
  }
552
552
  const an = (t, e) => {
553
- const n = (r, a) => r.x <= a.x + a.width && r.x + r.width >= a.x && r.y <= a.y + a.height && r.y + r.height >= a.y, o = (r) => r.rects.reduce((a, s) => a + s.width, 0), i = e.filter(({ rects: r }) => r.some((a) => n(t, a)));
554
- return i.sort((r, a) => o(a) - o(r)), i.findIndex((r) => r.rects.includes(t));
555
- }, ln = (t) => {
553
+ 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)));
554
+ return i.sort((s, r) => o(r) - o(s)), i.findIndex((s) => s.rects.includes(t));
555
+ }, cn = (t) => {
556
556
  t.classList.add("r6o-annotatable");
557
557
  const e = document.createElement("div");
558
558
  e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
@@ -561,27 +561,27 @@ const an = (t, e) => {
561
561
  destroy: () => {
562
562
  e.remove();
563
563
  },
564
- redraw: (a, s, c, f, h) => {
565
- const p = !(_t(n, a) && h);
566
- if (!f && !p) return;
567
- p && (e.innerHTML = ""), [...a].sort((E, b) => {
568
- const { annotation: { target: { created: C } } } = E, { annotation: { target: { created: g } } } = b;
569
- return C && g ? C.getTime() - g.getTime() : 0;
570
- }).forEach((E) => {
571
- E.rects.map((b) => {
572
- const C = an(b, a), g = Xe(E, s, c, f, C);
573
- if (p) {
574
- const u = document.createElement("span");
575
- u.className = "r6o-annotation", u.dataset.annotation = E.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 = $((g == null ? void 0 : g.fill) || q.fill).alpha((g == null ? void 0 : g.fillOpacity) === void 0 ? q.fillOpacity : g.fillOpacity).toHex(), g.underlineStyle && (u.style.borderStyle = g.underlineStyle), g.underlineColor && (u.style.borderColor = g.underlineColor), g.underlineThickness && (u.style.borderBottomWidth = `${g.underlineThickness}px`), g.underlineOffset && (u.style.paddingBottom = `${g.underlineOffset}px`), e.appendChild(u);
564
+ redraw: (r, a, l, u, f) => {
565
+ const g = !(_t(n, r) && f);
566
+ if (!u && !g) return;
567
+ g && (e.innerHTML = ""), [...r].sort((A, b) => {
568
+ const { annotation: { target: { created: S } } } = A, { annotation: { target: { created: p } } } = b;
569
+ return S && p ? S.getTime() - p.getTime() : 0;
570
+ }).forEach((A) => {
571
+ A.rects.map((b) => {
572
+ const S = an(b, r), p = Xe(A, a, l, u, S);
573
+ if (g) {
574
+ const d = document.createElement("span");
575
+ d.className = "r6o-annotation", d.dataset.annotation = A.annotation.id, d.style.left = `${b.x}px`, d.style.top = `${b.y}px`, d.style.width = `${b.width}px`, d.style.height = `${b.height}px`, d.style.backgroundColor = $((p == null ? void 0 : p.fill) || q.fill).alpha((p == null ? void 0 : p.fillOpacity) === void 0 ? q.fillOpacity : p.fillOpacity).toHex(), p.underlineStyle && (d.style.borderStyle = p.underlineStyle), p.underlineColor && (d.style.borderColor = p.underlineColor), p.underlineThickness && (d.style.borderBottomWidth = `${p.underlineThickness}px`), p.underlineOffset && (d.style.paddingBottom = `${p.underlineOffset}px`), e.appendChild(d);
576
576
  }
577
577
  });
578
- }), n = a;
578
+ }), n = r;
579
579
  },
580
- setVisible: (a) => {
581
- a ? e.classList.remove("hidden") : e.classList.add("hidden");
580
+ setVisible: (r) => {
581
+ r ? e.classList.remove("hidden") : e.classList.add("hidden");
582
582
  }
583
583
  };
584
- }, cn = (t, e, n) => Dt(t, e, n, ln(t));
584
+ }, ln = (t, e, n) => Dt(t, e, n, cn(t));
585
585
  var U = [];
586
586
  for (var Et = 0; Et < 256; ++Et)
587
587
  U.push((Et + 256).toString(16).slice(1));
@@ -628,44 +628,44 @@ function G(t, e) {
628
628
  }
629
629
  function St() {
630
630
  }
631
- function gn(t, e) {
631
+ function pn(t, e) {
632
632
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
633
633
  }
634
634
  const Q = [];
635
635
  function Kt(t, e = St) {
636
636
  let n;
637
637
  const o = /* @__PURE__ */ new Set();
638
- function i(s) {
639
- if (gn(t, s) && (t = s, n)) {
640
- const c = !Q.length;
641
- for (const f of o)
642
- f[1](), Q.push(f, t);
643
- if (c) {
644
- for (let f = 0; f < Q.length; f += 2)
645
- Q[f][0](Q[f + 1]);
638
+ function i(a) {
639
+ if (pn(t, a) && (t = a, n)) {
640
+ const l = !Q.length;
641
+ for (const u of o)
642
+ u[1](), Q.push(u, t);
643
+ if (l) {
644
+ for (let u = 0; u < Q.length; u += 2)
645
+ Q[u][0](Q[u + 1]);
646
646
  Q.length = 0;
647
647
  }
648
648
  }
649
649
  }
650
- function r(s) {
651
- i(s(t));
650
+ function s(a) {
651
+ i(a(t));
652
652
  }
653
- function a(s, c = St) {
654
- const f = [s, c];
655
- return o.add(f), o.size === 1 && (n = e(i, r) || St), s(t), () => {
656
- o.delete(f), o.size === 0 && n && (n(), n = null);
653
+ function r(a, l = St) {
654
+ const u = [a, l];
655
+ return o.add(u), o.size === 1 && (n = e(i, s) || St), a(t), () => {
656
+ o.delete(u), o.size === 0 && n && (n(), n = null);
657
657
  };
658
658
  }
659
- return { set: i, update: r, subscribe: a };
659
+ return { set: i, update: s, subscribe: r };
660
660
  }
661
- const pn = (t) => {
661
+ const gn = (t) => {
662
662
  const { subscribe: e, set: n } = Kt();
663
663
  let o;
664
664
  return e((i) => o = i), t.observe(({ changes: i }) => {
665
665
  if (o) {
666
- (i.deleted || []).some((a) => a.id === o) && n(void 0);
667
- const r = (i.updated || []).find(({ oldValue: a }) => a.id === o);
668
- r && n(r.newValue.id);
666
+ (i.deleted || []).some((r) => r.id === o) && n(void 0);
667
+ const s = (i.updated || []).find(({ oldValue: r }) => r.id === o);
668
+ s && n(s.newValue.id);
669
669
  }
670
670
  }), {
671
671
  get current() {
@@ -676,52 +676,52 @@ const pn = (t) => {
676
676
  };
677
677
  };
678
678
  var mn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(mn || {});
679
- const ft = { selected: [] }, yn = (t, e) => {
680
- const { subscribe: n, set: o } = Kt(ft);
681
- let i = e, r = ft;
682
- n((d) => r = d);
679
+ const ft = { selected: [] }, yn = (t, e, n) => {
680
+ const { subscribe: o, set: i } = Kt(ft);
681
+ let s = e, r = ft;
682
+ o((A) => r = A);
683
683
  const a = () => {
684
- G(r, ft) || o(ft);
685
- }, s = () => {
686
- var d;
687
- return ((d = r.selected) == null ? void 0 : d.length) === 0;
688
- }, c = (d) => {
689
- if (s())
684
+ G(r, ft) || i(ft);
685
+ }, l = () => {
686
+ var A;
687
+ return ((A = r.selected) == null ? void 0 : A.length) === 0;
688
+ }, u = (A) => {
689
+ if (l())
690
690
  return !1;
691
- const E = typeof d == "string" ? d : d.id;
692
- return r.selected.some((b) => b.id === E);
693
- }, f = (d, E) => {
694
- const b = t.getAnnotation(d);
695
- if (!b) {
696
- console.warn("Invalid selection: " + d);
691
+ const b = typeof A == "string" ? A : A.id;
692
+ return r.selected.some((S) => S.id === b);
693
+ }, f = (A, b) => {
694
+ const S = t.getAnnotation(A);
695
+ if (!S) {
696
+ console.warn("Invalid selection: " + A);
697
697
  return;
698
698
  }
699
- switch (Jt(b, i)) {
699
+ switch (Jt(S, s)) {
700
700
  case "EDIT":
701
- o({ selected: [{ id: d, editable: !0 }], event: E });
701
+ i({ selected: [{ id: A, editable: !0 }], event: b });
702
702
  break;
703
703
  case "SELECT":
704
- o({ selected: [{ id: d }], event: E });
704
+ i({ selected: [{ id: A }], event: b });
705
705
  break;
706
706
  default:
707
- o({ selected: [], event: E });
707
+ i({ selected: [], event: b });
708
708
  }
709
- }, h = (d, E) => {
710
- const b = Array.isArray(d) ? d : [d], C = b.map((g) => t.getAnnotation(g)).filter((g) => !!g);
711
- o({
712
- selected: C.map((g) => {
713
- const u = E === void 0 ? Jt(g, i) === "EDIT" : E;
714
- return { id: g.id, editable: u };
709
+ }, c = (A, b) => {
710
+ const S = Array.isArray(A) ? A : [A], p = S.map((d) => t.getAnnotation(d)).filter((d) => !!d);
711
+ i({
712
+ selected: p.map((d) => {
713
+ const y = b === void 0 ? Jt(d, s) === "EDIT" : b;
714
+ return { id: d.id, editable: y };
715
715
  })
716
- }), C.length !== b.length && console.warn("Invalid selection", d);
717
- }, l = (d) => {
718
- if (s())
716
+ }), p.length !== S.length && console.warn("Invalid selection", A);
717
+ }, g = (A) => {
718
+ if (l())
719
719
  return !1;
720
- const { selected: E } = r;
721
- E.some(({ id: b }) => d.includes(b)) && o({ selected: E.filter(({ id: b }) => !d.includes(b)) });
722
- }, p = (d) => i = d;
720
+ const { selected: b } = r;
721
+ b.some(({ id: S }) => A.includes(S)) && i({ selected: b.filter(({ id: S }) => !A.includes(S)) });
722
+ }, h = (A) => s = A;
723
723
  return t.observe(
724
- ({ changes: d }) => l((d.deleted || []).map((E) => E.id))
724
+ ({ changes: A }) => g((A.deleted || []).map((b) => b.id))
725
725
  ), {
726
726
  get event() {
727
727
  return r ? r.event : null;
@@ -730,17 +730,17 @@ const ft = { selected: [] }, yn = (t, e) => {
730
730
  return r ? [...r.selected] : null;
731
731
  },
732
732
  get userSelectAction() {
733
- return i;
733
+ return s;
734
734
  },
735
735
  clear: a,
736
- isEmpty: s,
737
- isSelected: c,
738
- setSelected: h,
739
- setUserSelectAction: p,
740
- subscribe: n,
736
+ isEmpty: l,
737
+ isSelected: u,
738
+ setSelected: c,
739
+ setUserSelectAction: h,
740
+ subscribe: o,
741
741
  userSelect: f
742
742
  };
743
- }, Jt = (t, e) => typeof e == "function" ? e(t) : e || "EDIT";
743
+ }, Jt = (t, e, n) => typeof e == "function" ? e(t) : e || "EDIT";
744
744
  var V = [];
745
745
  for (var Ct = 0; Ct < 256; ++Ct)
746
746
  V.push((Ct + 256).toString(16).slice(1));
@@ -753,9 +753,9 @@ function vn() {
753
753
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
754
754
  return ht(wn);
755
755
  }
756
- var xn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
756
+ var An = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
757
757
  const Zt = {
758
- randomUUID: xn
758
+ randomUUID: An
759
759
  };
760
760
  function he(t, e, n) {
761
761
  if (Zt.randomUUID && !e && !t)
@@ -780,7 +780,7 @@ const Lt = (t) => {
780
780
  created: n || /* @__PURE__ */ new Date(),
781
781
  creator: o,
782
782
  ...e
783
- }), An = (t, e) => {
783
+ }), xn = (t, e) => {
784
784
  const n = new Set(t.bodies.map((o) => o.id));
785
785
  return e.bodies.filter((o) => !n.has(o.id));
786
786
  }, En = (t, e) => {
@@ -789,8 +789,8 @@ const Lt = (t) => {
789
789
  }, Sn = (t, e) => e.bodies.map((n) => {
790
790
  const o = t.bodies.find((i) => i.id === n.id);
791
791
  return { newBody: n, oldBody: o && !G(o, n) ? o : void 0 };
792
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Cn = (t, e) => !G(t.target, e.target), ge = (t, e) => {
793
- const n = An(t, e), o = En(t, e), i = Sn(t, e);
792
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Cn = (t, e) => !G(t.target, e.target), pe = (t, e) => {
793
+ const n = xn(t, e), o = En(t, e), i = Sn(t, e);
794
794
  return {
795
795
  oldValue: t,
796
796
  newValue: e,
@@ -803,45 +803,45 @@ const Lt = (t) => {
803
803
  var k = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(k || {});
804
804
  const Ln = (t, e) => {
805
805
  var n, o;
806
- const { changes: i, origin: r } = e;
807
- if (!(t.options.origin ? t.options.origin === r : r !== "SILENT"))
806
+ const { changes: i, origin: s } = e;
807
+ if (!(t.options.origin ? t.options.origin === s : s !== "SILENT"))
808
808
  return !1;
809
809
  if (t.options.ignore) {
810
- const { ignore: a } = t.options, s = (c) => c && c.length > 0;
811
- if (!(s(i.created) || s(i.deleted))) {
812
- const c = (n = i.updated) == null ? void 0 : n.some((h) => s(h.bodiesCreated) || s(h.bodiesDeleted) || s(h.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
813
- if (a === "BODY_ONLY" && c && !f || a === "TARGET_ONLY" && f && !c)
810
+ const { ignore: r } = t.options, a = (l) => l && l.length > 0;
811
+ if (!(a(i.created) || a(i.deleted))) {
812
+ const l = (n = i.updated) == null ? void 0 : n.some((f) => a(f.bodiesCreated) || a(f.bodiesDeleted) || a(f.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((f) => f.targetUpdated);
813
+ if (r === "BODY_ONLY" && l && !u || r === "TARGET_ONLY" && u && !l)
814
814
  return !1;
815
815
  }
816
816
  }
817
817
  if (t.options.annotations) {
818
- const a = /* @__PURE__ */ new Set([
819
- ...(i.created || []).map((s) => s.id),
820
- ...(i.deleted || []).map((s) => s.id),
821
- ...(i.updated || []).map(({ oldValue: s }) => s.id)
818
+ const r = /* @__PURE__ */ new Set([
819
+ ...(i.created || []).map((a) => a.id),
820
+ ...(i.deleted || []).map((a) => a.id),
821
+ ...(i.updated || []).map(({ oldValue: a }) => a.id)
822
822
  ]);
823
- return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => a.has(s));
823
+ return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((a) => r.has(a));
824
824
  } else
825
825
  return !0;
826
826
  }, On = (t, e) => {
827
- 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)), r = new Set((e.deleted || []).map((l) => l.id)), a = new Set((e.updated || []).map(({ oldValue: l }) => l.id)), s = new Set((e.updated || []).filter(({ oldValue: l }) => n.has(l.id) || o.has(l.id)).map(({ oldValue: l }) => l.id)), c = [
828
- ...(t.created || []).filter((l) => !r.has(l.id)).map((l) => a.has(l.id) ? e.updated.find(({ oldValue: p }) => p.id === l.id).newValue : l),
827
+ const n = new Set((t.created || []).map((c) => c.id)), o = new Set((t.updated || []).map(({ newValue: c }) => c.id)), i = new Set((e.created || []).map((c) => c.id)), s = new Set((e.deleted || []).map((c) => c.id)), r = new Set((e.updated || []).map(({ oldValue: c }) => c.id)), a = new Set((e.updated || []).filter(({ oldValue: c }) => n.has(c.id) || o.has(c.id)).map(({ oldValue: c }) => c.id)), l = [
828
+ ...(t.created || []).filter((c) => !s.has(c.id)).map((c) => r.has(c.id) ? e.updated.find(({ oldValue: g }) => g.id === c.id).newValue : c),
829
829
  ...e.created || []
830
+ ], u = [
831
+ ...(t.deleted || []).filter((c) => !i.has(c.id)),
832
+ ...(e.deleted || []).filter((c) => !n.has(c.id))
830
833
  ], f = [
831
- ...(t.deleted || []).filter((l) => !i.has(l.id)),
832
- ...(e.deleted || []).filter((l) => !n.has(l.id))
833
- ], h = [
834
- ...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
835
- const { oldValue: p, newValue: d } = l;
836
- if (a.has(d.id)) {
837
- const E = e.updated.find((b) => b.oldValue.id === d.id).newValue;
838
- return ge(p, E);
834
+ ...(t.updated || []).filter(({ newValue: c }) => !s.has(c.id)).map((c) => {
835
+ const { oldValue: g, newValue: h } = c;
836
+ if (r.has(h.id)) {
837
+ const A = e.updated.find((b) => b.oldValue.id === h.id).newValue;
838
+ return pe(g, A);
839
839
  } else
840
- return l;
840
+ return c;
841
841
  }),
842
- ...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
842
+ ...(e.updated || []).filter(({ oldValue: c }) => !a.has(c.id))
843
843
  ];
844
- return { created: c, deleted: f, updated: h };
844
+ return { created: l, deleted: u, updated: f };
845
845
  }, Ot = (t) => {
846
846
  const e = t.id === void 0 ? he() : t.id;
847
847
  return {
@@ -862,7 +862,7 @@ const Ln = (t, e) => {
862
862
  }, i = (m) => {
863
863
  const v = n.findIndex((x) => x.onChange == m);
864
864
  v > -1 && n.splice(v, 1);
865
- }, r = (m, v) => {
865
+ }, s = (m, v) => {
866
866
  const x = {
867
867
  origin: m,
868
868
  changes: {
@@ -875,53 +875,53 @@ const Ln = (t, e) => {
875
875
  n.forEach((L) => {
876
876
  Ln(L, x) && L.onChange(x);
877
877
  });
878
- }, a = (m, v = k.LOCAL) => {
878
+ }, r = (m, v = k.LOCAL) => {
879
879
  if (m.id && t.get(m.id))
880
880
  throw Error(`Cannot add annotation ${m.id} - exists already`);
881
881
  {
882
882
  const x = Ot(m);
883
- t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), r(v, { created: [x] });
883
+ t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), s(v, { created: [x] });
884
884
  }
885
- }, s = (m, v) => {
885
+ }, a = (m, v) => {
886
886
  const x = Ot(typeof m == "string" ? v : m), L = typeof m == "string" ? m : m.id, B = L && t.get(L);
887
887
  if (B) {
888
- const M = ge(B, x);
888
+ const M = pe(B, x);
889
889
  return L === x.id ? t.set(L, x) : (t.delete(L), t.set(x.id, x)), B.bodies.forEach((K) => e.delete(K.id)), x.bodies.forEach((K) => e.set(K.id, x.id)), M;
890
890
  } else
891
891
  console.warn(`Cannot update annotation ${L} - does not exist`);
892
- }, c = (m, v = k.LOCAL, x = k.LOCAL) => {
893
- const L = Tn(v) ? x : v, B = s(m, v);
894
- B && r(L, { updated: [B] });
895
- }, f = (m, v = k.LOCAL) => {
892
+ }, l = (m, v = k.LOCAL, x = k.LOCAL) => {
893
+ const L = Tn(v) ? x : v, B = a(m, v);
894
+ B && s(L, { updated: [B] });
895
+ }, u = (m, v = k.LOCAL) => {
896
896
  const x = m.reduce((L, B) => {
897
- const M = s(B);
897
+ const M = a(B);
898
898
  return M ? [...L, M] : L;
899
899
  }, []);
900
- x.length > 0 && r(v, { updated: x });
901
- }, h = (m, v = k.LOCAL) => {
900
+ x.length > 0 && s(v, { updated: x });
901
+ }, f = (m, v = k.LOCAL) => {
902
902
  const x = t.get(m.annotation);
903
903
  if (x) {
904
904
  const L = {
905
905
  ...x,
906
906
  bodies: [...x.bodies, m]
907
907
  };
908
- t.set(x.id, L), e.set(m.id, L.id), r(v, { updated: [{
908
+ t.set(x.id, L), e.set(m.id, L.id), s(v, { updated: [{
909
909
  oldValue: x,
910
910
  newValue: L,
911
911
  bodiesCreated: [m]
912
912
  }] });
913
913
  } else
914
914
  console.warn(`Attempt to add body to missing annotation: ${m.annotation}`);
915
- }, l = () => [...t.values()], p = (m = k.LOCAL) => {
915
+ }, c = () => [...t.values()], g = (m = k.LOCAL) => {
916
916
  const v = [...t.values()];
917
- t.clear(), e.clear(), r(m, { deleted: v });
918
- }, d = (m, v = !0, x = k.LOCAL) => {
917
+ t.clear(), e.clear(), s(m, { deleted: v });
918
+ }, h = (m, v = !0, x = k.LOCAL) => {
919
919
  const L = m.map(Ot);
920
920
  if (v) {
921
921
  const B = [...t.values()];
922
922
  t.clear(), e.clear(), L.forEach((M) => {
923
923
  t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
924
- }), r(x, { created: L, deleted: B });
924
+ }), s(x, { created: L, deleted: B });
925
925
  } else {
926
926
  const B = m.reduce((M, K) => {
927
927
  const Y = K.id && t.get(K.id);
@@ -931,23 +931,23 @@ const Ln = (t, e) => {
931
931
  throw Error(`Bulk insert would overwrite the following annotations: ${B.map((M) => M.id).join(", ")}`);
932
932
  L.forEach((M) => {
933
933
  t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
934
- }), r(x, { created: L });
934
+ }), s(x, { created: L });
935
935
  }
936
- }, E = (m) => {
936
+ }, A = (m) => {
937
937
  const v = typeof m == "string" ? m : m.id, x = t.get(v);
938
938
  if (x)
939
939
  return t.delete(v), x.bodies.forEach((L) => e.delete(L.id)), x;
940
940
  console.warn(`Attempt to delete missing annotation: ${v}`);
941
941
  }, b = (m, v = k.LOCAL) => {
942
- const x = E(m);
943
- x && r(v, { deleted: [x] });
944
- }, C = (m, v = k.LOCAL) => {
942
+ const x = A(m);
943
+ x && s(v, { deleted: [x] });
944
+ }, S = (m, v = k.LOCAL) => {
945
945
  const x = m.reduce((L, B) => {
946
- const M = E(B);
946
+ const M = A(B);
947
947
  return M ? [...L, M] : L;
948
948
  }, []);
949
- x.length > 0 && r(v, { deleted: x });
950
- }, g = (m) => {
949
+ x.length > 0 && s(v, { deleted: x });
950
+ }, p = (m) => {
951
951
  const v = t.get(m.annotation);
952
952
  if (v) {
953
953
  const x = v.bodies.find((L) => L.id === m.id);
@@ -966,19 +966,19 @@ const Ln = (t, e) => {
966
966
  console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`);
967
967
  } else
968
968
  console.warn(`Attempt to delete body from missing annotation ${m.annotation}`);
969
- }, u = (m, v = k.LOCAL) => {
970
- const x = g(m);
971
- x && r(v, { updated: [x] });
969
+ }, d = (m, v = k.LOCAL) => {
970
+ const x = p(m);
971
+ x && s(v, { updated: [x] });
972
972
  }, y = (m, v = k.LOCAL) => {
973
- const x = m.map((L) => g(L)).filter(Boolean);
974
- x.length > 0 && r(v, { updated: x });
975
- }, S = (m) => {
973
+ const x = m.map((L) => p(L)).filter(Boolean);
974
+ x.length > 0 && s(v, { updated: x });
975
+ }, C = (m) => {
976
976
  const v = t.get(m);
977
977
  return v ? { ...v } : void 0;
978
- }, A = (m) => {
978
+ }, E = (m) => {
979
979
  const v = e.get(m);
980
980
  if (v) {
981
- const x = S(v).bodies.find((L) => L.id === m);
981
+ const x = C(v).bodies.find((L) => L.id === m);
982
982
  if (x)
983
983
  return x;
984
984
  console.error(`Store integrity error: body ${m} in index, but not in annotation`);
@@ -1002,10 +1002,10 @@ const Ln = (t, e) => {
1002
1002
  console.warn(`Attempt to add body to missing annotation ${m.annotation}`);
1003
1003
  }, T = (m, v, x = k.LOCAL) => {
1004
1004
  const L = w(m, v);
1005
- L && r(x, { updated: [L] });
1005
+ L && s(x, { updated: [L] });
1006
1006
  }, O = (m, v = k.LOCAL) => {
1007
1007
  const x = m.map((L) => w({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
1008
- r(v, { updated: x });
1008
+ s(v, { updated: x });
1009
1009
  }, R = (m) => {
1010
1010
  const v = t.get(m.annotation);
1011
1011
  if (v) {
@@ -1028,30 +1028,30 @@ const Ln = (t, e) => {
1028
1028
  console.warn(`Attempt to update target on missing annotation: ${m.annotation}`);
1029
1029
  };
1030
1030
  return {
1031
- addAnnotation: a,
1032
- addBody: h,
1033
- all: l,
1034
- bulkAddAnnotation: d,
1035
- bulkDeleteAnnotation: C,
1031
+ addAnnotation: r,
1032
+ addBody: f,
1033
+ all: c,
1034
+ bulkAddAnnotation: h,
1035
+ bulkDeleteAnnotation: S,
1036
1036
  bulkDeleteBodies: y,
1037
- bulkUpdateAnnotation: f,
1037
+ bulkUpdateAnnotation: u,
1038
1038
  bulkUpdateBodies: O,
1039
1039
  bulkUpdateTargets: (m, v = k.LOCAL) => {
1040
1040
  const x = m.map((L) => R(L)).filter(Boolean);
1041
- x.length > 0 && r(v, { updated: x });
1041
+ x.length > 0 && s(v, { updated: x });
1042
1042
  },
1043
- clear: p,
1043
+ clear: g,
1044
1044
  deleteAnnotation: b,
1045
- deleteBody: u,
1046
- getAnnotation: S,
1047
- getBody: A,
1045
+ deleteBody: d,
1046
+ getAnnotation: C,
1047
+ getBody: E,
1048
1048
  observe: o,
1049
1049
  unobserve: i,
1050
- updateAnnotation: c,
1050
+ updateAnnotation: l,
1051
1051
  updateBody: T,
1052
1052
  updateTarget: (m, v = k.LOCAL) => {
1053
1053
  const x = R(m);
1054
- x && r(v, { updated: [x] });
1054
+ x && s(v, { updated: [x] });
1055
1055
  }
1056
1056
  };
1057
1057
  };
@@ -1071,39 +1071,39 @@ let Mn = () => ({
1071
1071
  });
1072
1072
  const Bn = 250, kn = (t) => {
1073
1073
  const e = Mn(), n = [];
1074
- let o = -1, i = !1, r = 0;
1075
- const a = (d) => {
1074
+ let o = -1, i = !1, s = 0;
1075
+ const r = (h) => {
1076
1076
  if (!i) {
1077
- const { changes: E } = d, b = performance.now();
1078
- if (b - r > Bn)
1079
- n.splice(o + 1), n.push(E), o = n.length - 1;
1077
+ const { changes: A } = h, b = performance.now();
1078
+ if (b - s > Bn)
1079
+ n.splice(o + 1), n.push(A), o = n.length - 1;
1080
1080
  else {
1081
- const C = n.length - 1;
1082
- n[C] = On(n[C], E);
1081
+ const S = n.length - 1;
1082
+ n[S] = On(n[S], A);
1083
1083
  }
1084
- r = b;
1084
+ s = b;
1085
1085
  }
1086
1086
  i = !1;
1087
1087
  };
1088
- t.observe(a, { origin: k.LOCAL });
1089
- const s = (d) => d && d.length > 0 && t.bulkDeleteAnnotation(d), c = (d) => d && d.length > 0 && t.bulkAddAnnotation(d, !1), f = (d) => d && d.length > 0 && t.bulkUpdateAnnotation(d.map(({ oldValue: E }) => E)), h = (d) => d && d.length > 0 && t.bulkUpdateAnnotation(d.map(({ newValue: E }) => E)), l = (d) => d && d.length > 0 && t.bulkAddAnnotation(d, !1), p = (d) => d && d.length > 0 && t.bulkDeleteAnnotation(d);
1088
+ t.observe(r, { origin: k.LOCAL });
1089
+ const a = (h) => h && h.length > 0 && t.bulkDeleteAnnotation(h), l = (h) => h && h.length > 0 && t.bulkAddAnnotation(h, !1), u = (h) => h && h.length > 0 && t.bulkUpdateAnnotation(h.map(({ oldValue: A }) => A)), f = (h) => h && h.length > 0 && t.bulkUpdateAnnotation(h.map(({ newValue: A }) => A)), c = (h) => h && h.length > 0 && t.bulkAddAnnotation(h, !1), g = (h) => h && h.length > 0 && t.bulkDeleteAnnotation(h);
1090
1090
  return {
1091
1091
  canRedo: () => n.length - 1 > o,
1092
1092
  canUndo: () => o > -1,
1093
- destroy: () => t.unobserve(a),
1094
- on: (d, E) => e.on(d, E),
1093
+ destroy: () => t.unobserve(r),
1094
+ on: (h, A) => e.on(h, A),
1095
1095
  redo: () => {
1096
1096
  if (n.length - 1 > o) {
1097
1097
  i = !0;
1098
- const { created: d, updated: E, deleted: b } = n[o + 1];
1099
- c(d), h(E), p(b), e.emit("redo", n[o + 1]), o += 1;
1098
+ const { created: h, updated: A, deleted: b } = n[o + 1];
1099
+ l(h), f(A), g(b), e.emit("redo", n[o + 1]), o += 1;
1100
1100
  }
1101
1101
  },
1102
1102
  undo: () => {
1103
1103
  if (o > -1) {
1104
1104
  i = !0;
1105
- const { created: d, updated: E, deleted: b } = n[o];
1106
- s(d), f(E), l(b), e.emit("undo", n[o]), o -= 1;
1105
+ const { created: h, updated: A, deleted: b } = n[o];
1106
+ a(h), u(A), c(b), e.emit("undo", n[o]), o -= 1;
1107
1107
  }
1108
1108
  }
1109
1109
  };
@@ -1114,76 +1114,76 @@ const Bn = 250, kn = (t) => {
1114
1114
  set: e
1115
1115
  };
1116
1116
  }, _n = (t, e, n, o) => {
1117
- const { store: i, selection: r, hover: a, viewport: s } = t, c = /* @__PURE__ */ new Map();
1118
- let f = [], h;
1119
- const l = (b, C) => {
1120
- c.has(b) ? c.get(b).push(C) : c.set(b, [C]);
1121
- }, p = (b, C) => {
1122
- const g = c.get(b);
1123
- if (g) {
1124
- const u = g.indexOf(C);
1125
- u !== -1 && g.splice(u, 1);
1117
+ const { hover: i, selection: s, store: r, viewport: a } = t, l = /* @__PURE__ */ new Map();
1118
+ let u = [], f;
1119
+ const c = (b, S) => {
1120
+ l.has(b) ? l.get(b).push(S) : l.set(b, [S]);
1121
+ }, g = (b, S) => {
1122
+ const p = l.get(b);
1123
+ if (p) {
1124
+ const d = p.indexOf(S);
1125
+ d !== -1 && p.splice(d, 1);
1126
1126
  }
1127
- }, d = (b, C, g) => {
1128
- c.has(b) && setTimeout(() => {
1129
- c.get(b).forEach((u) => {
1127
+ }, h = (b, S, p) => {
1128
+ l.has(b) && setTimeout(() => {
1129
+ l.get(b).forEach((d) => {
1130
1130
  if (n) {
1131
- const y = Array.isArray(C) ? C.map((A) => n.serialize(A)) : n.serialize(C), S = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
1132
- u(y, S);
1131
+ const y = Array.isArray(S) ? S.map((E) => n.serialize(E)) : n.serialize(S), C = p ? p instanceof PointerEvent ? p : n.serialize(p) : void 0;
1132
+ d(y, C);
1133
1133
  } else
1134
- u(C, g);
1134
+ d(S, p);
1135
1135
  });
1136
1136
  }, 1);
1137
1137
  };
1138
- r.subscribe(({ selected: b }) => {
1139
- if (!(f.length === 0 && b.length === 0)) {
1140
- if (f.length === 0 && b.length > 0)
1141
- f = b.map(({ id: C }) => i.getAnnotation(C));
1142
- else if (f.length > 0 && b.length === 0)
1143
- f.forEach((C) => {
1144
- const g = i.getAnnotation(C.id);
1145
- g && !G(g, C) && d("updateAnnotation", g, C);
1146
- }), f = [];
1138
+ s.subscribe(({ selected: b }) => {
1139
+ if (!(u.length === 0 && b.length === 0)) {
1140
+ if (u.length === 0 && b.length > 0)
1141
+ u = b.map(({ id: S }) => r.getAnnotation(S));
1142
+ else if (u.length > 0 && b.length === 0)
1143
+ u.forEach((S) => {
1144
+ const p = r.getAnnotation(S.id);
1145
+ p && !G(p, S) && h("updateAnnotation", p, S);
1146
+ }), u = [];
1147
1147
  else {
1148
- const C = new Set(f.map((u) => u.id)), g = new Set(b.map(({ id: u }) => u));
1149
- f.filter((u) => !g.has(u.id)).forEach((u) => {
1150
- const y = i.getAnnotation(u.id);
1151
- y && !G(y, u) && d("updateAnnotation", y, u);
1152
- }), f = [
1148
+ const S = new Set(u.map((d) => d.id)), p = new Set(b.map(({ id: d }) => d));
1149
+ u.filter((d) => !p.has(d.id)).forEach((d) => {
1150
+ const y = r.getAnnotation(d.id);
1151
+ y && !G(y, d) && h("updateAnnotation", y, d);
1152
+ }), u = [
1153
1153
  // Remove annotations that were deselected
1154
- ...f.filter((u) => g.has(u.id)),
1154
+ ...u.filter((d) => p.has(d.id)),
1155
1155
  // Add editable annotations that were selected
1156
- ...b.filter(({ id: u }) => !C.has(u)).map(({ id: u }) => i.getAnnotation(u))
1156
+ ...b.filter(({ id: d }) => !S.has(d)).map(({ id: d }) => r.getAnnotation(d))
1157
1157
  ];
1158
1158
  }
1159
- d("selectionChanged", f);
1159
+ h("selectionChanged", u);
1160
1160
  }
1161
- }), a.subscribe((b) => {
1162
- !h && b ? d("mouseEnterAnnotation", i.getAnnotation(b)) : h && !b ? d("mouseLeaveAnnotation", i.getAnnotation(h)) : h && b && (d("mouseLeaveAnnotation", i.getAnnotation(h)), d("mouseEnterAnnotation", i.getAnnotation(b))), h = b;
1163
- }), s == null || s.subscribe((b) => d("viewportIntersect", b.map((C) => i.getAnnotation(C)))), i.observe((b) => {
1164
- const { created: C, deleted: g } = b.changes;
1165
- (C || []).forEach((u) => d("createAnnotation", u)), (g || []).forEach((u) => d("deleteAnnotation", u)), (b.changes.updated || []).filter((u) => [
1166
- ...u.bodiesCreated || [],
1167
- ...u.bodiesDeleted || [],
1168
- ...u.bodiesUpdated || []
1169
- ].length > 0).forEach(({ oldValue: u, newValue: y }) => {
1170
- const S = f.find((A) => A.id === u.id) || u;
1171
- f = f.map((A) => A.id === u.id ? y : A), d("updateAnnotation", y, S);
1161
+ }), i.subscribe((b) => {
1162
+ !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;
1163
+ }), a == null || a.subscribe((b) => h("viewportIntersect", b.map((S) => r.getAnnotation(S)))), r.observe((b) => {
1164
+ const { created: S, deleted: p } = b.changes;
1165
+ (S || []).forEach((d) => h("createAnnotation", d)), (p || []).forEach((d) => h("deleteAnnotation", d)), (b.changes.updated || []).filter((d) => [
1166
+ ...d.bodiesCreated || [],
1167
+ ...d.bodiesDeleted || [],
1168
+ ...d.bodiesUpdated || []
1169
+ ].length > 0).forEach(({ oldValue: d, newValue: y }) => {
1170
+ const C = u.find((E) => E.id === d.id) || d;
1171
+ u = u.map((E) => E.id === d.id ? y : E), h("updateAnnotation", y, C);
1172
1172
  });
1173
- }, { origin: k.LOCAL }), i.observe((b) => {
1174
- if (f) {
1175
- const C = new Set(f.map((u) => u.id)), g = (b.changes.updated || []).filter(({ newValue: u }) => C.has(u.id)).map(({ newValue: u }) => u);
1176
- g.length > 0 && (f = f.map((u) => g.find((S) => S.id === u.id) || u));
1173
+ }, { origin: k.LOCAL }), r.observe((b) => {
1174
+ if (u) {
1175
+ const S = new Set(u.map((d) => d.id)), p = (b.changes.updated || []).filter(({ newValue: d }) => S.has(d.id)).map(({ newValue: d }) => d);
1176
+ p.length > 0 && (u = u.map((d) => p.find((C) => C.id === d.id) || d));
1177
1177
  }
1178
1178
  }, { origin: k.REMOTE });
1179
- const E = (b) => (C) => {
1180
- const { updated: g } = C;
1181
- b ? (g || []).forEach((u) => d("updateAnnotation", u.oldValue, u.newValue)) : (g || []).forEach((u) => d("updateAnnotation", u.newValue, u.oldValue));
1179
+ const A = (b) => (S) => {
1180
+ const { updated: p } = S;
1181
+ b ? (p || []).forEach((d) => h("updateAnnotation", d.oldValue, d.newValue)) : (p || []).forEach((d) => h("updateAnnotation", d.newValue, d.oldValue));
1182
1182
  };
1183
- return e.on("undo", E(!0)), e.on("redo", E(!1)), { on: l, off: p, emit: d };
1183
+ return e.on("undo", A(!0)), e.on("redo", A(!1)), { on: c, off: g, emit: h };
1184
1184
  }, Nn = (t) => (e) => e.reduce((n, o) => {
1185
- const { parsed: i, error: r } = t.parse(o);
1186
- return r ? {
1185
+ const { parsed: i, error: s } = t.parse(o);
1186
+ return s ? {
1187
1187
  parsed: n.parsed,
1188
1188
  failed: [...n.failed, o]
1189
1189
  } : i ? {
@@ -1193,75 +1193,75 @@ const Bn = 250, kn = (t) => {
1193
1193
  ...n
1194
1194
  };
1195
1195
  }, { parsed: [], failed: [] }), Un = (t, e, n) => {
1196
- const { store: o, selection: i } = t, r = (g) => {
1196
+ const { store: o, selection: i } = t, s = (p) => {
1197
1197
  if (n) {
1198
- const { parsed: u, error: y } = n.parse(g);
1199
- u ? o.addAnnotation(u, k.REMOTE) : console.error(y);
1198
+ const { parsed: d, error: y } = n.parse(p);
1199
+ d ? o.addAnnotation(d, k.REMOTE) : console.error(y);
1200
1200
  } else
1201
- o.addAnnotation(Lt(g), k.REMOTE);
1202
- }, a = () => i.clear(), s = () => o.clear(), c = (g) => {
1203
- const u = o.getAnnotation(g);
1204
- return n && u ? n.serialize(u) : u;
1205
- }, f = () => n ? o.all().map(n.serialize) : o.all(), h = () => {
1206
- var g;
1207
- const u = (((g = i.selected) == null ? void 0 : g.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1208
- return n ? u.map(n.serialize) : u;
1209
- }, l = (g, u = !0) => fetch(g).then((y) => y.json()).then((y) => (d(y, u), y)), p = (g) => {
1210
- if (typeof g == "string") {
1211
- const u = o.getAnnotation(g);
1212
- if (o.deleteAnnotation(g), u)
1213
- return n ? n.serialize(u) : u;
1201
+ o.addAnnotation(Lt(p), k.REMOTE);
1202
+ }, r = () => i.clear(), a = () => o.clear(), l = (p) => {
1203
+ const d = o.getAnnotation(p);
1204
+ return n && d ? n.serialize(d) : d;
1205
+ }, u = () => n ? o.all().map(n.serialize) : o.all(), f = () => {
1206
+ var p;
1207
+ const d = (((p = i.selected) == null ? void 0 : p.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1208
+ return n ? d.map(n.serialize) : d;
1209
+ }, c = (p, d = !0) => fetch(p).then((y) => y.json()).then((y) => (h(y, d), y)), g = (p) => {
1210
+ if (typeof p == "string") {
1211
+ const d = o.getAnnotation(p);
1212
+ if (o.deleteAnnotation(p), d)
1213
+ return n ? n.serialize(d) : d;
1214
1214
  } else {
1215
- const u = n ? n.parse(g).parsed : g;
1216
- if (u)
1217
- return o.deleteAnnotation(u), g;
1215
+ const d = n ? n.parse(p).parsed : p;
1216
+ if (d)
1217
+ return o.deleteAnnotation(d), p;
1218
1218
  }
1219
- }, d = (g, u = !0) => {
1219
+ }, h = (p, d = !0) => {
1220
1220
  if (n) {
1221
- const y = n.parseAll || Nn(n), { parsed: S, failed: A } = y(g);
1222
- A.length > 0 && console.warn(`Discarded ${A.length} invalid annotations`, A), o.bulkAddAnnotation(S, u, k.REMOTE);
1221
+ const y = n.parseAll || Nn(n), { parsed: C, failed: E } = y(p);
1222
+ E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotation(C, d, k.REMOTE);
1223
1223
  } else
1224
- o.bulkAddAnnotation(g.map(Lt), u, k.REMOTE);
1225
- }, E = (g, u) => {
1226
- g ? i.setSelected(g, u) : i.clear();
1227
- }, b = (g) => {
1228
- i.clear(), i.setUserSelectAction(g);
1229
- }, C = (g) => {
1224
+ o.bulkAddAnnotation(p.map(Lt), d, k.REMOTE);
1225
+ }, A = (p, d) => {
1226
+ p ? i.setSelected(p, d) : i.clear();
1227
+ }, b = (p) => {
1228
+ i.clear(), i.setUserSelectAction(p);
1229
+ }, S = (p) => {
1230
1230
  if (n) {
1231
- const u = n.parse(g).parsed, y = n.serialize(o.getAnnotation(u.id));
1232
- return o.updateAnnotation(u), y;
1231
+ const d = n.parse(p).parsed, y = n.serialize(o.getAnnotation(d.id));
1232
+ return o.updateAnnotation(d), y;
1233
1233
  } else {
1234
- const u = o.getAnnotation(g.id);
1235
- return o.updateAnnotation(Lt(g)), u;
1234
+ const d = o.getAnnotation(p.id);
1235
+ return o.updateAnnotation(Lt(p)), d;
1236
1236
  }
1237
1237
  };
1238
1238
  return {
1239
- addAnnotation: r,
1240
- cancelSelected: a,
1239
+ addAnnotation: s,
1240
+ cancelSelected: r,
1241
1241
  canRedo: e.canRedo,
1242
1242
  canUndo: e.canUndo,
1243
- clearAnnotations: s,
1244
- getAnnotationById: c,
1245
- getAnnotations: f,
1246
- getSelected: h,
1247
- loadAnnotations: l,
1243
+ clearAnnotations: a,
1244
+ getAnnotationById: l,
1245
+ getAnnotations: u,
1246
+ getSelected: f,
1247
+ loadAnnotations: c,
1248
1248
  redo: e.redo,
1249
- removeAnnotation: p,
1250
- setAnnotations: d,
1251
- setSelected: E,
1249
+ removeAnnotation: g,
1250
+ setAnnotations: h,
1251
+ setSelected: A,
1252
1252
  setUserSelectAction: b,
1253
1253
  undo: e.undo,
1254
- updateAnnotation: C
1254
+ updateAnnotation: S
1255
1255
  };
1256
1256
  }, Vn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1257
1257
  let Dn = (t) => crypto.getRandomValues(new Uint8Array(t)), Kn = (t, e, n) => {
1258
1258
  let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
1259
- return (r = e) => {
1260
- let a = "";
1259
+ return (s = e) => {
1260
+ let r = "";
1261
1261
  for (; ; ) {
1262
- let s = n(i), c = i;
1263
- for (; c--; )
1264
- if (a += t[s[c] & o] || "", a.length === r) return a;
1262
+ let a = n(i), l = i;
1263
+ for (; l--; )
1264
+ if (r += t[a[l] & o] || "", r.length === s) return r;
1265
1265
  }
1266
1266
  };
1267
1267
  }, Yn = (t, e = 21) => Kn(t, e, Dn), Xn = (t = 21) => {
@@ -1274,31 +1274,31 @@ const $n = () => ({ isGuest: !0, id: Yn("1234567890abcdefghijklmnopqrstuvwxyzABC
1274
1274
  const e = JSON.stringify(t);
1275
1275
  let n = 0;
1276
1276
  for (let o = 0, i = e.length; o < i; o++) {
1277
- let r = e.charCodeAt(o);
1278
- n = (n << 5) - n + r, n |= 0;
1277
+ let s = e.charCodeAt(o);
1278
+ n = (n << 5) - n + s, n |= 0;
1279
1279
  }
1280
1280
  return `${n}`;
1281
- }, pe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, jn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1282
- const { id: o, type: i, purpose: r, value: a, created: s, modified: c, creator: f, ...h } = n;
1281
+ }, ge = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, jn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1282
+ const { id: o, type: i, purpose: s, value: r, created: a, modified: l, creator: u, ...f } = n;
1283
1283
  return {
1284
1284
  id: o || `temp-${Pn(n)}`,
1285
1285
  annotation: e,
1286
1286
  type: i,
1287
- purpose: r,
1288
- value: a,
1289
- creator: pe(f),
1290
- created: s ? new Date(s) : void 0,
1291
- updated: c ? new Date(c) : void 0,
1292
- ...h
1287
+ purpose: s,
1288
+ value: r,
1289
+ creator: ge(u),
1290
+ created: a ? new Date(a) : void 0,
1291
+ updated: l ? new Date(l) : void 0,
1292
+ ...f
1293
1293
  };
1294
1294
  }), Hn = (t) => t.map((e) => {
1295
1295
  var n;
1296
- const { annotation: o, created: i, updated: r, ...a } = e, s = {
1297
- ...a,
1296
+ const { annotation: o, created: i, updated: s, ...r } = e, a = {
1297
+ ...r,
1298
1298
  created: i == null ? void 0 : i.toISOString(),
1299
- modified: r == null ? void 0 : r.toISOString()
1299
+ modified: s == null ? void 0 : s.toISOString()
1300
1300
  };
1301
- return (n = s.id) != null && n.startsWith("temp-") && delete s.id, s;
1301
+ return (n = a.id) != null && n.startsWith("temp-") && delete a.id, a;
1302
1302
  });
1303
1303
  Xn();
1304
1304
  const Lo = (t, e) => ({
@@ -1310,107 +1310,107 @@ const Lo = (t, e) => ({
1310
1310
  creator: n,
1311
1311
  created: o,
1312
1312
  modified: i,
1313
- target: r
1314
- } = t, a = Array.isArray(r) ? r : [r];
1315
- if (a.length === 0)
1313
+ target: s
1314
+ } = t, r = Array.isArray(s) ? s : [s];
1315
+ if (r.length === 0)
1316
1316
  return { error: Error(`No targets found for annotation: ${t.id}`) };
1317
- const s = {
1318
- creator: pe(n),
1317
+ const a = {
1318
+ creator: ge(n),
1319
1319
  created: o ? new Date(o) : void 0,
1320
1320
  updated: i ? new Date(i) : void 0,
1321
1321
  annotation: e,
1322
1322
  selector: [],
1323
- styleClass: a[0].styleClass
1323
+ styleClass: r[0].styleClass
1324
1324
  };
1325
- for (const c of a) {
1326
- const h = (Array.isArray(c.selector) ? c.selector : [c.selector]).reduce((l, p) => {
1327
- switch (p.type) {
1325
+ for (const l of r) {
1326
+ const f = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((c, g) => {
1327
+ switch (g.type) {
1328
1328
  case "TextQuoteSelector":
1329
- l.quote = p.exact;
1329
+ c.quote = g.exact;
1330
1330
  break;
1331
1331
  case "TextPositionSelector":
1332
- l.start = p.start, l.end = p.end;
1332
+ c.start = g.start, c.end = g.end;
1333
1333
  break;
1334
1334
  }
1335
- return l;
1335
+ return c;
1336
1336
  }, {});
1337
- if (zn(h))
1338
- s.selector.push({ id: c.id, ...h });
1337
+ if (zn(f))
1338
+ a.selector.push({ id: l.id, ...f });
1339
1339
  else {
1340
- const l = [
1341
- h.start ? void 0 : "TextPositionSelector",
1342
- h.quote ? void 0 : "TextQuoteSelector"
1340
+ const c = [
1341
+ f.start ? void 0 : "TextPositionSelector",
1342
+ f.quote ? void 0 : "TextQuoteSelector"
1343
1343
  ].filter(Boolean);
1344
- return { error: Error(`Missing selector types: ${l.join(" and ")} for annotation: ${t.id}`) };
1344
+ return { error: Error(`Missing selector types: ${c.join(" and ")} for annotation: ${t.id}`) };
1345
1345
  }
1346
1346
  }
1347
- return { parsed: s };
1347
+ return { parsed: a };
1348
1348
  }, Wn = (t) => {
1349
1349
  const e = t.id || fe(), {
1350
1350
  creator: n,
1351
1351
  created: o,
1352
1352
  modified: i,
1353
- body: r,
1354
- ...a
1355
- } = t, s = jn(r, e), c = Fn(t);
1356
- return "error" in c ? { error: c.error } : {
1353
+ body: s,
1354
+ ...r
1355
+ } = t, a = jn(s, e), l = Fn(t);
1356
+ return "error" in l ? { error: l.error } : {
1357
1357
  parsed: {
1358
- ...a,
1358
+ ...r,
1359
1359
  id: e,
1360
- bodies: s,
1361
- target: c.parsed
1360
+ bodies: a,
1361
+ target: l.parsed
1362
1362
  }
1363
1363
  };
1364
1364
  }, qn = (t, e, n) => {
1365
- const { bodies: o, target: i, ...r } = t, {
1366
- selector: a,
1367
- creator: s,
1368
- created: c,
1369
- updated: f,
1370
- ...h
1371
- } = i, l = a.map((p) => {
1372
- const { quote: d, start: E, end: b, range: C } = p, { prefix: g, suffix: u } = Re(C, n), y = [{
1365
+ const { bodies: o, target: i, ...s } = t, {
1366
+ selector: r,
1367
+ creator: a,
1368
+ created: l,
1369
+ updated: u,
1370
+ ...f
1371
+ } = i, c = r.map((g) => {
1372
+ const { quote: h, start: A, end: b, range: S } = g, { prefix: p, suffix: d } = Re(S, n), y = [{
1373
1373
  type: "TextQuoteSelector",
1374
- exact: d,
1375
- prefix: g,
1376
- suffix: u
1374
+ exact: h,
1375
+ prefix: p,
1376
+ suffix: d
1377
1377
  }, {
1378
1378
  type: "TextPositionSelector",
1379
- start: E,
1379
+ start: A,
1380
1380
  end: b
1381
1381
  }];
1382
1382
  return {
1383
- ...h,
1384
- id: p.id,
1383
+ ...f,
1384
+ id: g.id,
1385
1385
  source: e,
1386
1386
  selector: y
1387
1387
  };
1388
1388
  });
1389
1389
  return {
1390
- ...r,
1390
+ ...s,
1391
1391
  "@context": "http://www.w3.org/ns/anno.jsonld",
1392
1392
  id: t.id,
1393
1393
  type: "Annotation",
1394
1394
  body: Hn(t.bodies),
1395
- creator: s,
1396
- created: c == null ? void 0 : c.toISOString(),
1397
- modified: f == null ? void 0 : f.toISOString(),
1398
- target: l
1395
+ creator: a,
1396
+ created: l == null ? void 0 : l.toISOString(),
1397
+ modified: u == null ? void 0 : u.toISOString(),
1398
+ target: c
1399
1399
  };
1400
1400
  };
1401
1401
  function me(t, e, n = 0, o = t.length - 1, i = Gn) {
1402
1402
  for (; o > n; ) {
1403
1403
  if (o - n > 600) {
1404
- const c = o - n + 1, f = e - n + 1, h = Math.log(c), l = 0.5 * Math.exp(2 * h / 3), p = 0.5 * Math.sqrt(h * l * (c - l) / c) * (f - c / 2 < 0 ? -1 : 1), d = Math.max(n, Math.floor(e - f * l / c + p)), E = Math.min(o, Math.floor(e + (c - f) * l / c + p));
1405
- me(t, e, d, E, i);
1404
+ const l = o - n + 1, u = e - n + 1, f = Math.log(l), c = 0.5 * Math.exp(2 * f / 3), g = 0.5 * Math.sqrt(f * c * (l - c) / l) * (u - l / 2 < 0 ? -1 : 1), h = Math.max(n, Math.floor(e - u * c / l + g)), A = Math.min(o, Math.floor(e + (l - u) * c / l + g));
1405
+ me(t, e, h, A, i);
1406
1406
  }
1407
- const r = t[e];
1408
- let a = n, s = o;
1409
- for (tt(t, n, e), i(t[o], r) > 0 && tt(t, n, o); a < s; ) {
1410
- for (tt(t, a, s), a++, s--; i(t[a], r) < 0; ) a++;
1411
- for (; i(t[s], r) > 0; ) s--;
1407
+ const s = t[e];
1408
+ let r = n, a = o;
1409
+ for (tt(t, n, e), i(t[o], s) > 0 && tt(t, n, o); r < a; ) {
1410
+ for (tt(t, r, a), r++, a--; i(t[r], s) < 0; ) r++;
1411
+ for (; i(t[a], s) > 0; ) a--;
1412
1412
  }
1413
- i(t[n], r) === 0 ? tt(t, n, s) : (s++, tt(t, s, o)), s <= e && (n = s + 1), e <= s && (o = s - 1);
1413
+ i(t[n], s) === 0 ? tt(t, n, a) : (a++, tt(t, a, o)), a <= e && (n = a + 1), e <= a && (o = a - 1);
1414
1414
  }
1415
1415
  }
1416
1416
  function tt(t, e, n) {
@@ -1430,27 +1430,27 @@ class Qn {
1430
1430
  search(e) {
1431
1431
  let n = this.data;
1432
1432
  const o = [];
1433
- if (!pt(e, n)) return o;
1434
- const i = this.toBBox, r = [];
1433
+ if (!gt(e, n)) return o;
1434
+ const i = this.toBBox, s = [];
1435
1435
  for (; n; ) {
1436
- for (let a = 0; a < n.children.length; a++) {
1437
- const s = n.children[a], c = n.leaf ? i(s) : s;
1438
- pt(e, c) && (n.leaf ? o.push(s) : Rt(e, c) ? this._all(s, o) : r.push(s));
1436
+ for (let r = 0; r < n.children.length; r++) {
1437
+ const a = n.children[r], l = n.leaf ? i(a) : a;
1438
+ gt(e, l) && (n.leaf ? o.push(a) : Rt(e, l) ? this._all(a, o) : s.push(a));
1439
1439
  }
1440
- n = r.pop();
1440
+ n = s.pop();
1441
1441
  }
1442
1442
  return o;
1443
1443
  }
1444
1444
  collides(e) {
1445
1445
  let n = this.data;
1446
- if (!pt(e, n)) return !1;
1446
+ if (!gt(e, n)) return !1;
1447
1447
  const o = [];
1448
1448
  for (; n; ) {
1449
1449
  for (let i = 0; i < n.children.length; i++) {
1450
- const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
1451
- if (pt(e, a)) {
1452
- if (n.leaf || Rt(e, a)) return !0;
1453
- o.push(r);
1450
+ const s = n.children[i], r = n.leaf ? this.toBBox(s) : s;
1451
+ if (gt(e, r)) {
1452
+ if (n.leaf || Rt(e, r)) return !0;
1453
+ o.push(s);
1454
1454
  }
1455
1455
  }
1456
1456
  n = o.pop();
@@ -1487,15 +1487,15 @@ class Qn {
1487
1487
  remove(e, n) {
1488
1488
  if (!e) return this;
1489
1489
  let o = this.data;
1490
- const i = this.toBBox(e), r = [], a = [];
1491
- let s, c, f;
1492
- for (; o || r.length; ) {
1493
- if (o || (o = r.pop(), c = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
1494
- const h = Jn(e, o.children, n);
1495
- if (h !== -1)
1496
- return o.children.splice(h, 1), r.push(o), this._condense(r), this;
1490
+ const i = this.toBBox(e), s = [], r = [];
1491
+ let a, l, u;
1492
+ for (; o || s.length; ) {
1493
+ if (o || (o = s.pop(), l = s[s.length - 1], a = r.pop(), u = !0), o.leaf) {
1494
+ const f = Jn(e, o.children, n);
1495
+ if (f !== -1)
1496
+ return o.children.splice(f, 1), s.push(o), this._condense(s), this;
1497
1497
  }
1498
- !f && !o.leaf && Rt(o, i) ? (r.push(o), a.push(s), s = 0, c = o, o = o.children[0]) : c ? (s++, o = c.children[s], f = !1) : o = null;
1498
+ !u && !o.leaf && Rt(o, i) ? (s.push(o), r.push(a), a = 0, l = o, o = o.children[0]) : l ? (a++, o = l.children[a], u = !1) : o = null;
1499
1499
  }
1500
1500
  return this;
1501
1501
  }
@@ -1521,77 +1521,77 @@ class Qn {
1521
1521
  return n;
1522
1522
  }
1523
1523
  _build(e, n, o, i) {
1524
- const r = o - n + 1;
1525
- let a = this._maxEntries, s;
1526
- if (r <= a)
1527
- return s = Z(e.slice(n, o + 1)), J(s, this.toBBox), s;
1528
- i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = Z([]), s.leaf = !1, s.height = i;
1529
- const c = Math.ceil(r / a), f = c * Math.ceil(Math.sqrt(a));
1530
- te(e, n, o, f, this.compareMinX);
1531
- for (let h = n; h <= o; h += f) {
1532
- const l = Math.min(h + f - 1, o);
1533
- te(e, h, l, c, this.compareMinY);
1534
- for (let p = h; p <= l; p += c) {
1535
- const d = Math.min(p + c - 1, l);
1536
- s.children.push(this._build(e, p, d, i - 1));
1524
+ const s = o - n + 1;
1525
+ let r = this._maxEntries, a;
1526
+ if (s <= r)
1527
+ return a = Z(e.slice(n, o + 1)), J(a, this.toBBox), a;
1528
+ 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;
1529
+ const l = Math.ceil(s / r), u = l * Math.ceil(Math.sqrt(r));
1530
+ te(e, n, o, u, this.compareMinX);
1531
+ for (let f = n; f <= o; f += u) {
1532
+ const c = Math.min(f + u - 1, o);
1533
+ te(e, f, c, l, this.compareMinY);
1534
+ for (let g = f; g <= c; g += l) {
1535
+ const h = Math.min(g + l - 1, c);
1536
+ a.children.push(this._build(e, g, h, i - 1));
1537
1537
  }
1538
1538
  }
1539
- return J(s, this.toBBox), s;
1539
+ return J(a, this.toBBox), a;
1540
1540
  }
1541
1541
  _chooseSubtree(e, n, o, i) {
1542
1542
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1543
- let r = 1 / 0, a = 1 / 0, s;
1544
- for (let c = 0; c < n.children.length; c++) {
1545
- const f = n.children[c], h = Tt(f), l = eo(e, f) - h;
1546
- l < a ? (a = l, r = h < r ? h : r, s = f) : l === a && h < r && (r = h, s = f);
1543
+ let s = 1 / 0, r = 1 / 0, a;
1544
+ for (let l = 0; l < n.children.length; l++) {
1545
+ const u = n.children[l], f = Tt(u), c = eo(e, u) - f;
1546
+ c < r ? (r = c, s = f < s ? f : s, a = u) : c === r && f < s && (s = f, a = u);
1547
1547
  }
1548
- n = s || n.children[0];
1548
+ n = a || n.children[0];
1549
1549
  }
1550
1550
  return n;
1551
1551
  }
1552
1552
  _insert(e, n, o) {
1553
- const i = o ? e : this.toBBox(e), r = [], a = this._chooseSubtree(i, this.data, n, r);
1554
- for (a.children.push(e), ot(a, i); n >= 0 && r[n].children.length > this._maxEntries; )
1555
- this._split(r, n), n--;
1556
- this._adjustParentBBoxes(i, r, n);
1553
+ const i = o ? e : this.toBBox(e), s = [], r = this._chooseSubtree(i, this.data, n, s);
1554
+ for (r.children.push(e), ot(r, i); n >= 0 && s[n].children.length > this._maxEntries; )
1555
+ this._split(s, n), n--;
1556
+ this._adjustParentBBoxes(i, s, n);
1557
1557
  }
1558
1558
  // split overflowed node into two
1559
1559
  _split(e, n) {
1560
- const o = e[n], i = o.children.length, r = this._minEntries;
1561
- this._chooseSplitAxis(o, r, i);
1562
- const a = this._chooseSplitIndex(o, r, i), s = Z(o.children.splice(a, o.children.length - a));
1563
- s.height = o.height, s.leaf = o.leaf, J(o, this.toBBox), J(s, this.toBBox), n ? e[n - 1].children.push(s) : this._splitRoot(o, s);
1560
+ const o = e[n], i = o.children.length, s = this._minEntries;
1561
+ this._chooseSplitAxis(o, s, i);
1562
+ const r = this._chooseSplitIndex(o, s, i), a = Z(o.children.splice(r, o.children.length - r));
1563
+ 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);
1564
1564
  }
1565
1565
  _splitRoot(e, n) {
1566
1566
  this.data = Z([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, J(this.data, this.toBBox);
1567
1567
  }
1568
1568
  _chooseSplitIndex(e, n, o) {
1569
- let i, r = 1 / 0, a = 1 / 0;
1570
- for (let s = n; s <= o - n; s++) {
1571
- const c = nt(e, 0, s, this.toBBox), f = nt(e, s, o, this.toBBox), h = no(c, f), l = Tt(c) + Tt(f);
1572
- h < r ? (r = h, i = s, a = l < a ? l : a) : h === r && l < a && (a = l, i = s);
1569
+ let i, s = 1 / 0, r = 1 / 0;
1570
+ for (let a = n; a <= o - n; a++) {
1571
+ const l = nt(e, 0, a, this.toBBox), u = nt(e, a, o, this.toBBox), f = no(l, u), c = Tt(l) + Tt(u);
1572
+ f < s ? (s = f, i = a, r = c < r ? c : r) : f === s && c < r && (r = c, i = a);
1573
1573
  }
1574
1574
  return i || o - n;
1575
1575
  }
1576
1576
  // sorts node children by the best axis for split
1577
1577
  _chooseSplitAxis(e, n, o) {
1578
- const i = e.leaf ? this.compareMinX : Zn, r = e.leaf ? this.compareMinY : to, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1579
- a < s && e.children.sort(i);
1578
+ const i = e.leaf ? this.compareMinX : Zn, s = e.leaf ? this.compareMinY : to, r = this._allDistMargin(e, n, o, i), a = this._allDistMargin(e, n, o, s);
1579
+ r < a && e.children.sort(i);
1580
1580
  }
1581
1581
  // total margin of all possible split distributions where each node is at least m full
1582
1582
  _allDistMargin(e, n, o, i) {
1583
1583
  e.children.sort(i);
1584
- const r = this.toBBox, a = nt(e, 0, n, r), s = nt(e, o - n, o, r);
1585
- let c = gt(a) + gt(s);
1586
- for (let f = n; f < o - n; f++) {
1587
- const h = e.children[f];
1588
- ot(a, e.leaf ? r(h) : h), c += gt(a);
1584
+ const s = this.toBBox, r = nt(e, 0, n, s), a = nt(e, o - n, o, s);
1585
+ let l = pt(r) + pt(a);
1586
+ for (let u = n; u < o - n; u++) {
1587
+ const f = e.children[u];
1588
+ ot(r, e.leaf ? s(f) : f), l += pt(r);
1589
1589
  }
1590
- for (let f = o - n - 1; f >= n; f--) {
1591
- const h = e.children[f];
1592
- ot(s, e.leaf ? r(h) : h), c += gt(s);
1590
+ for (let u = o - n - 1; u >= n; u--) {
1591
+ const f = e.children[u];
1592
+ ot(a, e.leaf ? s(f) : f), l += pt(a);
1593
1593
  }
1594
- return c;
1594
+ return l;
1595
1595
  }
1596
1596
  _adjustParentBBoxes(e, n, o) {
1597
1597
  for (let i = o; i >= 0; i--)
@@ -1613,9 +1613,9 @@ function J(t, e) {
1613
1613
  }
1614
1614
  function nt(t, e, n, o, i) {
1615
1615
  i || (i = Z(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
1616
- for (let r = e; r < n; r++) {
1617
- const a = t.children[r];
1618
- ot(i, t.leaf ? o(a) : a);
1616
+ for (let s = e; s < n; s++) {
1617
+ const r = t.children[s];
1618
+ ot(i, t.leaf ? o(r) : r);
1619
1619
  }
1620
1620
  return i;
1621
1621
  }
@@ -1631,20 +1631,20 @@ function to(t, e) {
1631
1631
  function Tt(t) {
1632
1632
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1633
1633
  }
1634
- function gt(t) {
1634
+ function pt(t) {
1635
1635
  return t.maxX - t.minX + (t.maxY - t.minY);
1636
1636
  }
1637
1637
  function eo(t, e) {
1638
1638
  return (Math.max(e.maxX, t.maxX) - Math.min(e.minX, t.minX)) * (Math.max(e.maxY, t.maxY) - Math.min(e.minY, t.minY));
1639
1639
  }
1640
1640
  function no(t, e) {
1641
- const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), r = Math.min(t.maxY, e.maxY);
1642
- return Math.max(0, i - n) * Math.max(0, r - o);
1641
+ 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);
1642
+ return Math.max(0, i - n) * Math.max(0, s - o);
1643
1643
  }
1644
1644
  function Rt(t, e) {
1645
1645
  return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1646
1646
  }
1647
- function pt(t, e) {
1647
+ function gt(t, e) {
1648
1648
  return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
1649
1649
  }
1650
1650
  function Z(t) {
@@ -1659,11 +1659,11 @@ function Z(t) {
1659
1659
  };
1660
1660
  }
1661
1661
  function te(t, e, n, o, i) {
1662
- const r = [e, n];
1663
- for (; r.length; ) {
1664
- if (n = r.pop(), e = r.pop(), n - e <= o) continue;
1665
- const a = e + Math.ceil((n - e) / o / 2) * o;
1666
- me(t, a, e, n, i), r.push(e, a, a, n);
1662
+ const s = [e, n];
1663
+ for (; s.length; ) {
1664
+ if (n = s.pop(), e = s.pop(), n - e <= o) continue;
1665
+ const r = e + Math.ceil((n - e) / o / 2) * o;
1666
+ me(t, r, e, n, i), s.push(e, r, r, n);
1667
1667
  }
1668
1668
  }
1669
1669
  let oo = () => ({
@@ -1681,11 +1681,11 @@ let oo = () => ({
1681
1681
  }
1682
1682
  });
1683
1683
  const io = (t, e) => {
1684
- const n = new Qn(), o = /* @__PURE__ */ new Map(), i = oo(), r = (y, S) => {
1685
- const A = y.selector.flatMap((T) => {
1686
- const O = W([T]) ? T.range : se(T, e).range;
1684
+ const n = new Qn(), o = /* @__PURE__ */ new Map(), i = oo(), s = (y, C) => {
1685
+ const E = y.selector.flatMap((T) => {
1686
+ const O = W([T]) ? T.range : re(T, e).range;
1687
1687
  return Array.from(O.getClientRects());
1688
- }), w = _e(A).map((T) => Ve(T, S));
1688
+ }), w = _e(E).map((T) => Ve(T, C));
1689
1689
  return w.map((T) => {
1690
1690
  const { x: O, y: R, width: m, height: v } = T;
1691
1691
  return {
@@ -1699,158 +1699,158 @@ const io = (t, e) => {
1699
1699
  }
1700
1700
  };
1701
1701
  });
1702
- }, a = () => [...o.values()], s = () => {
1702
+ }, r = () => [...o.values()], a = () => {
1703
1703
  n.clear(), o.clear();
1704
- }, c = (y) => {
1705
- const S = r(y, e.getBoundingClientRect());
1706
- S.forEach((A) => n.insert(A)), o.set(y.annotation, S);
1704
+ }, l = (y) => {
1705
+ const C = s(y, e.getBoundingClientRect());
1706
+ C.forEach((E) => n.insert(E)), o.set(y.annotation, C);
1707
+ }, u = (y) => {
1708
+ const C = o.get(y.annotation);
1709
+ C && (C.forEach((E) => n.remove(E)), o.delete(y.annotation));
1707
1710
  }, f = (y) => {
1708
- const S = o.get(y.annotation);
1709
- S && (S.forEach((A) => n.remove(A)), o.delete(y.annotation));
1710
- }, h = (y) => {
1711
- f(y), c(y);
1712
- }, l = (y, S = !0) => {
1713
- S && s();
1714
- const A = e.getBoundingClientRect(), w = y.map((O) => ({ target: O, rects: r(O, A) }));
1711
+ u(y), l(y);
1712
+ }, c = (y, C = !0) => {
1713
+ C && a();
1714
+ const E = e.getBoundingClientRect(), w = y.map((O) => ({ target: O, rects: s(O, E) }));
1715
1715
  w.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
1716
1716
  const T = w.flatMap(({ rects: O }) => O);
1717
1717
  n.load(T);
1718
- }, p = (y, S, A = !1) => {
1718
+ }, g = (y, C, E = !1) => {
1719
1719
  const w = n.search({
1720
1720
  minX: y,
1721
- minY: S,
1721
+ minY: C,
1722
1722
  maxX: y,
1723
- maxY: S
1723
+ maxY: C
1724
1724
  }), T = (O) => O.annotation.rects.reduce((R, m) => R + m.width * m.height, 0);
1725
- return w.length > 0 ? (w.sort((O, R) => T(O) - T(R)), A ? w.map((O) => O.annotation.id) : [w[0].annotation.id]) : [];
1726
- }, d = (y) => {
1727
- const S = E(y);
1728
- if (S.length === 0)
1725
+ return w.length > 0 ? (w.sort((O, R) => T(O) - T(R)), E ? w.map((O) => O.annotation.id) : [w[0].annotation.id]) : [];
1726
+ }, h = (y) => {
1727
+ const C = A(y);
1728
+ if (C.length === 0)
1729
1729
  return;
1730
- let A = S[0].left, w = S[0].top, T = S[0].right, O = S[0].bottom;
1731
- for (let R = 1; R < S.length; R++) {
1732
- const m = S[R];
1733
- A = Math.min(A, m.left), w = Math.min(w, m.top), T = Math.max(T, m.right), O = Math.max(O, m.bottom);
1730
+ let E = C[0].left, w = C[0].top, T = C[0].right, O = C[0].bottom;
1731
+ for (let R = 1; R < C.length; R++) {
1732
+ const m = C[R];
1733
+ E = Math.min(E, m.left), w = Math.min(w, m.top), T = Math.max(T, m.right), O = Math.max(O, m.bottom);
1734
1734
  }
1735
- return new DOMRect(A, w, T - A, O - w);
1736
- }, E = (y) => {
1737
- const S = o.get(y);
1738
- return S ? S[0].annotation.rects : [];
1735
+ return new DOMRect(E, w, T - E, O - w);
1736
+ }, A = (y) => {
1737
+ const C = o.get(y);
1738
+ return C ? C[0].annotation.rects : [];
1739
1739
  };
1740
1740
  return {
1741
- all: a,
1742
- clear: s,
1743
- getAt: p,
1744
- getAnnotationBounds: d,
1745
- getAnnotationRects: E,
1746
- getIntersecting: (y, S, A, w) => {
1747
- const T = n.search({ minX: y, minY: S, maxX: A, maxY: w }), O = new Set(T.map((R) => R.annotation.id));
1741
+ all: r,
1742
+ clear: a,
1743
+ getAt: g,
1744
+ getAnnotationBounds: h,
1745
+ getAnnotationRects: A,
1746
+ getIntersecting: (y, C, E, w) => {
1747
+ const T = n.search({ minX: y, minY: C, maxX: E, maxY: w }), O = new Set(T.map((R) => R.annotation.id));
1748
1748
  return Array.from(O).map((R) => ({
1749
1749
  annotation: t.getAnnotation(R),
1750
- rects: E(R)
1750
+ rects: A(R)
1751
1751
  })).filter((R) => !!R.annotation);
1752
1752
  },
1753
- insert: c,
1753
+ insert: l,
1754
1754
  recalculate: () => {
1755
- l(t.all().map((y) => y.target), !0), i.emit("recalculate");
1755
+ c(t.all().map((y) => y.target), !0), i.emit("recalculate");
1756
1756
  },
1757
- remove: f,
1758
- set: l,
1757
+ remove: u,
1758
+ set: c,
1759
1759
  size: () => n.all().length,
1760
- update: h,
1761
- on: (y, S) => i.on(y, S)
1760
+ update: f,
1761
+ on: (y, C) => i.on(y, C)
1762
1762
  };
1763
- }, ro = (t, e) => {
1763
+ }, so = (t, e) => {
1764
1764
  const n = Rn(), o = io(n, t), i = yn(n);
1765
1765
  i.setUserSelectAction(e);
1766
- const r = pn(n), a = In(), s = (u, y = k.LOCAL) => {
1767
- const S = wt(u, t), A = W(S.target.selector);
1768
- return A && n.addAnnotation(S, y), A;
1769
- }, c = (u, y = !0, S = k.LOCAL) => {
1770
- const A = u.map((T) => wt(T, t)), w = A.filter((T) => !W(T.target.selector));
1771
- return w.length > 0 ? (console.warn("Could not revive all targets for these annotations:", w), n.bulkAddAnnotation(A, y, S), w) : (n.bulkAddAnnotation(A, y, S), []);
1772
- }, f = (u, y = k.LOCAL) => {
1773
- const S = u.map((w) => wt(w, t)), A = S.filter((w) => !W(w.target.selector));
1774
- return A.length > 0 && console.warn("Could not revive all targets for these annotations:", A), S.forEach((w) => {
1766
+ const s = gn(n), r = In(), a = (d, y = k.LOCAL) => {
1767
+ const C = wt(d, t), E = W(C.target.selector);
1768
+ return E && n.addAnnotation(C, y), E;
1769
+ }, l = (d, y = !0, C = k.LOCAL) => {
1770
+ const E = d.map((T) => wt(T, t)), w = E.filter((T) => !W(T.target.selector));
1771
+ return w.length > 0 ? (console.warn("Could not revive all targets for these annotations:", w), n.bulkAddAnnotation(E, y, C), w) : (n.bulkAddAnnotation(E, y, C), []);
1772
+ }, u = (d, y = k.LOCAL) => {
1773
+ const C = d.map((w) => wt(w, t)), E = C.filter((w) => !W(w.target.selector));
1774
+ return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), C.forEach((w) => {
1775
1775
  n.getAnnotation(w.id) ? n.updateAnnotation(w, y) : n.addAnnotation(w, y);
1776
- }), A;
1777
- }, h = (u, y = k.LOCAL) => {
1778
- const S = yt(u, t);
1779
- n.updateTarget(S, y);
1780
- }, l = (u, y = k.LOCAL) => {
1781
- const S = u.map((A) => yt(A, t));
1782
- n.bulkUpdateTargets(S, y);
1783
- }, p = (u, y, S) => {
1784
- const A = o.getAt(u, y, !!S).map((T) => n.getAnnotation(T)), w = S ? A.filter(S) : A;
1776
+ }), E;
1777
+ }, f = (d, y = k.LOCAL) => {
1778
+ const C = yt(d, t);
1779
+ n.updateTarget(C, y);
1780
+ }, c = (d, y = k.LOCAL) => {
1781
+ const C = d.map((E) => yt(E, t));
1782
+ n.bulkUpdateTargets(C, y);
1783
+ }, g = (d, y, C) => {
1784
+ const E = o.getAt(d, y, !!C).map((T) => n.getAnnotation(T)), w = C ? E.filter(C) : E;
1785
1785
  return w.length > 0 ? w[0] : void 0;
1786
- }, d = (u, y, S, A = 5) => {
1787
- const w = o.getAnnotationRects(u);
1786
+ }, h = (d, y, C, E = 5) => {
1787
+ const w = o.getAnnotationRects(d);
1788
1788
  if (w.length !== 0) {
1789
- if (y && S) {
1790
- const T = w.find(({ top: O, right: R, bottom: m, left: v }) => y >= v - A && y <= R + A && S >= O - A && S <= m + A);
1789
+ if (y && C) {
1790
+ const T = w.find(({ top: O, right: R, bottom: m, left: v }) => y >= v - E && y <= R + E && C >= O - E && C <= m + E);
1791
1791
  if (T) return T;
1792
1792
  }
1793
- return o.getAnnotationBounds(u);
1793
+ return o.getAnnotationBounds(d);
1794
1794
  }
1795
- }, E = (u, y, S, A) => o.getIntersecting(u, y, S, A), b = (u) => o.getAnnotationRects(u), C = () => o.recalculate(), g = (u) => o.on("recalculate", u);
1796
- return n.observe(({ changes: u }) => {
1797
- const y = (u.deleted || []).filter((w) => W(w.target.selector)), S = (u.created || []).filter((w) => W(w.target.selector)), A = (u.updated || []).filter((w) => W(w.newValue.target.selector));
1798
- (y == null ? void 0 : y.length) > 0 && y.forEach((w) => o.remove(w.target)), S.length > 0 && o.set(S.map((w) => w.target), !1), (A == null ? void 0 : A.length) > 0 && A.forEach(({ newValue: w }) => o.update(w.target));
1795
+ }, A = (d, y, C, E) => o.getIntersecting(d, y, C, E), b = (d) => o.getAnnotationRects(d), S = () => o.recalculate(), p = (d) => o.on("recalculate", d);
1796
+ return n.observe(({ changes: d }) => {
1797
+ const y = (d.deleted || []).filter((w) => W(w.target.selector)), C = (d.created || []).filter((w) => W(w.target.selector)), E = (d.updated || []).filter((w) => W(w.newValue.target.selector));
1798
+ (y == null ? void 0 : y.length) > 0 && y.forEach((w) => o.remove(w.target)), C.length > 0 && o.set(C.map((w) => w.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: w }) => o.update(w.target));
1799
1799
  }), {
1800
1800
  store: {
1801
1801
  ...n,
1802
- addAnnotation: s,
1803
- bulkAddAnnotation: c,
1804
- bulkUpdateTargets: l,
1805
- bulkUpsertAnnotations: f,
1806
- getAnnotationBounds: d,
1802
+ addAnnotation: a,
1803
+ bulkAddAnnotation: l,
1804
+ bulkUpdateTargets: c,
1805
+ bulkUpsertAnnotations: u,
1806
+ getAnnotationBounds: h,
1807
1807
  getAnnotationRects: b,
1808
- getIntersecting: E,
1809
- getAt: p,
1810
- recalculatePositions: C,
1811
- onRecalculatePositions: g,
1812
- updateTarget: h
1808
+ getIntersecting: A,
1809
+ getAt: g,
1810
+ recalculatePositions: S,
1811
+ onRecalculatePositions: p,
1812
+ updateTarget: f
1813
1813
  },
1814
1814
  selection: i,
1815
- hover: r,
1816
- viewport: a
1815
+ hover: s,
1816
+ viewport: r
1817
1817
  };
1818
- }, so = () => {
1818
+ }, ro = () => {
1819
1819
  const t = document.createElement("canvas");
1820
1820
  t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
1821
1821
  const e = t.getContext("2d");
1822
1822
  return e.scale(2, 2), e.translate(0.5, 0.5), t;
1823
1823
  }, ao = (t, e = {}) => {
1824
- const n = so(), o = n.getContext("2d");
1824
+ const n = ro(), o = n.getContext("2d");
1825
1825
  document.body.appendChild(n);
1826
- const i = /* @__PURE__ */ new Map(), r = (h) => Array.from(i.entries()).filter(([l, p]) => p.presenceKey === h.presenceKey).map(([l, p]) => l);
1827
- return t.on("selectionChange", (h, l) => {
1828
- r(h).forEach((d) => i.delete(d)), l && l.forEach((d) => i.set(d, h));
1826
+ const i = /* @__PURE__ */ new Map(), s = (f) => Array.from(i.entries()).filter(([c, g]) => g.presenceKey === f.presenceKey).map(([c, g]) => c);
1827
+ return t.on("selectionChange", (f, c) => {
1828
+ s(f).forEach((h) => i.delete(h)), c && c.forEach((h) => i.set(h, f));
1829
1829
  }), {
1830
1830
  clear: () => {
1831
- const { width: h, height: l } = n;
1832
- o.clearRect(-0.5, -0.5, h + 1, l + 1);
1831
+ const { width: f, height: c } = n;
1832
+ o.clearRect(-0.5, -0.5, f + 1, c + 1);
1833
1833
  },
1834
1834
  destroy: () => {
1835
1835
  n.remove();
1836
1836
  },
1837
- paint: (h, l, p) => {
1837
+ paint: (f, c, g) => {
1838
1838
  e.font && (o.font = e.font);
1839
- const d = i.get(h.annotation.id);
1840
- if (d) {
1841
- const { height: E } = h.rects[0], b = h.rects[0].x + l.left, C = h.rects[0].y + l.top;
1842
- o.fillStyle = d.appearance.color, o.fillRect(b - 2, C - 2.5, 2, E + 5);
1843
- const g = o.measureText(d.appearance.label), u = g.width + 6, y = g.actualBoundingBoxAscent + g.actualBoundingBoxDescent + 8, S = g.fontBoundingBoxAscent ? 8 : 6.5;
1844
- return o.fillRect(b - 2, C - 2.5 - y, u, y), o.fillStyle = "#fff", o.fillText(d.appearance.label, b + 1, C - S), {
1845
- fill: d.appearance.color,
1846
- fillOpacity: p ? 0.45 : 0.18
1839
+ const h = i.get(f.annotation.id);
1840
+ if (h) {
1841
+ const { height: A } = f.rects[0], b = f.rects[0].x + c.left, S = f.rects[0].y + c.top;
1842
+ o.fillStyle = h.appearance.color, o.fillRect(b - 2, S - 2.5, 2, A + 5);
1843
+ const p = o.measureText(h.appearance.label), d = p.width + 6, y = p.actualBoundingBoxAscent + p.actualBoundingBoxDescent + 8, C = p.fontBoundingBoxAscent ? 8 : 6.5;
1844
+ return o.fillRect(b - 2, S - 2.5 - y, d, y), o.fillStyle = "#fff", o.fillText(h.appearance.label, b + 1, S - C), {
1845
+ fill: h.appearance.color,
1846
+ fillOpacity: g ? 0.45 : 0.18
1847
1847
  };
1848
1848
  }
1849
1849
  },
1850
1850
  reset: () => {
1851
1851
  n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
1852
- const h = n.getContext("2d");
1853
- h.scale(2, 2), h.translate(0.5, 0.5);
1852
+ const f = n.getContext("2d");
1853
+ f.scale(2, 2), f.translate(0.5, 0.5);
1854
1854
  }
1855
1855
  };
1856
1856
  }, Mt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
@@ -1873,14 +1873,14 @@ function be(t) {
1873
1873
  e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
1874
1874
  return e;
1875
1875
  }
1876
- function lo(t, e) {
1876
+ function co(t, e) {
1877
1877
  const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
1878
1878
  let i = !0;
1879
- for (let r = 0; r < n.length; r++)
1880
- o.indexOf(n[r]) === -1 && (i = !1);
1879
+ for (let s = 0; s < n.length; s++)
1880
+ o.indexOf(n[s]) === -1 && (i = !1);
1881
1881
  return i;
1882
1882
  }
1883
- const st = {
1883
+ const rt = {
1884
1884
  backspace: 8,
1885
1885
  "⌫": 8,
1886
1886
  tab: 9,
@@ -1964,9 +1964,9 @@ const st = {
1964
1964
  91: !1
1965
1965
  }, _ = {};
1966
1966
  for (let t = 1; t < 20; t++)
1967
- st["f".concat(t)] = 111 + t;
1968
- let I = [], rt = null, we = "all";
1969
- const F = /* @__PURE__ */ new Map(), lt = (t) => st[t.toLowerCase()] || H[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), co = (t) => Object.keys(st).find((e) => st[e] === t), uo = (t) => Object.keys(H).find((e) => H[e] === t);
1967
+ rt["f".concat(t)] = 111 + t;
1968
+ let I = [], st = null, we = "all";
1969
+ const F = /* @__PURE__ */ new Map(), ct = (t) => rt[t.toLowerCase()] || H[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), lo = (t) => Object.keys(rt).find((e) => rt[e] === t), uo = (t) => Object.keys(H).find((e) => H[e] === t);
1970
1970
  function ve(t) {
1971
1971
  we = t || "all";
1972
1972
  }
@@ -1977,28 +1977,28 @@ function fo() {
1977
1977
  return I.slice(0);
1978
1978
  }
1979
1979
  function ho() {
1980
- return I.map((t) => co(t) || uo(t) || String.fromCharCode(t));
1980
+ return I.map((t) => lo(t) || uo(t) || String.fromCharCode(t));
1981
1981
  }
1982
- function go() {
1982
+ function po() {
1983
1983
  const t = [];
1984
1984
  return Object.keys(_).forEach((e) => {
1985
1985
  _[e].forEach((n) => {
1986
1986
  let {
1987
1987
  key: o,
1988
1988
  scope: i,
1989
- mods: r,
1990
- shortcut: a
1989
+ mods: s,
1990
+ shortcut: r
1991
1991
  } = n;
1992
1992
  t.push({
1993
1993
  scope: i,
1994
- shortcut: a,
1995
- mods: r,
1996
- keys: o.split("+").map((s) => lt(s))
1994
+ shortcut: r,
1995
+ mods: s,
1996
+ keys: o.split("+").map((a) => ct(a))
1997
1997
  });
1998
1998
  });
1999
1999
  }), t;
2000
2000
  }
2001
- function po(t) {
2001
+ function go(t) {
2002
2002
  const e = t.target || t.srcElement, {
2003
2003
  tagName: n
2004
2004
  } = e;
@@ -2007,7 +2007,7 @@ function po(t) {
2007
2007
  return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = !1), o;
2008
2008
  }
2009
2009
  function mo(t) {
2010
- return typeof t == "string" && (t = lt(t)), I.indexOf(t) !== -1;
2010
+ return typeof t == "string" && (t = ct(t)), I.indexOf(t) !== -1;
2011
2011
  }
2012
2012
  function yo(t, e) {
2013
2013
  let n, o;
@@ -2015,11 +2015,11 @@ function yo(t, e) {
2015
2015
  for (const i in _)
2016
2016
  if (Object.prototype.hasOwnProperty.call(_, i))
2017
2017
  for (n = _[i], o = 0; o < n.length; )
2018
- n[o].scope === t ? n.splice(o, 1).forEach((a) => {
2018
+ n[o].scope === t ? n.splice(o, 1).forEach((r) => {
2019
2019
  let {
2020
- element: s
2021
- } = a;
2022
- return Yt(s);
2020
+ element: a
2021
+ } = r;
2022
+ return Yt(a);
2023
2023
  }) : o++;
2024
2024
  at() === t && ve(e || "all");
2025
2025
  }
@@ -2031,10 +2031,10 @@ function bo(t) {
2031
2031
  for (const o in H) H[o] === e && (j[o] = !1);
2032
2032
  }
2033
2033
  }
2034
- function xe(t) {
2034
+ function Ae(t) {
2035
2035
  if (typeof t > "u")
2036
2036
  Object.keys(_).forEach((i) => {
2037
- Array.isArray(_[i]) && _[i].forEach((r) => mt(r)), delete _[i];
2037
+ Array.isArray(_[i]) && _[i].forEach((s) => mt(s)), delete _[i];
2038
2038
  }), Yt(null);
2039
2039
  else if (Array.isArray(t))
2040
2040
  t.forEach((i) => {
@@ -2045,11 +2045,11 @@ function xe(t) {
2045
2045
  else if (typeof t == "string") {
2046
2046
  for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
2047
2047
  n[o - 1] = arguments[o];
2048
- let [i, r] = n;
2049
- typeof i == "function" && (r = i, i = ""), mt({
2048
+ let [i, s] = n;
2049
+ typeof i == "function" && (s = i, i = ""), mt({
2050
2050
  key: t,
2051
2051
  scope: i,
2052
- method: r,
2052
+ method: s,
2053
2053
  splitKey: "+"
2054
2054
  });
2055
2055
  }
@@ -2061,15 +2061,15 @@ const mt = (t) => {
2061
2061
  method: o,
2062
2062
  splitKey: i = "+"
2063
2063
  } = t;
2064
- be(e).forEach((a) => {
2065
- const s = a.split(i), c = s.length, f = s[c - 1], h = f === "*" ? "*" : lt(f);
2066
- if (!_[h]) return;
2064
+ be(e).forEach((r) => {
2065
+ const a = r.split(i), l = a.length, u = a[l - 1], f = u === "*" ? "*" : ct(u);
2066
+ if (!_[f]) return;
2067
2067
  n || (n = at());
2068
- const l = c > 1 ? ye(H, s) : [], p = [];
2069
- _[h] = _[h].filter((d) => {
2070
- const b = (o ? d.method === o : !0) && d.scope === n && lo(d.mods, l);
2071
- return b && p.push(d.element), !b;
2072
- }), p.forEach((d) => Yt(d));
2068
+ const c = l > 1 ? ye(H, a) : [], g = [];
2069
+ _[f] = _[f].filter((h) => {
2070
+ const b = (o ? h.method === o : !0) && h.scope === n && co(h.mods, c);
2071
+ return b && g.push(h.element), !b;
2072
+ }), g.forEach((h) => Yt(h));
2073
2073
  });
2074
2074
  };
2075
2075
  function ee(t, e, n, o) {
@@ -2078,8 +2078,8 @@ function ee(t, e, n, o) {
2078
2078
  let i;
2079
2079
  if (e.scope === n || e.scope === "all") {
2080
2080
  i = e.mods.length > 0;
2081
- for (const r in D)
2082
- Object.prototype.hasOwnProperty.call(D, r) && (!D[r] && e.mods.indexOf(+r) > -1 || D[r] && e.mods.indexOf(+r) === -1) && (i = !1);
2081
+ for (const s in D)
2082
+ Object.prototype.hasOwnProperty.call(D, s) && (!D[s] && e.mods.indexOf(+s) > -1 || D[s] && e.mods.indexOf(+s) === -1) && (i = !1);
2083
2083
  (e.mods.length === 0 && !D[16] && !D[18] && !D[17] && !D[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)));
2084
2084
  }
2085
2085
  }
@@ -2087,73 +2087,73 @@ function ne(t, e) {
2087
2087
  const n = _["*"];
2088
2088
  let o = t.keyCode || t.which || t.charCode;
2089
2089
  if (!j.filter.call(this, t)) return;
2090
- if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((s) => {
2091
- const c = Nt[s];
2092
- t[s] && I.indexOf(c) === -1 ? I.push(c) : !t[s] && I.indexOf(c) > -1 ? I.splice(I.indexOf(c), 1) : s === "metaKey" && t[s] && I.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (I = I.slice(I.indexOf(c))));
2090
+ if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((a) => {
2091
+ const l = Nt[a];
2092
+ 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))));
2093
2093
  }), o in D) {
2094
2094
  D[o] = !0;
2095
- for (const s in H)
2096
- H[s] === o && (j[s] = !0);
2095
+ for (const a in H)
2096
+ H[a] === o && (j[a] = !0);
2097
2097
  if (!n) return;
2098
2098
  }
2099
- for (const s in D)
2100
- Object.prototype.hasOwnProperty.call(D, s) && (D[s] = t[Nt[s]]);
2099
+ for (const a in D)
2100
+ Object.prototype.hasOwnProperty.call(D, a) && (D[a] = t[Nt[a]]);
2101
2101
  t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), D[17] = !0, D[18] = !0);
2102
2102
  const i = at();
2103
2103
  if (n)
2104
- for (let s = 0; s < n.length; s++)
2105
- n[s].scope === i && (t.type === "keydown" && n[s].keydown || t.type === "keyup" && n[s].keyup) && ee(t, n[s], i, e);
2104
+ for (let a = 0; a < n.length; a++)
2105
+ n[a].scope === i && (t.type === "keydown" && n[a].keydown || t.type === "keyup" && n[a].keyup) && ee(t, n[a], i, e);
2106
2106
  if (!(o in _)) return;
2107
- const r = _[o], a = r.length;
2108
- for (let s = 0; s < a; s++)
2109
- if ((t.type === "keydown" && r[s].keydown || t.type === "keyup" && r[s].keyup) && r[s].key) {
2110
- const c = r[s], {
2111
- splitKey: f
2112
- } = c, h = c.key.split(f), l = [];
2113
- for (let p = 0; p < h.length; p++)
2114
- l.push(lt(h[p]));
2115
- l.sort().join("") === I.sort().join("") && ee(t, c, i, e);
2107
+ const s = _[o], r = s.length;
2108
+ for (let a = 0; a < r; a++)
2109
+ if ((t.type === "keydown" && s[a].keydown || t.type === "keyup" && s[a].keyup) && s[a].key) {
2110
+ const l = s[a], {
2111
+ splitKey: u
2112
+ } = l, f = l.key.split(u), c = [];
2113
+ for (let g = 0; g < f.length; g++)
2114
+ c.push(ct(f[g]));
2115
+ c.sort().join("") === I.sort().join("") && ee(t, l, i, e);
2116
2116
  }
2117
2117
  }
2118
2118
  function j(t, e, n) {
2119
2119
  I = [];
2120
2120
  const o = be(t);
2121
- let i = [], r = "all", a = document, s = 0, c = !1, f = !0, h = "+", l = !1, p = !1;
2122
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (c = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (l = e.capture), typeof e.splitKey == "string" && (h = e.splitKey), e.single === !0 && (p = !0)), typeof e == "string" && (r = e), p && xe(t, r); s < o.length; s++)
2123
- t = o[s].split(h), i = [], t.length > 1 && (i = ye(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in _ || (_[t] = []), _[t].push({
2124
- keyup: c,
2125
- keydown: f,
2126
- scope: r,
2121
+ let i = [], s = "all", r = document, a = 0, l = !1, u = !0, f = "+", c = !1, g = !1;
2122
+ 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 && (u = e.keydown), e.capture !== void 0 && (c = e.capture), typeof e.splitKey == "string" && (f = e.splitKey), e.single === !0 && (g = !0)), typeof e == "string" && (s = e), g && Ae(t, s); a < o.length; a++)
2123
+ t = o[a].split(f), i = [], t.length > 1 && (i = ye(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : ct(t), t in _ || (_[t] = []), _[t].push({
2124
+ keyup: l,
2125
+ keydown: u,
2126
+ scope: s,
2127
2127
  mods: i,
2128
- shortcut: o[s],
2128
+ shortcut: o[a],
2129
2129
  method: n,
2130
- key: o[s],
2131
- splitKey: h,
2132
- element: a
2130
+ key: o[a],
2131
+ splitKey: f,
2132
+ element: r
2133
2133
  });
2134
- if (typeof a < "u" && window) {
2135
- if (!F.has(a)) {
2136
- const d = function() {
2134
+ if (typeof r < "u" && window) {
2135
+ if (!F.has(r)) {
2136
+ const h = function() {
2137
2137
  let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2138
- return ne(b, a);
2139
- }, E = function() {
2138
+ return ne(b, r);
2139
+ }, A = function() {
2140
2140
  let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2141
- ne(b, a), bo(b);
2141
+ ne(b, r), bo(b);
2142
2142
  };
2143
- F.set(a, {
2144
- keydownListener: d,
2145
- keyupListenr: E,
2146
- capture: l
2147
- }), Bt(a, "keydown", d, l), Bt(a, "keyup", E, l);
2143
+ F.set(r, {
2144
+ keydownListener: h,
2145
+ keyupListenr: A,
2146
+ capture: c
2147
+ }), Bt(r, "keydown", h, c), Bt(r, "keyup", A, c);
2148
2148
  }
2149
- if (!rt) {
2150
- const d = () => {
2149
+ if (!st) {
2150
+ const h = () => {
2151
2151
  I = [];
2152
2152
  };
2153
- rt = {
2154
- listener: d,
2155
- capture: l
2156
- }, Bt(window, "focus", d, l);
2153
+ st = {
2154
+ listener: h,
2155
+ capture: c
2156
+ }, Bt(window, "focus", h, c);
2157
2157
  }
2158
2158
  }
2159
2159
  }
@@ -2176,23 +2176,23 @@ function Yt(t) {
2176
2176
  const {
2177
2177
  keydownListener: o,
2178
2178
  keyupListenr: i,
2179
- capture: r
2179
+ capture: s
2180
2180
  } = F.get(t) || {};
2181
- o && i && (et(t, "keyup", i, r), et(t, "keydown", o, r), F.delete(t));
2181
+ o && i && (et(t, "keyup", i, s), et(t, "keydown", o, s), F.delete(t));
2182
2182
  }
2183
2183
  if ((e.length <= 0 || F.size <= 0) && (Object.keys(F).forEach((i) => {
2184
2184
  const {
2185
- keydownListener: r,
2186
- keyupListenr: a,
2187
- capture: s
2185
+ keydownListener: s,
2186
+ keyupListenr: r,
2187
+ capture: a
2188
2188
  } = F.get(i) || {};
2189
- r && a && (et(i, "keyup", a, s), et(i, "keydown", r, s), F.delete(i));
2190
- }), F.clear(), Object.keys(_).forEach((i) => delete _[i]), rt)) {
2189
+ s && r && (et(i, "keyup", r, a), et(i, "keydown", s, a), F.delete(i));
2190
+ }), F.clear(), Object.keys(_).forEach((i) => delete _[i]), st)) {
2191
2191
  const {
2192
2192
  listener: i,
2193
- capture: r
2194
- } = rt;
2195
- et(window, "focus", i, r), rt = null;
2193
+ capture: s
2194
+ } = st;
2195
+ et(window, "focus", i, s), st = null;
2196
2196
  }
2197
2197
  }
2198
2198
  const kt = {
@@ -2201,12 +2201,12 @@ const kt = {
2201
2201
  getScope: at,
2202
2202
  deleteScope: yo,
2203
2203
  getPressedKeyCodes: fo,
2204
- getAllKeyCodes: go,
2204
+ getAllKeyCodes: po,
2205
2205
  isPressed: mo,
2206
- filter: po,
2206
+ filter: go,
2207
2207
  trigger: wo,
2208
- unbind: xe,
2209
- keyMap: st,
2208
+ unbind: Ae,
2209
+ keyMap: rt,
2210
2210
  modifier: H,
2211
2211
  modifierMap: Nt
2212
2212
  };
@@ -2219,17 +2219,17 @@ if (typeof window < "u") {
2219
2219
  const oe = 300, vo = (t, e, n) => {
2220
2220
  let o;
2221
2221
  const i = (w) => o = w;
2222
- let r;
2223
- const a = (w) => r = w;
2224
- let s = !0;
2225
- const c = (w) => {
2226
- s = w, b.clear(), w || (l = void 0, p = void 0, d = void 0);
2227
- }, { store: f, selection: h } = e;
2228
- let l, p, d;
2229
- const E = (w) => {
2222
+ let s;
2223
+ const r = (w) => s = w;
2224
+ let a = !0;
2225
+ const l = (w) => {
2226
+ a = w, b.clear(), w || (c = void 0, g = void 0, h = void 0);
2227
+ }, { store: u, selection: f } = e;
2228
+ let c, g, h;
2229
+ const A = (w) => {
2230
2230
  var O;
2231
- if (!s || p === !1) return;
2232
- l = !((O = w.target.parentElement) != null && O.closest(P)) ? {
2231
+ if (!a || g === !1) return;
2232
+ c = !((O = w.target.parentElement) != null && O.closest(P)) ? {
2233
2233
  annotation: fe(),
2234
2234
  selector: [],
2235
2235
  creator: o,
@@ -2237,126 +2237,126 @@ const oe = 300, vo = (t, e, n) => {
2237
2237
  } : void 0;
2238
2238
  }, b = Vt((w) => {
2239
2239
  var B, M;
2240
- if (!s) return;
2240
+ if (!a) return;
2241
2241
  const T = document.getSelection();
2242
2242
  if (!!((M = (B = T.anchorNode) == null ? void 0 : B.parentElement) != null && M.closest(P))) {
2243
- l = void 0;
2243
+ c = void 0;
2244
2244
  return;
2245
2245
  }
2246
- const R = w.timeStamp - ((d == null ? void 0 : d.timeStamp) || w.timeStamp);
2247
- if ((d == null ? void 0 : d.type) === "pointerdown" && (R < 1e3 && !l || T.isCollapsed && R < oe) && E(d), !l) return;
2246
+ const R = w.timeStamp - ((h == null ? void 0 : h.timeStamp) || w.timeStamp);
2247
+ if ((h == null ? void 0 : h.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < oe) && A(h), !c) return;
2248
2248
  if (T.isCollapsed) {
2249
- f.getAnnotation(l.annotation) && (h.clear(), f.deleteAnnotation(l.annotation));
2249
+ u.getAnnotation(c.annotation) && (f.clear(), u.deleteAnnotation(c.annotation));
2250
2250
  return;
2251
2251
  }
2252
2252
  const m = T.getRangeAt(0), v = Ue(m, t);
2253
2253
  if (Be(v)) return;
2254
2254
  const x = Le(v.cloneRange());
2255
- (x.length !== l.selector.length || x.some((K, Y) => {
2256
- var ct;
2257
- return K.toString() !== ((ct = l.selector[Y]) == null ? void 0 : ct.quote);
2258
- })) && (l = {
2259
- ...l,
2255
+ (x.length !== c.selector.length || x.some((K, Y) => {
2256
+ var lt;
2257
+ return K.toString() !== ((lt = c.selector[Y]) == null ? void 0 : lt.quote);
2258
+ })) && (c = {
2259
+ ...c,
2260
2260
  selector: x.map((K) => Ne(K, t, n)),
2261
2261
  updated: /* @__PURE__ */ new Date()
2262
- }, f.getAnnotation(l.annotation) ? f.updateTarget(l, k.LOCAL) : (h.clear(), f.addAnnotation({
2263
- id: l.annotation,
2262
+ }, u.getAnnotation(c.annotation) ? u.updateTarget(c, k.LOCAL) : (f.clear(), u.addAnnotation({
2263
+ id: c.annotation,
2264
2264
  bodies: [],
2265
- target: l
2266
- }, k.LOCAL), h.userSelect(l.annotation, d)));
2267
- }, 10), C = (w) => {
2265
+ target: c
2266
+ }, k.LOCAL), f.userSelect(c.annotation, h)));
2267
+ }, 10), S = (w) => {
2268
2268
  var O;
2269
- (O = w.target.parentElement) != null && O.closest(P) || (d = De(w), p = d.button === 0);
2270
- }, g = (w) => {
2269
+ (O = w.target.parentElement) != null && O.closest(P) || (h = De(w), g = h.button === 0);
2270
+ }, p = (w) => {
2271
2271
  var m;
2272
- if (!!((m = w.target.parentElement) != null && m.closest(P)) || !p) return;
2272
+ if (!!((m = w.target.parentElement) != null && m.closest(P)) || !g) return;
2273
2273
  const O = () => {
2274
- const { x: v, y: x } = t.getBoundingClientRect(), L = w.target instanceof Node && t.contains(w.target) && f.getAt(w.clientX - v, w.clientY - x, r);
2274
+ const { x: v, y: x } = t.getBoundingClientRect(), L = w.target instanceof Node && t.contains(w.target) && u.getAt(w.clientX - v, w.clientY - x, s);
2275
2275
  if (L) {
2276
- const { selected: B } = h;
2277
- (B.length !== 1 || B[0].id !== L.id) && h.userSelect(L.id, w);
2278
- } else h.isEmpty() || h.clear();
2279
- }, R = w.timeStamp - d.timeStamp;
2276
+ const { selected: B } = f;
2277
+ (B.length !== 1 || B[0].id !== L.id) && f.userSelect(L.id, w);
2278
+ } else f.isEmpty() || f.clear();
2279
+ }, R = w.timeStamp - h.timeStamp;
2280
2280
  setTimeout(() => {
2281
2281
  const v = document.getSelection();
2282
- v != null && v.isCollapsed && R < oe ? (l = void 0, O()) : l && f.getAnnotation(l.annotation) && h.userSelect(l.annotation, w);
2282
+ v != null && v.isCollapsed && R < oe ? (c = void 0, O()) : c && u.getAnnotation(c.annotation) && f.userSelect(c.annotation, w);
2283
2283
  });
2284
2284
  };
2285
- document.addEventListener("pointerdown", C), document.addEventListener("pointerup", g), t.addEventListener("selectstart", E), document.addEventListener("selectionchange", b);
2286
- const u = ["up", "down", "left", "right"], y = [
2287
- ...u.map((w) => `shift+${w}`),
2285
+ document.addEventListener("pointerdown", S), document.addEventListener("pointerup", p), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", b);
2286
+ const d = ["up", "down", "left", "right"], y = [
2287
+ ...d.map((w) => `shift+${w}`),
2288
2288
  "ctrl+a",
2289
2289
  "⌘+a"
2290
2290
  ];
2291
2291
  j(y.join(","), { element: t, keydown: !0, keyup: !1 }, (w) => {
2292
- w.repeat || (d = Ke(w));
2292
+ w.repeat || (h = Ke(w));
2293
2293
  });
2294
- const S = (w) => {
2295
- w.repeat || w.target !== t && w.target !== document.body || (l = void 0, h.clear());
2294
+ const C = (w) => {
2295
+ w.repeat || w.target !== t && w.target !== document.body || (c = void 0, f.clear());
2296
2296
  };
2297
- return j(u.join(","), { keydown: !0, keyup: !1 }, S), {
2297
+ return j(d.join(","), { keydown: !0, keyup: !1 }, C), {
2298
2298
  destroy: () => {
2299
- l = void 0, p = void 0, d = void 0, b.clear(), document.removeEventListener("pointerdown", C), document.removeEventListener("pointerup", g), t.removeEventListener("selectstart", E), document.removeEventListener("selectionchange", b), j.unbind();
2299
+ c = void 0, g = void 0, h = void 0, b.clear(), document.removeEventListener("pointerdown", S), document.removeEventListener("pointerup", p), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", b), j.unbind();
2300
2300
  },
2301
- setFilter: a,
2301
+ setFilter: r,
2302
2302
  setUser: i,
2303
- setAnnotatingEnabled: c
2303
+ setAnnotatingEnabled: l
2304
2304
  };
2305
- }, xo = (t, e) => ({
2305
+ }, Ao = (t, e) => ({
2306
2306
  ...t,
2307
2307
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
2308
2308
  user: t.user || e.user
2309
2309
  }), ie = "SPANS", Oo = (t, e = {}) => {
2310
2310
  Oe(t), Te(t);
2311
- const n = xo(e, {
2311
+ const n = Ao(e, {
2312
2312
  annotatingEnabled: !0,
2313
2313
  user: $n()
2314
- }), o = ro(t, n.userSelectAction), { selection: i, viewport: r } = o, a = o.store, s = kn(a), c = _n(o, s, n.adapter);
2315
- let f = n.user;
2316
- const h = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ie : n.renderer || ie, l = h === "SPANS" ? cn(t, o, r) : h === "CSS_HIGHLIGHTS" ? sn(t, o, r) : h === "CANVAS" ? qe(t, o, r) : void 0;
2317
- if (!l)
2318
- throw `Unknown renderer implementation: ${h}`;
2319
- console.debug(`Using ${h} renderer`), n.style && l.setStyle(n.style);
2320
- const p = vo(t, o, n.offsetReferenceSelector);
2321
- p.setUser(f), p.setAnnotatingEnabled(n.annotatingEnabled);
2322
- const d = Un(o, s, n.adapter), E = () => f, b = (A) => {
2323
- p.setAnnotatingEnabled(
2324
- A === void 0 ? !0 : A
2314
+ }), o = so(t, n.userSelectAction), { selection: i, viewport: s } = o, r = o.store, a = kn(r), l = _n(o, a, n.adapter);
2315
+ let u = n.user;
2316
+ const f = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ie : n.renderer || ie, c = f === "SPANS" ? ln(t, o, s) : f === "CSS_HIGHLIGHTS" ? rn(t, o, s) : f === "CANVAS" ? qe(t, o, s) : void 0;
2317
+ if (!c)
2318
+ throw `Unknown renderer implementation: ${f}`;
2319
+ console.debug(`Using ${f} renderer`), n.style && c.setStyle(n.style);
2320
+ const g = vo(t, o, n.offsetReferenceSelector);
2321
+ g.setUser(u), g.setAnnotatingEnabled(n.annotatingEnabled);
2322
+ const h = Un(o, a, n.adapter), A = () => u, b = (E) => {
2323
+ g.setAnnotatingEnabled(
2324
+ E === void 0 ? !0 : E
2325
2325
  );
2326
- }, C = (A) => {
2327
- l.setFilter(A), p.setFilter(A);
2328
- }, g = (A) => {
2329
- f = A, p.setUser(A);
2330
- }, u = (A) => {
2331
- A && (l.setPainter(ao(A, n.presence)), A.on("selectionChange", () => l.redraw()));
2332
- }, y = (A) => {
2333
- A ? i.setSelected(A) : i.clear();
2326
+ }, S = (E) => {
2327
+ c.setFilter(E), g.setFilter(E);
2328
+ }, p = (E) => {
2329
+ u = E, g.setUser(E);
2330
+ }, d = (E) => {
2331
+ E && (c.setPainter(ao(E, n.presence)), E.on("selectionChange", () => c.redraw()));
2332
+ }, y = (E) => {
2333
+ E ? i.setSelected(E) : i.clear();
2334
2334
  };
2335
2335
  return {
2336
- ...d,
2336
+ ...h,
2337
2337
  destroy: () => {
2338
- l.destroy(), p.destroy(), s.destroy();
2338
+ c.destroy(), g.destroy(), a.destroy();
2339
2339
  },
2340
2340
  element: t,
2341
- getUser: E,
2341
+ getUser: A,
2342
2342
  setAnnotatingEnabled: b,
2343
- setFilter: C,
2344
- setStyle: l.setStyle.bind(l),
2345
- redraw: l.redraw.bind(l),
2346
- setUser: g,
2343
+ setFilter: S,
2344
+ setStyle: c.setStyle.bind(c),
2345
+ redraw: c.redraw.bind(c),
2346
+ setUser: p,
2347
2347
  setSelected: y,
2348
- setPresenceProvider: u,
2349
- setVisible: l.setVisible.bind(l),
2350
- on: c.on,
2351
- off: c.off,
2352
- scrollIntoView: Ye(t, a),
2348
+ setPresenceProvider: d,
2349
+ setVisible: c.setVisible.bind(c),
2350
+ on: l.on,
2351
+ off: l.off,
2352
+ scrollIntoView: Ye(t, r),
2353
2353
  state: o
2354
2354
  };
2355
2355
  };
2356
2356
  export {
2357
2357
  bt as DEFAULT_SELECTED_STYLE,
2358
2358
  q as DEFAULT_STYLE,
2359
- re as NOT_ANNOTATABLE_CLASS,
2359
+ se as NOT_ANNOTATABLE_CLASS,
2360
2360
  P as NOT_ANNOTATABLE_SELECTOR,
2361
2361
  k as Origin,
2362
2362
  mn as UserSelectAction,
@@ -2366,16 +2366,16 @@ export {
2366
2366
  De as clonePointerEvent,
2367
2367
  Co as createBody,
2368
2368
  qe as createCanvasRenderer,
2369
- sn as createHighlightsRenderer,
2369
+ rn as createHighlightsRenderer,
2370
2370
  ao as createPresencePainter,
2371
- rn as createRenderer,
2371
+ sn as createRenderer,
2372
2372
  vo as createSelectionHandler,
2373
- cn as createSpansRenderer,
2373
+ ln as createSpansRenderer,
2374
2374
  Oo as createTextAnnotator,
2375
- ro as createTextAnnotatorState,
2375
+ so as createTextAnnotatorState,
2376
2376
  So as denormalizeRectWithOffset,
2377
- xo as fillDefaults,
2378
- Ao as getAnnotatableFragment,
2377
+ Ao as fillDefaults,
2378
+ xo as getAnnotatableFragment,
2379
2379
  Re as getQuoteContext,
2380
2380
  It as getRangeAnnotatableContents,
2381
2381
  W as isRevived,
@@ -2387,7 +2387,7 @@ export {
2387
2387
  Te as programmaticallyFocusable,
2388
2388
  Ne as rangeToSelector,
2389
2389
  wt as reviveAnnotation,
2390
- se as reviveSelector,
2390
+ re as reviveSelector,
2391
2391
  yt as reviveTarget,
2392
2392
  Ye as scrollIntoView,
2393
2393
  qn as serializeW3CTextAnnotation,