@soomo/text-annotator 3.0.0-staging.2 → 3.0.0-staging.3

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.
@@ -7,7 +7,7 @@ import { Filter, ViewportState } from '@annotorious/core';
7
7
 
8
8
  export interface RendererImplementation {
9
9
  destroy(): void;
10
- redraw(highlights: Highlight[], bounds: ViewportBounds, style?: HighlightStyleExpression, painter?: HighlightPainter, force?: boolean): void;
10
+ redraw(highlights: Highlight[], bounds: ViewportBounds, style?: HighlightStyleExpression, painter?: HighlightPainter, lazy?: boolean): void;
11
11
  setVisible(visible: boolean): void;
12
12
  }
13
13
  export interface Renderer {
@@ -1,3 +1,4 @@
1
+ export declare const NOT_ANNOTATABLE_CLASS = "not-annotatable";
1
2
  export declare const NOT_ANNOTATABLE_SELECTOR = ".not-annotatable";
2
3
  /**
3
4
  * Splits a DOM Range into one or more ranges that span annotatable content only.
@@ -1,4 +1,4 @@
1
- const D = {
1
+ const H = {
2
2
  fill: "rgb(0, 128, 255)",
3
3
  fillOpacity: 0.18
4
4
  }, dt = {
@@ -6,22 +6,22 @@ const D = {
6
6
  fillOpacity: 0.45
7
7
  }, zt = (t, e, n, o, i) => {
8
8
  var s;
9
- const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) : n : (s = t.state) != null && s.selected ? dt : D;
9
+ const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) : n : (s = t.state) != null && s.selected ? dt : H;
10
10
  return o && o.paint(t, e) || r;
11
11
  }, ut = (t, e = 10) => {
12
12
  let n;
13
13
  return (...o) => {
14
14
  clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
15
15
  };
16
- }, Rt = "not-annotatable", H = `.${Rt}`, Ft = (t) => {
16
+ }, Rt = "not-annotatable", X = `.${Rt}`, Ft = (t) => {
17
17
  var n;
18
18
  const e = t.commonAncestorContainer;
19
- return e instanceof HTMLElement ? !e.closest(H) : !((n = e.parentElement) != null && n.closest(H));
19
+ return e instanceof HTMLElement ? !e.closest(X) : !((n = e.parentElement) != null && n.closest(X));
20
20
  }, Wt = function* (t) {
21
21
  const e = document.createNodeIterator(
22
22
  t.commonAncestorContainer,
23
23
  NodeFilter.SHOW_ELEMENT,
24
- (o) => o instanceof HTMLElement && o.classList.contains(Rt) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
24
+ (o) => o instanceof HTMLElement && o.classList.contains(Rt) && !o.parentElement.closest(X) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
25
25
  );
26
26
  let n;
27
27
  for (; n = e.nextNode(); )
@@ -42,10 +42,10 @@ const D = {
42
42
  return e.length > 0 ? e : [t];
43
43
  }, lt = (t) => {
44
44
  const e = t.cloneContents();
45
- return e.querySelectorAll(H).forEach((n) => n.remove()), e;
45
+ return e.querySelectorAll(X).forEach((n) => n.remove()), e;
46
46
  }, xn = (t) => {
47
47
  const e = t.cloneContents();
48
- return e.querySelectorAll(H).forEach((n) => n.remove()), e;
48
+ return e.querySelectorAll(X).forEach((n) => n.remove()), e;
49
49
  }, gt = (t, e) => {
50
50
  const n = document.createNodeIterator(e);
51
51
  let o = 0, i = n.nextNode();
@@ -182,7 +182,7 @@ const D = {
182
182
  NodeFilter.SHOW_TEXT,
183
183
  (m) => {
184
184
  var g;
185
- return (g = m.parentElement) != null && g.closest(H) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
185
+ return (g = m.parentElement) != null && g.closest(X) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
186
186
  }
187
187
  );
188
188
  let s = 0;
@@ -245,10 +245,10 @@ const D = {
245
245
  }, x = (p) => {
246
246
  a = p, m();
247
247
  }, y = (p) => {
248
- u = p, m();
248
+ u = p, m(!1);
249
249
  }, w = () => m();
250
250
  i.observe(w);
251
- const c = r.subscribe(() => m()), d = () => m();
251
+ const c = r.subscribe(() => m()), d = () => m(!0);
252
252
  document.addEventListener("scroll", d, { capture: !0, passive: !0 });
253
253
  const f = ut(() => {
254
254
  i.recalculatePositions(), h && h.reset(), m();
@@ -287,7 +287,7 @@ const D = {
287
287
  const { top: g, left: x } = u;
288
288
  a.forEach((y) => {
289
289
  var f;
290
- const w = h ? typeof h == "function" ? h(y.annotation, y.state) : h : (f = y.state) != null && f.selected ? dt : D, c = v && v.paint(y, u) || w, d = y.rects.map(({ x: b, y: E, width: L, height: B }) => ({
290
+ const w = h ? typeof h == "function" ? h(y.annotation, y.state) : h : (f = y.state) != null && f.selected ? dt : H, c = v && v.paint(y, u) || w, d = y.rects.map(({ x: b, y: E, width: L, height: B }) => ({
291
291
  x: b + x,
292
292
  y: E + g,
293
293
  width: L,
@@ -445,7 +445,7 @@ var ce = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
445
445
  return t instanceof Et ? t : new Et(t);
446
446
  };
447
447
  const me = (t) => [
448
- `background-color:${V((t == null ? void 0 : t.fill) || D.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? D.fillOpacity : t.fillOpacity).toHex()}`,
448
+ `background-color:${V((t == null ? void 0 : t.fill) || H.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? H.fillOpacity : t.fillOpacity).toHex()}`,
449
449
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
450
450
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
451
451
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
@@ -467,7 +467,7 @@ const me = (t) => [
467
467
  Array.from(e).filter((l) => !h.has(l));
468
468
  const v = r.map((l) => {
469
469
  var x;
470
- const m = a ? typeof a == "function" ? a(l.annotation, l.state) : a : (x = l.state) != null && x.selected ? dt : D, g = u && u.paint(l, s) || m;
470
+ const m = a ? typeof a == "function" ? a(l.annotation, l.state) : a : (x = l.state) != null && x.selected ? dt : H, g = u && u.paint(l, s) || m;
471
471
  return `::highlight(_${l.annotation.id}) { ${me(g)} }`;
472
472
  });
473
473
  t.innerHTML = v.join(`
@@ -517,7 +517,7 @@ const we = (t, e) => {
517
517
  e.remove();
518
518
  },
519
519
  redraw: (s, a, u, h, v) => {
520
- if (ct(n, s) && !v)
520
+ if (ct(n, s) && v)
521
521
  return;
522
522
  e.innerHTML = "";
523
523
  const m = s.reduce((g, { rects: x }) => [...g, ...x], []);
@@ -525,7 +525,7 @@ const we = (t, e) => {
525
525
  const x = g.rects.map((y) => {
526
526
  const w = document.createElement("span");
527
527
  w.className = "r6o-annotation", w.dataset.annotation = g.annotation.id, w.style.left = `${y.x}px`, w.style.top = `${y.y}px`, w.style.width = `${y.width}px`, w.style.height = `${y.height}px`;
528
- const c = we(y, m), d = zt(g, a, u, h, c), f = V((d == null ? void 0 : d.fill) || D.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? D.fillOpacity : d.fillOpacity).toHex();
528
+ const c = we(y, m), d = zt(g, a, u, h, c), f = V((d == null ? void 0 : d.fill) || H.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? H.fillOpacity : d.fillOpacity).toHex();
529
529
  return w.style.backgroundColor = f, d.underlineStyle && (w.style.borderStyle = d.underlineStyle), d.underlineColor && (w.style.borderColor = d.underlineColor), d.underlineThickness && (w.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (w.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(w), w;
530
530
  });
531
531
  return { id: g.annotation.id, spans: x };
@@ -566,7 +566,7 @@ function Vt(t, e, n) {
566
566
  return Se(o);
567
567
  }
568
568
  var Lt = Object.prototype.hasOwnProperty;
569
- function X(t, e) {
569
+ function D(t, e) {
570
570
  var n, o;
571
571
  if (t === e)
572
572
  return !0;
@@ -577,14 +577,14 @@ function X(t, e) {
577
577
  return t.toString() === e.toString();
578
578
  if (n === Array) {
579
579
  if ((o = t.length) === e.length)
580
- for (; o-- && X(t[o], e[o]); )
580
+ for (; o-- && D(t[o], e[o]); )
581
581
  ;
582
582
  return o === -1;
583
583
  }
584
584
  if (!n || typeof t == "object") {
585
585
  o = 0;
586
586
  for (n in t)
587
- if (Lt.call(t, n) && ++o && !Lt.call(e, n) || !(n in e) || !X(t[n], e[n]))
587
+ if (Lt.call(t, n) && ++o && !Lt.call(e, n) || !(n in e) || !D(t[n], e[n]))
588
588
  return !1;
589
589
  return Object.keys(e).length === o;
590
590
  }
@@ -693,8 +693,8 @@ const Oe = (t, e) => {
693
693
  return t.bodies.filter((o) => !n.has(o.id));
694
694
  }, Ne = (t, e) => e.bodies.map((n) => {
695
695
  const o = t.bodies.find((i) => i.id === n.id);
696
- return { newBody: n, oldBody: o && !X(o, n) ? o : void 0 };
697
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Ve = (t, e) => !X(t.target, e.target), Ut = (t, e) => {
696
+ return { newBody: n, oldBody: o && !D(o, n) ? o : void 0 };
697
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Ve = (t, e) => !D(t.target, e.target), Ut = (t, e) => {
698
698
  const n = Oe(t, e), o = Ie(t, e), i = Ne(t, e);
699
699
  return {
700
700
  oldValue: t,
@@ -1013,7 +1013,7 @@ const De = 250, He = (t) => {
1013
1013
  const { selected: c } = r, d = (c || []).map(({ id: f }) => i.getAnnotation(f));
1014
1014
  d.forEach((f) => {
1015
1015
  const b = h.find((E) => E.id === f.id);
1016
- (!b || !X(b, f)) && x("updateAnnotation", f, b);
1016
+ (!b || !D(b, f)) && x("updateAnnotation", f, b);
1017
1017
  }), h = h.map((f) => d.find(({ id: E }) => E === f.id) || f);
1018
1018
  };
1019
1019
  r.subscribe(({ selected: c }) => {
@@ -1023,13 +1023,13 @@ const De = 250, He = (t) => {
1023
1023
  else if (h.length > 0 && c.length === 0)
1024
1024
  h.forEach((d) => {
1025
1025
  const f = i.getAnnotation(d.id);
1026
- f && !X(f, d) && x("updateAnnotation", f, d);
1026
+ f && !D(f, d) && x("updateAnnotation", f, d);
1027
1027
  }), h = [];
1028
1028
  else {
1029
1029
  const d = new Set(h.map((b) => b.id)), f = new Set(c.map(({ id: b }) => b));
1030
1030
  h.filter((b) => !f.has(b.id)).forEach((b) => {
1031
1031
  const E = i.getAnnotation(b.id);
1032
- E && !X(E, b) && x("updateAnnotation", E, b);
1032
+ E && !D(E, b) && x("updateAnnotation", E, b);
1033
1033
  }), h = [
1034
1034
  // Remove annotations that were deselected
1035
1035
  ...h.filter((b) => f.has(b.id)),
@@ -1751,7 +1751,7 @@ const gn = (t, e) => {
1751
1751
  var c;
1752
1752
  if (!u)
1753
1753
  return;
1754
- !((c = y.target.parentElement) != null && c.closest(H)) ? s = {
1754
+ !((c = y.target.parentElement) != null && c.closest(X)) ? s = {
1755
1755
  annotation: Vt(),
1756
1756
  selector: [],
1757
1757
  creator: r,
@@ -1787,7 +1787,7 @@ const gn = (t, e) => {
1787
1787
  t.addEventListener("pointerdown", m);
1788
1788
  const g = (y) => {
1789
1789
  var f;
1790
- if (!!((f = y.target.parentElement) != null && f.closest(H)) || !u)
1790
+ if (!!((f = y.target.parentElement) != null && f.closest(X)) || !u)
1791
1791
  return;
1792
1792
  const c = () => {
1793
1793
  const { x: b, y: E } = t.getBoundingClientRect(), L = o.getAt(y.clientX - b, y.clientY - E);
@@ -1816,7 +1816,7 @@ const gn = (t, e) => {
1816
1816
  const h = e.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Tt : e.renderer || Tt, v = h === "SPANS" ? ye(t, n, i) : h === "CSS_HIGHLIGHTS" ? ve(t, n, i) : h === "CANVAS" ? le(t, n, i) : void 0;
1817
1817
  if (!v)
1818
1818
  throw `Unknown renderer implementation: ${h}`;
1819
- console.log(`Using ${h} renderer`), e.style && v.setStyle(e.style);
1819
+ console.debug(`Using ${h} renderer`), e.style && v.setStyle(e.style);
1820
1820
  const l = wn(t, n, e.offsetReferenceSelector);
1821
1821
  return l.setUser(u), {
1822
1822
  ...Fe(n, s, e.adapter),
@@ -1834,7 +1834,7 @@ const gn = (t, e) => {
1834
1834
  E ? o.setSelected(E) : o.clear();
1835
1835
  },
1836
1836
  setPresenceProvider: (E) => {
1837
- E && (v.setPainter(bn(t, E, e.presence)), E.on("selectionChange", () => v.redraw(!0)));
1837
+ E && (v.setPainter(bn(t, E, e.presence)), E.on("selectionChange", () => v.redraw()));
1838
1838
  },
1839
1839
  setVisible: (E) => v.setVisible(E),
1840
1840
  on: a.on,
@@ -1845,8 +1845,9 @@ const gn = (t, e) => {
1845
1845
  };
1846
1846
  export {
1847
1847
  dt as DEFAULT_SELECTED_STYLE,
1848
- D as DEFAULT_STYLE,
1849
- H as NOT_ANNOTATABLE_SELECTOR,
1848
+ H as DEFAULT_STYLE,
1849
+ Rt as NOT_ANNOTATABLE_CLASS,
1850
+ X as NOT_ANNOTATABLE_SELECTOR,
1850
1851
  R as Origin,
1851
1852
  An as W3CTextFormat,
1852
1853
  le as createCanvasRenderer,