@recogito/text-annotator 3.0.0-rc.43 → 3.0.0-rc.44

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