@recogito/text-annotator 3.0.0-rc.6 → 3.0.0-rc.7

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.
@@ -32,41 +32,41 @@ const mt = (e, t = 10) => {
32
32
  let a, r, d = nt;
33
33
  const u = pt(n);
34
34
  e.classList.add("r6o-annotatable");
35
- const b = j("r6o-highlight-layer bg"), h = j("r6o-highlight-layer fg", !0), E = b.getContext("2d"), m = h.getContext("2d");
36
- e.insertBefore(b, e.firstChild), e.appendChild(h), e.addEventListener("pointermove", (v) => {
37
- const { x: T, y: M } = e.getBoundingClientRect(), f = o.getAt(v.clientX - T, v.clientY - M);
35
+ const b = j("r6o-highlight-layer bg"), h = j("r6o-highlight-layer fg", !0), v = b.getContext("2d"), m = h.getContext("2d");
36
+ e.insertBefore(b, e.firstChild), e.appendChild(h), e.addEventListener("pointermove", (E) => {
37
+ const { x: T, y: L } = e.getBoundingClientRect(), f = o.getAt(E.clientX - T, E.clientY - L);
38
38
  f && (!r || r(f)) ? s.current !== f.id && (e.classList.add("hovered"), s.set(f.id)) : s.current && (e.classList.remove("hovered"), s.set(null));
39
39
  });
40
- const w = () => {
41
- const { top: v, left: T } = e.getBoundingClientRect(), { innerWidth: M, innerHeight: f } = window, x = -T, A = -v, B = M - T, S = f - v;
42
- return { top: v, left: T, minX: x, minY: A, maxX: B, maxY: S };
43
- }, L = () => c();
44
- document.addEventListener("scroll", L, { capture: !0, passive: !0 });
40
+ const x = () => {
41
+ const { top: E, left: T } = e.getBoundingClientRect(), { innerWidth: L, innerHeight: f } = window, w = -T, A = -E, B = L - T, S = f - E;
42
+ return { top: E, left: T, minX: w, minY: A, maxX: B, maxY: S };
43
+ }, M = () => c();
44
+ document.addEventListener("scroll", M, { capture: !0, passive: !0 });
45
45
  const y = mt(() => {
46
46
  Z(b), Z(h, !0), o.recalculatePositions(), c();
47
47
  });
48
48
  window.addEventListener("resize", y), new ResizeObserver(y).observe(e);
49
49
  const c = () => requestAnimationFrame(() => {
50
- const { top: v, left: T, minX: M, minY: f, maxX: x, maxY: A } = w(), B = r ? o.getIntersectingRects(M, f, x, A).filter(({ annotation: U }) => r(U)) : o.getIntersectingRects(M, f, x, A), { width: S, height: R } = h, X = new Set(i.selected.map(({ id: U }) => U));
51
- m.clearRect(-0.5, -0.5, S + 1, R + 1), E.clearRect(-0.5, -0.5, S + 1, R + 1), B.forEach(({ annotation: U, rects: at }) => {
50
+ const { top: E, left: T, minX: L, minY: f, maxX: w, maxY: A } = x(), B = r ? o.getIntersectingRects(L, f, w, A).filter(({ annotation: Y }) => r(Y)) : o.getIntersectingRects(L, f, w, A), { width: S, height: R } = h, X = new Set(i.selected.map(({ id: Y }) => Y));
51
+ m.clearRect(-0.5, -0.5, S + 1, R + 1), v.clearRect(-0.5, -0.5, S + 1, R + 1), B.forEach(({ annotation: Y, rects: at }) => {
52
52
  const rt = at.map(({ x: ct, y: dt, width: ut, height: ht }) => ({
53
53
  x: ct + T,
54
- y: dt + v,
54
+ y: dt + E,
55
55
  width: ut,
56
56
  height: ht
57
- })), lt = X.has(U.id);
58
- d.paint(U, rt, E, m, lt, a);
59
- }), setTimeout(() => u(B.map(({ annotation: U }) => U)), 1);
57
+ })), lt = X.has(Y.id);
58
+ d.paint(Y, rt, v, m, lt, a);
59
+ }), setTimeout(() => u(B.map(({ annotation: Y }) => Y)), 1);
60
60
  });
