@recogito/text-annotator 3.0.0-rc.17 → 3.0.0-rc.18

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
- export declare const NOT_ANNTOTATABLE_SELECTOR = ".not-annotatable";
1
+ export declare const NOT_ANNOTATABLE_SELECTOR = ".not-annotatable";
2
2
  /**
3
3
  * Splits a DOM Range into one or more ranges that span annotatable content only.
4
4
  */
@@ -280,10 +280,10 @@ const Ot = (t) => {
280
280
  window.addEventListener("resize", m);
281
281
  const f = new ResizeObserver(m);
282
282
  f.observe(t);
283
- const w = { attributes: !0, childList: !0, subtree: !0 }, T = new MutationObserver(p);
284
- return T.observe(document.body, w), {
283
+ const w = { attributes: !0, childList: !0, subtree: !0 }, R = new MutationObserver(p);
284
+ return R.observe(document.body, w), {
285
285
  destroy: () => {
286
- t.removeEventListener("pointermove", b), t.removeChild(y), o.unobserve(E), l(), document.removeEventListener("scroll", h), window.removeEventListener("resize", m), f.disconnect(), T.disconnect();
286
+ t.removeEventListener("pointermove", b), t.removeChild(y), o.unobserve(E), l(), document.removeEventListener("scroll", h), window.removeEventListener("resize", m), f.disconnect(), R.disconnect();
287
287
  },
288
288
  refresh: p,
289
289
  setDrawingStyle: v,
@@ -450,20 +450,20 @@ const me = (t) => `background-color: ${Y(t.fill || Z.fill).alpha(t.fillOpacity |
450
450
  }, ve = (t, e, n) => {
451
451
  const { store: o, selection: i, hover: s } = e;
452
452
  let r, a, d;
453
- const u = be(), y = It(n), c = (R) => {
454
- const { x: g, y: A } = t.getBoundingClientRect(), x = o.getAt(R.clientX - g, R.clientY - A);
453
+ const u = be(), y = It(n), c = (T) => {
454
+ const { x: g, y: A } = t.getBoundingClientRect(), x = o.getAt(T.clientX - g, T.clientY - A);
455
455
  x && (!d || d(x)) ? s.current !== x.id && (t.classList.add("hovered"), s.set(x.id)) : s.current && (t.classList.remove("hovered"), s.set(null));
456
456
  };
457
457
  t.addEventListener("pointermove", c);
458
458
  const b = () => {
459
- const R = Ot(t), { minX: g, minY: A, maxX: x, maxY: S } = R, B = d ? o.getIntersectingRects(g, A, x, S).filter(({ annotation: I }) => d(I)) : o.getIntersectingRects(g, 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
- }, p = (R) => {
462
- r = R, u.setPainter(R);
463
- }, v = (R) => {
464
- a = R, b();
465
- }, C = (R) => {
466
- d = R, b();
459
+ const T = Ot(t), { minX: g, minY: A, maxX: x, maxY: S } = T, B = d ? o.getIntersectingRects(g, A, x, S).filter(({ annotation: I }) => d(I)) : o.getIntersectingRects(g, A, x, S), N = i.selected.map(({ id: I }) => I);
460
+ u.refresh(B, T, N, a), setTimeout(() => y(B.map(({ annotation: I }) => I)), 1);
461
+ }, p = (T) => {
462
+ r = T, u.setPainter(T);
463
+ }, v = (T) => {
464
+ a = T, b();
465
+ }, C = (T) => {
466
+ d = T, b();
467
467
  }, E = () => b();
468
468
  o.observe(E);
469
469
  const l = i.subscribe(() => b());
@@ -831,10 +831,10 @@ const Oe = (t, e) => {
831
831
  }, w = (g, A, x = L.LOCAL) => {
832
832
  const S = f(g, A);
833
833
  S && s(x, { updated: [S] });
834
- }, T = (g, A = L.LOCAL) => {
834
+ }, R = (g, A = L.LOCAL) => {
835
835
  const x = g.map((S) => f({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
836
836
  s(A, { updated: x });
837
- }, R = (g) => {
837
+ }, T = (g) => {
838
838
  const A = t.get(g.annotation);
839
839
  if (A) {
840
840
  const x = {
@@ -862,9 +862,9 @@ const Oe = (t, e) => {
862
862
  bulkAddAnnotation: p,
863
863
  bulkDeleteAnnotation: E,
864
864
  bulkUpdateAnnotation: u,
865
- bulkUpdateBodies: T,
865
+ bulkUpdateBodies: R,
866
866
  bulkUpdateTargets: (g, A = L.LOCAL) => {
867
- const x = g.map((S) => R(S)).filter(Boolean);
867
+ const x = g.map((S) => T(S)).filter(Boolean);
868
868
  x.length > 0 && s(A, { updated: x });
869
869
  },
870
870
  clear: b,
@@ -877,7 +877,7 @@ const Oe = (t, e) => {
877
877
  updateAnnotation: d,
878
878
  updateBody: w,
879
879
  updateTarget: (g, A = L.LOCAL) => {
880
- const x = R(g);
880
+ const x = T(g);
881
881
  x && s(A, { updated: [x] });
882
882
  }
883
883
  };
@@ -952,8 +952,8 @@ const Ue = 250, De = (t) => {
952
952
  d.has(l) && setTimeout(() => {
953
953
  d.get(l).forEach((f) => {
954
954
  if (n) {
955
- const w = Array.isArray(h) ? h.map((R) => n.serialize(R)) : n.serialize(h), T = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
956
- f(w, T);
955
+ const w = Array.isArray(h) ? h.map((T) => n.serialize(T)) : n.serialize(h), R = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
956
+ f(w, R);
957
957
  } else
958
958
  f(h, m);
959
959
  });
@@ -998,18 +998,18 @@ const Ue = 250, De = (t) => {
998
998
  ...f.bodiesDeleted || [],
999
999
  ...f.bodiesUpdated || []
1000
1000
  ].length > 0).forEach(({ oldValue: f, newValue: w }) => {
1001
- const T = u.find((R) => R.id === f.id) || f;
1002
- u = u.map((R) => R.id === f.id ? w : R), v("updateAnnotation", w, T);
1001
+ const R = u.find((T) => T.id === f.id) || f;
1002
+ u = u.map((T) => T.id === f.id ? w : T), v("updateAnnotation", w, R);
1003
1003
  });
1004
1004
  }, { origin: L.LOCAL }), i.observe((l) => {
1005
1005
  if (u) {
1006
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);
1007
- m.length > 0 && (u = u.map((f) => m.find((T) => T.id === f.id) || f));
1007
+ m.length > 0 && (u = u.map((f) => m.find((R) => R.id === f.id) || f));
1008
1008
  }
1009
1009
  }, { origin: L.REMOTE });
1010
1010
  const E = (l) => (h) => {
1011
1011
  const { created: m, deleted: f, updated: w } = h;
1012
- (m || []).forEach((T) => v("createAnnotation", T)), (f || []).forEach((T) => v("deleteAnnotation", T)), l ? (w || []).forEach((T) => v("updateAnnotation", T.oldValue, T.newValue)) : (w || []).forEach((T) => v("updateAnnotation", T.newValue, T.oldValue));
1012
+ (m || []).forEach((R) => v("createAnnotation", R)), (f || []).forEach((R) => v("deleteAnnotation", R)), l ? (w || []).forEach((R) => v("updateAnnotation", R.oldValue, R.newValue)) : (w || []).forEach((R) => v("updateAnnotation", R.newValue, R.oldValue));
1013
1013
  };
1014
1014
  return e.on("undo", E(!0)), e.on("redo", E(!1)), { on: b, off: p, emit: v };
1015
1015
  }, Pe = (t) => (e) => e.reduce((n, o) => {
@@ -1495,16 +1495,16 @@ function Mt(t, e, n, o, i) {
1495
1495
  const dn = (t, e) => {
1496
1496
  const n = new on(), o = /* @__PURE__ */ new Map(), i = (l) => {
1497
1497
  const h = e.getBoundingClientRect(), m = l.selector.flatMap((w) => {
1498
- const R = w.range instanceof Range && !w.range.collapsed && w.range.startContainer.nodeType === Node.TEXT_NODE && w.range.endContainer.nodeType === Node.TEXT_NODE ? w.range : _t(w, e).range;
1499
- return Array.from(R.getClientRects());
1498
+ const T = w.range instanceof Range && !w.range.collapsed && w.range.startContainer.nodeType === Node.TEXT_NODE && w.range.endContainer.nodeType === Node.TEXT_NODE ? w.range : _t(w, e).range;
1499
+ return Array.from(T.getClientRects());
1500
1500
  }), f = oe(m);
1501
1501
  return f.map((w) => {
1502
- const { x: T, y: R, width: g, height: A } = w;
1502
+ const { x: R, y: T, width: g, height: A } = w;
1503
1503
  return {
1504
- minX: T - h.x,
1505
- minY: R - h.y,
1506
- maxX: T - h.x + g,
1507
- maxY: R - h.y + A,
1504
+ minX: R - h.x,
1505
+ minY: T - h.y,
1506
+ maxX: R - h.x + g,
1507
+ maxY: T - h.y + A,
1508
1508
  annotation: {
1509
1509
  id: l.annotation,
1510
1510
  rects: f
@@ -1524,8 +1524,8 @@ const dn = (t, e) => {
1524
1524
  }, y = (l, h = !0) => {
1525
1525
  h && r();
1526
1526
  const m = l.map((w) => ({ target: w, rects: i(w) }));
1527
- m.forEach(({ target: w, rects: T }) => o.set(w.annotation, T));
1528
- const f = m.reduce((w, { rects: T }) => [...w, ...T], []);
1527
+ m.forEach(({ target: w, rects: R }) => o.set(w.annotation, R));
1528
+ const f = m.reduce((w, { rects: R }) => [...w, ...R], []);
1529
1529
  n.load(f);
1530
1530
  }, c = (l, h) => {
1531
1531
  const m = n.search({
@@ -1533,19 +1533,19 @@ const dn = (t, e) => {
1533
1533
  minY: h,
1534
1534
  maxX: l,
1535
1535
  maxY: h
1536
- }), f = (w) => w.annotation.rects.reduce((T, R) => T + R.width * R.height, 0);
1536
+ }), f = (w) => w.annotation.rects.reduce((R, T) => R + T.width * T.height, 0);
1537
1537
  if (m.length > 0)
1538
- return m.sort((w, T) => f(w) - f(T)), m[0].annotation.id;
1538
+ return m.sort((w, R) => f(w) - f(R)), m[0].annotation.id;
1539
1539
  }, b = (l) => {
1540
1540
  const h = p(l);
1541
1541
  if (h.length === 0)
1542
1542
  return;
1543
- let m = h[0].left, f = h[0].top, w = h[0].right, T = h[0].bottom;
1544
- for (let R = 1; R < h.length; R++) {
1545
- const g = h[R];
1546
- m = Math.min(m, g.left), f = Math.min(f, g.top), w = Math.max(w, g.right), T = Math.max(T, g.bottom);
1543
+ let m = h[0].left, f = h[0].top, w = h[0].right, R = h[0].bottom;
1544
+ for (let T = 1; T < h.length; T++) {
1545
+ const g = h[T];
1546
+ m = Math.min(m, g.left), f = Math.min(f, g.top), w = Math.max(w, g.right), R = Math.max(R, g.bottom);
1547
1547
  }
1548
- return new DOMRect(m, f, w - m, T - f);
1548
+ return new DOMRect(m, f, w - m, R - f);
1549
1549
  }, p = (l) => {
1550
1550
  const h = o.get(l);
1551
1551
  return h ? h[0].annotation.rects : [];
@@ -1569,7 +1569,7 @@ const dn = (t, e) => {
1569
1569
  const m = st(l, t), f = D(m.target.selector);
1570
1570
  return f && n.addAnnotation(m, h), f;
1571
1571
  }, d = (l, h = !0, m = L.LOCAL) => {
1572
- const f = l.map((T) => st(T, t)), w = f.filter((T) => !D(T.target.selector));
1572
+ const f = l.map((R) => st(R, t)), w = f.filter((R) => !D(R.target.selector));
1573
1573
  return w.length > 0 ? (console.warn("Could not revive all targets for these annotations:", w), n.bulkAddAnnotation(f, h, m), w) : (n.bulkAddAnnotation(f, h, m), []);
1574
1574
  }, u = (l, h = L.LOCAL) => {
1575
1575
  const m = l.map((w) => st(w, t)), f = m.filter((w) => !D(w.target.selector));
@@ -1587,23 +1587,23 @@ const dn = (t, e) => {
1587
1587
  return m ? n.getAnnotation(m) : void 0;
1588
1588
  }, p = (l, h, m, f) => {
1589
1589
  const w = o.getIntersectingRects(l, h, m, f);
1590
- return Array.from(new Set(w.map((R) => R.annotation.id))).map((R) => n.getAnnotation(R)).filter(Boolean);
1590
+ return Array.from(new Set(w.map((T) => T.annotation.id))).map((T) => n.getAnnotation(T)).filter(Boolean);
1591
1591
  }, v = (l, h, m, f = 5) => {
1592
1592
  const w = o.getDOMRectsForAnnotation(l);
1593
1593
  if (w.length !== 0) {
1594
1594
  if (h && m) {
1595
- const T = w.find(({ top: R, right: g, bottom: A, left: x }) => h >= x - f && h <= g + f && m >= R - f && m <= A + f);
1596
- if (T)
1597
- return T;
1595
+ const R = w.find(({ top: T, right: g, bottom: A, left: x }) => h >= x - f && h <= g + f && m >= T - f && m <= A + f);
1596
+ if (R)
1597
+ return R;
1598
1598
  }
1599
1599
  return o.getBoundsForAnnotation(l);
1600
1600
  }
1601
1601
  }, C = (l, h, m, f) => {
1602
- const T = o.getIntersectingRects(l, h, m, f).reduce((R, g) => ((R[g.annotation.id] = R[g.annotation.id] || []).push(g), R), {});
1603
- return Object.entries(T).map(([R, g]) => ({
1604
- annotation: n.getAnnotation(R),
1602
+ const R = o.getIntersectingRects(l, h, m, f).reduce((T, g) => ((T[g.annotation.id] = T[g.annotation.id] || []).push(g), T), {});
1603
+ return Object.entries(R).map(([T, g]) => ({
1604
+ annotation: n.getAnnotation(T),
1605
1605
  rects: g.map(({ minX: A, minY: x, maxX: S, maxY: B }) => ({ x: A, y: x, width: S - A, height: B - x }))
1606
- }));
1606
+ })).filter((T) => !!T.annotation);
1607
1607
  }, E = () => o.recalculate();
1608
1608
  return n.observe(({ changes: l }) => {
1609
1609
  const h = (l.created || []).filter((w) => D(w.target.selector)), m = (l.deleted || []).filter((w) => D(w.target.selector)), f = (l.updated || []).filter((w) => D(w.newValue.target.selector));
@@ -1707,9 +1707,9 @@ const dn = (t, e) => {
1707
1707
  if (C.timeStamp - ((u == null ? void 0 : u.timeStamp) || C.timeStamp) < 1e3 && !r && y(u), E.isCollapsed || !d || !r)
1708
1708
  return;
1709
1709
  const l = E.getRangeAt(0), h = se(l.cloneRange()), m = Gt(h);
1710
- (m.length !== r.selector.length || m.some((w, T) => {
1711
- var R;
1712
- return w.toString() !== ((R = r.selector[T]) == null ? void 0 : R.quote);
1710
+ (m.length !== r.selector.length || m.some((w, R) => {
1711
+ var T;
1712
+ return w.toString() !== ((T = r.selector[R]) == null ? void 0 : T.quote);
1713
1713
  })) && (r = {
1714
1714
  ...r,
1715
1715
  selector: m.map((w) => ie(w, t, n))
@@ -1730,10 +1730,10 @@ const dn = (t, e) => {
1730
1730
  if (!!((m = C.target.parentElement) != null && m.closest(".not-annotatable")) || !d)
1731
1731
  return;
1732
1732
  const l = () => {
1733
- const { x: f, y: w } = t.getBoundingClientRect(), T = o.getAt(C.clientX - f, C.clientY - w);
1734
- if (T) {
1735
- const { selected: R } = i;
1736
- (R.length !== 1 || R[0].id !== T.id) && i.clickSelect(T.id, C);
1733
+ const { x: f, y: w } = t.getBoundingClientRect(), R = o.getAt(C.clientX - f, C.clientY - w);
1734
+ if (R) {
1735
+ const { selected: T } = i;
1736
+ (T.length !== 1 || T[0].id !== R.id) && i.clickSelect(R.id, C);
1737
1737
  } else
1738
1738
  i.isEmpty() || i.clear();
1739
1739
  }, h = C.timeStamp - u.timeStamp;
@@ -1783,7 +1783,7 @@ const dn = (t, e) => {
1783
1783
  };
1784
1784
  };
1785
1785
  export {
1786
- q as NOT_ANNTOTATABLE_SELECTOR,
1786
+ q as NOT_ANNOTATABLE_SELECTOR,
1787
1787
  L as Origin,
1788
1788
  vn as W3CTextFormat,
1789
1789
  ve as createCSSHighlightRenderer,