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