@soomo/text-annotator 3.0.0-staging.30 → 3.0.0-staging.31

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