@soomo/text-annotator 3.0.0-staging.35 → 3.0.0-staging.37

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 +1 @@
1
- .r6o-canvas-highlight-layer{position:fixed;top:0;bottom:0;left:0;width:100vw;height:100vh;pointer-events:none}.r6o-canvas-highlight-layer.bg{mix-blend-mode:multiply;z-index:1}.r6o-annotatable .r6o-span-highlight-layer{height:100%;left:0;mix-blend-mode:multiply;pointer-events:none;position:absolute;top:0;width:100%}.r6o-annotatable .r6o-span-highlight-layer.hidden{display:none}.r6o-annotatable .r6o-span-highlight-layer .r6o-annotation{border-style:solid;border-width:0;box-sizing:content-box;display:block;position:absolute}.r6o-annotation{box-sizing:content-box}.r6o-presence-layer{left:0;position:fixed;top:0;bottom:0;width:100vw;pointer-events:none}html,body{overscroll-behavior-y:none}.r6o-annotatable{position:relative;-webkit-tap-highlight-color:transparent}.r6o-annotatable.no-focus-outline{outline:none}.hovered *{cursor:pointer}*::selection,::selection{background:#0080ff2e}::-moz-selection{background:#0080ff2e}
1
+ .r6o-canvas-highlight-layer{position:fixed;top:0;bottom:0;left:0;width:100vw;height:100vh;pointer-events:none}.r6o-canvas-highlight-layer.bg{mix-blend-mode:multiply;z-index:1}.r6o-annotatable .r6o-span-highlight-layer{position:absolute;top:0;left:0;width:100%;height:100%;mix-blend-mode:multiply;pointer-events:none;z-index:1}.r6o-annotatable .r6o-span-highlight-layer.hidden{display:none}.r6o-annotatable .r6o-span-highlight-layer .r6o-annotation{border-style:solid;border-width:0;box-sizing:content-box;display:block;position:absolute}.r6o-annotation{box-sizing:content-box}.r6o-presence-layer{left:0;position:fixed;top:0;bottom:0;width:100vw;pointer-events:none}html,body{overscroll-behavior-y:none}.r6o-annotatable{position:relative;-webkit-tap-highlight-color:transparent}.r6o-annotatable.no-focus-outline{outline:none}.hovered *{cursor:pointer}*::selection,::selection{background:#0080ff2e}::-moz-selection{background:#0080ff2e}
@@ -291,17 +291,17 @@ const q = {
291
291
  const { store: i, selection: r, hover: s } = t;
292
292
  let a, d, f;
293
293
  const g = _e(n), l = (T) => {
294
- const { x: B, y: b } = e.getBoundingClientRect(), C = i.getAt(T.clientX - B, T.clientY - b, d);
294
+ const { x: M, y: b } = e.getBoundingClientRect(), C = i.getAt(T.clientX - M, T.clientY - b, d);
295
295
  C ? s.current !== C.id && (e.classList.add("hovered"), s.set(C.id)) : s.current && (e.classList.remove("hovered"), s.set(null));
296
296
  };
297
297
  e.addEventListener("pointermove", l);
298
298
  const m = (T = !1) => {
299
299
  f && f.clear();
300
- const B = He(e), { minX: b, minY: C, maxX: x, maxY: L } = B, R = d ? i.getIntersecting(b, C, x, L).filter(({ annotation: j }) => d(j)) : i.getIntersecting(b, C, x, L), I = r.selected.map(({ id: j }) => j), _ = R.map(({ annotation: j, rects: we }) => {
300
+ const M = He(e), { minX: b, minY: C, maxX: x, maxY: L } = M, R = d ? i.getIntersecting(b, C, x, L).filter(({ annotation: j }) => d(j)) : i.getIntersecting(b, C, x, L), I = r.selected.map(({ id: j }) => j), _ = R.map(({ annotation: j, rects: we }) => {
301
301
  const Ae = I.includes(j.id), Se = j.id === s.current;
302
302
  return { annotation: j, rects: we, state: { selected: Ae, hover: Se } };
303
303
  });
304
- o.redraw(_, B, a, f, T), setTimeout(() => g(R.map(({ annotation: j }) => j)), 1);
304
+ o.redraw(_, M, a, f, T), setTimeout(() => g(R.map(({ annotation: j }) => j)), 1);
305
305
  }, c = (T) => {
306
306
  f = T, m();
307
307
  }, S = (T) => {
@@ -318,12 +318,12 @@ const q = {
318
318
  window.addEventListener("resize", A);
319
319
  const h = new ResizeObserver(A);
320
320
  h.observe(e);
321
- const E = { attributes: !0, childList: !0, subtree: !0 }, M = new MutationObserver((T) => {
321
+ const E = { attributes: !0, childList: !0, subtree: !0 }, B = new MutationObserver((T) => {
322
322
  T.every((b) => b.target === e || e.contains(b.target)) || m(!0);
323
323
  });
324
- return M.observe(document.body, E), {
324
+ return B.observe(document.body, E), {
325
325
  destroy: () => {
326
- e.removeEventListener("pointermove", l), o.destroy(), i.unobserve(w), p(), document.removeEventListener("scroll", u), window.removeEventListener("resize", A), h.disconnect(), M.disconnect();
326
+ e.removeEventListener("pointermove", l), o.destroy(), i.unobserve(w), p(), document.removeEventListener("scroll", u), window.removeEventListener("resize", A), h.disconnect(), B.disconnect();
327
327
  },
328
328
  redraw: m,
329
329
  setStyle: S,
@@ -349,19 +349,19 @@ const q = {
349
349
  return u.getTime() - A.getTime();
350
350
  }).forEach((w) => {
351
351
  var h;
352
- const p = f ? typeof f == "function" ? f(w.annotation, w.state) : f : (h = w.state) != null && h.selected ? gt : q, u = g && g.paint(w, d) || p, A = w.rects.map(({ x: E, y: M, width: k, height: T }) => ({
352
+ const p = f ? typeof f == "function" ? f(w.annotation, w.state) : f : (h = w.state) != null && h.selected ? gt : q, u = g && g.paint(w, d) || p, A = w.rects.map(({ x: E, y: B, width: k, height: T }) => ({
353
353
  x: E + S,
354
- y: M + c,
354
+ y: B + c,
355
355
  width: k,
356
356
  height: T
357
357
  }));
358
358
  if (n.fillStyle = u.fill, n.globalAlpha = u.fillOpacity || 1, A.forEach(
359
- ({ x: E, y: M, width: k, height: T }) => n.fillRect(E, M, k, T)
359
+ ({ x: E, y: B, width: k, height: T }) => n.fillRect(E, B, k, T)
360
360
  ), u.underlineColor) {
361
361
  n.globalAlpha = 1, n.strokeStyle = u.underlineColor, n.lineWidth = u.underlineThickness ?? 1;
362
362
  const E = u.underlineOffset ?? 0;
363
- A.forEach(({ x: M, y: k, width: T, height: B }) => {
364
- n.beginPath(), n.moveTo(M, k + B + E), n.lineTo(M + T, k + B + E), n.stroke();
363
+ A.forEach(({ x: B, y: k, width: T, height: M }) => {
364
+ n.beginPath(), n.moveTo(B, k + M + E), n.lineTo(B + T, k + M + E), n.stroke();
365
365
  });
366
366
  }
367
367
  });
@@ -959,7 +959,7 @@ const xn = (e, t) => {
959
959
  console.error(`Store integrity error: body ${b} in index, but not in annotation`);
960
960
  } else
961
961
  console.warn(`Attempt to retrieve missing body: ${b}`);
962
- }, M = (b, C) => {
962
+ }, B = (b, C) => {
963
963
  if (b.annotation !== C.annotation)
964
964
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
965
965
  const x = e.get(b.annotation);
@@ -976,12 +976,12 @@ const xn = (e, t) => {
976
976
  } else
977
977
  console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
978
978
  }, k = (b, C, x = V.LOCAL) => {
979
- const L = M(b, C);
979
+ const L = B(b, C);
980
980
  L && r(x, { updated: [L] });
981
981
  }, T = (b, C = V.LOCAL) => {
982
- const x = b.map((L) => M({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
982
+ const x = b.map((L) => B({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
983
983
  r(C, { updated: x });
984
- }, B = (b) => {
984
+ }, M = (b) => {
985
985
  const C = e.get(b.annotation);
986
986
  if (C) {
987
987
  const x = {
@@ -1012,7 +1012,7 @@ const xn = (e, t) => {
1012
1012
  bulkUpdateAnnotation: f,
1013
1013
  bulkUpdateBodies: T,
1014
1014
  bulkUpdateTargets: (b, C = V.LOCAL) => {
1015
- const x = b.map((L) => B(L)).filter(Boolean);
1015
+ const x = b.map((L) => M(L)).filter(Boolean);
1016
1016
  x.length > 0 && r(C, { updated: x });
1017
1017
  },
1018
1018
  clear: m,
@@ -1025,7 +1025,7 @@ const xn = (e, t) => {
1025
1025
  updateAnnotation: d,
1026
1026
  updateBody: k,
1027
1027
  updateTarget: (b, C = V.LOCAL) => {
1028
- const x = B(b);
1028
+ const x = M(b);
1029
1029
  x && r(C, { updated: [x] });
1030
1030
  }
1031
1031
  };
@@ -1662,17 +1662,17 @@ const no = (e, t) => {
1662
1662
  const E = A.selector.flatMap((k) => {
1663
1663
  const T = z([k]) ? k.range : oe(k, t).range;
1664
1664
  return Array.from(T.getClientRects());
1665
- }), M = Ie(E).map((k) => De(k, h));
1666
- return M.map((k) => {
1667
- const { x: T, y: B, width: b, height: C } = k;
1665
+ }), B = Ie(E).map((k) => De(k, h));
1666
+ return B.map((k) => {
1667
+ const { x: T, y: M, width: b, height: C } = k;
1668
1668
  return {
1669
1669
  minX: T,
1670
- minY: B,
1670
+ minY: M,
1671
1671
  maxX: T + b,
1672
- maxY: B + C,
1672
+ maxY: M + C,
1673
1673
  annotation: {
1674
1674
  id: A.annotation,
1675
- rects: M
1675
+ rects: B
1676
1676
  }
1677
1677
  };
1678
1678
  });
@@ -1688,28 +1688,28 @@ const no = (e, t) => {
1688
1688
  f(A), d(A);
1689
1689
  }, l = (A, h = !0) => {
1690
1690
  h && a();
1691
- const E = t.getBoundingClientRect(), M = A.map((T) => ({ target: T, rects: r(T, E) }));
1692
- M.forEach(({ target: T, rects: B }) => o.set(T.annotation, B));
1693
- const k = M.flatMap(({ rects: T }) => T);
1691
+ const E = t.getBoundingClientRect(), B = A.map((T) => ({ target: T, rects: r(T, E) }));
1692
+ B.forEach(({ target: T, rects: M }) => o.set(T.annotation, M));
1693
+ const k = B.flatMap(({ rects: T }) => T);
1694
1694
  n.load(k);
1695
1695
  }, m = (A, h, E = !1) => {
1696
- const M = n.search({
1696
+ const B = n.search({
1697
1697
  minX: A,
1698
1698
  minY: h,
1699
1699
  maxX: A,
1700
1700
  maxY: h
1701
- }), k = (T) => T.annotation.rects.reduce((B, b) => B + b.width * b.height, 0);
1702
- return M.length > 0 ? (M.sort((T, B) => k(T) - k(B)), E ? M.map((T) => T.annotation.id) : [M[0].annotation.id]) : [];
1701
+ }), k = (T) => T.annotation.rects.reduce((M, b) => M + b.width * b.height, 0);
1702
+ return B.length > 0 ? (B.sort((T, M) => k(T) - k(M)), E ? B.map((T) => T.annotation.id) : [B[0].annotation.id]) : [];
1703
1703
  }, c = (A) => {
1704
1704
  const h = S(A);
1705
1705
  if (h.length === 0)
1706
1706
  return;
1707
- let E = h[0].left, M = h[0].top, k = h[0].right, T = h[0].bottom;
1708
- for (let B = 1; B < h.length; B++) {
1709
- const b = h[B];
1710
- E = Math.min(E, b.left), M = Math.min(M, b.top), k = Math.max(k, b.right), T = Math.max(T, b.bottom);
1707
+ let E = h[0].left, B = h[0].top, k = h[0].right, T = h[0].bottom;
1708
+ for (let M = 1; M < h.length; M++) {
1709
+ const b = h[M];
1710
+ E = Math.min(E, b.left), B = Math.min(B, b.top), k = Math.max(k, b.right), T = Math.max(T, b.bottom);
1711
1711
  }
1712
- return new DOMRect(E, M, k - E, T - M);
1712
+ return new DOMRect(E, B, k - E, T - B);
1713
1713
  }, S = (A) => {
1714
1714
  const h = o.get(A);
1715
1715
  return h ? h[0].annotation.rects : [];
@@ -1720,12 +1720,12 @@ const no = (e, t) => {
1720
1720
  getAt: m,
1721
1721
  getAnnotationBounds: c,
1722
1722
  getAnnotationRects: S,
1723
- getIntersecting: (A, h, E, M) => {
1724
- const k = n.search({ minX: A, minY: h, maxX: E, maxY: M }), T = new Set(k.map((B) => B.annotation.id));
1725
- return Array.from(T).map((B) => ({
1726
- annotation: e.getAnnotation(B),
1727
- rects: S(B)
1728
- })).filter((B) => !!B.annotation);
1723
+ getIntersecting: (A, h, E, B) => {
1724
+ const k = n.search({ minX: A, minY: h, maxX: E, maxY: B }), T = new Set(k.map((M) => M.annotation.id));
1725
+ return Array.from(T).map((M) => ({
1726
+ annotation: e.getAnnotation(M),
1727
+ rects: S(M)
1728
+ })).filter((M) => !!M.annotation);
1729
1729
  },
1730
1730
  insert: d,
1731
1731
  recalculate: () => {
@@ -1762,7 +1762,7 @@ const no = (e, t) => {
1762
1762
  const h = o.getAnnotationRects(w);
1763
1763
  if (h.length !== 0) {
1764
1764
  if (p && u) {
1765
- const E = h.find(({ top: M, right: k, bottom: T, left: B }) => p >= B - A && p <= k + A && u >= M - A && u <= T + A);
1765
+ const E = h.find(({ top: B, right: k, bottom: T, left: M }) => p >= M - A && p <= k + A && u >= B - A && u <= T + A);
1766
1766
  if (E) return E;
1767
1767
  }
1768
1768
  return o.getAnnotationBounds(w);
@@ -2231,10 +2231,10 @@ const So = (e, t, n) => {
2231
2231
  const d = (h) => a = h, { store: f, selection: g } = t;
2232
2232
  let l, m, c;
2233
2233
  const S = (h) => {
2234
- var M;
2234
+ var B;
2235
2235
  if (!a || m === !1)
2236
2236
  return;
2237
- l = !((M = h.target.parentElement) != null && M.closest(X)) ? {
2237
+ l = !((B = h.target.parentElement) != null && B.closest(X)) ? {
2238
2238
  annotation: se(),
2239
2239
  selector: [],
2240
2240
  creator: o,
@@ -2252,9 +2252,9 @@ const So = (e, t, n) => {
2252
2252
  }
2253
2253
  if (h.timeStamp - ((c == null ? void 0 : c.timeStamp) || h.timeStamp) < 1e3 && !l && S(c || h), E.isCollapsed || !l || m === !1)
2254
2254
  return;
2255
- const T = E.getRangeAt(0), B = Pe(T, e);
2256
- if (Ve(B)) return;
2257
- const b = Ee(B.cloneRange());
2255
+ const T = E.getRangeAt(0), M = Pe(T, e);
2256
+ if (Ve(M)) return;
2257
+ const b = Ee(M.cloneRange());
2258
2258
  (b.length !== l.selector.length || b.some((R, I) => {
2259
2259
  var _;
2260
2260
  return R.toString() !== ((_ = l.selector[I]) == null ? void 0 : _.quote);
@@ -2277,14 +2277,17 @@ const So = (e, t, n) => {
2277
2277
  var T;
2278
2278
  if (!!((T = h.target.parentElement) != null && T.closest(X)) || !m)
2279
2279
  return;
2280
- const M = () => {
2281
- const { x: B, y: b } = e.getBoundingClientRect(), C = h.target instanceof Node && e.contains(h.target) && f.getAt(h.clientX - B, h.clientY - b, r);
2280
+ const B = () => {
2281
+ const { x: M, y: b } = e.getBoundingClientRect(), C = h.target instanceof Node && e.contains(h.target) && f.getAt(h.clientX - M, h.clientY - b, r);
2282
2282
  if (C) {
2283
2283
  const { selected: x } = g;
2284
2284
  (x.length !== 1 || x[0].id !== C.id) && g.userSelect(C.id, h);
2285
2285
  } else g.isEmpty() || g.clear();
2286
2286
  }, k = h.timeStamp - c.timeStamp;
2287
- document.getSelection().isCollapsed && k < 300 ? (l = void 0, M()) : l && g.userSelect(l.annotation, h);
2287
+ setTimeout(() => {
2288
+ const { isCollapsed: M } = document.getSelection();
2289
+ M && k < 300 ? (l = void 0, B()) : l && g.userSelect(l.annotation, h);
2290
+ });
2288
2291
  };
2289
2292
  document.addEventListener("pointerup", p), U("*", { element: e, keyup: !1, keydown: !0 }, (h, E) => {
2290
2293
  h.repeat || (c = Ue(h));