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

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,22 +1,22 @@
1
- const P = {
1
+ const $ = {
2
2
  fill: "rgb(0, 128, 255)",
3
3
  fillOpacity: 0.18
4
- }, ot = {
4
+ }, et = {
5
5
  fill: "rgb(0, 128, 255)",
6
6
  fillOpacity: 0.45
7
7
  }, qt = (t, e, n, o, i) => {
8
8
  var a, s;
9
- const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? ot : P) : n : (s = t.state) != null && s.selected ? ot : P;
9
+ const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? et : $) : n : (s = t.state) != null && s.selected ? et : $;
10
10
  return o && o.paint(t, e) || r;
11
- }, Vt = "not-annotatable", _ = `.${Vt}`, jt = (t) => {
11
+ }, Ot = "not-annotatable", k = `.${Ot}`, jt = (t) => {
12
12
  var n;
13
13
  const e = t.commonAncestorContainer;
14
- return e instanceof HTMLElement ? !e.closest(_) : !((n = e.parentElement) != null && n.closest(_));
14
+ return e instanceof HTMLElement ? !e.closest(k) : !((n = e.parentElement) != null && n.closest(k));
15
15
  }, Gt = function* (t) {
16
16
  const e = document.createNodeIterator(
17
17
  t.commonAncestorContainer,
18
18
  NodeFilter.SHOW_ELEMENT,
19
- (o) => o instanceof HTMLElement && o.classList.contains(Vt) && !o.parentElement.closest(_) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
19
+ (o) => o instanceof HTMLElement && o.classList.contains(Ot) && !o.parentElement.closest(k) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
20
20
  );
21
21
  let n;
22
22
  for (; n = e.nextNode(); )
@@ -35,23 +35,23 @@ const P = {
35
35
  o.setStartAfter(n), o.collapsed || e.push(o);
36
36
  }
37
37
  return e.length > 0 ? e : [t];
38
- }, ft = (t) => {
38
+ }, ut = (t) => {
39
39
  const e = t.cloneContents();
40
- return e.querySelectorAll(_).forEach((n) => n.remove()), e;
40
+ return e.querySelectorAll(k).forEach((n) => n.remove()), e;
41
41
  }, Qt = (t) => {
42
42
  t.addEventListener("click", (e) => {
43
43
  // Allow clicks within not-annotatable elements
44
- !e.target.closest(_) && !e.target.closest("a") && e.preventDefault();
44
+ !e.target.closest(k) && !e.target.closest("a") && e.preventDefault();
45
45
  });
46
- }, pt = (t, e = 10) => {
46
+ }, ft = (t, e = 10) => {
47
47
  let n;
48
48
  return (...o) => {
49
49
  clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
50
50
  };
51
- }, Nn = (t) => {
51
+ }, In = (t) => {
52
52
  const e = t.cloneContents();
53
- return e.querySelectorAll(_).forEach((n) => n.remove()), e;
54
- }, vt = (t, e) => {
53
+ return e.querySelectorAll(k).forEach((n) => n.remove()), e;
54
+ }, mt = (t, e) => {
55
55
  const n = document.createNodeIterator(e);
56
56
  let o = 0, i = n.nextNode();
57
57
  for (; i !== null; ) {
@@ -59,7 +59,7 @@ const P = {
59
59
  return o;
60
60
  o += 1, i = n.nextNode();
61
61
  }
62
- }, yt = (t, e) => {
62
+ }, bt = (t, e) => {
63
63
  const n = document.createNodeIterator(e);
64
64
  let o = null;
65
65
  for (let i = 0; i < t + 1; i++)
@@ -72,31 +72,31 @@ const P = {
72
72
  startOffset: o,
73
73
  endContainer: i,
74
74
  endOffset: r
75
- } = t, a = Array.from(e.childNodes).map((l) => {
76
- const p = l.cloneNode(!0);
77
- return l.nodeName === "CANVAS" ? l : p;
78
- }), s = vt(n, e), h = vt(i, e), f = () => {
79
- const l = e;
80
- l.replaceChildren(...a);
81
- const p = yt(s, l), g = yt(h, l);
82
- return t.setStart(p, o), t.setEnd(g, r), t;
83
- }, m = (l) => {
84
- const p = document.createElement("SPAN");
85
- return l.surroundContents(p), p;
75
+ } = t, a = Array.from(e.childNodes).map((c) => {
76
+ const m = c.cloneNode(!0);
77
+ return c.nodeName === "CANVAS" ? c : m;
78
+ }), s = mt(n, e), h = mt(i, e), f = () => {
79
+ const c = e;
80
+ c.replaceChildren(...a);
81
+ const m = bt(s, c), g = bt(h, c);
82
+ return t.setStart(m, o), t.setEnd(g, r), t;
83
+ }, b = (c) => {
84
+ const m = document.createElement("SPAN");
85
+ return c.surroundContents(m), m;
86
86
  };
87
87
  if (n === i)
88
88
  throw "Not implemented";
89
89
  {
90
- const l = document.createRange();
91
- l.selectNodeContents(n), l.setStart(n, o);
92
- const p = m(l), g = document.createRange();
90
+ const c = document.createRange();
91
+ c.selectNodeContents(n), c.setStart(n, o);
92
+ const m = b(c), g = document.createRange();
93
93
  g.selectNode(i), g.setEnd(i, r);
94
- const x = m(g), u = Zt(t).reverse().map((d) => {
94
+ const x = b(g), d = Zt(t).reverse().map((u) => {
95
95
  var v;
96
- const c = document.createElement("SPAN");
97
- return (v = d.parentNode) == null || v.insertBefore(c, d), c.appendChild(d), c;
96
+ const l = document.createElement("SPAN");
97
+ return (v = u.parentNode) == null || v.insertBefore(l, u), l.appendChild(u), l;
98
98
  });
99
- return { unwrap: f, nodes: [p, ...u, x] };
99
+ return { unwrap: f, nodes: [m, ...d, x] };
100
100
  }
101
101
  }, Zt = (t) => {
102
102
  const {
@@ -120,14 +120,14 @@ const P = {
120
120
  }, te = (t, e, n = 10, o) => {
121
121
  const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
122
122
  r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
123
- const a = ft(r).textContent, s = document.createRange();
123
+ const a = ut(r).textContent, s = document.createRange();
124
124
  s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
125
- const h = ft(s).textContent;
125
+ const h = ut(s).textContent;
126
126
  return {
127
127
  prefix: a.substring(a.length - n),
128
128
  suffix: h.substring(0, n)
129
129
  };
130
- }, ee = /^\s*$/, ne = (t) => ee.test(t.toString()), $ = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), oe = (t, e) => {
130
+ }, ee = /^\s*$/, ne = (t) => ee.test(t.toString()), D = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), oe = (t, e) => {
131
131
  const n = (r) => Math.round(r * 10) / 10, o = {
132
132
  top: n(t.top),
133
133
  bottom: n(t.bottom),
@@ -178,16 +178,16 @@ const P = {
178
178
  }, []), se = (t, e, n) => {
179
179
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
180
180
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
181
- const r = ft(o).textContent, a = t.toString(), s = r.length || 0, h = s + a.length;
181
+ const r = ut(o).textContent, a = t.toString(), s = r.length || 0, h = s + a.length;
182
182
  return n ? { quote: a, start: s, end: h, range: t, offsetReference: i } : { quote: a, start: s, end: h, range: t };
183
- }, Ut = (t, e) => {
184
- var m, l;
183
+ }, Nt = (t, e) => {
184
+ var b, c;
185
185
  const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
186
186
  e,
187
187
  NodeFilter.SHOW_TEXT,
188
- (p) => {
188
+ (m) => {
189
189
  var g;
190
- return (g = p.parentElement) != null && g.closest(_) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
190
+ return (g = m.parentElement) != null && g.closest(k) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
191
191
  }
192
192
  );
193
193
  let a = 0;
@@ -197,125 +197,125 @@ const P = {
197
197
  let f = !i;
198
198
  for (; h !== null; ) {
199
199
  if (f || (f = i == null ? void 0 : i.contains(h)), f) {
200
- const p = ((m = h.textContent) == null ? void 0 : m.length) || 0;
201
- if (a + p > n) {
200
+ const m = ((b = h.textContent) == null ? void 0 : b.length) || 0;
201
+ if (a + m > n) {
202
202
  s.setStart(h, n - a);
203
203
  break;
204
204
  }
205
- a += p;
205
+ a += m;
206
206
  }
207
207
  h = r.nextNode();
208
208
  }
209
209
  for (; h !== null; ) {
210
- const p = ((l = h.textContent) == null ? void 0 : l.length) || 0;
211
- if (a + p >= o) {
210
+ const m = ((c = h.textContent) == null ? void 0 : c.length) || 0;
211
+ if (a + m >= o) {
212
212
  s.setEnd(h, o - a);
213
213
  break;
214
214
  }
215
- a += p, h = r.nextNode();
215
+ a += m, h = r.nextNode();
216
216
  }
217
217
  return {
218
218
  ...t,
219
219
  range: s
220
220
  };
221
- }, it = (t, e) => $(t.selector) ? t : {
221
+ }, nt = (t, e) => D(t.selector) ? t : {
222
222
  ...t,
223
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Ut(n, e))
224
- }, rt = (t, e) => $(t.target.selector) ? t : { ...t, target: it(t.target, e) }, ae = (t) => {
223
+ selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Nt(n, e))
224
+ }, ot = (t, e) => D(t.target.selector) ? t : { ...t, target: nt(t.target, e) }, ae = (t) => {
225
225
  const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, h = i - e;
226
226
  return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: h };
227
- }, ce = (t) => {
227
+ }, le = (t) => {
228
228
  let e = /* @__PURE__ */ new Set();
229
229
  return (o) => {
230
230
  const i = o.map((r) => r.id);
231
231
  (e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
232
232
  };
233
- }, mt = (t, e, n, o) => {
233
+ }, gt = (t, e, n, o) => {
234
234
  const { store: i, selection: r, hover: a } = e;
235
235
  let s, h, f;
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));
236
+ const b = le(n), c = (p) => {
237
+ const { x: A, y: w } = t.getBoundingClientRect(), S = i.getAt(p.clientX - A, p.clientY - w);
238
+ S && (!h || h(S)) ? a.current !== S.id && (t.classList.add("hovered"), a.set(S.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
239
239
  };
240
- t.addEventListener("pointermove", l);
241
- const p = (T = !1) => {
240
+ t.addEventListener("pointermove", c);
241
+ const m = (p = !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;
245
- return { annotation: D, rects: zt, state: { selected: Ft, hover: Wt, custom: {} } };
243
+ const A = ae(t), { minX: w, minY: S, maxX: B, maxY: I } = A, Y = h ? i.getIntersecting(w, S, B, I).filter(({ annotation: _ }) => h(_)) : i.getIntersecting(w, S, B, I), Ht = r.selected.map(({ id: _ }) => _), Pt = Y.map(({ annotation: _, rects: zt }) => {
244
+ const Ft = Ht.includes(_.id), Wt = _.id === a.current;
245
+ return { annotation: _, 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);
248
- }, g = (T) => {
249
- f = T, p();
250
- }, x = (T) => {
251
- s = T, p();
252
- }, y = (T) => {
253
- h = T, p(!1);
254
- }, u = () => p();
255
- i.observe(u);
256
- const d = r.subscribe(() => p()), c = () => p(!0);
257
- document.addEventListener("scroll", c, { capture: !0, passive: !0 });
258
- const v = pt(() => {
259
- i.recalculatePositions(), f && f.reset(), p();
247
+ o.redraw(Pt, A, s, f, p), setTimeout(() => b(Y.map(({ annotation: _ }) => _)), 1);
248
+ }, g = (p) => {
249
+ f = p, m();
250
+ }, x = (p) => {
251
+ s = p, m();
252
+ }, y = (p) => {
253
+ h = p, m(!1);
254
+ }, d = () => m();
255
+ i.observe(d);
256
+ const u = r.subscribe(() => m()), l = () => m(!0);
257
+ document.addEventListener("scroll", l, { capture: !0, passive: !0 });
258
+ const v = ft(() => {
259
+ i.recalculatePositions(), f && f.reset(), m();
260
260
  });
261
261
  window.addEventListener("resize", v);
262
262
  const C = new ResizeObserver(v);
263
263
  C.observe(t);
264
- const L = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((T) => {
265
- T.every((b) => b.target === t || t.contains(b.target)) || p(!0);
264
+ const L = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((p) => {
265
+ p.every((w) => w.target === t || t.contains(w.target)) || m(!0);
266
266
  });
267
267
  return E.observe(document.body, L), {
268
268
  destroy: () => {
269
- t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(u), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", v), C.disconnect(), E.disconnect();
269
+ t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(d), u(), document.removeEventListener("scroll", l), window.removeEventListener("resize", v), C.disconnect(), E.disconnect();
270
270
  },
271
- redraw: p,
271
+ redraw: m,
272
272
  setStyle: x,
273
273
  setFilter: y,
274
274
  setPainter: g,
275
275
  setVisible: o.setVisible
276
276
  };
277
- }, le = () => {
277
+ }, ce = () => {
278
278
  const t = document.createElement("canvas");
279
279
  return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-highlight-layer bg", t;
280
280
  }, de = (t, e) => {
281
281
  t.width = window.innerWidth, t.height = window.innerHeight;
282
282
  }, ue = (t) => {
283
283
  t.classList.add("r6o-annotatable");
284
- const e = le(), n = e.getContext("2d");
284
+ const e = ce(), n = e.getContext("2d");
285
285
  t.insertBefore(e, t.firstChild);
286
- const o = (s, h, f, m) => requestAnimationFrame(() => {
287
- const { width: l, height: p } = e;
288
- n.clearRect(-0.5, -0.5, l + 1, p + 1), m && m.clear();
286
+ const o = (s, h, f, b) => requestAnimationFrame(() => {
287
+ const { width: c, height: m } = e;
288
+ n.clearRect(-0.5, -0.5, c + 1, m + 1), b && b.clear();
289
289
  const { top: g, left: x } = h;
290
- [...s].sort((u, d) => {
291
- const { annotation: { target: { created: c } } } = u, { annotation: { target: { created: v } } } = d;
292
- return c.getTime() - v.getTime();
293
- }).forEach((u) => {
290
+ [...s].sort((d, u) => {
291
+ const { annotation: { target: { created: l } } } = d, { annotation: { target: { created: v } } } = u;
292
+ return l.getTime() - v.getTime();
293
+ }).forEach((d) => {
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 u = f ? typeof f == "function" ? f(d.annotation, d.state) : f : (L = d.state) != null && L.selected ? et : $, l = b && b.paint(d, h) || u, v = d.rects.map(({ x: E, y: T, width: p, height: A }) => ({
296
296
  x: E + x,
297
- y: B + g,
298
- width: T,
299
- height: O
297
+ y: T + g,
298
+ width: p,
299
+ height: A
300
300
  }));
301
- n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1;
301
+ n.fillStyle = l.fill, n.globalAlpha = l.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: T, width: p, height: A }) => n.fillRect(
305
305
  E,
306
- B - C / 2,
307
- T,
308
- O + C
306
+ T - C / 2,
307
+ p,
308
+ A + C
309
309
  )
310
- ), c.underlineColor) {
311
- n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
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();
310
+ ), l.underlineColor) {
311
+ n.globalAlpha = 1, n.strokeStyle = l.underlineColor, n.lineWidth = l.underlineThickness ?? 1;
312
+ const E = C / 2 + (l.underlineOffset ?? 0);
313
+ v.forEach(({ x: T, y: p, width: A, height: w }) => {
314
+ n.beginPath(), n.moveTo(T, p + w + E), n.lineTo(T + A, p + w + E), n.stroke();
315
315
  });
316
316
  }
317
317
  });
318
- }), i = pt(() => {
318
+ }), i = ft(() => {
319
319
  de(e);
320
320
  });
321
321
  return window.addEventListener("resize", i), {
@@ -327,70 +327,70 @@ const P = {
327
327
  },
328
328
  redraw: o
329
329
  };
330
- }, he = (t, e, n) => mt(t, e, n, ue(t));
330
+ }, he = (t, e, n) => gt(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
- }, k = function(t, e, n) {
335
+ }, U = 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
- }, kt = function(t) {
337
+ }, Ut = function(t) {
338
338
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
339
- }, wt = function(t) {
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
- }, st = function(t) {
342
- return { r: I(t.r), g: I(t.g), b: I(t.b), a: I(t.a, 3) };
343
- }, ge = /^#([0-9a-f]{3,8})$/i, J = function(t) {
339
+ }, vt = function(t) {
340
+ return { r: U(t.r, 0, 255), g: U(t.g, 0, 255), b: U(t.b, 0, 255), a: U(t.a) };
341
+ }, it = function(t) {
342
+ return { r: M(t.r), g: M(t.g), b: M(t.b), a: M(t.a, 3) };
343
+ }, ge = /^#([0-9a-f]{3,8})$/i, K = function(t) {
344
344
  var e = t.toString(16);
345
345
  return e.length < 2 ? "0" + e : e;
346
- }, Yt = function(t) {
346
+ }, Vt = function(t) {
347
347
  var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), a = r - Math.min(e, n, o), s = a ? r === e ? (n - o) / a : r === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
348
348
  return { h: 60 * (s < 0 ? s + 6 : s), s: r ? a / r * 100 : 0, v: r / 255 * 100, a: i };
349
- }, _t = function(t) {
349
+ }, kt = function(t) {
350
350
  var e = t.h, n = t.s, o = t.v, i = t.a;
351
351
  e = e / 360 * 6, n /= 100, o /= 100;
352
352
  var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), h = o * (1 - (1 - e + r) * n), f = r % 6;
353
353
  return { r: 255 * [o, s, a, a, h, o][f], g: 255 * [h, o, o, s, a, a][f], b: 255 * [a, a, h, o, o, s][f], a: i };
354
+ }, yt = function(t) {
355
+ return { h: Ut(t.h), s: U(t.s, 0, 100), l: U(t.l, 0, 100), a: U(t.a) };
356
+ }, wt = function(t) {
357
+ return { h: M(t.h), s: M(t.s), l: M(t.l), a: M(t.a, 3) };
354
358
  }, xt = function(t) {
355
- return { h: kt(t.h), s: k(t.s, 0, 100), l: k(t.l, 0, 100), a: k(t.a) };
356
- }, At = function(t) {
357
- return { h: I(t.h), s: I(t.s), l: I(t.l), a: I(t.a, 3) };
358
- }, Et = function(t) {
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 }));
359
+ return kt((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;
361
- }, Q = function(t) {
362
- return { h: (e = Yt(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
361
+ }, G = function(t) {
362
+ return { h: (e = Vt(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
363
363
  var e, n, o, i;
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) {
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, At = { 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 : vt({ 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)
373
373
  return null;
374
- var n, o, i = xt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (fe[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
375
- return Et(i);
374
+ var n, o, i = yt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (fe[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
375
+ return xt(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) ? vt({ 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))
382
382
  return null;
383
- var a = xt({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
384
- return Et(a);
383
+ var a = yt({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
384
+ return xt(a);
385
385
  }, "hsl"], [function(t) {
386
386
  var e = t.h, n = t.s, o = t.v, i = t.a, r = i === void 0 ? 1 : i;
387
387
  if (!X(e) || !X(n) || !X(o))
388
388
  return null;
389
389
  var a = function(s) {
390
- return { h: kt(s.h), s: k(s.s, 0, 100), v: k(s.v, 0, 100), a: k(s.a) };
390
+ return { h: Ut(s.h), s: U(s.s, 0, 100), v: U(s.v, 0, 100), a: U(s.a) };
391
391
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(r) });
392
- return _t(a);
393
- }, "hsv"]] }, Ct = function(t, e) {
392
+ return kt(a);
393
+ }, "hsv"]] }, Et = function(t, e) {
394
394
  for (var n = 0; n < e.length; n++) {
395
395
  var o = e[n][0](t);
396
396
  if (o)
@@ -398,72 +398,72 @@ var fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
398
398
  }
399
399
  return [null, void 0];
400
400
  }, ye = function(t) {
401
- return typeof t == "string" ? Ct(t.trim(), St.string) : typeof t == "object" && t !== null ? Ct(t, St.object) : [null, void 0];
402
- }, at = function(t, e) {
403
- var n = Q(t);
404
- return { h: n.h, s: k(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
405
- }, ct = function(t) {
401
+ return typeof t == "string" ? Et(t.trim(), At.string) : typeof t == "object" && t !== null ? Et(t, At.object) : [null, void 0];
402
+ }, rt = function(t, e) {
403
+ var n = G(t);
404
+ return { h: n.h, s: U(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
405
+ }, st = function(t) {
406
406
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
407
- }, Lt = function(t, e) {
408
- var n = Q(t);
409
- return { h: n.h, s: n.s, l: k(n.l + 100 * e, 0, 100), a: n.a };
410
- }, Bt = function() {
407
+ }, St = function(t, e) {
408
+ var n = G(t);
409
+ return { h: n.h, s: n.s, l: U(n.l + 100 * e, 0, 100), a: n.a };
410
+ }, Ct = function() {
411
411
  function t(e) {
412
412
  this.parsed = ye(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(st(this.rgba), 2);
418
418
  }, t.prototype.isDark = function() {
419
- return ct(this.rgba) < 0.5;
419
+ return st(this.rgba) < 0.5;
420
420
  }, t.prototype.isLight = function() {
421
- return ct(this.rgba) >= 0.5;
421
+ return st(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 = it(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? K(M(255 * r)) : "", "#" + K(n) + K(o) + K(i) + a;
424
424
  var e, n, o, i, r, a;
425
425
  }, t.prototype.toRgb = function() {
426
- return st(this.rgba);
426
+ return it(this.rgba);
427
427
  }, t.prototype.toRgbString = function() {
428
- return e = st(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
428
+ return e = it(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
429
429
  var e, n, o, i, r;
430
430
  }, t.prototype.toHsl = function() {
431
- return At(Q(this.rgba));
431
+ return wt(G(this.rgba));
432
432
  }, t.prototype.toHslString = function() {
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 + "%)";
433
+ return e = wt(G(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 = Vt(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
- return Y({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
439
+ return V({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
440
440
  var e;
441
441
  }, t.prototype.saturate = function(e) {
442
- return e === void 0 && (e = 0.1), Y(at(this.rgba, e));
442
+ return e === void 0 && (e = 0.1), V(rt(this.rgba, e));
443
443
  }, t.prototype.desaturate = function(e) {
444
- return e === void 0 && (e = 0.1), Y(at(this.rgba, -e));
444
+ return e === void 0 && (e = 0.1), V(rt(this.rgba, -e));
445
445
  }, t.prototype.grayscale = function() {
446
- return Y(at(this.rgba, -1));
446
+ return V(rt(this.rgba, -1));
447
447
  }, t.prototype.lighten = function(e) {
448
- return e === void 0 && (e = 0.1), Y(Lt(this.rgba, e));
448
+ return e === void 0 && (e = 0.1), V(St(this.rgba, e));
449
449
  }, t.prototype.darken = function(e) {
450
- return e === void 0 && (e = 0.1), Y(Lt(this.rgba, -e));
450
+ return e === void 0 && (e = 0.1), V(St(this.rgba, -e));
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" ? V({ 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
- 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);
457
+ var n = G(this.rgba);
458
+ return typeof e == "number" ? V({ h: e, s: n.s, l: n.l, a: n.a }) : M(n.h);
459
459
  }, t.prototype.isEqual = function(e) {
460
- return this.toHex() === Y(e).toHex();
460
+ return this.toHex() === V(e).toHex();
461
461
  }, t;
462
- }(), Y = function(t) {
463
- return t instanceof Bt ? t : new Bt(t);
462
+ }(), V = function(t) {
463
+ return t instanceof Ct ? t : new Ct(t);
464
464
  };
465
465
  const we = (t) => [
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()}`,
466
+ `background-color:${V((t == null ? void 0 : t.fill) || $.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? $.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,
469
469
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
@@ -481,23 +481,23 @@ const we = (t) => [
481
481
  },
482
482
  redraw: (r, a, s, h) => {
483
483
  h && h.clear();
484
- const f = new Set(r.map((l) => l.annotation.id));
485
- Array.from(e).filter((l) => !f.has(l));
486
- const m = r.map((l) => {
484
+ const f = new Set(r.map((c) => c.annotation.id));
485
+ Array.from(e).filter((c) => !f.has(c));
486
+ const b = r.map((c) => {
487
487
  var x;
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)} }`;
488
+ const m = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (x = c.state) != null && x.selected ? et : $, g = h && h.paint(c, a) || m;
489
+ return `::highlight(_${c.annotation.id}) { ${we(g)} }`;
490
490
  });
491
- t.innerHTML = m.join(`
492
- `), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
493
- const p = l.target.selector.map((x) => x.range), g = new Highlight(...p);
494
- CSS.highlights.set(`_${l.id}`, g);
491
+ t.innerHTML = b.join(`
492
+ `), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
493
+ const m = c.target.selector.map((x) => x.range), g = new Highlight(...m);
494
+ CSS.highlights.set(`_${c.id}`, g);
495
495
  }), e = f;
496
496
  }
497
497
  };
498
- }, Ae = (t, e, n) => mt(t, e, n, xe());
499
- var Tt = Object.prototype.hasOwnProperty;
500
- function gt(t, e) {
498
+ }, Ae = (t, e, n) => gt(t, e, n, xe());
499
+ var Lt = Object.prototype.hasOwnProperty;
500
+ function ht(t, e) {
501
501
  var n, o;
502
502
  if (t === e)
503
503
  return !0;
@@ -508,14 +508,14 @@ function gt(t, e) {
508
508
  return t.toString() === e.toString();
509
509
  if (n === Array) {
510
510
  if ((o = t.length) === e.length)
511
- for (; o-- && gt(t[o], e[o]); )
511
+ for (; o-- && ht(t[o], e[o]); )
512
512
  ;
513
513
  return o === -1;
514
514
  }
515
515
  if (!n || typeof t == "object") {
516
516
  o = 0;
517
517
  for (n in t)
518
- if (Tt.call(t, n) && ++o && !Tt.call(e, n) || !(n in e) || !gt(t[n], e[n]))
518
+ if (Lt.call(t, n) && ++o && !Lt.call(e, n) || !(n in e) || !ht(t[n], e[n]))
519
519
  return !1;
520
520
  return Object.keys(e).length === o;
521
521
  }
@@ -534,17 +534,17 @@ const Ee = (t, e) => {
534
534
  destroy: () => {
535
535
  e.remove();
536
536
  },
537
- redraw: (a, s, h, f, m) => {
538
- if (gt(n, a) && m)
537
+ redraw: (a, s, h, f, b) => {
538
+ if (ht(n, a) && b)
539
539
  return;
540
540
  e.innerHTML = "";
541
- const p = a.reduce((g, { rects: x }) => [...g, ...x], []);
541
+ const m = a.reduce((g, { rects: x }) => [...g, ...x], []);
542
542
  a.forEach((g) => {
543
543
  const x = g.rects.map((y) => {
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();
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;
544
+ const d = document.createElement("span");
545
+ d.className = "r6o-annotation", d.dataset.annotation = g.annotation.id, d.style.left = `${y.x}px`, d.style.top = `${y.y}px`, d.style.width = `${y.width}px`, d.style.height = `${y.height}px`;
546
+ const u = Ee(y, m), l = qt(g, s, h, f, u), v = V((l == null ? void 0 : l.fill) || $.fill).alpha((l == null ? void 0 : l.fillOpacity) === void 0 ? $.fillOpacity : l.fillOpacity).toHex();
547
+ return d.style.backgroundColor = v, l.underlineStyle && (d.style.borderStyle = l.underlineStyle), l.underlineColor && (d.style.borderColor = l.underlineColor), l.underlineThickness && (d.style.borderBottomWidth = `${l.underlineThickness}px`), l.underlineOffset && (d.style.paddingBottom = `${l.underlineOffset}px`), e.appendChild(d), d;
548
548
  });
549
549
  return { id: g.annotation.id, spans: x };
550
550
  }), n = a;
@@ -553,32 +553,32 @@ const Ee = (t, e) => {
553
553
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
554
554
  }
555
555
  };
556
- }, Ce = (t, e, n) => mt(t, e, n, Se(t));
557
- let Z;
556
+ }, Ce = (t, e, n) => gt(t, e, n, Se(t));
557
+ let Q;
558
558
  const Le = new Uint8Array(16);
559
- function Be() {
560
- if (!Z && (Z = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Z))
559
+ function Te() {
560
+ if (!Q && (Q = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Q))
561
561
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
562
- return Z(Le);
562
+ return Q(Le);
563
563
  }
564
- const V = [];
564
+ const O = [];
565
565
  for (let t = 0; t < 256; ++t)
566
- V.push((t + 256).toString(16).slice(1));
567
- function Te(t, e = 0) {
568
- return V[t[e + 0]] + V[t[e + 1]] + V[t[e + 2]] + V[t[e + 3]] + "-" + V[t[e + 4]] + V[t[e + 5]] + "-" + V[t[e + 6]] + V[t[e + 7]] + "-" + V[t[e + 8]] + V[t[e + 9]] + "-" + V[t[e + 10]] + V[t[e + 11]] + V[t[e + 12]] + V[t[e + 13]] + V[t[e + 14]] + V[t[e + 15]];
566
+ O.push((t + 256).toString(16).slice(1));
567
+ function Be(t, e = 0) {
568
+ return O[t[e + 0]] + O[t[e + 1]] + O[t[e + 2]] + O[t[e + 3]] + "-" + O[t[e + 4]] + O[t[e + 5]] + "-" + O[t[e + 6]] + O[t[e + 7]] + "-" + O[t[e + 8]] + O[t[e + 9]] + "-" + O[t[e + 10]] + O[t[e + 11]] + O[t[e + 12]] + O[t[e + 13]] + O[t[e + 14]] + O[t[e + 15]];
569
569
  }
570
- const Re = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Rt = {
570
+ const Re = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Tt = {
571
571
  randomUUID: Re
572
572
  };
573
- function Dt(t, e, n) {
574
- if (Rt.randomUUID && !e && !t)
575
- return Rt.randomUUID();
573
+ function Yt(t, e, n) {
574
+ if (Tt.randomUUID && !e && !t)
575
+ return Tt.randomUUID();
576
576
  t = t || {};
577
- const o = t.random || (t.rng || Be)();
578
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Te(o);
577
+ const o = t.random || (t.rng || Te)();
578
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Be(o);
579
579
  }
580
- var Nt = Object.prototype.hasOwnProperty;
581
- function q(t, e) {
580
+ var Bt = Object.prototype.hasOwnProperty;
581
+ function F(t, e) {
582
582
  var n, o;
583
583
  if (t === e)
584
584
  return !0;
@@ -589,54 +589,54 @@ function q(t, e) {
589
589
  return t.toString() === e.toString();
590
590
  if (n === Array) {
591
591
  if ((o = t.length) === e.length)
592
- for (; o-- && q(t[o], e[o]); )
592
+ for (; o-- && F(t[o], e[o]); )
593
593
  ;
594
594
  return o === -1;
595
595
  }
596
596
  if (!n || typeof t == "object") {
597
597
  o = 0;
598
598
  for (n in t)
599
- if (Nt.call(t, n) && ++o && !Nt.call(e, n) || !(n in e) || !q(t[n], e[n]))
599
+ if (Bt.call(t, n) && ++o && !Bt.call(e, n) || !(n in e) || !F(t[n], e[n]))
600
600
  return !1;
601
601
  return Object.keys(e).length === o;
602
602
  }
603
603
  }
604
604
  return t !== t && e !== e;
605
605
  }
606
- function lt() {
606
+ function at() {
607
607
  }
608
- function Ne(t, e) {
608
+ function Ie(t, e) {
609
609
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
610
610
  }
611
- const z = [];
612
- function bt(t, e = lt) {
611
+ const H = [];
612
+ function pt(t, e = at) {
613
613
  let n;
614
614
  const o = /* @__PURE__ */ new Set();
615
615
  function i(s) {
616
- if (Ne(t, s) && (t = s, n)) {
617
- const h = !z.length;
616
+ if (Ie(t, s) && (t = s, n)) {
617
+ const h = !H.length;
618
618
  for (const f of o)
619
- f[1](), z.push(f, t);
619
+ f[1](), H.push(f, t);
620
620
  if (h) {
621
- for (let f = 0; f < z.length; f += 2)
622
- z[f][0](z[f + 1]);
623
- z.length = 0;
621
+ for (let f = 0; f < H.length; f += 2)
622
+ H[f][0](H[f + 1]);
623
+ H.length = 0;
624
624
  }
625
625
  }
626
626
  }
627
627
  function r(s) {
628
628
  i(s(t));
629
629
  }
630
- function a(s, h = lt) {
630
+ function a(s, h = at) {
631
631
  const f = [s, h];
632
- return o.add(f), o.size === 1 && (n = e(i, r) || lt), s(t), () => {
632
+ return o.add(f), o.size === 1 && (n = e(i, r) || at), s(t), () => {
633
633
  o.delete(f), o.size === 0 && n && (n(), n = null);
634
634
  };
635
635
  }
636
636
  return { set: i, update: r, subscribe: a };
637
637
  }
638
638
  const Me = (t) => {
639
- const { subscribe: e, set: n } = bt();
639
+ const { subscribe: e, set: n } = pt();
640
640
  let o;
641
641
  return e((i) => o = i), t.observe(({ changes: i }) => {
642
642
  if (o) {
@@ -653,35 +653,35 @@ const Me = (t) => {
653
653
  };
654
654
  };
655
655
  var Oe = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Oe || {});
656
- const dt = { selected: [] }, Ie = (t, e = "EDIT") => {
657
- const { subscribe: n, set: o } = bt(dt);
658
- let i = dt;
659
- n((l) => i = l);
660
- const r = () => o(dt), a = () => {
661
- var l;
662
- return ((l = i.selected) == null ? void 0 : l.length) === 0;
663
- }, s = (l) => {
656
+ const lt = { selected: [] }, Ne = (t, e = "EDIT") => {
657
+ const { subscribe: n, set: o } = pt(lt);
658
+ let i = lt;
659
+ n((c) => i = c);
660
+ const r = () => o(lt), a = () => {
661
+ var c;
662
+ return ((c = i.selected) == null ? void 0 : c.length) === 0;
663
+ }, s = (c) => {
664
664
  if (i.selected.length === 0)
665
665
  return !1;
666
- const p = typeof l == "string" ? l : l.id;
667
- return i.selected.some((g) => g.id === p);
668
- }, h = (l, p) => {
669
- const g = t.getAnnotation(l);
666
+ const m = typeof c == "string" ? c : c.id;
667
+ return i.selected.some((g) => g.id === m);
668
+ }, h = (c, m) => {
669
+ const g = t.getAnnotation(c);
670
670
  if (g) {
671
- const x = Ve(g, e);
672
- o(x === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: p } : x === "SELECT" ? { selected: [{ id: l }], pointerEvent: p } : { selected: [], pointerEvent: p });
671
+ const x = Ue(g, e);
672
+ o(x === "EDIT" ? { selected: [{ id: c, editable: !0 }], pointerEvent: m } : x === "SELECT" ? { selected: [{ id: c }], pointerEvent: m } : { selected: [], pointerEvent: m });
673
673
  } else
674
- console.warn("Invalid selection: " + l);
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);
678
- }, m = (l) => {
674
+ console.warn("Invalid selection: " + c);
675
+ }, f = (c, m = !0) => {
676
+ const g = Array.isArray(c) ? c : [c], x = g.map((y) => t.getAnnotation(y)).filter(Boolean);
677
+ o({ selected: x.map(({ id: y }) => ({ id: y, editable: m })) }), x.length !== g.length && console.warn("Invalid selection", c);
678
+ }, b = (c) => {
679
679
  if (i.selected.length === 0)
680
680
  return !1;
681
- const { selected: p } = i;
682
- p.filter(({ id: g }) => l.includes(g)).length > 0 && o({ selected: p.filter(({ id: g }) => !l.includes(g)) });
681
+ const { selected: m } = i;
682
+ m.filter(({ id: g }) => c.includes(g)).length > 0 && o({ selected: m.filter(({ id: g }) => !c.includes(g)) });
683
683
  };
684
- return t.observe(({ changes: l }) => m((l.deleted || []).map((p) => p.id))), {
684
+ return t.observe(({ changes: c }) => b((c.deleted || []).map((m) => m.id))), {
685
685
  clear: r,
686
686
  clickSelect: h,
687
687
  get selected() {
@@ -695,37 +695,37 @@ const dt = { selected: [] }, Ie = (t, e = "EDIT") => {
695
695
  setSelected: f,
696
696
  subscribe: n
697
697
  };
698
- }, Ve = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
699
- let tt;
700
- const Ue = new Uint8Array(16);
698
+ }, Ue = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
699
+ let J;
700
+ const Ve = new Uint8Array(16);
701
701
  function ke() {
702
- if (!tt && (tt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !tt))
702
+ if (!J && (J = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !J))
703
703
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
704
- return tt(Ue);
704
+ return J(Ve);
705
705
  }
706
- const U = [];
706
+ const N = [];
707
707
  for (let t = 0; t < 256; ++t)
708
- U.push((t + 256).toString(16).slice(1));
708
+ N.push((t + 256).toString(16).slice(1));
709
709
  function Ye(t, e = 0) {
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]];
710
+ return N[t[e + 0]] + N[t[e + 1]] + N[t[e + 2]] + N[t[e + 3]] + "-" + N[t[e + 4]] + N[t[e + 5]] + "-" + N[t[e + 6]] + N[t[e + 7]] + "-" + N[t[e + 8]] + N[t[e + 9]] + "-" + N[t[e + 10]] + N[t[e + 11]] + N[t[e + 12]] + N[t[e + 13]] + N[t[e + 14]] + N[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), Rt = {
713
713
  randomUUID: _e
714
714
  };
715
- function De(t, e, n) {
716
- if (Mt.randomUUID && !e && !t)
717
- return Mt.randomUUID();
715
+ function Xe(t, e, n) {
716
+ if (Rt.randomUUID && !e && !t)
717
+ return Rt.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
722
  const On = (t, e, n, o) => ({
723
- id: De(),
723
+ id: Xe(),
724
724
  annotation: t.id,
725
725
  created: n || /* @__PURE__ */ new Date(),
726
726
  creator: o,
727
727
  ...e
728
- }), Xe = (t, e) => {
728
+ }), De = (t, e) => {
729
729
  const n = new Set(t.bodies.map((o) => o.id));
730
730
  return e.bodies.filter((o) => !n.has(o.id));
731
731
  }, $e = (t, e) => {
@@ -733,9 +733,9 @@ const On = (t, e, n, o) => ({
733
733
  return t.bodies.filter((o) => !n.has(o.id));
734
734
  }, He = (t, e) => e.bodies.map((n) => {
735
735
  const o = t.bodies.find((i) => i.id === n.id);
736
- return { newBody: n, oldBody: o && !q(o, n) ? o : void 0 };
737
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Pe = (t, e) => !q(t.target, e.target), Xt = (t, e) => {
738
- const n = Xe(t, e), o = $e(t, e), i = He(t, e);
736
+ return { newBody: n, oldBody: o && !F(o, n) ? o : void 0 };
737
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Pe = (t, e) => !F(t.target, e.target), _t = (t, e) => {
738
+ const n = De(t, e), o = $e(t, e), i = He(t, e);
739
739
  return {
740
740
  oldValue: t,
741
741
  newValue: e,
@@ -745,7 +745,7 @@ const On = (t, e, n, o) => ({
745
745
  targetUpdated: Pe(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
746
746
  };
747
747
  };
748
- var N = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(N || {});
748
+ var R = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(R || {});
749
749
  const ze = (t, e) => {
750
750
  var n, o;
751
751
  const { changes: i, origin: r } = e;
@@ -754,7 +754,7 @@ const ze = (t, e) => {
754
754
  if (t.options.ignore) {
755
755
  const { ignore: a } = t.options, s = (h) => h && h.length > 0;
756
756
  if (!(s(i.created) || s(i.deleted))) {
757
- const h = (n = i.updated) == null ? void 0 : n.some((m) => s(m.bodiesCreated) || s(m.bodiesDeleted) || s(m.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((m) => m.targetUpdated);
757
+ const h = (n = i.updated) == null ? void 0 : n.some((b) => s(b.bodiesCreated) || s(b.bodiesDeleted) || s(b.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((b) => b.targetUpdated);
758
758
  if (a === "BODY_ONLY" && h && !f || a === "TARGET_ONLY" && f && !h)
759
759
  return !1;
760
760
  }
@@ -769,214 +769,207 @@ const ze = (t, e) => {
769
769
  } else
770
770
  return !0;
771
771
  }, Fe = (t, e) => {
772
- const n = new Set((t.created || []).map((l) => l.id)), o = new Set((t.updated || []).map(({ newValue: l }) => l.id)), i = new Set((e.created || []).map((l) => l.id)), r = new Set((e.deleted || []).map((l) => l.id)), a = new Set((e.updated || []).map(({ oldValue: l }) => l.id)), s = new Set((e.updated || []).filter(({ oldValue: l }) => n.has(l.id) || o.has(l.id)).map(({ oldValue: l }) => l.id)), h = [
773
- ...(t.created || []).filter((l) => !r.has(l.id)).map((l) => a.has(l.id) ? e.updated.find(({ oldValue: p }) => p.id === l.id).newValue : l),
772
+ const n = new Set((t.created || []).map((c) => c.id)), o = new Set((t.updated || []).map(({ newValue: c }) => c.id)), i = new Set((e.created || []).map((c) => c.id)), r = new Set((e.deleted || []).map((c) => c.id)), a = new Set((e.updated || []).map(({ oldValue: c }) => c.id)), s = new Set((e.updated || []).filter(({ oldValue: c }) => n.has(c.id) || o.has(c.id)).map(({ oldValue: c }) => c.id)), h = [
773
+ ...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue: m }) => m.id === c.id).newValue : c),
774
774
  ...e.created || []
775
775
  ], f = [
776
- ...(t.deleted || []).filter((l) => !i.has(l.id)),
777
- ...(e.deleted || []).filter((l) => !n.has(l.id))
778
- ], m = [
779
- ...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
780
- const { oldValue: p, newValue: g } = l;
776
+ ...(t.deleted || []).filter((c) => !i.has(c.id)),
777
+ ...(e.deleted || []).filter((c) => !n.has(c.id))
778
+ ], b = [
779
+ ...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
780
+ const { oldValue: m, newValue: g } = c;
781
781
  if (a.has(g.id)) {
782
782
  const x = e.updated.find((y) => y.oldValue.id === g.id).newValue;
783
- return Xt(p, x);
783
+ return _t(m, x);
784
784
  } else
785
- return l;
785
+ return c;
786
786
  }),
787
- ...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
787
+ ...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
788
788
  ];
789
- return { created: h, deleted: f, updated: m };
789
+ return { created: h, deleted: f, updated: b };
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) => {
795
- const A = {
796
- origin: b,
791
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (p, A = {}) => n.push({ onChange: p, options: A }), i = (p) => {
792
+ const A = n.findIndex((w) => w.onChange == p);
793
+ A > -1 && n.splice(A, 1);
794
+ }, r = (p, A) => {
795
+ const w = {
796
+ origin: p,
797
797
  changes: {
798
- created: w.created || [],
799
- updated: w.updated || [],
800
- deleted: w.deleted || []
798
+ created: A.created || [],
799
+ updated: A.updated || [],
800
+ deleted: A.deleted || []
801
801
  },
802
802
  state: [...t.values()]
803
803
  };
804
804
  n.forEach((S) => {
805
- ze(S, A) && S.onChange(A);
805
+ ze(S, w) && S.onChange(w);
806
806
  });
807
- }, a = (b, w = N.LOCAL) => {
808
- if (t.get(b.id))
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);
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;
807
+ }, a = (p, A = R.LOCAL) => {
808
+ if (t.get(p.id))
809
+ throw Error(`Cannot add annotation ${p.id} - exists already`);
810
+ t.set(p.id, p), p.bodies.forEach((w) => e.set(w.id, p.id)), r(A, { created: [p] });
811
+ }, s = (p, A) => {
812
+ const w = typeof p == "string" ? A : p, S = typeof p == "string" ? p : p.id, B = t.get(S);
813
+ if (B) {
814
+ const I = _t(B, w);
815
+ return S === w.id ? t.set(S, w) : (t.delete(S), t.set(w.id, w)), B.bodies.forEach((Y) => e.delete(Y.id)), w.bodies.forEach((Y) => e.set(Y.id, w.id)), I;
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);
820
- R && r(S, { updated: [R] });
821
- }, f = (b, w = N.LOCAL) => {
822
- const A = b.reduce((S, R) => {
823
- const M = s(R);
824
- return M ? [...S, M] : S;
818
+ }, h = (p, A = R.LOCAL, w = R.LOCAL) => {
819
+ const S = We(A) ? w : A, B = s(p, A);
820
+ B && r(S, { updated: [B] });
821
+ }, f = (p, A = R.LOCAL) => {
822
+ const w = p.reduce((S, B) => {
823
+ const I = s(B);
824
+ return I ? [...S, I] : S;
825
825
  }, []);
826
- A.length > 0 && r(w, { updated: A });
827
- }, m = (b, w = N.LOCAL) => {
828
- const A = t.get(b.annotation);
829
- if (A) {
826
+ w.length > 0 && r(A, { updated: w });
827
+ }, b = (p, A = R.LOCAL) => {
828
+ const w = t.get(p.annotation);
829
+ if (w) {
830
830
  const S = {
831
- ...A,
832
- bodies: [...A.bodies, b]
831
+ ...w,
832
+ bodies: [...w.bodies, p]
833
833
  };
834
- t.set(A.id, S), e.set(b.id, S.id), r(w, { updated: [{
835
- oldValue: A,
834
+ t.set(w.id, S), e.set(p.id, S.id), r(A, { updated: [{
835
+ oldValue: w,
836
836
  newValue: S,
837
- bodiesCreated: [b]
837
+ bodiesCreated: [p]
838
838
  }] });
839
839
  } else
840
- console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
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) {
840
+ console.warn(`Attempt to add body to missing annotation: ${p.annotation}`);
841
+ }, c = () => [...t.values()], m = (p = R.LOCAL) => {
842
+ const A = [...t.values()];
843
+ t.clear(), e.clear(), r(p, { deleted: A });
844
+ }, g = (p, A = !0, w = R.LOCAL) => {
845
+ if (A) {
846
846
  const S = [...t.values()];
847
- t.clear(), e.clear(), b.forEach((R) => {
848
- t.set(R.id, R), R.bodies.forEach((M) => e.set(M.id, R.id));
849
- }), r(A, { created: b, deleted: S });
847
+ t.clear(), e.clear(), p.forEach((B) => {
848
+ t.set(B.id, B), B.bodies.forEach((I) => e.set(I.id, B.id));
849
+ }), r(w, { created: p, deleted: S });
850
850
  } else {
851
- const S = b.reduce((R, M) => {
852
- const H = t.get(M.id);
853
- return H ? [...R, H] : R;
851
+ const S = p.reduce((B, I) => {
852
+ const Y = t.get(I.id);
853
+ return Y ? [...B, Y] : B;
854
854
  }, []);
855
855
  if (S.length > 0)
856
- throw Error(`Bulk insert would overwrite the following annotations: ${S.map((R) => R.id).join(", ")}`);
857
- b.forEach((R) => {
858
- t.set(R.id, R), R.bodies.forEach((M) => e.set(M.id, R.id));
859
- }), r(A, { created: b });
856
+ throw Error(`Bulk insert would overwrite the following annotations: ${S.map((B) => B.id).join(", ")}`);
857
+ p.forEach((B) => {
858
+ t.set(B.id, B), B.bodies.forEach((I) => e.set(I.id, B.id));
859
+ }), r(w, { created: p });
860
860
  }
861
- }, x = (b) => {
862
- const w = typeof b == "string" ? b : b.id, A = t.get(w);
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) => {
867
- const A = x(b);
868
- A && r(w, { deleted: [A] });
869
- }, u = (b, w = N.LOCAL) => {
870
- const A = b.reduce((S, R) => {
871
- const M = x(R);
872
- return M ? [...S, M] : S;
861
+ }, x = (p) => {
862
+ const A = typeof p == "string" ? p : p.id, w = t.get(A);
863
+ if (w)
864
+ return t.delete(A), w.bodies.forEach((S) => e.delete(S.id)), w;
865
+ console.warn(`Attempt to delete missing annotation: ${A}`);
866
+ }, y = (p, A = R.LOCAL) => {
867
+ const w = x(p);
868
+ w && r(A, { deleted: [w] });
869
+ }, d = (p, A = R.LOCAL) => {
870
+ const w = p.reduce((S, B) => {
871
+ const I = x(B);
872
+ return I ? [...S, I] : S;
873
873
  }, []);
874
- A.length > 0 && r(w, { deleted: A });
875
- }, d = (b) => {
876
- const w = t.get(b.annotation);
874
+ w.length > 0 && r(A, { deleted: w });
875
+ }, u = (p, A = R.LOCAL) => {
876
+ const w = t.get(p.annotation);
877
877
  if (w) {
878
- const A = w.bodies.find((S) => S.id === b.id);
879
- if (A) {
880
- e.delete(A.id);
881
- const S = {
878
+ const S = w.bodies.find((B) => B.id === p.id);
879
+ if (S) {
880
+ e.delete(S.id);
881
+ const B = {
882
882
  ...w,
883
- bodies: w.bodies.filter((R) => R.id !== b.id)
883
+ bodies: w.bodies.filter((I) => I.id !== p.id)
884
884
  };
885
- return t.set(w.id, S), {
885
+ t.set(w.id, B), r(A, { updated: [{
886
886
  oldValue: w,
887
- newValue: S,
888
- bodiesDeleted: [A]
889
- };
887
+ newValue: B,
888
+ bodiesDeleted: [S]
889
+ }] });
890
890
  } else
891
- console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
891
+ console.warn(`Attempt to delete missing body ${p.id} from annotation ${p.annotation}`);
892
892
  } else
893
- console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
894
- }, c = (b, w = N.LOCAL) => {
895
- const A = d(b);
896
- A && r(w, { updated: [A] });
897
- }, v = (b, w = N.LOCAL) => {
898
- const A = b.map((S) => d(S)).filter(Boolean);
899
- A.length > 0 && r(w, { updated: A });
900
- }, C = (b) => {
901
- const w = t.get(b);
902
- return w ? { ...w } : void 0;
903
- }, L = (b) => {
904
- const w = e.get(b);
905
- if (w) {
906
- const A = C(w).bodies.find((S) => S.id === b);
907
- if (A)
908
- return A;
909
- console.error(`Store integrity error: body ${b} in index, but not in annotation`);
893
+ console.warn(`Attempt to delete body from missing annotation ${p.annotation}`);
894
+ }, l = (p) => {
895
+ const A = t.get(p);
896
+ return A ? { ...A } : void 0;
897
+ }, v = (p) => {
898
+ const A = e.get(p);
899
+ if (A) {
900
+ const w = l(A).bodies.find((S) => S.id === p);
901
+ if (w)
902
+ return w;
903
+ console.error(`Store integrity error: body ${p} in index, but not in annotation`);
910
904
  } else
911
- console.warn(`Attempt to retrieve missing body: ${b}`);
912
- }, E = (b, w) => {
913
- if (b.annotation !== w.annotation)
905
+ console.warn(`Attempt to retrieve missing body: ${p}`);
906
+ }, C = (p, A) => {
907
+ if (p.annotation !== A.annotation)
914
908
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
915
- const A = t.get(b.annotation);
916
- if (A) {
917
- const S = A.bodies.find((M) => M.id === b.id), R = {
918
- ...A,
919
- bodies: A.bodies.map((M) => M.id === S.id ? w : M)
909
+ const w = t.get(p.annotation);
910
+ if (w) {
911
+ const S = w.bodies.find((I) => I.id === p.id), B = {
912
+ ...w,
913
+ bodies: w.bodies.map((I) => I.id === S.id ? A : I)
920
914
  };
921
- return t.set(A.id, R), S.id !== w.id && (e.delete(S.id), e.set(w.id, R.id)), {
922
- oldValue: A,
923
- newValue: R,
924
- bodiesUpdated: [{ oldBody: S, newBody: w }]
915
+ return t.set(w.id, B), S.id !== A.id && (e.delete(S.id), e.set(A.id, B.id)), {
916
+ oldValue: w,
917
+ newValue: B,
918
+ bodiesUpdated: [{ oldBody: S, newBody: A }]
925
919
  };
926
920
  } else
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);
930
- S && r(A, { updated: [S] });
931
- }, T = (b, w = N.LOCAL) => {
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) {
937
- const A = {
938
- ...w,
921
+ console.warn(`Attempt to add body to missing annotation ${p.annotation}`);
922
+ }, L = (p, A, w = R.LOCAL) => {
923
+ const S = C(p, A);
924
+ S && r(w, { updated: [S] });
925
+ }, E = (p, A = R.LOCAL) => {
926
+ const w = p.map((S) => C({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
927
+ r(A, { updated: w });
928
+ }, T = (p) => {
929
+ const A = t.get(p.annotation);
930
+ if (A) {
931
+ const w = {
932
+ ...A,
939
933
  target: {
940
- ...w.target,
941
- ...b
934
+ ...A.target,
935
+ ...p
942
936
  }
943
937
  };
944
- return t.set(w.id, A), {
945
- oldValue: w,
946
- newValue: A,
938
+ return t.set(A.id, w), {
939
+ oldValue: A,
940
+ newValue: w,
947
941
  targetUpdated: {
948
- oldTarget: w.target,
949
- newTarget: b
942
+ oldTarget: A.target,
943
+ newTarget: p
950
944
  }
951
945
  };
952
946
  } else
953
- console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
947
+ console.warn(`Attempt to update target on missing annotation: ${p.annotation}`);
954
948
  };
955
949
  return {
956
950
  addAnnotation: a,
957
- addBody: m,
958
- all: l,
951
+ addBody: b,
952
+ all: c,
959
953
  bulkAddAnnotation: g,
960
- bulkDeleteAnnotation: u,
961
- bulkDeleteBodies: v,
954
+ bulkDeleteAnnotation: d,
962
955
  bulkUpdateAnnotation: f,
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 });
956
+ bulkUpdateBodies: E,
957
+ bulkUpdateTargets: (p, A = R.LOCAL) => {
958
+ const w = p.map((S) => T(S)).filter(Boolean);
959
+ w.length > 0 && r(A, { updated: w });
967
960
  },
968
- clear: p,
961
+ clear: m,
969
962
  deleteAnnotation: y,
970
- deleteBody: c,
971
- getAnnotation: C,
972
- getBody: L,
963
+ deleteBody: u,
964
+ getAnnotation: l,
965
+ getBody: v,
973
966
  observe: o,
974
967
  unobserve: i,
975
968
  updateAnnotation: h,
976
- updateBody: B,
977
- updateTarget: (b, w = N.LOCAL) => {
978
- const A = O(b);
979
- A && r(w, { updated: [A] });
969
+ updateBody: L,
970
+ updateTarget: (p, A = R.LOCAL) => {
971
+ const w = T(p);
972
+ w && r(A, { updated: [w] });
980
973
  }
981
974
  };
982
975
  };
@@ -1003,15 +996,15 @@ const Ge = 250, Ke = (t) => {
1003
996
  if (y - r > Ge)
1004
997
  n.splice(o + 1), n.push(x), o = n.length - 1;
1005
998
  else {
1006
- const u = n.length - 1;
1007
- n[u] = Fe(n[u], x);
999
+ const d = n.length - 1;
1000
+ n[d] = Fe(n[d], x);
1008
1001
  }
1009
1002
  r = y;
1010
1003
  }
1011
1004
  i = !1;
1012
1005
  };
1013
- t.observe(a, { origin: N.LOCAL });
1014
- const s = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), h = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), f = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: x }) => x)), m = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: x }) => x)), l = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), p = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
1006
+ t.observe(a, { origin: R.LOCAL });
1007
+ const s = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), h = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), f = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: x }) => x)), b = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: x }) => x)), c = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), m = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
1015
1008
  return {
1016
1009
  canRedo: () => n.length - 1 > o,
1017
1010
  canUndo: () => o > -1,
@@ -1021,88 +1014,88 @@ const Ge = 250, Ke = (t) => {
1021
1014
  if (n.length - 1 > o) {
1022
1015
  i = !0;
1023
1016
  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;
1017
+ h(g), b(x), m(y), e.emit("redo", n[o + 1]), o += 1;
1025
1018
  }
1026
1019
  },
1027
1020
  undo: () => {
1028
1021
  if (o > -1) {
1029
1022
  i = !0;
1030
1023
  const { created: g, updated: x, deleted: y } = n[o];
1031
- s(g), f(x), l(y), e.emit("undo", n[o]), o -= 1;
1024
+ s(g), f(x), c(y), e.emit("undo", n[o]), o -= 1;
1032
1025
  }
1033
1026
  }
1034
1027
  };
1035
1028
  }, Qe = () => {
1036
- const { subscribe: t, set: e } = bt([]);
1029
+ const { subscribe: t, set: e } = pt([]);
1037
1030
  return {
1038
1031
  subscribe: t,
1039
1032
  set: e
1040
1033
  };
1041
1034
  }, Je = (t, e, n, o) => {
1042
1035
  const { store: i, selection: r, hover: a, viewport: s } = t, h = /* @__PURE__ */ new Map();
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);
1048
- d && d.indexOf(u) > 0 && d.splice(d.indexOf(u), 1);
1049
- }, g = (y, u, d) => {
1036
+ let f = [], b;
1037
+ const c = (y, d) => {
1038
+ h.has(y) ? h.get(y).push(d) : h.set(y, [d]);
1039
+ }, m = (y, d) => {
1040
+ const u = h.get(y);
1041
+ u && u.indexOf(d) > 0 && u.splice(u.indexOf(d), 1);
1042
+ }, g = (y, d, u) => {
1050
1043
  h.has(y) && setTimeout(() => {
1051
- h.get(y).forEach((c) => {
1044
+ h.get(y).forEach((l) => {
1052
1045
  if (n) {
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
- c(v, C);
1046
+ const v = Array.isArray(d) ? d.map((L) => n.serialize(L)) : n.serialize(d), C = u ? u instanceof PointerEvent ? u : n.serialize(u) : void 0;
1047
+ l(v, C);
1055
1048
  } else
1056
- c(u, d);
1049
+ l(d, u);
1057
1050
  });
1058
1051
  }, 1);
1059
1052
  };
1060
1053
  r.subscribe(({ selected: y }) => {
1061
1054
  if (!(f.length === 0 && y.length === 0)) {
1062
1055
  if (f.length === 0 && y.length > 0)
1063
- f = y.map(({ id: u }) => i.getAnnotation(u));
1056
+ f = y.map(({ id: d }) => i.getAnnotation(d));
1064
1057
  else if (f.length > 0 && y.length === 0)
1065
- f.forEach((u) => {
1066
- const d = i.getAnnotation(u.id);
1067
- d && !q(d, u) && g("updateAnnotation", d, u);
1058
+ f.forEach((d) => {
1059
+ const u = i.getAnnotation(d.id);
1060
+ u && !F(u, d) && g("updateAnnotation", u, d);
1068
1061
  }), f = [];
1069
1062
  else {
1070
- const u = new Set(f.map((c) => c.id)), d = new Set(y.map(({ id: c }) => c));
1071
- f.filter((c) => !d.has(c.id)).forEach((c) => {
1072
- const v = i.getAnnotation(c.id);
1073
- v && !q(v, c) && g("updateAnnotation", v, c);
1063
+ const d = new Set(f.map((l) => l.id)), u = new Set(y.map(({ id: l }) => l));
1064
+ f.filter((l) => !u.has(l.id)).forEach((l) => {
1065
+ const v = i.getAnnotation(l.id);
1066
+ v && !F(v, l) && g("updateAnnotation", v, l);
1074
1067
  }), f = [
1075
1068
  // Remove annotations that were deselected
1076
- ...f.filter((c) => d.has(c.id)),
1069
+ ...f.filter((l) => u.has(l.id)),
1077
1070
  // Add editable annotations that were selected
1078
- ...y.filter(({ id: c }) => !u.has(c)).map(({ id: c }) => i.getAnnotation(c))
1071
+ ...y.filter(({ id: l }) => !d.has(l)).map(({ id: l }) => i.getAnnotation(l))
1079
1072
  ];
1080
1073
  }
1081
1074
  g("selectionChanged", f);
1082
1075
  }
1083
1076
  }), 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) => [
1088
- ...c.bodiesCreated || [],
1089
- ...c.bodiesDeleted || [],
1090
- ...c.bodiesUpdated || []
1091
- ].length > 0).forEach(({ oldValue: c, newValue: v }) => {
1092
- const C = f.find((L) => L.id === c.id) || c;
1093
- f = f.map((L) => L.id === c.id ? v : L), g("updateAnnotation", v, C);
1077
+ !b && y ? g("mouseEnterAnnotation", i.getAnnotation(y)) : b && !y ? g("mouseLeaveAnnotation", i.getAnnotation(b)) : b && y && (g("mouseLeaveAnnotation", i.getAnnotation(b)), g("mouseEnterAnnotation", i.getAnnotation(y))), b = y;
1078
+ }), s == null || s.subscribe((y) => g("viewportIntersect", y.map((d) => i.getAnnotation(d)))), i.observe((y) => {
1079
+ const { created: d, deleted: u } = y.changes;
1080
+ (d || []).forEach((l) => g("createAnnotation", l)), (u || []).forEach((l) => g("deleteAnnotation", l)), (y.changes.updated || []).filter((l) => [
1081
+ ...l.bodiesCreated || [],
1082
+ ...l.bodiesDeleted || [],
1083
+ ...l.bodiesUpdated || []
1084
+ ].length > 0).forEach(({ oldValue: l, newValue: v }) => {
1085
+ const C = f.find((L) => L.id === l.id) || l;
1086
+ f = f.map((L) => L.id === l.id ? v : L), g("updateAnnotation", v, C);
1094
1087
  });
1095
- }, { origin: N.LOCAL }), i.observe((y) => {
1088
+ }, { origin: R.LOCAL }), i.observe((y) => {
1096
1089
  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);
1098
- d.length > 0 && (f = f.map((c) => d.find((C) => C.id === c.id) || c));
1090
+ const d = new Set(f.map((l) => l.id)), u = (y.changes.updated || []).filter(({ newValue: l }) => d.has(l.id)).map(({ newValue: l }) => l);
1091
+ u.length > 0 && (f = f.map((l) => u.find((C) => C.id === l.id) || l));
1099
1092
  }
1100
- }, { origin: N.REMOTE });
1101
- const x = (y) => (u) => {
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));
1093
+ }, { origin: R.REMOTE });
1094
+ const x = (y) => (d) => {
1095
+ const { updated: u } = d;
1096
+ y ? (u || []).forEach((l) => g("updateAnnotation", l.oldValue, l.newValue)) : (u || []).forEach((l) => g("updateAnnotation", l.newValue, l.oldValue));
1104
1097
  };
1105
- return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: l, off: p, emit: g };
1098
+ return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: m, emit: g };
1106
1099
  }, Ze = (t) => (e) => e.reduce((n, o) => {
1107
1100
  const { parsed: i, error: r } = t.parse(o);
1108
1101
  return r ? {
@@ -1115,44 +1108,44 @@ const Ge = 250, Ke = (t) => {
1115
1108
  ...n
1116
1109
  };
1117
1110
  }, { parsed: [], failed: [] }), tn = (t, e, n) => {
1118
- const { store: o, selection: i } = t, r = (u) => {
1111
+ const { store: o, selection: i } = t, r = (d) => {
1119
1112
  if (n) {
1120
- const { parsed: d, error: c } = n.parse(u);
1121
- d ? o.addAnnotation(d, N.REMOTE) : console.error(c);
1113
+ const { parsed: u, error: l } = n.parse(d);
1114
+ u ? o.addAnnotation(u, R.REMOTE) : console.error(l);
1122
1115
  } else
1123
- o.addAnnotation(u, N.REMOTE);
1124
- }, a = () => i.clear(), s = () => o.clear(), h = (u) => {
1125
- const d = o.getAnnotation(u);
1126
- return n && d ? n.serialize(d) : d;
1127
- }, f = () => n ? o.all().map(n.serialize) : o.all(), m = () => {
1128
- var u;
1129
- const d = (((u = i.selected) == null ? void 0 : u.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
1130
- return n ? d.map(n.serialize) : d;
1131
- }, l = (u, d = !0) => fetch(u).then((c) => c.json()).then((c) => (g(c, d), c)), p = (u) => {
1132
- if (typeof u == "string") {
1133
- const d = o.getAnnotation(u);
1134
- if (o.deleteAnnotation(u), d)
1135
- return n ? n.serialize(d) : d;
1116
+ o.addAnnotation(d, R.REMOTE);
1117
+ }, a = () => i.clear(), s = () => o.clear(), h = (d) => {
1118
+ const u = o.getAnnotation(d);
1119
+ return n && u ? n.serialize(u) : u;
1120
+ }, f = () => n ? o.all().map(n.serialize) : o.all(), b = () => {
1121
+ var d;
1122
+ const u = (((d = i.selected) == null ? void 0 : d.map((l) => l.id)) || []).map((l) => o.getAnnotation(l)).filter(Boolean);
1123
+ return n ? u.map(n.serialize) : u;
1124
+ }, c = (d, u = !0) => fetch(d).then((l) => l.json()).then((l) => (g(l, u), l)), m = (d) => {
1125
+ if (typeof d == "string") {
1126
+ const u = o.getAnnotation(d);
1127
+ if (o.deleteAnnotation(d), u)
1128
+ return n ? n.serialize(u) : u;
1136
1129
  } else {
1137
- const d = n ? n.parse(u).parsed : u;
1138
- if (d)
1139
- return o.deleteAnnotation(d), u;
1130
+ const u = n ? n.parse(d).parsed : d;
1131
+ if (u)
1132
+ return o.deleteAnnotation(u), d;
1140
1133
  }
1141
- }, g = (u, d = !0) => {
1134
+ }, g = (d, u = !0) => {
1142
1135
  if (n) {
1143
- const { parsed: c, failed: v } = Ze(n)(u);
1144
- v.length > 0 && console.warn(`Discarded ${v.length} invalid annotations`, v), o.bulkAddAnnotation(c, d, N.REMOTE);
1136
+ const { parsed: l, failed: v } = Ze(n)(d);
1137
+ v.length > 0 && console.warn(`Discarded ${v.length} invalid annotations`, v), o.bulkAddAnnotation(l, u, R.REMOTE);
1145
1138
  } else
1146
- o.bulkAddAnnotation(u, d, N.REMOTE);
1147
- }, x = (u) => {
1148
- u ? i.setSelected(u) : i.clear();
1149
- }, y = (u) => {
1139
+ o.bulkAddAnnotation(d, u, R.REMOTE);
1140
+ }, x = (d) => {
1141
+ d ? i.setSelected(d) : i.clear();
1142
+ }, y = (d) => {
1150
1143
  if (n) {
1151
- const d = n.parse(u).parsed, c = n.serialize(o.getAnnotation(d.id));
1152
- return o.updateAnnotation(d), c;
1144
+ const u = n.parse(d).parsed, l = n.serialize(o.getAnnotation(u.id));
1145
+ return o.updateAnnotation(u), l;
1153
1146
  } else {
1154
- const d = o.getAnnotation(u.id);
1155
- return o.updateAnnotation(u), d;
1147
+ const u = o.getAnnotation(d.id);
1148
+ return o.updateAnnotation(d), u;
1156
1149
  }
1157
1150
  };
1158
1151
  return {
@@ -1163,10 +1156,10 @@ const Ge = 250, Ke = (t) => {
1163
1156
  clearAnnotations: s,
1164
1157
  getAnnotationById: h,
1165
1158
  getAnnotations: f,
1166
- getSelected: m,
1167
- loadAnnotations: l,
1159
+ getSelected: b,
1160
+ loadAnnotations: c,
1168
1161
  redo: e.redo,
1169
- removeAnnotation: p,
1162
+ removeAnnotation: m,
1170
1163
  setAnnotations: g,
1171
1164
  setSelected: x,
1172
1165
  undo: e.undo,
@@ -1190,7 +1183,7 @@ let nn = (t) => crypto.getRandomValues(new Uint8Array(t)), on = (t, e, n) => {
1190
1183
  e += en[n[t] & 63];
1191
1184
  return e;
1192
1185
  };
1193
- const an = () => ({ isGuest: !0, id: rn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), cn = (t) => {
1186
+ const an = () => ({ isGuest: !0, id: rn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), ln = (t) => {
1194
1187
  const e = JSON.stringify(t);
1195
1188
  let n = 0;
1196
1189
  for (let o = 0, i = e.length; o < i; o++) {
@@ -1198,16 +1191,16 @@ const an = () => ({ isGuest: !0, id: rn("1234567890abcdefghijklmnopqrstuvwxyzABC
1198
1191
  n = (n << 5) - n + r, n |= 0;
1199
1192
  }
1200
1193
  return `${n}`;
1201
- }, $t = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, ln = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1194
+ }, Xt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, cn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1202
1195
  const { id: o, type: i, purpose: r, value: a, created: s, creator: h, ...f } = n;
1203
1196
  return {
1204
- id: o || `temp-${cn(n)}`,
1197
+ id: o || `temp-${ln(n)}`,
1205
1198
  annotation: e,
1206
1199
  type: i,
1207
1200
  purpose: r,
1208
1201
  value: a,
1209
1202
  created: s ? new Date(s) : void 0,
1210
- creator: $t(h),
1203
+ creator: Xt(h),
1211
1204
  ...f
1212
1205
  };
1213
1206
  }), dn = (t) => t.map((e) => {
@@ -1216,7 +1209,7 @@ const an = () => ({ isGuest: !0, id: rn("1234567890abcdefghijklmnopqrstuvwxyzABC
1216
1209
  return delete i.annotation, (n = i.id) != null && n.startsWith("temp-") && delete i.id, { ...i, created: (o = i.created) == null ? void 0 : o.toISOString() };
1217
1210
  });
1218
1211
  sn();
1219
- const In = (t, e) => ({
1212
+ const Nn = (t, e) => ({
1220
1213
  parse: (n) => fn(n),
1221
1214
  serialize: (n) => gn(n, t, e)
1222
1215
  }), un = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, hn = (t) => {
@@ -1230,7 +1223,7 @@ const In = (t, e) => ({
1230
1223
  if (a.length === 0)
1231
1224
  return { error: Error(`No targets found for annotation: ${t.id}`) };
1232
1225
  const s = {
1233
- creator: $t(n),
1226
+ creator: Xt(n),
1234
1227
  created: o ? new Date(o) : void 0,
1235
1228
  updated: i ? new Date(i) : void 0,
1236
1229
  annotation: e,
@@ -1238,36 +1231,36 @@ const In = (t, e) => ({
1238
1231
  styleClass: a[0].styleClass
1239
1232
  };
1240
1233
  for (const h of a) {
1241
- const m = (Array.isArray(h.selector) ? h.selector : [h.selector]).reduce((l, p) => {
1242
- switch (p.type) {
1234
+ const b = (Array.isArray(h.selector) ? h.selector : [h.selector]).reduce((c, m) => {
1235
+ switch (m.type) {
1243
1236
  case "TextQuoteSelector":
1244
- l.quote = p.exact;
1237
+ c.quote = m.exact;
1245
1238
  break;
1246
1239
  case "TextPositionSelector":
1247
- l.start = p.start, l.end = p.end;
1240
+ c.start = m.start, c.end = m.end;
1248
1241
  break;
1249
1242
  }
1250
- return l;
1243
+ return c;
1251
1244
  }, {});
1252
- if (un(m))
1253
- s.selector.push({ id: h.id, ...m });
1245
+ if (un(b))
1246
+ s.selector.push({ id: h.id, ...b });
1254
1247
  else {
1255
- const l = [
1256
- m.start ? void 0 : "TextPositionSelector",
1257
- m.quote ? void 0 : "TextQuoteSelector"
1248
+ const c = [
1249
+ b.start ? void 0 : "TextPositionSelector",
1250
+ b.quote ? void 0 : "TextQuoteSelector"
1258
1251
  ].filter(Boolean);
1259
- return { error: Error(`Missing selector types: ${l.join(" and ")} for annotation: ${t.id}`) };
1252
+ return { error: Error(`Missing selector types: ${c.join(" and ")} for annotation: ${t.id}`) };
1260
1253
  }
1261
1254
  }
1262
1255
  return { parsed: s };
1263
1256
  }, fn = (t) => {
1264
- const e = t.id || Dt(), {
1257
+ const e = t.id || Yt(), {
1265
1258
  creator: n,
1266
1259
  created: o,
1267
1260
  modified: i,
1268
1261
  body: r,
1269
1262
  ...a
1270
- } = t, s = ln(r, e), h = hn(t);
1263
+ } = t, s = cn(r, e), h = hn(t);
1271
1264
  return "error" in h ? { error: h.error } : {
1272
1265
  parsed: {
1273
1266
  ...a,
@@ -1282,21 +1275,21 @@ const In = (t, e) => ({
1282
1275
  creator: s,
1283
1276
  created: h,
1284
1277
  updated: f,
1285
- ...m
1286
- } = i, l = a.map((p) => {
1287
- const { quote: g, start: x, end: y, range: u } = p, { prefix: d, suffix: c } = te(u, n), v = [{
1278
+ ...b
1279
+ } = i, c = a.map((m) => {
1280
+ const { quote: g, start: x, end: y, range: d } = m, { prefix: u, suffix: l } = te(d, n), v = [{
1288
1281
  type: "TextQuoteSelector",
1289
1282
  exact: g,
1290
- prefix: d,
1291
- suffix: c
1283
+ prefix: u,
1284
+ suffix: l
1292
1285
  }, {
1293
1286
  type: "TextPositionSelector",
1294
1287
  start: x,
1295
1288
  end: y
1296
1289
  }];
1297
1290
  return {
1298
- ...m,
1299
- id: p.id,
1291
+ ...b,
1292
+ id: m.id,
1300
1293
  source: e,
1301
1294
  selector: v
1302
1295
  };
@@ -1310,29 +1303,29 @@ const In = (t, e) => ({
1310
1303
  creator: s,
1311
1304
  created: h == null ? void 0 : h.toISOString(),
1312
1305
  modified: f == null ? void 0 : f.toISOString(),
1313
- target: l
1306
+ target: c
1314
1307
  };
1315
1308
  };
1316
1309
  function pn(t, e, n, o, i) {
1317
- Ht(t, e, n || 0, o || t.length - 1, i || mn);
1310
+ Dt(t, e, n || 0, o || t.length - 1, i || mn);
1318
1311
  }
1319
- function Ht(t, e, n, o, i) {
1312
+ function Dt(t, e, n, o, i) {
1320
1313
  for (; o > n; ) {
1321
1314
  if (o - n > 600) {
1322
- var r = o - n + 1, a = e - n + 1, s = Math.log(r), h = 0.5 * Math.exp(2 * s / 3), f = 0.5 * Math.sqrt(s * h * (r - h) / r) * (a - r / 2 < 0 ? -1 : 1), m = Math.max(n, Math.floor(e - a * h / r + f)), l = Math.min(o, Math.floor(e + (r - a) * h / r + f));
1323
- Ht(t, e, m, l, i);
1315
+ var r = o - n + 1, a = e - n + 1, s = Math.log(r), h = 0.5 * Math.exp(2 * s / 3), f = 0.5 * Math.sqrt(s * h * (r - h) / r) * (a - r / 2 < 0 ? -1 : 1), b = Math.max(n, Math.floor(e - a * h / r + f)), c = Math.min(o, Math.floor(e + (r - a) * h / r + f));
1316
+ Dt(t, e, b, c, i);
1324
1317
  }
1325
- var p = t[e], g = n, x = o;
1326
- for (j(t, n, e), i(t[o], p) > 0 && j(t, n, o); g < x; ) {
1327
- for (j(t, g, x), g++, x--; i(t[g], p) < 0; )
1318
+ var m = t[e], g = n, x = o;
1319
+ for (W(t, n, e), i(t[o], m) > 0 && W(t, n, o); g < x; ) {
1320
+ for (W(t, g, x), g++, x--; i(t[g], m) < 0; )
1328
1321
  g++;
1329
- for (; i(t[x], p) > 0; )
1322
+ for (; i(t[x], m) > 0; )
1330
1323
  x--;
1331
1324
  }
1332
- i(t[n], p) === 0 ? j(t, n, x) : (x++, j(t, x, o)), x <= e && (n = x + 1), e <= x && (o = x - 1);
1325
+ i(t[n], m) === 0 ? W(t, n, x) : (x++, W(t, x, o)), x <= e && (n = x + 1), e <= x && (o = x - 1);
1333
1326
  }
1334
1327
  }
1335
- function j(t, e, n) {
1328
+ function W(t, e, n) {
1336
1329
  var o = t[e];
1337
1330
  t[e] = t[n], t[n] = o;
1338
1331
  }
@@ -1349,13 +1342,13 @@ class bn {
1349
1342
  search(e) {
1350
1343
  let n = this.data;
1351
1344
  const o = [];
1352
- if (!nt(e, n))
1345
+ if (!tt(e, n))
1353
1346
  return o;
1354
1347
  const i = this.toBBox, r = [];
1355
1348
  for (; n; ) {
1356
1349
  for (let a = 0; a < n.children.length; a++) {
1357
1350
  const s = n.children[a], h = n.leaf ? i(s) : s;
1358
- nt(e, h) && (n.leaf ? o.push(s) : ht(e, h) ? this._all(s, o) : r.push(s));
1351
+ tt(e, h) && (n.leaf ? o.push(s) : dt(e, h) ? this._all(s, o) : r.push(s));
1359
1352
  }
1360
1353
  n = r.pop();
1361
1354
  }
@@ -1363,14 +1356,14 @@ class bn {
1363
1356
  }
1364
1357
  collides(e) {
1365
1358
  let n = this.data;
1366
- if (!nt(e, n))
1359
+ if (!tt(e, n))
1367
1360
  return !1;
1368
1361
  const o = [];
1369
1362
  for (; n; ) {
1370
1363
  for (let i = 0; i < n.children.length; i++) {
1371
1364
  const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
1372
- if (nt(e, a)) {
1373
- if (n.leaf || ht(e, a))
1365
+ if (tt(e, a)) {
1366
+ if (n.leaf || dt(e, a))
1374
1367
  return !0;
1375
1368
  o.push(r);
1376
1369
  }
@@ -1405,7 +1398,7 @@ class bn {
1405
1398
  return e && this._insert(e, this.data.height - 1), this;
1406
1399
  }
1407
1400
  clear() {
1408
- return this.data = W([]), this;
1401
+ return this.data = z([]), this;
1409
1402
  }
1410
1403
  remove(e, n) {
1411
1404
  if (!e)
@@ -1415,11 +1408,11 @@ class bn {
1415
1408
  let s, h, f;
1416
1409
  for (; o || r.length; ) {
1417
1410
  if (o || (o = r.pop(), h = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
1418
- const m = vn(e, o.children, n);
1419
- if (m !== -1)
1420
- return o.children.splice(m, 1), r.push(o), this._condense(r), this;
1411
+ const b = vn(e, o.children, n);
1412
+ if (b !== -1)
1413
+ return o.children.splice(b, 1), r.push(o), this._condense(r), this;
1421
1414
  }
1422
- !f && !o.leaf && ht(o, i) ? (r.push(o), a.push(s), s = 0, h = o, o = o.children[0]) : h ? (s++, o = h.children[s], f = !1) : o = null;
1415
+ !f && !o.leaf && dt(o, i) ? (r.push(o), a.push(s), s = 0, h = o, o = o.children[0]) : h ? (s++, o = h.children[s], f = !1) : o = null;
1423
1416
  }
1424
1417
  return this;
1425
1418
  }
@@ -1448,26 +1441,26 @@ class bn {
1448
1441
  const r = o - n + 1;
1449
1442
  let a = this._maxEntries, s;
1450
1443
  if (r <= a)
1451
- return s = W(e.slice(n, o + 1)), F(s, this.toBBox), s;
1452
- 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;
1444
+ return s = z(e.slice(n, o + 1)), P(s, this.toBBox), s;
1445
+ i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = z([]), s.leaf = !1, s.height = i;
1453
1446
  const h = Math.ceil(r / a), f = h * Math.ceil(Math.sqrt(a));
1454
- Ot(e, n, o, f, this.compareMinX);
1455
- for (let m = n; m <= o; m += f) {
1456
- const l = Math.min(m + f - 1, o);
1457
- Ot(e, m, l, h, this.compareMinY);
1458
- for (let p = m; p <= l; p += h) {
1459
- const g = Math.min(p + h - 1, l);
1460
- s.children.push(this._build(e, p, g, i - 1));
1447
+ It(e, n, o, f, this.compareMinX);
1448
+ for (let b = n; b <= o; b += f) {
1449
+ const c = Math.min(b + f - 1, o);
1450
+ It(e, b, c, h, this.compareMinY);
1451
+ for (let m = b; m <= c; m += h) {
1452
+ const g = Math.min(m + h - 1, c);
1453
+ s.children.push(this._build(e, m, g, i - 1));
1461
1454
  }
1462
1455
  }
1463
- return F(s, this.toBBox), s;
1456
+ return P(s, this.toBBox), s;
1464
1457
  }
1465
1458
  _chooseSubtree(e, n, o, i) {
1466
1459
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1467
1460
  let r = 1 / 0, a = 1 / 0, s;
1468
1461
  for (let h = 0; h < n.children.length; h++) {
1469
- const f = n.children[h], m = ut(f), l = xn(e, f) - m;
1470
- l < a ? (a = l, r = m < r ? m : r, s = f) : l === a && m < r && (r = m, s = f);
1462
+ const f = n.children[h], b = ct(f), c = xn(e, f) - b;
1463
+ c < a ? (a = c, r = b < r ? b : r, s = f) : c === a && b < r && (r = b, s = f);
1471
1464
  }
1472
1465
  n = s || n.children[0];
1473
1466
  }
@@ -1475,7 +1468,7 @@ class bn {
1475
1468
  }
1476
1469
  _insert(e, n, o) {
1477
1470
  const i = o ? e : this.toBBox(e), r = [], a = this._chooseSubtree(i, this.data, n, r);
1478
- for (a.children.push(e), K(a, i); n >= 0 && r[n].children.length > this._maxEntries; )
1471
+ for (a.children.push(e), j(a, i); n >= 0 && r[n].children.length > this._maxEntries; )
1479
1472
  this._split(r, n), n--;
1480
1473
  this._adjustParentBBoxes(i, r, n);
1481
1474
  }
@@ -1483,17 +1476,17 @@ class bn {
1483
1476
  _split(e, n) {
1484
1477
  const o = e[n], i = o.children.length, r = this._minEntries;
1485
1478
  this._chooseSplitAxis(o, r, i);
1486
- const a = this._chooseSplitIndex(o, r, i), s = W(o.children.splice(a, o.children.length - a));
1487
- s.height = o.height, s.leaf = o.leaf, F(o, this.toBBox), F(s, this.toBBox), n ? e[n - 1].children.push(s) : this._splitRoot(o, s);
1479
+ const a = this._chooseSplitIndex(o, r, i), s = z(o.children.splice(a, o.children.length - a));
1480
+ s.height = o.height, s.leaf = o.leaf, P(o, this.toBBox), P(s, this.toBBox), n ? e[n - 1].children.push(s) : this._splitRoot(o, s);
1488
1481
  }
1489
1482
  _splitRoot(e, n) {
1490
- this.data = W([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, F(this.data, this.toBBox);
1483
+ this.data = z([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, P(this.data, this.toBBox);
1491
1484
  }
1492
1485
  _chooseSplitIndex(e, n, o) {
1493
1486
  let i, r = 1 / 0, a = 1 / 0;
1494
1487
  for (let s = n; s <= o - n; s++) {
1495
- const h = G(e, 0, s, this.toBBox), f = G(e, s, o, this.toBBox), m = An(h, f), l = ut(h) + ut(f);
1496
- m < r ? (r = m, i = s, a = l < a ? l : a) : m === r && l < a && (a = l, i = s);
1488
+ const h = q(e, 0, s, this.toBBox), f = q(e, s, o, this.toBBox), b = An(h, f), c = ct(h) + ct(f);
1489
+ b < r ? (r = b, i = s, a = c < a ? c : a) : b === r && c < a && (a = c, i = s);
1497
1490
  }
1498
1491
  return i || o - n;
1499
1492
  }
@@ -1505,25 +1498,25 @@ class bn {
1505
1498
  // total margin of all possible split distributions where each node is at least m full
1506
1499
  _allDistMargin(e, n, o, i) {
1507
1500
  e.children.sort(i);
1508
- const r = this.toBBox, a = G(e, 0, n, r), s = G(e, o - n, o, r);
1509
- let h = et(a) + et(s);
1501
+ const r = this.toBBox, a = q(e, 0, n, r), s = q(e, o - n, o, r);
1502
+ let h = Z(a) + Z(s);
1510
1503
  for (let f = n; f < o - n; f++) {
1511
- const m = e.children[f];
1512
- K(a, e.leaf ? r(m) : m), h += et(a);
1504
+ const b = e.children[f];
1505
+ j(a, e.leaf ? r(b) : b), h += Z(a);
1513
1506
  }
1514
1507
  for (let f = o - n - 1; f >= n; f--) {
1515
- const m = e.children[f];
1516
- K(s, e.leaf ? r(m) : m), h += et(s);
1508
+ const b = e.children[f];
1509
+ j(s, e.leaf ? r(b) : b), h += Z(s);
1517
1510
  }
1518
1511
  return h;
1519
1512
  }
1520
1513
  _adjustParentBBoxes(e, n, o) {
1521
1514
  for (let i = o; i >= 0; i--)
1522
- K(n[i], e);
1515
+ j(n[i], e);
1523
1516
  }
1524
1517
  _condense(e) {
1525
1518
  for (let n = e.length - 1, o; n >= 0; n--)
1526
- e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : F(e[n], this.toBBox);
1519
+ e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : P(e[n], this.toBBox);
1527
1520
  }
1528
1521
  }
1529
1522
  function vn(t, e, n) {
@@ -1534,18 +1527,18 @@ function vn(t, e, n) {
1534
1527
  return o;
1535
1528
  return -1;
1536
1529
  }
1537
- function F(t, e) {
1538
- G(t, 0, t.children.length, e, t);
1530
+ function P(t, e) {
1531
+ q(t, 0, t.children.length, e, t);
1539
1532
  }
1540
- function G(t, e, n, o, i) {
1541
- i || (i = W(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
1533
+ function q(t, e, n, o, i) {
1534
+ i || (i = z(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
1542
1535
  for (let r = e; r < n; r++) {
1543
1536
  const a = t.children[r];
1544
- K(i, t.leaf ? o(a) : a);
1537
+ j(i, t.leaf ? o(a) : a);
1545
1538
  }
1546
1539
  return i;
1547
1540
  }
1548
- function K(t, e) {
1541
+ function j(t, e) {
1549
1542
  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
1543
  }
1551
1544
  function yn(t, e) {
@@ -1554,10 +1547,10 @@ function yn(t, e) {
1554
1547
  function wn(t, e) {
1555
1548
  return t.minY - e.minY;
1556
1549
  }
1557
- function ut(t) {
1550
+ function ct(t) {
1558
1551
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1559
1552
  }
1560
- function et(t) {
1553
+ function Z(t) {
1561
1554
  return t.maxX - t.minX + (t.maxY - t.minY);
1562
1555
  }
1563
1556
  function xn(t, e) {
@@ -1567,13 +1560,13 @@ function An(t, e) {
1567
1560
  const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), r = Math.min(t.maxY, e.maxY);
1568
1561
  return Math.max(0, i - n) * Math.max(0, r - o);
1569
1562
  }
1570
- function ht(t, e) {
1563
+ function dt(t, e) {
1571
1564
  return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1572
1565
  }
1573
- function nt(t, e) {
1566
+ function tt(t, e) {
1574
1567
  return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
1575
1568
  }
1576
- function W(t) {
1569
+ function z(t) {
1577
1570
  return {
1578
1571
  children: t,
1579
1572
  height: 1,
@@ -1584,7 +1577,7 @@ function W(t) {
1584
1577
  maxY: -1 / 0
1585
1578
  };
1586
1579
  }
1587
- function Ot(t, e, n, o, i) {
1580
+ function It(t, e, n, o, i) {
1588
1581
  const r = [e, n];
1589
1582
  for (; r.length; ) {
1590
1583
  if (n = r.pop(), e = r.pop(), n - e <= o)
@@ -1594,109 +1587,109 @@ function Ot(t, e, n, o, i) {
1594
1587
  }
1595
1588
  }
1596
1589
  const En = (t, e) => {
1597
- const n = new bn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1598
- const v = d.selector.flatMap((L) => {
1599
- const E = $([L]) ? L.range : Ut(L, e).range;
1590
+ const n = new bn(), o = /* @__PURE__ */ new Map(), i = (u, l) => {
1591
+ const v = u.selector.flatMap((L) => {
1592
+ const E = D([L]) ? L.range : Nt(L, e).range;
1600
1593
  return Array.from(E.getClientRects());
1601
- }), C = re(v).map(({ left: L, top: E, right: B, bottom: T }) => new DOMRect(L - c.left, E - c.top, B - L, T - E));
1594
+ }), C = re(v).map(({ left: L, top: E, right: T, bottom: p }) => new DOMRect(L - l.left, E - l.top, T - L, p - E));
1602
1595
  return C.map((L) => {
1603
- const { x: E, y: B, width: T, height: O } = L;
1596
+ const { x: E, y: T, width: p, height: A } = L;
1604
1597
  return {
1605
1598
  minX: E,
1606
- minY: B,
1607
- maxX: E + T,
1608
- maxY: B + O,
1599
+ minY: T,
1600
+ maxX: E + p,
1601
+ maxY: T + A,
1609
1602
  annotation: {
1610
- id: d.annotation,
1603
+ id: u.annotation,
1611
1604
  rects: C
1612
1605
  }
1613
1606
  };
1614
1607
  });
1615
1608
  }, r = () => [...o.values()], a = () => {
1616
1609
  n.clear(), o.clear();
1617
- }, s = (d) => {
1618
- const c = i(d, e.getBoundingClientRect());
1619
- c.forEach((v) => n.insert(v)), o.set(d.annotation, c);
1620
- }, h = (d) => {
1621
- const c = o.get(d.annotation);
1622
- c && (c.forEach((v) => n.remove(v)), o.delete(d.annotation));
1623
- }, f = (d) => {
1624
- h(d), s(d);
1625
- }, m = (d, c = !0) => {
1626
- c && a();
1627
- const v = e.getBoundingClientRect(), C = d.map((E) => ({ target: E, rects: i(E, v) }));
1628
- C.forEach(({ target: E, rects: B }) => o.set(E.annotation, B));
1629
- const L = C.reduce((E, { rects: B }) => [...E, ...B], []);
1610
+ }, s = (u) => {
1611
+ const l = i(u, e.getBoundingClientRect());
1612
+ l.forEach((v) => n.insert(v)), o.set(u.annotation, l);
1613
+ }, h = (u) => {
1614
+ const l = o.get(u.annotation);
1615
+ l && (l.forEach((v) => n.remove(v)), o.delete(u.annotation));
1616
+ }, f = (u) => {
1617
+ h(u), s(u);
1618
+ }, b = (u, l = !0) => {
1619
+ l && a();
1620
+ const v = e.getBoundingClientRect(), C = u.map((E) => ({ target: E, rects: i(E, v) }));
1621
+ C.forEach(({ target: E, rects: T }) => o.set(E.annotation, T));
1622
+ const L = C.reduce((E, { rects: T }) => [...E, ...T], []);
1630
1623
  n.load(L);
1631
- }, l = (d, c) => {
1624
+ }, c = (u, l) => {
1632
1625
  const v = n.search({
1633
- minX: d,
1634
- minY: c,
1635
- maxX: d,
1636
- maxY: c
1637
- }), C = (L) => L.annotation.rects.reduce((E, B) => E + B.width * B.height, 0);
1626
+ minX: u,
1627
+ minY: l,
1628
+ maxX: u,
1629
+ maxY: l
1630
+ }), C = (L) => L.annotation.rects.reduce((E, T) => E + T.width * T.height, 0);
1638
1631
  if (v.length > 0)
1639
1632
  return v.sort((L, E) => C(L) - C(E)), v[0].annotation.id;
1640
- }, p = (d) => {
1641
- const c = g(d);
1642
- if (c.length === 0)
1633
+ }, m = (u) => {
1634
+ const l = g(u);
1635
+ if (l.length === 0)
1643
1636
  return;
1644
- let v = c[0].left, C = c[0].top, L = c[0].right, E = c[0].bottom;
1645
- for (let B = 1; B < c.length; B++) {
1646
- const T = c[B];
1647
- v = Math.min(v, T.left), C = Math.min(C, T.top), L = Math.max(L, T.right), E = Math.max(E, T.bottom);
1637
+ let v = l[0].left, C = l[0].top, L = l[0].right, E = l[0].bottom;
1638
+ for (let T = 1; T < l.length; T++) {
1639
+ const p = l[T];
1640
+ v = Math.min(v, p.left), C = Math.min(C, p.top), L = Math.max(L, p.right), E = Math.max(E, p.bottom);
1648
1641
  }
1649
1642
  return new DOMRect(v, C, L - v, E - C);
1650
- }, g = (d) => {
1651
- const c = o.get(d);
1652
- return c ? c[0].annotation.rects : [];
1643
+ }, g = (u) => {
1644
+ const l = o.get(u);
1645
+ return l ? l[0].annotation.rects : [];
1653
1646
  };
1654
1647
  return {
1655
1648
  all: r,
1656
1649
  clear: a,
1657
- getAt: l,
1658
- getAnnotationBounds: p,
1650
+ getAt: c,
1651
+ getAnnotationBounds: m,
1659
1652
  getAnnotationRects: g,
1660
- getIntersecting: (d, c, v, C) => {
1661
- const L = n.search({ minX: d, minY: c, maxX: v, maxY: C }), E = new Set(L.reduce((B, T) => [...B, T.annotation.id], []));
1662
- return Array.from(E).map((B) => ({
1663
- annotation: t.getAnnotation(B),
1664
- rects: g(B)
1665
- })).filter((B) => !!B.annotation);
1653
+ getIntersecting: (u, l, v, C) => {
1654
+ const L = n.search({ minX: u, minY: l, maxX: v, maxY: C }), E = new Set(L.reduce((T, p) => [...T, p.annotation.id], []));
1655
+ return Array.from(E).map((T) => ({
1656
+ annotation: t.getAnnotation(T),
1657
+ rects: g(T)
1658
+ })).filter((T) => !!T.annotation);
1666
1659
  },
1667
1660
  insert: s,
1668
- recalculate: () => m(t.all().map((d) => d.target), !0),
1661
+ recalculate: () => b(t.all().map((u) => u.target), !0),
1669
1662
  remove: h,
1670
- set: m,
1663
+ set: b,
1671
1664
  size: () => n.all().length,
1672
1665
  update: f
1673
1666
  };
1674
1667
  }, 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);
1677
- 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));
1680
- 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));
1683
- return c.length > 0 && console.warn("Could not revive all targets for these annotations:", c), d.forEach((v) => {
1684
- n.getAnnotation(v.id) ? n.updateAnnotation(v, u) : n.addAnnotation(v, u);
1685
- }), c;
1686
- }, m = (y, u = N.LOCAL) => {
1687
- const d = it(y, t);
1688
- n.updateTarget(d, u);
1689
- }, l = (y, u = N.LOCAL) => {
1690
- const d = y.map((c) => it(c, t));
1691
- n.bulkUpdateTargets(d, u);
1692
- }, p = (y, u) => {
1693
- const d = o.getAt(y, u);
1694
- return d ? n.getAnnotation(d) : void 0;
1695
- }, g = (y, u, d, c = 5) => {
1668
+ const n = qe(), o = En(n, t), i = Ne(n, e), r = Me(n), a = Qe(), s = (y, d = R.LOCAL) => {
1669
+ const u = ot(y, t), l = D(u.target.selector);
1670
+ return l && n.addAnnotation(u, d), l;
1671
+ }, h = (y, d = !0, u = R.LOCAL) => {
1672
+ const l = y.map((C) => ot(C, t)), v = l.filter((C) => !D(C.target.selector));
1673
+ return v.length > 0 ? (console.warn("Could not revive all targets for these annotations:", v), n.bulkAddAnnotation(l, d, u), v) : (n.bulkAddAnnotation(l, d, u), []);
1674
+ }, f = (y, d = R.LOCAL) => {
1675
+ const u = y.map((v) => ot(v, t)), l = u.filter((v) => !D(v.target.selector));
1676
+ return l.length > 0 && console.warn("Could not revive all targets for these annotations:", l), u.forEach((v) => {
1677
+ n.getAnnotation(v.id) ? n.updateAnnotation(v, d) : n.addAnnotation(v, d);
1678
+ }), l;
1679
+ }, b = (y, d = R.LOCAL) => {
1680
+ const u = nt(y, t);
1681
+ n.updateTarget(u, d);
1682
+ }, c = (y, d = R.LOCAL) => {
1683
+ const u = y.map((l) => nt(l, t));
1684
+ n.bulkUpdateTargets(u, d);
1685
+ }, m = (y, d) => {
1686
+ const u = o.getAt(y, d);
1687
+ return u ? n.getAnnotation(u) : void 0;
1688
+ }, g = (y, d, u, l = 5) => {
1696
1689
  const v = o.getAnnotationRects(y);
1697
1690
  if (v.length !== 0) {
1698
- if (u && d) {
1699
- const C = v.find(({ top: L, right: E, bottom: B, left: T }) => u >= T - c && u <= E + c && d >= L - c && d <= B + c);
1691
+ if (d && u) {
1692
+ const C = v.find(({ top: L, right: E, bottom: T, left: p }) => d >= p - l && d <= E + l && u >= L - l && u <= T + l);
1700
1693
  if (C)
1701
1694
  return C;
1702
1695
  }
@@ -1704,20 +1697,20 @@ const En = (t, e) => {
1704
1697
  }
1705
1698
  }, x = () => o.recalculate();
1706
1699
  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));
1708
- 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));
1700
+ const d = (y.created || []).filter((v) => D(v.target.selector)), u = (y.deleted || []).filter((v) => D(v.target.selector)), l = (y.updated || []).filter((v) => D(v.newValue.target.selector));
1701
+ d.length > 0 && o.set(d.map((v) => v.target), !1), (u == null ? void 0 : u.length) > 0 && u.forEach((v) => o.remove(v.target)), (l == null ? void 0 : l.length) > 0 && l.forEach(({ newValue: v }) => o.update(v.target));
1709
1702
  }), {
1710
1703
  store: {
1711
1704
  ...n,
1712
1705
  addAnnotation: s,
1713
1706
  bulkAddAnnotation: h,
1714
- bulkUpdateTargets: l,
1707
+ bulkUpdateTargets: c,
1715
1708
  bulkUpsertAnnotations: f,
1716
1709
  getAnnotationBounds: g,
1717
- getAt: p,
1710
+ getAt: m,
1718
1711
  getIntersecting: o.getIntersecting,
1719
1712
  recalculatePositions: x,
1720
- updateTarget: m
1713
+ updateTarget: b
1721
1714
  },
1722
1715
  selection: i,
1723
1716
  hover: r,
@@ -1731,25 +1724,25 @@ const En = (t, e) => {
1731
1724
  }, Ln = (t, e, n = {}) => {
1732
1725
  const o = Cn(), i = o.getContext("2d");
1733
1726
  t.appendChild(o);
1734
- const r = /* @__PURE__ */ new Map(), a = (l) => Array.from(r.entries()).filter(([p, g]) => g.presenceKey === l.presenceKey).map(([p, g]) => p);
1735
- return e.on("selectionChange", (l, p) => {
1736
- a(l).forEach((x) => r.delete(x)), p && p.forEach((x) => r.set(x, l));
1727
+ const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([m, g]) => g.presenceKey === c.presenceKey).map(([m, g]) => m);
1728
+ return e.on("selectionChange", (c, m) => {
1729
+ a(c).forEach((x) => r.delete(x)), m && m.forEach((x) => r.set(x, c));
1737
1730
  }), {
1738
1731
  clear: () => {
1739
- const { width: l, height: p } = o;
1740
- i.clearRect(-0.5, -0.5, l + 1, p + 1);
1732
+ const { width: c, height: m } = o;
1733
+ i.clearRect(-0.5, -0.5, c + 1, m + 1);
1741
1734
  },
1742
1735
  destroy: () => {
1743
1736
  o.remove();
1744
1737
  },
1745
- paint: (l, p, g) => {
1738
+ paint: (c, m, g) => {
1746
1739
  n.font && (i.font = n.font);
1747
- const x = r.get(l.annotation.id);
1740
+ const x = r.get(c.annotation.id);
1748
1741
  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);
1751
- const c = i.measureText(x.appearance.label), v = c.width + 6, C = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, L = c.fontBoundingBoxAscent ? 8 : 6.5;
1752
- return i.fillRect(u - 2, d - 2.5 - C, v, C), i.fillStyle = "#fff", i.fillText(x.appearance.label, u + 1, d - L), {
1742
+ const { height: y } = c.rects[0], d = c.rects[0].x + m.left, u = c.rects[0].y + m.top;
1743
+ i.fillStyle = x.appearance.color, i.fillRect(d - 2, u - 2.5, 2, y + 5);
1744
+ const l = i.measureText(x.appearance.label), v = l.width + 6, C = l.actualBoundingBoxAscent + l.actualBoundingBoxDescent + 8, L = l.fontBoundingBoxAscent ? 8 : 6.5;
1745
+ return i.fillRect(d - 2, u - 2.5 - C, v, C), i.fillStyle = "#fff", i.fillText(x.appearance.label, d + 1, u - L), {
1753
1746
  fill: x.appearance.color,
1754
1747
  fillOpacity: g ? 0.45 : 0.18
1755
1748
  };
@@ -1757,169 +1750,169 @@ const En = (t, e) => {
1757
1750
  },
1758
1751
  reset: () => {
1759
1752
  o.width = 2 * window.innerWidth, o.height = 2 * window.innerHeight;
1760
- const l = o.getContext("2d");
1761
- l.scale(2, 2), l.translate(0.5, 0.5);
1753
+ const c = o.getContext("2d");
1754
+ c.scale(2, 2), c.translate(0.5, 0.5);
1762
1755
  }
1763
1756
  };
1764
- }, Pt = (t) => {
1757
+ }, $t = (t) => {
1765
1758
  if (t === null)
1766
1759
  return document.scrollingElement;
1767
1760
  const { overflowY: e } = window.getComputedStyle(t);
1768
- return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Pt(t.parentElement);
1769
- }, Bn = (t, e) => (n) => {
1761
+ return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : $t(t.parentElement);
1762
+ }, Tn = (t, e) => (n) => {
1770
1763
  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;
1772
- i.scroll({ top: u, left: d, behavior: "smooth" });
1773
- }, i = Pt(t);
1764
+ const a = i.getBoundingClientRect(), s = i.clientHeight, h = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: b, height: c } = e.getAnnotationBounds(n.id), m = f.top - a.top, g = f.left - a.left, x = i.parentElement ? i.scrollTop : 0, y = i.parentElement ? i.scrollLeft : 0, d = m + x - (s - c) / 2, u = g + y - (h - b) / 2;
1765
+ i.scroll({ top: d, left: u, behavior: "smooth" });
1766
+ }, i = $t(t);
1774
1767
  if (i) {
1775
1768
  const r = e.getAnnotation(n.id), { range: a } = r.target.selector[0];
1776
1769
  if (a && !a.collapsed)
1777
1770
  return o(r.target), !0;
1778
1771
  {
1779
- const s = it(r.target, t), { range: h } = s.selector[0];
1772
+ const s = nt(r.target, t), { range: h } = s.selector[0];
1780
1773
  if (h && !h.collapsed)
1781
1774
  return o(s), !0;
1782
1775
  }
1783
1776
  }
1784
1777
  return !1;
1785
- }, Tn = (t, e) => ({
1778
+ }, Bn = (t, e) => ({
1786
1779
  ...t,
1787
1780
  annotationEnabled: t.annotationEnabled === void 0 ? e.annotationEnabled : t.annotationEnabled
1788
1781
  }), Rn = (t, e, n, o) => {
1789
1782
  const { store: i, selection: r } = e;
1790
1783
  let a, s;
1791
- const h = (u) => a = u;
1792
- let f = !1, m;
1793
- const l = (u) => {
1794
- var c;
1784
+ const h = (d) => a = d;
1785
+ let f = !1, b;
1786
+ const c = (d) => {
1787
+ var l;
1795
1788
  if (!f)
1796
1789
  return;
1797
- !((c = u.target.parentElement) != null && c.closest(_)) ? s = {
1798
- annotation: Dt(),
1790
+ !((l = d.target.parentElement) != null && l.closest(k)) ? s = {
1791
+ annotation: Yt(),
1799
1792
  selector: [],
1800
1793
  creator: a,
1801
1794
  created: /* @__PURE__ */ new Date()
1802
1795
  } : s = void 0;
1803
1796
  };
1804
- n && t.addEventListener("selectstart", l);
1805
- const p = pt((u) => {
1806
- var E;
1807
- const d = document.getSelection();
1808
- if (!!((E = d.anchorNode.parentElement) != null && E.closest(_))) {
1797
+ n && t.addEventListener("selectstart", c);
1798
+ const m = ft((d) => {
1799
+ var E, T;
1800
+ const u = document.getSelection();
1801
+ if (!!((T = (E = u.anchorNode) == null ? void 0 : E.parentElement) != null && T.closest(k))) {
1809
1802
  s = void 0;
1810
1803
  return;
1811
1804
  }
1812
- if (u.timeStamp - ((m == null ? void 0 : m.timeStamp) || u.timeStamp) < 1e3 && !s && l(m), d.isCollapsed || !f || !s)
1805
+ if (d.timeStamp - ((b == null ? void 0 : b.timeStamp) || d.timeStamp) < 1e3 && !s && c(b), u.isCollapsed || !f || !s)
1813
1806
  return;
1814
- const v = d.getRangeAt(0);
1807
+ const v = u.getRangeAt(0);
1815
1808
  if (ne(v))
1816
1809
  return;
1817
1810
  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);
1811
+ (C.length !== s.selector.length || C.some((p, A) => {
1812
+ var w;
1813
+ return p.toString() !== ((w = s.selector[A]) == null ? void 0 : w.quote);
1821
1814
  })) && (s = {
1822
1815
  ...s,
1823
- selector: C.map((B) => se(B, t, o))
1824
- }, i.getAnnotation(s.annotation) ? i.updateTarget(s, N.LOCAL) : (i.addAnnotation({
1816
+ selector: C.map((p) => se(p, t, o))
1817
+ }, i.getAnnotation(s.annotation) ? i.updateTarget(s, R.LOCAL) : (i.addAnnotation({
1825
1818
  id: s.annotation,
1826
1819
  bodies: [],
1827
1820
  target: s
1828
- }, N.LOCAL), r.clickSelect(s.annotation, m)));
1821
+ }, R.LOCAL), r.clickSelect(s.annotation, b)));
1829
1822
  });
1830
- n && document.addEventListener("selectionchange", p);
1831
- const g = (u) => {
1832
- const { target: d, timeStamp: c, offsetX: v, offsetY: C, type: L } = u;
1833
- m = { ...u, target: d, timeStamp: c, offsetX: v, offsetY: C, type: L }, f = u.button === 0;
1823
+ n && document.addEventListener("selectionchange", m);
1824
+ const g = (d) => {
1825
+ const { target: u, timeStamp: l, offsetX: v, offsetY: C, type: L } = d;
1826
+ b = { ...d, target: u, timeStamp: l, offsetX: v, offsetY: C, type: L }, f = d.button === 0;
1834
1827
  };
1835
1828
  t.addEventListener("pointerdown", g);
1836
- const x = (u) => {
1829
+ const x = (d) => {
1837
1830
  var C;
1838
- if (!!((C = u.target.parentElement) != null && C.closest(_)) || !f)
1831
+ if (!!((C = d.target.parentElement) != null && C.closest(k)) || !f)
1839
1832
  return;
1840
- const c = () => {
1841
- const { x: L, y: E } = t.getBoundingClientRect(), B = i.getAt(u.clientX - L, u.clientY - E);
1842
- if (B) {
1843
- const { selected: T } = r;
1844
- (T.length !== 1 || T[0].id !== B.id) && r.clickSelect(B.id, u);
1833
+ const l = () => {
1834
+ const { x: L, y: E } = t.getBoundingClientRect(), T = i.getAt(d.clientX - L, d.clientY - E);
1835
+ if (T) {
1836
+ const { selected: p } = r;
1837
+ (p.length !== 1 || p[0].id !== T.id) && r.clickSelect(T.id, d);
1845
1838
  } else
1846
1839
  r.isEmpty() || r.clear();
1847
- }, v = u.timeStamp - m.timeStamp;
1848
- document.getSelection().isCollapsed && v < 300 ? (s = void 0, c()) : s && r.clickSelect(s.annotation, u);
1840
+ }, v = d.timeStamp - b.timeStamp;
1841
+ document.getSelection().isCollapsed && v < 300 ? (s = void 0, l()) : s && r.clickSelect(s.annotation, d);
1849
1842
  };
1850
1843
  return document.addEventListener("pointerup", x), {
1851
1844
  destroy: () => {
1852
- t.removeEventListener("selectstart", l), document.removeEventListener("selectionchange", p), t.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", x);
1845
+ t.removeEventListener("selectstart", c), document.removeEventListener("selectionchange", m), t.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", x);
1853
1846
  },
1854
1847
  setUser: h
1855
1848
  };
1856
- }, It = "SPANS", Vn = (t, e = {}) => {
1849
+ }, Mt = "SPANS", Un = (t, e = {}) => {
1857
1850
  Qt(t);
1858
- const n = Tn(e, {
1851
+ const n = Bn(e, {
1859
1852
  annotationEnabled: !0
1860
1853
  }), o = Sn(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Ke(a), h = Je(o, s, n.adapter);
1861
1854
  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;
1863
- if (!l)
1864
- throw `Unknown renderer implementation: ${m}`;
1865
- console.debug(`Using ${m} renderer`), n.style && l.setStyle(n.style);
1866
- const p = Rn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1867
- return p.setUser(f), {
1855
+ const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Mt : n.renderer || Mt, c = b === "SPANS" ? Ce(t, o, r) : b === "CSS_HIGHLIGHTS" ? Ae(t, o, r) : b === "CANVAS" ? he(t, o, r) : void 0;
1856
+ if (!c)
1857
+ throw `Unknown renderer implementation: ${b}`;
1858
+ console.debug(`Using ${b} renderer`), n.style && c.setStyle(n.style);
1859
+ const m = Rn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1860
+ return m.setUser(f), {
1868
1861
  ...tn(o, s, n.adapter),
1869
1862
  destroy: () => {
1870
- l.destroy(), p.destroy(), s.destroy();
1863
+ c.destroy(), m.destroy(), s.destroy();
1871
1864
  },
1872
1865
  element: t,
1873
1866
  getUser: () => f,
1874
- setFilter: (E) => l.setFilter(E),
1875
- setStyle: (E) => l.setStyle(E),
1867
+ setFilter: (E) => c.setFilter(E),
1868
+ setStyle: (E) => c.setStyle(E),
1876
1869
  setUser: (E) => {
1877
- f = E, p.setUser(E);
1870
+ f = E, m.setUser(E);
1878
1871
  },
1879
1872
  setSelected: (E) => {
1880
1873
  E ? i.setSelected(E) : i.clear();
1881
1874
  },
1882
1875
  setPresenceProvider: (E) => {
1883
- E && (l.setPainter(Ln(t, E, n.presence)), E.on("selectionChange", () => l.redraw()));
1876
+ E && (c.setPainter(Ln(t, E, n.presence)), E.on("selectionChange", () => c.redraw()));
1884
1877
  },
1885
- setVisible: (E) => l.setVisible(E),
1878
+ setVisible: (E) => c.setVisible(E),
1886
1879
  on: h.on,
1887
1880
  off: h.off,
1888
- scrollIntoView: Bn(t, a),
1881
+ scrollIntoView: Tn(t, a),
1889
1882
  state: o
1890
1883
  };
1891
1884
  };
1892
1885
  export {
1893
- ot as DEFAULT_SELECTED_STYLE,
1894
- P as DEFAULT_STYLE,
1895
- Vt as NOT_ANNOTATABLE_CLASS,
1896
- _ as NOT_ANNOTATABLE_SELECTOR,
1897
- N as Origin,
1886
+ et as DEFAULT_SELECTED_STYLE,
1887
+ $ as DEFAULT_STYLE,
1888
+ Ot as NOT_ANNOTATABLE_CLASS,
1889
+ k as NOT_ANNOTATABLE_SELECTOR,
1890
+ R as Origin,
1898
1891
  Oe as PointerSelectAction,
1899
- In as W3CTextFormat,
1892
+ Nn as W3CTextFormat,
1900
1893
  Qt as cancelSingleClickEvents,
1901
1894
  On as createBody,
1902
1895
  he as createCanvasRenderer,
1903
1896
  Ae as createHighlightsRenderer,
1904
1897
  xe as createRenderer,
1905
1898
  Ce as createSpansRenderer,
1906
- Vn as createTextAnnotator,
1899
+ Un as createTextAnnotator,
1907
1900
  Sn as createTextAnnotatorState,
1908
- pt as debounce,
1909
- Tn as fillDefaults,
1910
- Nn as getAnnotatableFragment,
1901
+ ft as debounce,
1902
+ Bn as fillDefaults,
1903
+ In as getAnnotatableFragment,
1911
1904
  Mn as getClientRectsPonyfill,
1912
1905
  te as getQuoteContext,
1913
- ft as getRangeAnnotatableContents,
1914
- $ as isRevived,
1906
+ ut as getRangeAnnotatableContents,
1907
+ D as isRevived,
1915
1908
  ne as isWhitespaceOrEmpty,
1916
1909
  re as mergeClientRects,
1917
1910
  qt as paint,
1918
1911
  fn as parseW3CTextAnnotation,
1919
1912
  se as rangeToSelector,
1920
- rt as reviveAnnotation,
1921
- Ut as reviveSelector,
1922
- it as reviveTarget,
1913
+ ot as reviveAnnotation,
1914
+ Nt as reviveSelector,
1915
+ nt as reviveTarget,
1923
1916
  gn as serializeW3CTextAnnotation,
1924
1917
  Kt as splitAnnotatableRanges,
1925
1918
  ee as whitespaceOrEmptyRegex