@recogito/text-annotator 3.0.0-rc.54 → 3.0.0-rc.56

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