@soomo/text-annotator 3.1.0-staging.4 → 3.1.0-staging.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
1
+ const le = "not-annotatable", Z = `.${le}`, nt = (t) => {
2
2
  var n;
3
3
  return !!(t instanceof HTMLElement ? t.closest(Z) : (n = t.parentElement) == null ? void 0 : n.closest(Z));
4
4
  }, Me = (t) => {
@@ -8,7 +8,7 @@ const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
8
8
  const e = document.createNodeIterator(
9
9
  t.commonAncestorContainer,
10
10
  NodeFilter.SHOW_ELEMENT,
11
- (o) => o instanceof HTMLElement && o.classList.contains(ce) && !o.parentElement.closest(Z) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
11
+ (o) => o instanceof HTMLElement && o.classList.contains(le) && !o.parentElement.closest(Z) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
12
12
  );
13
13
  let n;
14
14
  for (; n = e.nextNode(); )
@@ -26,7 +26,7 @@ const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
26
26
  o.setStartAfter(n), o.collapsed || e.push(o);
27
27
  }
28
28
  return e.length > 0 ? e : [t];
29
- }, Ut = (t) => {
29
+ }, Dt = (t) => {
30
30
  const e = t.cloneContents();
31
31
  return e.querySelectorAll(Z).forEach((n) => n.remove()), e;
32
32
  }, Ie = (t) => t.addEventListener("click", (e) => {
@@ -37,9 +37,9 @@ const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
37
37
  }, Ue = (t, e, n = 10, o) => {
38
38
  const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
39
39
  s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
40
- const r = Ut(s).textContent, a = document.createRange();
40
+ const r = Dt(s).textContent, a = document.createRange();
41
41
  a.setStart(t.endContainer, t.endOffset), i === document.body ? a.setEnd(i, i.childNodes.length) : a.setEndAfter(i);
42
- const d = Ut(a).textContent;
42
+ const d = Dt(a).textContent;
43
43
  return {
44
44
  prefix: r.substring(r.length - n),
45
45
  suffix: d.substring(0, n)
@@ -92,26 +92,26 @@ const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
92
92
  }
93
93
  }
94
94
  return i ? o : [...o, n];
95
- }, []), Ro = (t) => ({
95
+ }, []), Mo = (t) => ({
96
96
  length: t.length,
97
97
  item: (e) => t[e],
98
98
  [Symbol.iterator]: function* () {
99
99
  for (let e = 0; e < this.length; e++)
100
100
  yield this.item(e);
101
101
  }
102
- }), $e = (t, e, n) => {
102
+ }), Pe = (t, e, n) => {
103
103
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
104
104
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
105
- const s = Ut(o).textContent, r = t.toString(), a = s.length || 0, d = a + r.length;
105
+ const s = Dt(o).textContent, r = t.toString(), a = s.length || 0, d = a + r.length;
106
106
  return n ? { quote: r, start: a, end: d, range: t, offsetReference: i } : { quote: r, start: a, end: d, range: t };
107
- }, le = (t, e) => {
108
- var f, l;
107
+ }, de = (t, e) => {
108
+ var h, l;
109
109
  const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
110
110
  e,
111
111
  NodeFilter.SHOW_TEXT,
112
- (p) => {
113
- var h;
114
- return (h = p.parentElement) != null && h.closest(Z) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
112
+ (g) => {
113
+ var p;
114
+ return (p = g.parentElement) != null && p.closest(Z) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
115
115
  }
116
116
  );
117
117
  let r = 0;
@@ -121,22 +121,22 @@ const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
121
121
  let c = !i;
122
122
  for (; d !== null; ) {
123
123
  if (c || (c = i == null ? void 0 : i.contains(d)), c) {
124
- const p = ((f = d.textContent) == null ? void 0 : f.length) || 0;
125
- if (r + p > n) {
124
+ const g = ((h = d.textContent) == null ? void 0 : h.length) || 0;
125
+ if (r + g > n) {
126
126
  a.setStart(d, n - r);
127
127
  break;
128
128
  }
129
- r += p;
129
+ r += g;
130
130
  }
131
131
  d = s.nextNode();
132
132
  }
133
133
  for (; d !== null; ) {
134
- const p = ((l = d.textContent) == null ? void 0 : l.length) || 0;
135
- if (r + p >= o) {
134
+ const g = ((l = d.textContent) == null ? void 0 : l.length) || 0;
135
+ if (r + g >= o) {
136
136
  a.setEnd(d, o - r);
137
137
  break;
138
138
  }
139
- r += p, d = s.nextNode();
139
+ r += g, d = s.nextNode();
140
140
  }
141
141
  return {
142
142
  ...t,
@@ -144,21 +144,21 @@ const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
144
144
  };
145
145
  }, wt = (t, e) => F(t.selector) ? t : {
146
146
  ...t,
147
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : le(n, e))
148
- }, At = (t, e) => F(t.target.selector) ? t : { ...t, target: wt(t.target, e) }, de = (t, e) => {
147
+ selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : de(n, e))
148
+ }, xt = (t, e) => F(t.target.selector) ? t : { ...t, target: wt(t.target, e) }, ue = (t, e) => {
149
149
  if (t.isEqualNode(e))
150
150
  return !0;
151
151
  for (let n of t.childNodes)
152
- if (de(n, e))
152
+ if (ue(n, e))
153
153
  return !0;
154
154
  return !1;
155
- }, Pe = (t, e) => {
155
+ }, $e = (t, e) => {
156
156
  const n = t.cloneContents();
157
- return de(n, e);
157
+ return ue(n, e);
158
158
  }, je = (t, e) => {
159
159
  const n = t.cloneRange(), o = e.contains(n.startContainer), i = e.contains(n.endContainer);
160
- return !o && !i && !Pe(n, e) ? (n.collapse(), n) : (o || n.setStart(e, 0), i || n.setEnd(e, e.childNodes.length), n);
161
- }, xt = (t) => ({
160
+ return !o && !i && !$e(n, e) ? (n.collapse(), n) : (o || n.setStart(e, 0), i || n.setEnd(e, e.childNodes.length), n);
161
+ }, Et = (t) => ({
162
162
  ...t,
163
163
  type: t.type,
164
164
  x: t.x,
@@ -203,19 +203,19 @@ const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
203
203
  }), He = (t, e) => {
204
204
  const { left: n, top: o, right: i, bottom: s } = t;
205
205
  return new DOMRect(n - e.left, o - e.top, i - n, s - o);
206
- }, Mo = (t, e) => {
206
+ }, Bo = (t, e) => {
207
207
  const { left: n, top: o, right: i, bottom: s } = t;
208
208
  return new DOMRect(n + e.left, o + e.top, i - n, s - o);
209
- }, ue = (t) => {
209
+ }, fe = (t) => {
210
210
  if (t === null)
211
211
  return document.scrollingElement;
212
212
  const { overflowY: e } = window.getComputedStyle(t);
213
- return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ue(t.parentElement);
213
+ return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : fe(t.parentElement);
214
214
  }, ze = (t, e) => (n) => {
215
215
  const o = typeof n == "string" ? n : n.id, i = (r) => {
216
- const a = s.getBoundingClientRect(), d = s.clientHeight, c = s.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: l, height: p } = e.getAnnotationBounds(o), h = f.top - a.top, A = f.left - a.left, b = s.parentElement ? s.scrollTop : 0, E = s.parentElement ? s.scrollLeft : 0, m = h + b - (d - p) / 2, u = A + E - (c - l) / 2;
216
+ const a = s.getBoundingClientRect(), d = s.clientHeight, c = s.clientWidth, h = r.selector[0].range.getBoundingClientRect(), { width: l, height: g } = e.getAnnotationBounds(o), p = h.top - a.top, v = h.left - a.left, w = s.parentElement ? s.scrollTop : 0, E = s.parentElement ? s.scrollLeft : 0, m = p + w - (d - g) / 2, u = v + E - (c - l) / 2;
217
217
  s.scroll({ top: m, left: u, behavior: "smooth" });
218
- }, s = ue(t);
218
+ }, s = fe(t);
219
219
  if (s) {
220
220
  const r = e.getAnnotation(o), { range: a } = r.target.selector[0];
221
221
  if (a && !a.collapsed)
@@ -241,8 +241,8 @@ const ce = "not-annotatable", Z = `.${ce}`, nt = (t) => {
241
241
  function We(t) {
242
242
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
243
243
  }
244
- var Kt = { exports: {} };
245
- function fe(t, e = 100, n = {}) {
244
+ var Yt = { exports: {} };
245
+ function he(t, e = 100, n = {}) {
246
246
  if (typeof t != "function")
247
247
  throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);
248
248
  if (e < 0)
@@ -250,19 +250,19 @@ function fe(t, e = 100, n = {}) {
250
250
  const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
251
251
  let i, s, r, a, d;
252
252
  function c() {
253
- const p = i, h = s;
254
- return i = void 0, s = void 0, d = t.apply(p, h), d;
253
+ const g = i, p = s;
254
+ return i = void 0, s = void 0, d = t.apply(g, p), d;
255
255
  }
256
- function f() {
257
- const p = Date.now() - a;
258
- p < e && p >= 0 ? r = setTimeout(f, e - p) : (r = void 0, o || (d = c()));
256
+ function h() {
257
+ const g = Date.now() - a;
258
+ g < e && g >= 0 ? r = setTimeout(h, e - g) : (r = void 0, o || (d = c()));
259
259
  }
260
- const l = function(...p) {
260
+ const l = function(...g) {
261
261
  if (i && this !== i && Object.getPrototypeOf(this) === Object.getPrototypeOf(i))
262
262
  throw new Error("Debounced method called with different contexts of the same prototype.");
263
- i = this, s = p, a = Date.now();
264
- const h = o && !r;
265
- return r || (r = setTimeout(f, e)), h && (d = c()), d;
263
+ i = this, s = g, a = Date.now();
264
+ const p = o && !r;
265
+ return r || (r = setTimeout(h, e)), p && (d = c()), d;
266
266
  };
267
267
  return l.clear = () => {
268
268
  r && (clearTimeout(r), r = void 0);
@@ -272,10 +272,10 @@ function fe(t, e = 100, n = {}) {
272
272
  d = c(), l.clear();
273
273
  }, l;
274
274
  }
275
- Kt.exports.debounce = fe;
276
- Kt.exports = fe;
277
- var qe = Kt.exports;
278
- const Yt = /* @__PURE__ */ We(qe), Ge = (t) => {
275
+ Yt.exports.debounce = he;
276
+ Yt.exports = he;
277
+ var qe = Yt.exports;
278
+ const Xt = /* @__PURE__ */ We(qe), Ge = (t) => {
279
279
  const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, r = -e, a = o - n, d = i - e;
280
280
  return { top: e, left: n, minX: s, minY: r, maxX: a, maxY: d };
281
281
  }, Qe = (t) => {
@@ -284,48 +284,48 @@ const Yt = /* @__PURE__ */ We(qe), Ge = (t) => {
284
284
  const i = o.map((s) => s.id);
285
285
  (e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
286
286
  };
287
- }, Xt = (t, e, n, o) => {
287
+ }, Pt = (t, e, n, o) => {
288
288
  const { store: i, selection: s, hover: r } = e;
289
289
  let a, d, c;
290
- const f = Qe(n), l = (T) => {
291
- const { x: S, y: g } = t.getBoundingClientRect(), w = i.getAt(T.clientX - S, T.clientY - g, d);
292
- w ? r.current !== w.id && (t.classList.add("hovered"), r.set(w.id)) : r.current && (t.classList.remove("hovered"), r.set(null));
290
+ const h = Qe(n), l = (O) => {
291
+ const { x: M, y: f } = t.getBoundingClientRect(), y = i.getAt(O.clientX - M, O.clientY - f, d);
292
+ y ? r.current !== y.id && (t.classList.add("hovered"), r.set(y.id)) : r.current && (t.classList.remove("hovered"), r.set(null));
293
293
  };
294
294
  t.addEventListener("pointermove", l);
295
- const p = (T = !1) => {
295
+ const g = (O = !1) => {
296
296
  c && c.clear();
297
- const S = Ge(t), { minX: g, minY: w, maxX: v, maxY: O } = S, B = d ? i.getIntersecting(g, w, v, O).filter(({ annotation: Y }) => d(Y)) : i.getIntersecting(g, w, v, O), M = s.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: dt }) => {
298
- const Te = M.includes(Y.id), Re = Y.id === r.current;
299
- return { annotation: Y, rects: dt, state: { selected: Te, hover: Re } };
297
+ const M = Ge(t), { minX: f, minY: y, maxX: x, maxY: C } = M, B = d ? i.getIntersecting(f, y, x, C).filter(({ annotation: Y }) => d(Y)) : i.getIntersecting(f, y, x, C), R = s.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: At }) => {
298
+ const dt = R.includes(Y.id), Re = Y.id === r.current;
299
+ return { annotation: Y, rects: At, state: { selected: dt, hover: Re } };
300
300
  });
301
- o.redraw(K, S, a, c, T), setTimeout(() => f(B.map(({ annotation: Y }) => Y)), 1);
302
- }, h = (T) => {
303
- c = T, p();
304
- }, A = (T) => {
305
- a = T, p();
306
- }, b = (T) => {
307
- d = T, p(!1);
308
- }, E = () => p();
301
+ o.redraw(K, M, a, c, O), setTimeout(() => h(B.map(({ annotation: Y }) => Y)), 1);
302
+ }, p = (O) => {
303
+ c = O, g();
304
+ }, v = (O) => {
305
+ a = O, g();
306
+ }, w = (O) => {
307
+ d = O, g(!1);
308
+ }, E = () => g();
309
309
  i.observe(E);
310
- const m = s.subscribe(() => p()), u = () => p(!0);
310
+ const m = s.subscribe(() => g()), u = () => g(!0);
311
311
  document.addEventListener("scroll", u, { capture: !0, passive: !0 });
312
- const y = Yt(() => {
313
- i.recalculatePositions(), c == null || c.reset(), p();
312
+ const b = Xt(() => {
313
+ i.recalculatePositions(), c == null || c.reset(), g();
314
314
  }, 10);
315
- window.addEventListener("resize", y);
316
- const C = new ResizeObserver(y);
317
- C.observe(t);
318
- const x = { attributes: !0, childList: !0, subtree: !0 }, L = new MutationObserver((T) => {
319
- T.every((g) => g.target === t || t.contains(g.target)) || p(!0);
315
+ window.addEventListener("resize", b);
316
+ const S = new ResizeObserver(b);
317
+ S.observe(t);
318
+ const A = { attributes: !0, childList: !0, subtree: !0 }, L = new MutationObserver((O) => {
319
+ O.every((f) => f.target === t || t.contains(f.target)) || g(!0);
320
320
  });
321
- return L.observe(document.body, x), {
321
+ return L.observe(document.body, A), {
322
322
  destroy: () => {
323
- t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(E), m(), document.removeEventListener("scroll", u), y.clear(), window.removeEventListener("resize", y), C.disconnect(), L.disconnect();
323
+ t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(E), m(), document.removeEventListener("scroll", u), b.clear(), window.removeEventListener("resize", b), S.disconnect(), L.disconnect();
324
324
  },
325
- redraw: p,
326
- setStyle: A,
327
- setFilter: b,
328
- setPainter: h,
325
+ redraw: g,
326
+ setStyle: v,
327
+ setFilter: w,
328
+ setPainter: p,
329
329
  setVisible: o.setVisible
330
330
  };
331
331
  }, Je = () => {
@@ -337,32 +337,32 @@ const Yt = /* @__PURE__ */ We(qe), Ge = (t) => {
337
337
  t.classList.add("r6o-annotatable");
338
338
  const e = Je(), n = e.getContext("2d");
339
339
  document.body.appendChild(e);
340
- const o = (a, d, c, f) => requestAnimationFrame(() => {
341
- const { width: l, height: p } = e;
342
- n.clearRect(-0.5, -0.5, l + 1, p + 1), f && f.clear();
343
- const { top: h, left: A } = d;
340
+ const o = (a, d, c, h) => requestAnimationFrame(() => {
341
+ const { width: l, height: g } = e;
342
+ n.clearRect(-0.5, -0.5, l + 1, g + 1), h && h.clear();
343
+ const { top: p, left: v } = d;
344
344
  [...a].sort((E, m) => {
345
- const { annotation: { target: { created: u } } } = E, { annotation: { target: { created: y } } } = m;
346
- return u.getTime() - y.getTime();
345
+ const { annotation: { target: { created: u } } } = E, { annotation: { target: { created: b } } } = m;
346
+ return u.getTime() - b.getTime();
347
347
  }).forEach((E) => {
348
- var C;
349
- const m = c ? typeof c == "function" ? c(E.annotation, E.state) : c : (C = E.state) != null && C.selected ? vt : W, u = f && f.paint(E, d) || m, y = E.rects.map(({ x, y: L, width: R, height: T }) => ({
350
- x: x + A,
351
- y: L + h,
352
- width: R,
353
- height: T
348
+ var S;
349
+ const m = c ? typeof c == "function" ? c(E.annotation, E.state) : c : (S = E.state) != null && S.selected ? vt : W, u = h && h.paint(E, d) || m, b = E.rects.map(({ x: A, y: L, width: T, height: O }) => ({
350
+ x: A + v,
351
+ y: L + p,
352
+ width: T,
353
+ height: O
354
354
  }));
355
- if (n.fillStyle = u.fill, n.globalAlpha = u.fillOpacity || 1, y.forEach(
356
- ({ x, y: L, width: R, height: T }) => n.fillRect(x, L, R, T)
355
+ if (n.fillStyle = u.fill, n.globalAlpha = u.fillOpacity || 1, b.forEach(
356
+ ({ x: A, y: L, width: T, height: O }) => n.fillRect(A, L, T, O)
357
357
  ), u.underlineColor) {
358
358
  n.globalAlpha = 1, n.strokeStyle = u.underlineColor, n.lineWidth = u.underlineThickness ?? 1;
359
- const x = u.underlineOffset ?? 0;
360
- y.forEach(({ x: L, y: R, width: T, height: S }) => {
361
- n.beginPath(), n.moveTo(L, R + S + x), n.lineTo(L + T, R + S + x), n.stroke();
359
+ const A = u.underlineOffset ?? 0;
360
+ b.forEach(({ x: L, y: T, width: O, height: M }) => {
361
+ n.beginPath(), n.moveTo(L, T + M + A), n.lineTo(L + O, T + M + A), n.stroke();
362
362
  });
363
363
  }
364
364
  });
365
- }), i = Yt(() => Ze(e), 10);
365
+ }), i = Xt(() => Ze(e), 10);
366
366
  return window.addEventListener("resize", i), {
367
367
  destroy: () => {
368
368
  e.remove(), i.clear(), window.removeEventListener("resize", i);
@@ -372,18 +372,18 @@ const Yt = /* @__PURE__ */ We(qe), Ge = (t) => {
372
372
  },
373
373
  redraw: o
374
374
  };
375
- }, en = (t, e, n) => Xt(t, e, n, tn(t));
375
+ }, en = (t, e, n) => Pt(t, e, n, tn(t));
376
376
  var nn = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, H = function(t) {
377
377
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
378
378
  }, _ = function(t, e, n) {
379
379
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
380
380
  }, X = function(t, e, n) {
381
381
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
382
- }, he = function(t) {
382
+ }, pe = function(t) {
383
383
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
384
- }, jt = function(t) {
384
+ }, Ht = function(t) {
385
385
  return { r: X(t.r, 0, 255), g: X(t.g, 0, 255), b: X(t.b, 0, 255), a: X(t.a) };
386
- }, Et = function(t) {
386
+ }, St = function(t) {
387
387
  return { r: _(t.r), g: _(t.g), b: _(t.b), a: _(t.a, 3) };
388
388
  }, on = /^#([0-9a-f]{3,8})$/i, ft = function(t) {
389
389
  var e = t.toString(16);
@@ -391,120 +391,120 @@ var nn = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, H = function(t) {
391
391
  }, ge = function(t) {
392
392
  var e = t.r, n = t.g, o = t.b, i = t.a, s = Math.max(e, n, o), r = s - Math.min(e, n, o), a = r ? s === e ? (n - o) / r : s === n ? 2 + (o - e) / r : 4 + (e - n) / r : 0;
393
393
  return { h: 60 * (a < 0 ? a + 6 : a), s: s ? r / s * 100 : 0, v: s / 255 * 100, a: i };
394
- }, pe = function(t) {
394
+ }, me = function(t) {
395
395
  var e = t.h, n = t.s, o = t.v, i = t.a;
396
396
  e = e / 360 * 6, n /= 100, o /= 100;
397
397
  var s = Math.floor(e), r = o * (1 - n), a = o * (1 - (e - s) * n), d = o * (1 - (1 - e + s) * n), c = s % 6;
398
398
  return { r: 255 * [o, a, r, r, d, o][c], g: 255 * [d, o, o, a, r, r][c], b: 255 * [r, r, d, o, o, a][c], a: i };
399
- }, Ht = function(t) {
400
- return { h: he(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
401
399
  }, zt = function(t) {
402
- return { h: _(t.h), s: _(t.s), l: _(t.l), a: _(t.a, 3) };
400
+ return { h: pe(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
403
401
  }, Ft = function(t) {
404
- return pe((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
402
+ return { h: _(t.h), s: _(t.s), l: _(t.l), a: _(t.a, 3) };
403
+ }, Wt = function(t) {
404
+ return me((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
405
405
  var e, n, o;
406
406
  }, st = function(t) {
407
407
  return { h: (e = ge(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
408
408
  var e, n, o, i;
409
- }, sn = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, rn = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, an = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, cn = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Wt = { string: [[function(t) {
409
+ }, sn = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, rn = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, an = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, cn = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, qt = { string: [[function(t) {
410
410
  var e = on.exec(t);
411
411
  return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? _(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? _(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
412
412
  }, "hex"], [function(t) {
413
413
  var e = an.exec(t) || cn.exec(t);
414
- return e ? e[2] !== e[4] || e[4] !== e[6] ? null : jt({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
414
+ return e ? e[2] !== e[4] || e[4] !== e[6] ? null : Ht({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
415
415
  }, "rgb"], [function(t) {
416
416
  var e = sn.exec(t) || rn.exec(t);
417
417
  if (!e) return null;
418
- var n, o, i = Ht({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (nn[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
419
- return Ft(i);
418
+ var n, o, i = zt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (nn[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
419
+ return Wt(i);
420
420
  }, "hsl"]], object: [[function(t) {
421
421
  var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
422
- return H(e) && H(n) && H(o) ? jt({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
422
+ return H(e) && H(n) && H(o) ? Ht({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
423
423
  }, "rgb"], [function(t) {
424
424
  var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
425
425
  if (!H(e) || !H(n) || !H(o)) return null;
426
- var r = Ht({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
427
- return Ft(r);
426
+ var r = zt({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
427
+ return Wt(r);
428
428
  }, "hsl"], [function(t) {
429
429
  var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
430
430
  if (!H(e) || !H(n) || !H(o)) return null;
431
431
  var r = function(a) {
432
- return { h: he(a.h), s: X(a.s, 0, 100), v: X(a.v, 0, 100), a: X(a.a) };
432
+ return { h: pe(a.h), s: X(a.s, 0, 100), v: X(a.v, 0, 100), a: X(a.a) };
433
433
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
434
- return pe(r);
435
- }, "hsv"]] }, qt = function(t, e) {
434
+ return me(r);
435
+ }, "hsv"]] }, Gt = function(t, e) {
436
436
  for (var n = 0; n < e.length; n++) {
437
437
  var o = e[n][0](t);
438
438
  if (o) return [o, e[n][1]];
439
439
  }
440
440
  return [null, void 0];
441
441
  }, ln = function(t) {
442
- return typeof t == "string" ? qt(t.trim(), Wt.string) : typeof t == "object" && t !== null ? qt(t, Wt.object) : [null, void 0];
443
- }, St = function(t, e) {
442
+ return typeof t == "string" ? Gt(t.trim(), qt.string) : typeof t == "object" && t !== null ? Gt(t, qt.object) : [null, void 0];
443
+ }, Ct = function(t, e) {
444
444
  var n = st(t);
445
445
  return { h: n.h, s: X(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
446
- }, Ct = function(t) {
446
+ }, Lt = function(t) {
447
447
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
448
- }, Gt = function(t, e) {
448
+ }, Qt = function(t, e) {
449
449
  var n = st(t);
450
450
  return { h: n.h, s: n.s, l: X(n.l + 100 * e, 0, 100), a: n.a };
451
- }, Qt = function() {
451
+ }, Jt = function() {
452
452
  function t(e) {
453
453
  this.parsed = ln(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
454
454
  }
455
455
  return t.prototype.isValid = function() {
456
456
  return this.parsed !== null;
457
457
  }, t.prototype.brightness = function() {
458
- return _(Ct(this.rgba), 2);
458
+ return _(Lt(this.rgba), 2);
459
459
  }, t.prototype.isDark = function() {
460
- return Ct(this.rgba) < 0.5;
460
+ return Lt(this.rgba) < 0.5;
461
461
  }, t.prototype.isLight = function() {
462
- return Ct(this.rgba) >= 0.5;
462
+ return Lt(this.rgba) >= 0.5;
463
463
  }, t.prototype.toHex = function() {
464
- return e = Et(this.rgba), n = e.r, o = e.g, i = e.b, r = (s = e.a) < 1 ? ft(_(255 * s)) : "", "#" + ft(n) + ft(o) + ft(i) + r;
464
+ return e = St(this.rgba), n = e.r, o = e.g, i = e.b, r = (s = e.a) < 1 ? ft(_(255 * s)) : "", "#" + ft(n) + ft(o) + ft(i) + r;
465
465
  var e, n, o, i, s, r;
466
466
  }, t.prototype.toRgb = function() {
467
- return Et(this.rgba);
467
+ return St(this.rgba);
468
468
  }, t.prototype.toRgbString = function() {
469
- 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 + ")";
469
+ 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 + ")";
470
470
  var e, n, o, i, s;
471
471
  }, t.prototype.toHsl = function() {
472
- return zt(st(this.rgba));
472
+ return Ft(st(this.rgba));
473
473
  }, t.prototype.toHslString = function() {
474
- return e = zt(st(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
474
+ return e = Ft(st(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
475
475
  var e, n, o, i, s;
476
476
  }, t.prototype.toHsv = function() {
477
477
  return e = ge(this.rgba), { h: _(e.h), s: _(e.s), v: _(e.v), a: _(e.a, 3) };
478
478
  var e;
479
479
  }, t.prototype.invert = function() {
480
- return P({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
480
+ return $({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
481
481
  var e;
482
482
  }, t.prototype.saturate = function(e) {
483
- return e === void 0 && (e = 0.1), P(St(this.rgba, e));
483
+ return e === void 0 && (e = 0.1), $(Ct(this.rgba, e));
484
484
  }, t.prototype.desaturate = function(e) {
485
- return e === void 0 && (e = 0.1), P(St(this.rgba, -e));
485
+ return e === void 0 && (e = 0.1), $(Ct(this.rgba, -e));
486
486
  }, t.prototype.grayscale = function() {
487
- return P(St(this.rgba, -1));
487
+ return $(Ct(this.rgba, -1));
488
488
  }, t.prototype.lighten = function(e) {
489
- return e === void 0 && (e = 0.1), P(Gt(this.rgba, e));
489
+ return e === void 0 && (e = 0.1), $(Qt(this.rgba, e));
490
490
  }, t.prototype.darken = function(e) {
491
- return e === void 0 && (e = 0.1), P(Gt(this.rgba, -e));
491
+ return e === void 0 && (e = 0.1), $(Qt(this.rgba, -e));
492
492
  }, t.prototype.rotate = function(e) {
493
493
  return e === void 0 && (e = 15), this.hue(this.hue() + e);
494
494
  }, t.prototype.alpha = function(e) {
495
- return typeof e == "number" ? P({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : _(this.rgba.a, 3);
495
+ return typeof e == "number" ? $({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : _(this.rgba.a, 3);
496
496
  var n;
497
497
  }, t.prototype.hue = function(e) {
498
498
  var n = st(this.rgba);
499
- return typeof e == "number" ? P({ h: e, s: n.s, l: n.l, a: n.a }) : _(n.h);
499
+ return typeof e == "number" ? $({ h: e, s: n.s, l: n.l, a: n.a }) : _(n.h);
500
500
  }, t.prototype.isEqual = function(e) {
501
- return this.toHex() === P(e).toHex();
501
+ return this.toHex() === $(e).toHex();
502
502
  }, t;
503
- }(), P = function(t) {
504
- return t instanceof Qt ? t : new Qt(t);
503
+ }(), $ = function(t) {
504
+ return t instanceof Jt ? t : new Jt(t);
505
505
  };
506
506
  const dn = (t) => [
507
- `background-color:${P((t == null ? void 0 : t.fill) || W.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? W.fillOpacity : t.fillOpacity).toHex()}`,
507
+ `background-color:${$((t == null ? void 0 : t.fill) || W.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? W.fillOpacity : t.fillOpacity).toHex()}`,
508
508
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
509
509
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
510
510
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
@@ -524,21 +524,21 @@ const dn = (t) => [
524
524
  d && d.clear();
525
525
  const c = new Set(s.map((l) => l.annotation.id));
526
526
  Array.from(e).filter((l) => !c.has(l));
527
- const f = s.map((l) => {
528
- var A;
529
- const p = a ? typeof a == "function" ? a(l.annotation, l.state) : a : (A = l.state) != null && A.selected ? vt : W, h = d && d.paint(l, r) || p;
530
- return `::highlight(_${l.annotation.id}) { ${dn(h)} }`;
527
+ const h = s.map((l) => {
528
+ var v;
529
+ const g = a ? typeof a == "function" ? a(l.annotation, l.state) : a : (v = l.state) != null && v.selected ? vt : W, p = d && d.paint(l, r) || g;
530
+ return `::highlight(_${l.annotation.id}) { ${dn(p)} }`;
531
531
  });
532
- t.innerHTML = f.join(`
532
+ t.innerHTML = h.join(`
533
533
  `), CSS.highlights.clear(), s.forEach(({ annotation: l }) => {
534
- const p = l.target.selector.map((A) => A.range), h = new Highlight(...p);
535
- CSS.highlights.set(`_${l.id}`, h);
534
+ const g = l.target.selector.map((v) => v.range), p = new Highlight(...g);
535
+ CSS.highlights.set(`_${l.id}`, p);
536
536
  }), e = c;
537
537
  }
538
538
  };
539
- }, fn = (t, e, n) => Xt(t, e, n, un());
540
- var Jt = Object.prototype.hasOwnProperty;
541
- function Dt(t, e) {
539
+ }, fn = (t, e, n) => Pt(t, e, n, un());
540
+ var Zt = Object.prototype.hasOwnProperty;
541
+ function Vt(t, e) {
542
542
  var n, o;
543
543
  if (t === e) return !0;
544
544
  if (t && e && (n = t.constructor) === e.constructor) {
@@ -546,13 +546,13 @@ function Dt(t, e) {
546
546
  if (n === RegExp) return t.toString() === e.toString();
547
547
  if (n === Array) {
548
548
  if ((o = t.length) === e.length)
549
- for (; o-- && Dt(t[o], e[o]); ) ;
549
+ for (; o-- && Vt(t[o], e[o]); ) ;
550
550
  return o === -1;
551
551
  }
552
552
  if (!n || typeof t == "object") {
553
553
  o = 0;
554
554
  for (n in t)
555
- if (Jt.call(t, n) && ++o && !Jt.call(e, n) || !(n in e) || !Dt(t[n], e[n])) return !1;
555
+ if (Zt.call(t, n) && ++o && !Zt.call(e, n) || !(n in e) || !Vt(t[n], e[n])) return !1;
556
556
  return Object.keys(e).length === o;
557
557
  }
558
558
  }
@@ -561,7 +561,7 @@ function Dt(t, e) {
561
561
  const hn = (t, e) => {
562
562
  const n = (s, r) => s.x <= r.x + r.width && s.x + s.width >= r.x && s.y <= r.y + r.height && s.y + s.height >= r.y, o = (s) => s.rects.reduce((r, a) => r + a.width, 0), i = e.filter(({ rects: s }) => s.some((r) => n(t, r)));
563
563
  return i.sort((s, r) => o(r) - o(s)), i.findIndex((s) => s.rects.includes(t));
564
- }, gn = (t) => {
564
+ }, pn = (t) => {
565
565
  t.classList.add("r6o-annotatable");
566
566
  const e = document.createElement("div");
567
567
  e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
@@ -570,18 +570,18 @@ const hn = (t, e) => {
570
570
  destroy: () => {
571
571
  e.remove();
572
572
  },
573
- redraw: (r, a, d, c, f) => {
574
- const p = !(Dt(n, r) && f);
575
- if (!c && !p) return;
576
- p && (e.innerHTML = ""), [...r].sort((A, b) => {
577
- const { annotation: { target: { created: E } } } = A, { annotation: { target: { created: m } } } = b;
573
+ redraw: (r, a, d, c, h) => {
574
+ const g = !(Vt(n, r) && h);
575
+ if (!c && !g) return;
576
+ g && (e.innerHTML = ""), [...r].sort((v, w) => {
577
+ const { annotation: { target: { created: E } } } = v, { annotation: { target: { created: m } } } = w;
578
578
  return E && m ? E.getTime() - m.getTime() : 0;
579
- }).forEach((A) => {
580
- A.rects.map((b) => {
581
- const E = hn(b, r), m = Fe(A, a, d, c, E);
582
- if (p) {
579
+ }).forEach((v) => {
580
+ v.rects.map((w) => {
581
+ const E = hn(w, r), m = Fe(v, a, d, c, E);
582
+ if (g) {
583
583
  const u = document.createElement("span");
584
- u.className = "r6o-annotation", u.dataset.annotation = A.annotation.id, u.style.left = `${b.x}px`, u.style.top = `${b.y}px`, u.style.width = `${b.width}px`, u.style.height = `${b.height}px`, u.style.backgroundColor = P((m == null ? void 0 : m.fill) || W.fill).alpha((m == null ? void 0 : m.fillOpacity) === void 0 ? W.fillOpacity : m.fillOpacity).toHex(), m.underlineStyle && (u.style.borderStyle = m.underlineStyle), m.underlineColor && (u.style.borderColor = m.underlineColor), m.underlineThickness && (u.style.borderBottomWidth = `${m.underlineThickness}px`), m.underlineOffset && (u.style.paddingBottom = `${m.underlineOffset}px`), e.appendChild(u);
584
+ u.className = "r6o-annotation", u.dataset.annotation = v.annotation.id, u.style.left = `${w.x}px`, u.style.top = `${w.y}px`, u.style.width = `${w.width}px`, u.style.height = `${w.height}px`, u.style.backgroundColor = $((m == null ? void 0 : m.fill) || W.fill).alpha((m == null ? void 0 : m.fillOpacity) === void 0 ? W.fillOpacity : m.fillOpacity).toHex(), m.underlineStyle && (u.style.borderStyle = m.underlineStyle), m.underlineColor && (u.style.borderColor = m.underlineColor), m.underlineThickness && (u.style.borderBottomWidth = `${m.underlineThickness}px`), m.underlineOffset && (u.style.paddingBottom = `${m.underlineOffset}px`), e.appendChild(u);
585
585
  }
586
586
  });
587
587
  }), n = r;
@@ -590,10 +590,10 @@ const hn = (t, e) => {
590
590
  r ? e.classList.remove("hidden") : e.classList.add("hidden");
591
591
  }
592
592
  };
593
- }, pn = (t, e, n) => Xt(t, e, n, gn(t));
593
+ }, gn = (t, e, n) => Pt(t, e, n, pn(t));
594
594
  var U = [];
595
- for (var Lt = 0; Lt < 256; ++Lt)
596
- U.push((Lt + 256).toString(16).slice(1));
595
+ for (var Ot = 0; Ot < 256; ++Ot)
596
+ U.push((Ot + 256).toString(16).slice(1));
597
597
  function mn(t, e = 0) {
598
598
  return (U[t[e + 0]] + U[t[e + 1]] + U[t[e + 2]] + U[t[e + 3]] + "-" + U[t[e + 4]] + U[t[e + 5]] + "-" + U[t[e + 6]] + U[t[e + 7]] + "-" + U[t[e + 8]] + U[t[e + 9]] + "-" + U[t[e + 10]] + U[t[e + 11]] + U[t[e + 12]] + U[t[e + 13]] + U[t[e + 14]] + U[t[e + 15]]).toLowerCase();
599
599
  }
@@ -604,17 +604,17 @@ function bn() {
604
604
  return ht(yn);
605
605
  }
606
606
  var wn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
607
- const Zt = {
607
+ const te = {
608
608
  randomUUID: wn
609
609
  };
610
- function me(t, e, n) {
611
- if (Zt.randomUUID && !e && !t)
612
- return Zt.randomUUID();
610
+ function ye(t, e, n) {
611
+ if (te.randomUUID && !e && !t)
612
+ return te.randomUUID();
613
613
  t = t || {};
614
614
  var o = t.random || (t.rng || bn)();
615
615
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, mn(o);
616
616
  }
617
- var te = Object.prototype.hasOwnProperty;
617
+ var ee = Object.prototype.hasOwnProperty;
618
618
  function q(t, e) {
619
619
  var n, o;
620
620
  if (t === e) return !0;
@@ -629,19 +629,19 @@ function q(t, e) {
629
629
  if (!n || typeof t == "object") {
630
630
  o = 0;
631
631
  for (n in t)
632
- if (te.call(t, n) && ++o && !te.call(e, n) || !(n in e) || !q(t[n], e[n])) return !1;
632
+ if (ee.call(t, n) && ++o && !ee.call(e, n) || !(n in e) || !q(t[n], e[n])) return !1;
633
633
  return Object.keys(e).length === o;
634
634
  }
635
635
  }
636
636
  return t !== t && e !== e;
637
637
  }
638
- function Ot() {
638
+ function Tt() {
639
639
  }
640
640
  function vn(t, e) {
641
641
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
642
642
  }
643
643
  const G = [];
644
- function $t(t, e = Ot) {
644
+ function $t(t, e = Tt) {
645
645
  let n;
646
646
  const o = /* @__PURE__ */ new Set();
647
647
  function i(a) {
@@ -659,9 +659,9 @@ function $t(t, e = Ot) {
659
659
  function s(a) {
660
660
  i(a(t));
661
661
  }
662
- function r(a, d = Ot) {
662
+ function r(a, d = Tt) {
663
663
  const c = [a, d];
664
- return o.add(c), o.size === 1 && (n = e(i, s) || Ot), a(t), () => {
664
+ return o.add(c), o.size === 1 && (n = e(i, s) || Tt), a(t), () => {
665
665
  o.delete(c), o.size === 0 && n && (n(), n = null);
666
666
  };
667
667
  }
@@ -685,52 +685,52 @@ const An = (t) => {
685
685
  };
686
686
  };
687
687
  var xn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(xn || {});
688
- const gt = { selected: [] }, En = (t, e, n) => {
689
- const { subscribe: o, set: i } = $t(gt);
690
- let s = e, r = gt;
691
- o((A) => r = A);
688
+ const pt = { selected: [] }, En = (t, e, n) => {
689
+ const { subscribe: o, set: i } = $t(pt);
690
+ let s = e, r = pt;
691
+ o((v) => r = v);
692
692
  const a = () => {
693
- q(r, gt) || i(gt);
693
+ q(r, pt) || i(pt);
694
694
  }, d = () => {
695
- var A;
696
- return ((A = r.selected) == null ? void 0 : A.length) === 0;
697
- }, c = (A) => {
695
+ var v;
696
+ return ((v = r.selected) == null ? void 0 : v.length) === 0;
697
+ }, c = (v) => {
698
698
  if (d())
699
699
  return !1;
700
- const b = typeof A == "string" ? A : A.id;
701
- return r.selected.some((E) => E.id === b);
702
- }, f = (A, b) => {
703
- const E = t.getAnnotation(A);
700
+ const w = typeof v == "string" ? v : v.id;
701
+ return r.selected.some((E) => E.id === w);
702
+ }, h = (v, w) => {
703
+ const E = t.getAnnotation(v);
704
704
  if (!E) {
705
- console.warn("Invalid selection: " + A);
705
+ console.warn("Invalid selection: " + v);
706
706
  return;
707
707
  }
708
- switch (ee(E, s)) {
708
+ switch (ne(E, s)) {
709
709
  case "EDIT":
710
- i({ selected: [{ id: A, editable: !0 }], event: b });
710
+ i({ selected: [{ id: v, editable: !0 }], event: w });
711
711
  break;
712
712
  case "SELECT":
713
- i({ selected: [{ id: A }], event: b });
713
+ i({ selected: [{ id: v }], event: w });
714
714
  break;
715
715
  default:
716
- i({ selected: [], event: b });
716
+ i({ selected: [], event: w });
717
717
  }
718
- }, l = (A, b) => {
719
- const E = Array.isArray(A) ? A : [A], m = E.map((u) => t.getAnnotation(u)).filter((u) => !!u);
718
+ }, l = (v, w) => {
719
+ const E = Array.isArray(v) ? v : [v], m = E.map((u) => t.getAnnotation(u)).filter((u) => !!u);
720
720
  i({
721
721
  selected: m.map((u) => {
722
- const y = b === void 0 ? ee(u, s) === "EDIT" : b;
723
- return { id: u.id, editable: y };
722
+ const b = w === void 0 ? ne(u, s) === "EDIT" : w;
723
+ return { id: u.id, editable: b };
724
724
  })
725
- }), m.length !== E.length && console.warn("Invalid selection", A);
726
- }, p = (A) => {
725
+ }), m.length !== E.length && console.warn("Invalid selection", v);
726
+ }, g = (v) => {
727
727
  if (d())
728
728
  return !1;
729
- const { selected: b } = r;
730
- b.some(({ id: E }) => A.includes(E)) && i({ selected: b.filter(({ id: E }) => !A.includes(E)) });
731
- }, h = (A) => s = A;
729
+ const { selected: w } = r;
730
+ w.some(({ id: E }) => v.includes(E)) && i({ selected: w.filter(({ id: E }) => !v.includes(E)) });
731
+ }, p = (v) => s = v;
732
732
  return t.observe(
733
- ({ changes: A }) => p((A.deleted || []).map((b) => b.id))
733
+ ({ changes: v }) => g((v.deleted || []).map((w) => w.id))
734
734
  ), {
735
735
  get event() {
736
736
  return r ? r.event : null;
@@ -745,35 +745,35 @@ const gt = { selected: [] }, En = (t, e, n) => {
745
745
  isEmpty: d,
746
746
  isSelected: c,
747
747
  setSelected: l,
748
- setUserSelectAction: h,
748
+ setUserSelectAction: p,
749
749
  subscribe: o,
750
- userSelect: f
750
+ userSelect: h
751
751
  };
752
- }, ee = (t, e, n) => typeof e == "function" ? e(t) : e || "EDIT";
752
+ }, ne = (t, e, n) => typeof e == "function" ? e(t) : e || "EDIT";
753
753
  var D = [];
754
- for (var Tt = 0; Tt < 256; ++Tt)
755
- D.push((Tt + 256).toString(16).slice(1));
754
+ for (var Rt = 0; Rt < 256; ++Rt)
755
+ D.push((Rt + 256).toString(16).slice(1));
756
756
  function Sn(t, e = 0) {
757
757
  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();
758
758
  }
759
- var pt, Cn = new Uint8Array(16);
759
+ var gt, Cn = new Uint8Array(16);
760
760
  function Ln() {
761
- if (!pt && (pt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !pt))
761
+ if (!gt && (gt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !gt))
762
762
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
763
- return pt(Cn);
763
+ return gt(Cn);
764
764
  }
765
765
  var On = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
766
- const ne = {
766
+ const oe = {
767
767
  randomUUID: On
768
768
  };
769
- function ye(t, e, n) {
770
- if (ne.randomUUID && !e && !t)
771
- return ne.randomUUID();
769
+ function be(t, e, n) {
770
+ if (oe.randomUUID && !e && !t)
771
+ return oe.randomUUID();
772
772
  t = t || {};
773
773
  var o = t.random || (t.rng || Ln)();
774
774
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Sn(o);
775
775
  }
776
- const Rt = (t) => {
776
+ const Mt = (t) => {
777
777
  const e = (n) => {
778
778
  const o = { ...n };
779
779
  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;
@@ -783,8 +783,8 @@ const Rt = (t) => {
783
783
  bodies: (t.bodies || []).map(e),
784
784
  target: e(t.target)
785
785
  };
786
- }, Bo = (t, e, n, o) => ({
787
- id: ye(),
786
+ }, ko = (t, e, n, o) => ({
787
+ id: be(),
788
788
  annotation: typeof t == "string" ? t : t.id,
789
789
  created: n || /* @__PURE__ */ new Date(),
790
790
  creator: o,
@@ -798,7 +798,7 @@ const Rt = (t) => {
798
798
  }, Mn = (t, e) => e.bodies.map((n) => {
799
799
  const o = t.bodies.find((i) => i.id === n.id);
800
800
  return { newBody: n, oldBody: o && !q(o, n) ? o : void 0 };
801
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Bn = (t, e) => !q(t.target, e.target), be = (t, e) => {
801
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Bn = (t, e) => !q(t.target, e.target), we = (t, e) => {
802
802
  const n = Tn(t, e), o = Rn(t, e), i = Mn(t, e);
803
803
  return {
804
804
  oldValue: t,
@@ -818,7 +818,7 @@ const kn = (t, e) => {
818
818
  if (t.options.ignore) {
819
819
  const { ignore: r } = t.options, a = (d) => d && d.length > 0;
820
820
  if (!(a(i.created) || a(i.deleted))) {
821
- const d = (n = i.updated) == null ? void 0 : n.some((f) => a(f.bodiesCreated) || a(f.bodiesDeleted) || a(f.bodiesUpdated)), c = (o = i.updated) == null ? void 0 : o.some((f) => f.targetUpdated);
821
+ const d = (n = i.updated) == null ? void 0 : n.some((h) => a(h.bodiesCreated) || a(h.bodiesDeleted) || a(h.bodiesUpdated)), c = (o = i.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
822
822
  if (r === "BODY_ONLY" && d && !c || r === "TARGET_ONLY" && c && !d)
823
823
  return !1;
824
824
  }
@@ -834,25 +834,25 @@ const kn = (t, e) => {
834
834
  return !0;
835
835
  }, In = (t, e) => {
836
836
  const n = new Set((t.created || []).map((l) => l.id)), o = new Set((t.updated || []).map(({ newValue: l }) => l.id)), i = new Set((e.created || []).map((l) => l.id)), s = new Set((e.deleted || []).map((l) => l.id)), r = new Set((e.updated || []).map(({ oldValue: l }) => l.id)), a = new Set((e.updated || []).filter(({ oldValue: l }) => n.has(l.id) || o.has(l.id)).map(({ oldValue: l }) => l.id)), d = [
837
- ...(t.created || []).filter((l) => !s.has(l.id)).map((l) => r.has(l.id) ? e.updated.find(({ oldValue: p }) => p.id === l.id).newValue : l),
837
+ ...(t.created || []).filter((l) => !s.has(l.id)).map((l) => r.has(l.id) ? e.updated.find(({ oldValue: g }) => g.id === l.id).newValue : l),
838
838
  ...e.created || []
839
839
  ], c = [
840
840
  ...(t.deleted || []).filter((l) => !i.has(l.id)),
841
841
  ...(e.deleted || []).filter((l) => !n.has(l.id))
842
- ], f = [
842
+ ], h = [
843
843
  ...(t.updated || []).filter(({ newValue: l }) => !s.has(l.id)).map((l) => {
844
- const { oldValue: p, newValue: h } = l;
845
- if (r.has(h.id)) {
846
- const A = e.updated.find((b) => b.oldValue.id === h.id).newValue;
847
- return be(p, A);
844
+ const { oldValue: g, newValue: p } = l;
845
+ if (r.has(p.id)) {
846
+ const v = e.updated.find((w) => w.oldValue.id === p.id).newValue;
847
+ return we(g, v);
848
848
  } else
849
849
  return l;
850
850
  }),
851
851
  ...(e.updated || []).filter(({ oldValue: l }) => !a.has(l.id))
852
852
  ];
853
- return { created: d, deleted: c, updated: f };
854
- }, Mt = (t) => {
855
- const e = t.id === void 0 ? ye() : t.id;
853
+ return { created: d, deleted: c, updated: h };
854
+ }, Bt = (t) => {
855
+ const e = t.id === void 0 ? be() : t.id;
856
856
  return {
857
857
  ...t,
858
858
  id: e,
@@ -866,201 +866,201 @@ const kn = (t, e) => {
866
866
  }
867
867
  };
868
868
  }, Nn = (t) => t.id !== void 0, _n = () => {
869
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (g, w = {}) => {
870
- n.push({ onChange: g, options: w });
871
- }, i = (g) => {
872
- const w = n.findIndex((v) => v.onChange == g);
873
- w > -1 && n.splice(w, 1);
874
- }, s = (g, w) => {
875
- const v = {
876
- origin: g,
869
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (f, y = {}) => {
870
+ n.push({ onChange: f, options: y });
871
+ }, i = (f) => {
872
+ const y = n.findIndex((x) => x.onChange == f);
873
+ y > -1 && n.splice(y, 1);
874
+ }, s = (f, y) => {
875
+ const x = {
876
+ origin: f,
877
877
  changes: {
878
- created: w.created || [],
879
- updated: w.updated || [],
880
- deleted: w.deleted || []
878
+ created: y.created || [],
879
+ updated: y.updated || [],
880
+ deleted: y.deleted || []
881
881
  },
882
882
  state: [...t.values()]
883
883
  };
884
- n.forEach((O) => {
885
- kn(O, v) && O.onChange(v);
884
+ n.forEach((C) => {
885
+ kn(C, x) && C.onChange(x);
886
886
  });
887
- }, r = (g, w = k.LOCAL) => {
888
- if (g.id && t.get(g.id))
889
- throw Error(`Cannot add annotation ${g.id} - exists already`);
887
+ }, r = (f, y = k.LOCAL) => {
888
+ if (f.id && t.get(f.id))
889
+ throw Error(`Cannot add annotation ${f.id} - exists already`);
890
890
  {
891
- const v = Mt(g);
892
- t.set(v.id, v), v.bodies.forEach((O) => e.set(O.id, v.id)), s(w, { created: [v] });
891
+ const x = Bt(f);
892
+ t.set(x.id, x), x.bodies.forEach((C) => e.set(C.id, x.id)), s(y, { created: [x] });
893
893
  }
894
- }, a = (g, w) => {
895
- const v = Mt(typeof g == "string" ? w : g), O = typeof g == "string" ? g : g.id, B = O && t.get(O);
894
+ }, a = (f, y) => {
895
+ const x = Bt(typeof f == "string" ? y : f), C = typeof f == "string" ? f : f.id, B = C && t.get(C);
896
896
  if (B) {
897
- const M = be(B, v);
898
- return O === v.id ? t.set(O, v) : (t.delete(O), t.set(v.id, v)), B.bodies.forEach((K) => e.delete(K.id)), v.bodies.forEach((K) => e.set(K.id, v.id)), M;
897
+ const R = we(B, x);
898
+ return C === x.id ? t.set(C, x) : (t.delete(C), t.set(x.id, x)), B.bodies.forEach((K) => e.delete(K.id)), x.bodies.forEach((K) => e.set(K.id, x.id)), R;
899
899
  } else
900
- console.warn(`Cannot update annotation ${O} - does not exist`);
901
- }, d = (g, w = k.LOCAL, v = k.LOCAL) => {
902
- const O = Nn(w) ? v : w, B = a(g, w);
903
- B && s(O, { updated: [B] });
904
- }, c = (g, w = k.LOCAL) => {
905
- const v = g.reduce((O, B) => {
906
- const M = a(B);
907
- return M ? [...O, M] : O;
900
+ console.warn(`Cannot update annotation ${C} - does not exist`);
901
+ }, d = (f, y = k.LOCAL, x = k.LOCAL) => {
902
+ const C = Nn(y) ? x : y, B = a(f, y);
903
+ B && s(C, { updated: [B] });
904
+ }, c = (f, y = k.LOCAL) => {
905
+ const x = f.reduce((C, B) => {
906
+ const R = a(B);
907
+ return R ? [...C, R] : C;
908
908
  }, []);
909
- v.length > 0 && s(w, { updated: v });
910
- }, f = (g, w = k.LOCAL) => {
911
- const v = t.get(g.annotation);
912
- if (v) {
913
- const O = {
914
- ...v,
915
- bodies: [...v.bodies, g]
909
+ x.length > 0 && s(y, { updated: x });
910
+ }, h = (f, y = k.LOCAL) => {
911
+ const x = t.get(f.annotation);
912
+ if (x) {
913
+ const C = {
914
+ ...x,
915
+ bodies: [...x.bodies, f]
916
916
  };
917
- t.set(v.id, O), e.set(g.id, O.id), s(w, { updated: [{
918
- oldValue: v,
919
- newValue: O,
920
- bodiesCreated: [g]
917
+ t.set(x.id, C), e.set(f.id, C.id), s(y, { updated: [{
918
+ oldValue: x,
919
+ newValue: C,
920
+ bodiesCreated: [f]
921
921
  }] });
922
922
  } else
923
- console.warn(`Attempt to add body to missing annotation: ${g.annotation}`);
924
- }, l = () => [...t.values()], p = (g = k.LOCAL) => {
925
- const w = [...t.values()];
926
- t.clear(), e.clear(), s(g, { deleted: w });
927
- }, h = (g, w = !0, v = k.LOCAL) => {
928
- const O = g.map(Mt);
929
- if (w) {
923
+ console.warn(`Attempt to add body to missing annotation: ${f.annotation}`);
924
+ }, l = () => [...t.values()], g = (f = k.LOCAL) => {
925
+ const y = [...t.values()];
926
+ t.clear(), e.clear(), s(f, { deleted: y });
927
+ }, p = (f, y = !0, x = k.LOCAL) => {
928
+ const C = f.map(Bt);
929
+ if (y) {
930
930
  const B = [...t.values()];
931
- t.clear(), e.clear(), O.forEach((M) => {
932
- t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
933
- }), s(v, { created: O, deleted: B });
931
+ t.clear(), e.clear(), C.forEach((R) => {
932
+ t.set(R.id, R), R.bodies.forEach((K) => e.set(K.id, R.id));
933
+ }), s(x, { created: C, deleted: B });
934
934
  } else {
935
- const B = g.reduce((M, K) => {
935
+ const B = f.reduce((R, K) => {
936
936
  const Y = K.id && t.get(K.id);
937
- return Y ? [...M, Y] : M;
937
+ return Y ? [...R, Y] : R;
938
938
  }, []);
939
939
  if (B.length > 0)
940
- throw Error(`Bulk insert would overwrite the following annotations: ${B.map((M) => M.id).join(", ")}`);
941
- O.forEach((M) => {
942
- t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
943
- }), s(v, { created: O });
940
+ throw Error(`Bulk insert would overwrite the following annotations: ${B.map((R) => R.id).join(", ")}`);
941
+ C.forEach((R) => {
942
+ t.set(R.id, R), R.bodies.forEach((K) => e.set(K.id, R.id));
943
+ }), s(x, { created: C });
944
944
  }
945
- }, A = (g) => {
946
- const w = typeof g == "string" ? g : g.id, v = t.get(w);
947
- if (v)
948
- return t.delete(w), v.bodies.forEach((O) => e.delete(O.id)), v;
949
- console.warn(`Attempt to delete missing annotation: ${w}`);
950
- }, b = (g, w = k.LOCAL) => {
951
- const v = A(g);
952
- v && s(w, { deleted: [v] });
953
- }, E = (g, w = k.LOCAL) => {
954
- const v = g.reduce((O, B) => {
955
- const M = A(B);
956
- return M ? [...O, M] : O;
945
+ }, v = (f) => {
946
+ const y = typeof f == "string" ? f : f.id, x = t.get(y);
947
+ if (x)
948
+ return t.delete(y), x.bodies.forEach((C) => e.delete(C.id)), x;
949
+ console.warn(`Attempt to delete missing annotation: ${y}`);
950
+ }, w = (f, y = k.LOCAL) => {
951
+ const x = v(f);
952
+ x && s(y, { deleted: [x] });
953
+ }, E = (f, y = k.LOCAL) => {
954
+ const x = f.reduce((C, B) => {
955
+ const R = v(B);
956
+ return R ? [...C, R] : C;
957
957
  }, []);
958
- v.length > 0 && s(w, { deleted: v });
959
- }, m = (g) => {
960
- const w = t.get(g.annotation);
961
- if (w) {
962
- const v = w.bodies.find((O) => O.id === g.id);
963
- if (v) {
964
- e.delete(v.id);
965
- const O = {
966
- ...w,
967
- bodies: w.bodies.filter((B) => B.id !== g.id)
958
+ x.length > 0 && s(y, { deleted: x });
959
+ }, m = (f) => {
960
+ const y = t.get(f.annotation);
961
+ if (y) {
962
+ const x = y.bodies.find((C) => C.id === f.id);
963
+ if (x) {
964
+ e.delete(x.id);
965
+ const C = {
966
+ ...y,
967
+ bodies: y.bodies.filter((B) => B.id !== f.id)
968
968
  };
969
- return t.set(w.id, O), {
970
- oldValue: w,
971
- newValue: O,
972
- bodiesDeleted: [v]
969
+ return t.set(y.id, C), {
970
+ oldValue: y,
971
+ newValue: C,
972
+ bodiesDeleted: [x]
973
973
  };
974
974
  } else
975
- console.warn(`Attempt to delete missing body ${g.id} from annotation ${g.annotation}`);
975
+ console.warn(`Attempt to delete missing body ${f.id} from annotation ${f.annotation}`);
976
976
  } else
977
- console.warn(`Attempt to delete body from missing annotation ${g.annotation}`);
978
- }, u = (g, w = k.LOCAL) => {
979
- const v = m(g);
980
- v && s(w, { updated: [v] });
981
- }, y = (g, w = k.LOCAL) => {
982
- const v = g.map((O) => m(O)).filter(Boolean);
983
- v.length > 0 && s(w, { updated: v });
984
- }, C = (g) => {
985
- const w = t.get(g);
986
- return w ? { ...w } : void 0;
987
- }, x = (g) => {
988
- const w = e.get(g);
989
- if (w) {
990
- const v = C(w).bodies.find((O) => O.id === g);
991
- if (v)
992
- return v;
993
- console.error(`Store integrity error: body ${g} in index, but not in annotation`);
977
+ console.warn(`Attempt to delete body from missing annotation ${f.annotation}`);
978
+ }, u = (f, y = k.LOCAL) => {
979
+ const x = m(f);
980
+ x && s(y, { updated: [x] });
981
+ }, b = (f, y = k.LOCAL) => {
982
+ const x = f.map((C) => m(C)).filter(Boolean);
983
+ x.length > 0 && s(y, { updated: x });
984
+ }, S = (f) => {
985
+ const y = t.get(f);
986
+ return y ? { ...y } : void 0;
987
+ }, A = (f) => {
988
+ const y = e.get(f);
989
+ if (y) {
990
+ const x = S(y).bodies.find((C) => C.id === f);
991
+ if (x)
992
+ return x;
993
+ console.error(`Store integrity error: body ${f} in index, but not in annotation`);
994
994
  } else
995
- console.warn(`Attempt to retrieve missing body: ${g}`);
996
- }, L = (g, w) => {
997
- if (g.annotation !== w.annotation)
995
+ console.warn(`Attempt to retrieve missing body: ${f}`);
996
+ }, L = (f, y) => {
997
+ if (f.annotation !== y.annotation)
998
998
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
999
- const v = t.get(g.annotation);
1000
- if (v) {
1001
- const O = v.bodies.find((M) => M.id === g.id), B = {
1002
- ...v,
1003
- bodies: v.bodies.map((M) => M.id === O.id ? w : M)
999
+ const x = t.get(f.annotation);
1000
+ if (x) {
1001
+ const C = x.bodies.find((R) => R.id === f.id), B = {
1002
+ ...x,
1003
+ bodies: x.bodies.map((R) => R.id === C.id ? y : R)
1004
1004
  };
1005
- return t.set(v.id, B), O.id !== w.id && (e.delete(O.id), e.set(w.id, B.id)), {
1006
- oldValue: v,
1005
+ return t.set(x.id, B), C.id !== y.id && (e.delete(C.id), e.set(y.id, B.id)), {
1006
+ oldValue: x,
1007
1007
  newValue: B,
1008
- bodiesUpdated: [{ oldBody: O, newBody: w }]
1008
+ bodiesUpdated: [{ oldBody: C, newBody: y }]
1009
1009
  };
1010
1010
  } else
1011
- console.warn(`Attempt to add body to missing annotation ${g.annotation}`);
1012
- }, R = (g, w, v = k.LOCAL) => {
1013
- const O = L(g, w);
1014
- O && s(v, { updated: [O] });
1015
- }, T = (g, w = k.LOCAL) => {
1016
- const v = g.map((O) => L({ id: O.id, annotation: O.annotation }, O)).filter(Boolean);
1017
- s(w, { updated: v });
1018
- }, S = (g) => {
1019
- const w = t.get(g.annotation);
1020
- if (w) {
1021
- const v = {
1022
- ...w,
1011
+ console.warn(`Attempt to add body to missing annotation ${f.annotation}`);
1012
+ }, T = (f, y, x = k.LOCAL) => {
1013
+ const C = L(f, y);
1014
+ C && s(x, { updated: [C] });
1015
+ }, O = (f, y = k.LOCAL) => {
1016
+ const x = f.map((C) => L({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
1017
+ s(y, { updated: x });
1018
+ }, M = (f) => {
1019
+ const y = t.get(f.annotation);
1020
+ if (y) {
1021
+ const x = {
1022
+ ...y,
1023
1023
  target: {
1024
- ...w.target,
1025
- ...g
1024
+ ...y.target,
1025
+ ...f
1026
1026
  }
1027
1027
  };
1028
- return t.set(w.id, v), {
1029
- oldValue: w,
1030
- newValue: v,
1028
+ return t.set(y.id, x), {
1029
+ oldValue: y,
1030
+ newValue: x,
1031
1031
  targetUpdated: {
1032
- oldTarget: w.target,
1033
- newTarget: g
1032
+ oldTarget: y.target,
1033
+ newTarget: f
1034
1034
  }
1035
1035
  };
1036
1036
  } else
1037
- console.warn(`Attempt to update target on missing annotation: ${g.annotation}`);
1037
+ console.warn(`Attempt to update target on missing annotation: ${f.annotation}`);
1038
1038
  };
1039
1039
  return {
1040
1040
  addAnnotation: r,
1041
- addBody: f,
1041
+ addBody: h,
1042
1042
  all: l,
1043
- bulkAddAnnotation: h,
1043
+ bulkAddAnnotation: p,
1044
1044
  bulkDeleteAnnotation: E,
1045
- bulkDeleteBodies: y,
1045
+ bulkDeleteBodies: b,
1046
1046
  bulkUpdateAnnotation: c,
1047
- bulkUpdateBodies: T,
1048
- bulkUpdateTargets: (g, w = k.LOCAL) => {
1049
- const v = g.map((O) => S(O)).filter(Boolean);
1050
- v.length > 0 && s(w, { updated: v });
1047
+ bulkUpdateBodies: O,
1048
+ bulkUpdateTargets: (f, y = k.LOCAL) => {
1049
+ const x = f.map((C) => M(C)).filter(Boolean);
1050
+ x.length > 0 && s(y, { updated: x });
1051
1051
  },
1052
- clear: p,
1053
- deleteAnnotation: b,
1052
+ clear: g,
1053
+ deleteAnnotation: w,
1054
1054
  deleteBody: u,
1055
- getAnnotation: C,
1056
- getBody: x,
1055
+ getAnnotation: S,
1056
+ getBody: A,
1057
1057
  observe: o,
1058
1058
  unobserve: i,
1059
1059
  updateAnnotation: d,
1060
- updateBody: R,
1061
- updateTarget: (g, w = k.LOCAL) => {
1062
- const v = S(g);
1063
- v && s(w, { updated: [v] });
1060
+ updateBody: T,
1061
+ updateTarget: (f, y = k.LOCAL) => {
1062
+ const x = M(f);
1063
+ x && s(y, { updated: [x] });
1064
1064
  }
1065
1065
  };
1066
1066
  };
@@ -1081,38 +1081,38 @@ let Un = () => ({
1081
1081
  const Dn = 250, Vn = (t) => {
1082
1082
  const e = Un(), n = [];
1083
1083
  let o = -1, i = !1, s = 0;
1084
- const r = (h) => {
1084
+ const r = (p) => {
1085
1085
  if (!i) {
1086
- const { changes: A } = h, b = performance.now();
1087
- if (b - s > Dn)
1088
- n.splice(o + 1), n.push(A), o = n.length - 1;
1086
+ const { changes: v } = p, w = performance.now();
1087
+ if (w - s > Dn)
1088
+ n.splice(o + 1), n.push(v), o = n.length - 1;
1089
1089
  else {
1090
1090
  const E = n.length - 1;
1091
- n[E] = In(n[E], A);
1091
+ n[E] = In(n[E], v);
1092
1092
  }
1093
- s = b;
1093
+ s = w;
1094
1094
  }
1095
1095
  i = !1;
1096
1096
  };
1097
1097
  t.observe(r, { origin: k.LOCAL });
1098
- const a = (h) => h && h.length > 0 && t.bulkDeleteAnnotation(h), d = (h) => h && h.length > 0 && t.bulkAddAnnotation(h, !1), c = (h) => h && h.length > 0 && t.bulkUpdateAnnotation(h.map(({ oldValue: A }) => A)), f = (h) => h && h.length > 0 && t.bulkUpdateAnnotation(h.map(({ newValue: A }) => A)), l = (h) => h && h.length > 0 && t.bulkAddAnnotation(h, !1), p = (h) => h && h.length > 0 && t.bulkDeleteAnnotation(h);
1098
+ const a = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), d = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), c = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: v }) => v)), h = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: v }) => v)), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), g = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
1099
1099
  return {
1100
1100
  canRedo: () => n.length - 1 > o,
1101
1101
  canUndo: () => o > -1,
1102
1102
  destroy: () => t.unobserve(r),
1103
- on: (h, A) => e.on(h, A),
1103
+ on: (p, v) => e.on(p, v),
1104
1104
  redo: () => {
1105
1105
  if (n.length - 1 > o) {
1106
1106
  i = !0;
1107
- const { created: h, updated: A, deleted: b } = n[o + 1];
1108
- d(h), f(A), p(b), e.emit("redo", n[o + 1]), o += 1;
1107
+ const { created: p, updated: v, deleted: w } = n[o + 1];
1108
+ d(p), h(v), g(w), e.emit("redo", n[o + 1]), o += 1;
1109
1109
  }
1110
1110
  },
1111
1111
  undo: () => {
1112
1112
  if (o > -1) {
1113
1113
  i = !0;
1114
- const { created: h, updated: A, deleted: b } = n[o];
1115
- a(h), c(A), l(b), e.emit("undo", n[o]), o -= 1;
1114
+ const { created: p, updated: v, deleted: w } = n[o];
1115
+ a(p), c(v), l(w), e.emit("undo", n[o]), o -= 1;
1116
1116
  }
1117
1117
  }
1118
1118
  };
@@ -1124,72 +1124,72 @@ const Dn = 250, Vn = (t) => {
1124
1124
  };
1125
1125
  }, Yn = (t, e, n, o) => {
1126
1126
  const { hover: i, selection: s, store: r, viewport: a } = t, d = /* @__PURE__ */ new Map();
1127
- let c = [], f;
1128
- const l = (b, E) => {
1129
- d.has(b) ? d.get(b).push(E) : d.set(b, [E]);
1130
- }, p = (b, E) => {
1131
- const m = d.get(b);
1127
+ let c = [], h;
1128
+ const l = (w, E) => {
1129
+ d.has(w) ? d.get(w).push(E) : d.set(w, [E]);
1130
+ }, g = (w, E) => {
1131
+ const m = d.get(w);
1132
1132
  if (m) {
1133
1133
  const u = m.indexOf(E);
1134
1134
  u !== -1 && m.splice(u, 1);
1135
1135
  }
1136
- }, h = (b, E, m) => {
1137
- d.has(b) && setTimeout(() => {
1138
- d.get(b).forEach((u) => {
1136
+ }, p = (w, E, m) => {
1137
+ d.has(w) && setTimeout(() => {
1138
+ d.get(w).forEach((u) => {
1139
1139
  if (n) {
1140
- const y = Array.isArray(E) ? E.map((x) => n.serialize(x)) : n.serialize(E), C = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
1141
- u(y, C);
1140
+ const b = Array.isArray(E) ? E.map((A) => n.serialize(A)) : n.serialize(E), S = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
1141
+ u(b, S);
1142
1142
  } else
1143
1143
  u(E, m);
1144
1144
  });
1145
1145
  }, 1);
1146
1146
  };
1147
- s.subscribe(({ selected: b }) => {
1148
- if (!(c.length === 0 && b.length === 0)) {
1149
- if (c.length === 0 && b.length > 0)
1150
- c = b.map(({ id: E }) => r.getAnnotation(E));
1151
- else if (c.length > 0 && b.length === 0)
1147
+ s.subscribe(({ selected: w }) => {
1148
+ if (!(c.length === 0 && w.length === 0)) {
1149
+ if (c.length === 0 && w.length > 0)
1150
+ c = w.map(({ id: E }) => r.getAnnotation(E));
1151
+ else if (c.length > 0 && w.length === 0)
1152
1152
  c.forEach((E) => {
1153
1153
  const m = r.getAnnotation(E.id);
1154
- m && !q(m, E) && h("updateAnnotation", m, E);
1154
+ m && !q(m, E) && p("updateAnnotation", m, E);
1155
1155
  }), c = [];
1156
1156
  else {
1157
- const E = new Set(c.map((u) => u.id)), m = new Set(b.map(({ id: u }) => u));
1157
+ const E = new Set(c.map((u) => u.id)), m = new Set(w.map(({ id: u }) => u));
1158
1158
  c.filter((u) => !m.has(u.id)).forEach((u) => {
1159
- const y = r.getAnnotation(u.id);
1160
- y && !q(y, u) && h("updateAnnotation", y, u);
1159
+ const b = r.getAnnotation(u.id);
1160
+ b && !q(b, u) && p("updateAnnotation", b, u);
1161
1161
  }), c = [
1162
1162
  // Remove annotations that were deselected
1163
1163
  ...c.filter((u) => m.has(u.id)),
1164
1164
  // Add editable annotations that were selected
1165
- ...b.filter(({ id: u }) => !E.has(u)).map(({ id: u }) => r.getAnnotation(u))
1165
+ ...w.filter(({ id: u }) => !E.has(u)).map(({ id: u }) => r.getAnnotation(u))
1166
1166
  ];
1167
1167
  }
1168
- h("selectionChanged", c);
1168
+ p("selectionChanged", c);
1169
1169
  }
1170
- }), i.subscribe((b) => {
1171
- !f && b ? h("mouseEnterAnnotation", r.getAnnotation(b)) : f && !b ? h("mouseLeaveAnnotation", r.getAnnotation(f)) : f && b && (h("mouseLeaveAnnotation", r.getAnnotation(f)), h("mouseEnterAnnotation", r.getAnnotation(b))), f = b;
1172
- }), a == null || a.subscribe((b) => h("viewportIntersect", b.map((E) => r.getAnnotation(E)))), r.observe((b) => {
1173
- const { created: E, deleted: m } = b.changes;
1174
- (E || []).forEach((u) => h("createAnnotation", u)), (m || []).forEach((u) => h("deleteAnnotation", u)), (b.changes.updated || []).filter((u) => [
1170
+ }), i.subscribe((w) => {
1171
+ !h && w ? p("mouseEnterAnnotation", r.getAnnotation(w)) : h && !w ? p("mouseLeaveAnnotation", r.getAnnotation(h)) : h && w && (p("mouseLeaveAnnotation", r.getAnnotation(h)), p("mouseEnterAnnotation", r.getAnnotation(w))), h = w;
1172
+ }), a == null || a.subscribe((w) => p("viewportIntersect", w.map((E) => r.getAnnotation(E)))), r.observe((w) => {
1173
+ const { created: E, deleted: m } = w.changes;
1174
+ (E || []).forEach((u) => p("createAnnotation", u)), (m || []).forEach((u) => p("deleteAnnotation", u)), (w.changes.updated || []).filter((u) => [
1175
1175
  ...u.bodiesCreated || [],
1176
1176
  ...u.bodiesDeleted || [],
1177
1177
  ...u.bodiesUpdated || []
1178
- ].length > 0).forEach(({ oldValue: u, newValue: y }) => {
1179
- const C = c.find((x) => x.id === u.id) || u;
1180
- c = c.map((x) => x.id === u.id ? y : x), h("updateAnnotation", y, C);
1178
+ ].length > 0).forEach(({ oldValue: u, newValue: b }) => {
1179
+ const S = c.find((A) => A.id === u.id) || u;
1180
+ c = c.map((A) => A.id === u.id ? b : A), p("updateAnnotation", b, S);
1181
1181
  });
1182
- }, { origin: k.LOCAL }), r.observe((b) => {
1182
+ }, { origin: k.LOCAL }), r.observe((w) => {
1183
1183
  if (c) {
1184
- const E = new Set(c.map((u) => u.id)), m = (b.changes.updated || []).filter(({ newValue: u }) => E.has(u.id)).map(({ newValue: u }) => u);
1185
- m.length > 0 && (c = c.map((u) => m.find((C) => C.id === u.id) || u));
1184
+ const E = new Set(c.map((u) => u.id)), m = (w.changes.updated || []).filter(({ newValue: u }) => E.has(u.id)).map(({ newValue: u }) => u);
1185
+ m.length > 0 && (c = c.map((u) => m.find((S) => S.id === u.id) || u));
1186
1186
  }
1187
1187
  }, { origin: k.REMOTE });
1188
- const A = (b) => (E) => {
1188
+ const v = (w) => (E) => {
1189
1189
  const { updated: m } = E;
1190
- b ? (m || []).forEach((u) => h("updateAnnotation", u.oldValue, u.newValue)) : (m || []).forEach((u) => h("updateAnnotation", u.newValue, u.oldValue));
1190
+ w ? (m || []).forEach((u) => p("updateAnnotation", u.oldValue, u.newValue)) : (m || []).forEach((u) => p("updateAnnotation", u.newValue, u.oldValue));
1191
1191
  };
1192
- return e.on("undo", A(!0)), e.on("redo", A(!1)), { on: l, off: p, emit: h };
1192
+ return e.on("undo", v(!0)), e.on("redo", v(!1)), { on: l, off: g, emit: p };
1193
1193
  }, Xn = (t) => (e) => e.reduce((n, o) => {
1194
1194
  const { parsed: i, error: s } = t.parse(o);
1195
1195
  return s ? {
@@ -1201,21 +1201,21 @@ const Dn = 250, Vn = (t) => {
1201
1201
  } : {
1202
1202
  ...n
1203
1203
  };
1204
- }, { parsed: [], failed: [] }), $n = (t, e, n) => {
1204
+ }, { parsed: [], failed: [] }), Pn = (t, e, n) => {
1205
1205
  const { store: o, selection: i } = t, s = (m) => {
1206
1206
  if (n) {
1207
- const { parsed: u, error: y } = n.parse(m);
1208
- u ? o.addAnnotation(u, k.REMOTE) : console.error(y);
1207
+ const { parsed: u, error: b } = n.parse(m);
1208
+ u ? o.addAnnotation(u, k.REMOTE) : console.error(b);
1209
1209
  } else
1210
- o.addAnnotation(Rt(m), k.REMOTE);
1210
+ o.addAnnotation(Mt(m), k.REMOTE);
1211
1211
  }, r = () => i.clear(), a = () => o.clear(), d = (m) => {
1212
1212
  const u = o.getAnnotation(m);
1213
1213
  return n && u ? n.serialize(u) : u;
1214
- }, c = () => n ? o.all().map(n.serialize) : o.all(), f = () => {
1214
+ }, c = () => n ? o.all().map(n.serialize) : o.all(), h = () => {
1215
1215
  var m;
1216
- const u = (((m = i.selected) == null ? void 0 : m.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1216
+ const u = (((m = i.selected) == null ? void 0 : m.map((b) => b.id)) || []).map((b) => o.getAnnotation(b)).filter(Boolean);
1217
1217
  return n ? u.map(n.serialize) : u;
1218
- }, l = (m, u = !0) => fetch(m).then((y) => y.json()).then((y) => (h(y, u), y)), p = (m) => {
1218
+ }, l = (m, u = !0) => fetch(m).then((b) => b.json()).then((b) => (p(b, u), b)), g = (m) => {
1219
1219
  if (typeof m == "string") {
1220
1220
  const u = o.getAnnotation(m);
1221
1221
  if (o.deleteAnnotation(m), u)
@@ -1225,23 +1225,23 @@ const Dn = 250, Vn = (t) => {
1225
1225
  if (u)
1226
1226
  return o.deleteAnnotation(u), m;
1227
1227
  }
1228
- }, h = (m, u = !0) => {
1228
+ }, p = (m, u = !0) => {
1229
1229
  if (n) {
1230
- const y = n.parseAll || Xn(n), { parsed: C, failed: x } = y(m);
1231
- x.length > 0 && console.warn(`Discarded ${x.length} invalid annotations`, x), o.bulkAddAnnotation(C, u, k.REMOTE);
1230
+ const b = n.parseAll || Xn(n), { parsed: S, failed: A } = b(m);
1231
+ A.length > 0 && console.warn(`Discarded ${A.length} invalid annotations`, A), o.bulkAddAnnotation(S, u, k.REMOTE);
1232
1232
  } else
1233
- o.bulkAddAnnotation(m.map(Rt), u, k.REMOTE);
1234
- }, A = (m, u) => {
1233
+ o.bulkAddAnnotation(m.map(Mt), u, k.REMOTE);
1234
+ }, v = (m, u) => {
1235
1235
  m ? i.setSelected(m, u) : i.clear();
1236
- }, b = (m) => {
1236
+ }, w = (m) => {
1237
1237
  i.clear(), i.setUserSelectAction(m);
1238
1238
  }, E = (m) => {
1239
1239
  if (n) {
1240
- const u = n.parse(m).parsed, y = n.serialize(o.getAnnotation(u.id));
1241
- return o.updateAnnotation(u), y;
1240
+ const u = n.parse(m).parsed, b = n.serialize(o.getAnnotation(u.id));
1241
+ return o.updateAnnotation(u), b;
1242
1242
  } else {
1243
1243
  const u = o.getAnnotation(m.id);
1244
- return o.updateAnnotation(Rt(m)), u;
1244
+ return o.updateAnnotation(Mt(m)), u;
1245
1245
  }
1246
1246
  };
1247
1247
  return {
@@ -1252,17 +1252,17 @@ const Dn = 250, Vn = (t) => {
1252
1252
  clearAnnotations: a,
1253
1253
  getAnnotationById: d,
1254
1254
  getAnnotations: c,
1255
- getSelected: f,
1255
+ getSelected: h,
1256
1256
  loadAnnotations: l,
1257
1257
  redo: e.redo,
1258
- removeAnnotation: p,
1259
- setAnnotations: h,
1260
- setSelected: A,
1261
- setUserSelectAction: b,
1258
+ removeAnnotation: g,
1259
+ setAnnotations: p,
1260
+ setSelected: v,
1261
+ setUserSelectAction: w,
1262
1262
  undo: e.undo,
1263
1263
  updateAnnotation: E
1264
1264
  };
1265
- }, Pn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1265
+ }, $n = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1266
1266
  let jn = (t) => crypto.getRandomValues(new Uint8Array(t)), Hn = (t, e, n) => {
1267
1267
  let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
1268
1268
  return (s = e) => {
@@ -1276,7 +1276,7 @@ let jn = (t) => crypto.getRandomValues(new Uint8Array(t)), Hn = (t, e, n) => {
1276
1276
  }, zn = (t, e = 21) => Hn(t, e, jn), Fn = (t = 21) => {
1277
1277
  let e = "", n = crypto.getRandomValues(new Uint8Array(t));
1278
1278
  for (; t--; )
1279
- e += Pn[n[t] & 63];
1279
+ e += $n[n[t] & 63];
1280
1280
  return e;
1281
1281
  };
1282
1282
  const Wn = () => ({ isGuest: !0, id: zn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), qn = (t) => {
@@ -1287,18 +1287,18 @@ const Wn = () => ({ isGuest: !0, id: zn("1234567890abcdefghijklmnopqrstuvwxyzABC
1287
1287
  n = (n << 5) - n + s, n |= 0;
1288
1288
  }
1289
1289
  return `${n}`;
1290
- }, we = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Gn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1291
- const { id: o, type: i, purpose: s, value: r, created: a, modified: d, creator: c, ...f } = n;
1290
+ }, ve = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Gn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1291
+ const { id: o, type: i, purpose: s, value: r, created: a, modified: d, creator: c, ...h } = n;
1292
1292
  return {
1293
1293
  id: o || `temp-${qn(n)}`,
1294
1294
  annotation: e,
1295
1295
  type: i,
1296
1296
  purpose: s,
1297
1297
  value: r,
1298
- creator: we(c),
1298
+ creator: ve(c),
1299
1299
  created: a ? new Date(a) : void 0,
1300
1300
  updated: d ? new Date(d) : void 0,
1301
- ...f
1301
+ ...h
1302
1302
  };
1303
1303
  }), Qn = (t) => t.map((e) => {
1304
1304
  var n;
@@ -1310,7 +1310,7 @@ const Wn = () => ({ isGuest: !0, id: zn("1234567890abcdefghijklmnopqrstuvwxyzABC
1310
1310
  return (n = a.id) != null && n.startsWith("temp-") && delete a.id, a;
1311
1311
  });
1312
1312
  Fn();
1313
- const ko = (t, e) => ({
1313
+ const Io = (t, e) => ({
1314
1314
  parse: (n) => to(n),
1315
1315
  serialize: (n) => eo(n, t, e)
1316
1316
  }), Jn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, Zn = (t) => {
@@ -1324,7 +1324,7 @@ const ko = (t, e) => ({
1324
1324
  if (r.length === 0)
1325
1325
  return { error: Error(`No targets found for annotation: ${t.id}`) };
1326
1326
  const a = {
1327
- creator: we(n),
1327
+ creator: ve(n),
1328
1328
  created: o ? new Date(o) : void 0,
1329
1329
  updated: i ? new Date(i) : void 0,
1330
1330
  annotation: e,
@@ -1332,30 +1332,30 @@ const ko = (t, e) => ({
1332
1332
  styleClass: r[0].styleClass
1333
1333
  };
1334
1334
  for (const d of r) {
1335
- const f = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((l, p) => {
1336
- switch (p.type) {
1335
+ const h = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((l, g) => {
1336
+ switch (g.type) {
1337
1337
  case "TextQuoteSelector":
1338
- l.quote = p.exact;
1338
+ l.quote = g.exact;
1339
1339
  break;
1340
1340
  case "TextPositionSelector":
1341
- l.start = p.start, l.end = p.end;
1341
+ l.start = g.start, l.end = g.end;
1342
1342
  break;
1343
1343
  }
1344
1344
  return l;
1345
1345
  }, {});
1346
- if (Jn(f))
1347
- a.selector.push({ id: d.id, ...f });
1346
+ if (Jn(h))
1347
+ a.selector.push({ id: d.id, ...h });
1348
1348
  else {
1349
1349
  const l = [
1350
- f.start ? void 0 : "TextPositionSelector",
1351
- f.quote ? void 0 : "TextQuoteSelector"
1350
+ h.start ? void 0 : "TextPositionSelector",
1351
+ h.quote ? void 0 : "TextQuoteSelector"
1352
1352
  ].filter(Boolean);
1353
1353
  return { error: Error(`Missing selector types: ${l.join(" and ")} for annotation: ${t.id}`) };
1354
1354
  }
1355
1355
  }
1356
1356
  return { parsed: a };
1357
1357
  }, to = (t) => {
1358
- const e = t.id || me(), {
1358
+ const e = t.id || ye(), {
1359
1359
  creator: n,
1360
1360
  created: o,
1361
1361
  modified: i,
@@ -1376,23 +1376,23 @@ const ko = (t, e) => ({
1376
1376
  creator: a,
1377
1377
  created: d,
1378
1378
  updated: c,
1379
- ...f
1380
- } = i, l = r.map((p) => {
1381
- const { quote: h, start: A, end: b, range: E } = p, { prefix: m, suffix: u } = Ue(E, n), y = [{
1379
+ ...h
1380
+ } = i, l = r.map((g) => {
1381
+ const { quote: p, start: v, end: w, range: E } = g, { prefix: m, suffix: u } = Ue(E, n), b = [{
1382
1382
  type: "TextQuoteSelector",
1383
- exact: h,
1383
+ exact: p,
1384
1384
  prefix: m,
1385
1385
  suffix: u
1386
1386
  }, {
1387
1387
  type: "TextPositionSelector",
1388
- start: A,
1389
- end: b
1388
+ start: v,
1389
+ end: w
1390
1390
  }];
1391
1391
  return {
1392
- ...f,
1393
- id: p.id,
1392
+ ...h,
1393
+ id: g.id,
1394
1394
  source: e,
1395
- selector: y
1395
+ selector: b
1396
1396
  };
1397
1397
  });
1398
1398
  return {
@@ -1407,11 +1407,11 @@ const ko = (t, e) => ({
1407
1407
  target: l
1408
1408
  };
1409
1409
  };
1410
- function ve(t, e, n = 0, o = t.length - 1, i = no) {
1410
+ function Ae(t, e, n = 0, o = t.length - 1, i = no) {
1411
1411
  for (; o > n; ) {
1412
1412
  if (o - n > 600) {
1413
- const d = o - n + 1, c = e - n + 1, f = Math.log(d), l = 0.5 * Math.exp(2 * f / 3), p = 0.5 * Math.sqrt(f * l * (d - l) / d) * (c - d / 2 < 0 ? -1 : 1), h = Math.max(n, Math.floor(e - c * l / d + p)), A = Math.min(o, Math.floor(e + (d - c) * l / d + p));
1414
- ve(t, e, h, A, i);
1413
+ const d = o - n + 1, c = e - n + 1, h = Math.log(d), l = 0.5 * Math.exp(2 * h / 3), g = 0.5 * Math.sqrt(h * l * (d - l) / d) * (c - d / 2 < 0 ? -1 : 1), p = Math.max(n, Math.floor(e - c * l / d + g)), v = Math.min(o, Math.floor(e + (d - c) * l / d + g));
1414
+ Ae(t, e, p, v, i);
1415
1415
  }
1416
1416
  const s = t[e];
1417
1417
  let r = n, a = o;
@@ -1444,7 +1444,7 @@ class oo {
1444
1444
  for (; n; ) {
1445
1445
  for (let r = 0; r < n.children.length; r++) {
1446
1446
  const a = n.children[r], d = n.leaf ? i(a) : a;
1447
- yt(e, d) && (n.leaf ? o.push(a) : kt(e, d) ? this._all(a, o) : s.push(a));
1447
+ yt(e, d) && (n.leaf ? o.push(a) : It(e, d) ? this._all(a, o) : s.push(a));
1448
1448
  }
1449
1449
  n = s.pop();
1450
1450
  }
@@ -1458,7 +1458,7 @@ class oo {
1458
1458
  for (let i = 0; i < n.children.length; i++) {
1459
1459
  const s = n.children[i], r = n.leaf ? this.toBBox(s) : s;
1460
1460
  if (yt(e, r)) {
1461
- if (n.leaf || kt(e, r)) return !0;
1461
+ if (n.leaf || It(e, r)) return !0;
1462
1462
  o.push(s);
1463
1463
  }
1464
1464
  }
@@ -1500,11 +1500,11 @@ class oo {
1500
1500
  let a, d, c;
1501
1501
  for (; o || s.length; ) {
1502
1502
  if (o || (o = s.pop(), d = s[s.length - 1], a = r.pop(), c = !0), o.leaf) {
1503
- const f = io(e, o.children, n);
1504
- if (f !== -1)
1505
- return o.children.splice(f, 1), s.push(o), this._condense(s), this;
1503
+ const h = io(e, o.children, n);
1504
+ if (h !== -1)
1505
+ return o.children.splice(h, 1), s.push(o), this._condense(s), this;
1506
1506
  }
1507
- !c && !o.leaf && kt(o, i) ? (s.push(o), r.push(a), a = 0, d = o, o = o.children[0]) : d ? (a++, o = d.children[a], c = !1) : o = null;
1507
+ !c && !o.leaf && It(o, i) ? (s.push(o), r.push(a), a = 0, d = o, o = o.children[0]) : d ? (a++, o = d.children[a], c = !1) : o = null;
1508
1508
  }
1509
1509
  return this;
1510
1510
  }
@@ -1536,13 +1536,13 @@ class oo {
1536
1536
  return a = J(e.slice(n, o + 1)), Q(a, this.toBBox), a;
1537
1537
  i || (i = Math.ceil(Math.log(s) / Math.log(r)), r = Math.ceil(s / Math.pow(r, i - 1))), a = J([]), a.leaf = !1, a.height = i;
1538
1538
  const d = Math.ceil(s / r), c = d * Math.ceil(Math.sqrt(r));
1539
- oe(e, n, o, c, this.compareMinX);
1540
- for (let f = n; f <= o; f += c) {
1541
- const l = Math.min(f + c - 1, o);
1542
- oe(e, f, l, d, this.compareMinY);
1543
- for (let p = f; p <= l; p += d) {
1544
- const h = Math.min(p + d - 1, l);
1545
- a.children.push(this._build(e, p, h, i - 1));
1539
+ ie(e, n, o, c, this.compareMinX);
1540
+ for (let h = n; h <= o; h += c) {
1541
+ const l = Math.min(h + c - 1, o);
1542
+ ie(e, h, l, d, this.compareMinY);
1543
+ for (let g = h; g <= l; g += d) {
1544
+ const p = Math.min(g + d - 1, l);
1545
+ a.children.push(this._build(e, g, p, i - 1));
1546
1546
  }
1547
1547
  }
1548
1548
  return Q(a, this.toBBox), a;
@@ -1551,8 +1551,8 @@ class oo {
1551
1551
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1552
1552
  let s = 1 / 0, r = 1 / 0, a;
1553
1553
  for (let d = 0; d < n.children.length; d++) {
1554
- const c = n.children[d], f = Bt(c), l = ao(e, c) - f;
1555
- l < r ? (r = l, s = f < s ? f : s, a = c) : l === r && f < s && (s = f, a = c);
1554
+ const c = n.children[d], h = kt(c), l = ao(e, c) - h;
1555
+ l < r ? (r = l, s = h < s ? h : s, a = c) : l === r && h < s && (s = h, a = c);
1556
1556
  }
1557
1557
  n = a || n.children[0];
1558
1558
  }
@@ -1577,8 +1577,8 @@ class oo {
1577
1577
  _chooseSplitIndex(e, n, o) {
1578
1578
  let i, s = 1 / 0, r = 1 / 0;
1579
1579
  for (let a = n; a <= o - n; a++) {
1580
- const d = ot(e, 0, a, this.toBBox), c = ot(e, a, o, this.toBBox), f = co(d, c), l = Bt(d) + Bt(c);
1581
- f < s ? (s = f, i = a, r = l < r ? l : r) : f === s && l < r && (r = l, i = a);
1580
+ const d = ot(e, 0, a, this.toBBox), c = ot(e, a, o, this.toBBox), h = co(d, c), l = kt(d) + kt(c);
1581
+ h < s ? (s = h, i = a, r = l < r ? l : r) : h === s && l < r && (r = l, i = a);
1582
1582
  }
1583
1583
  return i || o - n;
1584
1584
  }
@@ -1593,12 +1593,12 @@ class oo {
1593
1593
  const s = this.toBBox, r = ot(e, 0, n, s), a = ot(e, o - n, o, s);
1594
1594
  let d = mt(r) + mt(a);
1595
1595
  for (let c = n; c < o - n; c++) {
1596
- const f = e.children[c];
1597
- it(r, e.leaf ? s(f) : f), d += mt(r);
1596
+ const h = e.children[c];
1597
+ it(r, e.leaf ? s(h) : h), d += mt(r);
1598
1598
  }
1599
1599
  for (let c = o - n - 1; c >= n; c--) {
1600
- const f = e.children[c];
1601
- it(a, e.leaf ? s(f) : f), d += mt(a);
1600
+ const h = e.children[c];
1601
+ it(a, e.leaf ? s(h) : h), d += mt(a);
1602
1602
  }
1603
1603
  return d;
1604
1604
  }
@@ -1637,7 +1637,7 @@ function so(t, e) {
1637
1637
  function ro(t, e) {
1638
1638
  return t.minY - e.minY;
1639
1639
  }
1640
- function Bt(t) {
1640
+ function kt(t) {
1641
1641
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1642
1642
  }
1643
1643
  function mt(t) {
@@ -1650,7 +1650,7 @@ function co(t, e) {
1650
1650
  const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), s = Math.min(t.maxY, e.maxY);
1651
1651
  return Math.max(0, i - n) * Math.max(0, s - o);
1652
1652
  }
1653
- function kt(t, e) {
1653
+ function It(t, e) {
1654
1654
  return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1655
1655
  }
1656
1656
  function yt(t, e) {
@@ -1667,12 +1667,12 @@ function J(t) {
1667
1667
  maxY: -1 / 0
1668
1668
  };
1669
1669
  }
1670
- function oe(t, e, n, o, i) {
1670
+ function ie(t, e, n, o, i) {
1671
1671
  const s = [e, n];
1672
1672
  for (; s.length; ) {
1673
1673
  if (n = s.pop(), e = s.pop(), n - e <= o) continue;
1674
1674
  const r = e + Math.ceil((n - e) / o / 2) * o;
1675
- ve(t, r, e, n, i), s.push(e, r, r, n);
1675
+ Ae(t, r, e, n, i), s.push(e, r, r, n);
1676
1676
  }
1677
1677
  }
1678
1678
  let lo = () => ({
@@ -1690,121 +1690,121 @@ let lo = () => ({
1690
1690
  }
1691
1691
  });
1692
1692
  const uo = (t, e) => {
1693
- const n = new oo(), o = /* @__PURE__ */ new Map(), i = lo(), s = (y, C) => {
1694
- const x = y.selector.flatMap((R) => {
1695
- const T = F([R]) ? R.range : le(R, e).range;
1696
- return Array.from(T.getClientRects());
1697
- }), L = Xe(x).map((R) => He(R, C));
1698
- return L.map((R) => {
1699
- const { x: T, y: S, width: g, height: w } = R;
1693
+ const n = new oo(), o = /* @__PURE__ */ new Map(), i = lo(), s = (b, S) => {
1694
+ const A = b.selector.flatMap((T) => {
1695
+ const O = F([T]) ? T.range : de(T, e).range;
1696
+ return Array.from(O.getClientRects());
1697
+ }), L = Xe(A).map((T) => He(T, S));
1698
+ return L.map((T) => {
1699
+ const { x: O, y: M, width: f, height: y } = T;
1700
1700
  return {
1701
- minX: T,
1702
- minY: S,
1703
- maxX: T + g,
1704
- maxY: S + w,
1701
+ minX: O,
1702
+ minY: M,
1703
+ maxX: O + f,
1704
+ maxY: M + y,
1705
1705
  annotation: {
1706
- id: y.annotation,
1706
+ id: b.annotation,
1707
1707
  rects: L
1708
1708
  }
1709
1709
  };
1710
1710
  });
1711
1711
  }, r = () => [...o.values()], a = () => {
1712
1712
  n.clear(), o.clear();
1713
- }, d = (y) => {
1714
- const C = s(y, e.getBoundingClientRect());
1715
- C.forEach((x) => n.insert(x)), o.set(y.annotation, C);
1716
- }, c = (y) => {
1717
- const C = o.get(y.annotation);
1718
- C && (C.forEach((x) => n.remove(x)), o.delete(y.annotation));
1719
- }, f = (y) => {
1720
- c(y), d(y);
1721
- }, l = (y, C = !0) => {
1722
- C && a();
1723
- const x = e.getBoundingClientRect(), L = y.map((T) => ({ target: T, rects: s(T, x) }));
1724
- L.forEach(({ target: T, rects: S }) => o.set(T.annotation, S));
1725
- const R = L.flatMap(({ rects: T }) => T);
1726
- n.load(R);
1727
- }, p = (y, C, x = !1) => {
1713
+ }, d = (b) => {
1714
+ const S = s(b, e.getBoundingClientRect());
1715
+ S.forEach((A) => n.insert(A)), o.set(b.annotation, S);
1716
+ }, c = (b) => {
1717
+ const S = o.get(b.annotation);
1718
+ S && (S.forEach((A) => n.remove(A)), o.delete(b.annotation));
1719
+ }, h = (b) => {
1720
+ c(b), d(b);
1721
+ }, l = (b, S = !0) => {
1722
+ S && a();
1723
+ const A = e.getBoundingClientRect(), L = b.map((O) => ({ target: O, rects: s(O, A) }));
1724
+ L.forEach(({ target: O, rects: M }) => o.set(O.annotation, M));
1725
+ const T = L.flatMap(({ rects: O }) => O);
1726
+ n.load(T);
1727
+ }, g = (b, S, A = !1) => {
1728
1728
  const L = n.search({
1729
- minX: y,
1730
- minY: C,
1731
- maxX: y,
1732
- maxY: C
1733
- }), R = (T) => T.annotation.rects.reduce((S, g) => S + g.width * g.height, 0);
1734
- return L.length > 0 ? (L.sort((T, S) => R(T) - R(S)), x ? L.map((T) => T.annotation.id) : [L[0].annotation.id]) : [];
1735
- }, h = (y) => {
1736
- const C = A(y);
1737
- if (C.length === 0)
1729
+ minX: b,
1730
+ minY: S,
1731
+ maxX: b,
1732
+ maxY: S
1733
+ }), T = (O) => O.annotation.rects.reduce((M, f) => M + f.width * f.height, 0);
1734
+ return L.length > 0 ? (L.sort((O, M) => T(O) - T(M)), A ? L.map((O) => O.annotation.id) : [L[0].annotation.id]) : [];
1735
+ }, p = (b) => {
1736
+ const S = v(b);
1737
+ if (S.length === 0)
1738
1738
  return;
1739
- let x = C[0].left, L = C[0].top, R = C[0].right, T = C[0].bottom;
1740
- for (let S = 1; S < C.length; S++) {
1741
- const g = C[S];
1742
- x = Math.min(x, g.left), L = Math.min(L, g.top), R = Math.max(R, g.right), T = Math.max(T, g.bottom);
1739
+ let A = S[0].left, L = S[0].top, T = S[0].right, O = S[0].bottom;
1740
+ for (let M = 1; M < S.length; M++) {
1741
+ const f = S[M];
1742
+ A = Math.min(A, f.left), L = Math.min(L, f.top), T = Math.max(T, f.right), O = Math.max(O, f.bottom);
1743
1743
  }
1744
- return new DOMRect(x, L, R - x, T - L);
1745
- }, A = (y) => {
1746
- const C = o.get(y);
1747
- return C ? C[0].annotation.rects : [];
1744
+ return new DOMRect(A, L, T - A, O - L);
1745
+ }, v = (b) => {
1746
+ const S = o.get(b);
1747
+ return S ? S[0].annotation.rects : [];
1748
1748
  };
1749
1749
  return {
1750
1750
  all: r,
1751
1751
  clear: a,
1752
- getAt: p,
1753
- getAnnotationBounds: h,
1754
- getAnnotationRects: A,
1755
- getIntersecting: (y, C, x, L) => {
1756
- const R = n.search({ minX: y, minY: C, maxX: x, maxY: L }), T = new Set(R.map((S) => S.annotation.id));
1757
- return Array.from(T).map((S) => ({
1758
- annotation: t.getAnnotation(S),
1759
- rects: A(S)
1760
- })).filter((S) => !!S.annotation);
1752
+ getAt: g,
1753
+ getAnnotationBounds: p,
1754
+ getAnnotationRects: v,
1755
+ getIntersecting: (b, S, A, L) => {
1756
+ const T = n.search({ minX: b, minY: S, maxX: A, maxY: L }), O = new Set(T.map((M) => M.annotation.id));
1757
+ return Array.from(O).map((M) => ({
1758
+ annotation: t.getAnnotation(M),
1759
+ rects: v(M)
1760
+ })).filter((M) => !!M.annotation);
1761
1761
  },
1762
1762
  insert: d,
1763
1763
  recalculate: () => {
1764
- l(t.all().map((y) => y.target), !0), i.emit("recalculate");
1764
+ l(t.all().map((b) => b.target), !0), i.emit("recalculate");
1765
1765
  },
1766
1766
  remove: c,
1767
1767
  set: l,
1768
1768
  size: () => n.all().length,
1769
- update: f,
1770
- on: (y, C) => i.on(y, C)
1769
+ update: h,
1770
+ on: (b, S) => i.on(b, S)
1771
1771
  };
1772
1772
  }, fo = (t, e) => {
1773
1773
  const n = _n(), o = uo(n, t), i = En(n);
1774
1774
  i.setUserSelectAction(e);
1775
- const s = An(n), r = Kn(), a = (u, y = k.LOCAL) => {
1776
- const C = At(u, t), x = F(C.target.selector);
1777
- return x && n.addAnnotation(C, y), x;
1778
- }, d = (u, y = !0, C = k.LOCAL) => {
1779
- const x = u.map((R) => At(R, t)), L = x.filter((R) => !F(R.target.selector));
1780
- return L.length > 0 ? (console.warn("Could not revive all targets for these annotations:", L), n.bulkAddAnnotation(x, y, C), L) : (n.bulkAddAnnotation(x, y, C), []);
1781
- }, c = (u, y = k.LOCAL) => {
1782
- const C = u.map((L) => At(L, t)), x = C.filter((L) => !F(L.target.selector));
1783
- return x.length > 0 && console.warn("Could not revive all targets for these annotations:", x), C.forEach((L) => {
1784
- n.getAnnotation(L.id) ? n.updateAnnotation(L, y) : n.addAnnotation(L, y);
1785
- }), x;
1786
- }, f = (u, y = k.LOCAL) => {
1787
- const C = wt(u, t);
1788
- n.updateTarget(C, y);
1789
- }, l = (u, y = k.LOCAL) => {
1790
- const C = u.map((x) => wt(x, t));
1791
- n.bulkUpdateTargets(C, y);
1792
- }, p = (u, y, C) => {
1793
- const x = o.getAt(u, y, !!C).map((R) => n.getAnnotation(R)), L = C ? x.filter(C) : x;
1775
+ const s = An(n), r = Kn(), a = (u, b = k.LOCAL) => {
1776
+ const S = xt(u, t), A = F(S.target.selector);
1777
+ return A && n.addAnnotation(S, b), A;
1778
+ }, d = (u, b = !0, S = k.LOCAL) => {
1779
+ const A = u.map((T) => xt(T, t)), L = A.filter((T) => !F(T.target.selector));
1780
+ return L.length > 0 ? (console.warn("Could not revive all targets for these annotations:", L), n.bulkAddAnnotation(A, b, S), L) : (n.bulkAddAnnotation(A, b, S), []);
1781
+ }, c = (u, b = k.LOCAL) => {
1782
+ const S = u.map((L) => xt(L, t)), A = S.filter((L) => !F(L.target.selector));
1783
+ return A.length > 0 && console.warn("Could not revive all targets for these annotations:", A), S.forEach((L) => {
1784
+ n.getAnnotation(L.id) ? n.updateAnnotation(L, b) : n.addAnnotation(L, b);
1785
+ }), A;
1786
+ }, h = (u, b = k.LOCAL) => {
1787
+ const S = wt(u, t);
1788
+ n.updateTarget(S, b);
1789
+ }, l = (u, b = k.LOCAL) => {
1790
+ const S = u.map((A) => wt(A, t));
1791
+ n.bulkUpdateTargets(S, b);
1792
+ }, g = (u, b, S) => {
1793
+ const A = o.getAt(u, b, !!S).map((T) => n.getAnnotation(T)), L = S ? A.filter(S) : A;
1794
1794
  return L.length > 0 ? L[0] : void 0;
1795
- }, h = (u, y, C, x = 5) => {
1795
+ }, p = (u, b, S, A = 5) => {
1796
1796
  const L = o.getAnnotationRects(u);
1797
1797
  if (L.length !== 0) {
1798
- if (y && C) {
1799
- const R = L.find(({ top: T, right: S, bottom: g, left: w }) => y >= w - x && y <= S + x && C >= T - x && C <= g + x);
1800
- if (R) return R;
1798
+ if (b && S) {
1799
+ const T = L.find(({ top: O, right: M, bottom: f, left: y }) => b >= y - A && b <= M + A && S >= O - A && S <= f + A);
1800
+ if (T) return T;
1801
1801
  }
1802
1802
  return o.getAnnotationBounds(u);
1803
1803
  }
1804
- }, A = (u, y, C, x) => o.getIntersecting(u, y, C, x), b = (u) => o.getAnnotationRects(u), E = () => o.recalculate(), m = (u) => o.on("recalculate", u);
1804
+ }, v = (u, b, S, A) => o.getIntersecting(u, b, S, A), w = (u) => o.getAnnotationRects(u), E = () => o.recalculate(), m = (u) => o.on("recalculate", u);
1805
1805
  return n.observe(({ changes: u }) => {
1806
- const y = (u.deleted || []).filter((L) => F(L.target.selector)), C = (u.created || []).filter((L) => F(L.target.selector)), x = (u.updated || []).filter((L) => F(L.newValue.target.selector));
1807
- (y == null ? void 0 : y.length) > 0 && y.forEach((L) => o.remove(L.target)), C.length > 0 && o.set(C.map((L) => L.target), !1), (x == null ? void 0 : x.length) > 0 && x.forEach(({ newValue: L }) => o.update(L.target));
1806
+ const b = (u.deleted || []).filter((L) => F(L.target.selector)), S = (u.created || []).filter((L) => F(L.target.selector)), A = (u.updated || []).filter((L) => F(L.newValue.target.selector));
1807
+ (b == null ? void 0 : b.length) > 0 && b.forEach((L) => o.remove(L.target)), S.length > 0 && o.set(S.map((L) => L.target), !1), (A == null ? void 0 : A.length) > 0 && A.forEach(({ newValue: L }) => o.update(L.target));
1808
1808
  }), {
1809
1809
  store: {
1810
1810
  ...n,
@@ -1812,13 +1812,13 @@ const uo = (t, e) => {
1812
1812
  bulkAddAnnotation: d,
1813
1813
  bulkUpdateTargets: l,
1814
1814
  bulkUpsertAnnotations: c,
1815
- getAnnotationBounds: h,
1816
- getAnnotationRects: b,
1817
- getIntersecting: A,
1818
- getAt: p,
1815
+ getAnnotationBounds: p,
1816
+ getAnnotationRects: w,
1817
+ getIntersecting: v,
1818
+ getAt: g,
1819
1819
  recalculatePositions: E,
1820
1820
  onRecalculatePositions: m,
1821
- updateTarget: f
1821
+ updateTarget: h
1822
1822
  },
1823
1823
  selection: i,
1824
1824
  hover: s,
@@ -1829,52 +1829,52 @@ const uo = (t, e) => {
1829
1829
  t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
1830
1830
  const e = t.getContext("2d");
1831
1831
  return e.scale(2, 2), e.translate(0.5, 0.5), t;
1832
- }, go = (t, e = {}) => {
1832
+ }, po = (t, e = {}) => {
1833
1833
  const n = ho(), o = n.getContext("2d");
1834
1834
  document.body.appendChild(n);
1835
- const i = /* @__PURE__ */ new Map(), s = (f) => Array.from(i.entries()).filter(([l, p]) => p.presenceKey === f.presenceKey).map(([l, p]) => l);
1836
- return t.on("selectionChange", (f, l) => {
1837
- s(f).forEach((h) => i.delete(h)), l && l.forEach((h) => i.set(h, f));
1835
+ const i = /* @__PURE__ */ new Map(), s = (h) => Array.from(i.entries()).filter(([l, g]) => g.presenceKey === h.presenceKey).map(([l, g]) => l);
1836
+ return t.on("selectionChange", (h, l) => {
1837
+ s(h).forEach((p) => i.delete(p)), l && l.forEach((p) => i.set(p, h));
1838
1838
  }), {
1839
1839
  clear: () => {
1840
- const { width: f, height: l } = n;
1841
- o.clearRect(-0.5, -0.5, f + 1, l + 1);
1840
+ const { width: h, height: l } = n;
1841
+ o.clearRect(-0.5, -0.5, h + 1, l + 1);
1842
1842
  },
1843
1843
  destroy: () => {
1844
1844
  n.remove();
1845
1845
  },
1846
- paint: (f, l, p) => {
1846
+ paint: (h, l, g) => {
1847
1847
  e.font && (o.font = e.font);
1848
- const h = i.get(f.annotation.id);
1849
- if (h) {
1850
- const { height: A } = f.rects[0], b = f.rects[0].x + l.left, E = f.rects[0].y + l.top;
1851
- o.fillStyle = h.appearance.color, o.fillRect(b - 2, E - 2.5, 2, A + 5);
1852
- const m = o.measureText(h.appearance.label), u = m.width + 6, y = m.actualBoundingBoxAscent + m.actualBoundingBoxDescent + 8, C = m.fontBoundingBoxAscent ? 8 : 6.5;
1853
- return o.fillRect(b - 2, E - 2.5 - y, u, y), o.fillStyle = "#fff", o.fillText(h.appearance.label, b + 1, E - C), {
1854
- fill: h.appearance.color,
1855
- fillOpacity: p ? 0.45 : 0.18
1848
+ const p = i.get(h.annotation.id);
1849
+ if (p) {
1850
+ const { height: v } = h.rects[0], w = h.rects[0].x + l.left, E = h.rects[0].y + l.top;
1851
+ o.fillStyle = p.appearance.color, o.fillRect(w - 2, E - 2.5, 2, v + 5);
1852
+ const m = o.measureText(p.appearance.label), u = m.width + 6, b = m.actualBoundingBoxAscent + m.actualBoundingBoxDescent + 8, S = m.fontBoundingBoxAscent ? 8 : 6.5;
1853
+ return o.fillRect(w - 2, E - 2.5 - b, u, b), o.fillStyle = "#fff", o.fillText(p.appearance.label, w + 1, E - S), {
1854
+ fill: p.appearance.color,
1855
+ fillOpacity: g ? 0.45 : 0.18
1856
1856
  };
1857
1857
  }
1858
1858
  },
1859
1859
  reset: () => {
1860
1860
  n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
1861
- const f = n.getContext("2d");
1862
- f.scale(2, 2), f.translate(0.5, 0.5);
1861
+ const h = n.getContext("2d");
1862
+ h.scale(2, 2), h.translate(0.5, 0.5);
1863
1863
  }
1864
1864
  };
1865
- }, It = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1866
- function Nt(t, e, n, o) {
1865
+ }, Nt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1866
+ function _t(t, e, n, o) {
1867
1867
  t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
1868
1868
  }
1869
1869
  function et(t, e, n, o) {
1870
1870
  t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
1871
1871
  }
1872
- function Ae(t, e) {
1872
+ function xe(t, e) {
1873
1873
  const n = e.slice(0, e.length - 1);
1874
1874
  for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
1875
1875
  return n;
1876
1876
  }
1877
- function xe(t) {
1877
+ function Ee(t) {
1878
1878
  typeof t != "string" && (t = ""), t = t.replace(/\s/g, "");
1879
1879
  const e = t.split(",");
1880
1880
  let n = e.lastIndexOf("");
@@ -1882,7 +1882,7 @@ function xe(t) {
1882
1882
  e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
1883
1883
  return e;
1884
1884
  }
1885
- function po(t, e) {
1885
+ function go(t, e) {
1886
1886
  const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
1887
1887
  let i = !0;
1888
1888
  for (let s = 0; s < n.length; s++)
@@ -1934,9 +1934,9 @@ const at = {
1934
1934
  ".": 190,
1935
1935
  "/": 191,
1936
1936
  "`": 192,
1937
- "-": It ? 173 : 189,
1938
- "=": It ? 61 : 187,
1939
- ";": It ? 59 : 186,
1937
+ "-": Nt ? 173 : 189,
1938
+ "=": Nt ? 61 : 187,
1939
+ ";": Nt ? 59 : 186,
1940
1940
  "'": 222,
1941
1941
  "[": 219,
1942
1942
  "]": 221,
@@ -1957,7 +1957,7 @@ const at = {
1957
1957
  "⌘": 91,
1958
1958
  cmd: 91,
1959
1959
  command: 91
1960
- }, Vt = {
1960
+ }, Kt = {
1961
1961
  16: "shiftKey",
1962
1962
  18: "altKey",
1963
1963
  17: "ctrlKey",
@@ -1974,13 +1974,13 @@ const at = {
1974
1974
  }, N = {};
1975
1975
  for (let t = 1; t < 20; t++)
1976
1976
  at["f".concat(t)] = 111 + t;
1977
- let I = [], rt = null, Ee = "all";
1977
+ let I = [], rt = null, Se = "all";
1978
1978
  const z = /* @__PURE__ */ new Map(), lt = (t) => at[t.toLowerCase()] || j[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), mo = (t) => Object.keys(at).find((e) => at[e] === t), yo = (t) => Object.keys(j).find((e) => j[e] === t);
1979
- function Se(t) {
1980
- Ee = t || "all";
1979
+ function Ce(t) {
1980
+ Se = t || "all";
1981
1981
  }
1982
1982
  function ct() {
1983
- return Ee || "all";
1983
+ return Se || "all";
1984
1984
  }
1985
1985
  function bo() {
1986
1986
  return I.slice(0);
@@ -2028,23 +2028,23 @@ function Eo(t, e) {
2028
2028
  let {
2029
2029
  element: a
2030
2030
  } = r;
2031
- return Pt(a);
2031
+ return jt(a);
2032
2032
  }) : o++;
2033
- ct() === t && Se(e || "all");
2033
+ ct() === t && Ce(e || "all");
2034
2034
  }
2035
2035
  function So(t) {
2036
2036
  let e = t.keyCode || t.which || t.charCode;
2037
2037
  const n = I.indexOf(e);
2038
2038
  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 V) {
2039
2039
  V[e] = !1;
2040
- for (const o in j) j[o] === e && ($[o] = !1);
2040
+ for (const o in j) j[o] === e && (P[o] = !1);
2041
2041
  }
2042
2042
  }
2043
- function Ce(t) {
2043
+ function Le(t) {
2044
2044
  if (typeof t > "u")
2045
2045
  Object.keys(N).forEach((i) => {
2046
2046
  Array.isArray(N[i]) && N[i].forEach((s) => bt(s)), delete N[i];
2047
- }), Pt(null);
2047
+ }), jt(null);
2048
2048
  else if (Array.isArray(t))
2049
2049
  t.forEach((i) => {
2050
2050
  i.key && bt(i);
@@ -2070,18 +2070,18 @@ const bt = (t) => {
2070
2070
  method: o,
2071
2071
  splitKey: i = "+"
2072
2072
  } = t;
2073
- xe(e).forEach((r) => {
2074
- const a = r.split(i), d = a.length, c = a[d - 1], f = c === "*" ? "*" : lt(c);
2075
- if (!N[f]) return;
2073
+ Ee(e).forEach((r) => {
2074
+ const a = r.split(i), d = a.length, c = a[d - 1], h = c === "*" ? "*" : lt(c);
2075
+ if (!N[h]) return;
2076
2076
  n || (n = ct());
2077
- const l = d > 1 ? Ae(j, a) : [], p = [];
2078
- N[f] = N[f].filter((h) => {
2079
- const b = (o ? h.method === o : !0) && h.scope === n && po(h.mods, l);
2080
- return b && p.push(h.element), !b;
2081
- }), p.forEach((h) => Pt(h));
2077
+ const l = d > 1 ? xe(j, a) : [], g = [];
2078
+ N[h] = N[h].filter((p) => {
2079
+ const w = (o ? p.method === o : !0) && p.scope === n && go(p.mods, l);
2080
+ return w && g.push(p.element), !w;
2081
+ }), g.forEach((p) => jt(p));
2082
2082
  });
2083
2083
  };
2084
- function ie(t, e, n, o) {
2084
+ function se(t, e, n, o) {
2085
2085
  if (e.element !== o)
2086
2086
  return;
2087
2087
  let i;
@@ -2092,44 +2092,44 @@ function ie(t, e, n, o) {
2092
2092
  (e.mods.length === 0 && !V[16] && !V[18] && !V[17] && !V[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)));
2093
2093
  }
2094
2094
  }
2095
- function se(t, e) {
2095
+ function re(t, e) {
2096
2096
  const n = N["*"];
2097
2097
  let o = t.keyCode || t.which || t.charCode;
2098
- if (!$.filter.call(this, t)) return;
2098
+ if (!P.filter.call(this, t)) return;
2099
2099
  if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((a) => {
2100
- const d = Vt[a];
2100
+ const d = Kt[a];
2101
2101
  t[a] && I.indexOf(d) === -1 ? I.push(d) : !t[a] && I.indexOf(d) > -1 ? I.splice(I.indexOf(d), 1) : a === "metaKey" && t[a] && I.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (I = I.slice(I.indexOf(d))));
2102
2102
  }), o in V) {
2103
2103
  V[o] = !0;
2104
2104
  for (const a in j)
2105
- j[a] === o && ($[a] = !0);
2105
+ j[a] === o && (P[a] = !0);
2106
2106
  if (!n) return;
2107
2107
  }
2108
2108
  for (const a in V)
2109
- Object.prototype.hasOwnProperty.call(V, a) && (V[a] = t[Vt[a]]);
2109
+ Object.prototype.hasOwnProperty.call(V, a) && (V[a] = t[Kt[a]]);
2110
2110
  t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), V[17] = !0, V[18] = !0);
2111
2111
  const i = ct();
2112
2112
  if (n)
2113
2113
  for (let a = 0; a < n.length; a++)
2114
- n[a].scope === i && (t.type === "keydown" && n[a].keydown || t.type === "keyup" && n[a].keyup) && ie(t, n[a], i, e);
2114
+ n[a].scope === i && (t.type === "keydown" && n[a].keydown || t.type === "keyup" && n[a].keyup) && se(t, n[a], i, e);
2115
2115
  if (!(o in N)) return;
2116
2116
  const s = N[o], r = s.length;
2117
2117
  for (let a = 0; a < r; a++)
2118
2118
  if ((t.type === "keydown" && s[a].keydown || t.type === "keyup" && s[a].keyup) && s[a].key) {
2119
2119
  const d = s[a], {
2120
2120
  splitKey: c
2121
- } = d, f = d.key.split(c), l = [];
2122
- for (let p = 0; p < f.length; p++)
2123
- l.push(lt(f[p]));
2124
- l.sort().join("") === I.sort().join("") && ie(t, d, i, e);
2121
+ } = d, h = d.key.split(c), l = [];
2122
+ for (let g = 0; g < h.length; g++)
2123
+ l.push(lt(h[g]));
2124
+ l.sort().join("") === I.sort().join("") && se(t, d, i, e);
2125
2125
  }
2126
2126
  }
2127
- function $(t, e, n) {
2127
+ function P(t, e, n) {
2128
2128
  I = [];
2129
- const o = xe(t);
2130
- let i = [], s = "all", r = document, a = 0, d = !1, c = !0, f = "+", l = !1, p = !1;
2131
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (r = e.element), e.keyup && (d = e.keyup), e.keydown !== void 0 && (c = e.keydown), e.capture !== void 0 && (l = e.capture), typeof e.splitKey == "string" && (f = e.splitKey), e.single === !0 && (p = !0)), typeof e == "string" && (s = e), p && Ce(t, s); a < o.length; a++)
2132
- t = o[a].split(f), i = [], t.length > 1 && (i = Ae(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in N || (N[t] = []), N[t].push({
2129
+ const o = Ee(t);
2130
+ let i = [], s = "all", r = document, a = 0, d = !1, c = !0, h = "+", l = !1, g = !1;
2131
+ for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (r = e.element), e.keyup && (d = e.keyup), e.keydown !== void 0 && (c = e.keydown), e.capture !== void 0 && (l = e.capture), typeof e.splitKey == "string" && (h = e.splitKey), e.single === !0 && (g = !0)), typeof e == "string" && (s = e), g && Le(t, s); a < o.length; a++)
2132
+ t = o[a].split(h), i = [], t.length > 1 && (i = xe(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : lt(t), t in N || (N[t] = []), N[t].push({
2133
2133
  keyup: d,
2134
2134
  keydown: c,
2135
2135
  scope: s,
@@ -2137,32 +2137,32 @@ function $(t, e, n) {
2137
2137
  shortcut: o[a],
2138
2138
  method: n,
2139
2139
  key: o[a],
2140
- splitKey: f,
2140
+ splitKey: h,
2141
2141
  element: r
2142
2142
  });
2143
2143
  if (typeof r < "u" && window) {
2144
2144
  if (!z.has(r)) {
2145
- const h = function() {
2146
- let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2147
- return se(b, r);
2148
- }, A = function() {
2149
- let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2150
- se(b, r), So(b);
2145
+ const p = function() {
2146
+ let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2147
+ return re(w, r);
2148
+ }, v = function() {
2149
+ let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2150
+ re(w, r), So(w);
2151
2151
  };
2152
2152
  z.set(r, {
2153
- keydownListener: h,
2154
- keyupListenr: A,
2153
+ keydownListener: p,
2154
+ keyupListenr: v,
2155
2155
  capture: l
2156
- }), Nt(r, "keydown", h, l), Nt(r, "keyup", A, l);
2156
+ }), _t(r, "keydown", p, l), _t(r, "keyup", v, l);
2157
2157
  }
2158
2158
  if (!rt) {
2159
- const h = () => {
2159
+ const p = () => {
2160
2160
  I = [];
2161
2161
  };
2162
2162
  rt = {
2163
- listener: h,
2163
+ listener: p,
2164
2164
  capture: l
2165
- }, Nt(window, "focus", h, l);
2165
+ }, _t(window, "focus", p, l);
2166
2166
  }
2167
2167
  }
2168
2168
  }
@@ -2174,7 +2174,7 @@ function Co(t) {
2174
2174
  });
2175
2175
  });
2176
2176
  }
2177
- function Pt(t) {
2177
+ function jt(t) {
2178
2178
  const e = Object.values(N).flat();
2179
2179
  if (e.findIndex((o) => {
2180
2180
  let {
@@ -2204,9 +2204,9 @@ function Pt(t) {
2204
2204
  et(window, "focus", i, s), rt = null;
2205
2205
  }
2206
2206
  }
2207
- const _t = {
2207
+ const Ut = {
2208
2208
  getPressedKeyString: wo,
2209
- setScope: Se,
2209
+ setScope: Ce,
2210
2210
  getScope: ct,
2211
2211
  deleteScope: Eo,
2212
2212
  getPressedKeyCodes: bo,
@@ -2214,157 +2214,174 @@ const _t = {
2214
2214
  isPressed: xo,
2215
2215
  filter: Ao,
2216
2216
  trigger: Co,
2217
- unbind: Ce,
2217
+ unbind: Le,
2218
2218
  keyMap: at,
2219
2219
  modifier: j,
2220
- modifierMap: Vt
2220
+ modifierMap: Kt
2221
2221
  };
2222
- for (const t in _t)
2223
- Object.prototype.hasOwnProperty.call(_t, t) && ($[t] = _t[t]);
2222
+ for (const t in Ut)
2223
+ Object.prototype.hasOwnProperty.call(Ut, t) && (P[t] = Ut[t]);
2224
2224
  if (typeof window < "u") {
2225
2225
  const t = window.hotkeys;
2226
- $.noConflict = (e) => (e && window.hotkeys === $ && (window.hotkeys = t), $), window.hotkeys = $;
2226
+ P.noConflict = (e) => (e && window.hotkeys === P && (window.hotkeys = t), P), window.hotkeys = P;
2227
2227
  }
2228
- const re = 300, Le = ["up", "down", "left", "right"], Oe = Ne ? "⌘+a" : "ctrl+a", Lo = [
2229
- ...Le.map((t) => `shift+${t}`),
2230
- Oe
2231
- ], Oo = (t, e, n) => {
2228
+ async function Lo(t, e, n = () => !1) {
2229
+ do {
2230
+ if (await t(), await n()) break;
2231
+ const o = e;
2232
+ await new Promise((i) => setTimeout(i, Math.max(0, o)));
2233
+ } while (!await n());
2234
+ }
2235
+ const ae = 300, Oe = ["up", "down", "left", "right"], Te = Ne ? "⌘+a" : "ctrl+a", Oo = [
2236
+ ...Oe.map((t) => `shift+${t}`),
2237
+ Te
2238
+ ], To = (t, e, n) => {
2232
2239
  const { store: o, selection: i } = e;
2233
2240
  let s;
2234
- const r = (S) => s = S;
2241
+ const r = (f) => s = f;
2235
2242
  let a;
2236
- const d = (S) => a = S;
2237
- let c, f, l, p = !1, h = !0;
2238
- const A = (S) => {
2239
- h = S, E.clear(), S || (c = void 0, l = void 0, p = !1);
2240
- }, b = (S) => {
2241
- h && (p = !1, f !== !1 && (c = nt(S.target) ? void 0 : {
2242
- annotation: me(),
2243
+ const d = (f) => a = f;
2244
+ let c, h, l, g = !1, p = !0;
2245
+ const v = (f) => {
2246
+ p = f, E.clear(), f || (c = void 0, l = void 0, g = !1);
2247
+ }, w = (f) => {
2248
+ p && (g = !1, h !== !1 && (c = nt(f.target) ? void 0 : {
2249
+ annotation: ye(),
2243
2250
  selector: [],
2244
2251
  creator: s,
2245
2252
  created: /* @__PURE__ */ new Date()
2246
2253
  }));
2247
- }, E = Yt((S) => {
2248
- if (!h) return;
2249
- const g = document.getSelection();
2250
- if (nt(g.anchorNode)) {
2254
+ }, E = Xt((f) => {
2255
+ if (!p) return;
2256
+ const y = document.getSelection();
2257
+ if (y != null && y.anchorNode && nt(y.anchorNode)) {
2251
2258
  c = void 0;
2252
2259
  return;
2253
2260
  }
2254
- const w = S.timeStamp - ((l == null ? void 0 : l.timeStamp) || S.timeStamp);
2255
- if ((l == null ? void 0 : l.type) === "pointerdown" && (w < 1e3 && !c || g.isCollapsed && w < re) && b(l || S), !c) return;
2256
- if (g.isCollapsed) {
2261
+ const x = f.timeStamp - ((l == null ? void 0 : l.timeStamp) || f.timeStamp);
2262
+ if ((l == null ? void 0 : l.type) === "pointerdown" && (x < 1e3 && !c || y.isCollapsed && x < ae) && w(l || f), !c) return;
2263
+ if (y.isCollapsed) {
2257
2264
  o.getAnnotation(c.annotation) && (i.clear(), o.deleteAnnotation(c.annotation));
2258
2265
  return;
2259
2266
  }
2260
- const v = g.getRangeAt(0), O = je(v, t);
2261
- if (Ve(O)) return;
2262
- const B = ke(O.cloneRange());
2263
- (B.length !== c.selector.length || B.some((K, Y) => {
2267
+ const C = y.getRangeAt(0), B = je(C, t);
2268
+ if (Ve(B)) return;
2269
+ const R = ke(B.cloneRange());
2270
+ (R.length !== c.selector.length || R.some((Y, At) => {
2264
2271
  var dt;
2265
- return K.toString() !== ((dt = c.selector[Y]) == null ? void 0 : dt.quote);
2272
+ return Y.toString() !== ((dt = c.selector[At]) == null ? void 0 : dt.quote);
2266
2273
  })) && (c = {
2267
2274
  ...c,
2268
- selector: B.map((K) => $e(K, t, n)),
2275
+ selector: R.map((Y) => Pe(Y, t, n)),
2269
2276
  updated: /* @__PURE__ */ new Date()
2270
2277
  }, o.getAnnotation(c.annotation) ? o.updateTarget(c, k.LOCAL) : i.clear());
2271
- }, 10), m = (S) => {
2272
- p || nt(S.target) || (l = xt(S), f = l.button === 0);
2278
+ }, 10), m = (f) => {
2279
+ g || nt(f.target) || (l = Et(f), h = l.button === 0);
2273
2280
  }, u = () => {
2274
2281
  o.getAnnotation(c.annotation) ? o.updateTarget(c) : o.addAnnotation({
2275
2282
  id: c.annotation,
2276
2283
  bodies: [],
2277
2284
  target: c
2278
2285
  });
2279
- }, y = (S) => {
2280
- if (p || nt(S.target) || !f) return;
2281
- const g = () => {
2282
- const { x: v, y: O } = t.getBoundingClientRect(), B = S.target instanceof Node && t.contains(S.target) && o.getAt(S.clientX - v, S.clientY - O, a);
2283
- if (B) {
2284
- const { selected: M } = i;
2285
- (M.length !== 1 || M[0].id !== B.id) && i.userSelect(B.id, S);
2286
+ }, b = async (f) => {
2287
+ if (g || nt(f.target) || !h) return;
2288
+ const y = () => {
2289
+ const { x: C, y: B } = t.getBoundingClientRect(), R = f.target instanceof Node && t.contains(f.target) && o.getAt(f.clientX - C, f.clientY - B, a);
2290
+ if (R) {
2291
+ const { selected: K } = i;
2292
+ (K.length !== 1 || K[0].id !== R.id) && i.userSelect(R.id, f);
2286
2293
  } else
2287
2294
  i.clear();
2288
- }, w = S.timeStamp - l.timeStamp;
2289
- setTimeout(() => {
2290
- const v = document.getSelection();
2291
- v != null && v.isCollapsed && w < re ? (c = void 0, g()) : c && c.selector.length > 0 && (i.clear(), u(), i.userSelect(c.annotation, xt(S)));
2292
- }, 1);
2293
- }, C = (S) => {
2294
- p = !0;
2295
- const g = document.getSelection();
2296
- g != null && g.isCollapsed || ((!c || c.selector.length === 0) && E(S), u(), i.userSelect(c.annotation, xt(S)));
2297
- }, x = (S) => {
2298
- h && S.key === "Shift" && c && (document.getSelection().isCollapsed || (i.clear(), u(), i.userSelect(c.annotation, ut(S))));
2299
- }, L = (S) => {
2300
- const g = () => setTimeout(() => {
2295
+ };
2296
+ if (f.timeStamp - l.timeStamp < ae) {
2297
+ await S();
2298
+ const C = document.getSelection();
2299
+ if (C != null && C.isCollapsed) {
2300
+ c = void 0, y();
2301
+ return;
2302
+ }
2303
+ }
2304
+ c && c.selector.length > 0 && (i.clear(), u(), i.userSelect(c.annotation, Et(f)));
2305
+ }, S = async () => {
2306
+ const f = document.getSelection();
2307
+ let y = !1, x = f == null ? void 0 : f.isCollapsed;
2308
+ const C = () => x || y, B = 2;
2309
+ return setTimeout(() => y = !0, 50), Lo(() => x = f == null ? void 0 : f.isCollapsed, B, C);
2310
+ }, A = (f) => {
2311
+ g = !0;
2312
+ const y = document.getSelection();
2313
+ y != null && y.isCollapsed || ((!c || c.selector.length === 0) && E(f), u(), i.userSelect(c.annotation, Et(f)));
2314
+ }, L = (f) => {
2315
+ p && f.key === "Shift" && c && (document.getSelection().isCollapsed || (i.clear(), u(), i.userSelect(c.annotation, ut(f))));
2316
+ }, T = (f) => {
2317
+ const y = () => setTimeout(() => {
2301
2318
  (c == null ? void 0 : c.selector.length) > 0 && (i.clear(), o.addAnnotation({
2302
2319
  id: c.annotation,
2303
2320
  bodies: [],
2304
2321
  target: c
2305
- }), i.userSelect(c.annotation, ut(S))), document.removeEventListener("selectionchange", g);
2322
+ }), i.userSelect(c.annotation, ut(f))), document.removeEventListener("selectionchange", y);
2306
2323
  }, 100);
2307
- document.addEventListener("selectionchange", g), b(S);
2324
+ document.addEventListener("selectionchange", y), w(f);
2308
2325
  };
2309
- $(Lo.join(","), { element: t, keydown: !0, keyup: !1 }, (S) => {
2310
- S.repeat || (l = ut(S));
2311
- }), $(Oe, { keydown: !0, keyup: !1 }, (S) => {
2312
- l = ut(S), L(S);
2326
+ P(Oo.join(","), { element: t, keydown: !0, keyup: !1 }, (f) => {
2327
+ f.repeat || (l = ut(f));
2328
+ }), P(Te, { keydown: !0, keyup: !1 }, (f) => {
2329
+ l = ut(f), T(f);
2313
2330
  });
2314
- const R = (S) => {
2315
- S.repeat || S.target !== t && S.target !== document.body || (c = void 0, i.clear());
2331
+ const O = (f) => {
2332
+ f.repeat || f.target !== t && f.target !== document.body || (c = void 0, i.clear());
2316
2333
  };
2317
- return $(Le.join(","), { keydown: !0, keyup: !1 }, R), document.addEventListener("pointerdown", m), document.addEventListener("pointerup", y), document.addEventListener("contextmenu", C), t.addEventListener("keyup", x), t.addEventListener("selectstart", b), document.addEventListener("selectionchange", E), {
2334
+ return P(Oe.join(","), { keydown: !0, keyup: !1 }, O), document.addEventListener("pointerdown", m), document.addEventListener("pointerup", b), document.addEventListener("contextmenu", A), t.addEventListener("keyup", L), t.addEventListener("selectstart", w), document.addEventListener("selectionchange", E), {
2318
2335
  destroy: () => {
2319
- c = void 0, f = void 0, l = void 0, p = !1, E.clear(), document.removeEventListener("pointerdown", m), document.removeEventListener("pointerup", y), document.removeEventListener("contextmenu", C), t.removeEventListener("keyup", x), t.removeEventListener("selectstart", b), document.removeEventListener("selectionchange", E), $.unbind();
2336
+ c = void 0, h = void 0, l = void 0, g = !1, E.clear(), document.removeEventListener("pointerdown", m), document.removeEventListener("pointerup", b), document.removeEventListener("contextmenu", A), t.removeEventListener("keyup", L), t.removeEventListener("selectstart", w), document.removeEventListener("selectionchange", E), P.unbind();
2320
2337
  },
2321
2338
  setFilter: d,
2322
2339
  setUser: r,
2323
- setAnnotatingEnabled: A
2340
+ setAnnotatingEnabled: v
2324
2341
  };
2325
- }, To = (t, e) => ({
2342
+ }, Ro = (t, e) => ({
2326
2343
  ...t,
2327
2344
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
2328
2345
  user: t.user || e.user
2329
- }), ae = "SPANS", Io = (t, e = {}) => {
2346
+ }), ce = "SPANS", No = (t, e = {}) => {
2330
2347
  Ie(t), _e(t);
2331
- const n = To(e, {
2348
+ const n = Ro(e, {
2332
2349
  annotatingEnabled: !0,
2333
2350
  user: Wn()
2334
2351
  }), o = fo(t, n.userSelectAction), { selection: i, viewport: s } = o, r = o.store, a = Vn(r), d = Yn(o, a, n.adapter);
2335
2352
  let c = n.user;
2336
- const f = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ae : n.renderer || ae, l = f === "SPANS" ? pn(t, o, s) : f === "CSS_HIGHLIGHTS" ? fn(t, o, s) : f === "CANVAS" ? en(t, o, s) : void 0;
2353
+ const h = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ce : n.renderer || ce, l = h === "SPANS" ? gn(t, o, s) : h === "CSS_HIGHLIGHTS" ? fn(t, o, s) : h === "CANVAS" ? en(t, o, s) : void 0;
2337
2354
  if (!l)
2338
- throw `Unknown renderer implementation: ${f}`;
2339
- console.debug(`Using ${f} renderer`), n.style && l.setStyle(n.style);
2340
- const p = Oo(t, o, n.offsetReferenceSelector);
2341
- p.setUser(c), p.setAnnotatingEnabled(n.annotatingEnabled);
2342
- const h = $n(o, a, n.adapter), A = () => c, b = (x) => {
2343
- p.setAnnotatingEnabled(
2344
- x === void 0 ? !0 : x
2355
+ throw `Unknown renderer implementation: ${h}`;
2356
+ console.debug(`Using ${h} renderer`), n.style && l.setStyle(n.style);
2357
+ const g = To(t, o, n.offsetReferenceSelector);
2358
+ g.setUser(c), g.setAnnotatingEnabled(n.annotatingEnabled);
2359
+ const p = Pn(o, a, n.adapter), v = () => c, w = (A) => {
2360
+ g.setAnnotatingEnabled(
2361
+ A === void 0 ? !0 : A
2345
2362
  );
2346
- }, E = (x) => {
2347
- l.setFilter(x), p.setFilter(x);
2348
- }, m = (x) => {
2349
- c = x, p.setUser(x);
2350
- }, u = (x) => {
2351
- x && (l.setPainter(go(x, n.presence)), x.on("selectionChange", () => l.redraw()));
2352
- }, y = (x) => {
2353
- x ? i.setSelected(x) : i.clear();
2363
+ }, E = (A) => {
2364
+ l.setFilter(A), g.setFilter(A);
2365
+ }, m = (A) => {
2366
+ c = A, g.setUser(A);
2367
+ }, u = (A) => {
2368
+ A && (l.setPainter(po(A, n.presence)), A.on("selectionChange", () => l.redraw()));
2369
+ }, b = (A) => {
2370
+ A ? i.setSelected(A) : i.clear();
2354
2371
  };
2355
2372
  return {
2356
- ...h,
2373
+ ...p,
2357
2374
  destroy: () => {
2358
- l.destroy(), p.destroy(), a.destroy();
2375
+ l.destroy(), g.destroy(), a.destroy();
2359
2376
  },
2360
2377
  element: t,
2361
- getUser: A,
2362
- setAnnotatingEnabled: b,
2378
+ getUser: v,
2379
+ setAnnotatingEnabled: w,
2363
2380
  setFilter: E,
2364
2381
  setStyle: l.setStyle.bind(l),
2365
2382
  redraw: l.redraw.bind(l),
2366
2383
  setUser: m,
2367
- setSelected: y,
2384
+ setSelected: b,
2368
2385
  setPresenceProvider: u,
2369
2386
  setVisible: l.setVisible.bind(l),
2370
2387
  on: d.on,
@@ -2376,27 +2393,27 @@ const re = 300, Le = ["up", "down", "left", "right"], Oe = Ne ? "⌘+a" : "ctrl+
2376
2393
  export {
2377
2394
  vt as DEFAULT_SELECTED_STYLE,
2378
2395
  W as DEFAULT_STYLE,
2379
- ce as NOT_ANNOTATABLE_CLASS,
2396
+ le as NOT_ANNOTATABLE_CLASS,
2380
2397
  Z as NOT_ANNOTATABLE_SELECTOR,
2381
2398
  k as Origin,
2382
2399
  xn as UserSelectAction,
2383
- ko as W3CTextFormat,
2400
+ Io as W3CTextFormat,
2384
2401
  Ie as cancelSingleClickEvents,
2385
2402
  ut as cloneKeyboardEvent,
2386
- xt as clonePointerEvent,
2387
- Bo as createBody,
2403
+ Et as clonePointerEvent,
2404
+ ko as createBody,
2388
2405
  en as createCanvasRenderer,
2389
2406
  fn as createHighlightsRenderer,
2390
- go as createPresencePainter,
2407
+ po as createPresencePainter,
2391
2408
  un as createRenderer,
2392
- Oo as createSelectionHandler,
2393
- pn as createSpansRenderer,
2394
- Io as createTextAnnotator,
2409
+ To as createSelectionHandler,
2410
+ gn as createSpansRenderer,
2411
+ No as createTextAnnotator,
2395
2412
  fo as createTextAnnotatorState,
2396
- Mo as denormalizeRectWithOffset,
2397
- To as fillDefaults,
2413
+ Bo as denormalizeRectWithOffset,
2414
+ Ro as fillDefaults,
2398
2415
  Ue as getQuoteContext,
2399
- Ut as getRangeAnnotatableContents,
2416
+ Dt as getRangeAnnotatableContents,
2400
2417
  Ne as isMac,
2401
2418
  nt as isNotAnnotatable,
2402
2419
  Me as isRangeAnnotatable,
@@ -2407,15 +2424,15 @@ export {
2407
2424
  Fe as paint,
2408
2425
  to as parseW3CTextAnnotation,
2409
2426
  _e as programmaticallyFocusable,
2410
- Pe as rangeContains,
2411
- $e as rangeToSelector,
2412
- At as reviveAnnotation,
2413
- le as reviveSelector,
2427
+ $e as rangeContains,
2428
+ Pe as rangeToSelector,
2429
+ xt as reviveAnnotation,
2430
+ de as reviveSelector,
2414
2431
  wt as reviveTarget,
2415
2432
  ze as scrollIntoView,
2416
2433
  eo as serializeW3CTextAnnotation,
2417
2434
  ke as splitAnnotatableRanges,
2418
- Ro as toDomRectList,
2435
+ Mo as toDomRectList,
2419
2436
  je as trimRangeToContainer,
2420
2437
  De as whitespaceOrEmptyRegex
2421
2438
  };