@recogito/text-annotator 3.0.0-rc.52 → 3.0.0-rc.54

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.
@@ -7,7 +7,7 @@ const re = "not-annotatable", tt = `.${re}`, it = (t) => {
7
7
  }, Le = (t) => t.addEventListener("click", (e) => {
8
8
  // Allow clicks within not-annotatable elements
9
9
  !e.target.closest(tt) && !e.target.closest("a") && e.preventDefault();
10
- }), At = (t) => ({
10
+ }), xt = (t) => ({
11
11
  ...t,
12
12
  type: t.type,
13
13
  x: t.x,
@@ -56,7 +56,7 @@ const re = "not-annotatable", tt = `.${re}`, it = (t) => {
56
56
  return (...o) => {
57
57
  clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
58
58
  };
59
- }, Me = function* (t) {
59
+ }, Be = function* (t) {
60
60
  const e = document.createNodeIterator(
61
61
  t.commonAncestorContainer,
62
62
  NodeFilter.SHOW_ELEMENT,
@@ -65,11 +65,11 @@ const re = "not-annotatable", tt = `.${re}`, it = (t) => {
65
65
  let n;
66
66
  for (; n = e.nextNode(); )
67
67
  n instanceof HTMLElement && (yield n);
68
- }, Be = (t) => {
68
+ }, Me = (t) => {
69
69
  if (!Ce(t)) return [];
70
70
  const e = [];
71
71
  let n = null;
72
- for (const o of Me(t)) {
72
+ for (const o of Be(t)) {
73
73
  let i;
74
74
  n ? (i = document.createRange(), i.setStartAfter(n), i.setEndBefore(o)) : (i = t.cloneRange(), i.setEndBefore(o)), i.collapsed || e.push(i), n = o;
75
75
  }
@@ -78,18 +78,18 @@ const re = "not-annotatable", tt = `.${re}`, it = (t) => {
78
78
  o.setStartAfter(n), o.collapsed || e.push(o);
79
79
  }
80
80
  return e.length > 0 ? e : [t];
81
- }, Nt = (t) => {
81
+ }, Ut = (t) => {
82
82
  const e = t.cloneContents();
83
83
  return e.querySelectorAll(tt).forEach((n) => n.remove()), e;
84
84
  }, Re = (t, e, n = 10, o) => {
85
85
  const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
86
86
  s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
87
- const a = Nt(s).textContent, r = document.createRange();
87
+ const a = Ut(s).textContent, r = document.createRange();
88
88
  r.setStart(t.endContainer, t.endOffset), i === document.body ? r.setEnd(i, i.childNodes.length) : r.setEndAfter(i);
89
- const l = Nt(r).textContent;
89
+ const d = Ut(r).textContent;
90
90
  return {
91
91
  prefix: a.substring(a.length - n),
92
- suffix: l.substring(0, n)
92
+ suffix: d.substring(0, n)
93
93
  };
94
94
  }, F = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ke = /^\s*$/, Ie = (t) => ke.test(t.toString()), _e = (t, e) => {
95
95
  const n = (s) => Math.round(s * 10) / 10, o = {
@@ -139,53 +139,60 @@ const re = "not-annotatable", tt = `.${re}`, it = (t) => {
139
139
  }
140
140
  }
141
141
  return i ? o : [...o, n];
142
- }, []), Ve = (t, e, n) => {
142
+ }, []), wo = (t) => ({
143
+ length: t.length,
144
+ item: (e) => t[e],
145
+ [Symbol.iterator]: function* () {
146
+ for (let e = 0; e < this.length; e++)
147
+ yield this.item(e);
148
+ }
149
+ }), Ve = (t, e, n) => {
143
150
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
144
151
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
145
- const s = Nt(o).textContent, a = t.toString(), r = s.length || 0, l = r + a.length;
146
- return n ? { quote: a, start: r, end: l, range: t, offsetReference: i } : { quote: a, start: r, end: l, range: t };
152
+ const s = Ut(o).textContent, a = t.toString(), r = s.length || 0, d = r + a.length;
153
+ return n ? { quote: a, start: r, end: d, range: t, offsetReference: i } : { quote: a, start: r, end: d, range: t };
147
154
  }, ae = (t, e) => {
148
155
  var h, u;
149
156
  const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
150
157
  e,
151
158
  NodeFilter.SHOW_TEXT,
152
- (p) => {
153
- var g;
154
- return (g = p.parentElement) != null && g.closest(tt) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
159
+ (g) => {
160
+ var v;
161
+ return (v = g.parentElement) != null && v.closest(tt) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
155
162
  }
156
163
  );
157
164
  let a = 0;
158
165
  const r = document.createRange();
159
- let l = s.nextNode();
160
- l === null && console.error("Could not revive annotation target. Content missing.");
166
+ let d = s.nextNode();
167
+ d === null && console.error("Could not revive annotation target. Content missing.");
161
168
  let f = !i;
162
- for (; l !== null; ) {
163
- if (f || (f = i == null ? void 0 : i.contains(l)), f) {
164
- const p = ((h = l.textContent) == null ? void 0 : h.length) || 0;
165
- if (a + p > n) {
166
- r.setStart(l, n - a);
169
+ for (; d !== null; ) {
170
+ if (f || (f = i == null ? void 0 : i.contains(d)), f) {
171
+ const g = ((h = d.textContent) == null ? void 0 : h.length) || 0;
172
+ if (a + g > n) {
173
+ r.setStart(d, n - a);
167
174
  break;
168
175
  }
169
- a += p;
176
+ a += g;
170
177
  }
171
- l = s.nextNode();
178
+ d = s.nextNode();
172
179
  }
173
- for (; l !== null; ) {
174
- const p = ((u = l.textContent) == null ? void 0 : u.length) || 0;
175
- if (a + p >= o) {
176
- r.setEnd(l, o - a);
180
+ for (; d !== null; ) {
181
+ const g = ((u = d.textContent) == null ? void 0 : u.length) || 0;
182
+ if (a + g >= o) {
183
+ r.setEnd(d, o - a);
177
184
  break;
178
185
  }
179
- a += p, l = s.nextNode();
186
+ a += g, d = s.nextNode();
180
187
  }
181
188
  return {
182
189
  ...t,
183
190
  range: r
184
191
  };
185
- }, bt = (t, e) => F(t.selector) ? t : {
192
+ }, wt = (t, e) => F(t.selector) ? t : {
186
193
  ...t,
187
194
  selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : ae(n, e))
188
- }, xt = (t, e) => F(t.target.selector) ? t : { ...t, target: bt(t.target, e) }, Ye = (t, e) => {
195
+ }, vt = (t, e) => F(t.target.selector) ? t : { ...t, target: wt(t.target, e) }, Ye = (t, e) => {
189
196
  const n = t.cloneRange();
190
197
  return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
191
198
  }, ce = (t) => {
@@ -193,83 +200,83 @@ const re = "not-annotatable", tt = `.${re}`, it = (t) => {
193
200
  return document.scrollingElement;
194
201
  const { overflowY: e } = window.getComputedStyle(t);
195
202
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ce(t.parentElement);
196
- }, Ke = (t, e) => (n) => {
203
+ }, De = (t, e) => (n) => {
197
204
  const o = typeof n == "string" ? n : n.id, i = (a) => {
198
- const r = s.getBoundingClientRect(), l = s.clientHeight, f = s.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: u, height: p } = e.getAnnotationBounds(o), g = h.top - r.top, b = h.left - r.left, w = s.parentElement ? s.scrollTop : 0, y = s.parentElement ? s.scrollLeft : 0, d = g + w - (l - p) / 2, c = b + y - (f - u) / 2;
199
- s.scroll({ top: d, left: c, behavior: "smooth" });
205
+ const r = s.getBoundingClientRect(), d = s.clientHeight, f = s.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: u, height: g } = e.getAnnotationBounds(o), v = h.top - r.top, p = h.left - r.left, y = s.parentElement ? s.scrollTop : 0, x = s.parentElement ? s.scrollLeft : 0, l = v + y - (d - g) / 2, c = p + x - (f - u) / 2;
206
+ s.scroll({ top: l, left: c, behavior: "smooth" });
200
207
  }, s = ce(t);
201
208
  if (s) {
202
209
  const a = e.getAnnotation(o), { range: r } = a.target.selector[0];
203
210
  if (r && !r.collapsed)
204
211
  return i(a.target), !0;
205
212
  {
206
- const l = bt(a.target, t), { range: f } = l.selector[0];
213
+ const d = wt(a.target, t), { range: f } = d.selector[0];
207
214
  if (f && !f.collapsed)
208
- return i(l), !0;
215
+ return i(d), !0;
209
216
  }
210
217
  }
211
218
  return !1;
212
219
  }, W = {
213
220
  fill: "rgb(0, 128, 255)",
214
221
  fillOpacity: 0.18
215
- }, wt = {
222
+ }, At = {
216
223
  fill: "rgb(0, 128, 255)",
217
224
  fillOpacity: 0.45
218
- }, De = (t, e, n, o, i) => {
225
+ }, Ke = (t, e, n, o, i) => {
219
226
  var a, r;
220
- const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? wt : W) : n : (r = t.state) != null && r.selected ? wt : W;
227
+ const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? At : W) : n : (r = t.state) != null && r.selected ? At : W;
221
228
  return o && o.paint(t, e) || s;
222
229
  }, Xe = (t) => {
223
- const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n, l = i - e;
224
- return { top: e, left: n, minX: s, minY: a, maxX: r, maxY: l };
230
+ const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n, d = i - e;
231
+ return { top: e, left: n, minX: s, minY: a, maxX: r, maxY: d };
225
232
  }, Pe = (t) => {
226
233
  let e = /* @__PURE__ */ new Set();
227
234
  return (o) => {
228
235
  const i = o.map((s) => s.id);
229
236
  (e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
230
237
  };
231
- }, Kt = (t, e, n, o) => {
238
+ }, Dt = (t, e, n, o) => {
232
239
  const { store: i, selection: s, hover: a } = e;
233
- let r, l, f;
234
- const h = Pe(n), u = (M) => {
235
- const { x: L, y: m } = t.getBoundingClientRect(), v = i.getAt(M.clientX - L, M.clientY - m, !1, l);
236
- v ? a.current !== v.id && (t.classList.add("hovered"), a.set(v.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
240
+ let r, d, f;
241
+ const h = Pe(n), u = (B) => {
242
+ const { x: T, y: m } = t.getBoundingClientRect(), A = i.getAt(B.clientX - T, B.clientY - m, !1, d);
243
+ A ? a.current !== A.id && (t.classList.add("hovered"), a.set(A.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
237
244
  };
238
245
  t.addEventListener("pointermove", u);
239
- const p = (M = !1) => {
246
+ const g = (B = !1) => {
240
247
  f && f.clear();
241
- const L = Xe(t), { minX: m, minY: v, maxX: x, maxY: C } = L, B = l ? i.getIntersecting(m, v, x, C).filter(({ annotation: U }) => l(U)) : i.getIntersecting(m, v, x, C), R = s.selected.map(({ id: U }) => U), N = B.map(({ annotation: U, rects: et }) => {
248
+ const T = Xe(t), { minX: m, minY: A, maxX: w, maxY: L } = T, M = d ? i.getIntersecting(m, A, w, L).filter(({ annotation: U }) => d(U)) : i.getIntersecting(m, A, w, L), R = s.selected.map(({ id: U }) => U), N = M.map(({ annotation: U, rects: et }) => {
242
249
  const q = R.includes(U.id), Se = U.id === a.current;
243
250
  return { annotation: U, rects: et, state: { selected: q, hover: Se } };
244
251
  });
245
- o.redraw(N, L, r, f, M), setTimeout(() => h(B.map(({ annotation: U }) => U)), 1);
246
- }, g = (M) => {
247
- f = M, p();
248
- }, b = (M) => {
249
- r = M, p();
250
- }, w = (M) => {
251
- l = M, p(!1);
252
- }, y = () => p();
253
- i.observe(y);
254
- const d = s.subscribe(() => p()), c = () => p(!0);
252
+ o.redraw(N, T, r, f, B), setTimeout(() => h(M.map(({ annotation: U }) => U)), 1);
253
+ }, v = (B) => {
254
+ f = B, g();
255
+ }, p = (B) => {
256
+ r = B, g();
257
+ }, y = (B) => {
258
+ d = B, g(!1);
259
+ }, x = () => g();
260
+ i.observe(x);
261
+ const l = s.subscribe(() => g()), c = () => g(!0);
255
262
  document.addEventListener("scroll", c, { capture: !0, passive: !0 });
256
- const A = Yt(() => {
257
- i.recalculatePositions(), f && f.reset(), p();
263
+ const b = Yt(() => {
264
+ i.recalculatePositions(), f && f.reset(), g();
258
265
  });
259
- window.addEventListener("resize", A);
260
- const E = new ResizeObserver(A);
261
- E.observe(t);
262
- const T = { attributes: !0, childList: !0, subtree: !0 }, S = new MutationObserver((M) => {
263
- M.every((m) => m.target === t || t.contains(m.target)) || p(!0);
266
+ window.addEventListener("resize", b);
267
+ const S = new ResizeObserver(b);
268
+ S.observe(t);
269
+ const E = { attributes: !0, childList: !0, subtree: !0 }, C = new MutationObserver((B) => {
270
+ B.every((m) => m.target === t || t.contains(m.target)) || g(!0);
264
271
  });
265
- return S.observe(document.body, T), {
272
+ return C.observe(document.body, E), {
266
273
  destroy: () => {
267
- t.removeEventListener("pointermove", u), o.destroy(), i.unobserve(y), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", A), E.disconnect(), S.disconnect();
274
+ t.removeEventListener("pointermove", u), o.destroy(), i.unobserve(x), l(), document.removeEventListener("scroll", c), window.removeEventListener("resize", b), S.disconnect(), C.disconnect();
268
275
  },
269
- redraw: p,
270
- setStyle: b,
271
- setFilter: w,
272
- setPainter: g,
276
+ redraw: g,
277
+ setStyle: p,
278
+ setFilter: y,
279
+ setPainter: v,
273
280
  setVisible: o.setVisible
274
281
  };
275
282
  }, $e = () => {
@@ -281,28 +288,28 @@ const re = "not-annotatable", tt = `.${re}`, it = (t) => {
281
288
  t.classList.add("r6o-annotatable");
282
289
  const e = $e(), n = e.getContext("2d");
283
290
  document.body.appendChild(e);
284
- const o = (r, l, f, h) => requestAnimationFrame(() => {
285
- const { width: u, height: p } = e;
286
- n.clearRect(-0.5, -0.5, u + 1, p + 1), h && h.clear();
287
- const { top: g, left: b } = l;
288
- [...r].sort((y, d) => {
289
- const { annotation: { target: { created: c } } } = y, { annotation: { target: { created: A } } } = d;
290
- return c.getTime() - A.getTime();
291
- }).forEach((y) => {
292
- var E;
293
- const d = f ? typeof f == "function" ? f(y.annotation, y.state) : f : (E = y.state) != null && E.selected ? wt : W, c = h && h.paint(y, l) || d, A = y.rects.map(({ x: T, y: S, width: O, height: M }) => ({
294
- x: T + b,
295
- y: S + g,
291
+ const o = (r, d, f, h) => requestAnimationFrame(() => {
292
+ const { width: u, height: g } = e;
293
+ n.clearRect(-0.5, -0.5, u + 1, g + 1), h && h.clear();
294
+ const { top: v, left: p } = d;
295
+ [...r].sort((x, l) => {
296
+ const { annotation: { target: { created: c } } } = x, { annotation: { target: { created: b } } } = l;
297
+ return c.getTime() - b.getTime();
298
+ }).forEach((x) => {
299
+ var S;
300
+ const l = f ? typeof f == "function" ? f(x.annotation, x.state) : f : (S = x.state) != null && S.selected ? At : W, c = h && h.paint(x, d) || l, b = x.rects.map(({ x: E, y: C, width: O, height: B }) => ({
301
+ x: E + p,
302
+ y: C + v,
296
303
  width: O,
297
- height: M
304
+ height: B
298
305
  }));
299
- if (n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1, A.forEach(
300
- ({ x: T, y: S, width: O, height: M }) => n.fillRect(T, S, O, M)
306
+ if (n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1, b.forEach(
307
+ ({ x: E, y: C, width: O, height: B }) => n.fillRect(E, C, O, B)
301
308
  ), c.underlineColor) {
302
309
  n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
303
- const T = c.underlineOffset ?? 0;
304
- A.forEach(({ x: S, y: O, width: M, height: L }) => {
305
- n.beginPath(), n.moveTo(S, O + L + T), n.lineTo(S + M, O + L + T), n.stroke();
310
+ const E = c.underlineOffset ?? 0;
311
+ b.forEach(({ x: C, y: O, width: B, height: T }) => {
312
+ n.beginPath(), n.moveTo(C, O + T + E), n.lineTo(C + B, O + T + E), n.stroke();
306
313
  });
307
314
  }
308
315
  });
@@ -318,7 +325,7 @@ const re = "not-annotatable", tt = `.${re}`, it = (t) => {
318
325
  },
319
326
  redraw: o
320
327
  };
321
- }, ze = (t, e, n) => Kt(t, e, n, je(t));
328
+ }, ze = (t, e, n) => Dt(t, e, n, je(t));
322
329
  var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, j = function(t) {
323
330
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
324
331
  }, V = function(t, e, n) {
@@ -329,7 +336,7 @@ var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, j = function(t) {
329
336
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
330
337
  }, Pt = function(t) {
331
338
  return { r: X(t.r, 0, 255), g: X(t.g, 0, 255), b: X(t.b, 0, 255), a: X(t.a) };
332
- }, vt = function(t) {
339
+ }, Et = function(t) {
333
340
  return { r: V(t.r), g: V(t.g), b: V(t.b), a: V(t.a, 3) };
334
341
  }, We = /^#([0-9a-f]{3,8})$/i, ht = function(t) {
335
342
  var e = t.toString(16);
@@ -340,8 +347,8 @@ var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, j = function(t) {
340
347
  }, ue = function(t) {
341
348
  var e = t.h, n = t.s, o = t.v, i = t.a;
342
349
  e = e / 360 * 6, n /= 100, o /= 100;
343
- var s = Math.floor(e), a = o * (1 - n), r = o * (1 - (e - s) * n), l = o * (1 - (1 - e + s) * n), f = s % 6;
344
- return { r: 255 * [o, r, a, a, l, o][f], g: 255 * [l, o, o, r, a, a][f], b: 255 * [a, a, l, o, o, r][f], a: i };
350
+ var s = Math.floor(e), a = o * (1 - n), r = o * (1 - (e - s) * n), d = o * (1 - (1 - e + s) * n), f = s % 6;
351
+ return { r: 255 * [o, r, a, a, d, o][f], g: 255 * [d, o, o, r, a, a][f], b: 255 * [a, a, d, o, o, r][f], a: i };
345
352
  }, $t = function(t) {
346
353
  return { h: le(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
347
354
  }, Ht = function(t) {
@@ -386,10 +393,10 @@ var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, j = function(t) {
386
393
  return [null, void 0];
387
394
  }, Ze = function(t) {
388
395
  return typeof t == "string" ? Ft(t.trim(), zt.string) : typeof t == "object" && t !== null ? Ft(t, zt.object) : [null, void 0];
389
- }, Et = function(t, e) {
396
+ }, St = function(t, e) {
390
397
  var n = at(t);
391
398
  return { h: n.h, s: X(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
392
- }, St = function(t) {
399
+ }, Ct = function(t) {
393
400
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
394
401
  }, Wt = function(t, e) {
395
402
  var n = at(t);
@@ -401,18 +408,18 @@ var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, j = function(t) {
401
408
  return t.prototype.isValid = function() {
402
409
  return this.parsed !== null;
403
410
  }, t.prototype.brightness = function() {
404
- return V(St(this.rgba), 2);
411
+ return V(Ct(this.rgba), 2);
405
412
  }, t.prototype.isDark = function() {
406
- return St(this.rgba) < 0.5;
413
+ return Ct(this.rgba) < 0.5;
407
414
  }, t.prototype.isLight = function() {
408
- return St(this.rgba) >= 0.5;
415
+ return Ct(this.rgba) >= 0.5;
409
416
  }, t.prototype.toHex = function() {
410
- return e = vt(this.rgba), n = e.r, o = e.g, i = e.b, a = (s = e.a) < 1 ? ht(V(255 * s)) : "", "#" + ht(n) + ht(o) + ht(i) + a;
417
+ return e = Et(this.rgba), n = e.r, o = e.g, i = e.b, a = (s = e.a) < 1 ? ht(V(255 * s)) : "", "#" + ht(n) + ht(o) + ht(i) + a;
411
418
  var e, n, o, i, s, a;
412
419
  }, t.prototype.toRgb = function() {
413
- return vt(this.rgba);
420
+ return Et(this.rgba);
414
421
  }, t.prototype.toRgbString = function() {
415
- return e = vt(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
422
+ return e = Et(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
416
423
  var e, n, o, i, s;
417
424
  }, t.prototype.toHsl = function() {
418
425
  return Ht(at(this.rgba));
@@ -426,11 +433,11 @@ var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, j = function(t) {
426
433
  return $({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
427
434
  var e;
428
435
  }, t.prototype.saturate = function(e) {
429
- return e === void 0 && (e = 0.1), $(Et(this.rgba, e));
436
+ return e === void 0 && (e = 0.1), $(St(this.rgba, e));
430
437
  }, t.prototype.desaturate = function(e) {
431
- return e === void 0 && (e = 0.1), $(Et(this.rgba, -e));
438
+ return e === void 0 && (e = 0.1), $(St(this.rgba, -e));
432
439
  }, t.prototype.grayscale = function() {
433
- return $(Et(this.rgba, -1));
440
+ return $(St(this.rgba, -1));
434
441
  }, t.prototype.lighten = function(e) {
435
442
  return e === void 0 && (e = 0.1), $(Wt(this.rgba, e));
436
443
  }, t.prototype.darken = function(e) {
@@ -466,25 +473,25 @@ const tn = (t) => [
466
473
  setVisible: (s) => {
467
474
  console.log("setVisible not implemented on CSS Custom Highlights renderer");
468
475
  },
469
- redraw: (s, a, r, l) => {
470
- l && l.clear();
476
+ redraw: (s, a, r, d) => {
477
+ d && d.clear();
471
478
  const f = new Set(s.map((u) => u.annotation.id));
472
479
  Array.from(e).filter((u) => !f.has(u));
473
480
  const h = s.map((u) => {
474
- var b;
475
- const p = r ? typeof r == "function" ? r(u.annotation, u.state) : r : (b = u.state) != null && b.selected ? wt : W, g = l && l.paint(u, a) || p;
476
- return `::highlight(_${u.annotation.id}) { ${tn(g)} }`;
481
+ var p;
482
+ const g = r ? typeof r == "function" ? r(u.annotation, u.state) : r : (p = u.state) != null && p.selected ? At : W, v = d && d.paint(u, a) || g;
483
+ return `::highlight(_${u.annotation.id}) { ${tn(v)} }`;
477
484
  });
478
485
  t.innerHTML = h.join(`
479
486
  `), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
480
- const p = u.target.selector.map((b) => b.range), g = new Highlight(...p);
481
- CSS.highlights.set(`_${u.id}`, g);
487
+ const g = u.target.selector.map((p) => p.range), v = new Highlight(...g);
488
+ CSS.highlights.set(`_${u.id}`, v);
482
489
  }), e = f;
483
490
  }
484
491
  };
485
- }, nn = (t, e, n) => Kt(t, e, n, en());
492
+ }, nn = (t, e, n) => Dt(t, e, n, en());
486
493
  var Gt = Object.prototype.hasOwnProperty;
487
- function Ut(t, e) {
494
+ function Vt(t, e) {
488
495
  var n, o;
489
496
  if (t === e) return !0;
490
497
  if (t && e && (n = t.constructor) === e.constructor) {
@@ -492,13 +499,13 @@ function Ut(t, e) {
492
499
  if (n === RegExp) return t.toString() === e.toString();
493
500
  if (n === Array) {
494
501
  if ((o = t.length) === e.length)
495
- for (; o-- && Ut(t[o], e[o]); ) ;
502
+ for (; o-- && Vt(t[o], e[o]); ) ;
496
503
  return o === -1;
497
504
  }
498
505
  if (!n || typeof t == "object") {
499
506
  o = 0;
500
507
  for (n in t)
501
- if (Gt.call(t, n) && ++o && !Gt.call(e, n) || !(n in e) || !Ut(t[n], e[n])) return !1;
508
+ if (Gt.call(t, n) && ++o && !Gt.call(e, n) || !(n in e) || !Vt(t[n], e[n])) return !1;
502
509
  return Object.keys(e).length === o;
503
510
  }
504
511
  }
@@ -516,18 +523,18 @@ const on = (t, e) => {
516
523
  destroy: () => {
517
524
  e.remove();
518
525
  },
519
- redraw: (a, r, l, f, h) => {
520
- const p = !(Ut(n, a) && h);
521
- if (!f && !p) return;
522
- p && (e.innerHTML = ""), [...a].sort((b, w) => {
523
- const { annotation: { target: { created: y } } } = b, { annotation: { target: { created: d } } } = w;
524
- return y && d ? y.getTime() - d.getTime() : 0;
525
- }).forEach((b) => {
526
- b.rects.map((w) => {
527
- const y = on(w, a), d = De(b, r, l, f, y);
528
- if (p) {
526
+ redraw: (a, r, d, f, h) => {
527
+ const g = !(Vt(n, a) && h);
528
+ if (!f && !g) return;
529
+ g && (e.innerHTML = ""), [...a].sort((p, y) => {
530
+ const { annotation: { target: { created: x } } } = p, { annotation: { target: { created: l } } } = y;
531
+ return x && l ? x.getTime() - l.getTime() : 0;
532
+ }).forEach((p) => {
533
+ p.rects.map((y) => {
534
+ const x = on(y, a), l = Ke(p, r, d, f, x);
535
+ if (g) {
529
536
  const c = document.createElement("span");
530
- c.className = "r6o-annotation", c.dataset.annotation = b.annotation.id, c.style.left = `${w.x}px`, c.style.top = `${w.y}px`, c.style.width = `${w.width}px`, c.style.height = `${w.height}px`, c.style.backgroundColor = $((d == null ? void 0 : d.fill) || W.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? W.fillOpacity : d.fillOpacity).toHex(), 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);
537
+ c.className = "r6o-annotation", c.dataset.annotation = p.annotation.id, c.style.left = `${y.x}px`, c.style.top = `${y.y}px`, c.style.width = `${y.width}px`, c.style.height = `${y.height}px`, c.style.backgroundColor = $((l == null ? void 0 : l.fill) || W.fill).alpha((l == null ? void 0 : l.fillOpacity) === void 0 ? W.fillOpacity : l.fillOpacity).toHex(), l.underlineStyle && (c.style.borderStyle = l.underlineStyle), l.underlineColor && (c.style.borderColor = l.underlineColor), l.underlineThickness && (c.style.borderBottomWidth = `${l.underlineThickness}px`), l.underlineOffset && (c.style.paddingBottom = `${l.underlineOffset}px`), e.appendChild(c);
531
538
  }
532
539
  });
533
540
  }), n = a;
@@ -536,21 +543,21 @@ const on = (t, e) => {
536
543
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
537
544
  }
538
545
  };
539
- }, rn = (t, e, n) => Kt(t, e, n, sn(t)), Y = [];
546
+ }, rn = (t, e, n) => Dt(t, e, n, sn(t)), Y = [];
540
547
  for (let t = 0; t < 256; ++t)
541
548
  Y.push((t + 256).toString(16).slice(1));
542
549
  function an(t, e = 0) {
543
550
  return (Y[t[e + 0]] + Y[t[e + 1]] + Y[t[e + 2]] + Y[t[e + 3]] + "-" + Y[t[e + 4]] + Y[t[e + 5]] + "-" + Y[t[e + 6]] + Y[t[e + 7]] + "-" + Y[t[e + 8]] + Y[t[e + 9]] + "-" + Y[t[e + 10]] + Y[t[e + 11]] + Y[t[e + 12]] + Y[t[e + 13]] + Y[t[e + 14]] + Y[t[e + 15]]).toLowerCase();
544
551
  }
545
- let Ct;
552
+ let Lt;
546
553
  const cn = new Uint8Array(16);
547
554
  function ln() {
548
- if (!Ct) {
555
+ if (!Lt) {
549
556
  if (typeof crypto > "u" || !crypto.getRandomValues)
550
557
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
551
- Ct = crypto.getRandomValues.bind(crypto);
558
+ Lt = crypto.getRandomValues.bind(crypto);
552
559
  }
553
- return Ct(cn);
560
+ return Lt(cn);
554
561
  }
555
562
  const dn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Qt = { randomUUID: dn };
556
563
  function fe(t, e, n) {
@@ -581,21 +588,21 @@ function G(t, e) {
581
588
  }
582
589
  return t !== t && e !== e;
583
590
  }
584
- function Lt() {
591
+ function Tt() {
585
592
  }
586
593
  function un(t, e) {
587
594
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
588
595
  }
589
596
  const Q = [];
590
- function Dt(t, e = Lt) {
597
+ function Kt(t, e = Tt) {
591
598
  let n;
592
599
  const o = /* @__PURE__ */ new Set();
593
600
  function i(r) {
594
601
  if (un(t, r) && (t = r, n)) {
595
- const l = !Q.length;
602
+ const d = !Q.length;
596
603
  for (const f of o)
597
604
  f[1](), Q.push(f, t);
598
- if (l) {
605
+ if (d) {
599
606
  for (let f = 0; f < Q.length; f += 2)
600
607
  Q[f][0](Q[f + 1]);
601
608
  Q.length = 0;
@@ -605,16 +612,16 @@ function Dt(t, e = Lt) {
605
612
  function s(r) {
606
613
  i(r(t));
607
614
  }
608
- function a(r, l = Lt) {
609
- const f = [r, l];
610
- return o.add(f), o.size === 1 && (n = e(i, s) || Lt), r(t), () => {
615
+ function a(r, d = Tt) {
616
+ const f = [r, d];
617
+ return o.add(f), o.size === 1 && (n = e(i, s) || Tt), r(t), () => {
611
618
  o.delete(f), o.size === 0 && n && (n(), n = null);
612
619
  };
613
620
  }
614
621
  return { set: i, update: s, subscribe: a };
615
622
  }
616
623
  const fn = (t) => {
617
- const { subscribe: e, set: n } = Dt();
624
+ const { subscribe: e, set: n } = Kt();
618
625
  let o;
619
626
  return e((i) => o = i), t.observe(({ changes: i }) => {
620
627
  if (o) {
@@ -631,56 +638,56 @@ const fn = (t) => {
631
638
  };
632
639
  };
633
640
  var hn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(hn || {});
634
- const pt = { selected: [] }, pn = (t, e, n) => {
635
- const { subscribe: o, set: i } = Dt(pt);
636
- let s = e, a = pt;
637
- o((b) => a = b);
641
+ const gt = { selected: [] }, gn = (t, e, n) => {
642
+ const { subscribe: o, set: i } = Kt(gt);
643
+ let s = e, a = gt;
644
+ o((p) => a = p);
638
645
  const r = () => {
639
- G(a, pt) || i(pt);
640
- }, l = () => {
641
- var b;
642
- return ((b = a.selected) == null ? void 0 : b.length) === 0;
643
- }, f = (b) => {
644
- if (l())
646
+ G(a, gt) || i(gt);
647
+ }, d = () => {
648
+ var p;
649
+ return ((p = a.selected) == null ? void 0 : p.length) === 0;
650
+ }, f = (p) => {
651
+ if (d())
645
652
  return !1;
646
- const w = typeof b == "string" ? b : b.id;
647
- return a.selected.some((y) => y.id === w);
648
- }, h = (b, w) => {
649
- let y;
650
- if (Array.isArray(b)) {
651
- if (y = b.map((c) => t.getAnnotation(c)).filter(Boolean), y.length < b.length) {
652
- console.warn("Invalid selection: " + b.filter((c) => !y.some((A) => A.id === c)));
653
+ const y = typeof p == "string" ? p : p.id;
654
+ return a.selected.some((x) => x.id === y);
655
+ }, h = (p, y) => {
656
+ let x;
657
+ if (Array.isArray(p)) {
658
+ if (x = p.map((c) => t.getAnnotation(c)).filter(Boolean), x.length < p.length) {
659
+ console.warn("Invalid selection: " + p.filter((c) => !x.some((b) => b.id === c)));
653
660
  return;
654
661
  }
655
662
  } else {
656
- const c = t.getAnnotation(b);
663
+ const c = t.getAnnotation(p);
657
664
  if (!c) {
658
- console.warn("Invalid selection: " + b);
665
+ console.warn("Invalid selection: " + p);
659
666
  return;
660
667
  }
661
- y = [c];
668
+ x = [c];
662
669
  }
663
- const d = y.reduce((c, A) => {
664
- const E = Zt(A, s);
665
- return E === "EDIT" ? [...c, { id: A.id, editable: !0 }] : E === "SELECT" ? [...c, { id: A.id }] : c;
670
+ const l = x.reduce((c, b) => {
671
+ const S = Zt(b, s);
672
+ return S === "EDIT" ? [...c, { id: b.id, editable: !0 }] : S === "SELECT" ? [...c, { id: b.id }] : c;
666
673
  }, []);
667
- i({ selected: d, event: w });
668
- }, u = (b, w) => {
669
- const y = Array.isArray(b) ? b : [b], d = y.map((c) => t.getAnnotation(c)).filter((c) => !!c);
674
+ i({ selected: l, event: y });
675
+ }, u = (p, y) => {
676
+ const x = Array.isArray(p) ? p : [p], l = x.map((c) => t.getAnnotation(c)).filter((c) => !!c);
670
677
  i({
671
- selected: d.map((c) => {
672
- const A = w === void 0 ? Zt(c, s) === "EDIT" : w;
673
- return { id: c.id, editable: A };
678
+ selected: l.map((c) => {
679
+ const b = y === void 0 ? Zt(c, s) === "EDIT" : y;
680
+ return { id: c.id, editable: b };
674
681
  })
675
- }), d.length !== y.length && console.warn("Invalid selection", b);
676
- }, p = (b) => {
677
- if (l())
682
+ }), l.length !== x.length && console.warn("Invalid selection", p);
683
+ }, g = (p) => {
684
+ if (d())
678
685
  return !1;
679
- const { selected: w } = a;
680
- w.some(({ id: y }) => b.includes(y)) && i({ selected: w.filter(({ id: y }) => !b.includes(y)) });
681
- }, g = (b) => s = b;
686
+ const { selected: y } = a;
687
+ y.some(({ id: x }) => p.includes(x)) && i({ selected: y.filter(({ id: x }) => !p.includes(x)) });
688
+ }, v = (p) => s = p;
682
689
  return t.observe(
683
- ({ changes: b }) => p((b.deleted || []).map((w) => w.id))
690
+ ({ changes: p }) => g((p.deleted || []).map((y) => y.id))
684
691
  ), {
685
692
  get event() {
686
693
  return a ? a.event : null;
@@ -692,28 +699,28 @@ const pt = { selected: [] }, pn = (t, e, n) => {
692
699
  return s;
693
700
  },
694
701
  clear: r,
695
- isEmpty: l,
702
+ isEmpty: d,
696
703
  isSelected: f,
697
704
  setSelected: u,
698
- setUserSelectAction: g,
705
+ setUserSelectAction: v,
699
706
  subscribe: o,
700
707
  userSelect: h
701
708
  };
702
- }, Zt = (t, e, n) => typeof e == "function" ? e(t) : e || "EDIT", K = [];
709
+ }, Zt = (t, e, n) => typeof e == "function" ? e(t) : e || "EDIT", D = [];
703
710
  for (let t = 0; t < 256; ++t)
704
- K.push((t + 256).toString(16).slice(1));
705
- function gn(t, e = 0) {
706
- return (K[t[e + 0]] + K[t[e + 1]] + K[t[e + 2]] + K[t[e + 3]] + "-" + K[t[e + 4]] + K[t[e + 5]] + "-" + K[t[e + 6]] + K[t[e + 7]] + "-" + K[t[e + 8]] + K[t[e + 9]] + "-" + K[t[e + 10]] + K[t[e + 11]] + K[t[e + 12]] + K[t[e + 13]] + K[t[e + 14]] + K[t[e + 15]]).toLowerCase();
711
+ D.push((t + 256).toString(16).slice(1));
712
+ function pn(t, e = 0) {
713
+ 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();
707
714
  }
708
- let Tt;
715
+ let Ot;
709
716
  const mn = new Uint8Array(16);
710
717
  function yn() {
711
- if (!Tt) {
718
+ if (!Ot) {
712
719
  if (typeof crypto > "u" || !crypto.getRandomValues)
713
720
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
714
- Tt = crypto.getRandomValues.bind(crypto);
721
+ Ot = crypto.getRandomValues.bind(crypto);
715
722
  }
716
- return Tt(mn);
723
+ return Ot(mn);
717
724
  }
718
725
  const bn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), te = { randomUUID: bn };
719
726
  function he(t, e, n) {
@@ -721,9 +728,9 @@ function he(t, e, n) {
721
728
  return te.randomUUID();
722
729
  t = t || {};
723
730
  const o = t.random || (t.rng || yn)();
724
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, gn(o);
731
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, pn(o);
725
732
  }
726
- const Ot = (t) => {
733
+ const Bt = (t) => {
727
734
  const e = (n) => {
728
735
  const o = { ...n };
729
736
  return n.created && typeof n.created == "string" && (o.created = new Date(n.created)), n.updated && typeof n.updated == "string" && (o.updated = new Date(n.updated)), o;
@@ -733,7 +740,7 @@ const Ot = (t) => {
733
740
  bodies: (t.bodies || []).map(e),
734
741
  target: e(t.target)
735
742
  };
736
- }, wo = (t, e, n, o) => ({
743
+ }, Ao = (t, e, n, o) => ({
737
744
  id: he(),
738
745
  annotation: typeof t == "string" ? t : t.id,
739
746
  created: n || /* @__PURE__ */ new Date(),
@@ -748,7 +755,7 @@ const Ot = (t) => {
748
755
  }, xn = (t, e) => e.bodies.map((n) => {
749
756
  const o = t.bodies.find((i) => i.id === n.id);
750
757
  return { newBody: n, oldBody: o && !G(o, n) ? o : void 0 };
751
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), vn = (t, e) => !G(t.target, e.target), pe = (t, e) => {
758
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), vn = (t, e) => !G(t.target, e.target), ge = (t, e) => {
752
759
  const n = wn(t, e), o = An(t, e), i = xn(t, e);
753
760
  return {
754
761
  oldValue: t,
@@ -766,10 +773,10 @@ const En = (t, e) => {
766
773
  if (!(t.options.origin ? t.options.origin === s : s !== "SILENT"))
767
774
  return !1;
768
775
  if (t.options.ignore) {
769
- const { ignore: a } = t.options, r = (l) => l && l.length > 0;
776
+ const { ignore: a } = t.options, r = (d) => d && d.length > 0;
770
777
  if (!(r(i.created) || r(i.deleted))) {
771
- const l = (n = i.updated) == null ? void 0 : n.some((h) => r(h.bodiesCreated) || r(h.bodiesDeleted) || r(h.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
772
- if (a === "BODY_ONLY" && l && !f || a === "TARGET_ONLY" && f && !l)
778
+ const d = (n = i.updated) == null ? void 0 : n.some((h) => r(h.bodiesCreated) || r(h.bodiesDeleted) || r(h.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
779
+ if (a === "BODY_ONLY" && d && !f || a === "TARGET_ONLY" && f && !d)
773
780
  return !1;
774
781
  }
775
782
  }
@@ -783,24 +790,24 @@ const En = (t, e) => {
783
790
  } else
784
791
  return !0;
785
792
  }, Sn = (t, e) => {
786
- const n = new Set((t.created || []).map((u) => u.id)), o = new Set((t.updated || []).map(({ newValue: u }) => u.id)), i = new Set((e.created || []).map((u) => u.id)), s = new Set((e.deleted || []).map((u) => u.id)), a = new Set((e.updated || []).map(({ oldValue: u }) => u.id)), r = new Set((e.updated || []).filter(({ oldValue: u }) => n.has(u.id) || o.has(u.id)).map(({ oldValue: u }) => u.id)), l = [
787
- ...(t.created || []).filter((u) => !s.has(u.id)).map((u) => a.has(u.id) ? e.updated.find(({ oldValue: p }) => p.id === u.id).newValue : u),
793
+ const n = new Set((t.created || []).map((u) => u.id)), o = new Set((t.updated || []).map(({ newValue: u }) => u.id)), i = new Set((e.created || []).map((u) => u.id)), s = new Set((e.deleted || []).map((u) => u.id)), a = new Set((e.updated || []).map(({ oldValue: u }) => u.id)), r = new Set((e.updated || []).filter(({ oldValue: u }) => n.has(u.id) || o.has(u.id)).map(({ oldValue: u }) => u.id)), d = [
794
+ ...(t.created || []).filter((u) => !s.has(u.id)).map((u) => a.has(u.id) ? e.updated.find(({ oldValue: g }) => g.id === u.id).newValue : u),
788
795
  ...e.created || []
789
796
  ], f = [
790
797
  ...(t.deleted || []).filter((u) => !i.has(u.id)),
791
798
  ...(e.deleted || []).filter((u) => !n.has(u.id))
792
799
  ], h = [
793
800
  ...(t.updated || []).filter(({ newValue: u }) => !s.has(u.id)).map((u) => {
794
- const { oldValue: p, newValue: g } = u;
795
- if (a.has(g.id)) {
796
- const b = e.updated.find((w) => w.oldValue.id === g.id).newValue;
797
- return pe(p, b);
801
+ const { oldValue: g, newValue: v } = u;
802
+ if (a.has(v.id)) {
803
+ const p = e.updated.find((y) => y.oldValue.id === v.id).newValue;
804
+ return ge(g, p);
798
805
  } else
799
806
  return u;
800
807
  }),
801
808
  ...(e.updated || []).filter(({ oldValue: u }) => !r.has(u.id))
802
809
  ];
803
- return { created: l, deleted: f, updated: h };
810
+ return { created: d, deleted: f, updated: h };
804
811
  }, Mt = (t) => {
805
812
  const e = t.id === void 0 ? he() : t.id;
806
813
  return {
@@ -816,170 +823,170 @@ const En = (t, e) => {
816
823
  }
817
824
  };
818
825
  }, Cn = (t) => t.id !== void 0, Ln = () => {
819
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, v = {}) => {
820
- n.push({ onChange: m, options: v });
826
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, A = {}) => {
827
+ n.push({ onChange: m, options: A });
821
828
  }, i = (m) => {
822
- const v = n.findIndex((x) => x.onChange == m);
823
- v > -1 && n.splice(v, 1);
824
- }, s = (m, v) => {
825
- const x = {
829
+ const A = n.findIndex((w) => w.onChange == m);
830
+ A > -1 && n.splice(A, 1);
831
+ }, s = (m, A) => {
832
+ const w = {
826
833
  origin: m,
827
834
  changes: {
828
- created: v.created || [],
829
- updated: v.updated || [],
830
- deleted: v.deleted || []
835
+ created: A.created || [],
836
+ updated: A.updated || [],
837
+ deleted: A.deleted || []
831
838
  },
832
839
  state: [...t.values()]
833
840
  };
834
- n.forEach((C) => {
835
- En(C, x) && C.onChange(x);
841
+ n.forEach((L) => {
842
+ En(L, w) && L.onChange(w);
836
843
  });
837
- }, a = (m, v = k.LOCAL) => {
844
+ }, a = (m, A = k.LOCAL) => {
838
845
  if (m.id && t.get(m.id))
839
846
  throw Error(`Cannot add annotation ${m.id} - exists already`);
840
847
  {
841
- const x = Mt(m);
842
- t.set(x.id, x), x.bodies.forEach((C) => e.set(C.id, x.id)), s(v, { created: [x] });
848
+ const w = Mt(m);
849
+ t.set(w.id, w), w.bodies.forEach((L) => e.set(L.id, w.id)), s(A, { created: [w] });
843
850
  }
844
- }, r = (m, v) => {
845
- const x = Mt(typeof m == "string" ? v : m), C = typeof m == "string" ? m : m.id, B = C && t.get(C);
846
- if (B) {
847
- const R = pe(B, x);
848
- return C === x.id ? t.set(C, x) : (t.delete(C), t.set(x.id, x)), B.bodies.forEach((N) => e.delete(N.id)), x.bodies.forEach((N) => e.set(N.id, x.id)), R;
851
+ }, r = (m, A) => {
852
+ const w = Mt(typeof m == "string" ? A : m), L = typeof m == "string" ? m : m.id, M = L && t.get(L);
853
+ if (M) {
854
+ const R = ge(M, w);
855
+ return L === w.id ? t.set(L, w) : (t.delete(L), t.set(w.id, w)), M.bodies.forEach((N) => e.delete(N.id)), w.bodies.forEach((N) => e.set(N.id, w.id)), R;
849
856
  } else
850
- console.warn(`Cannot update annotation ${C} - does not exist`);
851
- }, l = (m, v = k.LOCAL, x = k.LOCAL) => {
852
- const C = Cn(v) ? x : v, B = r(m, v);
853
- B && s(C, { updated: [B] });
854
- }, f = (m, v = k.LOCAL) => {
855
- const x = m.reduce((C, B) => {
856
- const R = r(B);
857
- return R ? [...C, R] : C;
857
+ console.warn(`Cannot update annotation ${L} - does not exist`);
858
+ }, d = (m, A = k.LOCAL, w = k.LOCAL) => {
859
+ const L = Cn(A) ? w : A, M = r(m, A);
860
+ M && s(L, { updated: [M] });
861
+ }, f = (m, A = k.LOCAL) => {
862
+ const w = m.reduce((L, M) => {
863
+ const R = r(M);
864
+ return R ? [...L, R] : L;
858
865
  }, []);
859
- x.length > 0 && s(v, { updated: x });
860
- }, h = (m, v = k.LOCAL) => {
861
- const x = t.get(m.annotation);
862
- if (x) {
863
- const C = {
864
- ...x,
865
- bodies: [...x.bodies, m]
866
+ w.length > 0 && s(A, { updated: w });
867
+ }, h = (m, A = k.LOCAL) => {
868
+ const w = t.get(m.annotation);
869
+ if (w) {
870
+ const L = {
871
+ ...w,
872
+ bodies: [...w.bodies, m]
866
873
  };
867
- t.set(x.id, C), e.set(m.id, C.id), s(v, { updated: [{
868
- oldValue: x,
869
- newValue: C,
874
+ t.set(w.id, L), e.set(m.id, L.id), s(A, { updated: [{
875
+ oldValue: w,
876
+ newValue: L,
870
877
  bodiesCreated: [m]
871
878
  }] });
872
879
  } else
873
880
  console.warn(`Attempt to add body to missing annotation: ${m.annotation}`);
874
- }, u = () => [...t.values()], p = (m = k.LOCAL) => {
875
- const v = [...t.values()];
876
- t.clear(), e.clear(), s(m, { deleted: v });
877
- }, g = (m, v = !0, x = k.LOCAL) => {
878
- const C = m.map(Mt);
879
- if (v) {
880
- const B = [...t.values()];
881
- t.clear(), e.clear(), C.forEach((R) => {
881
+ }, u = () => [...t.values()], g = (m = k.LOCAL) => {
882
+ const A = [...t.values()];
883
+ t.clear(), e.clear(), s(m, { deleted: A });
884
+ }, v = (m, A = !0, w = k.LOCAL) => {
885
+ const L = m.map(Mt);
886
+ if (A) {
887
+ const M = [...t.values()];
888
+ t.clear(), e.clear(), L.forEach((R) => {
882
889
  t.set(R.id, R), R.bodies.forEach((N) => e.set(N.id, R.id));
883
- }), s(x, { created: C, deleted: B });
890
+ }), s(w, { created: L, deleted: M });
884
891
  } else {
885
- const B = m.reduce((R, N) => {
892
+ const M = m.reduce((R, N) => {
886
893
  const U = N.id && t.get(N.id);
887
894
  return U ? [...R, U] : R;
888
895
  }, []);
889
- if (B.length > 0)
890
- throw Error(`Bulk insert would overwrite the following annotations: ${B.map((R) => R.id).join(", ")}`);
891
- C.forEach((R) => {
896
+ if (M.length > 0)
897
+ throw Error(`Bulk insert would overwrite the following annotations: ${M.map((R) => R.id).join(", ")}`);
898
+ L.forEach((R) => {
892
899
  t.set(R.id, R), R.bodies.forEach((N) => e.set(N.id, R.id));
893
- }), s(x, { created: C });
900
+ }), s(w, { created: L });
894
901
  }
895
- }, b = (m) => {
896
- const v = typeof m == "string" ? m : m.id, x = t.get(v);
897
- if (x)
898
- return t.delete(v), x.bodies.forEach((C) => e.delete(C.id)), x;
899
- console.warn(`Attempt to delete missing annotation: ${v}`);
900
- }, w = (m, v = k.LOCAL) => {
901
- const x = b(m);
902
- x && s(v, { deleted: [x] });
903
- }, y = (m, v = k.LOCAL) => {
904
- const x = m.reduce((C, B) => {
905
- const R = b(B);
906
- return R ? [...C, R] : C;
902
+ }, p = (m) => {
903
+ const A = typeof m == "string" ? m : m.id, w = t.get(A);
904
+ if (w)
905
+ return t.delete(A), w.bodies.forEach((L) => e.delete(L.id)), w;
906
+ console.warn(`Attempt to delete missing annotation: ${A}`);
907
+ }, y = (m, A = k.LOCAL) => {
908
+ const w = p(m);
909
+ w && s(A, { deleted: [w] });
910
+ }, x = (m, A = k.LOCAL) => {
911
+ const w = m.reduce((L, M) => {
912
+ const R = p(M);
913
+ return R ? [...L, R] : L;
907
914
  }, []);
908
- x.length > 0 && s(v, { deleted: x });
909
- }, d = (m) => {
910
- const v = t.get(m.annotation);
911
- if (v) {
912
- const x = v.bodies.find((C) => C.id === m.id);
913
- if (x) {
914
- e.delete(x.id);
915
- const C = {
916
- ...v,
917
- bodies: v.bodies.filter((B) => B.id !== m.id)
915
+ w.length > 0 && s(A, { deleted: w });
916
+ }, l = (m) => {
917
+ const A = t.get(m.annotation);
918
+ if (A) {
919
+ const w = A.bodies.find((L) => L.id === m.id);
920
+ if (w) {
921
+ e.delete(w.id);
922
+ const L = {
923
+ ...A,
924
+ bodies: A.bodies.filter((M) => M.id !== m.id)
918
925
  };
919
- return t.set(v.id, C), {
920
- oldValue: v,
921
- newValue: C,
922
- bodiesDeleted: [x]
926
+ return t.set(A.id, L), {
927
+ oldValue: A,
928
+ newValue: L,
929
+ bodiesDeleted: [w]
923
930
  };
924
931
  } else
925
932
  console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`);
926
933
  } else
927
934
  console.warn(`Attempt to delete body from missing annotation ${m.annotation}`);
928
- }, c = (m, v = k.LOCAL) => {
929
- const x = d(m);
930
- x && s(v, { updated: [x] });
931
- }, A = (m, v = k.LOCAL) => {
932
- const x = m.map((C) => d(C)).filter(Boolean);
933
- x.length > 0 && s(v, { updated: x });
935
+ }, c = (m, A = k.LOCAL) => {
936
+ const w = l(m);
937
+ w && s(A, { updated: [w] });
938
+ }, b = (m, A = k.LOCAL) => {
939
+ const w = m.map((L) => l(L)).filter(Boolean);
940
+ w.length > 0 && s(A, { updated: w });
941
+ }, S = (m) => {
942
+ const A = t.get(m);
943
+ return A ? { ...A } : void 0;
934
944
  }, E = (m) => {
935
- const v = t.get(m);
936
- return v ? { ...v } : void 0;
937
- }, T = (m) => {
938
- const v = e.get(m);
939
- if (v) {
940
- const x = E(v).bodies.find((C) => C.id === m);
941
- if (x)
942
- return x;
945
+ const A = e.get(m);
946
+ if (A) {
947
+ const w = S(A).bodies.find((L) => L.id === m);
948
+ if (w)
949
+ return w;
943
950
  console.error(`Store integrity error: body ${m} in index, but not in annotation`);
944
951
  } else
945
952
  console.warn(`Attempt to retrieve missing body: ${m}`);
946
- }, S = (m, v) => {
947
- if (m.annotation !== v.annotation)
953
+ }, C = (m, A) => {
954
+ if (m.annotation !== A.annotation)
948
955
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
949
- const x = t.get(m.annotation);
950
- if (x) {
951
- const C = x.bodies.find((R) => R.id === m.id), B = {
952
- ...x,
953
- bodies: x.bodies.map((R) => R.id === C.id ? v : R)
956
+ const w = t.get(m.annotation);
957
+ if (w) {
958
+ const L = w.bodies.find((R) => R.id === m.id), M = {
959
+ ...w,
960
+ bodies: w.bodies.map((R) => R.id === L.id ? A : R)
954
961
  };
955
- return t.set(x.id, B), C.id !== v.id && (e.delete(C.id), e.set(v.id, B.id)), {
956
- oldValue: x,
957
- newValue: B,
958
- bodiesUpdated: [{ oldBody: C, newBody: v }]
962
+ return t.set(w.id, M), L.id !== A.id && (e.delete(L.id), e.set(A.id, M.id)), {
963
+ oldValue: w,
964
+ newValue: M,
965
+ bodiesUpdated: [{ oldBody: L, newBody: A }]
959
966
  };
960
967
  } else
961
968
  console.warn(`Attempt to add body to missing annotation ${m.annotation}`);
962
- }, O = (m, v, x = k.LOCAL) => {
963
- const C = S(m, v);
964
- C && s(x, { updated: [C] });
965
- }, M = (m, v = k.LOCAL) => {
966
- const x = m.map((C) => S({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
967
- s(v, { updated: x });
968
- }, L = (m) => {
969
- const v = t.get(m.annotation);
970
- if (v) {
971
- const x = {
972
- ...v,
969
+ }, O = (m, A, w = k.LOCAL) => {
970
+ const L = C(m, A);
971
+ L && s(w, { updated: [L] });
972
+ }, B = (m, A = k.LOCAL) => {
973
+ const w = m.map((L) => C({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
974
+ s(A, { updated: w });
975
+ }, T = (m) => {
976
+ const A = t.get(m.annotation);
977
+ if (A) {
978
+ const w = {
979
+ ...A,
973
980
  target: {
974
- ...v.target,
981
+ ...A.target,
975
982
  ...m
976
983
  }
977
984
  };
978
- return t.set(v.id, x), {
979
- oldValue: v,
980
- newValue: x,
985
+ return t.set(A.id, w), {
986
+ oldValue: A,
987
+ newValue: w,
981
988
  targetUpdated: {
982
- oldTarget: v.target,
989
+ oldTarget: A.target,
983
990
  newTarget: m
984
991
  }
985
992
  };
@@ -990,27 +997,27 @@ const En = (t, e) => {
990
997
  addAnnotation: a,
991
998
  addBody: h,
992
999
  all: u,
993
- bulkAddAnnotation: g,
994
- bulkDeleteAnnotation: y,
995
- bulkDeleteBodies: A,
1000
+ bulkAddAnnotation: v,
1001
+ bulkDeleteAnnotation: x,
1002
+ bulkDeleteBodies: b,
996
1003
  bulkUpdateAnnotation: f,
997
- bulkUpdateBodies: M,
998
- bulkUpdateTargets: (m, v = k.LOCAL) => {
999
- const x = m.map((C) => L(C)).filter(Boolean);
1000
- x.length > 0 && s(v, { updated: x });
1004
+ bulkUpdateBodies: B,
1005
+ bulkUpdateTargets: (m, A = k.LOCAL) => {
1006
+ const w = m.map((L) => T(L)).filter(Boolean);
1007
+ w.length > 0 && s(A, { updated: w });
1001
1008
  },
1002
- clear: p,
1003
- deleteAnnotation: w,
1009
+ clear: g,
1010
+ deleteAnnotation: y,
1004
1011
  deleteBody: c,
1005
- getAnnotation: E,
1006
- getBody: T,
1012
+ getAnnotation: S,
1013
+ getBody: E,
1007
1014
  observe: o,
1008
1015
  unobserve: i,
1009
- updateAnnotation: l,
1016
+ updateAnnotation: d,
1010
1017
  updateBody: O,
1011
- updateTarget: (m, v = k.LOCAL) => {
1012
- const x = L(m);
1013
- x && s(v, { updated: [x] });
1018
+ updateTarget: (m, A = k.LOCAL) => {
1019
+ const w = T(m);
1020
+ w && s(A, { updated: [w] });
1014
1021
  }
1015
1022
  };
1016
1023
  };
@@ -1028,118 +1035,119 @@ let Tn = () => ({
1028
1035
  };
1029
1036
  }
1030
1037
  });
1031
- const On = 250, Mn = (t) => {
1032
- const e = Tn(), n = [];
1033
- let o = -1, i = !1, s = 0;
1034
- const a = (g) => {
1035
- if (!i) {
1036
- const { changes: b } = g, w = performance.now();
1037
- if (w - s > On)
1038
- n.splice(o + 1), n.push(b), o = n.length - 1;
1038
+ const On = 250, Bn = (t, e) => {
1039
+ const n = Tn(), o = [];
1040
+ let i = -1, s = !1, a = 0;
1041
+ const r = (p) => {
1042
+ if (!s) {
1043
+ const { changes: y } = p, x = performance.now();
1044
+ if (x - a > On)
1045
+ o.splice(i + 1), o.push(y), i = o.length - 1;
1039
1046
  else {
1040
- const y = n.length - 1;
1041
- n[y] = Sn(n[y], b);
1047
+ const l = o.length - 1;
1048
+ o[l] = Sn(o[l], y);
1042
1049
  }
1043
- s = w;
1050
+ a = x;
1044
1051
  }
1045
- i = !1;
1052
+ s = !1;
1046
1053
  };
1047
- t.observe(a, { origin: k.LOCAL });
1048
- const r = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), l = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), f = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: b }) => b)), h = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: b }) => b)), u = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), p = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
1054
+ t.observe(r, { origin: k.LOCAL });
1055
+ const d = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), f = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), h = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: y }) => y)), u = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: y }) => y)), g = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), v = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
1049
1056
  return {
1050
- canRedo: () => n.length - 1 > o,
1051
- canUndo: () => o > -1,
1052
- destroy: () => t.unobserve(a),
1053
- on: (g, b) => e.on(g, b),
1057
+ canRedo: () => o.length - 1 > i,
1058
+ canUndo: () => i > -1,
1059
+ destroy: () => t.unobserve(r),
1060
+ getHistory: () => ({ changes: [...o], pointer: i }),
1061
+ on: (p, y) => n.on(p, y),
1054
1062
  redo: () => {
1055
- if (n.length - 1 > o) {
1056
- i = !0;
1057
- const { created: g, updated: b, deleted: w } = n[o + 1];
1058
- l(g), h(b), p(w), e.emit("redo", n[o + 1]), o += 1;
1063
+ if (o.length - 1 > i) {
1064
+ s = !0;
1065
+ const { created: p, updated: y, deleted: x } = o[i + 1];
1066
+ f(p), u(y), v(x), n.emit("redo", o[i + 1]), i += 1;
1059
1067
  }
1060
1068
  },
1061
1069
  undo: () => {
1062
- if (o > -1) {
1063
- i = !0;
1064
- const { created: g, updated: b, deleted: w } = n[o];
1065
- r(g), f(b), u(w), e.emit("undo", n[o]), o -= 1;
1070
+ if (i > -1) {
1071
+ s = !0;
1072
+ const { created: p, updated: y, deleted: x } = o[i];
1073
+ d(p), h(y), g(x), n.emit("undo", o[i]), i -= 1;
1066
1074
  }
1067
1075
  }
1068
1076
  };
1069
- }, Bn = () => {
1070
- const { subscribe: t, set: e } = Dt([]);
1077
+ }, Mn = () => {
1078
+ const { subscribe: t, set: e } = Kt([]);
1071
1079
  return {
1072
1080
  subscribe: t,
1073
1081
  set: e
1074
1082
  };
1075
1083
  }, Rn = (t, e, n, o) => {
1076
- const { hover: i, selection: s, store: a, viewport: r } = t, l = /* @__PURE__ */ new Map();
1084
+ const { hover: i, selection: s, store: a, viewport: r } = t, d = /* @__PURE__ */ new Map();
1077
1085
  let f = [], h;
1078
- const u = (w, y) => {
1079
- l.has(w) ? l.get(w).push(y) : l.set(w, [y]);
1080
- }, p = (w, y) => {
1081
- const d = l.get(w);
1082
- if (d) {
1083
- const c = d.indexOf(y);
1084
- c !== -1 && d.splice(c, 1);
1086
+ const u = (y, x) => {
1087
+ d.has(y) ? d.get(y).push(x) : d.set(y, [x]);
1088
+ }, g = (y, x) => {
1089
+ const l = d.get(y);
1090
+ if (l) {
1091
+ const c = l.indexOf(x);
1092
+ c !== -1 && l.splice(c, 1);
1085
1093
  }
1086
- }, g = (w, y, d) => {
1087
- l.has(w) && setTimeout(() => {
1088
- l.get(w).forEach((c) => {
1094
+ }, v = (y, x, l) => {
1095
+ d.has(y) && setTimeout(() => {
1096
+ d.get(y).forEach((c) => {
1089
1097
  if (n) {
1090
- const A = Array.isArray(y) ? y.map((T) => n.serialize(T)) : n.serialize(y), E = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1091
- c(A, E);
1098
+ const b = Array.isArray(x) ? x.map((E) => n.serialize(E)) : n.serialize(x), S = l ? l instanceof PointerEvent ? l : n.serialize(l) : void 0;
1099
+ c(b, S);
1092
1100
  } else
1093
- c(y, d);
1101
+ c(x, l);
1094
1102
  });
1095
1103
  }, 1);
1096
1104
  };
1097
- s.subscribe(({ selected: w }) => {
1098
- if (!(f.length === 0 && w.length === 0)) {
1099
- if (f.length === 0 && w.length > 0)
1100
- f = w.map(({ id: y }) => a.getAnnotation(y));
1101
- else if (f.length > 0 && w.length === 0)
1102
- f.forEach((y) => {
1103
- const d = a.getAnnotation(y.id);
1104
- d && !G(d, y) && g("updateAnnotation", d, y);
1105
+ s.subscribe(({ selected: y }) => {
1106
+ if (!(f.length === 0 && y.length === 0)) {
1107
+ if (f.length === 0 && y.length > 0)
1108
+ f = y.map(({ id: x }) => a.getAnnotation(x));
1109
+ else if (f.length > 0 && y.length === 0)
1110
+ f.forEach((x) => {
1111
+ const l = a.getAnnotation(x.id);
1112
+ l && !G(l, x) && v("updateAnnotation", l, x);
1105
1113
  }), f = [];
1106
1114
  else {
1107
- const y = new Set(f.map((c) => c.id)), d = new Set(w.map(({ id: c }) => c));
1108
- f.filter((c) => !d.has(c.id)).forEach((c) => {
1109
- const A = a.getAnnotation(c.id);
1110
- A && !G(A, c) && g("updateAnnotation", A, c);
1115
+ const x = new Set(f.map((c) => c.id)), l = new Set(y.map(({ id: c }) => c));
1116
+ f.filter((c) => !l.has(c.id)).forEach((c) => {
1117
+ const b = a.getAnnotation(c.id);
1118
+ b && !G(b, c) && v("updateAnnotation", b, c);
1111
1119
  }), f = [
1112
1120
  // Remove annotations that were deselected
1113
- ...f.filter((c) => d.has(c.id)),
1121
+ ...f.filter((c) => l.has(c.id)),
1114
1122
  // Add editable annotations that were selected
1115
- ...w.filter(({ id: c }) => !y.has(c)).map(({ id: c }) => a.getAnnotation(c))
1123
+ ...y.filter(({ id: c }) => !x.has(c)).map(({ id: c }) => a.getAnnotation(c))
1116
1124
  ];
1117
1125
  }
1118
- g("selectionChanged", f);
1126
+ v("selectionChanged", f);
1119
1127
  }
1120
- }), i.subscribe((w) => {
1121
- !h && w ? g("mouseEnterAnnotation", a.getAnnotation(w)) : h && !w ? g("mouseLeaveAnnotation", a.getAnnotation(h)) : h && w && (g("mouseLeaveAnnotation", a.getAnnotation(h)), g("mouseEnterAnnotation", a.getAnnotation(w))), h = w;
1122
- }), r == null || r.subscribe((w) => g("viewportIntersect", w.map((y) => a.getAnnotation(y)))), a.observe((w) => {
1123
- const { created: y, deleted: d } = w.changes;
1124
- (y || []).forEach((c) => g("createAnnotation", c)), (d || []).forEach((c) => g("deleteAnnotation", c)), (w.changes.updated || []).filter((c) => [
1128
+ }), i.subscribe((y) => {
1129
+ !h && y ? v("mouseEnterAnnotation", a.getAnnotation(y)) : h && !y ? v("mouseLeaveAnnotation", a.getAnnotation(h)) : h && y && (v("mouseLeaveAnnotation", a.getAnnotation(h)), v("mouseEnterAnnotation", a.getAnnotation(y))), h = y;
1130
+ }), r == null || r.subscribe((y) => v("viewportIntersect", y.map((x) => a.getAnnotation(x)))), a.observe((y) => {
1131
+ const { created: x, deleted: l } = y.changes;
1132
+ (x || []).forEach((c) => v("createAnnotation", c)), (l || []).forEach((c) => v("deleteAnnotation", c)), (y.changes.updated || []).filter((c) => [
1125
1133
  ...c.bodiesCreated || [],
1126
1134
  ...c.bodiesDeleted || [],
1127
1135
  ...c.bodiesUpdated || []
1128
- ].length > 0).forEach(({ oldValue: c, newValue: A }) => {
1129
- const E = f.find((T) => T.id === c.id) || c;
1130
- f = f.map((T) => T.id === c.id ? A : T), g("updateAnnotation", A, E);
1136
+ ].length > 0).forEach(({ oldValue: c, newValue: b }) => {
1137
+ const S = f.find((E) => E.id === c.id) || c;
1138
+ f = f.map((E) => E.id === c.id ? b : E), v("updateAnnotation", b, S);
1131
1139
  });
1132
- }, { origin: k.LOCAL }), a.observe((w) => {
1140
+ }, { origin: k.LOCAL }), a.observe((y) => {
1133
1141
  if (f) {
1134
- const y = new Set(f.map((c) => c.id)), d = (w.changes.updated || []).filter(({ newValue: c }) => y.has(c.id)).map(({ newValue: c }) => c);
1135
- d.length > 0 && (f = f.map((c) => d.find((E) => E.id === c.id) || c));
1142
+ const x = new Set(f.map((c) => c.id)), l = (y.changes.updated || []).filter(({ newValue: c }) => x.has(c.id)).map(({ newValue: c }) => c);
1143
+ l.length > 0 && (f = f.map((c) => l.find((S) => S.id === c.id) || c));
1136
1144
  }
1137
1145
  }, { origin: k.REMOTE });
1138
- const b = (w) => (y) => {
1139
- const { updated: d } = y;
1140
- w ? (d || []).forEach((c) => g("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => g("updateAnnotation", c.newValue, c.oldValue));
1146
+ const p = (y) => (x) => {
1147
+ const { updated: l } = x;
1148
+ y ? (l || []).forEach((c) => v("updateAnnotation", c.oldValue, c.newValue)) : (l || []).forEach((c) => v("updateAnnotation", c.newValue, c.oldValue));
1141
1149
  };
1142
- return e.on("undo", b(!0)), e.on("redo", b(!1)), { on: u, off: p, emit: g };
1150
+ return e.on("undo", p(!0)), e.on("redo", p(!1)), { on: u, off: g, emit: v };
1143
1151
  }, kn = (t) => (e) => e.reduce((n, o) => {
1144
1152
  const { parsed: i, error: s } = t.parse(o);
1145
1153
  return s ? {
@@ -1152,46 +1160,46 @@ const On = 250, Mn = (t) => {
1152
1160
  ...n
1153
1161
  };
1154
1162
  }, { parsed: [], failed: [] }), In = (t, e, n) => {
1155
- const { store: o, selection: i } = t, s = (d) => {
1163
+ const { store: o, selection: i } = t, s = (l) => {
1156
1164
  if (n) {
1157
- const { parsed: c, error: A } = n.parse(d);
1158
- c ? o.addAnnotation(c, k.REMOTE) : console.error(A);
1165
+ const { parsed: c, error: b } = n.parse(l);
1166
+ c ? o.addAnnotation(c, k.REMOTE) : console.error(b);
1159
1167
  } else
1160
- o.addAnnotation(Ot(d), k.REMOTE);
1161
- }, a = () => i.clear(), r = () => o.clear(), l = (d) => {
1162
- const c = o.getAnnotation(d);
1168
+ o.addAnnotation(Bt(l), k.REMOTE);
1169
+ }, a = () => i.clear(), r = () => o.clear(), d = (l) => {
1170
+ const c = o.getAnnotation(l);
1163
1171
  return n && c ? n.serialize(c) : c;
1164
1172
  }, f = () => n ? o.all().map(n.serialize) : o.all(), h = () => {
1165
- var d;
1166
- const c = (((d = i.selected) == null ? void 0 : d.map((A) => A.id)) || []).map((A) => o.getAnnotation(A)).filter(Boolean);
1173
+ var l;
1174
+ const c = (((l = i.selected) == null ? void 0 : l.map((b) => b.id)) || []).map((b) => o.getAnnotation(b)).filter(Boolean);
1167
1175
  return n ? c.map(n.serialize) : c;
1168
- }, u = (d, c = !0) => fetch(d).then((A) => A.json()).then((A) => (g(A, c), A)), p = (d) => {
1169
- if (typeof d == "string") {
1170
- const c = o.getAnnotation(d);
1171
- if (o.deleteAnnotation(d), c)
1176
+ }, u = (l, c = !0) => fetch(l).then((b) => b.json()).then((b) => (v(b, c), b)), g = (l) => {
1177
+ if (typeof l == "string") {
1178
+ const c = o.getAnnotation(l);
1179
+ if (o.deleteAnnotation(l), c)
1172
1180
  return n ? n.serialize(c) : c;
1173
1181
  } else {
1174
- const c = n ? n.parse(d).parsed : d;
1182
+ const c = n ? n.parse(l).parsed : l;
1175
1183
  if (c)
1176
- return o.deleteAnnotation(c), d;
1184
+ return o.deleteAnnotation(c), l;
1177
1185
  }
1178
- }, g = (d, c = !0) => {
1186
+ }, v = (l, c = !0) => {
1179
1187
  if (n) {
1180
- const A = n.parseAll || kn(n), { parsed: E, failed: T } = A(d);
1181
- T.length > 0 && console.warn(`Discarded ${T.length} invalid annotations`, T), o.bulkAddAnnotation(E, c, k.REMOTE);
1188
+ const b = n.parseAll || kn(n), { parsed: S, failed: E } = b(l);
1189
+ E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotation(S, c, k.REMOTE);
1182
1190
  } else
1183
- o.bulkAddAnnotation(d.map(Ot), c, k.REMOTE);
1184
- }, b = (d, c) => {
1185
- d ? i.setSelected(d, c) : i.clear();
1186
- }, w = (d) => {
1187
- i.clear(), i.setUserSelectAction(d);
1188
- }, y = (d) => {
1191
+ o.bulkAddAnnotation(l.map(Bt), c, k.REMOTE);
1192
+ }, p = (l, c) => {
1193
+ l ? i.setSelected(l, c) : i.clear();
1194
+ }, y = (l) => {
1195
+ i.clear(), i.setUserSelectAction(l);
1196
+ }, x = (l) => {
1189
1197
  if (n) {
1190
- const c = n.parse(d).parsed, A = n.serialize(o.getAnnotation(c.id));
1191
- return o.updateAnnotation(c), A;
1198
+ const c = n.parse(l).parsed, b = n.serialize(o.getAnnotation(c.id));
1199
+ return o.updateAnnotation(c), b;
1192
1200
  } else {
1193
- const c = o.getAnnotation(d.id);
1194
- return o.updateAnnotation(Ot(d)), c;
1201
+ const c = o.getAnnotation(l.id);
1202
+ return o.updateAnnotation(Bt(l)), c;
1195
1203
  }
1196
1204
  };
1197
1205
  return {
@@ -1200,17 +1208,18 @@ const On = 250, Mn = (t) => {
1200
1208
  canRedo: e.canRedo,
1201
1209
  canUndo: e.canUndo,
1202
1210
  clearAnnotations: r,
1203
- getAnnotationById: l,
1211
+ getAnnotationById: d,
1204
1212
  getAnnotations: f,
1213
+ getHistory: e.getHistory,
1205
1214
  getSelected: h,
1206
1215
  loadAnnotations: u,
1207
1216
  redo: e.redo,
1208
- removeAnnotation: p,
1209
- setAnnotations: g,
1210
- setSelected: b,
1211
- setUserSelectAction: w,
1217
+ removeAnnotation: g,
1218
+ setAnnotations: v,
1219
+ setSelected: p,
1220
+ setUserSelectAction: y,
1212
1221
  undo: e.undo,
1213
- updateAnnotation: y
1222
+ updateAnnotation: x
1214
1223
  };
1215
1224
  }, _n = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1216
1225
  let Nn = (t) => crypto.getRandomValues(new Uint8Array(t)), Un = (t, e, n) => {
@@ -1218,18 +1227,18 @@ let Nn = (t) => crypto.getRandomValues(new Uint8Array(t)), Un = (t, e, n) => {
1218
1227
  return (s = e) => {
1219
1228
  let a = "";
1220
1229
  for (; ; ) {
1221
- let r = n(i), l = i;
1222
- for (; l--; )
1223
- if (a += t[r[l] & o] || "", a.length === s) return a;
1230
+ let r = n(i), d = i | 0;
1231
+ for (; d--; )
1232
+ if (a += t[r[d] & o] || "", a.length >= s) return a;
1224
1233
  }
1225
1234
  };
1226
- }, Vn = (t, e = 21) => Un(t, e, Nn), Yn = (t = 21) => {
1227
- let e = "", n = crypto.getRandomValues(new Uint8Array(t));
1235
+ }, Vn = (t, e = 21) => Un(t, e | 0, Nn), Yn = (t = 21) => {
1236
+ let e = "", n = crypto.getRandomValues(new Uint8Array(t |= 0));
1228
1237
  for (; t--; )
1229
1238
  e += _n[n[t] & 63];
1230
1239
  return e;
1231
1240
  };
1232
- const Kn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Dn = (t) => {
1241
+ const Dn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Kn = (t) => {
1233
1242
  const e = JSON.stringify(t);
1234
1243
  let n = 0;
1235
1244
  for (let o = 0, i = e.length; o < i; o++) {
@@ -1237,17 +1246,17 @@ const Kn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABC
1237
1246
  n = (n << 5) - n + s, n |= 0;
1238
1247
  }
1239
1248
  return `${n}`;
1240
- }, ge = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Xn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1241
- const { id: o, type: i, purpose: s, value: a, created: r, modified: l, creator: f, ...h } = n;
1249
+ }, pe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Xn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1250
+ const { id: o, type: i, purpose: s, value: a, created: r, modified: d, creator: f, ...h } = n;
1242
1251
  return {
1243
- id: o || `temp-${Dn(n)}`,
1252
+ id: o || `temp-${Kn(n)}`,
1244
1253
  annotation: e,
1245
1254
  type: i,
1246
1255
  purpose: s,
1247
1256
  value: a,
1248
- creator: ge(f),
1257
+ creator: pe(f),
1249
1258
  created: r ? new Date(r) : void 0,
1250
- updated: l ? new Date(l) : void 0,
1259
+ updated: d ? new Date(d) : void 0,
1251
1260
  ...h
1252
1261
  };
1253
1262
  }), Pn = (t) => t.map((e) => {
@@ -1260,7 +1269,7 @@ const Kn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABC
1260
1269
  return (n = r.id) != null && n.startsWith("temp-") && delete r.id, r;
1261
1270
  });
1262
1271
  Yn();
1263
- const Ao = (t, e) => ({
1272
+ const xo = (t, e) => ({
1264
1273
  parse: (n) => jn(n),
1265
1274
  serialize: (n) => zn(n, t, e)
1266
1275
  }), $n = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, Hn = (t) => {
@@ -1274,7 +1283,7 @@ const Ao = (t, e) => ({
1274
1283
  if (a.length === 0)
1275
1284
  return { error: Error(`No targets found for annotation: ${t.id}`) };
1276
1285
  const r = {
1277
- creator: ge(n),
1286
+ creator: pe(n),
1278
1287
  created: o ? new Date(o) : void 0,
1279
1288
  updated: i ? new Date(i) : void 0,
1280
1289
  annotation: e,
@@ -1282,14 +1291,14 @@ const Ao = (t, e) => ({
1282
1291
  // @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
1283
1292
  styleClass: "styleClass" in a[0] ? a[0].styleClass : void 0
1284
1293
  };
1285
- for (const l of a) {
1286
- const h = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((u, p) => {
1287
- switch (p.type) {
1294
+ for (const d of a) {
1295
+ const h = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((u, g) => {
1296
+ switch (g.type) {
1288
1297
  case "TextQuoteSelector":
1289
- u.quote = p.exact;
1298
+ u.quote = g.exact;
1290
1299
  break;
1291
1300
  case "TextPositionSelector":
1292
- u.start = p.start, u.end = p.end;
1301
+ u.start = g.start, u.end = g.end;
1293
1302
  break;
1294
1303
  }
1295
1304
  return u;
@@ -1298,9 +1307,9 @@ const Ao = (t, e) => ({
1298
1307
  r.selector.push(
1299
1308
  {
1300
1309
  ...h,
1301
- id: l.id,
1310
+ id: d.id,
1302
1311
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1303
- scope: l.scope
1312
+ scope: d.scope
1304
1313
  }
1305
1314
  );
1306
1315
  else {
@@ -1319,40 +1328,40 @@ const Ao = (t, e) => ({
1319
1328
  modified: i,
1320
1329
  body: s,
1321
1330
  ...a
1322
- } = t, r = Xn(s, e), l = Hn(t);
1323
- return "error" in l ? { error: l.error } : {
1331
+ } = t, r = Xn(s, e), d = Hn(t);
1332
+ return "error" in d ? { error: d.error } : {
1324
1333
  parsed: {
1325
1334
  ...a,
1326
1335
  id: e,
1327
1336
  bodies: r,
1328
- target: l.parsed
1337
+ target: d.parsed
1329
1338
  }
1330
1339
  };
1331
1340
  }, zn = (t, e, n) => {
1332
1341
  const { bodies: o, target: i, ...s } = t, {
1333
1342
  selector: a,
1334
1343
  creator: r,
1335
- created: l,
1344
+ created: d,
1336
1345
  updated: f,
1337
1346
  ...h
1338
- } = i, u = a.map((p) => {
1339
- const { id: g, quote: b, start: w, end: y, range: d } = p, { prefix: c, suffix: A } = Re(d, n), E = [{
1347
+ } = i, u = a.map((g) => {
1348
+ const { id: v, quote: p, start: y, end: x, range: l } = g, { prefix: c, suffix: b } = Re(l, n), S = [{
1340
1349
  type: "TextQuoteSelector",
1341
- exact: b,
1350
+ exact: p,
1342
1351
  prefix: c,
1343
- suffix: A
1352
+ suffix: b
1344
1353
  }, {
1345
1354
  type: "TextPositionSelector",
1346
- start: w,
1347
- end: y
1355
+ start: y,
1356
+ end: x
1348
1357
  }];
1349
1358
  return {
1350
1359
  ...h,
1351
- id: g,
1360
+ id: v,
1352
1361
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1353
- scope: "scope" in p ? p.scope : void 0,
1362
+ scope: "scope" in g ? g.scope : void 0,
1354
1363
  source: e,
1355
- selector: E
1364
+ selector: S
1356
1365
  };
1357
1366
  });
1358
1367
  return {
@@ -1362,7 +1371,7 @@ const Ao = (t, e) => ({
1362
1371
  type: "Annotation",
1363
1372
  body: Pn(t.bodies),
1364
1373
  creator: r,
1365
- created: l == null ? void 0 : l.toISOString(),
1374
+ created: d == null ? void 0 : d.toISOString(),
1366
1375
  modified: f == null ? void 0 : f.toISOString(),
1367
1376
  target: u
1368
1377
  };
@@ -1370,8 +1379,8 @@ const Ao = (t, e) => ({
1370
1379
  function me(t, e, n = 0, o = t.length - 1, i = Fn) {
1371
1380
  for (; o > n; ) {
1372
1381
  if (o - n > 600) {
1373
- const l = o - n + 1, f = e - n + 1, h = Math.log(l), u = 0.5 * Math.exp(2 * h / 3), p = 0.5 * Math.sqrt(h * u * (l - u) / l) * (f - l / 2 < 0 ? -1 : 1), g = Math.max(n, Math.floor(e - f * u / l + p)), b = Math.min(o, Math.floor(e + (l - f) * u / l + p));
1374
- me(t, e, g, b, i);
1382
+ const d = o - n + 1, f = e - n + 1, h = Math.log(d), u = 0.5 * Math.exp(2 * h / 3), g = 0.5 * Math.sqrt(h * u * (d - u) / d) * (f - d / 2 < 0 ? -1 : 1), v = Math.max(n, Math.floor(e - f * u / d + g)), p = Math.min(o, Math.floor(e + (d - f) * u / d + g));
1383
+ me(t, e, v, p, i);
1375
1384
  }
1376
1385
  const s = t[e];
1377
1386
  let a = n, r = o;
@@ -1403,8 +1412,8 @@ class Wn {
1403
1412
  const i = this.toBBox, s = [];
1404
1413
  for (; n; ) {
1405
1414
  for (let a = 0; a < n.children.length; a++) {
1406
- const r = n.children[a], l = n.leaf ? i(r) : r;
1407
- mt(e, l) && (n.leaf ? o.push(r) : Rt(e, l) ? this._all(r, o) : s.push(r));
1415
+ const r = n.children[a], d = n.leaf ? i(r) : r;
1416
+ mt(e, d) && (n.leaf ? o.push(r) : kt(e, d) ? this._all(r, o) : s.push(r));
1408
1417
  }
1409
1418
  n = s.pop();
1410
1419
  }
@@ -1418,7 +1427,7 @@ class Wn {
1418
1427
  for (let i = 0; i < n.children.length; i++) {
1419
1428
  const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
1420
1429
  if (mt(e, a)) {
1421
- if (n.leaf || Rt(e, a)) return !0;
1430
+ if (n.leaf || kt(e, a)) return !0;
1422
1431
  o.push(s);
1423
1432
  }
1424
1433
  }
@@ -1457,14 +1466,14 @@ class Wn {
1457
1466
  if (!e) return this;
1458
1467
  let o = this.data;
1459
1468
  const i = this.toBBox(e), s = [], a = [];
1460
- let r, l, f;
1469
+ let r, d, f;
1461
1470
  for (; o || s.length; ) {
1462
- if (o || (o = s.pop(), l = s[s.length - 1], r = a.pop(), f = !0), o.leaf) {
1471
+ if (o || (o = s.pop(), d = s[s.length - 1], r = a.pop(), f = !0), o.leaf) {
1463
1472
  const h = qn(e, o.children, n);
1464
1473
  if (h !== -1)
1465
1474
  return o.children.splice(h, 1), s.push(o), this._condense(s), this;
1466
1475
  }
1467
- !f && !o.leaf && Rt(o, i) ? (s.push(o), a.push(r), r = 0, l = o, o = o.children[0]) : l ? (r++, o = l.children[r], f = !1) : o = null;
1476
+ !f && !o.leaf && kt(o, i) ? (s.push(o), a.push(r), r = 0, d = o, o = o.children[0]) : d ? (r++, o = d.children[r], f = !1) : o = null;
1468
1477
  }
1469
1478
  return this;
1470
1479
  }
@@ -1495,14 +1504,14 @@ class Wn {
1495
1504
  if (s <= a)
1496
1505
  return r = Z(e.slice(n, o + 1)), J(r, this.toBBox), r;
1497
1506
  i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = Z([]), r.leaf = !1, r.height = i;
1498
- const l = Math.ceil(s / a), f = l * Math.ceil(Math.sqrt(a));
1507
+ const d = Math.ceil(s / a), f = d * Math.ceil(Math.sqrt(a));
1499
1508
  ee(e, n, o, f, this.compareMinX);
1500
1509
  for (let h = n; h <= o; h += f) {
1501
1510
  const u = Math.min(h + f - 1, o);
1502
- ee(e, h, u, l, this.compareMinY);
1503
- for (let p = h; p <= u; p += l) {
1504
- const g = Math.min(p + l - 1, u);
1505
- r.children.push(this._build(e, p, g, i - 1));
1511
+ ee(e, h, u, d, this.compareMinY);
1512
+ for (let g = h; g <= u; g += d) {
1513
+ const v = Math.min(g + d - 1, u);
1514
+ r.children.push(this._build(e, g, v, i - 1));
1506
1515
  }
1507
1516
  }
1508
1517
  return J(r, this.toBBox), r;
@@ -1510,8 +1519,8 @@ class Wn {
1510
1519
  _chooseSubtree(e, n, o, i) {
1511
1520
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1512
1521
  let s = 1 / 0, a = 1 / 0, r;
1513
- for (let l = 0; l < n.children.length; l++) {
1514
- const f = n.children[l], h = Bt(f), u = Jn(e, f) - h;
1522
+ for (let d = 0; d < n.children.length; d++) {
1523
+ const f = n.children[d], h = Rt(f), u = Jn(e, f) - h;
1515
1524
  u < a ? (a = u, s = h < s ? h : s, r = f) : u === a && h < s && (s = h, r = f);
1516
1525
  }
1517
1526
  n = r || n.children[0];
@@ -1537,7 +1546,7 @@ class Wn {
1537
1546
  _chooseSplitIndex(e, n, o) {
1538
1547
  let i, s = 1 / 0, a = 1 / 0;
1539
1548
  for (let r = n; r <= o - n; r++) {
1540
- const l = st(e, 0, r, this.toBBox), f = st(e, r, o, this.toBBox), h = Zn(l, f), u = Bt(l) + Bt(f);
1549
+ const d = st(e, 0, r, this.toBBox), f = st(e, r, o, this.toBBox), h = Zn(d, f), u = Rt(d) + Rt(f);
1541
1550
  h < s ? (s = h, i = r, a = u < a ? u : a) : h === s && u < a && (a = u, i = r);
1542
1551
  }
1543
1552
  return i || o - n;
@@ -1551,16 +1560,16 @@ class Wn {
1551
1560
  _allDistMargin(e, n, o, i) {
1552
1561
  e.children.sort(i);
1553
1562
  const s = this.toBBox, a = st(e, 0, n, s), r = st(e, o - n, o, s);
1554
- let l = gt(a) + gt(r);
1563
+ let d = pt(a) + pt(r);
1555
1564
  for (let f = n; f < o - n; f++) {
1556
1565
  const h = e.children[f];
1557
- rt(a, e.leaf ? s(h) : h), l += gt(a);
1566
+ rt(a, e.leaf ? s(h) : h), d += pt(a);
1558
1567
  }
1559
1568
  for (let f = o - n - 1; f >= n; f--) {
1560
1569
  const h = e.children[f];
1561
- rt(r, e.leaf ? s(h) : h), l += gt(r);
1570
+ rt(r, e.leaf ? s(h) : h), d += pt(r);
1562
1571
  }
1563
- return l;
1572
+ return d;
1564
1573
  }
1565
1574
  _adjustParentBBoxes(e, n, o) {
1566
1575
  for (let i = o; i >= 0; i--)
@@ -1597,10 +1606,10 @@ function Gn(t, e) {
1597
1606
  function Qn(t, e) {
1598
1607
  return t.minY - e.minY;
1599
1608
  }
1600
- function Bt(t) {
1609
+ function Rt(t) {
1601
1610
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1602
1611
  }
1603
- function gt(t) {
1612
+ function pt(t) {
1604
1613
  return t.maxX - t.minX + (t.maxY - t.minY);
1605
1614
  }
1606
1615
  function Jn(t, e) {
@@ -1610,7 +1619,7 @@ function Zn(t, e) {
1610
1619
  const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), s = Math.min(t.maxY, e.maxY);
1611
1620
  return Math.max(0, i - n) * Math.max(0, s - o);
1612
1621
  }
1613
- function Rt(t, e) {
1622
+ function kt(t, e) {
1614
1623
  return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1615
1624
  }
1616
1625
  function mt(t, e) {
@@ -1636,133 +1645,129 @@ function ee(t, e, n, o, i) {
1636
1645
  }
1637
1646
  }
1638
1647
  const to = (t, e) => {
1639
- const n = new Wn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1640
- const A = d.selector.flatMap((T) => {
1641
- const S = F([T]) ? T.range : ae(T, e).range;
1642
- return Array.from(S.getClientRects());
1643
- }), E = Ue(A).map(({ left: T, top: S, right: O, bottom: M }) => new DOMRect(T - c.left, S - c.top, O - T, M - S));
1644
- return E.map((T) => {
1645
- const { x: S, y: O, width: M, height: L } = T;
1648
+ const n = new Wn(), o = /* @__PURE__ */ new Map(), i = (l, c) => {
1649
+ const b = l.selector.flatMap((E) => {
1650
+ const C = F([E]) ? E.range : ae(E, e).range;
1651
+ return Array.from(C.getClientRects());
1652
+ }), S = Ue(b).map(({ left: E, top: C, right: O, bottom: B }) => new DOMRect(E - c.left, C - c.top, O - E, B - C));
1653
+ return S.map((E) => {
1654
+ const { x: C, y: O, width: B, height: T } = E;
1646
1655
  return {
1647
- minX: S,
1656
+ minX: C,
1648
1657
  minY: O,
1649
- maxX: S + M,
1650
- maxY: O + L,
1658
+ maxX: C + B,
1659
+ maxY: O + T,
1651
1660
  annotation: {
1652
- id: d.annotation,
1653
- rects: E
1661
+ id: l.annotation,
1662
+ rects: S
1654
1663
  }
1655
1664
  };
1656
1665
  });
1657
1666
  }, s = () => [...o.values()], a = () => {
1658
1667
  n.clear(), o.clear();
1659
- }, r = (d) => {
1660
- const c = i(d, e.getBoundingClientRect());
1661
- c.forEach((A) => n.insert(A)), o.set(d.annotation, c);
1662
- }, l = (d) => {
1663
- const c = o.get(d.annotation);
1664
- c && (c.forEach((A) => n.remove(A)), o.delete(d.annotation));
1665
- }, f = (d) => {
1666
- l(d), r(d);
1667
- }, h = (d, c = !0) => {
1668
+ }, r = (l) => {
1669
+ const c = i(l, e.getBoundingClientRect());
1670
+ c.length !== 0 && (c.forEach((b) => n.insert(b)), o.set(l.annotation, c));
1671
+ }, d = (l) => {
1672
+ const c = o.get(l.annotation);
1673
+ c && (c.forEach((b) => n.remove(b)), o.delete(l.annotation));
1674
+ }, f = (l) => {
1675
+ d(l), r(l);
1676
+ }, h = (l, c = !0) => {
1668
1677
  c && a();
1669
- const A = e.getBoundingClientRect(), E = d.map((S) => ({ target: S, rects: i(S, A) }));
1670
- E.forEach(({ target: S, rects: O }) => o.set(S.annotation, O));
1671
- const T = E.flatMap(({ rects: S }) => S);
1672
- n.load(T);
1673
- }, u = (d, c, A = !1) => {
1674
- const E = n.search({
1675
- minX: d,
1678
+ const b = e.getBoundingClientRect(), S = l.map((C) => ({ target: C, rects: i(C, b) }));
1679
+ S.forEach(({ target: C, rects: O }) => {
1680
+ O.length > 0 && o.set(C.annotation, O);
1681
+ });
1682
+ const E = S.flatMap(({ rects: C }) => C);
1683
+ n.load(E);
1684
+ }, u = (l, c, b = !1) => {
1685
+ const S = n.search({
1686
+ minX: l,
1676
1687
  minY: c,
1677
- maxX: d,
1688
+ maxX: l,
1678
1689
  maxY: c
1679
- }), T = (S) => S.annotation.rects.reduce((O, M) => O + M.width * M.height, 0);
1680
- return E.length > 0 ? (E.sort((S, O) => T(S) - T(O)), A ? E.map((S) => S.annotation.id) : [E[0].annotation.id]) : [];
1681
- }, p = (d) => {
1682
- const c = g(d);
1690
+ }), E = (C) => C.annotation.rects.reduce((O, B) => O + B.width * B.height, 0);
1691
+ return S.length > 0 ? (S.sort((C, O) => E(C) - E(O)), b ? S.map((C) => C.annotation.id) : [S[0].annotation.id]) : [];
1692
+ }, g = (l) => {
1693
+ const c = v(l);
1683
1694
  if (c.length === 0)
1684
1695
  return;
1685
- let A = c[0].left, E = c[0].top, T = c[0].right, S = c[0].bottom;
1696
+ let b = c[0].left, S = c[0].top, E = c[0].right, C = c[0].bottom;
1686
1697
  for (let O = 1; O < c.length; O++) {
1687
- const M = c[O];
1688
- A = Math.min(A, M.left), E = Math.min(E, M.top), T = Math.max(T, M.right), S = Math.max(S, M.bottom);
1698
+ const B = c[O];
1699
+ b = Math.min(b, B.left), S = Math.min(S, B.top), E = Math.max(E, B.right), C = Math.max(C, B.bottom);
1689
1700
  }
1690
- return new DOMRect(A, E, T - A, S - E);
1691
- }, g = (d) => {
1692
- const c = o.get(d);
1701
+ return new DOMRect(b, S, E - b, C - S);
1702
+ }, v = (l) => {
1703
+ const c = o.get(l);
1693
1704
  return c ? c[0].annotation.rects : [];
1694
1705
  };
1695
1706
  return {
1696
1707
  all: s,
1697
1708
  clear: a,
1698
1709
  getAt: u,
1699
- getAnnotationBounds: p,
1700
- getAnnotationRects: g,
1701
- getIntersecting: (d, c, A, E) => {
1702
- const T = n.search({ minX: d, minY: c, maxX: A, maxY: E }), S = new Set(T.map((O) => O.annotation.id));
1703
- return Array.from(S).map((O) => ({
1710
+ getAnnotationBounds: g,
1711
+ getAnnotationRects: v,
1712
+ getIntersecting: (l, c, b, S) => {
1713
+ const E = n.search({ minX: l, minY: c, maxX: b, maxY: S }), C = new Set(E.map((O) => O.annotation.id));
1714
+ return Array.from(C).map((O) => ({
1704
1715
  annotation: t.getAnnotation(O),
1705
- rects: g(O)
1716
+ rects: v(O)
1706
1717
  })).filter((O) => !!O.annotation);
1707
1718
  },
1708
1719
  insert: r,
1709
- recalculate: () => h(t.all().map((d) => d.target), !0),
1710
- remove: l,
1720
+ recalculate: () => h(t.all().map((l) => l.target), !0),
1721
+ remove: d,
1711
1722
  set: h,
1712
1723
  size: () => n.all().length,
1713
1724
  update: f
1714
1725
  };
1715
1726
  }, eo = (t, e) => {
1716
- const n = Ln(), o = to(n, t), i = pn(n);
1727
+ const n = Ln(), o = to(n, t), i = gn(n);
1717
1728
  i.setUserSelectAction(e);
1718
- const s = fn(n), a = Bn(), r = (y, d = k.LOCAL) => {
1719
- const c = xt(y, t), A = F(c.target.selector);
1720
- return A && n.addAnnotation(c, d), A;
1721
- }, l = (y, d = !0, c = k.LOCAL) => {
1722
- const A = y.map((T) => xt(T, t)), E = A.filter((T) => !F(T.target.selector));
1723
- return n.bulkAddAnnotation(A, d, c), E;
1724
- }, f = (y, d = k.LOCAL) => {
1725
- const c = y.map((E) => xt(E, t)), A = c.filter((E) => !F(E.target.selector));
1726
- return c.forEach((E) => {
1727
- n.getAnnotation(E.id) ? n.updateAnnotation(E, d) : n.addAnnotation(E, d);
1728
- }), A;
1729
- }, h = (y, d = k.LOCAL) => {
1730
- const c = bt(y, t);
1731
- n.updateTarget(c, d);
1732
- }, u = (y, d = k.LOCAL) => {
1733
- const c = y.map((A) => bt(A, t));
1734
- n.bulkUpdateTargets(c, d);
1729
+ const s = fn(n), a = Mn(), r = (l, c = k.LOCAL) => {
1730
+ const b = vt(l, t), S = F(b.target.selector);
1731
+ return S && n.addAnnotation(b, c), S;
1732
+ }, d = (l, c = !0, b = k.LOCAL) => {
1733
+ const S = l.map((C) => vt(C, t)), E = S.filter((C) => !F(C.target.selector));
1734
+ return n.bulkAddAnnotation(S, c, b), E;
1735
+ }, f = (l, c = k.LOCAL) => {
1736
+ const b = l.map((E) => vt(E, t)), S = b.filter((E) => !F(E.target.selector));
1737
+ return b.forEach((E) => {
1738
+ n.getAnnotation(E.id) ? n.updateAnnotation(E, c) : n.addAnnotation(E, c);
1739
+ }), S;
1740
+ }, h = (l, c = k.LOCAL) => {
1741
+ const b = wt(l, t);
1742
+ n.updateTarget(b, c);
1743
+ }, u = (l, c = k.LOCAL) => {
1744
+ const b = l.map((S) => wt(S, t));
1745
+ n.bulkUpdateTargets(b, c);
1735
1746
  };
1736
- function p(y, d, c, A) {
1737
- const E = c || !!A, T = o.getAt(y, d, E).map((O) => n.getAnnotation(O)), S = A ? T.filter(A) : T;
1738
- if (S.length !== 0)
1739
- return c ? S : S[0];
1747
+ function g(l, c, b, S) {
1748
+ const E = b || !!S, C = o.getAt(l, c, E).map((B) => n.getAnnotation(B)), O = S ? C.filter(S) : C;
1749
+ if (O.length !== 0)
1750
+ return b ? O : O[0];
1740
1751
  }
1741
- const g = (y, d, c, A = 5) => {
1742
- const E = o.getAnnotationRects(y);
1743
- if (E.length !== 0) {
1744
- if (d && c) {
1745
- const T = E.find(({ top: S, right: O, bottom: M, left: L }) => d >= L - A && d <= O + A && c >= S - A && c <= M + A);
1746
- if (T) return T;
1747
- }
1748
- return o.getAnnotationBounds(y);
1749
- }
1750
- }, b = (y) => o.getAnnotationRects(y), w = () => o.recalculate();
1751
- return n.observe(({ changes: y }) => {
1752
- const d = (y.deleted || []).filter((E) => F(E.target.selector)), c = (y.created || []).filter((E) => F(E.target.selector)), A = (y.updated || []).filter((E) => F(E.newValue.target.selector));
1753
- (d == null ? void 0 : d.length) > 0 && d.forEach((E) => o.remove(E.target)), c.length > 0 && o.set(c.map((E) => E.target), !1), (A == null ? void 0 : A.length) > 0 && A.forEach(({ newValue: E }) => o.update(E.target));
1752
+ const v = (l) => {
1753
+ if (o.getAnnotationRects(l).length !== 0)
1754
+ return o.getAnnotationBounds(l);
1755
+ }, p = (l, c, b, S) => o.getIntersecting(l, c, b, S), y = (l) => o.getAnnotationRects(l), x = () => o.recalculate();
1756
+ return n.observe(({ changes: l }) => {
1757
+ const c = (l.deleted || []).filter((E) => F(E.target.selector)), b = (l.created || []).filter((E) => F(E.target.selector)), S = (l.updated || []).filter((E) => F(E.newValue.target.selector));
1758
+ (c == null ? void 0 : c.length) > 0 && c.forEach((E) => o.remove(E.target)), b.length > 0 && o.set(b.map((E) => E.target), !1), (S == null ? void 0 : S.length) > 0 && S.forEach(({ newValue: E }) => o.update(E.target));
1754
1759
  }), {
1755
1760
  store: {
1756
1761
  ...n,
1757
1762
  addAnnotation: r,
1758
- bulkAddAnnotation: l,
1763
+ bulkAddAnnotation: d,
1759
1764
  bulkUpdateTargets: u,
1760
1765
  bulkUpsertAnnotations: f,
1761
- getAnnotationBounds: g,
1762
- getAnnotationRects: b,
1763
- getAt: p,
1764
- getIntersecting: o.getIntersecting,
1765
- recalculatePositions: w,
1766
+ getAnnotationBounds: v,
1767
+ getAnnotationRects: y,
1768
+ getIntersecting: p,
1769
+ getAt: g,
1770
+ recalculatePositions: x,
1766
1771
  updateTarget: h
1767
1772
  },
1768
1773
  selection: i,
@@ -1777,9 +1782,9 @@ const to = (t, e) => {
1777
1782
  }, oo = (t, e = {}) => {
1778
1783
  const n = no(), o = n.getContext("2d");
1779
1784
  document.body.appendChild(n);
1780
- const i = /* @__PURE__ */ new Map(), s = (h) => Array.from(i.entries()).filter(([u, p]) => p.presenceKey === h.presenceKey).map(([u, p]) => u);
1785
+ const i = /* @__PURE__ */ new Map(), s = (h) => Array.from(i.entries()).filter(([u, g]) => g.presenceKey === h.presenceKey).map(([u, g]) => u);
1781
1786
  return t.on("selectionChange", (h, u) => {
1782
- s(h).forEach((g) => i.delete(g)), u && u.forEach((g) => i.set(g, h));
1787
+ s(h).forEach((v) => i.delete(v)), u && u.forEach((v) => i.set(v, h));
1783
1788
  }), {
1784
1789
  clear: () => {
1785
1790
  const { width: h, height: u } = n;
@@ -1788,16 +1793,16 @@ const to = (t, e) => {
1788
1793
  destroy: () => {
1789
1794
  n.remove();
1790
1795
  },
1791
- paint: (h, u, p) => {
1796
+ paint: (h, u, g) => {
1792
1797
  e.font && (o.font = e.font);
1793
- const g = i.get(h.annotation.id);
1794
- if (g) {
1795
- const { height: b } = h.rects[0], w = h.rects[0].x + u.left, y = h.rects[0].y + u.top;
1796
- o.fillStyle = g.appearance.color, o.fillRect(w - 2, y - 2.5, 2, b + 5);
1797
- const d = o.measureText(g.appearance.label), c = d.width + 6, A = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, E = d.fontBoundingBoxAscent ? 8 : 6.5;
1798
- return o.fillRect(w - 2, y - 2.5 - A, c, A), o.fillStyle = "#fff", o.fillText(g.appearance.label, w + 1, y - E), {
1799
- fill: g.appearance.color,
1800
- fillOpacity: p ? 0.45 : 0.18
1798
+ const v = i.get(h.annotation.id);
1799
+ if (v) {
1800
+ const { height: p } = h.rects[0], y = h.rects[0].x + u.left, x = h.rects[0].y + u.top;
1801
+ o.fillStyle = v.appearance.color, o.fillRect(y - 2, x - 2.5, 2, p + 5);
1802
+ const l = o.measureText(v.appearance.label), c = l.width + 6, b = l.actualBoundingBoxAscent + l.actualBoundingBoxDescent + 8, S = l.fontBoundingBoxAscent ? 8 : 6.5;
1803
+ return o.fillRect(y - 2, x - 2.5 - b, c, b), o.fillStyle = "#fff", o.fillText(v.appearance.label, y + 1, x - S), {
1804
+ fill: v.appearance.color,
1805
+ fillOpacity: g ? 0.45 : 0.18
1801
1806
  };
1802
1807
  }
1803
1808
  },
@@ -1807,8 +1812,8 @@ const to = (t, e) => {
1807
1812
  h.scale(2, 2), h.translate(0.5, 0.5);
1808
1813
  }
1809
1814
  };
1810
- }, kt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1811
- function It(t, e, n, o) {
1815
+ }, It = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1816
+ function _t(t, e, n, o) {
1812
1817
  t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
1813
1818
  }
1814
1819
  function ot(t, e, n, o) {
@@ -1879,9 +1884,9 @@ const lt = {
1879
1884
  ".": 190,
1880
1885
  "/": 191,
1881
1886
  "`": 192,
1882
- "-": kt ? 173 : 189,
1883
- "=": kt ? 61 : 187,
1884
- ";": kt ? 59 : 186,
1887
+ "-": It ? 173 : 189,
1888
+ "=": It ? 61 : 187,
1889
+ ";": It ? 59 : 186,
1885
1890
  "'": 222,
1886
1891
  "[": 219,
1887
1892
  "]": 221,
@@ -1902,7 +1907,7 @@ const lt = {
1902
1907
  "⌘": 91,
1903
1908
  cmd: 91,
1904
1909
  command: 91
1905
- }, Vt = {
1910
+ }, bt = {
1906
1911
  16: "shiftKey",
1907
1912
  18: "altKey",
1908
1913
  17: "ctrlKey",
@@ -1911,7 +1916,7 @@ const lt = {
1911
1916
  ctrlKey: 17,
1912
1917
  altKey: 18,
1913
1918
  metaKey: 91
1914
- }, D = {
1919
+ }, K = {
1915
1920
  16: !1,
1916
1921
  18: !1,
1917
1922
  17: !1,
@@ -1977,11 +1982,11 @@ function ho(t, e) {
1977
1982
  }) : o++;
1978
1983
  dt() === t && Ae(e || "all");
1979
1984
  }
1980
- function po(t) {
1985
+ function go(t) {
1981
1986
  let e = t.keyCode || t.which || t.charCode;
1982
1987
  const n = I.indexOf(e);
1983
- if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in D) {
1984
- D[e] = !1;
1988
+ if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in K) {
1989
+ K[e] = !1;
1985
1990
  for (const o in H) H[o] === e && (P[o] = !1);
1986
1991
  }
1987
1992
  }
@@ -2016,14 +2021,14 @@ const yt = (t) => {
2016
2021
  splitKey: i = "+"
2017
2022
  } = t;
2018
2023
  be(e).forEach((a) => {
2019
- const r = a.split(i), l = r.length, f = r[l - 1], h = f === "*" ? "*" : ut(f);
2024
+ const r = a.split(i), d = r.length, f = r[d - 1], h = f === "*" ? "*" : ut(f);
2020
2025
  if (!_[h]) return;
2021
2026
  n || (n = dt());
2022
- const u = l > 1 ? ye(H, r) : [], p = [];
2023
- _[h] = _[h].filter((g) => {
2024
- const w = (o ? g.method === o : !0) && g.scope === n && io(g.mods, u);
2025
- return w && p.push(g.element), !w;
2026
- }), p.forEach((g) => Xt(g));
2027
+ const u = d > 1 ? ye(H, r) : [], g = [];
2028
+ _[h] = _[h].filter((v) => {
2029
+ const y = (o ? v.method === o : !0) && v.scope === n && io(v.mods, u);
2030
+ return y && g.push(v.element), !y;
2031
+ }), g.forEach((v) => Xt(v));
2027
2032
  });
2028
2033
  };
2029
2034
  function ne(t, e, n, o) {
@@ -2032,27 +2037,27 @@ function ne(t, e, n, o) {
2032
2037
  let i;
2033
2038
  if (e.scope === n || e.scope === "all") {
2034
2039
  i = e.mods.length > 0;
2035
- for (const s in D)
2036
- Object.prototype.hasOwnProperty.call(D, s) && (!D[s] && e.mods.indexOf(+s) > -1 || D[s] && e.mods.indexOf(+s) === -1) && (i = !1);
2037
- (e.mods.length === 0 && !D[16] && !D[18] && !D[17] && !D[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(I), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2040
+ for (const s in K)
2041
+ Object.prototype.hasOwnProperty.call(K, s) && (!K[s] && e.mods.indexOf(+s) > -1 || K[s] && e.mods.indexOf(+s) === -1) && (i = !1);
2042
+ (e.mods.length === 0 && !K[16] && !K[18] && !K[17] && !K[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(I), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2038
2043
  }
2039
2044
  }
2040
2045
  function oe(t, e) {
2041
2046
  const n = _["*"];
2042
2047
  let o = t.keyCode || t.which || t.charCode;
2043
2048
  if (!P.filter.call(this, t)) return;
2044
- if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((r) => {
2045
- const l = Vt[r];
2046
- t[r] && I.indexOf(l) === -1 ? I.push(l) : !t[r] && I.indexOf(l) > -1 ? I.splice(I.indexOf(l), 1) : r === "metaKey" && t[r] && I.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (I = I.slice(I.indexOf(l))));
2047
- }), o in D) {
2048
- D[o] = !0;
2049
+ if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["metaKey", "ctrlKey", "altKey", "shiftKey"].forEach((r) => {
2050
+ const d = bt[r];
2051
+ t[r] && I.indexOf(d) === -1 ? I.push(d) : !t[r] && I.indexOf(d) > -1 ? I.splice(I.indexOf(d), 1) : r === "metaKey" && t[r] && (I = I.filter((f) => f in bt || f === o));
2052
+ }), o in K) {
2053
+ K[o] = !0;
2049
2054
  for (const r in H)
2050
2055
  H[r] === o && (P[r] = !0);
2051
2056
  if (!n) return;
2052
2057
  }
2053
- for (const r in D)
2054
- Object.prototype.hasOwnProperty.call(D, r) && (D[r] = t[Vt[r]]);
2055
- t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), D[17] = !0, D[18] = !0);
2058
+ for (const r in K)
2059
+ Object.prototype.hasOwnProperty.call(K, r) && (K[r] = t[bt[r]]);
2060
+ t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), K[17] = !0, K[18] = !0);
2056
2061
  const i = dt();
2057
2062
  if (n)
2058
2063
  for (let r = 0; r < n.length; r++)
@@ -2061,21 +2066,21 @@ function oe(t, e) {
2061
2066
  const s = _[o], a = s.length;
2062
2067
  for (let r = 0; r < a; r++)
2063
2068
  if ((t.type === "keydown" && s[r].keydown || t.type === "keyup" && s[r].keyup) && s[r].key) {
2064
- const l = s[r], {
2069
+ const d = s[r], {
2065
2070
  splitKey: f
2066
- } = l, h = l.key.split(f), u = [];
2067
- for (let p = 0; p < h.length; p++)
2068
- u.push(ut(h[p]));
2069
- u.sort().join("") === I.sort().join("") && ne(t, l, i, e);
2071
+ } = d, h = d.key.split(f), u = [];
2072
+ for (let g = 0; g < h.length; g++)
2073
+ u.push(ut(h[g]));
2074
+ u.sort().join("") === I.sort().join("") && ne(t, d, i, e);
2070
2075
  }
2071
2076
  }
2072
2077
  function P(t, e, n) {
2073
2078
  I = [];
2074
2079
  const o = be(t);
2075
- let i = [], s = "all", a = document, r = 0, l = !1, f = !0, h = "+", u = !1, p = !1;
2076
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (u = e.capture), typeof e.splitKey == "string" && (h = e.splitKey), e.single === !0 && (p = !0)), typeof e == "string" && (s = e), p && xe(t, s); r < o.length; r++)
2080
+ let i = [], s = "all", a = document, r = 0, d = !1, f = !0, h = "+", u = !1, g = !1;
2081
+ for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (d = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (u = e.capture), typeof e.splitKey == "string" && (h = e.splitKey), e.single === !0 && (g = !0)), typeof e == "string" && (s = e), g && xe(t, s); r < o.length; r++)
2077
2082
  t = o[r].split(h), i = [], t.length > 1 && (i = ye(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : ut(t), t in _ || (_[t] = []), _[t].push({
2078
- keyup: l,
2083
+ keyup: d,
2079
2084
  keydown: f,
2080
2085
  scope: s,
2081
2086
  mods: i,
@@ -2087,31 +2092,31 @@ function P(t, e, n) {
2087
2092
  });
2088
2093
  if (typeof a < "u" && window) {
2089
2094
  if (!z.has(a)) {
2090
- const g = function() {
2091
- let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2092
- return oe(w, a);
2093
- }, b = function() {
2094
- let w = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2095
- oe(w, a), po(w);
2095
+ const v = function() {
2096
+ let y = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2097
+ return oe(y, a);
2098
+ }, p = function() {
2099
+ let y = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2100
+ oe(y, a), go(y);
2096
2101
  };
2097
2102
  z.set(a, {
2098
- keydownListener: g,
2099
- keyupListenr: b,
2103
+ keydownListener: v,
2104
+ keyupListenr: p,
2100
2105
  capture: u
2101
- }), It(a, "keydown", g, u), It(a, "keyup", b, u);
2106
+ }), _t(a, "keydown", v, u), _t(a, "keyup", p, u);
2102
2107
  }
2103
2108
  if (!ct) {
2104
- const g = () => {
2109
+ const v = () => {
2105
2110
  I = [];
2106
2111
  };
2107
2112
  ct = {
2108
- listener: g,
2113
+ listener: v,
2109
2114
  capture: u
2110
- }, It(window, "focus", g, u);
2115
+ }, _t(window, "focus", v, u);
2111
2116
  }
2112
2117
  }
2113
2118
  }
2114
- function go(t) {
2119
+ function po(t) {
2115
2120
  let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
2116
2121
  Object.keys(_).forEach((n) => {
2117
2122
  _[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
@@ -2149,7 +2154,7 @@ function Xt(t) {
2149
2154
  ot(window, "focus", i, s), ct = null;
2150
2155
  }
2151
2156
  }
2152
- const _t = {
2157
+ const Nt = {
2153
2158
  getPressedKeyString: co,
2154
2159
  setScope: Ae,
2155
2160
  getScope: dt,
@@ -2158,14 +2163,14 @@ const _t = {
2158
2163
  getAllKeyCodes: lo,
2159
2164
  isPressed: fo,
2160
2165
  filter: uo,
2161
- trigger: go,
2166
+ trigger: po,
2162
2167
  unbind: xe,
2163
2168
  keyMap: lt,
2164
2169
  modifier: H,
2165
- modifierMap: Vt
2170
+ modifierMap: bt
2166
2171
  };
2167
- for (const t in _t)
2168
- Object.prototype.hasOwnProperty.call(_t, t) && (P[t] = _t[t]);
2172
+ for (const t in Nt)
2173
+ Object.prototype.hasOwnProperty.call(Nt, t) && (P[t] = Nt[t]);
2169
2174
  if (typeof window < "u") {
2170
2175
  const t = window.hotkeys;
2171
2176
  P.noConflict = (e) => (e && window.hotkeys === P && (window.hotkeys = t), P), window.hotkeys = P;
@@ -2175,96 +2180,98 @@ const ie = 300, ve = ["up", "down", "left", "right"], Ee = Te ? "⌘+a" : "ctrl+
2175
2180
  Ee
2176
2181
  ], yo = (t, e, n) => {
2177
2182
  let o;
2178
- const { annotatingEnabled: i, offsetReferenceSelector: s, selectionMode: a } = n, r = (L) => o = L;
2179
- let l;
2180
- const f = (L) => l = L, { store: h, selection: u } = e;
2181
- let p, g, b;
2182
- const w = (L) => {
2183
- g !== !1 && (p = it(L.target) ? void 0 : {
2183
+ const { annotatingEnabled: i, offsetReferenceSelector: s, selectionMode: a } = n, r = (T) => o = T;
2184
+ let d;
2185
+ const f = (T) => d = T, { store: h, selection: u } = e;
2186
+ let g, v, p;
2187
+ const y = (T) => {
2188
+ v !== !1 && (g = it(T.target) ? void 0 : {
2184
2189
  annotation: fe(),
2185
2190
  selector: [],
2186
2191
  creator: o,
2187
2192
  created: /* @__PURE__ */ new Date()
2188
2193
  });
2189
- }, y = Yt((L) => {
2194
+ }, x = Yt((T) => {
2190
2195
  const m = document.getSelection();
2196
+ if (!(m != null && m.anchorNode))
2197
+ return;
2191
2198
  if (it(m.anchorNode)) {
2192
- p = void 0;
2199
+ g = void 0;
2193
2200
  return;
2194
2201
  }
2195
- const v = L.timeStamp - ((b == null ? void 0 : b.timeStamp) || L.timeStamp);
2196
- if ((b == null ? void 0 : b.type) === "pointerdown" && (v < 1e3 && !p || m.isCollapsed && v < ie) && w(b || L), !p) return;
2202
+ const A = T.timeStamp - ((p == null ? void 0 : p.timeStamp) || T.timeStamp);
2203
+ if ((p == null ? void 0 : p.type) === "pointerdown" && (A < 1e3 && !g || m.isCollapsed && A < ie) && y(p || T), !g) return;
2197
2204
  if (m.isCollapsed) {
2198
- h.getAnnotation(p.annotation) && (u.clear(), h.deleteAnnotation(p.annotation));
2205
+ h.getAnnotation(g.annotation) && (u.clear(), h.deleteAnnotation(g.annotation));
2199
2206
  return;
2200
2207
  }
2201
- const x = m.getRangeAt(0), C = Ye(x, t);
2202
- if (Ie(C)) return;
2203
- const B = Be(C.cloneRange());
2204
- (B.length !== p.selector.length || B.some((N, U) => {
2208
+ const w = m.getRangeAt(0), L = Ye(w, t);
2209
+ if (Ie(L)) return;
2210
+ const M = Me(L.cloneRange());
2211
+ (M.length !== g.selector.length || M.some((N, U) => {
2205
2212
  var et;
2206
- return N.toString() !== ((et = p.selector[U]) == null ? void 0 : et.quote);
2207
- })) && (p = {
2208
- ...p,
2209
- selector: B.map((N) => Ve(N, t, s)),
2213
+ return N.toString() !== ((et = g.selector[U]) == null ? void 0 : et.quote);
2214
+ })) && (g = {
2215
+ ...g,
2216
+ selector: M.map((N) => Ve(N, t, s)),
2210
2217
  updated: /* @__PURE__ */ new Date()
2211
- }, h.getAnnotation(p.annotation) ? h.updateTarget(p, k.LOCAL) : u.clear());
2212
- }), d = (L) => {
2213
- it(L.target) || (b = At(L), g = b.button === 0);
2214
- }, c = (L) => {
2215
- if (it(L.target) || !g) return;
2218
+ }, h.getAnnotation(g.annotation) ? h.updateTarget(g, k.LOCAL) : u.clear());
2219
+ }), l = (T) => {
2220
+ it(T.target) || (p = xt(T), v = p.button === 0);
2221
+ }, c = (T) => {
2222
+ if (it(T.target) || !v) return;
2216
2223
  const m = () => {
2217
- const { x, y: C } = t.getBoundingClientRect(), B = L.target instanceof Node && t.contains(L.target) && h.getAt(L.clientX - x, L.clientY - C, a === "all", l);
2218
- if (B) {
2219
- const { selected: R } = u, N = new Set(R.map((q) => q.id)), U = Array.isArray(B) ? B.map((q) => q.id) : [B.id];
2220
- (N.size !== U.length || !U.every((q) => N.has(q))) && u.userSelect(U, L);
2224
+ const { x: w, y: L } = t.getBoundingClientRect(), M = T.target instanceof Node && t.contains(T.target) && h.getAt(T.clientX - w, T.clientY - L, a === "all", d);
2225
+ if (M) {
2226
+ const { selected: R } = u, N = new Set(R.map((q) => q.id)), U = Array.isArray(M) ? M.map((q) => q.id) : [M.id];
2227
+ (N.size !== U.length || !U.every((q) => N.has(q))) && u.userSelect(U, T);
2221
2228
  } else
2222
2229
  u.clear();
2223
- }, v = L.timeStamp - b.timeStamp;
2230
+ }, A = T.timeStamp - p.timeStamp;
2224
2231
  setTimeout(() => {
2225
- const x = document.getSelection();
2226
- x != null && x.isCollapsed && v < ie ? (p = void 0, m()) : p && p.selector.length > 0 && (u.clear(), O(), u.userSelect(p.annotation, At(L)));
2232
+ const w = document.getSelection();
2233
+ w != null && w.isCollapsed && A < ie ? (g = void 0, m()) : g && g.selector.length > 0 && (O(), u.userSelect(g.annotation, xt(T)));
2227
2234
  });
2228
- }, A = (L) => {
2235
+ }, b = (T) => {
2229
2236
  const m = document.getSelection();
2230
- m != null && m.isCollapsed || ((!p || p.selector.length === 0) && y(L), O(), u.userSelect(p.annotation, At(L)));
2231
- }, E = (L) => {
2232
- L.key === "Shift" && p && (document.getSelection().isCollapsed || (u.clear(), O(), u.userSelect(p.annotation, ft(L))));
2233
- }, T = (L) => {
2237
+ m != null && m.isCollapsed || ((!g || g.selector.length === 0) && x(T), O(), u.userSelect(g.annotation, xt(T)));
2238
+ }, S = (T) => {
2239
+ T.key === "Shift" && g && (document.getSelection().isCollapsed || (O(), u.userSelect(g.annotation, ft(T))));
2240
+ }, E = (T) => {
2234
2241
  const m = () => setTimeout(() => {
2235
- (p == null ? void 0 : p.selector.length) > 0 && (u.clear(), h.addAnnotation({
2236
- id: p.annotation,
2242
+ (g == null ? void 0 : g.selector.length) > 0 && (u.clear(), h.addAnnotation({
2243
+ id: g.annotation,
2237
2244
  bodies: [],
2238
- target: p
2239
- }), u.userSelect(p.annotation, ft(L))), document.removeEventListener("selectionchange", m);
2245
+ target: g
2246
+ }), u.userSelect(g.annotation, ft(T))), document.removeEventListener("selectionchange", m);
2240
2247
  }, 100);
2241
- document.addEventListener("selectionchange", m), w(L);
2248
+ document.addEventListener("selectionchange", m), y(T);
2242
2249
  };
2243
- P(mo.join(","), { element: t, keydown: !0, keyup: !1 }, (L) => {
2244
- L.repeat || (b = ft(L));
2245
- }), P(Ee, { keydown: !0, keyup: !1 }, (L) => {
2246
- b = ft(L), T(L);
2250
+ P(mo.join(","), { element: t, keydown: !0, keyup: !1 }, (T) => {
2251
+ T.repeat || (p = ft(T));
2252
+ }), P(Ee, { keydown: !0, keyup: !1 }, (T) => {
2253
+ p = ft(T), E(T);
2247
2254
  });
2248
- const S = (L) => {
2249
- L.repeat || L.target !== t && L.target !== document.body || (p = void 0, u.clear());
2255
+ const C = (T) => {
2256
+ T.repeat || T.target !== t && T.target !== document.body || (g = void 0, u.clear());
2250
2257
  };
2251
- P(ve.join(","), { keydown: !0, keyup: !1 }, S);
2258
+ P(ve.join(","), { keydown: !0, keyup: !1 }, C);
2252
2259
  const O = () => {
2253
- const L = h.getAnnotation(p.annotation);
2254
- if (!L) {
2260
+ const T = h.getAnnotation(g.annotation);
2261
+ if (!T) {
2255
2262
  h.addAnnotation({
2256
- id: p.annotation,
2263
+ id: g.annotation,
2257
2264
  bodies: [],
2258
- target: p
2265
+ target: g
2259
2266
  });
2260
2267
  return;
2261
2268
  }
2262
- const { target: { updated: m } } = L, { updated: v } = p;
2263
- (!m || !v || m < v) && h.updateTarget(p);
2269
+ const { target: { updated: m } } = T, { updated: A } = g;
2270
+ (!m || !A || m < A) && h.updateTarget(g);
2264
2271
  };
2265
- return t.addEventListener("pointerdown", d), document.addEventListener("pointerup", c), document.addEventListener("contextmenu", A), i && (t.addEventListener("keyup", E), t.addEventListener("selectstart", w), document.addEventListener("selectionchange", y)), {
2272
+ return t.addEventListener("pointerdown", l), document.addEventListener("pointerup", c), document.addEventListener("contextmenu", b), i && (t.addEventListener("keyup", S), t.addEventListener("selectstart", y), document.addEventListener("selectionchange", x)), {
2266
2273
  destroy: () => {
2267
- t.removeEventListener("pointerdown", d), document.removeEventListener("pointerup", c), document.removeEventListener("contextmenu", A), t.removeEventListener("keyup", E), t.removeEventListener("selectstart", w), document.removeEventListener("selectionchange", y), P.unbind();
2274
+ t.removeEventListener("pointerdown", l), document.removeEventListener("pointerup", c), document.removeEventListener("contextmenu", b), t.removeEventListener("keyup", S), t.removeEventListener("selectstart", y), document.removeEventListener("selectionchange", x), P.unbind();
2268
2275
  },
2269
2276
  setFilter: f,
2270
2277
  setUser: r
@@ -2273,85 +2280,86 @@ const ie = 300, ve = ["up", "down", "left", "right"], Ee = Te ? "⌘+a" : "ctrl+
2273
2280
  ...t,
2274
2281
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
2275
2282
  user: t.user || e.user
2276
- }), se = "SPANS", xo = (t, e = {}) => {
2283
+ }), se = "SPANS", vo = (t, e = {}) => {
2277
2284
  Le(t), Oe(t);
2278
2285
  const n = bo(e, {
2279
2286
  annotatingEnabled: !0,
2280
- user: Kn()
2281
- }), o = eo(t, n.userSelectAction), { selection: i, viewport: s } = o, a = o.store, r = Mn(a), l = Rn(o, r, n.adapter);
2287
+ user: Dn()
2288
+ }), o = eo(t, n.userSelectAction), { selection: i, viewport: s } = o, a = o.store, r = Bn(a), d = Rn(o, r, n.adapter);
2282
2289
  let f = n.user;
2283
2290
  const h = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : se : n.renderer || se, u = h === "SPANS" ? rn(t, o, s) : h === "CSS_HIGHLIGHTS" ? nn(t, o, s) : h === "CANVAS" ? ze(t, o, s) : void 0;
2284
2291
  if (!u)
2285
2292
  throw `Unknown renderer implementation: ${h}`;
2286
2293
  console.debug(`Using ${h} renderer`), n.style && u.setStyle(n.style);
2287
- const p = yo(t, o, n);
2288
- return p.setUser(f), {
2294
+ const g = yo(t, o, n);
2295
+ return g.setUser(f), {
2289
2296
  ...In(o, r, n.adapter),
2290
2297
  destroy: () => {
2291
- u.destroy(), p.destroy(), r.destroy();
2298
+ u.destroy(), g.destroy(), r.destroy();
2292
2299
  },
2293
2300
  element: t,
2294
2301
  getUser: () => f,
2295
- setFilter: (S) => {
2296
- u.setFilter(S), p.setFilter(S);
2302
+ setFilter: (C) => {
2303
+ u.setFilter(C), g.setFilter(C);
2297
2304
  },
2298
- setStyle: (S) => u.setStyle(S),
2299
- setUser: (S) => {
2300
- f = S, p.setUser(S);
2305
+ setStyle: (C) => u.setStyle(C),
2306
+ setUser: (C) => {
2307
+ f = C, g.setUser(C);
2301
2308
  },
2302
- setSelected: (S) => {
2303
- S ? i.setSelected(S) : i.clear();
2309
+ setSelected: (C) => {
2310
+ C ? i.setSelected(C) : i.clear();
2304
2311
  },
2305
- setPresenceProvider: (S) => {
2306
- S && (u.setPainter(oo(S, n.presence)), S.on("selectionChange", () => u.redraw()));
2312
+ setPresenceProvider: (C) => {
2313
+ C && (u.setPainter(oo(C, n.presence)), C.on("selectionChange", () => u.redraw()));
2307
2314
  },
2308
- setVisible: (S) => u.setVisible(S),
2309
- on: l.on,
2310
- off: l.off,
2311
- scrollIntoView: Ke(t, a),
2315
+ setVisible: (C) => u.setVisible(C),
2316
+ on: d.on,
2317
+ off: d.off,
2318
+ scrollIntoView: De(t, a),
2312
2319
  state: o
2313
2320
  };
2314
2321
  };
2315
2322
  export {
2316
- wt as DEFAULT_SELECTED_STYLE,
2323
+ At as DEFAULT_SELECTED_STYLE,
2317
2324
  W as DEFAULT_STYLE,
2318
2325
  re as NOT_ANNOTATABLE_CLASS,
2319
2326
  tt as NOT_ANNOTATABLE_SELECTOR,
2320
2327
  k as Origin,
2321
2328
  yo as SelectionHandler,
2322
2329
  hn as UserSelectAction,
2323
- Ao as W3CTextFormat,
2330
+ xo as W3CTextFormat,
2324
2331
  Le as cancelSingleClickEvents,
2325
2332
  ft as cloneKeyboardEvent,
2326
- At as clonePointerEvent,
2327
- wo as createBody,
2333
+ xt as clonePointerEvent,
2334
+ Ao as createBody,
2328
2335
  ze as createCanvasRenderer,
2329
2336
  nn as createHighlightsRenderer,
2330
2337
  oo as createPresencePainter,
2331
2338
  en as createRenderer,
2332
2339
  rn as createSpansRenderer,
2333
- xo as createTextAnnotator,
2340
+ vo as createTextAnnotator,
2334
2341
  eo as createTextAnnotatorState,
2335
2342
  Yt as debounce,
2336
2343
  bo as fillDefaults,
2337
2344
  Re as getQuoteContext,
2338
- Nt as getRangeAnnotatableContents,
2345
+ Ut as getRangeAnnotatableContents,
2339
2346
  Te as isMac,
2340
2347
  it as isNotAnnotatable,
2341
2348
  Ce as isRangeAnnotatable,
2342
2349
  F as isRevived,
2343
2350
  Ie as isWhitespaceOrEmpty,
2344
2351
  Ue as mergeClientRects,
2345
- De as paint,
2352
+ Ke as paint,
2346
2353
  jn as parseW3CTextAnnotation,
2347
2354
  Oe as programmaticallyFocusable,
2348
2355
  Ve as rangeToSelector,
2349
- xt as reviveAnnotation,
2356
+ vt as reviveAnnotation,
2350
2357
  ae as reviveSelector,
2351
- bt as reviveTarget,
2352
- Ke as scrollIntoView,
2358
+ wt as reviveTarget,
2359
+ De as scrollIntoView,
2353
2360
  zn as serializeW3CTextAnnotation,
2354
- Be as splitAnnotatableRanges,
2361
+ Me as splitAnnotatableRanges,
2362
+ wo as toDomRectList,
2355
2363
  Ye as trimRangeToContainer,
2356
2364
  ke as whitespaceOrEmptyRegex
2357
2365
  };