@soomo/text-annotator 3.4.0-staging.1 → 3.4.0-staging.2

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.
@@ -2,9 +2,9 @@ import z from "debounce";
2
2
  import { colord as ot } from "colord";
3
3
  import { dequal as ut } from "dequal/lite";
4
4
  import { v4 as st } from "uuid";
5
- import { serializeW3CBodies as ft, parseW3CBodies as gt, parseW3CUser as mt, createStore as pt, createSelectionState as ht, createHoverState as yt, createViewportState as bt, Origin as U, createAnonymousGuest as St, createUndoStack as Ct, createLifecycleObserver as Et, createBaseAnnotator as vt } from "@annotorious/core";
5
+ import { serializeW3CBodies as ft, parseW3CBodies as gt, parseW3CUser as mt, createStore as pt, createSelectionState as ht, createHoverState as yt, createViewportState as bt, Origin as U, createAnonymousGuest as St, createUndoStack as Ct, createLifecycleObserver as Et, createBaseAnnotator as wt } from "@annotorious/core";
6
6
  import { Origin as ke, UserSelectAction as Ne, createBody as Be } from "@annotorious/core";
7
- import wt from "rbush";
7
+ import vt from "rbush";
8
8
  import { createNanoEvents as At } from "nanoevents";
9
9
  import V from "hotkeys-js";
10
10
  import { poll as xt } from "poll";
@@ -98,12 +98,12 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
98
98
  s = !0;
99
99
  break;
100
100
  } else if (i === "block-contains" || i === "block-is-contained") {
101
- e.width < r.width && (o = o.map((a) => a === r ? e : a)), s = !0;
101
+ e.width < r.width && (o = o.map((a) => a === r ? e : a)), e.width === r.width && e.height < r.width && (o = o.map((a) => a === r ? e : a)), s = !0;
102
102
  break;
103
103
  }
104
104
  }
105
105
  return s ? o : [...o, e];
