@soomo/text-annotator 3.2.0-staging.3 → 3.2.0-staging.5

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{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{position:absolute;display:block;border-style:solid;border-width:0;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;overflow:hidden;z-index:1}.r6o-annotatable .r6o-span-highlight-layer.hidden{display:none}.r6o-annotatable .r6o-span-highlight-layer .r6o-annotation{position:absolute;display:block;border-style:solid;border-width:0;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}
@@ -72,7 +72,7 @@ const fe = "not-annotatable", nt = `.${fe}`, rt = (t) => {
72
72
  }, Xe = (t, e) => {
73
73
  const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
74
74
  return new DOMRect(n, i, o - n, s - i);
75
- }, Pe = (t) => t.reduce((e, n) => {
75
+ }, $e = (t) => t.reduce((e, n) => {
76
76
  if (n.width === 0 || n.height === 0)
77
77
  return e;
78
78
  let o = [...e], i = !1;
@@ -100,7 +100,7 @@ const fe = "not-annotatable", nt = `.${fe}`, rt = (t) => {
100
100
  for (let e = 0; e < this.length; e++)
101
101
  yield this.item(e);
102
102
  }
103
- }), $e = (t, e, n) => {
103
+ }), Pe = (t, e, n) => {
104
104
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
105
105
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
106
106
  const s = Kt(o).textContent, a = t.toString(), r = s.length || 0, l = r + a.length;
@@ -217,17 +217,16 @@ const fe = "not-annotatable", nt = `.${fe}`, rt = (t) => {
217
217
  n.scroll({ top: x, left: p, behavior: "smooth" });
218
218
  }, Fe = (t, e) => (n, o) => {
219
219
  const i = typeof n == "string" ? n : n.id, s = o ? typeof o == "string" ? document.getElementById(o) : o : ge(t);
220
- if (s) {
221
- const a = e.getAnnotation(i), { range: r } = a.target.selector[0];
222
- if (r && !r.collapsed)
223
- return zt(e, a.target, s), !0;
224
- {
225
- const l = vt(a.target, t), { range: d } = l.selector[0];
226
- if (d && !d.collapsed)
227
- return zt(e, l, s), !0;
228
- }
229
- }
230
- return !1;
220
+ if (!s)
221
+ return console.warn(`The scroll parent is missing for the annotation: ${i}`, { container: t }), !1;
222
+ const a = e.getAnnotation(i);
223
+ if (!a)
224
+ return console.warn(`The annotation is missing in the store: ${i}`), !1;
225
+ const { range: r } = a.target.selector[0];
226
+ if (r && !r.collapsed)
227
+ return zt(e, a.target, s), !0;
228
+ const l = vt(a.target, t), { range: d } = l.selector[0];
229
+ return d && !d.collapsed ? (zt(e, l, s), !0) : !1;
231
230
  }, G = {
232
231
  fill: "rgb(0, 128, 255)",
233
232
  fillOpacity: 0.18
@@ -283,7 +282,7 @@ function Ge() {
283
282
  return gt.exports.debounce = t, gt.exports = t, gt.exports;
284
283
  }
285
284
  var Qe = /* @__PURE__ */ Ge();
286
- const Pt = /* @__PURE__ */ qe(Qe), Je = (t) => {
285
+ const $t = /* @__PURE__ */ qe(Qe), Je = (t) => {
287
286
  const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n, l = i - e;
288
287
  return { top: e, left: n, minX: s, minY: a, maxX: r, maxY: l };
289
288
  }, Ze = (t) => {
@@ -292,17 +291,17 @@ const Pt = /* @__PURE__ */ qe(Qe), Je = (t) => {
292
291
  const i = o.map((s) => s.id);
293
292
  (e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
294
293
  };
295
- }, $t = (t, e, n, o) => {
294
+ }, Pt = (t, e, n, o) => {
296
295
  const { store: i, selection: s, hover: a } = e;
297
296
  let r, l, d;
298
297
  const g = Ze(n), u = (T) => {
299
- const { x: M, y: _ } = t.getBoundingClientRect(), P = i.getAt(T.clientX - M, T.clientY - _, !1, l);
300
- P ? a.current !== P.id && (t.classList.add("hovered"), a.set(P.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
298
+ const { x: M, y: _ } = t.getBoundingClientRect(), $ = i.getAt(T.clientX - M, T.clientY - _, !1, l);
299
+ $ ? a.current !== $.id && (t.classList.add("hovered"), a.set($.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
301
300
  };
302
301
  t.addEventListener("pointermove", u);
303
302
  const h = (T = !1) => {
304
303
  d && d.clear();
305
- const M = Je(t), { minX: _, minY: P, maxX: f, maxY: b } = M, A = l ? i.getIntersecting(_, P, f, b).filter(({ annotation: O }) => l(O)) : i.getIntersecting(_, P, f, b), C = s.selected.map(({ id: O }) => O), B = A.map(({ annotation: O, rects: I }) => {
304
+ const M = Je(t), { minX: _, minY: $, maxX: f, maxY: b } = M, A = l ? i.getIntersecting(_, $, f, b).filter(({ annotation: O }) => l(O)) : i.getIntersecting(_, $, f, b), C = s.selected.map(({ id: O }) => O), B = A.map(({ annotation: O, rects: I }) => {
306
305
  const V = C.includes(O.id), Q = O.id === a.current;
307
306
  return { annotation: O, rects: I, state: { selected: V, hover: Q } };
308
307
  });
@@ -317,7 +316,7 @@ const Pt = /* @__PURE__ */ qe(Qe), Je = (t) => {
317
316
  i.observe(E);
318
317
  const m = s.subscribe(() => h()), c = () => h(!0);
319
318
  document.addEventListener("scroll", c, { capture: !0, passive: !0 });
320
- const y = Pt(() => {
319
+ const y = $t(() => {
321
320
  i.recalculatePositions(), d == null || d.reset(), h();
322
321
  }, 10);
323
322
  window.addEventListener("resize", y);
@@ -370,7 +369,7 @@ const Pt = /* @__PURE__ */ qe(Qe), Je = (t) => {
370
369
  });
371
370
  }
372
371
  });
373
- }), i = Pt(() => en(e), 10);
372
+ }), i = $t(() => en(e), 10);
374
373
  return window.addEventListener("resize", i), {
375
374
  destroy: () => {
376
375
  e.remove(), i.clear(), window.removeEventListener("resize", i);
@@ -380,17 +379,17 @@ const Pt = /* @__PURE__ */ qe(Qe), Je = (t) => {
380
379
  },
381
380
  redraw: o
382
381
  };
383
- }, on = (t, e, n) => $t(t, e, n, nn(t));
382
+ }, on = (t, e, n) => Pt(t, e, n, nn(t));
384
383
  var sn = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
385
384
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
386
385
  }, D = function(t, e, n) {
387
386
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
388
- }, $ = function(t, e, n) {
387
+ }, P = function(t, e, n) {
389
388
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
390
389
  }, me = function(t) {
391
390
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
392
391
  }, Wt = function(t) {
393
- return { r: $(t.r, 0, 255), g: $(t.g, 0, 255), b: $(t.b, 0, 255), a: $(t.a) };
392
+ return { r: P(t.r, 0, 255), g: P(t.g, 0, 255), b: P(t.b, 0, 255), a: P(t.a) };
394
393
  }, Ot = function(t) {
395
394
  return { r: D(t.r), g: D(t.g), b: D(t.b), a: D(t.a, 3) };
396
395
  }, rn = /^#([0-9a-f]{3,8})$/i, mt = function(t) {
@@ -405,7 +404,7 @@ var sn = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
405
404
  var s = Math.floor(e), a = o * (1 - n), r = o * (1 - (e - s) * n), l = o * (1 - (1 - e + s) * n), d = s % 6;
406
405
  return { r: 255 * [o, r, a, a, l, o][d], g: 255 * [l, o, o, r, a, a][d], b: 255 * [a, a, l, o, o, r][d], a: i };
407
406
  }, qt = function(t) {
408
- return { h: me(t.h), s: $(t.s, 0, 100), l: $(t.l, 0, 100), a: $(t.a) };
407
+ return { h: me(t.h), s: P(t.s, 0, 100), l: P(t.l, 0, 100), a: P(t.a) };
409
408
  }, Gt = function(t) {
410
409
  return { h: D(t.h), s: D(t.s), l: D(t.l), a: D(t.a, 3) };
411
410
  }, Qt = function(t) {
@@ -437,7 +436,7 @@ var sn = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
437
436
  var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
438
437
  if (!F(e) || !F(n) || !F(o)) return null;
439
438
  var a = function(r) {
440
- return { h: me(r.h), s: $(r.s, 0, 100), v: $(r.v, 0, 100), a: $(r.a) };
439
+ return { h: me(r.h), s: P(r.s, 0, 100), v: P(r.v, 0, 100), a: P(r.a) };
441
440
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
442
441
  return be(a);
443
442
  }, "hsv"]] }, Zt = function(t, e) {
@@ -450,12 +449,12 @@ var sn = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
450
449
  return typeof t == "string" ? Zt(t.trim(), Jt.string) : typeof t == "object" && t !== null ? Zt(t, Jt.object) : [null, void 0];
451
450
  }, Rt = function(t, e) {
452
451
  var n = lt(t);
453
- return { h: n.h, s: $(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
452
+ return { h: n.h, s: P(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
454
453
  }, Mt = function(t) {
455
454
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
456
455
  }, te = function(t, e) {
457
456
  var n = lt(t);
458
- return { h: n.h, s: n.s, l: $(n.l + 100 * e, 0, 100), a: n.a };
457
+ return { h: n.h, s: n.s, l: P(n.l + 100 * e, 0, 100), a: n.a };
459
458
  }, ee = function() {
460
459
  function t(e) {
461
460
  this.parsed = un(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
@@ -544,7 +543,7 @@ const fn = (t) => [
544
543
  }), e = d;
545
544
  }
546
545
  };
547
- }, pn = (t, e, n) => $t(t, e, n, hn());
546
+ }, pn = (t, e, n) => Pt(t, e, n, hn());
548
547
  var ne = Object.prototype.hasOwnProperty;
549
548
  function Xt(t, e) {
550
549
  var n, o;
@@ -598,7 +597,7 @@ const gn = (t, e) => {
598
597
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
599
598
  }
600
599
  };
601
- }, yn = (t, e, n) => $t(t, e, n, mn(t)), Y = [];
600
+ }, yn = (t, e, n) => Pt(t, e, n, mn(t)), Y = [];
602
601
  for (let t = 0; t < 256; ++t)
603
602
  Y.push((t + 256).toString(16).slice(1));
604
603
  function bn(t, e = 0) {
@@ -1045,7 +1044,7 @@ const Nn = (t, e) => {
1045
1044
  }, _ = (f, b = k.LOCAL) => {
1046
1045
  const A = f.map((C) => T({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
1047
1046
  s(b, { updated: A });
1048
- }, P = (f) => {
1047
+ }, $ = (f) => {
1049
1048
  const b = t.get(f.annotation);
1050
1049
  if (b) {
1051
1050
  const A = {
@@ -1076,7 +1075,7 @@ const Nn = (t, e) => {
1076
1075
  bulkUpdateAnnotations: g,
1077
1076
  bulkUpdateBodies: _,
1078
1077
  bulkUpdateTargets: (f, b = k.LOCAL) => {
1079
- const A = f.map((C) => P(C)).filter(Boolean);
1078
+ const A = f.map((C) => $(C)).filter(Boolean);
1080
1079
  A.length > 0 && s(b, { updated: A });
1081
1080
  },
1082
1081
  bulkUpsertAnnotations: u,
@@ -1090,7 +1089,7 @@ const Nn = (t, e) => {
1090
1089
  updateAnnotation: l,
1091
1090
  updateBody: M,
1092
1091
  updateTarget: (f, b = k.LOCAL) => {
1093
- const A = P(f);
1092
+ const A = $(f);
1094
1093
  A && s(b, { updated: [A] });
1095
1094
  },
1096
1095
  upsertAnnotation: d
@@ -1155,7 +1154,7 @@ const Yn = 250, Kn = (t, e) => {
1155
1154
  subscribe: t,
1156
1155
  set: e
1157
1156
  };
1158
- }, Pn = (t, e, n, o) => {
1157
+ }, $n = (t, e, n, o) => {
1159
1158
  const { hover: i, selection: s, store: a, viewport: r } = t, l = /* @__PURE__ */ new Map();
1160
1159
  let d = [], g;
1161
1160
  const u = (w, E) => {
@@ -1223,7 +1222,7 @@ const Yn = 250, Kn = (t, e) => {
1223
1222
  w ? (m || []).forEach((c) => x("updateAnnotation", c.oldValue, c.newValue)) : (m || []).forEach((c) => x("updateAnnotation", c.newValue, c.oldValue));
1224
1223
  };
1225
1224
  return e.on("undo", p(!0)), e.on("redo", p(!1)), { on: u, off: h, emit: x };
1226
- }, $n = (t) => (e) => e.reduce((n, o) => {
1225
+ }, Pn = (t) => (e) => e.reduce((n, o) => {
1227
1226
  const { parsed: i, error: s } = t.parse(o);
1228
1227
  return s ? {
1229
1228
  parsed: n.parsed,
@@ -1260,7 +1259,7 @@ const Yn = 250, Kn = (t, e) => {
1260
1259
  }
1261
1260
  }, x = (m, c = !0) => {
1262
1261
  if (n) {
1263
- const y = n.parseAll || $n(n), { parsed: S, failed: v } = y(m);
1262
+ const y = n.parseAll || Pn(n), { parsed: S, failed: v } = y(m);
1264
1263
  v.length > 0 && console.warn(`Discarded ${v.length} invalid annotations`, v), o.bulkAddAnnotations(S, c, k.REMOTE);
1265
1264
  } else
1266
1265
  o.bulkAddAnnotations(m.map(Nt), c, k.REMOTE);
@@ -1741,14 +1740,14 @@ const ho = (t, e) => {
1741
1740
  const v = y.selector.flatMap((R) => {
1742
1741
  const T = q([R]) ? R.range : he(R, e).range;
1743
1742
  return Array.from(T.getClientRects());
1744
- }), L = Pe(v).map((R) => ze(R, S));
1743
+ }), L = $e(v).map((R) => ze(R, S));
1745
1744
  return L.map((R) => {
1746
- const { x: T, y: M, width: _, height: P } = R;
1745
+ const { x: T, y: M, width: _, height: $ } = R;
1747
1746
  return {
1748
1747
  minX: T,
1749
1748
  minY: M,
1750
1749
  maxX: T + _,
1751
- maxY: M + P,
1750
+ maxY: M + $,
1752
1751
  annotation: {
1753
1752
  id: y.annotation,
1754
1753
  rects: L
@@ -2292,7 +2291,7 @@ const de = 300, Re = ["up", "down", "left", "right"], Me = Ie ? "⌘+a" : "ctrl+
2292
2291
  creator: s,
2293
2292
  created: /* @__PURE__ */ new Date()
2294
2293
  });
2295
- }, c = Pt((f) => {
2294
+ }, c = $t((f) => {
2296
2295
  if (!w) return;
2297
2296
  const b = document.getSelection();
2298
2297
  if (!(b != null && b.anchorNode))
@@ -2315,7 +2314,7 @@ const de = 300, Re = ["up", "down", "left", "right"], Me = Ie ? "⌘+a" : "ctrl+
2315
2314
  return V.toString() !== ((Ct = h.selector[Q]) == null ? void 0 : Ct.quote);
2316
2315
  })) && (h = {
2317
2316
  ...h,
2318
- selector: O.map((V) => $e(V, t, r)),
2317
+ selector: O.map((V) => Pe(V, t, r)),
2319
2318
  updated: /* @__PURE__ */ new Date()
2320
2319
  }, o.getAnnotation(h.annotation) ? o.updateTarget(h, k.LOCAL) : i.clear());
2321
2320
  }, 10), y = (f) => {
@@ -2398,7 +2397,7 @@ const de = 300, Re = ["up", "down", "left", "right"], Me = Ie ? "⌘+a" : "ctrl+
2398
2397
  const n = Bo(e, {
2399
2398
  annotatingEnabled: !0,
2400
2399
  user: Gn()
2401
- }), o = po(t, n), { selection: i, viewport: s } = o, a = o.store, r = Kn(a), l = Pn(o, r, n.adapter);
2400
+ }), o = po(t, n), { selection: i, viewport: s } = o, a = o.store, r = Kn(a), l = $n(o, r, n.adapter);
2402
2401
  let d = n.user;
2403
2402
  const g = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ue : n.renderer || ue, u = g === "SPANS" ? yn(t, o, s) : g === "CSS_HIGHLIGHTS" ? pn(t, o, s) : g === "CANVAS" ? on(t, o, s) : void 0;
2404
2403
  if (!u)
@@ -2468,12 +2467,12 @@ export {
2468
2467
  Be as isRangeAnnotatable,
2469
2468
  q as isRevived,
2470
2469
  Ye as isWhitespaceOrEmpty,
2471
- Pe as mergeClientRects,
2470
+ $e as mergeClientRects,
2472
2471
  We as paint,
2473
2472
  no as parseW3CTextAnnotation,
2474
2473
  Ne as programmaticallyFocusable,
2475
2474
  He as rangeContains,
2476
- $e as rangeToSelector,
2475
+ Pe as rangeToSelector,
2477
2476
  Lt as reviveAnnotation,
2478
2477
  he as reviveSelector,
2479
2478
  vt as reviveTarget,