@soomo/text-annotator 3.0.0-staging.31 → 3.0.0-staging.32

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