@recogito/text-annotator 3.0.0-rc.21 → 3.0.0-rc.23

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