@recogito/text-annotator 3.0.0-rc.14 → 3.0.0-rc.15

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.
@@ -232,7 +232,7 @@ const Ot = (t) => {
232
232
  }, Z = {
233
233
  fill: "rgb(0, 128, 255)",
234
234
  fillOpacity: 0.18
235
- }, Dt = {
235
+ }, Yt = {
236
236
  fill: "rgb(0, 128, 255)",
237
237
  fillOpacity: 0.45
238
238
  }, re = () => {
@@ -256,9 +256,9 @@ const Ot = (t) => {
256
256
  };
257
257
  t.addEventListener("pointermove", b);
258
258
  const g = () => requestAnimationFrame(() => {
259
- const p = Ot(t), { top: A, left: x, minX: S, minY: B, maxX: L, maxY: I } = p, pt = a ? o.getIntersectingRects(S, B, L, I).filter(({ annotation: _ }) => a(_)) : o.getIntersectingRects(S, B, L, I), { width: zt, height: Wt } = y, qt = new Set(i.selected.map(({ id: _ }) => _));
259
+ const p = Ot(t), { top: A, left: x, minX: S, minY: B, maxX: N, maxY: I } = p, pt = a ? o.getIntersectingRects(S, B, N, I).filter(({ annotation: _ }) => a(_)) : o.getIntersectingRects(S, B, N, I), { width: zt, height: Wt } = y, qt = new Set(i.selected.map(({ id: _ }) => _));
260
260
  c.clearRect(-0.5, -0.5, zt + 1, Wt + 1), d && d.clear(), pt.forEach((_) => {
261
- const tt = qt.has(_.annotation.id), mt = r ? typeof r == "function" ? r(_.annotation, tt) : r : tt ? Dt : Z, bt = d && d.paint(_, p, tt) || mt, jt = _.rects.map(({ x: et, y: nt, width: ot, height: it }) => ({
261
+ const tt = qt.has(_.annotation.id), mt = r ? typeof r == "function" ? r(_.annotation, tt) : r : tt ? Yt : Z, bt = d && d.paint(_, p, tt) || mt, jt = _.rects.map(({ x: et, y: nt, width: ot, height: it }) => ({
262
262
  x: et + x,
263
263
  y: nt + A,
264
264
  width: ot,
@@ -291,13 +291,13 @@ const Ot = (t) => {
291
291
  setPainter: (p) => d = p
292
292
  };
293
293
  };
294
- var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
294
+ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
295
295
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
296
296
  }, M = function(t, e, n) {
297
297
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
298
298
  }, X = function(t, e, n) {
299
299
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
300
- }, Yt = function(t) {
300
+ }, Dt = function(t) {
301
301
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
302
302
  }, xt = function(t) {
303
303
  return { r: X(t.r, 0, 255), g: X(t.g, 0, 255), b: X(t.b, 0, 255), a: X(t.a) };
@@ -315,7 +315,7 @@ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
315
315
  var s = Math.floor(e), r = o * (1 - n), a = o * (1 - (e - s) * n), d = o * (1 - (1 - e + s) * n), u = s % 6;
316
316
  return { r: 255 * [o, a, r, r, d, o][u], g: 255 * [d, o, o, a, r, r][u], b: 255 * [r, r, d, o, o, a][u], a: i };
317
317
  }, At = function(t) {
318
- return { h: Yt(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
318
+ return { h: Dt(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
319
319
  }, Et = function(t) {
320
320
  return { h: M(t.h), s: M(t.s), l: M(t.l), a: M(t.a, 3) };
321
321
  }, St = function(t) {
@@ -338,19 +338,19 @@ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
338
338
  return St(i);
339
339
  }, "hsl"]], object: [[function(t) {
340
340
  var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
341
- return Y(e) && Y(n) && Y(o) ? xt({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
341
+ return D(e) && D(n) && D(o) ? xt({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
342
342
  }, "rgb"], [function(t) {
343
343
  var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
344
- if (!Y(e) || !Y(n) || !Y(o))
344
+ if (!D(e) || !D(n) || !D(o))
345
345
  return null;
346
346
  var r = At({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
347
347
  return St(r);
348
348
  }, "hsl"], [function(t) {
349
349
  var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
350
- if (!Y(e) || !Y(n) || !Y(o))
350
+ if (!D(e) || !D(n) || !D(o))
351
351
  return null;
352
352
  var r = function(a) {
353
- return { h: Yt(a.h), s: X(a.s, 0, 100), v: X(a.v, 0, 100), a: X(a.a) };
353
+ return { h: Dt(a.h), s: X(a.s, 0, 100), v: X(a.v, 0, 100), a: X(a.a) };
354
354
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
355
355
  return Vt(r);
356
356
  }, "hsv"]] }, Tt = function(t, e) {
@@ -399,33 +399,33 @@ var le = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
399
399
  return e = Ut(this.rgba), { h: M(e.h), s: M(e.s), v: M(e.v), a: M(e.a, 3) };
400
400
  var e;
401
401
  }, t.prototype.invert = function() {
402
- return D({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
402
+ return Y({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
403
403
  var e;
404
404
  }, t.prototype.saturate = function(e) {
405
- return e === void 0 && (e = 0.1), D(rt(this.rgba, e));
405
+ return e === void 0 && (e = 0.1), Y(rt(this.rgba, e));
406
406
  }, t.prototype.desaturate = function(e) {
407
- return e === void 0 && (e = 0.1), D(rt(this.rgba, -e));
407
+ return e === void 0 && (e = 0.1), Y(rt(this.rgba, -e));
408
408
  }, t.prototype.grayscale = function() {
409
- return D(rt(this.rgba, -1));
409
+ return Y(rt(this.rgba, -1));
410
410
  }, t.prototype.lighten = function(e) {
411
- return e === void 0 && (e = 0.1), D(Rt(this.rgba, e));
411
+ return e === void 0 && (e = 0.1), Y(Rt(this.rgba, e));
412
412
  }, t.prototype.darken = function(e) {
413
- return e === void 0 && (e = 0.1), D(Rt(this.rgba, -e));
413
+ return e === void 0 && (e = 0.1), Y(Rt(this.rgba, -e));
414
414
  }, t.prototype.rotate = function(e) {
415
415
  return e === void 0 && (e = 15), this.hue(this.hue() + e);
416
416
  }, t.prototype.alpha = function(e) {
417
- return typeof e == "number" ? D({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : M(this.rgba.a, 3);
417
+ return typeof e == "number" ? Y({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : M(this.rgba.a, 3);
418
418
  var n;
419
419
  }, t.prototype.hue = function(e) {
420
420
  var n = W(this.rgba);
421
- return typeof e == "number" ? D({ h: e, s: n.s, l: n.l, a: n.a }) : M(n.h);
421
+ return typeof e == "number" ? Y({ h: e, s: n.s, l: n.l, a: n.a }) : M(n.h);
422
422
  }, t.prototype.isEqual = function(e) {
423
- return this.toHex() === D(e).toHex();
423
+ return this.toHex() === Y(e).toHex();
424
424
  }, t;
425
- }(), D = function(t) {
425
+ }(), Y = function(t) {
426
426
  return t instanceof Bt ? t : new Bt(t);
427
427
  };
428
- const me = (t) => `background-color: ${D(t.fill || Z.fill).alpha(t.fillOpacity || Z.fillOpacity).toHex()};`, be = () => {
428
+ const me = (t) => `background-color: ${Y(t.fill || Z.fill).alpha(t.fillOpacity || Z.fillOpacity).toHex()};`, be = () => {
429
429
  const t = document.createElement("style");
430
430
  document.getElementsByTagName("head")[0].appendChild(t);
431
431
  let e, n = /* @__PURE__ */ new Set();
@@ -436,7 +436,7 @@ const me = (t) => `background-color: ${D(t.fill || Z.fill).alpha(t.fillOpacity |
436
436
  refresh: (r, a, d, u) => {
437
437
  e && e.clear();
438
438
  const y = new Set(r.map((v) => v.annotation.id)), c = new Set(d), b = Array.from(n).filter((v) => !y.has(v)), g = r.map((v) => {
439
- const C = c.has(v.annotation.id), w = u ? typeof u == "function" ? u(v.annotation, C) : u : C ? Dt : Z, l = e && e.paint(v, a, C) || w;
439
+ const C = c.has(v.annotation.id), w = u ? typeof u == "function" ? u(v.annotation, C) : u : C ? Yt : Z, l = e && e.paint(v, a, C) || w;
440
440
  return `::highlight(_${v.annotation.id}) { ${me(l)} }`;
441
441
  });
442
442
  t.innerHTML = g.join(`
@@ -456,8 +456,8 @@ const me = (t) => `background-color: ${D(t.fill || Z.fill).alpha(t.fillOpacity |
456
456
  };
457
457
  t.addEventListener("pointermove", c);
458
458
  const b = () => {
459
- const R = Ot(t), { minX: p, minY: A, maxX: x, maxY: S } = R, B = d ? o.getIntersectingRects(p, A, x, S).filter(({ annotation: I }) => d(I)) : o.getIntersectingRects(p, A, x, S), L = i.selected.map(({ id: I }) => I);
460
- u.refresh(B, R, L, a), setTimeout(() => y(B.map(({ annotation: I }) => I)), 1);
459
+ const R = Ot(t), { minX: p, minY: A, maxX: x, maxY: S } = R, B = d ? o.getIntersectingRects(p, A, x, S).filter(({ annotation: I }) => d(I)) : o.getIntersectingRects(p, A, x, S), N = i.selected.map(({ id: I }) => I);
460
+ u.refresh(B, R, N, a), setTimeout(() => y(B.map(({ annotation: I }) => I)), 1);
461
461
  }, g = (R) => {
462
462
  r = R, u.setPainter(R);
463
463
  }, v = (R) => {
@@ -484,75 +484,37 @@ const me = (t) => `background-color: ${D(t.fill || Z.fill).alpha(t.fillOpacity |
484
484
  setFilter: C,
485
485
  setPainter: g
486
486
  };
487
- }, ye = () => {
488
- const t = document.createElement("canvas");
489
- t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-highlight-layer presence";
490
- const e = t.getContext("2d");
491
- return e.scale(2, 2), e.translate(0.5, 0.5), t;
492
- }, we = (t, e, n = {}) => {
493
- const o = ye(), i = o.getContext("2d");
494
- t.appendChild(o);
495
- const s = /* @__PURE__ */ new Map(), r = (c) => Array.from(s.entries()).filter(([b, g]) => g.presenceKey === c.presenceKey).map(([b, g]) => b);
496
- return e.on("selectionChange", (c, b) => {
497
- r(c).forEach((v) => s.delete(v)), b && b.forEach((v) => s.set(v, c));
498
- }), {
499
- clear: () => {
500
- const { width: c, height: b } = o;
501
- i.clearRect(-0.5, -0.5, c + 1, b + 1);
502
- },
503
- destroy: () => {
504
- o.remove();
505
- },
506
- paint: (c, b, g) => {
507
- n.font && (i.font = n.font);
508
- const v = s.get(c.annotation.id);
509
- if (v) {
510
- const { height: C } = c.rects[0], w = c.rects[0].x + b.left, l = c.rects[0].y + b.top;
511
- i.fillStyle = v.appearance.color, i.fillRect(w - 2, l - 2.5, 2, C + 5);
512
- const h = i.measureText(v.appearance.label), m = h.width + 6, f = h.actualBoundingBoxAscent + h.actualBoundingBoxDescent + 8, E = h.fontBoundingBoxAscent ? 8 : 6.5;
513
- return i.fillRect(w - 2, l - 2.5 - f, m, f), i.fillStyle = "#fff", i.fillText(v.appearance.label, w + 1, l - E), {
514
- fill: v.appearance.color,
515
- fillOpacity: g ? 0.45 : 0.18
516
- };
517
- }
518
- },
519
- reset: () => {
520
- o.width = 2 * window.innerWidth, o.height = 2 * window.innerHeight;
521
- const c = o.getContext("2d");
522
- c.scale(2, 2), c.translate(0.5, 0.5);
523
- }
524
- };
525
487
  };
526
488
  let K;
527
- const xe = new Uint8Array(16);
528
- function Ae() {
489
+ const ye = new Uint8Array(16);
490
+ function we() {
529
491
  if (!K && (K = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !K))
530
492
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
531
- return K(xe);
493
+ return K(ye);
532
494
  }
533
495
  const O = [];
534
496
  for (let t = 0; t < 256; ++t)
535
497
  O.push((t + 256).toString(16).slice(1));
536
- function Ee(t, e = 0) {
498
+ function xe(t, e = 0) {
537
499
  return O[t[e + 0]] + O[t[e + 1]] + O[t[e + 2]] + O[t[e + 3]] + "-" + O[t[e + 4]] + O[t[e + 5]] + "-" + O[t[e + 6]] + O[t[e + 7]] + "-" + O[t[e + 8]] + O[t[e + 9]] + "-" + O[t[e + 10]] + O[t[e + 11]] + O[t[e + 12]] + O[t[e + 13]] + O[t[e + 14]] + O[t[e + 15]];
538
500
  }
539
- const Se = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Nt = {
540
- randomUUID: Se
501
+ const Ae = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Lt = {
502
+ randomUUID: Ae
541
503
  };
542
504
  function kt(t, e, n) {
543
- if (Nt.randomUUID && !e && !t)
544
- return Nt.randomUUID();
505
+ if (Lt.randomUUID && !e && !t)
506
+ return Lt.randomUUID();
545
507
  t = t || {};
546
- const o = t.random || (t.rng || Ae)();
508
+ const o = t.random || (t.rng || we)();
547
509
  if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, e) {
548
510
  n = n || 0;
549
511
  for (let i = 0; i < 16; ++i)
550
512
  e[n + i] = o[i];
551
513
  return e;
552
514
  }
553
- return Ee(o);
515
+ return xe(o);
554
516
  }
555
- var Lt = Object.prototype.hasOwnProperty;
517
+ var Nt = Object.prototype.hasOwnProperty;
556
518
  function V(t, e) {
557
519
  var n, o;
558
520
  if (t === e)
@@ -571,7 +533,7 @@ function V(t, e) {
571
533
  if (!n || typeof t == "object") {
572
534
  o = 0;
573
535
  for (n in t)
574
- if (Lt.call(t, n) && ++o && !Lt.call(e, n) || !(n in e) || !V(t[n], e[n]))
536
+ if (Nt.call(t, n) && ++o && !Nt.call(e, n) || !(n in e) || !V(t[n], e[n]))
575
537
  return !1;
576
538
  return Object.keys(e).length === o;
577
539
  }
@@ -580,7 +542,7 @@ function V(t, e) {
580
542
  }
581
543
  function ct() {
582
544
  }
583
- function Ce(t, e) {
545
+ function Ee(t, e) {
584
546
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
585
547
  }
586
548
  const k = [];
@@ -588,7 +550,7 @@ function gt(t, e = ct) {
588
550
  let n;
589
551
  const o = /* @__PURE__ */ new Set();
590
552
  function i(a) {
591
- if (Ce(t, a) && (t = a, n)) {
553
+ if (Ee(t, a) && (t = a, n)) {
592
554
  const d = !k.length;
593
555
  for (const u of o)
594
556
  u[1](), k.push(u, t);
@@ -610,7 +572,7 @@ function gt(t, e = ct) {
610
572
  }
611
573
  return { set: i, update: s, subscribe: r };
612
574
  }
613
- const Te = (t) => {
575
+ const Se = (t) => {
614
576
  const { subscribe: e, set: n } = gt();
615
577
  let o;
616
578
  return e((i) => o = i), t.observe(({ changes: i }) => {
@@ -626,7 +588,7 @@ const Te = (t) => {
626
588
  subscribe: e,
627
589
  set: n
628
590
  };
629
- }, lt = { selected: [] }, Re = (t, e = "EDIT") => {
591
+ }, lt = { selected: [] }, Ce = (t, e = "EDIT") => {
630
592
  const { subscribe: n, set: o } = gt(lt);
631
593
  let i = lt;
632
594
  n((c) => i = c);
@@ -641,7 +603,7 @@ const Te = (t) => {
641
603
  }, d = (c, b) => {
642
604
  const g = t.getAnnotation(c);
643
605
  if (g) {
644
- const v = Be(g, e);
606
+ const v = Te(g, e);
645
607
  o(v === "EDIT" ? { selected: [{ id: c, editable: !0 }], pointerEvent: b } : v === "SELECT" ? { selected: [{ id: c }], pointerEvent: b } : { selected: [], pointerEvent: b });
646
608
  } else
647
609
  console.warn("Invalid selection: " + c);
@@ -668,32 +630,32 @@ const Te = (t) => {
668
630
  setSelected: u,
669
631
  subscribe: n
670
632
  };
671
- }, Be = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT", Ne = [];
633
+ }, Te = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT", Re = [];
672
634
  for (let t = 0; t < 256; ++t)
673
- Ne.push((t + 256).toString(16).slice(1));
635
+ Re.push((t + 256).toString(16).slice(1));
674
636
  typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
675
- const Le = (t, e) => {
637
+ const Be = (t, e) => {
676
638
  const n = new Set(t.bodies.map((o) => o.id));
677
639
  return e.bodies.filter((o) => !n.has(o.id));
678
- }, Me = (t, e) => {
640
+ }, Le = (t, e) => {
679
641
  const n = new Set(e.bodies.map((o) => o.id));
680
642
  return t.bodies.filter((o) => !n.has(o.id));
681
- }, Oe = (t, e) => e.bodies.map((n) => {
643
+ }, Ne = (t, e) => e.bodies.map((n) => {
682
644
  const o = t.bodies.find((i) => i.id === n.id);
683
645
  return { newBody: n, oldBody: o && !V(o, n) ? o : void 0 };
684
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Ie = (t, e) => !V(t.target, e.target), Pt = (t, e) => {
685
- const n = Le(t, e), o = Me(t, e), i = Oe(t, e);
646
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Me = (t, e) => !V(t.target, e.target), Pt = (t, e) => {
647
+ const n = Be(t, e), o = Le(t, e), i = Ne(t, e);
686
648
  return {
687
649
  oldValue: t,
688
650
  newValue: e,
689
651
  bodiesCreated: n.length > 0 ? n : void 0,
690
652
  bodiesDeleted: o.length > 0 ? o : void 0,
691
653
  bodiesUpdated: i.length > 0 ? i : void 0,
692
- targetUpdated: Ie(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
654
+ targetUpdated: Me(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
693
655
  };
694
656
  };
695
- var N = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(N || {});
696
- const Xe = (t, e) => {
657
+ var L = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(L || {});
658
+ const Oe = (t, e) => {
697
659
  var n, o;
698
660
  const { changes: i, origin: s } = e;
699
661
  if (!(!t.options.origin || t.options.origin === s))
@@ -715,7 +677,7 @@ const Xe = (t, e) => {
715
677
  return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((a) => r.has(a));
716
678
  } else
717
679
  return !0;
718
- }, _e = (t, e) => {
680
+ }, Ie = (t, e) => {
719
681
  const n = new Set((t.created || []).map((c) => c.id)), o = new Set((t.updated || []).map(({ newValue: c }) => c.id)), i = new Set((e.created || []).map((c) => c.id)), s = new Set((e.deleted || []).map((c) => c.id)), r = new Set((e.updated || []).map(({ oldValue: c }) => c.id)), a = new Set((e.updated || []).filter(({ oldValue: c }) => n.has(c.id) || o.has(c.id)).map(({ oldValue: c }) => c.id)), d = [
720
682
  ...(t.created || []).filter((c) => !s.has(c.id)).map((c) => r.has(c.id) ? e.updated.find(({ oldValue: b }) => b.id === c.id).newValue : c),
721
683
  ...e.created || []
@@ -734,7 +696,7 @@ const Xe = (t, e) => {
734
696
  ...(e.updated || []).filter(({ oldValue: c }) => !a.has(c.id))
735
697
  ];
736
698
  return { created: d, deleted: u, updated: y };
737
- }, De = (t) => t.id !== void 0, Ye = () => {
699
+ }, Xe = (t) => t.id !== void 0, _e = () => {
738
700
  const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (p, A = {}) => n.push({ onChange: p, options: A }), i = (p) => {
739
701
  const A = n.findIndex((x) => x.onChange == p);
740
702
  A > -1 && n.splice(A, 1);
@@ -749,29 +711,29 @@ const Xe = (t, e) => {
749
711
  state: [...t.values()]
750
712
  };
751
713
  n.forEach((S) => {
752
- Xe(S, x) && S.onChange(x);
714
+ Oe(S, x) && S.onChange(x);
753
715
  });
754
- }, r = (p, A = N.LOCAL) => {
716
+ }, r = (p, A = L.LOCAL) => {
755
717
  if (t.get(p.id))
756
718
  throw Error(`Cannot add annotation ${p.id} - exists already`);
757
719
  t.set(p.id, p), p.bodies.forEach((x) => e.set(x.id, p.id)), s(A, { created: [p] });
758
720
  }, a = (p, A) => {
759
721
  const x = typeof p == "string" ? A : p, S = typeof p == "string" ? p : p.id, B = t.get(S);
760
722
  if (B) {
761
- const L = Pt(B, x);
762
- return S === x.id ? t.set(S, x) : (t.delete(S), t.set(x.id, x)), B.bodies.forEach((I) => e.delete(I.id)), x.bodies.forEach((I) => e.set(I.id, x.id)), L;
723
+ const N = Pt(B, x);
724
+ return S === x.id ? t.set(S, x) : (t.delete(S), t.set(x.id, x)), B.bodies.forEach((I) => e.delete(I.id)), x.bodies.forEach((I) => e.set(I.id, x.id)), N;
763
725
  } else
764
726
  console.warn(`Cannot update annotation ${S} - does not exist`);
765
- }, d = (p, A = N.LOCAL, x = N.LOCAL) => {
766
- const S = De(A) ? x : A, B = a(p, A);
727
+ }, d = (p, A = L.LOCAL, x = L.LOCAL) => {
728
+ const S = Xe(A) ? x : A, B = a(p, A);
767
729
  B && s(S, { updated: [B] });
768
- }, u = (p, A = N.LOCAL) => {
730
+ }, u = (p, A = L.LOCAL) => {
769
731
  const x = p.reduce((S, B) => {
770
- const L = a(B);
771
- return L ? [...S, L] : S;
732
+ const N = a(B);
733
+ return N ? [...S, N] : S;
772
734
  }, []);
773
735
  x.length > 0 && s(A, { updated: x });
774
- }, y = (p, A = N.LOCAL) => {
736
+ }, y = (p, A = L.LOCAL) => {
775
737
  const x = t.get(p.annotation);
776
738
  if (x) {
777
739
  const S = {
@@ -785,24 +747,24 @@ const Xe = (t, e) => {
785
747
  }] });
786
748
  } else
787
749
  console.warn(`Attempt to add body to missing annotation: ${p.annotation}`);
788
- }, c = () => [...t.values()], b = (p = N.LOCAL) => {
750
+ }, c = () => [...t.values()], b = (p = L.LOCAL) => {
789
751
  const A = [...t.values()];
790
752
  t.clear(), e.clear(), s(p, { deleted: A });
791
- }, g = (p, A = !0, x = N.LOCAL) => {
753
+ }, g = (p, A = !0, x = L.LOCAL) => {
792
754
  if (A) {
793
755
  const S = [...t.values()];
794
756
  t.clear(), e.clear(), p.forEach((B) => {
795
- t.set(B.id, B), B.bodies.forEach((L) => e.set(L.id, B.id));
757
+ t.set(B.id, B), B.bodies.forEach((N) => e.set(N.id, B.id));
796
758
  }), s(x, { created: p, deleted: S });
797
759
  } else {
798
- const S = p.reduce((B, L) => {
799
- const I = t.get(L.id);
760
+ const S = p.reduce((B, N) => {
761
+ const I = t.get(N.id);
800
762
  return I ? [...B, I] : B;
801
763
  }, []);
802
764
  if (S.length > 0)
803
765
  throw Error(`Bulk insert would overwrite the following annotations: ${S.map((B) => B.id).join(", ")}`);
804
766
  p.forEach((B) => {
805
- t.set(B.id, B), B.bodies.forEach((L) => e.set(L.id, B.id));
767
+ t.set(B.id, B), B.bodies.forEach((N) => e.set(N.id, B.id));
806
768
  }), s(x, { created: p });
807
769
  }
808
770
  }, v = (p) => {
@@ -810,16 +772,16 @@ const Xe = (t, e) => {
810
772
  if (x)
811
773
  return t.delete(A), x.bodies.forEach((S) => e.delete(S.id)), x;
812
774
  console.warn(`Attempt to delete missing annotation: ${A}`);
813
- }, C = (p, A = N.LOCAL) => {
775
+ }, C = (p, A = L.LOCAL) => {
814
776
  const x = v(p);
815
777
  x && s(A, { deleted: [x] });
816
- }, w = (p, A = N.LOCAL) => {
778
+ }, w = (p, A = L.LOCAL) => {
817
779
  const x = p.reduce((S, B) => {
818
- const L = v(B);
819
- return L ? [...S, L] : S;
780
+ const N = v(B);
781
+ return N ? [...S, N] : S;
820
782
  }, []);
821
783
  x.length > 0 && s(A, { deleted: x });
822
- }, l = (p, A = N.LOCAL) => {
784
+ }, l = (p, A = L.LOCAL) => {
823
785
  const x = t.get(p.annotation);
824
786
  if (x) {
825
787
  const S = x.bodies.find((B) => B.id === p.id);
@@ -827,7 +789,7 @@ const Xe = (t, e) => {
827
789
  e.delete(S.id);
828
790
  const B = {
829
791
  ...x,
830
- bodies: x.bodies.filter((L) => L.id !== p.id)
792
+ bodies: x.bodies.filter((N) => N.id !== p.id)
831
793
  };
832
794
  t.set(x.id, B), s(A, { updated: [{
833
795
  oldValue: x,
@@ -855,9 +817,9 @@ const Xe = (t, e) => {
855
817
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
856
818
  const x = t.get(p.annotation);
857
819
  if (x) {
858
- const S = x.bodies.find((L) => L.id === p.id), B = {
820
+ const S = x.bodies.find((N) => N.id === p.id), B = {
859
821
  ...x,
860
- bodies: x.bodies.map((L) => L.id === S.id ? A : L)
822
+ bodies: x.bodies.map((N) => N.id === S.id ? A : N)
861
823
  };
862
824
  return t.set(x.id, B), S.id !== A.id && (e.delete(S.id), e.set(A.id, B.id)), {
863
825
  oldValue: x,
@@ -866,10 +828,10 @@ const Xe = (t, e) => {
866
828
  };
867
829
  } else
868
830
  console.warn(`Attempt to add body to missing annotation ${p.annotation}`);
869
- }, E = (p, A, x = N.LOCAL) => {
831
+ }, E = (p, A, x = L.LOCAL) => {
870
832
  const S = f(p, A);
871
833
  S && s(x, { updated: [S] });
872
- }, T = (p, A = N.LOCAL) => {
834
+ }, T = (p, A = L.LOCAL) => {
873
835
  const x = p.map((S) => f({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
874
836
  s(A, { updated: x });
875
837
  }, R = (p) => {
@@ -901,7 +863,7 @@ const Xe = (t, e) => {
901
863
  bulkDeleteAnnotation: w,
902
864
  bulkUpdateAnnotation: u,
903
865
  bulkUpdateBodies: T,
904
- bulkUpdateTargets: (p, A = N.LOCAL) => {
866
+ bulkUpdateTargets: (p, A = L.LOCAL) => {
905
867
  const x = p.map((S) => R(S)).filter(Boolean);
906
868
  x.length > 0 && s(A, { updated: x });
907
869
  },
@@ -914,13 +876,13 @@ const Xe = (t, e) => {
914
876
  unobserve: i,
915
877
  updateAnnotation: d,
916
878
  updateBody: E,
917
- updateTarget: (p, A = N.LOCAL) => {
879
+ updateTarget: (p, A = L.LOCAL) => {
918
880
  const x = R(p);
919
881
  x && s(A, { updated: [x] });
920
882
  }
921
883
  };
922
884
  };
923
- let Ue = () => ({
885
+ let Ye = () => ({
924
886
  emit(t, ...e) {
925
887
  for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
926
888
  o[n](...e);
@@ -934,23 +896,23 @@ let Ue = () => ({
934
896
  };
935
897
  }
936
898
  });
937
- const Ve = 250, ke = (t) => {
938
- const e = Ue(), n = [];
899
+ const De = 250, Ue = (t) => {
900
+ const e = Ye(), n = [];
939
901
  let o = -1, i = !1, s = 0;
940
902
  const r = (g) => {
941
903
  if (!i) {
942
904
  const { changes: v } = g, C = performance.now();
943
- if (C - s > Ve)
905
+ if (C - s > De)
944
906
  n.splice(o + 1), n.push(v), o = n.length - 1;
945
907
  else {
946
908
  const w = n.length - 1;
947
- n[w] = _e(n[w], v);
909
+ n[w] = Ie(n[w], v);
948
910
  }
949
911
  s = C;
950
912
  }
951
913
  i = !1;
952
914
  };
953
- t.observe(r, { origin: N.LOCAL });
915
+ t.observe(r, { origin: L.LOCAL });
954
916
  const a = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), d = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), u = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: v }) => v)), y = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: v }) => v)), c = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), b = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
955
917
  return {
956
918
  canRedo: () => n.length - 1 > o,
@@ -972,13 +934,13 @@ const Ve = 250, ke = (t) => {
972
934
  }
973
935
  }
974
936
  };
975
- }, Pe = () => {
937
+ }, Ve = () => {
976
938
  const { subscribe: t, set: e } = gt([]);
977
939
  return {
978
940
  subscribe: t,
979
941
  set: e
980
942
  };
981
- }, He = (t, e, n, o) => {
943
+ }, ke = (t, e, n, o) => {
982
944
  const { store: i, selection: s, hover: r, viewport: a } = t, d = /* @__PURE__ */ new Map();
983
945
  let u = [], y, c;
984
946
  const b = (l, h) => {
@@ -1039,18 +1001,18 @@ const Ve = 250, ke = (t) => {
1039
1001
  const T = u.find((R) => R.id === f.id) || f;
1040
1002
  u = u.map((R) => R.id === f.id ? E : R), v("updateAnnotation", E, T);
1041
1003
  });
1042
- }, { origin: N.LOCAL }), i.observe((l) => {
1004
+ }, { origin: L.LOCAL }), i.observe((l) => {
1043
1005
  if (u) {
1044
1006
  const h = new Set(u.map((f) => f.id)), m = (l.changes.updated || []).filter(({ newValue: f }) => h.has(f.id)).map(({ newValue: f }) => f);
1045
1007
  m.length > 0 && (u = u.map((f) => m.find((T) => T.id === f.id) || f));
1046
1008
  }
1047
- }, { origin: N.REMOTE });
1009
+ }, { origin: L.REMOTE });
1048
1010
  const w = (l) => (h) => {
1049
1011
  const { created: m, deleted: f, updated: E } = h;
1050
1012
  (m || []).forEach((T) => v("createAnnotation", T)), (f || []).forEach((T) => v("deleteAnnotation", T)), l ? (E || []).forEach((T) => v("updateAnnotation", T.oldValue, T.newValue)) : (E || []).forEach((T) => v("updateAnnotation", T.newValue, T.oldValue));
1051
1013
  };
1052
1014
  return e.on("undo", w(!0)), e.on("redo", w(!1)), { on: b, off: g, emit: v };
1053
- }, $e = (t) => (e) => e.reduce((n, o) => {
1015
+ }, Pe = (t) => (e) => e.reduce((n, o) => {
1054
1016
  const { parsed: i, error: s } = t.parse(o);
1055
1017
  return s ? {
1056
1018
  parsed: n.parsed,
@@ -1061,13 +1023,13 @@ const Ve = 250, ke = (t) => {
1061
1023
  } : {
1062
1024
  ...n
1063
1025
  };
1064
- }, { parsed: [], failed: [] }), Fe = (t, e, n) => {
1026
+ }, { parsed: [], failed: [] }), He = (t, e, n) => {
1065
1027
  const { store: o, selection: i } = t, s = (w) => {
1066
1028
  if (n) {
1067
1029
  const { parsed: l, error: h } = n.parse(w);
1068
- l ? o.addAnnotation(l, N.REMOTE) : console.error(h);
1030
+ l ? o.addAnnotation(l, L.REMOTE) : console.error(h);
1069
1031
  } else
1070
- o.addAnnotation(w, N.REMOTE);
1032
+ o.addAnnotation(w, L.REMOTE);
1071
1033
  }, r = () => i.clear(), a = () => o.clear(), d = (w) => {
1072
1034
  const l = o.getAnnotation(w);
1073
1035
  return n && l ? n.serialize(l) : l;
@@ -1087,10 +1049,10 @@ const Ve = 250, ke = (t) => {
1087
1049
  }
1088
1050
  }, g = (w) => {
1089
1051
  if (n) {
1090
- const { parsed: l, failed: h } = $e(n)(w);
1091
- h.length > 0 && console.warn(`Discarded ${h.length} invalid annotations`, h), o.bulkAddAnnotation(l, !0, N.REMOTE);
1052
+ const { parsed: l, failed: h } = Pe(n)(w);
1053
+ h.length > 0 && console.warn(`Discarded ${h.length} invalid annotations`, h), o.bulkAddAnnotation(l, !0, L.REMOTE);
1092
1054
  } else
1093
- o.bulkAddAnnotation(w, !0, N.REMOTE);
1055
+ o.bulkAddAnnotation(w, !0, L.REMOTE);
1094
1056
  }, v = (w) => {
1095
1057
  w ? i.setSelected(w) : i.clear();
1096
1058
  }, C = (w) => {
@@ -1120,7 +1082,7 @@ const Ve = 250, ke = (t) => {
1120
1082
  updateAnnotation: C
1121
1083
  };
1122
1084
  };
1123
- let ze = (t) => crypto.getRandomValues(new Uint8Array(t)), We = (t, e, n) => {
1085
+ let $e = (t) => crypto.getRandomValues(new Uint8Array(t)), Fe = (t, e, n) => {
1124
1086
  let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
1125
1087
  return (s = e) => {
1126
1088
  let r = "";
@@ -1131,8 +1093,8 @@ let ze = (t) => crypto.getRandomValues(new Uint8Array(t)), We = (t, e, n) => {
1131
1093
  return r;
1132
1094
  }
1133
1095
  };
1134
- }, qe = (t, e = 21) => We(t, e, ze), je = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce((e, n) => (n &= 63, n < 36 ? e += n.toString(36) : n < 62 ? e += (n - 26).toString(36).toUpperCase() : n > 62 ? e += "-" : e += "_", e), "");
1135
- const Ke = () => ({ isGuest: !0, id: qe("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Qe = (t) => {
1096
+ }, ze = (t, e = 21) => Fe(t, e, $e), We = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce((e, n) => (n &= 63, n < 36 ? e += n.toString(36) : n < 62 ? e += (n - 26).toString(36).toUpperCase() : n > 62 ? e += "-" : e += "_", e), "");
1097
+ const qe = () => ({ isGuest: !0, id: ze("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), je = (t) => {
1136
1098
  const e = JSON.stringify(t);
1137
1099
  let n = 0;
1138
1100
  for (let o = 0, i = e.length; o < i; o++) {
@@ -1140,10 +1102,10 @@ const Ke = () => ({ isGuest: !0, id: qe("1234567890abcdefghijklmnopqrstuvwxyzABC
1140
1102
  n = (n << 5) - n + s, n |= 0;
1141
1103
  }
1142
1104
  return `${n}`;
1143
- }, Ht = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Ge = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1105
+ }, Ht = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Ke = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1144
1106
  const { id: o, type: i, purpose: s, value: r, created: a, creator: d, ...u } = n;
1145
1107
  return {
1146
- id: o || `temp-${Qe(n)}`,
1108
+ id: o || `temp-${je(n)}`,
1147
1109
  annotation: e,
1148
1110
  type: i,
1149
1111
  purpose: s,
@@ -1152,16 +1114,16 @@ const Ke = () => ({ isGuest: !0, id: qe("1234567890abcdefghijklmnopqrstuvwxyzABC
1152
1114
  creator: Ht(d),
1153
1115
  ...u
1154
1116
  };
1155
- }), Je = (t) => t.map((e) => {
1117
+ }), Qe = (t) => t.map((e) => {
1156
1118
  var n, o;
1157
1119
  const i = { ...e };
1158
1120
  return delete i.annotation, (n = i.id) != null && n.startsWith("temp-") && delete i.id, { ...i, created: (o = i.created) == null ? void 0 : o.toISOString() };
1159
1121
  });
1160
- je();
1122
+ We();
1161
1123
  const vn = (t, e) => ({
1162
- parse: (n) => en(n),
1163
- serialize: (n) => nn(n, t, e)
1164
- }), Ze = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, tn = (t, e) => {
1124
+ parse: (n) => Ze(n),
1125
+ serialize: (n) => tn(n, t, e)
1126
+ }), Ge = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, Je = (t, e) => {
1165
1127
  const {
1166
1128
  id: n,
1167
1129
  creator: o,
@@ -1187,7 +1149,7 @@ const vn = (t, e) => ({
1187
1149
  }
1188
1150
  return b;
1189
1151
  }, {});
1190
- if (Ze(c))
1152
+ if (Ge(c))
1191
1153
  d.selector.push(c);
1192
1154
  else {
1193
1155
  const b = [
@@ -1198,14 +1160,14 @@ const vn = (t, e) => ({
1198
1160
  }
1199
1161
  }
1200
1162
  return { parsed: d };
1201
- }, en = (t, e) => {
1163
+ }, Ze = (t, e) => {
1202
1164
  const n = t.id || kt(), {
1203
1165
  creator: o,
1204
1166
  created: i,
1205
1167
  modified: s,
1206
1168
  body: r,
1207
1169
  ...a
1208
- } = t, d = Ge(r, n), u = tn(t);
1170
+ } = t, d = Ke(r, n), u = Je(t);
1209
1171
  return "error" in u ? { error: u.error } : {
1210
1172
  parsed: {
1211
1173
  ...a,
@@ -1214,7 +1176,7 @@ const vn = (t, e) => ({
1214
1176
  target: u.parsed
1215
1177
  }
1216
1178
  };
1217
- }, nn = (t, e, n) => {
1179
+ }, tn = (t, e, n) => {
1218
1180
  const { bodies: o, target: i, ...s } = t, {
1219
1181
  selector: r,
1220
1182
  creator: a,
@@ -1243,15 +1205,15 @@ const vn = (t, e) => ({
1243
1205
  "@context": "http://www.w3.org/ns/anno.jsonld",
1244
1206
  id: t.id,
1245
1207
  type: "Annotation",
1246
- body: Je(t.bodies),
1208
+ body: Qe(t.bodies),
1247
1209
  creator: a,
1248
1210
  created: d == null ? void 0 : d.toISOString(),
1249
1211
  modified: u == null ? void 0 : u.toISOString(),
1250
1212
  target: c
1251
1213
  };
1252
1214
  };
1253
- function on(t, e, n, o, i) {
1254
- $t(t, e, n || 0, o || t.length - 1, i || sn);
1215
+ function en(t, e, n, o, i) {
1216
+ $t(t, e, n || 0, o || t.length - 1, i || nn);
1255
1217
  }
1256
1218
  function $t(t, e, n, o, i) {
1257
1219
  for (; o > n; ) {
@@ -1273,10 +1235,10 @@ function $(t, e, n) {
1273
1235
  var o = t[e];
1274
1236
  t[e] = t[n], t[n] = o;
1275
1237
  }
1276
- function sn(t, e) {
1238
+ function nn(t, e) {
1277
1239
  return t < e ? -1 : t > e ? 1 : 0;
1278
1240
  }
1279
- class rn {
1241
+ class on {
1280
1242
  constructor(e = 9) {
1281
1243
  this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
1282
1244
  }
@@ -1352,7 +1314,7 @@ class rn {
1352
1314
  let a, d, u;
1353
1315
  for (; o || s.length; ) {
1354
1316
  if (o || (o = s.pop(), d = s[s.length - 1], a = r.pop(), u = !0), o.leaf) {
1355
- const y = an(e, o.children, n);
1317
+ const y = sn(e, o.children, n);
1356
1318
  if (y !== -1)
1357
1319
  return o.children.splice(y, 1), s.push(o), this._condense(s), this;
1358
1320
  }
@@ -1403,7 +1365,7 @@ class rn {
1403
1365
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1404
1366
  let s = 1 / 0, r = 1 / 0, a;
1405
1367
  for (let d = 0; d < n.children.length; d++) {
1406
- const u = n.children[d], y = dt(u), c = dn(e, u) - y;
1368
+ const u = n.children[d], y = dt(u), c = cn(e, u) - y;
1407
1369
  c < r ? (r = c, s = y < s ? y : s, a = u) : c === r && y < s && (s = y, a = u);
1408
1370
  }
1409
1371
  n = a || n.children[0];
@@ -1429,14 +1391,14 @@ class rn {
1429
1391
  _chooseSplitIndex(e, n, o) {
1430
1392
  let i, s = 1 / 0, r = 1 / 0;
1431
1393
  for (let a = n; a <= o - n; a++) {
1432
- const d = F(e, 0, a, this.toBBox), u = F(e, a, o, this.toBBox), y = un(d, u), c = dt(d) + dt(u);
1394
+ const d = F(e, 0, a, this.toBBox), u = F(e, a, o, this.toBBox), y = ln(d, u), c = dt(d) + dt(u);
1433
1395
  y < s ? (s = y, i = a, r = c < r ? c : r) : y === s && c < r && (r = c, i = a);
1434
1396
  }
1435
1397
  return i || o - n;
1436
1398
  }
1437
1399
  // sorts node children by the best axis for split
1438
1400
  _chooseSplitAxis(e, n, o) {
1439
- const i = e.leaf ? this.compareMinX : cn, s = e.leaf ? this.compareMinY : ln, r = this._allDistMargin(e, n, o, i), a = this._allDistMargin(e, n, o, s);
1401
+ const i = e.leaf ? this.compareMinX : rn, s = e.leaf ? this.compareMinY : an, r = this._allDistMargin(e, n, o, i), a = this._allDistMargin(e, n, o, s);
1440
1402
  r < a && e.children.sort(i);
1441
1403
  }
1442
1404
  // total margin of all possible split distributions where each node is at least m full
@@ -1463,7 +1425,7 @@ class rn {
1463
1425
  e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : P(e[n], this.toBBox);
1464
1426
  }
1465
1427
  }
1466
- function an(t, e, n) {
1428
+ function sn(t, e, n) {
1467
1429
  if (!n)
1468
1430
  return e.indexOf(t);
1469
1431
  for (let o = 0; o < e.length; o++)
@@ -1485,10 +1447,10 @@ function F(t, e, n, o, i) {
1485
1447
  function z(t, e) {
1486
1448
  return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
1487
1449
  }
1488
- function cn(t, e) {
1450
+ function rn(t, e) {
1489
1451
  return t.minX - e.minX;
1490
1452
  }
1491
- function ln(t, e) {
1453
+ function an(t, e) {
1492
1454
  return t.minY - e.minY;
1493
1455
  }
1494
1456
  function dt(t) {
@@ -1497,10 +1459,10 @@ function dt(t) {
1497
1459
  function Q(t) {
1498
1460
  return t.maxX - t.minX + (t.maxY - t.minY);
1499
1461
  }
1500
- function dn(t, e) {
1462
+ function cn(t, e) {
1501
1463
  return (Math.max(e.maxX, t.maxX) - Math.min(e.minX, t.minX)) * (Math.max(e.maxY, t.maxY) - Math.min(e.minY, t.minY));
1502
1464
  }
1503
- function un(t, e) {
1465
+ function ln(t, e) {
1504
1466
  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);
1505
1467
  return Math.max(0, i - n) * Math.max(0, s - o);
1506
1468
  }
@@ -1527,11 +1489,11 @@ function Mt(t, e, n, o, i) {
1527
1489
  if (n = s.pop(), e = s.pop(), n - e <= o)
1528
1490
  continue;
1529
1491
  const r = e + Math.ceil((n - e) / o / 2) * o;
1530
- on(t, r, e, n, i), s.push(e, r, r, n);
1492
+ en(t, r, e, n, i), s.push(e, r, r, n);
1531
1493
  }
1532
1494
  }
1533
- const hn = (t, e) => {
1534
- const n = new rn(), o = /* @__PURE__ */ new Map(), i = (l) => {
1495
+ const dn = (t, e) => {
1496
+ const n = new on(), o = /* @__PURE__ */ new Map(), i = (l) => {
1535
1497
  const h = e.getBoundingClientRect(), m = l.selector.flatMap((E) => {
1536
1498
  const R = E.range instanceof Range && !E.range.collapsed && E.range.startContainer.nodeType === Node.TEXT_NODE && E.range.endContainer.nodeType === Node.TEXT_NODE ? E.range : _t(E, e).range;
1537
1499
  return Array.from(R.getClientRects());
@@ -1601,17 +1563,17 @@ const hn = (t, e) => {
1601
1563
  size: () => n.all().length,
1602
1564
  update: u
1603
1565
  };
1604
- }, fn = (t, e) => {
1605
- const n = Ye(), o = hn(n, t), i = Re(n, e), s = Te(n), r = Pe(), a = (w, l = N.LOCAL) => {
1566
+ }, un = (t, e) => {
1567
+ const n = _e(), o = dn(n, t), i = Ce(n, e), s = Se(n), r = Ve(), a = (w, l = L.LOCAL) => {
1606
1568
  const h = wt(w, t), m = U(h.target.selector);
1607
1569
  return m && n.addAnnotation(h, l), m;
1608
- }, d = (w, l = !0, h = N.LOCAL) => {
1570
+ }, d = (w, l = !0, h = L.LOCAL) => {
1609
1571
  const m = w.map((E) => wt(E, t)), f = m.filter((E) => !U(E.target.selector));
1610
1572
  return f.length > 0 ? (console.warn("Could not revive all targets for these annotations:", f), n.bulkAddAnnotation(m, l, h), f) : (n.bulkAddAnnotation(m, l, h), []);
1611
- }, u = (w, l = N.LOCAL) => {
1573
+ }, u = (w, l = L.LOCAL) => {
1612
1574
  const h = J(w, t);
1613
1575
  n.updateTarget(h, l);
1614
- }, y = (w, l = N.LOCAL) => {
1576
+ }, y = (w, l = L.LOCAL) => {
1615
1577
  const h = w.map((m) => J(m, t));
1616
1578
  n.bulkUpdateTargets(h, l);
1617
1579
  }, c = (w, l) => {
@@ -1657,6 +1619,44 @@ const hn = (t, e) => {
1657
1619
  hover: s,
1658
1620
  viewport: r
1659
1621
  };
1622
+ }, hn = () => {
1623
+ const t = document.createElement("canvas");
1624
+ t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-highlight-layer presence";
1625
+ const e = t.getContext("2d");
1626
+ return e.scale(2, 2), e.translate(0.5, 0.5), t;
1627
+ }, fn = (t, e, n = {}) => {
1628
+ const o = hn(), i = o.getContext("2d");
1629
+ t.appendChild(o);
1630
+ const s = /* @__PURE__ */ new Map(), r = (c) => Array.from(s.entries()).filter(([b, g]) => g.presenceKey === c.presenceKey).map(([b, g]) => b);
1631
+ return e.on("selectionChange", (c, b) => {
1632
+ r(c).forEach((v) => s.delete(v)), b && b.forEach((v) => s.set(v, c));
1633
+ }), {
1634
+ clear: () => {
1635
+ const { width: c, height: b } = o;
1636
+ i.clearRect(-0.5, -0.5, c + 1, b + 1);
1637
+ },
1638
+ destroy: () => {
1639
+ o.remove();
1640
+ },
1641
+ paint: (c, b, g) => {
1642
+ n.font && (i.font = n.font);
1643
+ const v = s.get(c.annotation.id);
1644
+ if (v) {
1645
+ const { height: C } = c.rects[0], w = c.rects[0].x + b.left, l = c.rects[0].y + b.top;
1646
+ i.fillStyle = v.appearance.color, i.fillRect(w - 2, l - 2.5, 2, C + 5);
1647
+ const h = i.measureText(v.appearance.label), m = h.width + 6, f = h.actualBoundingBoxAscent + h.actualBoundingBoxDescent + 8, E = h.fontBoundingBoxAscent ? 8 : 6.5;
1648
+ return i.fillRect(w - 2, l - 2.5 - f, m, f), i.fillStyle = "#fff", i.fillText(v.appearance.label, w + 1, l - E), {
1649
+ fill: v.appearance.color,
1650
+ fillOpacity: g ? 0.45 : 0.18
1651
+ };
1652
+ }
1653
+ },
1654
+ reset: () => {
1655
+ o.width = 2 * window.innerWidth, o.height = 2 * window.innerHeight;
1656
+ const c = o.getContext("2d");
1657
+ c.scale(2, 2), c.translate(0.5, 0.5);
1658
+ }
1659
+ };
1660
1660
  }, Ft = (t) => {
1661
1661
  if (t === null)
1662
1662
  return document.scrollingElement;
@@ -1697,7 +1697,7 @@ const hn = (t, e) => {
1697
1697
  t.addEventListener("selectstart", y);
1698
1698
  const c = ft((C) => {
1699
1699
  const w = document.getSelection();
1700
- if (C.timeStamp - u.timeStamp < 1e3 && !r && y(u), w.isCollapsed || !d || !r)
1700
+ if (C.timeStamp - ((u == null ? void 0 : u.timeStamp) || C.timeStamp) < 1e3 && !r && y(u), w.isCollapsed || !d || !r)
1701
1701
  return;
1702
1702
  const l = w.getRangeAt(0), h = se(l.cloneRange()), m = Gt(h);
1703
1703
  (m.length !== r.selector.length || m.some((E, T) => {
@@ -1706,7 +1706,7 @@ const hn = (t, e) => {
1706
1706
  })) && (r = {
1707
1707
  ...r,
1708
1708
  selector: m.map((E) => ie(E, t, n))
1709
- }, o.getAnnotation(r.annotation) ? o.updateTarget(r, N.LOCAL) : (o.addAnnotation({
1709
+ }, o.getAnnotation(r.annotation) ? o.updateTarget(r, L.LOCAL) : (o.addAnnotation({
1710
1710
  id: r.annotation,
1711
1711
  bodies: [],
1712
1712
  target: r
@@ -1739,20 +1739,20 @@ const hn = (t, e) => {
1739
1739
  setUser: a
1740
1740
  };
1741
1741
  }, yn = (t, e = {}) => {
1742
- t.addEventListener("click", (f) => f.target.nodeName !== "A" && f.preventDefault());
1743
- const n = fn(t, e.pointerAction), { selection: o, viewport: i } = n, s = n.store, r = ke(s), a = He(
1742
+ t.addEventListener("click", (f) => !f.target.closest("a") && f.preventDefault());
1743
+ const n = un(t, e.pointerAction), { selection: o, viewport: i } = n, s = n.store, r = Ue(s), a = ke(
1744
1744
  n,
1745
1745
  r,
1746
1746
  e.adapter
1747
1747
  );
1748
- let d = Ke();
1748
+ let d = qe();
1749
1749
  const u = e.experimentalCSSRenderer && !!CSS.highlights;
1750
1750
  u && console.log("Using experimental CSS Custom Highlight API renderer");
1751
1751
  const y = u ? ve(t, n, i) : ce(t, n, i);
1752
1752
  e.style && y.setDrawingStyle(e.style);
1753
1753
  const c = pn(t, n, e.offsetReferenceSelector);
1754
1754
  return c.setUser(d), {
1755
- ...Fe(n, r, e.adapter),
1755
+ ...He(n, r, e.adapter),
1756
1756
  destroy: () => {
1757
1757
  y.destroy(), c.destroy(), r.destroy();
1758
1758
  },
@@ -1767,7 +1767,7 @@ const hn = (t, e) => {
1767
1767
  f ? o.setSelected(f) : o.clear();
1768
1768
  },
1769
1769
  setPresenceProvider: (f) => {
1770
- f && (y.setPainter(we(t, f, e.presence)), f.on("selectionChange", () => y.refresh()));
1770
+ f && (y.setPainter(fn(t, f, e.presence)), f.on("selectionChange", () => y.refresh()));
1771
1771
  },
1772
1772
  on: a.on,
1773
1773
  off: a.off,
@@ -1777,13 +1777,12 @@ const hn = (t, e) => {
1777
1777
  };
1778
1778
  export {
1779
1779
  q as NOT_ANNTOTATABLE_SELECTOR,
1780
- N as Origin,
1780
+ L as Origin,
1781
1781
  vn as W3CTextFormat,
1782
1782
  ve as createCSSHighlightRenderer,
1783
1783
  ce as createCanvasHighlightRenderer,
1784
- we as createPresencePainter,
1785
1784
  yn as createTextAnnotator,
1786
- fn as createTextAnnotatorState,
1785
+ un as createTextAnnotatorState,
1787
1786
  ft as debounce,
1788
1787
  mn as getAnnotatableFragment,
1789
1788
  bn as getClientRectsPonyfill,
@@ -1791,12 +1790,12 @@ export {
1791
1790
  ht as getRangeAnnotatableContents,
1792
1791
  U as isRevived,
1793
1792
  oe as mergeClientRects,
1794
- en as parseW3CTextAnnotation,
1793
+ Ze as parseW3CTextAnnotation,
1795
1794
  ie as rangeToSelector,
1796
1795
  wt as reviveAnnotation,
1797
1796
  _t as reviveSelector,
1798
1797
  J as reviveTarget,
1799
- nn as serializeW3CTextAnnotation,
1798
+ tn as serializeW3CTextAnnotation,
1800
1799
  Gt as splitAnnotatableRanges,
1801
1800
  se as trimRange
1802
1801
  };