@recogito/text-annotator 3.0.0-rc.24 → 3.0.0-rc.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const Y = {
1
+ const H = {
2
2
  fill: "rgb(0, 128, 255)",
3
3
  fillOpacity: 0.18
4
4
  }, et = {
@@ -6,22 +6,17 @@ const Y = {
6
6
  fillOpacity: 0.45
7
7
  }, qt = (t, e, n, o, i) => {
8
8
  var a, s;
9
- const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? et : Y) : n : (s = t.state) != null && s.selected ? et : Y;
9
+ const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? et : H) : n : (s = t.state) != null && s.selected ? et : H;
10
10
  return o && o.paint(t, e) || r;
11
- }, ft = (t, e = 10) => {
12
- let n;
13
- return (...o) => {
14
- clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
15
- };
16
- }, It = "not-annotatable", H = `.${It}`, jt = (t) => {
11
+ }, It = "not-annotatable", k = `.${It}`, jt = (t) => {
17
12
  var n;
18
13
  const e = t.commonAncestorContainer;
19
- return e instanceof HTMLElement ? !e.closest(H) : !((n = e.parentElement) != null && n.closest(H));
14
+ return e instanceof HTMLElement ? !e.closest(k) : !((n = e.parentElement) != null && n.closest(k));
20
15
  }, Gt = function* (t) {
21
16
  const e = document.createNodeIterator(
22
17
  t.commonAncestorContainer,
23
18
  NodeFilter.SHOW_ELEMENT,
24
- (o) => o instanceof HTMLElement && o.classList.contains(It) && !o.parentElement.closest(H) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
19
+ (o) => o instanceof HTMLElement && o.classList.contains(It) && !o.parentElement.closest(k) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
25
20
  );
26
21
  let n;
27
22
  for (; n = e.nextNode(); )
@@ -42,10 +37,20 @@ const Y = {
42
37
  return e.length > 0 ? e : [t];
43
38
  }, ut = (t) => {
44
39
  const e = t.cloneContents();
45
- return e.querySelectorAll(H).forEach((n) => n.remove()), e;
46
- }, Nn = (t) => {
40
+ return e.querySelectorAll(k).forEach((n) => n.remove()), e;
41
+ }, Qt = (t) => {
42
+ t.addEventListener("click", (e) => {
43
+ // Allow clicks within not-annotatable elements
44
+ !e.target.closest(k) && !e.target.closest("a") && e.preventDefault();
45
+ });
46
+ }, ft = (t, e = 10) => {
47
+ let n;
48
+ return (...o) => {
49
+ clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
50
+ };
51
+ }, Ln = (t) => {
47
52
  const e = t.cloneContents();
48
- return e.querySelectorAll(H).forEach((n) => n.remove()), e;
53
+ return e.querySelectorAll(k).forEach((n) => n.remove()), e;
49
54
  }, mt = (t, e) => {
50
55
  const n = document.createNodeIterator(e);
51
56
  let o = 0, i = n.nextNode();
@@ -60,40 +65,40 @@ const Y = {
60
65
  for (let i = 0; i < t + 1; i++)
61
66
  o = n.nextNode();
62
67
  return o;
63
- }, Qt = (t) => {
68
+ }, Jt = (t) => {
64
69
  const {
65
70
  commonAncestorContainer: e,
66
71
  startContainer: n,
67
72
  startOffset: o,
68
73
  endContainer: i,
69
74
  endOffset: r
70
- } = t, a = Array.from(e.childNodes).map((c) => {
71
- const m = c.cloneNode(!0);
72
- return c.nodeName === "CANVAS" ? c : m;
75
+ } = t, a = Array.from(e.childNodes).map((l) => {
76
+ const m = l.cloneNode(!0);
77
+ return l.nodeName === "CANVAS" ? l : m;
73
78
  }), s = mt(n, e), u = mt(i, e), f = () => {
74
- const c = e;
75
- c.replaceChildren(...a);
76
- const m = bt(s, c), p = bt(u, c);
79
+ const l = e;
80
+ l.replaceChildren(...a);
81
+ const m = bt(s, l), p = bt(u, l);
77
82
  return t.setStart(m, o), t.setEnd(p, r), t;
78
- }, b = (c) => {
83
+ }, b = (l) => {
79
84
  const m = document.createElement("SPAN");
80
- return c.surroundContents(m), m;
85
+ return l.surroundContents(m), m;
81
86
  };
82
87
  if (n === i)
83
88
  throw "Not implemented";
84
89
  {
85
- const c = document.createRange();
86
- c.selectNodeContents(n), c.setStart(n, o);
87
- const m = b(c), p = document.createRange();
90
+ const l = document.createRange();
91
+ l.selectNodeContents(n), l.setStart(n, o);
92
+ const m = b(l), p = document.createRange();
88
93
  p.selectNode(i), p.setEnd(i, r);
89
- const w = b(p), h = Jt(t).reverse().map((d) => {
94
+ const w = b(p), h = Zt(t).reverse().map((d) => {
90
95
  var y;
91
- const l = document.createElement("SPAN");
92
- return (y = d.parentNode) == null || y.insertBefore(l, d), l.appendChild(d), l;
96
+ const c = document.createElement("SPAN");
97
+ return (y = d.parentNode) == null || y.insertBefore(c, d), c.appendChild(d), c;
93
98
  });
94
99
  return { unwrap: f, nodes: [m, ...h, w] };
95
100
  }
96
- }, Jt = (t) => {
101
+ }, Zt = (t) => {
97
102
  const {
98
103
  commonAncestorContainer: e,
99
104
  startContainer: n,
@@ -104,15 +109,15 @@ const Y = {
104
109
  for (; r != null; )
105
110
  r === o && (a = !1), a && s.push(r), r === n && (a = !0), r = i.nextNode();
106
111
  return s;
107
- }, Ln = (t) => {
112
+ }, Bn = (t) => {
108
113
  const { startContainer: e, endContainer: n } = t;
109
114
  if (e === n)
110
115
  return Array.from(t.getClientRects());
111
116
  {
112
- const { unwrap: o, nodes: i } = Qt(t), r = i.reduce((a, s) => [...a, ...s.getClientRects()], []);
117
+ const { unwrap: o, nodes: i } = Jt(t), r = i.reduce((a, s) => [...a, ...s.getClientRects()], []);
113
118
  return o(), r;
114
119
  }
115
- }, Zt = (t, e, n = 10, o) => {
120
+ }, te = (t, e, n = 10, o) => {
116
121
  const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
117
122
  r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
118
123
  const a = ut(r).textContent, s = document.createRange();
@@ -122,7 +127,7 @@ const Y = {
122
127
  prefix: a.substring(a.length - n),
123
128
  suffix: u.substring(0, n)
124
129
  };
125
- }, k = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), te = (t, e) => {
130
+ }, Y = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ee = (t, e) => {
126
131
  const n = (r) => Math.round(r * 10) / 10, o = {
127
132
  top: n(t.top),
128
133
  bottom: n(t.bottom),
@@ -146,17 +151,17 @@ const Y = {
146
151
  return "block-contains";
147
152
  } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
148
153
  return "block-is-contained";
149
- }, ee = (t, e) => {
154
+ }, ne = (t, e) => {
150
155
  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);
151
156
  return new DOMRect(n, i, o - n, r - i);
152
- }, ne = (t) => t.reduce((e, n) => {
157
+ }, oe = (t) => t.reduce((e, n) => {
153
158
  if (n.width === 0 || n.height === 0)
154
159
  return e;
155
160
  let o = [...e], i = !1;
156
161
  for (const r of e) {
157
- const a = te(n, r);
162
+ const a = ee(n, r);
158
163
  if (a === "inline-adjacent") {
159
- o = o.map((s) => s === r ? ee(n, r) : s), i = !0;
164
+ o = o.map((s) => s === r ? ne(n, r) : s), i = !0;
160
165
  break;
161
166
  } else if (a === "inline-contains") {
162
167
  o = o.map((s) => s === r ? n : s), i = !0;
@@ -170,19 +175,19 @@ const Y = {
170
175
  }
171
176
  }
172
177
  return i ? o : [...o, n];
173
- }, []), oe = (t, e, n) => {
178
+ }, []), ie = (t, e, n) => {
174
179
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
175
180
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
176
181
  const r = ut(o).textContent, a = t.toString(), s = r.length || 0, u = s + a.length;
177
182
  return n ? { quote: a, start: s, end: u, range: t, offsetReference: i } : { quote: a, start: s, end: u, range: t };
178
183
  }, Mt = (t, e) => {
179
- var b, c;
184
+ var b, l;
180
185
  const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
181
186
  e,
182
187
  NodeFilter.SHOW_TEXT,
183
188
  (m) => {
184
189
  var p;
185
- return (p = m.parentElement) != null && p.closest(H) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
190
+ return (p = m.parentElement) != null && p.closest(k) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
186
191
  }
187
192
  );
188
193
  let a = 0;
@@ -202,7 +207,7 @@ const Y = {
202
207
  u = r.nextNode();
203
208
  }
204
209
  for (; u !== null; ) {
205
- const m = ((c = u.textContent) == null ? void 0 : c.length) || 0;
210
+ const m = ((l = u.textContent) == null ? void 0 : l.length) || 0;
206
211
  if (a + m >= o) {
207
212
  s.setEnd(u, o - a);
208
213
  break;
@@ -213,10 +218,10 @@ const Y = {
213
218
  ...t,
214
219
  range: s
215
220
  };
216
- }, nt = (t, e) => k(t.selector) ? t : {
221
+ }, nt = (t, e) => Y(t.selector) ? t : {
217
222
  ...t,
218
223
  selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Mt(n, e))
219
- }, ot = (t, e) => k(t.target.selector) ? t : { ...t, target: nt(t.target, e) }, ie = (t) => {
224
+ }, ot = (t, e) => Y(t.target.selector) ? t : { ...t, target: nt(t.target, e) }, re = (t) => {
220
225
  var i;
221
226
  const { startContainer: e, endContainer: n } = t;
222
227
  if (e.nodeType === Node.TEXT_NODE && n.nodeType === Node.TEXT_NODE)
@@ -230,10 +235,10 @@ const Y = {
230
235
  t.setEnd(a, ((i = a == null ? void 0 : a.textContent) == null ? void 0 : i.length) || 0);
231
236
  }
232
237
  return t;
233
- }, re = (t) => {
238
+ }, se = (t) => {
234
239
  const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, u = i - e;
235
240
  return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: u };
236
- }, se = (t) => {
241
+ }, ae = (t) => {
237
242
  let e = /* @__PURE__ */ new Set();
238
243
  return (o) => {
239
244
  const i = o.map((r) => r.id);
@@ -242,14 +247,14 @@ const Y = {
242
247
  }, pt = (t, e, n, o) => {
243
248
  const { store: i, selection: r, hover: a } = e;
244
249
  let s, u, f;
245
- const b = se(n), c = (g) => {
250
+ const b = ae(n), l = (g) => {
246
251
  const { x: A, y: x } = t.getBoundingClientRect(), S = i.getAt(g.clientX - A, g.clientY - x);
247
252
  S && (!u || u(S)) ? a.current !== S.id && (t.classList.add("hovered"), a.set(S.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
248
253
  };
249
- t.addEventListener("pointermove", c);
254
+ t.addEventListener("pointermove", l);
250
255
  const m = (g = !1) => {
251
256
  f && f.clear();
252
- const A = re(t), { minX: x, minY: S, maxX: N, maxY: B } = A, _ = u ? i.getIntersecting(x, S, N, B).filter(({ annotation: X }) => u(X)) : i.getIntersecting(x, S, N, B), $t = r.selected.map(({ id: X }) => X), Pt = _.map(({ annotation: X, rects: zt }) => {
257
+ const A = se(t), { minX: x, minY: S, maxX: N, maxY: B } = A, _ = u ? i.getIntersecting(x, S, N, B).filter(({ annotation: X }) => u(X)) : i.getIntersecting(x, S, N, B), $t = r.selected.map(({ id: X }) => X), Pt = _.map(({ annotation: X, rects: zt }) => {
253
258
  const Ft = $t.includes(X.id), Wt = X.id === a.current;
254
259
  return { annotation: X, rects: zt, state: { selected: Ft, hover: Wt, custom: {} } };
255
260
  });
@@ -262,8 +267,8 @@ const Y = {
262
267
  u = g, m(!1);
263
268
  }, h = () => m();
264
269
  i.observe(h);
265
- const d = r.subscribe(() => m()), l = () => m(!0);
266
- document.addEventListener("scroll", l, { capture: !0, passive: !0 });
270
+ const d = r.subscribe(() => m()), c = () => m(!0);
271
+ document.addEventListener("scroll", c, { capture: !0, passive: !0 });
267
272
  const y = ft(() => {
268
273
  i.recalculatePositions(), f && f.reset(), m();
269
274
  });
@@ -275,7 +280,7 @@ const Y = {
275
280
  });
276
281
  return E.observe(document.body, C), {
277
282
  destroy: () => {
278
- t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", l), window.removeEventListener("resize", y), T.disconnect(), E.disconnect();
283
+ t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", y), T.disconnect(), E.disconnect();
279
284
  },
280
285
  redraw: m,
281
286
  setStyle: w,
@@ -283,22 +288,22 @@ const Y = {
283
288
  setPainter: p,
284
289
  setVisible: o.setVisible
285
290
  };
286
- }, ae = () => {
291
+ }, le = () => {
287
292
  const t = document.createElement("canvas");
288
293
  return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-highlight-layer bg", t;
289
294
  }, ce = (t, e) => {
290
295
  t.width = window.innerWidth, t.height = window.innerHeight;
291
- }, le = (t) => {
296
+ }, de = (t) => {
292
297
  t.classList.add("r6o-annotatable");
293
- const e = ae(), n = e.getContext("2d");
298
+ const e = le(), n = e.getContext("2d");
294
299
  t.insertBefore(e, t.firstChild);
295
300
  const o = (s, u, f, b) => requestAnimationFrame(() => {
296
- const { width: c, height: m } = e;
297
- n.clearRect(-0.5, -0.5, c + 1, m + 1), b && b.clear();
301
+ const { width: l, height: m } = e;
302
+ n.clearRect(-0.5, -0.5, l + 1, m + 1), b && b.clear();
298
303
  const { top: p, left: w } = u;
299
304
  s.forEach((v) => {
300
305
  var T;
301
- const h = f ? typeof f == "function" ? f(v.annotation, v.state) : f : (T = v.state) != null && T.selected ? et : Y, d = b && b.paint(v, u) || h, l = v.rects.map(({ x: C, y: E, width: R, height: g }) => ({
306
+ const h = f ? typeof f == "function" ? f(v.annotation, v.state) : f : (T = v.state) != null && T.selected ? et : H, d = b && b.paint(v, u) || h, c = v.rects.map(({ x: C, y: E, width: R, height: g }) => ({
302
307
  x: C + w,
303
308
  y: E + p,
304
309
  width: R,
@@ -306,7 +311,7 @@ const Y = {
306
311
  }));
307
312
  n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1;
308
313
  const y = 5;
309
- if (l.forEach(
314
+ if (c.forEach(
310
315
  ({ x: C, y: E, width: R, height: g }) => n.fillRect(
311
316
  C,
312
317
  E - y / 2,
@@ -316,7 +321,7 @@ const Y = {
316
321
  ), d.underlineColor) {
317
322
  n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
318
323
  const C = y / 2 + (d.underlineOffset ?? 0);
319
- l.forEach(({ x: E, y: R, width: g, height: A }) => {
324
+ c.forEach(({ x: E, y: R, width: g, height: A }) => {
320
325
  n.beginPath(), n.moveTo(E, R + A + C), n.lineTo(E + g, R + A + C), n.stroke();
321
326
  });
322
327
  }
@@ -333,8 +338,8 @@ const Y = {
333
338
  },
334
339
  redraw: o
335
340
  };
336
- }, de = (t, e, n) => pt(t, e, n, le(t));
337
- var ue = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
341
+ }, ue = (t, e, n) => pt(t, e, n, de(t));
342
+ var he = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
338
343
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
339
344
  }, O = function(t, e, n) {
340
345
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
@@ -346,7 +351,7 @@ var ue = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
346
351
  return { r: U(t.r, 0, 255), g: U(t.g, 0, 255), b: U(t.b, 0, 255), a: U(t.a) };
347
352
  }, it = function(t) {
348
353
  return { r: O(t.r), g: O(t.g), b: O(t.b), a: O(t.a, 3) };
349
- }, he = /^#([0-9a-f]{3,8})$/i, K = function(t) {
354
+ }, fe = /^#([0-9a-f]{3,8})$/i, K = function(t) {
350
355
  var e = t.toString(16);
351
356
  return e.length < 2 ? "0" + e : e;
352
357
  }, Vt = function(t) {
@@ -367,17 +372,17 @@ var ue = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
367
372
  }, G = function(t) {
368
373
  return { h: (e = Vt(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
369
374
  var e, n, o, i;
370
- }, fe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, pe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ge = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, me = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, At = { string: [[function(t) {
371
- var e = he.exec(t);
375
+ }, pe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, me = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, be = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, At = { string: [[function(t) {
376
+ var e = fe.exec(t);
372
377
  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 ? O(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 ? O(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
373
378
  }, "hex"], [function(t) {
374
- var e = ge.exec(t) || me.exec(t);
379
+ var e = me.exec(t) || be.exec(t);
375
380
  return e ? e[2] !== e[4] || e[4] !== e[6] ? null : vt({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
376
381
  }, "rgb"], [function(t) {
377
- var e = fe.exec(t) || pe.exec(t);
382
+ var e = pe.exec(t) || ge.exec(t);
378
383
  if (!e)
379
384
  return null;
380
- var n, o, i = yt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (ue[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
385
+ var n, o, i = yt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (he[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
381
386
  return xt(i);
382
387
  }, "hsl"]], object: [[function(t) {
383
388
  var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
@@ -403,7 +408,7 @@ var ue = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
403
408
  return [o, e[n][1]];
404
409
  }
405
410
  return [null, void 0];
406
- }, be = function(t) {
411
+ }, ve = function(t) {
407
412
  return typeof t == "string" ? Et(t.trim(), At.string) : typeof t == "object" && t !== null ? Et(t, At.object) : [null, void 0];
408
413
  }, rt = function(t, e) {
409
414
  var n = G(t);
@@ -415,7 +420,7 @@ var ue = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
415
420
  return { h: n.h, s: n.s, l: U(n.l + 100 * e, 0, 100), a: n.a };
416
421
  }, Ct = function() {
417
422
  function t(e) {
418
- this.parsed = be(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
423
+ this.parsed = ve(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
419
424
  }
420
425
  return t.prototype.isValid = function() {
421
426
  return this.parsed !== null;
@@ -468,13 +473,13 @@ var ue = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, D = function(t) {
468
473
  }(), V = function(t) {
469
474
  return t instanceof Ct ? t : new Ct(t);
470
475
  };
471
- const ve = (t) => [
472
- `background-color:${V((t == null ? void 0 : t.fill) || Y.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? Y.fillOpacity : t.fillOpacity).toHex()}`,
476
+ const ye = (t) => [
477
+ `background-color:${V((t == null ? void 0 : t.fill) || H.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? H.fillOpacity : t.fillOpacity).toHex()}`,
473
478
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
474
479
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
475
480
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
476
481
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
477
- ].filter(Boolean).join(";"), ye = () => {
482
+ ].filter(Boolean).join(";"), we = () => {
478
483
  const t = document.createElement("style");
479
484
  document.getElementsByTagName("head")[0].appendChild(t);
480
485
  let e = /* @__PURE__ */ new Set();
@@ -487,21 +492,21 @@ const ve = (t) => [
487
492
  },
488
493
  redraw: (r, a, s, u) => {
489
494
  u && u.clear();
490
- const f = new Set(r.map((c) => c.annotation.id));
491
- Array.from(e).filter((c) => !f.has(c));
492
- const b = r.map((c) => {
495
+ const f = new Set(r.map((l) => l.annotation.id));
496
+ Array.from(e).filter((l) => !f.has(l));
497
+ const b = r.map((l) => {
493
498
  var w;
494
- const m = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (w = c.state) != null && w.selected ? et : Y, p = u && u.paint(c, a) || m;
495
- return `::highlight(_${c.annotation.id}) { ${ve(p)} }`;
499
+ const m = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (w = l.state) != null && w.selected ? et : H, p = u && u.paint(l, a) || m;
500
+ return `::highlight(_${l.annotation.id}) { ${ye(p)} }`;
496
501
  });
497
502
  t.innerHTML = b.join(`
498
- `), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
499
- const m = c.target.selector.map((w) => w.range), p = new Highlight(...m);
500
- CSS.highlights.set(`_${c.id}`, p);
503
+ `), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
504
+ const m = l.target.selector.map((w) => w.range), p = new Highlight(...m);
505
+ CSS.highlights.set(`_${l.id}`, p);
501
506
  }), e = f;
502
507
  }
503
508
  };
504
- }, we = (t, e, n) => pt(t, e, n, ye());
509
+ }, xe = (t, e, n) => pt(t, e, n, we());
505
510
  var Tt = Object.prototype.hasOwnProperty;
506
511
  function ht(t, e) {
507
512
  var n, o;
@@ -528,10 +533,10 @@ function ht(t, e) {
528
533
  }
529
534
  return t !== t && e !== e;
530
535
  }
531
- const xe = (t, e) => {
536
+ const Ae = (t, e) => {
532
537
  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;
533
538
  return e.filter((o) => t !== o && n(t, o) && o.width > t.width).length;
534
- }, Ae = (t) => {
539
+ }, Ee = (t) => {
535
540
  t.classList.add("r6o-annotatable");
536
541
  const e = document.createElement("div");
537
542
  e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
@@ -549,8 +554,8 @@ const xe = (t, e) => {
549
554
  const w = p.rects.map((v) => {
550
555
  const h = document.createElement("span");
551
556
  h.className = "r6o-annotation", h.dataset.annotation = p.annotation.id, h.style.left = `${v.x}px`, h.style.top = `${v.y}px`, h.style.width = `${v.width}px`, h.style.height = `${v.height}px`;
552
- const d = xe(v, m), l = qt(p, s, u, f, d), y = V((l == null ? void 0 : l.fill) || Y.fill).alpha((l == null ? void 0 : l.fillOpacity) === void 0 ? Y.fillOpacity : l.fillOpacity).toHex();
553
- return h.style.backgroundColor = y, l.underlineStyle && (h.style.borderStyle = l.underlineStyle), l.underlineColor && (h.style.borderColor = l.underlineColor), l.underlineThickness && (h.style.borderBottomWidth = `${l.underlineThickness}px`), l.underlineOffset && (h.style.paddingBottom = `${l.underlineOffset}px`), e.appendChild(h), h;
557
+ const d = Ae(v, m), c = qt(p, s, u, f, d), y = V((c == null ? void 0 : c.fill) || H.fill).alpha((c == null ? void 0 : c.fillOpacity) === void 0 ? H.fillOpacity : c.fillOpacity).toHex();
558
+ return h.style.backgroundColor = y, c.underlineStyle && (h.style.borderStyle = c.underlineStyle), c.underlineColor && (h.style.borderColor = c.underlineColor), c.underlineThickness && (h.style.borderBottomWidth = `${c.underlineThickness}px`), c.underlineOffset && (h.style.paddingBottom = `${c.underlineOffset}px`), e.appendChild(h), h;
554
559
  });
555
560
  return { id: p.annotation.id, spans: w };
556
561
  }), n = a;
@@ -559,29 +564,29 @@ const xe = (t, e) => {
559
564
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
560
565
  }
561
566
  };
562
- }, Ee = (t, e, n) => pt(t, e, n, Ae(t));
567
+ }, Se = (t, e, n) => pt(t, e, n, Ee(t));
563
568
  let Q;
564
- const Se = new Uint8Array(16);
565
- function Ce() {
569
+ const Ce = new Uint8Array(16);
570
+ function Te() {
566
571
  if (!Q && (Q = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Q))
567
572
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
568
- return Q(Se);
573
+ return Q(Ce);
569
574
  }
570
575
  const I = [];
571
576
  for (let t = 0; t < 256; ++t)
572
577
  I.push((t + 256).toString(16).slice(1));
573
- function Te(t, e = 0) {
578
+ function Re(t, e = 0) {
574
579
  return I[t[e + 0]] + I[t[e + 1]] + I[t[e + 2]] + I[t[e + 3]] + "-" + I[t[e + 4]] + I[t[e + 5]] + "-" + I[t[e + 6]] + I[t[e + 7]] + "-" + I[t[e + 8]] + I[t[e + 9]] + "-" + I[t[e + 10]] + I[t[e + 11]] + I[t[e + 12]] + I[t[e + 13]] + I[t[e + 14]] + I[t[e + 15]];
575
580
  }
576
- const Re = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Rt = {
577
- randomUUID: Re
581
+ const Ne = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Rt = {
582
+ randomUUID: Ne
578
583
  };
579
584
  function Xt(t, e, n) {
580
585
  if (Rt.randomUUID && !e && !t)
581
586
  return Rt.randomUUID();
582
587
  t = t || {};
583
- const o = t.random || (t.rng || Ce)();
584
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Te(o);
588
+ const o = t.random || (t.rng || Te)();
589
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Re(o);
585
590
  }
586
591
  var Nt = Object.prototype.hasOwnProperty;
587
592
  function F(t, e) {
@@ -611,7 +616,7 @@ function F(t, e) {
611
616
  }
612
617
  function at() {
613
618
  }
614
- function Ne(t, e) {
619
+ function Le(t, e) {
615
620
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
616
621
  }
617
622
  const $ = [];
@@ -619,7 +624,7 @@ function gt(t, e = at) {
619
624
  let n;
620
625
  const o = /* @__PURE__ */ new Set();
621
626
  function i(s) {
622
- if (Ne(t, s) && (t = s, n)) {
627
+ if (Le(t, s) && (t = s, n)) {
623
628
  const u = !$.length;
624
629
  for (const f of o)
625
630
  f[1](), $.push(f, t);
@@ -641,7 +646,7 @@ function gt(t, e = at) {
641
646
  }
642
647
  return { set: i, update: r, subscribe: a };
643
648
  }
644
- const Le = (t) => {
649
+ const Be = (t) => {
645
650
  const { subscribe: e, set: n } = gt();
646
651
  let o;
647
652
  return e((i) => o = i), t.observe(({ changes: i }) => {
@@ -658,36 +663,36 @@ const Le = (t) => {
658
663
  set: n
659
664
  };
660
665
  };
661
- var Be = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Be || {});
662
- const ct = { selected: [] }, Oe = (t, e = "EDIT") => {
663
- const { subscribe: n, set: o } = gt(ct);
664
- let i = ct;
665
- n((c) => i = c);
666
- const r = () => o(ct), a = () => {
667
- var c;
668
- return ((c = i.selected) == null ? void 0 : c.length) === 0;
669
- }, s = (c) => {
666
+ var Oe = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Oe || {});
667
+ const lt = { selected: [] }, Ie = (t, e = "EDIT") => {
668
+ const { subscribe: n, set: o } = gt(lt);
669
+ let i = lt;
670
+ n((l) => i = l);
671
+ const r = () => o(lt), a = () => {
672
+ var l;
673
+ return ((l = i.selected) == null ? void 0 : l.length) === 0;
674
+ }, s = (l) => {
670
675
  if (i.selected.length === 0)
671
676
  return !1;
672
- const m = typeof c == "string" ? c : c.id;
677
+ const m = typeof l == "string" ? l : l.id;
673
678
  return i.selected.some((p) => p.id === m);
674
- }, u = (c, m) => {
675
- const p = t.getAnnotation(c);
679
+ }, u = (l, m) => {
680
+ const p = t.getAnnotation(l);
676
681
  if (p) {
677
- const w = Ie(p, e);
678
- o(w === "EDIT" ? { selected: [{ id: c, editable: !0 }], pointerEvent: m } : w === "SELECT" ? { selected: [{ id: c }], pointerEvent: m } : { selected: [], pointerEvent: m });
682
+ const w = Me(p, e);
683
+ o(w === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: m } : w === "SELECT" ? { selected: [{ id: l }], pointerEvent: m } : { selected: [], pointerEvent: m });
679
684
  } else
680
- console.warn("Invalid selection: " + c);
681
- }, f = (c, m = !0) => {
682
- const p = Array.isArray(c) ? c : [c], w = p.map((v) => t.getAnnotation(v)).filter(Boolean);
683
- o({ selected: w.map(({ id: v }) => ({ id: v, editable: m })) }), w.length !== p.length && console.warn("Invalid selection", c);
684
- }, b = (c) => {
685
+ console.warn("Invalid selection: " + l);
686
+ }, f = (l, m = !0) => {
687
+ const p = Array.isArray(l) ? l : [l], w = p.map((v) => t.getAnnotation(v)).filter(Boolean);
688
+ o({ selected: w.map(({ id: v }) => ({ id: v, editable: m })) }), w.length !== p.length && console.warn("Invalid selection", l);
689
+ }, b = (l) => {
685
690
  if (i.selected.length === 0)
686
691
  return !1;
687
692
  const { selected: m } = i;
688
- m.filter(({ id: p }) => c.includes(p)).length > 0 && o({ selected: m.filter(({ id: p }) => !c.includes(p)) });
693
+ m.filter(({ id: p }) => l.includes(p)).length > 0 && o({ selected: m.filter(({ id: p }) => !l.includes(p)) });
689
694
  };
690
- return t.observe(({ changes: c }) => b((c.deleted || []).map((m) => m.id))), {
695
+ return t.observe(({ changes: l }) => b((l.deleted || []).map((m) => m.id))), {
691
696
  clear: r,
692
697
  clickSelect: u,
693
698
  get selected() {
@@ -701,58 +706,58 @@ const ct = { selected: [] }, Oe = (t, e = "EDIT") => {
701
706
  setSelected: f,
702
707
  subscribe: n
703
708
  };
704
- }, Ie = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
709
+ }, Me = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
705
710
  let J;
706
- const Me = new Uint8Array(16);
707
- function Ue() {
711
+ const Ue = new Uint8Array(16);
712
+ function Ve() {
708
713
  if (!J && (J = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !J))
709
714
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
710
- return J(Me);
715
+ return J(Ue);
711
716
  }
712
717
  const M = [];
713
718
  for (let t = 0; t < 256; ++t)
714
719
  M.push((t + 256).toString(16).slice(1));
715
- function Ve(t, e = 0) {
720
+ function _e(t, e = 0) {
716
721
  return M[t[e + 0]] + M[t[e + 1]] + M[t[e + 2]] + M[t[e + 3]] + "-" + M[t[e + 4]] + M[t[e + 5]] + "-" + M[t[e + 6]] + M[t[e + 7]] + "-" + M[t[e + 8]] + M[t[e + 9]] + "-" + M[t[e + 10]] + M[t[e + 11]] + M[t[e + 12]] + M[t[e + 13]] + M[t[e + 14]] + M[t[e + 15]];
717
722
  }
718
- const _e = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Lt = {
719
- randomUUID: _e
723
+ const Xe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Lt = {
724
+ randomUUID: Xe
720
725
  };
721
- function Xe(t, e, n) {
726
+ function De(t, e, n) {
722
727
  if (Lt.randomUUID && !e && !t)
723
728
  return Lt.randomUUID();
724
729
  t = t || {};
725
- const o = t.random || (t.rng || Ue)();
726
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Ve(o);
730
+ const o = t.random || (t.rng || Ve)();
731
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, _e(o);
727
732
  }
728
- const Bn = (t, e, n, o) => ({
729
- id: Xe(),
733
+ const On = (t, e, n, o) => ({
734
+ id: De(),
730
735
  annotation: t.id,
731
736
  created: n || /* @__PURE__ */ new Date(),
732
737
  creator: o,
733
738
  ...e
734
- }), De = (t, e) => {
739
+ }), ke = (t, e) => {
735
740
  const n = new Set(t.bodies.map((o) => o.id));
736
741
  return e.bodies.filter((o) => !n.has(o.id));
737
- }, ke = (t, e) => {
742
+ }, Ye = (t, e) => {
738
743
  const n = new Set(e.bodies.map((o) => o.id));
739
744
  return t.bodies.filter((o) => !n.has(o.id));
740
- }, Ye = (t, e) => e.bodies.map((n) => {
745
+ }, He = (t, e) => e.bodies.map((n) => {
741
746
  const o = t.bodies.find((i) => i.id === n.id);
742
747
  return { newBody: n, oldBody: o && !F(o, n) ? o : void 0 };
743
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), He = (t, e) => !F(t.target, e.target), Dt = (t, e) => {
744
- const n = De(t, e), o = ke(t, e), i = Ye(t, e);
748
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), $e = (t, e) => !F(t.target, e.target), Dt = (t, e) => {
749
+ const n = ke(t, e), o = Ye(t, e), i = He(t, e);
745
750
  return {
746
751
  oldValue: t,
747
752
  newValue: e,
748
753
  bodiesCreated: n.length > 0 ? n : void 0,
749
754
  bodiesDeleted: o.length > 0 ? o : void 0,
750
755
  bodiesUpdated: i.length > 0 ? i : void 0,
751
- targetUpdated: He(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
756
+ targetUpdated: $e(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
752
757
  };
753
758
  };
754
759
  var L = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(L || {});
755
- const $e = (t, e) => {
760
+ const Pe = (t, e) => {
756
761
  var n, o;
757
762
  const { changes: i, origin: r } = e;
758
763
  if (!(!t.options.origin || t.options.origin === r))
@@ -774,26 +779,26 @@ const $e = (t, e) => {
774
779
  return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => a.has(s));
775
780
  } else
776
781
  return !0;
777
- }, Pe = (t, e) => {
778
- const n = new Set((t.created || []).map((c) => c.id)), o = new Set((t.updated || []).map(({ newValue: c }) => c.id)), i = new Set((e.created || []).map((c) => c.id)), r = new Set((e.deleted || []).map((c) => c.id)), a = new Set((e.updated || []).map(({ oldValue: c }) => c.id)), s = new Set((e.updated || []).filter(({ oldValue: c }) => n.has(c.id) || o.has(c.id)).map(({ oldValue: c }) => c.id)), u = [
779
- ...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue: m }) => m.id === c.id).newValue : c),
782
+ }, ze = (t, e) => {
783
+ 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 = [
784
+ ...(t.created || []).filter((l) => !r.has(l.id)).map((l) => a.has(l.id) ? e.updated.find(({ oldValue: m }) => m.id === l.id).newValue : l),
780
785
  ...e.created || []
781
786
  ], f = [
782
- ...(t.deleted || []).filter((c) => !i.has(c.id)),
783
- ...(e.deleted || []).filter((c) => !n.has(c.id))
787
+ ...(t.deleted || []).filter((l) => !i.has(l.id)),
788
+ ...(e.deleted || []).filter((l) => !n.has(l.id))
784
789
  ], b = [
785
- ...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
786
- const { oldValue: m, newValue: p } = c;
790
+ ...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
791
+ const { oldValue: m, newValue: p } = l;
787
792
  if (a.has(p.id)) {
788
793
  const w = e.updated.find((v) => v.oldValue.id === p.id).newValue;
789
794
  return Dt(m, w);
790
795
  } else
791
- return c;
796
+ return l;
792
797
  }),
793
- ...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
798
+ ...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
794
799
  ];
795
800
  return { created: u, deleted: f, updated: b };
796
- }, ze = (t) => t.id !== void 0, Fe = () => {
801
+ }, Fe = (t) => t.id !== void 0, We = () => {
797
802
  const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (g, A = {}) => n.push({ onChange: g, options: A }), i = (g) => {
798
803
  const A = n.findIndex((x) => x.onChange == g);
799
804
  A > -1 && n.splice(A, 1);
@@ -808,7 +813,7 @@ const $e = (t, e) => {
808
813
  state: [...t.values()]
809
814
  };
810
815
  n.forEach((S) => {
811
- $e(S, x) && S.onChange(x);
816
+ Pe(S, x) && S.onChange(x);
812
817
  });
813
818
  }, a = (g, A = L.LOCAL) => {
814
819
  if (t.get(g.id))
@@ -822,7 +827,7 @@ const $e = (t, e) => {
822
827
  } else
823
828
  console.warn(`Cannot update annotation ${S} - does not exist`);
824
829
  }, u = (g, A = L.LOCAL, x = L.LOCAL) => {
825
- const S = ze(A) ? x : A, N = s(g, A);
830
+ const S = Fe(A) ? x : A, N = s(g, A);
826
831
  N && r(S, { updated: [N] });
827
832
  }, f = (g, A = L.LOCAL) => {
828
833
  const x = g.reduce((S, N) => {
@@ -844,7 +849,7 @@ const $e = (t, e) => {
844
849
  }] });
845
850
  } else
846
851
  console.warn(`Attempt to add body to missing annotation: ${g.annotation}`);
847
- }, c = () => [...t.values()], m = (g = L.LOCAL) => {
852
+ }, l = () => [...t.values()], m = (g = L.LOCAL) => {
848
853
  const A = [...t.values()];
849
854
  t.clear(), e.clear(), r(g, { deleted: A });
850
855
  }, p = (g, A = !0, x = L.LOCAL) => {
@@ -897,13 +902,13 @@ const $e = (t, e) => {
897
902
  console.warn(`Attempt to delete missing body ${g.id} from annotation ${g.annotation}`);
898
903
  } else
899
904
  console.warn(`Attempt to delete body from missing annotation ${g.annotation}`);
900
- }, l = (g) => {
905
+ }, c = (g) => {
901
906
  const A = t.get(g);
902
907
  return A ? { ...A } : void 0;
903
908
  }, y = (g) => {
904
909
  const A = e.get(g);
905
910
  if (A) {
906
- const x = l(A).bodies.find((S) => S.id === g);
911
+ const x = c(A).bodies.find((S) => S.id === g);
907
912
  if (x)
908
913
  return x;
909
914
  console.error(`Store integrity error: body ${g} in index, but not in annotation`);
@@ -955,7 +960,7 @@ const $e = (t, e) => {
955
960
  return {
956
961
  addAnnotation: a,
957
962
  addBody: b,
958
- all: c,
963
+ all: l,
959
964
  bulkAddAnnotation: p,
960
965
  bulkDeleteAnnotation: h,
961
966
  bulkUpdateAnnotation: f,
@@ -967,7 +972,7 @@ const $e = (t, e) => {
967
972
  clear: m,
968
973
  deleteAnnotation: v,
969
974
  deleteBody: d,
970
- getAnnotation: l,
975
+ getAnnotation: c,
971
976
  getBody: y,
972
977
  observe: o,
973
978
  unobserve: i,
@@ -979,7 +984,7 @@ const $e = (t, e) => {
979
984
  }
980
985
  };
981
986
  };
982
- let We = () => ({
987
+ let qe = () => ({
983
988
  emit(t, ...e) {
984
989
  for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
985
990
  o[n](...e);
@@ -993,24 +998,24 @@ let We = () => ({
993
998
  };
994
999
  }
995
1000
  });
996
- const qe = 250, je = (t) => {
997
- const e = We(), n = [];
1001
+ const je = 250, Ge = (t) => {
1002
+ const e = qe(), n = [];
998
1003
  let o = -1, i = !1, r = 0;
999
1004
  const a = (p) => {
1000
1005
  if (!i) {
1001
1006
  const { changes: w } = p, v = performance.now();
1002
- if (v - r > qe)
1007
+ if (v - r > je)
1003
1008
  n.splice(o + 1), n.push(w), o = n.length - 1;
1004
1009
  else {
1005
1010
  const h = n.length - 1;
1006
- n[h] = Pe(n[h], w);
1011
+ n[h] = ze(n[h], w);
1007
1012
  }
1008
1013
  r = v;
1009
1014
  }
1010
1015
  i = !1;
1011
1016
  };
1012
1017
  t.observe(a, { origin: L.LOCAL });
1013
- const s = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), u = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: w }) => w)), b = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: w }) => w)), c = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), m = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
1018
+ const s = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), u = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), f = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: w }) => w)), b = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: w }) => w)), l = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), m = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
1014
1019
  return {
1015
1020
  canRedo: () => n.length - 1 > o,
1016
1021
  canUndo: () => o > -1,
@@ -1027,32 +1032,32 @@ const qe = 250, je = (t) => {
1027
1032
  if (o > -1) {
1028
1033
  i = !0;
1029
1034
  const { created: p, updated: w, deleted: v } = n[o];
1030
- s(p), f(w), c(v), e.emit("undo", n[o]), o -= 1;
1035
+ s(p), f(w), l(v), e.emit("undo", n[o]), o -= 1;
1031
1036
  }
1032
1037
  }
1033
1038
  };
1034
- }, Ge = () => {
1039
+ }, Ke = () => {
1035
1040
  const { subscribe: t, set: e } = gt([]);
1036
1041
  return {
1037
1042
  subscribe: t,
1038
1043
  set: e
1039
1044
  };
1040
- }, Ke = (t, e, n, o) => {
1045
+ }, Qe = (t, e, n, o) => {
1041
1046
  const { store: i, selection: r, hover: a, viewport: s } = t, u = /* @__PURE__ */ new Map();
1042
1047
  let f = [], b;
1043
- const c = (v, h) => {
1048
+ const l = (v, h) => {
1044
1049
  u.has(v) ? u.get(v).push(h) : u.set(v, [h]);
1045
1050
  }, m = (v, h) => {
1046
1051
  const d = u.get(v);
1047
1052
  d && d.indexOf(h) > 0 && d.splice(d.indexOf(h), 1);
1048
1053
  }, p = (v, h, d) => {
1049
1054
  u.has(v) && setTimeout(() => {
1050
- u.get(v).forEach((l) => {
1055
+ u.get(v).forEach((c) => {
1051
1056
  if (n) {
1052
1057
  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;
1053
- l(y, T);
1058
+ c(y, T);
1054
1059
  } else
1055
- l(h, d);
1060
+ c(h, d);
1056
1061
  });
1057
1062
  }, 1);
1058
1063
  };
@@ -1066,15 +1071,15 @@ const qe = 250, je = (t) => {
1066
1071
  d && !F(d, h) && p("updateAnnotation", d, h);
1067
1072
  }), f = [];
1068
1073
  else {
1069
- const h = new Set(f.map((l) => l.id)), d = new Set(v.map(({ id: l }) => l));
1070
- f.filter((l) => !d.has(l.id)).forEach((l) => {
1071
- const y = i.getAnnotation(l.id);
1072
- y && !F(y, l) && p("updateAnnotation", y, l);
1074
+ const h = new Set(f.map((c) => c.id)), d = new Set(v.map(({ id: c }) => c));
1075
+ f.filter((c) => !d.has(c.id)).forEach((c) => {
1076
+ const y = i.getAnnotation(c.id);
1077
+ y && !F(y, c) && p("updateAnnotation", y, c);
1073
1078
  }), f = [
1074
1079
  // Remove annotations that were deselected
1075
- ...f.filter((l) => d.has(l.id)),
1080
+ ...f.filter((c) => d.has(c.id)),
1076
1081
  // Add editable annotations that were selected
1077
- ...v.filter(({ id: l }) => !h.has(l)).map(({ id: l }) => i.getAnnotation(l))
1082
+ ...v.filter(({ id: c }) => !h.has(c)).map(({ id: c }) => i.getAnnotation(c))
1078
1083
  ];
1079
1084
  }
1080
1085
  p("selectionChanged", f);
@@ -1083,26 +1088,26 @@ const qe = 250, je = (t) => {
1083
1088
  !b && v ? p("mouseEnterAnnotation", i.getAnnotation(v)) : b && !v ? p("mouseLeaveAnnotation", i.getAnnotation(b)) : b && v && (p("mouseLeaveAnnotation", i.getAnnotation(b)), p("mouseEnterAnnotation", i.getAnnotation(v))), b = v;
1084
1089
  }), s == null || s.subscribe((v) => p("viewportIntersect", v.map((h) => i.getAnnotation(h)))), i.observe((v) => {
1085
1090
  const { created: h, deleted: d } = v.changes;
1086
- (h || []).forEach((l) => p("createAnnotation", l)), (d || []).forEach((l) => p("deleteAnnotation", l)), (v.changes.updated || []).filter((l) => [
1087
- ...l.bodiesCreated || [],
1088
- ...l.bodiesDeleted || [],
1089
- ...l.bodiesUpdated || []
1090
- ].length > 0).forEach(({ oldValue: l, newValue: y }) => {
1091
- const T = f.find((C) => C.id === l.id) || l;
1092
- f = f.map((C) => C.id === l.id ? y : C), p("updateAnnotation", y, T);
1091
+ (h || []).forEach((c) => p("createAnnotation", c)), (d || []).forEach((c) => p("deleteAnnotation", c)), (v.changes.updated || []).filter((c) => [
1092
+ ...c.bodiesCreated || [],
1093
+ ...c.bodiesDeleted || [],
1094
+ ...c.bodiesUpdated || []
1095
+ ].length > 0).forEach(({ oldValue: c, newValue: y }) => {
1096
+ const T = f.find((C) => C.id === c.id) || c;
1097
+ f = f.map((C) => C.id === c.id ? y : C), p("updateAnnotation", y, T);
1093
1098
  });
1094
1099
  }, { origin: L.LOCAL }), i.observe((v) => {
1095
1100
  if (f) {
1096
- const h = new Set(f.map((l) => l.id)), d = (v.changes.updated || []).filter(({ newValue: l }) => h.has(l.id)).map(({ newValue: l }) => l);
1097
- d.length > 0 && (f = f.map((l) => d.find((T) => T.id === l.id) || l));
1101
+ const h = new Set(f.map((c) => c.id)), d = (v.changes.updated || []).filter(({ newValue: c }) => h.has(c.id)).map(({ newValue: c }) => c);
1102
+ d.length > 0 && (f = f.map((c) => d.find((T) => T.id === c.id) || c));
1098
1103
  }
1099
1104
  }, { origin: L.REMOTE });
1100
1105
  const w = (v) => (h) => {
1101
1106
  const { updated: d } = h;
1102
- v ? (d || []).forEach((l) => p("updateAnnotation", l.oldValue, l.newValue)) : (d || []).forEach((l) => p("updateAnnotation", l.newValue, l.oldValue));
1107
+ v ? (d || []).forEach((c) => p("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => p("updateAnnotation", c.newValue, c.oldValue));
1103
1108
  };
1104
- return e.on("undo", w(!0)), e.on("redo", w(!1)), { on: c, off: m, emit: p };
1105
- }, Qe = (t) => (e) => e.reduce((n, o) => {
1109
+ return e.on("undo", w(!0)), e.on("redo", w(!1)), { on: l, off: m, emit: p };
1110
+ }, Je = (t) => (e) => e.reduce((n, o) => {
1106
1111
  const { parsed: i, error: r } = t.parse(o);
1107
1112
  return r ? {
1108
1113
  parsed: n.parsed,
@@ -1113,11 +1118,11 @@ const qe = 250, je = (t) => {
1113
1118
  } : {
1114
1119
  ...n
1115
1120
  };
1116
- }, { parsed: [], failed: [] }), Je = (t, e, n) => {
1121
+ }, { parsed: [], failed: [] }), Ze = (t, e, n) => {
1117
1122
  const { store: o, selection: i } = t, r = (h) => {
1118
1123
  if (n) {
1119
- const { parsed: d, error: l } = n.parse(h);
1120
- d ? o.addAnnotation(d, L.REMOTE) : console.error(l);
1124
+ const { parsed: d, error: c } = n.parse(h);
1125
+ d ? o.addAnnotation(d, L.REMOTE) : console.error(c);
1121
1126
  } else
1122
1127
  o.addAnnotation(h, L.REMOTE);
1123
1128
  }, a = () => i.clear(), s = () => o.clear(), u = (h) => {
@@ -1125,9 +1130,9 @@ const qe = 250, je = (t) => {
1125
1130
  return n && d ? n.serialize(d) : d;
1126
1131
  }, f = () => n ? o.all().map(n.serialize) : o.all(), b = () => {
1127
1132
  var h;
1128
- const d = (((h = i.selected) == null ? void 0 : h.map((l) => l.id)) || []).map((l) => o.getAnnotation(l)).filter(Boolean);
1133
+ const d = (((h = i.selected) == null ? void 0 : h.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
1129
1134
  return n ? d.map(n.serialize) : d;
1130
- }, c = (h, d = !0) => fetch(h).then((l) => l.json()).then((l) => (p(l, d), l)), m = (h) => {
1135
+ }, l = (h, d = !0) => fetch(h).then((c) => c.json()).then((c) => (p(c, d), c)), m = (h) => {
1131
1136
  if (typeof h == "string") {
1132
1137
  const d = o.getAnnotation(h);
1133
1138
  if (o.deleteAnnotation(h), d)
@@ -1139,16 +1144,16 @@ const qe = 250, je = (t) => {
1139
1144
  }
1140
1145
  }, p = (h, d = !0) => {
1141
1146
  if (n) {
1142
- const { parsed: l, failed: y } = Qe(n)(h);
1143
- y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(l, d, L.REMOTE);
1147
+ const { parsed: c, failed: y } = Je(n)(h);
1148
+ y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(c, d, L.REMOTE);
1144
1149
  } else
1145
1150
  o.bulkAddAnnotation(h, d, L.REMOTE);
1146
1151
  }, w = (h) => {
1147
1152
  h ? i.setSelected(h) : i.clear();
1148
1153
  }, v = (h) => {
1149
1154
  if (n) {
1150
- const d = n.parse(h).parsed, l = n.serialize(o.getAnnotation(d.id));
1151
- return o.updateAnnotation(d), l;
1155
+ const d = n.parse(h).parsed, c = n.serialize(o.getAnnotation(d.id));
1156
+ return o.updateAnnotation(d), c;
1152
1157
  } else {
1153
1158
  const d = o.getAnnotation(h.id);
1154
1159
  return o.updateAnnotation(h), d;
@@ -1163,7 +1168,7 @@ const qe = 250, je = (t) => {
1163
1168
  getAnnotationById: u,
1164
1169
  getAnnotations: f,
1165
1170
  getSelected: b,
1166
- loadAnnotations: c,
1171
+ loadAnnotations: l,
1167
1172
  redo: e.redo,
1168
1173
  removeAnnotation: m,
1169
1174
  setAnnotations: p,
@@ -1171,8 +1176,8 @@ const qe = 250, je = (t) => {
1171
1176
  undo: e.undo,
1172
1177
  updateAnnotation: v
1173
1178
  };
1174
- }, Ze = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1175
- let tn = (t) => crypto.getRandomValues(new Uint8Array(t)), en = (t, e, n) => {
1179
+ }, tn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1180
+ let en = (t) => crypto.getRandomValues(new Uint8Array(t)), nn = (t, e, n) => {
1176
1181
  let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
1177
1182
  return (r = e) => {
1178
1183
  let a = "";
@@ -1183,13 +1188,13 @@ let tn = (t) => crypto.getRandomValues(new Uint8Array(t)), en = (t, e, n) => {
1183
1188
  return a;
1184
1189
  }
1185
1190
  };
1186
- }, nn = (t, e = 21) => en(t, e, tn), on = (t = 21) => {
1191
+ }, on = (t, e = 21) => nn(t, e, en), rn = (t = 21) => {
1187
1192
  let e = "", n = crypto.getRandomValues(new Uint8Array(t));
1188
1193
  for (; t--; )
1189
- e += Ze[n[t] & 63];
1194
+ e += tn[n[t] & 63];
1190
1195
  return e;
1191
1196
  };
1192
- const rn = () => ({ isGuest: !0, id: nn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), sn = (t) => {
1197
+ const sn = () => ({ isGuest: !0, id: on("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), an = (t) => {
1193
1198
  const e = JSON.stringify(t);
1194
1199
  let n = 0;
1195
1200
  for (let o = 0, i = e.length; o < i; o++) {
@@ -1197,10 +1202,10 @@ const rn = () => ({ isGuest: !0, id: nn("1234567890abcdefghijklmnopqrstuvwxyzABC
1197
1202
  n = (n << 5) - n + r, n |= 0;
1198
1203
  }
1199
1204
  return `${n}`;
1200
- }, kt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, an = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1205
+ }, kt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, ln = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1201
1206
  const { id: o, type: i, purpose: r, value: a, created: s, creator: u, ...f } = n;
1202
1207
  return {
1203
- id: o || `temp-${sn(n)}`,
1208
+ id: o || `temp-${an(n)}`,
1204
1209
  annotation: e,
1205
1210
  type: i,
1206
1211
  purpose: r,
@@ -1214,11 +1219,11 @@ const rn = () => ({ isGuest: !0, id: nn("1234567890abcdefghijklmnopqrstuvwxyzABC
1214
1219
  const i = { ...e };
1215
1220
  return delete i.annotation, (n = i.id) != null && n.startsWith("temp-") && delete i.id, { ...i, created: (o = i.created) == null ? void 0 : o.toISOString() };
1216
1221
  });
1217
- on();
1218
- const On = (t, e) => ({
1219
- parse: (n) => un(n),
1220
- serialize: (n) => hn(n, t, e)
1221
- }), ln = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, dn = (t) => {
1222
+ rn();
1223
+ const In = (t, e) => ({
1224
+ parse: (n) => hn(n),
1225
+ serialize: (n) => fn(n, t, e)
1226
+ }), dn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, un = (t) => {
1222
1227
  const {
1223
1228
  id: e,
1224
1229
  creator: n,
@@ -1233,36 +1238,36 @@ const On = (t, e) => ({
1233
1238
  selector: []
1234
1239
  };
1235
1240
  for (const u of a) {
1236
- const b = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((c, m) => {
1241
+ const b = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((l, m) => {
1237
1242
  switch (m.type) {
1238
1243
  case "TextQuoteSelector":
1239
- c.quote = m.exact;
1244
+ l.quote = m.exact;
1240
1245
  break;
1241
1246
  case "TextPositionSelector":
1242
- c.start = m.start, c.end = m.end;
1247
+ l.start = m.start, l.end = m.end;
1243
1248
  break;
1244
1249
  }
1245
- return c;
1250
+ return l;
1246
1251
  }, {});
1247
- if (ln(b))
1252
+ if (dn(b))
1248
1253
  s.selector.push({ id: u.id, ...b });
1249
1254
  else {
1250
- const c = [
1255
+ const l = [
1251
1256
  b.start ? void 0 : "TextPositionSelector",
1252
1257
  b.quote ? void 0 : "TextQuoteSelector"
1253
1258
  ].filter(Boolean);
1254
- return { error: Error(`Missing selector types: ${c.join(" and ")} for annotation: ${t.id}`) };
1259
+ return { error: Error(`Missing selector types: ${l.join(" and ")} for annotation: ${t.id}`) };
1255
1260
  }
1256
1261
  }
1257
1262
  return { parsed: s };
1258
- }, un = (t) => {
1263
+ }, hn = (t) => {
1259
1264
  const e = t.id || Xt(), {
1260
1265
  creator: n,
1261
1266
  created: o,
1262
1267
  modified: i,
1263
1268
  body: r,
1264
1269
  ...a
1265
- } = t, s = an(r, e), u = dn(t);
1270
+ } = t, s = ln(r, e), u = un(t);
1266
1271
  return "error" in u ? { error: u.error } : {
1267
1272
  parsed: {
1268
1273
  ...a,
@@ -1271,19 +1276,19 @@ const On = (t, e) => ({
1271
1276
  target: u.parsed
1272
1277
  }
1273
1278
  };
1274
- }, hn = (t, e, n) => {
1279
+ }, fn = (t, e, n) => {
1275
1280
  const { bodies: o, target: i, ...r } = t, {
1276
1281
  selector: a,
1277
1282
  creator: s,
1278
1283
  created: u,
1279
1284
  updated: f,
1280
1285
  ...b
1281
- } = i, c = a.map((m) => {
1282
- const { quote: p, start: w, end: v, range: h } = m, { prefix: d, suffix: l } = Zt(h, n), y = [{
1286
+ } = i, l = a.map((m) => {
1287
+ const { quote: p, start: w, end: v, range: h } = m, { prefix: d, suffix: c } = te(h, n), y = [{
1283
1288
  type: "TextQuoteSelector",
1284
1289
  exact: p,
1285
1290
  prefix: d,
1286
- suffix: l
1291
+ suffix: c
1287
1292
  }, {
1288
1293
  type: "TextPositionSelector",
1289
1294
  start: w,
@@ -1305,17 +1310,17 @@ const On = (t, e) => ({
1305
1310
  creator: s,
1306
1311
  created: u == null ? void 0 : u.toISOString(),
1307
1312
  modified: f == null ? void 0 : f.toISOString(),
1308
- target: c
1313
+ target: l
1309
1314
  };
1310
1315
  };
1311
- function fn(t, e, n, o, i) {
1312
- Yt(t, e, n || 0, o || t.length - 1, i || pn);
1316
+ function pn(t, e, n, o, i) {
1317
+ Yt(t, e, n || 0, o || t.length - 1, i || gn);
1313
1318
  }
1314
1319
  function Yt(t, e, n, o, i) {
1315
1320
  for (; o > n; ) {
1316
1321
  if (o - n > 600) {
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), b = Math.max(n, Math.floor(e - a * u / r + f)), c = Math.min(o, Math.floor(e + (r - a) * u / r + f));
1318
- Yt(t, e, b, c, i);
1322
+ 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), b = Math.max(n, Math.floor(e - a * u / r + f)), l = Math.min(o, Math.floor(e + (r - a) * u / r + f));
1323
+ Yt(t, e, b, l, i);
1319
1324
  }
1320
1325
  var m = t[e], p = n, w = o;
1321
1326
  for (W(t, n, e), i(t[o], m) > 0 && W(t, n, o); p < w; ) {
@@ -1331,10 +1336,10 @@ function W(t, e, n) {
1331
1336
  var o = t[e];
1332
1337
  t[e] = t[n], t[n] = o;
1333
1338
  }
1334
- function pn(t, e) {
1339
+ function gn(t, e) {
1335
1340
  return t < e ? -1 : t > e ? 1 : 0;
1336
1341
  }
1337
- class gn {
1342
+ class mn {
1338
1343
  constructor(e = 9) {
1339
1344
  this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
1340
1345
  }
@@ -1410,7 +1415,7 @@ class gn {
1410
1415
  let s, u, f;
1411
1416
  for (; o || r.length; ) {
1412
1417
  if (o || (o = r.pop(), u = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
1413
- const b = mn(e, o.children, n);
1418
+ const b = bn(e, o.children, n);
1414
1419
  if (b !== -1)
1415
1420
  return o.children.splice(b, 1), r.push(o), this._condense(r), this;
1416
1421
  }
@@ -1448,10 +1453,10 @@ class gn {
1448
1453
  const u = Math.ceil(r / a), f = u * Math.ceil(Math.sqrt(a));
1449
1454
  Bt(e, n, o, f, this.compareMinX);
1450
1455
  for (let b = n; b <= o; b += f) {
1451
- const c = Math.min(b + f - 1, o);
1452
- Bt(e, b, c, u, this.compareMinY);
1453
- for (let m = b; m <= c; m += u) {
1454
- const p = Math.min(m + u - 1, c);
1456
+ const l = Math.min(b + f - 1, o);
1457
+ Bt(e, b, l, u, this.compareMinY);
1458
+ for (let m = b; m <= l; m += u) {
1459
+ const p = Math.min(m + u - 1, l);
1455
1460
  s.children.push(this._build(e, m, p, i - 1));
1456
1461
  }
1457
1462
  }
@@ -1461,8 +1466,8 @@ class gn {
1461
1466
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1462
1467
  let r = 1 / 0, a = 1 / 0, s;
1463
1468
  for (let u = 0; u < n.children.length; u++) {
1464
- const f = n.children[u], b = lt(f), c = yn(e, f) - b;
1465
- c < a ? (a = c, r = b < r ? b : r, s = f) : c === a && b < r && (r = b, s = f);
1469
+ const f = n.children[u], b = ct(f), l = wn(e, f) - b;
1470
+ l < a ? (a = l, r = b < r ? b : r, s = f) : l === a && b < r && (r = b, s = f);
1466
1471
  }
1467
1472
  n = s || n.children[0];
1468
1473
  }
@@ -1487,14 +1492,14 @@ class gn {
1487
1492
  _chooseSplitIndex(e, n, o) {
1488
1493
  let i, r = 1 / 0, a = 1 / 0;
1489
1494
  for (let s = n; s <= o - n; s++) {
1490
- const u = q(e, 0, s, this.toBBox), f = q(e, s, o, this.toBBox), b = wn(u, f), c = lt(u) + lt(f);
1491
- b < r ? (r = b, i = s, a = c < a ? c : a) : b === r && c < a && (a = c, i = s);
1495
+ const u = q(e, 0, s, this.toBBox), f = q(e, s, o, this.toBBox), b = xn(u, f), l = ct(u) + ct(f);
1496
+ b < r ? (r = b, i = s, a = l < a ? l : a) : b === r && l < a && (a = l, i = s);
1492
1497
  }
1493
1498
  return i || o - n;
1494
1499
  }
1495
1500
  // sorts node children by the best axis for split
1496
1501
  _chooseSplitAxis(e, n, o) {
1497
- const i = e.leaf ? this.compareMinX : bn, r = e.leaf ? this.compareMinY : vn, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1502
+ const i = e.leaf ? this.compareMinX : vn, r = e.leaf ? this.compareMinY : yn, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1498
1503
  a < s && e.children.sort(i);
1499
1504
  }
1500
1505
  // total margin of all possible split distributions where each node is at least m full
@@ -1521,7 +1526,7 @@ class gn {
1521
1526
  e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : P(e[n], this.toBBox);
1522
1527
  }
1523
1528
  }
1524
- function mn(t, e, n) {
1529
+ function bn(t, e, n) {
1525
1530
  if (!n)
1526
1531
  return e.indexOf(t);
1527
1532
  for (let o = 0; o < e.length; o++)
@@ -1543,22 +1548,22 @@ function q(t, e, n, o, i) {
1543
1548
  function j(t, e) {
1544
1549
  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;
1545
1550
  }
1546
- function bn(t, e) {
1551
+ function vn(t, e) {
1547
1552
  return t.minX - e.minX;
1548
1553
  }
1549
- function vn(t, e) {
1554
+ function yn(t, e) {
1550
1555
  return t.minY - e.minY;
1551
1556
  }
1552
- function lt(t) {
1557
+ function ct(t) {
1553
1558
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1554
1559
  }
1555
1560
  function Z(t) {
1556
1561
  return t.maxX - t.minX + (t.maxY - t.minY);
1557
1562
  }
1558
- function yn(t, e) {
1563
+ function wn(t, e) {
1559
1564
  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));
1560
1565
  }
1561
- function wn(t, e) {
1566
+ function xn(t, e) {
1562
1567
  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);
1563
1568
  return Math.max(0, i - n) * Math.max(0, r - o);
1564
1569
  }
@@ -1585,15 +1590,15 @@ function Bt(t, e, n, o, i) {
1585
1590
  if (n = r.pop(), e = r.pop(), n - e <= o)
1586
1591
  continue;
1587
1592
  const a = e + Math.ceil((n - e) / o / 2) * o;
1588
- fn(t, a, e, n, i), r.push(e, a, a, n);
1593
+ pn(t, a, e, n, i), r.push(e, a, a, n);
1589
1594
  }
1590
1595
  }
1591
- const xn = (t, e) => {
1592
- const n = new gn(), o = /* @__PURE__ */ new Map(), i = (d, l) => {
1596
+ const An = (t, e) => {
1597
+ const n = new mn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1593
1598
  const y = d.selector.flatMap((C) => {
1594
1599
  const R = C.range instanceof Range && !C.range.collapsed && C.range.startContainer.nodeType === Node.TEXT_NODE && C.range.endContainer.nodeType === Node.TEXT_NODE ? C.range : Mt(C, e).range;
1595
1600
  return Array.from(R.getClientRects());
1596
- }), T = ne(y).map(({ left: C, top: E, right: R, bottom: g }) => new DOMRect(C - l.left, E - l.top, R - C, g - E));
1601
+ }), T = oe(y).map(({ left: C, top: E, right: R, bottom: g }) => new DOMRect(C - c.left, E - c.top, R - C, g - E));
1597
1602
  return T.map((C) => {
1598
1603
  const { x: E, y: R, width: g, height: A } = C;
1599
1604
  return {
@@ -1610,50 +1615,50 @@ const xn = (t, e) => {
1610
1615
  }, r = () => [...o.values()], a = () => {
1611
1616
  n.clear(), o.clear();
1612
1617
  }, s = (d) => {
1613
- const l = i(d, e.getBoundingClientRect());
1614
- l.forEach((y) => n.insert(y)), o.set(d.annotation, l);
1618
+ const c = i(d, e.getBoundingClientRect());
1619
+ c.forEach((y) => n.insert(y)), o.set(d.annotation, c);
1615
1620
  }, u = (d) => {
1616
- const l = o.get(d.annotation);
1617
- l && (l.forEach((y) => n.remove(y)), o.delete(d.annotation));
1621
+ const c = o.get(d.annotation);
1622
+ c && (c.forEach((y) => n.remove(y)), o.delete(d.annotation));
1618
1623
  }, f = (d) => {
1619
1624
  u(d), s(d);
1620
- }, b = (d, l = !0) => {
1621
- l && a();
1625
+ }, b = (d, c = !0) => {
1626
+ c && a();
1622
1627
  const y = e.getBoundingClientRect(), T = d.map((E) => ({ target: E, rects: i(E, y) }));
1623
1628
  T.forEach(({ target: E, rects: R }) => o.set(E.annotation, R));
1624
1629
  const C = T.reduce((E, { rects: R }) => [...E, ...R], []);
1625
1630
  n.load(C);
1626
- }, c = (d, l) => {
1631
+ }, l = (d, c) => {
1627
1632
  const y = n.search({
1628
1633
  minX: d,
1629
- minY: l,
1634
+ minY: c,
1630
1635
  maxX: d,
1631
- maxY: l
1636
+ maxY: c
1632
1637
  }), T = (C) => C.annotation.rects.reduce((E, R) => E + R.width * R.height, 0);
1633
1638
  if (y.length > 0)
1634
1639
  return y.sort((C, E) => T(C) - T(E)), y[0].annotation.id;
1635
1640
  }, m = (d) => {
1636
- const l = p(d);
1637
- if (l.length === 0)
1641
+ const c = p(d);
1642
+ if (c.length === 0)
1638
1643
  return;
1639
- let y = l[0].left, T = l[0].top, C = l[0].right, E = l[0].bottom;
1640
- for (let R = 1; R < l.length; R++) {
1641
- const g = l[R];
1644
+ let y = c[0].left, T = c[0].top, C = c[0].right, E = c[0].bottom;
1645
+ for (let R = 1; R < c.length; R++) {
1646
+ const g = c[R];
1642
1647
  y = Math.min(y, g.left), T = Math.min(T, g.top), C = Math.max(C, g.right), E = Math.max(E, g.bottom);
1643
1648
  }
1644
1649
  return new DOMRect(y, T, C - y, E - T);
1645
1650
  }, p = (d) => {
1646
- const l = o.get(d);
1647
- return l ? l[0].annotation.rects : [];
1651
+ const c = o.get(d);
1652
+ return c ? c[0].annotation.rects : [];
1648
1653
  };
1649
1654
  return {
1650
1655
  all: r,
1651
1656
  clear: a,
1652
- getAt: c,
1657
+ getAt: l,
1653
1658
  getAnnotationBounds: m,
1654
1659
  getAnnotationRects: p,
1655
- getIntersecting: (d, l, y, T) => {
1656
- const C = n.search({ minX: d, minY: l, maxX: y, maxY: T }), E = new Set(C.reduce((R, g) => [...R, g.annotation.id], []));
1660
+ getIntersecting: (d, c, y, T) => {
1661
+ const C = n.search({ minX: d, minY: c, maxX: y, maxY: T }), E = new Set(C.reduce((R, g) => [...R, g.annotation.id], []));
1657
1662
  return Array.from(E).map((R) => ({
1658
1663
  annotation: t.getAnnotation(R),
1659
1664
  rects: p(R)
@@ -1666,32 +1671,32 @@ const xn = (t, e) => {
1666
1671
  size: () => n.all().length,
1667
1672
  update: f
1668
1673
  };
1669
- }, An = (t, e) => {
1670
- const n = Fe(), o = xn(n, t), i = Oe(n, e), r = Le(n), a = Ge(), s = (v, h = L.LOCAL) => {
1671
- const d = ot(v, t), l = k(d.target.selector);
1672
- return l && n.addAnnotation(d, h), l;
1674
+ }, En = (t, e) => {
1675
+ const n = We(), o = An(n, t), i = Ie(n, e), r = Be(n), a = Ke(), s = (v, h = L.LOCAL) => {
1676
+ const d = ot(v, t), c = Y(d.target.selector);
1677
+ return c && n.addAnnotation(d, h), c;
1673
1678
  }, u = (v, h = !0, d = L.LOCAL) => {
1674
- const l = v.map((T) => ot(T, t)), y = l.filter((T) => !k(T.target.selector));
1675
- return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(l, h, d), y) : (n.bulkAddAnnotation(l, h, d), []);
1679
+ const c = v.map((T) => ot(T, t)), y = c.filter((T) => !Y(T.target.selector));
1680
+ 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), []);
1676
1681
  }, f = (v, h = L.LOCAL) => {
1677
- const d = v.map((y) => ot(y, t)), l = d.filter((y) => !k(y.target.selector));
1678
- return l.length > 0 && console.warn("Could not revive all targets for these annotations:", l), d.forEach((y) => {
1682
+ const d = v.map((y) => ot(y, t)), c = d.filter((y) => !Y(y.target.selector));
1683
+ return c.length > 0 && console.warn("Could not revive all targets for these annotations:", c), d.forEach((y) => {
1679
1684
  n.getAnnotation(y.id) ? n.updateAnnotation(y, h) : n.addAnnotation(y, h);
1680
- }), l;
1685
+ }), c;
1681
1686
  }, b = (v, h = L.LOCAL) => {
1682
1687
  const d = nt(v, t);
1683
1688
  n.updateTarget(d, h);
1684
- }, c = (v, h = L.LOCAL) => {
1685
- const d = v.map((l) => nt(l, t));
1689
+ }, l = (v, h = L.LOCAL) => {
1690
+ const d = v.map((c) => nt(c, t));
1686
1691
  n.bulkUpdateTargets(d, h);
1687
1692
  }, m = (v, h) => {
1688
1693
  const d = o.getAt(v, h);
1689
1694
  return d ? n.getAnnotation(d) : void 0;
1690
- }, p = (v, h, d, l = 5) => {
1695
+ }, p = (v, h, d, c = 5) => {
1691
1696
  const y = o.getAnnotationRects(v);
1692
1697
  if (y.length !== 0) {
1693
1698
  if (h && d) {
1694
- const T = y.find(({ top: C, right: E, bottom: R, left: g }) => h >= g - l && h <= E + l && d >= C - l && d <= R + l);
1699
+ const T = y.find(({ top: C, right: E, bottom: R, left: g }) => h >= g - c && h <= E + c && d >= C - c && d <= R + c);
1695
1700
  if (T)
1696
1701
  return T;
1697
1702
  }
@@ -1699,14 +1704,14 @@ const xn = (t, e) => {
1699
1704
  }
1700
1705
  }, w = () => o.recalculate();
1701
1706
  return n.observe(({ changes: v }) => {
1702
- const h = (v.created || []).filter((y) => k(y.target.selector)), d = (v.deleted || []).filter((y) => k(y.target.selector)), l = (v.updated || []).filter((y) => k(y.newValue.target.selector));
1703
- 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)), (l == null ? void 0 : l.length) > 0 && l.forEach(({ newValue: y }) => o.update(y.target));
1707
+ const h = (v.created || []).filter((y) => Y(y.target.selector)), d = (v.deleted || []).filter((y) => Y(y.target.selector)), c = (v.updated || []).filter((y) => Y(y.newValue.target.selector));
1708
+ 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));
1704
1709
  }), {
1705
1710
  store: {
1706
1711
  ...n,
1707
1712
  addAnnotation: s,
1708
1713
  bulkAddAnnotation: u,
1709
- bulkUpdateTargets: c,
1714
+ bulkUpdateTargets: l,
1710
1715
  bulkUpsertAnnotations: f,
1711
1716
  getAnnotationBounds: p,
1712
1717
  getAt: m,
@@ -1718,32 +1723,32 @@ const xn = (t, e) => {
1718
1723
  hover: r,
1719
1724
  viewport: a
1720
1725
  };
1721
- }, En = () => {
1726
+ }, Sn = () => {
1722
1727
  const t = document.createElement("canvas");
1723
1728
  t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-highlight-layer presence";
1724
1729
  const e = t.getContext("2d");
1725
1730
  return e.scale(2, 2), e.translate(0.5, 0.5), t;
1726
- }, Sn = (t, e, n = {}) => {
1727
- const o = En(), i = o.getContext("2d");
1731
+ }, Cn = (t, e, n = {}) => {
1732
+ const o = Sn(), i = o.getContext("2d");
1728
1733
  t.appendChild(o);
1729
- const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([m, p]) => p.presenceKey === c.presenceKey).map(([m, p]) => m);
1730
- return e.on("selectionChange", (c, m) => {
1731
- a(c).forEach((w) => r.delete(w)), m && m.forEach((w) => r.set(w, c));
1734
+ const r = /* @__PURE__ */ new Map(), a = (l) => Array.from(r.entries()).filter(([m, p]) => p.presenceKey === l.presenceKey).map(([m, p]) => m);
1735
+ return e.on("selectionChange", (l, m) => {
1736
+ a(l).forEach((w) => r.delete(w)), m && m.forEach((w) => r.set(w, l));
1732
1737
  }), {
1733
1738
  clear: () => {
1734
- const { width: c, height: m } = o;
1735
- i.clearRect(-0.5, -0.5, c + 1, m + 1);
1739
+ const { width: l, height: m } = o;
1740
+ i.clearRect(-0.5, -0.5, l + 1, m + 1);
1736
1741
  },
1737
1742
  destroy: () => {
1738
1743
  o.remove();
1739
1744
  },
1740
- paint: (c, m, p) => {
1745
+ paint: (l, m, p) => {
1741
1746
  n.font && (i.font = n.font);
1742
- const w = r.get(c.annotation.id);
1747
+ const w = r.get(l.annotation.id);
1743
1748
  if (w) {
1744
- const { height: v } = c.rects[0], h = c.rects[0].x + m.left, d = c.rects[0].y + m.top;
1749
+ const { height: v } = l.rects[0], h = l.rects[0].x + m.left, d = l.rects[0].y + m.top;
1745
1750
  i.fillStyle = w.appearance.color, i.fillRect(h - 2, d - 2.5, 2, v + 5);
1746
- const l = i.measureText(w.appearance.label), y = l.width + 6, T = l.actualBoundingBoxAscent + l.actualBoundingBoxDescent + 8, C = l.fontBoundingBoxAscent ? 8 : 6.5;
1751
+ const c = i.measureText(w.appearance.label), y = c.width + 6, T = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, C = c.fontBoundingBoxAscent ? 8 : 6.5;
1747
1752
  return i.fillRect(h - 2, d - 2.5 - T, y, T), i.fillStyle = "#fff", i.fillText(w.appearance.label, h + 1, d - C), {
1748
1753
  fill: w.appearance.color,
1749
1754
  fillOpacity: p ? 0.45 : 0.18
@@ -1752,8 +1757,8 @@ const xn = (t, e) => {
1752
1757
  },
1753
1758
  reset: () => {
1754
1759
  o.width = 2 * window.innerWidth, o.height = 2 * window.innerHeight;
1755
- const c = o.getContext("2d");
1756
- c.scale(2, 2), c.translate(0.5, 0.5);
1760
+ const l = o.getContext("2d");
1761
+ l.scale(2, 2), l.translate(0.5, 0.5);
1757
1762
  }
1758
1763
  };
1759
1764
  }, Ht = (t) => {
@@ -1761,9 +1766,9 @@ const xn = (t, e) => {
1761
1766
  return document.scrollingElement;
1762
1767
  const { overflowY: e } = window.getComputedStyle(t);
1763
1768
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Ht(t.parentElement);
1764
- }, Cn = (t, e) => (n) => {
1769
+ }, Tn = (t, e) => (n) => {
1765
1770
  const o = (r) => {
1766
- const a = i.getBoundingClientRect(), s = i.clientHeight, u = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: b, height: c } = e.getAnnotationBounds(n.id), m = f.top - a.top, p = f.left - a.left, w = i.parentElement ? i.scrollTop : 0, v = i.parentElement ? i.scrollLeft : 0, h = m + w - (s - c) / 2, d = p + v - (u - b) / 2;
1771
+ const a = i.getBoundingClientRect(), s = i.clientHeight, u = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: b, height: l } = e.getAnnotationBounds(n.id), m = f.top - a.top, p = f.left - a.left, w = i.parentElement ? i.scrollTop : 0, v = i.parentElement ? i.scrollLeft : 0, h = m + w - (s - l) / 2, d = p + v - (u - b) / 2;
1767
1772
  i.scroll({ top: h, left: d, behavior: "smooth" });
1768
1773
  }, i = Ht(t);
1769
1774
  if (i) {
@@ -1777,37 +1782,37 @@ const xn = (t, e) => {
1777
1782
  }
1778
1783
  }
1779
1784
  return !1;
1780
- }, Tn = (t, e) => ({
1785
+ }, Rn = (t, e) => ({
1781
1786
  ...t,
1782
1787
  annotationEnabled: t.annotationEnabled === void 0 ? e.annotationEnabled : t.annotationEnabled
1783
- }), Rn = (t, e, n, o) => {
1788
+ }), Nn = (t, e, n, o) => {
1784
1789
  const { store: i, selection: r } = e;
1785
1790
  let a, s;
1786
1791
  const u = (h) => a = h;
1787
1792
  let f = !1, b;
1788
- const c = (h) => {
1789
- var l;
1793
+ const l = (h) => {
1794
+ var c;
1790
1795
  if (!f)
1791
1796
  return;
1792
- !((l = h.target.parentElement) != null && l.closest(H)) ? s = {
1797
+ !((c = h.target.parentElement) != null && c.closest(k)) ? s = {
1793
1798
  annotation: Xt(),
1794
1799
  selector: [],
1795
1800
  creator: a,
1796
1801
  created: /* @__PURE__ */ new Date()
1797
1802
  } : s = void 0;
1798
1803
  };
1799
- n && t.addEventListener("selectstart", c);
1804
+ n && t.addEventListener("selectstart", l);
1800
1805
  const m = ft((h) => {
1801
1806
  const d = document.getSelection();
1802
- if (h.timeStamp - ((b == null ? void 0 : b.timeStamp) || h.timeStamp) < 1e3 && !s && c(b), d.isCollapsed || !f || !s)
1807
+ if (h.timeStamp - ((b == null ? void 0 : b.timeStamp) || h.timeStamp) < 1e3 && !s && l(b), d.isCollapsed || !f || !s)
1803
1808
  return;
1804
- const l = d.getRangeAt(0), y = ie(l.cloneRange()), T = Kt(y);
1809
+ const c = d.getRangeAt(0), y = re(c.cloneRange()), T = Kt(y);
1805
1810
  (T.length !== s.selector.length || T.some((E, R) => {
1806
1811
  var g;
1807
1812
  return E.toString() !== ((g = s.selector[R]) == null ? void 0 : g.quote);
1808
1813
  })) && (s = {
1809
1814
  ...s,
1810
- selector: T.map((E) => oe(E, t, o))
1815
+ selector: T.map((E) => ie(E, t, o))
1811
1816
  }, i.getAnnotation(s.annotation) ? i.updateTarget(s, L.LOCAL) : (i.addAnnotation({
1812
1817
  id: s.annotation,
1813
1818
  bodies: [],
@@ -1816,15 +1821,15 @@ const xn = (t, e) => {
1816
1821
  });
1817
1822
  n && document.addEventListener("selectionchange", m);
1818
1823
  const p = (h) => {
1819
- const { target: d, timeStamp: l, offsetX: y, offsetY: T, type: C } = h;
1820
- b = { ...h, target: d, timeStamp: l, offsetX: y, offsetY: T, type: C }, f = h.button === 0;
1824
+ const { target: d, timeStamp: c, offsetX: y, offsetY: T, type: C } = h;
1825
+ b = { ...h, target: d, timeStamp: c, offsetX: y, offsetY: T, type: C }, f = h.button === 0;
1821
1826
  };
1822
1827
  t.addEventListener("pointerdown", p);
1823
1828
  const w = (h) => {
1824
1829
  var T;
1825
- if (!!((T = h.target.parentElement) != null && T.closest(H)) || !f)
1830
+ if (!!((T = h.target.parentElement) != null && T.closest(k)) || !f)
1826
1831
  return;
1827
- const l = () => {
1832
+ const c = () => {
1828
1833
  const { x: C, y: E } = t.getBoundingClientRect(), R = i.getAt(h.clientX - C, h.clientY - E);
1829
1834
  if (R) {
1830
1835
  const { selected: g } = r;
@@ -1832,34 +1837,34 @@ const xn = (t, e) => {
1832
1837
  } else
1833
1838
  r.isEmpty() || r.clear();
1834
1839
  }, y = h.timeStamp - b.timeStamp;
1835
- document.getSelection().isCollapsed && y < 300 ? (s = void 0, l()) : s && r.clickSelect(s.annotation, h);
1840
+ document.getSelection().isCollapsed && y < 300 ? (s = void 0, c()) : s && r.clickSelect(s.annotation, h);
1836
1841
  };
1837
1842
  return document.addEventListener("pointerup", w), {
1838
1843
  destroy: () => {
1839
- t.removeEventListener("selectstart", c), document.removeEventListener("selectionchange", m), t.removeEventListener("pointerdown", p), document.removeEventListener("pointerup", w);
1844
+ t.removeEventListener("selectstart", l), document.removeEventListener("selectionchange", m), t.removeEventListener("pointerdown", p), document.removeEventListener("pointerup", w);
1840
1845
  },
1841
1846
  setUser: u
1842
1847
  };
1843
- }, Ot = "SPANS", In = (t, e = {}) => {
1844
- t.addEventListener("click", (E) => !E.target.closest("a") && E.preventDefault());
1845
- const n = Tn(e, {
1848
+ }, Ot = "SPANS", Mn = (t, e = {}) => {
1849
+ Qt(t);
1850
+ const n = Rn(e, {
1846
1851
  annotationEnabled: !0
1847
- }), o = An(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = je(a), u = Ke(o, s, n.adapter);
1848
- let f = rn();
1849
- const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Ot : n.renderer || Ot, c = b === "SPANS" ? Ee(t, o, r) : b === "CSS_HIGHLIGHTS" ? we(t, o, r) : b === "CANVAS" ? de(t, o, r) : void 0;
1850
- if (!c)
1852
+ }), o = En(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Ge(a), u = Qe(o, s, n.adapter);
1853
+ let f = sn();
1854
+ const b = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : Ot : n.renderer || Ot, l = b === "SPANS" ? Se(t, o, r) : b === "CSS_HIGHLIGHTS" ? xe(t, o, r) : b === "CANVAS" ? ue(t, o, r) : void 0;
1855
+ if (!l)
1851
1856
  throw `Unknown renderer implementation: ${b}`;
1852
- console.debug(`Using ${b} renderer`), n.style && c.setStyle(n.style);
1853
- const m = Rn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1857
+ console.debug(`Using ${b} renderer`), n.style && l.setStyle(n.style);
1858
+ const m = Nn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1854
1859
  return m.setUser(f), {
1855
- ...Je(o, s, n.adapter),
1860
+ ...Ze(o, s, n.adapter),
1856
1861
  destroy: () => {
1857
- c.destroy(), m.destroy(), s.destroy();
1862
+ l.destroy(), m.destroy(), s.destroy();
1858
1863
  },
1859
1864
  element: t,
1860
1865
  getUser: () => f,
1861
- setFilter: (E) => c.setFilter(E),
1862
- setStyle: (E) => c.setStyle(E),
1866
+ setFilter: (E) => l.setFilter(E),
1867
+ setStyle: (E) => l.setStyle(E),
1863
1868
  setUser: (E) => {
1864
1869
  f = E, m.setUser(E);
1865
1870
  },
@@ -1867,46 +1872,47 @@ const xn = (t, e) => {
1867
1872
  E ? i.setSelected(E) : i.clear();
1868
1873
  },
1869
1874
  setPresenceProvider: (E) => {
1870
- E && (c.setPainter(Sn(t, E, n.presence)), E.on("selectionChange", () => c.redraw()));
1875
+ E && (l.setPainter(Cn(t, E, n.presence)), E.on("selectionChange", () => l.redraw()));
1871
1876
  },
1872
- setVisible: (E) => c.setVisible(E),
1877
+ setVisible: (E) => l.setVisible(E),
1873
1878
  on: u.on,
1874
1879
  off: u.off,
1875
- scrollIntoView: Cn(t, a),
1880
+ scrollIntoView: Tn(t, a),
1876
1881
  state: o
1877
1882
  };
1878
1883
  };
1879
1884
  export {
1880
1885
  et as DEFAULT_SELECTED_STYLE,
1881
- Y as DEFAULT_STYLE,
1886
+ H as DEFAULT_STYLE,
1882
1887
  It as NOT_ANNOTATABLE_CLASS,
1883
- H as NOT_ANNOTATABLE_SELECTOR,
1888
+ k as NOT_ANNOTATABLE_SELECTOR,
1884
1889
  L as Origin,
1885
- Be as PointerSelectAction,
1886
- On as W3CTextFormat,
1887
- Bn as createBody,
1888
- de as createCanvasRenderer,
1889
- we as createHighlightsRenderer,
1890
- ye as createRenderer,
1891
- Ee as createSpansRenderer,
1892
- In as createTextAnnotator,
1893
- An as createTextAnnotatorState,
1890
+ Oe as PointerSelectAction,
1891
+ In as W3CTextFormat,
1892
+ Qt as cancelSingleClickEvents,
1893
+ On as createBody,
1894
+ ue as createCanvasRenderer,
1895
+ xe as createHighlightsRenderer,
1896
+ we as createRenderer,
1897
+ Se as createSpansRenderer,
1898
+ Mn as createTextAnnotator,
1899
+ En as createTextAnnotatorState,
1894
1900
  ft as debounce,
1895
- Tn as fillDefaults,
1896
- Nn as getAnnotatableFragment,
1897
- Ln as getClientRectsPonyfill,
1898
- Zt as getQuoteContext,
1901
+ Rn as fillDefaults,
1902
+ Ln as getAnnotatableFragment,
1903
+ Bn as getClientRectsPonyfill,
1904
+ te as getQuoteContext,
1899
1905
  ut as getRangeAnnotatableContents,
1900
- k as isRevived,
1901
- ne as mergeClientRects,
1906
+ Y as isRevived,
1907
+ oe as mergeClientRects,
1902
1908
  qt as paint,
1903
- un as parseW3CTextAnnotation,
1904
- oe as rangeToSelector,
1909
+ hn as parseW3CTextAnnotation,
1910
+ ie as rangeToSelector,
1905
1911
  ot as reviveAnnotation,
1906
1912
  Mt as reviveSelector,
1907
1913
  nt as reviveTarget,
1908
- hn as serializeW3CTextAnnotation,
1914
+ fn as serializeW3CTextAnnotation,
1909
1915
  Kt as splitAnnotatableRanges,
1910
- ie as trimRange
1916
+ re as trimRange
1911
1917
  };
1912
1918
  //# sourceMappingURL=text-annotator.es.js.map