@soomo/text-annotator 3.1.0-staging.9 → 3.2.0-staging.1

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