61
61
  return o.observe(() => c()), i.subscribe(() => c()), {
62
62
  redraw: c,
63
- setDrawingStyle: (v) => {
64
- a = v, c();
63
+ setDrawingStyle: (E) => {
64
+ a = E, c();
65
65
  },
66
- setFilter: (v) => {
67
- r = v, c();
66
+ setFilter: (E) => {
67
+ r = E, c();
68
68
  },
69
- setPainter: (v) => d = v
69
+ setPainter: (E) => d = E
70
70
  };
71
71
  }, k = (e, t) => {
72
72
  const { start: n, end: o } = e.selector, i = e.selector.offsetReference ? e.selector.offsetReference : t;
@@ -104,7 +104,7 @@ const mt = (e, t = 10) => {
104
104
  };
105
105
  };
106
106
  var Q = Object.prototype.hasOwnProperty;
107
- function Y(e, t) {
107
+ function U(e, t) {
108
108
  var n, o;
109
109
  if (e === t)
110
110
  return !0;
@@ -115,14 +115,14 @@ function Y(e, t) {
115
115
  return e.toString() === t.toString();
116
116
  if (n === Array) {
117
117
  if ((o = e.length) === t.length)
118
- for (; o-- && Y(e[o], t[o]); )
118
+ for (; o-- && U(e[o], t[o]); )
119
119
  ;
120
120
  return o === -1;
121
121
  }
122
122
  if (!n || typeof e == "object") {
123
123
  o = 0;
124
124
  for (n in e)
125
- if (Q.call(e, n) && ++o && !Q.call(t, n) || !(n in t) || !Y(e[n], t[n]))
125
+ if (Q.call(e, n) && ++o && !Q.call(t, n) || !(n in t) || !U(e[n], t[n]))
126
126
  return !1;
127
127
  return Object.keys(t).length === o;
128
128
  }
@@ -155,19 +155,19 @@ function J(e, t = W) {
155
155
  }
156
156
  function a(r, d = W) {
157
157
  const u = [r, d];
158
- return o.add(u), o.size === 1 && (n = t(i) || W), r(e), () => {
158
+ return o.add(u), o.size === 1 && (n = t(i, s) || W), r(e), () => {
159
159
  o.delete(u), o.size === 0 && n && (n(), n = null);
160
160
  };
161
161
  }
162
162
  return { set: i, update: s, subscribe: a };
163
163
  }
164
- const xt = (e) => {
165
- const { subscribe: t, set: n } = J(null);
166
- let o = null;
164
+ const wt = (e) => {
165
+ const { subscribe: t, set: n } = J();
166
+ let o;
167
167
  return t((i) => o = i), e.observe(({ changes: i }) => {
168
168
  if (o) {
169
- i.deleted.some((a) => a.id === o) && n(null);
170
- const s = i.updated.find(({ oldValue: a }) => a.id === o);
169
+ (i.deleted || []).some((a) => a.id === o) && n(void 0);
170
+ const s = (i.updated || []).find(({ oldValue: a }) => a.id === o);
171
171
  s && n(s.newValue.id);
172
172
  }
173
173
  }), {
@@ -177,7 +177,7 @@ const xt = (e) => {
177
177
  subscribe: t,
178
178
  set: n
179
179
  };
180
- }, q = { selected: [] }, wt = (e, t = "EDIT") => {
180
+ }, q = { selected: [] }, xt = (e, t = "EDIT") => {
181
181
  const { subscribe: n, set: o } = J(q);
182
182
  let i = q;
183
183
  n((h) => i = h);
@@ -187,25 +187,25 @@ const xt = (e) => {
187
187
  }, r = (h) => {
188
188
  if (i.selected.length === 0)
189
189
  return !1;
190
- const E = typeof h == "string" ? h : h.id;
191
- return i.selected.some((m) => m.id === E);
192
- }, d = (h, E) => {
190
+ const v = typeof h == "string" ? h : h.id;
191
+ return i.selected.some((m) => m.id === v);
192
+ }, d = (h, v) => {
193
193
  const m = e.getAnnotation(h);
194
194
  if (m) {
195
- const w = yt(m, t);
196
- o(w === "EDIT" ? { selected: [{ id: h, editable: !0 }], pointerEvent: E } : w === "SELECT" ? { selected: [{ id: h }], pointerEvent: E } : { selected: [], pointerEvent: E });
195
+ const x = yt(m, t);
196
+ o(x === "EDIT" ? { selected: [{ id: h, editable: !0 }], pointerEvent: v } : x === "SELECT" ? { selected: [{ id: h }], pointerEvent: v } : { selected: [], pointerEvent: v });
197
197
  } else
198
198
  console.warn("Invalid selection: " + h);
199
- }, u = (h, E = !0) => {
200
- const m = Array.isArray(h) ? h : [h], w = m.map((L) => e.getAnnotation(L)).filter((L) => L);
201
- o({ selected: w.map(({ id: L }) => ({ id: L, editable: E })) }), w.length !== m.length && console.warn("Invalid selection", h);
199
+ }, u = (h, v = !0) => {
200
+ const m = Array.isArray(h) ? h : [h], x = m.map((M) => e.getAnnotation(M)).filter(Boolean);
201
+ o({ selected: x.map(({ id: M }) => ({ id: M, editable: v })) }), x.length !== m.length && console.warn("Invalid selection", h);
202
202
  }, b = (h) => {
203
203
  if (i.selected.length === 0)
204
204
  return !1;
205
- const { selected: E } = i;
206
- E.filter(({ id: m }) => h.includes(m)).length > 0 && o({ selected: E.filter(({ id: m }) => !h.includes(m)) });
205
+ const { selected: v } = i;
206
+ v.filter(({ id: m }) => h.includes(m)).length > 0 && o({ selected: v.filter(({ id: m }) => !h.includes(m)) });
207
207
  };
208
- return e.observe(({ changes: h }) => b(h.deleted.map((E) => E.id))), {
208
+ return e.observe(({ changes: h }) => b((h.deleted || []).map((v) => v.id))), {
209
209
  clear: s,
210
210
  clickSelect: d,
211
211
  get selected() {
@@ -219,11 +219,11 @@ const xt = (e) => {
219
219
  setSelected: u,
220
220
  subscribe: n
221
221
  };
222
- }, yt = (e, t) => typeof t == "function" ? t(e) || "EDIT" : t || "EDIT", vt = [];
222
+ }, yt = (e, t) => typeof t == "function" ? t(e) || "EDIT" : t || "EDIT", Et = [];
223
223
  for (let e = 0; e < 256; ++e)
224
- vt.push((e + 256).toString(16).slice(1));
224
+ Et.push((e + 256).toString(16).slice(1));
225
225
  typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
226
- const Et = (e, t) => {
226
+ const vt = (e, t) => {
227
227
  const n = new Set(e.bodies.map((o) => o.id));
228
228
  return t.bodies.filter((o) => !n.has(o.id));
229
229
  }, Tt = (e, t) => {
@@ -231,9 +231,9 @@ const Et = (e, t) => {
231
231
  return e.bodies.filter((o) => !n.has(o.id));
232
232
  }, Bt = (e, t) => t.bodies.map((n) => {
233
233
  const o = e.bodies.find((i) => i.id === n.id);
234
- return { newBody: n, oldBody: o && !Y(o, n) ? o : void 0 };
235
- }).filter(({ oldBody: n }) => n), St = (e, t) => !Y(e.target, t.target), ot = (e, t) => {
236
- const n = Et(e, t), o = Tt(e, t), i = Bt(e, t);
234
+ return { newBody: n, oldBody: o && !U(o, n) ? o : void 0 };
235
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), St = (e, t) => !U(e.target, t.target), ot = (e, t) => {
236
+ const n = vt(e, t), o = Tt(e, t), i = Bt(e, t);
237
237
  return {
238
238
  oldValue: e,
239
239
  newValue: t,
@@ -244,13 +244,13 @@ const Et = (e, t) => {
244
244
  };
245
245
  };
246
246
  var C = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e))(C || {});
247
- const Lt = (e, t) => {
247
+ const Mt = (e, t) => {
248
248
  var n, o;
249
249
  const { changes: i, origin: s } = t;
250
250
  if (!(!e.options.origin || e.options.origin === s))
251
251
  return !1;
252
252
  if (e.options.ignore) {
253
- const { ignore: a } = e.options, r = (d) => (d == null ? void 0 : d.length) > 0;
253
+ const { ignore: a } = e.options, r = (d) => d && d.length > 0;
254
254
  if (!(r(i.created) || r(i.deleted))) {
255
255
  const d = (n = i.updated) == null ? void 0 : n.some((b) => r(b.bodiesCreated) || r(b.bodiesDeleted) || r(b.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((b) => b.targetUpdated);
256
256
  if (a === "BODY_ONLY" && d && !u || a === "TARGET_ONLY" && u && !d)
@@ -259,26 +259,26 @@ const Lt = (e, t) => {
259
259
  }
260
260
  if (e.options.annotations) {
261
261
  const a = /* @__PURE__ */ new Set([
262
- ...i.created.map((r) => r.id),
263
- ...i.deleted.map((r) => r.id),
264
- ...i.updated.map(({ oldValue: r }) => r.id)
262
+ ...(i.created || []).map((r) => r.id),
263
+ ...(i.deleted || []).map((r) => r.id),
264
+ ...(i.updated || []).map(({ oldValue: r }) => r.id)
265
265
  ]);
266
266
  return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((r) => a.has(r));
267
267
  } else
268
268
  return !0;
269
- }, Mt = (e, t) => {
269
+ }, Lt = (e, t) => {
270
270
  const n = new Set((e.created || []).map((h) => h.id)), o = new Set((e.updated || []).map(({ newValue: h }) => h.id)), i = new Set((t.created || []).map((h) => h.id)), s = new Set((t.deleted || []).map((h) => h.id)), a = new Set((t.updated || []).map(({ oldValue: h }) => h.id)), r = new Set((t.updated || []).filter(({ oldValue: h }) => n.has(h.id) || o.has(h.id)).map(({ oldValue: h }) => h.id)), d = [
271
- ...(e.created || []).filter((h) => !s.has(h.id)).map((h) => a.has(h.id) ? t.updated.find(({ oldValue: E }) => E.id === h.id).newValue : h),
271
+ ...(e.created || []).filter((h) => !s.has(h.id)).map((h) => a.has(h.id) ? t.updated.find(({ oldValue: v }) => v.id === h.id).newValue : h),
272
272
  ...t.created || []
273
273
  ], u = [
274
274
  ...(e.deleted || []).filter((h) => !i.has(h.id)),
275
275
  ...(t.deleted || []).filter((h) => !n.has(h.id))
276
276
  ], b = [
277
277
  ...(e.updated || []).filter(({ newValue: h }) => !s.has(h.id)).map((h) => {
278
- const { oldValue: E, newValue: m } = h;
278
+ const { oldValue: v, newValue: m } = h;
279
279
  if (a.has(m.id)) {
280
- const w = t.updated.find((L) => L.oldValue.id === m.id).newValue;
281
- return ot(E, w);
280
+ const x = t.updated.find((M) => M.oldValue.id === m.id).newValue;
281
+ return ot(v, x);
282
282
  } else
283
283
  return h;
284
284
  }),
@@ -286,61 +286,61 @@ const Lt = (e, t) => {
286
286
  ];
287
287
  return { created: d, deleted: u, updated: b };
288
288
  }, Ct = (e) => e.id !== void 0, Rt = () => {
289
- const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = [], o = (f, x = {}) => n.push({ onChange: f, options: x }), i = (f) => {
290
- const x = n.findIndex((A) => A.onChange == f);
291
- x > -1 && n.splice(x, 1);
292
- }, s = (f, x) => {
289
+ const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = [], o = (f, w = {}) => n.push({ onChange: f, options: w }), i = (f) => {
290
+ const w = n.findIndex((A) => A.onChange == f);
291
+ w > -1 && n.splice(w, 1);
292
+ }, s = (f, w) => {
293
293
  const A = {
294
294
  origin: f,
295
295
  changes: {
296
- created: x.created || [],
297
- updated: x.updated || [],
298
- deleted: x.deleted || []
296
+ created: w.created || [],
297
+ updated: w.updated || [],
298
+ deleted: w.deleted || []
299
299
  },
300
300
  state: [...e.values()]
301
301
  };
302
302
  n.forEach((B) => {
303
- Lt(B, A) && B.onChange(A);
303
+ Mt(B, A) && B.onChange(A);
304
304
  });
305
- }, a = (f, x = C.LOCAL) => {
305
+ }, a = (f, w = C.LOCAL) => {
306
306
  if (e.get(f.id))
307
307
  throw Error(`Cannot add annotation ${f.id} - exists already`);
308
- e.set(f.id, f), f.bodies.forEach((A) => t.set(A.id, f.id)), s(x, { created: [f] });
309
- }, r = (f, x) => {
310
- const A = typeof f == "string" ? x : f, B = typeof f == "string" ? f : f.id, S = e.get(B);
308
+ e.set(f.id, f), f.bodies.forEach((A) => t.set(A.id, f.id)), s(w, { created: [f] });
309
+ }, r = (f, w) => {
310
+ const A = typeof f == "string" ? w : f, B = typeof f == "string" ? f : f.id, S = e.get(B);
311
311
  if (S) {
312
312
  const R = ot(S, A);
313
313
  return B === A.id ? e.set(B, A) : (e.delete(B), e.set(A.id, A)), S.bodies.forEach((X) => t.delete(X.id)), A.bodies.forEach((X) => t.set(X.id, A.id)), R;
314
314
  } else
315
315
  console.warn(`Cannot update annotation ${B} - does not exist`);
316
- }, d = (f, x = C.LOCAL, A = C.LOCAL) => {
317
- const B = Ct(x) ? A : x, S = r(f, x);
316
+ }, d = (f, w = C.LOCAL, A = C.LOCAL) => {
317
+ const B = Ct(w) ? A : w, S = r(f, w);
318
318
  S && s(B, { updated: [S] });
319
- }, u = (f, x = C.LOCAL) => {
319
+ }, u = (f, w = C.LOCAL) => {
320
320
  const A = f.reduce((B, S) => {
321
321
  const R = r(S);
322
322
  return R ? [...B, R] : B;
323
323
  }, []);
324
- A.length > 0 && s(x, { updated: A });
325
- }, b = (f, x = C.LOCAL) => {
324
+ A.length > 0 && s(w, { updated: A });
325
+ }, b = (f, w = C.LOCAL) => {
326
326
  const A = e.get(f.annotation);
327
327
  if (A) {
328
328
  const B = {
329
329
  ...A,
330
330
  bodies: [...A.bodies, f]
331
331
  };
332
- e.set(A.id, B), t.set(f.id, B.id), s(x, { updated: [{
332
+ e.set(A.id, B), t.set(f.id, B.id), s(w, { updated: [{
333
333
  oldValue: A,
334
334
  newValue: B,
335
335
  bodiesCreated: [f]
336
336
  }] });
337
337
  } else
338
338
  console.warn(`Attempt to add body to missing annotation: ${f.annotation}`);
339
- }, h = () => [...e.values()], E = (f = C.LOCAL) => {
340
- const x = [...e.values()];
341
- e.clear(), t.clear(), s(f, { deleted: x });
342
- }, m = (f, x = !0, A = C.LOCAL) => {
343
- if (x) {
339
+ }, h = () => [...e.values()], v = (f = C.LOCAL) => {
340
+ const w = [...e.values()];
341
+ e.clear(), t.clear(), s(f, { deleted: w });
342
+ }, m = (f, w = !0, A = C.LOCAL) => {
343
+ if (w) {
344
344
  const B = [...e.values()];
345
345
  e.clear(), t.clear(), f.forEach((S) => {
346
346
  e.set(S.id, S), S.bodies.forEach((R) => t.set(R.id, S.id));
@@ -356,21 +356,21 @@ const Lt = (e, t) => {
356
356
  e.set(S.id, S), S.bodies.forEach((R) => t.set(R.id, S.id));
357
357
  }), s(A, { created: f });
358
358
  }
359
- }, w = (f) => {
360
- const x = typeof f == "string" ? f : f.id, A = e.get(x);
359
+ }, x = (f) => {
360
+ const w = typeof f == "string" ? f : f.id, A = e.get(w);
361
361
  if (A)
362
- return e.delete(x), A.bodies.forEach((B) => t.delete(B.id)), A;
363
- console.warn(`Attempt to delete missing annotation: ${x}`);
364
- }, L = (f, x = C.LOCAL) => {
365
- const A = w(f);
366
- A && s(x, { deleted: [A] });
367
- }, y = (f, x = C.LOCAL) => {
362
+ return e.delete(w), A.bodies.forEach((B) => t.delete(B.id)), A;
363
+ console.warn(`Attempt to delete missing annotation: ${w}`);
364
+ }, M = (f, w = C.LOCAL) => {
365
+ const A = x(f);
366
+ A && s(w, { deleted: [A] });
367
+ }, y = (f, w = C.LOCAL) => {
368
368
  const A = f.reduce((B, S) => {
369
- const R = w(S);
369
+ const R = x(S);
370
370
  return R ? [...B, R] : B;
371
371
  }, []);
372
- A.length > 0 && s(x, { deleted: A });
373
- }, l = (f, x = C.LOCAL) => {
372
+ A.length > 0 && s(w, { deleted: A });
373
+ }, l = (f, w = C.LOCAL) => {
374
374
  const A = e.get(f.annotation);
375
375
  if (A) {
376
376
  const B = A.bodies.find((S) => S.id === f.id);
@@ -380,7 +380,7 @@ const Lt = (e, t) => {
380
380
  ...A,
381
381
  bodies: A.bodies.filter((R) => R.id !== f.id)
382
382
  };
383
- e.set(A.id, S), s(x, { updated: [{
383
+ e.set(A.id, S), s(w, { updated: [{
384
384
  oldValue: A,
385
385
  newValue: S,
386
386
  bodiesDeleted: [B]
@@ -390,54 +390,54 @@ const Lt = (e, t) => {
390
390
  } else
391
391
  console.warn(`Attempt to delete body from missing annotation ${f.annotation}`);
392
392
  }, c = (f) => {
393
- const x = e.get(f);
394
- return x ? { ...x } : void 0;
393
+ const w = e.get(f);
394
+ return w ? { ...w } : void 0;
395
395
  }, g = (f) => {
396
- const x = t.get(f);
397
- if (x) {
398
- const A = c(x).bodies.find((B) => B.id === f);
396
+ const w = t.get(f);
397
+ if (w) {
398
+ const A = c(w).bodies.find((B) => B.id === f);
399
399
  if (A)
400
400
  return A;
401
401
  console.error(`Store integrity error: body ${f} in index, but not in annotation`);
402
402
  } else
403
403
  console.warn(`Attempt to retrieve missing body: ${f}`);
404
- }, p = (f, x) => {
405
- if (f.annotation !== x.annotation)
404
+ }, p = (f, w) => {
405
+ if (f.annotation !== w.annotation)
406
406
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
407
407
  const A = e.get(f.annotation);
408
408
  if (A) {
409
409
  const B = A.bodies.find((R) => R.id === f.id), S = {
410
410
  ...A,
411
- bodies: A.bodies.map((R) => R.id === B.id ? x : R)
411
+ bodies: A.bodies.map((R) => R.id === B.id ? w : R)
412
412
  };
413
- return e.set(A.id, S), B.id !== x.id && (t.delete(B.id), t.set(x.id, S.id)), {
413
+ return e.set(A.id, S), B.id !== w.id && (t.delete(B.id), t.set(w.id, S.id)), {
414
414
  oldValue: A,
415
415
  newValue: S,
416
- bodiesUpdated: [{ oldBody: B, newBody: x }]
416
+ bodiesUpdated: [{ oldBody: B, newBody: w }]
417
417
  };
418
418
  } else
419
419
  console.warn(`Attempt to add body to missing annotation ${f.annotation}`);
420
- }, v = (f, x, A = C.LOCAL) => {
421
- const B = p(f, x);
422
- s(A, { updated: [B] });
423
- }, T = (f, x = C.LOCAL) => {
424
- const A = f.map((B) => p({ id: B.id, annotation: B.annotation }, B));
425
- s(x, { updated: A });
426
- }, M = (f) => {
427
- const x = e.get(f.annotation);
428
- if (x) {
420
+ }, E = (f, w, A = C.LOCAL) => {
421
+ const B = p(f, w);
422
+ B && s(A, { updated: [B] });
423
+ }, T = (f, w = C.LOCAL) => {
424
+ const A = f.map((B) => p({ id: B.id, annotation: B.annotation }, B)).filter(Boolean);
425
+ s(w, { updated: A });
426
+ }, L = (f) => {
427
+ const w = e.get(f.annotation);
428
+ if (w) {
429
429
  const A = {
430
- ...x,
430
+ ...w,
431
431
  target: {
432
- ...x.target,
432
+ ...w.target,
433
433
  ...f
434
434
  }
435
435
  };
436
- return e.set(x.id, A), {
437
- oldValue: x,
436
+ return e.set(w.id, A), {
437
+ oldValue: w,
438
438
  newValue: A,
439
439
  targetUpdated: {
440
- oldTarget: x.target,
440
+ oldTarget: w.target,
441
441
  newTarget: f
442
442
  }
443
443
  };
@@ -452,79 +452,78 @@ const Lt = (e, t) => {
452
452
  bulkDeleteAnnotation: y,
453
453
  bulkUpdateAnnotation: u,
454
454
  bulkUpdateBodies: T,
455
- bulkUpdateTargets: (f, x = C.LOCAL) => {
456
- const A = f.map(M).filter((B) => B);
457
- A.length > 0 && s(x, { updated: A });
455
+ bulkUpdateTargets: (f, w = C.LOCAL) => {
456
+ const A = f.map((B) => L(B)).filter(Boolean);
457
+ A.length > 0 && s(w, { updated: A });
458
458
  },
459
- clear: E,
460
- deleteAnnotation: L,
459
+ clear: v,
460
+ deleteAnnotation: M,
461
461
  deleteBody: l,
462
462
  getAnnotation: c,
463
463
  getBody: g,
464
464
  observe: o,
465
465
  unobserve: i,
466
466
  updateAnnotation: d,
467
- updateBody: v,
468
- updateTarget: (f, x = C.LOCAL) => {
469
- const A = M(f);
470
- A && s(x, { updated: [A] });
467
+ updateBody: E,
468
+ updateTarget: (f, w = C.LOCAL) => {
469
+ const A = L(f);
470
+ A && s(w, { updated: [A] });
471
471
  }
472
472
  };
473
473
  };
474
474
  let Ot = () => ({
475
475
  emit(e, ...t) {
476
- let n = this.events[e] || [];
477
- for (let o = 0, i = n.length; o < i; o++)
478
- n[o](...t);
476
+ for (let n = 0, o = this.events[e] || [], i = o.length; n < i; n++)
477
+ o[n](...t);
479
478
  },
480
479
  events: {},
481
480
  on(e, t) {
482
481
  var n;
483
- return (n = this.events[e]) != null && n.push(t) || (this.events[e] = [t]), () => {
482
+ return ((n = this.events)[e] || (n[e] = [])).push(t), () => {
484
483
  var o;
485
484
  this.events[e] = (o = this.events[e]) == null ? void 0 : o.filter((i) => t !== i);
486
485
  };
487
486
  }
488
487
  });
489
- const Xt = 250, Ut = (e) => {
488
+ const Xt = 250, Yt = (e) => {
490
489
  const t = Ot(), n = [];
491
490
  let o = -1, i = !1, s = 0;
492
491
  const a = (m) => {
493
492
  if (!i) {
494
- const { changes: w } = m, L = performance.now();
495
- if (L - s > Xt)
496
- n.splice(o + 1), n.push(w), o = n.length - 1;
493
+ const { changes: x } = m, M = performance.now();
494
+ if (M - s > Xt)
495
+ n.splice(o + 1), n.push(x), o = n.length - 1;
497
496
  else {
498
497
  const y = n.length - 1;
499
- n[y] = Mt(n[y], w);
498
+ n[y] = Lt(n[y], x);
500
499
  }
501
- s = L;
500
+ s = M;
502
501
  }
503
502
  i = !1;
504
503
  };
505
504
  e.observe(a, { origin: C.LOCAL });
506
- const r = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkDeleteAnnotation(m), d = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkAddAnnotation(m, !1), u = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkUpdateAnnotation(m.map(({ oldValue: w }) => w)), b = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkUpdateAnnotation(m.map(({ newValue: w }) => w)), h = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkAddAnnotation(m, !1), E = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkDeleteAnnotation(m);
505
+ const r = (m) => m && m.length > 0 && e.bulkDeleteAnnotation(m), d = (m) => m && m.length > 0 && e.bulkAddAnnotation(m, !1), u = (m) => m && m.length > 0 && e.bulkUpdateAnnotation(m.map(({ oldValue: x }) => x)), b = (m) => m && m.length > 0 && e.bulkUpdateAnnotation(m.map(({ newValue: x }) => x)), h = (m) => m && m.length > 0 && e.bulkAddAnnotation(m, !1), v = (m) => m && m.length > 0 && e.bulkDeleteAnnotation(m);
507
506
  return {
508
507
  canRedo: () => n.length - 1 > o,
509
508
  canUndo: () => o > -1,
510
509
  destroy: () => e.unobserve(a),
511
- on: (m, w) => t.on(m, w),
510
+ on: (m, x) => t.on(m, x),
512
511
  redo: () => {
513
512
  if (n.length - 1 > o) {
514
513
  i = !0;
515
- const { created: m, updated: w, deleted: L } = n[o + 1];
516
- d(m), b(w), E(L), t.emit("redo", n[o + 1]), o += 1;
514
+ const { created: m, updated: x, deleted: M } = n[o + 1];
515
+ d(m), b(x), v(M), t.emit("redo", n[o + 1]), o += 1;
517
516
  }
518
517
  },
519
518
  undo: () => {
520
519
  if (o > -1) {
521
520
  i = !0;
522
- const { created: m, updated: w, deleted: L } = n[o];
523
- r(m), u(w), h(L), t.emit("undo", n[o]), o -= 1;
521
+ const { created: m, updated: x, deleted: M } = n[o];
522
+ r(m), u(x), h(M), t.emit("undo", n[o]), o -= 1;
524
523
  }
525
524
  }
526
525
  };
527
- }, Yt = () => {
526
+ }, Ut = () => {
528
527
  const { subscribe: e, set: t } = J([]);
529
528
  return {
530
529
  subscribe: e,
@@ -533,27 +532,27 @@ const Xt = 250, Ut = (e) => {
533
532
  }, Dt = (e, t, n, o) => {
534
533
  const { store: i, selection: s, hover: a, viewport: r } = e, d = /* @__PURE__ */ new Map();
535
534
  let u = [], b, h;
536
- const E = (l, c) => {
535
+ const v = (l, c) => {
537
536
  d.has(l) ? d.get(l).push(c) : d.set(l, [c]);
538
537
  }, m = (l, c) => {
539
538
  const g = d.get(l);
540
539
  g && g.indexOf(c) > 0 && g.splice(g.indexOf(c), 1);
541
- }, w = (l, c, g) => {
540
+ }, x = (l, c, g) => {
542
541
  d.has(l) && setTimeout(() => {
543
542
  d.get(l).forEach((p) => {
544
543
  if (n) {
545
- const v = Array.isArray(c) ? c.map((M) => n.serialize(M)) : n.serialize(c), T = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
546
- p(v, T);
544
+ const E = Array.isArray(c) ? c.map((L) => n.serialize(L)) : n.serialize(c), T = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
545
+ p(E, T);
547
546
  } else
548
547
  p(c, g);
549
548
  });
550
549
  }, 1);
551
- }, L = () => {
552
- const { selected: l } = s, c = l.map(({ id: g }) => i.getAnnotation(g));
550
+ }, M = () => {
551
+ const { selected: l } = s, c = (l || []).map(({ id: g }) => i.getAnnotation(g));
553
552
  c.forEach((g) => {
554
- const p = u.find((v) => v.id === g.id);
555
- (!p || !Y(p, g)) && w("updateAnnotation", g, p);
556
- }), u = u.map((g) => c.find(({ id: v }) => v === g.id) || g);
553
+ const p = u.find((E) => E.id === g.id);
554
+ (!p || !U(p, g)) && x("updateAnnotation", g, p);
555
+ }), u = u.map((g) => c.find(({ id: E }) => E === g.id) || g);
557
556
  };
558
557
  s.subscribe(({ selected: l }) => {
559
558
  if (!(u.length === 0 && l.length === 0)) {
@@ -562,13 +561,13 @@ const Xt = 250, Ut = (e) => {
562
561
  else if (u.length > 0 && l.length === 0)
563
562
  u.forEach((c) => {
564
563
  const g = i.getAnnotation(c.id);
565
- g && !Y(g, c) && w("updateAnnotation", g, c);
564
+ g && !U(g, c) && x("updateAnnotation", g, c);
566
565
  }), u = [];
567
566
  else {
568
567
  const c = new Set(u.map((p) => p.id)), g = new Set(l.map(({ id: p }) => p));
569
568
  u.filter((p) => !g.has(p.id)).forEach((p) => {
570
- const v = i.getAnnotation(p.id);
571
- v && !Y(v, p) && w("updateAnnotation", v, p);
569
+ const E = i.getAnnotation(p.id);
570
+ E && !U(E, p) && x("updateAnnotation", E, p);
572
571
  }), u = [
573
572
  // Remove annotations that were deselected
574
573
  ...u.filter((p) => g.has(p.id)),
@@ -576,40 +575,42 @@ const Xt = 250, Ut = (e) => {
576
575
  ...l.filter(({ id: p }) => !c.has(p)).map(({ id: p }) => i.getAnnotation(p))
577
576
  ];
578
577
  }
579
- w("selectionChanged", u);
578
+ x("selectionChanged", u);
580
579
  }
581
580
  }), a.subscribe((l) => {
582
- !b && l ? w("mouseEnterAnnotation", i.getAnnotation(l)) : b && !l ? w("mouseLeaveAnnotation", i.getAnnotation(b)) : b && l && (w("mouseLeaveAnnotation", i.getAnnotation(b)), w("mouseEnterAnnotation", i.getAnnotation(l))), b = l;
583
- }), r == null || r.subscribe((l) => w("viewportIntersect", l.map(i.getAnnotation))), i.observe((l) => {
584
- o && (h && clearTimeout(h), h = setTimeout(L, 1e3));
581
+ !b && l ? x("mouseEnterAnnotation", i.getAnnotation(l)) : b && !l ? x("mouseLeaveAnnotation", i.getAnnotation(b)) : b && l && (x("mouseLeaveAnnotation", i.getAnnotation(b)), x("mouseEnterAnnotation", i.getAnnotation(l))), b = l;
582
+ }), r == null || r.subscribe((l) => x("viewportIntersect", l.map((c) => i.getAnnotation(c)))), i.observe((l) => {
583
+ o && (h && clearTimeout(h), h = setTimeout(M, 1e3));
585
584
  const { created: c, deleted: g } = l.changes;
586
- c.forEach((p) => w("createAnnotation", p)), g.forEach((p) => w("deleteAnnotation", p)), l.changes.updated.filter((p) => [
585
+ (c || []).forEach((p) => x("createAnnotation", p)), (g || []).forEach((p) => x("deleteAnnotation", p)), (l.changes.updated || []).filter((p) => [
587
586
  ...p.bodiesCreated || [],
588
587
  ...p.bodiesDeleted || [],
589
588
  ...p.bodiesUpdated || []
590
- ].length > 0).forEach(({ oldValue: p, newValue: v }) => {
591
- const T = u.find((M) => M.id === p.id) || p;
592
- u = u.map((M) => M.id === p.id ? v : M), w("updateAnnotation", v, T);
589
+ ].length > 0).forEach(({ oldValue: p, newValue: E }) => {
590
+ const T = u.find((L) => L.id === p.id) || p;
591
+ u = u.map((L) => L.id === p.id ? E : L), x("updateAnnotation", E, T);
593
592
  });
594
593
  }, { origin: C.LOCAL }), i.observe((l) => {
595
594
  if (u) {
596
- const c = new Set(u.map((p) => p.id)), g = l.changes.updated.filter(({ newValue: p }) => c.has(p.id)).map(({ newValue: p }) => p);
595
+ const c = new Set(u.map((p) => p.id)), g = (l.changes.updated || []).filter(({ newValue: p }) => c.has(p.id)).map(({ newValue: p }) => p);
597
596
  g.length > 0 && (u = u.map((p) => g.find((T) => T.id === p.id) || p));
598
597
  }
599
598
  }, { origin: C.REMOTE });
600
599
  const y = (l) => (c) => {
601
- const { created: g, deleted: p, updated: v } = c;
602
- g.forEach((T) => w("createAnnotation", T)), p.forEach((T) => w("deleteAnnotation", T)), l ? v.forEach((T) => w("updateAnnotation", T.oldValue, T.newValue)) : v.forEach((T) => w("updateAnnotation", T.newValue, T.oldValue));
600
+ const { created: g, deleted: p, updated: E } = c;
601
+ (g || []).forEach((T) => x("createAnnotation", T)), (p || []).forEach((T) => x("deleteAnnotation", T)), l ? (E || []).forEach((T) => x("updateAnnotation", T.oldValue, T.newValue)) : (E || []).forEach((T) => x("updateAnnotation", T.newValue, T.oldValue));
603
602
  };
604
- return t.on("undo", y(!0)), t.on("redo", y(!1)), { on: E, off: m, emit: w };
603
+ return t.on("undo", y(!0)), t.on("redo", y(!1)), { on: v, off: m, emit: x };
605
604
  }, It = (e) => (t) => t.reduce((n, o) => {
606
605
  const { parsed: i, error: s } = e.parse(o);
607
606
  return s ? {
608
607
  parsed: n.parsed,
609
608
  failed: [...n.failed, o]
610
- } : {
609
+ } : i ? {
611
610
  parsed: [...n.parsed, i],
612
611
  failed: n.failed
612
+ } : {
613
+ ...n
613
614
  };
614
615
  }, { parsed: [], failed: [] }), Vt = (e, t, n) => {
615
616
  const { store: o, selection: i } = e, s = (y) => {
@@ -623,15 +624,17 @@ const Xt = 250, Ut = (e) => {
623
624
  return n && l ? n.serialize(l) : l;
624
625
  }, u = () => n ? o.all().map(n.serialize) : o.all(), b = () => {
625
626
  var y;
626
- const l = (((y = i.selected) == null ? void 0 : y.map((c) => c.id)) || []).map((c) => o.getAnnotation(c));
627
+ const l = (((y = i.selected) == null ? void 0 : y.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
627
628
  return n ? l.map(n.serialize) : l;
628
- }, h = (y) => fetch(y).then((l) => l.json()).then((l) => (m(l), l)), E = (y) => {
629
+ }, h = (y) => fetch(y).then((l) => l.json()).then((l) => (m(l), l)), v = (y) => {
629
630
  if (typeof y == "string") {
630
631
  const l = o.getAnnotation(y);
631
- return o.deleteAnnotation(y), n ? n.serialize(l) : l;
632
+ if (o.deleteAnnotation(y), l)
633
+ return n ? n.serialize(l) : l;
632
634
  } else {
633
635
  const l = n ? n.parse(y).parsed : y;
634
- return o.deleteAnnotation(l), y;
636
+ if (l)
637
+ return o.deleteAnnotation(l), y;
635
638
  }
636
639
  }, m = (y) => {
637
640
  if (n) {
@@ -639,9 +642,9 @@ const Xt = 250, Ut = (e) => {
639
642
  c.length > 0 && console.warn(`Discarded ${c.length} invalid annotations`, c), o.bulkAddAnnotation(l, !0, C.REMOTE);
640
643
  } else
641
644
  o.bulkAddAnnotation(y, !0, C.REMOTE);
642
- }, w = (y) => {
645
+ }, x = (y) => {
643
646
  y ? i.setSelected(y) : i.clear();
644
- }, L = (y) => {
647
+ }, M = (y) => {
645
648
  if (n) {
646
649
  const l = n.parse(y).parsed, c = n.serialize(o.getAnnotation(l.id));
647
650
  return o.updateAnnotation(l), c;
@@ -661,11 +664,11 @@ const Xt = 250, Ut = (e) => {
661
664
  getSelected: b,
662
665
  loadAnnotations: h,
663
666
  redo: t.redo,
664
- removeAnnotation: E,
667
+ removeAnnotation: v,
665
668
  setAnnotations: m,
666
- setSelected: w,
669
+ setSelected: x,
667
670
  undo: t.undo,
668
- updateAnnotation: L
671
+ updateAnnotation: M
669
672
  };
670
673
  };
671
674
  let _t = (e) => crypto.getRandomValues(new Uint8Array(e)), kt = (e, t, n) => {
@@ -691,14 +694,14 @@ function it(e, t, n, o, i) {
691
694
  var s = o - n + 1, a = t - n + 1, r = Math.log(s), d = 0.5 * Math.exp(2 * r / 3), u = 0.5 * Math.sqrt(r * d * (s - d) / s) * (a - s / 2 < 0 ? -1 : 1), b = Math.max(n, Math.floor(t - a * d / s + u)), h = Math.min(o, Math.floor(t + (s - a) * d / s + u));
692
695
  it(e, t, b, h, i);
693
696
  }
694
- var E = e[t], m = n, w = o;
695
- for (_(e, n, t), i(e[o], E) > 0 && _(e, n, o); m < w; ) {
696
- for (_(e, m, w), m++, w--; i(e[m], E) < 0; )
697
+ var v = e[t], m = n, x = o;
698
+ for (_(e, n, t), i(e[o], v) > 0 && _(e, n, o); m < x; ) {
699
+ for (_(e, m, x), m++, x--; i(e[m], v) < 0; )
697
700
  m++;
698
- for (; i(e[w], E) > 0; )
699
- w--;
701
+ for (; i(e[x], v) > 0; )
702
+ x--;
700
703
  }
701
- i(e[n], E) === 0 ? _(e, n, w) : (w++, _(e, w, o)), w <= t && (n = w + 1), t <= w && (o = w - 1);
704
+ i(e[n], v) === 0 ? _(e, n, x) : (x++, _(e, x, o)), x <= t && (n = x + 1), t <= x && (o = x - 1);
702
705
  }
703
706
  }
704
707
  function _(e, t, n) {
@@ -824,9 +827,9 @@ class $t {
824
827
  for (let b = n; b <= o; b += u) {
825
828
  const h = Math.min(b + u - 1, o);
826
829
  tt(t, b, h, d, this.compareMinY);
827
- for (let E = b; E <= h; E += d) {
828
- const m = Math.min(E + d - 1, h);
829
- r.children.push(this._build(t, E, m, i - 1));
830
+ for (let v = b; v <= h; v += d) {
831
+ const m = Math.min(v + d - 1, h);
832
+ r.children.push(this._build(t, v, m, i - 1));
830
833
  }
831
834
  }
832
835
  return I(r, this.toBBox), r;
@@ -1025,14 +1028,14 @@ const jt = (e, t) => {
1025
1028
  return e;
1026
1029
  }, ee = (e, t) => {
1027
1030
  const n = new $t(), o = /* @__PURE__ */ new Map(), i = (l) => {
1028
- const c = t.getBoundingClientRect(), p = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : k(l, t), v = Array.from(p.selector.range.getClientRects()), T = Qt(v);
1029
- return T.map((M) => {
1030
- const { x: f, y: x, width: A, height: B } = M;
1031
+ const c = t.getBoundingClientRect(), p = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : k(l, t), E = Array.from(p.selector.range.getClientRects()), T = Qt(E);
1032
+ return T.map((L) => {
1033
+ const { x: f, y: w, width: A, height: B } = L;
1031
1034
  return {
1032
1035
  minX: f - c.x,
1033
- minY: x - c.y,
1036
+ minY: w - c.y,
1034
1037
  maxX: f - c.x + A,
1035
- maxY: x - c.y + B,
1038
+ maxY: w - c.y + B,
1036
1039
  annotation: {
1037
1040
  id: l.annotation,
1038
1041
  rects: T
@@ -1050,9 +1053,9 @@ const jt = (e, t) => {
1050
1053
  d(l), r(l);
1051
1054
  }, b = (l, c = !0) => {
1052
1055
  c && a();
1053
- const g = l.map((v) => ({ target: v, rects: i(v) }));
1054
- g.forEach(({ target: v, rects: T }) => o.set(v.annotation, T));
1055
- const p = g.reduce((v, { rects: T }) => [...v, ...T], []);
1056
+ const g = l.map((E) => ({ target: E, rects: i(E) }));
1057
+ g.forEach(({ target: E, rects: T }) => o.set(E.annotation, T));
1058
+ const p = g.reduce((E, { rects: T }) => [...E, ...T], []);
1056
1059
  n.load(p);
1057
1060
  }, h = (l, c) => {
1058
1061
  const g = n.search({
@@ -1060,19 +1063,19 @@ const jt = (e, t) => {
1060
1063
  minY: c,
1061
1064
  maxX: l,
1062
1065
  maxY: c
1063
- }), p = (v) => v.annotation.rects.reduce((T, M) => T + M.width * M.height, 0);
1066
+ }), p = (E) => E.annotation.rects.reduce((T, L) => T + L.width * L.height, 0);
1064
1067
  if (g.length > 0)
1065
- return g.sort((v, T) => p(v) - p(T)), g[0].annotation.id;
1066
- }, E = (l) => {
1068
+ return g.sort((E, T) => p(E) - p(T)), g[0].annotation.id;
1069
+ }, v = (l) => {
1067
1070
  const c = m(l);
1068
1071
  if (c.length === 0)
1069
1072
  return;
1070
- let g = c[0].left, p = c[0].top, v = c[0].right, T = c[0].bottom;
1071
- for (let M = 1; M < c.length; M++) {
1072
- const f = c[M];
1073
- g = Math.min(g, f.left), p = Math.min(p, f.top), v = Math.max(v, f.right), T = Math.max(T, f.bottom);
1073
+ let g = c[0].left, p = c[0].top, E = c[0].right, T = c[0].bottom;
1074
+ for (let L = 1; L < c.length; L++) {
1075
+ const f = c[L];
1076
+ g = Math.min(g, f.left), p = Math.min(p, f.top), E = Math.max(E, f.right), T = Math.max(T, f.bottom);
1074
1077
  }
1075
- return new DOMRect(g, p, v - g, T - p);
1078
+ return new DOMRect(g, p, E - g, T - p);
1076
1079
  }, m = (l) => {
1077
1080
  const c = o.get(l);
1078
1081
  return c ? c[0].annotation.rects : [];
@@ -1081,7 +1084,7 @@ const jt = (e, t) => {
1081
1084
  all: s,
1082
1085
  clear: a,
1083
1086
  getAt: h,
1084
- getBoundsForAnnotation: E,
1087
+ getBoundsForAnnotation: v,
1085
1088
  getDOMRectsForAnnotation: m,
1086
1089
  getIntersectingRects: (l, c, g, p) => n.search({ minX: l, minY: c, maxX: g, maxY: p }),
1087
1090
  insert: r,
@@ -1095,14 +1098,14 @@ const jt = (e, t) => {
1095
1098
  const { range: t } = e.target.selector;
1096
1099
  return t instanceof Range && !t.collapsed;
1097
1100
  }, ne = (e, t) => {
1098
- const n = Rt(), o = ee(n, e), i = wt(n, t), s = xt(n), a = Yt(), r = (y, l = C.LOCAL) => {
1101
+ const n = Rt(), o = ee(n, e), i = xt(n, t), s = wt(n), a = Ut(), r = (y, l = C.LOCAL) => {
1099
1102
  const c = y.target.selector.range instanceof Range ? y : { ...y, target: k(y.target, e) }, { range: g } = c.target.selector, p = g && !g.collapsed;
1100
1103
  return p && n.addAnnotation(c, l), p;
1101
1104
  }, d = (y, l = !0, c = C.LOCAL) => {
1102
- const g = y.map((v) => F(v) ? v : { ...v, target: k(v.target, e) });
1103
- if (g.some((v) => v.target.selector.range.collapsed)) {
1104
- const v = g.filter((T) => T.target.selector.range.collapsed);
1105
- return console.warn("Could not revive all targets"), console.warn(v), n.bulkAddAnnotation(g, l, c), v;
1105
+ const g = y.map((E) => F(E) ? E : { ...E, target: k(E.target, e) });
1106
+ if (g.some((E) => E.target.selector.range.collapsed)) {
1107
+ const E = g.filter((T) => T.target.selector.range.collapsed);
1108
+ return console.warn("Could not revive all targets"), console.warn(E), n.bulkAddAnnotation(g, l, c), E;
1106
1109
  } else
1107
1110
  return n.bulkAddAnnotation(g, l, c), [];
1108
1111
  }, u = (y, l = C.LOCAL) => {
@@ -1114,26 +1117,26 @@ const jt = (e, t) => {
1114
1117
  }, h = (y, l) => {
1115
1118
  const c = o.getAt(y, l);
1116
1119
  return c ? n.getAnnotation(c) : void 0;
1117
- }, E = (y, l, c, g) => {
1120
+ }, v = (y, l, c, g) => {
1118
1121
  const p = o.getIntersectingRects(y, l, c, g);
1119
1122
  return Array.from(new Set(p.map((T) => T.annotation.id))).map((T) => n.getAnnotation(T)).filter((T) => T);
1120
1123
  }, m = (y, l, c, g = 5) => {
1121
1124
  const p = o.getDOMRectsForAnnotation(y);
1122
1125
  if (p.length > 0) {
1123
1126
  if (l && c) {
1124
- const v = p.find(({ top: T, right: M, bottom: f, left: x }) => l >= x - g && l <= M + g && c >= T - g && c <= f + g);
1125
- if (v)
1126
- return v;
1127
+ const E = p.find(({ top: T, right: L, bottom: f, left: w }) => l >= w - g && l <= L + g && c >= T - g && c <= f + g);
1128
+ if (E)
1129
+ return E;
1127
1130
  }
1128
1131
  return o.getBoundsForAnnotation(y);
1129
1132
  }
1130
- }, w = (y, l, c, g) => {
1131
- const v = o.getIntersectingRects(y, l, c, g).reduce((T, M) => ((T[M.annotation.id] = T[M.annotation.id] || []).push(M), T), {});
1132
- return Object.entries(v).map(([T, M]) => ({
1133
+ }, x = (y, l, c, g) => {
1134
+ const E = o.getIntersectingRects(y, l, c, g).reduce((T, L) => ((T[L.annotation.id] = T[L.annotation.id] || []).push(L), T), {});
1135
+ return Object.entries(E).map(([T, L]) => ({
1133
1136
  annotation: n.getAnnotation(T),
1134
- rects: M.map(({ minX: f, minY: x, maxX: A, maxY: B }) => ({ x: f, y: x, width: A - f, height: B - x }))
1137
+ rects: L.map(({ minX: f, minY: w, maxX: A, maxY: B }) => ({ x: f, y: w, width: A - f, height: B - w }))
1135
1138
  }));
1136
- }, L = () => o.recalculate();
1139
+ }, M = () => o.recalculate();
1137
1140
  return n.observe(({ changes: y }) => {
1138
1141
  const l = (y.created || []).filter(F), c = (y.deleted || []).filter(F), g = (y.updated || []).filter((p) => F(p.newValue));
1139
1142
  l.length > 0 && o.set(l.map((p) => p.target), !1), (c == null ? void 0 : c.length) > 0 && c.forEach((p) => o.remove(p.target)), (g == null ? void 0 : g.length) > 0 && g.forEach(({ newValue: p }) => o.update(p.target));
@@ -1145,9 +1148,9 @@ const jt = (e, t) => {
1145
1148
  bulkUpdateTargets: b,
1146
1149
  getAnnotationBounds: m,
1147
1150
  getAt: h,
1148
- getIntersecting: E,
1149
- getIntersectingRects: w,
1150
- recalculatePositions: L,
1151
+ getIntersecting: v,
1152
+ getIntersectingRects: x,
1153
+ recalculatePositions: M,
1151
1154
  updateTarget: u
1152
1155
  },
1153
1156
  selection: i,
@@ -1162,20 +1165,25 @@ const jt = (e, t) => {
1162
1165
  t.font && (d.font = t.font);
1163
1166
  const h = n.get(s.id);
1164
1167
  if (h) {
1165
- const { x: E, y: m, height: w } = a[0];
1166
- d.fillStyle = h.appearance.color, d.fillRect(E - 2, m - 2.5, 2, w + 5);
1167
- const L = d.measureText(h.appearance.label), y = L.width + 6, l = L.actualBoundingBoxAscent + L.actualBoundingBoxDescent + 8, c = L.fontBoundingBoxAscent ? 8 : 6.5;
1168
- d.fillRect(E - 2, m - 2.5 - l, y, l), d.fillStyle = "#fff", d.fillText(h.appearance.label, E + 1, m - c), r.fillStyle = h.appearance.color, r.globalAlpha = u ? 0.45 : 0.18, a.forEach(({ x: g, y: p, width: v, height: T }) => r.fillRect(g, p - 2.5, v, T + 5));
1168
+ const { x: v, y: m, height: x } = a[0];
1169
+ d.fillStyle = h.appearance.color, d.fillRect(v - 2, m - 2.5, 2, x + 5);
1170
+ const M = d.measureText(h.appearance.label), y = M.width + 6, l = M.actualBoundingBoxAscent + M.actualBoundingBoxDescent + 8, c = M.fontBoundingBoxAscent ? 8 : 6.5;
1171
+ d.fillRect(v - 2, m - 2.5 - l, y, l), d.fillStyle = "#fff", d.fillText(h.appearance.label, v + 1, m - c), r.fillStyle = h.appearance.color, r.globalAlpha = u ? 0.45 : 0.18, a.forEach(({ x: g, y: p, width: E, height: T }) => r.fillRect(g, p - 2.5, E, T + 5));
1169
1172
  } else
1170
1173
  nt.paint(s, a, r, d, u, b);
1171
1174
  } };
1172
- }, st = (e) => e === null ? null : e.scrollHeight > e.clientHeight ? e : st(e.parentElement), ie = (e, t) => (n) => {
1175
+ }, st = (e) => {
1176
+ if (e === null)
1177
+ return document.scrollingElement;
1178
+ const { overflowY: t } = window.getComputedStyle(e);
1179
+ return t !== "visible" && t !== "hidden" && e.scrollHeight > e.clientHeight ? e : st(e.parentElement);
1180
+ }, ie = (e, t) => (n) => {
1173
1181
  const o = st(e);
1174
1182
  if (o) {
1175
1183
  const i = t.getAnnotation(n.id), { range: s } = i.target.selector;
1176
1184
  if (!s || s.collapsed)
1177
1185
  return !1;
1178
- const a = o.getBoundingClientRect(), r = o.clientHeight, d = o.clientWidth, u = i.target.selector.range.getBoundingClientRect(), { width: b, height: h } = t.getAnnotationBounds(n.id), E = u.top - a.top, m = u.left - a.left, w = o.parentElement ? o.scrollTop : 0, L = o.parentElement ? o.scrollLeft : 0, y = E + w - (r - h) / 2, l = m + L - (d - b) / 2;
1186
+ const a = o.getBoundingClientRect(), r = o.clientHeight, d = o.clientWidth, u = i.target.selector.range.getBoundingClientRect(), { width: b, height: h } = t.getAnnotationBounds(n.id), v = u.top - a.top, m = u.left - a.left, x = o.parentElement ? o.scrollTop : 0, M = o.parentElement ? o.scrollLeft : 0, y = v + x - (r - h) / 2, l = m + M - (d - b) / 2;
1179
1187
  return o.scroll({ top: y, left: l, behavior: "smooth" }), !0;
1180
1188
  }
1181
1189
  };
@@ -1216,12 +1224,12 @@ const de = (e, t, n) => {
1216
1224
  }, ue = (e, t, n) => {
1217
1225
  const { store: o, selection: i } = t;
1218
1226
  let s, a = null;
1219
- const r = (E) => s = E;
1227
+ const r = (v) => s = v;
1220
1228
  let d = !1, u;
1221
- e.addEventListener("selectstart", (E) => {
1229
+ e.addEventListener("selectstart", (v) => {
1222
1230
  if (!d)
1223
1231
  return;
1224
- !E.target.parentElement.closest(".not-annotatable") ? a = {
1232
+ !v.target.parentElement.closest(".not-annotatable") ? a = {
1225
1233
  annotation: ce(),
1226
1234
  selector: void 0,
1227
1235
  creator: s,
@@ -1229,17 +1237,17 @@ const de = (e, t, n) => {
1229
1237
  } : (a = null, u = void 0);
1230
1238
  });
1231
1239
  let b;
1232
- document.addEventListener("selectionchange", (E) => {
1240
+ document.addEventListener("selectionchange", (v) => {
1233
1241
  b && clearTimeout(b), b = setTimeout(() => h(), 50);
1234
1242
  });
1235
1243
  const h = () => {
1236
- var m, w;
1237
- const E = document.getSelection();
1238
- if (!E.isCollapsed && d && a) {
1239
- const L = Array.from(Array(E.rangeCount).keys()).map((c) => E.getRangeAt(c));
1240
- te(L[0]).toString() !== ((w = (m = a.selector) == null ? void 0 : m.range) == null ? void 0 : w.toString()) && (a = {
1244
+ var m, x;
1245
+ const v = document.getSelection();
1246
+ if (!v.isCollapsed && d && a) {
1247
+ const M = Array.from(Array(v.rangeCount).keys()).map((c) => v.getRangeAt(c));
1248
+ te(M[0]).toString() !== ((x = (m = a.selector) == null ? void 0 : m.range) == null ? void 0 : x.toString()) && (a = {
1241
1249
  ...a,
1242
- selector: de(L[0], e, n)
1250
+ selector: de(M[0], e, n)
1243
1251
  }, o.getAnnotation(a.annotation) ? o.updateTarget(a, C.LOCAL) : (o.addAnnotation({
1244
1252
  id: a.annotation,
1245
1253
  bodies: [],
@@ -1247,18 +1255,18 @@ const de = (e, t, n) => {
1247
1255
  }), i.clickSelect(a.annotation, u)));
1248
1256
  }
1249
1257
  };
1250
- return e.addEventListener("pointerdown", (E) => {
1251
- u = E, d = E.button === 0;
1252
- }), document.addEventListener("pointerup", (E) => {
1253
- var w;
1254
- u = E, !((w = E.target.parentElement) != null && w.closest(".not-annotatable") || !d) && setTimeout(() => {
1258
+ return e.addEventListener("pointerdown", (v) => {
1259
+ u = v, d = v.button === 0;
1260
+ }), document.addEventListener("pointerup", (v) => {
1261
+ var x;
1262
+ u = v, !((x = v.target.parentElement) != null && x.closest(".not-annotatable") || !d) && setTimeout(() => {
1255
1263
  if (a != null && a.selector)
1256
- o.updateTarget(a, C.LOCAL), i.clickSelect(a.annotation, E), a = null, u = void 0;
1264
+ o.updateTarget(a, C.LOCAL), i.clickSelect(a.annotation, v), a = null, u = void 0;
1257
1265
  else {
1258
- const { x: L, y } = e.getBoundingClientRect(), l = o.getAt(E.clientX - L, E.clientY - y);
1266
+ const { x: M, y } = e.getBoundingClientRect(), l = o.getAt(v.clientX - M, v.clientY - y);
1259
1267
  if (l) {
1260
1268
  const { selected: c } = i;
1261
- (c.length !== 1 || c[0].id !== l.id) && (i.clickSelect(l.id, E), u = void 0);
1269
+ (c.length !== 1 || c[0].id !== l.id) && (i.clickSelect(l.id, v), u = void 0);
1262
1270
  } else
1263
1271
  i.isEmpty() || i.clear();
1264
1272
  }
@@ -1268,7 +1276,7 @@ const de = (e, t, n) => {
1268
1276
  };
1269
1277
  };
1270
1278
  const he = (e, t = {}) => {
1271
- const n = ne(e, t.pointerAction), { selection: o, viewport: i } = n, s = n.store, a = Ut(s), r = Dt(
1279
+ const n = ne(e, t.pointerAction), { selection: o, viewport: i } = n, s = n.store, a = Yt(s), r = Dt(
1272
1280
  n,
1273
1281
  a,
1274
1282
  t.adapter