@soomo/text-annotator 3.1.0-staging.21 → 3.1.0-staging.23

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