@recogito/text-annotator 3.0.5 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
- const re = "not-annotatable", et = `.${re}`, it = (t) => {
1
+ const re = "not-annotatable", nt = `.${re}`, rt = (t) => {
2
2
  var n;
3
- return !!(t instanceof HTMLElement ? t.closest(et) : (n = t.parentElement) == null ? void 0 : n.closest(et));
3
+ return !!(t instanceof HTMLElement ? t.closest(nt) : (n = t.parentElement) == null ? void 0 : n.closest(nt));
4
4
  }, Ce = (t) => {
5
5
  const e = t.commonAncestorContainer;
6
- return !it(e);
6
+ return !rt(e);
7
7
  }, Le = (t) => t.addEventListener("click", (e) => {
8
8
  // Allow clicks within not-annotatable elements
9
- !e.target.closest(et) && !e.target.closest("a") && e.preventDefault();
10
- }), vt = (t) => ({
9
+ !e.target.closest(nt) && !e.target.closest("a") && e.preventDefault();
10
+ }), Et = (t) => ({
11
11
  ...t,
12
12
  type: t.type,
13
13
  x: t.x,
@@ -33,7 +33,7 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
33
33
  pointerId: t.pointerId,
34
34
  pointerType: t.pointerType,
35
35
  timeStamp: t.timeStamp
36
- }), ht = (t) => ({
36
+ }), gt = (t) => ({
37
37
  ...t,
38
38
  type: t.type,
39
39
  key: t.key,
@@ -52,16 +52,16 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
52
52
  }), Te = typeof navigator < "u" && // @ts-ignore
53
53
  /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform), Oe = (t) => {
54
54
  !t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
55
- }, Dt = (t, e = 10) => {
55
+ }, Kt = (t, e = 10) => {
56
56
  let n;
57
- return (...o) => {
57
+ return ((...o) => {
58
58
  clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
59
- };
59
+ });
60
60
  }, Re = function* (t) {
61
61
  const e = document.createNodeIterator(
62
62
  t.commonAncestorContainer,
63
63
  NodeFilter.SHOW_ELEMENT,
64
- (o) => o instanceof HTMLElement && o.classList.contains(re) && !o.parentElement.closest(et) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
64
+ (o) => o instanceof HTMLElement && o.classList.contains(re) && !o.parentElement.closest(nt) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
65
65
  );
66
66
  let n;
67
67
  for (; n = e.nextNode(); )
@@ -79,20 +79,20 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
79
79
  o.setStartAfter(n), o.collapsed || e.push(o);
80
80
  }
81
81
  return e.length > 0 ? e : [t];
