@recogito/text-annotator 3.0.0-rc.36 → 3.0.0-rc.37

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