@recogito/text-annotator 3.0.0-rc.40 → 3.0.0-rc.42

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