@recogito/text-annotator 3.0.0-rc.31 → 3.0.0-rc.33

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.
@@ -5,8 +5,8 @@ const P = {
5
5
  fill: "rgb(0, 128, 255)",
6
6
  fillOpacity: 0.45
7
7
  }, Kt = (t, e, n, o, i) => {
8
- var a, s;
9
- const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? ot : P) : n : (s = t.state) != null && s.selected ? ot : P;
8
+ var c, s;
9
+ const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((c = t.state) != null && c.selected ? ot : P) : n : (s = t.state) != null && s.selected ? ot : P;
10
10
  return o && o.paint(t, e) || r;
11
11
  }, Yt = "not-annotatable", D = `.${Yt}`, Qt = (t) => {
12
12
  var n;
@@ -71,31 +71,31 @@ const P = {
71
71
  startOffset: o,
72
72
  endContainer: i,
73
73
  endOffset: r
74
- } = t, a = Array.from(e.childNodes).map((l) => {
75
- const p = l.cloneNode(!0);
76
- return l.nodeName === "CANVAS" ? l : p;
77
- }), s = wt(n, e), u = wt(i, e), f = () => {
74
+ } = t, c = Array.from(e.childNodes).map((l) => {
75
+ const g = l.cloneNode(!0);
76
+ return l.nodeName === "CANVAS" ? l : g;
77
+ }), s = wt(n, e), u = wt(i, e), h = () => {
78
78
  const l = e;
79
- l.replaceChildren(...a);
80
- const p = xt(s, l), g = xt(u, l);
81
- return t.setStart(p, o), t.setEnd(g, r), t;
79
+ l.replaceChildren(...c);
80
+ const g = xt(s, l), f = xt(u, l);
81
+ return t.setStart(g, o), t.setEnd(f, r), t;
82
82
  }, m = (l) => {
83
- const p = document.createElement("SPAN");
84
- return l.surroundContents(p), p;
83
+ const g = document.createElement("SPAN");
84
+ return l.surroundContents(g), g;
85
85
  };
86
86
  if (n === i)
87
87
  throw "Not implemented";
88
88
  {
89
89
  const l = document.createRange();
90
90
  l.selectNodeContents(n), l.setStart(n, o);
91
- const p = m(l), g = document.createRange();
92
- g.selectNode(i), g.setEnd(i, r);
93
- const w = m(g), h = ne(t).reverse().map((d) => {
91
+ const g = m(l), f = document.createRange();
92
+ f.selectNode(i), f.setEnd(i, r);
93
+ const x = m(f), p = ne(t).reverse().map((d) => {
94
94
  var y;
95
- const c = document.createElement("SPAN");
96
- return (y = d.parentNode) == null || y.insertBefore(c, d), c.appendChild(d), c;
95
+ const a = document.createElement("SPAN");
96
+ return (y = d.parentNode) == null || y.insertBefore(a, d), a.appendChild(d), a;
97
97
  });
98
- return { unwrap: f, nodes: [p, ...h, w] };
98
+ return { unwrap: h, nodes: [g, ...p, x] };
99
99
  }
100
100
  }, ne = (t) => {
101
101
  const {
@@ -103,27 +103,27 @@ const P = {
103
103
  startContainer: n,
104
104
  endContainer: o
105
105
  } = t, i = document.createNodeIterator(e, NodeFilter.SHOW_TEXT);
106
- let r = i.nextNode(), a = !1;
106
+ let r = i.nextNode(), c = !1;
107
107
  const s = [];
108
108
  for (; r != null; )
109
- r === o && (a = !1), a && s.push(r), r === n && (a = !0), r = i.nextNode();
109
+ r === o && (c = !1), c && s.push(r), r === n && (c = !0), r = i.nextNode();
110
110
  return s;
111
111
  }, In = (t) => {
112
112
  const { startContainer: e, endContainer: n } = t;
113
113
  if (e === n)
114
114
  return Array.from(t.getClientRects());
115
115
  {
116
- const { unwrap: o, nodes: i } = ee(t), r = i.reduce((a, s) => [...a, ...s.getClientRects()], []);
116
+ const { unwrap: o, nodes: i } = ee(t), r = i.reduce((c, s) => [...c, ...s.getClientRects()], []);
117
117
  return o(), r;
118
118
  }
119
119
  }, oe = (t, e, n = 10, o) => {
120
120
  const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
121
121
  r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
122
- const a = pt(r).textContent, s = document.createRange();
122
+ const c = pt(r).textContent, s = document.createRange();
123
123
  s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
124
124
  const u = pt(s).textContent;
125
125
  return {
126
- prefix: a.substring(a.length - n),
126
+ prefix: c.substring(c.length - n),
127
127
  suffix: u.substring(0, n)
128
128
  };
129
129
  }, ie = /^\s*$/, re = (t) => ie.test(t.toString()), $ = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), se = (t, e) => {
@@ -158,17 +158,17 @@ const P = {
158
158
  return e;
159
159
  let o = [...e], i = !1;
160
160
  for (const r of e) {
161
- const a = se(n, r);
162
- if (a === "inline-adjacent") {
161
+ const c = se(n, r);
162
+ if (c === "inline-adjacent") {
163
163
  o = o.map((s) => s === r ? ae(n, r) : s), i = !0;
164
164
  break;
165
- } else if (a === "inline-contains") {
165
+ } else if (c === "inline-contains") {
166
166
  o = o.map((s) => s === r ? n : s), i = !0;
167
167
  break;
168
- } else if (a === "inline-is-contained") {
168
+ } else if (c === "inline-is-contained") {
169
169
  i = !0;
170
170
  break;
171
- } else if (a === "block-contains" || a === "block-is-contained") {
171
+ } else if (c === "block-contains" || c === "block-is-contained") {
172
172
  n.width < r.width && (o = o.map((s) => s === r ? n : s)), i = !0;
173
173
  break;
174
174
  }
@@ -177,41 +177,41 @@ const P = {
177
177
  }, []), le = (t, e, n) => {
178
178
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
179
179
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
180
- const r = pt(o).textContent, a = t.toString(), s = r.length || 0, u = s + a.length;
181
- return n ? { quote: a, start: s, end: u, range: t, offsetReference: i } : { quote: a, start: s, end: u, range: t };
180
+ const r = pt(o).textContent, c = t.toString(), s = r.length || 0, u = s + c.length;
181
+ return n ? { quote: c, start: s, end: u, range: t, offsetReference: i } : { quote: c, start: s, end: u, range: t };
182
182
  }, Dt = (t, e) => {
183
183
  var m, l;
184
184
  const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
185
185
  e,
186
186
  NodeFilter.SHOW_TEXT,
187
- (p) => {
188
- var g;
189
- return (g = p.parentElement) != null && g.closest(D) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
187
+ (g) => {
188
+ var f;
189
+ return (f = g.parentElement) != null && f.closest(D) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
190
190
  }
191
191
  );
192
- let a = 0;
192
+ let c = 0;
193
193
  const s = document.createRange();
194
194
  let u = r.nextNode();
195
195
  u === null && console.error("Could not revive annotation target. Content missing.");
196
- let f = !i;
196
+ let h = !i;
197
197
  for (; u !== null; ) {
198
- if (f || (f = i == null ? void 0 : i.contains(u)), f) {
199
- const p = ((m = u.textContent) == null ? void 0 : m.length) || 0;
200
- if (a + p > n) {
201
- s.setStart(u, n - a);
198
+ if (h || (h = i == null ? void 0 : i.contains(u)), h) {
199
+ const g = ((m = u.textContent) == null ? void 0 : m.length) || 0;
200
+ if (c + g > n) {
201
+ s.setStart(u, n - c);
202
202
  break;
203
203
  }
204
- a += p;
204
+ c += g;
205
205
  }
206
206
  u = r.nextNode();
207
207
  }
208
208
  for (; u !== null; ) {
209
- const p = ((l = u.textContent) == null ? void 0 : l.length) || 0;
210
- if (a + p >= o) {
211
- s.setEnd(u, o - a);
209
+ const g = ((l = u.textContent) == null ? void 0 : l.length) || 0;
210
+ if (c + g >= o) {
211
+ s.setEnd(u, o - c);
212
212
  break;
213
213
  }
214
- a += p, u = r.nextNode();
214
+ c += g, u = r.nextNode();
215
215
  }
216
216
  return {
217
217
  ...t,
@@ -221,8 +221,8 @@ const P = {
221
221
  ...t,
222
222
  selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : Dt(n, e))
223
223
  }, rt = (t, e) => $(t.target.selector) ? t : { ...t, target: it(t.target, e) }, de = (t) => {
224
- const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, u = i - e;
225
- return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: u };
224
+ const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, c = -e, s = o - n, u = i - e;
225
+ return { top: e, left: n, minX: r, minY: c, maxX: s, maxY: u };
226
226
  }, ue = (t) => {
227
227
  let e = /* @__PURE__ */ new Set();
228
228
  return (o) => {
@@ -230,47 +230,47 @@ const P = {
230
230
  (e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
231
231
  };
232
232
  }, vt = (t, e, n, o) => {
233
- const { store: i, selection: r, hover: a } = e;
234
- let s, u, f;
235
- const m = ue(n), l = (T) => {
236
- const { x: O, y: b } = t.getBoundingClientRect(), x = i.getAt(T.clientX - O, T.clientY - b);
237
- x && (!u || u(x)) ? a.current !== x.id && (t.classList.add("hovered"), a.set(x.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
233
+ const { store: i, selection: r, hover: c } = e;
234
+ let s, u, h;
235
+ const m = ue(n), l = (B) => {
236
+ const { x: M, y: b } = t.getBoundingClientRect(), w = i.getAt(B.clientX - M, B.clientY - b);
237
+ w && (!u || u(w)) ? c.current !== w.id && (t.classList.add("hovered"), c.set(w.id)) : c.current && (t.classList.remove("hovered"), c.set(null));
238
238
  };
239
239
  t.addEventListener("pointermove", l);
240
- const p = (T = !1) => {
241
- f && f.clear();
242
- const O = de(t), { minX: b, minY: x, maxX: A, maxY: S } = O, R = u ? i.getIntersecting(b, x, A, S).filter(({ annotation: _ }) => u(_)) : i.getIntersecting(b, x, A, S), M = r.selected.map(({ id: _ }) => _), H = R.map(({ annotation: _, rects: qt }) => {
243
- const jt = M.includes(_.id), Gt = _.id === a.current;
240
+ const g = (B = !1) => {
241
+ h && h.clear();
242
+ const M = de(t), { minX: b, minY: w, maxX: A, maxY: C } = M, R = u ? i.getIntersecting(b, w, A, C).filter(({ annotation: _ }) => u(_)) : i.getIntersecting(b, w, A, C), O = r.selected.map(({ id: _ }) => _), H = R.map(({ annotation: _, rects: qt }) => {
243
+ const jt = O.includes(_.id), Gt = _.id === c.current;
244
244
  return { annotation: _, rects: qt, state: { selected: jt, hover: Gt } };
245
245
  });
246
- o.redraw(H, O, s, f, T), setTimeout(() => m(R.map(({ annotation: _ }) => _)), 1);
247
- }, g = (T) => {
248
- f = T, p();
249
- }, w = (T) => {
250
- s = T, p();
251
- }, v = (T) => {
252
- u = T, p(!1);
253
- }, h = () => p();
254
- i.observe(h);
255
- const d = r.subscribe(() => p()), c = () => p(!0);
256
- document.addEventListener("scroll", c, { capture: !0, passive: !0 });
246
+ o.redraw(H, M, s, h, B), setTimeout(() => m(R.map(({ annotation: _ }) => _)), 1);
247
+ }, f = (B) => {
248
+ h = B, g();
249
+ }, x = (B) => {
250
+ s = B, g();
251
+ }, v = (B) => {
252
+ u = B, g(!1);
253
+ }, p = () => g();
254
+ i.observe(p);
255
+ const d = r.subscribe(() => g()), a = () => g(!0);
256
+ document.addEventListener("scroll", a, { capture: !0, passive: !0 });
257
257
  const y = bt(() => {
258
- i.recalculatePositions(), f && f.reset(), p();
258
+ i.recalculatePositions(), h && h.reset(), g();
259
259
  });
260
260
  window.addEventListener("resize", y);
261
- const C = new ResizeObserver(y);
262
- C.observe(t);
263
- const L = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((T) => {
264
- T.every((b) => b.target === t || t.contains(b.target)) || p(!0);
261
+ const S = new ResizeObserver(y);
262
+ S.observe(t);
263
+ const L = { attributes: !0, childList: !0, subtree: !0 }, E = new MutationObserver((B) => {
264
+ B.every((b) => b.target === t || t.contains(b.target)) || g(!0);
265
265
  });
266
266
  return E.observe(document.body, L), {
267
267
  destroy: () => {
268
- t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", c), window.removeEventListener("resize", y), C.disconnect(), E.disconnect();
268
+ t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(p), d(), document.removeEventListener("scroll", a), window.removeEventListener("resize", y), S.disconnect(), E.disconnect();
269
269
  },
270
- redraw: p,
271
- setStyle: w,
270
+ redraw: g,
271
+ setStyle: x,
272
272
  setFilter: v,
273
- setPainter: g,
273
+ setPainter: f,
274
274
  setVisible: o.setVisible
275
275
  };
276
276
  }, he = () => {
@@ -282,35 +282,35 @@ const P = {
282
282
  t.classList.add("r6o-annotatable");
283
283
  const e = he(), n = e.getContext("2d");
284
284
  t.insertBefore(e, t.firstChild);
285
- const o = (s, u, f, m) => requestAnimationFrame(() => {
286
- const { width: l, height: p } = e;
287
- n.clearRect(-0.5, -0.5, l + 1, p + 1), m && m.clear();
288
- const { top: g, left: w } = u;
289
- [...s].sort((h, d) => {
290
- const { annotation: { target: { created: c } } } = h, { annotation: { target: { created: y } } } = d;
291
- return c.getTime() - y.getTime();
292
- }).forEach((h) => {
285
+ const o = (s, u, h, m) => requestAnimationFrame(() => {
286
+ const { width: l, height: g } = e;
287
+ n.clearRect(-0.5, -0.5, l + 1, g + 1), m && m.clear();
288
+ const { top: f, left: x } = u;
289
+ [...s].sort((p, d) => {
290
+ const { annotation: { target: { created: a } } } = p, { annotation: { target: { created: y } } } = d;
291
+ return a.getTime() - y.getTime();
292
+ }).forEach((p) => {
293
293
  var L;
294
- const d = f ? typeof f == "function" ? f(h.annotation, h.state) : f : (L = h.state) != null && L.selected ? ot : P, c = m && m.paint(h, u) || d, y = h.rects.map(({ x: E, y: B, width: T, height: O }) => ({
295
- x: E + w,
296
- y: B + g,
297
- width: T,
298
- height: O
294
+ const d = h ? typeof h == "function" ? h(p.annotation, p.state) : h : (L = p.state) != null && L.selected ? ot : P, a = m && m.paint(p, u) || d, y = p.rects.map(({ x: E, y: T, width: B, height: M }) => ({
295
+ x: E + x,
296
+ y: T + f,
297
+ width: B,
298
+ height: M
299
299
  }));
300
- n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1;
301
- const C = 5;
300
+ n.fillStyle = a.fill, n.globalAlpha = a.fillOpacity || 1;
301
+ const S = 5;
302
302
  if (y.forEach(
303
- ({ x: E, y: B, width: T, height: O }) => n.fillRect(
303
+ ({ x: E, y: T, width: B, height: M }) => n.fillRect(
304
304
  E,
305
- B - C / 2,
306
- T,
307
- O + C
305
+ T - S / 2,
306
+ B,
307
+ M + S
308
308
  )
309
- ), c.underlineColor) {
310
- n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
311
- const E = C / 2 + (c.underlineOffset ?? 0);
312
- y.forEach(({ x: B, y: T, width: O, height: b }) => {
313
- n.beginPath(), n.moveTo(B, T + b + E), n.lineTo(B + O, T + b + E), n.stroke();
309
+ ), a.underlineColor) {
310
+ n.globalAlpha = 1, n.strokeStyle = a.underlineColor, n.lineWidth = a.underlineThickness ?? 1;
311
+ const E = S / 2 + (a.underlineOffset ?? 0);
312
+ y.forEach(({ x: T, y: B, width: M, height: b }) => {
313
+ n.beginPath(), n.moveTo(T, B + b + E), n.lineTo(T + M, B + b + E), n.stroke();
314
314
  });
315
315
  }
316
316
  });
@@ -343,13 +343,13 @@ var me = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
343
343
  var e = t.toString(16);
344
344
  return e.length < 2 ? "0" + e : e;
345
345
  }, Xt = function(t) {
346
- var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), a = r - Math.min(e, n, o), s = a ? r === e ? (n - o) / a : r === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
347
- return { h: 60 * (s < 0 ? s + 6 : s), s: r ? a / r * 100 : 0, v: r / 255 * 100, a: i };
346
+ var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), c = r - Math.min(e, n, o), s = c ? r === e ? (n - o) / c : r === n ? 2 + (o - e) / c : 4 + (e - n) / c : 0;
347
+ return { h: 60 * (s < 0 ? s + 6 : s), s: r ? c / r * 100 : 0, v: r / 255 * 100, a: i };
348
348
  }, $t = function(t) {
349
349
  var e = t.h, n = t.s, o = t.v, i = t.a;
350
350
  e = e / 360 * 6, n /= 100, o /= 100;
351
- var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), u = o * (1 - (1 - e + r) * n), f = r % 6;
352
- return { r: 255 * [o, s, a, a, u, o][f], g: 255 * [u, o, o, s, a, a][f], b: 255 * [a, a, u, o, o, s][f], a: i };
351
+ var r = Math.floor(e), c = o * (1 - n), s = o * (1 - (e - r) * n), u = o * (1 - (1 - e + r) * n), h = r % 6;
352
+ return { r: 255 * [o, s, c, c, u, o][h], g: 255 * [u, o, o, s, c, c][h], b: 255 * [c, c, u, o, o, s][h], a: i };
353
353
  }, Et = function(t) {
354
354
  return { h: _t(t.h), s: k(t.s, 0, 100), l: k(t.l, 0, 100), a: k(t.a) };
355
355
  }, St = function(t) {
@@ -377,15 +377,15 @@ var me = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
377
377
  }, "rgb"], [function(t) {
378
378
  var e = t.h, n = t.s, o = t.l, i = t.a, r = i === void 0 ? 1 : i;
379
379
  if (!X(e) || !X(n) || !X(o)) return null;
380
- var a = Et({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
381
- return Ct(a);
380
+ var c = Et({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
381
+ return Ct(c);
382
382
  }, "hsl"], [function(t) {
383
383
  var e = t.h, n = t.s, o = t.v, i = t.a, r = i === void 0 ? 1 : i;
384
384
  if (!X(e) || !X(n) || !X(o)) return null;
385
- var a = function(s) {
385
+ var c = function(s) {
386
386
  return { h: _t(s.h), s: k(s.s, 0, 100), v: k(s.v, 0, 100), a: k(s.a) };
387
387
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(r) });
388
- return $t(a);
388
+ return $t(c);
389
389
  }, "hsv"]] }, Bt = function(t, e) {
390
390
  for (var n = 0; n < e.length; n++) {
391
391
  var o = e[n][0](t);
@@ -415,8 +415,8 @@ var me = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, X = function(t) {
415
415
  }, t.prototype.isLight = function() {
416
416
  return ct(this.rgba) >= 0.5;
417
417
  }, t.prototype.toHex = function() {
418
- return e = st(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? J(I(255 * r)) : "", "#" + J(n) + J(o) + J(i) + a;
419
- var e, n, o, i, r, a;
418
+ return e = st(this.rgba), n = e.r, o = e.g, i = e.b, c = (r = e.a) < 1 ? J(I(255 * r)) : "", "#" + J(n) + J(o) + J(i) + c;
419
+ var e, n, o, i, r, c;
420
420
  }, t.prototype.toRgb = function() {
421
421
  return st(this.rgba);
422
422
  }, t.prototype.toRgbString = function() {
@@ -474,20 +474,20 @@ const Ee = (t) => [
474
474
  setVisible: (r) => {
475
475
  console.log("setVisible not implemented on CSS Custom Highlights renderer");
476
476
  },
477
- redraw: (r, a, s, u) => {
477
+ redraw: (r, c, s, u) => {
478
478
  u && u.clear();
479
- const f = new Set(r.map((l) => l.annotation.id));
480
- Array.from(e).filter((l) => !f.has(l));
479
+ const h = new Set(r.map((l) => l.annotation.id));
480
+ Array.from(e).filter((l) => !h.has(l));
481
481
  const m = r.map((l) => {
482
- var w;
483
- const p = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (w = l.state) != null && w.selected ? ot : P, g = u && u.paint(l, a) || p;
484
- return `::highlight(_${l.annotation.id}) { ${Ee(g)} }`;
482
+ var x;
483
+ const g = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (x = l.state) != null && x.selected ? ot : P, f = u && u.paint(l, c) || g;
484
+ return `::highlight(_${l.annotation.id}) { ${Ee(f)} }`;
485
485
  });
486
486
  t.innerHTML = m.join(`
487
487
  `), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
488
- const p = l.target.selector.map((w) => w.range), g = new Highlight(...p);
489
- CSS.highlights.set(`_${l.id}`, g);
490
- }), e = f;
488
+ const g = l.target.selector.map((x) => x.range), f = new Highlight(...g);
489
+ CSS.highlights.set(`_${l.id}`, f);
490
+ }), e = h;
491
491
  }
492
492
  };
493
493
  }, Ce = (t, e, n) => vt(t, e, n, Se());
@@ -524,25 +524,25 @@ const Le = (t, e) => {
524
524
  destroy: () => {
525
525
  e.remove();
526
526
  },
527
- redraw: (a, s, u, f, m) => {
528
- const p = !(mt(n, a) && m);
529
- if (!f && !p) return;
530
- p && (e.innerHTML = "");
531
- const g = a.reduce((w, { rects: v }) => [...w, ...v], []);
532
- a.forEach((w) => {
533
- w.rects.map((v) => {
534
- const h = Le(v, g), d = Kt(w, s, u, f, h);
535
- if (p) {
536
- const c = document.createElement("span");
537
- c.className = "r6o-annotation", c.dataset.annotation = w.annotation.id, c.style.left = `${v.x}px`, c.style.top = `${v.y}px`, c.style.width = `${v.width}px`, c.style.height = `${v.height}px`;
527
+ redraw: (c, s, u, h, m) => {
528
+ const g = !(mt(n, c) && m);
529
+ if (!h && !g) return;
530
+ g && (e.innerHTML = "");
531
+ const f = c.reduce((x, { rects: v }) => [...x, ...v], []);
532
+ c.forEach((x) => {
533
+ x.rects.map((v) => {
534
+ const p = Le(v, f), d = Kt(x, s, u, h, p);
535
+ if (g) {
536
+ const a = document.createElement("span");
537
+ a.className = "r6o-annotation", a.dataset.annotation = x.annotation.id, a.style.left = `${v.x}px`, a.style.top = `${v.y}px`, a.style.width = `${v.width}px`, a.style.height = `${v.height}px`;
538
538
  const y = Y((d == null ? void 0 : d.fill) || P.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? P.fillOpacity : d.fillOpacity).toHex();
539
- c.style.backgroundColor = y, d.underlineStyle && (c.style.borderStyle = d.underlineStyle), d.underlineColor && (c.style.borderColor = d.underlineColor), d.underlineThickness && (c.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (c.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(c);
539
+ a.style.backgroundColor = y, d.underlineStyle && (a.style.borderStyle = d.underlineStyle), d.underlineColor && (a.style.borderColor = d.underlineColor), d.underlineThickness && (a.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (a.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(a);
540
540
  }
541
541
  });
542
- }), n = a;
542
+ }), n = c;
543
543
  },
544
- setVisible: (a) => {
545
- a ? e.classList.remove("hidden") : e.classList.add("hidden");
544
+ setVisible: (c) => {
545
+ c ? e.classList.remove("hidden") : e.classList.add("hidden");
546
546
  }
547
547
  };
548
548
  }, Te = (t, e, n) => vt(t, e, n, Be(t));
@@ -595,40 +595,40 @@ function dt() {
595
595
  function Ie(t, e) {
596
596
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
597
597
  }
598
- const z = [];
598
+ const F = [];
599
599
  function yt(t, e = dt) {
600
600
  let n;
601
601
  const o = /* @__PURE__ */ new Set();
602
602
  function i(s) {
603
603
  if (Ie(t, s) && (t = s, n)) {
604
- const u = !z.length;
605
- for (const f of o)
606
- f[1](), z.push(f, t);
604
+ const u = !F.length;
605
+ for (const h of o)
606
+ h[1](), F.push(h, t);
607
607
  if (u) {
608
- for (let f = 0; f < z.length; f += 2)
609
- z[f][0](z[f + 1]);
610
- z.length = 0;
608
+ for (let h = 0; h < F.length; h += 2)
609
+ F[h][0](F[h + 1]);
610
+ F.length = 0;
611
611
  }
612
612
  }
613
613
  }
614
614
  function r(s) {
615
615
  i(s(t));
616
616
  }
617
- function a(s, u = dt) {
618
- const f = [s, u];
619
- return o.add(f), o.size === 1 && (n = e(i, r) || dt), s(t), () => {
620
- o.delete(f), o.size === 0 && n && (n(), n = null);
617
+ function c(s, u = dt) {
618
+ const h = [s, u];
619
+ return o.add(h), o.size === 1 && (n = e(i, r) || dt), s(t), () => {
620
+ o.delete(h), o.size === 0 && n && (n(), n = null);
621
621
  };
622
622
  }
623
- return { set: i, update: r, subscribe: a };
623
+ return { set: i, update: r, subscribe: c };
624
624
  }
625
625
  const Ve = (t) => {
626
626
  const { subscribe: e, set: n } = yt();
627
627
  let o;
628
628
  return e((i) => o = i), t.observe(({ changes: i }) => {
629
629
  if (o) {
630
- (i.deleted || []).some((a) => a.id === o) && n(void 0);
631
- const r = (i.updated || []).find(({ oldValue: a }) => a.id === o);
630
+ (i.deleted || []).some((c) => c.id === o) && n(void 0);
631
+ const r = (i.updated || []).find(({ oldValue: c }) => c.id === o);
632
632
  r && n(r.newValue.id);
633
633
  }
634
634
  }), {
@@ -644,36 +644,36 @@ const ut = { selected: [] }, ke = (t, e = "EDIT") => {
644
644
  const { subscribe: n, set: o } = yt(ut);
645
645
  let i = ut;
646
646
  n((l) => i = l);
647
- const r = () => o(ut), a = () => {
647
+ const r = () => o(ut), c = () => {
648
648
  var l;
649
649
  return ((l = i.selected) == null ? void 0 : l.length) === 0;
650
650
  }, s = (l) => {
651
651
  if (i.selected.length === 0)
652
652
  return !1;
653
- const p = typeof l == "string" ? l : l.id;
654
- return i.selected.some((g) => g.id === p);
655
- }, u = (l, p) => {
656
- const g = t.getAnnotation(l);
657
- if (g) {
658
- const w = It(g, e);
659
- o(w === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: p } : w === "SELECT" ? { selected: [{ id: l }], pointerEvent: p } : { selected: [], pointerEvent: p });
653
+ const g = typeof l == "string" ? l : l.id;
654
+ return i.selected.some((f) => f.id === g);
655
+ }, u = (l, g) => {
656
+ const f = t.getAnnotation(l);
657
+ if (f) {
658
+ const x = It(f, e);
659
+ o(x === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: g } : x === "SELECT" ? { selected: [{ id: l }], pointerEvent: g } : { selected: [], pointerEvent: g });
660
660
  } else
661
661
  console.warn("Invalid selection: " + l);
662
- }, f = (l, p) => {
663
- const g = Array.isArray(l) ? l : [l], w = g.map((v) => t.getAnnotation(v)).filter(Boolean);
662
+ }, h = (l, g) => {
663
+ const f = Array.isArray(l) ? l : [l], x = f.map((v) => t.getAnnotation(v)).filter(Boolean);
664
664
  o({
665
- selected: w.map((v) => {
666
- const h = p === void 0 ? It(v, e) === "EDIT" : p;
667
- return { id: v.id, editable: h };
665
+ selected: x.map((v) => {
666
+ const p = g === void 0 ? It(v, e) === "EDIT" : g;
667
+ return { id: v.id, editable: p };
668
668
  })
669
- }), w.length !== g.length && console.warn("Invalid selection", l);
669
+ }), x.length !== f.length && console.warn("Invalid selection", l);
670
670
  }, m = (l) => {
671
671
  if (i.selected.length === 0)
672
672
  return !1;
673
- const { selected: p } = i;
674
- p.filter(({ id: g }) => l.includes(g)).length > 0 && o({ selected: p.filter(({ id: g }) => !l.includes(g)) });
673
+ const { selected: g } = i;
674
+ g.filter(({ id: f }) => l.includes(f)).length > 0 && o({ selected: g.filter(({ id: f }) => !l.includes(f)) });
675
675
  };
676
- return t.observe(({ changes: l }) => m((l.deleted || []).map((p) => p.id))), {
676
+ return t.observe(({ changes: l }) => m((l.deleted || []).map((g) => g.id))), {
677
677
  clear: r,
678
678
  clickSelect: u,
679
679
  get selected() {
@@ -682,9 +682,9 @@ const ut = { selected: [] }, ke = (t, e = "EDIT") => {
682
682
  get pointerEvent() {
683
683
  return i ? i.pointerEvent : null;
684
684
  },
685
- isEmpty: a,
685
+ isEmpty: c,
686
686
  isSelected: s,
687
- setSelected: f,
687
+ setSelected: h,
688
688
  subscribe: n
689
689
  };
690
690
  }, It = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT";
@@ -723,18 +723,18 @@ const Vn = (t, e, n, o) => ({
723
723
  }, Pe = (t, e) => {
724
724
  const n = new Set(e.bodies.map((o) => o.id));
725
725
  return t.bodies.filter((o) => !n.has(o.id));
726
- }, ze = (t, e) => e.bodies.map((n) => {
726
+ }, Fe = (t, e) => e.bodies.map((n) => {
727
727
  const o = t.bodies.find((i) => i.id === n.id);
728
728
  return { newBody: n, oldBody: o && !q(o, n) ? o : void 0 };
729
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Fe = (t, e) => !q(t.target, e.target), Pt = (t, e) => {
730
- const n = He(t, e), o = Pe(t, e), i = ze(t, e);
729
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), ze = (t, e) => !q(t.target, e.target), Pt = (t, e) => {
730
+ const n = He(t, e), o = Pe(t, e), i = Fe(t, e);
731
731
  return {
732
732
  oldValue: t,
733
733
  newValue: e,
734
734
  bodiesCreated: n.length > 0 ? n : void 0,
735
735
  bodiesDeleted: o.length > 0 ? o : void 0,
736
736
  bodiesUpdated: i.length > 0 ? i : void 0,
737
- targetUpdated: Fe(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
737
+ targetUpdated: ze(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
738
738
  };
739
739
  };
740
740
  var N = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(N || {});
@@ -744,200 +744,200 @@ const We = (t, e) => {
744
744
  if (!(!t.options.origin || t.options.origin === r))
745
745
  return !1;
746
746
  if (t.options.ignore) {
747
- const { ignore: a } = t.options, s = (u) => u && u.length > 0;
747
+ const { ignore: c } = t.options, s = (u) => u && u.length > 0;
748
748
  if (!(s(i.created) || s(i.deleted))) {
749
- const u = (n = i.updated) == null ? void 0 : n.some((m) => s(m.bodiesCreated) || s(m.bodiesDeleted) || s(m.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((m) => m.targetUpdated);
750
- if (a === "BODY_ONLY" && u && !f || a === "TARGET_ONLY" && f && !u)
749
+ const u = (n = i.updated) == null ? void 0 : n.some((m) => s(m.bodiesCreated) || s(m.bodiesDeleted) || s(m.bodiesUpdated)), h = (o = i.updated) == null ? void 0 : o.some((m) => m.targetUpdated);
750
+ if (c === "BODY_ONLY" && u && !h || c === "TARGET_ONLY" && h && !u)
751
751
  return !1;
752
752
  }
753
753
  }
754
754
  if (t.options.annotations) {
755
- const a = /* @__PURE__ */ new Set([
755
+ const c = /* @__PURE__ */ new Set([
756
756
  ...(i.created || []).map((s) => s.id),
757
757
  ...(i.deleted || []).map((s) => s.id),
758
758
  ...(i.updated || []).map(({ oldValue: s }) => s.id)
759
759
  ]);
760
- return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => a.has(s));
760
+ return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => c.has(s));
761
761
  } else
762
762
  return !0;
763
763
  }, qe = (t, e) => {
764
- const n = new Set((t.created || []).map((l) => l.id)), o = new Set((t.updated || []).map(({ newValue: l }) => l.id)), i = new Set((e.created || []).map((l) => l.id)), r = new Set((e.deleted || []).map((l) => l.id)), a = new Set((e.updated || []).map(({ oldValue: l }) => l.id)), s = new Set((e.updated || []).filter(({ oldValue: l }) => n.has(l.id) || o.has(l.id)).map(({ oldValue: l }) => l.id)), u = [
765
- ...(t.created || []).filter((l) => !r.has(l.id)).map((l) => a.has(l.id) ? e.updated.find(({ oldValue: p }) => p.id === l.id).newValue : l),
764
+ const n = new Set((t.created || []).map((l) => l.id)), o = new Set((t.updated || []).map(({ newValue: l }) => l.id)), i = new Set((e.created || []).map((l) => l.id)), r = new Set((e.deleted || []).map((l) => l.id)), c = new Set((e.updated || []).map(({ oldValue: l }) => l.id)), s = new Set((e.updated || []).filter(({ oldValue: l }) => n.has(l.id) || o.has(l.id)).map(({ oldValue: l }) => l.id)), u = [
765
+ ...(t.created || []).filter((l) => !r.has(l.id)).map((l) => c.has(l.id) ? e.updated.find(({ oldValue: g }) => g.id === l.id).newValue : l),
766
766
  ...e.created || []
767
- ], f = [
767
+ ], h = [
768
768
  ...(t.deleted || []).filter((l) => !i.has(l.id)),
769
769
  ...(e.deleted || []).filter((l) => !n.has(l.id))
770
770
  ], m = [
771
771
  ...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
772
- const { oldValue: p, newValue: g } = l;
773
- if (a.has(g.id)) {
774
- const w = e.updated.find((v) => v.oldValue.id === g.id).newValue;
775
- return Pt(p, w);
772
+ const { oldValue: g, newValue: f } = l;
773
+ if (c.has(f.id)) {
774
+ const x = e.updated.find((v) => v.oldValue.id === f.id).newValue;
775
+ return Pt(g, x);
776
776
  } else
777
777
  return l;
778
778
  }),
779
779
  ...(e.updated || []).filter(({ oldValue: l }) => !s.has(l.id))
780
780
  ];
781
- return { created: u, deleted: f, updated: m };
781
+ return { created: u, deleted: h, updated: m };
782
782
  }, je = (t) => t.id !== void 0, Ge = () => {
783
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, x = {}) => n.push({ onChange: b, options: x }), i = (b) => {
784
- const x = n.findIndex((A) => A.onChange == b);
785
- x > -1 && n.splice(x, 1);
786
- }, r = (b, x) => {
783
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, w = {}) => n.push({ onChange: b, options: w }), i = (b) => {
784
+ const w = n.findIndex((A) => A.onChange == b);
785
+ w > -1 && n.splice(w, 1);
786
+ }, r = (b, w) => {
787
787
  const A = {
788
788
  origin: b,
789
789
  changes: {
790
- created: x.created || [],
791
- updated: x.updated || [],
792
- deleted: x.deleted || []
790
+ created: w.created || [],
791
+ updated: w.updated || [],
792
+ deleted: w.deleted || []
793
793
  },
794
794
  state: [...t.values()]
795
795
  };
796
- n.forEach((S) => {
797
- We(S, A) && S.onChange(A);
796
+ n.forEach((C) => {
797
+ We(C, A) && C.onChange(A);
798
798
  });
799
- }, a = (b, x = N.LOCAL) => {
799
+ }, c = (b, w = N.LOCAL) => {
800
800
  if (t.get(b.id))
801
801
  throw Error(`Cannot add annotation ${b.id} - exists already`);
802
- t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(x, { created: [b] });
803
- }, s = (b, x) => {
804
- const A = typeof b == "string" ? x : b, S = typeof b == "string" ? b : b.id, R = t.get(S);
802
+ t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(w, { created: [b] });
803
+ }, s = (b, w) => {
804
+ const A = typeof b == "string" ? w : b, C = typeof b == "string" ? b : b.id, R = t.get(C);
805
805
  if (R) {
806
- const M = Pt(R, A);
807
- return S === A.id ? t.set(S, A) : (t.delete(S), t.set(A.id, A)), R.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), M;
806
+ const O = Pt(R, A);
807
+ return C === A.id ? t.set(C, A) : (t.delete(C), t.set(A.id, A)), R.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), O;
808
808
  } else
809
- console.warn(`Cannot update annotation ${S} - does not exist`);
810
- }, u = (b, x = N.LOCAL, A = N.LOCAL) => {
811
- const S = je(x) ? A : x, R = s(b, x);
812
- R && r(S, { updated: [R] });
813
- }, f = (b, x = N.LOCAL) => {
814
- const A = b.reduce((S, R) => {
815
- const M = s(R);
816
- return M ? [...S, M] : S;
809
+ console.warn(`Cannot update annotation ${C} - does not exist`);
810
+ }, u = (b, w = N.LOCAL, A = N.LOCAL) => {
811
+ const C = je(w) ? A : w, R = s(b, w);
812
+ R && r(C, { updated: [R] });
813
+ }, h = (b, w = N.LOCAL) => {
814
+ const A = b.reduce((C, R) => {
815
+ const O = s(R);
816
+ return O ? [...C, O] : C;
817
817
  }, []);
818
- A.length > 0 && r(x, { updated: A });
819
- }, m = (b, x = N.LOCAL) => {
818
+ A.length > 0 && r(w, { updated: A });
819
+ }, m = (b, w = N.LOCAL) => {
820
820
  const A = t.get(b.annotation);
821
821
  if (A) {
822
- const S = {
822
+ const C = {
823
823
  ...A,
824
824
  bodies: [...A.bodies, b]
825
825
  };
826
- t.set(A.id, S), e.set(b.id, S.id), r(x, { updated: [{
826
+ t.set(A.id, C), e.set(b.id, C.id), r(w, { updated: [{
827
827
  oldValue: A,
828
- newValue: S,
828
+ newValue: C,
829
829
  bodiesCreated: [b]
830
830
  }] });
831
831
  } else
832
832
  console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
833
- }, l = () => [...t.values()], p = (b = N.LOCAL) => {
834
- const x = [...t.values()];
835
- t.clear(), e.clear(), r(b, { deleted: x });
836
- }, g = (b, x = !0, A = N.LOCAL) => {
837
- if (x) {
838
- const S = [...t.values()];
833
+ }, l = () => [...t.values()], g = (b = N.LOCAL) => {
834
+ const w = [...t.values()];
835
+ t.clear(), e.clear(), r(b, { deleted: w });
836
+ }, f = (b, w = !0, A = N.LOCAL) => {
837
+ if (w) {
838
+ const C = [...t.values()];
839
839
  t.clear(), e.clear(), b.forEach((R) => {
840
- t.set(R.id, R), R.bodies.forEach((M) => e.set(M.id, R.id));
841
- }), r(A, { created: b, deleted: S });
840
+ t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
841
+ }), r(A, { created: b, deleted: C });
842
842
  } else {
843
- const S = b.reduce((R, M) => {
844
- const H = t.get(M.id);
843
+ const C = b.reduce((R, O) => {
844
+ const H = t.get(O.id);
845
845
  return H ? [...R, H] : R;
846
846
  }, []);
847
- if (S.length > 0)
848
- throw Error(`Bulk insert would overwrite the following annotations: ${S.map((R) => R.id).join(", ")}`);
847
+ if (C.length > 0)
848
+ throw Error(`Bulk insert would overwrite the following annotations: ${C.map((R) => R.id).join(", ")}`);
849
849
  b.forEach((R) => {
850
- t.set(R.id, R), R.bodies.forEach((M) => e.set(M.id, R.id));
850
+ t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
851
851
  }), r(A, { created: b });
852
852
  }
853
- }, w = (b) => {
854
- const x = typeof b == "string" ? b : b.id, A = t.get(x);
853
+ }, x = (b) => {
854
+ const w = typeof b == "string" ? b : b.id, A = t.get(w);
855
855
  if (A)
856
- return t.delete(x), A.bodies.forEach((S) => e.delete(S.id)), A;
857
- console.warn(`Attempt to delete missing annotation: ${x}`);
858
- }, v = (b, x = N.LOCAL) => {
859
- const A = w(b);
860
- A && r(x, { deleted: [A] });
861
- }, h = (b, x = N.LOCAL) => {
862
- const A = b.reduce((S, R) => {
863
- const M = w(R);
864
- return M ? [...S, M] : S;
856
+ return t.delete(w), A.bodies.forEach((C) => e.delete(C.id)), A;
857
+ console.warn(`Attempt to delete missing annotation: ${w}`);
858
+ }, v = (b, w = N.LOCAL) => {
859
+ const A = x(b);
860
+ A && r(w, { deleted: [A] });
861
+ }, p = (b, w = N.LOCAL) => {
862
+ const A = b.reduce((C, R) => {
863
+ const O = x(R);
864
+ return O ? [...C, O] : C;
865
865
  }, []);
866
- A.length > 0 && r(x, { deleted: A });
866
+ A.length > 0 && r(w, { deleted: A });
867
867
  }, d = (b) => {
868
- const x = t.get(b.annotation);
869
- if (x) {
870
- const A = x.bodies.find((S) => S.id === b.id);
868
+ const w = t.get(b.annotation);
869
+ if (w) {
870
+ const A = w.bodies.find((C) => C.id === b.id);
871
871
  if (A) {
872
872
  e.delete(A.id);
873
- const S = {
874
- ...x,
875
- bodies: x.bodies.filter((R) => R.id !== b.id)
873
+ const C = {
874
+ ...w,
875
+ bodies: w.bodies.filter((R) => R.id !== b.id)
876
876
  };
877
- return t.set(x.id, S), {
878
- oldValue: x,
879
- newValue: S,
877
+ return t.set(w.id, C), {
878
+ oldValue: w,
879
+ newValue: C,
880
880
  bodiesDeleted: [A]
881
881
  };
882
882
  } else
883
883
  console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
884
884
  } else
885
885
  console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
886
- }, c = (b, x = N.LOCAL) => {
886
+ }, a = (b, w = N.LOCAL) => {
887
887
  const A = d(b);
888
- A && r(x, { updated: [A] });
889
- }, y = (b, x = N.LOCAL) => {
890
- const A = b.map((S) => d(S)).filter(Boolean);
891
- A.length > 0 && r(x, { updated: A });
892
- }, C = (b) => {
893
- const x = t.get(b);
894
- return x ? { ...x } : void 0;
888
+ A && r(w, { updated: [A] });
889
+ }, y = (b, w = N.LOCAL) => {
890
+ const A = b.map((C) => d(C)).filter(Boolean);
891
+ A.length > 0 && r(w, { updated: A });
892
+ }, S = (b) => {
893
+ const w = t.get(b);
894
+ return w ? { ...w } : void 0;
895
895
  }, L = (b) => {
896
- const x = e.get(b);
897
- if (x) {
898
- const A = C(x).bodies.find((S) => S.id === b);
896
+ const w = e.get(b);
897
+ if (w) {
898
+ const A = S(w).bodies.find((C) => C.id === b);
899
899
  if (A)
900
900
  return A;
901
901
  console.error(`Store integrity error: body ${b} in index, but not in annotation`);
902
902
  } else
903
903
  console.warn(`Attempt to retrieve missing body: ${b}`);
904
- }, E = (b, x) => {
905
- if (b.annotation !== x.annotation)
904
+ }, E = (b, w) => {
905
+ if (b.annotation !== w.annotation)
906
906
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
907
907
  const A = t.get(b.annotation);
908
908
  if (A) {
909
- const S = A.bodies.find((M) => M.id === b.id), R = {
909
+ const C = A.bodies.find((O) => O.id === b.id), R = {
910
910
  ...A,
911
- bodies: A.bodies.map((M) => M.id === S.id ? x : M)
911
+ bodies: A.bodies.map((O) => O.id === C.id ? w : O)
912
912
  };
913
- return t.set(A.id, R), S.id !== x.id && (e.delete(S.id), e.set(x.id, R.id)), {
913
+ return t.set(A.id, R), C.id !== w.id && (e.delete(C.id), e.set(w.id, R.id)), {
914
914
  oldValue: A,
915
915
  newValue: R,
916
- bodiesUpdated: [{ oldBody: S, newBody: x }]
916
+ bodiesUpdated: [{ oldBody: C, newBody: w }]
917
917
  };
918
918
  } else
919
919
  console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
920
- }, B = (b, x, A = N.LOCAL) => {
921
- const S = E(b, x);
922
- S && r(A, { updated: [S] });
923
- }, T = (b, x = N.LOCAL) => {
924
- const A = b.map((S) => E({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
925
- r(x, { updated: A });
926
- }, O = (b) => {
927
- const x = t.get(b.annotation);
928
- if (x) {
920
+ }, T = (b, w, A = N.LOCAL) => {
921
+ const C = E(b, w);
922
+ C && r(A, { updated: [C] });
923
+ }, B = (b, w = N.LOCAL) => {
924
+ const A = b.map((C) => E({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
925
+ r(w, { updated: A });
926
+ }, M = (b) => {
927
+ const w = t.get(b.annotation);
928
+ if (w) {
929
929
  const A = {
930
- ...x,
930
+ ...w,
931
931
  target: {
932
- ...x.target,
932
+ ...w.target,
933
933
  ...b
934
934
  }
935
935
  };
936
- return t.set(x.id, A), {
937
- oldValue: x,
936
+ return t.set(w.id, A), {
937
+ oldValue: w,
938
938
  newValue: A,
939
939
  targetUpdated: {
940
- oldTarget: x.target,
940
+ oldTarget: w.target,
941
941
  newTarget: b
942
942
  }
943
943
  };
@@ -945,30 +945,30 @@ const We = (t, e) => {
945
945
  console.warn(`Attempt to update target on missing annotation: ${b.annotation}`);
946
946
  };
947
947
  return {
948
- addAnnotation: a,
948
+ addAnnotation: c,
949
949
  addBody: m,
950
950
  all: l,
951
- bulkAddAnnotation: g,
952
- bulkDeleteAnnotation: h,
951
+ bulkAddAnnotation: f,
952
+ bulkDeleteAnnotation: p,
953
953
  bulkDeleteBodies: y,
954
- bulkUpdateAnnotation: f,
955
- bulkUpdateBodies: T,
956
- bulkUpdateTargets: (b, x = N.LOCAL) => {
957
- const A = b.map((S) => O(S)).filter(Boolean);
958
- A.length > 0 && r(x, { updated: A });
954
+ bulkUpdateAnnotation: h,
955
+ bulkUpdateBodies: B,
956
+ bulkUpdateTargets: (b, w = N.LOCAL) => {
957
+ const A = b.map((C) => M(C)).filter(Boolean);
958
+ A.length > 0 && r(w, { updated: A });
959
959
  },
960
- clear: p,
960
+ clear: g,
961
961
  deleteAnnotation: v,
962
- deleteBody: c,
963
- getAnnotation: C,
962
+ deleteBody: a,
963
+ getAnnotation: S,
964
964
  getBody: L,
965
965
  observe: o,
966
966
  unobserve: i,
967
967
  updateAnnotation: u,
968
- updateBody: B,
969
- updateTarget: (b, x = N.LOCAL) => {
970
- const A = O(b);
971
- A && r(x, { updated: [A] });
968
+ updateBody: T,
969
+ updateTarget: (b, w = N.LOCAL) => {
970
+ const A = M(b);
971
+ A && r(w, { updated: [A] });
972
972
  }
973
973
  };
974
974
  };
@@ -989,38 +989,38 @@ let Ke = () => ({
989
989
  const Qe = 250, Je = (t) => {
990
990
  const e = Ke(), n = [];
991
991
  let o = -1, i = !1, r = 0;
992
- const a = (g) => {
992
+ const c = (f) => {
993
993
  if (!i) {
994
- const { changes: w } = g, v = performance.now();
994
+ const { changes: x } = f, v = performance.now();
995
995
  if (v - r > Qe)
996
- n.splice(o + 1), n.push(w), o = n.length - 1;
996
+ n.splice(o + 1), n.push(x), o = n.length - 1;
997
997
  else {
998
- const h = n.length - 1;
999
- n[h] = qe(n[h], w);
998
+ const p = n.length - 1;
999
+ n[p] = qe(n[p], x);
1000
1000
  }
1001
1001
  r = v;
1002
1002
  }
1003
1003
  i = !1;
1004
1004
  };
1005
- t.observe(a, { origin: N.LOCAL });
1006
- const s = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g), u = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), f = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ oldValue: w }) => w)), m = (g) => g && g.length > 0 && t.bulkUpdateAnnotation(g.map(({ newValue: w }) => w)), l = (g) => g && g.length > 0 && t.bulkAddAnnotation(g, !1), p = (g) => g && g.length > 0 && t.bulkDeleteAnnotation(g);
1005
+ t.observe(c, { origin: N.LOCAL });
1006
+ const s = (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)), m = (f) => f && f.length > 0 && t.bulkUpdateAnnotation(f.map(({ newValue: x }) => x)), l = (f) => f && f.length > 0 && t.bulkAddAnnotation(f, !1), g = (f) => f && f.length > 0 && t.bulkDeleteAnnotation(f);
1007
1007
  return {
1008
1008
  canRedo: () => n.length - 1 > o,
1009
1009
  canUndo: () => o > -1,
1010
- destroy: () => t.unobserve(a),
1011
- on: (g, w) => e.on(g, w),
1010
+ destroy: () => t.unobserve(c),
1011
+ on: (f, x) => e.on(f, x),
1012
1012
  redo: () => {
1013
1013
  if (n.length - 1 > o) {
1014
1014
  i = !0;
1015
- const { created: g, updated: w, deleted: v } = n[o + 1];
1016
- u(g), m(w), p(v), e.emit("redo", n[o + 1]), o += 1;
1015
+ const { created: f, updated: x, deleted: v } = n[o + 1];
1016
+ u(f), m(x), g(v), e.emit("redo", n[o + 1]), o += 1;
1017
1017
  }
1018
1018
  },
1019
1019
  undo: () => {
1020
1020
  if (o > -1) {
1021
1021
  i = !0;
1022
- const { created: g, updated: w, deleted: v } = n[o];
1023
- s(g), f(w), l(v), e.emit("undo", n[o]), o -= 1;
1022
+ const { created: f, updated: x, deleted: v } = n[o];
1023
+ s(f), h(x), l(v), e.emit("undo", n[o]), o -= 1;
1024
1024
  }
1025
1025
  }
1026
1026
  };
@@ -1031,73 +1031,73 @@ const Qe = 250, Je = (t) => {
1031
1031
  set: e
1032
1032
  };
1033
1033
  }, tn = (t, e, n, o) => {
1034
- const { store: i, selection: r, hover: a, viewport: s } = t, u = /* @__PURE__ */ new Map();
1035
- let f = [], m;
1036
- const l = (v, h) => {
1037
- u.has(v) ? u.get(v).push(h) : u.set(v, [h]);
1038
- }, p = (v, h) => {
1034
+ const { store: i, selection: r, hover: c, viewport: s } = t, u = /* @__PURE__ */ new Map();
1035
+ let h = [], m;
1036
+ const l = (v, p) => {
1037
+ u.has(v) ? u.get(v).push(p) : u.set(v, [p]);
1038
+ }, g = (v, p) => {
1039
1039
  const d = u.get(v);
1040
1040
  if (d) {
1041
- const c = d.indexOf(h);
1042
- c !== -1 && d.splice(c, 1);
1041
+ const a = d.indexOf(p);
1042
+ a !== -1 && d.splice(a, 1);
1043
1043
  }
1044
- }, g = (v, h, d) => {
1044
+ }, f = (v, p, d) => {
1045
1045
  u.has(v) && setTimeout(() => {
1046
- u.get(v).forEach((c) => {
1046
+ u.get(v).forEach((a) => {
1047
1047
  if (n) {
1048
- const y = Array.isArray(h) ? h.map((L) => n.serialize(L)) : n.serialize(h), C = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1049
- c(y, C);
1048
+ const y = Array.isArray(p) ? p.map((L) => n.serialize(L)) : n.serialize(p), S = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
1049
+ a(y, S);
1050
1050
  } else
1051
- c(h, d);
1051
+ a(p, d);
1052
1052
  });
1053
1053
  }, 1);
1054
1054
  };
1055
1055
  r.subscribe(({ selected: v }) => {
1056
- if (!(f.length === 0 && v.length === 0)) {
1057
- if (f.length === 0 && v.length > 0)
1058
- f = v.map(({ id: h }) => i.getAnnotation(h));
1059
- else if (f.length > 0 && v.length === 0)
1060
- f.forEach((h) => {
1061
- const d = i.getAnnotation(h.id);
1062
- d && !q(d, h) && g("updateAnnotation", d, h);
1063
- }), f = [];
1056
+ if (!(h.length === 0 && v.length === 0)) {
1057
+ if (h.length === 0 && v.length > 0)
1058
+ h = v.map(({ id: p }) => i.getAnnotation(p));
1059
+ else if (h.length > 0 && v.length === 0)
1060
+ h.forEach((p) => {
1061
+ const d = i.getAnnotation(p.id);
1062
+ d && !q(d, p) && f("updateAnnotation", d, p);
1063
+ }), h = [];
1064
1064
  else {
1065
- const h = new Set(f.map((c) => c.id)), d = new Set(v.map(({ id: c }) => c));
1066
- f.filter((c) => !d.has(c.id)).forEach((c) => {
1067
- const y = i.getAnnotation(c.id);
1068
- y && !q(y, c) && g("updateAnnotation", y, c);
1069
- }), f = [
1065
+ const p = new Set(h.map((a) => a.id)), d = new Set(v.map(({ id: a }) => a));
1066
+ h.filter((a) => !d.has(a.id)).forEach((a) => {
1067
+ const y = i.getAnnotation(a.id);
1068
+ y && !q(y, a) && f("updateAnnotation", y, a);
1069
+ }), h = [
1070
1070
  // Remove annotations that were deselected
1071
- ...f.filter((c) => d.has(c.id)),
1071
+ ...h.filter((a) => d.has(a.id)),
1072
1072
  // Add editable annotations that were selected
1073
- ...v.filter(({ id: c }) => !h.has(c)).map(({ id: c }) => i.getAnnotation(c))
1073
+ ...v.filter(({ id: a }) => !p.has(a)).map(({ id: a }) => i.getAnnotation(a))
1074
1074
  ];
1075
1075
  }
1076
- g("selectionChanged", f);
1076
+ f("selectionChanged", h);
1077
1077
  }
1078
- }), a.subscribe((v) => {
1079
- !m && v ? g("mouseEnterAnnotation", i.getAnnotation(v)) : m && !v ? g("mouseLeaveAnnotation", i.getAnnotation(m)) : m && v && (g("mouseLeaveAnnotation", i.getAnnotation(m)), g("mouseEnterAnnotation", i.getAnnotation(v))), m = v;
1080
- }), s == null || s.subscribe((v) => g("viewportIntersect", v.map((h) => i.getAnnotation(h)))), i.observe((v) => {
1081
- const { created: h, deleted: d } = v.changes;
1082
- (h || []).forEach((c) => g("createAnnotation", c)), (d || []).forEach((c) => g("deleteAnnotation", c)), (v.changes.updated || []).filter((c) => [
1083
- ...c.bodiesCreated || [],
1084
- ...c.bodiesDeleted || [],
1085
- ...c.bodiesUpdated || []
1086
- ].length > 0).forEach(({ oldValue: c, newValue: y }) => {
1087
- const C = f.find((L) => L.id === c.id) || c;
1088
- f = f.map((L) => L.id === c.id ? y : L), g("updateAnnotation", y, C);
1078
+ }), c.subscribe((v) => {
1079
+ !m && v ? f("mouseEnterAnnotation", i.getAnnotation(v)) : m && !v ? f("mouseLeaveAnnotation", i.getAnnotation(m)) : m && v && (f("mouseLeaveAnnotation", i.getAnnotation(m)), f("mouseEnterAnnotation", i.getAnnotation(v))), m = v;
1080
+ }), s == null || s.subscribe((v) => f("viewportIntersect", v.map((p) => i.getAnnotation(p)))), i.observe((v) => {
1081
+ const { created: p, deleted: d } = v.changes;
1082
+ (p || []).forEach((a) => f("createAnnotation", a)), (d || []).forEach((a) => f("deleteAnnotation", a)), (v.changes.updated || []).filter((a) => [
1083
+ ...a.bodiesCreated || [],
1084
+ ...a.bodiesDeleted || [],
1085
+ ...a.bodiesUpdated || []
1086
+ ].length > 0).forEach(({ oldValue: a, newValue: y }) => {
1087
+ const S = h.find((L) => L.id === a.id) || a;
1088
+ h = h.map((L) => L.id === a.id ? y : L), f("updateAnnotation", y, S);
1089
1089
  });
1090
1090
  }, { origin: N.LOCAL }), i.observe((v) => {
1091
- if (f) {
1092
- const h = new Set(f.map((c) => c.id)), d = (v.changes.updated || []).filter(({ newValue: c }) => h.has(c.id)).map(({ newValue: c }) => c);
1093
- d.length > 0 && (f = f.map((c) => d.find((C) => C.id === c.id) || c));
1091
+ if (h) {
1092
+ const p = new Set(h.map((a) => a.id)), d = (v.changes.updated || []).filter(({ newValue: a }) => p.has(a.id)).map(({ newValue: a }) => a);
1093
+ d.length > 0 && (h = h.map((a) => d.find((S) => S.id === a.id) || a));
1094
1094
  }
1095
1095
  }, { origin: N.REMOTE });
1096
- const w = (v) => (h) => {
1097
- const { updated: d } = h;
1098
- v ? (d || []).forEach((c) => g("updateAnnotation", c.oldValue, c.newValue)) : (d || []).forEach((c) => g("updateAnnotation", c.newValue, c.oldValue));
1096
+ const x = (v) => (p) => {
1097
+ const { updated: d } = p;
1098
+ v ? (d || []).forEach((a) => f("updateAnnotation", a.oldValue, a.newValue)) : (d || []).forEach((a) => f("updateAnnotation", a.newValue, a.oldValue));
1099
1099
  };
1100
- return e.on("undo", w(!0)), e.on("redo", w(!1)), { on: l, off: p, emit: g };
1100
+ return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: l, off: g, emit: f };
1101
1101
  }, en = (t) => (e) => e.reduce((n, o) => {
1102
1102
  const { parsed: i, error: r } = t.parse(o);
1103
1103
  return r ? {
@@ -1110,60 +1110,60 @@ const Qe = 250, Je = (t) => {
1110
1110
  ...n
1111
1111
  };
1112
1112
  }, { parsed: [], failed: [] }), nn = (t, e, n) => {
1113
- const { store: o, selection: i } = t, r = (h) => {
1113
+ const { store: o, selection: i } = t, r = (p) => {
1114
1114
  if (n) {
1115
- const { parsed: d, error: c } = n.parse(h);
1116
- d ? o.addAnnotation(d, N.REMOTE) : console.error(c);
1115
+ const { parsed: d, error: a } = n.parse(p);
1116
+ d ? o.addAnnotation(d, N.REMOTE) : console.error(a);
1117
1117
  } else
1118
- o.addAnnotation(h, N.REMOTE);
1119
- }, a = () => i.clear(), s = () => o.clear(), u = (h) => {
1120
- const d = o.getAnnotation(h);
1118
+ o.addAnnotation(p, N.REMOTE);
1119
+ }, c = () => i.clear(), s = () => o.clear(), u = (p) => {
1120
+ const d = o.getAnnotation(p);
1121
1121
  return n && d ? n.serialize(d) : d;
1122
- }, f = () => n ? o.all().map(n.serialize) : o.all(), m = () => {
1123
- var h;
1124
- const d = (((h = i.selected) == null ? void 0 : h.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
1122
+ }, h = () => n ? o.all().map(n.serialize) : o.all(), m = () => {
1123
+ var p;
1124
+ const d = (((p = i.selected) == null ? void 0 : p.map((a) => a.id)) || []).map((a) => o.getAnnotation(a)).filter(Boolean);
1125
1125
  return n ? d.map(n.serialize) : d;
1126
- }, l = (h, d = !0) => fetch(h).then((c) => c.json()).then((c) => (g(c, d), c)), p = (h) => {
1127
- if (typeof h == "string") {
1128
- const d = o.getAnnotation(h);
1129
- if (o.deleteAnnotation(h), d)
1126
+ }, l = (p, d = !0) => fetch(p).then((a) => a.json()).then((a) => (f(a, d), a)), g = (p) => {
1127
+ if (typeof p == "string") {
1128
+ const d = o.getAnnotation(p);
1129
+ if (o.deleteAnnotation(p), d)
1130
1130
  return n ? n.serialize(d) : d;
1131
1131
  } else {
1132
- const d = n ? n.parse(h).parsed : h;
1132
+ const d = n ? n.parse(p).parsed : p;
1133
1133
  if (d)
1134
- return o.deleteAnnotation(d), h;
1134
+ return o.deleteAnnotation(d), p;
1135
1135
  }
1136
- }, g = (h, d = !0) => {
1136
+ }, f = (p, d = !0) => {
1137
1137
  if (n) {
1138
- const { parsed: c, failed: y } = en(n)(h);
1139
- y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(c, d, N.REMOTE);
1138
+ const { parsed: a, failed: y } = en(n)(p);
1139
+ y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(a, d, N.REMOTE);
1140
1140
  } else
1141
- o.bulkAddAnnotation(h, d, N.REMOTE);
1142
- }, w = (h, d) => {
1143
- h ? i.setSelected(h, d) : i.clear();
1144
- }, v = (h) => {
1141
+ o.bulkAddAnnotation(p, d, N.REMOTE);
1142
+ }, x = (p, d) => {
1143
+ p ? i.setSelected(p, d) : i.clear();
1144
+ }, v = (p) => {
1145
1145
  if (n) {
1146
- const d = n.parse(h).parsed, c = n.serialize(o.getAnnotation(d.id));
1147
- return o.updateAnnotation(d), c;
1146
+ const d = n.parse(p).parsed, a = n.serialize(o.getAnnotation(d.id));
1147
+ return o.updateAnnotation(d), a;
1148
1148
  } else {
1149
- const d = o.getAnnotation(h.id);
1150
- return o.updateAnnotation(h), d;
1149
+ const d = o.getAnnotation(p.id);
1150
+ return o.updateAnnotation(p), d;
1151
1151
  }
1152
1152
  };
1153
1153
  return {
1154
1154
  addAnnotation: r,
1155
- cancelSelected: a,
1155
+ cancelSelected: c,
1156
1156
  canRedo: e.canRedo,
1157
1157
  canUndo: e.canUndo,
1158
1158
  clearAnnotations: s,
1159
1159
  getAnnotationById: u,
1160
- getAnnotations: f,
1160
+ getAnnotations: h,
1161
1161
  getSelected: m,
1162
1162
  loadAnnotations: l,
1163
1163
  redo: e.redo,
1164
- removeAnnotation: p,
1165
- setAnnotations: g,
1166
- setSelected: w,
1164
+ removeAnnotation: g,
1165
+ setAnnotations: f,
1166
+ setSelected: x,
1167
1167
  undo: e.undo,
1168
1168
  updateAnnotation: v
1169
1169
  };
@@ -1171,11 +1171,11 @@ const Qe = 250, Je = (t) => {
1171
1171
  let rn = (t) => crypto.getRandomValues(new Uint8Array(t)), sn = (t, e, n) => {
1172
1172
  let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
1173
1173
  return (r = e) => {
1174
- let a = "";
1174
+ let c = "";
1175
1175
  for (; ; ) {
1176
1176
  let s = n(i), u = i;
1177
1177
  for (; u--; )
1178
- if (a += t[s[u] & o] || "", a.length === r) return a;
1178
+ if (c += t[s[u] & o] || "", c.length === r) return c;
1179
1179
  }
1180
1180
  };
1181
1181
  }, an = (t, e = 21) => sn(t, e, rn), cn = (t = 21) => {
@@ -1192,23 +1192,23 @@ const ln = () => ({ isGuest: !0, id: an("1234567890abcdefghijklmnopqrstuvwxyzABC
1192
1192
  n = (n << 5) - n + r, n |= 0;
1193
1193
  }
1194
1194
  return `${n}`;
1195
- }, zt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, un = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1196
- const { id: o, type: i, purpose: r, value: a, created: s, modified: u, creator: f, ...m } = n;
1195
+ }, Ft = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, un = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1196
+ const { id: o, type: i, purpose: r, value: c, created: s, modified: u, creator: h, ...m } = n;
1197
1197
  return {
1198
1198
  id: o || `temp-${dn(n)}`,
1199
1199
  annotation: e,
1200
1200
  type: i,
1201
1201
  purpose: r,
1202
- value: a,
1203
- creator: zt(f),
1202
+ value: c,
1203
+ creator: Ft(h),
1204
1204
  created: s ? new Date(s) : void 0,
1205
1205
  updated: u ? new Date(u) : void 0,
1206
1206
  ...m
1207
1207
  };
1208
1208
  }), hn = (t) => t.map((e) => {
1209
1209
  var n;
1210
- const { annotation: o, created: i, updated: r, ...a } = e, s = {
1211
- ...a,
1210
+ const { annotation: o, created: i, updated: r, ...c } = e, s = {
1211
+ ...c,
1212
1212
  created: i == null ? void 0 : i.toISOString(),
1213
1213
  modified: r == null ? void 0 : r.toISOString()
1214
1214
  };
@@ -1225,21 +1225,21 @@ const Un = (t, e) => ({
1225
1225
  created: o,
1226
1226
  modified: i,
1227
1227
  target: r
1228
- } = t, a = Array.isArray(r) ? r : [r], s = {
1229
- creator: zt(n),
1228
+ } = t, c = Array.isArray(r) ? r : [r], s = {
1229
+ creator: Ft(n),
1230
1230
  created: o ? new Date(o) : void 0,
1231
1231
  updated: i ? new Date(i) : void 0,
1232
1232
  annotation: e,
1233
1233
  selector: []
1234
1234
  };
1235
- for (const u of a) {
1236
- const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((l, p) => {
1237
- switch (p.type) {
1235
+ for (const u of c) {
1236
+ const m = (Array.isArray(u.selector) ? u.selector : [u.selector]).reduce((l, g) => {
1237
+ switch (g.type) {
1238
1238
  case "TextQuoteSelector":
1239
- l.quote = p.exact;
1239
+ l.quote = g.exact;
1240
1240
  break;
1241
1241
  case "TextPositionSelector":
1242
- l.start = p.start, l.end = p.end;
1242
+ l.start = g.start, l.end = g.end;
1243
1243
  break;
1244
1244
  }
1245
1245
  return l;
@@ -1261,11 +1261,11 @@ const Un = (t, e) => ({
1261
1261
  created: o,
1262
1262
  modified: i,
1263
1263
  body: r,
1264
- ...a
1264
+ ...c
1265
1265
  } = t, s = un(r, e), u = gn(t);
1266
1266
  return "error" in u ? { error: u.error } : {
1267
1267
  parsed: {
1268
- ...a,
1268
+ ...c,
1269
1269
  id: e,
1270
1270
  bodies: s,
1271
1271
  target: u.parsed
@@ -1273,25 +1273,25 @@ const Un = (t, e) => ({
1273
1273
  };
1274
1274
  }, mn = (t, e, n) => {
1275
1275
  const { bodies: o, target: i, ...r } = t, {
1276
- selector: a,
1276
+ selector: c,
1277
1277
  creator: s,
1278
1278
  created: u,
1279
- updated: f,
1279
+ updated: h,
1280
1280
  ...m
1281
- } = i, l = a.map((p) => {
1282
- const { quote: g, start: w, end: v, range: h } = p, { prefix: d, suffix: c } = oe(h, n), y = [{
1281
+ } = i, l = c.map((g) => {
1282
+ const { quote: f, start: x, end: v, range: p } = g, { prefix: d, suffix: a } = oe(p, n), y = [{
1283
1283
  type: "TextQuoteSelector",
1284
- exact: g,
1284
+ exact: f,
1285
1285
  prefix: d,
1286
- suffix: c
1286
+ suffix: a
1287
1287
  }, {
1288
1288
  type: "TextPositionSelector",
1289
- start: w,
1289
+ start: x,
1290
1290
  end: v
1291
1291
  }];
1292
1292
  return {
1293
1293
  ...m,
1294
- id: p.id,
1294
+ id: g.id,
1295
1295
  source: e,
1296
1296
  selector: y
1297
1297
  };
@@ -1304,25 +1304,25 @@ const Un = (t, e) => ({
1304
1304
  body: hn(t.bodies),
1305
1305
  creator: s,
1306
1306
  created: u == null ? void 0 : u.toISOString(),
1307
- modified: f == null ? void 0 : f.toISOString(),
1307
+ modified: h == null ? void 0 : h.toISOString(),
1308
1308
  target: l
1309
1309
  };
1310
1310
  };
1311
1311
  function bn(t, e, n, o, i) {
1312
- Ft(t, e, n || 0, o || t.length - 1, i || vn);
1312
+ zt(t, e, n || 0, o || t.length - 1, i || vn);
1313
1313
  }
1314
- function Ft(t, e, n, o, i) {
1314
+ function zt(t, e, n, o, i) {
1315
1315
  for (; o > n; ) {
1316
1316
  if (o - n > 600) {
1317
- var r = o - n + 1, a = e - n + 1, s = Math.log(r), u = 0.5 * Math.exp(2 * s / 3), f = 0.5 * Math.sqrt(s * u * (r - u) / r) * (a - r / 2 < 0 ? -1 : 1), m = Math.max(n, Math.floor(e - a * u / r + f)), l = Math.min(o, Math.floor(e + (r - a) * u / r + f));
1318
- Ft(t, e, m, l, i);
1317
+ var r = o - n + 1, c = e - n + 1, s = Math.log(r), u = 0.5 * Math.exp(2 * s / 3), h = 0.5 * Math.sqrt(s * u * (r - u) / r) * (c - r / 2 < 0 ? -1 : 1), m = Math.max(n, Math.floor(e - c * u / r + h)), l = Math.min(o, Math.floor(e + (r - c) * u / r + h));
1318
+ zt(t, e, m, l, i);
1319
1319
  }
1320
- var p = t[e], g = n, w = o;
1321
- for (j(t, n, e), i(t[o], p) > 0 && j(t, n, o); g < w; ) {
1322
- for (j(t, g, w), g++, w--; i(t[g], p) < 0; ) g++;
1323
- for (; i(t[w], p) > 0; ) w--;
1320
+ var g = t[e], f = n, x = o;
1321
+ for (j(t, n, e), i(t[o], g) > 0 && j(t, n, o); f < x; ) {
1322
+ for (j(t, f, x), f++, x--; i(t[f], g) < 0; ) f++;
1323
+ for (; i(t[x], g) > 0; ) x--;
1324
1324
  }
1325
- i(t[n], p) === 0 ? j(t, n, w) : (w++, j(t, w, o)), w <= e && (n = w + 1), e <= w && (o = w - 1);
1325
+ i(t[n], g) === 0 ? j(t, n, x) : (x++, j(t, x, o)), x <= e && (n = x + 1), e <= x && (o = x - 1);
1326
1326
  }
1327
1327
  }
1328
1328
  function j(t, e, n) {
@@ -1345,8 +1345,8 @@ class yn {
1345
1345
  if (!nt(e, n)) return o;
1346
1346
  const i = this.toBBox, r = [];
1347
1347
  for (; n; ) {
1348
- for (let a = 0; a < n.children.length; a++) {
1349
- const s = n.children[a], u = n.leaf ? i(s) : s;
1348
+ for (let c = 0; c < n.children.length; c++) {
1349
+ const s = n.children[c], u = n.leaf ? i(s) : s;
1350
1350
  nt(e, u) && (n.leaf ? o.push(s) : gt(e, u) ? this._all(s, o) : r.push(s));
1351
1351
  }
1352
1352
  n = r.pop();
@@ -1359,9 +1359,9 @@ class yn {
1359
1359
  const o = [];
1360
1360
  for (; n; ) {
1361
1361
  for (let i = 0; i < n.children.length; i++) {
1362
- const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
1363
- if (nt(e, a)) {
1364
- if (n.leaf || gt(e, a)) return !0;
1362
+ const r = n.children[i], c = n.leaf ? this.toBBox(r) : r;
1363
+ if (nt(e, c)) {
1364
+ if (n.leaf || gt(e, c)) return !0;
1365
1365
  o.push(r);
1366
1366
  }
1367
1367
  }
@@ -1399,15 +1399,15 @@ class yn {
1399
1399
  remove(e, n) {
1400
1400
  if (!e) return this;
1401
1401
  let o = this.data;
1402
- const i = this.toBBox(e), r = [], a = [];
1403
- let s, u, f;
1402
+ const i = this.toBBox(e), r = [], c = [];
1403
+ let s, u, h;
1404
1404
  for (; o || r.length; ) {
1405
- if (o || (o = r.pop(), u = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
1405
+ if (o || (o = r.pop(), u = r[r.length - 1], s = c.pop(), h = !0), o.leaf) {
1406
1406
  const m = wn(e, o.children, n);
1407
1407
  if (m !== -1)
1408
1408
  return o.children.splice(m, 1), r.push(o), this._condense(r), this;
1409
1409
  }
1410
- !f && !o.leaf && gt(o, i) ? (r.push(o), a.push(s), s = 0, u = o, o = o.children[0]) : u ? (s++, o = u.children[s], f = !1) : o = null;
1410
+ !h && !o.leaf && gt(o, i) ? (r.push(o), c.push(s), s = 0, u = o, o = o.children[0]) : u ? (s++, o = u.children[s], h = !1) : o = null;
1411
1411
  }
1412
1412
  return this;
1413
1413
  }
@@ -1434,36 +1434,36 @@ class yn {
1434
1434
  }
1435
1435
  _build(e, n, o, i) {
1436
1436
  const r = o - n + 1;
1437
- let a = this._maxEntries, s;
1438
- if (r <= a)
1439
- return s = W(e.slice(n, o + 1)), F(s, this.toBBox), s;
1440
- i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = W([]), s.leaf = !1, s.height = i;
1441
- const u = Math.ceil(r / a), f = u * Math.ceil(Math.sqrt(a));
1442
- Ut(e, n, o, f, this.compareMinX);
1443
- for (let m = n; m <= o; m += f) {
1444
- const l = Math.min(m + f - 1, o);
1437
+ let c = this._maxEntries, s;
1438
+ if (r <= c)
1439
+ return s = W(e.slice(n, o + 1)), z(s, this.toBBox), s;
1440
+ i || (i = Math.ceil(Math.log(r) / Math.log(c)), c = Math.ceil(r / Math.pow(c, i - 1))), s = W([]), s.leaf = !1, s.height = i;
1441
+ const u = Math.ceil(r / c), h = u * Math.ceil(Math.sqrt(c));
1442
+ Ut(e, n, o, h, this.compareMinX);
1443
+ for (let m = n; m <= o; m += h) {
1444
+ const l = Math.min(m + h - 1, o);
1445
1445
  Ut(e, m, l, u, this.compareMinY);
1446
- for (let p = m; p <= l; p += u) {
1447
- const g = Math.min(p + u - 1, l);
1448
- s.children.push(this._build(e, p, g, i - 1));
1446
+ for (let g = m; g <= l; g += u) {
1447
+ const f = Math.min(g + u - 1, l);
1448
+ s.children.push(this._build(e, g, f, i - 1));
1449
1449
  }
1450
1450
  }
1451
- return F(s, this.toBBox), s;
1451
+ return z(s, this.toBBox), s;
1452
1452
  }
1453
1453
  _chooseSubtree(e, n, o, i) {
1454
1454
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1455
- let r = 1 / 0, a = 1 / 0, s;
1455
+ let r = 1 / 0, c = 1 / 0, s;
1456
1456
  for (let u = 0; u < n.children.length; u++) {
1457
- const f = n.children[u], m = ft(f), l = En(e, f) - m;
1458
- l < a ? (a = l, r = m < r ? m : r, s = f) : l === a && m < r && (r = m, s = f);
1457
+ const h = n.children[u], m = ft(h), l = En(e, h) - m;
1458
+ l < c ? (c = l, r = m < r ? m : r, s = h) : l === c && m < r && (r = m, s = h);
1459
1459
  }
1460
1460
  n = s || n.children[0];
1461
1461
  }
1462
1462
  return n;
1463
1463
  }
1464
1464
  _insert(e, n, o) {
1465
- const i = o ? e : this.toBBox(e), r = [], a = this._chooseSubtree(i, this.data, n, r);
1466
- for (a.children.push(e), K(a, i); n >= 0 && r[n].children.length > this._maxEntries; )
1465
+ const i = o ? e : this.toBBox(e), r = [], c = this._chooseSubtree(i, this.data, n, r);
1466
+ for (c.children.push(e), K(c, i); n >= 0 && r[n].children.length > this._maxEntries; )
1467
1467
  this._split(r, n), n--;
1468
1468
  this._adjustParentBBoxes(i, r, n);
1469
1469
  }
@@ -1471,36 +1471,36 @@ class yn {
1471
1471
  _split(e, n) {
1472
1472
  const o = e[n], i = o.children.length, r = this._minEntries;
1473
1473
  this._chooseSplitAxis(o, r, i);
1474
- const a = this._chooseSplitIndex(o, r, i), s = W(o.children.splice(a, o.children.length - a));
1475
- s.height = o.height, s.leaf = o.leaf, F(o, this.toBBox), F(s, this.toBBox), n ? e[n - 1].children.push(s) : this._splitRoot(o, s);
1474
+ const c = this._chooseSplitIndex(o, r, i), s = W(o.children.splice(c, o.children.length - c));
1475
+ s.height = o.height, s.leaf = o.leaf, z(o, this.toBBox), z(s, this.toBBox), n ? e[n - 1].children.push(s) : this._splitRoot(o, s);
1476
1476
  }
1477
1477
  _splitRoot(e, n) {
1478
- this.data = W([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, F(this.data, this.toBBox);
1478
+ this.data = W([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, z(this.data, this.toBBox);
1479
1479
  }
1480
1480
  _chooseSplitIndex(e, n, o) {
1481
- let i, r = 1 / 0, a = 1 / 0;
1481
+ let i, r = 1 / 0, c = 1 / 0;
1482
1482
  for (let s = n; s <= o - n; s++) {
1483
- const u = G(e, 0, s, this.toBBox), f = G(e, s, o, this.toBBox), m = Sn(u, f), l = ft(u) + ft(f);
1484
- m < r ? (r = m, i = s, a = l < a ? l : a) : m === r && l < a && (a = l, i = s);
1483
+ const u = G(e, 0, s, this.toBBox), h = G(e, s, o, this.toBBox), m = Sn(u, h), l = ft(u) + ft(h);
1484
+ m < r ? (r = m, i = s, c = l < c ? l : c) : m === r && l < c && (c = l, i = s);
1485
1485
  }
1486
1486
  return i || o - n;
1487
1487
  }
1488
1488
  // sorts node children by the best axis for split
1489
1489
  _chooseSplitAxis(e, n, o) {
1490
- const i = e.leaf ? this.compareMinX : xn, r = e.leaf ? this.compareMinY : An, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1491
- a < s && e.children.sort(i);
1490
+ const i = e.leaf ? this.compareMinX : xn, r = e.leaf ? this.compareMinY : An, c = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1491
+ c < s && e.children.sort(i);
1492
1492
  }
1493
1493
  // total margin of all possible split distributions where each node is at least m full
1494
1494
  _allDistMargin(e, n, o, i) {
1495
1495
  e.children.sort(i);
1496
- const r = this.toBBox, a = G(e, 0, n, r), s = G(e, o - n, o, r);
1497
- let u = et(a) + et(s);
1498
- for (let f = n; f < o - n; f++) {
1499
- const m = e.children[f];
1500
- K(a, e.leaf ? r(m) : m), u += et(a);
1496
+ const r = this.toBBox, c = G(e, 0, n, r), s = G(e, o - n, o, r);
1497
+ let u = et(c) + et(s);
1498
+ for (let h = n; h < o - n; h++) {
1499
+ const m = e.children[h];
1500
+ K(c, e.leaf ? r(m) : m), u += et(c);
1501
1501
  }
1502
- for (let f = o - n - 1; f >= n; f--) {
1503
- const m = e.children[f];
1502
+ for (let h = o - n - 1; h >= n; h--) {
1503
+ const m = e.children[h];
1504
1504
  K(s, e.leaf ? r(m) : m), u += et(s);
1505
1505
  }
1506
1506
  return u;
@@ -1511,7 +1511,7 @@ class yn {
1511
1511
  }
1512
1512
  _condense(e) {
1513
1513
  for (let n = e.length - 1, o; n >= 0; n--)
1514
- e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : F(e[n], this.toBBox);
1514
+ e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : z(e[n], this.toBBox);
1515
1515
  }
1516
1516
  }
1517
1517
  function wn(t, e, n) {
@@ -1520,14 +1520,14 @@ function wn(t, e, n) {
1520
1520
  if (n(t, e[o])) return o;
1521
1521
  return -1;
1522
1522
  }
1523
- function F(t, e) {
1523
+ function z(t, e) {
1524
1524
  G(t, 0, t.children.length, e, t);
1525
1525
  }
1526
1526
  function G(t, e, n, o, i) {
1527
1527
  i || (i = W(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
1528
1528
  for (let r = e; r < n; r++) {
1529
- const a = t.children[r];
1530
- K(i, t.leaf ? o(a) : a);
1529
+ const c = t.children[r];
1530
+ K(i, t.leaf ? o(c) : c);
1531
1531
  }
1532
1532
  return i;
1533
1533
  }
@@ -1574,138 +1574,137 @@ function Ut(t, e, n, o, i) {
1574
1574
  const r = [e, n];
1575
1575
  for (; r.length; ) {
1576
1576
  if (n = r.pop(), e = r.pop(), n - e <= o) continue;
1577
- const a = e + Math.ceil((n - e) / o / 2) * o;
1578
- bn(t, a, e, n, i), r.push(e, a, a, n);
1577
+ const c = e + Math.ceil((n - e) / o / 2) * o;
1578
+ bn(t, c, e, n, i), r.push(e, c, c, n);
1579
1579
  }
1580
1580
  }
1581
1581
  const Cn = (t, e) => {
1582
- const n = new yn(), o = /* @__PURE__ */ new Map(), i = (d, c) => {
1582
+ const n = new yn(), o = /* @__PURE__ */ new Map(), i = (d, a) => {
1583
1583
  const y = d.selector.flatMap((L) => {
1584
1584
  const E = $([L]) ? L.range : Dt(L, e).range;
1585
1585
  return Array.from(E.getClientRects());
1586
- }), C = ce(y).map(({ left: L, top: E, right: B, bottom: T }) => new DOMRect(L - c.left, E - c.top, B - L, T - E));
1587
- return C.map((L) => {
1588
- const { x: E, y: B, width: T, height: O } = L;
1586
+ }), S = ce(y).map(({ left: L, top: E, right: T, bottom: B }) => new DOMRect(L - a.left, E - a.top, T - L, B - E));
1587
+ return S.map((L) => {
1588
+ const { x: E, y: T, width: B, height: M } = L;
1589
1589
  return {
1590
1590
  minX: E,
1591
- minY: B,
1592
- maxX: E + T,
1593
- maxY: B + O,
1591
+ minY: T,
1592
+ maxX: E + B,
1593
+ maxY: T + M,
1594
1594
  annotation: {
1595
1595
  id: d.annotation,
1596
- rects: C
1596
+ rects: S
1597
1597
  }
1598
1598
  };
1599
1599
  });
1600
- }, r = () => [...o.values()], a = () => {
1600
+ }, r = () => [...o.values()], c = () => {
1601
1601
  n.clear(), o.clear();
1602
1602
  }, s = (d) => {
1603
- const c = i(d, e.getBoundingClientRect());
1604
- c.forEach((y) => n.insert(y)), o.set(d.annotation, c);
1603
+ const a = i(d, e.getBoundingClientRect());
1604
+ a.forEach((y) => n.insert(y)), o.set(d.annotation, a);
1605
1605
  }, u = (d) => {
1606
- const c = o.get(d.annotation);
1607
- c && (c.forEach((y) => n.remove(y)), o.delete(d.annotation));
1608
- }, f = (d) => {
1606
+ const a = o.get(d.annotation);
1607
+ a && (a.forEach((y) => n.remove(y)), o.delete(d.annotation));
1608
+ }, h = (d) => {
1609
1609
  u(d), s(d);
1610
- }, m = (d, c = !0) => {
1611
- c && a();
1612
- const y = e.getBoundingClientRect(), C = d.map((E) => ({ target: E, rects: i(E, y) }));
1613
- C.forEach(({ target: E, rects: B }) => o.set(E.annotation, B));
1614
- const L = C.flatMap(({ rects: E }) => E);
1610
+ }, m = (d, a = !0) => {
1611
+ a && c();
1612
+ const y = e.getBoundingClientRect(), S = d.map((E) => ({ target: E, rects: i(E, y) }));
1613
+ S.forEach(({ target: E, rects: T }) => o.set(E.annotation, T));
1614
+ const L = S.flatMap(({ rects: E }) => E);
1615
1615
  n.load(L);
1616
- }, l = (d, c) => {
1617
- const y = n.search({
1616
+ }, l = (d, a, y = !1) => {
1617
+ const S = n.search({
1618
1618
  minX: d,
1619
- minY: c,
1619
+ minY: a,
1620
1620
  maxX: d,
1621
- maxY: c
1622
- }), C = (L) => L.annotation.rects.reduce((E, B) => E + B.width * B.height, 0);
1623
- if (y.length > 0)
1624
- return y.sort((L, E) => C(L) - C(E)), y[0].annotation.id;
1625
- }, p = (d) => {
1626
- const c = g(d);
1627
- if (c.length === 0)
1621
+ maxY: a
1622
+ }), L = (E) => E.annotation.rects.reduce((T, B) => T + B.width * B.height, 0);
1623
+ return S.length > 0 ? (S.sort((E, T) => L(E) - L(T)), y ? S.map((E) => E.annotation.id) : [S[0].annotation.id]) : [];
1624
+ }, g = (d) => {
1625
+ const a = f(d);
1626
+ if (a.length === 0)
1628
1627
  return;
1629
- let y = c[0].left, C = c[0].top, L = c[0].right, E = c[0].bottom;
1630
- for (let B = 1; B < c.length; B++) {
1631
- const T = c[B];
1632
- y = Math.min(y, T.left), C = Math.min(C, T.top), L = Math.max(L, T.right), E = Math.max(E, T.bottom);
1628
+ let y = a[0].left, S = a[0].top, L = a[0].right, E = a[0].bottom;
1629
+ for (let T = 1; T < a.length; T++) {
1630
+ const B = a[T];
1631
+ y = Math.min(y, B.left), S = Math.min(S, B.top), L = Math.max(L, B.right), E = Math.max(E, B.bottom);
1633
1632
  }
1634
- return new DOMRect(y, C, L - y, E - C);
1635
- }, g = (d) => {
1636
- const c = o.get(d);
1637
- return c ? c[0].annotation.rects : [];
1633
+ return new DOMRect(y, S, L - y, E - S);
1634
+ }, f = (d) => {
1635
+ const a = o.get(d);
1636
+ return a ? a[0].annotation.rects : [];
1638
1637
  };
1639
1638
  return {
1640
1639
  all: r,
1641
- clear: a,
1640
+ clear: c,
1642
1641
  getAt: l,
1643
- getAnnotationBounds: p,
1644
- getAnnotationRects: g,
1645
- getIntersecting: (d, c, y, C) => {
1646
- const L = n.search({ minX: d, minY: c, maxX: y, maxY: C }), E = new Set(L.map((B) => B.annotation.id));
1647
- return Array.from(E).map((B) => ({
1648
- annotation: t.getAnnotation(B),
1649
- rects: g(B)
1650
- })).filter((B) => !!B.annotation);
1642
+ getAnnotationBounds: g,
1643
+ getAnnotationRects: f,
1644
+ getIntersecting: (d, a, y, S) => {
1645
+ const L = n.search({ minX: d, minY: a, maxX: y, maxY: S }), E = new Set(L.map((T) => T.annotation.id));
1646
+ return Array.from(E).map((T) => ({
1647
+ annotation: t.getAnnotation(T),
1648
+ rects: f(T)
1649
+ })).filter((T) => !!T.annotation);
1651
1650
  },
1652
1651
  insert: s,
1653
1652
  recalculate: () => m(t.all().map((d) => d.target), !0),
1654
1653
  remove: u,
1655
1654
  set: m,
1656
1655
  size: () => n.all().length,
1657
- update: f
1656
+ update: h
1658
1657
  };
1659
1658
  }, Ln = (t, e) => {
1660
- const n = Ge(), o = Cn(n, t), i = ke(n, e), r = Ve(n), a = Ze(), s = (v, h = N.LOCAL) => {
1661
- const d = rt(v, t), c = $(d.target.selector);
1662
- return c && n.addAnnotation(d, h), c;
1663
- }, u = (v, h = !0, d = N.LOCAL) => {
1664
- const c = v.map((C) => rt(C, t)), y = c.filter((C) => !$(C.target.selector));
1665
- return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(c, h, d), y) : (n.bulkAddAnnotation(c, h, d), []);
1666
- }, f = (v, h = N.LOCAL) => {
1667
- const d = v.map((y) => rt(y, t)), c = d.filter((y) => !$(y.target.selector));
1668
- return c.length > 0 && console.warn("Could not revive all targets for these annotations:", c), d.forEach((y) => {
1669
- n.getAnnotation(y.id) ? n.updateAnnotation(y, h) : n.addAnnotation(y, h);
1670
- }), c;
1671
- }, m = (v, h = N.LOCAL) => {
1659
+ const n = Ge(), o = Cn(n, t), i = ke(n, e), r = Ve(n), c = Ze(), s = (v, p = N.LOCAL) => {
1660
+ const d = rt(v, t), a = $(d.target.selector);
1661
+ return a && n.addAnnotation(d, p), a;
1662
+ }, u = (v, p = !0, d = N.LOCAL) => {
1663
+ const a = v.map((S) => rt(S, t)), y = a.filter((S) => !$(S.target.selector));
1664
+ return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(a, p, d), y) : (n.bulkAddAnnotation(a, p, d), []);
1665
+ }, h = (v, p = N.LOCAL) => {
1666
+ const d = v.map((y) => rt(y, t)), a = d.filter((y) => !$(y.target.selector));
1667
+ return a.length > 0 && console.warn("Could not revive all targets for these annotations:", a), d.forEach((y) => {
1668
+ n.getAnnotation(y.id) ? n.updateAnnotation(y, p) : n.addAnnotation(y, p);
1669
+ }), a;
1670
+ }, m = (v, p = N.LOCAL) => {
1672
1671
  const d = it(v, t);
1673
- n.updateTarget(d, h);
1674
- }, l = (v, h = N.LOCAL) => {
1675
- const d = v.map((c) => it(c, t));
1676
- n.bulkUpdateTargets(d, h);
1677
- }, p = (v, h) => {
1678
- const d = o.getAt(v, h);
1679
- return d ? n.getAnnotation(d) : void 0;
1680
- }, g = (v, h, d, c = 5) => {
1672
+ n.updateTarget(d, p);
1673
+ }, l = (v, p = N.LOCAL) => {
1674
+ const d = v.map((a) => it(a, t));
1675
+ n.bulkUpdateTargets(d, p);
1676
+ }, g = (v, p, d) => {
1677
+ const a = o.getAt(v, p, !!d).map((S) => n.getAnnotation(S)), y = d ? a.filter(d) : a;
1678
+ return y.length > 0 ? y[0] : void 0;
1679
+ }, f = (v, p, d, a = 5) => {
1681
1680
  const y = o.getAnnotationRects(v);
1682
1681
  if (y.length !== 0) {
1683
- if (h && d) {
1684
- const C = y.find(({ top: L, right: E, bottom: B, left: T }) => h >= T - c && h <= E + c && d >= L - c && d <= B + c);
1685
- if (C) return C;
1682
+ if (p && d) {
1683
+ const S = y.find(({ top: L, right: E, bottom: T, left: B }) => p >= B - a && p <= E + a && d >= L - a && d <= T + a);
1684
+ if (S) return S;
1686
1685
  }
1687
1686
  return o.getAnnotationBounds(v);
1688
1687
  }
1689
- }, w = () => o.recalculate();
1688
+ }, x = () => o.recalculate();
1690
1689
  return n.observe(({ changes: v }) => {
1691
- const h = (v.deleted || []).filter((y) => $(y.target.selector)), d = (v.created || []).filter((y) => $(y.target.selector)), c = (v.updated || []).filter((y) => $(y.newValue.target.selector));
1692
- (h == null ? void 0 : h.length) > 0 && h.forEach((y) => o.remove(y.target)), d.length > 0 && o.set(d.map((y) => y.target), !1), (c == null ? void 0 : c.length) > 0 && c.forEach(({ newValue: y }) => o.update(y.target));
1690
+ const p = (v.deleted || []).filter((y) => $(y.target.selector)), d = (v.created || []).filter((y) => $(y.target.selector)), a = (v.updated || []).filter((y) => $(y.newValue.target.selector));
1691
+ (p == null ? void 0 : p.length) > 0 && p.forEach((y) => o.remove(y.target)), d.length > 0 && o.set(d.map((y) => y.target), !1), (a == null ? void 0 : a.length) > 0 && a.forEach(({ newValue: y }) => o.update(y.target));
1693
1692
  }), {
1694
1693
  store: {
1695
1694
  ...n,
1696
1695
  addAnnotation: s,
1697
1696
  bulkAddAnnotation: u,
1698
1697
  bulkUpdateTargets: l,
1699
- bulkUpsertAnnotations: f,
1700
- getAnnotationBounds: g,
1701
- getAt: p,
1698
+ bulkUpsertAnnotations: h,
1699
+ getAnnotationBounds: f,
1700
+ getAt: g,
1702
1701
  getIntersecting: o.getIntersecting,
1703
- recalculatePositions: w,
1702
+ recalculatePositions: x,
1704
1703
  updateTarget: m
1705
1704
  },
1706
1705
  selection: i,
1707
1706
  hover: r,
1708
- viewport: a
1707
+ viewport: c
1709
1708
  };
1710
1709
  }, Bn = () => {
1711
1710
  const t = document.createElement("canvas");
@@ -1715,27 +1714,27 @@ const Cn = (t, e) => {
1715
1714
  }, Tn = (t, e, n = {}) => {
1716
1715
  const o = Bn(), i = o.getContext("2d");
1717
1716
  t.appendChild(o);
1718
- const r = /* @__PURE__ */ new Map(), a = (l) => Array.from(r.entries()).filter(([p, g]) => g.presenceKey === l.presenceKey).map(([p, g]) => p);
1719
- return e.on("selectionChange", (l, p) => {
1720
- a(l).forEach((w) => r.delete(w)), p && p.forEach((w) => r.set(w, l));
1717
+ const r = /* @__PURE__ */ new Map(), c = (l) => Array.from(r.entries()).filter(([g, f]) => f.presenceKey === l.presenceKey).map(([g, f]) => g);
1718
+ return e.on("selectionChange", (l, g) => {
1719
+ c(l).forEach((x) => r.delete(x)), g && g.forEach((x) => r.set(x, l));
1721
1720
  }), {
1722
1721
  clear: () => {
1723
- const { width: l, height: p } = o;
1724
- i.clearRect(-0.5, -0.5, l + 1, p + 1);
1722
+ const { width: l, height: g } = o;
1723
+ i.clearRect(-0.5, -0.5, l + 1, g + 1);
1725
1724
  },
1726
1725
  destroy: () => {
1727
1726
  o.remove();
1728
1727
  },
1729
- paint: (l, p, g) => {
1728
+ paint: (l, g, f) => {
1730
1729
  n.font && (i.font = n.font);
1731
- const w = r.get(l.annotation.id);
1732
- if (w) {
1733
- const { height: v } = l.rects[0], h = l.rects[0].x + p.left, d = l.rects[0].y + p.top;
1734
- i.fillStyle = w.appearance.color, i.fillRect(h - 2, d - 2.5, 2, v + 5);
1735
- const c = i.measureText(w.appearance.label), y = c.width + 6, C = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, L = c.fontBoundingBoxAscent ? 8 : 6.5;
1736
- return i.fillRect(h - 2, d - 2.5 - C, y, C), i.fillStyle = "#fff", i.fillText(w.appearance.label, h + 1, d - L), {
1737
- fill: w.appearance.color,
1738
- fillOpacity: g ? 0.45 : 0.18
1730
+ const x = r.get(l.annotation.id);
1731
+ if (x) {
1732
+ const { height: v } = l.rects[0], p = l.rects[0].x + g.left, d = l.rects[0].y + g.top;
1733
+ i.fillStyle = x.appearance.color, i.fillRect(p - 2, d - 2.5, 2, v + 5);
1734
+ const a = i.measureText(x.appearance.label), y = a.width + 6, S = a.actualBoundingBoxAscent + a.actualBoundingBoxDescent + 8, L = a.fontBoundingBoxAscent ? 8 : 6.5;
1735
+ return i.fillRect(p - 2, d - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(x.appearance.label, p + 1, d - L), {
1736
+ fill: x.appearance.color,
1737
+ fillOpacity: f ? 0.45 : 0.18
1739
1738
  };
1740
1739
  }
1741
1740
  },
@@ -1751,17 +1750,17 @@ const Cn = (t, e) => {
1751
1750
  const { overflowY: e } = window.getComputedStyle(t);
1752
1751
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Wt(t.parentElement);
1753
1752
  }, Rn = (t, e) => (n) => {
1754
- const o = typeof n == "string" ? n : n.id, i = (a) => {
1755
- const s = r.getBoundingClientRect(), u = r.clientHeight, f = r.clientWidth, m = a.selector[0].range.getBoundingClientRect(), { width: l, height: p } = e.getAnnotationBounds(o), g = m.top - s.top, w = m.left - s.left, v = r.parentElement ? r.scrollTop : 0, h = r.parentElement ? r.scrollLeft : 0, d = g + v - (u - p) / 2, c = w + h - (f - l) / 2;
1756
- r.scroll({ top: d, left: c, behavior: "smooth" });
1753
+ const o = typeof n == "string" ? n : n.id, i = (c) => {
1754
+ const s = r.getBoundingClientRect(), u = r.clientHeight, h = r.clientWidth, m = c.selector[0].range.getBoundingClientRect(), { width: l, height: g } = e.getAnnotationBounds(o), f = m.top - s.top, x = m.left - s.left, v = r.parentElement ? r.scrollTop : 0, p = r.parentElement ? r.scrollLeft : 0, d = f + v - (u - g) / 2, a = x + p - (h - l) / 2;
1755
+ r.scroll({ top: d, left: a, behavior: "smooth" });
1757
1756
  }, r = Wt(t);
1758
1757
  if (r) {
1759
- const a = e.getAnnotation(o), { range: s } = a.target.selector[0];
1758
+ const c = e.getAnnotation(o), { range: s } = c.target.selector[0];
1760
1759
  if (s && !s.collapsed)
1761
- return i(a.target), !0;
1760
+ return i(c.target), !0;
1762
1761
  {
1763
- const u = it(a.target, t), { range: f } = u.selector[0];
1764
- if (f && !f.collapsed)
1762
+ const u = it(c.target, t), { range: h } = u.selector[0];
1763
+ if (h && !h.collapsed)
1765
1764
  return i(u), !0;
1766
1765
  }
1767
1766
  }
@@ -1770,92 +1769,96 @@ const Cn = (t, e) => {
1770
1769
  ...t,
1771
1770
  annotationEnabled: t.annotationEnabled === void 0 ? e.annotationEnabled : t.annotationEnabled
1772
1771
  }), Mn = (t, e, n, o) => {
1773
- const { store: i, selection: r } = e;
1774
- let a, s;
1775
- const u = (h) => a = h;
1776
- let f = !1, m;
1777
- const l = (h) => {
1778
- var c;
1779
- if (!f) return;
1780
- !((c = h.target.parentElement) != null && c.closest(D)) ? s = {
1772
+ let i;
1773
+ const r = (a) => i = a;
1774
+ let c;
1775
+ const s = (a) => c = a, { store: u, selection: h } = e;
1776
+ let m, l = !1, g;
1777
+ const f = (a) => {
1778
+ var S;
1779
+ if (!l) return;
1780
+ !((S = a.target.parentElement) != null && S.closest(D)) ? m = {
1781
1781
  annotation: Ht(),
1782
1782
  selector: [],
1783
- creator: a,
1783
+ creator: i,
1784
1784
  created: /* @__PURE__ */ new Date()
1785
- } : s = void 0;
1785
+ } : m = void 0;
1786
1786
  };
1787
- n && t.addEventListener("selectstart", l);
1788
- const p = bt((h) => {
1789
- var E, B;
1790
- const d = document.getSelection();
1791
- if (!!((B = (E = d.anchorNode) == null ? void 0 : E.parentElement) != null && B.closest(D))) {
1792
- s = void 0;
1787
+ n && t.addEventListener("selectstart", f);
1788
+ const x = bt((a) => {
1789
+ var B, M;
1790
+ const y = document.getSelection();
1791
+ if (!!((M = (B = y.anchorNode) == null ? void 0 : B.parentElement) != null && M.closest(D))) {
1792
+ m = void 0;
1793
1793
  return;
1794
1794
  }
1795
- if (h.timeStamp - ((m == null ? void 0 : m.timeStamp) || h.timeStamp) < 1e3 && !s && l(m), d.isCollapsed || !f || !s) return;
1796
- const y = d.getRangeAt(0);
1797
- if (re(y)) return;
1798
- const C = Zt(y.cloneRange());
1799
- (C.length !== s.selector.length || C.some((T, O) => {
1800
- var b;
1801
- return T.toString() !== ((b = s.selector[O]) == null ? void 0 : b.quote);
1802
- })) && (s = {
1803
- ...s,
1804
- selector: C.map((T) => le(T, t, o)),
1795
+ if (a.timeStamp - ((g == null ? void 0 : g.timeStamp) || a.timeStamp) < 1e3 && !m && f(g), y.isCollapsed || !l || !m) return;
1796
+ const L = y.getRangeAt(0);
1797
+ if (re(L)) return;
1798
+ const E = Zt(L.cloneRange());
1799
+ (E.length !== m.selector.length || E.some((b, w) => {
1800
+ var A;
1801
+ return b.toString() !== ((A = m.selector[w]) == null ? void 0 : A.quote);
1802
+ })) && (m = {
1803
+ ...m,
1804
+ selector: E.map((b) => le(b, t, o)),
1805
1805
  updated: /* @__PURE__ */ new Date()
1806
- }, i.getAnnotation(s.annotation) ? i.updateTarget(s, N.LOCAL) : (r.clear(), i.addAnnotation({
1807
- id: s.annotation,
1806
+ }, u.getAnnotation(m.annotation) ? u.updateTarget(m, N.LOCAL) : (h.clear(), u.addAnnotation({
1807
+ id: m.annotation,
1808
1808
  bodies: [],
1809
- target: s
1810
- }), r.clickSelect(s.annotation, m)));
1809
+ target: m
1810
+ }), h.clickSelect(m.annotation, g)));
1811
1811
  });
1812
- n && document.addEventListener("selectionchange", p);
1813
- const g = (h) => {
1814
- const { target: d, timeStamp: c, offsetX: y, offsetY: C, type: L } = h;
1815
- m = { ...h, target: d, timeStamp: c, offsetX: y, offsetY: C, type: L }, f = h.button === 0;
1812
+ n && document.addEventListener("selectionchange", x);
1813
+ const v = (a) => {
1814
+ const { target: y, timeStamp: S, offsetX: L, offsetY: E, type: T } = a;
1815
+ g = { ...a, target: y, timeStamp: S, offsetX: L, offsetY: E, type: T }, l = a.button === 0;
1816
1816
  };
1817
- t.addEventListener("pointerdown", g);
1818
- const w = (h) => {
1819
- var C;
1820
- if (!!((C = h.target.parentElement) != null && C.closest(D)) || !f)
1817
+ t.addEventListener("pointerdown", v);
1818
+ const p = (a) => {
1819
+ var E;
1820
+ if (!!((E = a.target.parentElement) != null && E.closest(D)) || !l)
1821
1821
  return;
1822
- const c = () => {
1823
- const { x: L, y: E } = t.getBoundingClientRect(), B = i.getAt(h.clientX - L, h.clientY - E);
1824
- if (B) {
1825
- const { selected: T } = r;
1826
- (T.length !== 1 || T[0].id !== B.id) && r.clickSelect(B.id, h);
1827
- } else r.isEmpty() || r.clear();
1828
- }, y = h.timeStamp - m.timeStamp;
1829
- document.getSelection().isCollapsed && y < 300 ? (s = void 0, c()) : s && r.clickSelect(s.annotation, h);
1822
+ const S = () => {
1823
+ const { x: T, y: B } = t.getBoundingClientRect(), M = u.getAt(a.clientX - T, a.clientY - B, c);
1824
+ if (M) {
1825
+ const { selected: b } = h;
1826
+ (b.length !== 1 || b[0].id !== M.id) && h.clickSelect(M.id, a);
1827
+ } else h.isEmpty() || h.clear();
1828
+ }, L = a.timeStamp - g.timeStamp;
1829
+ document.getSelection().isCollapsed && L < 300 ? (m = void 0, S()) : m && h.clickSelect(m.annotation, a);
1830
1830
  };
1831
- return document.addEventListener("pointerup", w), {
1831
+ return document.addEventListener("pointerup", p), {
1832
1832
  destroy: () => {
1833
- t.removeEventListener("selectstart", l), document.removeEventListener("selectionchange", p), t.removeEventListener("pointerdown", g), document.removeEventListener("pointerup", w);
1833
+ t.removeEventListener("selectstart", f), document.removeEventListener("selectionchange", x), t.removeEventListener("pointerdown", v), document.removeEventListener("pointerup", p);
1834
1834
  },
1835
- setUser: u
1835
+ setFilter: s,
1836
+ setUser: r
1836
1837
  };
1837
1838
  }, kt = "SPANS", kn = (t, e = {}) => {
1838
1839
  te(t);
1839
1840
  const n = Nn(e, {
1840
1841
  annotationEnabled: !0
1841
- }), o = Ln(t, n.pointerAction), { selection: i, viewport: r } = o, a = o.store, s = Je(a), u = tn(o, s, n.adapter);
1842
- let f = ln();
1842
+ }), o = Ln(t, n.pointerAction), { selection: i, viewport: r } = o, c = o.store, s = Je(c), u = tn(o, s, n.adapter);
1843
+ let h = ln();
1843
1844
  const m = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : kt : n.renderer || kt, l = m === "SPANS" ? Te(t, o, r) : m === "CSS_HIGHLIGHTS" ? Ce(t, o, r) : m === "CANVAS" ? pe(t, o, r) : void 0;
1844
1845
  if (!l)
1845
1846
  throw `Unknown renderer implementation: ${m}`;
1846
1847
  console.debug(`Using ${m} renderer`), n.style && l.setStyle(n.style);
1847
- const p = Mn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1848
- return p.setUser(f), {
1848
+ const g = Mn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
1849
+ return g.setUser(h), {
1849
1850
  ...nn(o, s, n.adapter),
1850
1851
  destroy: () => {
1851
- l.destroy(), p.destroy(), s.destroy();
1852
+ l.destroy(), g.destroy(), s.destroy();
1852
1853
  },
1853
1854
  element: t,
1854
- getUser: () => f,
1855
- setFilter: (E) => l.setFilter(E),
1855
+ getUser: () => h,
1856
+ setFilter: (E) => {
1857
+ l.setFilter(E), g.setFilter(E);
1858
+ },
1856
1859
  setStyle: (E) => l.setStyle(E),
1857
1860
  setUser: (E) => {
1858
- f = E, p.setUser(E);
1861
+ h = E, g.setUser(E);
1859
1862
  },
1860
1863
  setSelected: (E) => {
1861
1864
  E ? i.setSelected(E) : i.clear();
@@ -1866,7 +1869,7 @@ const Cn = (t, e) => {
1866
1869
  setVisible: (E) => l.setVisible(E),
1867
1870
  on: u.on,
1868
1871
  off: u.off,
1869
- scrollIntoView: Rn(t, a),
1872
+ scrollIntoView: Rn(t, c),
1870
1873
  state: o
1871
1874
  };
1872
1875
  };