@recogito/text-annotator 3.0.0-rc.44 → 3.0.0-rc.45

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