@recogito/text-annotator 3.0.0-rc.53 → 3.0.0-rc.55

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