@soomo/text-annotator 3.0.0-staging.51 → 3.0.0-staging.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +4,55 @@ const q = {
4
4
  }, yt = {
5
5
  fill: "rgb(0, 128, 255)",
6
6
  fillOpacity: 0.45
7
- }, Se = (t, e, n, o, i) => {
7
+ }, Ee = (t, e, n, o, i) => {
8
8
  var a, s;
9
9
  const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? yt : q) : n : (s = t.state) != null && s.selected ? yt : q;
10
10
  return o && o.paint(t, e) || r;
11
+ }, Se = (t) => {
12
+ const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, l = i - e;
13
+ return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: l };
14
+ }, Ce = (t) => {
15
+ let e = /* @__PURE__ */ new Set();
16
+ return (o) => {
17
+ const i = o.map((r) => r.id);
18
+ (e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
19
+ };
20
+ }, ie = "not-annotatable", j = `.${ie}`, Le = (t) => {
21
+ var n;
22
+ const e = t.commonAncestorContainer;
23
+ return e instanceof HTMLElement ? !e.closest(j) : !((n = e.parentElement) != null && n.closest(j));
24
+ }, Oe = function* (t) {
25
+ const e = document.createNodeIterator(
26
+ t.commonAncestorContainer,
27
+ NodeFilter.SHOW_ELEMENT,
28
+ (o) => o instanceof HTMLElement && o.classList.contains(ie) && !o.parentElement.closest(j) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
29
+ );
30
+ let n;
31
+ for (; n = e.nextNode(); )
32
+ n instanceof HTMLElement && (yield n);
33
+ }, Te = (t) => {
34
+ if (!Le(t)) return [];
35
+ const e = [];
36
+ let n = null;
37
+ for (const o of Oe(t)) {
38
+ let i;
39
+ n ? (i = document.createRange(), i.setStartAfter(n), i.setEndBefore(o)) : (i = t.cloneRange(), i.setEndBefore(o)), i.collapsed || e.push(i), n = o;
40
+ }
41
+ if (n) {
42
+ const o = t.cloneRange();
43
+ o.setStartAfter(n), o.collapsed || e.push(o);
44
+ }
45
+ return e.length > 0 ? e : [t];
46
+ }, kt = (t) => {
47
+ const e = t.cloneContents();
48
+ return e.querySelectorAll(j).forEach((n) => n.remove()), e;
49
+ }, Re = (t) => t.addEventListener("click", (e) => {
50
+ // Allow clicks within not-annotatable elements
51
+ !e.target.closest(j) && !e.target.closest("a") && e.preventDefault();
52
+ }), Me = (t) => {
53
+ !t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
11
54
  };
12
- function Ce(t) {
55
+ function Be(t) {
13
56
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
14
57
  }
15
58
  var _t = { exports: {} };
@@ -20,120 +63,283 @@ function re(t, e = 100, n = {}) {
20
63
  throw new RangeError("`wait` must not be negative.");
21
64
  const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
22
65
  let i, r, a, s, l;
23
- function f() {
24
- const u = i, h = r;
25
- return i = void 0, r = void 0, l = t.apply(u, h), l;
66
+ function u() {
67
+ const p = i, d = r;
68
+ return i = void 0, r = void 0, l = t.apply(p, d), l;
26
69
  }
27
- function p() {
28
- const u = Date.now() - s;
29
- u < e && u >= 0 ? a = setTimeout(p, e - u) : (a = void 0, o || (l = f()));
70
+ function h() {
71
+ const p = Date.now() - s;
72
+ p < e && p >= 0 ? a = setTimeout(h, e - p) : (a = void 0, o || (l = u()));
30
73
  }
31
- const c = function(...u) {
74
+ const c = function(...p) {
32
75
  if (i && this !== i)
33
76
  throw new Error("Debounced method called with different contexts.");
34
- i = this, r = u, s = Date.now();
35
- const h = o && !a;
36
- return a || (a = setTimeout(p, e)), h && (l = f()), l;
77
+ i = this, r = p, s = Date.now();
78
+ const d = o && !a;
79
+ return a || (a = setTimeout(h, e)), d && (l = u()), l;
37
80
  };
38
81
  return c.clear = () => {
39
82
  a && (clearTimeout(a), a = void 0);
40
83
  }, c.flush = () => {
41
84
  a && c.trigger();
42
85
  }, c.trigger = () => {
43
- l = f(), c.clear();
86
+ l = u(), c.clear();
44
87
  }, c;
45
88
  }
46
89
  _t.exports.debounce = re;
47
90
  _t.exports = re;
48
- var Le = _t.exports;
49
- const Ut = /* @__PURE__ */ Ce(Le), Oe = (t) => {
50
- const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, l = i - e;
51
- return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: l };
52
- }, Te = (t) => {
53
- let e = /* @__PURE__ */ new Set();
54
- return (o) => {
55
- const i = o.map((r) => r.id);
56
- (e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
91
+ var ke = _t.exports;
92
+ const Ie = /* @__PURE__ */ Be(ke), Ut = (t, e = 10, n) => {
93
+ const o = Ie(t, e, n), i = o.bind(void 0);
94
+ Object.getOwnPropertyNames(o).forEach(
95
+ (a) => Object.defineProperty(i, a, Object.getOwnPropertyDescriptor(o, a))
96
+ );
97
+ const r = Object.getPrototypeOf(o);
98
+ return Object.setPrototypeOf(i, r), i;
99
+ }, xo = (t) => {
100
+ const e = t.cloneContents();
101
+ return e.querySelectorAll(j).forEach((n) => n.remove()), e;
102
+ }, Ne = (t, e, n = 10, o) => {
103
+ const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
104
+ r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
105
+ const a = kt(r).textContent, s = document.createRange();
106
+ s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
107
+ const l = kt(s).textContent;
108
+ return {
109
+ prefix: a.substring(a.length - n),
110
+ suffix: l.substring(0, n)
111
+ };
112
+ }, _e = /^\s*$/, Ue = (t) => _e.test(t.toString()), W = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), Ve = (t, e) => {
113
+ const n = (r) => Math.round(r * 10) / 10, o = {
114
+ top: n(t.top),
115
+ bottom: n(t.bottom),
116
+ left: n(t.left),
117
+ right: n(t.right)
118
+ }, i = {
119
+ top: n(e.top),
120
+ bottom: n(e.bottom),
121
+ left: n(e.left),
122
+ right: n(e.right)
123
+ };
124
+ if (Math.abs(o.top - i.top) < 0.5 && Math.abs(o.bottom - i.bottom) < 0.5) {
125
+ if (Math.abs(o.left - i.right) < 0.5 || Math.abs(o.right - i.left) < 0.5)
126
+ return "inline-adjacent";
127
+ if (o.left >= i.left && o.right <= i.right)
128
+ return "inline-is-contained";
129
+ if (o.left <= i.left && o.right >= i.right)
130
+ return "inline-contains";
131
+ } else if (o.top <= i.top && o.bottom >= i.bottom) {
132
+ if (o.left <= i.left && o.right >= i.right)
133
+ return "block-contains";
134
+ } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
135
+ return "block-is-contained";
136
+ }, De = (t, e) => {
137
+ 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);
138
+ return new DOMRect(n, i, o - n, r - i);
139
+ }, Ke = (t) => t.reduce((e, n) => {
140
+ if (n.width === 0 || n.height === 0)
141
+ return e;
142
+ let o = [...e], i = !1;
143
+ for (const r of e) {
144
+ const a = Ve(n, r);
145
+ if (a === "inline-adjacent") {
146
+ o = o.map((s) => s === r ? De(n, r) : s), i = !0;
147
+ break;
148
+ } else if (a === "inline-contains") {
149
+ o = o.map((s) => s === r ? n : s), i = !0;
150
+ break;
151
+ } else if (a === "inline-is-contained") {
152
+ i = !0;
153
+ break;
154
+ } else if (a === "block-contains" || a === "block-is-contained") {
155
+ n.width < r.width && (o = o.map((s) => s === r ? n : s)), i = !0;
156
+ break;
157
+ }
158
+ }
159
+ return i ? o : [...o, n];
160
+ }, []), Eo = (t) => ({
161
+ length: t.length,
162
+ item: (e) => t[e],
163
+ [Symbol.iterator]: function* () {
164
+ for (let e = 0; e < this.length; e++)
165
+ yield this.item(e);
166
+ }
167
+ }), Ye = (t, e, n) => {
168
+ const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
169
+ o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
170
+ const r = kt(o).textContent, a = t.toString(), s = r.length || 0, l = s + a.length;
171
+ return n ? { quote: a, start: s, end: l, range: t, offsetReference: i } : { quote: a, start: s, end: l, range: t };
172
+ }, se = (t, e) => {
173
+ var h, c;
174
+ const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
175
+ e,
176
+ NodeFilter.SHOW_TEXT,
177
+ (p) => {
178
+ var d;
179
+ return (d = p.parentElement) != null && d.closest(j) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
180
+ }
181
+ );
182
+ let a = 0;
183
+ const s = document.createRange();
184
+ let l = r.nextNode();
185
+ l === null && console.error("Could not revive annotation target. Content missing.");
186
+ let u = !i;
187
+ for (; l !== null; ) {
188
+ if (u || (u = i == null ? void 0 : i.contains(l)), u) {
189
+ const p = ((h = l.textContent) == null ? void 0 : h.length) || 0;
190
+ if (a + p > n) {
191
+ s.setStart(l, n - a);
192
+ break;
193
+ }
194
+ a += p;
195
+ }
196
+ l = r.nextNode();
197
+ }
198
+ for (; l !== null; ) {
199
+ const p = ((c = l.textContent) == null ? void 0 : c.length) || 0;
200
+ if (a + p >= o) {
201
+ s.setEnd(l, o - a);
202
+ break;
203
+ }
204
+ a += p, l = r.nextNode();
205
+ }
206
+ return {
207
+ ...t,
208
+ range: s
57
209
  };
58
- }, Vt = (t, e, n, o) => {
210
+ }, bt = (t, e) => W(t.selector) ? t : {
211
+ ...t,
212
+ selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : se(n, e))
213
+ }, wt = (t, e) => W(t.target.selector) ? t : { ...t, target: bt(t.target, e) }, Xe = (t, e) => {
214
+ const n = t.cloneRange();
215
+ return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
216
+ }, Pe = (t, e) => {
217
+ const { left: n, top: o, right: i, bottom: r } = t;
218
+ return new DOMRect(n - e.left, o - e.top, i - n, r - o);
219
+ }, So = (t, e) => {
220
+ const { left: n, top: o, right: i, bottom: r } = t;
221
+ return new DOMRect(n + e.left, o + e.top, i - n, r - o);
222
+ }, $e = (t) => ({
223
+ ...t,
224
+ type: t.type,
225
+ x: t.x,
226
+ y: t.y,
227
+ clientX: t.clientX,
228
+ clientY: t.clientY,
229
+ offsetX: t.offsetX,
230
+ offsetY: t.offsetY,
231
+ screenX: t.screenX,
232
+ screenY: t.screenY,
233
+ isPrimary: t.isPrimary,
234
+ altKey: t.altKey,
235
+ ctrlKey: t.ctrlKey,
236
+ metaKey: t.metaKey,
237
+ shiftKey: t.shiftKey,
238
+ button: t.button,
239
+ buttons: t.buttons,
240
+ currentTarget: t.currentTarget,
241
+ target: t.target,
242
+ defaultPrevented: t.defaultPrevented,
243
+ detail: t.detail,
244
+ eventPhase: t.eventPhase,
245
+ pointerId: t.pointerId,
246
+ pointerType: t.pointerType,
247
+ timeStamp: t.timeStamp
248
+ }), je = (t) => ({
249
+ ...t,
250
+ type: t.type,
251
+ key: t.key,
252
+ code: t.code,
253
+ location: t.location,
254
+ repeat: t.repeat,
255
+ altKey: t.altKey,
256
+ ctrlKey: t.ctrlKey,
257
+ metaKey: t.metaKey,
258
+ shiftKey: t.shiftKey,
259
+ currentTarget: t.currentTarget,
260
+ target: t.target,
261
+ defaultPrevented: t.defaultPrevented,
262
+ detail: t.detail,
263
+ timeStamp: t.timeStamp
264
+ }), Vt = (t, e, n, o) => {
59
265
  const { store: i, selection: r, hover: a } = e;
60
- let s, l, f;
61
- const p = Te(n), c = (O) => {
62
- const { x: R, y } = t.getBoundingClientRect(), w = i.getAt(O.clientX - R, O.clientY - y, l);
266
+ let s, l, u;
267
+ const h = Ce(n), c = (O) => {
268
+ const { x: R, y: g } = t.getBoundingClientRect(), w = i.getAt(O.clientX - R, O.clientY - g, l);
63
269
  w ? a.current !== w.id && (t.classList.add("hovered"), a.set(w.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
64
270
  };
65
271
  t.addEventListener("pointermove", c);
66
- const u = (O = !1) => {
67
- f && f.clear();
68
- const R = Oe(t), { minX: y, minY: w, maxX: v, maxY: L } = R, M = l ? i.getIntersecting(y, w, v, L).filter(({ annotation: X }) => l(X)) : i.getIntersecting(y, w, v, L), B = r.selected.map(({ id: X }) => X), K = M.map(({ annotation: X, rects: lt }) => {
69
- const Ae = B.includes(X.id), Ee = X.id === a.current;
70
- return { annotation: X, rects: lt, state: { selected: Ae, hover: Ee } };
272
+ const p = (O = !1) => {
273
+ u && u.clear();
274
+ const R = Se(t), { minX: g, minY: w, maxX: x, maxY: L } = R, B = l ? i.getIntersecting(g, w, x, L).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(g, w, x, L), M = r.selected.map(({ id: Y }) => Y), K = B.map(({ annotation: Y, rects: lt }) => {
275
+ const Ae = M.includes(Y.id), xe = Y.id === a.current;
276
+ return { annotation: Y, rects: lt, state: { selected: Ae, hover: xe } };
71
277
  });
72
- o.redraw(K, R, s, f, O), setTimeout(() => p(M.map(({ annotation: X }) => X)), 1);
73
- }, h = (O) => {
74
- f = O, u();
75
- }, x = (O) => {
76
- s = O, u();
278
+ o.redraw(K, R, s, u, O), setTimeout(() => h(B.map(({ annotation: Y }) => Y)), 1);
279
+ }, d = (O) => {
280
+ u = O, p();
77
281
  }, A = (O) => {
78
- l = O, u(!1);
79
- }, b = () => u();
80
- i.observe(b);
81
- const g = r.subscribe(() => u()), d = () => u(!0);
82
- document.addEventListener("scroll", d, { capture: !0, passive: !0 });
83
- const m = Ut(() => {
84
- i.recalculatePositions(), f && f.reset(), u();
85
- }, 10).bind(void 0);
86
- window.addEventListener("resize", m);
87
- const E = new ResizeObserver(m);
88
- E.observe(t);
89
- const C = { attributes: !0, childList: !0, subtree: !0 }, S = new MutationObserver((O) => {
90
- O.every((y) => y.target === t || t.contains(y.target)) || u(!0);
282
+ s = O, p();
283
+ }, v = (O) => {
284
+ l = O, p(!1);
285
+ }, S = () => p();
286
+ i.observe(S);
287
+ const m = r.subscribe(() => p()), f = () => p(!0);
288
+ document.addEventListener("scroll", f, { capture: !0, passive: !0 });
289
+ const y = Ut(() => {
290
+ i.recalculatePositions(), u == null || u.reset(), p();
91
291
  });
92
- return S.observe(document.body, C), {
292
+ window.addEventListener("resize", y);
293
+ const C = new ResizeObserver(y);
294
+ C.observe(t);
295
+ const E = { attributes: !0, childList: !0, subtree: !0 }, b = new MutationObserver((O) => {
296
+ O.every((g) => g.target === t || t.contains(g.target)) || p(!0);
297
+ });
298
+ return b.observe(document.body, E), {
93
299
  destroy: () => {
94
- t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(b), g(), document.removeEventListener("scroll", d), m.clear(), window.removeEventListener("resize", m), E.disconnect(), S.disconnect();
300
+ t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(S), m(), document.removeEventListener("scroll", f), y.clear(), window.removeEventListener("resize", y), C.disconnect(), b.disconnect();
95
301
  },
96
- redraw: u,
97
- setStyle: x,
98
- setFilter: A,
99
- setPainter: h,
302
+ redraw: p,
303
+ setStyle: A,
304
+ setFilter: v,
305
+ setPainter: d,
100
306
  setVisible: o.setVisible
101
307
  };
102
- }, Re = () => {
308
+ }, He = () => {
103
309
  const t = document.createElement("canvas");
104
310
  return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
105
- }, Be = (t, e) => {
311
+ }, ze = (t, e) => {
106
312
  t.width = window.innerWidth, t.height = window.innerHeight;
107
- }, Me = (t) => {
313
+ }, Fe = (t) => {
108
314
  t.classList.add("r6o-annotatable");
109
- const e = Re(), n = e.getContext("2d");
315
+ const e = He(), n = e.getContext("2d");
110
316
  document.body.appendChild(e);
111
- const o = (s, l, f, p) => requestAnimationFrame(() => {
112
- const { width: c, height: u } = e;
113
- n.clearRect(-0.5, -0.5, c + 1, u + 1), p && p.clear();
114
- const { top: h, left: x } = l;
115
- [...s].sort((b, g) => {
116
- const { annotation: { target: { created: d } } } = b, { annotation: { target: { created: m } } } = g;
117
- return d.getTime() - m.getTime();
118
- }).forEach((b) => {
119
- var E;
120
- const g = f ? typeof f == "function" ? f(b.annotation, b.state) : f : (E = b.state) != null && E.selected ? yt : q, d = p && p.paint(b, l) || g, m = b.rects.map(({ x: C, y: S, width: T, height: O }) => ({
121
- x: C + x,
122
- y: S + h,
317
+ const o = (s, l, u, h) => requestAnimationFrame(() => {
318
+ const { width: c, height: p } = e;
319
+ n.clearRect(-0.5, -0.5, c + 1, p + 1), h && h.clear();
320
+ const { top: d, left: A } = l;
321
+ [...s].sort((S, m) => {
322
+ const { annotation: { target: { created: f } } } = S, { annotation: { target: { created: y } } } = m;
323
+ return f.getTime() - y.getTime();
324
+ }).forEach((S) => {
325
+ var C;
326
+ const m = u ? typeof u == "function" ? u(S.annotation, S.state) : u : (C = S.state) != null && C.selected ? yt : q, f = h && h.paint(S, l) || m, y = S.rects.map(({ x: E, y: b, width: T, height: O }) => ({
327
+ x: E + A,
328
+ y: b + d,
123
329
  width: T,
124
330
  height: O
125
331
  }));
126
- if (n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1, m.forEach(
127
- ({ x: C, y: S, width: T, height: O }) => n.fillRect(C, S, T, O)
128
- ), d.underlineColor) {
129
- n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
130
- const C = d.underlineOffset ?? 0;
131
- m.forEach(({ x: S, y: T, width: O, height: R }) => {
132
- n.beginPath(), n.moveTo(S, T + R + C), n.lineTo(S + O, T + R + C), n.stroke();
332
+ if (n.fillStyle = f.fill, n.globalAlpha = f.fillOpacity || 1, y.forEach(
333
+ ({ x: E, y: b, width: T, height: O }) => n.fillRect(E, b, T, O)
334
+ ), f.underlineColor) {
335
+ n.globalAlpha = 1, n.strokeStyle = f.underlineColor, n.lineWidth = f.underlineThickness ?? 1;
336
+ const E = f.underlineOffset ?? 0;
337
+ y.forEach(({ x: b, y: T, width: O, height: R }) => {
338
+ n.beginPath(), n.moveTo(b, T + R + E), n.lineTo(b + O, T + R + E), n.stroke();
133
339
  });
134
340
  }
135
341
  });
136
- }), i = Ut(() => Be(e), 10).bind(void 0);
342
+ }), i = Ut(() => ze(e));
137
343
  return window.addEventListener("resize", i), {
138
344
  destroy: () => {
139
345
  e.remove(), i.clear(), window.removeEventListener("resize", i);
@@ -143,85 +349,85 @@ const Ut = /* @__PURE__ */ Ce(Le), Oe = (t) => {
143
349
  },
144
350
  redraw: o
145
351
  };
146
- }, Ne = (t, e, n) => Vt(t, e, n, Me(t));
147
- var ke = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
352
+ }, We = (t, e, n) => Vt(t, e, n, Fe(t));
353
+ var qe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
148
354
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
149
355
  }, _ = function(t, e, n) {
150
356
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
151
- }, Y = function(t, e, n) {
357
+ }, X = function(t, e, n) {
152
358
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
153
- }, se = function(t) {
359
+ }, ae = function(t) {
154
360
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
155
- }, Xt = function(t) {
156
- return { r: Y(t.r, 0, 255), g: Y(t.g, 0, 255), b: Y(t.b, 0, 255), a: Y(t.a) };
157
- }, wt = function(t) {
361
+ }, Yt = function(t) {
362
+ return { r: X(t.r, 0, 255), g: X(t.g, 0, 255), b: X(t.b, 0, 255), a: X(t.a) };
363
+ }, vt = function(t) {
158
364
  return { r: _(t.r), g: _(t.g), b: _(t.b), a: _(t.a, 3) };
159
- }, Ie = /^#([0-9a-f]{3,8})$/i, dt = function(t) {
365
+ }, Ge = /^#([0-9a-f]{3,8})$/i, dt = function(t) {
160
366
  var e = t.toString(16);
161
367
  return e.length < 2 ? "0" + e : e;
162
- }, ae = function(t) {
368
+ }, ce = function(t) {
163
369
  var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), a = r - Math.min(e, n, o), s = a ? r === e ? (n - o) / a : r === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
164
370
  return { h: 60 * (s < 0 ? s + 6 : s), s: r ? a / r * 100 : 0, v: r / 255 * 100, a: i };
165
- }, ce = function(t) {
371
+ }, le = function(t) {
166
372
  var e = t.h, n = t.s, o = t.v, i = t.a;
167
373
  e = e / 360 * 6, n /= 100, o /= 100;
168
- var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), l = o * (1 - (1 - e + r) * n), f = r % 6;
169
- return { r: 255 * [o, s, a, a, l, o][f], g: 255 * [l, o, o, s, a, a][f], b: 255 * [a, a, l, o, o, s][f], a: i };
170
- }, Yt = function(t) {
171
- return { h: se(t.h), s: Y(t.s, 0, 100), l: Y(t.l, 0, 100), a: Y(t.a) };
374
+ var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), l = o * (1 - (1 - e + r) * n), u = r % 6;
375
+ return { r: 255 * [o, s, a, a, l, o][u], g: 255 * [l, o, o, s, a, a][u], b: 255 * [a, a, l, o, o, s][u], a: i };
376
+ }, Xt = function(t) {
377
+ return { h: ae(t.h), s: X(t.s, 0, 100), l: X(t.l, 0, 100), a: X(t.a) };
172
378
  }, Pt = function(t) {
173
379
  return { h: _(t.h), s: _(t.s), l: _(t.l), a: _(t.a, 3) };
174
380
  }, $t = function(t) {
175
- return ce((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 }));
381
+ return le((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 }));
176
382
  var e, n, o;
177
383
  }, it = function(t) {
178
- return { h: (e = ae(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 };
384
+ return { h: (e = ce(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 };
179
385
  var e, n, o, i;
180
- }, _e = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ue = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ve = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, De = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ht = { string: [[function(t) {
181
- var e = Ie.exec(t);
386
+ }, Qe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Je = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ze = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, tn = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, jt = { string: [[function(t) {
387
+ var e = Ge.exec(t);
182
388
  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 ? _(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 ? _(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
183
389
  }, "hex"], [function(t) {
184
- var e = Ve.exec(t) || De.exec(t);
185
- 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;
390
+ var e = Ze.exec(t) || tn.exec(t);
391
+ return e ? e[2] !== e[4] || e[4] !== e[6] ? null : Yt({ 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;
186
392
  }, "rgb"], [function(t) {
187
- var e = _e.exec(t) || Ue.exec(t);
393
+ var e = Qe.exec(t) || Je.exec(t);
188
394
  if (!e) return null;
189
- var n, o, i = Yt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (ke[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
395
+ var n, o, i = Xt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (qe[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
190
396
  return $t(i);
191
397
  }, "hsl"]], object: [[function(t) {
192
398
  var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
193
- return z(e) && z(n) && z(o) ? Xt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
399
+ return z(e) && z(n) && z(o) ? Yt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
194
400
  }, "rgb"], [function(t) {
195
401
  var e = t.h, n = t.s, o = t.l, i = t.a, r = i === void 0 ? 1 : i;
196
402
  if (!z(e) || !z(n) || !z(o)) return null;
197
- var a = Yt({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
403
+ var a = Xt({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
198
404
  return $t(a);
199
405
  }, "hsl"], [function(t) {
200
406
  var e = t.h, n = t.s, o = t.v, i = t.a, r = i === void 0 ? 1 : i;
201
407
  if (!z(e) || !z(n) || !z(o)) return null;
202
408
  var a = function(s) {
203
- return { h: se(s.h), s: Y(s.s, 0, 100), v: Y(s.v, 0, 100), a: Y(s.a) };
409
+ return { h: ae(s.h), s: X(s.s, 0, 100), v: X(s.v, 0, 100), a: X(s.a) };
204
410
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(r) });
205
- return ce(a);
206
- }, "hsv"]] }, jt = function(t, e) {
411
+ return le(a);
412
+ }, "hsv"]] }, Ht = function(t, e) {
207
413
  for (var n = 0; n < e.length; n++) {
208
414
  var o = e[n][0](t);
209
415
  if (o) return [o, e[n][1]];
210
416
  }
211
417
  return [null, void 0];
212
- }, Ke = function(t) {
213
- return typeof t == "string" ? jt(t.trim(), Ht.string) : typeof t == "object" && t !== null ? jt(t, Ht.object) : [null, void 0];
214
- }, vt = function(t, e) {
418
+ }, en = function(t) {
419
+ return typeof t == "string" ? Ht(t.trim(), jt.string) : typeof t == "object" && t !== null ? Ht(t, jt.object) : [null, void 0];
420
+ }, At = function(t, e) {
215
421
  var n = it(t);
216
- return { h: n.h, s: Y(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
422
+ return { h: n.h, s: X(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
217
423
  }, xt = function(t) {
218
424
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
219
425
  }, zt = function(t, e) {
220
426
  var n = it(t);
221
- return { h: n.h, s: n.s, l: Y(n.l + 100 * e, 0, 100), a: n.a };
427
+ return { h: n.h, s: n.s, l: X(n.l + 100 * e, 0, 100), a: n.a };
222
428
  }, Ft = function() {
223
429
  function t(e) {
224
- this.parsed = Ke(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
430
+ this.parsed = en(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
225
431
  }
226
432
  return t.prototype.isValid = function() {
227
433
  return this.parsed !== null;
@@ -232,12 +438,12 @@ var ke = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
232
438
  }, t.prototype.isLight = function() {
233
439
  return xt(this.rgba) >= 0.5;
234
440
  }, t.prototype.toHex = function() {
235
- return e = wt(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? dt(_(255 * r)) : "", "#" + dt(n) + dt(o) + dt(i) + a;
441
+ return e = vt(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? dt(_(255 * r)) : "", "#" + dt(n) + dt(o) + dt(i) + a;
236
442
  var e, n, o, i, r, a;
237
443
  }, t.prototype.toRgb = function() {
238
- return wt(this.rgba);
444
+ return vt(this.rgba);
239
445
  }, t.prototype.toRgbString = function() {
240
- return e = wt(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
446
+ return e = vt(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
241
447
  var e, n, o, i, r;
242
448
  }, t.prototype.toHsl = function() {
243
449
  return Pt(it(this.rgba));
@@ -245,17 +451,17 @@ var ke = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
245
451
  return e = Pt(it(this.rgba)), n = e.h, o = e.s, i = e.l, (r = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + r + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
246
452
  var e, n, o, i, r;
247
453
  }, t.prototype.toHsv = function() {
248
- return e = ae(this.rgba), { h: _(e.h), s: _(e.s), v: _(e.v), a: _(e.a, 3) };
454
+ return e = ce(this.rgba), { h: _(e.h), s: _(e.s), v: _(e.v), a: _(e.a, 3) };
249
455
  var e;
250
456
  }, t.prototype.invert = function() {
251
457
  return P({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
252
458
  var e;
253
459
  }, t.prototype.saturate = function(e) {
254
- return e === void 0 && (e = 0.1), P(vt(this.rgba, e));
460
+ return e === void 0 && (e = 0.1), P(At(this.rgba, e));
255
461
  }, t.prototype.desaturate = function(e) {
256
- return e === void 0 && (e = 0.1), P(vt(this.rgba, -e));
462
+ return e === void 0 && (e = 0.1), P(At(this.rgba, -e));
257
463
  }, t.prototype.grayscale = function() {
258
- return P(vt(this.rgba, -1));
464
+ return P(At(this.rgba, -1));
259
465
  }, t.prototype.lighten = function(e) {
260
466
  return e === void 0 && (e = 0.1), P(zt(this.rgba, e));
261
467
  }, t.prototype.darken = function(e) {
@@ -274,13 +480,13 @@ var ke = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
274
480
  }(), P = function(t) {
275
481
  return t instanceof Ft ? t : new Ft(t);
276
482
  };
277
- const Xe = (t) => [
483
+ const nn = (t) => [
278
484
  `background-color:${P((t == null ? void 0 : t.fill) || q.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? q.fillOpacity : t.fillOpacity).toHex()}`,
279
485
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
280
486
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
281
487
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
282
488
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
283
- ].filter(Boolean).join(";"), Ye = () => {
489
+ ].filter(Boolean).join(";"), on = () => {
284
490
  const t = document.createElement("style");
285
491
  document.getElementsByTagName("head")[0].appendChild(t);
286
492
  let e = /* @__PURE__ */ new Set();
@@ -293,23 +499,23 @@ const Xe = (t) => [
293
499
  },
294
500
  redraw: (r, a, s, l) => {
295
501
  l && l.clear();
296
- const f = new Set(r.map((c) => c.annotation.id));
297
- Array.from(e).filter((c) => !f.has(c));
298
- const p = r.map((c) => {
299
- var x;
300
- const u = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (x = c.state) != null && x.selected ? yt : q, h = l && l.paint(c, a) || u;
301
- return `::highlight(_${c.annotation.id}) { ${Xe(h)} }`;
502
+ const u = new Set(r.map((c) => c.annotation.id));
503
+ Array.from(e).filter((c) => !u.has(c));
504
+ const h = r.map((c) => {
505
+ var A;
506
+ const p = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (A = c.state) != null && A.selected ? yt : q, d = l && l.paint(c, a) || p;
507
+ return `::highlight(_${c.annotation.id}) { ${nn(d)} }`;
302
508
  });
303
- t.innerHTML = p.join(`
509
+ t.innerHTML = h.join(`
304
510
  `), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
305
- const u = c.target.selector.map((x) => x.range), h = new Highlight(...u);
306
- CSS.highlights.set(`_${c.id}`, h);
307
- }), e = f;
511
+ const p = c.target.selector.map((A) => A.range), d = new Highlight(...p);
512
+ CSS.highlights.set(`_${c.id}`, d);
513
+ }), e = u;
308
514
  }
309
515
  };
310
- }, Pe = (t, e, n) => Vt(t, e, n, Ye());
516
+ }, rn = (t, e, n) => Vt(t, e, n, on());
311
517
  var Wt = Object.prototype.hasOwnProperty;
312
- function Nt(t, e) {
518
+ function It(t, e) {
313
519
  var n, o;
314
520
  if (t === e) return !0;
315
521
  if (t && e && (n = t.constructor) === e.constructor) {
@@ -317,22 +523,22 @@ function Nt(t, e) {
317
523
  if (n === RegExp) return t.toString() === e.toString();
318
524
  if (n === Array) {
319
525
  if ((o = t.length) === e.length)
320
- for (; o-- && Nt(t[o], e[o]); ) ;
526
+ for (; o-- && It(t[o], e[o]); ) ;
321
527
  return o === -1;
322
528
  }
323
529
  if (!n || typeof t == "object") {
324
530
  o = 0;
325
531
  for (n in t)
326
- if (Wt.call(t, n) && ++o && !Wt.call(e, n) || !(n in e) || !Nt(t[n], e[n])) return !1;
532
+ if (Wt.call(t, n) && ++o && !Wt.call(e, n) || !(n in e) || !It(t[n], e[n])) return !1;
327
533
  return Object.keys(e).length === o;
328
534
  }
329
535
  }
330
536
  return t !== t && e !== e;
331
537
  }
332
- const $e = (t, e) => {
538
+ const sn = (t, e) => {
333
539
  const n = (r, a) => r.x <= a.x + a.width && r.x + r.width >= a.x && r.y <= a.y + a.height && r.y + r.height >= a.y, o = (r) => r.rects.reduce((a, s) => a + s.width, 0), i = e.filter(({ rects: r }) => r.some((a) => n(t, a)));
334
540
  return i.sort((r, a) => o(a) - o(r)), i.findIndex((r) => r.rects.includes(t));
335
- }, He = (t) => {
541
+ }, an = (t) => {
336
542
  t.classList.add("r6o-annotatable");
337
543
  const e = document.createElement("div");
338
544
  e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
@@ -341,49 +547,45 @@ const $e = (t, e) => {
341
547
  destroy: () => {
342
548
  e.remove();
343
549
  },
344
- redraw: (a, s, l, f, p) => {
345
- const u = !(Nt(n, a) && p);
346
- if (!f && !u) return;
347
- u && (e.innerHTML = ""), [...a].sort((x, A) => {
348
- const { annotation: { target: { created: b } } } = x, { annotation: { target: { created: g } } } = A;
349
- return b.getTime() - g.getTime();
350
- }).forEach((x) => {
351
- x.rects.map((A) => {
352
- const b = $e(A, a), g = Se(x, s, l, f, b);
353
- if (u) {
354
- const d = document.createElement("span");
355
- d.className = "r6o-annotation", d.dataset.annotation = x.annotation.id, d.style.left = `${A.x}px`, d.style.top = `${A.y}px`, d.style.width = `${A.width}px`, d.style.height = `${A.height}px`, d.style.backgroundColor = P((g == null ? void 0 : g.fill) || q.fill).alpha((g == null ? void 0 : g.fillOpacity) === void 0 ? q.fillOpacity : g.fillOpacity).toHex(), g.underlineStyle && (d.style.borderStyle = g.underlineStyle), g.underlineColor && (d.style.borderColor = g.underlineColor), g.underlineThickness && (d.style.borderBottomWidth = `${g.underlineThickness}px`), g.underlineOffset && (d.style.paddingBottom = `${g.underlineOffset}px`), e.appendChild(d);
550
+ redraw: (a, s, l, u, h) => {
551
+ const p = !(It(n, a) && h);
552
+ !u && !p || (p && (e.innerHTML = ""), [...a].forEach((d) => {
553
+ d.rects.map((A) => {
554
+ const v = sn(A, a), S = Ee(d, s, l, u, v);
555
+ if (p) {
556
+ const m = document.createElement("span");
557
+ m.className = "r6o-annotation", m.dataset.annotation = d.annotation.id, m.style.left = `${A.x}px`, m.style.top = `${A.y}px`, m.style.width = `${A.width}px`, m.style.height = `${A.height}px`, m.style.backgroundColor = P((S == null ? void 0 : S.fill) || q.fill).alpha((S == null ? void 0 : S.fillOpacity) === void 0 ? q.fillOpacity : S.fillOpacity).toHex(), S.underlineStyle && (m.style.borderStyle = S.underlineStyle), S.underlineColor && (m.style.borderColor = S.underlineColor), S.underlineThickness && (m.style.borderBottomWidth = `${S.underlineThickness}px`), S.underlineOffset && (m.style.paddingBottom = `${S.underlineOffset}px`), e.appendChild(m);
356
558
  }
357
559
  });
358
- }), n = a;
560
+ }), n = a);
359
561
  },
360
562
  setVisible: (a) => {
361
563
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
362
564
  }
363
565
  };
364
- }, je = (t, e, n) => Vt(t, e, n, He(t));
566
+ }, cn = (t, e, n) => Vt(t, e, n, an(t));
365
567
  var U = [];
366
- for (var At = 0; At < 256; ++At)
367
- U.push((At + 256).toString(16).slice(1));
368
- function ze(t, e = 0) {
568
+ for (var Et = 0; Et < 256; ++Et)
569
+ U.push((Et + 256).toString(16).slice(1));
570
+ function ln(t, e = 0) {
369
571
  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();
370
572
  }
371
- var ut, Fe = new Uint8Array(16);
372
- function We() {
573
+ var ut, dn = new Uint8Array(16);
574
+ function un() {
373
575
  if (!ut && (ut = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ut))
374
576
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
375
- return ut(Fe);
577
+ return ut(dn);
376
578
  }
377
- var qe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
579
+ var fn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
378
580
  const qt = {
379
- randomUUID: qe
581
+ randomUUID: fn
380
582
  };
381
- function le(t, e, n) {
583
+ function de(t, e, n) {
382
584
  if (qt.randomUUID && !e && !t)
383
585
  return qt.randomUUID();
384
586
  t = t || {};
385
- var o = t.random || (t.rng || We)();
386
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, ze(o);
587
+ var o = t.random || (t.rng || un)();
588
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, ln(o);
387
589
  }
388
590
  var Gt = Object.prototype.hasOwnProperty;
389
591
  function G(t, e) {
@@ -406,23 +608,23 @@ function G(t, e) {
406
608
  }
407
609
  return t !== t && e !== e;
408
610
  }
409
- function Et() {
611
+ function St() {
410
612
  }
411
- function Ge(t, e) {
613
+ function hn(t, e) {
412
614
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
413
615
  }
414
616
  const Q = [];
415
- function Dt(t, e = Et) {
617
+ function Dt(t, e = St) {
416
618
  let n;
417
619
  const o = /* @__PURE__ */ new Set();
418
620
  function i(s) {
419
- if (Ge(t, s) && (t = s, n)) {
621
+ if (hn(t, s) && (t = s, n)) {
420
622
  const l = !Q.length;
421
- for (const f of o)
422
- f[1](), Q.push(f, t);
623
+ for (const u of o)
624
+ u[1](), Q.push(u, t);
423
625
  if (l) {
424
- for (let f = 0; f < Q.length; f += 2)
425
- Q[f][0](Q[f + 1]);
626
+ for (let u = 0; u < Q.length; u += 2)
627
+ Q[u][0](Q[u + 1]);
426
628
  Q.length = 0;
427
629
  }
428
630
  }
@@ -430,15 +632,15 @@ function Dt(t, e = Et) {
430
632
  function r(s) {
431
633
  i(s(t));
432
634
  }
433
- function a(s, l = Et) {
434
- const f = [s, l];
435
- return o.add(f), o.size === 1 && (n = e(i, r) || Et), s(t), () => {
436
- o.delete(f), o.size === 0 && n && (n(), n = null);
635
+ function a(s, l = St) {
636
+ const u = [s, l];
637
+ return o.add(u), o.size === 1 && (n = e(i, r) || St), s(t), () => {
638
+ o.delete(u), o.size === 0 && n && (n(), n = null);
437
639
  };
438
640
  }
439
641
  return { set: i, update: r, subscribe: a };
440
642
  }
441
- const Qe = (t) => {
643
+ const pn = (t) => {
442
644
  const { subscribe: e, set: n } = Dt();
443
645
  let o;
444
646
  return e((i) => o = i), t.observe(({ changes: i }) => {
@@ -455,132 +657,132 @@ const Qe = (t) => {
455
657
  set: n
456
658
  };
457
659
  };
458
- var Je = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Je || {});
459
- const ft = { selected: [] }, Ze = (t) => {
460
- const { subscribe: e, set: n } = Dt(ft);
461
- let o, i = ft;
462
- e((u) => i = u);
463
- const r = () => {
464
- G(i, ft) || n(ft);
465
- }, a = () => {
466
- var u;
467
- return ((u = i.selected) == null ? void 0 : u.length) === 0;
468
- }, s = (u) => {
469
- if (a())
660
+ var gn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(gn || {});
661
+ const ft = { selected: [] }, mn = (t, e) => {
662
+ const { subscribe: n, set: o } = Dt(ft);
663
+ let i = e, r = ft;
664
+ n((d) => r = d);
665
+ const a = () => {
666
+ G(r, ft) || o(ft);
667
+ }, s = () => {
668
+ var d;
669
+ return ((d = r.selected) == null ? void 0 : d.length) === 0;
670
+ }, l = (d) => {
671
+ if (s())
470
672
  return !1;
471
- const h = typeof u == "string" ? u : u.id;
472
- return i.selected.some((x) => x.id === h);
473
- }, l = (u, h) => {
474
- const x = t.getAnnotation(u);
475
- if (!x) {
476
- console.warn("Invalid selection: " + u);
673
+ const A = typeof d == "string" ? d : d.id;
674
+ return r.selected.some((v) => v.id === A);
675
+ }, u = (d, A) => {
676
+ const v = t.getAnnotation(d);
677
+ if (!v) {
678
+ console.warn("Invalid selection: " + d);
477
679
  return;
478
680
  }
479
- switch (Qt(x, o)) {
681
+ switch (Qt(v, i)) {
480
682
  case "EDIT":
481
- n({ selected: [{ id: u, editable: !0 }], event: h });
683
+ o({ selected: [{ id: d, editable: !0 }], event: A });
482
684
  break;
483
685
  case "SELECT":
484
- n({ selected: [{ id: u }], event: h });
686
+ o({ selected: [{ id: d }], event: A });
485
687
  break;
486
688
  default:
487
- n({ selected: [], event: h });
689
+ o({ selected: [], event: A });
488
690
  }
489
- }, f = (u, h) => {
490
- const x = Array.isArray(u) ? u : [u], A = x.map((b) => t.getAnnotation(b)).filter((b) => !!b);
491
- n({
492
- selected: A.map((b) => {
493
- const g = h === void 0 ? Qt(b, o) === "EDIT" : h;
494
- return { id: b.id, editable: g };
691
+ }, h = (d, A) => {
692
+ const v = Array.isArray(d) ? d : [d], S = v.map((m) => t.getAnnotation(m)).filter((m) => !!m);
693
+ o({
694
+ selected: S.map((m) => {
695
+ const f = A === void 0 ? Qt(m, i) === "EDIT" : A;
696
+ return { id: m.id, editable: f };
495
697
  })
496
- }), A.length !== x.length && console.warn("Invalid selection", u);
497
- }, p = (u) => {
498
- if (a())
698
+ }), S.length !== v.length && console.warn("Invalid selection", d);
699
+ }, c = (d) => {
700
+ if (s())
499
701
  return !1;
500
- const { selected: h } = i;
501
- h.some(({ id: x }) => u.includes(x)) && n({ selected: h.filter(({ id: x }) => !u.includes(x)) });
502
- }, c = (u) => o = u;
702
+ const { selected: A } = r;
703
+ A.some(({ id: v }) => d.includes(v)) && o({ selected: A.filter(({ id: v }) => !d.includes(v)) });
704
+ }, p = (d) => i = d;
503
705
  return t.observe(
504
- ({ changes: u }) => p((u.deleted || []).map((h) => h.id))
706
+ ({ changes: d }) => c((d.deleted || []).map((A) => A.id))
505
707
  ), {
506
708
  get event() {
507
- return i ? i.event : null;
709
+ return r ? r.event : null;
508
710
  },
509
711
  get selected() {
510
- return i ? [...i.selected] : null;
712
+ return r ? [...r.selected] : null;
511
713
  },
512
714
  get userSelectAction() {
513
- return o;
715
+ return i;
514
716
  },
515
- clear: r,
516
- isEmpty: a,
517
- isSelected: s,
518
- setSelected: f,
519
- setUserSelectAction: c,
520
- subscribe: e,
521
- userSelect: l
717
+ clear: a,
718
+ isEmpty: s,
719
+ isSelected: l,
720
+ setSelected: h,
721
+ setUserSelectAction: p,
722
+ subscribe: n,
723
+ userSelect: u
522
724
  };
523
725
  }, Qt = (t, e) => typeof e == "function" ? e(t) : e || "EDIT";
524
726
  var V = [];
525
- for (var St = 0; St < 256; ++St)
526
- V.push((St + 256).toString(16).slice(1));
527
- function tn(t, e = 0) {
727
+ for (var Ct = 0; Ct < 256; ++Ct)
728
+ V.push((Ct + 256).toString(16).slice(1));
729
+ function yn(t, e = 0) {
528
730
  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();
529
731
  }
530
- var ht, en = new Uint8Array(16);
531
- function nn() {
732
+ var ht, bn = new Uint8Array(16);
733
+ function wn() {
532
734
  if (!ht && (ht = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ht))
533
735
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
534
- return ht(en);
736
+ return ht(bn);
535
737
  }
536
- var on = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
738
+ var vn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
537
739
  const Jt = {
538
- randomUUID: on
740
+ randomUUID: vn
539
741
  };
540
- function de(t, e, n) {
742
+ function ue(t, e, n) {
541
743
  if (Jt.randomUUID && !e && !t)
542
744
  return Jt.randomUUID();
543
745
  t = t || {};
544
- var o = t.random || (t.rng || nn)();
545
- return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, tn(o);
746
+ var o = t.random || (t.rng || wn)();
747
+ return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, yn(o);
546
748
  }
547
- const So = (t, e, n, o) => ({
548
- id: de(),
749
+ const Co = (t, e, n, o) => ({
750
+ id: ue(),
549
751
  annotation: typeof t == "string" ? t : t.id,
550
752
  created: n || /* @__PURE__ */ new Date(),
551
753
  creator: o,
552
754
  ...e
553
- }), rn = (t, e) => {
755
+ }), An = (t, e) => {
554
756
  const n = new Set(t.bodies.map((o) => o.id));
555
757
  return e.bodies.filter((o) => !n.has(o.id));
556
- }, sn = (t, e) => {
758
+ }, xn = (t, e) => {
557
759
  const n = new Set(e.bodies.map((o) => o.id));
558
760
  return t.bodies.filter((o) => !n.has(o.id));
559
- }, an = (t, e) => e.bodies.map((n) => {
761
+ }, En = (t, e) => e.bodies.map((n) => {
560
762
  const o = t.bodies.find((i) => i.id === n.id);
561
763
  return { newBody: n, oldBody: o && !G(o, n) ? o : void 0 };
562
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), cn = (t, e) => !G(t.target, e.target), ue = (t, e) => {
563
- const n = rn(t, e), o = sn(t, e), i = an(t, e);
764
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Sn = (t, e) => !G(t.target, e.target), fe = (t, e) => {
765
+ const n = An(t, e), o = xn(t, e), i = En(t, e);
564
766
  return {
565
767
  oldValue: t,
566
768
  newValue: e,
567
769
  bodiesCreated: n.length > 0 ? n : void 0,
568
770
  bodiesDeleted: o.length > 0 ? o : void 0,
569
771
  bodiesUpdated: i.length > 0 ? i : void 0,
570
- targetUpdated: cn(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
772
+ targetUpdated: Sn(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
571
773
  };
572
774
  };
573
- var N = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(N || {});
574
- const ln = (t, e) => {
775
+ var k = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(k || {});
776
+ const Cn = (t, e) => {
575
777
  var n, o;
576
778
  const { changes: i, origin: r } = e;
577
- if (!(!t.options.origin || t.options.origin === r))
779
+ if (!(t.options.origin ? t.options.origin === r : r !== "SILENT"))
578
780
  return !1;
579
781
  if (t.options.ignore) {
580
782
  const { ignore: a } = t.options, s = (l) => l && l.length > 0;
581
783
  if (!(s(i.created) || s(i.deleted))) {
582
- const l = (n = i.updated) == null ? void 0 : n.some((p) => s(p.bodiesCreated) || s(p.bodiesDeleted) || s(p.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((p) => p.targetUpdated);
583
- if (a === "BODY_ONLY" && l && !f || a === "TARGET_ONLY" && f && !l)
784
+ const l = (n = i.updated) == null ? void 0 : n.some((h) => s(h.bodiesCreated) || s(h.bodiesDeleted) || s(h.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((h) => h.targetUpdated);
785
+ if (a === "BODY_ONLY" && l && !u || a === "TARGET_ONLY" && u && !l)
584
786
  return !1;
585
787
  }
586
788
  }
@@ -593,27 +795,27 @@ const ln = (t, e) => {
593
795
  return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((s) => a.has(s));
594
796
  } else
595
797
  return !0;
596
- }, dn = (t, e) => {
798
+ }, Ln = (t, e) => {
597
799
  const n = new Set((t.created || []).map((c) => c.id)), o = new Set((t.updated || []).map(({ newValue: c }) => c.id)), i = new Set((e.created || []).map((c) => c.id)), r = new Set((e.deleted || []).map((c) => c.id)), a = new Set((e.updated || []).map(({ oldValue: c }) => c.id)), s = new Set((e.updated || []).filter(({ oldValue: c }) => n.has(c.id) || o.has(c.id)).map(({ oldValue: c }) => c.id)), l = [
598
- ...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue: u }) => u.id === c.id).newValue : c),
800
+ ...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue: p }) => p.id === c.id).newValue : c),
599
801
  ...e.created || []
600
- ], f = [
802
+ ], u = [
601
803
  ...(t.deleted || []).filter((c) => !i.has(c.id)),
602
804
  ...(e.deleted || []).filter((c) => !n.has(c.id))
603
- ], p = [
805
+ ], h = [
604
806
  ...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
605
- const { oldValue: u, newValue: h } = c;
606
- if (a.has(h.id)) {
607
- const x = e.updated.find((A) => A.oldValue.id === h.id).newValue;
608
- return ue(u, x);
807
+ const { oldValue: p, newValue: d } = c;
808
+ if (a.has(d.id)) {
809
+ const A = e.updated.find((v) => v.oldValue.id === d.id).newValue;
810
+ return fe(p, A);
609
811
  } else
610
812
  return c;
611
813
  }),
612
814
  ...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
613
815
  ];
614
- return { created: l, deleted: f, updated: p };
615
- }, Ct = (t) => {
616
- const e = t.id === void 0 ? de() : t.id;
816
+ return { created: l, deleted: u, updated: h };
817
+ }, Lt = (t) => {
818
+ const e = t.id === void 0 ? ue() : t.id;
617
819
  return {
618
820
  ...t,
619
821
  id: e,
@@ -626,13 +828,15 @@ const ln = (t, e) => {
626
828
  annotation: e
627
829
  }
628
830
  };
629
- }, un = (t) => t.id !== void 0, fn = () => {
630
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (y, w = {}) => n.push({ onChange: y, options: w }), i = (y) => {
631
- const w = n.findIndex((v) => v.onChange == y);
831
+ }, On = (t) => t.id !== void 0, Tn = () => {
832
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (g, w = {}) => {
833
+ n.push({ onChange: g, options: w });
834
+ }, i = (g) => {
835
+ const w = n.findIndex((x) => x.onChange == g);
632
836
  w > -1 && n.splice(w, 1);
633
- }, r = (y, w) => {
634
- const v = {
635
- origin: y,
837
+ }, r = (g, w) => {
838
+ const x = {
839
+ origin: g,
636
840
  changes: {
637
841
  created: w.created || [],
638
842
  updated: w.updated || [],
@@ -641,189 +845,189 @@ const ln = (t, e) => {
641
845
  state: [...t.values()]
642
846
  };
643
847
  n.forEach((L) => {
644
- ln(L, v) && L.onChange(v);
848
+ Cn(L, x) && L.onChange(x);
645
849
  });
646
- }, a = (y, w = N.LOCAL) => {
647
- if (y.id && t.get(y.id))
648
- throw Error(`Cannot add annotation ${y.id} - exists already`);
850
+ }, a = (g, w = k.LOCAL) => {
851
+ if (g.id && t.get(g.id))
852
+ throw Error(`Cannot add annotation ${g.id} - exists already`);
649
853
  {
650
- const v = Ct(y);
651
- t.set(v.id, v), v.bodies.forEach((L) => e.set(L.id, v.id)), r(w, { created: [v] });
854
+ const x = Lt(g);
855
+ t.set(x.id, x), x.bodies.forEach((L) => e.set(L.id, x.id)), r(w, { created: [x] });
652
856
  }
653
- }, s = (y, w) => {
654
- const v = Ct(typeof y == "string" ? w : y), L = typeof y == "string" ? y : y.id, M = L && t.get(L);
655
- if (M) {
656
- const B = ue(M, v);
657
- return L === v.id ? t.set(L, v) : (t.delete(L), t.set(v.id, v)), M.bodies.forEach((K) => e.delete(K.id)), v.bodies.forEach((K) => e.set(K.id, v.id)), B;
857
+ }, s = (g, w) => {
858
+ const x = Lt(typeof g == "string" ? w : g), L = typeof g == "string" ? g : g.id, B = L && t.get(L);
859
+ if (B) {
860
+ const M = fe(B, x);
861
+ return L === x.id ? t.set(L, x) : (t.delete(L), t.set(x.id, x)), B.bodies.forEach((K) => e.delete(K.id)), x.bodies.forEach((K) => e.set(K.id, x.id)), M;
658
862
  } else
659
863
  console.warn(`Cannot update annotation ${L} - does not exist`);
660
- }, l = (y, w = N.LOCAL, v = N.LOCAL) => {
661
- const L = un(w) ? v : w, M = s(y, w);
662
- M && r(L, { updated: [M] });
663
- }, f = (y, w = N.LOCAL) => {
664
- const v = y.reduce((L, M) => {
665
- const B = s(M);
666
- return B ? [...L, B] : L;
864
+ }, l = (g, w = k.LOCAL, x = k.LOCAL) => {
865
+ const L = On(w) ? x : w, B = s(g, w);
866
+ B && r(L, { updated: [B] });
867
+ }, u = (g, w = k.LOCAL) => {
868
+ const x = g.reduce((L, B) => {
869
+ const M = s(B);
870
+ return M ? [...L, M] : L;
667
871
  }, []);
668
- v.length > 0 && r(w, { updated: v });
669
- }, p = (y, w = N.LOCAL) => {
670
- const v = t.get(y.annotation);
671
- if (v) {
872
+ x.length > 0 && r(w, { updated: x });
873
+ }, h = (g, w = k.LOCAL) => {
874
+ const x = t.get(g.annotation);
875
+ if (x) {
672
876
  const L = {
673
- ...v,
674
- bodies: [...v.bodies, y]
877
+ ...x,
878
+ bodies: [...x.bodies, g]
675
879
  };
676
- t.set(v.id, L), e.set(y.id, L.id), r(w, { updated: [{
677
- oldValue: v,
880
+ t.set(x.id, L), e.set(g.id, L.id), r(w, { updated: [{
881
+ oldValue: x,
678
882
  newValue: L,
679
- bodiesCreated: [y]
883
+ bodiesCreated: [g]
680
884
  }] });
681
885
  } else
682
- console.warn(`Attempt to add body to missing annotation: ${y.annotation}`);
683
- }, c = () => [...t.values()], u = (y = N.LOCAL) => {
886
+ console.warn(`Attempt to add body to missing annotation: ${g.annotation}`);
887
+ }, c = () => [...t.values()], p = (g = k.LOCAL) => {
684
888
  const w = [...t.values()];
685
- t.clear(), e.clear(), r(y, { deleted: w });
686
- }, h = (y, w = !0, v = N.LOCAL) => {
687
- const L = y.map(Ct);
889
+ t.clear(), e.clear(), r(g, { deleted: w });
890
+ }, d = (g, w = !0, x = k.LOCAL) => {
891
+ const L = g.map(Lt);
688
892
  if (w) {
689
- const M = [...t.values()];
690
- t.clear(), e.clear(), L.forEach((B) => {
691
- t.set(B.id, B), B.bodies.forEach((K) => e.set(K.id, B.id));
692
- }), r(v, { created: L, deleted: M });
893
+ const B = [...t.values()];
894
+ t.clear(), e.clear(), L.forEach((M) => {
895
+ t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
896
+ }), r(x, { created: L, deleted: B });
693
897
  } else {
694
- const M = y.reduce((B, K) => {
695
- const X = K.id && t.get(K.id);
696
- return X ? [...B, X] : B;
898
+ const B = g.reduce((M, K) => {
899
+ const Y = K.id && t.get(K.id);
900
+ return Y ? [...M, Y] : M;
697
901
  }, []);
698
- if (M.length > 0)
699
- throw Error(`Bulk insert would overwrite the following annotations: ${M.map((B) => B.id).join(", ")}`);
700
- L.forEach((B) => {
701
- t.set(B.id, B), B.bodies.forEach((K) => e.set(K.id, B.id));
702
- }), r(v, { created: L });
902
+ if (B.length > 0)
903
+ throw Error(`Bulk insert would overwrite the following annotations: ${B.map((M) => M.id).join(", ")}`);
904
+ L.forEach((M) => {
905
+ t.set(M.id, M), M.bodies.forEach((K) => e.set(K.id, M.id));
906
+ }), r(x, { created: L });
703
907
  }
704
- }, x = (y) => {
705
- const w = typeof y == "string" ? y : y.id, v = t.get(w);
706
- if (v)
707
- return t.delete(w), v.bodies.forEach((L) => e.delete(L.id)), v;
908
+ }, A = (g) => {
909
+ const w = typeof g == "string" ? g : g.id, x = t.get(w);
910
+ if (x)
911
+ return t.delete(w), x.bodies.forEach((L) => e.delete(L.id)), x;
708
912
  console.warn(`Attempt to delete missing annotation: ${w}`);
709
- }, A = (y, w = N.LOCAL) => {
710
- const v = x(y);
711
- v && r(w, { deleted: [v] });
712
- }, b = (y, w = N.LOCAL) => {
713
- const v = y.reduce((L, M) => {
714
- const B = x(M);
715
- return B ? [...L, B] : L;
913
+ }, v = (g, w = k.LOCAL) => {
914
+ const x = A(g);
915
+ x && r(w, { deleted: [x] });
916
+ }, S = (g, w = k.LOCAL) => {
917
+ const x = g.reduce((L, B) => {
918
+ const M = A(B);
919
+ return M ? [...L, M] : L;
716
920
  }, []);
717
- v.length > 0 && r(w, { deleted: v });
718
- }, g = (y) => {
719
- const w = t.get(y.annotation);
921
+ x.length > 0 && r(w, { deleted: x });
922
+ }, m = (g) => {
923
+ const w = t.get(g.annotation);
720
924
  if (w) {
721
- const v = w.bodies.find((L) => L.id === y.id);
722
- if (v) {
723
- e.delete(v.id);
925
+ const x = w.bodies.find((L) => L.id === g.id);
926
+ if (x) {
927
+ e.delete(x.id);
724
928
  const L = {
725
929
  ...w,
726
- bodies: w.bodies.filter((M) => M.id !== y.id)
930
+ bodies: w.bodies.filter((B) => B.id !== g.id)
727
931
  };
728
932
  return t.set(w.id, L), {
729
933
  oldValue: w,
730
934
  newValue: L,
731
- bodiesDeleted: [v]
935
+ bodiesDeleted: [x]
732
936
  };
733
937
  } else
734
- console.warn(`Attempt to delete missing body ${y.id} from annotation ${y.annotation}`);
938
+ console.warn(`Attempt to delete missing body ${g.id} from annotation ${g.annotation}`);
735
939
  } else
736
- console.warn(`Attempt to delete body from missing annotation ${y.annotation}`);
737
- }, d = (y, w = N.LOCAL) => {
738
- const v = g(y);
739
- v && r(w, { updated: [v] });
740
- }, m = (y, w = N.LOCAL) => {
741
- const v = y.map((L) => g(L)).filter(Boolean);
742
- v.length > 0 && r(w, { updated: v });
743
- }, E = (y) => {
744
- const w = t.get(y);
940
+ console.warn(`Attempt to delete body from missing annotation ${g.annotation}`);
941
+ }, f = (g, w = k.LOCAL) => {
942
+ const x = m(g);
943
+ x && r(w, { updated: [x] });
944
+ }, y = (g, w = k.LOCAL) => {
945
+ const x = g.map((L) => m(L)).filter(Boolean);
946
+ x.length > 0 && r(w, { updated: x });
947
+ }, C = (g) => {
948
+ const w = t.get(g);
745
949
  return w ? { ...w } : void 0;
746
- }, C = (y) => {
747
- const w = e.get(y);
950
+ }, E = (g) => {
951
+ const w = e.get(g);
748
952
  if (w) {
749
- const v = E(w).bodies.find((L) => L.id === y);
750
- if (v)
751
- return v;
752
- console.error(`Store integrity error: body ${y} in index, but not in annotation`);
953
+ const x = C(w).bodies.find((L) => L.id === g);
954
+ if (x)
955
+ return x;
956
+ console.error(`Store integrity error: body ${g} in index, but not in annotation`);
753
957
  } else
754
- console.warn(`Attempt to retrieve missing body: ${y}`);
755
- }, S = (y, w) => {
756
- if (y.annotation !== w.annotation)
958
+ console.warn(`Attempt to retrieve missing body: ${g}`);
959
+ }, b = (g, w) => {
960
+ if (g.annotation !== w.annotation)
757
961
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
758
- const v = t.get(y.annotation);
759
- if (v) {
760
- const L = v.bodies.find((B) => B.id === y.id), M = {
761
- ...v,
762
- bodies: v.bodies.map((B) => B.id === L.id ? w : B)
962
+ const x = t.get(g.annotation);
963
+ if (x) {
964
+ const L = x.bodies.find((M) => M.id === g.id), B = {
965
+ ...x,
966
+ bodies: x.bodies.map((M) => M.id === L.id ? w : M)
763
967
  };
764
- return t.set(v.id, M), L.id !== w.id && (e.delete(L.id), e.set(w.id, M.id)), {
765
- oldValue: v,
766
- newValue: M,
968
+ return t.set(x.id, B), L.id !== w.id && (e.delete(L.id), e.set(w.id, B.id)), {
969
+ oldValue: x,
970
+ newValue: B,
767
971
  bodiesUpdated: [{ oldBody: L, newBody: w }]
768
972
  };
769
973
  } else
770
- console.warn(`Attempt to add body to missing annotation ${y.annotation}`);
771
- }, T = (y, w, v = N.LOCAL) => {
772
- const L = S(y, w);
773
- L && r(v, { updated: [L] });
774
- }, O = (y, w = N.LOCAL) => {
775
- const v = y.map((L) => S({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
776
- r(w, { updated: v });
777
- }, R = (y) => {
778
- const w = t.get(y.annotation);
974
+ console.warn(`Attempt to add body to missing annotation ${g.annotation}`);
975
+ }, T = (g, w, x = k.LOCAL) => {
976
+ const L = b(g, w);
977
+ L && r(x, { updated: [L] });
978
+ }, O = (g, w = k.LOCAL) => {
979
+ const x = g.map((L) => b({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
980
+ r(w, { updated: x });
981
+ }, R = (g) => {
982
+ const w = t.get(g.annotation);
779
983
  if (w) {
780
- const v = {
984
+ const x = {
781
985
  ...w,
782
986
  target: {
783
987
  ...w.target,
784
- ...y
988
+ ...g
785
989
  }
786
990
  };
787
- return t.set(w.id, v), {
991
+ return t.set(w.id, x), {
788
992
  oldValue: w,
789
- newValue: v,
993
+ newValue: x,
790
994
  targetUpdated: {
791
995
  oldTarget: w.target,
792
- newTarget: y
996
+ newTarget: g
793
997
  }
794
998
  };
795
999
  } else
796
- console.warn(`Attempt to update target on missing annotation: ${y.annotation}`);
1000
+ console.warn(`Attempt to update target on missing annotation: ${g.annotation}`);
797
1001
  };
798
1002
  return {
799
1003
  addAnnotation: a,
800
- addBody: p,
1004
+ addBody: h,
801
1005
  all: c,
802
- bulkAddAnnotation: h,
803
- bulkDeleteAnnotation: b,
804
- bulkDeleteBodies: m,
805
- bulkUpdateAnnotation: f,
1006
+ bulkAddAnnotation: d,
1007
+ bulkDeleteAnnotation: S,
1008
+ bulkDeleteBodies: y,
1009
+ bulkUpdateAnnotation: u,
806
1010
  bulkUpdateBodies: O,
807
- bulkUpdateTargets: (y, w = N.LOCAL) => {
808
- const v = y.map((L) => R(L)).filter(Boolean);
809
- v.length > 0 && r(w, { updated: v });
1011
+ bulkUpdateTargets: (g, w = k.LOCAL) => {
1012
+ const x = g.map((L) => R(L)).filter(Boolean);
1013
+ x.length > 0 && r(w, { updated: x });
810
1014
  },
811
- clear: u,
812
- deleteAnnotation: A,
813
- deleteBody: d,
814
- getAnnotation: E,
815
- getBody: C,
1015
+ clear: p,
1016
+ deleteAnnotation: v,
1017
+ deleteBody: f,
1018
+ getAnnotation: C,
1019
+ getBody: E,
816
1020
  observe: o,
817
1021
  unobserve: i,
818
1022
  updateAnnotation: l,
819
1023
  updateBody: T,
820
- updateTarget: (y, w = N.LOCAL) => {
821
- const v = R(y);
822
- v && r(w, { updated: [v] });
1024
+ updateTarget: (g, w = k.LOCAL) => {
1025
+ const x = R(g);
1026
+ x && r(w, { updated: [x] });
823
1027
  }
824
1028
  };
825
1029
  };
826
- let hn = () => ({
1030
+ let Rn = () => ({
827
1031
  emit(t, ...e) {
828
1032
  for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
829
1033
  o[n](...e);
@@ -837,119 +1041,119 @@ let hn = () => ({
837
1041
  };
838
1042
  }
839
1043
  });
840
- const gn = 250, pn = (t) => {
841
- const e = hn(), n = [];
1044
+ const Mn = 250, Bn = (t) => {
1045
+ const e = Rn(), n = [];
842
1046
  let o = -1, i = !1, r = 0;
843
- const a = (h) => {
1047
+ const a = (d) => {
844
1048
  if (!i) {
845
- const { changes: x } = h, A = performance.now();
846
- if (A - r > gn)
847
- n.splice(o + 1), n.push(x), o = n.length - 1;
1049
+ const { changes: A } = d, v = performance.now();
1050
+ if (v - r > Mn)
1051
+ n.splice(o + 1), n.push(A), o = n.length - 1;
848
1052
  else {
849
- const b = n.length - 1;
850
- n[b] = dn(n[b], x);
1053
+ const S = n.length - 1;
1054
+ n[S] = Ln(n[S], A);
851
1055
  }
852
- r = A;
1056
+ r = v;
853
1057
  }
854
1058
  i = !1;
855
1059
  };
856
- t.observe(a, { origin: N.LOCAL });
857
- const s = (h) => h && h.length > 0 && t.bulkDeleteAnnotation(h), l = (h) => h && h.length > 0 && t.bulkAddAnnotation(h, !1), f = (h) => h && h.length > 0 && t.bulkUpdateAnnotation(h.map(({ oldValue: x }) => x)), p = (h) => h && h.length > 0 && t.bulkUpdateAnnotation(h.map(({ newValue: x }) => x)), c = (h) => h && h.length > 0 && t.bulkAddAnnotation(h, !1), u = (h) => h && h.length > 0 && t.bulkDeleteAnnotation(h);
1060
+ t.observe(a, { origin: k.LOCAL });
1061
+ const s = (d) => d && d.length > 0 && t.bulkDeleteAnnotation(d), l = (d) => d && d.length > 0 && t.bulkAddAnnotation(d, !1), u = (d) => d && d.length > 0 && t.bulkUpdateAnnotation(d.map(({ oldValue: A }) => A)), h = (d) => d && d.length > 0 && t.bulkUpdateAnnotation(d.map(({ newValue: A }) => A)), c = (d) => d && d.length > 0 && t.bulkAddAnnotation(d, !1), p = (d) => d && d.length > 0 && t.bulkDeleteAnnotation(d);
858
1062
  return {
859
1063
  canRedo: () => n.length - 1 > o,
860
1064
  canUndo: () => o > -1,
861
1065
  destroy: () => t.unobserve(a),
862
- on: (h, x) => e.on(h, x),
1066
+ on: (d, A) => e.on(d, A),
863
1067
  redo: () => {
864
1068
  if (n.length - 1 > o) {
865
1069
  i = !0;
866
- const { created: h, updated: x, deleted: A } = n[o + 1];
867
- l(h), p(x), u(A), e.emit("redo", n[o + 1]), o += 1;
1070
+ const { created: d, updated: A, deleted: v } = n[o + 1];
1071
+ l(d), h(A), p(v), e.emit("redo", n[o + 1]), o += 1;
868
1072
  }
869
1073
  },
870
1074
  undo: () => {
871
1075
  if (o > -1) {
872
1076
  i = !0;
873
- const { created: h, updated: x, deleted: A } = n[o];
874
- s(h), f(x), c(A), e.emit("undo", n[o]), o -= 1;
1077
+ const { created: d, updated: A, deleted: v } = n[o];
1078
+ s(d), u(A), c(v), e.emit("undo", n[o]), o -= 1;
875
1079
  }
876
1080
  }
877
1081
  };
878
- }, mn = () => {
1082
+ }, kn = () => {
879
1083
  const { subscribe: t, set: e } = Dt([]);
880
1084
  return {
881
1085
  subscribe: t,
882
1086
  set: e
883
1087
  };
884
- }, yn = (t, e, n, o) => {
1088
+ }, In = (t, e, n, o) => {
885
1089
  const { store: i, selection: r, hover: a, viewport: s } = t, l = /* @__PURE__ */ new Map();
886
- let f = [], p;
887
- const c = (A, b) => {
888
- l.has(A) ? l.get(A).push(b) : l.set(A, [b]);
889
- }, u = (A, b) => {
890
- const g = l.get(A);
891
- if (g) {
892
- const d = g.indexOf(b);
893
- d !== -1 && g.splice(d, 1);
1090
+ let u = [], h;
1091
+ const c = (v, S) => {
1092
+ l.has(v) ? l.get(v).push(S) : l.set(v, [S]);
1093
+ }, p = (v, S) => {
1094
+ const m = l.get(v);
1095
+ if (m) {
1096
+ const f = m.indexOf(S);
1097
+ f !== -1 && m.splice(f, 1);
894
1098
  }
895
- }, h = (A, b, g) => {
896
- l.has(A) && setTimeout(() => {
897
- l.get(A).forEach((d) => {
1099
+ }, d = (v, S, m) => {
1100
+ l.has(v) && setTimeout(() => {
1101
+ l.get(v).forEach((f) => {
898
1102
  if (n) {
899
- const m = Array.isArray(b) ? b.map((C) => n.serialize(C)) : n.serialize(b), E = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
900
- d(m, E);
1103
+ const y = Array.isArray(S) ? S.map((E) => n.serialize(E)) : n.serialize(S), C = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
1104
+ f(y, C);
901
1105
  } else
902
- d(b, g);
1106
+ f(S, m);
903
1107
  });
904
1108
  }, 1);
905
1109
  };
906
- r.subscribe(({ selected: A }) => {
907
- if (!(f.length === 0 && A.length === 0)) {
908
- if (f.length === 0 && A.length > 0)
909
- f = A.map(({ id: b }) => i.getAnnotation(b));
910
- else if (f.length > 0 && A.length === 0)
911
- f.forEach((b) => {
912
- const g = i.getAnnotation(b.id);
913
- g && !G(g, b) && h("updateAnnotation", g, b);
914
- }), f = [];
1110
+ r.subscribe(({ selected: v }) => {
1111
+ if (!(u.length === 0 && v.length === 0)) {
1112
+ if (u.length === 0 && v.length > 0)
1113
+ u = v.map(({ id: S }) => i.getAnnotation(S));
1114
+ else if (u.length > 0 && v.length === 0)
1115
+ u.forEach((S) => {
1116
+ const m = i.getAnnotation(S.id);
1117
+ m && !G(m, S) && d("updateAnnotation", m, S);
1118
+ }), u = [];
915
1119
  else {
916
- const b = new Set(f.map((d) => d.id)), g = new Set(A.map(({ id: d }) => d));
917
- f.filter((d) => !g.has(d.id)).forEach((d) => {
918
- const m = i.getAnnotation(d.id);
919
- m && !G(m, d) && h("updateAnnotation", m, d);
920
- }), f = [
1120
+ const S = new Set(u.map((f) => f.id)), m = new Set(v.map(({ id: f }) => f));
1121
+ u.filter((f) => !m.has(f.id)).forEach((f) => {
1122
+ const y = i.getAnnotation(f.id);
1123
+ y && !G(y, f) && d("updateAnnotation", y, f);
1124
+ }), u = [
921
1125
  // Remove annotations that were deselected
922
- ...f.filter((d) => g.has(d.id)),
1126
+ ...u.filter((f) => m.has(f.id)),
923
1127
  // Add editable annotations that were selected
924
- ...A.filter(({ id: d }) => !b.has(d)).map(({ id: d }) => i.getAnnotation(d))
1128
+ ...v.filter(({ id: f }) => !S.has(f)).map(({ id: f }) => i.getAnnotation(f))
925
1129
  ];
926
1130
  }
927
- h("selectionChanged", f);
1131
+ d("selectionChanged", u);
928
1132
  }
929
- }), a.subscribe((A) => {
930
- !p && A ? h("mouseEnterAnnotation", i.getAnnotation(A)) : p && !A ? h("mouseLeaveAnnotation", i.getAnnotation(p)) : p && A && (h("mouseLeaveAnnotation", i.getAnnotation(p)), h("mouseEnterAnnotation", i.getAnnotation(A))), p = A;
931
- }), s == null || s.subscribe((A) => h("viewportIntersect", A.map((b) => i.getAnnotation(b)))), i.observe((A) => {
932
- const { created: b, deleted: g } = A.changes;
933
- (b || []).forEach((d) => h("createAnnotation", d)), (g || []).forEach((d) => h("deleteAnnotation", d)), (A.changes.updated || []).filter((d) => [
934
- ...d.bodiesCreated || [],
935
- ...d.bodiesDeleted || [],
936
- ...d.bodiesUpdated || []
937
- ].length > 0).forEach(({ oldValue: d, newValue: m }) => {
938
- const E = f.find((C) => C.id === d.id) || d;
939
- f = f.map((C) => C.id === d.id ? m : C), h("updateAnnotation", m, E);
1133
+ }), a.subscribe((v) => {
1134
+ !h && v ? d("mouseEnterAnnotation", i.getAnnotation(v)) : h && !v ? d("mouseLeaveAnnotation", i.getAnnotation(h)) : h && v && (d("mouseLeaveAnnotation", i.getAnnotation(h)), d("mouseEnterAnnotation", i.getAnnotation(v))), h = v;
1135
+ }), s == null || s.subscribe((v) => d("viewportIntersect", v.map((S) => i.getAnnotation(S)))), i.observe((v) => {
1136
+ const { created: S, deleted: m } = v.changes;
1137
+ (S || []).forEach((f) => d("createAnnotation", f)), (m || []).forEach((f) => d("deleteAnnotation", f)), (v.changes.updated || []).filter((f) => [
1138
+ ...f.bodiesCreated || [],
1139
+ ...f.bodiesDeleted || [],
1140
+ ...f.bodiesUpdated || []
1141
+ ].length > 0).forEach(({ oldValue: f, newValue: y }) => {
1142
+ const C = u.find((E) => E.id === f.id) || f;
1143
+ u = u.map((E) => E.id === f.id ? y : E), d("updateAnnotation", y, C);
940
1144
  });
941
- }, { origin: N.LOCAL }), i.observe((A) => {
942
- if (f) {
943
- const b = new Set(f.map((d) => d.id)), g = (A.changes.updated || []).filter(({ newValue: d }) => b.has(d.id)).map(({ newValue: d }) => d);
944
- g.length > 0 && (f = f.map((d) => g.find((E) => E.id === d.id) || d));
1145
+ }, { origin: k.LOCAL }), i.observe((v) => {
1146
+ if (u) {
1147
+ const S = new Set(u.map((f) => f.id)), m = (v.changes.updated || []).filter(({ newValue: f }) => S.has(f.id)).map(({ newValue: f }) => f);
1148
+ m.length > 0 && (u = u.map((f) => m.find((C) => C.id === f.id) || f));
945
1149
  }
946
- }, { origin: N.REMOTE });
947
- const x = (A) => (b) => {
948
- const { updated: g } = b;
949
- A ? (g || []).forEach((d) => h("updateAnnotation", d.oldValue, d.newValue)) : (g || []).forEach((d) => h("updateAnnotation", d.newValue, d.oldValue));
1150
+ }, { origin: k.REMOTE });
1151
+ const A = (v) => (S) => {
1152
+ const { updated: m } = S;
1153
+ v ? (m || []).forEach((f) => d("updateAnnotation", f.oldValue, f.newValue)) : (m || []).forEach((f) => d("updateAnnotation", f.newValue, f.oldValue));
950
1154
  };
951
- return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: u, emit: h };
952
- }, bn = (t) => (e) => e.reduce((n, o) => {
1155
+ return e.on("undo", A(!0)), e.on("redo", A(!1)), { on: c, off: p, emit: d };
1156
+ }, Nn = (t) => (e) => e.reduce((n, o) => {
953
1157
  const { parsed: i, error: r } = t.parse(o);
954
1158
  return r ? {
955
1159
  parsed: n.parsed,
@@ -960,47 +1164,47 @@ const gn = 250, pn = (t) => {
960
1164
  } : {
961
1165
  ...n
962
1166
  };
963
- }, { parsed: [], failed: [] }), wn = (t, e, n) => {
964
- const { store: o, selection: i } = t, r = (g) => {
1167
+ }, { parsed: [], failed: [] }), _n = (t, e, n) => {
1168
+ const { store: o, selection: i } = t, r = (m) => {
965
1169
  if (n) {
966
- const { parsed: d, error: m } = n.parse(g);
967
- d ? o.addAnnotation(d, N.REMOTE) : console.error(m);
1170
+ const { parsed: f, error: y } = n.parse(m);
1171
+ f ? o.addAnnotation(f, k.REMOTE) : console.error(y);
968
1172
  } else
969
- o.addAnnotation(g, N.REMOTE);
970
- }, a = () => i.clear(), s = () => o.clear(), l = (g) => {
971
- const d = o.getAnnotation(g);
972
- return n && d ? n.serialize(d) : d;
973
- }, f = () => n ? o.all().map(n.serialize) : o.all(), p = () => {
974
- var g;
975
- const d = (((g = i.selected) == null ? void 0 : g.map((m) => m.id)) || []).map((m) => o.getAnnotation(m)).filter(Boolean);
976
- return n ? d.map(n.serialize) : d;
977
- }, c = (g, d = !0) => fetch(g).then((m) => m.json()).then((m) => (h(m, d), m)), u = (g) => {
978
- if (typeof g == "string") {
979
- const d = o.getAnnotation(g);
980
- if (o.deleteAnnotation(g), d)
981
- return n ? n.serialize(d) : d;
1173
+ o.addAnnotation(m, k.REMOTE);
1174
+ }, a = () => i.clear(), s = () => o.clear(), l = (m) => {
1175
+ const f = o.getAnnotation(m);
1176
+ return n && f ? n.serialize(f) : f;
1177
+ }, u = () => n ? o.all().map(n.serialize) : o.all(), h = () => {
1178
+ var m;
1179
+ const f = (((m = i.selected) == null ? void 0 : m.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
1180
+ return n ? f.map(n.serialize) : f;
1181
+ }, c = (m, f = !0) => fetch(m).then((y) => y.json()).then((y) => (d(y, f), y)), p = (m) => {
1182
+ if (typeof m == "string") {
1183
+ const f = o.getAnnotation(m);
1184
+ if (o.deleteAnnotation(m), f)
1185
+ return n ? n.serialize(f) : f;
982
1186
  } else {
983
- const d = n ? n.parse(g).parsed : g;
984
- if (d)
985
- return o.deleteAnnotation(d), g;
1187
+ const f = n ? n.parse(m).parsed : m;
1188
+ if (f)
1189
+ return o.deleteAnnotation(f), m;
986
1190
  }
987
- }, h = (g, d = !0) => {
1191
+ }, d = (m, f = !0) => {
988
1192
  if (n) {
989
- const { parsed: m, failed: E } = bn(n)(g);
990
- E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotation(m, d, N.REMOTE);
1193
+ const { parsed: y, failed: C } = Nn(n)(m);
1194
+ C.length > 0 && console.warn(`Discarded ${C.length} invalid annotations`, C), o.bulkAddAnnotation(y, f, k.REMOTE);
991
1195
  } else
992
- o.bulkAddAnnotation(g, d, N.REMOTE);
993
- }, x = (g, d) => {
994
- g ? i.setSelected(g, d) : i.clear();
995
- }, A = (g) => {
996
- i.clear(), i.setUserSelectAction(g);
997
- }, b = (g) => {
1196
+ o.bulkAddAnnotation(m, f, k.REMOTE);
1197
+ }, A = (m, f) => {
1198
+ m ? i.setSelected(m, f) : i.clear();
1199
+ }, v = (m) => {
1200
+ i.clear(), i.setUserSelectAction(m);
1201
+ }, S = (m) => {
998
1202
  if (n) {
999
- const d = n.parse(g).parsed, m = n.serialize(o.getAnnotation(d.id));
1000
- return o.updateAnnotation(d), m;
1203
+ const f = n.parse(m).parsed, y = n.serialize(o.getAnnotation(f.id));
1204
+ return o.updateAnnotation(f), y;
1001
1205
  } else {
1002
- const d = o.getAnnotation(g.id);
1003
- return o.updateAnnotation(g), d;
1206
+ const f = o.getAnnotation(m.id);
1207
+ return o.updateAnnotation(m), f;
1004
1208
  }
1005
1209
  };
1006
1210
  return {
@@ -1010,19 +1214,19 @@ const gn = 250, pn = (t) => {
1010
1214
  canUndo: e.canUndo,
1011
1215
  clearAnnotations: s,
1012
1216
  getAnnotationById: l,
1013
- getAnnotations: f,
1014
- getSelected: p,
1217
+ getAnnotations: u,
1218
+ getSelected: h,
1015
1219
  loadAnnotations: c,
1016
1220
  redo: e.redo,
1017
- removeAnnotation: u,
1018
- setAnnotations: h,
1019
- setSelected: x,
1020
- setUserSelectAction: A,
1221
+ removeAnnotation: p,
1222
+ setAnnotations: d,
1223
+ setSelected: A,
1224
+ setUserSelectAction: v,
1021
1225
  undo: e.undo,
1022
- updateAnnotation: b
1226
+ updateAnnotation: S
1023
1227
  };
1024
- }, vn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1025
- let xn = (t) => crypto.getRandomValues(new Uint8Array(t)), An = (t, e, n) => {
1228
+ }, Un = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1229
+ let Vn = (t) => crypto.getRandomValues(new Uint8Array(t)), Dn = (t, e, n) => {
1026
1230
  let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
1027
1231
  return (r = e) => {
1028
1232
  let a = "";
@@ -1032,13 +1236,13 @@ let xn = (t) => crypto.getRandomValues(new Uint8Array(t)), An = (t, e, n) => {
1032
1236
  if (a += t[s[l] & o] || "", a.length === r) return a;
1033
1237
  }
1034
1238
  };
1035
- }, En = (t, e = 21) => An(t, e, xn), Sn = (t = 21) => {
1239
+ }, Kn = (t, e = 21) => Dn(t, e, Vn), Yn = (t = 21) => {
1036
1240
  let e = "", n = crypto.getRandomValues(new Uint8Array(t));
1037
1241
  for (; t--; )
1038
- e += vn[n[t] & 63];
1242
+ e += Un[n[t] & 63];
1039
1243
  return e;
1040
1244
  };
1041
- const Cn = () => ({ isGuest: !0, id: En("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Ln = (t) => {
1245
+ const Xn = () => ({ isGuest: !0, id: Kn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Pn = (t) => {
1042
1246
  const e = JSON.stringify(t);
1043
1247
  let n = 0;
1044
1248
  for (let o = 0, i = e.length; o < i; o++) {
@@ -1046,20 +1250,20 @@ const Cn = () => ({ isGuest: !0, id: En("1234567890abcdefghijklmnopqrstuvwxyzABC
1046
1250
  n = (n << 5) - n + r, n |= 0;
1047
1251
  }
1048
1252
  return `${n}`;
1049
- }, fe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, On = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1050
- const { id: o, type: i, purpose: r, value: a, created: s, modified: l, creator: f, ...p } = n;
1253
+ }, he = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, $n = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1254
+ const { id: o, type: i, purpose: r, value: a, created: s, modified: l, creator: u, ...h } = n;
1051
1255
  return {
1052
- id: o || `temp-${Ln(n)}`,
1256
+ id: o || `temp-${Pn(n)}`,
1053
1257
  annotation: e,
1054
1258
  type: i,
1055
1259
  purpose: r,
1056
1260
  value: a,
1057
- creator: fe(f),
1261
+ creator: he(u),
1058
1262
  created: s ? new Date(s) : void 0,
1059
1263
  updated: l ? new Date(l) : void 0,
1060
- ...p
1264
+ ...h
1061
1265
  };
1062
- }), Tn = (t) => t.map((e) => {
1266
+ }), jn = (t) => t.map((e) => {
1063
1267
  var n;
1064
1268
  const { annotation: o, created: i, updated: r, ...a } = e, s = {
1065
1269
  ...a,
@@ -1068,276 +1272,11 @@ const Cn = () => ({ isGuest: !0, id: En("1234567890abcdefghijklmnopqrstuvwxyzABC
1068
1272
  };
1069
1273
  return (n = s.id) != null && n.startsWith("temp-") && delete s.id, s;
1070
1274
  });
1071
- Sn();
1072
- const he = "not-annotatable", H = `.${he}`, Rn = (t) => {
1073
- var n;
1074
- const e = t.commonAncestorContainer;
1075
- return e instanceof HTMLElement ? !e.closest(H) : !((n = e.parentElement) != null && n.closest(H));
1076
- }, Bn = function* (t) {
1077
- const e = document.createNodeIterator(
1078
- t.commonAncestorContainer,
1079
- NodeFilter.SHOW_ELEMENT,
1080
- (o) => o instanceof HTMLElement && o.classList.contains(he) && !o.parentElement.closest(H) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
1081
- );
1082
- let n;
1083
- for (; n = e.nextNode(); )
1084
- n instanceof HTMLElement && (yield n);
1085
- }, Mn = (t) => {
1086
- if (!Rn(t)) return [];
1087
- const e = [];
1088
- let n = null;
1089
- for (const o of Bn(t)) {
1090
- let i;
1091
- n ? (i = document.createRange(), i.setStartAfter(n), i.setEndBefore(o)) : (i = t.cloneRange(), i.setEndBefore(o)), i.collapsed || e.push(i), n = o;
1092
- }
1093
- if (n) {
1094
- const o = t.cloneRange();
1095
- o.setStartAfter(n), o.collapsed || e.push(o);
1096
- }
1097
- return e.length > 0 ? e : [t];
1098
- }, kt = (t) => {
1099
- const e = t.cloneContents();
1100
- return e.querySelectorAll(H).forEach((n) => n.remove()), e;
1101
- }, Nn = (t) => t.addEventListener("click", (e) => {
1102
- // Allow clicks within not-annotatable elements
1103
- !e.target.closest(H) && !e.target.closest("a") && e.preventDefault();
1104
- }), kn = (t) => {
1105
- !t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
1106
- }, Co = (t) => {
1107
- const e = t.cloneContents();
1108
- return e.querySelectorAll(H).forEach((n) => n.remove()), e;
1109
- }, Zt = (t, e) => {
1110
- const n = document.createNodeIterator(e);
1111
- let o = 0, i = n.nextNode();
1112
- for (; i !== null; ) {
1113
- if (i === t)
1114
- return o;
1115
- o += 1, i = n.nextNode();
1116
- }
1117
- }, te = (t, e) => {
1118
- const n = document.createNodeIterator(e);
1119
- let o = null;
1120
- for (let i = 0; i < t + 1; i++)
1121
- o = n.nextNode();
1122
- return o;
1123
- }, In = (t) => {
1124
- const {
1125
- commonAncestorContainer: e,
1126
- startContainer: n,
1127
- startOffset: o,
1128
- endContainer: i,
1129
- endOffset: r
1130
- } = t, a = Array.from(e.childNodes).map((c) => {
1131
- const u = c.cloneNode(!0);
1132
- return c.nodeName === "CANVAS" ? c : u;
1133
- }), s = Zt(n, e), l = Zt(i, e), f = () => {
1134
- const c = e;
1135
- c.replaceChildren(...a);
1136
- const u = te(s, c), h = te(l, c);
1137
- return t.setStart(u, o), t.setEnd(h, r), t;
1138
- }, p = (c) => {
1139
- const u = document.createElement("SPAN");
1140
- return c.surroundContents(u), u;
1141
- };
1142
- if (n === i)
1143
- throw "Not implemented";
1144
- {
1145
- const c = document.createRange();
1146
- c.selectNodeContents(n), c.setStart(n, o);
1147
- const u = p(c), h = document.createRange();
1148
- h.selectNode(i), h.setEnd(i, r);
1149
- const x = p(h), b = _n(t).reverse().map((g) => {
1150
- var m;
1151
- const d = document.createElement("SPAN");
1152
- return (m = g.parentNode) == null || m.insertBefore(d, g), d.appendChild(g), d;
1153
- });
1154
- return { unwrap: f, nodes: [u, ...b, x] };
1155
- }
1156
- }, _n = (t) => {
1157
- const {
1158
- commonAncestorContainer: e,
1159
- startContainer: n,
1160
- endContainer: o
1161
- } = t, i = document.createNodeIterator(e, NodeFilter.SHOW_TEXT);
1162
- let r = i.nextNode(), a = !1;
1163
- const s = [];
1164
- for (; r != null; )
1165
- r === o && (a = !1), a && s.push(r), r === n && (a = !0), r = i.nextNode();
1166
- return s;
1167
- }, Lo = (t) => {
1168
- const { startContainer: e, endContainer: n } = t;
1169
- if (e === n)
1170
- return Array.from(t.getClientRects());
1171
- {
1172
- const { unwrap: o, nodes: i } = In(t), r = i.reduce((a, s) => [...a, ...s.getClientRects()], []);
1173
- return o(), r;
1174
- }
1175
- }, Un = (t, e, n = 10, o) => {
1176
- const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
1177
- r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
1178
- const a = kt(r).textContent, s = document.createRange();
1179
- s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
1180
- const l = kt(s).textContent;
1181
- return {
1182
- prefix: a.substring(a.length - n),
1183
- suffix: l.substring(0, n)
1184
- };
1185
- }, Vn = /^\s*$/, Dn = (t) => Vn.test(t.toString()), W = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), Kn = (t, e) => {
1186
- const n = (r) => Math.round(r * 10) / 10, o = {
1187
- top: n(t.top),
1188
- bottom: n(t.bottom),
1189
- left: n(t.left),
1190
- right: n(t.right)
1191
- }, i = {
1192
- top: n(e.top),
1193
- bottom: n(e.bottom),
1194
- left: n(e.left),
1195
- right: n(e.right)
1196
- };
1197
- if (Math.abs(o.top - i.top) < 0.5 && Math.abs(o.bottom - i.bottom) < 0.5) {
1198
- if (Math.abs(o.left - i.right) < 0.5 || Math.abs(o.right - i.left) < 0.5)
1199
- return "inline-adjacent";
1200
- if (o.left >= i.left && o.right <= i.right)
1201
- return "inline-is-contained";
1202
- if (o.left <= i.left && o.right >= i.right)
1203
- return "inline-contains";
1204
- } else if (o.top <= i.top && o.bottom >= i.bottom) {
1205
- if (o.left <= i.left && o.right >= i.right)
1206
- return "block-contains";
1207
- } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
1208
- return "block-is-contained";
1209
- }, Xn = (t, e) => {
1210
- 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);
1211
- return new DOMRect(n, i, o - n, r - i);
1212
- }, Yn = (t) => t.reduce((e, n) => {
1213
- if (n.width === 0 || n.height === 0)
1214
- return e;
1215
- let o = [...e], i = !1;
1216
- for (const r of e) {
1217
- const a = Kn(n, r);
1218
- if (a === "inline-adjacent") {
1219
- o = o.map((s) => s === r ? Xn(n, r) : s), i = !0;
1220
- break;
1221
- } else if (a === "inline-contains") {
1222
- o = o.map((s) => s === r ? n : s), i = !0;
1223
- break;
1224
- } else if (a === "inline-is-contained") {
1225
- i = !0;
1226
- break;
1227
- } else if (a === "block-contains" || a === "block-is-contained") {
1228
- n.width < r.width && (o = o.map((s) => s === r ? n : s)), i = !0;
1229
- break;
1230
- }
1231
- }
1232
- return i ? o : [...o, n];
1233
- }, []), Oo = (t) => ({
1234
- length: t.length,
1235
- item: (e) => t[e],
1236
- [Symbol.iterator]: function* () {
1237
- for (let e = 0; e < this.length; e++)
1238
- yield this.item(e);
1239
- }
1240
- }), Pn = (t, e, n) => {
1241
- const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
1242
- o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
1243
- const r = kt(o).textContent, a = t.toString(), s = r.length || 0, l = s + a.length;
1244
- return n ? { quote: a, start: s, end: l, range: t, offsetReference: i } : { quote: a, start: s, end: l, range: t };
1245
- }, ge = (t, e) => {
1246
- var p, c;
1247
- const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
1248
- e,
1249
- NodeFilter.SHOW_TEXT,
1250
- (u) => {
1251
- var h;
1252
- return (h = u.parentElement) != null && h.closest(H) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
1253
- }
1254
- );
1255
- let a = 0;
1256
- const s = document.createRange();
1257
- let l = r.nextNode();
1258
- l === null && console.error("Could not revive annotation target. Content missing.");
1259
- let f = !i;
1260
- for (; l !== null; ) {
1261
- if (f || (f = i == null ? void 0 : i.contains(l)), f) {
1262
- const u = ((p = l.textContent) == null ? void 0 : p.length) || 0;
1263
- if (a + u > n) {
1264
- s.setStart(l, n - a);
1265
- break;
1266
- }
1267
- a += u;
1268
- }
1269
- l = r.nextNode();
1270
- }
1271
- for (; l !== null; ) {
1272
- const u = ((c = l.textContent) == null ? void 0 : c.length) || 0;
1273
- if (a + u >= o) {
1274
- s.setEnd(l, o - a);
1275
- break;
1276
- }
1277
- a += u, l = r.nextNode();
1278
- }
1279
- return {
1280
- ...t,
1281
- range: s
1282
- };
1283
- }, bt = (t, e) => W(t.selector) ? t : {
1284
- ...t,
1285
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : ge(n, e))
1286
- }, Lt = (t, e) => W(t.target.selector) ? t : { ...t, target: bt(t.target, e) }, $n = (t, e) => {
1287
- const n = t.cloneRange();
1288
- return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
1289
- }, Hn = (t, e) => {
1290
- const { left: n, top: o, right: i, bottom: r } = t;
1291
- return new DOMRect(n - e.left, o - e.top, i - n, r - o);
1292
- }, To = (t, e) => {
1293
- const { left: n, top: o, right: i, bottom: r } = t;
1294
- return new DOMRect(n + e.left, o + e.top, i - n, r - o);
1295
- }, jn = (t) => ({
1296
- ...t,
1297
- type: t.type,
1298
- x: t.x,
1299
- y: t.y,
1300
- clientX: t.clientX,
1301
- clientY: t.clientY,
1302
- offsetX: t.offsetX,
1303
- offsetY: t.offsetY,
1304
- screenX: t.screenX,
1305
- screenY: t.screenY,
1306
- isPrimary: t.isPrimary,
1307
- altKey: t.altKey,
1308
- ctrlKey: t.ctrlKey,
1309
- metaKey: t.metaKey,
1310
- shiftKey: t.shiftKey,
1311
- button: t.button,
1312
- buttons: t.buttons,
1313
- currentTarget: t.currentTarget,
1314
- target: t.target,
1315
- defaultPrevented: t.defaultPrevented,
1316
- detail: t.detail,
1317
- eventPhase: t.eventPhase,
1318
- pointerId: t.pointerId,
1319
- pointerType: t.pointerType,
1320
- timeStamp: t.timeStamp
1321
- }), zn = (t) => ({
1322
- ...t,
1323
- type: t.type,
1324
- key: t.key,
1325
- code: t.code,
1326
- location: t.location,
1327
- repeat: t.repeat,
1328
- altKey: t.altKey,
1329
- ctrlKey: t.ctrlKey,
1330
- metaKey: t.metaKey,
1331
- shiftKey: t.shiftKey,
1332
- currentTarget: t.currentTarget,
1333
- target: t.target,
1334
- defaultPrevented: t.defaultPrevented,
1335
- detail: t.detail,
1336
- timeStamp: t.timeStamp
1337
- }), Ro = (t, e) => ({
1338
- parse: (n) => qn(n),
1339
- serialize: (n) => Gn(n, t, e)
1340
- }), Fn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, Wn = (t) => {
1275
+ Yn();
1276
+ const Lo = (t, e) => ({
1277
+ parse: (n) => Fn(n),
1278
+ serialize: (n) => Wn(n, t, e)
1279
+ }), Hn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, zn = (t) => {
1341
1280
  const {
1342
1281
  id: e,
1343
1282
  creator: n,
@@ -1348,7 +1287,7 @@ const he = "not-annotatable", H = `.${he}`, Rn = (t) => {
1348
1287
  if (a.length === 0)
1349
1288
  return { error: Error(`No targets found for annotation: ${t.id}`) };
1350
1289
  const s = {
1351
- creator: fe(n),
1290
+ creator: he(n),
1352
1291
  created: o ? new Date(o) : void 0,
1353
1292
  updated: i ? new Date(i) : void 0,
1354
1293
  annotation: e,
@@ -1356,36 +1295,36 @@ const he = "not-annotatable", H = `.${he}`, Rn = (t) => {
1356
1295
  styleClass: a[0].styleClass
1357
1296
  };
1358
1297
  for (const l of a) {
1359
- const p = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((c, u) => {
1360
- switch (u.type) {
1298
+ const h = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((c, p) => {
1299
+ switch (p.type) {
1361
1300
  case "TextQuoteSelector":
1362
- c.quote = u.exact;
1301
+ c.quote = p.exact;
1363
1302
  break;
1364
1303
  case "TextPositionSelector":
1365
- c.start = u.start, c.end = u.end;
1304
+ c.start = p.start, c.end = p.end;
1366
1305
  break;
1367
1306
  }
1368
1307
  return c;
1369
1308
  }, {});
1370
- if (Fn(p))
1371
- s.selector.push({ id: l.id, ...p });
1309
+ if (Hn(h))
1310
+ s.selector.push({ id: l.id, ...h });
1372
1311
  else {
1373
1312
  const c = [
1374
- p.start ? void 0 : "TextPositionSelector",
1375
- p.quote ? void 0 : "TextQuoteSelector"
1313
+ h.start ? void 0 : "TextPositionSelector",
1314
+ h.quote ? void 0 : "TextQuoteSelector"
1376
1315
  ].filter(Boolean);
1377
1316
  return { error: Error(`Missing selector types: ${c.join(" and ")} for annotation: ${t.id}`) };
1378
1317
  }
1379
1318
  }
1380
1319
  return { parsed: s };
1381
- }, qn = (t) => {
1382
- const e = t.id || le(), {
1320
+ }, Fn = (t) => {
1321
+ const e = t.id || de(), {
1383
1322
  creator: n,
1384
1323
  created: o,
1385
1324
  modified: i,
1386
1325
  body: r,
1387
1326
  ...a
1388
- } = t, s = On(r, e), l = Wn(t);
1327
+ } = t, s = $n(r, e), l = zn(t);
1389
1328
  return "error" in l ? { error: l.error } : {
1390
1329
  parsed: {
1391
1330
  ...a,
@@ -1394,29 +1333,29 @@ const he = "not-annotatable", H = `.${he}`, Rn = (t) => {
1394
1333
  target: l.parsed
1395
1334
  }
1396
1335
  };
1397
- }, Gn = (t, e, n) => {
1336
+ }, Wn = (t, e, n) => {
1398
1337
  const { bodies: o, target: i, ...r } = t, {
1399
1338
  selector: a,
1400
1339
  creator: s,
1401
1340
  created: l,
1402
- updated: f,
1403
- ...p
1404
- } = i, c = a.map((u) => {
1405
- const { quote: h, start: x, end: A, range: b } = u, { prefix: g, suffix: d } = Un(b, n), m = [{
1341
+ updated: u,
1342
+ ...h
1343
+ } = i, c = a.map((p) => {
1344
+ const { quote: d, start: A, end: v, range: S } = p, { prefix: m, suffix: f } = Ne(S, n), y = [{
1406
1345
  type: "TextQuoteSelector",
1407
- exact: h,
1408
- prefix: g,
1409
- suffix: d
1346
+ exact: d,
1347
+ prefix: m,
1348
+ suffix: f
1410
1349
  }, {
1411
1350
  type: "TextPositionSelector",
1412
- start: x,
1413
- end: A
1351
+ start: A,
1352
+ end: v
1414
1353
  }];
1415
1354
  return {
1416
- ...p,
1417
- id: u.id,
1355
+ ...h,
1356
+ id: p.id,
1418
1357
  source: e,
1419
- selector: m
1358
+ selector: y
1420
1359
  };
1421
1360
  });
1422
1361
  return {
@@ -1424,18 +1363,18 @@ const he = "not-annotatable", H = `.${he}`, Rn = (t) => {
1424
1363
  "@context": "http://www.w3.org/ns/anno.jsonld",
1425
1364
  id: t.id,
1426
1365
  type: "Annotation",
1427
- body: Tn(t.bodies),
1366
+ body: jn(t.bodies),
1428
1367
  creator: s,
1429
1368
  created: l == null ? void 0 : l.toISOString(),
1430
- modified: f == null ? void 0 : f.toISOString(),
1369
+ modified: u == null ? void 0 : u.toISOString(),
1431
1370
  target: c
1432
1371
  };
1433
1372
  };
1434
- function pe(t, e, n = 0, o = t.length - 1, i = Qn) {
1373
+ function pe(t, e, n = 0, o = t.length - 1, i = qn) {
1435
1374
  for (; o > n; ) {
1436
1375
  if (o - n > 600) {
1437
- const l = o - n + 1, f = e - n + 1, p = Math.log(l), c = 0.5 * Math.exp(2 * p / 3), u = 0.5 * Math.sqrt(p * c * (l - c) / l) * (f - l / 2 < 0 ? -1 : 1), h = Math.max(n, Math.floor(e - f * c / l + u)), x = Math.min(o, Math.floor(e + (l - f) * c / l + u));
1438
- pe(t, e, h, x, i);
1376
+ const l = o - n + 1, u = e - n + 1, h = Math.log(l), c = 0.5 * Math.exp(2 * h / 3), p = 0.5 * Math.sqrt(h * c * (l - c) / l) * (u - l / 2 < 0 ? -1 : 1), d = Math.max(n, Math.floor(e - u * c / l + p)), A = Math.min(o, Math.floor(e + (l - u) * c / l + p));
1377
+ pe(t, e, d, A, i);
1439
1378
  }
1440
1379
  const r = t[e];
1441
1380
  let a = n, s = o;
@@ -1450,10 +1389,10 @@ function tt(t, e, n) {
1450
1389
  const o = t[e];
1451
1390
  t[e] = t[n], t[n] = o;
1452
1391
  }
1453
- function Qn(t, e) {
1392
+ function qn(t, e) {
1454
1393
  return t < e ? -1 : t > e ? 1 : 0;
1455
1394
  }
1456
- class Jn {
1395
+ class Gn {
1457
1396
  constructor(e = 9) {
1458
1397
  this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
1459
1398
  }
@@ -1463,12 +1402,12 @@ class Jn {
1463
1402
  search(e) {
1464
1403
  let n = this.data;
1465
1404
  const o = [];
1466
- if (!pt(e, n)) return o;
1405
+ if (!gt(e, n)) return o;
1467
1406
  const i = this.toBBox, r = [];
1468
1407
  for (; n; ) {
1469
1408
  for (let a = 0; a < n.children.length; a++) {
1470
1409
  const s = n.children[a], l = n.leaf ? i(s) : s;
1471
- pt(e, l) && (n.leaf ? o.push(s) : Tt(e, l) ? this._all(s, o) : r.push(s));
1410
+ gt(e, l) && (n.leaf ? o.push(s) : Tt(e, l) ? this._all(s, o) : r.push(s));
1472
1411
  }
1473
1412
  n = r.pop();
1474
1413
  }
@@ -1476,12 +1415,12 @@ class Jn {
1476
1415
  }
1477
1416
  collides(e) {
1478
1417
  let n = this.data;
1479
- if (!pt(e, n)) return !1;
1418
+ if (!gt(e, n)) return !1;
1480
1419
  const o = [];
1481
1420
  for (; n; ) {
1482
1421
  for (let i = 0; i < n.children.length; i++) {
1483
1422
  const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
1484
- if (pt(e, a)) {
1423
+ if (gt(e, a)) {
1485
1424
  if (n.leaf || Tt(e, a)) return !0;
1486
1425
  o.push(r);
1487
1426
  }
@@ -1521,14 +1460,14 @@ class Jn {
1521
1460
  if (!e) return this;
1522
1461
  let o = this.data;
1523
1462
  const i = this.toBBox(e), r = [], a = [];
1524
- let s, l, f;
1463
+ let s, l, u;
1525
1464
  for (; o || r.length; ) {
1526
- if (o || (o = r.pop(), l = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
1527
- const p = Zn(e, o.children, n);
1528
- if (p !== -1)
1529
- return o.children.splice(p, 1), r.push(o), this._condense(r), this;
1465
+ if (o || (o = r.pop(), l = r[r.length - 1], s = a.pop(), u = !0), o.leaf) {
1466
+ const h = Qn(e, o.children, n);
1467
+ if (h !== -1)
1468
+ return o.children.splice(h, 1), r.push(o), this._condense(r), this;
1530
1469
  }
1531
- !f && !o.leaf && Tt(o, i) ? (r.push(o), a.push(s), s = 0, l = o, o = o.children[0]) : l ? (s++, o = l.children[s], f = !1) : o = null;
1470
+ !u && !o.leaf && Tt(o, i) ? (r.push(o), a.push(s), s = 0, l = o, o = o.children[0]) : l ? (s++, o = l.children[s], u = !1) : o = null;
1532
1471
  }
1533
1472
  return this;
1534
1473
  }
@@ -1559,14 +1498,14 @@ class Jn {
1559
1498
  if (r <= a)
1560
1499
  return s = Z(e.slice(n, o + 1)), J(s, this.toBBox), s;
1561
1500
  i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = Z([]), s.leaf = !1, s.height = i;
1562
- const l = Math.ceil(r / a), f = l * Math.ceil(Math.sqrt(a));
1563
- ee(e, n, o, f, this.compareMinX);
1564
- for (let p = n; p <= o; p += f) {
1565
- const c = Math.min(p + f - 1, o);
1566
- ee(e, p, c, l, this.compareMinY);
1567
- for (let u = p; u <= c; u += l) {
1568
- const h = Math.min(u + l - 1, c);
1569
- s.children.push(this._build(e, u, h, i - 1));
1501
+ const l = Math.ceil(r / a), u = l * Math.ceil(Math.sqrt(a));
1502
+ Zt(e, n, o, u, this.compareMinX);
1503
+ for (let h = n; h <= o; h += u) {
1504
+ const c = Math.min(h + u - 1, o);
1505
+ Zt(e, h, c, l, this.compareMinY);
1506
+ for (let p = h; p <= c; p += l) {
1507
+ const d = Math.min(p + l - 1, c);
1508
+ s.children.push(this._build(e, p, d, i - 1));
1570
1509
  }
1571
1510
  }
1572
1511
  return J(s, this.toBBox), s;
@@ -1575,8 +1514,8 @@ class Jn {
1575
1514
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1576
1515
  let r = 1 / 0, a = 1 / 0, s;
1577
1516
  for (let l = 0; l < n.children.length; l++) {
1578
- const f = n.children[l], p = Ot(f), c = no(e, f) - p;
1579
- c < a ? (a = c, r = p < r ? p : r, s = f) : c === a && p < r && (r = p, s = f);
1517
+ const u = n.children[l], h = Ot(u), c = to(e, u) - h;
1518
+ c < a ? (a = c, r = h < r ? h : r, s = u) : c === a && h < r && (r = h, s = u);
1580
1519
  }
1581
1520
  n = s || n.children[0];
1582
1521
  }
@@ -1601,28 +1540,28 @@ class Jn {
1601
1540
  _chooseSplitIndex(e, n, o) {
1602
1541
  let i, r = 1 / 0, a = 1 / 0;
1603
1542
  for (let s = n; s <= o - n; s++) {
1604
- const l = nt(e, 0, s, this.toBBox), f = nt(e, s, o, this.toBBox), p = oo(l, f), c = Ot(l) + Ot(f);
1605
- p < r ? (r = p, i = s, a = c < a ? c : a) : p === r && c < a && (a = c, i = s);
1543
+ const l = nt(e, 0, s, this.toBBox), u = nt(e, s, o, this.toBBox), h = eo(l, u), c = Ot(l) + Ot(u);
1544
+ h < r ? (r = h, i = s, a = c < a ? c : a) : h === r && c < a && (a = c, i = s);
1606
1545
  }
1607
1546
  return i || o - n;
1608
1547
  }
1609
1548
  // sorts node children by the best axis for split
1610
1549
  _chooseSplitAxis(e, n, o) {
1611
- const i = e.leaf ? this.compareMinX : to, r = e.leaf ? this.compareMinY : eo, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1550
+ const i = e.leaf ? this.compareMinX : Jn, r = e.leaf ? this.compareMinY : Zn, a = this._allDistMargin(e, n, o, i), s = this._allDistMargin(e, n, o, r);
1612
1551
  a < s && e.children.sort(i);
1613
1552
  }
1614
1553
  // total margin of all possible split distributions where each node is at least m full
1615
1554
  _allDistMargin(e, n, o, i) {
1616
1555
  e.children.sort(i);
1617
1556
  const r = this.toBBox, a = nt(e, 0, n, r), s = nt(e, o - n, o, r);
1618
- let l = gt(a) + gt(s);
1619
- for (let f = n; f < o - n; f++) {
1620
- const p = e.children[f];
1621
- ot(a, e.leaf ? r(p) : p), l += gt(a);
1557
+ let l = pt(a) + pt(s);
1558
+ for (let u = n; u < o - n; u++) {
1559
+ const h = e.children[u];
1560
+ ot(a, e.leaf ? r(h) : h), l += pt(a);
1622
1561
  }
1623
- for (let f = o - n - 1; f >= n; f--) {
1624
- const p = e.children[f];
1625
- ot(s, e.leaf ? r(p) : p), l += gt(s);
1562
+ for (let u = o - n - 1; u >= n; u--) {
1563
+ const h = e.children[u];
1564
+ ot(s, e.leaf ? r(h) : h), l += pt(s);
1626
1565
  }
1627
1566
  return l;
1628
1567
  }
@@ -1635,7 +1574,7 @@ class Jn {
1635
1574
  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);
1636
1575
  }
1637
1576
  }
1638
- function Zn(t, e, n) {
1577
+ function Qn(t, e, n) {
1639
1578
  if (!n) return e.indexOf(t);
1640
1579
  for (let o = 0; o < e.length; o++)
1641
1580
  if (n(t, e[o])) return o;
@@ -1655,29 +1594,29 @@ function nt(t, e, n, o, i) {
1655
1594
  function ot(t, e) {
1656
1595
  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;
1657
1596
  }
1658
- function to(t, e) {
1597
+ function Jn(t, e) {
1659
1598
  return t.minX - e.minX;
1660
1599
  }
1661
- function eo(t, e) {
1600
+ function Zn(t, e) {
1662
1601
  return t.minY - e.minY;
1663
1602
  }
1664
1603
  function Ot(t) {
1665
1604
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1666
1605
  }
1667
- function gt(t) {
1606
+ function pt(t) {
1668
1607
  return t.maxX - t.minX + (t.maxY - t.minY);
1669
1608
  }
1670
- function no(t, e) {
1609
+ function to(t, e) {
1671
1610
  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));
1672
1611
  }
1673
- function oo(t, e) {
1612
+ function eo(t, e) {
1674
1613
  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);
1675
1614
  return Math.max(0, i - n) * Math.max(0, r - o);
1676
1615
  }
1677
1616
  function Tt(t, e) {
1678
1617
  return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1679
1618
  }
1680
- function pt(t, e) {
1619
+ function gt(t, e) {
1681
1620
  return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
1682
1621
  }
1683
1622
  function Z(t) {
@@ -1691,7 +1630,7 @@ function Z(t) {
1691
1630
  maxY: -1 / 0
1692
1631
  };
1693
1632
  }
1694
- function ee(t, e, n, o, i) {
1633
+ function Zt(t, e, n, o, i) {
1695
1634
  const r = [e, n];
1696
1635
  for (; r.length; ) {
1697
1636
  if (n = r.pop(), e = r.pop(), n - e <= o) continue;
@@ -1699,7 +1638,7 @@ function ee(t, e, n, o, i) {
1699
1638
  pe(t, a, e, n, i), r.push(e, a, a, n);
1700
1639
  }
1701
1640
  }
1702
- let io = () => ({
1641
+ let no = () => ({
1703
1642
  emit(t, ...e) {
1704
1643
  for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
1705
1644
  o[n](...e);
@@ -1713,217 +1652,154 @@ let io = () => ({
1713
1652
  };
1714
1653
  }
1715
1654
  });
1716
- const ro = (t, e) => {
1717
- const n = new Jn(), o = /* @__PURE__ */ new Map(), i = io(), r = (m, E) => {
1718
- const C = m.selector.flatMap((T) => {
1719
- const O = W([T]) ? T.range : ge(T, e).range;
1655
+ const oo = (t, e) => {
1656
+ const n = new Gn(), o = /* @__PURE__ */ new Map(), i = no(), r = (y, C) => {
1657
+ const E = y.selector.flatMap((T) => {
1658
+ const O = W([T]) ? T.range : se(T, e).range;
1720
1659
  return Array.from(O.getClientRects());
1721
- }), S = Yn(C).map((T) => Hn(T, E));
1722
- return S.map((T) => {
1723
- const { x: O, y: R, width: y, height: w } = T;
1660
+ }), b = Ke(E).map((T) => Pe(T, C));
1661
+ return b.map((T) => {
1662
+ const { x: O, y: R, width: g, height: w } = T;
1724
1663
  return {
1725
1664
  minX: O,
1726
1665
  minY: R,
1727
- maxX: O + y,
1666
+ maxX: O + g,
1728
1667
  maxY: R + w,
1729
1668
  annotation: {
1730
- id: m.annotation,
1731
- rects: S
1669
+ id: y.annotation,
1670
+ rects: b
1732
1671
  }
1733
1672
  };
1734
1673
  });
1735
1674
  }, a = () => [...o.values()], s = () => {
1736
1675
  n.clear(), o.clear();
1737
- }, l = (m) => {
1738
- const E = r(m, e.getBoundingClientRect());
1739
- E.forEach((C) => n.insert(C)), o.set(m.annotation, E);
1740
- }, f = (m) => {
1741
- const E = o.get(m.annotation);
1742
- E && (E.forEach((C) => n.remove(C)), o.delete(m.annotation));
1743
- }, p = (m) => {
1744
- f(m), l(m);
1745
- }, c = (m, E = !0) => {
1746
- E && s();
1747
- const C = e.getBoundingClientRect(), S = m.map((O) => ({ target: O, rects: r(O, C) }));
1748
- S.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
1749
- const T = S.flatMap(({ rects: O }) => O);
1676
+ }, l = (y) => {
1677
+ const C = r(y, e.getBoundingClientRect());
1678
+ C.forEach((E) => n.insert(E)), o.set(y.annotation, C);
1679
+ }, u = (y) => {
1680
+ const C = o.get(y.annotation);
1681
+ C && (C.forEach((E) => n.remove(E)), o.delete(y.annotation));
1682
+ }, h = (y) => {
1683
+ u(y), l(y);
1684
+ }, c = (y, C = !0) => {
1685
+ C && s();
1686
+ const E = e.getBoundingClientRect(), b = y.map((O) => ({ target: O, rects: r(O, E) }));
1687
+ b.forEach(({ target: O, rects: R }) => o.set(O.annotation, R));
1688
+ const T = b.flatMap(({ rects: O }) => O);
1750
1689
  n.load(T);
1751
- }, u = (m, E, C = !1) => {
1752
- const S = n.search({
1753
- minX: m,
1754
- minY: E,
1755
- maxX: m,
1756
- maxY: E
1757
- }), T = (O) => O.annotation.rects.reduce((R, y) => R + y.width * y.height, 0);
1758
- return S.length > 0 ? (S.sort((O, R) => T(O) - T(R)), C ? S.map((O) => O.annotation.id) : [S[0].annotation.id]) : [];
1759
- }, h = (m) => {
1760
- const E = x(m);
1761
- if (E.length === 0)
1690
+ }, p = (y, C, E = !1) => {
1691
+ const b = n.search({
1692
+ minX: y,
1693
+ minY: C,
1694
+ maxX: y,
1695
+ maxY: C
1696
+ }), T = (O) => O.annotation.rects.reduce((R, g) => R + g.width * g.height, 0);
1697
+ return b.length > 0 ? (b.sort((O, R) => T(O) - T(R)), E ? b.map((O) => O.annotation.id) : [b[0].annotation.id]) : [];
1698
+ }, d = (y) => {
1699
+ const C = A(y);
1700
+ if (C.length === 0)
1762
1701
  return;
1763
- let C = E[0].left, S = E[0].top, T = E[0].right, O = E[0].bottom;
1764
- for (let R = 1; R < E.length; R++) {
1765
- const y = E[R];
1766
- C = Math.min(C, y.left), S = Math.min(S, y.top), T = Math.max(T, y.right), O = Math.max(O, y.bottom);
1702
+ let E = C[0].left, b = C[0].top, T = C[0].right, O = C[0].bottom;
1703
+ for (let R = 1; R < C.length; R++) {
1704
+ const g = C[R];
1705
+ E = Math.min(E, g.left), b = Math.min(b, g.top), T = Math.max(T, g.right), O = Math.max(O, g.bottom);
1767
1706
  }
1768
- return new DOMRect(C, S, T - C, O - S);
1769
- }, x = (m) => {
1770
- const E = o.get(m);
1771
- return E ? E[0].annotation.rects : [];
1707
+ return new DOMRect(E, b, T - E, O - b);
1708
+ }, A = (y) => {
1709
+ const C = o.get(y);
1710
+ return C ? C[0].annotation.rects : [];
1772
1711
  };
1773
1712
  return {
1774
1713
  all: a,
1775
1714
  clear: s,
1776
- getAt: u,
1777
- getAnnotationBounds: h,
1778
- getAnnotationRects: x,
1779
- getIntersecting: (m, E, C, S) => {
1780
- const T = n.search({ minX: m, minY: E, maxX: C, maxY: S }), O = new Set(T.map((R) => R.annotation.id));
1715
+ getAt: p,
1716
+ getAnnotationBounds: d,
1717
+ getAnnotationRects: A,
1718
+ getIntersecting: (y, C, E, b) => {
1719
+ const T = n.search({ minX: y, minY: C, maxX: E, maxY: b }), O = new Set(T.map((R) => R.annotation.id));
1781
1720
  return Array.from(O).map((R) => ({
1782
1721
  annotation: t.getAnnotation(R),
1783
- rects: x(R)
1722
+ rects: A(R)
1784
1723
  })).filter((R) => !!R.annotation);
1785
1724
  },
1786
1725
  insert: l,
1787
1726
  recalculate: () => {
1788
- c(t.all().map((m) => m.target), !0), i.emit("recalculate");
1727
+ c(t.all().map((y) => y.target), !0), i.emit("recalculate");
1789
1728
  },
1790
- remove: f,
1729
+ remove: u,
1791
1730
  set: c,
1792
1731
  size: () => n.all().length,
1793
- update: p,
1794
- on: (m, E) => i.on(m, E)
1732
+ update: h,
1733
+ on: (y, C) => i.on(y, C)
1795
1734
  };
1796
- }, so = (t, e) => {
1797
- const n = fn(), o = ro(n, t), i = Ze(n);
1735
+ }, io = (t, e) => {
1736
+ const n = Tn(), o = oo(n, t), i = mn(n);
1798
1737
  i.setUserSelectAction(e);
1799
- const r = Qe(n), a = mn(), s = (b, g = N.LOCAL) => {
1800
- const d = Lt(b, t), m = W(d.target.selector);
1801
- return m && n.addAnnotation(d, g), m;
1802
- }, l = (b, g = !0, d = N.LOCAL) => {
1803
- const m = b.map((C) => Lt(C, t)), E = m.filter((C) => !W(C.target.selector));
1804
- return E.length > 0 ? (console.warn("Could not revive all targets for these annotations:", E), n.bulkAddAnnotation(m, g, d), E) : (n.bulkAddAnnotation(m, g, d), []);
1805
- }, f = (b, g = N.LOCAL) => {
1806
- const d = b.map((E) => Lt(E, t)), m = d.filter((E) => !W(E.target.selector));
1807
- return m.length > 0 && console.warn("Could not revive all targets for these annotations:", m), d.forEach((E) => {
1808
- n.getAnnotation(E.id) ? n.updateAnnotation(E, g) : n.addAnnotation(E, g);
1809
- }), m;
1810
- }, p = (b, g = N.LOCAL) => {
1811
- const d = bt(b, t);
1812
- n.updateTarget(d, g);
1813
- }, c = (b, g = N.LOCAL) => {
1814
- const d = b.map((m) => bt(m, t));
1815
- n.bulkUpdateTargets(d, g);
1816
- }, u = (b, g, d) => {
1817
- const m = o.getAt(b, g, !!d).map((C) => n.getAnnotation(C)), E = d ? m.filter(d) : m;
1818
- return E.length > 0 ? E[0] : void 0;
1819
- }, h = (b, g, d, m = 5) => {
1820
- const E = o.getAnnotationRects(b);
1821
- if (E.length !== 0) {
1822
- if (g && d) {
1823
- const C = E.find(({ top: S, right: T, bottom: O, left: R }) => g >= R - m && g <= T + m && d >= S - m && d <= O + m);
1824
- if (C) return C;
1738
+ const r = pn(n), a = kn(), s = (f, y = k.LOCAL) => {
1739
+ const C = wt(f, t), E = W(C.target.selector);
1740
+ return E && n.addAnnotation(C, y), E;
1741
+ }, l = (f, y = !0, C = k.LOCAL) => {
1742
+ const E = f.map((T) => wt(T, t)), b = E.filter((T) => !W(T.target.selector));
1743
+ return b.length > 0 ? (console.warn("Could not revive all targets for these annotations:", b), n.bulkAddAnnotation(E, y, C), b) : (n.bulkAddAnnotation(E, y, C), []);
1744
+ }, u = (f, y = k.LOCAL) => {
1745
+ const C = f.map((b) => wt(b, t)), E = C.filter((b) => !W(b.target.selector));
1746
+ return E.length > 0 && console.warn("Could not revive all targets for these annotations:", E), C.forEach((b) => {
1747
+ n.getAnnotation(b.id) ? n.updateAnnotation(b, y) : n.addAnnotation(b, y);
1748
+ }), E;
1749
+ }, h = (f, y = k.LOCAL) => {
1750
+ const C = bt(f, t);
1751
+ n.updateTarget(C, y);
1752
+ }, c = (f, y = k.LOCAL) => {
1753
+ const C = f.map((E) => bt(E, t));
1754
+ n.bulkUpdateTargets(C, y);
1755
+ }, p = (f, y, C) => {
1756
+ const E = o.getAt(f, y, !!C).map((T) => n.getAnnotation(T)), b = C ? E.filter(C) : E;
1757
+ return b.length > 0 ? b[0] : void 0;
1758
+ }, d = (f, y, C, E = 5) => {
1759
+ const b = o.getAnnotationRects(f);
1760
+ if (b.length !== 0) {
1761
+ if (y && C) {
1762
+ const T = b.find(({ top: O, right: R, bottom: g, left: w }) => y >= w - E && y <= R + E && C >= O - E && C <= g + E);
1763
+ if (T) return T;
1825
1764
  }
1826
- return o.getAnnotationBounds(b);
1765
+ return o.getAnnotationBounds(f);
1827
1766
  }
1828
- }, x = () => o.recalculate(), A = (b) => o.on("recalculate", b);
1829
- return n.observe(({ changes: b }) => {
1830
- const g = (b.deleted || []).filter((E) => W(E.target.selector)), d = (b.created || []).filter((E) => W(E.target.selector)), m = (b.updated || []).filter((E) => W(E.newValue.target.selector));
1831
- (g == null ? void 0 : g.length) > 0 && g.forEach((E) => o.remove(E.target)), d.length > 0 && o.set(d.map((E) => E.target), !1), (m == null ? void 0 : m.length) > 0 && m.forEach(({ newValue: E }) => o.update(E.target));
1767
+ }, A = (f, y, C, E) => o.getIntersecting(f, y, C, E), v = (f) => o.getAnnotationRects(f), S = () => o.recalculate(), m = (f) => o.on("recalculate", f);
1768
+ return n.observe(({ changes: f }) => {
1769
+ const y = (f.deleted || []).filter((b) => W(b.target.selector)), C = (f.created || []).filter((b) => W(b.target.selector)), E = (f.updated || []).filter((b) => W(b.newValue.target.selector));
1770
+ (y == null ? void 0 : y.length) > 0 && y.forEach((b) => o.remove(b.target)), C.length > 0 && o.set(C.map((b) => b.target), !1), (E == null ? void 0 : E.length) > 0 && E.forEach(({ newValue: b }) => o.update(b.target));
1832
1771
  }), {
1833
1772
  store: {
1834
1773
  ...n,
1835
1774
  addAnnotation: s,
1836
1775
  bulkAddAnnotation: l,
1837
1776
  bulkUpdateTargets: c,
1838
- bulkUpsertAnnotations: f,
1839
- getAnnotationBounds: h,
1840
- getAt: u,
1841
- getIntersecting: o.getIntersecting.bind(o),
1842
- getAnnotationRects: o.getAnnotationRects.bind(o),
1843
- recalculatePositions: x,
1844
- onRecalculatePositions: A,
1845
- updateTarget: p
1777
+ bulkUpsertAnnotations: u,
1778
+ getAnnotationBounds: d,
1779
+ getAnnotationRects: v,
1780
+ getIntersecting: A,
1781
+ getAt: p,
1782
+ recalculatePositions: S,
1783
+ onRecalculatePositions: m,
1784
+ updateTarget: h
1846
1785
  },
1847
1786
  selection: i,
1848
1787
  hover: r,
1849
1788
  viewport: a
1850
1789
  };
1851
- }, ao = () => {
1852
- const t = document.createElement("canvas");
1853
- t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
1854
- const e = t.getContext("2d");
1855
- return e.scale(2, 2), e.translate(0.5, 0.5), t;
1856
- }, co = (t, e, n = {}) => {
1857
- const o = ao(), i = o.getContext("2d");
1858
- document.body.appendChild(o);
1859
- const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([u, h]) => h.presenceKey === c.presenceKey).map(([u, h]) => u);
1860
- return e.on("selectionChange", (c, u) => {
1861
- a(c).forEach((x) => r.delete(x)), u && u.forEach((x) => r.set(x, c));
1862
- }), {
1863
- clear: () => {
1864
- const { width: c, height: u } = o;
1865
- i.clearRect(-0.5, -0.5, c + 1, u + 1);
1866
- },
1867
- destroy: () => {
1868
- o.remove();
1869
- },
1870
- paint: (c, u, h) => {
1871
- n.font && (i.font = n.font);
1872
- const x = r.get(c.annotation.id);
1873
- if (x) {
1874
- const { height: A } = c.rects[0], b = c.rects[0].x + u.left, g = c.rects[0].y + u.top;
1875
- i.fillStyle = x.appearance.color, i.fillRect(b - 2, g - 2.5, 2, A + 5);
1876
- const d = i.measureText(x.appearance.label), m = d.width + 6, E = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, C = d.fontBoundingBoxAscent ? 8 : 6.5;
1877
- return i.fillRect(b - 2, g - 2.5 - E, m, E), i.fillStyle = "#fff", i.fillText(x.appearance.label, b + 1, g - C), {
1878
- fill: x.appearance.color,
1879
- fillOpacity: h ? 0.45 : 0.18
1880
- };
1881
- }
1882
- },
1883
- reset: () => {
1884
- o.width = 2 * window.innerWidth, o.height = 2 * window.innerHeight;
1885
- const c = o.getContext("2d");
1886
- c.scale(2, 2), c.translate(0.5, 0.5);
1887
- }
1888
- };
1889
- }, me = (t) => {
1890
- if (t === null)
1891
- return document.scrollingElement;
1892
- const { overflowY: e } = window.getComputedStyle(t);
1893
- return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : me(t.parentElement);
1894
- }, lo = (t, e) => (n) => {
1895
- const o = typeof n == "string" ? n : n.id, i = (a) => {
1896
- const s = r.getBoundingClientRect(), l = r.clientHeight, f = r.clientWidth, p = a.selector[0].range.getBoundingClientRect(), { width: c, height: u } = e.getAnnotationBounds(o), h = p.top - s.top, x = p.left - s.left, A = r.parentElement ? r.scrollTop : 0, b = r.parentElement ? r.scrollLeft : 0, g = h + A - (l - u) / 2, d = x + b - (f - c) / 2;
1897
- r.scroll({ top: g, left: d, behavior: "smooth" });
1898
- }, r = me(t);
1899
- if (r) {
1900
- const a = e.getAnnotation(o), { range: s } = a.target.selector[0];
1901
- if (s && !s.collapsed)
1902
- return i(a.target), !0;
1903
- {
1904
- const l = bt(a.target, t), { range: f } = l.selector[0];
1905
- if (f && !f.collapsed)
1906
- return i(l), !0;
1907
- }
1908
- }
1909
- return !1;
1910
- }, uo = (t, e) => ({
1911
- ...t,
1912
- annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
1913
- user: t.user || e.user
1914
- }), Rt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1915
- function Bt(t, e, n, o) {
1790
+ }, Rt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1791
+ function Mt(t, e, n, o) {
1916
1792
  t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
1917
1793
  }
1918
1794
  function et(t, e, n, o) {
1919
1795
  t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
1920
1796
  }
1921
- function ye(t, e) {
1797
+ function ge(t, e) {
1922
1798
  const n = e.slice(0, e.length - 1);
1923
1799
  for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
1924
1800
  return n;
1925
1801
  }
1926
- function be(t) {
1802
+ function me(t) {
1927
1803
  typeof t != "string" && (t = ""), t = t.replace(/\s/g, "");
1928
1804
  const e = t.split(",");
1929
1805
  let n = e.lastIndexOf("");
@@ -1931,7 +1807,7 @@ function be(t) {
1931
1807
  e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
1932
1808
  return e;
1933
1809
  }
1934
- function fo(t, e) {
1810
+ function ro(t, e) {
1935
1811
  const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
1936
1812
  let i = !0;
1937
1813
  for (let r = 0; r < n.length; r++)
@@ -1990,7 +1866,7 @@ const st = {
1990
1866
  "[": 219,
1991
1867
  "]": 221,
1992
1868
  "\\": 220
1993
- }, j = {
1869
+ }, H = {
1994
1870
  // shiftKey
1995
1871
  "⇧": 16,
1996
1872
  shift: 16,
@@ -2006,7 +1882,7 @@ const st = {
2006
1882
  "⌘": 91,
2007
1883
  cmd: 91,
2008
1884
  command: 91
2009
- }, It = {
1885
+ }, Nt = {
2010
1886
  16: "shiftKey",
2011
1887
  18: "altKey",
2012
1888
  17: "ctrlKey",
@@ -2020,27 +1896,27 @@ const st = {
2020
1896
  18: !1,
2021
1897
  17: !1,
2022
1898
  91: !1
2023
- }, I = {};
1899
+ }, N = {};
2024
1900
  for (let t = 1; t < 20; t++)
2025
1901
  st["f".concat(t)] = 111 + t;
2026
- let k = [], rt = null, we = "all";
2027
- const F = /* @__PURE__ */ new Map(), ct = (t) => st[t.toLowerCase()] || j[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), ho = (t) => Object.keys(st).find((e) => st[e] === t), go = (t) => Object.keys(j).find((e) => j[e] === t);
2028
- function ve(t) {
2029
- we = t || "all";
1902
+ let I = [], rt = null, ye = "all";
1903
+ const F = /* @__PURE__ */ new Map(), ct = (t) => st[t.toLowerCase()] || H[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), so = (t) => Object.keys(st).find((e) => st[e] === t), ao = (t) => Object.keys(H).find((e) => H[e] === t);
1904
+ function be(t) {
1905
+ ye = t || "all";
2030
1906
  }
2031
1907
  function at() {
2032
- return we || "all";
1908
+ return ye || "all";
2033
1909
  }
2034
- function po() {
2035
- return k.slice(0);
1910
+ function co() {
1911
+ return I.slice(0);
2036
1912
  }
2037
- function mo() {
2038
- return k.map((t) => ho(t) || go(t) || String.fromCharCode(t));
1913
+ function lo() {
1914
+ return I.map((t) => so(t) || ao(t) || String.fromCharCode(t));
2039
1915
  }
2040
- function yo() {
1916
+ function uo() {
2041
1917
  const t = [];
2042
- return Object.keys(I).forEach((e) => {
2043
- I[e].forEach((n) => {
1918
+ return Object.keys(N).forEach((e) => {
1919
+ N[e].forEach((n) => {
2044
1920
  let {
2045
1921
  key: o,
2046
1922
  scope: i,
@@ -2056,7 +1932,7 @@ function yo() {
2056
1932
  });
2057
1933
  }), t;
2058
1934
  }
2059
- function bo(t) {
1935
+ function fo(t) {
2060
1936
  const e = t.target || t.srcElement, {
2061
1937
  tagName: n
2062
1938
  } = e;
@@ -2064,35 +1940,35 @@ function bo(t) {
2064
1940
  const i = n === "INPUT" && !["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes(e.type);
2065
1941
  return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = !1), o;
2066
1942
  }
2067
- function wo(t) {
2068
- return typeof t == "string" && (t = ct(t)), k.indexOf(t) !== -1;
1943
+ function ho(t) {
1944
+ return typeof t == "string" && (t = ct(t)), I.indexOf(t) !== -1;
2069
1945
  }
2070
- function vo(t, e) {
1946
+ function po(t, e) {
2071
1947
  let n, o;
2072
1948
  t || (t = at());
2073
- for (const i in I)
2074
- if (Object.prototype.hasOwnProperty.call(I, i))
2075
- for (n = I[i], o = 0; o < n.length; )
1949
+ for (const i in N)
1950
+ if (Object.prototype.hasOwnProperty.call(N, i))
1951
+ for (n = N[i], o = 0; o < n.length; )
2076
1952
  n[o].scope === t ? n.splice(o, 1).forEach((a) => {
2077
1953
  let {
2078
1954
  element: s
2079
1955
  } = a;
2080
1956
  return Kt(s);
2081
1957
  }) : o++;
2082
- at() === t && ve(e || "all");
1958
+ at() === t && be(e || "all");
2083
1959
  }
2084
- function xo(t) {
1960
+ function go(t) {
2085
1961
  let e = t.keyCode || t.which || t.charCode;
2086
- const n = k.indexOf(e);
2087
- if (n >= 0 && k.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && k.splice(0, k.length), (e === 93 || e === 224) && (e = 91), e in D) {
1962
+ const n = I.indexOf(e);
1963
+ if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in D) {
2088
1964
  D[e] = !1;
2089
- for (const o in j) j[o] === e && ($[o] = !1);
1965
+ for (const o in H) H[o] === e && ($[o] = !1);
2090
1966
  }
2091
1967
  }
2092
- function xe(t) {
1968
+ function we(t) {
2093
1969
  if (typeof t > "u")
2094
- Object.keys(I).forEach((i) => {
2095
- Array.isArray(I[i]) && I[i].forEach((r) => mt(r)), delete I[i];
1970
+ Object.keys(N).forEach((i) => {
1971
+ Array.isArray(N[i]) && N[i].forEach((r) => mt(r)), delete N[i];
2096
1972
  }), Kt(null);
2097
1973
  else if (Array.isArray(t))
2098
1974
  t.forEach((i) => {
@@ -2119,18 +1995,18 @@ const mt = (t) => {
2119
1995
  method: o,
2120
1996
  splitKey: i = "+"
2121
1997
  } = t;
2122
- be(e).forEach((a) => {
2123
- const s = a.split(i), l = s.length, f = s[l - 1], p = f === "*" ? "*" : ct(f);
2124
- if (!I[p]) return;
1998
+ me(e).forEach((a) => {
1999
+ const s = a.split(i), l = s.length, u = s[l - 1], h = u === "*" ? "*" : ct(u);
2000
+ if (!N[h]) return;
2125
2001
  n || (n = at());
2126
- const c = l > 1 ? ye(j, s) : [], u = [];
2127
- I[p] = I[p].filter((h) => {
2128
- const A = (o ? h.method === o : !0) && h.scope === n && fo(h.mods, c);
2129
- return A && u.push(h.element), !A;
2130
- }), u.forEach((h) => Kt(h));
2002
+ const c = l > 1 ? ge(H, s) : [], p = [];
2003
+ N[h] = N[h].filter((d) => {
2004
+ const v = (o ? d.method === o : !0) && d.scope === n && ro(d.mods, c);
2005
+ return v && p.push(d.element), !v;
2006
+ }), p.forEach((d) => Kt(d));
2131
2007
  });
2132
2008
  };
2133
- function ne(t, e, n, o) {
2009
+ function te(t, e, n, o) {
2134
2010
  if (e.element !== o)
2135
2011
  return;
2136
2012
  let i;
@@ -2138,93 +2014,93 @@ function ne(t, e, n, o) {
2138
2014
  i = e.mods.length > 0;
2139
2015
  for (const r in D)
2140
2016
  Object.prototype.hasOwnProperty.call(D, r) && (!D[r] && e.mods.indexOf(+r) > -1 || D[r] && e.mods.indexOf(+r) === -1) && (i = !1);
2141
- (e.mods.length === 0 && !D[16] && !D[18] && !D[17] && !D[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(k), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2017
+ (e.mods.length === 0 && !D[16] && !D[18] && !D[17] && !D[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(I), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2142
2018
  }
2143
2019
  }
2144
- function oe(t, e) {
2145
- const n = I["*"];
2020
+ function ee(t, e) {
2021
+ const n = N["*"];
2146
2022
  let o = t.keyCode || t.which || t.charCode;
2147
2023
  if (!$.filter.call(this, t)) return;
2148
- if ((o === 93 || o === 224) && (o = 91), k.indexOf(o) === -1 && o !== 229 && k.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((s) => {
2149
- const l = It[s];
2150
- t[s] && k.indexOf(l) === -1 ? k.push(l) : !t[s] && k.indexOf(l) > -1 ? k.splice(k.indexOf(l), 1) : s === "metaKey" && t[s] && k.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (k = k.slice(k.indexOf(l))));
2024
+ if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((s) => {
2025
+ const l = Nt[s];
2026
+ t[s] && I.indexOf(l) === -1 ? I.push(l) : !t[s] && I.indexOf(l) > -1 ? I.splice(I.indexOf(l), 1) : s === "metaKey" && t[s] && I.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (I = I.slice(I.indexOf(l))));
2151
2027
  }), o in D) {
2152
2028
  D[o] = !0;
2153
- for (const s in j)
2154
- j[s] === o && ($[s] = !0);
2029
+ for (const s in H)
2030
+ H[s] === o && ($[s] = !0);
2155
2031
  if (!n) return;
2156
2032
  }
2157
2033
  for (const s in D)
2158
- Object.prototype.hasOwnProperty.call(D, s) && (D[s] = t[It[s]]);
2159
- t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (k.indexOf(17) === -1 && k.push(17), k.indexOf(18) === -1 && k.push(18), D[17] = !0, D[18] = !0);
2034
+ Object.prototype.hasOwnProperty.call(D, s) && (D[s] = t[Nt[s]]);
2035
+ t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), D[17] = !0, D[18] = !0);
2160
2036
  const i = at();
2161
2037
  if (n)
2162
2038
  for (let s = 0; s < n.length; s++)
2163
- n[s].scope === i && (t.type === "keydown" && n[s].keydown || t.type === "keyup" && n[s].keyup) && ne(t, n[s], i, e);
2164
- if (!(o in I)) return;
2165
- const r = I[o], a = r.length;
2039
+ n[s].scope === i && (t.type === "keydown" && n[s].keydown || t.type === "keyup" && n[s].keyup) && te(t, n[s], i, e);
2040
+ if (!(o in N)) return;
2041
+ const r = N[o], a = r.length;
2166
2042
  for (let s = 0; s < a; s++)
2167
2043
  if ((t.type === "keydown" && r[s].keydown || t.type === "keyup" && r[s].keyup) && r[s].key) {
2168
2044
  const l = r[s], {
2169
- splitKey: f
2170
- } = l, p = l.key.split(f), c = [];
2171
- for (let u = 0; u < p.length; u++)
2172
- c.push(ct(p[u]));
2173
- c.sort().join("") === k.sort().join("") && ne(t, l, i, e);
2045
+ splitKey: u
2046
+ } = l, h = l.key.split(u), c = [];
2047
+ for (let p = 0; p < h.length; p++)
2048
+ c.push(ct(h[p]));
2049
+ c.sort().join("") === I.sort().join("") && te(t, l, i, e);
2174
2050
  }
2175
2051
  }
2176
2052
  function $(t, e, n) {
2177
- k = [];
2178
- const o = be(t);
2179
- let i = [], r = "all", a = document, s = 0, l = !1, f = !0, p = "+", c = !1, u = !1;
2180
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (c = e.capture), typeof e.splitKey == "string" && (p = e.splitKey), e.single === !0 && (u = !0)), typeof e == "string" && (r = e), u && xe(t, r); s < o.length; s++)
2181
- t = o[s].split(p), i = [], t.length > 1 && (i = ye(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : ct(t), t in I || (I[t] = []), I[t].push({
2053
+ I = [];
2054
+ const o = me(t);
2055
+ let i = [], r = "all", a = document, s = 0, l = !1, u = !0, h = "+", c = !1, p = !1;
2056
+ for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (u = e.keydown), e.capture !== void 0 && (c = e.capture), typeof e.splitKey == "string" && (h = e.splitKey), e.single === !0 && (p = !0)), typeof e == "string" && (r = e), p && we(t, r); s < o.length; s++)
2057
+ t = o[s].split(h), i = [], t.length > 1 && (i = ge(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : ct(t), t in N || (N[t] = []), N[t].push({
2182
2058
  keyup: l,
2183
- keydown: f,
2059
+ keydown: u,
2184
2060
  scope: r,
2185
2061
  mods: i,
2186
2062
  shortcut: o[s],
2187
2063
  method: n,
2188
2064
  key: o[s],
2189
- splitKey: p,
2065
+ splitKey: h,
2190
2066
  element: a
2191
2067
  });
2192
2068
  if (typeof a < "u" && window) {
2193
2069
  if (!F.has(a)) {
2194
- const h = function() {
2195
- let A = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2196
- return oe(A, a);
2197
- }, x = function() {
2198
- let A = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2199
- oe(A, a), xo(A);
2070
+ const d = function() {
2071
+ let v = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2072
+ return ee(v, a);
2073
+ }, A = function() {
2074
+ let v = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2075
+ ee(v, a), go(v);
2200
2076
  };
2201
2077
  F.set(a, {
2202
- keydownListener: h,
2203
- keyupListenr: x,
2078
+ keydownListener: d,
2079
+ keyupListenr: A,
2204
2080
  capture: c
2205
- }), Bt(a, "keydown", h, c), Bt(a, "keyup", x, c);
2081
+ }), Mt(a, "keydown", d, c), Mt(a, "keyup", A, c);
2206
2082
  }
2207
2083
  if (!rt) {
2208
- const h = () => {
2209
- k = [];
2084
+ const d = () => {
2085
+ I = [];
2210
2086
  };
2211
2087
  rt = {
2212
- listener: h,
2088
+ listener: d,
2213
2089
  capture: c
2214
- }, Bt(window, "focus", h, c);
2090
+ }, Mt(window, "focus", d, c);
2215
2091
  }
2216
2092
  }
2217
2093
  }
2218
- function Ao(t) {
2094
+ function mo(t) {
2219
2095
  let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
2220
- Object.keys(I).forEach((n) => {
2221
- I[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
2096
+ Object.keys(N).forEach((n) => {
2097
+ N[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
2222
2098
  i && i.method && i.method();
2223
2099
  });
2224
2100
  });
2225
2101
  }
2226
2102
  function Kt(t) {
2227
- const e = Object.values(I).flat();
2103
+ const e = Object.values(N).flat();
2228
2104
  if (e.findIndex((o) => {
2229
2105
  let {
2230
2106
  element: i
@@ -2245,7 +2121,7 @@ function Kt(t) {
2245
2121
  capture: s
2246
2122
  } = F.get(i) || {};
2247
2123
  r && a && (et(i, "keyup", a, s), et(i, "keydown", r, s), F.delete(i));
2248
- }), F.clear(), Object.keys(I).forEach((i) => delete I[i]), rt)) {
2124
+ }), F.clear(), Object.keys(N).forEach((i) => delete N[i]), rt)) {
2249
2125
  const {
2250
2126
  listener: i,
2251
2127
  capture: r
@@ -2253,205 +2129,265 @@ function Kt(t) {
2253
2129
  et(window, "focus", i, r), rt = null;
2254
2130
  }
2255
2131
  }
2256
- const Mt = {
2257
- getPressedKeyString: mo,
2258
- setScope: ve,
2132
+ const Bt = {
2133
+ getPressedKeyString: lo,
2134
+ setScope: be,
2259
2135
  getScope: at,
2260
- deleteScope: vo,
2261
- getPressedKeyCodes: po,
2262
- getAllKeyCodes: yo,
2263
- isPressed: wo,
2264
- filter: bo,
2265
- trigger: Ao,
2266
- unbind: xe,
2136
+ deleteScope: po,
2137
+ getPressedKeyCodes: co,
2138
+ getAllKeyCodes: uo,
2139
+ isPressed: ho,
2140
+ filter: fo,
2141
+ trigger: mo,
2142
+ unbind: we,
2267
2143
  keyMap: st,
2268
- modifier: j,
2269
- modifierMap: It
2144
+ modifier: H,
2145
+ modifierMap: Nt
2270
2146
  };
2271
- for (const t in Mt)
2272
- Object.prototype.hasOwnProperty.call(Mt, t) && ($[t] = Mt[t]);
2147
+ for (const t in Bt)
2148
+ Object.prototype.hasOwnProperty.call(Bt, t) && ($[t] = Bt[t]);
2273
2149
  if (typeof window < "u") {
2274
2150
  const t = window.hotkeys;
2275
2151
  $.noConflict = (e) => (e && window.hotkeys === $ && (window.hotkeys = t), $), window.hotkeys = $;
2276
2152
  }
2277
- const Eo = (t, e, n) => {
2153
+ const ne = 300, yo = (t, e, n) => {
2278
2154
  let o;
2279
- const i = (S) => o = S;
2155
+ const i = (b) => o = b;
2280
2156
  let r;
2281
- const a = (S) => r = S;
2157
+ const a = (b) => r = b;
2282
2158
  let s = !0;
2283
- const l = (S) => {
2284
- s = S, A.clear(), S || (c = void 0, u = void 0, h = void 0);
2285
- }, { store: f, selection: p } = e;
2286
- let c, u, h;
2287
- const x = (S) => {
2159
+ const l = (b) => {
2160
+ s = b, v.clear(), b || (c = void 0, p = void 0, d = void 0);
2161
+ }, { store: u, selection: h } = e;
2162
+ let c, p, d;
2163
+ const A = (b) => {
2288
2164
  var O;
2289
- if (!s || u === !1)
2290
- return;
2291
- c = !((O = S.target.parentElement) != null && O.closest(H)) ? {
2292
- annotation: le(),
2165
+ if (!s || p === !1) return;
2166
+ c = !((O = b.target.parentElement) != null && O.closest(j)) ? {
2167
+ annotation: de(),
2293
2168
  selector: [],
2294
2169
  creator: o,
2295
2170
  created: /* @__PURE__ */ new Date()
2296
2171
  } : void 0;
2297
- };
2298
- t.addEventListener("selectstart", x);
2299
- const A = Ut((S) => {
2300
- var M, B;
2172
+ }, v = Ut((b) => {
2173
+ var B, M;
2301
2174
  if (!s) return;
2302
2175
  const T = document.getSelection();
2303
- if (!!((B = (M = T.anchorNode) == null ? void 0 : M.parentElement) != null && B.closest(H))) {
2176
+ if (!!((M = (B = T.anchorNode) == null ? void 0 : B.parentElement) != null && M.closest(j))) {
2304
2177
  c = void 0;
2305
2178
  return;
2306
2179
  }
2307
- if (S.timeStamp - ((h == null ? void 0 : h.timeStamp) || S.timeStamp) < 1e3 && !c && x(h || S), !c) return;
2180
+ const R = b.timeStamp - ((d == null ? void 0 : d.timeStamp) || b.timeStamp);
2181
+ if ((d == null ? void 0 : d.type) === "pointerdown" && (R < 1e3 && !c || T.isCollapsed && R < ne) && A(d), !c) return;
2308
2182
  if (T.isCollapsed) {
2309
- f.getAnnotation(c.annotation) && (p.clear(), f.deleteAnnotation(c.annotation));
2183
+ u.getAnnotation(c.annotation) && (h.clear(), u.deleteAnnotation(c.annotation));
2310
2184
  return;
2311
2185
  }
2312
- const y = T.getRangeAt(0), w = $n(y, t);
2313
- if (Dn(w)) return;
2314
- const v = Mn(w.cloneRange());
2315
- (v.length !== c.selector.length || v.some((K, X) => {
2186
+ const g = T.getRangeAt(0), w = Xe(g, t);
2187
+ if (Ue(w)) return;
2188
+ const x = Te(w.cloneRange());
2189
+ (x.length !== c.selector.length || x.some((K, Y) => {
2316
2190
  var lt;
2317
- return K.toString() !== ((lt = c.selector[X]) == null ? void 0 : lt.quote);
2191
+ return K.toString() !== ((lt = c.selector[Y]) == null ? void 0 : lt.quote);
2318
2192
  })) && (c = {
2319
2193
  ...c,
2320
- selector: v.map((K) => Pn(K, t, n)),
2194
+ selector: x.map((K) => Ye(K, t, n)),
2321
2195
  updated: /* @__PURE__ */ new Date()
2322
- }, f.getAnnotation(c.annotation) ? f.updateTarget(c, N.LOCAL) : (p.clear(), f.addAnnotation({
2196
+ }, u.getAnnotation(c.annotation) ? u.updateTarget(c, k.LOCAL) : (h.clear(), u.addAnnotation({
2323
2197
  id: c.annotation,
2324
2198
  bodies: [],
2325
2199
  target: c
2326
- }, N.LOCAL), p.userSelect(c.annotation, h)));
2327
- }, 10).bind(void 0);
2328
- document.addEventListener("selectionchange", A);
2329
- const b = (S) => {
2330
- h = jn(S), u = h.button === 0, c = void 0;
2331
- };
2332
- document.addEventListener("pointerdown", b);
2333
- const g = (S) => {
2334
- var y;
2335
- if (!!((y = S.target.parentElement) != null && y.closest(H)) || !u)
2200
+ }, k.LOCAL), h.userSelect(c.annotation, d)));
2201
+ }), S = (b) => {
2202
+ d = $e(b), p = d.button === 0;
2203
+ }, m = (b) => {
2204
+ var g;
2205
+ if (!!((g = b.target.parentElement) != null && g.closest(j)) || !p)
2336
2206
  return;
2337
2207
  const O = () => {
2338
- const { x: w, y: v } = t.getBoundingClientRect(), L = S.target instanceof Node && t.contains(S.target) && f.getAt(S.clientX - w, S.clientY - v, r);
2208
+ const { x: w, y: x } = t.getBoundingClientRect(), L = b.target instanceof Node && t.contains(b.target) && u.getAt(b.clientX - w, b.clientY - x, r);
2339
2209
  if (L) {
2340
- const { selected: M } = p;
2341
- (M.length !== 1 || M[0].id !== L.id) && p.userSelect(L.id, S);
2342
- } else p.isEmpty() || p.clear();
2343
- }, R = S.timeStamp - h.timeStamp;
2210
+ const { selected: B } = h;
2211
+ (B.length !== 1 || B[0].id !== L.id) && h.userSelect(L.id, b);
2212
+ } else h.isEmpty() || h.clear();
2213
+ };
2214
+ document.getSelection();
2215
+ const R = b.timeStamp - d.timeStamp;
2344
2216
  setTimeout(() => {
2345
2217
  const w = document.getSelection();
2346
- w != null && w.isCollapsed && R < 300 ? O() : c && p.userSelect(c.annotation, S);
2218
+ w != null && w.isCollapsed && R < ne ? (c = void 0, O()) : c && u.getAnnotation(c.annotation) && h.userSelect(c.annotation, b);
2347
2219
  });
2348
2220
  };
2349
- document.addEventListener("pointerup", g);
2350
- const d = ["up", "down", "left", "right"], m = [
2351
- ...d.map((S) => `shift+${S}`),
2221
+ document.addEventListener("pointerdown", S), document.addEventListener("pointerup", m), t.addEventListener("selectstart", A), document.addEventListener("selectionchange", v);
2222
+ const f = ["up", "down", "left", "right"], y = [
2223
+ ...f.map((b) => `shift+${b}`),
2352
2224
  "ctrl+a",
2353
2225
  "⌘+a"
2354
2226
  ];
2355
- $(m.join(","), { element: t, keydown: !0, keyup: !1 }, (S) => {
2356
- S.repeat || (h = zn(S));
2227
+ $(y.join(","), { element: t, keydown: !0, keyup: !1 }, (b) => {
2228
+ b.repeat || (d = je(b));
2357
2229
  });
2358
- const E = (S) => {
2359
- S.repeat || S.target !== t && S.target !== document.body || (c = void 0, p.clear());
2230
+ const C = (b) => {
2231
+ b.repeat || b.target !== t && b.target !== document.body || (c = void 0, h.clear());
2360
2232
  };
2361
- return $(d.join(","), { keydown: !0, keyup: !1 }, E), {
2233
+ return $(f.join(","), { keydown: !0, keyup: !1 }, C), {
2362
2234
  destroy: () => {
2363
- c = void 0, u = void 0, h = void 0, A.clear(), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", A), document.removeEventListener("pointerdown", b), document.removeEventListener("pointerup", g), $.unbind();
2235
+ c = void 0, p = void 0, d = void 0, v.clear(), document.removeEventListener("pointerdown", S), document.removeEventListener("pointerup", m), t.removeEventListener("selectstart", A), document.removeEventListener("selectionchange", v), $.unbind();
2364
2236
  },
2365
2237
  setFilter: a,
2366
2238
  setUser: i,
2367
2239
  setAnnotatingEnabled: l
2368
2240
  };
2369
- }, ie = "SPANS", Bo = (t, e = {}) => {
2370
- Nn(t), kn(t);
2371
- const n = uo(e, {
2241
+ }, bo = () => {
2242
+ const t = document.createElement("canvas");
2243
+ t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
2244
+ const e = t.getContext("2d");
2245
+ return e.scale(2, 2), e.translate(0.5, 0.5), t;
2246
+ }, wo = (t, e, n = {}) => {
2247
+ const o = bo(), i = o.getContext("2d");
2248
+ document.body.appendChild(o);
2249
+ const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([p, d]) => d.presenceKey === c.presenceKey).map(([p, d]) => p);
2250
+ return e.on("selectionChange", (c, p) => {
2251
+ a(c).forEach((A) => r.delete(A)), p && p.forEach((A) => r.set(A, c));
2252
+ }), {
2253
+ clear: () => {
2254
+ const { width: c, height: p } = o;
2255
+ i.clearRect(-0.5, -0.5, c + 1, p + 1);
2256
+ },
2257
+ destroy: () => {
2258
+ o.remove();
2259
+ },
2260
+ paint: (c, p, d) => {
2261
+ n.font && (i.font = n.font);
2262
+ const A = r.get(c.annotation.id);
2263
+ if (A) {
2264
+ const { height: v } = c.rects[0], S = c.rects[0].x + p.left, m = c.rects[0].y + p.top;
2265
+ i.fillStyle = A.appearance.color, i.fillRect(S - 2, m - 2.5, 2, v + 5);
2266
+ const f = i.measureText(A.appearance.label), y = f.width + 6, C = f.actualBoundingBoxAscent + f.actualBoundingBoxDescent + 8, E = f.fontBoundingBoxAscent ? 8 : 6.5;
2267
+ return i.fillRect(S - 2, m - 2.5 - C, y, C), i.fillStyle = "#fff", i.fillText(A.appearance.label, S + 1, m - E), {
2268
+ fill: A.appearance.color,
2269
+ fillOpacity: d ? 0.45 : 0.18
2270
+ };
2271
+ }
2272
+ },
2273
+ reset: () => {
2274
+ o.width = 2 * window.innerWidth, o.height = 2 * window.innerHeight;
2275
+ const c = o.getContext("2d");
2276
+ c.scale(2, 2), c.translate(0.5, 0.5);
2277
+ }
2278
+ };
2279
+ }, ve = (t) => {
2280
+ if (t === null)
2281
+ return document.scrollingElement;
2282
+ const { overflowY: e } = window.getComputedStyle(t);
2283
+ return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ve(t.parentElement);
2284
+ }, vo = (t, e) => (n) => {
2285
+ const o = typeof n == "string" ? n : n.id, i = (a) => {
2286
+ const s = r.getBoundingClientRect(), l = r.clientHeight, u = r.clientWidth, h = a.selector[0].range.getBoundingClientRect(), { width: c, height: p } = e.getAnnotationBounds(o), d = h.top - s.top, A = h.left - s.left, v = r.parentElement ? r.scrollTop : 0, S = r.parentElement ? r.scrollLeft : 0, m = d + v - (l - p) / 2, f = A + S - (u - c) / 2;
2287
+ r.scroll({ top: m, left: f, behavior: "smooth" });
2288
+ }, r = ve(t);
2289
+ if (r) {
2290
+ const a = e.getAnnotation(o), { range: s } = a.target.selector[0];
2291
+ if (s && !s.collapsed)
2292
+ return i(a.target), !0;
2293
+ {
2294
+ const l = bt(a.target, t), { range: u } = l.selector[0];
2295
+ if (u && !u.collapsed)
2296
+ return i(l), !0;
2297
+ }
2298
+ }
2299
+ return !1;
2300
+ }, Ao = (t, e) => ({
2301
+ ...t,
2302
+ annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
2303
+ user: t.user || e.user
2304
+ }), oe = "SPANS", Oo = (t, e = {}) => {
2305
+ Re(t), Me(t);
2306
+ const n = Ao(e, {
2372
2307
  annotatingEnabled: !0,
2373
- user: Cn()
2374
- }), o = so(t, n.userSelectAction), { selection: i, viewport: r } = o, a = o.store, s = pn(a), l = yn(o, s, n.adapter);
2375
- let f = n.user;
2376
- const p = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ie : n.renderer || ie, c = p === "SPANS" ? je(t, o, r) : p === "CSS_HIGHLIGHTS" ? Pe(t, o, r) : p === "CANVAS" ? Ne(t, o, r) : void 0;
2308
+ user: Xn()
2309
+ }), o = io(t, n.userSelectAction), { selection: i, viewport: r } = o, a = o.store, s = Bn(a), l = In(o, s, n.adapter);
2310
+ let u = n.user;
2311
+ const h = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : oe : n.renderer || oe, c = h === "SPANS" ? cn(t, o, r) : h === "CSS_HIGHLIGHTS" ? rn(t, o, r) : h === "CANVAS" ? We(t, o, r) : void 0;
2377
2312
  if (!c)
2378
- throw `Unknown renderer implementation: ${p}`;
2379
- console.debug(`Using ${p} renderer`), n.style && c.setStyle(n.style);
2380
- const u = Eo(t, o, n.offsetReferenceSelector);
2381
- u.setUser(f), u.setAnnotatingEnabled(n.annotatingEnabled);
2382
- const h = wn(o, s, n.adapter), x = () => f, A = (C) => {
2383
- u.setAnnotatingEnabled(
2384
- C === void 0 ? !0 : C
2313
+ throw `Unknown renderer implementation: ${h}`;
2314
+ console.debug(`Using ${h} renderer`), n.style && c.setStyle(n.style);
2315
+ const p = yo(t, o, n.offsetReferenceSelector);
2316
+ p.setUser(u), p.setAnnotatingEnabled(n.annotatingEnabled);
2317
+ const d = _n(o, s, n.adapter), A = () => u, v = (E) => {
2318
+ p.setAnnotatingEnabled(
2319
+ E === void 0 ? !0 : E
2385
2320
  );
2386
- }, b = (C) => {
2387
- c.setFilter(C), u.setFilter(C);
2388
- }, g = (C) => {
2389
- f = C, u.setUser(C);
2390
- }, d = (C) => {
2391
- C && (c.setPainter(co(t, C, n.presence)), C.on("selectionChange", () => c.redraw()));
2392
- }, m = (C) => {
2393
- C ? i.setSelected(C) : i.clear();
2321
+ }, S = (E) => {
2322
+ c.setFilter(E), p.setFilter(E);
2323
+ }, m = (E) => {
2324
+ u = E, p.setUser(E);
2325
+ }, f = (E) => {
2326
+ E && (c.setPainter(wo(t, E, n.presence)), E.on("selectionChange", () => c.redraw()));
2327
+ }, y = (E) => {
2328
+ E ? i.setSelected(E) : i.clear();
2394
2329
  };
2395
2330
  return {
2396
- ...h,
2331
+ ...d,
2397
2332
  destroy: () => {
2398
- c.destroy(), u.destroy(), s.destroy();
2333
+ c.destroy(), p.destroy(), s.destroy();
2399
2334
  },
2400
2335
  element: t,
2401
- getUser: x,
2402
- setAnnotatingEnabled: A,
2403
- setFilter: b,
2336
+ getUser: A,
2337
+ setAnnotatingEnabled: v,
2338
+ setFilter: S,
2404
2339
  setStyle: c.setStyle.bind(c),
2405
2340
  redraw: c.redraw.bind(c),
2406
- setUser: g,
2407
- setSelected: m,
2408
- setPresenceProvider: d,
2341
+ setUser: m,
2342
+ setSelected: y,
2343
+ setPresenceProvider: f,
2409
2344
  setVisible: c.setVisible.bind(c),
2410
2345
  on: l.on,
2411
2346
  off: l.off,
2412
- scrollIntoView: lo(t, a),
2347
+ scrollIntoView: vo(t, a),
2413
2348
  state: o
2414
2349
  };
2415
2350
  };
2416
2351
  export {
2417
2352
  yt as DEFAULT_SELECTED_STYLE,
2418
2353
  q as DEFAULT_STYLE,
2419
- he as NOT_ANNOTATABLE_CLASS,
2420
- H as NOT_ANNOTATABLE_SELECTOR,
2421
- N as Origin,
2422
- Je as UserSelectAction,
2423
- Ro as W3CTextFormat,
2424
- Nn as cancelSingleClickEvents,
2425
- zn as cloneKeyboardEvent,
2426
- jn as clonePointerEvent,
2427
- So as createBody,
2428
- Ne as createCanvasRenderer,
2429
- Pe as createHighlightsRenderer,
2430
- Ye as createRenderer,
2431
- je as createSpansRenderer,
2432
- Bo as createTextAnnotator,
2433
- so as createTextAnnotatorState,
2434
- To as denormalizeRectWithOffset,
2435
- uo as fillDefaults,
2436
- Co as getAnnotatableFragment,
2437
- Lo as getClientRectsPonyfill,
2438
- Un as getQuoteContext,
2354
+ ie as NOT_ANNOTATABLE_CLASS,
2355
+ j as NOT_ANNOTATABLE_SELECTOR,
2356
+ k as Origin,
2357
+ gn as UserSelectAction,
2358
+ Lo as W3CTextFormat,
2359
+ Re as cancelSingleClickEvents,
2360
+ je as cloneKeyboardEvent,
2361
+ $e as clonePointerEvent,
2362
+ Co as createBody,
2363
+ We as createCanvasRenderer,
2364
+ rn as createHighlightsRenderer,
2365
+ on as createRenderer,
2366
+ yo as createSelectionHandler,
2367
+ cn as createSpansRenderer,
2368
+ Oo as createTextAnnotator,
2369
+ io as createTextAnnotatorState,
2370
+ Ut as debounce,
2371
+ So as denormalizeRectWithOffset,
2372
+ Ao as fillDefaults,
2373
+ xo as getAnnotatableFragment,
2374
+ Ne as getQuoteContext,
2439
2375
  kt as getRangeAnnotatableContents,
2440
2376
  W as isRevived,
2441
- Dn as isWhitespaceOrEmpty,
2442
- Yn as mergeClientRects,
2443
- Hn as normalizeRectWithOffset,
2444
- Se as paint,
2445
- qn as parseW3CTextAnnotation,
2446
- kn as programmaticallyFocusable,
2447
- Pn as rangeToSelector,
2448
- Lt as reviveAnnotation,
2449
- ge as reviveSelector,
2377
+ Ue as isWhitespaceOrEmpty,
2378
+ Ke as mergeClientRects,
2379
+ Pe as normalizeRectWithOffset,
2380
+ Ee as paint,
2381
+ Fn as parseW3CTextAnnotation,
2382
+ Me as programmaticallyFocusable,
2383
+ Ye as rangeToSelector,
2384
+ wt as reviveAnnotation,
2385
+ se as reviveSelector,
2450
2386
  bt as reviveTarget,
2451
- Gn as serializeW3CTextAnnotation,
2452
- Mn as splitAnnotatableRanges,
2453
- Oo as toDomRectList,
2454
- $n as trimRangeToContainer,
2455
- Vn as whitespaceOrEmptyRegex
2387
+ Wn as serializeW3CTextAnnotation,
2388
+ Te as splitAnnotatableRanges,
2389
+ Eo as toDomRectList,
2390
+ Xe as trimRangeToContainer,
2391
+ _e as whitespaceOrEmptyRegex
2456
2392
  };
2457
2393
  //# sourceMappingURL=text-annotator.es.js.map