@soomo/text-annotator 3.0.0-staging.4 → 3.0.0-staging.6

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