@recogito/text-annotator 3.0.0-rc.41 → 3.0.0-rc.42

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