82
- }, Nt = (t) => {
82
+ }, Vt = (t) => {
83
83
  const e = t.cloneContents();
84
- return e.querySelectorAll(et).forEach((n) => n.remove()), e;
85
- }, Be = (t, e, n = 10, o) => {
84
+ return e.querySelectorAll(nt).forEach((n) => n.remove()), e;
85
+ }, ke = (t, e, n = 10, o) => {
86
86
  const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
87
87
  s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
88
- const a = Nt(s).textContent, r = document.createRange();
88
+ const a = Vt(s).textContent, r = document.createRange();
89
89
  r.setStart(t.endContainer, t.endOffset), i === document.body ? r.setEnd(i, i.childNodes.length) : r.setEndAfter(i);
90
- const l = Nt(r).textContent;
90
+ const d = Vt(r).textContent;
91
91
  return {
92
92
  prefix: a.substring(a.length - n),
93
- suffix: l.substring(0, n)
93
+ suffix: d.substring(0, n)
94
94
  };
95
- }, q = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), ke = /^\s*$/, Ie = (t) => ke.test(t.toString()), _e = (t, e) => {
95
+ }, q = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), Be = /^\s*$/, Ie = (t) => Be.test(t.toString()), Ue = (t, e) => {
96
96
  const n = (s) => Math.round(s * 10) / 10, o = {
97
97
  top: n(t.top),
98
98
  bottom: n(t.bottom),
@@ -116,7 +116,7 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
116
116
  return "block-contains";
117
117
  } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
118
118
  return "block-is-contained";
119
- }, Ue = (t, e) => {
119
+ }, _e = (t, e) => {
120
120
  const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
121
121
  return new DOMRect(n, i, o - n, s - i);
122
122
  }, Ne = (t) => t.reduce((e, n) => {
@@ -124,9 +124,9 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
124
124
  return e;
125
125
  let o = [...e], i = !1;
126
126
  for (const s of e) {
127
- const a = _e(n, s);
127
+ const a = Ue(n, s);
128
128
  if (a === "inline-adjacent") {
129
- o = o.map((r) => r === s ? Ue(n, s) : r), i = !0;
129
+ o = o.map((r) => r === s ? _e(n, s) : r), i = !0;
130
130
  break;
131
131
  } else if (a === "inline-contains") {
132
132
  o = o.map((r) => r === s ? n : r), i = !0;
@@ -140,7 +140,7 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
140
140
  }
141
141
  }
142
142
  return i ? o : [...o, n];
143
- }, []), wo = (t) => ({
143
+ }, []), xo = (t) => ({
144
144
  length: t.length,
145
145
  item: (e) => t[e],
146
146
  [Symbol.iterator]: function* () {
@@ -150,41 +150,41 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
150
150
  }), Ve = (t, e, n) => {
151
151
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
152
152
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
153
- const s = Nt(o).textContent, a = t.toString(), r = s.length || 0, l = r + a.length;
154
- return n ? { quote: a, start: r, end: l, range: t, offsetReference: i } : { quote: a, start: r, end: l, range: t };
153
+ const s = Vt(o).textContent, a = t.toString(), r = s.length || 0, d = r + a.length;
154
+ return n ? { quote: a, start: r, end: d, range: t, offsetReference: i } : { quote: a, start: r, end: d, range: t };
155
155
  }, ae = (t, e) => {
156
- var h, u;
156
+ var g, u;
157
157
  const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
158
158
  e,
159
159
  NodeFilter.SHOW_TEXT,
160
- (p) => {
160
+ (h) => {
161
161
  var v;
162
- return (v = p.parentElement) != null && v.closest(et) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
162
+ return (v = h.parentElement) != null && v.closest(nt) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
163
163
  }
164
164
  );
165
165
  let a = 0;
166
166
  const r = document.createRange();
167
- let l = s.nextNode();
168
- l === null && console.error("Could not revive annotation target. Content missing.");
167
+ let d = s.nextNode();
168
+ d === null && console.error("Could not revive annotation target. Content missing.");
169
169
  let f = !i;
170
- for (; l !== null; ) {
171
- if (f || (f = typeof (i == null ? void 0 : i.contains) == "function" ? i.contains(l) : !1), f) {
172
- const p = ((h = l.textContent) == null ? void 0 : h.length) || 0;
173
- if (a + p > n) {
174
- r.setStart(l, n - a);
170
+ for (; d !== null; ) {
171
+ if (f || (f = typeof (i == null ? void 0 : i.contains) == "function" ? i.contains(d) : !1), f) {
172
+ const h = ((g = d.textContent) == null ? void 0 : g.length) || 0;
173
+ if (a + h > n) {
174
+ r.setStart(d, n - a);
175
175
  break;
176
176
  }
177
- a += p;
177
+ a += h;
178
178
  }
179
- l = s.nextNode();
179
+ d = s.nextNode();
180
180
  }
181
- for (; l !== null; ) {
182
- const p = ((u = l.textContent) == null ? void 0 : u.length) || 0;
183
- if (a + p >= o) {
184
- r.setEnd(l, o - a);
181
+ for (; d !== null; ) {
182
+ const h = ((u = d.textContent) == null ? void 0 : u.length) || 0;
183
+ if (a + h >= o) {
184
+ r.setEnd(d, o - a);
185
185
  break;
186
186
  }
187
- a += p, l = s.nextNode();
187
+ a += h, d = s.nextNode();
188
188
  }
189
189
  return {
190
190
  ...t,
@@ -193,19 +193,19 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
193
193
  }, At = (t, e) => q(t.selector) ? t : {
194
194
  ...t,
195
195
  selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : ae(n, e))
196
- }, Et = (t, e) => q(t.target.selector) ? t : { ...t, target: At(t.target, e) }, De = (t, e) => {
196
+ }, St = (t, e) => q(t.target.selector) ? t : { ...t, target: At(t.target, e) }, De = (t, e) => {
197
197
  const n = t.cloneRange();
198
198
  return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
199
- }, ce = (t) => {
199
+ }, le = (t) => {
200
200
  if (t === null)
201
201
  return document.scrollingElement;
202
202
  const { overflowY: e } = window.getComputedStyle(t);
203
- return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ce(t.parentElement);
204
- }, Ye = (t, e) => (n) => {
205
- const o = typeof n == "string" ? n : n.id, i = (h) => {
206
- const u = s.getBoundingClientRect(), p = s.clientHeight, v = s.clientWidth, g = h.selector[0].range.getBoundingClientRect(), { width: m, height: A } = e.getAnnotationBounds(o), d = g.top - u.top, c = g.left - u.left, y = s.parentElement ? s.scrollTop : 0, S = s.parentElement ? s.scrollLeft : 0, E = d + y - (p - A) / 2, C = c + S - (v - m) / 2;
207
- s.scroll({ top: E, left: C, behavior: "smooth" });
208
- }, s = ce(t);
203
+ return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : le(t.parentElement);
204
+ }, Ke = (t, e) => (n) => {
205
+ const o = typeof n == "string" ? n : n.id, i = (g) => {
206
+ const u = s.getBoundingClientRect(), h = s.clientHeight, v = s.clientWidth, b = g.selector[0].range.getBoundingClientRect(), { width: p, height: x } = e.getAnnotationBounds(o), c = b.top - u.top, l = b.left - u.left, m = s.parentElement ? s.scrollTop : 0, S = s.parentElement ? s.scrollLeft : 0, E = c + m - (h - x) / 2, L = l + S - (v - p) / 2;
207
+ s.scroll({ top: E, left: L, behavior: "smooth" });
208
+ }, s = le(t);
209
209
  if (!s)
210
210
  return console.warn(`The scroll parent is missing for the annotation: ${o}`, { container: t }), !1;
211
211
  const a = e.getAnnotation(o);
@@ -214,21 +214,21 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
214
214
  const { range: r } = a.target.selector[0];
215
215
  if (r && !r.collapsed)
216
216
  return i(a.target), !0;
217
- const l = At(a.target, t), { range: f } = l.selector[0];
218
- return f && !f.collapsed ? (i(l), !0) : !1;
217
+ const d = At(a.target, t), { range: f } = d.selector[0];
218
+ return f && !f.collapsed ? (i(d), !0) : !1;
219
219
  }, G = {
220
220
  fill: "rgb(0, 128, 255)",
221
221
  fillOpacity: 0.18
222
- }, xt = {
222
+ }, vt = {
223
223
  fill: "rgb(0, 128, 255)",
224
224
  fillOpacity: 0.45
225
- }, Ke = (t, e, n, o, i) => {
225
+ }, Ye = (t, e, n, o, i) => {
226
226
  var a, r;
227
- const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? xt : G) : n : (r = t.state) != null && r.selected ? xt : G;
227
+ const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? vt : G) : n : (r = t.state) != null && r.selected ? vt : G;
228
228
  return o && o.paint(t, e) || s;
229
229
  }, Xe = (t) => {
230
- const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n, l = i - e;
231
- 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 };
232
232
  }, Pe = (t) => {
233
233
  let e = /* @__PURE__ */ new Set();
234
234
  return (o) => {
@@ -237,45 +237,49 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
237
237
  };
238
238
  }, Yt = (t, e, n, o) => {
239
239
  const { store: i, selection: s, hover: a } = e;
240
- let r, l, f;
241
- const h = Pe(n), u = (M) => {
242
- const { x: T, y: I } = t.getBoundingClientRect(), D = i.getAt(M.clientX - T, M.clientY - I, !1, l);
243
- D ? a.current !== D.id && (t.classList.add("hovered"), a.set(D.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
240
+ let r, d, f;
241
+ const g = Pe(n), u = (V) => {
242
+ const { x: T, y: M } = t.getBoundingClientRect(), y = i.getAt(V.clientX - T, V.clientY - M, !1, d);
243
+ y ? a.current !== y.id && (t.classList.add("hovered"), a.set(y.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
244
244
  };
245
245
  t.addEventListener("pointermove", u);
246
- const p = (M = !1) => {
246
+ const h = (V = !1) => {
247
247
  f && f.clear();
248
- const T = Xe(t), { minX: I, minY: D, maxX: b, maxY: x } = T, w = l ? i.getIntersecting(I, D, b, x).filter(({ annotation: O }) => l(O)) : i.getIntersecting(I, D, b, x), L = s.selected.map(({ id: O }) => O), B = w.map(({ annotation: O, rects: _ }) => {
249
- const P = L.includes(O.id), Se = O.id === a.current;
250
- return { annotation: O, rects: _, state: { selected: P, hover: Se } };
248
+ const T = Xe(t), { minX: M, minY: y, maxX: w, maxY: A } = T, C = d ? i.getIntersecting(M, y, w, A).filter(({ annotation: k }) => d(k)) : i.getIntersecting(M, y, w, A), I = s.selected.map(({ id: k }) => k), O = C.map(({ annotation: k, rects: P }) => {
249
+ const Q = I.includes(k.id), Se = k.id === a.current;
250
+ return {
251
+ annotation: k,
252
+ rects: P,
253
+ state: { selected: Q, hovered: Se }
254
+ };
251
255
  });
252
- o.redraw(B, T, r, f, M), setTimeout(() => h(w.map(({ annotation: O }) => O)), 1);
253
- }, v = (M) => {
254
- f = M, p();
255
- }, g = (M) => {
256
- r = M, p();
257
- }, m = (M) => {
258
- l = M, p(!1);
259
- }, A = () => p();
260
- i.observe(A);
261
- const d = s.subscribe(() => p()), c = () => p(!0);
262
- document.addEventListener("scroll", c, { capture: !0, passive: !0 });
263
- const y = Dt(() => {
264
- i.recalculatePositions(), f && f.reset(), p();
256
+ o.redraw(O, T, r, f, V), setTimeout(() => g(C.map(({ annotation: k }) => k)), 1);
257
+ }, v = (V) => {
258
+ f = V, h();
259
+ }, b = (V) => {
260
+ r = V, h();
261
+ }, p = (V) => {
262
+ d = V, h(!1);
263
+ }, x = () => h();
264
+ i.observe(x);
265
+ const c = s.subscribe(() => h()), l = a.subscribe(() => h()), m = () => h(!0);
266
+ document.addEventListener("scroll", m, { capture: !0, passive: !0 });
267
+ const S = Kt(() => {
268
+ i.recalculatePositions(), f && f.reset(), h();
265
269
  });
266
- window.addEventListener("resize", y);
267
- const S = new ResizeObserver(y);
268
- S.observe(t);
269
- const E = { attributes: !0, childList: !0, subtree: !0 }, C = new MutationObserver((M) => {
270
- M.every((I) => I.target === t || t.contains(I.target)) || p(!0);
270
+ window.addEventListener("resize", S);
271
+ const E = new ResizeObserver(S);
272
+ E.observe(t);
273
+ const L = { attributes: !0, childList: !0, subtree: !0 }, R = new MutationObserver((V) => {
274
+ V.every((M) => M.target === t || t.contains(M.target)) || h(!0);
271
275
  });
272
- return C.observe(document.body, E), {
276
+ return R.observe(document.body, L), {
273
277
  destroy: () => {
274
- t.removeEventListener("pointermove", u), o.destroy(), i.unobserve(A), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", y), S.disconnect(), C.disconnect();
278
+ t.removeEventListener("pointermove", u), o.destroy(), i.unobserve(x), c(), l(), document.removeEventListener("scroll", m), window.removeEventListener("resize", S), E.disconnect(), R.disconnect();
275
279
  },
276
- redraw: p,
277
- setStyle: g,
278
- setFilter: m,
280
+ redraw: h,
281
+ setStyle: b,
282
+ setFilter: p,
279
283
  setPainter: v,
280
284
  setVisible: o.setVisible
281
285
  };
@@ -288,32 +292,32 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
288
292
  t.classList.add("r6o-annotatable");
289
293
  const e = $e(), n = e.getContext("2d");
290
294
  document.body.appendChild(e);
291
- const o = (r, l, f, h) => requestAnimationFrame(() => {
292
- const { width: u, height: p } = e;
293
- n.clearRect(-0.5, -0.5, u + 1, p + 1), h && h.clear();
294
- const { top: v, left: g } = l;
295
- [...r].sort((A, d) => {
296
- const { annotation: { target: { created: c } } } = A, { annotation: { target: { created: y } } } = d;
297
- return c.getTime() - y.getTime();
298
- }).forEach((A) => {
295
+ const o = (r, d, f, g) => requestAnimationFrame(() => {
296
+ const { width: u, height: h } = e;
297
+ n.clearRect(-0.5, -0.5, u + 1, h + 1), g && g.clear();
298
+ const { top: v, left: b } = d;
299
+ [...r].sort((x, c) => {
300
+ const { annotation: { target: { created: l } } } = x, { annotation: { target: { created: m } } } = c;
301
+ return l.getTime() - m.getTime();
302
+ }).forEach((x) => {
299
303
  var S;
300
- const d = f ? typeof f == "function" ? f(A.annotation, A.state) : f : (S = A.state) != null && S.selected ? xt : G, c = h && h.paint(A, l) || d, y = A.rects.map(({ x: E, y: C, width: R, height: M }) => ({
301
- x: E + g,
302
- y: C + v,
304
+ const c = f ? typeof f == "function" ? f(x.annotation, x.state) : f : (S = x.state) != null && S.selected ? vt : G, l = g && g.paint(x, d) || c, m = x.rects.map(({ x: E, y: L, width: R, height: U }) => ({
305
+ x: E + b,
306
+ y: L + v,
303
307
  width: R,
304
- height: M
308
+ height: U
305
309
  }));
306
- if (n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1, y.forEach(
307
- ({ x: E, y: C, width: R, height: M }) => n.fillRect(E, C, R, M)
308
- ), c.underlineColor) {
309
- n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
310
- const E = c.underlineOffset ?? 0;
311
- y.forEach(({ x: C, y: R, width: M, height: T }) => {
312
- n.beginPath(), n.moveTo(C, R + T + E), n.lineTo(C + M, R + T + E), n.stroke();
310
+ if (n.fillStyle = l.fill, n.globalAlpha = l.fillOpacity || 1, m.forEach(
311
+ ({ x: E, y: L, width: R, height: U }) => n.fillRect(E, L, R, U)
312
+ ), l.underlineColor) {
313
+ n.globalAlpha = 1, n.strokeStyle = l.underlineColor, n.lineWidth = l.underlineThickness ?? 1;
314
+ const E = l.underlineOffset ?? 0;
315
+ m.forEach(({ x: L, y: R, width: U, height: V }) => {
316
+ n.beginPath(), n.moveTo(L, R + V + E), n.lineTo(L + U, R + V + E), n.stroke();
313
317
  });
314
318
  }
315
319
  });
316
- }), i = Dt(() => {
320
+ }), i = Kt(() => {
317
321
  He(e);
318
322
  });
319
323
  return window.addEventListener("resize", i), {
@@ -328,16 +332,16 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
328
332
  }, ze = (t, e, n) => Yt(t, e, n, je(t));
329
333
  var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
330
334
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
331
- }, V = function(t, e, n) {
335
+ }, D = function(t, e, n) {
332
336
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
333
337
  }, $ = function(t, e, n) {
334
338
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
335
- }, le = function(t) {
339
+ }, ce = function(t) {
336
340
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
337
- }, Pt = function(t) {
341
+ }, $t = function(t) {
338
342
  return { r: $(t.r, 0, 255), g: $(t.g, 0, 255), b: $(t.b, 0, 255), a: $(t.a) };
339
- }, St = function(t) {
340
- return { r: V(t.r), g: V(t.g), b: V(t.b), a: V(t.a, 3) };
343
+ }, Ct = function(t) {
344
+ return { r: D(t.r), g: D(t.g), b: D(t.b), a: D(t.a, 3) };
341
345
  }, We = /^#([0-9a-f]{3,8})$/i, pt = function(t) {
342
346
  var e = t.toString(16);
343
347
  return e.length < 2 ? "0" + e : e;
@@ -347,114 +351,114 @@ var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
347
351
  }, ue = function(t) {
348
352
  var e = t.h, n = t.s, o = t.v, i = t.a;
349
353
  e = e / 360 * 6, n /= 100, o /= 100;
350
- 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;
351
- 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 };
352
- }, $t = function(t) {
353
- return { h: le(t.h), s: $(t.s, 0, 100), l: $(t.l, 0, 100), a: $(t.a) };
354
+ 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;
355
+ 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 };
354
356
  }, Ht = function(t) {
355
- return { h: V(t.h), s: V(t.s), l: V(t.l), a: V(t.a, 3) };
357
+ return { h: ce(t.h), s: $(t.s, 0, 100), l: $(t.l, 0, 100), a: $(t.a) };
356
358
  }, jt = function(t) {
359
+ return { h: D(t.h), s: D(t.s), l: D(t.l), a: D(t.a, 3) };
360
+ }, zt = function(t) {
357
361
  return ue((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
358
362
  var e, n, o;
359
- }, ct = function(t) {
363
+ }, dt = function(t) {
360
364
  return { h: (e = de(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
361
365
  var e, n, o, i;
362
- }, qe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Qe = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Je = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, zt = { string: [[function(t) {
366
+ }, qe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Qe = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Je = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ft = { string: [[function(t) {
363
367
  var e = We.exec(t);
364
- return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? V(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? V(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
368
+ return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? D(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? D(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
365
369
  }, "hex"], [function(t) {
366
370
  var e = Qe.exec(t) || Je.exec(t);
367
- return e ? e[2] !== e[4] || e[4] !== e[6] ? null : Pt({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
371
+ return e ? e[2] !== e[4] || e[4] !== e[6] ? null : $t({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
368
372
  }, "rgb"], [function(t) {
369
373
  var e = qe.exec(t) || Ge.exec(t);
370
374
  if (!e) return null;
371
- var n, o, i = $t({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (Fe[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
372
- return jt(i);
375
+ var n, o, i = Ht({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (Fe[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
376
+ return zt(i);
373
377
  }, "hsl"]], object: [[function(t) {
374
378
  var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
375
- return F(e) && F(n) && F(o) ? Pt({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
379
+ return F(e) && F(n) && F(o) ? $t({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
376
380
  }, "rgb"], [function(t) {
377
381
  var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
378
382
  if (!F(e) || !F(n) || !F(o)) return null;
379
- var a = $t({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
380
- return jt(a);
383
+ var a = Ht({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
384
+ return zt(a);
381
385
  }, "hsl"], [function(t) {
382
386
  var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
383
387
  if (!F(e) || !F(n) || !F(o)) return null;
384
- var a = function(r) {
385
- return { h: le(r.h), s: $(r.s, 0, 100), v: $(r.v, 0, 100), a: $(r.a) };
386
- }({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
388
+ var a = (function(r) {
389
+ return { h: ce(r.h), s: $(r.s, 0, 100), v: $(r.v, 0, 100), a: $(r.a) };
390
+ })({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
387
391
  return ue(a);
388
- }, "hsv"]] }, Ft = function(t, e) {
392
+ }, "hsv"]] }, Wt = function(t, e) {
389
393
  for (var n = 0; n < e.length; n++) {
390
394
  var o = e[n][0](t);
391
395
  if (o) return [o, e[n][1]];
392
396
  }
393
397
  return [null, void 0];
394
398
  }, Ze = function(t) {
395
- return typeof t == "string" ? Ft(t.trim(), zt.string) : typeof t == "object" && t !== null ? Ft(t, zt.object) : [null, void 0];
396
- }, Ct = function(t, e) {
397
- var n = ct(t);
399
+ return typeof t == "string" ? Wt(t.trim(), Ft.string) : typeof t == "object" && t !== null ? Wt(t, Ft.object) : [null, void 0];
400
+ }, Lt = function(t, e) {
401
+ var n = dt(t);
398
402
  return { h: n.h, s: $(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
399
- }, Lt = function(t) {
403
+ }, Tt = function(t) {
400
404
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
401
- }, Wt = function(t, e) {
402
- var n = ct(t);
405
+ }, qt = function(t, e) {
406
+ var n = dt(t);
403
407
  return { h: n.h, s: n.s, l: $(n.l + 100 * e, 0, 100), a: n.a };
404
- }, qt = function() {
408
+ }, Gt = (function() {
405
409
  function t(e) {
406
410
  this.parsed = Ze(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
407
411
  }
408
412
  return t.prototype.isValid = function() {
409
413
  return this.parsed !== null;
410
414
  }, t.prototype.brightness = function() {
411
- return V(Lt(this.rgba), 2);
415
+ return D(Tt(this.rgba), 2);
412
416
  }, t.prototype.isDark = function() {
413
- return Lt(this.rgba) < 0.5;
417
+ return Tt(this.rgba) < 0.5;
414
418
  }, t.prototype.isLight = function() {
415
- return Lt(this.rgba) >= 0.5;
419
+ return Tt(this.rgba) >= 0.5;
416
420
  }, t.prototype.toHex = function() {
417
- return e = St(this.rgba), n = e.r, o = e.g, i = e.b, a = (s = e.a) < 1 ? pt(V(255 * s)) : "", "#" + pt(n) + pt(o) + pt(i) + a;
421
+ return e = Ct(this.rgba), n = e.r, o = e.g, i = e.b, a = (s = e.a) < 1 ? pt(D(255 * s)) : "", "#" + pt(n) + pt(o) + pt(i) + a;
418
422
  var e, n, o, i, s, a;
419
423
  }, t.prototype.toRgb = function() {
420
- return St(this.rgba);
424
+ return Ct(this.rgba);
421
425
  }, t.prototype.toRgbString = function() {
422
- return e = St(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
426
+ return e = Ct(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
423
427
  var e, n, o, i, s;
424
428
  }, t.prototype.toHsl = function() {
425
- return Ht(ct(this.rgba));
429
+ return jt(dt(this.rgba));
426
430
  }, t.prototype.toHslString = function() {
427
- return e = Ht(ct(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
431
+ return e = jt(dt(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
428
432
  var e, n, o, i, s;
429
433
  }, t.prototype.toHsv = function() {
430
- return e = de(this.rgba), { h: V(e.h), s: V(e.s), v: V(e.v), a: V(e.a, 3) };
434
+ return e = de(this.rgba), { h: D(e.h), s: D(e.s), v: D(e.v), a: D(e.a, 3) };
431
435
  var e;
432
436
  }, t.prototype.invert = function() {
433
437
  return j({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
434
438
  var e;
435
439
  }, t.prototype.saturate = function(e) {
436
- return e === void 0 && (e = 0.1), j(Ct(this.rgba, e));
440
+ return e === void 0 && (e = 0.1), j(Lt(this.rgba, e));
437
441
  }, t.prototype.desaturate = function(e) {
438
- return e === void 0 && (e = 0.1), j(Ct(this.rgba, -e));
442
+ return e === void 0 && (e = 0.1), j(Lt(this.rgba, -e));
439
443
  }, t.prototype.grayscale = function() {
440
- return j(Ct(this.rgba, -1));
444
+ return j(Lt(this.rgba, -1));
441
445
  }, t.prototype.lighten = function(e) {
442
- return e === void 0 && (e = 0.1), j(Wt(this.rgba, e));
446
+ return e === void 0 && (e = 0.1), j(qt(this.rgba, e));
443
447
  }, t.prototype.darken = function(e) {
444
- return e === void 0 && (e = 0.1), j(Wt(this.rgba, -e));
448
+ return e === void 0 && (e = 0.1), j(qt(this.rgba, -e));
445
449
  }, t.prototype.rotate = function(e) {
446
450
  return e === void 0 && (e = 15), this.hue(this.hue() + e);
447
451
  }, t.prototype.alpha = function(e) {
448
- return typeof e == "number" ? j({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : V(this.rgba.a, 3);
452
+ return typeof e == "number" ? j({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : D(this.rgba.a, 3);
449
453
  var n;
450
454
  }, t.prototype.hue = function(e) {
451
- var n = ct(this.rgba);
452
- return typeof e == "number" ? j({ h: e, s: n.s, l: n.l, a: n.a }) : V(n.h);
455
+ var n = dt(this.rgba);
456
+ return typeof e == "number" ? j({ h: e, s: n.s, l: n.l, a: n.a }) : D(n.h);
453
457
  }, t.prototype.isEqual = function(e) {
454
458
  return this.toHex() === j(e).toHex();
455
459
  }, t;
456
- }(), j = function(t) {
457
- return t instanceof qt ? t : new qt(t);
460
+ })(), j = function(t) {
461
+ return t instanceof Gt ? t : new Gt(t);
458
462
  };
459
463
  const tn = (t) => [
460
464
  `background-color:${j((t == null ? void 0 : t.fill) || G.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? G.fillOpacity : t.fillOpacity).toHex()}`,
@@ -473,25 +477,25 @@ const tn = (t) => [
473
477
  setVisible: (s) => {
474
478
  console.log("setVisible not implemented on CSS Custom Highlights renderer");
475
479
  },
476
- redraw: (s, a, r, l) => {
477
- l && l.clear();
480
+ redraw: (s, a, r, d) => {
481
+ d && d.clear();
478
482
  const f = new Set(s.map((u) => u.annotation.id));
479
483
  Array.from(e).filter((u) => !f.has(u));
480
- const h = s.map((u) => {
481
- var g;
482
- const p = r ? typeof r == "function" ? r(u.annotation, u.state) : r : (g = u.state) != null && g.selected ? xt : G, v = l && l.paint(u, a) || p;
484
+ const g = s.map((u) => {
485
+ var b;
486
+ const h = r ? typeof r == "function" ? r(u.annotation, u.state) : r : (b = u.state) != null && b.selected ? vt : G, v = d && d.paint(u, a) || h;
483
487
  return `::highlight(_${u.annotation.id}) { ${tn(v)} }`;
484
488
  });
485
- t.innerHTML = h.join(`
489
+ t.innerHTML = g.join(`
486
490
  `), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
487
- const p = u.target.selector.map((g) => g.range), v = new Highlight(...p);
491
+ const h = u.target.selector.map((b) => b.range), v = new Highlight(...h);
488
492
  CSS.highlights.set(`_${u.id}`, v);
489
493
  }), e = f;
490
494
  }
491
495
  };
492
496
  }, nn = (t, e, n) => Yt(t, e, n, en());
493
- var Gt = Object.prototype.hasOwnProperty;
494
- function Vt(t, e) {
497
+ var Qt = Object.prototype.hasOwnProperty;
498
+ function Dt(t, e) {
495
499
  var n, o;
496
500
  if (t === e) return !0;
497
501
  if (t && e && (n = t.constructor) === e.constructor) {
@@ -499,13 +503,13 @@ function Vt(t, e) {
499
503
  if (n === RegExp) return t.toString() === e.toString();
500
504
  if (n === Array) {
501
505
  if ((o = t.length) === e.length)
502
- for (; o-- && Vt(t[o], e[o]); ) ;
506
+ for (; o-- && Dt(t[o], e[o]); ) ;
503
507
  return o === -1;
504
508
  }
505
509
  if (!n || typeof t == "object") {
506
510
  o = 0;
507
511
  for (n in t)
508
- if (Gt.call(t, n) && ++o && !Gt.call(e, n) || !(n in e) || !Vt(t[n], e[n])) return !1;
512
+ if (Qt.call(t, n) && ++o && !Qt.call(e, n) || !(n in e) || !Dt(t[n], e[n])) return !1;
509
513
  return Object.keys(e).length === o;
510
514
  }
511
515
  }
@@ -523,18 +527,18 @@ const on = (t, e) => {
523
527
  destroy: () => {
524
528
  e.remove();
525
529
  },
526
- redraw: (a, r, l, f, h) => {
527
- const p = !(Vt(n, a) && h);
528
- if (!f && !p) return;
529
- p && (e.innerHTML = ""), [...a].sort((g, m) => {
530
- const { annotation: { target: { created: A } } } = g, { annotation: { target: { created: d } } } = m;
531
- return A && d ? A.getTime() - d.getTime() : 0;
532
- }).forEach((g) => {
533
- g.rects.map((m) => {
534
- const A = on(m, a), d = Ke(g, r, l, f, A);
535
- if (p) {
536
- const c = document.createElement("span");
537
- c.className = "r6o-annotation", c.dataset.annotation = g.annotation.id, c.style.left = `${m.x}px`, c.style.top = `${m.y}px`, c.style.width = `${m.width}px`, c.style.height = `${m.height}px`, c.style.backgroundColor = j((d == null ? void 0 : d.fill) || G.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? G.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);
530
+ redraw: (a, r, d, f, g) => {
531
+ const h = !(Dt(n, a) && g);
532
+ if (!f && !h) return;
533
+ h && (e.innerHTML = ""), [...a].sort((b, p) => {
534
+ const { annotation: { target: { created: x } } } = b, { annotation: { target: { created: c } } } = p;
535
+ return x && c ? x.getTime() - c.getTime() : 0;
536
+ }).forEach((b) => {
537
+ b.rects.map((p) => {
538
+ const x = on(p, a), c = Ye(b, r, d, f, x);
539
+ if (h) {
540
+ const l = document.createElement("span");
541
+ l.className = "r6o-annotation", l.dataset.annotation = b.annotation.id, l.style.left = `${p.x}px`, l.style.top = `${p.y}px`, l.style.width = `${p.width}px`, l.style.height = `${p.height}px`, l.style.backgroundColor = j((c == null ? void 0 : c.fill) || G.fill).alpha((c == null ? void 0 : c.fillOpacity) === void 0 ? G.fillOpacity : c.fillOpacity).toHex(), c.underlineStyle && (l.style.borderStyle = c.underlineStyle), c.underlineColor && (l.style.borderColor = c.underlineColor), c.underlineThickness && (l.style.borderBottomWidth = `${c.underlineThickness}px`), c.underlineOffset && (l.style.paddingBottom = `${c.underlineOffset}px`), e.appendChild(l);
538
542
  }
539
543
  });
540
544
  }), n = a;
@@ -543,35 +547,35 @@ const on = (t, e) => {
543
547
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
544
548
  }
545
549
  };
546
- }, rn = (t, e, n) => Yt(t, e, n, sn(t)), Y = [];
550
+ }, rn = (t, e, n) => Yt(t, e, n, sn(t)), K = [];
547
551
  for (let t = 0; t < 256; ++t)
548
- Y.push((t + 256).toString(16).slice(1));
552
+ K.push((t + 256).toString(16).slice(1));
549
553
  function an(t, e = 0) {
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();
554
+ 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();
551
555
  }
552
- let Tt;
553
- const cn = new Uint8Array(16);
554
- function ln() {
555
- if (!Tt) {
556
+ let Ot;
557
+ const ln = new Uint8Array(16);
558
+ function cn() {
559
+ if (!Ot) {
556
560
  if (typeof crypto > "u" || !crypto.getRandomValues)
557
561
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
558
- Tt = crypto.getRandomValues.bind(crypto);
562
+ Ot = crypto.getRandomValues.bind(crypto);
559
563
  }
560
- return Tt(cn);
564
+ return Ot(ln);
561
565
  }
562
- const dn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Qt = { randomUUID: dn };
566
+ const dn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Jt = { randomUUID: dn };
563
567
  function fe(t, e, n) {
564
568
  var i;
565
- if (Qt.randomUUID && !t)
566
- return Qt.randomUUID();
569
+ if (Jt.randomUUID && !t)
570
+ return Jt.randomUUID();
567
571
  t = t || {};
568
- const o = t.random ?? ((i = t.rng) == null ? void 0 : i.call(t)) ?? ln();
572
+ const o = t.random ?? ((i = t.rng) == null ? void 0 : i.call(t)) ?? cn();
569
573
  if (o.length < 16)
570
574
  throw new Error("Random bytes length must be >= 16");
571
575
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, an(o);
572
576
  }
573
- var Jt = Object.prototype.hasOwnProperty;
574
- function Q(t, e) {
577
+ var Zt = Object.prototype.hasOwnProperty;
578
+ function J(t, e) {
575
579
  var n, o;
576
580
  if (t === e) return !0;
577
581
  if (t && e && (n = t.constructor) === e.constructor) {
@@ -579,52 +583,52 @@ function Q(t, e) {
579
583
  if (n === RegExp) return t.toString() === e.toString();
580
584
  if (n === Array) {
581
585
  if ((o = t.length) === e.length)
582
- for (; o-- && Q(t[o], e[o]); ) ;
586
+ for (; o-- && J(t[o], e[o]); ) ;
583
587
  return o === -1;
584
588
  }
585
589
  if (!n || typeof t == "object") {
586
590
  o = 0;
587
591
  for (n in t)
588
- if (Jt.call(t, n) && ++o && !Jt.call(e, n) || !(n in e) || !Q(t[n], e[n])) return !1;
592
+ if (Zt.call(t, n) && ++o && !Zt.call(e, n) || !(n in e) || !J(t[n], e[n])) return !1;
589
593
  return Object.keys(e).length === o;
590
594
  }
591
595
  }
592
596
  return t !== t && e !== e;
593
597
  }
594
- function Ot() {
598
+ function Rt() {
595
599
  }
596
600
  function un(t, e) {
597
601
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
598
602
  }
599
- const J = [];
600
- function Kt(t, e = Ot) {
603
+ const Z = [];
604
+ function Xt(t, e = Rt) {
601
605
  let n;
602
606
  const o = /* @__PURE__ */ new Set();
603
607
  function i(r) {
604
608
  if (un(t, r) && (t = r, n)) {
605
- const l = !J.length;
609
+ const d = !Z.length;
606
610
  for (const f of o)
607
- f[1](), J.push(f, t);
608
- if (l) {
609
- for (let f = 0; f < J.length; f += 2)
610
- J[f][0](J[f + 1]);
611
- J.length = 0;
611
+ f[1](), Z.push(f, t);
612
+ if (d) {
613
+ for (let f = 0; f < Z.length; f += 2)
614
+ Z[f][0](Z[f + 1]);
615
+ Z.length = 0;
612
616
  }
613
617
  }
614
618
  }
615
619
  function s(r) {
616
620
  i(r(t));
617
621
  }
618
- function a(r, l = Ot) {
619
- const f = [r, l];
620
- return o.add(f), o.size === 1 && (n = e(i, s) || Ot), r(t), () => {
622
+ function a(r, d = Rt) {
623
+ const f = [r, d];
624
+ return o.add(f), o.size === 1 && (n = e(i, s) || Rt), r(t), () => {
621
625
  o.delete(f), o.size === 0 && n && (n(), n = null);
622
626
  };
623
627
  }
624
628
  return { set: i, update: s, subscribe: a };
625
629
  }
626
630
  const fn = (t) => {
627
- const { subscribe: e, set: n } = Kt();
631
+ const { subscribe: e, set: n } = Xt();
628
632
  let o;
629
633
  return e((i) => o = i), t.observe(({ changes: i }) => {
630
634
  if (o) {
@@ -641,58 +645,58 @@ const fn = (t) => {
641
645
  };
642
646
  };
643
647
  var hn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(hn || {});
644
- const gt = { selected: [] }, pn = (t, e, n) => {
645
- const { subscribe: o, set: i } = Kt(gt);
646
- let s = e, a = gt;
647
- o((g) => a = g);
648
+ const mt = { selected: [] }, gn = (t, e, n) => {
649
+ const { subscribe: o, set: i } = Xt(mt);
650
+ let s = e, a = mt;
651
+ o((p) => a = p);
648
652
  const r = () => {
649
- Q(a, gt) || i(gt);
650
- }, l = () => {
651
- var g;
652
- return ((g = a.selected) == null ? void 0 : g.length) === 0;
653
- }, f = (g) => {
654
- if (l())
653
+ J(a, mt) || i(mt);
654
+ }, d = () => {
655
+ var p;
656
+ return ((p = a.selected) == null ? void 0 : p.length) === 0;
657
+ }, f = (p) => {
658
+ if (d())
655
659
  return !1;
656
- const m = typeof g == "string" ? g : g.id;
657
- return a.selected.some((A) => A.id === m);
658
- }, h = (g, m) => {
659
- let A;
660
- if (Array.isArray(g)) {
661
- if (A = g.map((c) => t.getAnnotation(c)).filter(Boolean), A.length < g.length) {
662
- console.warn("Invalid selection: " + g.filter((c) => !A.some((y) => y.id === c)));
660
+ const x = typeof p == "string" ? p : p.id;
661
+ return a.selected.some((c) => c.id === x);
662
+ }, g = (p, x) => {
663
+ let c;
664
+ if (Array.isArray(p)) {
665
+ if (c = p.map((m) => t.getAnnotation(m)).filter(Boolean), c.length < p.length) {
666
+ console.warn("Invalid selection: " + p.filter((m) => !c.some((S) => S.id === m)));
663
667
  return;
664
668
  }
665
669
  } else {
666
- const c = t.getAnnotation(g);
667
- if (!c) {
668
- console.warn("Invalid selection: " + g);
670
+ const m = t.getAnnotation(p);
671
+ if (!m) {
672
+ console.warn("Invalid selection: " + p);
669
673
  return;
670
674
  }
671
- A = [c];
675
+ c = [m];
672
676
  }
673
- const d = A.reduce((c, y) => {
674
- const S = Zt(y, s, n);
675
- return S === "EDIT" ? [...c, { id: y.id, editable: !0 }] : S === "SELECT" ? [...c, { id: y.id }] : c;
677
+ const l = c.reduce((m, S) => {
678
+ const E = b(S);
679
+ return E === "EDIT" ? [...m, { id: S.id, editable: !0 }] : E === "SELECT" ? [...m, { id: S.id }] : m;
676
680
  }, []);
677
- i({ selected: d, event: m });
678
- }, u = (g, m) => {
679
- const A = Array.isArray(g) ? g : [g], d = A.map((c) => t.getAnnotation(c)).filter((c) => !!c);
681
+ i({ selected: l, event: x });
682
+ }, u = (p, x) => {
683
+ const c = Array.isArray(p) ? p : [p], l = c.map((m) => t.getAnnotation(m)).filter((m) => !!m);
680
684
  i({
681
- selected: d.map((c) => {
682
- const y = m === void 0 ? Zt(c, s, n) === "EDIT" : m;
683
- return { id: c.id, editable: y };
685
+ selected: l.map((m) => {
686
+ const S = x === void 0 ? b(m) === "EDIT" : x;
687
+ return { id: m.id, editable: S };
684
688
  })
685
- }), d.length !== A.length && console.warn("Invalid selection", g);
686
- }, p = (g) => {
687
- if (l())
689
+ }), l.length !== c.length && console.warn("Invalid selection", p);
690
+ }, h = (p) => {
691
+ if (d())
688
692
  return !1;
689
- const { selected: m } = a;
690
- m.some(({ id: A }) => g.includes(A)) && i({ selected: m.filter(({ id: A }) => !g.includes(A)) });
691
- }, v = (g) => {
692
- s = g, u(a.selected.map(({ id: m }) => m));
693
- };
693
+ const { selected: x } = a;
694
+ x.some(({ id: c }) => p.includes(c)) && i({ selected: x.filter(({ id: c }) => !p.includes(c)) });
695
+ }, v = (p) => {
696
+ s = p, u(a.selected.map(({ id: x }) => x));
697
+ }, b = (p) => pn(p, s, n);
694
698
  return t.observe(
695
- ({ changes: g }) => p((g.deleted || []).map((m) => m.id))
699
+ ({ changes: p }) => h((p.deleted || []).map((x) => x.id))
696
700
  ), {
697
701
  get event() {
698
702
  return a ? a.event : null;
@@ -704,44 +708,45 @@ const gt = { selected: [] }, pn = (t, e, n) => {
704
708
  return s;
705
709
  },
706
710
  clear: r,
707
- isEmpty: l,
711
+ evalSelectAction: b,
712
+ isEmpty: d,
708
713
  isSelected: f,
709
714
  setSelected: u,
710
715
  setUserSelectAction: v,
711
716
  subscribe: o,
712
- userSelect: h
717
+ userSelect: g
713
718
  };
714
- }, Zt = (t, e, n) => {
719
+ }, pn = (t, e, n) => {
715
720
  const o = n ? n.serialize(t) : t;
716
721
  return typeof e == "function" ? e(o) : e || "EDIT";
717
- }, K = [];
722
+ }, Y = [];
718
723
  for (let t = 0; t < 256; ++t)
719
- K.push((t + 256).toString(16).slice(1));
720
- function gn(t, e = 0) {
721
- 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();
724
+ Y.push((t + 256).toString(16).slice(1));
725
+ function mn(t, e = 0) {
726
+ 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();
722
727
  }
723
- let Rt;
724
- const mn = new Uint8Array(16);
725
- function yn() {
726
- if (!Rt) {
728
+ let Mt;
729
+ const yn = new Uint8Array(16);
730
+ function bn() {
731
+ if (!Mt) {
727
732
  if (typeof crypto > "u" || !crypto.getRandomValues)
728
733
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
729
- Rt = crypto.getRandomValues.bind(crypto);
734
+ Mt = crypto.getRandomValues.bind(crypto);
730
735
  }
731
- return Rt(mn);
736
+ return Mt(yn);
732
737
  }
733
- const bn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), te = { randomUUID: bn };
738
+ const wn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), te = { randomUUID: wn };
734
739
  function he(t, e, n) {
735
740
  var o;
736
741
  if (te.randomUUID && !t)
737
742
  return te.randomUUID();
738
743
  t = t || {};
739
- const i = t.random ?? ((o = t.rng) == null ? void 0 : o.call(t)) ?? yn();
744
+ const i = t.random ?? ((o = t.rng) == null ? void 0 : o.call(t)) ?? bn();
740
745
  if (i.length < 16)
741
746
  throw new Error("Random bytes length must be >= 16");
742
- return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, gn(i);
747
+ return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, mn(i);
743
748
  }
744
- const Mt = (t) => {
749
+ const kt = (t) => {
745
750
  const e = (n) => {
746
751
  const o = { ...n };
747
752
  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;
@@ -757,37 +762,37 @@ const Mt = (t) => {
757
762
  created: n || /* @__PURE__ */ new Date(),
758
763
  creator: o,
759
764
  ...e
760
- }), wn = (t, e) => {
765
+ }), xn = (t, e) => {
761
766
  const n = new Set(t.bodies.map((o) => o.id));
762
767
  return e.bodies.filter((o) => !n.has(o.id));
763
768
  }, An = (t, e) => {
764
769
  const n = new Set(e.bodies.map((o) => o.id));
765
770
  return t.bodies.filter((o) => !n.has(o.id));
766
- }, xn = (t, e) => e.bodies.map((n) => {
771
+ }, vn = (t, e) => e.bodies.map((n) => {
767
772
  const o = t.bodies.find((i) => i.id === n.id);
768
- return { newBody: n, oldBody: o && !Q(o, n) ? o : void 0 };
769
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), vn = (t, e) => !Q(t.target, e.target), pe = (t, e) => {
770
- const n = wn(t, e), o = An(t, e), i = xn(t, e);
773
+ return { newBody: n, oldBody: o && !J(o, n) ? o : void 0 };
774
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), En = (t, e) => !J(t.target, e.target), ge = (t, e) => {
775
+ const n = xn(t, e), o = An(t, e), i = vn(t, e);
771
776
  return {
772
777
  oldValue: t,
773
778
  newValue: e,
774
779
  bodiesCreated: n.length > 0 ? n : void 0,
775
780
  bodiesDeleted: o.length > 0 ? o : void 0,
776
781
  bodiesUpdated: i.length > 0 ? i : void 0,
777
- targetUpdated: vn(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
782
+ targetUpdated: En(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
778
783
  };
779
784
  };
780
- var k = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(k || {});
781
- const En = (t, e) => {
785
+ var B = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(B || {});
786
+ const Sn = (t, e) => {
782
787
  var n, o;
783
788
  const { changes: i, origin: s } = e;
784
789
  if (!(t.options.origin ? t.options.origin === s : s !== "SILENT"))
785
790
  return !1;
786
791
  if (t.options.ignore) {
787
- const { ignore: a } = t.options, r = (l) => l && l.length > 0;
792
+ const { ignore: a } = t.options, r = (d) => d && d.length > 0;
788
793
  if (!(r(i.created) || r(i.deleted))) {
789
- 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);
790
- if (a === "BODY_ONLY" && l && !f || a === "TARGET_ONLY" && f && !l)
794
+ const d = (n = i.updated) == null ? void 0 : n.some((g) => r(g.bodiesCreated) || r(g.bodiesDeleted) || r(g.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((g) => g.targetUpdated);
795
+ if (a === "BODY_ONLY" && d && !f || a === "TARGET_ONLY" && f && !d)
791
796
  return !1;
792
797
  }
793
798
  }
@@ -800,26 +805,26 @@ const En = (t, e) => {
800
805
  return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((r) => a.has(r));
801
806
  } else
802
807
  return !0;
803
- }, Sn = (t, e) => {
804
- 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 = [
805
- ...(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),
808
+ }, Cn = (t, e) => {
809
+ 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 = [
810
+ ...(t.created || []).filter((u) => !s.has(u.id)).map((u) => a.has(u.id) ? e.updated.find(({ oldValue: h }) => h.id === u.id).newValue : u),
806
811
  ...e.created || []
807
812
  ], f = [
808
813
  ...(t.deleted || []).filter((u) => !i.has(u.id)),
809
814
  ...(e.deleted || []).filter((u) => !n.has(u.id))
810
- ], h = [
815
+ ], g = [
811
816
  ...(t.updated || []).filter(({ newValue: u }) => !s.has(u.id)).map((u) => {
812
- const { oldValue: p, newValue: v } = u;
817
+ const { oldValue: h, newValue: v } = u;
813
818
  if (a.has(v.id)) {
814
- const g = e.updated.find((m) => m.oldValue.id === v.id).newValue;
815
- return pe(p, g);
819
+ const b = e.updated.find((p) => p.oldValue.id === v.id).newValue;
820
+ return ge(h, b);
816
821
  } else
817
822
  return u;
818
823
  }),
819
824
  ...(e.updated || []).filter(({ oldValue: u }) => !r.has(u.id))
820
825
  ];
821
- return { created: l, deleted: f, updated: h };
822
- }, mt = (t) => {
826
+ return { created: d, deleted: f, updated: g };
827
+ }, yt = (t) => {
823
828
  const e = t.id === void 0 ? he() : t.id;
824
829
  return {
825
830
  ...t,
@@ -833,215 +838,215 @@ const En = (t, e) => {
833
838
  annotation: e
834
839
  }
835
840
  };
836
- }, Cn = (t) => t.id !== void 0, Ln = () => {
837
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, x = {}) => {
838
- n.push({ onChange: b, options: x });
839
- }, i = (b) => {
840
- const x = n.findIndex((w) => w.onChange == b);
841
- x > -1 && n.splice(x, 1);
842
- }, s = (b, x) => {
843
- const w = {
844
- origin: b,
841
+ }, Ln = (t) => t.id !== void 0, Tn = () => {
842
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (y, w = {}) => {
843
+ n.push({ onChange: y, options: w });
844
+ }, i = (y) => {
845
+ const w = n.findIndex((A) => A.onChange == y);
846
+ w > -1 && n.splice(w, 1);
847
+ }, s = (y, w) => {
848
+ const A = {
849
+ origin: y,
845
850
  changes: {
846
- created: x.created || [],
847
- updated: x.updated || [],
848
- deleted: x.deleted || []
851
+ created: w.created || [],
852
+ updated: w.updated || [],
853
+ deleted: w.deleted || []
849
854
  },
850
855
  state: [...t.values()]
851
856
  };
852
- n.forEach((L) => {
853
- En(L, w) && L.onChange(w);
857
+ n.forEach((C) => {
858
+ Sn(C, A) && C.onChange(A);
854
859
  });
855
- }, a = (b, x = k.LOCAL) => {
856
- if (b.id && t.get(b.id))
857
- throw Error(`Cannot add annotation ${b.id} - exists already`);
860
+ }, a = (y, w = B.LOCAL) => {
861
+ if (y.id && t.get(y.id))
862
+ throw Error(`Cannot add annotation ${y.id} - exists already`);
858
863
  {
859
- const w = mt(b);
860
- t.set(w.id, w), w.bodies.forEach((L) => e.set(L.id, w.id)), s(x, { created: [w] });
864
+ const A = yt(y);
865
+ t.set(A.id, A), A.bodies.forEach((C) => e.set(C.id, A.id)), s(w, { created: [A] });
861
866
  }
862
- }, r = (b, x) => {
863
- const w = mt(typeof b == "string" ? x : b), L = typeof b == "string" ? b : b.id, B = L && t.get(L);
864
- if (B) {
865
- const O = pe(B, w);
866
- return L === w.id ? t.set(L, w) : (t.delete(L), t.set(w.id, w)), B.bodies.forEach((_) => e.delete(_.id)), w.bodies.forEach((_) => e.set(_.id, w.id)), O;
867
+ }, r = (y, w) => {
868
+ const A = yt(typeof y == "string" ? w : y), C = typeof y == "string" ? y : y.id, I = C && t.get(C);
869
+ if (I) {
870
+ const O = ge(I, A);
871
+ return C === A.id ? t.set(C, A) : (t.delete(C), t.set(A.id, A)), I.bodies.forEach((k) => e.delete(k.id)), A.bodies.forEach((k) => e.set(k.id, A.id)), O;
867
872
  } else
868
- console.warn(`Cannot update annotation ${L} - does not exist`);
869
- }, l = (b, x = k.LOCAL, w = k.LOCAL) => {
870
- const L = Cn(x) ? w : x, B = r(b, x);
871
- B && s(L, { updated: [B] });
872
- }, f = (b, x = k.LOCAL) => {
873
- t.get(b.id) ? l(b, x) : a(b, x);
874
- }, h = (b, x = k.LOCAL) => {
875
- const w = b.reduce((L, B) => {
876
- const O = r(B);
877
- return O ? [...L, O] : L;
873
+ console.warn(`Cannot update annotation ${C} - does not exist`);
874
+ }, d = (y, w = B.LOCAL, A = B.LOCAL) => {
875
+ const C = Ln(w) ? A : w, I = r(y, w);
876
+ I && s(C, { updated: [I] });
877
+ }, f = (y, w = B.LOCAL) => {
878
+ t.get(y.id) ? d(y, w) : a(y, w);
879
+ }, g = (y, w = B.LOCAL) => {
880
+ const A = y.reduce((C, I) => {
881
+ const O = r(I);
882
+ return O ? [...C, O] : C;
878
883
  }, []);
879
- w.length > 0 && s(x, { updated: w });
880
- }, u = (b, x = k.LOCAL) => {
881
- const w = b.map(mt), { toAdd: L, toUpdate: B } = w.reduce((_, P) => t.get(P.id) ? { ..._, toUpdate: [..._.toUpdate, P] } : { ..._, toAdd: [..._.toAdd, P] }, { toAdd: [], toUpdate: [] }), O = B.map((_) => r(_, x)).filter(Boolean);
882
- L.forEach((_) => {
883
- t.set(_.id, _), _.bodies.forEach((P) => e.set(P.id, _.id));
884
- }), s(x, { created: L, updated: O });
885
- }, p = (b, x = k.LOCAL) => {
886
- const w = t.get(b.annotation);
887
- if (w) {
888
- const L = {
889
- ...w,
890
- bodies: [...w.bodies, b]
884
+ A.length > 0 && s(w, { updated: A });
885
+ }, u = (y, w = B.LOCAL) => {
886
+ const A = y.map(yt), { toAdd: C, toUpdate: I } = A.reduce((k, P) => t.get(P.id) ? { ...k, toUpdate: [...k.toUpdate, P] } : { ...k, toAdd: [...k.toAdd, P] }, { toAdd: [], toUpdate: [] }), O = I.map((k) => r(k, w)).filter(Boolean);
887
+ C.forEach((k) => {
888
+ t.set(k.id, k), k.bodies.forEach((P) => e.set(P.id, k.id));
889
+ }), s(w, { created: C, updated: O });
890
+ }, h = (y, w = B.LOCAL) => {
891
+ const A = t.get(y.annotation);
892
+ if (A) {
893
+ const C = {
894
+ ...A,
895
+ bodies: [...A.bodies, y]
891
896
  };
892
- t.set(w.id, L), e.set(b.id, L.id), s(x, { updated: [{
893
- oldValue: w,
894
- newValue: L,
895
- bodiesCreated: [b]
897
+ t.set(A.id, C), e.set(y.id, C.id), s(w, { updated: [{
898
+ oldValue: A,
899
+ newValue: C,
900
+ bodiesCreated: [y]
896
901
  }] });
897
902
  } else
898
- console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
899
- }, v = () => [...t.values()], g = (b = k.LOCAL) => {
900
- const x = [...t.values()];
901
- t.clear(), e.clear(), s(b, { deleted: x });
902
- }, m = (b, x = !0, w = k.LOCAL) => {
903
- const L = b.map(mt);
904
- if (x) {
905
- const B = [...t.values()];
906
- t.clear(), e.clear(), L.forEach((O) => {
907
- t.set(O.id, O), O.bodies.forEach((_) => e.set(_.id, O.id));
908
- }), s(w, { created: L, deleted: B });
903
+ console.warn(`Attempt to add body to missing annotation: ${y.annotation}`);
904
+ }, v = () => [...t.values()], b = (y = B.LOCAL) => {
905
+ const w = [...t.values()];
906
+ t.clear(), e.clear(), s(y, { deleted: w });
907
+ }, p = (y, w = !0, A = B.LOCAL) => {
908
+ const C = y.map(yt);
909
+ if (w) {
910
+ const I = [...t.values()];
911
+ t.clear(), e.clear(), C.forEach((O) => {
912
+ t.set(O.id, O), O.bodies.forEach((k) => e.set(k.id, O.id));
913
+ }), s(A, { created: C, deleted: I });
909
914
  } else {
910
- const B = b.reduce((O, _) => {
911
- const P = _.id && t.get(_.id);
915
+ const I = y.reduce((O, k) => {
916
+ const P = k.id && t.get(k.id);
912
917
  return P ? [...O, P] : O;
913
918
  }, []);
914
- if (B.length > 0)
915
- throw Error(`Bulk insert would overwrite the following annotations: ${B.map((O) => O.id).join(", ")}`);
916
- L.forEach((O) => {
917
- t.set(O.id, O), O.bodies.forEach((_) => e.set(_.id, O.id));
918
- }), s(w, { created: L });
919
+ if (I.length > 0)
920
+ throw Error(`Bulk insert would overwrite the following annotations: ${I.map((O) => O.id).join(", ")}`);
921
+ C.forEach((O) => {
922
+ t.set(O.id, O), O.bodies.forEach((k) => e.set(k.id, O.id));
923
+ }), s(A, { created: C });
919
924
  }
920
- }, A = (b) => {
921
- const x = typeof b == "string" ? b : b.id, w = t.get(x);
922
- if (w)
923
- return t.delete(x), w.bodies.forEach((L) => e.delete(L.id)), w;
924
- console.warn(`Attempt to delete missing annotation: ${x}`);
925
- }, d = (b, x = k.LOCAL) => {
926
- const w = A(b);
927
- w && s(x, { deleted: [w] });
928
- }, c = (b, x = k.LOCAL) => {
929
- const w = b.reduce((L, B) => {
930
- const O = A(B);
931
- return O ? [...L, O] : L;
925
+ }, x = (y) => {
926
+ const w = typeof y == "string" ? y : y.id, A = t.get(w);
927
+ if (A)
928
+ return t.delete(w), A.bodies.forEach((C) => e.delete(C.id)), A;
929
+ console.warn(`Attempt to delete missing annotation: ${w}`);
930
+ }, c = (y, w = B.LOCAL) => {
931
+ const A = x(y);
932
+ A && s(w, { deleted: [A] });
933
+ }, l = (y, w = B.LOCAL) => {
934
+ const A = y.reduce((C, I) => {
935
+ const O = x(I);
936
+ return O ? [...C, O] : C;
932
937
  }, []);
933
- w.length > 0 && s(x, { deleted: w });
934
- }, y = (b) => {
935
- const x = t.get(b.annotation);
936
- if (x) {
937
- const w = x.bodies.find((L) => L.id === b.id);
938
- if (w) {
939
- e.delete(w.id);
940
- const L = {
941
- ...x,
942
- bodies: x.bodies.filter((B) => B.id !== b.id)
938
+ A.length > 0 && s(w, { deleted: A });
939
+ }, m = (y) => {
940
+ const w = t.get(y.annotation);
941
+ if (w) {
942
+ const A = w.bodies.find((C) => C.id === y.id);
943
+ if (A) {
944
+ e.delete(A.id);
945
+ const C = {
946
+ ...w,
947
+ bodies: w.bodies.filter((I) => I.id !== y.id)
943
948
  };
944
- return t.set(x.id, L), {
945
- oldValue: x,
946
- newValue: L,
947
- bodiesDeleted: [w]
949
+ return t.set(w.id, C), {
950
+ oldValue: w,
951
+ newValue: C,
952
+ bodiesDeleted: [A]
948
953
  };
949
954
  } else
950
- console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
955
+ console.warn(`Attempt to delete missing body ${y.id} from annotation ${y.annotation}`);
951
956
  } else
952
- console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
953
- }, S = (b, x = k.LOCAL) => {
954
- const w = y(b);
955
- w && s(x, { updated: [w] });
956
- }, E = (b, x = k.LOCAL) => {
957
- const w = b.map((L) => y(L)).filter(Boolean);
958
- w.length > 0 && s(x, { updated: w });
959
- }, C = (b) => {
960
- const x = t.get(b);
961
- return x ? { ...x } : void 0;
962
- }, R = (b) => {
963
- const x = e.get(b);
964
- if (x) {
965
- const w = C(x).bodies.find((L) => L.id === b);
966
- if (w)
967
- return w;
968
- console.error(`Store integrity error: body ${b} in index, but not in annotation`);
957
+ console.warn(`Attempt to delete body from missing annotation ${y.annotation}`);
958
+ }, S = (y, w = B.LOCAL) => {
959
+ const A = m(y);
960
+ A && s(w, { updated: [A] });
961
+ }, E = (y, w = B.LOCAL) => {
962
+ const A = y.map((C) => m(C)).filter(Boolean);
963
+ A.length > 0 && s(w, { updated: A });
964
+ }, L = (y) => {
965
+ const w = t.get(y);
966
+ return w ? { ...w } : void 0;
967
+ }, R = (y) => {
968
+ const w = e.get(y);
969
+ if (w) {
970
+ const A = L(w).bodies.find((C) => C.id === y);
971
+ if (A)
972
+ return A;
973
+ console.error(`Store integrity error: body ${y} in index, but not in annotation`);
969
974
  } else
970
- console.warn(`Attempt to retrieve missing body: ${b}`);
971
- }, M = (b, x) => {
972
- if (b.annotation !== x.annotation)
975
+ console.warn(`Attempt to retrieve missing body: ${y}`);
976
+ }, U = (y, w) => {
977
+ if (y.annotation !== w.annotation)
973
978
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
974
- const w = t.get(b.annotation);
975
- if (w) {
976
- const L = w.bodies.find((O) => O.id === b.id), B = {
977
- ...w,
978
- bodies: w.bodies.map((O) => O.id === L.id ? x : O)
979
+ const A = t.get(y.annotation);
980
+ if (A) {
981
+ const C = A.bodies.find((O) => O.id === y.id), I = {
982
+ ...A,
983
+ bodies: A.bodies.map((O) => O.id === C.id ? w : O)
979
984
  };
980
- return t.set(w.id, B), L.id !== x.id && (e.delete(L.id), e.set(x.id, B.id)), {
981
- oldValue: w,
982
- newValue: B,
983
- bodiesUpdated: [{ oldBody: L, newBody: x }]
985
+ return t.set(A.id, I), C.id !== w.id && (e.delete(C.id), e.set(w.id, I.id)), {
986
+ oldValue: A,
987
+ newValue: I,
988
+ bodiesUpdated: [{ oldBody: C, newBody: w }]
984
989
  };
985
990
  } else
986
- console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
987
- }, T = (b, x, w = k.LOCAL) => {
988
- const L = M(b, x);
989
- L && s(w, { updated: [L] });
990
- }, I = (b, x = k.LOCAL) => {
991
- const w = b.map((L) => M({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
992
- s(x, { updated: w });
993
- }, D = (b) => {
994
- const x = t.get(b.annotation);
995
- if (x) {
996
- const w = {
997
- ...x,
991
+ console.warn(`Attempt to add body to missing annotation ${y.annotation}`);
992
+ }, V = (y, w, A = B.LOCAL) => {
993
+ const C = U(y, w);
994
+ C && s(A, { updated: [C] });
995
+ }, T = (y, w = B.LOCAL) => {
996
+ const A = y.map((C) => U({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
997
+ s(w, { updated: A });
998
+ }, M = (y) => {
999
+ const w = t.get(y.annotation);
1000
+ if (w) {
1001
+ const A = {
1002
+ ...w,
998
1003
  target: {
999
- ...x.target,
1000
- ...b
1004
+ ...w.target,
1005
+ ...y
1001
1006
  }
1002
1007
  };
1003
- return t.set(x.id, w), {
1004
- oldValue: x,
1005
- newValue: w,
1008
+ return t.set(w.id, A), {
1009
+ oldValue: w,
1010
+ newValue: A,
1006
1011
  targetUpdated: {
1007
- oldTarget: x.target,
1008
- newTarget: b
1012
+ oldTarget: w.target,
1013
+ newTarget: y
1009
1014
  }
1010
1015
  };
1011
1016
  } else
1012
- console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
1017
+ console.warn(`Attempt to update target on missing annotation: ${y.annotation}`);
1013
1018
  };
1014
1019
  return {
1015
1020
  addAnnotation: a,
1016
- addBody: p,
1021
+ addBody: h,
1017
1022
  all: v,
1018
- bulkAddAnnotations: m,
1019
- bulkDeleteAnnotations: c,
1023
+ bulkAddAnnotations: p,
1024
+ bulkDeleteAnnotations: l,
1020
1025
  bulkDeleteBodies: E,
1021
- bulkUpdateAnnotations: h,
1022
- bulkUpdateBodies: I,
1023
- bulkUpdateTargets: (b, x = k.LOCAL) => {
1024
- const w = b.map((L) => D(L)).filter(Boolean);
1025
- w.length > 0 && s(x, { updated: w });
1026
+ bulkUpdateAnnotations: g,
1027
+ bulkUpdateBodies: T,
1028
+ bulkUpdateTargets: (y, w = B.LOCAL) => {
1029
+ const A = y.map((C) => M(C)).filter(Boolean);
1030
+ A.length > 0 && s(w, { updated: A });
1026
1031
  },
1027
1032
  bulkUpsertAnnotations: u,
1028
- clear: g,
1029
- deleteAnnotation: d,
1033
+ clear: b,
1034
+ deleteAnnotation: c,
1030
1035
  deleteBody: S,
1031
- getAnnotation: C,
1036
+ getAnnotation: L,
1032
1037
  getBody: R,
1033
1038
  observe: o,
1034
1039
  unobserve: i,
1035
- updateAnnotation: l,
1036
- updateBody: T,
1037
- updateTarget: (b, x = k.LOCAL) => {
1038
- const w = D(b);
1039
- w && s(x, { updated: [w] });
1040
+ updateAnnotation: d,
1041
+ updateBody: V,
1042
+ updateTarget: (y, w = B.LOCAL) => {
1043
+ const A = M(y);
1044
+ A && s(w, { updated: [A] });
1040
1045
  },
1041
1046
  upsertAnnotation: f
1042
1047
  };
1043
1048
  };
1044
- let Tn = () => ({
1049
+ let On = () => ({
1045
1050
  emit(t, ...e) {
1046
1051
  for (let n = this.events[t] || [], o = 0, i = n.length; o < i; o++)
1047
1052
  n[o](...e);
@@ -1055,120 +1060,120 @@ let Tn = () => ({
1055
1060
  };
1056
1061
  }
1057
1062
  });
1058
- const On = 250, Rn = (t, e) => {
1059
- const n = Tn(), o = [];
1063
+ const Rn = 250, Mn = (t, e) => {
1064
+ const n = On(), o = [];
1060
1065
  let i = -1, s = !1, a = 0;
1061
- const r = (g) => {
1066
+ const r = (b) => {
1062
1067
  if (!s) {
1063
- const { changes: m } = g, A = performance.now();
1064
- if (A - a > On)
1065
- o.splice(i + 1), o.push(m), i = o.length - 1;
1068
+ const { changes: p } = b, x = performance.now();
1069
+ if (x - a > Rn)
1070
+ o.splice(i + 1), o.push(p), i = o.length - 1;
1066
1071
  else {
1067
- const d = o.length - 1;
1068
- o[d] = Sn(o[d], m);
1072
+ const c = o.length - 1;
1073
+ o[c] = Cn(o[c], p);
1069
1074
  }
1070
- a = A;
1075
+ a = x;
1071
1076
  }
1072
1077
  s = !1;
1073
1078
  };
1074
- t.observe(r, { origin: k.LOCAL });
1075
- const l = (g) => g && g.length > 0 && t.bulkDeleteAnnotations(g), f = (g) => g && g.length > 0 && t.bulkAddAnnotations(g, !1), h = (g) => g && g.length > 0 && t.bulkUpdateAnnotations(g.map(({ oldValue: m }) => m)), u = (g) => g && g.length > 0 && t.bulkUpdateAnnotations(g.map(({ newValue: m }) => m)), p = (g) => g && g.length > 0 && t.bulkAddAnnotations(g, !1), v = (g) => g && g.length > 0 && t.bulkDeleteAnnotations(g);
1079
+ t.observe(r, { origin: B.LOCAL });
1080
+ const d = (b) => b && b.length > 0 && t.bulkDeleteAnnotations(b), f = (b) => b && b.length > 0 && t.bulkAddAnnotations(b, !1), g = (b) => b && b.length > 0 && t.bulkUpdateAnnotations(b.map(({ oldValue: p }) => p)), u = (b) => b && b.length > 0 && t.bulkUpdateAnnotations(b.map(({ newValue: p }) => p)), h = (b) => b && b.length > 0 && t.bulkAddAnnotations(b, !1), v = (b) => b && b.length > 0 && t.bulkDeleteAnnotations(b);
1076
1081
  return {
1077
1082
  canRedo: () => o.length - 1 > i,
1078
1083
  canUndo: () => i > -1,
1079
1084
  destroy: () => t.unobserve(r),
1080
1085
  getHistory: () => ({ changes: [...o], pointer: i }),
1081
- on: (g, m) => n.on(g, m),
1086
+ on: (b, p) => n.on(b, p),
1082
1087
  redo: () => {
1083
1088
  if (o.length - 1 > i) {
1084
1089
  s = !0;
1085
- const { created: g, updated: m, deleted: A } = o[i + 1];
1086
- f(g), u(m), v(A), n.emit("redo", o[i + 1]), i += 1;
1090
+ const { created: b, updated: p, deleted: x } = o[i + 1];
1091
+ f(b), u(p), v(x), n.emit("redo", o[i + 1]), i += 1;
1087
1092
  }
1088
1093
  },
1089
1094
  undo: () => {
1090
1095
  if (i > -1) {
1091
1096
  s = !0;
1092
- const { created: g, updated: m, deleted: A } = o[i];
1093
- l(g), h(m), p(A), n.emit("undo", o[i]), i -= 1;
1097
+ const { created: b, updated: p, deleted: x } = o[i];
1098
+ d(b), g(p), h(x), n.emit("undo", o[i]), i -= 1;
1094
1099
  }
1095
1100
  }
1096
1101
  };
1097
- }, Mn = () => {
1098
- const { subscribe: t, set: e } = Kt([]);
1102
+ }, kn = () => {
1103
+ const { subscribe: t, set: e } = Xt([]);
1099
1104
  return {
1100
1105
  subscribe: t,
1101
1106
  set: e
1102
1107
  };
1103
1108
  }, Bn = (t, e, n, o) => {
1104
- const { hover: i, selection: s, store: a, viewport: r } = t, l = /* @__PURE__ */ new Map();
1105
- let f = [], h;
1106
- const u = (m, A) => {
1107
- l.has(m) ? l.get(m).push(A) : l.set(m, [A]);
1108
- }, p = (m, A) => {
1109
- const d = l.get(m);
1110
- if (d) {
1111
- const c = d.indexOf(A);
1112
- c !== -1 && d.splice(c, 1);
1109
+ const { hover: i, selection: s, store: a, viewport: r } = t, d = /* @__PURE__ */ new Map();
1110
+ let f = [], g;
1111
+ const u = (p, x) => {
1112
+ d.has(p) ? d.get(p).push(x) : d.set(p, [x]);
1113
+ }, h = (p, x) => {
1114
+ const c = d.get(p);
1115
+ if (c) {
1116
+ const l = c.indexOf(x);
1117
+ l !== -1 && c.splice(l, 1);
1113
1118
  }
1114
- }, v = (m, A, d) => {
1115
- l.has(m) && setTimeout(() => {
1116
- l.get(m).forEach((c) => {
1119
+ }, v = (p, x, c) => {
1120
+ d.has(p) && setTimeout(() => {
1121
+ d.get(p).forEach((l) => {
1117
1122
  if (n) {
1118
- const y = Array.isArray(A) ? A.map((E) => n.serialize(E)) : n.serialize(A), S = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1119
- c(y, S);
1123
+ const m = Array.isArray(x) ? x.map((E) => n.serialize(E)) : n.serialize(x), S = c ? c instanceof PointerEvent ? c : n.serialize(c) : void 0;
1124
+ l(m, S);
1120
1125
  } else
1121
- c(A, d);
1126
+ l(x, c);
1122
1127
  });
1123
1128
  }, 1);
1124
1129
  };
1125
- s.subscribe(({ selected: m }) => {
1126
- if (!(f.length === 0 && m.length === 0)) {
1127
- if (f.length === 0 && m.length > 0)
1128
- f = m.map(({ id: A }) => a.getAnnotation(A));
1129
- else if (f.length > 0 && m.length === 0)
1130
- f.forEach((A) => {
1131
- const d = a.getAnnotation(A.id);
1132
- d && !Q(d, A) && v("updateAnnotation", d, A);
1130
+ s.subscribe(({ selected: p }) => {
1131
+ if (!(f.length === 0 && p.length === 0)) {
1132
+ if (f.length === 0 && p.length > 0)
1133
+ f = p.map(({ id: x }) => a.getAnnotation(x));
1134
+ else if (f.length > 0 && p.length === 0)
1135
+ f.forEach((x) => {
1136
+ const c = a.getAnnotation(x.id);
1137
+ c && !J(c, x) && v("updateAnnotation", c, x);
1133
1138
  }), f = [];
1134
1139
  else {
1135
- const A = new Set(f.map((c) => c.id)), d = new Set(m.map(({ id: c }) => c));
1136
- f.filter((c) => !d.has(c.id)).forEach((c) => {
1137
- const y = a.getAnnotation(c.id);
1138
- y && !Q(y, c) && v("updateAnnotation", y, c);
1140
+ const x = new Set(f.map((l) => l.id)), c = new Set(p.map(({ id: l }) => l));
1141
+ f.filter((l) => !c.has(l.id)).forEach((l) => {
1142
+ const m = a.getAnnotation(l.id);
1143
+ m && !J(m, l) && v("updateAnnotation", m, l);
1139
1144
  }), f = [
1140
1145
  // Remove annotations that were deselected
1141
- ...f.filter((c) => d.has(c.id)),
1146
+ ...f.filter((l) => c.has(l.id)),
1142
1147
  // Add editable annotations that were selected
1143
- ...m.filter(({ id: c }) => !A.has(c)).map(({ id: c }) => a.getAnnotation(c))
1148
+ ...p.filter(({ id: l }) => !x.has(l)).map(({ id: l }) => a.getAnnotation(l))
1144
1149
  ];
1145
1150
  }
1146
1151
  v("selectionChanged", f);
1147
1152
  }
1148
- }), i.subscribe((m) => {
1149
- !h && m ? v("mouseEnterAnnotation", a.getAnnotation(m)) : h && !m ? v("mouseLeaveAnnotation", a.getAnnotation(h)) : h && m && (v("mouseLeaveAnnotation", a.getAnnotation(h)), v("mouseEnterAnnotation", a.getAnnotation(m))), h = m;
1150
- }), r == null || r.subscribe((m) => v("viewportIntersect", m.map((A) => a.getAnnotation(A)))), a.observe((m) => {
1151
- const { created: A, deleted: d } = m.changes;
1152
- (A || []).forEach((c) => v("createAnnotation", c)), (d || []).forEach((c) => v("deleteAnnotation", c)), (m.changes.updated || []).filter((c) => [
1153
- ...c.bodiesCreated || [],
1154
- ...c.bodiesDeleted || [],
1155
- ...c.bodiesUpdated || []
1156
- ].length > 0).forEach(({ oldValue: c, newValue: y }) => {
1157
- const S = f.find((E) => E.id === c.id) || c;
1158
- f = f.map((E) => E.id === c.id ? y : E), v("updateAnnotation", y, S);
1153
+ }), i.subscribe((p) => {
1154
+ !g && p ? v("mouseEnterAnnotation", a.getAnnotation(p)) : g && !p ? v("mouseLeaveAnnotation", a.getAnnotation(g)) : g && p && (v("mouseLeaveAnnotation", a.getAnnotation(g)), v("mouseEnterAnnotation", a.getAnnotation(p))), g = p;
1155
+ }), r == null || r.subscribe((p) => v("viewportIntersect", p.map((x) => a.getAnnotation(x)))), a.observe((p) => {
1156
+ const { created: x, deleted: c } = p.changes;
1157
+ (x || []).forEach((l) => v("createAnnotation", l)), (c || []).forEach((l) => v("deleteAnnotation", l)), (p.changes.updated || []).filter((l) => [
1158
+ ...l.bodiesCreated || [],
1159
+ ...l.bodiesDeleted || [],
1160
+ ...l.bodiesUpdated || []
1161
+ ].length > 0).forEach(({ oldValue: l, newValue: m }) => {
1162
+ const S = f.find((E) => E.id === l.id) || l;
1163
+ f = f.map((E) => E.id === l.id ? m : E), v("updateAnnotation", m, S);
1159
1164
  });
1160
- }, { origin: k.LOCAL }), a.observe((m) => {
1165
+ }, { origin: B.LOCAL }), a.observe((p) => {
1161
1166
  if (f) {
1162
- const A = new Set(f.map((c) => c.id)), d = (m.changes.updated || []).filter(({ newValue: c }) => A.has(c.id)).map(({ newValue: c }) => c);
1163
- d.length > 0 && (f = f.map((c) => d.find((S) => S.id === c.id) || c));
1167
+ const x = new Set(f.map((l) => l.id)), c = (p.changes.updated || []).filter(({ newValue: l }) => x.has(l.id)).map(({ newValue: l }) => l);
1168
+ c.length > 0 && (f = f.map((l) => c.find((S) => S.id === l.id) || l));
1164
1169
  }
1165
- }, { origin: k.REMOTE });
1166
- const g = (m) => (A) => {
1167
- const { updated: d } = A;
1168
- m ? (d || []).forEach((c) => v("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => v("updateAnnotation", c.newValue, c.oldValue));
1170
+ }, { origin: B.REMOTE });
1171
+ const b = (p) => (x) => {
1172
+ const { updated: c } = x;
1173
+ p ? (c || []).forEach((l) => v("updateAnnotation", l.oldValue, l.newValue)) : (c || []).forEach((l) => v("updateAnnotation", l.newValue, l.oldValue));
1169
1174
  };
1170
- return e.on("undo", g(!0)), e.on("redo", g(!1)), { on: u, off: p, emit: v };
1171
- }, kn = (t) => (e) => e.reduce((n, o) => {
1175
+ return e.on("undo", b(!0)), e.on("redo", b(!1)), { on: u, off: h, emit: v };
1176
+ }, In = (t) => (e) => e.reduce((n, o) => {
1172
1177
  const { parsed: i, error: s } = t.parse(o);
1173
1178
  return s ? {
1174
1179
  parsed: n.parsed,
@@ -1179,47 +1184,47 @@ const On = 250, Rn = (t, e) => {
1179
1184
  } : {
1180
1185
  ...n
1181
1186
  };
1182
- }, { parsed: [], failed: [] }), In = (t, e, n) => {
1183
- const { store: o, selection: i } = t, s = (d) => {
1187
+ }, { parsed: [], failed: [] }), Un = (t, e, n) => {
1188
+ const { store: o, selection: i } = t, s = (c) => {
1184
1189
  if (n) {
1185
- const { parsed: c, error: y } = n.parse(d);
1186
- c ? o.addAnnotation(c, k.REMOTE) : console.error(y);
1190
+ const { parsed: l, error: m } = n.parse(c);
1191
+ l ? o.addAnnotation(l, B.REMOTE) : console.error(m);
1187
1192
  } else
1188
- o.addAnnotation(Mt(d), k.REMOTE);
1189
- }, a = () => i.clear(), r = () => o.clear(), l = (d) => {
1190
- const c = o.getAnnotation(d);
1191
- return n && c ? n.serialize(c) : c;
1192
- }, f = () => n ? o.all().map(n.serialize) : o.all(), h = () => {
1193
- var d;
1194
- const c = (((d = i.selected) == null ? void 0 : d.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1195
- return n ? c.map(n.serialize) : c;
1196
- }, u = (d, c = !0) => fetch(d).then((y) => y.json()).then((y) => (v(y, c), y)), p = (d) => {
1197
- if (typeof d == "string") {
1198
- const c = o.getAnnotation(d);
1199
- if (o.deleteAnnotation(d), c)
1200
- return n ? n.serialize(c) : c;
1193
+ o.addAnnotation(kt(c), B.REMOTE);
1194
+ }, a = () => i.clear(), r = () => o.clear(), d = (c) => {
1195
+ const l = o.getAnnotation(c);
1196
+ return n && l ? n.serialize(l) : l;
1197
+ }, f = () => n ? o.all().map(n.serialize) : o.all(), g = () => {
1198
+ var c;
1199
+ const l = (((c = i.selected) == null ? void 0 : c.map((m) => m.id)) || []).map((m) => o.getAnnotation(m)).filter(Boolean);
1200
+ return n ? l.map(n.serialize) : l;
1201
+ }, u = (c, l = !0) => fetch(c).then((m) => m.json()).then((m) => (v(m, l), m)), h = (c) => {
1202
+ if (typeof c == "string") {
1203
+ const l = o.getAnnotation(c);
1204
+ if (o.deleteAnnotation(c), l)
1205
+ return n ? n.serialize(l) : l;
1201
1206
  } else {
1202
- const c = n ? n.parse(d).parsed : d;
1203
- if (c)
1204
- return o.deleteAnnotation(c), d;
1207
+ const l = n ? n.parse(c).parsed : c;
1208
+ if (l)
1209
+ return o.deleteAnnotation(l), c;
1205
1210
  }
1206
- }, v = (d, c = !0) => {
1211
+ }, v = (c, l = !0) => {
1207
1212
  if (n) {
1208
- const y = n.parseAll || kn(n), { parsed: S, failed: E } = y(d);
1209
- E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotations(S, c, k.REMOTE);
1213
+ const m = n.parseAll || In(n), { parsed: S, failed: E } = m(c);
1214
+ E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotations(S, l, B.REMOTE);
1210
1215
  } else
1211
- o.bulkAddAnnotations(d.map(Mt), c, k.REMOTE);
1212
- }, g = (d, c) => {
1213
- d ? i.setSelected(d, c) : i.clear();
1214
- }, m = (d) => {
1215
- i.clear(), i.setUserSelectAction(d);
1216
- }, A = (d) => {
1216
+ o.bulkAddAnnotations(c.map(kt), l, B.REMOTE);
1217
+ }, b = (c, l) => {
1218
+ c ? i.setSelected(c, l) : i.clear();
1219
+ }, p = (c) => {
1220
+ i.clear(), i.setUserSelectAction(c);
1221
+ }, x = (c) => {
1217
1222
  if (n) {
1218
- const c = n.parse(d).parsed, y = n.serialize(o.getAnnotation(c.id));
1219
- return o.updateAnnotation(c), y;
1223
+ const l = n.parse(c).parsed, m = n.serialize(o.getAnnotation(l.id));
1224
+ return o.updateAnnotation(l), m;
1220
1225
  } else {
1221
- const c = o.getAnnotation(d.id);
1222
- return o.updateAnnotation(Mt(d)), c;
1226
+ const l = o.getAnnotation(c.id);
1227
+ return o.updateAnnotation(kt(c)), l;
1223
1228
  }
1224
1229
  };
1225
1230
  return {
@@ -1228,37 +1233,37 @@ const On = 250, Rn = (t, e) => {
1228
1233
  canRedo: e.canRedo,
1229
1234
  canUndo: e.canUndo,
1230
1235
  clearAnnotations: r,
1231
- getAnnotationById: l,
1236
+ getAnnotationById: d,
1232
1237
  getAnnotations: f,
1233
1238
  getHistory: e.getHistory,
1234
- getSelected: h,
1239
+ getSelected: g,
1235
1240
  loadAnnotations: u,
1236
1241
  redo: e.redo,
1237
- removeAnnotation: p,
1242
+ removeAnnotation: h,
1238
1243
  setAnnotations: v,
1239
- setSelected: g,
1240
- setUserSelectAction: m,
1244
+ setSelected: b,
1245
+ setUserSelectAction: p,
1241
1246
  undo: e.undo,
1242
- updateAnnotation: A
1247
+ updateAnnotation: x
1243
1248
  };
1244
1249
  }, _n = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1245
- let Un = (t) => crypto.getRandomValues(new Uint8Array(t)), Nn = (t, e, n) => {
1250
+ let Nn = (t) => crypto.getRandomValues(new Uint8Array(t)), Vn = (t, e, n) => {
1246
1251
  let o = (2 << Math.log2(t.length - 1)) - 1, i = -~(1.6 * o * e / t.length);
1247
1252
  return (s = e) => {
1248
1253
  let a = "";
1249
1254
  for (; ; ) {
1250
- let r = n(i), l = i | 0;
1251
- for (; l--; )
1252
- if (a += t[r[l] & o] || "", a.length >= s) return a;
1255
+ let r = n(i), d = i | 0;
1256
+ for (; d--; )
1257
+ if (a += t[r[d] & o] || "", a.length >= s) return a;
1253
1258
  }
1254
1259
  };
1255
- }, Vn = (t, e = 21) => Nn(t, e | 0, Un), Dn = (t = 21) => {
1260
+ }, Dn = (t, e = 21) => Vn(t, e | 0, Nn), Kn = (t = 21) => {
1256
1261
  let e = "", n = crypto.getRandomValues(new Uint8Array(t |= 0));
1257
1262
  for (; t--; )
1258
1263
  e += _n[n[t] & 63];
1259
1264
  return e;
1260
1265
  };
1261
- const Yn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Kn = (t) => {
1266
+ const Yn = () => ({ isGuest: !0, id: Dn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Xn = (t) => {
1262
1267
  const e = JSON.stringify(t);
1263
1268
  let n = 0;
1264
1269
  for (let o = 0, i = e.length; o < i; o++) {
@@ -1266,20 +1271,20 @@ const Yn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABC
1266
1271
  n = (n << 5) - n + s, n |= 0;
1267
1272
  }
1268
1273
  return `${n}`;
1269
- }, ge = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Xn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1270
- const { id: o, type: i, purpose: s, value: a, created: r, modified: l, creator: f, ...h } = n;
1274
+ }, pe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Pn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1275
+ const { id: o, type: i, purpose: s, value: a, created: r, modified: d, creator: f, ...g } = n;
1271
1276
  return {
1272
- id: o || `temp-${Kn(n)}`,
1277
+ id: o || `temp-${Xn(n)}`,
1273
1278
  annotation: e,
1274
1279
  type: i,
1275
1280
  purpose: s,
1276
1281
  value: a,
1277
- creator: ge(f),
1282
+ creator: pe(f),
1278
1283
  created: r ? new Date(r) : void 0,
1279
- updated: l ? new Date(l) : void 0,
1280
- ...h
1284
+ updated: d ? new Date(d) : void 0,
1285
+ ...g
1281
1286
  };
1282
- }), Pn = (t) => t.map((e) => {
1287
+ }), $n = (t) => t.map((e) => {
1283
1288
  var n;
1284
1289
  const { annotation: o, created: i, updated: s, ...a } = e, r = {
1285
1290
  ...a,
@@ -1288,11 +1293,11 @@ const Yn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABC
1288
1293
  };
1289
1294
  return (n = r.id) != null && n.startsWith("temp-") && delete r.id, r;
1290
1295
  });
1291
- Dn();
1292
- const xo = (t, e) => ({
1293
- parse: (n) => jn(n),
1294
- serialize: (n) => zn(n, t, e)
1295
- }), $n = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, Hn = (t) => {
1296
+ Kn();
1297
+ const vo = (t, e) => ({
1298
+ parse: (n) => zn(n),
1299
+ serialize: (n) => Fn(n, t, e)
1300
+ }), Hn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, jn = (t) => {
1296
1301
  const {
1297
1302
  id: e,
1298
1303
  creator: n,
@@ -1303,7 +1308,7 @@ const xo = (t, e) => ({
1303
1308
  if (a.length === 0)
1304
1309
  return { error: Error(`No targets found for annotation: ${t.id}`) };
1305
1310
  const r = {
1306
- creator: ge(n),
1311
+ creator: pe(n),
1307
1312
  created: o ? new Date(o) : void 0,
1308
1313
  updated: i ? new Date(i) : void 0,
1309
1314
  annotation: e,
@@ -1311,80 +1316,80 @@ const xo = (t, e) => ({
1311
1316
  // @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
1312
1317
  styleClass: "styleClass" in a[0] ? a[0].styleClass : void 0
1313
1318
  };
1314
- for (const l of a) {
1315
- const h = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((u, p) => {
1316
- switch (p.type) {
1319
+ for (const d of a) {
1320
+ const g = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((u, h) => {
1321
+ switch (h.type) {
1317
1322
  case "TextQuoteSelector":
1318
- u.quote = p.exact;
1323
+ u.quote = h.exact;
1319
1324
  break;
1320
1325
  case "TextPositionSelector":
1321
- u.start = p.start, u.end = p.end;
1326
+ u.start = h.start, u.end = h.end;
1322
1327
  break;
1323
1328
  }
1324
1329
  return u;
1325
1330
  }, {});
1326
- if ($n(h))
1331
+ if (Hn(g))
1327
1332
  r.selector.push(
1328
1333
  {
1329
- ...h,
1330
- id: l.id,
1334
+ ...g,
1335
+ id: d.id,
1331
1336
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1332
- scope: l.scope
1337
+ scope: d.scope
1333
1338
  }
1334
1339
  );
1335
1340
  else {
1336
1341
  const u = [
1337
- h.start ? void 0 : "TextPositionSelector",
1338
- h.quote ? void 0 : "TextQuoteSelector"
1342
+ g.start ? void 0 : "TextPositionSelector",
1343
+ g.quote ? void 0 : "TextQuoteSelector"
1339
1344
  ].filter(Boolean);
1340
1345
  return { error: Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`) };
1341
1346
  }
1342
1347
  }
1343
1348
  return { parsed: r };
1344
- }, jn = (t) => {
1349
+ }, zn = (t) => {
1345
1350
  const e = t.id || fe(), {
1346
1351
  creator: n,
1347
1352
  created: o,
1348
1353
  modified: i,
1349
1354
  body: s,
1350
1355
  ...a
1351
- } = t, r = Xn(s, e), l = Hn(t);
1352
- return "error" in l ? { error: l.error } : {
1356
+ } = t, r = Pn(s, e), d = jn(t);
1357
+ return "error" in d ? { error: d.error } : {
1353
1358
  parsed: {
1354
1359
  ...a,
1355
1360
  id: e,
1356
1361
  bodies: r,
1357
- target: l.parsed
1362
+ target: d.parsed
1358
1363
  }
1359
1364
  };
1360
- }, zn = (t, e, n) => {
1365
+ }, Fn = (t, e, n) => {
1361
1366
  const { bodies: o, target: i, ...s } = t, {
1362
1367
  selector: a,
1363
1368
  creator: r,
1364
- created: l,
1369
+ created: d,
1365
1370
  updated: f,
1366
- ...h
1367
- } = i, u = a.map((p) => {
1368
- const { id: v, quote: g, start: m, end: A, range: d } = p, c = {
1371
+ ...g
1372
+ } = i, u = a.map((h) => {
1373
+ const { id: v, quote: b, start: p, end: x, range: c } = h, l = {
1369
1374
  type: "TextQuoteSelector",
1370
- exact: g
1375
+ exact: b
1371
1376
  };
1372
1377
  if (n) {
1373
- const { prefix: S, suffix: E } = Be(d, n);
1374
- c.prefix = S, c.suffix = E;
1378
+ const { prefix: S, suffix: E } = ke(c, n);
1379
+ l.prefix = S, l.suffix = E;
1375
1380
  }
1376
- const y = {
1381
+ const m = {
1377
1382
  type: "TextPositionSelector",
1378
- start: m,
1379
- end: A
1383
+ start: p,
1384
+ end: x
1380
1385
  };
1381
1386
  return {
1382
- ...h,
1387
+ ...g,
1383
1388
  id: v,
1384
1389
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
1385
- scope: "scope" in p ? p.scope : void 0,
1390
+ scope: "scope" in h ? h.scope : void 0,
1386
1391
  source: e,
1387
- selector: [c, y]
1392
+ selector: [l, m]
1388
1393
  };
1389
1394
  });
1390
1395
  return {
@@ -1392,36 +1397,36 @@ const xo = (t, e) => ({
1392
1397
  "@context": "http://www.w3.org/ns/anno.jsonld",
1393
1398
  id: t.id,
1394
1399
  type: "Annotation",
1395
- body: Pn(t.bodies),
1400
+ body: $n(t.bodies),
1396
1401
  creator: r,
1397
- created: l == null ? void 0 : l.toISOString(),
1402
+ created: d == null ? void 0 : d.toISOString(),
1398
1403
  modified: f == null ? void 0 : f.toISOString(),
1399
1404
  target: u
1400
1405
  };
1401
1406
  };
1402
- function me(t, e, n = 0, o = t.length - 1, i = Fn) {
1407
+ function me(t, e, n = 0, o = t.length - 1, i = Wn) {
1403
1408
  for (; o > n; ) {
1404
1409
  if (o - n > 600) {
1405
- 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), v = Math.max(n, Math.floor(e - f * u / l + p)), g = Math.min(o, Math.floor(e + (l - f) * u / l + p));
1406
- me(t, e, v, g, i);
1410
+ const d = o - n + 1, f = e - n + 1, g = Math.log(d), u = 0.5 * Math.exp(2 * g / 3), h = 0.5 * Math.sqrt(g * u * (d - u) / d) * (f - d / 2 < 0 ? -1 : 1), v = Math.max(n, Math.floor(e - f * u / d + h)), b = Math.min(o, Math.floor(e + (d - f) * u / d + h));
1411
+ me(t, e, v, b, i);
1407
1412
  }
1408
1413
  const s = t[e];
1409
1414
  let a = n, r = o;
1410
- for (nt(t, n, e), i(t[o], s) > 0 && nt(t, n, o); a < r; ) {
1411
- for (nt(t, a, r), a++, r--; i(t[a], s) < 0; ) a++;
1415
+ for (it(t, n, e), i(t[o], s) > 0 && it(t, n, o); a < r; ) {
1416
+ for (it(t, a, r), a++, r--; i(t[a], s) < 0; ) a++;
1412
1417
  for (; i(t[r], s) > 0; ) r--;
1413
1418
  }
1414
- i(t[n], s) === 0 ? nt(t, n, r) : (r++, nt(t, r, o)), r <= e && (n = r + 1), e <= r && (o = r - 1);
1419
+ i(t[n], s) === 0 ? it(t, n, r) : (r++, it(t, r, o)), r <= e && (n = r + 1), e <= r && (o = r - 1);
1415
1420
  }
1416
1421
  }
1417
- function nt(t, e, n) {
1422
+ function it(t, e, n) {
1418
1423
  const o = t[e];
1419
1424
  t[e] = t[n], t[n] = o;
1420
1425
  }
1421
- function Fn(t, e) {
1426
+ function Wn(t, e) {
1422
1427
  return t < e ? -1 : t > e ? 1 : 0;
1423
1428
  }
1424
- class Wn {
1429
+ class qn {
1425
1430
  constructor(e = 9) {
1426
1431
  this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
1427
1432
  }
@@ -1431,12 +1436,12 @@ class Wn {
1431
1436
  search(e) {
1432
1437
  let n = this.data;
1433
1438
  const o = [];
1434
- if (!bt(e, n)) return o;
1439
+ if (!wt(e, n)) return o;
1435
1440
  const i = this.toBBox, s = [];
1436
1441
  for (; n; ) {
1437
1442
  for (let a = 0; a < n.children.length; a++) {
1438
- const r = n.children[a], l = n.leaf ? i(r) : r;
1439
- bt(e, l) && (n.leaf ? o.push(r) : kt(e, l) ? this._all(r, o) : s.push(r));
1443
+ const r = n.children[a], d = n.leaf ? i(r) : r;
1444
+ wt(e, d) && (n.leaf ? o.push(r) : It(e, d) ? this._all(r, o) : s.push(r));
1440
1445
  }
1441
1446
  n = s.pop();
1442
1447
  }
@@ -1444,13 +1449,13 @@ class Wn {
1444
1449
  }
1445
1450
  collides(e) {
1446
1451
  let n = this.data;
1447
- if (!bt(e, n)) return !1;
1452
+ if (!wt(e, n)) return !1;
1448
1453
  const o = [];
1449
1454
  for (; n; ) {
1450
1455
  for (let i = 0; i < n.children.length; i++) {
1451
1456
  const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
1452
- if (bt(e, a)) {
1453
- if (n.leaf || kt(e, a)) return !0;
1457
+ if (wt(e, a)) {
1458
+ if (n.leaf || It(e, a)) return !0;
1454
1459
  o.push(s);
1455
1460
  }
1456
1461
  }
@@ -1483,20 +1488,20 @@ class Wn {
1483
1488
  return e && this._insert(e, this.data.height - 1), this;
1484
1489
  }
1485
1490
  clear() {
1486
- return this.data = tt([]), this;
1491
+ return this.data = et([]), this;
1487
1492
  }
1488
1493
  remove(e, n) {
1489
1494
  if (!e) return this;
1490
1495
  let o = this.data;
1491
1496
  const i = this.toBBox(e), s = [], a = [];
1492
- let r, l, f;
1497
+ let r, d, f;
1493
1498
  for (; o || s.length; ) {
1494
- if (o || (o = s.pop(), l = s[s.length - 1], r = a.pop(), f = !0), o.leaf) {
1495
- const h = qn(e, o.children, n);
1496
- if (h !== -1)
1497
- return o.children.splice(h, 1), s.push(o), this._condense(s), this;
1499
+ if (o || (o = s.pop(), d = s[s.length - 1], r = a.pop(), f = !0), o.leaf) {
1500
+ const g = Gn(e, o.children, n);
1501
+ if (g !== -1)
1502
+ return o.children.splice(g, 1), s.push(o), this._condense(s), this;
1498
1503
  }
1499
- !f && !o.leaf && kt(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;
1504
+ !f && !o.leaf && It(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;
1500
1505
  }
1501
1506
  return this;
1502
1507
  }
@@ -1525,26 +1530,26 @@ class Wn {
1525
1530
  const s = o - n + 1;
1526
1531
  let a = this._maxEntries, r;
1527
1532
  if (s <= a)
1528
- return r = tt(e.slice(n, o + 1)), Z(r, this.toBBox), r;
1529
- i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = tt([]), r.leaf = !1, r.height = i;
1530
- const l = Math.ceil(s / a), f = l * Math.ceil(Math.sqrt(a));
1533
+ return r = et(e.slice(n, o + 1)), tt(r, this.toBBox), r;
1534
+ i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = et([]), r.leaf = !1, r.height = i;
1535
+ const d = Math.ceil(s / a), f = d * Math.ceil(Math.sqrt(a));
1531
1536
  ee(e, n, o, f, this.compareMinX);
1532
- for (let h = n; h <= o; h += f) {
1533
- const u = Math.min(h + f - 1, o);
1534
- ee(e, h, u, l, this.compareMinY);
1535
- for (let p = h; p <= u; p += l) {
1536
- const v = Math.min(p + l - 1, u);
1537
- r.children.push(this._build(e, p, v, i - 1));
1537
+ for (let g = n; g <= o; g += f) {
1538
+ const u = Math.min(g + f - 1, o);
1539
+ ee(e, g, u, d, this.compareMinY);
1540
+ for (let h = g; h <= u; h += d) {
1541
+ const v = Math.min(h + d - 1, u);
1542
+ r.children.push(this._build(e, h, v, i - 1));
1538
1543
  }
1539
1544
  }
1540
- return Z(r, this.toBBox), r;
1545
+ return tt(r, this.toBBox), r;
1541
1546
  }
1542
1547
  _chooseSubtree(e, n, o, i) {
1543
1548
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1544
1549
  let s = 1 / 0, a = 1 / 0, r;
1545
- for (let l = 0; l < n.children.length; l++) {
1546
- const f = n.children[l], h = Bt(f), u = Jn(e, f) - h;
1547
- u < a ? (a = u, s = h < s ? h : s, r = f) : u === a && h < s && (s = h, r = f);
1550
+ for (let d = 0; d < n.children.length; d++) {
1551
+ const f = n.children[d], g = Bt(f), u = Zn(e, f) - g;
1552
+ u < a ? (a = u, s = g < s ? g : s, r = f) : u === a && g < s && (s = g, r = f);
1548
1553
  }
1549
1554
  n = r || n.children[0];
1550
1555
  }
@@ -1552,7 +1557,7 @@ class Wn {
1552
1557
  }
1553
1558
  _insert(e, n, o) {
1554
1559
  const i = o ? e : this.toBBox(e), s = [], a = this._chooseSubtree(i, this.data, n, s);
1555
- for (a.children.push(e), rt(a, i); n >= 0 && s[n].children.length > this._maxEntries; )
1560
+ for (a.children.push(e), lt(a, i); n >= 0 && s[n].children.length > this._maxEntries; )
1556
1561
  this._split(s, n), n--;
1557
1562
  this._adjustParentBBoxes(i, s, n);
1558
1563
  }
@@ -1560,95 +1565,95 @@ class Wn {
1560
1565
  _split(e, n) {
1561
1566
  const o = e[n], i = o.children.length, s = this._minEntries;
1562
1567
  this._chooseSplitAxis(o, s, i);
1563
- const a = this._chooseSplitIndex(o, s, i), r = tt(o.children.splice(a, o.children.length - a));
1564
- r.height = o.height, r.leaf = o.leaf, Z(o, this.toBBox), Z(r, this.toBBox), n ? e[n - 1].children.push(r) : this._splitRoot(o, r);
1568
+ const a = this._chooseSplitIndex(o, s, i), r = et(o.children.splice(a, o.children.length - a));
1569
+ r.height = o.height, r.leaf = o.leaf, tt(o, this.toBBox), tt(r, this.toBBox), n ? e[n - 1].children.push(r) : this._splitRoot(o, r);
1565
1570
  }
1566
1571
  _splitRoot(e, n) {
1567
- this.data = tt([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, Z(this.data, this.toBBox);
1572
+ this.data = et([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, tt(this.data, this.toBBox);
1568
1573
  }
1569
1574
  _chooseSplitIndex(e, n, o) {
1570
1575
  let i, s = 1 / 0, a = 1 / 0;
1571
1576
  for (let r = n; r <= o - n; r++) {
1572
- const l = st(e, 0, r, this.toBBox), f = st(e, r, o, this.toBBox), h = Zn(l, f), u = Bt(l) + Bt(f);
1573
- h < s ? (s = h, i = r, a = u < a ? u : a) : h === s && u < a && (a = u, i = r);
1577
+ const d = at(e, 0, r, this.toBBox), f = at(e, r, o, this.toBBox), g = to(d, f), u = Bt(d) + Bt(f);
1578
+ g < s ? (s = g, i = r, a = u < a ? u : a) : g === s && u < a && (a = u, i = r);
1574
1579
  }
1575
1580
  return i || o - n;
1576
1581
  }
1577
1582
  // sorts node children by the best axis for split
1578
1583
  _chooseSplitAxis(e, n, o) {
1579
- const i = e.leaf ? this.compareMinX : Gn, s = e.leaf ? this.compareMinY : Qn, a = this._allDistMargin(e, n, o, i), r = this._allDistMargin(e, n, o, s);
1584
+ const i = e.leaf ? this.compareMinX : Qn, s = e.leaf ? this.compareMinY : Jn, a = this._allDistMargin(e, n, o, i), r = this._allDistMargin(e, n, o, s);
1580
1585
  a < r && e.children.sort(i);
1581
1586
  }
1582
1587
  // total margin of all possible split distributions where each node is at least m full
1583
1588
  _allDistMargin(e, n, o, i) {
1584
1589
  e.children.sort(i);
1585
- const s = this.toBBox, a = st(e, 0, n, s), r = st(e, o - n, o, s);
1586
- let l = yt(a) + yt(r);
1590
+ const s = this.toBBox, a = at(e, 0, n, s), r = at(e, o - n, o, s);
1591
+ let d = bt(a) + bt(r);
1587
1592
  for (let f = n; f < o - n; f++) {
1588
- const h = e.children[f];
1589
- rt(a, e.leaf ? s(h) : h), l += yt(a);
1593
+ const g = e.children[f];
1594
+ lt(a, e.leaf ? s(g) : g), d += bt(a);
1590
1595
  }
1591
1596
  for (let f = o - n - 1; f >= n; f--) {
1592
- const h = e.children[f];
1593
- rt(r, e.leaf ? s(h) : h), l += yt(r);
1597
+ const g = e.children[f];
1598
+ lt(r, e.leaf ? s(g) : g), d += bt(r);
1594
1599
  }
1595
- return l;
1600
+ return d;
1596
1601
  }
1597
1602
  _adjustParentBBoxes(e, n, o) {
1598
1603
  for (let i = o; i >= 0; i--)
1599
- rt(n[i], e);
1604
+ lt(n[i], e);
1600
1605
  }
1601
1606
  _condense(e) {
1602
1607
  for (let n = e.length - 1, o; n >= 0; n--)
1603
- e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : Z(e[n], this.toBBox);
1608
+ e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : tt(e[n], this.toBBox);
1604
1609
  }
1605
1610
  }
1606
- function qn(t, e, n) {
1611
+ function Gn(t, e, n) {
1607
1612
  if (!n) return e.indexOf(t);
1608
1613
  for (let o = 0; o < e.length; o++)
1609
1614
  if (n(t, e[o])) return o;
1610
1615
  return -1;
1611
1616
  }
1612
- function Z(t, e) {
1613
- st(t, 0, t.children.length, e, t);
1617
+ function tt(t, e) {
1618
+ at(t, 0, t.children.length, e, t);
1614
1619
  }
1615
- function st(t, e, n, o, i) {
1616
- i || (i = tt(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
1620
+ function at(t, e, n, o, i) {
1621
+ i || (i = et(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
1617
1622
  for (let s = e; s < n; s++) {
1618
1623
  const a = t.children[s];
1619
- rt(i, t.leaf ? o(a) : a);
1624
+ lt(i, t.leaf ? o(a) : a);
1620
1625
  }
1621
1626
  return i;
1622
1627
  }
1623
- function rt(t, e) {
1628
+ function lt(t, e) {
1624
1629
  return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
1625
1630
  }
1626
- function Gn(t, e) {
1631
+ function Qn(t, e) {
1627
1632
  return t.minX - e.minX;
1628
1633
  }
1629
- function Qn(t, e) {
1634
+ function Jn(t, e) {
1630
1635
  return t.minY - e.minY;
1631
1636
  }
1632
1637
  function Bt(t) {
1633
1638
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1634
1639
  }
1635
- function yt(t) {
1640
+ function bt(t) {
1636
1641
  return t.maxX - t.minX + (t.maxY - t.minY);
1637
1642
  }
1638
- function Jn(t, e) {
1643
+ function Zn(t, e) {
1639
1644
  return (Math.max(e.maxX, t.maxX) - Math.min(e.minX, t.minX)) * (Math.max(e.maxY, t.maxY) - Math.min(e.minY, t.minY));
1640
1645
  }
1641
- function Zn(t, e) {
1646
+ function to(t, e) {
1642
1647
  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);
1643
1648
  return Math.max(0, i - n) * Math.max(0, s - o);
1644
1649
  }
1645
- function kt(t, e) {
1650
+ function It(t, e) {
1646
1651
  return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1647
1652
  }
1648
- function bt(t, e) {
1653
+ function wt(t, e) {
1649
1654
  return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
1650
1655
  }
1651
- function tt(t) {
1656
+ function et(t) {
1652
1657
  return {
1653
1658
  children: t,
1654
1659
  height: 1,
@@ -1667,177 +1672,177 @@ function ee(t, e, n, o, i) {
1667
1672
  me(t, a, e, n, i), s.push(e, a, a, n);
1668
1673
  }
1669
1674
  }
1670
- const to = (t, e) => {
1671
- const n = new Wn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1672
- const y = d.selector.flatMap((E) => {
1673
- const C = q([E]) ? E.range : ae(E, e).range;
1674
- return Array.from(C.getClientRects());
1675
- }), S = Ne(y).map(({ left: E, top: C, right: R, bottom: M }) => new DOMRect(E - c.left, C - c.top, R - E, M - C));
1675
+ const eo = (t, e) => {
1676
+ const n = new qn(), o = /* @__PURE__ */ new Map(), i = (c, l) => {
1677
+ const m = c.selector.flatMap((E) => {
1678
+ const L = q([E]) ? E.range : ae(E, e).range;
1679
+ return Array.from(L.getClientRects());
1680
+ }), S = Ne(m).map(({ left: E, top: L, right: R, bottom: U }) => new DOMRect(E - l.left, L - l.top, R - E, U - L));
1676
1681
  return S.map((E) => {
1677
- const { x: C, y: R, width: M, height: T } = E;
1682
+ const { x: L, y: R, width: U, height: V } = E;
1678
1683
  return {
1679
- minX: C,
1684
+ minX: L,
1680
1685
  minY: R,
1681
- maxX: C + M,
1682
- maxY: R + T,
1686
+ maxX: L + U,
1687
+ maxY: R + V,
1683
1688
  annotation: {
1684
- id: d.annotation,
1689
+ id: c.annotation,
1685
1690
  rects: S
1686
1691
  }
1687
1692
  };
1688
1693
  });
1689
1694
  }, s = () => [...o.values()], a = () => {
1690
1695
  n.clear(), o.clear();
1691
- }, r = (d) => {
1692
- const c = i(d, e.getBoundingClientRect());
1693
- c.length !== 0 && (c.forEach((y) => n.insert(y)), o.set(d.annotation, c));
1694
- }, l = (d) => {
1695
- const c = o.get(d.annotation);
1696
- c && (c.forEach((y) => n.remove(y)), o.delete(d.annotation));
1697
- }, f = (d) => {
1698
- l(d), r(d);
1699
- }, h = (d, c = !0) => {
1700
- c && a();
1701
- const y = e.getBoundingClientRect(), S = d.map((C) => ({ target: C, rects: i(C, y) }));
1702
- S.forEach(({ target: C, rects: R }) => {
1703
- R.length > 0 && o.set(C.annotation, R);
1696
+ }, r = (c) => {
1697
+ const l = i(c, e.getBoundingClientRect());
1698
+ l.length !== 0 && (l.forEach((m) => n.insert(m)), o.set(c.annotation, l));
1699
+ }, d = (c) => {
1700
+ const l = o.get(c.annotation);
1701
+ l && (l.forEach((m) => n.remove(m)), o.delete(c.annotation));
1702
+ }, f = (c) => {
1703
+ d(c), r(c);
1704
+ }, g = (c, l = !0) => {
1705
+ l && a();
1706
+ const m = e.getBoundingClientRect(), S = c.map((L) => ({ target: L, rects: i(L, m) }));
1707
+ S.forEach(({ target: L, rects: R }) => {
1708
+ R.length > 0 && o.set(L.annotation, R);
1704
1709
  });
1705
- const E = S.flatMap(({ rects: C }) => C);
1710
+ const E = S.flatMap(({ rects: L }) => L);
1706
1711
  n.load(E);
1707
- }, u = (d, c, y = !1) => {
1712
+ }, u = (c, l, m = !1) => {
1708
1713
  const S = n.search({
1709
- minX: d,
1710
- minY: c,
1711
- maxX: d,
1712
- maxY: c
1713
- }), E = (C) => C.annotation.rects.reduce((R, M) => R + M.width * M.height, 0);
1714
- return S.length > 0 ? (S.sort((C, R) => E(C) - E(R)), y ? S.map((C) => C.annotation.id) : [S[0].annotation.id]) : [];
1715
- }, p = (d) => {
1716
- const c = v(d);
1717
- if (c.length === 0)
1714
+ minX: c,
1715
+ minY: l,
1716
+ maxX: c,
1717
+ maxY: l
1718
+ }), E = (L) => L.annotation.rects.reduce((R, U) => R + U.width * U.height, 0);
1719
+ return S.length > 0 ? (S.sort((L, R) => E(L) - E(R)), m ? S.map((L) => L.annotation.id) : [S[0].annotation.id]) : [];
1720
+ }, h = (c) => {
1721
+ const l = v(c);
1722
+ if (l.length === 0)
1718
1723
  return;
1719
- let y = c[0].left, S = c[0].top, E = c[0].right, C = c[0].bottom;
1720
- for (let R = 1; R < c.length; R++) {
1721
- const M = c[R];
1722
- y = Math.min(y, M.left), S = Math.min(S, M.top), E = Math.max(E, M.right), C = Math.max(C, M.bottom);
1724
+ let m = l[0].left, S = l[0].top, E = l[0].right, L = l[0].bottom;
1725
+ for (let R = 1; R < l.length; R++) {
1726
+ const U = l[R];
1727
+ m = Math.min(m, U.left), S = Math.min(S, U.top), E = Math.max(E, U.right), L = Math.max(L, U.bottom);
1723
1728
  }
1724
- return new DOMRect(y, S, E - y, C - S);
1725
- }, v = (d) => {
1726
- const c = o.get(d);
1727
- return c ? c[0].annotation.rects : [];
1729
+ return new DOMRect(m, S, E - m, L - S);
1730
+ }, v = (c) => {
1731
+ const l = o.get(c);
1732
+ return l ? l[0].annotation.rects : [];
1728
1733
  };
1729
1734
  return {
1730
1735
  all: s,
1731
1736
  clear: a,
1732
1737
  getAt: u,
1733
- getAnnotationBounds: p,
1738
+ getAnnotationBounds: h,
1734
1739
  getAnnotationRects: v,
1735
- getIntersecting: (d, c, y, S) => {
1736
- const E = n.search({ minX: d, minY: c, maxX: y, maxY: S }), C = new Set(E.map((R) => R.annotation.id));
1737
- return Array.from(C).map((R) => ({
1740
+ getIntersecting: (c, l, m, S) => {
1741
+ const E = n.search({ minX: c, minY: l, maxX: m, maxY: S }), L = new Set(E.map((R) => R.annotation.id));
1742
+ return Array.from(L).map((R) => ({
1738
1743
  annotation: t.getAnnotation(R),
1739
1744
  rects: v(R)
1740
1745
  })).filter((R) => !!R.annotation);
1741
1746
  },
1742
1747
  insert: r,
1743
- recalculate: () => h(t.all().map((d) => d.target), !0),
1744
- remove: l,
1745
- set: h,
1748
+ recalculate: () => g(t.all().map((c) => c.target), !0),
1749
+ remove: d,
1750
+ set: g,
1746
1751
  size: () => n.all().length,
1747
1752
  update: f
1748
1753
  };
1749
- }, eo = (t, e) => {
1750
- const n = Ln(), o = to(n, t), i = pn(n, e.userSelectAction, e.adapter), s = fn(n), a = Mn(), r = (d, c = k.LOCAL) => {
1751
- const y = Et(d, t), S = q(y.target.selector);
1752
- return S && n.addAnnotation(y, c), S;
1753
- }, l = (d, c = !0, y = k.LOCAL) => {
1754
- const S = d.map((C) => Et(C, t)), E = S.filter((C) => !q(C.target.selector));
1755
- return n.bulkAddAnnotations(S, c, y), E;
1756
- }, f = (d, c = k.LOCAL) => {
1757
- const y = d.map((E) => Et(E, t)), S = y.filter((E) => !q(E.target.selector));
1758
- return y.forEach((E) => {
1759
- n.getAnnotation(E.id) ? n.updateAnnotation(E, c) : n.addAnnotation(E, c);
1754
+ }, no = (t, e) => {
1755
+ const n = Tn(), o = eo(n, t), i = gn(n, e.userSelectAction, e.adapter), s = fn(n), a = kn(), r = (c, l = B.LOCAL) => {
1756
+ const m = St(c, t), S = q(m.target.selector);
1757
+ return S && n.addAnnotation(m, l), S;
1758
+ }, d = (c, l = !0, m = B.LOCAL) => {
1759
+ const S = c.map((L) => St(L, t)), E = S.filter((L) => !q(L.target.selector));
1760
+ return n.bulkAddAnnotations(S, l, m), E;
1761
+ }, f = (c, l = B.LOCAL) => {
1762
+ const m = c.map((E) => St(E, t)), S = m.filter((E) => !q(E.target.selector));
1763
+ return m.forEach((E) => {
1764
+ n.getAnnotation(E.id) ? n.updateAnnotation(E, l) : n.addAnnotation(E, l);
1760
1765
  }), S;
1761
- }, h = (d, c = k.LOCAL) => {
1762
- const y = At(d, t);
1763
- n.updateTarget(y, c);
1764
- }, u = (d, c = k.LOCAL) => {
1765
- const y = d.map((S) => At(S, t));
1766
- n.bulkUpdateTargets(y, c);
1766
+ }, g = (c, l = B.LOCAL) => {
1767
+ const m = At(c, t);
1768
+ n.updateTarget(m, l);
1769
+ }, u = (c, l = B.LOCAL) => {
1770
+ const m = c.map((S) => At(S, t));
1771
+ n.bulkUpdateTargets(m, l);
1767
1772
  };
1768
- function p(d, c, y, S) {
1769
- const E = y || !!S, C = o.getAt(d, c, E).map((M) => n.getAnnotation(M)), R = S ? C.filter(S) : C;
1773
+ function h(c, l, m, S) {
1774
+ const E = m || !!S, L = o.getAt(c, l, E).map((U) => n.getAnnotation(U)), R = S ? L.filter(S) : L;
1770
1775
  if (R.length !== 0)
1771
- return y ? R : R[0];
1776
+ return m ? R : R[0];
1772
1777
  }
1773
- const v = (d) => {
1774
- if (o.getAnnotationRects(d).length !== 0)
1775
- return o.getAnnotationBounds(d);
1776
- }, g = (d, c, y, S) => o.getIntersecting(d, c, y, S), m = (d) => o.getAnnotationRects(d), A = () => o.recalculate();
1777
- return n.observe(({ changes: d }) => {
1778
- const c = (d.deleted || []).filter((E) => q(E.target.selector)), y = (d.created || []).filter((E) => q(E.target.selector)), S = (d.updated || []).filter((E) => q(E.newValue.target.selector));
1779
- (c == null ? void 0 : c.length) > 0 && c.forEach((E) => o.remove(E.target)), y.length > 0 && o.set(y.map((E) => E.target), !1), (S == null ? void 0 : S.length) > 0 && S.forEach(({ newValue: E }) => o.update(E.target));
1778
+ const v = (c) => {
1779
+ if (o.getAnnotationRects(c).length !== 0)
1780
+ return o.getAnnotationBounds(c);
1781
+ }, b = (c, l, m, S) => o.getIntersecting(c, l, m, S), p = (c) => o.getAnnotationRects(c), x = () => o.recalculate();
1782
+ return n.observe(({ changes: c }) => {
1783
+ const l = (c.deleted || []).filter((E) => q(E.target.selector)), m = (c.created || []).filter((E) => q(E.target.selector)), S = (c.updated || []).filter((E) => q(E.newValue.target.selector));
1784
+ (l == null ? void 0 : l.length) > 0 && l.forEach((E) => o.remove(E.target)), m.length > 0 && o.set(m.map((E) => E.target), !1), (S == null ? void 0 : S.length) > 0 && S.forEach(({ newValue: E }) => o.update(E.target));
1780
1785
  }), {
1781
1786
  store: {
1782
1787
  ...n,
1783
1788
  addAnnotation: r,
1784
- bulkAddAnnotations: l,
1789
+ bulkAddAnnotations: d,
1785
1790
  bulkUpdateTargets: u,
1786
1791
  bulkUpsertAnnotations: f,
1787
1792
  getAnnotationBounds: v,
1788
- getAnnotationRects: m,
1789
- getIntersecting: g,
1790
- getAt: p,
1791
- recalculatePositions: A,
1792
- updateTarget: h
1793
+ getAnnotationRects: p,
1794
+ getIntersecting: b,
1795
+ getAt: h,
1796
+ recalculatePositions: x,
1797
+ updateTarget: g
1793
1798
  },
1794
1799
  selection: i,
1795
1800
  hover: s,
1796
1801
  viewport: a
1797
1802
  };
1798
- }, no = () => {
1803
+ }, oo = () => {
1799
1804
  const t = document.createElement("canvas");
1800
1805
  t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
1801
1806
  const e = t.getContext("2d");
1802
1807
  return e.scale(2, 2), e.translate(0.5, 0.5), t;
1803
- }, oo = (t, e = {}) => {
1804
- const n = no(), o = n.getContext("2d");
1808
+ }, io = (t, e = {}) => {
1809
+ const n = oo(), o = n.getContext("2d");
1805
1810
  document.body.appendChild(n);
1806
- const i = /* @__PURE__ */ new Map(), s = (h) => Array.from(i.entries()).filter(([u, p]) => p.presenceKey === h.presenceKey).map(([u, p]) => u);
1807
- return t.on("selectionChange", (h, u) => {
1808
- s(h).forEach((v) => i.delete(v)), u && u.forEach((v) => i.set(v, h));
1811
+ const i = /* @__PURE__ */ new Map(), s = (g) => Array.from(i.entries()).filter(([u, h]) => h.presenceKey === g.presenceKey).map(([u, h]) => u);
1812
+ return t.on("selectionChange", (g, u) => {
1813
+ s(g).forEach((v) => i.delete(v)), u && u.forEach((v) => i.set(v, g));
1809
1814
  }), {
1810
1815
  clear: () => {
1811
- const { width: h, height: u } = n;
1812
- o.clearRect(-0.5, -0.5, h + 1, u + 1);
1816
+ const { width: g, height: u } = n;
1817
+ o.clearRect(-0.5, -0.5, g + 1, u + 1);
1813
1818
  },
1814
1819
  destroy: () => {
1815
1820
  n.remove();
1816
1821
  },
1817
- paint: (h, u, p) => {
1822
+ paint: (g, u, h) => {
1818
1823
  e.font && (o.font = e.font);
1819
- const v = i.get(h.annotation.id);
1824
+ const v = i.get(g.annotation.id);
1820
1825
  if (v) {
1821
- const { height: g } = h.rects[0], m = h.rects[0].x + u.left, A = h.rects[0].y + u.top;
1822
- o.fillStyle = v.appearance.color, o.fillRect(m - 2, A - 2.5, 2, g + 5);
1823
- const d = o.measureText(v.appearance.label), c = d.width + 6, y = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, S = d.fontBoundingBoxAscent ? 8 : 6.5;
1824
- return o.fillRect(m - 2, A - 2.5 - y, c, y), o.fillStyle = "#fff", o.fillText(v.appearance.label, m + 1, A - S), {
1826
+ const { height: b } = g.rects[0], p = g.rects[0].x + u.left, x = g.rects[0].y + u.top;
1827
+ o.fillStyle = v.appearance.color, o.fillRect(p - 2, x - 2.5, 2, b + 5);
1828
+ const c = o.measureText(v.appearance.label), l = c.width + 6, m = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, S = c.fontBoundingBoxAscent ? 8 : 6.5;
1829
+ return o.fillRect(p - 2, x - 2.5 - m, l, m), o.fillStyle = "#fff", o.fillText(v.appearance.label, p + 1, x - S), {
1825
1830
  fill: v.appearance.color,
1826
- fillOpacity: p ? 0.45 : 0.18
1831
+ fillOpacity: h ? 0.45 : 0.18
1827
1832
  };
1828
1833
  }
1829
1834
  },
1830
1835
  reset: () => {
1831
1836
  n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
1832
- const h = n.getContext("2d");
1833
- h.scale(2, 2), h.translate(0.5, 0.5);
1837
+ const g = n.getContext("2d");
1838
+ g.scale(2, 2), g.translate(0.5, 0.5);
1834
1839
  }
1835
1840
  };
1836
- }, It = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1841
+ }, Ut = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1837
1842
  function _t(t, e, n, o) {
1838
1843
  t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
1839
1844
  }
1840
- function ot(t, e, n, o) {
1845
+ function st(t, e, n, o) {
1841
1846
  t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
1842
1847
  }
1843
1848
  function ye(t, e) {
@@ -1853,14 +1858,14 @@ function be(t) {
1853
1858
  e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
1854
1859
  return e;
1855
1860
  }
1856
- function io(t, e) {
1861
+ function so(t, e) {
1857
1862
  const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
1858
1863
  let i = !0;
1859
1864
  for (let s = 0; s < n.length; s++)
1860
1865
  o.indexOf(n[s]) === -1 && (i = !1);
1861
1866
  return i;
1862
1867
  }
1863
- const dt = {
1868
+ const ft = {
1864
1869
  backspace: 8,
1865
1870
  "⌫": 8,
1866
1871
  tab: 9,
@@ -1875,6 +1880,11 @@ const dt = {
1875
1880
  up: 38,
1876
1881
  right: 39,
1877
1882
  down: 40,
1883
+ /// https://w3c.github.io/uievents/#events-keyboard-key-location
1884
+ arrowup: 38,
1885
+ arrowdown: 40,
1886
+ arrowleft: 37,
1887
+ arrowright: 39,
1878
1888
  del: 46,
1879
1889
  delete: 46,
1880
1890
  ins: 45,
@@ -1905,10 +1915,12 @@ const dt = {
1905
1915
  ".": 190,
1906
1916
  "/": 191,
1907
1917
  "`": 192,
1908
- "-": It ? 173 : 189,
1909
- "=": It ? 61 : 187,
1910
- ";": It ? 59 : 186,
1918
+ "-": Ut ? 173 : 189,
1919
+ "=": Ut ? 61 : 187,
1920
+ ";": Ut ? 59 : 186,
1911
1921
  "'": 222,
1922
+ "{": 219,
1923
+ "}": 221,
1912
1924
  "[": 219,
1913
1925
  "]": 221,
1914
1926
  "\\": 220
@@ -1927,8 +1939,9 @@ const dt = {
1927
1939
  // metaKey
1928
1940
  "⌘": 91,
1929
1941
  cmd: 91,
1942
+ meta: 91,
1930
1943
  command: 91
1931
- }, at = {
1944
+ }, ct = {
1932
1945
  16: "shiftKey",
1933
1946
  18: "altKey",
1934
1947
  17: "ctrlKey",
@@ -1944,22 +1957,22 @@ const dt = {
1944
1957
  91: !1
1945
1958
  }, N = {};
1946
1959
  for (let t = 1; t < 20; t++)
1947
- dt["f".concat(t)] = 111 + t;
1948
- let U = [], lt = null, we = "all";
1949
- const W = /* @__PURE__ */ new Map(), ft = (t) => dt[t.toLowerCase()] || z[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), so = (t) => Object.keys(dt).find((e) => dt[e] === t), ro = (t) => Object.keys(z).find((e) => z[e] === t);
1950
- function Ae(t) {
1960
+ ft["f".concat(t)] = 111 + t;
1961
+ let _ = [], ut = null, we = "all";
1962
+ const W = /* @__PURE__ */ new Map(), ot = (t) => ft[t.toLowerCase()] || z[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), ro = (t) => Object.keys(ft).find((e) => ft[e] === t), ao = (t) => Object.keys(z).find((e) => z[e] === t);
1963
+ function xe(t) {
1951
1964
  we = t || "all";
1952
1965
  }
1953
- function ut() {
1966
+ function ht() {
1954
1967
  return we || "all";
1955
1968
  }
1956
- function ao() {
1957
- return U.slice(0);
1969
+ function lo() {
1970
+ return _.slice(0);
1958
1971
  }
1959
1972
  function co() {
1960
- return U.map((t) => so(t) || ro(t) || String.fromCharCode(t));
1973
+ return _.map((t) => ro(t) || ao(t) || String.fromCharCode(t));
1961
1974
  }
1962
- function lo() {
1975
+ function uo() {
1963
1976
  const t = [];
1964
1977
  return Object.keys(N).forEach((e) => {
1965
1978
  N[e].forEach((n) => {
@@ -1973,12 +1986,12 @@ function lo() {
1973
1986
  scope: i,
1974
1987
  shortcut: a,
1975
1988
  mods: s,
1976
- keys: o.split("+").map((r) => ft(r))
1989
+ keys: o.split("+").map((r) => ot(r))
1977
1990
  });
1978
1991
  });
1979
1992
  }), t;
1980
1993
  }
1981
- function uo(t) {
1994
+ function fo(t) {
1982
1995
  const e = t.target || t.srcElement, {
1983
1996
  tagName: n
1984
1997
  } = e;
@@ -1986,12 +1999,12 @@ function uo(t) {
1986
1999
  const i = n === "INPUT" && !["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes(e.type);
1987
2000
  return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = !1), o;
1988
2001
  }
1989
- function fo(t) {
1990
- return typeof t == "string" && (t = ft(t)), U.indexOf(t) !== -1;
2002
+ function ho(t) {
2003
+ return typeof t == "string" && (t = ot(t)), _.indexOf(t) !== -1;
1991
2004
  }
1992
- function ho(t, e) {
2005
+ function go(t, e) {
1993
2006
  let n, o;
1994
- t || (t = ut());
2007
+ t || (t = ht());
1995
2008
  for (const i in N)
1996
2009
  if (Object.prototype.hasOwnProperty.call(N, i))
1997
2010
  for (n = N[i], o = 0; o < n.length; )
@@ -1999,34 +2012,35 @@ function ho(t, e) {
1999
2012
  let {
2000
2013
  element: r
2001
2014
  } = a;
2002
- return Xt(r);
2015
+ return Pt(r);
2003
2016
  }) : o++;
2004
- ut() === t && Ae(e || "all");
2017
+ ht() === t && xe(e || "all");
2005
2018
  }
2006
2019
  function po(t) {
2007
2020
  let e = t.keyCode || t.which || t.charCode;
2008
- const n = U.indexOf(e);
2009
- if (n >= 0 && U.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && U.splice(0, U.length), (e === 93 || e === 224) && (e = 91), e in X) {
2021
+ t.key && t.key.toLowerCase() === "capslock" && (e = ot(t.key));
2022
+ const n = _.indexOf(e);
2023
+ if (n >= 0 && _.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && _.splice(0, _.length), (e === 93 || e === 224) && (e = 91), e in X) {
2010
2024
  X[e] = !1;
2011
2025
  for (const o in z) z[o] === e && (H[o] = !1);
2012
2026
  }
2013
2027
  }
2014
- function xe(t) {
2028
+ function Ae(t) {
2015
2029
  if (typeof t > "u")
2016
2030
  Object.keys(N).forEach((i) => {
2017
- Array.isArray(N[i]) && N[i].forEach((s) => wt(s)), delete N[i];
2018
- }), Xt(null);
2031
+ Array.isArray(N[i]) && N[i].forEach((s) => xt(s)), delete N[i];
2032
+ }), Pt(null);
2019
2033
  else if (Array.isArray(t))
2020
2034
  t.forEach((i) => {
2021
- i.key && wt(i);
2035
+ i.key && xt(i);
2022
2036
  });
2023
2037
  else if (typeof t == "object")
2024
- t.key && wt(t);
2038
+ t.key && xt(t);
2025
2039
  else if (typeof t == "string") {
2026
2040
  for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
2027
2041
  n[o - 1] = arguments[o];
2028
2042
  let [i, s] = n;
2029
- typeof i == "function" && (s = i, i = ""), wt({
2043
+ typeof i == "function" && (s = i, i = ""), xt({
2030
2044
  key: t,
2031
2045
  scope: i,
2032
2046
  method: s,
@@ -2034,7 +2048,7 @@ function xe(t) {
2034
2048
  });
2035
2049
  }
2036
2050
  }
2037
- const wt = (t) => {
2051
+ const xt = (t) => {
2038
2052
  let {
2039
2053
  key: e,
2040
2054
  scope: n,
@@ -2042,14 +2056,14 @@ const wt = (t) => {
2042
2056
  splitKey: i = "+"
2043
2057
  } = t;
2044
2058
  be(e).forEach((a) => {
2045
- const r = a.split(i), l = r.length, f = r[l - 1], h = f === "*" ? "*" : ft(f);
2046
- if (!N[h]) return;
2047
- n || (n = ut());
2048
- const u = l > 1 ? ye(z, r) : [], p = [];
2049
- N[h] = N[h].filter((v) => {
2050
- const m = (o ? v.method === o : !0) && v.scope === n && io(v.mods, u);
2051
- return m && p.push(v.element), !m;
2052
- }), p.forEach((v) => Xt(v));
2059
+ const r = a.split(i), d = r.length, f = r[d - 1], g = f === "*" ? "*" : ot(f);
2060
+ if (!N[g]) return;
2061
+ n || (n = ht());
2062
+ const u = d > 1 ? ye(z, r) : [], h = [];
2063
+ N[g] = N[g].filter((v) => {
2064
+ const p = (o ? v.method === o : !0) && v.scope === n && so(v.mods, u);
2065
+ return p && h.push(v.element), !p;
2066
+ }), h.forEach((v) => Pt(v));
2053
2067
  });
2054
2068
  };
2055
2069
  function ne(t, e, n, o) {
@@ -2060,29 +2074,29 @@ function ne(t, e, n, o) {
2060
2074
  i = e.mods.length > 0;
2061
2075
  for (const s in X)
2062
2076
  Object.prototype.hasOwnProperty.call(X, s) && (!X[s] && e.mods.indexOf(+s) > -1 || X[s] && e.mods.indexOf(+s) === -1) && (i = !1);
2063
- (e.mods.length === 0 && !X[16] && !X[18] && !X[17] && !X[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(U), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2077
+ (e.mods.length === 0 && !X[16] && !X[18] && !X[17] && !X[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(_), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2064
2078
  }
2065
2079
  }
2066
2080
  function oe(t, e) {
2067
2081
  const n = N["*"];
2068
2082
  let o = t.keyCode || t.which || t.charCode;
2069
- if (!H.filter.call(this, t)) return;
2070
- if ((o === 93 || o === 224) && (o = 91), U.indexOf(o) === -1 && o !== 229 && U.push(o), ["metaKey", "ctrlKey", "altKey", "shiftKey"].forEach((r) => {
2071
- const l = at[r];
2072
- t[r] && U.indexOf(l) === -1 ? U.push(l) : !t[r] && U.indexOf(l) > -1 ? U.splice(U.indexOf(l), 1) : r === "metaKey" && t[r] && (U = U.filter((f) => f in at || f === o));
2083
+ if (t.key && t.key.toLowerCase() === "capslock" || !H.filter.call(this, t)) return;
2084
+ if ((o === 93 || o === 224) && (o = 91), _.indexOf(o) === -1 && o !== 229 && _.push(o), ["metaKey", "ctrlKey", "altKey", "shiftKey"].forEach((r) => {
2085
+ const d = ct[r];
2086
+ t[r] && _.indexOf(d) === -1 ? _.push(d) : !t[r] && _.indexOf(d) > -1 ? _.splice(_.indexOf(d), 1) : r === "metaKey" && t[r] && (_ = _.filter((f) => f in ct || f === o));
2073
2087
  }), o in X) {
2074
2088
  X[o] = !0;
2075
2089
  for (const r in z)
2076
2090
  if (Object.prototype.hasOwnProperty.call(z, r)) {
2077
- const l = at[z[r]];
2078
- H[r] = t[l];
2091
+ const d = ct[z[r]];
2092
+ H[r] = t[d];
2079
2093
  }
2080
2094
  if (!n) return;
2081
2095
  }
2082
2096
  for (const r in X)
2083
- Object.prototype.hasOwnProperty.call(X, r) && (X[r] = t[at[r]]);
2084
- t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (U.indexOf(17) === -1 && U.push(17), U.indexOf(18) === -1 && U.push(18), X[17] = !0, X[18] = !0);
2085
- const i = ut();
2097
+ Object.prototype.hasOwnProperty.call(X, r) && (X[r] = t[ct[r]]);
2098
+ t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (_.indexOf(17) === -1 && _.push(17), _.indexOf(18) === -1 && _.push(18), X[17] = !0, X[18] = !0);
2099
+ const i = ht();
2086
2100
  if (n)
2087
2101
  for (let r = 0; r < n.length; r++)
2088
2102
  n[r].scope === i && (t.type === "keydown" && n[r].keydown || t.type === "keyup" && n[r].keyup) && ne(t, n[r], i, e);
@@ -2090,57 +2104,57 @@ function oe(t, e) {
2090
2104
  const s = N[o], a = s.length;
2091
2105
  for (let r = 0; r < a; r++)
2092
2106
  if ((t.type === "keydown" && s[r].keydown || t.type === "keyup" && s[r].keyup) && s[r].key) {
2093
- const l = s[r], {
2107
+ const d = s[r], {
2094
2108
  splitKey: f
2095
- } = l, h = l.key.split(f), u = [];
2096
- for (let p = 0; p < h.length; p++)
2097
- u.push(ft(h[p]));
2098
- u.sort().join("") === U.sort().join("") && ne(t, l, i, e);
2109
+ } = d, g = d.key.split(f), u = [];
2110
+ for (let h = 0; h < g.length; h++)
2111
+ u.push(ot(g[h]));
2112
+ u.sort().join("") === _.sort().join("") && ne(t, d, i, e);
2099
2113
  }
2100
2114
  }
2101
2115
  function H(t, e, n) {
2102
- U = [];
2116
+ _ = [];
2103
2117
  const o = be(t);
2104
- let i = [], s = "all", a = document, r = 0, l = !1, f = !0, h = "+", u = !1, p = !1;
2105
- 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++)
2106
- t = o[r].split(h), i = [], t.length > 1 && (i = ye(z, t)), t = t[t.length - 1], t = t === "*" ? "*" : ft(t), t in N || (N[t] = []), N[t].push({
2107
- keyup: l,
2118
+ let i = [], s = "all", a = document, r = 0, d = !1, f = !0, g = "+", u = !1, h = !1;
2119
+ 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" && (g = e.splitKey), e.single === !0 && (h = !0)), typeof e == "string" && (s = e), h && Ae(t, s); r < o.length; r++)
2120
+ t = o[r].split(g), i = [], t.length > 1 && (i = ye(z, t)), t = t[t.length - 1], t = t === "*" ? "*" : ot(t), t in N || (N[t] = []), N[t].push({
2121
+ keyup: d,
2108
2122
  keydown: f,
2109
2123
  scope: s,
2110
2124
  mods: i,
2111
2125
  shortcut: o[r],
2112
2126
  method: n,
2113
2127
  key: o[r],
2114
- splitKey: h,
2128
+ splitKey: g,
2115
2129
  element: a
2116
2130
  });
2117
2131
  if (typeof a < "u" && window) {
2118
2132
  if (!W.has(a)) {
2119
2133
  const v = function() {
2120
- let m = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2121
- return oe(m, a);
2122
- }, g = function() {
2123
- let m = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2124
- oe(m, a), po(m);
2134
+ let p = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2135
+ return oe(p, a);
2136
+ }, b = function() {
2137
+ let p = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2138
+ oe(p, a), po(p);
2125
2139
  };
2126
2140
  W.set(a, {
2127
2141
  keydownListener: v,
2128
- keyupListenr: g,
2142
+ keyupListenr: b,
2129
2143
  capture: u
2130
- }), _t(a, "keydown", v, u), _t(a, "keyup", g, u);
2144
+ }), _t(a, "keydown", v, u), _t(a, "keyup", b, u);
2131
2145
  }
2132
- if (!lt) {
2146
+ if (!ut) {
2133
2147
  const v = () => {
2134
- U = [];
2148
+ _ = [];
2135
2149
  };
2136
- lt = {
2150
+ ut = {
2137
2151
  listener: v,
2138
2152
  capture: u
2139
2153
  }, _t(window, "focus", v, u);
2140
2154
  }
2141
2155
  }
2142
2156
  }
2143
- function go(t) {
2157
+ function mo(t) {
2144
2158
  let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
2145
2159
  Object.keys(N).forEach((n) => {
2146
2160
  N[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
@@ -2148,7 +2162,7 @@ function go(t) {
2148
2162
  });
2149
2163
  });
2150
2164
  }
2151
- function Xt(t) {
2165
+ function Pt(t) {
2152
2166
  const e = Object.values(N).flat();
2153
2167
  if (e.findIndex((o) => {
2154
2168
  let {
@@ -2161,7 +2175,7 @@ function Xt(t) {
2161
2175
  keyupListenr: i,
2162
2176
  capture: s
2163
2177
  } = W.get(t) || {};
2164
- o && i && (ot(t, "keyup", i, s), ot(t, "keydown", o, s), W.delete(t));
2178
+ o && i && (st(t, "keyup", i, s), st(t, "keydown", o, s), W.delete(t));
2165
2179
  }
2166
2180
  if ((e.length <= 0 || W.size <= 0) && (Object.keys(W).forEach((i) => {
2167
2181
  const {
@@ -2169,222 +2183,254 @@ function Xt(t) {
2169
2183
  keyupListenr: a,
2170
2184
  capture: r
2171
2185
  } = W.get(i) || {};
2172
- s && a && (ot(i, "keyup", a, r), ot(i, "keydown", s, r), W.delete(i));
2173
- }), W.clear(), Object.keys(N).forEach((i) => delete N[i]), lt)) {
2186
+ s && a && (st(i, "keyup", a, r), st(i, "keydown", s, r), W.delete(i));
2187
+ }), W.clear(), Object.keys(N).forEach((i) => delete N[i]), ut)) {
2174
2188
  const {
2175
2189
  listener: i,
2176
2190
  capture: s
2177
- } = lt;
2178
- ot(window, "focus", i, s), lt = null;
2191
+ } = ut;
2192
+ st(window, "focus", i, s), ut = null;
2179
2193
  }
2180
2194
  }
2181
- const Ut = {
2195
+ const Nt = {
2182
2196
  getPressedKeyString: co,
2183
- setScope: Ae,
2184
- getScope: ut,
2185
- deleteScope: ho,
2186
- getPressedKeyCodes: ao,
2187
- getAllKeyCodes: lo,
2188
- isPressed: fo,
2189
- filter: uo,
2190
- trigger: go,
2191
- unbind: xe,
2192
- keyMap: dt,
2197
+ setScope: xe,
2198
+ getScope: ht,
2199
+ deleteScope: go,
2200
+ getPressedKeyCodes: lo,
2201
+ getAllKeyCodes: uo,
2202
+ isPressed: ho,
2203
+ filter: fo,
2204
+ trigger: mo,
2205
+ unbind: Ae,
2206
+ keyMap: ft,
2193
2207
  modifier: z,
2194
- modifierMap: at
2208
+ modifierMap: ct
2195
2209
  };
2196
- for (const t in Ut)
2197
- Object.prototype.hasOwnProperty.call(Ut, t) && (H[t] = Ut[t]);
2210
+ for (const t in Nt)
2211
+ Object.prototype.hasOwnProperty.call(Nt, t) && (H[t] = Nt[t]);
2198
2212
  if (typeof window < "u") {
2199
2213
  const t = window.hotkeys;
2200
2214
  H.noConflict = (e) => (e && window.hotkeys === H && (window.hotkeys = t), H), window.hotkeys = H;
2201
2215
  }
2202
- const ie = 300, ve = ["up", "down", "left", "right"], Ee = Te ? "⌘+a" : "ctrl+a", mo = [
2216
+ const ie = 300, ve = ["up", "down", "left", "right"], Ee = Te ? "⌘+a" : "ctrl+a", yo = [
2203
2217
  ...ve.map((t) => `shift+${t}`),
2204
2218
  Ee
2205
- ], yo = (t, e, n) => {
2219
+ ], bo = (t, e, n) => {
2206
2220
  let o;
2207
2221
  const { annotatingEnabled: i, offsetReferenceSelector: s, selectionMode: a } = n, r = (T) => o = T;
2208
- let l;
2209
- const f = (T) => l = T, { store: h, selection: u } = e;
2210
- let p, v, g;
2211
- const m = (T) => {
2212
- v !== !1 && (p = it(T.target) ? void 0 : {
2213
- annotation: fe(),
2214
- selector: [],
2215
- creator: o,
2216
- created: /* @__PURE__ */ new Date()
2217
- });
2218
- }, A = Dt((T) => {
2219
- const I = document.getSelection();
2220
- if (!(I != null && I.anchorNode))
2222
+ let d;
2223
+ const f = (T) => d = T, { store: g, selection: u } = e;
2224
+ let h, v, b;
2225
+ const p = (T) => {
2226
+ const M = T;
2227
+ return M.ctrlKey || M.metaKey;
2228
+ }, x = (T) => {
2229
+ if (v !== !1)
2230
+ if (rt(T.target))
2231
+ h = void 0;
2232
+ else {
2233
+ const { selected: M } = u;
2234
+ if (p({ ...T, ...b }) && M.length === 1 && M[0].editable) {
2235
+ const y = g.getAnnotation(M[0].id);
2236
+ h = {
2237
+ previous: {
2238
+ ...y.target
2239
+ },
2240
+ next: {
2241
+ annotation: y.id,
2242
+ selector: [],
2243
+ created: y.target.created,
2244
+ creator: y.target.creator,
2245
+ updated: /* @__PURE__ */ new Date(),
2246
+ updatedBy: o
2247
+ }
2248
+ };
2249
+ } else
2250
+ h = {
2251
+ next: {
2252
+ annotation: fe(),
2253
+ selector: [],
2254
+ created: /* @__PURE__ */ new Date(),
2255
+ creator: o
2256
+ }
2257
+ };
2258
+ }
2259
+ }, c = Kt((T) => {
2260
+ const M = document.getSelection();
2261
+ if (!(M != null && M.anchorNode))
2221
2262
  return;
2222
- if (it(I.anchorNode)) {
2223
- p = void 0;
2263
+ if (rt(M.anchorNode)) {
2264
+ h = void 0;
2224
2265
  return;
2225
2266
  }
2226
- const D = T.timeStamp - ((g == null ? void 0 : g.timeStamp) || T.timeStamp);
2227
- if ((g == null ? void 0 : g.type) === "pointerdown" && (D < 1e3 && !p || I.isCollapsed && D < ie) && m(g || T), !p) return;
2228
- if (I.isCollapsed) {
2229
- h.getAnnotation(p.annotation) && (u.clear(), h.deleteAnnotation(p.annotation));
2267
+ const y = T.timeStamp - ((b == null ? void 0 : b.timeStamp) || T.timeStamp);
2268
+ if ((b == null ? void 0 : b.type) === "pointerdown" && (y < 1e3 && !h || M.isCollapsed && y < ie) && x(b || T), !h) return;
2269
+ if (M.isCollapsed) {
2270
+ g.getAnnotation(h.next.annotation) && !p(b) && (u.clear(), g.deleteAnnotation(h.next.annotation));
2230
2271
  return;
2231
2272
  }
2232
- const b = I.getRangeAt(0), x = De(b, t);
2233
- if (Ie(x)) return;
2234
- const w = Me(x.cloneRange());
2235
- (w.length !== p.selector.length || w.some((B, O) => {
2236
- var _;
2237
- return B.toString() !== ((_ = p.selector[O]) == null ? void 0 : _.quote);
2238
- })) && (p = {
2239
- ...p,
2240
- selector: w.map((B) => Ve(B, t, s)),
2241
- updated: /* @__PURE__ */ new Date()
2242
- }, h.getAnnotation(p.annotation) ? h.updateTarget(p, k.LOCAL) : u.clear());
2243
- }), d = (T) => {
2244
- it(T.target) || (g = vt(T), v = g.button === 0);
2245
- }, c = (T) => {
2246
- if (it(T.target) || !v) return;
2247
- const I = () => {
2248
- const { x: b, y: x } = t.getBoundingClientRect(), w = T.target instanceof Node && t.contains(T.target) && h.getAt(T.clientX - b, T.clientY - x, a === "all", l);
2249
- if (w) {
2250
- const { selected: L } = u, B = new Set(L.map((P) => P.id)), O = Array.isArray(w) ? w.map((P) => P.id) : [w.id];
2251
- (B.size !== O.length || !O.every((P) => B.has(P))) && u.userSelect(O, T);
2252
- } else
2253
- u.clear();
2254
- }, D = T.timeStamp - g.timeStamp;
2273
+ const A = Array.from(Array(M.rangeCount).keys()).map((O) => M.getRangeAt(O)).map((O) => De(O, t));
2274
+ if (A.every((O) => Ie(O))) return;
2275
+ const C = A.flatMap((O) => Me(O.cloneRange()));
2276
+ (C.length !== h.next.selector.length || C.some((O, k) => {
2277
+ var P;
2278
+ return O.toString() !== ((P = h.next.selector[k]) == null ? void 0 : P.quote);
2279
+ })) && (h = {
2280
+ ...h,
2281
+ next: {
2282
+ ...h.next,
2283
+ selector: [
2284
+ ...h.previous ? h.previous.selector : [],
2285
+ ...C.map((O) => Ve(O, t, s))
2286
+ ],
2287
+ updated: /* @__PURE__ */ new Date()
2288
+ }
2289
+ }, g.getAnnotation(h.next.annotation) ? g.updateTarget(h.next, B.LOCAL) : p(b) || u.clear());
2290
+ }), l = (T) => {
2291
+ rt(T.target) || (b = Et(T), v = b.button === 0);
2292
+ }, m = (T) => {
2293
+ if (rt(T.target) || !v) return;
2294
+ const M = () => {
2295
+ const { x: w, y: A } = t.getBoundingClientRect(), C = T.target instanceof Node && t.contains(T.target) && g.getAt(T.clientX - w, T.clientY - A, a === "all", d);
2296
+ if (C) {
2297
+ const { selected: I } = u, O = new Set(I.map((Q) => Q.id)), k = Array.isArray(C) ? C.map((Q) => Q.id) : [C.id];
2298
+ (O.size !== k.length || !k.every((Q) => O.has(Q))) && u.userSelect(k, T);
2299
+ } else p(T) || u.clear();
2300
+ }, y = T.timeStamp - b.timeStamp;
2255
2301
  setTimeout(() => {
2256
- const b = document.getSelection();
2257
- b != null && b.isCollapsed && D < ie ? (p = void 0, I()) : p && p.selector.length > 0 && (R(), u.userSelect(p.annotation, vt(T)));
2302
+ const w = document.getSelection();
2303
+ w != null && w.isCollapsed && y < ie ? (h = void 0, M()) : h && h.next.selector.length > 0 && (U(), u.userSelect(h.next.annotation, Et(T)));
2258
2304
  });
2259
- }, y = (T) => {
2260
- const I = document.getSelection();
2261
- I != null && I.isCollapsed || ((!p || p.selector.length === 0) && A(T), p && (R(), u.userSelect(p.annotation, vt(T))));
2262
2305
  }, S = (T) => {
2263
- T.key === "Shift" && p && (document.getSelection().isCollapsed || (R(), u.userSelect(p.annotation, ht(T))));
2306
+ const M = document.getSelection();
2307
+ M != null && M.isCollapsed || ((!h || h.next.selector.length === 0) && c(T), h && (U(), u.userSelect(h.next.annotation, Et(T))));
2264
2308
  }, E = (T) => {
2265
- const I = () => setTimeout(() => {
2266
- (p == null ? void 0 : p.selector.length) > 0 && (u.clear(), h.addAnnotation({
2267
- id: p.annotation,
2309
+ T.key === "Shift" && h && (document.getSelection().isCollapsed || (U(), u.userSelect(h.next.annotation, gt(T))));
2310
+ }, L = (T) => {
2311
+ const M = () => setTimeout(() => {
2312
+ (h == null ? void 0 : h.next.selector.length) > 0 && (u.clear(), g.addAnnotation({
2313
+ id: h.next.annotation,
2268
2314
  bodies: [],
2269
- target: p
2270
- }), u.userSelect(p.annotation, ht(T))), document.removeEventListener("selectionchange", I);
2315
+ target: h.next
2316
+ }), u.userSelect(h.next.annotation, gt(T))), document.removeEventListener("selectionchange", M);
2271
2317
  }, 100);
2272
- document.addEventListener("selectionchange", I), m(T);
2318
+ document.addEventListener("selectionchange", M), x(T);
2273
2319
  };
2274
- H(mo.join(","), { element: t, keydown: !0, keyup: !1 }, (T) => {
2275
- T.repeat || (g = ht(T));
2320
+ H(yo.join(","), { element: t, keydown: !0, keyup: !1 }, (T) => {
2321
+ T.repeat || (b = gt(T));
2276
2322
  }), H(Ee, { keydown: !0, keyup: !1 }, (T) => {
2277
- g = ht(T), E(T);
2323
+ b = gt(T), L(T);
2278
2324
  });
2279
- const C = (T) => {
2280
- T.repeat || T.target !== t && T.target !== document.body || (p = void 0, u.clear());
2325
+ const R = (T) => {
2326
+ T.repeat || T.target !== t && T.target !== document.body || (h = void 0, u.clear());
2281
2327
  };
2282
- H(ve.join(","), { keydown: !0, keyup: !1 }, C);
2283
- const R = () => {
2284
- const T = h.getAnnotation(p.annotation);
2328
+ H(ve.join(","), { keydown: !0, keyup: !1 }, R);
2329
+ const U = () => {
2330
+ const T = g.getAnnotation(h.next.annotation);
2285
2331
  if (!T) {
2286
- h.addAnnotation({
2287
- id: p.annotation,
2332
+ g.addAnnotation({
2333
+ id: h.next.annotation,
2288
2334
  bodies: [],
2289
- target: p
2335
+ target: h.next
2290
2336
  });
2291
2337
  return;
2292
2338
  }
2293
- const { target: { updated: I } } = T, { updated: D } = p;
2294
- (!I || !D || I < D) && h.updateTarget(p);
2339
+ const { target: { updated: M } } = T, { updated: y } = h.next;
2340
+ (!M || !y || M < y) && g.updateTarget(h.next);
2295
2341
  };
2296
- return t.addEventListener("pointerdown", d), document.addEventListener("pointerup", c), document.addEventListener("contextmenu", y), i && (t.addEventListener("keyup", S), t.addEventListener("selectstart", m), document.addEventListener("selectionchange", A)), {
2342
+ return t.addEventListener("pointerdown", l), document.addEventListener("pointerup", m), document.addEventListener("contextmenu", S), i && (t.addEventListener("keyup", E), t.addEventListener("selectstart", x), document.addEventListener("selectionchange", c)), {
2297
2343
  destroy: () => {
2298
- t.removeEventListener("pointerdown", d), document.removeEventListener("pointerup", c), document.removeEventListener("contextmenu", y), t.removeEventListener("keyup", S), t.removeEventListener("selectstart", m), document.removeEventListener("selectionchange", A), H.unbind();
2344
+ t.removeEventListener("pointerdown", l), document.removeEventListener("pointerup", m), document.removeEventListener("contextmenu", S), t.removeEventListener("keyup", E), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", c), H.unbind();
2299
2345
  },
2300
2346
  setFilter: f,
2301
2347
  setUser: r
2302
2348
  };
2303
- }, bo = (t, e) => ({
2349
+ }, wo = (t, e) => ({
2304
2350
  ...t,
2305
2351
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
2306
2352
  user: t.user || e.user
2307
- }), se = "SPANS", vo = (t, e = {}) => {
2353
+ }), se = "SPANS", Eo = (t, e = {}) => {
2308
2354
  Le(t), Oe(t);
2309
- const n = bo(e, {
2355
+ const n = wo(e, {
2310
2356
  annotatingEnabled: !0,
2311
2357
  user: Yn()
2312
- }), o = eo(t, n), { selection: i, viewport: s } = o, a = o.store, r = Rn(a), l = Bn(o, r, n.adapter);
2358
+ }), o = no(t, n), { selection: i, viewport: s } = o, a = o.store, r = Mn(a), d = Bn(o, r, n.adapter);
2313
2359
  let f = n.user;
2314
- 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;
2360
+ const g = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : se : n.renderer || se, u = g === "SPANS" ? rn(t, o, s) : g === "CSS_HIGHLIGHTS" ? nn(t, o, s) : g === "CANVAS" ? ze(t, o, s) : void 0;
2315
2361
  if (!u)
2316
- throw `Unknown renderer implementation: ${h}`;
2317
- console.debug(`Using ${h} renderer`), n.style && u.setStyle(n.style);
2318
- const p = yo(t, o, n);
2319
- return p.setUser(f), {
2320
- ...In(o, r, n.adapter),
2362
+ throw `Unknown renderer implementation: ${g}`;
2363
+ console.debug(`Using ${g} renderer`), n.style && u.setStyle(n.style);
2364
+ const h = bo(t, o, n);
2365
+ return h.setUser(f), {
2366
+ ...Un(o, r, n.adapter),
2321
2367
  destroy: () => {
2322
- u.destroy(), p.destroy(), r.destroy();
2368
+ u.destroy(), h.destroy(), r.destroy();
2323
2369
  },
2324
2370
  element: t,
2325
2371
  getUser: () => f,
2326
- setFilter: (C) => {
2327
- u.setFilter(C), p.setFilter(C);
2372
+ setFilter: (L) => {
2373
+ u.setFilter(L), h.setFilter(L);
2328
2374
  },
2329
- setStyle: (C) => u.setStyle(C),
2330
- setUser: (C) => {
2331
- f = C, p.setUser(C);
2375
+ setStyle: (L) => u.setStyle(L),
2376
+ setUser: (L) => {
2377
+ f = L, h.setUser(L);
2332
2378
  },
2333
- setSelected: (C) => {
2334
- C ? i.setSelected(C) : i.clear();
2379
+ setSelected: (L) => {
2380
+ L ? i.setSelected(L) : i.clear();
2335
2381
  },
2336
- setPresenceProvider: (C) => {
2337
- C && (u.setPainter(oo(C, n.presence)), C.on("selectionChange", () => u.redraw()));
2382
+ setPresenceProvider: (L) => {
2383
+ L && (u.setPainter(io(L, n.presence)), L.on("selectionChange", () => u.redraw()));
2338
2384
  },
2339
- setVisible: (C) => u.setVisible(C),
2340
- on: l.on,
2341
- off: l.off,
2342
- scrollIntoView: Ye(t, a),
2385
+ setVisible: (L) => u.setVisible(L),
2386
+ on: d.on,
2387
+ off: d.off,
2388
+ scrollIntoView: Ke(t, a),
2343
2389
  state: o
2344
2390
  };
2345
2391
  };
2346
2392
  export {
2347
- xt as DEFAULT_SELECTED_STYLE,
2393
+ vt as DEFAULT_SELECTED_STYLE,
2348
2394
  G as DEFAULT_STYLE,
2349
2395
  re as NOT_ANNOTATABLE_CLASS,
2350
- et as NOT_ANNOTATABLE_SELECTOR,
2351
- k as Origin,
2352
- yo as SelectionHandler,
2396
+ nt as NOT_ANNOTATABLE_SELECTOR,
2397
+ B as Origin,
2398
+ bo as SelectionHandler,
2353
2399
  hn as UserSelectAction,
2354
- xo as W3CTextFormat,
2400
+ vo as W3CTextFormat,
2355
2401
  Le as cancelSingleClickEvents,
2356
- ht as cloneKeyboardEvent,
2357
- vt as clonePointerEvent,
2402
+ gt as cloneKeyboardEvent,
2403
+ Et as clonePointerEvent,
2358
2404
  Ao as createBody,
2359
2405
  ze as createCanvasRenderer,
2360
2406
  nn as createHighlightsRenderer,
2361
- oo as createPresencePainter,
2407
+ io as createPresencePainter,
2362
2408
  en as createRenderer,
2363
2409
  rn as createSpansRenderer,
2364
- vo as createTextAnnotator,
2365
- eo as createTextAnnotatorState,
2366
- Dt as debounce,
2367
- bo as fillDefaults,
2368
- Be as getQuoteContext,
2369
- Nt as getRangeAnnotatableContents,
2410
+ Eo as createTextAnnotator,
2411
+ no as createTextAnnotatorState,
2412
+ Kt as debounce,
2413
+ wo as fillDefaults,
2414
+ ke as getQuoteContext,
2415
+ Vt as getRangeAnnotatableContents,
2370
2416
  Te as isMac,
2371
- it as isNotAnnotatable,
2417
+ rt as isNotAnnotatable,
2372
2418
  Ce as isRangeAnnotatable,
2373
2419
  q as isRevived,
2374
2420
  Ie as isWhitespaceOrEmpty,
2375
2421
  Ne as mergeClientRects,
2376
- Ke as paint,
2377
- jn as parseW3CTextAnnotation,
2422
+ Ye as paint,
2423
+ zn as parseW3CTextAnnotation,
2378
2424
  Oe as programmaticallyFocusable,
2379
2425
  Ve as rangeToSelector,
2380
- Et as reviveAnnotation,
2426
+ St as reviveAnnotation,
2381
2427
  ae as reviveSelector,
2382
2428
  At as reviveTarget,
2383
- Ye as scrollIntoView,
2384
- zn as serializeW3CTextAnnotation,
2429
+ Ke as scrollIntoView,
2430
+ Fn as serializeW3CTextAnnotation,
2385
2431
  Me as splitAnnotatableRanges,
2386
- wo as toDomRectList,
2432
+ xo as toDomRectList,
2387
2433
  De as trimRangeToContainer,
2388
- ke as whitespaceOrEmptyRegex
2434
+ Be as whitespaceOrEmptyRegex
2389
2435
  };
2390
2436
  //# sourceMappingURL=text-annotator.es.js.map