@soomo/text-annotator 3.0.0-staging.33 → 3.0.0-staging.35

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