@recogito/text-annotator 3.0.0-rc.30 → 3.0.0-rc.31

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.
@@ -8,22 +8,21 @@ const P = {
8
8
  var a, s;
9
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;
10
10
  return o && o.paint(t, e) || r;
11
- }, _t = "not-annotatable", X = `.${_t}`, Qt = (t) => {
11
+ }, Yt = "not-annotatable", D = `.${Yt}`, Qt = (t) => {
12
12
  var n;
13
13
  const e = t.commonAncestorContainer;
14
- return e instanceof HTMLElement ? !e.closest(X) : !((n = e.parentElement) != null && n.closest(X));
14
+ return e instanceof HTMLElement ? !e.closest(D) : !((n = e.parentElement) != null && n.closest(D));
15
15
  }, Jt = 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(_t) && !o.parentElement.closest(X) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
19
+ (o) => o instanceof HTMLElement && o.classList.contains(Yt) && !o.parentElement.closest(D) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
20
20
  );
21
21
  let n;
22
22
  for (; n = e.nextNode(); )
23
23
  n instanceof HTMLElement && (yield n);
24
24
  }, Zt = (t) => {
25
- if (!Qt(t))
26
- return [];
25
+ if (!Qt(t)) return [];
27
26
  const e = [];
28
27
  let n = null;
29
28
  for (const o of Jt(t)) {
@@ -37,11 +36,11 @@ const P = {
37
36
  return e.length > 0 ? e : [t];
38
37
  }, pt = (t) => {
39
38
  const e = t.cloneContents();
40
- return e.querySelectorAll(X).forEach((n) => n.remove()), e;
39
+ return e.querySelectorAll(D).forEach((n) => n.remove()), e;
41
40
  }, te = (t) => {
42
41
  t.addEventListener("click", (e) => {
43
42
  // Allow clicks within not-annotatable elements
44
- !e.target.closest(X) && !e.target.closest("a") && e.preventDefault();
43
+ !e.target.closest(D) && !e.target.closest("a") && e.preventDefault();
45
44
  });
46
45
  }, bt = (t, e = 10) => {
47
46
  let n;
@@ -50,7 +49,7 @@ const P = {
50
49
  };
51
50
  }, On = (t) => {
52
51
  const e = t.cloneContents();
53
- return e.querySelectorAll(X).forEach((n) => n.remove()), e;
52
+ return e.querySelectorAll(D).forEach((n) => n.remove()), e;
54
53
  }, wt = (t, e) => {
55
54
  const n = document.createNodeIterator(e);
56
55
  let o = 0, i = n.nextNode();
@@ -91,12 +90,12 @@ const P = {
91
90
  l.selectNodeContents(n), l.setStart(n, o);
92
91
  const p = m(l), g = document.createRange();
93
92
  g.selectNode(i), g.setEnd(i, r);
94
- const x = m(g), h = ne(t).reverse().map((d) => {
93
+ const w = m(g), h = ne(t).reverse().map((d) => {
95
94
  var y;
96
95
  const c = document.createElement("SPAN");
97
96
  return (y = d.parentNode) == null || y.insertBefore(c, d), c.appendChild(d), c;
98
97
  });
99
- return { unwrap: f, nodes: [p, ...h, x] };
98
+ return { unwrap: f, nodes: [p, ...h, w] };
100
99
  }
101
100
  }, ne = (t) => {
102
101
  const {
@@ -109,7 +108,7 @@ const P = {
109
108
  for (; r != null; )
110
109
  r === o && (a = !1), a && s.push(r), r === n && (a = !0), r = i.nextNode();
111
110
  return s;
112
- }, Mn = (t) => {
111
+ }, In = (t) => {
113
112
  const { startContainer: e, endContainer: n } = t;
114
113
  if (e === n)
115
114
  return Array.from(t.getClientRects());
@@ -127,7 +126,7 @@ const P = {
127
126
  prefix: a.substring(a.length - n),
128
127
  suffix: u.substring(0, n)
129
128
  };
130
- }, $ = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ie = (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) => {
131
130
  const n = (r) => Math.round(r * 10) / 10, o = {
132
131
  top: n(t.top),
133
132
  bottom: n(t.bottom),
@@ -151,17 +150,17 @@ const P = {
151
150
  return "block-contains";
152
151
  } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
153
152
  return "block-is-contained";
154
- }, re = (t, e) => {
153
+ }, ae = (t, e) => {
155
154
  const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), r = Math.max(t.bottom, e.bottom);
156
155
  return new DOMRect(n, i, o - n, r - i);
157
- }, se = (t) => t.reduce((e, n) => {
156
+ }, ce = (t) => t.reduce((e, n) => {
158
157
  if (n.width === 0 || n.height === 0)
159
158
  return e;
160
159
  let o = [...e], i = !1;
161
160
  for (const r of e) {
162
- const a = ie(n, r);
161
+ const a = se(n, r);
163
162
  if (a === "inline-adjacent") {
164
- o = o.map((s) => s === r ? re(n, r) : s), i = !0;
163
+ o = o.map((s) => s === r ? ae(n, r) : s), i = !0;
165
164
  break;
166
165
  } else if (a === "inline-contains") {
167
166
  o = o.map((s) => s === r ? n : s), i = !0;
@@ -175,19 +174,19 @@ const P = {
175
174
  }
176
175
  }
177
176
  return i ? o : [...o, n];
178
- }, []), ae = (t, e, n) => {
177
+ }, []), le = (t, e, n) => {
179
178
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
180
179
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
181
180
  const r = pt(o).textContent, a = t.toString(), s = r.length || 0, u = s + a.length;
182
181
  return n ? { quote: a, start: s, end: u, range: t, offsetReference: i } : { quote: a, start: s, end: u, range: t };
183
- }, Xt = (t, e) => {
182
+ }, Dt = (t, e) => {
184
183
  var m, l;
185
184
  const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
186
185
  e,
187
186
  NodeFilter.SHOW_TEXT,
188
187
  (p) => {
189
188
  var g;
190
- return (g = p.parentElement) != null && g.closest(X) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
189
+ return (g = p.parentElement) != null && g.closest(D) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
191
190
  }
192
191
  );
193
192
  let a = 0;
@@ -220,25 +219,11 @@ const P = {
220
219
  };
221
220
  }, it = (t, e) => $(t.selector) ? t : {
222
221
  ...t,
223
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Xt(n, e))
224
- }, rt = (t, e) => $(t.target.selector) ? t : { ...t, target: it(t.target, e) }, ce = (t) => {
225
- var i;
226
- const { startContainer: e, endContainer: n } = t;
227
- if (e.nodeType === Node.TEXT_NODE && n.nodeType === Node.TEXT_NODE)
228
- return t;
229
- if (e.nodeType !== Node.TEXT_NODE) {
230
- const r = e.nextSibling || e.parentNode, a = (r == null ? void 0 : r.nodeType) === Node.TEXT_NODE ? r : Array.from(r.childNodes).filter((s) => s.nodeType === Node.TEXT_NODE).shift();
231
- t.setEnd(a, 0);
232
- }
233
- if (n.nodeType !== Node.TEXT_NODE) {
234
- const r = n.previousSibling || n.parentNode, a = (r == null ? void 0 : r.nodeType) === Node.TEXT_NODE ? r : Array.from(r.childNodes).filter((s) => s.nodeType === Node.TEXT_NODE).pop();
235
- t.setEnd(a, ((i = a == null ? void 0 : a.textContent) == null ? void 0 : i.length) || 0);
236
- }
237
- return t;
238
- }, le = (t) => {
222
+ selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Dt(n, e))
223
+ }, rt = (t, e) => $(t.target.selector) ? t : { ...t, target: it(t.target, e) }, de = (t) => {
239
224
  const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, u = i - e;
240
225
  return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: u };
241
- }, de = (t) => {
226
+ }, ue = (t) => {
242
227
  let e = /* @__PURE__ */ new Set();
243
228
  return (o) => {
244
229
  const i = o.map((r) => r.id);
@@ -247,24 +232,24 @@ const P = {
247
232
  }, vt = (t, e, n, o) => {
248
233
  const { store: i, selection: r, hover: a } = e;
249
234
  let s, u, f;
250
- const m = de(n), l = (L) => {
251
- const { x: O, y: b } = t.getBoundingClientRect(), w = i.getAt(L.clientX - O, L.clientY - b);
252
- w && (!u || u(w)) ? a.current !== w.id && (t.classList.add("hovered"), a.set(w.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
235
+ const m = ue(n), l = (T) => {
236
+ const { x: O, y: b } = t.getBoundingClientRect(), x = i.getAt(T.clientX - O, T.clientY - b);
237
+ x && (!u || u(x)) ? a.current !== x.id && (t.classList.add("hovered"), a.set(x.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
253
238
  };
254
239
  t.addEventListener("pointermove", l);
255
- const p = (L = !1) => {
240
+ const p = (T = !1) => {
256
241
  f && f.clear();
257
- const O = le(t), { minX: b, minY: w, maxX: A, maxY: S } = O, R = u ? i.getIntersecting(b, w, A, S).filter(({ annotation: k }) => u(k)) : i.getIntersecting(b, w, A, S), M = r.selected.map(({ id: k }) => k), H = R.map(({ annotation: k, rects: qt }) => {
258
- const jt = M.includes(k.id), Gt = k.id === a.current;
259
- return { annotation: k, rects: qt, state: { selected: jt, hover: Gt } };
242
+ const O = de(t), { minX: b, minY: x, maxX: A, maxY: S } = O, R = u ? i.getIntersecting(b, x, A, S).filter(({ annotation: _ }) => u(_)) : i.getIntersecting(b, x, A, S), M = r.selected.map(({ id: _ }) => _), H = R.map(({ annotation: _, rects: qt }) => {
243
+ const jt = M.includes(_.id), Gt = _.id === a.current;
244
+ return { annotation: _, rects: qt, state: { selected: jt, hover: Gt } };
260
245
  });
261
- o.redraw(H, O, s, f, L), setTimeout(() => m(R.map(({ annotation: k }) => k)), 1);
262
- }, g = (L) => {
263
- f = L, p();
264
- }, x = (L) => {
265
- s = L, p();
266
- }, v = (L) => {
267
- u = L, p(!1);
246
+ o.redraw(H, O, s, f, T), setTimeout(() => m(R.map(({ annotation: _ }) => _)), 1);
247
+ }, g = (T) => {
248
+ f = T, p();
249
+ }, w = (T) => {
250
+ s = T, p();
251
+ }, v = (T) => {
252
+ u = T, p(!1);
268
253
  }, h = () => p();
269
254
  i.observe(h);
270
255
  const d = r.subscribe(() => p()), c = () => p(!0);
@@ -273,64 +258,64 @@ const P = {
273
258
  i.recalculatePositions(), f && f.reset(), p();
274
259
  });
275
260
  window.addEventListener("resize", y);
276
- const T = new ResizeObserver(y);
277
- T.observe(t);
278
- const C = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((L) => {
279
- L.every((b) => b.target === t || t.contains(b.target)) || p(!0);
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)) || p(!0);
280
265
  });
281
- return E.observe(document.body, C), {
266
+ return E.observe(document.body, L), {
282
267
  destroy: () => {
283
- t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", y), T.disconnect(), E.disconnect();
268
+ t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", y), C.disconnect(), E.disconnect();
284
269
  },
285
270
  redraw: p,
286
- setStyle: x,
271
+ setStyle: w,
287
272
  setFilter: v,
288
273
  setPainter: g,
289
274
  setVisible: o.setVisible
290
275
  };
291
- }, ue = () => {
276
+ }, he = () => {
292
277
  const t = document.createElement("canvas");
293
278
  return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-highlight-layer bg", t;
294
- }, he = (t, e) => {
279
+ }, fe = (t, e) => {
295
280
  t.width = window.innerWidth, t.height = window.innerHeight;
296
- }, fe = (t) => {
281
+ }, ge = (t) => {
297
282
  t.classList.add("r6o-annotatable");
298
- const e = ue(), n = e.getContext("2d");
283
+ const e = he(), n = e.getContext("2d");
299
284
  t.insertBefore(e, t.firstChild);
300
285
  const o = (s, u, f, m) => requestAnimationFrame(() => {
301
286
  const { width: l, height: p } = e;
302
287
  n.clearRect(-0.5, -0.5, l + 1, p + 1), m && m.clear();
303
- const { top: g, left: x } = u;
288
+ const { top: g, left: w } = u;
304
289
  [...s].sort((h, d) => {
305
290
  const { annotation: { target: { created: c } } } = h, { annotation: { target: { created: y } } } = d;
306
291
  return c.getTime() - y.getTime();
307
292
  }).forEach((h) => {
308
- var C;
309
- const d = f ? typeof f == "function" ? f(h.annotation, h.state) : f : (C = h.state) != null && C.selected ? ot : P, c = m && m.paint(h, u) || d, y = h.rects.map(({ x: E, y: N, width: L, height: O }) => ({
310
- x: E + x,
311
- y: N + g,
312
- width: L,
293
+ var L;
294
+ const d = f ? typeof f == "function" ? f(h.annotation, h.state) : f : (L = h.state) != null && L.selected ? ot : P, c = m && m.paint(h, u) || d, y = h.rects.map(({ x: E, y: B, width: T, height: O }) => ({
295
+ x: E + w,
296
+ y: B + g,
297
+ width: T,
313
298
  height: O
314
299
  }));
315
300
  n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1;
316
- const T = 5;
301
+ const C = 5;
317
302
  if (y.forEach(
318
- ({ x: E, y: N, width: L, height: O }) => n.fillRect(
303
+ ({ x: E, y: B, width: T, height: O }) => n.fillRect(
319
304
  E,
320
- N - T / 2,
321
- L,
322
- O + T
305
+ B - C / 2,
306
+ T,
307
+ O + C
323
308
  )
324
309
  ), c.underlineColor) {
325
310
  n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
326
- const E = T / 2 + (c.underlineOffset ?? 0);
327
- y.forEach(({ x: N, y: L, width: O, height: b }) => {
328
- n.beginPath(), n.moveTo(N, L + b + E), n.lineTo(N + O, L + b + E), n.stroke();
311
+ const E = C / 2 + (c.underlineOffset ?? 0);
312
+ y.forEach(({ x: B, y: T, width: O, height: b }) => {
313
+ n.beginPath(), n.moveTo(B, T + b + E), n.lineTo(B + O, T + b + E), n.stroke();
329
314
  });
330
315
  }
331
316
  });
332
317
  }), i = bt(() => {
333
- he(e);
318
+ fe(e);
334
319
  });
335
320
  return window.addEventListener("resize", i), {
336
321
  destroy: () => {
@@ -341,89 +326,85 @@ const P = {
341
326
  },
342
327
  redraw: o
343
328
  };
344
- }, ge = (t, e, n) => vt(t, e, n, fe(t));
345
- var pe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
329
+ }, pe = (t, e, n) => vt(t, e, n, ge(t));
330
+ var me = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
346
331
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
347
332
  }, I = function(t, e, n) {
348
333
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
349
- }, U = function(t, e, n) {
334
+ }, k = function(t, e, n) {
350
335
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
351
- }, kt = function(t) {
336
+ }, _t = function(t) {
352
337
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
353
338
  }, At = function(t) {
354
- return { r: U(t.r, 0, 255), g: U(t.g, 0, 255), b: U(t.b, 0, 255), a: U(t.a) };
339
+ return { r: k(t.r, 0, 255), g: k(t.g, 0, 255), b: k(t.b, 0, 255), a: k(t.a) };
355
340
  }, st = function(t) {
356
341
  return { r: I(t.r), g: I(t.g), b: I(t.b), a: I(t.a, 3) };
357
- }, me = /^#([0-9a-f]{3,8})$/i, J = function(t) {
342
+ }, be = /^#([0-9a-f]{3,8})$/i, J = function(t) {
358
343
  var e = t.toString(16);
359
344
  return e.length < 2 ? "0" + e : e;
360
- }, Yt = function(t) {
345
+ }, Xt = function(t) {
361
346
  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;
362
347
  return { h: 60 * (s < 0 ? s + 6 : s), s: r ? a / r * 100 : 0, v: r / 255 * 100, a: i };
363
- }, Ht = function(t) {
348
+ }, $t = function(t) {
364
349
  var e = t.h, n = t.s, o = t.v, i = t.a;
365
350
  e = e / 360 * 6, n /= 100, o /= 100;
366
351
  var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), u = o * (1 - (1 - e + r) * n), f = r % 6;
367
352
  return { r: 255 * [o, s, a, a, u, o][f], g: 255 * [u, o, o, s, a, a][f], b: 255 * [a, a, u, o, o, s][f], a: i };
368
353
  }, Et = function(t) {
369
- return { h: kt(t.h), s: U(t.s, 0, 100), l: U(t.l, 0, 100), a: U(t.a) };
354
+ return { h: _t(t.h), s: k(t.s, 0, 100), l: k(t.l, 0, 100), a: k(t.a) };
370
355
  }, St = function(t) {
371
356
  return { h: I(t.h), s: I(t.s), l: I(t.l), a: I(t.a, 3) };
372
357
  }, Ct = function(t) {
373
- 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 }));
374
359
  var e, n, o;
375
360
  }, Q = function(t) {
376
- 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
+ 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
362
  var e, n, o, i;
378
- }, be = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ve = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ye = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, we = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Tt = { string: [[function(t) {
379
- var e = me.exec(t);
363
+ }, ve = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ye = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, we = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, xe = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Lt = { string: [[function(t) {
364
+ var e = be.exec(t);
380
365
  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;
381
366
  }, "hex"], [function(t) {
382
- var e = ye.exec(t) || we.exec(t);
367
+ var e = we.exec(t) || xe.exec(t);
383
368
  return e ? e[2] !== e[4] || e[4] !== e[6] ? null : At({ 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;
384
369
  }, "rgb"], [function(t) {
385
- var e = be.exec(t) || ve.exec(t);
386
- if (!e)
387
- return null;
388
- var n, o, i = Et({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (pe[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
370
+ var e = ve.exec(t) || ye.exec(t);
371
+ if (!e) return null;
372
+ var n, o, i = Et({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (me[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
389
373
  return Ct(i);
390
374
  }, "hsl"]], object: [[function(t) {
391
375
  var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
392
- return Y(e) && Y(n) && Y(o) ? At({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
376
+ return X(e) && X(n) && X(o) ? At({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
393
377
  }, "rgb"], [function(t) {
394
378
  var e = t.h, n = t.s, o = t.l, i = t.a, r = i === void 0 ? 1 : i;
395
- if (!Y(e) || !Y(n) || !Y(o))
396
- return null;
379
+ if (!X(e) || !X(n) || !X(o)) return null;
397
380
  var a = Et({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
398
381
  return Ct(a);
399
382
  }, "hsl"], [function(t) {
400
383
  var e = t.h, n = t.s, o = t.v, i = t.a, r = i === void 0 ? 1 : i;
401
- if (!Y(e) || !Y(n) || !Y(o))
402
- return null;
384
+ if (!X(e) || !X(n) || !X(o)) return null;
403
385
  var a = function(s) {
404
- return { h: kt(s.h), s: U(s.s, 0, 100), v: U(s.v, 0, 100), a: U(s.a) };
386
+ return { h: _t(s.h), s: k(s.s, 0, 100), v: k(s.v, 0, 100), a: k(s.a) };
405
387
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(r) });
406
- return Ht(a);
407
- }, "hsv"]] }, Nt = function(t, e) {
388
+ return $t(a);
389
+ }, "hsv"]] }, Bt = function(t, e) {
408
390
  for (var n = 0; n < e.length; n++) {
409
391
  var o = e[n][0](t);
410
- if (o)
411
- return [o, e[n][1]];
392
+ if (o) return [o, e[n][1]];
412
393
  }
413
394
  return [null, void 0];
414
- }, xe = function(t) {
415
- return typeof t == "string" ? Nt(t.trim(), Tt.string) : typeof t == "object" && t !== null ? Nt(t, Tt.object) : [null, void 0];
395
+ }, Ae = function(t) {
396
+ return typeof t == "string" ? Bt(t.trim(), Lt.string) : typeof t == "object" && t !== null ? Bt(t, Lt.object) : [null, void 0];
416
397
  }, at = function(t, e) {
417
398
  var n = Q(t);
418
- return { h: n.h, s: U(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
399
+ return { h: n.h, s: k(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
419
400
  }, ct = function(t) {
420
401
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
421
- }, Lt = function(t, e) {
402
+ }, Tt = function(t, e) {
422
403
  var n = Q(t);
423
- return { h: n.h, s: n.s, l: U(n.l + 100 * e, 0, 100), a: n.a };
404
+ return { h: n.h, s: n.s, l: k(n.l + 100 * e, 0, 100), a: n.a };
424
405
  }, Rt = function() {
425
406
  function t(e) {
426
- this.parsed = xe(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
407
+ this.parsed = Ae(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
427
408
  }
428
409
  return t.prototype.isValid = function() {
429
410
  return this.parsed !== null;
@@ -447,42 +428,42 @@ var pe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, Y = function(t) {
447
428
  return e = St(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 + "%)";
448
429
  var e, n, o, i, r;
449
430
  }, t.prototype.toHsv = function() {
450
- return e = Yt(this.rgba), { h: I(e.h), s: I(e.s), v: I(e.v), a: I(e.a, 3) };
431
+ return e = Xt(this.rgba), { h: I(e.h), s: I(e.s), v: I(e.v), a: I(e.a, 3) };
451
432
  var e;
452
433
  }, t.prototype.invert = function() {
453
- return _({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
434
+ return Y({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
454
435
  var e;
455
436
  }, t.prototype.saturate = function(e) {
456
- return e === void 0 && (e = 0.1), _(at(this.rgba, e));
437
+ return e === void 0 && (e = 0.1), Y(at(this.rgba, e));
457
438
  }, t.prototype.desaturate = function(e) {
458
- return e === void 0 && (e = 0.1), _(at(this.rgba, -e));
439
+ return e === void 0 && (e = 0.1), Y(at(this.rgba, -e));
459
440
  }, t.prototype.grayscale = function() {
460
- return _(at(this.rgba, -1));
441
+ return Y(at(this.rgba, -1));
461
442
  }, t.prototype.lighten = function(e) {
462
- return e === void 0 && (e = 0.1), _(Lt(this.rgba, e));
443
+ return e === void 0 && (e = 0.1), Y(Tt(this.rgba, e));
463
444
  }, t.prototype.darken = function(e) {
464
- return e === void 0 && (e = 0.1), _(Lt(this.rgba, -e));
445
+ return e === void 0 && (e = 0.1), Y(Tt(this.rgba, -e));
465
446
  }, t.prototype.rotate = function(e) {
466
447
  return e === void 0 && (e = 15), this.hue(this.hue() + e);
467
448
  }, t.prototype.alpha = function(e) {
468
- return typeof e == "number" ? _({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : I(this.rgba.a, 3);
449
+ return typeof e == "number" ? Y({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : I(this.rgba.a, 3);
469
450
  var n;
470
451
  }, t.prototype.hue = function(e) {
471
452
  var n = Q(this.rgba);
472
- return typeof e == "number" ? _({ h: e, s: n.s, l: n.l, a: n.a }) : I(n.h);
453
+ return typeof e == "number" ? Y({ h: e, s: n.s, l: n.l, a: n.a }) : I(n.h);
473
454
  }, t.prototype.isEqual = function(e) {
474
- return this.toHex() === _(e).toHex();
455
+ return this.toHex() === Y(e).toHex();
475
456
  }, t;
476
- }(), _ = function(t) {
457
+ }(), Y = function(t) {
477
458
  return t instanceof Rt ? t : new Rt(t);
478
459
  };
479
- const Ae = (t) => [
480
- `background-color:${_((t == null ? void 0 : t.fill) || P.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? P.fillOpacity : t.fillOpacity).toHex()}`,
460
+ const Ee = (t) => [
461
+ `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()}`,
481
462
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
482
463
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
483
464
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
484
465
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
485
- ].filter(Boolean).join(";"), Ee = () => {
466
+ ].filter(Boolean).join(";"), Se = () => {
486
467
  const t = document.createElement("style");
487
468
  document.getElementsByTagName("head")[0].appendChild(t);
488
469
  let e = /* @__PURE__ */ new Set();
@@ -498,48 +479,43 @@ const Ae = (t) => [
498
479
  const f = new Set(r.map((l) => l.annotation.id));
499
480
  Array.from(e).filter((l) => !f.has(l));
500
481
  const m = r.map((l) => {
501
- var x;
502
- const p = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (x = l.state) != null && x.selected ? ot : P, g = u && u.paint(l, a) || p;
503
- return `::highlight(_${l.annotation.id}) { ${Ae(g)} }`;
482
+ var w;
483
+ const p = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (w = l.state) != null && w.selected ? ot : P, g = u && u.paint(l, a) || p;
484
+ return `::highlight(_${l.annotation.id}) { ${Ee(g)} }`;
504
485
  });
505
486
  t.innerHTML = m.join(`
506
487
  `), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
507
- const p = l.target.selector.map((x) => x.range), g = new Highlight(...p);
488
+ const p = l.target.selector.map((w) => w.range), g = new Highlight(...p);
508
489
  CSS.highlights.set(`_${l.id}`, g);
509
490
  }), e = f;
510
491
  }
511
492
  };
512
- }, Se = (t, e, n) => vt(t, e, n, Ee());
513
- var Bt = Object.prototype.hasOwnProperty;
493
+ }, Ce = (t, e, n) => vt(t, e, n, Se());
494
+ var Nt = Object.prototype.hasOwnProperty;
514
495
  function mt(t, e) {
515
496
  var n, o;
516
- if (t === e)
517
- return !0;
497
+ if (t === e) return !0;
518
498
  if (t && e && (n = t.constructor) === e.constructor) {
519
- if (n === Date)
520
- return t.getTime() === e.getTime();
521
- if (n === RegExp)
522
- return t.toString() === e.toString();
499
+ if (n === Date) return t.getTime() === e.getTime();
500
+ if (n === RegExp) return t.toString() === e.toString();
523
501
  if (n === Array) {
524
502
  if ((o = t.length) === e.length)
525
- for (; o-- && mt(t[o], e[o]); )
526
- ;
503
+ for (; o-- && mt(t[o], e[o]); ) ;
527
504
  return o === -1;
528
505
  }
529
506
  if (!n || typeof t == "object") {
530
507
  o = 0;
531
508
  for (n in t)
532
- if (Bt.call(t, n) && ++o && !Bt.call(e, n) || !(n in e) || !mt(t[n], e[n]))
533
- return !1;
509
+ if (Nt.call(t, n) && ++o && !Nt.call(e, n) || !(n in e) || !mt(t[n], e[n])) return !1;
534
510
  return Object.keys(e).length === o;
535
511
  }
536
512
  }
537
513
  return t !== t && e !== e;
538
514
  }
539
- const Ce = (t, e) => {
515
+ const Le = (t, e) => {
540
516
  const n = (o, i) => o.x <= i.x + i.width && o.x + o.width >= i.x && o.y <= i.y + i.height && o.y + o.height >= i.y;
541
517
  return e.filter((o) => t !== o && n(t, o) && o.width > t.width).length;
542
- }, Te = (t) => {
518
+ }, Be = (t) => {
543
519
  t.classList.add("r6o-annotatable");
544
520
  const e = document.createElement("div");
545
521
  e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
@@ -550,17 +526,16 @@ const Ce = (t, e) => {
550
526
  },
551
527
  redraw: (a, s, u, f, m) => {
552
528
  const p = !(mt(n, a) && m);
553
- if (!f && !p)
554
- return;
529
+ if (!f && !p) return;
555
530
  p && (e.innerHTML = "");
556
- const g = a.reduce((x, { rects: v }) => [...x, ...v], []);
557
- a.forEach((x) => {
558
- x.rects.map((v) => {
559
- const h = Ce(v, g), d = Kt(x, s, u, f, h);
531
+ const g = a.reduce((w, { rects: v }) => [...w, ...v], []);
532
+ a.forEach((w) => {
533
+ w.rects.map((v) => {
534
+ const h = Le(v, g), d = Kt(w, s, u, f, h);
560
535
  if (p) {
561
536
  const c = document.createElement("span");
562
- 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`;
563
- const y = _((d == null ? void 0 : d.fill) || P.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? P.fillOpacity : d.fillOpacity).toHex();
537
+ c.className = "r6o-annotation", c.dataset.annotation = w.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`;
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();
564
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);
565
540
  }
566
541
  });
@@ -570,51 +545,46 @@ const Ce = (t, e) => {
570
545
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
571
546
  }
572
547
  };
573
- }, Ne = (t, e, n) => vt(t, e, n, Te(t));
548
+ }, Te = (t, e, n) => vt(t, e, n, Be(t));
574
549
  var V = [];
575
550
  for (var lt = 0; lt < 256; ++lt)
576
551
  V.push((lt + 256).toString(16).slice(1));
577
- function Le(t, e = 0) {
552
+ function Re(t, e = 0) {
578
553
  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]]).toLowerCase();
579
554
  }
580
- var Z, Re = new Uint8Array(16);
581
- function Be() {
555
+ var Z, Ne = new Uint8Array(16);
556
+ function Me() {
582
557
  if (!Z && (Z = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Z))
583
558
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
584
- return Z(Re);
559
+ return Z(Ne);
585
560
  }
586
561
  var Oe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
587
- const Ot = {
562
+ const Mt = {
588
563
  randomUUID: Oe
589
564
  };
590
- function $t(t, e, n) {
591
- if (Ot.randomUUID && !e && !t)
592
- return Ot.randomUUID();
565
+ function Ht(t, e, n) {
566
+ if (Mt.randomUUID && !e && !t)
567
+ return Mt.randomUUID();
593
568
  t = t || {};
594
- var o = t.random || (t.rng || Be)();
595
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Le(o);
569
+ var o = t.random || (t.rng || Me)();
570
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Re(o);
596
571
  }
597
- var Mt = Object.prototype.hasOwnProperty;
572
+ var Ot = Object.prototype.hasOwnProperty;
598
573
  function q(t, e) {
599
574
  var n, o;
600
- if (t === e)
601
- return !0;
575
+ if (t === e) return !0;
602
576
  if (t && e && (n = t.constructor) === e.constructor) {
603
- if (n === Date)
604
- return t.getTime() === e.getTime();
605
- if (n === RegExp)
606
- return t.toString() === e.toString();
577
+ if (n === Date) return t.getTime() === e.getTime();
578
+ if (n === RegExp) return t.toString() === e.toString();
607
579
  if (n === Array) {
608
580
  if ((o = t.length) === e.length)
609
- for (; o-- && q(t[o], e[o]); )
610
- ;
581
+ for (; o-- && q(t[o], e[o]); ) ;
611
582
  return o === -1;
612
583
  }
613
584
  if (!n || typeof t == "object") {
614
585
  o = 0;
615
586
  for (n in t)
616
- if (Mt.call(t, n) && ++o && !Mt.call(e, n) || !(n in e) || !q(t[n], e[n]))
617
- return !1;
587
+ if (Ot.call(t, n) && ++o && !Ot.call(e, n) || !(n in e) || !q(t[n], e[n])) return !1;
618
588
  return Object.keys(e).length === o;
619
589
  }
620
590
  }
@@ -622,7 +592,7 @@ function q(t, e) {
622
592
  }
623
593
  function dt() {
624
594
  }
625
- function Me(t, e) {
595
+ function Ie(t, e) {
626
596
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
627
597
  }
628
598
  const z = [];
@@ -630,7 +600,7 @@ function yt(t, e = dt) {
630
600
  let n;
631
601
  const o = /* @__PURE__ */ new Set();
632
602
  function i(s) {
633
- if (Me(t, s) && (t = s, n)) {
603
+ if (Ie(t, s) && (t = s, n)) {
634
604
  const u = !z.length;
635
605
  for (const f of o)
636
606
  f[1](), z.push(f, t);
@@ -652,7 +622,7 @@ function yt(t, e = dt) {
652
622
  }
653
623
  return { set: i, update: r, subscribe: a };
654
624
  }
655
- const Ie = (t) => {
625
+ const Ve = (t) => {
656
626
  const { subscribe: e, set: n } = yt();
657
627
  let o;
658
628
  return e((i) => o = i), t.observe(({ changes: i }) => {
@@ -669,8 +639,8 @@ const Ie = (t) => {
669
639
  set: n
670
640
  };
671
641
  };
672
- var Ve = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Ve || {});
673
- const ut = { selected: [] }, De = (t, e = "EDIT") => {
642
+ var Ue = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Ue || {});
643
+ const ut = { selected: [] }, ke = (t, e = "EDIT") => {
674
644
  const { subscribe: n, set: o } = yt(ut);
675
645
  let i = ut;
676
646
  n((l) => i = l);
@@ -685,18 +655,18 @@ const ut = { selected: [] }, De = (t, e = "EDIT") => {
685
655
  }, u = (l, p) => {
686
656
  const g = t.getAnnotation(l);
687
657
  if (g) {
688
- const x = It(g, e);
689
- o(x === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: p } : x === "SELECT" ? { selected: [{ id: l }], pointerEvent: p } : { selected: [], pointerEvent: p });
658
+ const w = It(g, e);
659
+ o(w === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: p } : w === "SELECT" ? { selected: [{ id: l }], pointerEvent: p } : { selected: [], pointerEvent: p });
690
660
  } else
691
661
  console.warn("Invalid selection: " + l);
692
662
  }, f = (l, p) => {
693
- const g = Array.isArray(l) ? l : [l], x = g.map((v) => t.getAnnotation(v)).filter(Boolean);
663
+ const g = Array.isArray(l) ? l : [l], w = g.map((v) => t.getAnnotation(v)).filter(Boolean);
694
664
  o({
695
- selected: x.map((v) => {
665
+ selected: w.map((v) => {
696
666
  const h = p === void 0 ? It(v, e) === "EDIT" : p;
697
667
  return { id: v.id, editable: h };
698
668
  })
699
- }), x.length !== g.length && console.warn("Invalid selection", l);
669
+ }), w.length !== g.length && console.warn("Invalid selection", l);
700
670
  }, m = (l) => {
701
671
  if (i.selected.length === 0)
702
672
  return !1;
@@ -718,31 +688,31 @@ const ut = { selected: [] }, De = (t, e = "EDIT") => {
718
688
  subscribe: n
719
689
  };
720
690
  }, It = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
721
- var D = [];
691
+ var U = [];
722
692
  for (var ht = 0; ht < 256; ++ht)
723
- D.push((ht + 256).toString(16).slice(1));
724
- function Ue(t, e = 0) {
725
- return (D[t[e + 0]] + D[t[e + 1]] + D[t[e + 2]] + D[t[e + 3]] + "-" + D[t[e + 4]] + D[t[e + 5]] + "-" + D[t[e + 6]] + D[t[e + 7]] + "-" + D[t[e + 8]] + D[t[e + 9]] + "-" + D[t[e + 10]] + D[t[e + 11]] + D[t[e + 12]] + D[t[e + 13]] + D[t[e + 14]] + D[t[e + 15]]).toLowerCase();
693
+ U.push((ht + 256).toString(16).slice(1));
694
+ function Ye(t, e = 0) {
695
+ 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]]).toLowerCase();
726
696
  }
727
- var tt, _e = new Uint8Array(16);
728
- function Xe() {
697
+ var tt, De = new Uint8Array(16);
698
+ function _e() {
729
699
  if (!tt && (tt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !tt))
730
700
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
731
- return tt(_e);
701
+ return tt(De);
732
702
  }
733
- var ke = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
703
+ var Xe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
734
704
  const Vt = {
735
- randomUUID: ke
705
+ randomUUID: Xe
736
706
  };
737
- function Ye(t, e, n) {
707
+ function $e(t, e, n) {
738
708
  if (Vt.randomUUID && !e && !t)
739
709
  return Vt.randomUUID();
740
710
  t = t || {};
741
- var o = t.random || (t.rng || Xe)();
742
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Ue(o);
711
+ var o = t.random || (t.rng || _e)();
712
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Ye(o);
743
713
  }
744
- const In = (t, e, n, o) => ({
745
- id: Ye(),
714
+ const Vn = (t, e, n, o) => ({
715
+ id: $e(),
746
716
  annotation: t.id,
747
717
  created: n || /* @__PURE__ */ new Date(),
748
718
  creator: o,
@@ -750,25 +720,25 @@ const In = (t, e, n, o) => ({
750
720
  }), He = (t, e) => {
751
721
  const n = new Set(t.bodies.map((o) => o.id));
752
722
  return e.bodies.filter((o) => !n.has(o.id));
753
- }, $e = (t, e) => {
723
+ }, Pe = (t, e) => {
754
724
  const n = new Set(e.bodies.map((o) => o.id));
755
725
  return t.bodies.filter((o) => !n.has(o.id));
756
- }, Pe = (t, e) => e.bodies.map((n) => {
726
+ }, ze = (t, e) => e.bodies.map((n) => {
757
727
  const o = t.bodies.find((i) => i.id === n.id);
758
728
  return { newBody: n, oldBody: o && !q(o, n) ? o : void 0 };
759
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), ze = (t, e) => !q(t.target, e.target), Pt = (t, e) => {
760
- const n = He(t, e), o = $e(t, e), i = Pe(t, e);
729
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Fe = (t, e) => !q(t.target, e.target), Pt = (t, e) => {
730
+ const n = He(t, e), o = Pe(t, e), i = ze(t, e);
761
731
  return {
762
732
  oldValue: t,
763
733
  newValue: e,
764
734
  bodiesCreated: n.length > 0 ? n : void 0,
765
735
  bodiesDeleted: o.length > 0 ? o : void 0,
766
736
  bodiesUpdated: i.length > 0 ? i : void 0,
767
- targetUpdated: ze(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
737
+ targetUpdated: Fe(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
768
738
  };
769
739
  };
770
- var B = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(B || {});
771
- const Fe = (t, e) => {
740
+ var N = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(N || {});
741
+ const We = (t, e) => {
772
742
  var n, o;
773
743
  const { changes: i, origin: r } = e;
774
744
  if (!(!t.options.origin || t.options.origin === r))
@@ -790,7 +760,7 @@ const Fe = (t, e) => {
790
760
  return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => a.has(s));
791
761
  } else
792
762
  return !0;
793
- }, We = (t, e) => {
763
+ }, qe = (t, e) => {
794
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)), 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)), u = [
795
765
  ...(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),
796
766
  ...e.created || []
@@ -801,70 +771,70 @@ const Fe = (t, e) => {
801
771
  ...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
802
772
  const { oldValue: p, newValue: g } = l;
803
773
  if (a.has(g.id)) {
804
- const x = e.updated.find((v) => v.oldValue.id === g.id).newValue;
805
- return Pt(p, x);
774
+ const w = e.updated.find((v) => v.oldValue.id === g.id).newValue;
775
+ return Pt(p, w);
806
776
  } else
807
777
  return l;
808
778
  }),
809
779
  ...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
810
780
  ];
811
781
  return { created: u, deleted: f, updated: m };
812
- }, qe = (t) => t.id !== void 0, je = () => {
813
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, w = {}) => n.push({ onChange: b, options: w }), i = (b) => {
814
- const w = n.findIndex((A) => A.onChange == b);
815
- w > -1 && n.splice(w, 1);
816
- }, r = (b, w) => {
782
+ }, je = (t) => t.id !== void 0, Ge = () => {
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) => {
817
787
  const A = {
818
788
  origin: b,
819
789
  changes: {
820
- created: w.created || [],
821
- updated: w.updated || [],
822
- deleted: w.deleted || []
790
+ created: x.created || [],
791
+ updated: x.updated || [],
792
+ deleted: x.deleted || []
823
793
  },
824
794
  state: [...t.values()]
825
795
  };
826
796
  n.forEach((S) => {
827
- Fe(S, A) && S.onChange(A);
797
+ We(S, A) && S.onChange(A);
828
798
  });
829
- }, a = (b, w = B.LOCAL) => {
799
+ }, a = (b, x = N.LOCAL) => {
830
800
  if (t.get(b.id))
831
801
  throw Error(`Cannot add annotation ${b.id} - exists already`);
832
- t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(w, { created: [b] });
833
- }, s = (b, w) => {
834
- 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, S = typeof b == "string" ? b : b.id, R = t.get(S);
835
805
  if (R) {
836
806
  const M = Pt(R, A);
837
807
  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;
838
808
  } else
839
809
  console.warn(`Cannot update annotation ${S} - does not exist`);
840
- }, u = (b, w = B.LOCAL, A = B.LOCAL) => {
841
- const S = qe(w) ? A : w, R = s(b, w);
810
+ }, u = (b, x = N.LOCAL, A = N.LOCAL) => {
811
+ const S = je(x) ? A : x, R = s(b, x);
842
812
  R && r(S, { updated: [R] });
843
- }, f = (b, w = B.LOCAL) => {
813
+ }, f = (b, x = N.LOCAL) => {
844
814
  const A = b.reduce((S, R) => {
845
815
  const M = s(R);
846
816
  return M ? [...S, M] : S;
847
817
  }, []);
848
- A.length > 0 && r(w, { updated: A });
849
- }, m = (b, w = B.LOCAL) => {
818
+ A.length > 0 && r(x, { updated: A });
819
+ }, m = (b, x = N.LOCAL) => {
850
820
  const A = t.get(b.annotation);
851
821
  if (A) {
852
822
  const S = {
853
823
  ...A,
854
824
  bodies: [...A.bodies, b]
855
825
  };
856
- t.set(A.id, S), e.set(b.id, S.id), r(w, { updated: [{
826
+ t.set(A.id, S), e.set(b.id, S.id), r(x, { updated: [{
857
827
  oldValue: A,
858
828
  newValue: S,
859
829
  bodiesCreated: [b]
860
830
  }] });
861
831
  } else
862
832
  console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
863
- }, l = () => [...t.values()], p = (b = B.LOCAL) => {
864
- const w = [...t.values()];
865
- t.clear(), e.clear(), r(b, { deleted: w });
866
- }, g = (b, w = !0, A = B.LOCAL) => {
867
- if (w) {
833
+ }, l = () => [...t.values()], p = (b = N.LOCAL) => {
834
+ const x = [...t.values()];
835
+ t.clear(), e.clear(), r(b, { deleted: x });
836
+ }, g = (b, x = !0, A = N.LOCAL) => {
837
+ if (x) {
868
838
  const S = [...t.values()];
869
839
  t.clear(), e.clear(), b.forEach((R) => {
870
840
  t.set(R.id, R), R.bodies.forEach((M) => e.set(M.id, R.id));
@@ -880,32 +850,32 @@ const Fe = (t, e) => {
880
850
  t.set(R.id, R), R.bodies.forEach((M) => e.set(M.id, R.id));
881
851
  }), r(A, { created: b });
882
852
  }
883
- }, x = (b) => {
884
- 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);
885
855
  if (A)
886
- return t.delete(w), A.bodies.forEach((S) => e.delete(S.id)), A;
887
- console.warn(`Attempt to delete missing annotation: ${w}`);
888
- }, v = (b, w = B.LOCAL) => {
889
- const A = x(b);
890
- A && r(w, { deleted: [A] });
891
- }, h = (b, w = B.LOCAL) => {
856
+ return t.delete(x), A.bodies.forEach((S) => e.delete(S.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
+ }, h = (b, x = N.LOCAL) => {
892
862
  const A = b.reduce((S, R) => {
893
- const M = x(R);
863
+ const M = w(R);
894
864
  return M ? [...S, M] : S;
895
865
  }, []);
896
- A.length > 0 && r(w, { deleted: A });
866
+ A.length > 0 && r(x, { deleted: A });
897
867
  }, d = (b) => {
898
- const w = t.get(b.annotation);
899
- if (w) {
900
- 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((S) => S.id === b.id);
901
871
  if (A) {
902
872
  e.delete(A.id);
903
873
  const S = {
904
- ...w,
905
- bodies: w.bodies.filter((R) => R.id !== b.id)
874
+ ...x,
875
+ bodies: x.bodies.filter((R) => R.id !== b.id)
906
876
  };
907
- return t.set(w.id, S), {
908
- oldValue: w,
877
+ return t.set(x.id, S), {
878
+ oldValue: x,
909
879
  newValue: S,
910
880
  bodiesDeleted: [A]
911
881
  };
@@ -913,61 +883,61 @@ const Fe = (t, e) => {
913
883
  console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
914
884
  } else
915
885
  console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
916
- }, c = (b, w = B.LOCAL) => {
886
+ }, c = (b, x = N.LOCAL) => {
917
887
  const A = d(b);
918
- A && r(w, { updated: [A] });
919
- }, y = (b, w = B.LOCAL) => {
888
+ A && r(x, { updated: [A] });
889
+ }, y = (b, x = N.LOCAL) => {
920
890
  const A = b.map((S) => d(S)).filter(Boolean);
921
- A.length > 0 && r(w, { updated: A });
922
- }, T = (b) => {
923
- const w = t.get(b);
924
- return w ? { ...w } : void 0;
891
+ A.length > 0 && r(x, { updated: A });
925
892
  }, C = (b) => {
926
- const w = e.get(b);
927
- if (w) {
928
- const A = T(w).bodies.find((S) => S.id === b);
893
+ const x = t.get(b);
894
+ return x ? { ...x } : void 0;
895
+ }, L = (b) => {
896
+ const x = e.get(b);
897
+ if (x) {
898
+ const A = C(x).bodies.find((S) => S.id === b);
929
899
  if (A)
930
900
  return A;
931
901
  console.error(`Store integrity error: body ${b} in index, but not in annotation`);
932
902
  } else
933
903
  console.warn(`Attempt to retrieve missing body: ${b}`);
934
- }, E = (b, w) => {
935
- if (b.annotation !== w.annotation)
904
+ }, E = (b, x) => {
905
+ if (b.annotation !== x.annotation)
936
906
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
937
907
  const A = t.get(b.annotation);
938
908
  if (A) {
939
909
  const S = A.bodies.find((M) => M.id === b.id), R = {
940
910
  ...A,
941
- bodies: A.bodies.map((M) => M.id === S.id ? w : M)
911
+ bodies: A.bodies.map((M) => M.id === S.id ? x : M)
942
912
  };
943
- 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), S.id !== x.id && (e.delete(S.id), e.set(x.id, R.id)), {
944
914
  oldValue: A,
945
915
  newValue: R,
946
- bodiesUpdated: [{ oldBody: S, newBody: w }]
916
+ bodiesUpdated: [{ oldBody: S, newBody: x }]
947
917
  };
948
918
  } else
949
919
  console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
950
- }, N = (b, w, A = B.LOCAL) => {
951
- const S = E(b, w);
920
+ }, B = (b, x, A = N.LOCAL) => {
921
+ const S = E(b, x);
952
922
  S && r(A, { updated: [S] });
953
- }, L = (b, w = B.LOCAL) => {
923
+ }, T = (b, x = N.LOCAL) => {
954
924
  const A = b.map((S) => E({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
955
- r(w, { updated: A });
925
+ r(x, { updated: A });
956
926
  }, O = (b) => {
957
- const w = t.get(b.annotation);
958
- if (w) {
927
+ const x = t.get(b.annotation);
928
+ if (x) {
959
929
  const A = {
960
- ...w,
930
+ ...x,
961
931
  target: {
962
- ...w.target,
932
+ ...x.target,
963
933
  ...b
964
934
  }
965
935
  };
966
- return t.set(w.id, A), {
967
- oldValue: w,
936
+ return t.set(x.id, A), {
937
+ oldValue: x,
968
938
  newValue: A,
969
939
  targetUpdated: {
970
- oldTarget: w.target,
940
+ oldTarget: x.target,
971
941
  newTarget: b
972
942
  }
973
943
  };
@@ -982,27 +952,27 @@ const Fe = (t, e) => {
982
952
  bulkDeleteAnnotation: h,
983
953
  bulkDeleteBodies: y,
984
954
  bulkUpdateAnnotation: f,
985
- bulkUpdateBodies: L,
986
- bulkUpdateTargets: (b, w = B.LOCAL) => {
955
+ bulkUpdateBodies: T,
956
+ bulkUpdateTargets: (b, x = N.LOCAL) => {
987
957
  const A = b.map((S) => O(S)).filter(Boolean);
988
- A.length > 0 && r(w, { updated: A });
958
+ A.length > 0 && r(x, { updated: A });
989
959
  },
990
960
  clear: p,
991
961
  deleteAnnotation: v,
992
962
  deleteBody: c,
993
- getAnnotation: T,
994
- getBody: C,
963
+ getAnnotation: C,
964
+ getBody: L,
995
965
  observe: o,
996
966
  unobserve: i,
997
967
  updateAnnotation: u,
998
- updateBody: N,
999
- updateTarget: (b, w = B.LOCAL) => {
968
+ updateBody: B,
969
+ updateTarget: (b, x = N.LOCAL) => {
1000
970
  const A = O(b);
1001
- A && r(w, { updated: [A] });
971
+ A && r(x, { updated: [A] });
1002
972
  }
1003
973
  };
1004
974
  };
1005
- let Ge = () => ({
975
+ let Ke = () => ({
1006
976
  emit(t, ...e) {
1007
977
  for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
1008
978
  o[n](...e);
@@ -1016,64 +986,67 @@ let Ge = () => ({
1016
986
  };
1017
987
  }
1018
988
  });
1019
- const Ke = 250, Qe = (t) => {
1020
- const e = Ge(), n = [];
989
+ const Qe = 250, Je = (t) => {
990
+ const e = Ke(), n = [];
1021
991
  let o = -1, i = !1, r = 0;
1022
992
  const a = (g) => {
1023
993
  if (!i) {
1024
- const { changes: x } = g, v = performance.now();
1025
- if (v - r > Ke)
1026
- n.splice(o + 1), n.push(x), o = n.length - 1;
994
+ const { changes: w } = g, v = performance.now();
995
+ if (v - r > Qe)
996
+ n.splice(o + 1), n.push(w), o = n.length - 1;
1027
997
  else {
1028
998
  const h = n.length - 1;
1029
- n[h] = We(n[h], x);
999
+ n[h] = qe(n[h], w);
1030
1000
  }
1031
1001
  r = v;
1032
1002
  }
1033
1003
  i = !1;
1034
1004
  };
1035
- t.observe(a, { origin: B.LOCAL });
1036
- const s = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), u = (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);
1005
+ t.observe(a, { origin: N.LOCAL });
1006
+ const s = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), u = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), f = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: w }) => w)), m = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: w }) => w)), l = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), p = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
1037
1007
  return {
1038
1008
  canRedo: () => n.length - 1 > o,
1039
1009
  canUndo: () => o > -1,
1040
1010
  destroy: () => t.unobserve(a),
1041
- on: (g, x) => e.on(g, x),
1011
+ on: (g, w) => e.on(g, w),
1042
1012
  redo: () => {
1043
1013
  if (n.length - 1 > o) {
1044
1014
  i = !0;
1045
- const { created: g, updated: x, deleted: v } = n[o + 1];
1046
- u(g), m(x), p(v), e.emit("redo", n[o + 1]), o += 1;
1015
+ const { created: g, updated: w, deleted: v } = n[o + 1];
1016
+ u(g), m(w), p(v), e.emit("redo", n[o + 1]), o += 1;
1047
1017
  }
1048
1018
  },
1049
1019
  undo: () => {
1050
1020
  if (o > -1) {
1051
1021
  i = !0;
1052
- const { created: g, updated: x, deleted: v } = n[o];
1053
- s(g), f(x), l(v), e.emit("undo", n[o]), o -= 1;
1022
+ const { created: g, updated: w, deleted: v } = n[o];
1023
+ s(g), f(w), l(v), e.emit("undo", n[o]), o -= 1;
1054
1024
  }
1055
1025
  }
1056
1026
  };
1057
- }, Je = () => {
1027
+ }, Ze = () => {
1058
1028
  const { subscribe: t, set: e } = yt([]);
1059
1029
  return {
1060
1030
  subscribe: t,
1061
1031
  set: e
1062
1032
  };
1063
- }, Ze = (t, e, n, o) => {
1033
+ }, tn = (t, e, n, o) => {
1064
1034
  const { store: i, selection: r, hover: a, viewport: s } = t, u = /* @__PURE__ */ new Map();
1065
1035
  let f = [], m;
1066
1036
  const l = (v, h) => {
1067
1037
  u.has(v) ? u.get(v).push(h) : u.set(v, [h]);
1068
1038
  }, p = (v, h) => {
1069
1039
  const d = u.get(v);
1070
- d && d.indexOf(h) > 0 && d.splice(d.indexOf(h), 1);
1040
+ if (d) {
1041
+ const c = d.indexOf(h);
1042
+ c !== -1 && d.splice(c, 1);
1043
+ }
1071
1044
  }, g = (v, h, d) => {
1072
1045
  u.has(v) && setTimeout(() => {
1073
1046
  u.get(v).forEach((c) => {
1074
1047
  if (n) {
1075
- const y = Array.isArray(h) ? h.map((C) => n.serialize(C)) : n.serialize(h), T = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1076
- c(y, T);
1048
+ const y = Array.isArray(h) ? h.map((L) => n.serialize(L)) : n.serialize(h), C = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1049
+ c(y, C);
1077
1050
  } else
1078
1051
  c(h, d);
1079
1052
  });
@@ -1111,21 +1084,21 @@ const Ke = 250, Qe = (t) => {
1111
1084
  ...c.bodiesDeleted || [],
1112
1085
  ...c.bodiesUpdated || []
1113
1086
  ].length > 0).forEach(({ oldValue: c, newValue: y }) => {
1114
- const T = f.find((C) => C.id === c.id) || c;
1115
- f = f.map((C) => C.id === c.id ? y : C), g("updateAnnotation", y, T);
1087
+ const C = f.find((L) => L.id === c.id) || c;
1088
+ f = f.map((L) => L.id === c.id ? y : L), g("updateAnnotation", y, C);
1116
1089
  });
1117
- }, { origin: B.LOCAL }), i.observe((v) => {
1090
+ }, { origin: N.LOCAL }), i.observe((v) => {
1118
1091
  if (f) {
1119
1092
  const h = new Set(f.map((c) => c.id)), d = (v.changes.updated || []).filter(({ newValue: c }) => h.has(c.id)).map(({ newValue: c }) => c);
1120
- d.length > 0 && (f = f.map((c) => d.find((T) => T.id === c.id) || c));
1093
+ d.length > 0 && (f = f.map((c) => d.find((C) => C.id === c.id) || c));
1121
1094
  }
1122
- }, { origin: B.REMOTE });
1123
- const x = (v) => (h) => {
1095
+ }, { origin: N.REMOTE });
1096
+ const w = (v) => (h) => {
1124
1097
  const { updated: d } = h;
1125
1098
  v ? (d || []).forEach((c) => g("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => g("updateAnnotation", c.newValue, c.oldValue));
1126
1099
  };
1127
- return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: l, off: p, emit: g };
1128
- }, tn = (t) => (e) => e.reduce((n, o) => {
1100
+ return e.on("undo", w(!0)), e.on("redo", w(!1)), { on: l, off: p, emit: g };
1101
+ }, en = (t) => (e) => e.reduce((n, o) => {
1129
1102
  const { parsed: i, error: r } = t.parse(o);
1130
1103
  return r ? {
1131
1104
  parsed: n.parsed,
@@ -1136,13 +1109,13 @@ const Ke = 250, Qe = (t) => {
1136
1109
  } : {
1137
1110
  ...n
1138
1111
  };
1139
- }, { parsed: [], failed: [] }), en = (t, e, n) => {
1112
+ }, { parsed: [], failed: [] }), nn = (t, e, n) => {
1140
1113
  const { store: o, selection: i } = t, r = (h) => {
1141
1114
  if (n) {
1142
1115
  const { parsed: d, error: c } = n.parse(h);
1143
- d ? o.addAnnotation(d, B.REMOTE) : console.error(c);
1116
+ d ? o.addAnnotation(d, N.REMOTE) : console.error(c);
1144
1117
  } else
1145
- o.addAnnotation(h, B.REMOTE);
1118
+ o.addAnnotation(h, N.REMOTE);
1146
1119
  }, a = () => i.clear(), s = () => o.clear(), u = (h) => {
1147
1120
  const d = o.getAnnotation(h);
1148
1121
  return n && d ? n.serialize(d) : d;
@@ -1162,11 +1135,11 @@ const Ke = 250, Qe = (t) => {
1162
1135
  }
1163
1136
  }, g = (h, d = !0) => {
1164
1137
  if (n) {
1165
- const { parsed: c, failed: y } = tn(n)(h);
1166
- y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(c, d, B.REMOTE);
1138
+ const { parsed: c, failed: y } = en(n)(h);
1139
+ y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(c, d, N.REMOTE);
1167
1140
  } else
1168
- o.bulkAddAnnotation(h, d, B.REMOTE);
1169
- }, x = (h, d) => {
1141
+ o.bulkAddAnnotation(h, d, N.REMOTE);
1142
+ }, w = (h, d) => {
1170
1143
  h ? i.setSelected(h, d) : i.clear();
1171
1144
  }, v = (h) => {
1172
1145
  if (n) {
@@ -1190,29 +1163,28 @@ const Ke = 250, Qe = (t) => {
1190
1163
  redo: e.redo,
1191
1164
  removeAnnotation: p,
1192
1165
  setAnnotations: g,
1193
- setSelected: x,
1166
+ setSelected: w,
1194
1167
  undo: e.undo,
1195
1168
  updateAnnotation: v
1196
1169
  };
1197
- }, nn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1198
- let on = (t) => crypto.getRandomValues(new Uint8Array(t)), rn = (t, e, n) => {
1170
+ }, on = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1171
+ let rn = (t) => crypto.getRandomValues(new Uint8Array(t)), sn = (t, e, n) => {
1199
1172
  let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
1200
1173
  return (r = e) => {
1201
1174
  let a = "";
1202
1175
  for (; ; ) {
1203
1176
  let s = n(i), u = i;
1204
1177
  for (; u--; )
1205
- if (a += t[s[u] & o] || "", a.length === r)
1206
- return a;
1178
+ if (a += t[s[u] & o] || "", a.length === r) return a;
1207
1179
  }
1208
1180
  };
1209
- }, sn = (t, e = 21) => rn(t, e, on), an = (t = 21) => {
1181
+ }, an = (t, e = 21) => sn(t, e, rn), cn = (t = 21) => {
1210
1182
  let e = "", n = crypto.getRandomValues(new Uint8Array(t));
1211
1183
  for (; t--; )
1212
- e += nn[n[t] & 63];
1184
+ e += on[n[t] & 63];
1213
1185
  return e;
1214
1186
  };
1215
- const cn = () => ({ isGuest: !0, id: sn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), ln = (t) => {
1187
+ const ln = () => ({ isGuest: !0, id: an("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), dn = (t) => {
1216
1188
  const e = JSON.stringify(t);
1217
1189
  let n = 0;
1218
1190
  for (let o = 0, i = e.length; o < i; o++) {
@@ -1220,10 +1192,10 @@ const cn = () => ({ isGuest: !0, id: sn("1234567890abcdefghijklmnopqrstuvwxyzABC
1220
1192
  n = (n << 5) - n + r, n |= 0;
1221
1193
  }
1222
1194
  return `${n}`;
1223
- }, zt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, dn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1195
+ }, zt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, un = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1224
1196
  const { id: o, type: i, purpose: r, value: a, created: s, modified: u, creator: f, ...m } = n;
1225
1197
  return {
1226
- id: o || `temp-${ln(n)}`,
1198
+ id: o || `temp-${dn(n)}`,
1227
1199
  annotation: e,
1228
1200
  type: i,
1229
1201
  purpose: r,
@@ -1233,7 +1205,7 @@ const cn = () => ({ isGuest: !0, id: sn("1234567890abcdefghijklmnopqrstuvwxyzABC
1233
1205
  updated: u ? new Date(u) : void 0,
1234
1206
  ...m
1235
1207
  };
1236
- }), un = (t) => t.map((e) => {
1208
+ }), hn = (t) => t.map((e) => {
1237
1209
  var n;
1238
1210
  const { annotation: o, created: i, updated: r, ...a } = e, s = {
1239
1211
  ...a,
@@ -1242,11 +1214,11 @@ const cn = () => ({ isGuest: !0, id: sn("1234567890abcdefghijklmnopqrstuvwxyzABC
1242
1214
  };
1243
1215
  return (n = s.id) != null && n.startsWith("temp-") && delete s.id, s;
1244
1216
  });
1245
- an();
1246
- const Vn = (t, e) => ({
1247
- parse: (n) => gn(n),
1248
- serialize: (n) => pn(n, t, e)
1249
- }), hn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, fn = (t) => {
1217
+ cn();
1218
+ const Un = (t, e) => ({
1219
+ parse: (n) => pn(n),
1220
+ serialize: (n) => mn(n, t, e)
1221
+ }), fn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, gn = (t) => {
1250
1222
  const {
1251
1223
  id: e,
1252
1224
  creator: n,
@@ -1272,7 +1244,7 @@ const Vn = (t, e) => ({
1272
1244
  }
1273
1245
  return l;
1274
1246
  }, {});
1275
- if (hn(m))
1247
+ if (fn(m))
1276
1248
  s.selector.push({ id: u.id, ...m });
1277
1249
  else {
1278
1250
  const l = [
@@ -1283,14 +1255,14 @@ const Vn = (t, e) => ({
1283
1255
  }
1284
1256
  }
1285
1257
  return { parsed: s };
1286
- }, gn = (t) => {
1287
- const e = t.id || $t(), {
1258
+ }, pn = (t) => {
1259
+ const e = t.id || Ht(), {
1288
1260
  creator: n,
1289
1261
  created: o,
1290
1262
  modified: i,
1291
1263
  body: r,
1292
1264
  ...a
1293
- } = t, s = dn(r, e), u = fn(t);
1265
+ } = t, s = un(r, e), u = gn(t);
1294
1266
  return "error" in u ? { error: u.error } : {
1295
1267
  parsed: {
1296
1268
  ...a,
@@ -1299,7 +1271,7 @@ const Vn = (t, e) => ({
1299
1271
  target: u.parsed
1300
1272
  }
1301
1273
  };
1302
- }, pn = (t, e, n) => {
1274
+ }, mn = (t, e, n) => {
1303
1275
  const { bodies: o, target: i, ...r } = t, {
1304
1276
  selector: a,
1305
1277
  creator: s,
@@ -1307,14 +1279,14 @@ const Vn = (t, e) => ({
1307
1279
  updated: f,
1308
1280
  ...m
1309
1281
  } = i, l = a.map((p) => {
1310
- const { quote: g, start: x, end: v, range: h } = p, { prefix: d, suffix: c } = oe(h, n), y = [{
1282
+ const { quote: g, start: w, end: v, range: h } = p, { prefix: d, suffix: c } = oe(h, n), y = [{
1311
1283
  type: "TextQuoteSelector",
1312
1284
  exact: g,
1313
1285
  prefix: d,
1314
1286
  suffix: c
1315
1287
  }, {
1316
1288
  type: "TextPositionSelector",
1317
- start: x,
1289
+ start: w,
1318
1290
  end: v
1319
1291
  }];
1320
1292
  return {
@@ -1329,15 +1301,15 @@ const Vn = (t, e) => ({
1329
1301
  "@context": "http://www.w3.org/ns/anno.jsonld",
1330
1302
  id: t.id,
1331
1303
  type: "Annotation",
1332
- body: un(t.bodies),
1304
+ body: hn(t.bodies),
1333
1305
  creator: s,
1334
1306
  created: u == null ? void 0 : u.toISOString(),
1335
1307
  modified: f == null ? void 0 : f.toISOString(),
1336
1308
  target: l
1337
1309
  };
1338
1310
  };
1339
- function mn(t, e, n, o, i) {
1340
- Ft(t, e, n || 0, o || t.length - 1, i || bn);
1311
+ function bn(t, e, n, o, i) {
1312
+ Ft(t, e, n || 0, o || t.length - 1, i || vn);
1341
1313
  }
1342
1314
  function Ft(t, e, n, o, i) {
1343
1315
  for (; o > n; ) {
@@ -1345,24 +1317,22 @@ function Ft(t, e, n, o, i) {
1345
1317
  var r = o - n + 1, a = e - n + 1, s = Math.log(r), u = 0.5 * Math.exp(2 * s / 3), f = 0.5 * Math.sqrt(s * u * (r - u) / r) * (a - r / 2 < 0 ? -1 : 1), m = Math.max(n, Math.floor(e - a * u / r + f)), l = Math.min(o, Math.floor(e + (r - a) * u / r + f));
1346
1318
  Ft(t, e, m, l, i);
1347
1319
  }
1348
- var p = t[e], g = n, x = o;
1349
- for (j(t, n, e), i(t[o], p) > 0 && j(t, n, o); g < x; ) {
1350
- for (j(t, g, x), g++, x--; i(t[g], p) < 0; )
1351
- g++;
1352
- for (; i(t[x], p) > 0; )
1353
- x--;
1320
+ var p = t[e], g = n, w = o;
1321
+ for (j(t, n, e), i(t[o], p) > 0 && j(t, n, o); g < w; ) {
1322
+ for (j(t, g, w), g++, w--; i(t[g], p) < 0; ) g++;
1323
+ for (; i(t[w], p) > 0; ) w--;
1354
1324
  }
1355
- 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], p) === 0 ? j(t, n, w) : (w++, j(t, w, o)), w <= e && (n = w + 1), e <= w && (o = w - 1);
1356
1326
  }
1357
1327
  }
1358
1328
  function j(t, e, n) {
1359
1329
  var o = t[e];
1360
1330
  t[e] = t[n], t[n] = o;
1361
1331
  }
1362
- function bn(t, e) {
1332
+ function vn(t, e) {
1363
1333
  return t < e ? -1 : t > e ? 1 : 0;
1364
1334
  }
1365
- class vn {
1335
+ class yn {
1366
1336
  constructor(e = 9) {
1367
1337
  this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
1368
1338
  }
@@ -1372,8 +1342,7 @@ class vn {
1372
1342
  search(e) {
1373
1343
  let n = this.data;
1374
1344
  const o = [];
1375
- if (!nt(e, n))
1376
- return o;
1345
+ if (!nt(e, n)) return o;
1377
1346
  const i = this.toBBox, r = [];
1378
1347
  for (; n; ) {
1379
1348
  for (let a = 0; a < n.children.length; a++) {
@@ -1386,15 +1355,13 @@ class vn {
1386
1355
  }
1387
1356
  collides(e) {
1388
1357
  let n = this.data;
1389
- if (!nt(e, n))
1390
- return !1;
1358
+ if (!nt(e, n)) return !1;
1391
1359
  const o = [];
1392
1360
  for (; n; ) {
1393
1361
  for (let i = 0; i < n.children.length; i++) {
1394
1362
  const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
1395
1363
  if (nt(e, a)) {
1396
- if (n.leaf || gt(e, a))
1397
- return !0;
1364
+ if (n.leaf || gt(e, a)) return !0;
1398
1365
  o.push(r);
1399
1366
  }
1400
1367
  }
@@ -1403,8 +1370,7 @@ class vn {
1403
1370
  return !1;
1404
1371
  }
1405
1372
  load(e) {
1406
- if (!(e && e.length))
1407
- return this;
1373
+ if (!(e && e.length)) return this;
1408
1374
  if (e.length < this._minEntries) {
1409
1375
  for (let o = 0; o < e.length; o++)
1410
1376
  this.insert(e[o]);
@@ -1431,14 +1397,13 @@ class vn {
1431
1397
  return this.data = W([]), this;
1432
1398
  }
1433
1399
  remove(e, n) {
1434
- if (!e)
1435
- return this;
1400
+ if (!e) return this;
1436
1401
  let o = this.data;
1437
1402
  const i = this.toBBox(e), r = [], a = [];
1438
1403
  let s, u, f;
1439
1404
  for (; o || r.length; ) {
1440
1405
  if (o || (o = r.pop(), u = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
1441
- const m = yn(e, o.children, n);
1406
+ const m = wn(e, o.children, n);
1442
1407
  if (m !== -1)
1443
1408
  return o.children.splice(m, 1), r.push(o), this._condense(r), this;
1444
1409
  }
@@ -1474,10 +1439,10 @@ class vn {
1474
1439
  return s = W(e.slice(n, o + 1)), F(s, this.toBBox), s;
1475
1440
  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;
1476
1441
  const u = Math.ceil(r / a), f = u * Math.ceil(Math.sqrt(a));
1477
- Dt(e, n, o, f, this.compareMinX);
1442
+ Ut(e, n, o, f, this.compareMinX);
1478
1443
  for (let m = n; m <= o; m += f) {
1479
1444
  const l = Math.min(m + f - 1, o);
1480
- Dt(e, m, l, u, this.compareMinY);
1445
+ Ut(e, m, l, u, this.compareMinY);
1481
1446
  for (let p = m; p <= l; p += u) {
1482
1447
  const g = Math.min(p + u - 1, l);
1483
1448
  s.children.push(this._build(e, p, g, i - 1));
@@ -1489,7 +1454,7 @@ class vn {
1489
1454
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1490
1455
  let r = 1 / 0, a = 1 / 0, s;
1491
1456
  for (let u = 0; u < n.children.length; u++) {
1492
- const f = n.children[u], m = ft(f), l = An(e, f) - m;
1457
+ const f = n.children[u], m = ft(f), l = En(e, f) - m;
1493
1458
  l < a ? (a = l, r = m < r ? m : r, s = f) : l === a && m < r && (r = m, s = f);
1494
1459
  }
1495
1460
  n = s || n.children[0];
@@ -1515,14 +1480,14 @@ class vn {
1515
1480
  _chooseSplitIndex(e, n, o) {
1516
1481
  let i, r = 1 / 0, a = 1 / 0;
1517
1482
  for (let s = n; s <= o - n; s++) {
1518
- const u = G(e, 0, s, this.toBBox), f = G(e, s, o, this.toBBox), m = En(u, f), l = ft(u) + ft(f);
1483
+ const u = G(e, 0, s, this.toBBox), f = G(e, s, o, this.toBBox), m = Sn(u, f), l = ft(u) + ft(f);
1519
1484
  m < r ? (r = m, i = s, a = l < a ? l : a) : m === r && l < a && (a = l, i = s);
1520
1485
  }
1521
1486
  return i || o - n;
1522
1487
  }
1523
1488
  // sorts node children by the best axis for split
1524
1489
  _chooseSplitAxis(e, n, o) {
1525
- const i = e.leaf ? this.compareMinX : wn, r = e.leaf ? this.compareMinY : xn, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1490
+ const i = e.leaf ? this.compareMinX : xn, r = e.leaf ? this.compareMinY : An, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1526
1491
  a < s && e.children.sort(i);
1527
1492
  }
1528
1493
  // total margin of all possible split distributions where each node is at least m full
@@ -1549,12 +1514,10 @@ class vn {
1549
1514
  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);
1550
1515
  }
1551
1516
  }
1552
- function yn(t, e, n) {
1553
- if (!n)
1554
- return e.indexOf(t);
1517
+ function wn(t, e, n) {
1518
+ if (!n) return e.indexOf(t);
1555
1519
  for (let o = 0; o < e.length; o++)
1556
- if (n(t, e[o]))
1557
- return o;
1520
+ if (n(t, e[o])) return o;
1558
1521
  return -1;
1559
1522
  }
1560
1523
  function F(t, e) {
@@ -1571,10 +1534,10 @@ function G(t, e, n, o, i) {
1571
1534
  function K(t, e) {
1572
1535
  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;
1573
1536
  }
1574
- function wn(t, e) {
1537
+ function xn(t, e) {
1575
1538
  return t.minX - e.minX;
1576
1539
  }
1577
- function xn(t, e) {
1540
+ function An(t, e) {
1578
1541
  return t.minY - e.minY;
1579
1542
  }
1580
1543
  function ft(t) {
@@ -1583,10 +1546,10 @@ function ft(t) {
1583
1546
  function et(t) {
1584
1547
  return t.maxX - t.minX + (t.maxY - t.minY);
1585
1548
  }
1586
- function An(t, e) {
1549
+ function En(t, e) {
1587
1550
  return (Math.max(e.maxX, t.maxX) - Math.min(e.minX, t.minX)) * (Math.max(e.maxY, t.maxY) - Math.min(e.minY, t.minY));
1588
1551
  }
1589
- function En(t, e) {
1552
+ function Sn(t, e) {
1590
1553
  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);
1591
1554
  return Math.max(0, i - n) * Math.max(0, r - o);
1592
1555
  }
@@ -1607,31 +1570,30 @@ function W(t) {
1607
1570
  maxY: -1 / 0
1608
1571
  };
1609
1572
  }
1610
- function Dt(t, e, n, o, i) {
1573
+ function Ut(t, e, n, o, i) {
1611
1574
  const r = [e, n];
1612
1575
  for (; r.length; ) {
1613
- if (n = r.pop(), e = r.pop(), n - e <= o)
1614
- continue;
1576
+ if (n = r.pop(), e = r.pop(), n - e <= o) continue;
1615
1577
  const a = e + Math.ceil((n - e) / o / 2) * o;
1616
- mn(t, a, e, n, i), r.push(e, a, a, n);
1578
+ bn(t, a, e, n, i), r.push(e, a, a, n);
1617
1579
  }
1618
1580
  }
1619
- const Sn = (t, e) => {
1620
- const n = new vn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1621
- const y = d.selector.flatMap((C) => {
1622
- const N = C.range instanceof Range && !C.range.collapsed && C.range.startContainer.nodeType === Node.TEXT_NODE && C.range.endContainer.nodeType === Node.TEXT_NODE ? C.range : Xt(C, e).range;
1623
- return Array.from(N.getClientRects());
1624
- }), T = se(y).map(({ left: C, top: E, right: N, bottom: L }) => new DOMRect(C - c.left, E - c.top, N - C, L - E));
1625
- return T.map((C) => {
1626
- const { x: E, y: N, width: L, height: O } = C;
1581
+ const Cn = (t, e) => {
1582
+ const n = new yn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1583
+ const y = d.selector.flatMap((L) => {
1584
+ const E = $([L]) ? L.range : Dt(L, e).range;
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: O } = L;
1627
1589
  return {
1628
1590
  minX: E,
1629
- minY: N,
1630
- maxX: E + L,
1631
- maxY: N + O,
1591
+ minY: B,
1592
+ maxX: E + T,
1593
+ maxY: B + O,
1632
1594
  annotation: {
1633
1595
  id: d.annotation,
1634
- rects: T
1596
+ rects: C
1635
1597
  }
1636
1598
  };
1637
1599
  });
@@ -1647,29 +1609,29 @@ const Sn = (t, e) => {
1647
1609
  u(d), s(d);
1648
1610
  }, m = (d, c = !0) => {
1649
1611
  c && a();
1650
- const y = e.getBoundingClientRect(), T = d.map((E) => ({ target: E, rects: i(E, y) }));
1651
- T.forEach(({ target: E, rects: N }) => o.set(E.annotation, N));
1652
- const C = T.reduce((E, { rects: N }) => [...E, ...N], []);
1653
- n.load(C);
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);
1615
+ n.load(L);
1654
1616
  }, l = (d, c) => {
1655
1617
  const y = n.search({
1656
1618
  minX: d,
1657
1619
  minY: c,
1658
1620
  maxX: d,
1659
1621
  maxY: c
1660
- }), T = (C) => C.annotation.rects.reduce((E, N) => E + N.width * N.height, 0);
1622
+ }), C = (L) => L.annotation.rects.reduce((E, B) => E + B.width * B.height, 0);
1661
1623
  if (y.length > 0)
1662
- return y.sort((C, E) => T(C) - T(E)), y[0].annotation.id;
1624
+ return y.sort((L, E) => C(L) - C(E)), y[0].annotation.id;
1663
1625
  }, p = (d) => {
1664
1626
  const c = g(d);
1665
1627
  if (c.length === 0)
1666
1628
  return;
1667
- let y = c[0].left, T = c[0].top, C = c[0].right, E = c[0].bottom;
1668
- for (let N = 1; N < c.length; N++) {
1669
- const L = c[N];
1670
- y = Math.min(y, L.left), T = Math.min(T, L.top), C = Math.max(C, L.right), E = Math.max(E, L.bottom);
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);
1671
1633
  }
1672
- return new DOMRect(y, T, C - y, E - T);
1634
+ return new DOMRect(y, C, L - y, E - C);
1673
1635
  }, g = (d) => {
1674
1636
  const c = o.get(d);
1675
1637
  return c ? c[0].annotation.rects : [];
@@ -1680,12 +1642,12 @@ const Sn = (t, e) => {
1680
1642
  getAt: l,
1681
1643
  getAnnotationBounds: p,
1682
1644
  getAnnotationRects: g,
1683
- getIntersecting: (d, c, y, T) => {
1684
- const C = n.search({ minX: d, minY: c, maxX: y, maxY: T }), E = new Set(C.reduce((N, L) => [...N, L.annotation.id], []));
1685
- return Array.from(E).map((N) => ({
1686
- annotation: t.getAnnotation(N),
1687
- rects: g(N)
1688
- })).filter((N) => !!N.annotation);
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: g(B)
1650
+ })).filter((B) => !!B.annotation);
1689
1651
  },
1690
1652
  insert: s,
1691
1653
  recalculate: () => m(t.all().map((d) => d.target), !0),
@@ -1694,22 +1656,22 @@ const Sn = (t, e) => {
1694
1656
  size: () => n.all().length,
1695
1657
  update: f
1696
1658
  };
1697
- }, Cn = (t, e) => {
1698
- const n = je(), o = Sn(n, t), i = De(n, e), r = Ie(n), a = Je(), s = (v, h = B.LOCAL) => {
1659
+ }, Ln = (t, e) => {
1660
+ const n = Ge(), o = Cn(n, t), i = ke(n, e), r = Ve(n), a = Ze(), s = (v, h = N.LOCAL) => {
1699
1661
  const d = rt(v, t), c = $(d.target.selector);
1700
1662
  return c && n.addAnnotation(d, h), c;
1701
- }, u = (v, h = !0, d = B.LOCAL) => {
1702
- const c = v.map((T) => rt(T, t)), y = c.filter((T) => !$(T.target.selector));
1663
+ }, u = (v, h = !0, d = N.LOCAL) => {
1664
+ const c = v.map((C) => rt(C, t)), y = c.filter((C) => !$(C.target.selector));
1703
1665
  return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(c, h, d), y) : (n.bulkAddAnnotation(c, h, d), []);
1704
- }, f = (v, h = B.LOCAL) => {
1666
+ }, f = (v, h = N.LOCAL) => {
1705
1667
  const d = v.map((y) => rt(y, t)), c = d.filter((y) => !$(y.target.selector));
1706
1668
  return c.length > 0 && console.warn("Could not revive all targets for these annotations:", c), d.forEach((y) => {
1707
1669
  n.getAnnotation(y.id) ? n.updateAnnotation(y, h) : n.addAnnotation(y, h);
1708
1670
  }), c;
1709
- }, m = (v, h = B.LOCAL) => {
1671
+ }, m = (v, h = N.LOCAL) => {
1710
1672
  const d = it(v, t);
1711
1673
  n.updateTarget(d, h);
1712
- }, l = (v, h = B.LOCAL) => {
1674
+ }, l = (v, h = N.LOCAL) => {
1713
1675
  const d = v.map((c) => it(c, t));
1714
1676
  n.bulkUpdateTargets(d, h);
1715
1677
  }, p = (v, h) => {
@@ -1719,16 +1681,15 @@ const Sn = (t, e) => {
1719
1681
  const y = o.getAnnotationRects(v);
1720
1682
  if (y.length !== 0) {
1721
1683
  if (h && d) {
1722
- const T = y.find(({ top: C, right: E, bottom: N, left: L }) => h >= L - c && h <= E + c && d >= C - c && d <= N + c);
1723
- if (T)
1724
- return T;
1684
+ const C = y.find(({ top: L, right: E, bottom: B, left: T }) => h >= T - c && h <= E + c && d >= L - c && d <= B + c);
1685
+ if (C) return C;
1725
1686
  }
1726
1687
  return o.getAnnotationBounds(v);
1727
1688
  }
1728
- }, x = () => o.recalculate();
1689
+ }, w = () => o.recalculate();
1729
1690
  return n.observe(({ changes: v }) => {
1730
- const h = (v.created || []).filter((y) => $(y.target.selector)), d = (v.deleted || []).filter((y) => $(y.target.selector)), c = (v.updated || []).filter((y) => $(y.newValue.target.selector));
1731
- h.length > 0 && o.set(h.map((y) => y.target), !1), (d == null ? void 0 : d.length) > 0 && d.forEach((y) => o.remove(y.target)), (c == null ? void 0 : c.length) > 0 && c.forEach(({ newValue: y }) => o.update(y.target));
1691
+ const h = (v.deleted || []).filter((y) => $(y.target.selector)), d = (v.created || []).filter((y) => $(y.target.selector)), c = (v.updated || []).filter((y) => $(y.newValue.target.selector));
1692
+ (h == null ? void 0 : h.length) > 0 && h.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));
1732
1693
  }), {
1733
1694
  store: {
1734
1695
  ...n,
@@ -1739,24 +1700,24 @@ const Sn = (t, e) => {
1739
1700
  getAnnotationBounds: g,
1740
1701
  getAt: p,
1741
1702
  getIntersecting: o.getIntersecting,
1742
- recalculatePositions: x,
1703
+ recalculatePositions: w,
1743
1704
  updateTarget: m
1744
1705
  },
1745
1706
  selection: i,
1746
1707
  hover: r,
1747
1708
  viewport: a
1748
1709
  };
1749
- }, Tn = () => {
1710
+ }, Bn = () => {
1750
1711
  const t = document.createElement("canvas");
1751
1712
  t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-highlight-layer presence";
1752
1713
  const e = t.getContext("2d");
1753
1714
  return e.scale(2, 2), e.translate(0.5, 0.5), t;
1754
- }, Nn = (t, e, n = {}) => {
1755
- const o = Tn(), i = o.getContext("2d");
1715
+ }, Tn = (t, e, n = {}) => {
1716
+ const o = Bn(), i = o.getContext("2d");
1756
1717
  t.appendChild(o);
1757
1718
  const r = /* @__PURE__ */ new Map(), a = (l) => Array.from(r.entries()).filter(([p, g]) => g.presenceKey === l.presenceKey).map(([p, g]) => p);
1758
1719
  return e.on("selectionChange", (l, p) => {
1759
- a(l).forEach((x) => r.delete(x)), p && p.forEach((x) => r.set(x, l));
1720
+ a(l).forEach((w) => r.delete(w)), p && p.forEach((w) => r.set(w, l));
1760
1721
  }), {
1761
1722
  clear: () => {
1762
1723
  const { width: l, height: p } = o;
@@ -1767,13 +1728,13 @@ const Sn = (t, e) => {
1767
1728
  },
1768
1729
  paint: (l, p, g) => {
1769
1730
  n.font && (i.font = n.font);
1770
- const x = r.get(l.annotation.id);
1771
- if (x) {
1731
+ const w = r.get(l.annotation.id);
1732
+ if (w) {
1772
1733
  const { height: v } = l.rects[0], h = l.rects[0].x + p.left, d = l.rects[0].y + p.top;
1773
- i.fillStyle = x.appearance.color, i.fillRect(h - 2, d - 2.5, 2, v + 5);
1774
- const c = i.measureText(x.appearance.label), y = c.width + 6, T = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, C = c.fontBoundingBoxAscent ? 8 : 6.5;
1775
- return i.fillRect(h - 2, d - 2.5 - T, y, T), i.fillStyle = "#fff", i.fillText(x.appearance.label, h + 1, d - C), {
1776
- fill: x.appearance.color,
1734
+ i.fillStyle = w.appearance.color, i.fillRect(h - 2, d - 2.5, 2, v + 5);
1735
+ const c = i.measureText(w.appearance.label), y = c.width + 6, C = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, L = c.fontBoundingBoxAscent ? 8 : 6.5;
1736
+ return i.fillRect(h - 2, d - 2.5 - C, y, C), i.fillStyle = "#fff", i.fillText(w.appearance.label, h + 1, d - L), {
1737
+ fill: w.appearance.color,
1777
1738
  fillOpacity: g ? 0.45 : 0.18
1778
1739
  };
1779
1740
  }
@@ -1789,9 +1750,9 @@ const Sn = (t, e) => {
1789
1750
  return document.scrollingElement;
1790
1751
  const { overflowY: e } = window.getComputedStyle(t);
1791
1752
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Wt(t.parentElement);
1792
- }, Ln = (t, e) => (n) => {
1753
+ }, Rn = (t, e) => (n) => {
1793
1754
  const o = typeof n == "string" ? n : n.id, i = (a) => {
1794
- const s = r.getBoundingClientRect(), u = r.clientHeight, f = r.clientWidth, m = a.selector[0].range.getBoundingClientRect(), { width: l, height: p } = e.getAnnotationBounds(o), g = m.top - s.top, x = m.left - s.left, v = r.parentElement ? r.scrollTop : 0, h = r.parentElement ? r.scrollLeft : 0, d = g + v - (u - p) / 2, c = x + h - (f - l) / 2;
1755
+ const s = r.getBoundingClientRect(), u = r.clientHeight, f = r.clientWidth, m = a.selector[0].range.getBoundingClientRect(), { width: l, height: p } = e.getAnnotationBounds(o), g = m.top - s.top, w = m.left - s.left, v = r.parentElement ? r.scrollTop : 0, h = r.parentElement ? r.scrollLeft : 0, d = g + v - (u - p) / 2, c = w + h - (f - l) / 2;
1795
1756
  r.scroll({ top: d, left: c, behavior: "smooth" });
1796
1757
  }, r = Wt(t);
1797
1758
  if (r) {
@@ -1805,20 +1766,19 @@ const Sn = (t, e) => {
1805
1766
  }
1806
1767
  }
1807
1768
  return !1;
1808
- }, Rn = (t, e) => ({
1769
+ }, Nn = (t, e) => ({
1809
1770
  ...t,
1810
1771
  annotationEnabled: t.annotationEnabled === void 0 ? e.annotationEnabled : t.annotationEnabled
1811
- }), Bn = (t, e, n, o) => {
1772
+ }), Mn = (t, e, n, o) => {
1812
1773
  const { store: i, selection: r } = e;
1813
1774
  let a, s;
1814
1775
  const u = (h) => a = h;
1815
1776
  let f = !1, m;
1816
1777
  const l = (h) => {
1817
1778
  var c;
1818
- if (!f)
1819
- return;
1820
- !((c = h.target.parentElement) != null && c.closest(X)) ? s = {
1821
- annotation: $t(),
1779
+ if (!f) return;
1780
+ !((c = h.target.parentElement) != null && c.closest(D)) ? s = {
1781
+ annotation: Ht(),
1822
1782
  selector: [],
1823
1783
  creator: a,
1824
1784
  created: /* @__PURE__ */ new Date()
@@ -1826,23 +1786,24 @@ const Sn = (t, e) => {
1826
1786
  };
1827
1787
  n && t.addEventListener("selectstart", l);
1828
1788
  const p = bt((h) => {
1829
- var N, L;
1789
+ var E, B;
1830
1790
  const d = document.getSelection();
1831
- if (!!((L = (N = d.anchorNode) == null ? void 0 : N.parentElement) != null && L.closest(X))) {
1791
+ if (!!((B = (E = d.anchorNode) == null ? void 0 : E.parentElement) != null && B.closest(D))) {
1832
1792
  s = void 0;
1833
1793
  return;
1834
1794
  }
1835
- if (h.timeStamp - ((m == null ? void 0 : m.timeStamp) || h.timeStamp) < 1e3 && !s && l(m), d.isCollapsed || !f || !s)
1836
- return;
1837
- const y = d.getRangeAt(0), T = ce(y.cloneRange()), C = Zt(T);
1838
- (C.length !== s.selector.length || C.some((O, b) => {
1839
- var w;
1840
- return O.toString() !== ((w = s.selector[b]) == null ? void 0 : w.quote);
1795
+ if (h.timeStamp - ((m == null ? void 0 : m.timeStamp) || h.timeStamp) < 1e3 && !s && l(m), d.isCollapsed || !f || !s) return;
1796
+ const y = d.getRangeAt(0);
1797
+ if (re(y)) return;
1798
+ const C = Zt(y.cloneRange());
1799
+ (C.length !== s.selector.length || C.some((T, O) => {
1800
+ var b;
1801
+ return T.toString() !== ((b = s.selector[O]) == null ? void 0 : b.quote);
1841
1802
  })) && (s = {
1842
1803
  ...s,
1843
- selector: C.map((O) => ae(O, t, o)),
1804
+ selector: C.map((T) => le(T, t, o)),
1844
1805
  updated: /* @__PURE__ */ new Date()
1845
- }, i.getAnnotation(s.annotation) ? i.updateTarget(s, B.LOCAL) : (i.addAnnotation({
1806
+ }, i.getAnnotation(s.annotation) ? i.updateTarget(s, N.LOCAL) : (r.clear(), i.addAnnotation({
1846
1807
  id: s.annotation,
1847
1808
  bodies: [],
1848
1809
  target: s
@@ -1850,43 +1811,42 @@ const Sn = (t, e) => {
1850
1811
  });
1851
1812
  n && document.addEventListener("selectionchange", p);
1852
1813
  const g = (h) => {
1853
- const { target: d, timeStamp: c, offsetX: y, offsetY: T, type: C } = h;
1854
- m = { ...h, target: d, timeStamp: c, offsetX: y, offsetY: T, type: C }, f = h.button === 0;
1814
+ const { target: d, timeStamp: c, offsetX: y, offsetY: C, type: L } = h;
1815
+ m = { ...h, target: d, timeStamp: c, offsetX: y, offsetY: C, type: L }, f = h.button === 0;
1855
1816
  };
1856
1817
  t.addEventListener("pointerdown", g);
1857
- const x = (h) => {
1858
- var T;
1859
- if (!!((T = h.target.parentElement) != null && T.closest(X)) || !f)
1818
+ const w = (h) => {
1819
+ var C;
1820
+ if (!!((C = h.target.parentElement) != null && C.closest(D)) || !f)
1860
1821
  return;
1861
1822
  const c = () => {
1862
- const { x: C, y: E } = t.getBoundingClientRect(), N = i.getAt(h.clientX - C, h.clientY - E);
1863
- if (N) {
1864
- const { selected: L } = r;
1865
- (L.length !== 1 || L[0].id !== N.id) && r.clickSelect(N.id, h);
1866
- } else
1867
- r.isEmpty() || r.clear();
1823
+ const { x: L, y: E } = t.getBoundingClientRect(), B = i.getAt(h.clientX - L, h.clientY - E);
1824
+ if (B) {
1825
+ const { selected: T } = r;
1826
+ (T.length !== 1 || T[0].id !== B.id) && r.clickSelect(B.id, h);
1827
+ } else r.isEmpty() || r.clear();
1868
1828
  }, y = h.timeStamp - m.timeStamp;
1869
1829
  document.getSelection().isCollapsed && y < 300 ? (s = void 0, c()) : s && r.clickSelect(s.annotation, h);
1870
1830
  };
1871
- return document.addEventListener("pointerup", x), {
1831
+ return document.addEventListener("pointerup", w), {
1872
1832
  destroy: () => {
1873
- t.removeEventListener("selectstart", l), document.removeEventListener("selectionchange", p), t.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", x);
1833
+ t.removeEventListener("selectstart", l), document.removeEventListener("selectionchange", p), t.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", w);
1874
1834
  },
1875
1835
  setUser: u
1876
1836
  };
1877
- }, Ut = "SPANS", Dn = (t, e = {}) => {
1837
+ }, kt = "SPANS", kn = (t, e = {}) => {
1878
1838
  te(t);
1879
- const n = Rn(e, {
1839
+ const n = Nn(e, {
1880
1840
  annotationEnabled: !0
1881
- }), o = Cn(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Qe(a), u = Ze(o, s, n.adapter);
1882
- let f = cn();
1883
- const m = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Ut : n.renderer || Ut, l = m === "SPANS" ? Ne(t, o, r) : m === "CSS_HIGHLIGHTS" ? Se(t, o, r) : m === "CANVAS" ? ge(t, o, r) : void 0;
1841
+ }), o = Ln(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Je(a), u = tn(o, s, n.adapter);
1842
+ let f = ln();
1843
+ 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;
1884
1844
  if (!l)
1885
1845
  throw `Unknown renderer implementation: ${m}`;
1886
1846
  console.debug(`Using ${m} renderer`), n.style && l.setStyle(n.style);
1887
- const p = Bn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1847
+ const p = Mn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1888
1848
  return p.setUser(f), {
1889
- ...en(o, s, n.adapter),
1849
+ ...nn(o, s, n.adapter),
1890
1850
  destroy: () => {
1891
1851
  l.destroy(), p.destroy(), s.destroy();
1892
1852
  },
@@ -1901,47 +1861,48 @@ const Sn = (t, e) => {
1901
1861
  E ? i.setSelected(E) : i.clear();
1902
1862
  },
1903
1863
  setPresenceProvider: (E) => {
1904
- E && (l.setPainter(Nn(t, E, n.presence)), E.on("selectionChange", () => l.redraw()));
1864
+ E && (l.setPainter(Tn(t, E, n.presence)), E.on("selectionChange", () => l.redraw()));
1905
1865
  },
1906
1866
  setVisible: (E) => l.setVisible(E),
1907
1867
  on: u.on,
1908
1868
  off: u.off,
1909
- scrollIntoView: Ln(t, a),
1869
+ scrollIntoView: Rn(t, a),
1910
1870
  state: o
1911
1871
  };
1912
1872
  };
1913
1873
  export {
1914
1874
  ot as DEFAULT_SELECTED_STYLE,
1915
1875
  P as DEFAULT_STYLE,
1916
- _t as NOT_ANNOTATABLE_CLASS,
1917
- X as NOT_ANNOTATABLE_SELECTOR,
1918
- B as Origin,
1919
- Ve as PointerSelectAction,
1920
- Vn as W3CTextFormat,
1876
+ Yt as NOT_ANNOTATABLE_CLASS,
1877
+ D as NOT_ANNOTATABLE_SELECTOR,
1878
+ N as Origin,
1879
+ Ue as PointerSelectAction,
1880
+ Un as W3CTextFormat,
1921
1881
  te as cancelSingleClickEvents,
1922
- In as createBody,
1923
- ge as createCanvasRenderer,
1924
- Se as createHighlightsRenderer,
1925
- Ee as createRenderer,
1926
- Ne as createSpansRenderer,
1927
- Dn as createTextAnnotator,
1928
- Cn as createTextAnnotatorState,
1882
+ Vn as createBody,
1883
+ pe as createCanvasRenderer,
1884
+ Ce as createHighlightsRenderer,
1885
+ Se as createRenderer,
1886
+ Te as createSpansRenderer,
1887
+ kn as createTextAnnotator,
1888
+ Ln as createTextAnnotatorState,
1929
1889
  bt as debounce,
1930
- Rn as fillDefaults,
1890
+ Nn as fillDefaults,
1931
1891
  On as getAnnotatableFragment,
1932
- Mn as getClientRectsPonyfill,
1892
+ In as getClientRectsPonyfill,
1933
1893
  oe as getQuoteContext,
1934
1894
  pt as getRangeAnnotatableContents,
1935
1895
  $ as isRevived,
1936
- se as mergeClientRects,
1896
+ re as isWhitespaceOrEmpty,
1897
+ ce as mergeClientRects,
1937
1898
  Kt as paint,
1938
- gn as parseW3CTextAnnotation,
1939
- ae as rangeToSelector,
1899
+ pn as parseW3CTextAnnotation,
1900
+ le as rangeToSelector,
1940
1901
  rt as reviveAnnotation,
1941
- Xt as reviveSelector,
1902
+ Dt as reviveSelector,
1942
1903
  it as reviveTarget,
1943
- pn as serializeW3CTextAnnotation,
1904
+ mn as serializeW3CTextAnnotation,
1944
1905
  Zt as splitAnnotatableRanges,
1945
- ce as trimRange
1906
+ ie as whitespaceOrEmptyRegex
1946
1907
  };
1947
1908
  //# sourceMappingURL=text-annotator.es.js.map