106
- }, []), we = (t) => ({
106
+ }, []), ve = (t) => ({
107
107
  length: t.length,
108
108
  item: (n) => t[n],
109
109
  [Symbol.iterator]: function* () {
@@ -279,7 +279,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
279
279
  S = C, p();
280
280
  }, R = (C) => {
281
281
  a = C, p();
282
- }, w = (C) => {
282
+ }, v = (C) => {
283
283
  u = C, p(!1);
284
284
  }, T = () => p();
285
285
  s.observe(T);
@@ -291,16 +291,16 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
291
291
  window.addEventListener("resize", g);
292
292
  const d = new ResizeObserver(g);
293
293
  d.observe(t);
294
- const h = { attributes: !0, childList: !0, subtree: !0 }, v = new MutationObserver(z((C) => {
294
+ const h = { attributes: !0, childList: !0, subtree: !0 }, w = new MutationObserver(z((C) => {
295
295
  C.every((B) => B.target === t || t.contains(B.target)) || p(!0);
296
296
  }, 150));
297
- return v.observe(document.body, h), {
297
+ return w.observe(document.body, h), {
298
298
  destroy: () => {
299
- t.removeEventListener("pointermove", f), o.destroy(), s.unobserve(T), E(), m(), document.removeEventListener("scroll", l), g.clear(), window.removeEventListener("resize", g), d.disconnect(), v.disconnect();
299
+ t.removeEventListener("pointermove", f), o.destroy(), s.unobserve(T), E(), m(), document.removeEventListener("scroll", l), g.clear(), window.removeEventListener("resize", g), d.disconnect(), w.disconnect();
300
300
  },
301
301
  redraw: p,
302
302
  setStyle: R,
303
- setFilter: w,
303
+ setFilter: v,
304
304
  setPainter: c,
305
305
  setVisible: o.setVisible
306
306
  };
@@ -322,19 +322,19 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
322
322
  return m.getTime() - l.getTime();
323
323
  }).forEach((T) => {
324
324
  var g;
325
- const E = S ? typeof S == "function" ? S(T.annotation, T.state) : S : (g = T.state) != null && g.selected ? j : H, m = y && y.paint(T, u) || E, l = T.rects.map(({ x: d, y: h, width: v, height: A }) => ({
325
+ const E = S ? typeof S == "function" ? S(T.annotation, T.state) : S : (g = T.state) != null && g.selected ? j : H, m = y && y.paint(T, u) || E, l = T.rects.map(({ x: d, y: h, width: w, height: A }) => ({
326
326
  x: d + R,
327
327
  y: h + c,
328
- width: v,
328
+ width: w,
329
329
  height: A
330
330
  }));
331
331
  if (e.fillStyle = m.fill, e.globalAlpha = m.fillOpacity || 1, l.forEach(
332
- ({ x: d, y: h, width: v, height: A }) => e.fillRect(d, h, v, A)
332
+ ({ x: d, y: h, width: w, height: A }) => e.fillRect(d, h, w, A)
333
333
  ), m.underlineColor) {
334
334
  e.globalAlpha = 1, e.strokeStyle = m.underlineColor, e.lineWidth = m.underlineThickness ?? 1;
335
335
  const d = m.underlineOffset ?? 0;
336
- l.forEach(({ x: h, y: v, width: A, height: C }) => {
337
- e.beginPath(), e.moveTo(h, v + C + d), e.lineTo(h + A, v + C + d), e.stroke();
336
+ l.forEach(({ x: h, y: w, width: A, height: C }) => {
337
+ e.beginPath(), e.moveTo(h, w + C + d), e.lineTo(h + A, w + C + d), e.stroke();
338
338
  });
339
339
  }
340
340
  });
@@ -396,15 +396,15 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
396
396
  redraw: (i, a, u, S, y) => {
397
397
  const p = !(ut(e, i) && y);
398
398
  if (!S && !p) return;
399
- p && (n.innerHTML = ""), [...i].sort((R, w) => {
400
- const { annotation: { target: { created: T } } } = R, { annotation: { target: { created: E } } } = w;
399
+ p && (n.innerHTML = ""), [...i].sort((R, v) => {
400
+ const { annotation: { target: { created: T } } } = R, { annotation: { target: { created: E } } } = v;
401
401
  return T && E ? T.getTime() - E.getTime() : 0;
402
402
  }).forEach((R) => {
403
- R.rects.map((w) => {
404
- const T = Jt(w, i), E = Wt(R, a, u, S, T);
403
+ R.rects.map((v) => {
404
+ const T = Jt(v, i), E = Wt(R, a, u, S, T);
405
405
  if (p) {
406
406
  const m = document.createElement("span");
407
- m.className = "r6o-annotation", m.dataset.annotation = R.annotation.id, m.style.left = `${w.x}px`, m.style.top = `${w.y}px`, m.style.width = `${w.width}px`, m.style.height = `${w.height}px`, m.style.backgroundColor = ot((E == null ? void 0 : E.fill) || H.fill).alpha((E == null ? void 0 : E.fillOpacity) === void 0 ? H.fillOpacity : E.fillOpacity).toHex(), E.underlineStyle && (m.style.borderStyle = E.underlineStyle), E.underlineColor && (m.style.borderColor = E.underlineColor), E.underlineThickness && (m.style.borderBottomWidth = `${E.underlineThickness}px`), E.underlineOffset && (m.style.paddingBottom = `${E.underlineOffset}px`), n.appendChild(m);
407
+ m.className = "r6o-annotation", m.dataset.annotation = R.annotation.id, m.style.left = `${v.x}px`, m.style.top = `${v.y}px`, m.style.width = `${v.width}px`, m.style.height = `${v.height}px`, m.style.backgroundColor = ot((E == null ? void 0 : E.fill) || H.fill).alpha((E == null ? void 0 : E.fillOpacity) === void 0 ? H.fillOpacity : E.fillOpacity).toHex(), E.underlineStyle && (m.style.borderStyle = E.underlineStyle), E.underlineColor && (m.style.borderColor = E.underlineColor), E.underlineThickness && (m.style.borderBottomWidth = `${E.underlineThickness}px`), E.underlineOffset && (m.style.paddingBottom = `${E.underlineOffset}px`), n.appendChild(m);
408
408
  }
409
409
  });
410
410
  }), e = i;
@@ -489,7 +489,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
489
489
  updated: S,
490
490
  ...y
491
491
  } = s, f = i.map((p) => {
492
- const { id: c, quote: R, start: w, end: T, range: E } = p, m = {
492
+ const { id: c, quote: R, start: v, end: T, range: E } = p, m = {
493
493
  type: "TextQuoteSelector",
494
494
  exact: R
495
495
  };
@@ -499,7 +499,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
499
499
  }
500
500
  const l = {
501
501
  type: "TextPositionSelector",
502
- start: w,
502
+ start: v,
503
503
  end: T
504
504
  };
505
505
  return {
@@ -523,13 +523,13 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
523
523
  target: f
524
524
  };
525
525
  }, ie = (t, n) => {
526
- const e = new wt(), o = /* @__PURE__ */ new Map(), s = At(), r = (l, g) => {
527
- const d = l.selector.flatMap((v) => {
528
- const A = M([v]) ? v.range : it(v, n).range;
526
+ const e = new vt(), o = /* @__PURE__ */ new Map(), s = At(), r = (l, g) => {
527
+ const d = l.selector.flatMap((w) => {
528
+ const A = M([w]) ? w.range : it(w, n).range;
529
529
  return Array.from(A.getClientRects());
530
- }), h = Dt(d).map((v) => _t(v, g));
531
- return h.map((v) => {
532
- const { x: A, y: C, width: L, height: B } = v;
530
+ }), h = Dt(d).map((w) => _t(w, g));
531
+ return h.map((w) => {
532
+ const { x: A, y: C, width: L, height: B } = w;
533
533
  return {
534
534
  minX: A,
535
535
  minY: C,
@@ -557,26 +557,26 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
557
557
  h.forEach(({ target: A, rects: C }) => {
558
558
  C.length > 0 && o.set(A.annotation, C);
559
559
  });
560
- const v = h.flatMap(({ rects: A }) => A);
561
- e.load(v);
560
+ const w = h.flatMap(({ rects: A }) => A);
561
+ e.load(w);
562
562
  }, p = (l, g, d = !1) => {
563
563
  const h = e.search({
564
564
  minX: l,
565
565
  minY: g,
566
566
  maxX: l,
567
567
  maxY: g
568
- }), v = (A) => A.annotation.rects.reduce((C, L) => C + L.width * L.height, 0);
569
- return h.length > 0 ? (h.sort((A, C) => v(A) - v(C)), d ? h.map((A) => A.annotation.id) : [h[0].annotation.id]) : [];
568
+ }), w = (A) => A.annotation.rects.reduce((C, L) => C + L.width * L.height, 0);
569
+ return h.length > 0 ? (h.sort((A, C) => w(A) - w(C)), d ? h.map((A) => A.annotation.id) : [h[0].annotation.id]) : [];
570
570
  }, c = (l) => {
571
571
  const g = R(l);
572
572
  if (g.length === 0)
573
573
  return;
574
- let d = g[0].left, h = g[0].top, v = g[0].right, A = g[0].bottom;
574
+ let d = g[0].left, h = g[0].top, w = g[0].right, A = g[0].bottom;
575
575
  for (let C = 1; C < g.length; C++) {
576
576
  const L = g[C];
577
- d = Math.min(d, L.left), h = Math.min(h, L.top), v = Math.max(v, L.right), A = Math.max(A, L.bottom);
577
+ d = Math.min(d, L.left), h = Math.min(h, L.top), w = Math.max(w, L.right), A = Math.max(A, L.bottom);
578
578
  }
579
- return new DOMRect(d, h, v - d, A - h);
579
+ return new DOMRect(d, h, w - d, A - h);
580
580
  }, R = (l) => {
581
581
  const g = o.get(l);
582
582
  return g ? g[0].annotation.rects : [];
@@ -588,7 +588,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
588
588
  getAnnotationBounds: c,
589
589
  getAnnotationRects: R,
590
590
  getIntersecting: (l, g, d, h) => {
591
- const v = e.search({ minX: l, minY: g, maxX: d, maxY: h }), A = new Set(v.map((C) => C.annotation.id));
591
+ const w = e.search({ minX: l, minY: g, maxX: d, maxY: h }), A = new Set(w.map((C) => C.annotation.id));
592
592
  return Array.from(A).map((C) => ({
593
593
  annotation: t.getAnnotation(C),
594
594
  rects: R(C)
@@ -609,7 +609,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
609
609
  const g = G(m, t), d = M(g.target.selector);
610
610
  return d && e.addAnnotation(g, l), d;
611
611
  }, u = (m, l = !0, g = U.LOCAL) => {
612
- const d = m.map((v) => G(v, t)), h = d.filter((v) => !M(v.target.selector));
612
+ const d = m.map((w) => G(w, t)), h = d.filter((w) => !M(w.target.selector));
613
613
  return e.bulkAddAnnotations(d, l, g), h;
614
614
  }, S = (m, l = U.LOCAL) => {
615
615
  const g = m.map((h) => G(h, t)), d = g.filter((h) => !M(h.target.selector));
@@ -624,11 +624,11 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
624
624
  e.bulkUpdateTargets(g, l);
625
625
  };
626
626
  function p(m, l, g, d) {
627
- const h = g || !!d, v = o.getAt(m, l, h).map((C) => e.getAnnotation(C)), A = d ? v.filter(d) : v;
627
+ const h = g || !!d, w = o.getAt(m, l, h).map((C) => e.getAnnotation(C)), A = d ? w.filter(d) : w;
628
628
  if (A.length !== 0)
629
629
  return g ? A : A[0];
630
630
  }
631
- const c = (m) => o.getAnnotationRects(m).length > 0 ? o.getAnnotationBounds(m) : void 0, R = (m, l, g, d) => o.getIntersecting(m, l, g, d), w = (m) => o.getAnnotationRects(m), T = () => o.recalculate(), E = (m) => o.on("recalculate", m);
631
+ const c = (m) => o.getAnnotationRects(m).length > 0 ? o.getAnnotationBounds(m) : void 0, R = (m, l, g, d) => o.getIntersecting(m, l, g, d), v = (m) => o.getAnnotationRects(m), T = () => o.recalculate(), E = (m) => o.on("recalculate", m);
632
632
  return e.observe(({ changes: m }) => {
633
633
  const l = (m.deleted || []).filter((h) => M(h.target.selector)), g = (m.created || []).filter((h) => M(h.target.selector)), d = (m.updated || []).filter((h) => M(h.newValue.target.selector));
634
634
  (l == null ? void 0 : l.length) > 0 && l.forEach((h) => o.remove(h.target)), g.length > 0 && o.set(g.map((h) => h.target), !1), (d == null ? void 0 : d.length) > 0 && d.forEach(({ newValue: h }) => o.update(h.target));
@@ -640,7 +640,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
640
640
  bulkUpdateTargets: f,
641
641
  bulkUpsertAnnotations: S,
642
642
  getAnnotationBounds: c,
643
- getAnnotationRects: w,
643
+ getAnnotationRects: v,
644
644
  getIntersecting: R,
645
645
  getAt: p,
646
646
  recalculatePositions: T,
@@ -674,10 +674,10 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
674
674
  n.font && (o.font = n.font);
675
675
  const c = s.get(y.annotation.id);
676
676
  if (c) {
677
- const { height: R } = y.rects[0], w = y.rects[0].x + f.left, T = y.rects[0].y + f.top;
678
- o.fillStyle = c.appearance.color, o.fillRect(w - 2, T - 2.5, 2, R + 5);
677
+ const { height: R } = y.rects[0], v = y.rects[0].x + f.left, T = y.rects[0].y + f.top;
678
+ o.fillStyle = c.appearance.color, o.fillRect(v - 2, T - 2.5, 2, R + 5);
679
679
  const E = o.measureText(c.appearance.label), m = E.width + 6, l = E.actualBoundingBoxAscent + E.actualBoundingBoxDescent + 8, g = E.fontBoundingBoxAscent ? 8 : 6.5;
680
- return o.fillRect(w - 2, T - 2.5 - l, m, l), o.fillStyle = "#fff", o.fillText(c.appearance.label, w + 1, T - g), {
680
+ return o.fillRect(v - 2, T - 2.5 - l, m, l), o.fillStyle = "#fff", o.fillText(c.appearance.label, v + 1, T - g), {
681
681
  fill: c.appearance.color,
682
682
  fillOpacity: p ? 0.45 : 0.18
683
683
  };
@@ -703,9 +703,9 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
703
703
  } = e, y = (b) => r = b;
704
704
  let f;
705
705
  const p = (b) => f = b;
706
- let c, R, w, T = i;
706
+ let c, R, v, T = i;
707
707
  const E = (b) => {
708
- T = b, l.clear(), b || (c = void 0, R = void 0, w = void 0);
708
+ T = b, l.clear(), b || (c = void 0, R = void 0, v = void 0);
709
709
  }, m = (b) => {
710
710
  T && R !== !1 && (c = X(t, b.target) ? void 0 : {
711
711
  annotation: st(),
@@ -722,8 +722,8 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
722
722
  c = void 0;
723
723
  return;
724
724
  }
725
- const O = b.timeStamp - ((w == null ? void 0 : w.timeStamp) || b.timeStamp);
726
- if ((w == null ? void 0 : w.type) === "pointerdown" && (O < 1e3 && !c || x.isCollapsed && O < et) && m(w || b), !c) return;
725
+ const O = b.timeStamp - ((v == null ? void 0 : v.timeStamp) || b.timeStamp);
726
+ if ((v == null ? void 0 : v.type) === "pointerdown" && (O < 1e3 && !c || x.isCollapsed && O < et) && m(v || b), !c) return;
727
727
  if (x.isCollapsed) {
728
728
  o.getAnnotation(c.annotation) && (s.clear(), o.deleteAnnotation(c.annotation));
729
729
  return;
@@ -740,7 +740,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
740
740
  updated: /* @__PURE__ */ new Date()
741
741
  }, o.getAnnotation(c.annotation) ? o.updateTarget(c, U.LOCAL) : s.clear());
742
742
  }, 10), g = (b) => {
743
- w = Q(b), R = w.button === 0;
743
+ v = Q(b), R = v.button === 0;
744
744
  }, d = async (b) => {
745
745
  if (!R) return;
746
746
  const x = Q(b), O = () => {
@@ -761,7 +761,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
761
761
  } else
762
762
  s.clear();
763
763
  };
764
- if (x.timeStamp - w.timeStamp < et) {
764
+ if (x.timeStamp - v.timeStamp < et) {
765
765
  await h();
766
766
  const I = document.getSelection();
767
767
  if (I != null && I.isCollapsed) {
@@ -775,7 +775,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
775
775
  let x = !1, O = b == null ? void 0 : b.isCollapsed;
776
776
  const F = () => O || x, I = 1;
777
777
  return setTimeout(() => x = !0, 50), xt(() => O = b == null ? void 0 : b.isCollapsed, I, F);
778
- }, v = (b) => {
778
+ }, w = (b) => {
779
779
  const x = document.getSelection();
780
780
  x != null && x.isCollapsed || ((!c || c.selector.length === 0) && l(b), c && (B(), s.userSelect(c.annotation, Q(b))));
781
781
  }, A = (b) => {
@@ -791,9 +791,9 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
791
791
  document.addEventListener("selectionchange", x), m(b);
792
792
  };
793
793
  V(de.join(","), { element: t, keydown: !0, keyup: !1 }, (b) => {
794
- b.repeat || (w = Y(b));
794
+ b.repeat || (v = Y(b));
795
795
  }), V(dt, { keydown: !0, keyup: !1 }, (b) => {
796
- w = Y(b), C(b);
796
+ v = Y(b), C(b);
797
797
  });
798
798
  const L = (b) => {
799
799
  b.repeat || b.target !== t && b.target !== document.body || (c = void 0, s.clear());
@@ -812,9 +812,9 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
812
812
  const { target: { updated: x } } = b, { updated: O } = c;
813
813
  (!x || !O || x < O) && o.updateTarget(c);
814
814
  };
815
- return document.addEventListener("pointerdown", g), document.addEventListener("pointerup", d), document.addEventListener("contextmenu", v), t.addEventListener("keyup", A), t.addEventListener("selectstart", m), document.addEventListener("selectionchange", l), {
815
+ return document.addEventListener("pointerdown", g), document.addEventListener("pointerup", d), document.addEventListener("contextmenu", w), t.addEventListener("keyup", A), t.addEventListener("selectstart", m), document.addEventListener("selectionchange", l), {
816
816
  destroy: () => {
817
- c = void 0, R = void 0, w = void 0, l.clear(), document.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", d), document.removeEventListener("contextmenu", v), t.removeEventListener("keyup", A), t.removeEventListener("selectstart", m), document.removeEventListener("selectionchange", l), V.unbind();
817
+ c = void 0, R = void 0, v = void 0, l.clear(), document.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", d), document.removeEventListener("contextmenu", w), t.removeEventListener("keyup", A), t.removeEventListener("selectstart", m), document.removeEventListener("selectionchange", l), V.unbind();
818
818
  },
819
819
  setFilter: p,
820
820
  setUser: y,
@@ -837,7 +837,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
837
837
  console.debug(`Using ${y} renderer`), e.style && f.setStyle(e.style);
838
838
  const p = ue(t, o, e);
839
839
  p.setUser(S), p.setAnnotatingEnabled(e.annotatingEnabled);
840
- const c = vt(o, a, e.adapter), R = () => S, w = (d) => {
840
+ const c = wt(o, a, e.adapter), R = () => S, v = (d) => {
841
841
  p.setAnnotatingEnabled(
842
842
  d === void 0 ? !0 : d
843
843
  );
@@ -857,7 +857,7 @@ const rt = "not-annotatable", _ = `.${rt}`, X = (t, n) => {
857
857
  },
858
858
  element: t,
859
859
  getUser: R,
860
- setAnnotatingEnabled: w,
860
+ setAnnotatingEnabled: v,
861
861
  setFilter: T,
862
862
  setStyle: f.setStyle.bind(f),
863
863
  redraw: f.redraw.bind(f),
@@ -911,7 +911,7 @@ export {
911
911
  Ft as scrollIntoView,
912
912
  re as serializeW3CTextAnnotation,
913
913
  Bt as splitAnnotatableRanges,
914
- we as toDomRectList,
914
+ ve as toDomRectList,
915
915
  _t as toParentBounds,
916
916
  Ae as toViewportBounds,
917
917
  Ut as trimRangeToContainer,