@soomo/text-annotator 3.0.0-staging.10 → 3.0.0-staging.12

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.
@@ -59,7 +59,7 @@ const P = {
59
59
  return o;
60
60
  o += 1, i = n.nextNode();
61
61
  }
62
- }, yt = (t, e) => {
62
+ }, wt = (t, e) => {
63
63
  const n = document.createNodeIterator(e);
64
64
  let o = null;
65
65
  for (let i = 0; i < t + 1; i++)
@@ -78,7 +78,7 @@ const P = {
78
78
  }), s = vt(n, e), h = vt(i, e), f = () => {
79
79
  const l = e;
80
80
  l.replaceChildren(...a);
81
- const p = yt(s, l), g = yt(h, l);
81
+ const p = wt(s, l), g = wt(h, l);
82
82
  return t.setStart(p, o), t.setEnd(g, r), t;
83
83
  }, m = (l) => {
84
84
  const p = document.createElement("SPAN");
@@ -109,7 +109,7 @@ const P = {
109
109
  for (; r != null; )
110
110
  r === o && (a = !1), a && s.push(r), r === n && (a = !0), r = i.nextNode();
111
111
  return s;
112
- }, Mn = (t) => {
112
+ }, On = (t) => {
113
113
  const { startContainer: e, endContainer: n } = t;
114
114
  if (e === n)
115
115
  return Array.from(t.getClientRects());
@@ -234,22 +234,22 @@ const P = {
234
234
  const { store: i, selection: r, hover: a } = e;
235
235
  let s, h, f;
236
236
  const m = ce(n), l = (T) => {
237
- const { x: O, y: b } = t.getBoundingClientRect(), w = i.getAt(T.clientX - O, T.clientY - b);
238
- w && (!h || h(w)) ? a.current !== w.id && (t.classList.add("hovered"), a.set(w.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
237
+ const { x: I, y: b } = t.getBoundingClientRect(), y = i.getAt(T.clientX - I, T.clientY - b);
238
+ y && (!h || h(y)) ? a.current !== y.id && (t.classList.add("hovered"), a.set(y.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
239
239
  };
240
240
  t.addEventListener("pointermove", l);
241
241
  const p = (T = !1) => {
242
242
  f && f.clear();
243
- const O = ae(t), { minX: b, minY: w, maxX: A, maxY: S } = O, R = h ? i.getIntersecting(b, w, A, S).filter(({ annotation: D }) => h(D)) : i.getIntersecting(b, w, A, S), M = r.selected.map(({ id: D }) => D), H = R.map(({ annotation: D, rects: zt }) => {
244
- const Ft = M.includes(D.id), Wt = D.id === a.current;
243
+ const I = ae(t), { minX: b, minY: y, maxX: A, maxY: S } = I, R = h ? i.getIntersecting(b, y, A, S).filter(({ annotation: D }) => h(D)) : i.getIntersecting(b, y, A, S), O = r.selected.map(({ id: D }) => D), H = R.map(({ annotation: D, rects: zt }) => {
244
+ const Ft = O.includes(D.id), Wt = D.id === a.current;
245
245
  return { annotation: D, rects: zt, state: { selected: Ft, hover: Wt, custom: {} } };
246
246
  });
247
- o.redraw(H, O, s, f, T), setTimeout(() => m(R.map(({ annotation: D }) => D)), 1);
247
+ o.redraw(H, I, s, f, T), setTimeout(() => m(R.map(({ annotation: D }) => D)), 1);
248
248
  }, g = (T) => {
249
249
  f = T, p();
250
250
  }, x = (T) => {
251
251
  s = T, p();
252
- }, y = (T) => {
252
+ }, w = (T) => {
253
253
  h = T, p(!1);
254
254
  }, u = () => p();
255
255
  i.observe(u);
@@ -270,7 +270,7 @@ const P = {
270
270
  },
271
271
  redraw: p,
272
272
  setStyle: x,
273
- setFilter: y,
273
+ setFilter: w,
274
274
  setPainter: g,
275
275
  setVisible: o.setVisible
276
276
  };
@@ -292,26 +292,26 @@ const P = {
292
292
  return c.getTime() - v.getTime();
293
293
  }).forEach((u) => {
294
294
  var L;
295
- const d = f ? typeof f == "function" ? f(u.annotation, u.state) : f : (L = u.state) != null && L.selected ? ot : P, c = m && m.paint(u, h) || d, v = u.rects.map(({ x: E, y: B, width: T, height: O }) => ({
295
+ const d = f ? typeof f == "function" ? f(u.annotation, u.state) : f : (L = u.state) != null && L.selected ? ot : P, c = m && m.paint(u, h) || d, v = u.rects.map(({ x: E, y: B, width: T, height: I }) => ({
296
296
  x: E + x,
297
297
  y: B + g,
298
298
  width: T,
299
- height: O
299
+ height: I
300
300
  }));
301
301
  n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1;
302
302
  const C = 5;
303
303
  if (v.forEach(
304
- ({ x: E, y: B, width: T, height: O }) => n.fillRect(
304
+ ({ x: E, y: B, width: T, height: I }) => n.fillRect(
305
305
  E,
306
306
  B - C / 2,
307
307
  T,
308
- O + C
308
+ I + C
309
309
  )
310
310
  ), c.underlineColor) {
311
311
  n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
312
312
  const E = C / 2 + (c.underlineOffset ?? 0);
313
- v.forEach(({ x: B, y: T, width: O, height: b }) => {
314
- n.beginPath(), n.moveTo(B, T + b + E), n.lineTo(B + O, T + b + E), n.stroke();
313
+ v.forEach(({ x: B, y: T, width: I, height: b }) => {
314
+ n.beginPath(), n.moveTo(B, T + b + E), n.lineTo(B + I, T + b + E), n.stroke();
315
315
  });
316
316
  }
317
317
  });
@@ -330,16 +330,16 @@ const P = {
330
330
  }, he = (t, e, n) => mt(t, e, n, ue(t));
331
331
  var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
332
332
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
333
- }, I = function(t, e, n) {
333
+ }, M = function(t, e, n) {
334
334
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
335
335
  }, k = function(t, e, n) {
336
336
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
337
337
  }, kt = function(t) {
338
338
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
339
- }, wt = function(t) {
339
+ }, yt = function(t) {
340
340
  return { r: k(t.r, 0, 255), g: k(t.g, 0, 255), b: k(t.b, 0, 255), a: k(t.a) };
341
341
  }, st = function(t) {
342
- return { r: I(t.r), g: I(t.g), b: I(t.b), a: I(t.a, 3) };
342
+ return { r: M(t.r), g: M(t.g), b: M(t.b), a: M(t.a, 3) };
343
343
  }, ge = /^#([0-9a-f]{3,8})$/i, J = function(t) {
344
344
  var e = t.toString(16);
345
345
  return e.length < 2 ? "0" + e : e;
@@ -354,7 +354,7 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
354
354
  }, xt = function(t) {
355
355
  return { h: kt(t.h), s: k(t.s, 0, 100), l: k(t.l, 0, 100), a: k(t.a) };
356
356
  }, At = function(t) {
357
- return { h: I(t.h), s: I(t.s), l: I(t.l), a: I(t.a, 3) };
357
+ return { h: M(t.h), s: M(t.s), l: M(t.l), a: M(t.a, 3) };
358
358
  }, Et = function(t) {
359
359
  return _t((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
360
360
  var e, n, o;
@@ -363,10 +363,10 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
363
363
  var e, n, o, i;
364
364
  }, pe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, me = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, be = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ve = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, St = { string: [[function(t) {
365
365
  var e = ge.exec(t);
366
- return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? I(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? I(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
366
+ return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? M(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? M(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
367
367
  }, "hex"], [function(t) {
368
368
  var e = be.exec(t) || ve.exec(t);
369
- return e ? e[2] !== e[4] || e[4] !== e[6] ? null : wt({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
369
+ return e ? e[2] !== e[4] || e[4] !== e[6] ? null : yt({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
370
370
  }, "rgb"], [function(t) {
371
371
  var e = pe.exec(t) || me.exec(t);
372
372
  if (!e)
@@ -375,7 +375,7 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
375
375
  return Et(i);
376
376
  }, "hsl"]], object: [[function(t) {
377
377
  var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
378
- return X(e) && X(n) && X(o) ? wt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
378
+ return X(e) && X(n) && X(o) ? yt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
379
379
  }, "rgb"], [function(t) {
380
380
  var e = t.h, n = t.s, o = t.l, i = t.a, r = i === void 0 ? 1 : i;
381
381
  if (!X(e) || !X(n) || !X(o))
@@ -397,7 +397,7 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
397
397
  return [o, e[n][1]];
398
398
  }
399
399
  return [null, void 0];
400
- }, ye = function(t) {
400
+ }, we = function(t) {
401
401
  return typeof t == "string" ? Ct(t.trim(), St.string) : typeof t == "object" && t !== null ? Ct(t, St.object) : [null, void 0];
402
402
  }, at = function(t, e) {
403
403
  var n = Q(t);
@@ -409,18 +409,18 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
409
409
  return { h: n.h, s: n.s, l: k(n.l + 100 * e, 0, 100), a: n.a };
410
410
  }, Bt = function() {
411
411
  function t(e) {
412
- this.parsed = ye(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
412
+ this.parsed = we(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
413
413
  }
414
414
  return t.prototype.isValid = function() {
415
415
  return this.parsed !== null;
416
416
  }, t.prototype.brightness = function() {
417
- return I(ct(this.rgba), 2);
417
+ return M(ct(this.rgba), 2);
418
418
  }, t.prototype.isDark = function() {
419
419
  return ct(this.rgba) < 0.5;
420
420
  }, t.prototype.isLight = function() {
421
421
  return ct(this.rgba) >= 0.5;
422
422
  }, t.prototype.toHex = function() {
423
- return e = st(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? J(I(255 * r)) : "", "#" + J(n) + J(o) + J(i) + a;
423
+ return e = st(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? J(M(255 * r)) : "", "#" + J(n) + J(o) + J(i) + a;
424
424
  var e, n, o, i, r, a;
425
425
  }, t.prototype.toRgb = function() {
426
426
  return st(this.rgba);
@@ -433,7 +433,7 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
433
433
  return e = At(Q(this.rgba)), n = e.h, o = e.s, i = e.l, (r = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + r + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
434
434
  var e, n, o, i, r;
435
435
  }, t.prototype.toHsv = function() {
436
- return e = Yt(this.rgba), { h: I(e.h), s: I(e.s), v: I(e.v), a: I(e.a, 3) };
436
+ return e = Yt(this.rgba), { h: M(e.h), s: M(e.s), v: M(e.v), a: M(e.a, 3) };
437
437
  var e;
438
438
  }, t.prototype.invert = function() {
439
439
  return Y({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
@@ -451,18 +451,18 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
451
451
  }, t.prototype.rotate = function(e) {
452
452
  return e === void 0 && (e = 15), this.hue(this.hue() + e);
453
453
  }, t.prototype.alpha = function(e) {
454
- return typeof e == "number" ? Y({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : I(this.rgba.a, 3);
454
+ return typeof e == "number" ? Y({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : M(this.rgba.a, 3);
455
455
  var n;
456
456
  }, t.prototype.hue = function(e) {
457
457
  var n = Q(this.rgba);
458
- return typeof e == "number" ? Y({ h: e, s: n.s, l: n.l, a: n.a }) : I(n.h);
458
+ return typeof e == "number" ? Y({ h: e, s: n.s, l: n.l, a: n.a }) : M(n.h);
459
459
  }, t.prototype.isEqual = function(e) {
460
460
  return this.toHex() === Y(e).toHex();
461
461
  }, t;
462
462
  }(), Y = function(t) {
463
463
  return t instanceof Bt ? t : new Bt(t);
464
464
  };
465
- const we = (t) => [
465
+ const ye = (t) => [
466
466
  `background-color:${Y((t == null ? void 0 : t.fill) || P.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? P.fillOpacity : t.fillOpacity).toHex()}`,
467
467
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
468
468
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
@@ -486,7 +486,7 @@ const we = (t) => [
486
486
  const m = r.map((l) => {
487
487
  var x;
488
488
  const p = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (x = l.state) != null && x.selected ? ot : P, g = h && h.paint(l, a) || p;
489
- return `::highlight(_${l.annotation.id}) { ${we(g)} }`;
489
+ return `::highlight(_${l.annotation.id}) { ${ye(g)} }`;
490
490
  });
491
491
  t.innerHTML = m.join(`
492
492
  `), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
@@ -540,10 +540,10 @@ const Ee = (t, e) => {
540
540
  e.innerHTML = "";
541
541
  const p = a.reduce((g, { rects: x }) => [...g, ...x], []);
542
542
  a.forEach((g) => {
543
- const x = g.rects.map((y) => {
543
+ const x = g.rects.map((w) => {
544
544
  const u = document.createElement("span");
545
- u.className = "r6o-annotation", u.dataset.annotation = g.annotation.id, u.style.left = `${y.x}px`, u.style.top = `${y.y}px`, u.style.width = `${y.width}px`, u.style.height = `${y.height}px`;
546
- const d = Ee(y, p), c = qt(g, s, h, f, d), v = Y((c == null ? void 0 : c.fill) || P.fill).alpha((c == null ? void 0 : c.fillOpacity) === void 0 ? P.fillOpacity : c.fillOpacity).toHex();
545
+ u.className = "r6o-annotation", u.dataset.annotation = g.annotation.id, u.style.left = `${w.x}px`, u.style.top = `${w.y}px`, u.style.width = `${w.width}px`, u.style.height = `${w.height}px`;
546
+ const d = Ee(w, p), c = qt(g, s, h, f, d), v = Y((c == null ? void 0 : c.fill) || P.fill).alpha((c == null ? void 0 : c.fillOpacity) === void 0 ? P.fillOpacity : c.fillOpacity).toHex();
547
547
  return u.style.backgroundColor = v, c.underlineStyle && (u.style.borderStyle = c.underlineStyle), c.underlineColor && (u.style.borderColor = c.underlineColor), c.underlineThickness && (u.style.borderBottomWidth = `${c.underlineThickness}px`), c.underlineOffset && (u.style.paddingBottom = `${c.underlineOffset}px`), e.appendChild(u), u;
548
548
  });
549
549
  return { id: g.annotation.id, spans: x };
@@ -635,7 +635,7 @@ function bt(t, e = lt) {
635
635
  }
636
636
  return { set: i, update: r, subscribe: a };
637
637
  }
638
- const Me = (t) => {
638
+ const Oe = (t) => {
639
639
  const { subscribe: e, set: n } = bt();
640
640
  let o;
641
641
  return e((i) => o = i), t.observe(({ changes: i }) => {
@@ -652,8 +652,8 @@ const Me = (t) => {
652
652
  set: n
653
653
  };
654
654
  };
655
- var Oe = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Oe || {});
656
- const dt = { selected: [] }, Ie = (t, e = "EDIT") => {
655
+ var Ie = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Ie || {});
656
+ const dt = { selected: [] }, Me = (t, e = "EDIT") => {
657
657
  const { subscribe: n, set: o } = bt(dt);
658
658
  let i = dt;
659
659
  n((l) => i = l);
@@ -673,8 +673,8 @@ const dt = { selected: [] }, Ie = (t, e = "EDIT") => {
673
673
  } else
674
674
  console.warn("Invalid selection: " + l);
675
675
  }, f = (l, p = !0) => {
676
- const g = Array.isArray(l) ? l : [l], x = g.map((y) => t.getAnnotation(y)).filter(Boolean);
677
- o({ selected: x.map(({ id: y }) => ({ id: y, editable: p })) }), x.length !== g.length && console.warn("Invalid selection", l);
676
+ const g = Array.isArray(l) ? l : [l], x = g.map((w) => t.getAnnotation(w)).filter(Boolean);
677
+ o({ selected: x.map(({ id: w }) => ({ id: w, editable: p })) }), x.length !== g.length && console.warn("Invalid selection", l);
678
678
  }, m = (l) => {
679
679
  if (i.selected.length === 0)
680
680
  return !1;
@@ -709,17 +709,17 @@ for (let t = 0; t < 256; ++t)
709
709
  function Ye(t, e = 0) {
710
710
  return U[t[e + 0]] + U[t[e + 1]] + U[t[e + 2]] + U[t[e + 3]] + "-" + U[t[e + 4]] + U[t[e + 5]] + "-" + U[t[e + 6]] + U[t[e + 7]] + "-" + U[t[e + 8]] + U[t[e + 9]] + "-" + U[t[e + 10]] + U[t[e + 11]] + U[t[e + 12]] + U[t[e + 13]] + U[t[e + 14]] + U[t[e + 15]];
711
711
  }
712
- const _e = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Mt = {
712
+ const _e = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Ot = {
713
713
  randomUUID: _e
714
714
  };
715
715
  function De(t, e, n) {
716
- if (Mt.randomUUID && !e && !t)
717
- return Mt.randomUUID();
716
+ if (Ot.randomUUID && !e && !t)
717
+ return Ot.randomUUID();
718
718
  t = t || {};
719
719
  const o = t.random || (t.rng || ke)();
720
720
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Ye(o);
721
721
  }
722
- const On = (t, e, n, o) => ({
722
+ const In = (t, e, n, o) => ({
723
723
  id: De(),
724
724
  annotation: t.id,
725
725
  created: n || /* @__PURE__ */ new Date(),
@@ -779,7 +779,7 @@ const ze = (t, e) => {
779
779
  ...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
780
780
  const { oldValue: p, newValue: g } = l;
781
781
  if (a.has(g.id)) {
782
- const x = e.updated.find((y) => y.oldValue.id === g.id).newValue;
782
+ const x = e.updated.find((w) => w.oldValue.id === g.id).newValue;
783
783
  return Xt(p, x);
784
784
  } else
785
785
  return l;
@@ -788,50 +788,50 @@ const ze = (t, e) => {
788
788
  ];
789
789
  return { created: h, deleted: f, updated: m };
790
790
  }, We = (t) => t.id !== void 0, qe = () => {
791
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, w = {}) => n.push({ onChange: b, options: w }), i = (b) => {
792
- const w = n.findIndex((A) => A.onChange == b);
793
- w > -1 && n.splice(w, 1);
794
- }, r = (b, w) => {
791
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, y = {}) => n.push({ onChange: b, options: y }), i = (b) => {
792
+ const y = n.findIndex((A) => A.onChange == b);
793
+ y > -1 && n.splice(y, 1);
794
+ }, r = (b, y) => {
795
795
  const A = {
796
796
  origin: b,
797
797
  changes: {
798
- created: w.created || [],
799
- updated: w.updated || [],
800
- deleted: w.deleted || []
798
+ created: y.created || [],
799
+ updated: y.updated || [],
800
+ deleted: y.deleted || []
801
801
  },
802
802
  state: [...t.values()]
803
803
  };
804
804
  n.forEach((S) => {
805
805
  ze(S, A) && S.onChange(A);
806
806
  });
807
- }, a = (b, w = N.LOCAL) => {
807
+ }, a = (b, y = N.LOCAL) => {
808
808
  if (t.get(b.id))
809
809
  throw Error(`Cannot add annotation ${b.id} - exists already`);
810
- t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(w, { created: [b] });
811
- }, s = (b, w) => {
812
- const A = typeof b == "string" ? w : b, S = typeof b == "string" ? b : b.id, R = t.get(S);
810
+ t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(y, { created: [b] });
811
+ }, s = (b, y) => {
812
+ const A = typeof b == "string" ? y : b, S = typeof b == "string" ? b : b.id, R = t.get(S);
813
813
  if (R) {
814
- const M = Xt(R, A);
815
- return S === A.id ? t.set(S, A) : (t.delete(S), t.set(A.id, A)), R.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), M;
814
+ const O = Xt(R, A);
815
+ return S === A.id ? t.set(S, A) : (t.delete(S), t.set(A.id, A)), R.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), O;
816
816
  } else
817
817
  console.warn(`Cannot update annotation ${S} - does not exist`);
818
- }, h = (b, w = N.LOCAL, A = N.LOCAL) => {
819
- const S = We(w) ? A : w, R = s(b, w);
818
+ }, h = (b, y = N.LOCAL, A = N.LOCAL) => {
819
+ const S = We(y) ? A : y, R = s(b, y);
820
820
  R && r(S, { updated: [R] });
821
- }, f = (b, w = N.LOCAL) => {
821
+ }, f = (b, y = N.LOCAL) => {
822
822
  const A = b.reduce((S, R) => {
823
- const M = s(R);
824
- return M ? [...S, M] : S;
823
+ const O = s(R);
824
+ return O ? [...S, O] : S;
825
825
  }, []);
826
- A.length > 0 && r(w, { updated: A });
827
- }, m = (b, w = N.LOCAL) => {
826
+ A.length > 0 && r(y, { updated: A });
827
+ }, m = (b, y = N.LOCAL) => {
828
828
  const A = t.get(b.annotation);
829
829
  if (A) {
830
830
  const S = {
831
831
  ...A,
832
832
  bodies: [...A.bodies, b]
833
833
  };
834
- t.set(A.id, S), e.set(b.id, S.id), r(w, { updated: [{
834
+ t.set(A.id, S), e.set(b.id, S.id), r(y, { updated: [{
835
835
  oldValue: A,
836
836
  newValue: S,
837
837
  bodiesCreated: [b]
@@ -839,51 +839,51 @@ const ze = (t, e) => {
839
839
  } else
840
840
  console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
841
841
  }, l = () => [...t.values()], p = (b = N.LOCAL) => {
842
- const w = [...t.values()];
843
- t.clear(), e.clear(), r(b, { deleted: w });
844
- }, g = (b, w = !0, A = N.LOCAL) => {
845
- if (w) {
842
+ const y = [...t.values()];
843
+ t.clear(), e.clear(), r(b, { deleted: y });
844
+ }, g = (b, y = !0, A = N.LOCAL) => {
845
+ if (y) {
846
846
  const S = [...t.values()];
847
847
  t.clear(), e.clear(), b.forEach((R) => {
848
- t.set(R.id, R), R.bodies.forEach((M) => e.set(M.id, R.id));
848
+ t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
849
849
  }), r(A, { created: b, deleted: S });
850
850
  } else {
851
- const S = b.reduce((R, M) => {
852
- const H = t.get(M.id);
851
+ const S = b.reduce((R, O) => {
852
+ const H = t.get(O.id);
853
853
  return H ? [...R, H] : R;
854
854
  }, []);
855
855
  if (S.length > 0)
856
856
  throw Error(`Bulk insert would overwrite the following annotations: ${S.map((R) => R.id).join(", ")}`);
857
857
  b.forEach((R) => {
858
- t.set(R.id, R), R.bodies.forEach((M) => e.set(M.id, R.id));
858
+ t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
859
859
  }), r(A, { created: b });
860
860
  }
861
861
  }, x = (b) => {
862
- const w = typeof b == "string" ? b : b.id, A = t.get(w);
862
+ const y = typeof b == "string" ? b : b.id, A = t.get(y);
863
863
  if (A)
864
- return t.delete(w), A.bodies.forEach((S) => e.delete(S.id)), A;
865
- console.warn(`Attempt to delete missing annotation: ${w}`);
866
- }, y = (b, w = N.LOCAL) => {
864
+ return t.delete(y), A.bodies.forEach((S) => e.delete(S.id)), A;
865
+ console.warn(`Attempt to delete missing annotation: ${y}`);
866
+ }, w = (b, y = N.LOCAL) => {
867
867
  const A = x(b);
868
- A && r(w, { deleted: [A] });
869
- }, u = (b, w = N.LOCAL) => {
868
+ A && r(y, { deleted: [A] });
869
+ }, u = (b, y = N.LOCAL) => {
870
870
  const A = b.reduce((S, R) => {
871
- const M = x(R);
872
- return M ? [...S, M] : S;
871
+ const O = x(R);
872
+ return O ? [...S, O] : S;
873
873
  }, []);
874
- A.length > 0 && r(w, { deleted: A });
874
+ A.length > 0 && r(y, { deleted: A });
875
875
  }, d = (b) => {
876
- const w = t.get(b.annotation);
877
- if (w) {
878
- const A = w.bodies.find((S) => S.id === b.id);
876
+ const y = t.get(b.annotation);
877
+ if (y) {
878
+ const A = y.bodies.find((S) => S.id === b.id);
879
879
  if (A) {
880
880
  e.delete(A.id);
881
881
  const S = {
882
- ...w,
883
- bodies: w.bodies.filter((R) => R.id !== b.id)
882
+ ...y,
883
+ bodies: y.bodies.filter((R) => R.id !== b.id)
884
884
  };
885
- return t.set(w.id, S), {
886
- oldValue: w,
885
+ return t.set(y.id, S), {
886
+ oldValue: y,
887
887
  newValue: S,
888
888
  bodiesDeleted: [A]
889
889
  };
@@ -891,61 +891,61 @@ const ze = (t, e) => {
891
891
  console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
892
892
  } else
893
893
  console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
894
- }, c = (b, w = N.LOCAL) => {
894
+ }, c = (b, y = N.LOCAL) => {
895
895
  const A = d(b);
896
- A && r(w, { updated: [A] });
897
- }, v = (b, w = N.LOCAL) => {
896
+ A && r(y, { updated: [A] });
897
+ }, v = (b, y = N.LOCAL) => {
898
898
  const A = b.map((S) => d(S)).filter(Boolean);
899
- A.length > 0 && r(w, { updated: A });
899
+ A.length > 0 && r(y, { updated: A });
900
900
  }, C = (b) => {
901
- const w = t.get(b);
902
- return w ? { ...w } : void 0;
901
+ const y = t.get(b);
902
+ return y ? { ...y } : void 0;
903
903
  }, L = (b) => {
904
- const w = e.get(b);
905
- if (w) {
906
- const A = C(w).bodies.find((S) => S.id === b);
904
+ const y = e.get(b);
905
+ if (y) {
906
+ const A = C(y).bodies.find((S) => S.id === b);
907
907
  if (A)
908
908
  return A;
909
909
  console.error(`Store integrity error: body ${b} in index, but not in annotation`);
910
910
  } else
911
911
  console.warn(`Attempt to retrieve missing body: ${b}`);
912
- }, E = (b, w) => {
913
- if (b.annotation !== w.annotation)
912
+ }, E = (b, y) => {
913
+ if (b.annotation !== y.annotation)
914
914
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
915
915
  const A = t.get(b.annotation);
916
916
  if (A) {
917
- const S = A.bodies.find((M) => M.id === b.id), R = {
917
+ const S = A.bodies.find((O) => O.id === b.id), R = {
918
918
  ...A,
919
- bodies: A.bodies.map((M) => M.id === S.id ? w : M)
919
+ bodies: A.bodies.map((O) => O.id === S.id ? y : O)
920
920
  };
921
- return t.set(A.id, R), S.id !== w.id && (e.delete(S.id), e.set(w.id, R.id)), {
921
+ return t.set(A.id, R), S.id !== y.id && (e.delete(S.id), e.set(y.id, R.id)), {
922
922
  oldValue: A,
923
923
  newValue: R,
924
- bodiesUpdated: [{ oldBody: S, newBody: w }]
924
+ bodiesUpdated: [{ oldBody: S, newBody: y }]
925
925
  };
926
926
  } else
927
927
  console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
928
- }, B = (b, w, A = N.LOCAL) => {
929
- const S = E(b, w);
928
+ }, B = (b, y, A = N.LOCAL) => {
929
+ const S = E(b, y);
930
930
  S && r(A, { updated: [S] });
931
- }, T = (b, w = N.LOCAL) => {
931
+ }, T = (b, y = N.LOCAL) => {
932
932
  const A = b.map((S) => E({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
933
- r(w, { updated: A });
934
- }, O = (b) => {
935
- const w = t.get(b.annotation);
936
- if (w) {
933
+ r(y, { updated: A });
934
+ }, I = (b) => {
935
+ const y = t.get(b.annotation);
936
+ if (y) {
937
937
  const A = {
938
- ...w,
938
+ ...y,
939
939
  target: {
940
- ...w.target,
940
+ ...y.target,
941
941
  ...b
942
942
  }
943
943
  };
944
- return t.set(w.id, A), {
945
- oldValue: w,
944
+ return t.set(y.id, A), {
945
+ oldValue: y,
946
946
  newValue: A,
947
947
  targetUpdated: {
948
- oldTarget: w.target,
948
+ oldTarget: y.target,
949
949
  newTarget: b
950
950
  }
951
951
  };
@@ -961,12 +961,12 @@ const ze = (t, e) => {
961
961
  bulkDeleteBodies: v,
962
962
  bulkUpdateAnnotation: f,
963
963
  bulkUpdateBodies: T,
964
- bulkUpdateTargets: (b, w = N.LOCAL) => {
965
- const A = b.map((S) => O(S)).filter(Boolean);
966
- A.length > 0 && r(w, { updated: A });
964
+ bulkUpdateTargets: (b, y = N.LOCAL) => {
965
+ const A = b.map((S) => I(S)).filter(Boolean);
966
+ A.length > 0 && r(y, { updated: A });
967
967
  },
968
968
  clear: p,
969
- deleteAnnotation: y,
969
+ deleteAnnotation: w,
970
970
  deleteBody: c,
971
971
  getAnnotation: C,
972
972
  getBody: L,
@@ -974,9 +974,9 @@ const ze = (t, e) => {
974
974
  unobserve: i,
975
975
  updateAnnotation: h,
976
976
  updateBody: B,
977
- updateTarget: (b, w = N.LOCAL) => {
978
- const A = O(b);
979
- A && r(w, { updated: [A] });
977
+ updateTarget: (b, y = N.LOCAL) => {
978
+ const A = I(b);
979
+ A && r(y, { updated: [A] });
980
980
  }
981
981
  };
982
982
  };
@@ -999,14 +999,14 @@ const Ge = 250, Ke = (t) => {
999
999
  let o = -1, i = !1, r = 0;
1000
1000
  const a = (g) => {
1001
1001
  if (!i) {
1002
- const { changes: x } = g, y = performance.now();
1003
- if (y - r > Ge)
1002
+ const { changes: x } = g, w = performance.now();
1003
+ if (w - r > Ge)
1004
1004
  n.splice(o + 1), n.push(x), o = n.length - 1;
1005
1005
  else {
1006
1006
  const u = n.length - 1;
1007
1007
  n[u] = Fe(n[u], x);
1008
1008
  }
1009
- r = y;
1009
+ r = w;
1010
1010
  }
1011
1011
  i = !1;
1012
1012
  };
@@ -1020,15 +1020,15 @@ const Ge = 250, Ke = (t) => {
1020
1020
  redo: () => {
1021
1021
  if (n.length - 1 > o) {
1022
1022
  i = !0;
1023
- const { created: g, updated: x, deleted: y } = n[o + 1];
1024
- h(g), m(x), p(y), e.emit("redo", n[o + 1]), o += 1;
1023
+ const { created: g, updated: x, deleted: w } = n[o + 1];
1024
+ h(g), m(x), p(w), e.emit("redo", n[o + 1]), o += 1;
1025
1025
  }
1026
1026
  },
1027
1027
  undo: () => {
1028
1028
  if (o > -1) {
1029
1029
  i = !0;
1030
- const { created: g, updated: x, deleted: y } = n[o];
1031
- s(g), f(x), l(y), e.emit("undo", n[o]), o -= 1;
1030
+ const { created: g, updated: x, deleted: w } = n[o];
1031
+ s(g), f(x), l(w), e.emit("undo", n[o]), o -= 1;
1032
1032
  }
1033
1033
  }
1034
1034
  };
@@ -1041,14 +1041,14 @@ const Ge = 250, Ke = (t) => {
1041
1041
  }, Je = (t, e, n, o) => {
1042
1042
  const { store: i, selection: r, hover: a, viewport: s } = t, h = /* @__PURE__ */ new Map();
1043
1043
  let f = [], m;
1044
- const l = (y, u) => {
1045
- h.has(y) ? h.get(y).push(u) : h.set(y, [u]);
1046
- }, p = (y, u) => {
1047
- const d = h.get(y);
1044
+ const l = (w, u) => {
1045
+ h.has(w) ? h.get(w).push(u) : h.set(w, [u]);
1046
+ }, p = (w, u) => {
1047
+ const d = h.get(w);
1048
1048
  d && d.indexOf(u) > 0 && d.splice(d.indexOf(u), 1);
1049
- }, g = (y, u, d) => {
1050
- h.has(y) && setTimeout(() => {
1051
- h.get(y).forEach((c) => {
1049
+ }, g = (w, u, d) => {
1050
+ h.has(w) && setTimeout(() => {
1051
+ h.get(w).forEach((c) => {
1052
1052
  if (n) {
1053
1053
  const v = Array.isArray(u) ? u.map((L) => n.serialize(L)) : n.serialize(u), C = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1054
1054
  c(v, C);
@@ -1057,17 +1057,17 @@ const Ge = 250, Ke = (t) => {
1057
1057
  });
1058
1058
  }, 1);
1059
1059
  };
1060
- r.subscribe(({ selected: y }) => {
1061
- if (!(f.length === 0 && y.length === 0)) {
1062
- if (f.length === 0 && y.length > 0)
1063
- f = y.map(({ id: u }) => i.getAnnotation(u));
1064
- else if (f.length > 0 && y.length === 0)
1060
+ r.subscribe(({ selected: w }) => {
1061
+ if (!(f.length === 0 && w.length === 0)) {
1062
+ if (f.length === 0 && w.length > 0)
1063
+ f = w.map(({ id: u }) => i.getAnnotation(u));
1064
+ else if (f.length > 0 && w.length === 0)
1065
1065
  f.forEach((u) => {
1066
1066
  const d = i.getAnnotation(u.id);
1067
1067
  d && !q(d, u) && g("updateAnnotation", d, u);
1068
1068
  }), f = [];
1069
1069
  else {
1070
- const u = new Set(f.map((c) => c.id)), d = new Set(y.map(({ id: c }) => c));
1070
+ const u = new Set(f.map((c) => c.id)), d = new Set(w.map(({ id: c }) => c));
1071
1071
  f.filter((c) => !d.has(c.id)).forEach((c) => {
1072
1072
  const v = i.getAnnotation(c.id);
1073
1073
  v && !q(v, c) && g("updateAnnotation", v, c);
@@ -1075,16 +1075,16 @@ const Ge = 250, Ke = (t) => {
1075
1075
  // Remove annotations that were deselected
1076
1076
  ...f.filter((c) => d.has(c.id)),
1077
1077
  // Add editable annotations that were selected
1078
- ...y.filter(({ id: c }) => !u.has(c)).map(({ id: c }) => i.getAnnotation(c))
1078
+ ...w.filter(({ id: c }) => !u.has(c)).map(({ id: c }) => i.getAnnotation(c))
1079
1079
  ];
1080
1080
  }
1081
1081
  g("selectionChanged", f);
1082
1082
  }
1083
- }), a.subscribe((y) => {
1084
- !m && y ? g("mouseEnterAnnotation", i.getAnnotation(y)) : m && !y ? g("mouseLeaveAnnotation", i.getAnnotation(m)) : m && y && (g("mouseLeaveAnnotation", i.getAnnotation(m)), g("mouseEnterAnnotation", i.getAnnotation(y))), m = y;
1085
- }), s == null || s.subscribe((y) => g("viewportIntersect", y.map((u) => i.getAnnotation(u)))), i.observe((y) => {
1086
- const { created: u, deleted: d } = y.changes;
1087
- (u || []).forEach((c) => g("createAnnotation", c)), (d || []).forEach((c) => g("deleteAnnotation", c)), (y.changes.updated || []).filter((c) => [
1083
+ }), a.subscribe((w) => {
1084
+ !m && w ? g("mouseEnterAnnotation", i.getAnnotation(w)) : m && !w ? g("mouseLeaveAnnotation", i.getAnnotation(m)) : m && w && (g("mouseLeaveAnnotation", i.getAnnotation(m)), g("mouseEnterAnnotation", i.getAnnotation(w))), m = w;
1085
+ }), s == null || s.subscribe((w) => g("viewportIntersect", w.map((u) => i.getAnnotation(u)))), i.observe((w) => {
1086
+ const { created: u, deleted: d } = w.changes;
1087
+ (u || []).forEach((c) => g("createAnnotation", c)), (d || []).forEach((c) => g("deleteAnnotation", c)), (w.changes.updated || []).filter((c) => [
1088
1088
  ...c.bodiesCreated || [],
1089
1089
  ...c.bodiesDeleted || [],
1090
1090
  ...c.bodiesUpdated || []
@@ -1092,15 +1092,15 @@ const Ge = 250, Ke = (t) => {
1092
1092
  const C = f.find((L) => L.id === c.id) || c;
1093
1093
  f = f.map((L) => L.id === c.id ? v : L), g("updateAnnotation", v, C);
1094
1094
  });
1095
- }, { origin: N.LOCAL }), i.observe((y) => {
1095
+ }, { origin: N.LOCAL }), i.observe((w) => {
1096
1096
  if (f) {
1097
- const u = new Set(f.map((c) => c.id)), d = (y.changes.updated || []).filter(({ newValue: c }) => u.has(c.id)).map(({ newValue: c }) => c);
1097
+ const u = new Set(f.map((c) => c.id)), d = (w.changes.updated || []).filter(({ newValue: c }) => u.has(c.id)).map(({ newValue: c }) => c);
1098
1098
  d.length > 0 && (f = f.map((c) => d.find((C) => C.id === c.id) || c));
1099
1099
  }
1100
1100
  }, { origin: N.REMOTE });
1101
- const x = (y) => (u) => {
1101
+ const x = (w) => (u) => {
1102
1102
  const { updated: d } = u;
1103
- y ? (d || []).forEach((c) => g("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => g("updateAnnotation", c.newValue, c.oldValue));
1103
+ w ? (d || []).forEach((c) => g("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => g("updateAnnotation", c.newValue, c.oldValue));
1104
1104
  };
1105
1105
  return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: l, off: p, emit: g };
1106
1106
  }, Ze = (t) => (e) => e.reduce((n, o) => {
@@ -1146,7 +1146,7 @@ const Ge = 250, Ke = (t) => {
1146
1146
  o.bulkAddAnnotation(u, d, N.REMOTE);
1147
1147
  }, x = (u) => {
1148
1148
  u ? i.setSelected(u) : i.clear();
1149
- }, y = (u) => {
1149
+ }, w = (u) => {
1150
1150
  if (n) {
1151
1151
  const d = n.parse(u).parsed, c = n.serialize(o.getAnnotation(d.id));
1152
1152
  return o.updateAnnotation(d), c;
@@ -1170,7 +1170,7 @@ const Ge = 250, Ke = (t) => {
1170
1170
  setAnnotations: g,
1171
1171
  setSelected: x,
1172
1172
  undo: e.undo,
1173
- updateAnnotation: y
1173
+ updateAnnotation: w
1174
1174
  };
1175
1175
  }, en = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1176
1176
  let nn = (t) => crypto.getRandomValues(new Uint8Array(t)), on = (t, e, n) => {
@@ -1199,24 +1199,29 @@ const an = () => ({ isGuest: !0, id: rn("1234567890abcdefghijklmnopqrstuvwxyzABC
1199
1199
  }
1200
1200
  return `${n}`;
1201
1201
  }, $t = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, ln = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1202
- const { id: o, type: i, purpose: r, value: a, created: s, creator: h, ...f } = n;
1202
+ const { id: o, type: i, purpose: r, value: a, created: s, modified: h, creator: f, ...m } = n;
1203
1203
  return {
1204
1204
  id: o || `temp-${cn(n)}`,
1205
1205
  annotation: e,
1206
1206
  type: i,
1207
1207
  purpose: r,
1208
1208
  value: a,
1209
+ creator: $t(f),
1209
1210
  created: s ? new Date(s) : void 0,
1210
- creator: $t(h),
1211
- ...f
1211
+ updated: h ? new Date(h) : void 0,
1212
+ ...m
1212
1213
  };
1213
1214
  }), dn = (t) => t.map((e) => {
1214
- var n, o;
1215
- const i = { ...e };
1216
- return delete i.annotation, (n = i.id) != null && n.startsWith("temp-") && delete i.id, { ...i, created: (o = i.created) == null ? void 0 : o.toISOString() };
1215
+ var n;
1216
+ const { annotation: o, created: i, updated: r, ...a } = e, s = {
1217
+ ...a,
1218
+ created: i == null ? void 0 : i.toISOString(),
1219
+ modified: r == null ? void 0 : r.toISOString()
1220
+ };
1221
+ return (n = s.id) != null && n.startsWith("temp-") && delete s.id, s;
1217
1222
  });
1218
1223
  sn();
1219
- const In = (t, e) => ({
1224
+ const Mn = (t, e) => ({
1220
1225
  parse: (n) => fn(n),
1221
1226
  serialize: (n) => gn(n, t, e)
1222
1227
  }), un = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, hn = (t) => {
@@ -1284,7 +1289,7 @@ const In = (t, e) => ({
1284
1289
  updated: f,
1285
1290
  ...m
1286
1291
  } = i, l = a.map((p) => {
1287
- const { quote: g, start: x, end: y, range: u } = p, { prefix: d, suffix: c } = te(u, n), v = [{
1292
+ const { quote: g, start: x, end: w, range: u } = p, { prefix: d, suffix: c } = te(u, n), v = [{
1288
1293
  type: "TextQuoteSelector",
1289
1294
  exact: g,
1290
1295
  prefix: d,
@@ -1292,7 +1297,7 @@ const In = (t, e) => ({
1292
1297
  }, {
1293
1298
  type: "TextPositionSelector",
1294
1299
  start: x,
1295
- end: y
1300
+ end: w
1296
1301
  }];
1297
1302
  return {
1298
1303
  ...m,
@@ -1451,10 +1456,10 @@ class bn {
1451
1456
  return s = W(e.slice(n, o + 1)), F(s, this.toBBox), s;
1452
1457
  i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = W([]), s.leaf = !1, s.height = i;
1453
1458
  const h = Math.ceil(r / a), f = h * Math.ceil(Math.sqrt(a));
1454
- Ot(e, n, o, f, this.compareMinX);
1459
+ It(e, n, o, f, this.compareMinX);
1455
1460
  for (let m = n; m <= o; m += f) {
1456
1461
  const l = Math.min(m + f - 1, o);
1457
- Ot(e, m, l, h, this.compareMinY);
1462
+ It(e, m, l, h, this.compareMinY);
1458
1463
  for (let p = m; p <= l; p += h) {
1459
1464
  const g = Math.min(p + h - 1, l);
1460
1465
  s.children.push(this._build(e, p, g, i - 1));
@@ -1499,7 +1504,7 @@ class bn {
1499
1504
  }
1500
1505
  // sorts node children by the best axis for split
1501
1506
  _chooseSplitAxis(e, n, o) {
1502
- const i = e.leaf ? this.compareMinX : yn, r = e.leaf ? this.compareMinY : wn, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1507
+ const i = e.leaf ? this.compareMinX : wn, r = e.leaf ? this.compareMinY : yn, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1503
1508
  a < s && e.children.sort(i);
1504
1509
  }
1505
1510
  // total margin of all possible split distributions where each node is at least m full
@@ -1548,10 +1553,10 @@ function G(t, e, n, o, i) {
1548
1553
  function K(t, e) {
1549
1554
  return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
1550
1555
  }
1551
- function yn(t, e) {
1556
+ function wn(t, e) {
1552
1557
  return t.minX - e.minX;
1553
1558
  }
1554
- function wn(t, e) {
1559
+ function yn(t, e) {
1555
1560
  return t.minY - e.minY;
1556
1561
  }
1557
1562
  function ut(t) {
@@ -1584,7 +1589,7 @@ function W(t) {
1584
1589
  maxY: -1 / 0
1585
1590
  };
1586
1591
  }
1587
- function Ot(t, e, n, o, i) {
1592
+ function It(t, e, n, o, i) {
1588
1593
  const r = [e, n];
1589
1594
  for (; r.length; ) {
1590
1595
  if (n = r.pop(), e = r.pop(), n - e <= o)
@@ -1600,12 +1605,12 @@ const En = (t, e) => {
1600
1605
  return Array.from(E.getClientRects());
1601
1606
  }), C = re(v).map(({ left: L, top: E, right: B, bottom: T }) => new DOMRect(L - c.left, E - c.top, B - L, T - E));
1602
1607
  return C.map((L) => {
1603
- const { x: E, y: B, width: T, height: O } = L;
1608
+ const { x: E, y: B, width: T, height: I } = L;
1604
1609
  return {
1605
1610
  minX: E,
1606
1611
  minY: B,
1607
1612
  maxX: E + T,
1608
- maxY: B + O,
1613
+ maxY: B + I,
1609
1614
  annotation: {
1610
1615
  id: d.annotation,
1611
1616
  rects: C
@@ -1672,39 +1677,39 @@ const En = (t, e) => {
1672
1677
  update: f
1673
1678
  };
1674
1679
  }, Sn = (t, e) => {
1675
- const n = qe(), o = En(n, t), i = Ie(n, e), r = Me(n), a = Qe(), s = (y, u = N.LOCAL) => {
1676
- const d = rt(y, t), c = $(d.target.selector);
1680
+ const n = qe(), o = En(n, t), i = Me(n, e), r = Oe(n), a = Qe(), s = (w, u = N.LOCAL) => {
1681
+ const d = rt(w, t), c = $(d.target.selector);
1677
1682
  return c && n.addAnnotation(d, u), c;
1678
- }, h = (y, u = !0, d = N.LOCAL) => {
1679
- const c = y.map((C) => rt(C, t)), v = c.filter((C) => !$(C.target.selector));
1683
+ }, h = (w, u = !0, d = N.LOCAL) => {
1684
+ const c = w.map((C) => rt(C, t)), v = c.filter((C) => !$(C.target.selector));
1680
1685
  return v.length > 0 ? (console.warn("Could not revive all targets for these annotations:", v), n.bulkAddAnnotation(c, u, d), v) : (n.bulkAddAnnotation(c, u, d), []);
1681
- }, f = (y, u = N.LOCAL) => {
1682
- const d = y.map((v) => rt(v, t)), c = d.filter((v) => !$(v.target.selector));
1686
+ }, f = (w, u = N.LOCAL) => {
1687
+ const d = w.map((v) => rt(v, t)), c = d.filter((v) => !$(v.target.selector));
1683
1688
  return c.length > 0 && console.warn("Could not revive all targets for these annotations:", c), d.forEach((v) => {
1684
1689
  n.getAnnotation(v.id) ? n.updateAnnotation(v, u) : n.addAnnotation(v, u);
1685
1690
  }), c;
1686
- }, m = (y, u = N.LOCAL) => {
1687
- const d = it(y, t);
1691
+ }, m = (w, u = N.LOCAL) => {
1692
+ const d = it(w, t);
1688
1693
  n.updateTarget(d, u);
1689
- }, l = (y, u = N.LOCAL) => {
1690
- const d = y.map((c) => it(c, t));
1694
+ }, l = (w, u = N.LOCAL) => {
1695
+ const d = w.map((c) => it(c, t));
1691
1696
  n.bulkUpdateTargets(d, u);
1692
- }, p = (y, u) => {
1693
- const d = o.getAt(y, u);
1697
+ }, p = (w, u) => {
1698
+ const d = o.getAt(w, u);
1694
1699
  return d ? n.getAnnotation(d) : void 0;
1695
- }, g = (y, u, d, c = 5) => {
1696
- const v = o.getAnnotationRects(y);
1700
+ }, g = (w, u, d, c = 5) => {
1701
+ const v = o.getAnnotationRects(w);
1697
1702
  if (v.length !== 0) {
1698
1703
  if (u && d) {
1699
1704
  const C = v.find(({ top: L, right: E, bottom: B, left: T }) => u >= T - c && u <= E + c && d >= L - c && d <= B + c);
1700
1705
  if (C)
1701
1706
  return C;
1702
1707
  }
1703
- return o.getAnnotationBounds(y);
1708
+ return o.getAnnotationBounds(w);
1704
1709
  }
1705
1710
  }, x = () => o.recalculate();
1706
- return n.observe(({ changes: y }) => {
1707
- const u = (y.created || []).filter((v) => $(v.target.selector)), d = (y.deleted || []).filter((v) => $(v.target.selector)), c = (y.updated || []).filter((v) => $(v.newValue.target.selector));
1711
+ return n.observe(({ changes: w }) => {
1712
+ const u = (w.created || []).filter((v) => $(v.target.selector)), d = (w.deleted || []).filter((v) => $(v.target.selector)), c = (w.updated || []).filter((v) => $(v.newValue.target.selector));
1708
1713
  u.length > 0 && o.set(u.map((v) => v.target), !1), (d == null ? void 0 : d.length) > 0 && d.forEach((v) => o.remove(v.target)), (c == null ? void 0 : c.length) > 0 && c.forEach(({ newValue: v }) => o.update(v.target));
1709
1714
  }), {
1710
1715
  store: {
@@ -1746,8 +1751,8 @@ const En = (t, e) => {
1746
1751
  n.font && (i.font = n.font);
1747
1752
  const x = r.get(l.annotation.id);
1748
1753
  if (x) {
1749
- const { height: y } = l.rects[0], u = l.rects[0].x + p.left, d = l.rects[0].y + p.top;
1750
- i.fillStyle = x.appearance.color, i.fillRect(u - 2, d - 2.5, 2, y + 5);
1754
+ const { height: w } = l.rects[0], u = l.rects[0].x + p.left, d = l.rects[0].y + p.top;
1755
+ i.fillStyle = x.appearance.color, i.fillRect(u - 2, d - 2.5, 2, w + 5);
1751
1756
  const c = i.measureText(x.appearance.label), v = c.width + 6, C = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, L = c.fontBoundingBoxAscent ? 8 : 6.5;
1752
1757
  return i.fillRect(u - 2, d - 2.5 - C, v, C), i.fillStyle = "#fff", i.fillText(x.appearance.label, u + 1, d - L), {
1753
1758
  fill: x.appearance.color,
@@ -1768,7 +1773,7 @@ const En = (t, e) => {
1768
1773
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Pt(t.parentElement);
1769
1774
  }, Bn = (t, e) => (n) => {
1770
1775
  const o = (r) => {
1771
- const a = i.getBoundingClientRect(), s = i.clientHeight, h = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: m, height: l } = e.getAnnotationBounds(n.id), p = f.top - a.top, g = f.left - a.left, x = i.parentElement ? i.scrollTop : 0, y = i.parentElement ? i.scrollLeft : 0, u = p + x - (s - l) / 2, d = g + y - (h - m) / 2;
1776
+ const a = i.getBoundingClientRect(), s = i.clientHeight, h = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: m, height: l } = e.getAnnotationBounds(n.id), p = f.top - a.top, g = f.left - a.left, x = i.parentElement ? i.scrollTop : 0, w = i.parentElement ? i.scrollLeft : 0, u = p + x - (s - l) / 2, d = g + w - (h - m) / 2;
1772
1777
  i.scroll({ top: u, left: d, behavior: "smooth" });
1773
1778
  }, i = Pt(t);
1774
1779
  if (i) {
@@ -1803,9 +1808,9 @@ const En = (t, e) => {
1803
1808
  };
1804
1809
  n && t.addEventListener("selectstart", l);
1805
1810
  const p = pt((u) => {
1806
- var E;
1811
+ var E, B;
1807
1812
  const d = document.getSelection();
1808
- if (!!((E = d.anchorNode.parentElement) != null && E.closest(_))) {
1813
+ if (!!((B = (E = d.anchorNode) == null ? void 0 : E.parentElement) != null && B.closest(_))) {
1809
1814
  s = void 0;
1810
1815
  return;
1811
1816
  }
@@ -1815,12 +1820,12 @@ const En = (t, e) => {
1815
1820
  if (ne(v))
1816
1821
  return;
1817
1822
  const C = Kt(v.cloneRange());
1818
- (C.length !== s.selector.length || C.some((B, T) => {
1819
- var O;
1820
- return B.toString() !== ((O = s.selector[T]) == null ? void 0 : O.quote);
1823
+ (C.length !== s.selector.length || C.some((T, I) => {
1824
+ var b;
1825
+ return T.toString() !== ((b = s.selector[I]) == null ? void 0 : b.quote);
1821
1826
  })) && (s = {
1822
1827
  ...s,
1823
- selector: C.map((B) => se(B, t, o))
1828
+ selector: C.map((T) => se(T, t, o))
1824
1829
  }, i.getAnnotation(s.annotation) ? i.updateTarget(s, N.LOCAL) : (i.addAnnotation({
1825
1830
  id: s.annotation,
1826
1831
  bodies: [],
@@ -1853,13 +1858,13 @@ const En = (t, e) => {
1853
1858
  },
1854
1859
  setUser: h
1855
1860
  };
1856
- }, It = "SPANS", Vn = (t, e = {}) => {
1861
+ }, Mt = "SPANS", Vn = (t, e = {}) => {
1857
1862
  Qt(t);
1858
1863
  const n = Tn(e, {
1859
1864
  annotationEnabled: !0
1860
1865
  }), o = Sn(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Ke(a), h = Je(o, s, n.adapter);
1861
1866
  let f = an();
1862
- const m = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : It : n.renderer || It, l = m === "SPANS" ? Ce(t, o, r) : m === "CSS_HIGHLIGHTS" ? Ae(t, o, r) : m === "CANVAS" ? he(t, o, r) : void 0;
1867
+ const m = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Mt : n.renderer || Mt, l = m === "SPANS" ? Ce(t, o, r) : m === "CSS_HIGHLIGHTS" ? Ae(t, o, r) : m === "CANVAS" ? he(t, o, r) : void 0;
1863
1868
  if (!l)
1864
1869
  throw `Unknown renderer implementation: ${m}`;
1865
1870
  console.debug(`Using ${m} renderer`), n.style && l.setStyle(n.style);
@@ -1895,10 +1900,10 @@ export {
1895
1900
  Vt as NOT_ANNOTATABLE_CLASS,
1896
1901
  _ as NOT_ANNOTATABLE_SELECTOR,
1897
1902
  N as Origin,
1898
- Oe as PointerSelectAction,
1899
- In as W3CTextFormat,
1903
+ Ie as PointerSelectAction,
1904
+ Mn as W3CTextFormat,
1900
1905
  Qt as cancelSingleClickEvents,
1901
- On as createBody,
1906
+ In as createBody,
1902
1907
  he as createCanvasRenderer,
1903
1908
  Ae as createHighlightsRenderer,
1904
1909
  xe as createRenderer,
@@ -1908,7 +1913,7 @@ export {
1908
1913
  pt as debounce,
1909
1914
  Tn as fillDefaults,
1910
1915
  Nn as getAnnotatableFragment,
1911
- Mn as getClientRectsPonyfill,
1916
+ On as getClientRectsPonyfill,
1912
1917
  te as getQuoteContext,
1913
1918
  ft as getRangeAnnotatableContents,
1914
1919
  $ as isRevived,