@recogito/text-annotator 3.0.0-rc.32 → 3.0.0-rc.34

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.
@@ -5,8 +5,8 @@ const P = {
5
5
  fill: "rgb(0, 128, 255)",
6
6
  fillOpacity: 0.45
7
7
  }, Kt = (t, e, n, o, i) => {
8
- var s, a;
9
- const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((s = t.state) != null && s.selected ? ot : P) : n : (a = t.state) != null && a.selected ? ot : P;
8
+ var c, s;
9
+ const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((c = t.state) != null && c.selected ? ot : P) : n : (s = t.state) != null && s.selected ? ot : P;
10
10
  return o && o.paint(t, e) || r;
11
11
  }, Yt = "not-annotatable", D = `.${Yt}`, Qt = (t) => {
12
12
  var n;
@@ -71,13 +71,13 @@ const P = {
71
71
  startOffset: o,
72
72
  endContainer: i,
73
73
  endOffset: r
74
- } = t, s = Array.from(e.childNodes).map((l) => {
74
+ } = t, c = Array.from(e.childNodes).map((l) => {
75
75
  const g = l.cloneNode(!0);
76
76
  return l.nodeName === "CANVAS" ? l : g;
77
- }), a = wt(n, e), u = wt(i, e), h = () => {
77
+ }), s = wt(n, e), u = wt(i, e), h = () => {
78
78
  const l = e;
79
- l.replaceChildren(...s);
80
- const g = xt(a, l), f = xt(u, l);
79
+ l.replaceChildren(...c);
80
+ const g = xt(s, l), f = xt(u, l);
81
81
  return t.setStart(g, o), t.setEnd(f, r), t;
82
82
  }, m = (l) => {
83
83
  const g = document.createElement("SPAN");
@@ -90,12 +90,12 @@ const P = {
90
90
  l.selectNodeContents(n), l.setStart(n, o);
91
91
  const g = m(l), f = document.createRange();
92
92
  f.selectNode(i), f.setEnd(i, r);
93
- const x = m(f), p = ne(t).reverse().map((d) => {
93
+ const w = m(f), p = ne(t).reverse().map((d) => {
94
94
  var y;
95
- const c = document.createElement("SPAN");
96
- return (y = d.parentNode) == null || y.insertBefore(c, d), c.appendChild(d), c;
95
+ const a = document.createElement("SPAN");
96
+ return (y = d.parentNode) == null || y.insertBefore(a, d), a.appendChild(d), a;
97
97
  });
98
- return { unwrap: h, nodes: [g, ...p, x] };
98
+ return { unwrap: h, nodes: [g, ...p, w] };
99
99
  }
100
100
  }, ne = (t) => {
101
101
  const {
@@ -103,30 +103,30 @@ const P = {
103
103
  startContainer: n,
104
104
  endContainer: o
105
105
  } = t, i = document.createNodeIterator(e, NodeFilter.SHOW_TEXT);
106
- let r = i.nextNode(), s = !1;
107
- const a = [];
106
+ let r = i.nextNode(), c = !1;
107
+ const s = [];
108
108
  for (; r != null; )
109
- r === o && (s = !1), s && a.push(r), r === n && (s = !0), r = i.nextNode();
110
- return a;
109
+ r === o && (c = !1), c && s.push(r), r === n && (c = !0), r = i.nextNode();
110
+ return s;
111
111
  }, In = (t) => {
112
112
  const { startContainer: e, endContainer: n } = t;
113
113
  if (e === n)
114
114
  return Array.from(t.getClientRects());
115
115
  {
116
- const { unwrap: o, nodes: i } = ee(t), r = i.reduce((s, a) => [...s, ...a.getClientRects()], []);
116
+ const { unwrap: o, nodes: i } = ee(t), r = i.reduce((c, s) => [...c, ...s.getClientRects()], []);
117
117
  return o(), r;
118
118
  }
119
119
  }, oe = (t, e, n = 10, o) => {
120
120
  const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
121
121
  r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
122
- const s = pt(r).textContent, a = document.createRange();
123
- a.setStart(t.endContainer, t.endOffset), i === document.body ? a.setEnd(i, i.childNodes.length) : a.setEndAfter(i);
124
- const u = pt(a).textContent;
122
+ const c = pt(r).textContent, s = document.createRange();
123
+ s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
124
+ const u = pt(s).textContent;
125
125
  return {
126
- prefix: s.substring(s.length - n),
126
+ prefix: c.substring(c.length - n),
127
127
  suffix: u.substring(0, n)
128
128
  };
129
- }, ie = /^\s*$/, re = (t) => ie.test(t.toString()), H = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), se = (t, e) => {
129
+ }, ie = /^\s*$/, re = (t) => ie.test(t.toString()), $ = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), se = (t, e) => {
130
130
  const n = (r) => Math.round(r * 10) / 10, o = {
131
131
  top: n(t.top),
132
132
  bottom: n(t.bottom),
@@ -158,18 +158,18 @@ const P = {
158
158
  return e;
159
159
  let o = [...e], i = !1;
160
160
  for (const r of e) {
161
- const s = se(n, r);
162
- if (s === "inline-adjacent") {
163
- o = o.map((a) => a === r ? ae(n, r) : a), i = !0;
161
+ const c = se(n, r);
162
+ if (c === "inline-adjacent") {
163
+ o = o.map((s) => s === r ? ae(n, r) : s), i = !0;
164
164
  break;
165
- } else if (s === "inline-contains") {
166
- o = o.map((a) => a === r ? n : a), i = !0;
165
+ } else if (c === "inline-contains") {
166
+ o = o.map((s) => s === r ? n : s), i = !0;
167
167
  break;
168
- } else if (s === "inline-is-contained") {
168
+ } else if (c === "inline-is-contained") {
169
169
  i = !0;
170
170
  break;
171
- } else if (s === "block-contains" || s === "block-is-contained") {
172
- n.width < r.width && (o = o.map((a) => a === r ? n : a)), i = !0;
171
+ } else if (c === "block-contains" || c === "block-is-contained") {
172
+ n.width < r.width && (o = o.map((s) => s === r ? n : s)), i = !0;
173
173
  break;
174
174
  }
175
175
  }
@@ -177,8 +177,8 @@ const P = {
177
177
  }, []), le = (t, e, n) => {
178
178
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
179
179
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
180
- const r = pt(o).textContent, s = t.toString(), a = r.length || 0, u = a + s.length;
181
- return n ? { quote: s, start: a, end: u, range: t, offsetReference: i } : { quote: s, start: a, end: u, range: t };
180
+ const r = pt(o).textContent, c = t.toString(), s = r.length || 0, u = s + c.length;
181
+ return n ? { quote: c, start: s, end: u, range: t, offsetReference: i } : { quote: c, start: s, end: u, range: t };
182
182
  }, Dt = (t, e) => {
183
183
  var m, l;
184
184
  const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
@@ -189,40 +189,40 @@ const P = {
189
189
  return (f = g.parentElement) != null && f.closest(D) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
190
190
  }
191
191
  );
192
- let s = 0;
193
- const a = document.createRange();
192
+ let c = 0;
193
+ const s = document.createRange();
194
194
  let u = r.nextNode();
195
195
  u === null && console.error("Could not revive annotation target. Content missing.");
196
196
  let h = !i;
197
197
  for (; u !== null; ) {
198
198
  if (h || (h = i == null ? void 0 : i.contains(u)), h) {
199
199
  const g = ((m = u.textContent) == null ? void 0 : m.length) || 0;
200
- if (s + g > n) {
201
- a.setStart(u, n - s);
200
+ if (c + g > n) {
201
+ s.setStart(u, n - c);
202
202
  break;
203
203
  }
204
- s += g;
204
+ c += g;
205
205
  }
206
206
  u = r.nextNode();
207
207
  }
208
208
  for (; u !== null; ) {
209
209
  const g = ((l = u.textContent) == null ? void 0 : l.length) || 0;
210
- if (s + g >= o) {
211
- a.setEnd(u, o - s);
210
+ if (c + g >= o) {
211
+ s.setEnd(u, o - c);
212
212
  break;
213
213
  }
214
- s += g, u = r.nextNode();
214
+ c += g, u = r.nextNode();
215
215
  }
216
216
  return {
217
217
  ...t,
218
- range: a
218
+ range: s
219
219
  };
220
- }, it = (t, e) => H(t.selector) ? t : {
220
+ }, it = (t, e) => $(t.selector) ? t : {
221
221
  ...t,
222
222
  selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Dt(n, e))
223
- }, rt = (t, e) => H(t.target.selector) ? t : { ...t, target: it(t.target, e) }, de = (t) => {
224
- const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, s = -e, a = o - n, u = i - e;
225
- return { top: e, left: n, minX: r, minY: s, maxX: a, maxY: u };
223
+ }, rt = (t, e) => $(t.target.selector) ? t : { ...t, target: it(t.target, e) }, de = (t) => {
224
+ const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, c = -e, s = o - n, u = i - e;
225
+ return { top: e, left: n, minX: r, minY: c, maxX: s, maxY: u };
226
226
  }, ue = (t) => {
227
227
  let e = /* @__PURE__ */ new Set();
228
228
  return (o) => {
@@ -230,45 +230,45 @@ const P = {
230
230
  (e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
231
231
  };
232
232
  }, vt = (t, e, n, o) => {
233
- const { store: i, selection: r, hover: s } = e;
234
- let a, u, h;
235
- const m = ue(n), l = (T) => {
236
- const { x: M, y: b } = t.getBoundingClientRect(), w = i.getAt(T.clientX - M, T.clientY - b);
237
- w && (!u || u(w)) ? s.current !== w.id && (t.classList.add("hovered"), s.set(w.id)) : s.current && (t.classList.remove("hovered"), s.set(null));
233
+ const { store: i, selection: r, hover: c } = e;
234
+ let s, u, h;
235
+ const m = ue(n), l = (B) => {
236
+ const { x: M, y: b } = t.getBoundingClientRect(), x = i.getAt(B.clientX - M, B.clientY - b, u);
237
+ x ? c.current !== x.id && (t.classList.add("hovered"), c.set(x.id)) : c.current && (t.classList.remove("hovered"), c.set(null));
238
238
  };
239
239
  t.addEventListener("pointermove", l);
240
- const g = (T = !1) => {
240
+ const g = (B = !1) => {
241
241
  h && h.clear();
242
- const M = de(t), { minX: b, minY: w, maxX: A, maxY: S } = M, R = u ? i.getIntersecting(b, w, A, S).filter(({ annotation: _ }) => u(_)) : i.getIntersecting(b, w, A, S), O = r.selected.map(({ id: _ }) => _), $ = R.map(({ annotation: _, rects: qt }) => {
243
- const jt = O.includes(_.id), Gt = _.id === s.current;
242
+ const M = de(t), { minX: b, minY: x, maxX: A, maxY: C } = M, R = u ? i.getIntersecting(b, x, A, C).filter(({ annotation: _ }) => u(_)) : i.getIntersecting(b, x, A, C), O = r.selected.map(({ id: _ }) => _), H = R.map(({ annotation: _, rects: qt }) => {
243
+ const jt = O.includes(_.id), Gt = _.id === c.current;
244
244
  return { annotation: _, rects: qt, state: { selected: jt, hover: Gt } };
245
245
  });
246
- o.redraw($, M, a, h, T), setTimeout(() => m(R.map(({ annotation: _ }) => _)), 1);
247
- }, f = (T) => {
248
- h = T, g();
249
- }, x = (T) => {
250
- a = T, g();
251
- }, v = (T) => {
252
- u = T, g(!1);
246
+ o.redraw(H, M, s, h, B), setTimeout(() => m(R.map(({ annotation: _ }) => _)), 1);
247
+ }, f = (B) => {
248
+ h = B, g();
249
+ }, w = (B) => {
250
+ s = B, g();
251
+ }, v = (B) => {
252
+ u = B, g(!1);
253
253
  }, p = () => g();
254
254
  i.observe(p);
255
- const d = r.subscribe(() => g()), c = () => g(!0);
256
- document.addEventListener("scroll", c, { capture: !0, passive: !0 });
255
+ const d = r.subscribe(() => g()), a = () => g(!0);
256
+ document.addEventListener("scroll", a, { capture: !0, passive: !0 });
257
257
  const y = bt(() => {
258
258
  i.recalculatePositions(), h && h.reset(), g();
259
259
  });
260
260
  window.addEventListener("resize", y);
261
- const C = new ResizeObserver(y);
262
- C.observe(t);
263
- const L = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((T) => {
264
- T.every((b) => b.target === t || t.contains(b.target)) || g(!0);
261
+ const S = new ResizeObserver(y);
262
+ S.observe(t);
263
+ const L = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((B) => {
264
+ B.every((b) => b.target === t || t.contains(b.target)) || g(!0);
265
265
  });
266
266
  return E.observe(document.body, L), {
267
267
  destroy: () => {
268
- t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(p), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", y), C.disconnect(), E.disconnect();
268
+ t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(p), d(), document.removeEventListener("scroll", a), window.removeEventListener("resize", y), S.disconnect(), E.disconnect();
269
269
  },
270
270
  redraw: g,
271
- setStyle: x,
271
+ setStyle: w,
272
272
  setFilter: v,
273
273
  setPainter: f,
274
274
  setVisible: o.setVisible
@@ -282,35 +282,35 @@ const P = {
282
282
  t.classList.add("r6o-annotatable");
283
283
  const e = he(), n = e.getContext("2d");
284
284
  t.insertBefore(e, t.firstChild);
285
- const o = (a, u, h, m) => requestAnimationFrame(() => {
285
+ const o = (s, u, h, m) => requestAnimationFrame(() => {
286
286
  const { width: l, height: g } = e;
287
287
  n.clearRect(-0.5, -0.5, l + 1, g + 1), m && m.clear();
288
- const { top: f, left: x } = u;
289
- [...a].sort((p, d) => {
290
- const { annotation: { target: { created: c } } } = p, { annotation: { target: { created: y } } } = d;
291
- return c.getTime() - y.getTime();
288
+ const { top: f, left: w } = u;
289
+ [...s].sort((p, d) => {
290
+ const { annotation: { target: { created: a } } } = p, { annotation: { target: { created: y } } } = d;
291
+ return a.getTime() - y.getTime();
292
292
  }).forEach((p) => {
293
293
  var L;
294
- const d = h ? typeof h == "function" ? h(p.annotation, p.state) : h : (L = p.state) != null && L.selected ? ot : P, c = m && m.paint(p, u) || d, y = p.rects.map(({ x: E, y: B, width: T, height: M }) => ({
295
- x: E + x,
296
- y: B + f,
297
- width: T,
294
+ const d = h ? typeof h == "function" ? h(p.annotation, p.state) : h : (L = p.state) != null && L.selected ? ot : P, a = m && m.paint(p, u) || d, y = p.rects.map(({ x: E, y: T, width: B, height: M }) => ({
295
+ x: E + w,
296
+ y: T + f,
297
+ width: B,
298
298
  height: M
299
299
  }));
300
- n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1;
301
- const C = 5;
300
+ n.fillStyle = a.fill, n.globalAlpha = a.fillOpacity || 1;
301
+ const S = 5;
302
302
  if (y.forEach(
303
- ({ x: E, y: B, width: T, height: M }) => n.fillRect(
303
+ ({ x: E, y: T, width: B, height: M }) => n.fillRect(
304
304
  E,
305
- B - C / 2,
306
- T,
307
- M + C
305
+ T - S / 2,
306
+ B,
307
+ M + S
308
308
  )
309
- ), c.underlineColor) {
310
- n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
311
- const E = C / 2 + (c.underlineOffset ?? 0);
312
- y.forEach(({ x: B, y: T, width: M, height: b }) => {
313
- n.beginPath(), n.moveTo(B, T + b + E), n.lineTo(B + M, T + b + E), n.stroke();
309
+ ), a.underlineColor) {
310
+ n.globalAlpha = 1, n.strokeStyle = a.underlineColor, n.lineWidth = a.underlineThickness ?? 1;
311
+ const E = S / 2 + (a.underlineOffset ?? 0);
312
+ y.forEach(({ x: T, y: B, width: M, height: b }) => {
313
+ n.beginPath(), n.moveTo(T, B + b + E), n.lineTo(T + M, B + b + E), n.stroke();
314
314
  });
315
315
  }
316
316
  });
@@ -321,7 +321,7 @@ const P = {
321
321
  destroy: () => {
322
322
  t.removeChild(e), window.removeEventListener("resize", i);
323
323
  },
324
- setVisible: (a) => {
324
+ setVisible: (s) => {
325
325
  console.log("setVisible not implemented on Canvas renderer");
326
326
  },
327
327
  redraw: o
@@ -343,19 +343,19 @@ var me = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
343
343
  var e = t.toString(16);
344
344
  return e.length < 2 ? "0" + e : e;
345
345
  }, Xt = function(t) {
346
- var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), s = r - Math.min(e, n, o), a = s ? r === e ? (n - o) / s : r === n ? 2 + (o - e) / s : 4 + (e - n) / s : 0;
347
- return { h: 60 * (a < 0 ? a + 6 : a), s: r ? s / r * 100 : 0, v: r / 255 * 100, a: i };
348
- }, Ht = function(t) {
346
+ var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), c = r - Math.min(e, n, o), s = c ? r === e ? (n - o) / c : r === n ? 2 + (o - e) / c : 4 + (e - n) / c : 0;
347
+ return { h: 60 * (s < 0 ? s + 6 : s), s: r ? c / r * 100 : 0, v: r / 255 * 100, a: i };
348
+ }, $t = function(t) {
349
349
  var e = t.h, n = t.s, o = t.v, i = t.a;
350
350
  e = e / 360 * 6, n /= 100, o /= 100;
351
- var r = Math.floor(e), s = o * (1 - n), a = o * (1 - (e - r) * n), u = o * (1 - (1 - e + r) * n), h = r % 6;
352
- return { r: 255 * [o, a, s, s, u, o][h], g: 255 * [u, o, o, a, s, s][h], b: 255 * [s, s, u, o, o, a][h], a: i };
351
+ var r = Math.floor(e), c = o * (1 - n), s = o * (1 - (e - r) * n), u = o * (1 - (1 - e + r) * n), h = r % 6;
352
+ return { r: 255 * [o, s, c, c, u, o][h], g: 255 * [u, o, o, s, c, c][h], b: 255 * [c, c, u, o, o, s][h], a: i };
353
353
  }, Et = function(t) {
354
354
  return { h: _t(t.h), s: k(t.s, 0, 100), l: k(t.l, 0, 100), a: k(t.a) };
355
355
  }, St = function(t) {
356
356
  return { h: I(t.h), s: I(t.s), l: I(t.l), a: I(t.a, 3) };
357
357
  }, Ct = function(t) {
358
- return Ht((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 }));
358
+ 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
359
  var e, n, o;
360
360
  }, Q = function(t) {
361
361
  return { h: (e = Xt(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 };
@@ -377,15 +377,15 @@ var me = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
377
377
  }, "rgb"], [function(t) {
378
378
  var e = t.h, n = t.s, o = t.l, i = t.a, r = i === void 0 ? 1 : i;
379
379
  if (!X(e) || !X(n) || !X(o)) return null;
380
- var s = Et({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
381
- return Ct(s);
380
+ var c = Et({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
381
+ return Ct(c);
382
382
  }, "hsl"], [function(t) {
383
383
  var e = t.h, n = t.s, o = t.v, i = t.a, r = i === void 0 ? 1 : i;
384
384
  if (!X(e) || !X(n) || !X(o)) return null;
385
- var s = function(a) {
386
- return { h: _t(a.h), s: k(a.s, 0, 100), v: k(a.v, 0, 100), a: k(a.a) };
385
+ var c = function(s) {
386
+ return { h: _t(s.h), s: k(s.s, 0, 100), v: k(s.v, 0, 100), a: k(s.a) };
387
387
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(r) });
388
- return Ht(s);
388
+ return $t(c);
389
389
  }, "hsv"]] }, Bt = function(t, e) {
390
390
  for (var n = 0; n < e.length; n++) {
391
391
  var o = e[n][0](t);
@@ -415,8 +415,8 @@ var me = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
415
415
  }, t.prototype.isLight = function() {
416
416
  return ct(this.rgba) >= 0.5;
417
417
  }, t.prototype.toHex = function() {
418
- return e = st(this.rgba), n = e.r, o = e.g, i = e.b, s = (r = e.a) < 1 ? J(I(255 * r)) : "", "#" + J(n) + J(o) + J(i) + s;
419
- var e, n, o, i, r, s;
418
+ return e = st(this.rgba), n = e.r, o = e.g, i = e.b, c = (r = e.a) < 1 ? J(I(255 * r)) : "", "#" + J(n) + J(o) + J(i) + c;
419
+ var e, n, o, i, r, c;
420
420
  }, t.prototype.toRgb = function() {
421
421
  return st(this.rgba);
422
422
  }, t.prototype.toRgbString = function() {
@@ -474,18 +474,18 @@ const Ee = (t) => [
474
474
  setVisible: (r) => {
475
475
  console.log("setVisible not implemented on CSS Custom Highlights renderer");
476
476
  },
477
- redraw: (r, s, a, u) => {
477
+ redraw: (r, c, s, u) => {
478
478
  u && u.clear();
479
479
  const h = new Set(r.map((l) => l.annotation.id));
480
480
  Array.from(e).filter((l) => !h.has(l));
481
481
  const m = r.map((l) => {
482
- var x;
483
- const g = a ? typeof a == "function" ? a(l.annotation, l.state) : a : (x = l.state) != null && x.selected ? ot : P, f = u && u.paint(l, s) || g;
482
+ var w;
483
+ const g = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (w = l.state) != null && w.selected ? ot : P, f = u && u.paint(l, c) || g;
484
484
  return `::highlight(_${l.annotation.id}) { ${Ee(f)} }`;
485
485
  });
486
486
  t.innerHTML = m.join(`
487
487
  `), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
488
- const g = l.target.selector.map((x) => x.range), f = new Highlight(...g);
488
+ const g = l.target.selector.map((w) => w.range), f = new Highlight(...g);
489
489
  CSS.highlights.set(`_${l.id}`, f);
490
490
  }), e = h;
491
491
  }
@@ -524,25 +524,25 @@ const Le = (t, e) => {
524
524
  destroy: () => {
525
525
  e.remove();
526
526
  },
527
- redraw: (s, a, u, h, m) => {
528
- const g = !(mt(n, s) && m);
527
+ redraw: (c, s, u, h, m) => {
528
+ const g = !(mt(n, c) && m);
529
529
  if (!h && !g) return;
530
530
  g && (e.innerHTML = "");
531
- const f = s.reduce((x, { rects: v }) => [...x, ...v], []);
532
- s.forEach((x) => {
533
- x.rects.map((v) => {
534
- const p = Le(v, f), d = Kt(x, a, u, h, p);
531
+ const f = c.reduce((w, { rects: v }) => [...w, ...v], []);
532
+ c.forEach((w) => {
533
+ w.rects.map((v) => {
534
+ const p = Le(v, f), d = Kt(w, s, u, h, p);
535
535
  if (g) {
536
- const c = document.createElement("span");
537
- c.className = "r6o-annotation", c.dataset.annotation = x.annotation.id, c.style.left = `${v.x}px`, c.style.top = `${v.y}px`, c.style.width = `${v.width}px`, c.style.height = `${v.height}px`;
536
+ const a = document.createElement("span");
537
+ a.className = "r6o-annotation", a.dataset.annotation = w.annotation.id, a.style.left = `${v.x}px`, a.style.top = `${v.y}px`, a.style.width = `${v.width}px`, a.style.height = `${v.height}px`;
538
538
  const y = Y((d == null ? void 0 : d.fill) || P.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? P.fillOpacity : d.fillOpacity).toHex();
539
- c.style.backgroundColor = y, d.underlineStyle && (c.style.borderStyle = d.underlineStyle), d.underlineColor && (c.style.borderColor = d.underlineColor), d.underlineThickness && (c.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (c.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(c);
539
+ a.style.backgroundColor = y, d.underlineStyle && (a.style.borderStyle = d.underlineStyle), d.underlineColor && (a.style.borderColor = d.underlineColor), d.underlineThickness && (a.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (a.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(a);
540
540
  }
541
541
  });
542
- }), n = s;
542
+ }), n = c;
543
543
  },
544
- setVisible: (s) => {
545
- s ? e.classList.remove("hidden") : e.classList.add("hidden");
544
+ setVisible: (c) => {
545
+ c ? e.classList.remove("hidden") : e.classList.add("hidden");
546
546
  }
547
547
  };
548
548
  }, Te = (t, e, n) => vt(t, e, n, Be(t));
@@ -562,7 +562,7 @@ var Oe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(cryp
562
562
  const Mt = {
563
563
  randomUUID: Oe
564
564
  };
565
- function $t(t, e, n) {
565
+ function Ht(t, e, n) {
566
566
  if (Mt.randomUUID && !e && !t)
567
567
  return Mt.randomUUID();
568
568
  t = t || {};
@@ -599,8 +599,8 @@ const F = [];
599
599
  function yt(t, e = dt) {
600
600
  let n;
601
601
  const o = /* @__PURE__ */ new Set();
602
- function i(a) {
603
- if (Ie(t, a) && (t = a, n)) {
602
+ function i(s) {
603
+ if (Ie(t, s) && (t = s, n)) {
604
604
  const u = !F.length;
605
605
  for (const h of o)
606
606
  h[1](), F.push(h, t);
@@ -611,24 +611,24 @@ function yt(t, e = dt) {
611
611
  }
612
612
  }
613
613
  }
614
- function r(a) {
615
- i(a(t));
614
+ function r(s) {
615
+ i(s(t));
616
616
  }
617
- function s(a, u = dt) {
618
- const h = [a, u];
619
- return o.add(h), o.size === 1 && (n = e(i, r) || dt), a(t), () => {
617
+ function c(s, u = dt) {
618
+ const h = [s, u];
619
+ return o.add(h), o.size === 1 && (n = e(i, r) || dt), s(t), () => {
620
620
  o.delete(h), o.size === 0 && n && (n(), n = null);
621
621
  };
622
622
  }
623
- return { set: i, update: r, subscribe: s };
623
+ return { set: i, update: r, subscribe: c };
624
624
  }
625
625
  const Ve = (t) => {
626
626
  const { subscribe: e, set: n } = yt();
627
627
  let o;
628
628
  return e((i) => o = i), t.observe(({ changes: i }) => {
629
629
  if (o) {
630
- (i.deleted || []).some((s) => s.id === o) && n(void 0);
631
- const r = (i.updated || []).find(({ oldValue: s }) => s.id === o);
630
+ (i.deleted || []).some((c) => c.id === o) && n(void 0);
631
+ const r = (i.updated || []).find(({ oldValue: c }) => c.id === o);
632
632
  r && n(r.newValue.id);
633
633
  }
634
634
  }), {
@@ -644,10 +644,10 @@ const ut = { selected: [] }, ke = (t, e = "EDIT") => {
644
644
  const { subscribe: n, set: o } = yt(ut);
645
645
  let i = ut;
646
646
  n((l) => i = l);
647
- const r = () => o(ut), s = () => {
647
+ const r = () => o(ut), c = () => {
648
648
  var l;
649
649
  return ((l = i.selected) == null ? void 0 : l.length) === 0;
650
- }, a = (l) => {
650
+ }, s = (l) => {
651
651
  if (i.selected.length === 0)
652
652
  return !1;
653
653
  const g = typeof l == "string" ? l : l.id;
@@ -655,18 +655,18 @@ const ut = { selected: [] }, ke = (t, e = "EDIT") => {
655
655
  }, u = (l, g) => {
656
656
  const f = t.getAnnotation(l);
657
657
  if (f) {
658
- const x = It(f, e);
659
- o(x === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: g } : x === "SELECT" ? { selected: [{ id: l }], pointerEvent: g } : { selected: [], pointerEvent: g });
658
+ const w = It(f, e);
659
+ o(w === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: g } : w === "SELECT" ? { selected: [{ id: l }], pointerEvent: g } : { selected: [], pointerEvent: g });
660
660
  } else
661
661
  console.warn("Invalid selection: " + l);
662
662
  }, h = (l, g) => {
663
- const f = Array.isArray(l) ? l : [l], x = f.map((v) => t.getAnnotation(v)).filter(Boolean);
663
+ const f = Array.isArray(l) ? l : [l], w = f.map((v) => t.getAnnotation(v)).filter(Boolean);
664
664
  o({
665
- selected: x.map((v) => {
665
+ selected: w.map((v) => {
666
666
  const p = g === void 0 ? It(v, e) === "EDIT" : g;
667
667
  return { id: v.id, editable: p };
668
668
  })
669
- }), x.length !== f.length && console.warn("Invalid selection", l);
669
+ }), w.length !== f.length && console.warn("Invalid selection", l);
670
670
  }, m = (l) => {
671
671
  if (i.selected.length === 0)
672
672
  return !1;
@@ -682,8 +682,8 @@ const ut = { selected: [] }, ke = (t, e = "EDIT") => {
682
682
  get pointerEvent() {
683
683
  return i ? i.pointerEvent : null;
684
684
  },
685
- isEmpty: s,
686
- isSelected: a,
685
+ isEmpty: c,
686
+ isSelected: s,
687
687
  setSelected: h,
688
688
  subscribe: n
689
689
  };
@@ -704,7 +704,7 @@ var Xe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(cryp
704
704
  const Vt = {
705
705
  randomUUID: Xe
706
706
  };
707
- function He(t, e, n) {
707
+ function $e(t, e, n) {
708
708
  if (Vt.randomUUID && !e && !t)
709
709
  return Vt.randomUUID();
710
710
  t = t || {};
@@ -712,12 +712,12 @@ function He(t, e, n) {
712
712
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Ye(o);
713
713
  }
714
714
  const Vn = (t, e, n, o) => ({
715
- id: He(),
715
+ id: $e(),
716
716
  annotation: t.id,
717
717
  created: n || /* @__PURE__ */ new Date(),
718
718
  creator: o,
719
719
  ...e
720
- }), $e = (t, e) => {
720
+ }), He = (t, e) => {
721
721
  const n = new Set(t.bodies.map((o) => o.id));
722
722
  return e.bodies.filter((o) => !n.has(o.id));
723
723
  }, Pe = (t, e) => {
@@ -727,7 +727,7 @@ const Vn = (t, e, n, o) => ({
727
727
  const o = t.bodies.find((i) => i.id === n.id);
728
728
  return { newBody: n, oldBody: o && !q(o, n) ? o : void 0 };
729
729
  }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), ze = (t, e) => !q(t.target, e.target), Pt = (t, e) => {
730
- const n = $e(t, e), o = Pe(t, e), i = Fe(t, e);
730
+ const n = He(t, e), o = Pe(t, e), i = Fe(t, e);
731
731
  return {
732
732
  oldValue: t,
733
733
  newValue: e,
@@ -744,25 +744,25 @@ const We = (t, e) => {
744
744
  if (!(!t.options.origin || t.options.origin === r))
745
745
  return !1;
746
746
  if (t.options.ignore) {
747
- const { ignore: s } = t.options, a = (u) => u && u.length > 0;
748
- if (!(a(i.created) || a(i.deleted))) {
749
- const u = (n = i.updated) == null ? void 0 : n.some((m) => a(m.bodiesCreated) || a(m.bodiesDeleted) || a(m.bodiesUpdated)), h = (o = i.updated) == null ? void 0 : o.some((m) => m.targetUpdated);
750
- if (s === "BODY_ONLY" && u && !h || s === "TARGET_ONLY" && h && !u)
747
+ const { ignore: c } = t.options, s = (u) => u && u.length > 0;
748
+ if (!(s(i.created) || s(i.deleted))) {
749
+ const u = (n = i.updated) == null ? void 0 : n.some((m) => s(m.bodiesCreated) || s(m.bodiesDeleted) || s(m.bodiesUpdated)), h = (o = i.updated) == null ? void 0 : o.some((m) => m.targetUpdated);
750
+ if (c === "BODY_ONLY" && u && !h || c === "TARGET_ONLY" && h && !u)
751
751
  return !1;
752
752
  }
753
753
  }
754
754
  if (t.options.annotations) {
755
- const s = /* @__PURE__ */ new Set([
756
- ...(i.created || []).map((a) => a.id),
757
- ...(i.deleted || []).map((a) => a.id),
758
- ...(i.updated || []).map(({ oldValue: a }) => a.id)
755
+ const c = /* @__PURE__ */ new Set([
756
+ ...(i.created || []).map((s) => s.id),
757
+ ...(i.deleted || []).map((s) => s.id),
758
+ ...(i.updated || []).map(({ oldValue: s }) => s.id)
759
759
  ]);
760
- return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((a) => s.has(a));
760
+ return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => c.has(s));
761
761
  } else
762
762
  return !0;
763
763
  }, qe = (t, e) => {
764
- 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)), s = new Set((e.updated || []).map(({ oldValue: l }) => l.id)), a = new Set((e.updated || []).filter(({ oldValue: l }) => n.has(l.id) || o.has(l.id)).map(({ oldValue: l }) => l.id)), u = [
765
- ...(t.created || []).filter((l) => !r.has(l.id)).map((l) => s.has(l.id) ? e.updated.find(({ oldValue: g }) => g.id === l.id).newValue : l),
764
+ 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)), c = 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)), u = [
765
+ ...(t.created || []).filter((l) => !r.has(l.id)).map((l) => c.has(l.id) ? e.updated.find(({ oldValue: g }) => g.id === l.id).newValue : l),
766
766
  ...e.created || []
767
767
  ], h = [
768
768
  ...(t.deleted || []).filter((l) => !i.has(l.id)),
@@ -770,174 +770,174 @@ const We = (t, e) => {
770
770
  ], m = [
771
771
  ...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
772
772
  const { oldValue: g, newValue: f } = l;
773
- if (s.has(f.id)) {
774
- const x = e.updated.find((v) => v.oldValue.id === f.id).newValue;
775
- return Pt(g, x);
773
+ if (c.has(f.id)) {
774
+ const w = e.updated.find((v) => v.oldValue.id === f.id).newValue;
775
+ return Pt(g, w);
776
776
  } else
777
777
  return l;
778
778
  }),
779
- ...(e.updated || []).filter(({ oldValue: l }) => !a.has(l.id))
779
+ ...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
780
780
  ];
781
781
  return { created: u, deleted: h, updated: m };
782
782
  }, je = (t) => t.id !== void 0, Ge = () => {
783
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, w = {}) => n.push({ onChange: b, options: w }), i = (b) => {
784
- const w = n.findIndex((A) => A.onChange == b);
785
- w > -1 && n.splice(w, 1);
786
- }, r = (b, w) => {
783
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, x = {}) => n.push({ onChange: b, options: x }), i = (b) => {
784
+ const x = n.findIndex((A) => A.onChange == b);
785
+ x > -1 && n.splice(x, 1);
786
+ }, r = (b, x) => {
787
787
  const A = {
788
788
  origin: b,
789
789
  changes: {
790
- created: w.created || [],
791
- updated: w.updated || [],
792
- deleted: w.deleted || []
790
+ created: x.created || [],
791
+ updated: x.updated || [],
792
+ deleted: x.deleted || []
793
793
  },
794
794
  state: [...t.values()]
795
795
  };
796
- n.forEach((S) => {
797
- We(S, A) && S.onChange(A);
796
+ n.forEach((C) => {
797
+ We(C, A) && C.onChange(A);
798
798
  });
799
- }, s = (b, w = N.LOCAL) => {
799
+ }, c = (b, x = N.LOCAL) => {
800
800
  if (t.get(b.id))
801
801
  throw Error(`Cannot add annotation ${b.id} - exists already`);
802
- t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(w, { created: [b] });
803
- }, a = (b, w) => {
804
- const A = typeof b == "string" ? w : b, S = typeof b == "string" ? b : b.id, R = t.get(S);
802
+ t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(x, { created: [b] });
803
+ }, s = (b, x) => {
804
+ const A = typeof b == "string" ? x : b, C = typeof b == "string" ? b : b.id, R = t.get(C);
805
805
  if (R) {
806
806
  const O = Pt(R, A);
807
- return S === A.id ? t.set(S, A) : (t.delete(S), t.set(A.id, A)), R.bodies.forEach(($) => e.delete($.id)), A.bodies.forEach(($) => e.set($.id, A.id)), O;
807
+ return C === A.id ? t.set(C, A) : (t.delete(C), t.set(A.id, A)), R.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), O;
808
808
  } else
809
- console.warn(`Cannot update annotation ${S} - does not exist`);
810
- }, u = (b, w = N.LOCAL, A = N.LOCAL) => {
811
- const S = je(w) ? A : w, R = a(b, w);
812
- R && r(S, { updated: [R] });
813
- }, h = (b, w = N.LOCAL) => {
814
- const A = b.reduce((S, R) => {
815
- const O = a(R);
816
- return O ? [...S, O] : S;
809
+ console.warn(`Cannot update annotation ${C} - does not exist`);
810
+ }, u = (b, x = N.LOCAL, A = N.LOCAL) => {
811
+ const C = je(x) ? A : x, R = s(b, x);
812
+ R && r(C, { updated: [R] });
813
+ }, h = (b, x = N.LOCAL) => {
814
+ const A = b.reduce((C, R) => {
815
+ const O = s(R);
816
+ return O ? [...C, O] : C;
817
817
  }, []);
818
- A.length > 0 && r(w, { updated: A });
819
- }, m = (b, w = N.LOCAL) => {
818
+ A.length > 0 && r(x, { updated: A });
819
+ }, m = (b, x = N.LOCAL) => {
820
820
  const A = t.get(b.annotation);
821
821
  if (A) {
822
- const S = {
822
+ const C = {
823
823
  ...A,
824
824
  bodies: [...A.bodies, b]
825
825
  };
826
- t.set(A.id, S), e.set(b.id, S.id), r(w, { updated: [{
826
+ t.set(A.id, C), e.set(b.id, C.id), r(x, { updated: [{
827
827
  oldValue: A,
828
- newValue: S,
828
+ newValue: C,
829
829
  bodiesCreated: [b]
830
830
  }] });
831
831
  } else
832
832
  console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
833
833
  }, l = () => [...t.values()], g = (b = N.LOCAL) => {
834
- const w = [...t.values()];
835
- t.clear(), e.clear(), r(b, { deleted: w });
836
- }, f = (b, w = !0, A = N.LOCAL) => {
837
- if (w) {
838
- const S = [...t.values()];
834
+ const x = [...t.values()];
835
+ t.clear(), e.clear(), r(b, { deleted: x });
836
+ }, f = (b, x = !0, A = N.LOCAL) => {
837
+ if (x) {
838
+ const C = [...t.values()];
839
839
  t.clear(), e.clear(), b.forEach((R) => {
840
840
  t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
841
- }), r(A, { created: b, deleted: S });
841
+ }), r(A, { created: b, deleted: C });
842
842
  } else {
843
- const S = b.reduce((R, O) => {
844
- const $ = t.get(O.id);
845
- return $ ? [...R, $] : R;
843
+ const C = b.reduce((R, O) => {
844
+ const H = t.get(O.id);
845
+ return H ? [...R, H] : R;
846
846
  }, []);
847
- if (S.length > 0)
848
- throw Error(`Bulk insert would overwrite the following annotations: ${S.map((R) => R.id).join(", ")}`);
847
+ if (C.length > 0)
848
+ throw Error(`Bulk insert would overwrite the following annotations: ${C.map((R) => R.id).join(", ")}`);
849
849
  b.forEach((R) => {
850
850
  t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
851
851
  }), r(A, { created: b });
852
852
  }
853
- }, x = (b) => {
854
- const w = typeof b == "string" ? b : b.id, A = t.get(w);
853
+ }, w = (b) => {
854
+ const x = typeof b == "string" ? b : b.id, A = t.get(x);
855
855
  if (A)
856
- return t.delete(w), A.bodies.forEach((S) => e.delete(S.id)), A;
857
- console.warn(`Attempt to delete missing annotation: ${w}`);
858
- }, v = (b, w = N.LOCAL) => {
859
- const A = x(b);
860
- A && r(w, { deleted: [A] });
861
- }, p = (b, w = N.LOCAL) => {
862
- const A = b.reduce((S, R) => {
863
- const O = x(R);
864
- return O ? [...S, O] : S;
856
+ return t.delete(x), A.bodies.forEach((C) => e.delete(C.id)), A;
857
+ console.warn(`Attempt to delete missing annotation: ${x}`);
858
+ }, v = (b, x = N.LOCAL) => {
859
+ const A = w(b);
860
+ A && r(x, { deleted: [A] });
861
+ }, p = (b, x = N.LOCAL) => {
862
+ const A = b.reduce((C, R) => {
863
+ const O = w(R);
864
+ return O ? [...C, O] : C;
865
865
  }, []);
866
- A.length > 0 && r(w, { deleted: A });
866
+ A.length > 0 && r(x, { deleted: A });
867
867
  }, d = (b) => {
868
- const w = t.get(b.annotation);
869
- if (w) {
870
- const A = w.bodies.find((S) => S.id === b.id);
868
+ const x = t.get(b.annotation);
869
+ if (x) {
870
+ const A = x.bodies.find((C) => C.id === b.id);
871
871
  if (A) {
872
872
  e.delete(A.id);
873
- const S = {
874
- ...w,
875
- bodies: w.bodies.filter((R) => R.id !== b.id)
873
+ const C = {
874
+ ...x,
875
+ bodies: x.bodies.filter((R) => R.id !== b.id)
876
876
  };
877
- return t.set(w.id, S), {
878
- oldValue: w,
879
- newValue: S,
877
+ return t.set(x.id, C), {
878
+ oldValue: x,
879
+ newValue: C,
880
880
  bodiesDeleted: [A]
881
881
  };
882
882
  } else
883
883
  console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
884
884
  } else
885
885
  console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
886
- }, c = (b, w = N.LOCAL) => {
886
+ }, a = (b, x = N.LOCAL) => {
887
887
  const A = d(b);
888
- A && r(w, { updated: [A] });
889
- }, y = (b, w = N.LOCAL) => {
890
- const A = b.map((S) => d(S)).filter(Boolean);
891
- A.length > 0 && r(w, { updated: A });
892
- }, C = (b) => {
893
- const w = t.get(b);
894
- return w ? { ...w } : void 0;
888
+ A && r(x, { updated: [A] });
889
+ }, y = (b, x = N.LOCAL) => {
890
+ const A = b.map((C) => d(C)).filter(Boolean);
891
+ A.length > 0 && r(x, { updated: A });
892
+ }, S = (b) => {
893
+ const x = t.get(b);
894
+ return x ? { ...x } : void 0;
895
895
  }, L = (b) => {
896
- const w = e.get(b);
897
- if (w) {
898
- const A = C(w).bodies.find((S) => S.id === b);
896
+ const x = e.get(b);
897
+ if (x) {
898
+ const A = S(x).bodies.find((C) => C.id === b);
899
899
  if (A)
900
900
  return A;
901
901
  console.error(`Store integrity error: body ${b} in index, but not in annotation`);
902
902
  } else
903
903
  console.warn(`Attempt to retrieve missing body: ${b}`);
904
- }, E = (b, w) => {
905
- if (b.annotation !== w.annotation)
904
+ }, E = (b, x) => {
905
+ if (b.annotation !== x.annotation)
906
906
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
907
907
  const A = t.get(b.annotation);
908
908
  if (A) {
909
- const S = A.bodies.find((O) => O.id === b.id), R = {
909
+ const C = A.bodies.find((O) => O.id === b.id), R = {
910
910
  ...A,
911
- bodies: A.bodies.map((O) => O.id === S.id ? w : O)
911
+ bodies: A.bodies.map((O) => O.id === C.id ? x : O)
912
912
  };
913
- return t.set(A.id, R), S.id !== w.id && (e.delete(S.id), e.set(w.id, R.id)), {
913
+ return t.set(A.id, R), C.id !== x.id && (e.delete(C.id), e.set(x.id, R.id)), {
914
914
  oldValue: A,
915
915
  newValue: R,
916
- bodiesUpdated: [{ oldBody: S, newBody: w }]
916
+ bodiesUpdated: [{ oldBody: C, newBody: x }]
917
917
  };
918
918
  } else
919
919
  console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
920
- }, B = (b, w, A = N.LOCAL) => {
921
- const S = E(b, w);
922
- S && r(A, { updated: [S] });
923
- }, T = (b, w = N.LOCAL) => {
924
- const A = b.map((S) => E({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
925
- r(w, { updated: A });
920
+ }, T = (b, x, A = N.LOCAL) => {
921
+ const C = E(b, x);
922
+ C && r(A, { updated: [C] });
923
+ }, B = (b, x = N.LOCAL) => {
924
+ const A = b.map((C) => E({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
925
+ r(x, { updated: A });
926
926
  }, M = (b) => {
927
- const w = t.get(b.annotation);
928
- if (w) {
927
+ const x = t.get(b.annotation);
928
+ if (x) {
929
929
  const A = {
930
- ...w,
930
+ ...x,
931
931
  target: {
932
- ...w.target,
932
+ ...x.target,
933
933
  ...b
934
934
  }
935
935
  };
936
- return t.set(w.id, A), {
937
- oldValue: w,
936
+ return t.set(x.id, A), {
937
+ oldValue: x,
938
938
  newValue: A,
939
939
  targetUpdated: {
940
- oldTarget: w.target,
940
+ oldTarget: x.target,
941
941
  newTarget: b
942
942
  }
943
943
  };
@@ -945,30 +945,30 @@ const We = (t, e) => {
945
945
  console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
946
946
  };
947
947
  return {
948
- addAnnotation: s,
948
+ addAnnotation: c,
949
949
  addBody: m,
950
950
  all: l,
951
951
  bulkAddAnnotation: f,
952
952
  bulkDeleteAnnotation: p,
953
953
  bulkDeleteBodies: y,
954
954
  bulkUpdateAnnotation: h,
955
- bulkUpdateBodies: T,
956
- bulkUpdateTargets: (b, w = N.LOCAL) => {
957
- const A = b.map((S) => M(S)).filter(Boolean);
958
- A.length > 0 && r(w, { updated: A });
955
+ bulkUpdateBodies: B,
956
+ bulkUpdateTargets: (b, x = N.LOCAL) => {
957
+ const A = b.map((C) => M(C)).filter(Boolean);
958
+ A.length > 0 && r(x, { updated: A });
959
959
  },
960
960
  clear: g,
961
961
  deleteAnnotation: v,
962
- deleteBody: c,
963
- getAnnotation: C,
962
+ deleteBody: a,
963
+ getAnnotation: S,
964
964
  getBody: L,
965
965
  observe: o,
966
966
  unobserve: i,
967
967
  updateAnnotation: u,
968
- updateBody: B,
969
- updateTarget: (b, w = N.LOCAL) => {
968
+ updateBody: T,
969
+ updateTarget: (b, x = N.LOCAL) => {
970
970
  const A = M(b);
971
- A && r(w, { updated: [A] });
971
+ A && r(x, { updated: [A] });
972
972
  }
973
973
  };
974
974
  };
@@ -989,38 +989,38 @@ let Ke = () => ({
989
989
  const Qe = 250, Je = (t) => {
990
990
  const e = Ke(), n = [];
991
991
  let o = -1, i = !1, r = 0;
992
- const s = (f) => {
992
+ const c = (f) => {
993
993
  if (!i) {
994
- const { changes: x } = f, v = performance.now();
994
+ const { changes: w } = f, v = performance.now();
995
995
  if (v - r > Qe)
996
- n.splice(o + 1), n.push(x), o = n.length - 1;
996
+ n.splice(o + 1), n.push(w), o = n.length - 1;
997
997
  else {
998
998
  const p = n.length - 1;
999
- n[p] = qe(n[p], x);
999
+ n[p] = qe(n[p], w);
1000
1000
  }
1001
1001
  r = v;
1002
1002
  }
1003
1003
  i = !1;
1004
1004
  };
1005
- t.observe(s, { origin: N.LOCAL });
1006
- const a = (f) => f && f.length > 0 && t.bulkDeleteAnnotation(f), u = (f) => f && f.length > 0 && t.bulkAddAnnotation(f, !1), h = (f) => f && f.length > 0 && t.bulkUpdateAnnotation(f.map(({ oldValue: x }) => x)), m = (f) => f && f.length > 0 && t.bulkUpdateAnnotation(f.map(({ newValue: x }) => x)), l = (f) => f && f.length > 0 && t.bulkAddAnnotation(f, !1), g = (f) => f && f.length > 0 && t.bulkDeleteAnnotation(f);
1005
+ t.observe(c, { origin: N.LOCAL });
1006
+ const s = (f) => f && f.length > 0 && t.bulkDeleteAnnotation(f), u = (f) => f && f.length > 0 && t.bulkAddAnnotation(f, !1), h = (f) => f && f.length > 0 && t.bulkUpdateAnnotation(f.map(({ oldValue: w }) => w)), m = (f) => f && f.length > 0 && t.bulkUpdateAnnotation(f.map(({ newValue: w }) => w)), l = (f) => f && f.length > 0 && t.bulkAddAnnotation(f, !1), g = (f) => f && f.length > 0 && t.bulkDeleteAnnotation(f);
1007
1007
  return {
1008
1008
  canRedo: () => n.length - 1 > o,
1009
1009
  canUndo: () => o > -1,
1010
- destroy: () => t.unobserve(s),
1011
- on: (f, x) => e.on(f, x),
1010
+ destroy: () => t.unobserve(c),
1011
+ on: (f, w) => e.on(f, w),
1012
1012
  redo: () => {
1013
1013
  if (n.length - 1 > o) {
1014
1014
  i = !0;
1015
- const { created: f, updated: x, deleted: v } = n[o + 1];
1016
- u(f), m(x), g(v), e.emit("redo", n[o + 1]), o += 1;
1015
+ const { created: f, updated: w, deleted: v } = n[o + 1];
1016
+ u(f), m(w), g(v), e.emit("redo", n[o + 1]), o += 1;
1017
1017
  }
1018
1018
  },
1019
1019
  undo: () => {
1020
1020
  if (o > -1) {
1021
1021
  i = !0;
1022
- const { created: f, updated: x, deleted: v } = n[o];
1023
- a(f), h(x), l(v), e.emit("undo", n[o]), o -= 1;
1022
+ const { created: f, updated: w, deleted: v } = n[o];
1023
+ s(f), h(w), l(v), e.emit("undo", n[o]), o -= 1;
1024
1024
  }
1025
1025
  }
1026
1026
  };
@@ -1031,24 +1031,24 @@ const Qe = 250, Je = (t) => {
1031
1031
  set: e
1032
1032
  };
1033
1033
  }, tn = (t, e, n, o) => {
1034
- const { store: i, selection: r, hover: s, viewport: a } = t, u = /* @__PURE__ */ new Map();
1034
+ const { store: i, selection: r, hover: c, viewport: s } = t, u = /* @__PURE__ */ new Map();
1035
1035
  let h = [], m;
1036
1036
  const l = (v, p) => {
1037
1037
  u.has(v) ? u.get(v).push(p) : u.set(v, [p]);
1038
1038
  }, g = (v, p) => {
1039
1039
  const d = u.get(v);
1040
1040
  if (d) {
1041
- const c = d.indexOf(p);
1042
- c !== -1 && d.splice(c, 1);
1041
+ const a = d.indexOf(p);
1042
+ a !== -1 && d.splice(a, 1);
1043
1043
  }
1044
1044
  }, f = (v, p, d) => {
1045
1045
  u.has(v) && setTimeout(() => {
1046
- u.get(v).forEach((c) => {
1046
+ u.get(v).forEach((a) => {
1047
1047
  if (n) {
1048
- const y = Array.isArray(p) ? p.map((L) => n.serialize(L)) : n.serialize(p), C = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1049
- c(y, C);
1048
+ const y = Array.isArray(p) ? p.map((L) => n.serialize(L)) : n.serialize(p), S = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1049
+ a(y, S);
1050
1050
  } else
1051
- c(p, d);
1051
+ a(p, d);
1052
1052
  });
1053
1053
  }, 1);
1054
1054
  };
@@ -1062,42 +1062,42 @@ const Qe = 250, Je = (t) => {
1062
1062
  d && !q(d, p) && f("updateAnnotation", d, p);
1063
1063
  }), h = [];
1064
1064
  else {
1065
- const p = new Set(h.map((c) => c.id)), d = new Set(v.map(({ id: c }) => c));
1066
- h.filter((c) => !d.has(c.id)).forEach((c) => {
1067
- const y = i.getAnnotation(c.id);
1068
- y && !q(y, c) && f("updateAnnotation", y, c);
1065
+ const p = new Set(h.map((a) => a.id)), d = new Set(v.map(({ id: a }) => a));
1066
+ h.filter((a) => !d.has(a.id)).forEach((a) => {
1067
+ const y = i.getAnnotation(a.id);
1068
+ y && !q(y, a) && f("updateAnnotation", y, a);
1069
1069
  }), h = [
1070
1070
  // Remove annotations that were deselected
1071
- ...h.filter((c) => d.has(c.id)),
1071
+ ...h.filter((a) => d.has(a.id)),
1072
1072
  // Add editable annotations that were selected
1073
- ...v.filter(({ id: c }) => !p.has(c)).map(({ id: c }) => i.getAnnotation(c))
1073
+ ...v.filter(({ id: a }) => !p.has(a)).map(({ id: a }) => i.getAnnotation(a))
1074
1074
  ];
1075
1075
  }
1076
1076
  f("selectionChanged", h);
1077
1077
  }
1078
- }), s.subscribe((v) => {
1078
+ }), c.subscribe((v) => {
1079
1079
  !m && v ? f("mouseEnterAnnotation", i.getAnnotation(v)) : m && !v ? f("mouseLeaveAnnotation", i.getAnnotation(m)) : m && v && (f("mouseLeaveAnnotation", i.getAnnotation(m)), f("mouseEnterAnnotation", i.getAnnotation(v))), m = v;
1080
- }), a == null || a.subscribe((v) => f("viewportIntersect", v.map((p) => i.getAnnotation(p)))), i.observe((v) => {
1080
+ }), s == null || s.subscribe((v) => f("viewportIntersect", v.map((p) => i.getAnnotation(p)))), i.observe((v) => {
1081
1081
  const { created: p, deleted: d } = v.changes;
1082
- (p || []).forEach((c) => f("createAnnotation", c)), (d || []).forEach((c) => f("deleteAnnotation", c)), (v.changes.updated || []).filter((c) => [
1083
- ...c.bodiesCreated || [],
1084
- ...c.bodiesDeleted || [],
1085
- ...c.bodiesUpdated || []
1086
- ].length > 0).forEach(({ oldValue: c, newValue: y }) => {
1087
- const C = h.find((L) => L.id === c.id) || c;
1088
- h = h.map((L) => L.id === c.id ? y : L), f("updateAnnotation", y, C);
1082
+ (p || []).forEach((a) => f("createAnnotation", a)), (d || []).forEach((a) => f("deleteAnnotation", a)), (v.changes.updated || []).filter((a) => [
1083
+ ...a.bodiesCreated || [],
1084
+ ...a.bodiesDeleted || [],
1085
+ ...a.bodiesUpdated || []
1086
+ ].length > 0).forEach(({ oldValue: a, newValue: y }) => {
1087
+ const S = h.find((L) => L.id === a.id) || a;
1088
+ h = h.map((L) => L.id === a.id ? y : L), f("updateAnnotation", y, S);
1089
1089
  });
1090
1090
  }, { origin: N.LOCAL }), i.observe((v) => {
1091
1091
  if (h) {
1092
- const p = new Set(h.map((c) => c.id)), d = (v.changes.updated || []).filter(({ newValue: c }) => p.has(c.id)).map(({ newValue: c }) => c);
1093
- d.length > 0 && (h = h.map((c) => d.find((C) => C.id === c.id) || c));
1092
+ const p = new Set(h.map((a) => a.id)), d = (v.changes.updated || []).filter(({ newValue: a }) => p.has(a.id)).map(({ newValue: a }) => a);
1093
+ d.length > 0 && (h = h.map((a) => d.find((S) => S.id === a.id) || a));
1094
1094
  }
1095
1095
  }, { origin: N.REMOTE });
1096
- const x = (v) => (p) => {
1096
+ const w = (v) => (p) => {
1097
1097
  const { updated: d } = p;
1098
- v ? (d || []).forEach((c) => f("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => f("updateAnnotation", c.newValue, c.oldValue));
1098
+ v ? (d || []).forEach((a) => f("updateAnnotation", a.oldValue, a.newValue)) : (d || []).forEach((a) => f("updateAnnotation", a.newValue, a.oldValue));
1099
1099
  };
1100
- return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: l, off: g, emit: f };
1100
+ return e.on("undo", w(!0)), e.on("redo", w(!1)), { on: l, off: g, emit: f };
1101
1101
  }, en = (t) => (e) => e.reduce((n, o) => {
1102
1102
  const { parsed: i, error: r } = t.parse(o);
1103
1103
  return r ? {
@@ -1112,18 +1112,18 @@ const Qe = 250, Je = (t) => {
1112
1112
  }, { parsed: [], failed: [] }), nn = (t, e, n) => {
1113
1113
  const { store: o, selection: i } = t, r = (p) => {
1114
1114
  if (n) {
1115
- const { parsed: d, error: c } = n.parse(p);
1116
- d ? o.addAnnotation(d, N.REMOTE) : console.error(c);
1115
+ const { parsed: d, error: a } = n.parse(p);
1116
+ d ? o.addAnnotation(d, N.REMOTE) : console.error(a);
1117
1117
  } else
1118
1118
  o.addAnnotation(p, N.REMOTE);
1119
- }, s = () => i.clear(), a = () => o.clear(), u = (p) => {
1119
+ }, c = () => i.clear(), s = () => o.clear(), u = (p) => {
1120
1120
  const d = o.getAnnotation(p);
1121
1121
  return n && d ? n.serialize(d) : d;
1122
1122
  }, h = () => n ? o.all().map(n.serialize) : o.all(), m = () => {
1123
1123
  var p;
1124
- const d = (((p = i.selected) == null ? void 0 : p.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
1124
+ const d = (((p = i.selected) == null ? void 0 : p.map((a) => a.id)) || []).map((a) => o.getAnnotation(a)).filter(Boolean);
1125
1125
  return n ? d.map(n.serialize) : d;
1126
- }, l = (p, d = !0) => fetch(p).then((c) => c.json()).then((c) => (f(c, d), c)), g = (p) => {
1126
+ }, l = (p, d = !0) => fetch(p).then((a) => a.json()).then((a) => (f(a, d), a)), g = (p) => {
1127
1127
  if (typeof p == "string") {
1128
1128
  const d = o.getAnnotation(p);
1129
1129
  if (o.deleteAnnotation(p), d)
@@ -1135,16 +1135,16 @@ const Qe = 250, Je = (t) => {
1135
1135
  }
1136
1136
  }, f = (p, d = !0) => {
1137
1137
  if (n) {
1138
- const { parsed: c, failed: y } = en(n)(p);
1139
- y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(c, d, N.REMOTE);
1138
+ const { parsed: a, failed: y } = en(n)(p);
1139
+ y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(a, d, N.REMOTE);
1140
1140
  } else
1141
1141
  o.bulkAddAnnotation(p, d, N.REMOTE);
1142
- }, x = (p, d) => {
1142
+ }, w = (p, d) => {
1143
1143
  p ? i.setSelected(p, d) : i.clear();
1144
1144
  }, v = (p) => {
1145
1145
  if (n) {
1146
- const d = n.parse(p).parsed, c = n.serialize(o.getAnnotation(d.id));
1147
- return o.updateAnnotation(d), c;
1146
+ const d = n.parse(p).parsed, a = n.serialize(o.getAnnotation(d.id));
1147
+ return o.updateAnnotation(d), a;
1148
1148
  } else {
1149
1149
  const d = o.getAnnotation(p.id);
1150
1150
  return o.updateAnnotation(p), d;
@@ -1152,10 +1152,10 @@ const Qe = 250, Je = (t) => {
1152
1152
  };
1153
1153
  return {
1154
1154
  addAnnotation: r,
1155
- cancelSelected: s,
1155
+ cancelSelected: c,
1156
1156
  canRedo: e.canRedo,
1157
1157
  canUndo: e.canUndo,
1158
- clearAnnotations: a,
1158
+ clearAnnotations: s,
1159
1159
  getAnnotationById: u,
1160
1160
  getAnnotations: h,
1161
1161
  getSelected: m,
@@ -1163,7 +1163,7 @@ const Qe = 250, Je = (t) => {
1163
1163
  redo: e.redo,
1164
1164
  removeAnnotation: g,
1165
1165
  setAnnotations: f,
1166
- setSelected: x,
1166
+ setSelected: w,
1167
1167
  undo: e.undo,
1168
1168
  updateAnnotation: v
1169
1169
  };
@@ -1171,11 +1171,11 @@ const Qe = 250, Je = (t) => {
1171
1171
  let rn = (t) => crypto.getRandomValues(new Uint8Array(t)), sn = (t, e, n) => {
1172
1172
  let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
1173
1173
  return (r = e) => {
1174
- let s = "";
1174
+ let c = "";
1175
1175
  for (; ; ) {
1176
- let a = n(i), u = i;
1176
+ let s = n(i), u = i;
1177
1177
  for (; u--; )
1178
- if (s += t[a[u] & o] || "", s.length === r) return s;
1178
+ if (c += t[s[u] & o] || "", c.length === r) return c;
1179
1179
  }
1180
1180
  };
1181
1181
  }, an = (t, e = 21) => sn(t, e, rn), cn = (t = 21) => {
@@ -1193,26 +1193,26 @@ const ln = () => ({ isGuest: !0, id: an("1234567890abcdefghijklmnopqrstuvwxyzABC
1193
1193
  }
1194
1194
  return `${n}`;
1195
1195
  }, Ft = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, un = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1196
- const { id: o, type: i, purpose: r, value: s, created: a, modified: u, creator: h, ...m } = n;
1196
+ const { id: o, type: i, purpose: r, value: c, created: s, modified: u, creator: h, ...m } = n;
1197
1197
  return {
1198
1198
  id: o || `temp-${dn(n)}`,
1199
1199
  annotation: e,
1200
1200
  type: i,
1201
1201
  purpose: r,
1202
- value: s,
1202
+ value: c,
1203
1203
  creator: Ft(h),
1204
- created: a ? new Date(a) : void 0,
1204
+ created: s ? new Date(s) : void 0,
1205
1205
  updated: u ? new Date(u) : void 0,
1206
1206
  ...m
1207
1207
  };
1208
1208
  }), hn = (t) => t.map((e) => {
1209
1209
  var n;
1210
- const { annotation: o, created: i, updated: r, ...s } = e, a = {
1211
- ...s,
1210
+ const { annotation: o, created: i, updated: r, ...c } = e, s = {
1211
+ ...c,
1212
1212
  created: i == null ? void 0 : i.toISOString(),
1213
1213
  modified: r == null ? void 0 : r.toISOString()
1214
1214
  };
1215
- return (n = a.id) != null && n.startsWith("temp-") && delete a.id, a;
1215
+ return (n = s.id) != null && n.startsWith("temp-") && delete s.id, s;
1216
1216
  });
1217
1217
  cn();
1218
1218
  const Un = (t, e) => ({
@@ -1225,14 +1225,14 @@ const Un = (t, e) => ({
1225
1225
  created: o,
1226
1226
  modified: i,
1227
1227
  target: r
1228
- } = t, s = Array.isArray(r) ? r : [r], a = {
1228
+ } = t, c = Array.isArray(r) ? r : [r], s = {
1229
1229
  creator: Ft(n),
1230
1230
  created: o ? new Date(o) : void 0,
1231
1231
  updated: i ? new Date(i) : void 0,
1232
1232
  annotation: e,
1233
1233
  selector: []
1234
1234
  };
1235
- for (const u of s) {
1235
+ for (const u of c) {
1236
1236
  const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((l, g) => {
1237
1237
  switch (g.type) {
1238
1238
  case "TextQuoteSelector":
@@ -1245,7 +1245,7 @@ const Un = (t, e) => ({
1245
1245
  return l;
1246
1246
  }, {});
1247
1247
  if (fn(m))
1248
- a.selector.push({ id: u.id, ...m });
1248
+ s.selector.push({ id: u.id, ...m });
1249
1249
  else {
1250
1250
  const l = [
1251
1251
  m.start ? void 0 : "TextPositionSelector",
@@ -1254,39 +1254,39 @@ const Un = (t, e) => ({
1254
1254
  return { error: Error(`Missing selector types: ${l.join(" and ")} for annotation: ${t.id}`) };
1255
1255
  }
1256
1256
  }
1257
- return { parsed: a };
1257
+ return { parsed: s };
1258
1258
  }, pn = (t) => {
1259
- const e = t.id || $t(), {
1259
+ const e = t.id || Ht(), {
1260
1260
  creator: n,
1261
1261
  created: o,
1262
1262
  modified: i,
1263
1263
  body: r,
1264
- ...s
1265
- } = t, a = un(r, e), u = gn(t);
1264
+ ...c
1265
+ } = t, s = un(r, e), u = gn(t);
1266
1266
  return "error" in u ? { error: u.error } : {
1267
1267
  parsed: {
1268
- ...s,
1268
+ ...c,
1269
1269
  id: e,
1270
- bodies: a,
1270
+ bodies: s,
1271
1271
  target: u.parsed
1272
1272
  }
1273
1273
  };
1274
1274
  }, mn = (t, e, n) => {
1275
1275
  const { bodies: o, target: i, ...r } = t, {
1276
- selector: s,
1277
- creator: a,
1276
+ selector: c,
1277
+ creator: s,
1278
1278
  created: u,
1279
1279
  updated: h,
1280
1280
  ...m
1281
- } = i, l = s.map((g) => {
1282
- const { quote: f, start: x, end: v, range: p } = g, { prefix: d, suffix: c } = oe(p, n), y = [{
1281
+ } = i, l = c.map((g) => {
1282
+ const { quote: f, start: w, end: v, range: p } = g, { prefix: d, suffix: a } = oe(p, n), y = [{
1283
1283
  type: "TextQuoteSelector",
1284
1284
  exact: f,
1285
1285
  prefix: d,
1286
- suffix: c
1286
+ suffix: a
1287
1287
  }, {
1288
1288
  type: "TextPositionSelector",
1289
- start: x,
1289
+ start: w,
1290
1290
  end: v
1291
1291
  }];
1292
1292
  return {
@@ -1302,7 +1302,7 @@ const Un = (t, e) => ({
1302
1302
  id: t.id,
1303
1303
  type: "Annotation",
1304
1304
  body: hn(t.bodies),
1305
- creator: a,
1305
+ creator: s,
1306
1306
  created: u == null ? void 0 : u.toISOString(),
1307
1307
  modified: h == null ? void 0 : h.toISOString(),
1308
1308
  target: l
@@ -1314,15 +1314,15 @@ function bn(t, e, n, o, i) {
1314
1314
  function zt(t, e, n, o, i) {
1315
1315
  for (; o > n; ) {
1316
1316
  if (o - n > 600) {
1317
- var r = o - n + 1, s = e - n + 1, a = Math.log(r), u = 0.5 * Math.exp(2 * a / 3), h = 0.5 * Math.sqrt(a * u * (r - u) / r) * (s - r / 2 < 0 ? -1 : 1), m = Math.max(n, Math.floor(e - s * u / r + h)), l = Math.min(o, Math.floor(e + (r - s) * u / r + h));
1317
+ var r = o - n + 1, c = e - n + 1, s = Math.log(r), u = 0.5 * Math.exp(2 * s / 3), h = 0.5 * Math.sqrt(s * u * (r - u) / r) * (c - r / 2 < 0 ? -1 : 1), m = Math.max(n, Math.floor(e - c * u / r + h)), l = Math.min(o, Math.floor(e + (r - c) * u / r + h));
1318
1318
  zt(t, e, m, l, i);
1319
1319
  }
1320
- var g = t[e], f = n, x = o;
1321
- for (j(t, n, e), i(t[o], g) > 0 && j(t, n, o); f < x; ) {
1322
- for (j(t, f, x), f++, x--; i(t[f], g) < 0; ) f++;
1323
- for (; i(t[x], g) > 0; ) x--;
1320
+ var g = t[e], f = n, w = o;
1321
+ for (j(t, n, e), i(t[o], g) > 0 && j(t, n, o); f < w; ) {
1322
+ for (j(t, f, w), f++, w--; i(t[f], g) < 0; ) f++;
1323
+ for (; i(t[w], g) > 0; ) w--;
1324
1324
  }
1325
- i(t[n], g) === 0 ? j(t, n, x) : (x++, j(t, x, o)), x <= e && (n = x + 1), e <= x && (o = x - 1);
1325
+ i(t[n], g) === 0 ? j(t, n, w) : (w++, j(t, w, o)), w <= e && (n = w + 1), e <= w && (o = w - 1);
1326
1326
  }
1327
1327
  }
1328
1328
  function j(t, e, n) {
@@ -1345,9 +1345,9 @@ class yn {
1345
1345
  if (!nt(e, n)) return o;
1346
1346
  const i = this.toBBox, r = [];
1347
1347
  for (; n; ) {
1348
- for (let s = 0; s < n.children.length; s++) {
1349
- const a = n.children[s], u = n.leaf ? i(a) : a;
1350
- nt(e, u) && (n.leaf ? o.push(a) : gt(e, u) ? this._all(a, o) : r.push(a));
1348
+ for (let c = 0; c < n.children.length; c++) {
1349
+ const s = n.children[c], u = n.leaf ? i(s) : s;
1350
+ nt(e, u) && (n.leaf ? o.push(s) : gt(e, u) ? this._all(s, o) : r.push(s));
1351
1351
  }
1352
1352
  n = r.pop();
1353
1353
  }
@@ -1359,9 +1359,9 @@ class yn {
1359
1359
  const o = [];
1360
1360
  for (; n; ) {
1361
1361
  for (let i = 0; i < n.children.length; i++) {
1362
- const r = n.children[i], s = n.leaf ? this.toBBox(r) : r;
1363
- if (nt(e, s)) {
1364
- if (n.leaf || gt(e, s)) return !0;
1362
+ const r = n.children[i], c = n.leaf ? this.toBBox(r) : r;
1363
+ if (nt(e, c)) {
1364
+ if (n.leaf || gt(e, c)) return !0;
1365
1365
  o.push(r);
1366
1366
  }
1367
1367
  }
@@ -1399,15 +1399,15 @@ class yn {
1399
1399
  remove(e, n) {
1400
1400
  if (!e) return this;
1401
1401
  let o = this.data;
1402
- const i = this.toBBox(e), r = [], s = [];
1403
- let a, u, h;
1402
+ const i = this.toBBox(e), r = [], c = [];
1403
+ let s, u, h;
1404
1404
  for (; o || r.length; ) {
1405
- if (o || (o = r.pop(), u = r[r.length - 1], a = s.pop(), h = !0), o.leaf) {
1405
+ if (o || (o = r.pop(), u = r[r.length - 1], s = c.pop(), h = !0), o.leaf) {
1406
1406
  const m = wn(e, o.children, n);
1407
1407
  if (m !== -1)
1408
1408
  return o.children.splice(m, 1), r.push(o), this._condense(r), this;
1409
1409
  }
1410
- !h && !o.leaf && gt(o, i) ? (r.push(o), s.push(a), a = 0, u = o, o = o.children[0]) : u ? (a++, o = u.children[a], h = !1) : o = null;
1410
+ !h && !o.leaf && gt(o, i) ? (r.push(o), c.push(s), s = 0, u = o, o = o.children[0]) : u ? (s++, o = u.children[s], h = !1) : o = null;
1411
1411
  }
1412
1412
  return this;
1413
1413
  }
@@ -1434,36 +1434,36 @@ class yn {
1434
1434
  }
1435
1435
  _build(e, n, o, i) {
1436
1436
  const r = o - n + 1;
1437
- let s = this._maxEntries, a;
1438
- if (r <= s)
1439
- return a = W(e.slice(n, o + 1)), z(a, this.toBBox), a;
1440
- i || (i = Math.ceil(Math.log(r) / Math.log(s)), s = Math.ceil(r / Math.pow(s, i - 1))), a = W([]), a.leaf = !1, a.height = i;
1441
- const u = Math.ceil(r / s), h = u * Math.ceil(Math.sqrt(s));
1437
+ let c = this._maxEntries, s;
1438
+ if (r <= c)
1439
+ return s = W(e.slice(n, o + 1)), z(s, this.toBBox), s;
1440
+ i || (i = Math.ceil(Math.log(r) / Math.log(c)), c = Math.ceil(r / Math.pow(c, i - 1))), s = W([]), s.leaf = !1, s.height = i;
1441
+ const u = Math.ceil(r / c), h = u * Math.ceil(Math.sqrt(c));
1442
1442
  Ut(e, n, o, h, this.compareMinX);
1443
1443
  for (let m = n; m <= o; m += h) {
1444
1444
  const l = Math.min(m + h - 1, o);
1445
1445
  Ut(e, m, l, u, this.compareMinY);
1446
1446
  for (let g = m; g <= l; g += u) {
1447
1447
  const f = Math.min(g + u - 1, l);
1448
- a.children.push(this._build(e, g, f, i - 1));
1448
+ s.children.push(this._build(e, g, f, i - 1));
1449
1449
  }
1450
1450
  }
1451
- return z(a, this.toBBox), a;
1451
+ return z(s, this.toBBox), s;
1452
1452
  }
1453
1453
  _chooseSubtree(e, n, o, i) {
1454
1454
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1455
- let r = 1 / 0, s = 1 / 0, a;
1455
+ let r = 1 / 0, c = 1 / 0, s;
1456
1456
  for (let u = 0; u < n.children.length; u++) {
1457
1457
  const h = n.children[u], m = ft(h), l = En(e, h) - m;
1458
- l < s ? (s = l, r = m < r ? m : r, a = h) : l === s && m < r && (r = m, a = h);
1458
+ l < c ? (c = l, r = m < r ? m : r, s = h) : l === c && m < r && (r = m, s = h);
1459
1459
  }
1460
- n = a || n.children[0];
1460
+ n = s || n.children[0];
1461
1461
  }
1462
1462
  return n;
1463
1463
  }
1464
1464
  _insert(e, n, o) {
1465
- const i = o ? e : this.toBBox(e), r = [], s = this._chooseSubtree(i, this.data, n, r);
1466
- for (s.children.push(e), K(s, i); n >= 0 && r[n].children.length > this._maxEntries; )
1465
+ const i = o ? e : this.toBBox(e), r = [], c = this._chooseSubtree(i, this.data, n, r);
1466
+ for (c.children.push(e), K(c, i); n >= 0 && r[n].children.length > this._maxEntries; )
1467
1467
  this._split(r, n), n--;
1468
1468
  this._adjustParentBBoxes(i, r, n);
1469
1469
  }
@@ -1471,37 +1471,37 @@ class yn {
1471
1471
  _split(e, n) {
1472
1472
  const o = e[n], i = o.children.length, r = this._minEntries;
1473
1473
  this._chooseSplitAxis(o, r, i);
1474
- const s = this._chooseSplitIndex(o, r, i), a = W(o.children.splice(s, o.children.length - s));
1475
- a.height = o.height, a.leaf = o.leaf, z(o, this.toBBox), z(a, this.toBBox), n ? e[n - 1].children.push(a) : this._splitRoot(o, a);
1474
+ const c = this._chooseSplitIndex(o, r, i), s = W(o.children.splice(c, o.children.length - c));
1475
+ s.height = o.height, s.leaf = o.leaf, z(o, this.toBBox), z(s, this.toBBox), n ? e[n - 1].children.push(s) : this._splitRoot(o, s);
1476
1476
  }
1477
1477
  _splitRoot(e, n) {
1478
1478
  this.data = W([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, z(this.data, this.toBBox);
1479
1479
  }
1480
1480
  _chooseSplitIndex(e, n, o) {
1481
- let i, r = 1 / 0, s = 1 / 0;
1482
- for (let a = n; a <= o - n; a++) {
1483
- const u = G(e, 0, a, this.toBBox), h = G(e, a, o, this.toBBox), m = Sn(u, h), l = ft(u) + ft(h);
1484
- m < r ? (r = m, i = a, s = l < s ? l : s) : m === r && l < s && (s = l, i = a);
1481
+ let i, r = 1 / 0, c = 1 / 0;
1482
+ for (let s = n; s <= o - n; s++) {
1483
+ const u = G(e, 0, s, this.toBBox), h = G(e, s, o, this.toBBox), m = Sn(u, h), l = ft(u) + ft(h);
1484
+ m < r ? (r = m, i = s, c = l < c ? l : c) : m === r && l < c && (c = l, i = s);
1485
1485
  }
1486
1486
  return i || o - n;
1487
1487
  }
1488
1488
  // sorts node children by the best axis for split
1489
1489
  _chooseSplitAxis(e, n, o) {
1490
- const i = e.leaf ? this.compareMinX : xn, r = e.leaf ? this.compareMinY : An, s = this._allDistMargin(e, n, o, i), a = this._allDistMargin(e, n, o, r);
1491
- s < a && e.children.sort(i);
1490
+ const i = e.leaf ? this.compareMinX : xn, r = e.leaf ? this.compareMinY : An, c = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1491
+ c < s && e.children.sort(i);
1492
1492
  }
1493
1493
  // total margin of all possible split distributions where each node is at least m full
1494
1494
  _allDistMargin(e, n, o, i) {
1495
1495
  e.children.sort(i);
1496
- const r = this.toBBox, s = G(e, 0, n, r), a = G(e, o - n, o, r);
1497
- let u = et(s) + et(a);
1496
+ const r = this.toBBox, c = G(e, 0, n, r), s = G(e, o - n, o, r);
1497
+ let u = et(c) + et(s);
1498
1498
  for (let h = n; h < o - n; h++) {
1499
1499
  const m = e.children[h];
1500
- K(s, e.leaf ? r(m) : m), u += et(s);
1500
+ K(c, e.leaf ? r(m) : m), u += et(c);
1501
1501
  }
1502
1502
  for (let h = o - n - 1; h >= n; h--) {
1503
1503
  const m = e.children[h];
1504
- K(a, e.leaf ? r(m) : m), u += et(a);
1504
+ K(s, e.leaf ? r(m) : m), u += et(s);
1505
1505
  }
1506
1506
  return u;
1507
1507
  }
@@ -1526,8 +1526,8 @@ function z(t, e) {
1526
1526
  function G(t, e, n, o, i) {
1527
1527
  i || (i = W(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
1528
1528
  for (let r = e; r < n; r++) {
1529
- const s = t.children[r];
1530
- K(i, t.leaf ? o(s) : s);
1529
+ const c = t.children[r];
1530
+ K(i, t.leaf ? o(c) : c);
1531
1531
  }
1532
1532
  return i;
1533
1533
  }
@@ -1574,82 +1574,81 @@ function Ut(t, e, n, o, i) {
1574
1574
  const r = [e, n];
1575
1575
  for (; r.length; ) {
1576
1576
  if (n = r.pop(), e = r.pop(), n - e <= o) continue;
1577
- const s = e + Math.ceil((n - e) / o / 2) * o;
1578
- bn(t, s, e, n, i), r.push(e, s, s, n);
1577
+ const c = e + Math.ceil((n - e) / o / 2) * o;
1578
+ bn(t, c, e, n, i), r.push(e, c, c, n);
1579
1579
  }
1580
1580
  }
1581
1581
  const Cn = (t, e) => {
1582
- const n = new yn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1582
+ const n = new yn(), o = /* @__PURE__ */ new Map(), i = (d, a) => {
1583
1583
  const y = d.selector.flatMap((L) => {
1584
- const E = H([L]) ? L.range : Dt(L, e).range;
1584
+ const E = $([L]) ? L.range : Dt(L, e).range;
1585
1585
  return Array.from(E.getClientRects());
1586
- }), C = ce(y).map(({ left: L, top: E, right: B, bottom: T }) => new DOMRect(L - c.left, E - c.top, B - L, T - E));
1587
- return C.map((L) => {
1588
- const { x: E, y: B, width: T, height: M } = L;
1586
+ }), S = ce(y).map(({ left: L, top: E, right: T, bottom: B }) => new DOMRect(L - a.left, E - a.top, T - L, B - E));
1587
+ return S.map((L) => {
1588
+ const { x: E, y: T, width: B, height: M } = L;
1589
1589
  return {
1590
1590
  minX: E,
1591
- minY: B,
1592
- maxX: E + T,
1593
- maxY: B + M,
1591
+ minY: T,
1592
+ maxX: E + B,
1593
+ maxY: T + M,
1594
1594
  annotation: {
1595
1595
  id: d.annotation,
1596
- rects: C
1596
+ rects: S
1597
1597
  }
1598
1598
  };
1599
1599
  });
1600
- }, r = () => [...o.values()], s = () => {
1600
+ }, r = () => [...o.values()], c = () => {
1601
1601
  n.clear(), o.clear();
1602
- }, a = (d) => {
1603
- const c = i(d, e.getBoundingClientRect());
1604
- c.forEach((y) => n.insert(y)), o.set(d.annotation, c);
1602
+ }, s = (d) => {
1603
+ const a = i(d, e.getBoundingClientRect());
1604
+ a.forEach((y) => n.insert(y)), o.set(d.annotation, a);
1605
1605
  }, u = (d) => {
1606
- const c = o.get(d.annotation);
1607
- c && (c.forEach((y) => n.remove(y)), o.delete(d.annotation));
1606
+ const a = o.get(d.annotation);
1607
+ a && (a.forEach((y) => n.remove(y)), o.delete(d.annotation));
1608
1608
  }, h = (d) => {
1609
- u(d), a(d);
1610
- }, m = (d, c = !0) => {
1611
- c && s();
1612
- const y = e.getBoundingClientRect(), C = d.map((E) => ({ target: E, rects: i(E, y) }));
1613
- C.forEach(({ target: E, rects: B }) => o.set(E.annotation, B));
1614
- const L = C.flatMap(({ rects: E }) => E);
1609
+ u(d), s(d);
1610
+ }, m = (d, a = !0) => {
1611
+ a && c();
1612
+ const y = e.getBoundingClientRect(), S = d.map((E) => ({ target: E, rects: i(E, y) }));
1613
+ S.forEach(({ target: E, rects: T }) => o.set(E.annotation, T));
1614
+ const L = S.flatMap(({ rects: E }) => E);
1615
1615
  n.load(L);
1616
- }, l = (d, c) => {
1617
- const y = n.search({
1616
+ }, l = (d, a, y = !1) => {
1617
+ const S = n.search({
1618
1618
  minX: d,
1619
- minY: c,
1619
+ minY: a,
1620
1620
  maxX: d,
1621
- maxY: c
1622
- }), C = (L) => L.annotation.rects.reduce((E, B) => E + B.width * B.height, 0);
1623
- if (y.length > 0)
1624
- return y.sort((L, E) => C(L) - C(E)), y[0].annotation.id;
1621
+ maxY: a
1622
+ }), L = (E) => E.annotation.rects.reduce((T, B) => T + B.width * B.height, 0);
1623
+ return S.length > 0 ? (S.sort((E, T) => L(E) - L(T)), y ? S.map((E) => E.annotation.id) : [S[0].annotation.id]) : [];
1625
1624
  }, g = (d) => {
1626
- const c = f(d);
1627
- if (c.length === 0)
1625
+ const a = f(d);
1626
+ if (a.length === 0)
1628
1627
  return;
1629
- let y = c[0].left, C = c[0].top, L = c[0].right, E = c[0].bottom;
1630
- for (let B = 1; B < c.length; B++) {
1631
- const T = c[B];
1632
- y = Math.min(y, T.left), C = Math.min(C, T.top), L = Math.max(L, T.right), E = Math.max(E, T.bottom);
1628
+ let y = a[0].left, S = a[0].top, L = a[0].right, E = a[0].bottom;
1629
+ for (let T = 1; T < a.length; T++) {
1630
+ const B = a[T];
1631
+ y = Math.min(y, B.left), S = Math.min(S, B.top), L = Math.max(L, B.right), E = Math.max(E, B.bottom);
1633
1632
  }
1634
- return new DOMRect(y, C, L - y, E - C);
1633
+ return new DOMRect(y, S, L - y, E - S);
1635
1634
  }, f = (d) => {
1636
- const c = o.get(d);
1637
- return c ? c[0].annotation.rects : [];
1635
+ const a = o.get(d);
1636
+ return a ? a[0].annotation.rects : [];
1638
1637
  };
1639
1638
  return {
1640
1639
  all: r,
1641
- clear: s,
1640
+ clear: c,
1642
1641
  getAt: l,
1643
1642
  getAnnotationBounds: g,
1644
1643
  getAnnotationRects: f,
1645
- getIntersecting: (d, c, y, C) => {
1646
- const L = n.search({ minX: d, minY: c, maxX: y, maxY: C }), E = new Set(L.map((B) => B.annotation.id));
1647
- return Array.from(E).map((B) => ({
1648
- annotation: t.getAnnotation(B),
1649
- rects: f(B)
1650
- })).filter((B) => !!B.annotation);
1644
+ getIntersecting: (d, a, y, S) => {
1645
+ const L = n.search({ minX: d, minY: a, maxX: y, maxY: S }), E = new Set(L.map((T) => T.annotation.id));
1646
+ return Array.from(E).map((T) => ({
1647
+ annotation: t.getAnnotation(T),
1648
+ rects: f(T)
1649
+ })).filter((T) => !!T.annotation);
1651
1650
  },
1652
- insert: a,
1651
+ insert: s,
1653
1652
  recalculate: () => m(t.all().map((d) => d.target), !0),
1654
1653
  remove: u,
1655
1654
  set: m,
@@ -1657,55 +1656,55 @@ const Cn = (t, e) => {
1657
1656
  update: h
1658
1657
  };
1659
1658
  }, Ln = (t, e) => {
1660
- const n = Ge(), o = Cn(n, t), i = ke(n, e), r = Ve(n), s = Ze(), a = (v, p = N.LOCAL) => {
1661
- const d = rt(v, t), c = H(d.target.selector);
1662
- return c && n.addAnnotation(d, p), c;
1659
+ const n = Ge(), o = Cn(n, t), i = ke(n, e), r = Ve(n), c = Ze(), s = (v, p = N.LOCAL) => {
1660
+ const d = rt(v, t), a = $(d.target.selector);
1661
+ return a && n.addAnnotation(d, p), a;
1663
1662
  }, u = (v, p = !0, d = N.LOCAL) => {
1664
- const c = v.map((C) => rt(C, t)), y = c.filter((C) => !H(C.target.selector));
1665
- return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(c, p, d), y) : (n.bulkAddAnnotation(c, p, d), []);
1663
+ const a = v.map((S) => rt(S, t)), y = a.filter((S) => !$(S.target.selector));
1664
+ return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(a, p, d), y) : (n.bulkAddAnnotation(a, p, d), []);
1666
1665
  }, h = (v, p = N.LOCAL) => {
1667
- const d = v.map((y) => rt(y, t)), c = d.filter((y) => !H(y.target.selector));
1668
- return c.length > 0 && console.warn("Could not revive all targets for these annotations:", c), d.forEach((y) => {
1666
+ const d = v.map((y) => rt(y, t)), a = d.filter((y) => !$(y.target.selector));
1667
+ return a.length > 0 && console.warn("Could not revive all targets for these annotations:", a), d.forEach((y) => {
1669
1668
  n.getAnnotation(y.id) ? n.updateAnnotation(y, p) : n.addAnnotation(y, p);
1670
- }), c;
1669
+ }), a;
1671
1670
  }, m = (v, p = N.LOCAL) => {
1672
1671
  const d = it(v, t);
1673
1672
  n.updateTarget(d, p);
1674
1673
  }, l = (v, p = N.LOCAL) => {
1675
- const d = v.map((c) => it(c, t));
1674
+ const d = v.map((a) => it(a, t));
1676
1675
  n.bulkUpdateTargets(d, p);
1677
- }, g = (v, p) => {
1678
- const d = o.getAt(v, p);
1679
- return d ? n.getAnnotation(d) : void 0;
1680
- }, f = (v, p, d, c = 5) => {
1676
+ }, g = (v, p, d) => {
1677
+ const a = o.getAt(v, p, !!d).map((S) => n.getAnnotation(S)), y = d ? a.filter(d) : a;
1678
+ return y.length > 0 ? y[0] : void 0;
1679
+ }, f = (v, p, d, a = 5) => {
1681
1680
  const y = o.getAnnotationRects(v);
1682
1681
  if (y.length !== 0) {
1683
1682
  if (p && d) {
1684
- const C = y.find(({ top: L, right: E, bottom: B, left: T }) => p >= T - c && p <= E + c && d >= L - c && d <= B + c);
1685
- if (C) return C;
1683
+ const S = y.find(({ top: L, right: E, bottom: T, left: B }) => p >= B - a && p <= E + a && d >= L - a && d <= T + a);
1684
+ if (S) return S;
1686
1685
  }
1687
1686
  return o.getAnnotationBounds(v);
1688
1687
  }
1689
- }, x = () => o.recalculate();
1688
+ }, w = () => o.recalculate();
1690
1689
  return n.observe(({ changes: v }) => {
1691
- const p = (v.deleted || []).filter((y) => H(y.target.selector)), d = (v.created || []).filter((y) => H(y.target.selector)), c = (v.updated || []).filter((y) => H(y.newValue.target.selector));
1692
- (p == null ? void 0 : p.length) > 0 && p.forEach((y) => o.remove(y.target)), d.length > 0 && o.set(d.map((y) => y.target), !1), (c == null ? void 0 : c.length) > 0 && c.forEach(({ newValue: y }) => o.update(y.target));
1690
+ const p = (v.deleted || []).filter((y) => $(y.target.selector)), d = (v.created || []).filter((y) => $(y.target.selector)), a = (v.updated || []).filter((y) => $(y.newValue.target.selector));
1691
+ (p == null ? void 0 : p.length) > 0 && p.forEach((y) => o.remove(y.target)), d.length > 0 && o.set(d.map((y) => y.target), !1), (a == null ? void 0 : a.length) > 0 && a.forEach(({ newValue: y }) => o.update(y.target));
1693
1692
  }), {
1694
1693
  store: {
1695
1694
  ...n,
1696
- addAnnotation: a,
1695
+ addAnnotation: s,
1697
1696
  bulkAddAnnotation: u,
1698
1697
  bulkUpdateTargets: l,
1699
1698
  bulkUpsertAnnotations: h,
1700
1699
  getAnnotationBounds: f,
1701
1700
  getAt: g,
1702
1701
  getIntersecting: o.getIntersecting,
1703
- recalculatePositions: x,
1702
+ recalculatePositions: w,
1704
1703
  updateTarget: m
1705
1704
  },
1706
1705
  selection: i,
1707
1706
  hover: r,
1708
- viewport: s
1707
+ viewport: c
1709
1708
  };
1710
1709
  }, Bn = () => {
1711
1710
  const t = document.createElement("canvas");
@@ -1715,9 +1714,9 @@ const Cn = (t, e) => {
1715
1714
  }, Tn = (t, e, n = {}) => {
1716
1715
  const o = Bn(), i = o.getContext("2d");
1717
1716
  t.appendChild(o);
1718
- const r = /* @__PURE__ */ new Map(), s = (l) => Array.from(r.entries()).filter(([g, f]) => f.presenceKey === l.presenceKey).map(([g, f]) => g);
1717
+ const r = /* @__PURE__ */ new Map(), c = (l) => Array.from(r.entries()).filter(([g, f]) => f.presenceKey === l.presenceKey).map(([g, f]) => g);
1719
1718
  return e.on("selectionChange", (l, g) => {
1720
- s(l).forEach((x) => r.delete(x)), g && g.forEach((x) => r.set(x, l));
1719
+ c(l).forEach((w) => r.delete(w)), g && g.forEach((w) => r.set(w, l));
1721
1720
  }), {
1722
1721
  clear: () => {
1723
1722
  const { width: l, height: g } = o;
@@ -1728,13 +1727,13 @@ const Cn = (t, e) => {
1728
1727
  },
1729
1728
  paint: (l, g, f) => {
1730
1729
  n.font && (i.font = n.font);
1731
- const x = r.get(l.annotation.id);
1732
- if (x) {
1730
+ const w = r.get(l.annotation.id);
1731
+ if (w) {
1733
1732
  const { height: v } = l.rects[0], p = l.rects[0].x + g.left, d = l.rects[0].y + g.top;
1734
- i.fillStyle = x.appearance.color, i.fillRect(p - 2, d - 2.5, 2, v + 5);
1735
- const c = i.measureText(x.appearance.label), y = c.width + 6, C = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, L = c.fontBoundingBoxAscent ? 8 : 6.5;
1736
- return i.fillRect(p - 2, d - 2.5 - C, y, C), i.fillStyle = "#fff", i.fillText(x.appearance.label, p + 1, d - L), {
1737
- fill: x.appearance.color,
1733
+ i.fillStyle = w.appearance.color, i.fillRect(p - 2, d - 2.5, 2, v + 5);
1734
+ const a = i.measureText(w.appearance.label), y = a.width + 6, S = a.actualBoundingBoxAscent + a.actualBoundingBoxDescent + 8, L = a.fontBoundingBoxAscent ? 8 : 6.5;
1735
+ return i.fillRect(p - 2, d - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(w.appearance.label, p + 1, d - L), {
1736
+ fill: w.appearance.color,
1738
1737
  fillOpacity: f ? 0.45 : 0.18
1739
1738
  };
1740
1739
  }
@@ -1751,16 +1750,16 @@ const Cn = (t, e) => {
1751
1750
  const { overflowY: e } = window.getComputedStyle(t);
1752
1751
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Wt(t.parentElement);
1753
1752
  }, Rn = (t, e) => (n) => {
1754
- const o = typeof n == "string" ? n : n.id, i = (s) => {
1755
- const a = r.getBoundingClientRect(), u = r.clientHeight, h = r.clientWidth, m = s.selector[0].range.getBoundingClientRect(), { width: l, height: g } = e.getAnnotationBounds(o), f = m.top - a.top, x = m.left - a.left, v = r.parentElement ? r.scrollTop : 0, p = r.parentElement ? r.scrollLeft : 0, d = f + v - (u - g) / 2, c = x + p - (h - l) / 2;
1756
- r.scroll({ top: d, left: c, behavior: "smooth" });
1753
+ const o = typeof n == "string" ? n : n.id, i = (c) => {
1754
+ const s = r.getBoundingClientRect(), u = r.clientHeight, h = r.clientWidth, m = c.selector[0].range.getBoundingClientRect(), { width: l, height: g } = e.getAnnotationBounds(o), f = m.top - s.top, w = m.left - s.left, v = r.parentElement ? r.scrollTop : 0, p = r.parentElement ? r.scrollLeft : 0, d = f + v - (u - g) / 2, a = w + p - (h - l) / 2;
1755
+ r.scroll({ top: d, left: a, behavior: "smooth" });
1757
1756
  }, r = Wt(t);
1758
1757
  if (r) {
1759
- const s = e.getAnnotation(o), { range: a } = s.target.selector[0];
1760
- if (a && !a.collapsed)
1761
- return i(s.target), !0;
1758
+ const c = e.getAnnotation(o), { range: s } = c.target.selector[0];
1759
+ if (s && !s.collapsed)
1760
+ return i(c.target), !0;
1762
1761
  {
1763
- const u = it(s.target, t), { range: h } = u.selector[0];
1762
+ const u = it(c.target, t), { range: h } = u.selector[0];
1764
1763
  if (h && !h.collapsed)
1765
1764
  return i(u), !0;
1766
1765
  }
@@ -1771,35 +1770,35 @@ const Cn = (t, e) => {
1771
1770
  annotationEnabled: t.annotationEnabled === void 0 ? e.annotationEnabled : t.annotationEnabled
1772
1771
  }), Mn = (t, e, n, o) => {
1773
1772
  let i;
1774
- const r = (c) => i = c;
1775
- let s;
1776
- const a = (c) => s = c, { store: u, selection: h } = e;
1773
+ const r = (a) => i = a;
1774
+ let c;
1775
+ const s = (a) => c = a, { store: u, selection: h } = e;
1777
1776
  let m, l = !1, g;
1778
- const f = (c) => {
1779
- var C;
1777
+ const f = (a) => {
1778
+ var S;
1780
1779
  if (!l) return;
1781
- !((C = c.target.parentElement) != null && C.closest(D)) ? m = {
1782
- annotation: $t(),
1780
+ !((S = a.target.parentElement) != null && S.closest(D)) ? m = {
1781
+ annotation: Ht(),
1783
1782
  selector: [],
1784
1783
  creator: i,
1785
1784
  created: /* @__PURE__ */ new Date()
1786
1785
  } : m = void 0;
1787
1786
  };
1788
1787
  n && t.addEventListener("selectstart", f);
1789
- const x = bt((c) => {
1790
- var T, M;
1788
+ const w = bt((a) => {
1789
+ var B, M;
1791
1790
  const y = document.getSelection();
1792
- if (!!((M = (T = y.anchorNode) == null ? void 0 : T.parentElement) != null && M.closest(D))) {
1791
+ if (!!((M = (B = y.anchorNode) == null ? void 0 : B.parentElement) != null && M.closest(D))) {
1793
1792
  m = void 0;
1794
1793
  return;
1795
1794
  }
1796
- if (c.timeStamp - ((g == null ? void 0 : g.timeStamp) || c.timeStamp) < 1e3 && !m && f(g), y.isCollapsed || !l || !m) return;
1795
+ if (a.timeStamp - ((g == null ? void 0 : g.timeStamp) || a.timeStamp) < 1e3 && !m && f(g), y.isCollapsed || !l || !m) return;
1797
1796
  const L = y.getRangeAt(0);
1798
1797
  if (re(L)) return;
1799
1798
  const E = Zt(L.cloneRange());
1800
- (E.length !== m.selector.length || E.some((b, w) => {
1799
+ (E.length !== m.selector.length || E.some((b, x) => {
1801
1800
  var A;
1802
- return b.toString() !== ((A = m.selector[w]) == null ? void 0 : A.quote);
1801
+ return b.toString() !== ((A = m.selector[x]) == null ? void 0 : A.quote);
1803
1802
  })) && (m = {
1804
1803
  ...m,
1805
1804
  selector: E.map((b) => le(b, t, o)),
@@ -1810,37 +1809,37 @@ const Cn = (t, e) => {
1810
1809
  target: m
1811
1810
  }), h.clickSelect(m.annotation, g)));
1812
1811
  });
1813
- n && document.addEventListener("selectionchange", x);
1814
- const v = (c) => {
1815
- const { target: y, timeStamp: C, offsetX: L, offsetY: E, type: B } = c;
1816
- g = { ...c, target: y, timeStamp: C, offsetX: L, offsetY: E, type: B }, l = c.button === 0;
1812
+ n && document.addEventListener("selectionchange", w);
1813
+ const v = (a) => {
1814
+ const { target: y, timeStamp: S, offsetX: L, offsetY: E, type: T } = a;
1815
+ g = { ...a, target: y, timeStamp: S, offsetX: L, offsetY: E, type: T }, l = a.button === 0;
1817
1816
  };
1818
1817
  t.addEventListener("pointerdown", v);
1819
- const p = (c) => {
1818
+ const p = (a) => {
1820
1819
  var E;
1821
- if (!!((E = c.target.parentElement) != null && E.closest(D)) || !l)
1820
+ if (!!((E = a.target.parentElement) != null && E.closest(D)) || !l)
1822
1821
  return;
1823
- const C = () => {
1824
- const { x: B, y: T } = t.getBoundingClientRect(), M = u.getAt(c.clientX - B, c.clientY - T);
1825
- if (M && (!s || s(M))) {
1826
- const { selected: w } = h;
1827
- (w.length !== 1 || w[0].id !== M.id) && h.clickSelect(M.id, c);
1822
+ const S = () => {
1823
+ const { x: T, y: B } = t.getBoundingClientRect(), M = u.getAt(a.clientX - T, a.clientY - B, c);
1824
+ if (M) {
1825
+ const { selected: b } = h;
1826
+ (b.length !== 1 || b[0].id !== M.id) && h.clickSelect(M.id, a);
1828
1827
  } else h.isEmpty() || h.clear();
1829
- }, L = c.timeStamp - g.timeStamp;
1830
- document.getSelection().isCollapsed && L < 300 ? (m = void 0, C()) : m && h.clickSelect(m.annotation, c);
1828
+ }, L = a.timeStamp - g.timeStamp;
1829
+ document.getSelection().isCollapsed && L < 300 ? (m = void 0, S()) : m && h.clickSelect(m.annotation, a);
1831
1830
  };
1832
1831
  return document.addEventListener("pointerup", p), {
1833
1832
  destroy: () => {
1834
- t.removeEventListener("selectstart", f), document.removeEventListener("selectionchange", x), t.removeEventListener("pointerdown", v), document.removeEventListener("pointerup", p);
1833
+ t.removeEventListener("selectstart", f), document.removeEventListener("selectionchange", w), t.removeEventListener("pointerdown", v), document.removeEventListener("pointerup", p);
1835
1834
  },
1836
- setFilter: a,
1835
+ setFilter: s,
1837
1836
  setUser: r
1838
1837
  };
1839
1838
  }, kt = "SPANS", kn = (t, e = {}) => {
1840
1839
  te(t);
1841
1840
  const n = Nn(e, {
1842
1841
  annotationEnabled: !0
1843
- }), o = Ln(t, n.pointerAction), { selection: i, viewport: r } = o, s = o.store, a = Je(s), u = tn(o, a, n.adapter);
1842
+ }), o = Ln(t, n.pointerAction), { selection: i, viewport: r } = o, c = o.store, s = Je(c), u = tn(o, s, n.adapter);
1844
1843
  let h = ln();
1845
1844
  const m = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : kt : n.renderer || kt, l = m === "SPANS" ? Te(t, o, r) : m === "CSS_HIGHLIGHTS" ? Ce(t, o, r) : m === "CANVAS" ? pe(t, o, r) : void 0;
1846
1845
  if (!l)
@@ -1848,9 +1847,9 @@ const Cn = (t, e) => {
1848
1847
  console.debug(`Using ${m} renderer`), n.style && l.setStyle(n.style);
1849
1848
  const g = Mn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1850
1849
  return g.setUser(h), {
1851
- ...nn(o, a, n.adapter),
1850
+ ...nn(o, s, n.adapter),
1852
1851
  destroy: () => {
1853
- l.destroy(), g.destroy(), a.destroy();
1852
+ l.destroy(), g.destroy(), s.destroy();
1854
1853
  },
1855
1854
  element: t,
1856
1855
  getUser: () => h,
@@ -1870,7 +1869,7 @@ const Cn = (t, e) => {
1870
1869
  setVisible: (E) => l.setVisible(E),
1871
1870
  on: u.on,
1872
1871
  off: u.off,
1873
- scrollIntoView: Rn(t, s),
1872
+ scrollIntoView: Rn(t, c),
1874
1873
  state: o
1875
1874
  };
1876
1875
  };
@@ -1896,7 +1895,7 @@ export {
1896
1895
  In as getClientRectsPonyfill,
1897
1896
  oe as getQuoteContext,
1898
1897
  pt as getRangeAnnotatableContents,
1899
- H as isRevived,
1898
+ $ as isRevived,
1900
1899
  re as isWhitespaceOrEmpty,
1901
1900
  ce as mergeClientRects,
1902
1901
  Kt as paint,