@soomo/text-annotator 3.0.0-staging.47 → 3.0.0-staging.49

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,52 +1,52 @@
1
1
  const q = {
2
2
  fill: "rgb(0, 128, 255)",
3
3
  fillOpacity: 0.18
4
- }, gt = {
4
+ }, mt = {
5
5
  fill: "rgb(0, 128, 255)",
6
6
  fillOpacity: 0.45
7
7
  }, Ae = (t, e, n, o, i) => {
8
8
  var a, s;
9
- const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? gt : q) : n : (s = t.state) != null && s.selected ? gt : q;
9
+ const r = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? mt : q) : n : (s = t.state) != null && s.selected ? mt : q;
10
10
  return o && o.paint(t, e) || r;
11
11
  };
12
12
  function Ee(t) {
13
13
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
14
14
  }
15
- var Nt = { exports: {} };
16
- function oe(t, e = 100, n = {}) {
15
+ var It = { exports: {} };
16
+ function ie(t, e = 100, n = {}) {
17
17
  if (typeof t != "function")
18
18
  throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);
19
19
  if (e < 0)
20
20
  throw new RangeError("`wait` must not be negative.");
21
21
  const { immediate: o } = typeof n == "boolean" ? { immediate: n } : n;
22
22
  let i, r, a, s, l;
23
- function u() {
24
- const p = i, d = r;
25
- return i = void 0, r = void 0, l = t.apply(p, d), l;
23
+ function f() {
24
+ const p = i, u = r;
25
+ return i = void 0, r = void 0, l = t.apply(p, u), l;
26
26
  }
27
27
  function g() {
28
28
  const p = Date.now() - s;
29
- p < e && p >= 0 ? a = setTimeout(g, e - p) : (a = void 0, o || (l = u()));
29
+ p < e && p >= 0 ? a = setTimeout(g, e - p) : (a = void 0, o || (l = f()));
30
30
  }
31
31
  const c = function(...p) {
32
32
  if (i && this !== i)
33
33
  throw new Error("Debounced method called with different contexts.");
34
34
  i = this, r = p, s = Date.now();
35
- const d = o && !a;
36
- return a || (a = setTimeout(g, e)), d && (l = u()), l;
35
+ const u = o && !a;
36
+ return a || (a = setTimeout(g, e)), u && (l = f()), l;
37
37
  };
38
38
  return c.clear = () => {
39
39
  a && (clearTimeout(a), a = void 0);
40
40
  }, c.flush = () => {
41
41
  a && c.trigger();
42
42
  }, c.trigger = () => {
43
- l = u(), c.clear();
43
+ l = f(), c.clear();
44
44
  }, c;
45
45
  }
46
- Nt.exports.debounce = oe;
47
- Nt.exports = oe;
48
- var Se = Nt.exports;
49
- const It = /* @__PURE__ */ Ee(Se), Ce = (t) => {
46
+ It.exports.debounce = ie;
47
+ It.exports = ie;
48
+ var Se = It.exports;
49
+ const _t = /* @__PURE__ */ Ee(Se), Ce = (t) => {
50
50
  const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, r = -n, a = -e, s = o - n, l = i - e;
51
51
  return { top: e, left: n, minX: r, minY: a, maxX: s, maxY: l };
52
52
  }, Le = (t) => {
@@ -55,48 +55,48 @@ const It = /* @__PURE__ */ Ee(Se), Ce = (t) => {
55
55
  const i = o.map((r) => r.id);
56
56
  (e.size !== i.length || i.some((r) => !e.has(r))) && t.set(i), e = new Set(i);
57
57
  };
58
- }, _t = (t, e, n, o) => {
58
+ }, Ut = (t, e, n, o) => {
59
59
  const { store: i, selection: r, hover: a } = e;
60
- let s, l, u;
61
- const g = Le(n), c = (L) => {
62
- const { x: T, y: m } = t.getBoundingClientRect(), A = i.getAt(L.clientX - T, L.clientY - m, l);
63
- A ? a.current !== A.id && (t.classList.add("hovered"), a.set(A.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
60
+ let s, l, f;
61
+ const g = Le(n), c = (O) => {
62
+ const { x: B, y: m } = t.getBoundingClientRect(), w = i.getAt(O.clientX - B, O.clientY - m, l);
63
+ w ? a.current !== w.id && (t.classList.add("hovered"), a.set(w.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
64
64
  };
65
65
  t.addEventListener("pointermove", c);
66
- const p = (L = !1) => {
67
- u && u.clear();
68
- const T = Ce(t), { minX: m, minY: A, maxX: S, maxY: C } = T, R = l ? i.getIntersecting(m, A, S, C).filter(({ annotation: Y }) => l(Y)) : i.getIntersecting(m, A, S, C), N = r.selected.map(({ id: Y }) => Y), $ = R.map(({ annotation: Y, rects: we }) => {
69
- const ve = N.includes(Y.id), xe = Y.id === a.current;
70
- return { annotation: Y, rects: we, state: { selected: ve, hover: xe } };
66
+ const p = (O = !1) => {
67
+ f && f.clear();
68
+ const B = Ce(t), { minX: m, minY: w, maxX: E, maxY: L } = B, T = l ? i.getIntersecting(m, w, E, L).filter(({ annotation: P }) => l(P)) : i.getIntersecting(m, w, E, L), N = r.selected.map(({ id: P }) => P), K = T.map(({ annotation: P, rects: lt }) => {
69
+ const ve = N.includes(P.id), xe = P.id === a.current;
70
+ return { annotation: P, rects: lt, state: { selected: ve, hover: xe } };
71
71
  });
72
- o.redraw($, T, s, u, L), setTimeout(() => g(R.map(({ annotation: Y }) => Y)), 1);
73
- }, d = (L) => {
74
- u = L, p();
75
- }, x = (L) => {
76
- s = L, p();
77
- }, v = (L) => {
78
- l = L, p(!1);
79
- }, b = () => p();
80
- i.observe(b);
81
- const h = r.subscribe(() => p()), f = () => p(!0);
82
- document.addEventListener("scroll", f, { capture: !0, passive: !0 });
83
- const y = It(() => {
84
- i.recalculatePositions(), u && u.reset(), p();
72
+ o.redraw(K, B, s, f, O), setTimeout(() => g(T.map(({ annotation: P }) => P)), 1);
73
+ }, u = (O) => {
74
+ f = O, p();
75
+ }, x = (O) => {
76
+ s = O, p();
77
+ }, b = (O) => {
78
+ l = O, p(!1);
79
+ }, v = () => p();
80
+ i.observe(v);
81
+ const h = r.subscribe(() => p()), d = () => p(!0);
82
+ document.addEventListener("scroll", d, { capture: !0, passive: !0 });
83
+ const y = _t(() => {
84
+ i.recalculatePositions(), f && f.reset(), p();
85
85
  }, 10);
86
86
  window.addEventListener("resize", y);
87
- const E = new ResizeObserver(y);
88
- E.observe(t);
89
- const w = { attributes: !0, childList: !0, subtree: !0 }, O = new MutationObserver((L) => {
90
- L.every((m) => m.target === t || t.contains(m.target)) || p(!0);
87
+ const A = new ResizeObserver(y);
88
+ A.observe(t);
89
+ const C = { attributes: !0, childList: !0, subtree: !0 }, S = new MutationObserver((O) => {
90
+ O.every((m) => m.target === t || t.contains(m.target)) || p(!0);
91
91
  });
92
- return O.observe(document.body, w), {
92
+ return S.observe(document.body, C), {
93
93
  destroy: () => {
94
- t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(b), h(), document.removeEventListener("scroll", f), y.clear(), window.removeEventListener("resize", y), E.disconnect(), O.disconnect();
94
+ t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(v), h(), document.removeEventListener("scroll", d), y.clear(), window.removeEventListener("resize", y), A.disconnect(), S.disconnect();
95
95
  },
96
96
  redraw: p,
97
97
  setStyle: x,
98
- setFilter: v,
99
- setPainter: d,
98
+ setFilter: b,
99
+ setPainter: u,
100
100
  setVisible: o.setVisible
101
101
  };
102
102
  }, Oe = () => {
@@ -108,32 +108,32 @@ const It = /* @__PURE__ */ Ee(Se), Ce = (t) => {
108
108
  t.classList.add("r6o-annotatable");
109
109
  const e = Oe(), n = e.getContext("2d");
110
110
  document.body.appendChild(e);
111
- const o = (s, l, u, g) => requestAnimationFrame(() => {
111
+ const o = (s, l, f, g) => requestAnimationFrame(() => {
112
112
  const { width: c, height: p } = e;
113
113
  n.clearRect(-0.5, -0.5, c + 1, p + 1), g && g.clear();
114
- const { top: d, left: x } = l;
115
- [...s].sort((b, h) => {
116
- const { annotation: { target: { created: f } } } = b, { annotation: { target: { created: y } } } = h;
117
- return f.getTime() - y.getTime();
118
- }).forEach((b) => {
119
- var E;
120
- const h = u ? typeof u == "function" ? u(b.annotation, b.state) : u : (E = b.state) != null && E.selected ? gt : q, f = g && g.paint(b, l) || h, y = b.rects.map(({ x: w, y: O, width: B, height: L }) => ({
121
- x: w + x,
122
- y: O + d,
123
- width: B,
124
- height: L
114
+ const { top: u, left: x } = l;
115
+ [...s].sort((v, h) => {
116
+ const { annotation: { target: { created: d } } } = v, { annotation: { target: { created: y } } } = h;
117
+ return d.getTime() - y.getTime();
118
+ }).forEach((v) => {
119
+ var A;
120
+ const h = f ? typeof f == "function" ? f(v.annotation, v.state) : f : (A = v.state) != null && A.selected ? mt : q, d = g && g.paint(v, l) || h, y = v.rects.map(({ x: C, y: S, width: R, height: O }) => ({
121
+ x: C + x,
122
+ y: S + u,
123
+ width: R,
124
+ height: O
125
125
  }));
126
- if (n.fillStyle = f.fill, n.globalAlpha = f.fillOpacity || 1, y.forEach(
127
- ({ x: w, y: O, width: B, height: L }) => n.fillRect(w, O, B, L)
128
- ), f.underlineColor) {
129
- n.globalAlpha = 1, n.strokeStyle = f.underlineColor, n.lineWidth = f.underlineThickness ?? 1;
130
- const w = f.underlineOffset ?? 0;
131
- y.forEach(({ x: O, y: B, width: L, height: T }) => {
132
- n.beginPath(), n.moveTo(O, B + T + w), n.lineTo(O + L, B + T + w), n.stroke();
126
+ if (n.fillStyle = d.fill, n.globalAlpha = d.fillOpacity || 1, y.forEach(
127
+ ({ x: C, y: S, width: R, height: O }) => n.fillRect(C, S, R, O)
128
+ ), d.underlineColor) {
129
+ n.globalAlpha = 1, n.strokeStyle = d.underlineColor, n.lineWidth = d.underlineThickness ?? 1;
130
+ const C = d.underlineOffset ?? 0;
131
+ y.forEach(({ x: S, y: R, width: O, height: B }) => {
132
+ n.beginPath(), n.moveTo(S, R + B + C), n.lineTo(S + O, R + B + C), n.stroke();
133
133
  });
134
134
  }
135
135
  });
136
- }), i = It(() => Te(e), 10);
136
+ }), i = _t(() => Te(e), 10);
137
137
  return window.addEventListener("resize", i), {
138
138
  destroy: () => {
139
139
  e.remove(), i.clear(), window.removeEventListener("resize", i);
@@ -143,144 +143,144 @@ const It = /* @__PURE__ */ Ee(Se), Ce = (t) => {
143
143
  },
144
144
  redraw: o
145
145
  };
146
- }, Be = (t, e, n) => _t(t, e, n, Re(t));
146
+ }, Be = (t, e, n) => Ut(t, e, n, Re(t));
147
147
  var Me = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, z = function(t) {
148
148
  return typeof t == "string" ? t.length > 0 : typeof t == "number";
149
149
  }, _ = function(t, e, n) {
150
150
  return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
151
- }, K = function(t, e, n) {
151
+ }, Y = function(t, e, n) {
152
152
  return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
153
- }, ie = function(t) {
153
+ }, re = function(t) {
154
154
  return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
155
- }, Dt = function(t) {
156
- return { r: K(t.r, 0, 255), g: K(t.g, 0, 255), b: K(t.b, 0, 255), a: K(t.a) };
157
- }, yt = function(t) {
155
+ }, Kt = function(t) {
156
+ return { r: Y(t.r, 0, 255), g: Y(t.g, 0, 255), b: Y(t.b, 0, 255), a: Y(t.a) };
157
+ }, bt = function(t) {
158
158
  return { r: _(t.r), g: _(t.g), b: _(t.b), a: _(t.a, 3) };
159
- }, ke = /^#([0-9a-f]{3,8})$/i, lt = function(t) {
159
+ }, ke = /^#([0-9a-f]{3,8})$/i, dt = function(t) {
160
160
  var e = t.toString(16);
161
161
  return e.length < 2 ? "0" + e : e;
162
- }, re = function(t) {
162
+ }, se = function(t) {
163
163
  var e = t.r, n = t.g, o = t.b, i = t.a, r = Math.max(e, n, o), a = r - Math.min(e, n, o), s = a ? r === e ? (n - o) / a : r === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
164
164
  return { h: 60 * (s < 0 ? s + 6 : s), s: r ? a / r * 100 : 0, v: r / 255 * 100, a: i };
165
- }, se = function(t) {
165
+ }, ae = function(t) {
166
166
  var e = t.h, n = t.s, o = t.v, i = t.a;
167
167
  e = e / 360 * 6, n /= 100, o /= 100;
168
- var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), l = o * (1 - (1 - e + r) * n), u = r % 6;
169
- return { r: 255 * [o, s, a, a, l, o][u], g: 255 * [l, o, o, s, a, a][u], b: 255 * [a, a, l, o, o, s][u], a: i };
168
+ var r = Math.floor(e), a = o * (1 - n), s = o * (1 - (e - r) * n), l = o * (1 - (1 - e + r) * n), f = r % 6;
169
+ return { r: 255 * [o, s, a, a, l, o][f], g: 255 * [l, o, o, s, a, a][f], b: 255 * [a, a, l, o, o, s][f], a: i };
170
170
  }, Yt = function(t) {
171
- return { h: ie(t.h), s: K(t.s, 0, 100), l: K(t.l, 0, 100), a: K(t.a) };
172
- }, Kt = function(t) {
173
- return { h: _(t.h), s: _(t.s), l: _(t.l), a: _(t.a, 3) };
171
+ return { h: re(t.h), s: Y(t.s, 0, 100), l: Y(t.l, 0, 100), a: Y(t.a) };
174
172
  }, Xt = function(t) {
175
- return se((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 }));
173
+ return { h: _(t.h), s: _(t.s), l: _(t.l), a: _(t.a, 3) };
174
+ }, Pt = function(t) {
175
+ return ae((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
176
176
  var e, n, o;
177
177
  }, it = function(t) {
178
- return { h: (e = re(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 };
178
+ return { h: (e = se(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
179
179
  var e, n, o, i;
180
- }, Ne = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ie = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, _e = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ue = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Pt = { string: [[function(t) {
180
+ }, Ne = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ie = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, _e = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ue = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, $t = { string: [[function(t) {
181
181
  var e = ke.exec(t);
182
182
  return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? _(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? _(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
183
183
  }, "hex"], [function(t) {
184
184
  var e = _e.exec(t) || Ue.exec(t);
185
- return e ? e[2] !== e[4] || e[4] !== e[6] ? null : Dt({ 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;
185
+ return e ? e[2] !== e[4] || e[4] !== e[6] ? null : Kt({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
186
186
  }, "rgb"], [function(t) {
187
187
  var e = Ne.exec(t) || Ie.exec(t);
188
188
  if (!e) return null;
189
189
  var n, o, i = Yt({ 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) });
190
- return Xt(i);
190
+ return Pt(i);
191
191
  }, "hsl"]], object: [[function(t) {
192
192
  var e = t.r, n = t.g, o = t.b, i = t.a, r = i === void 0 ? 1 : i;
193
- return z(e) && z(n) && z(o) ? Dt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
193
+ return z(e) && z(n) && z(o) ? Kt({ r: Number(e), g: Number(n), b: Number(o), a: Number(r) }) : null;
194
194
  }, "rgb"], [function(t) {
195
195
  var e = t.h, n = t.s, o = t.l, i = t.a, r = i === void 0 ? 1 : i;
196
196
  if (!z(e) || !z(n) || !z(o)) return null;
197
197
  var a = Yt({ h: Number(e), s: Number(n), l: Number(o), a: Number(r) });
198
- return Xt(a);
198
+ return Pt(a);
199
199
  }, "hsl"], [function(t) {
200
200
  var e = t.h, n = t.s, o = t.v, i = t.a, r = i === void 0 ? 1 : i;
201
201
  if (!z(e) || !z(n) || !z(o)) return null;
202
202
  var a = function(s) {
203
- return { h: ie(s.h), s: K(s.s, 0, 100), v: K(s.v, 0, 100), a: K(s.a) };
203
+ return { h: re(s.h), s: Y(s.s, 0, 100), v: Y(s.v, 0, 100), a: Y(s.a) };
204
204
  }({ h: Number(e), s: Number(n), v: Number(o), a: Number(r) });
205
- return se(a);
206
- }, "hsv"]] }, $t = function(t, e) {
205
+ return ae(a);
206
+ }, "hsv"]] }, Ht = function(t, e) {
207
207
  for (var n = 0; n < e.length; n++) {
208
208
  var o = e[n][0](t);
209
209
  if (o) return [o, e[n][1]];
210
210
  }
211
211
  return [null, void 0];
212
212
  }, Ve = function(t) {
213
- return typeof t == "string" ? $t(t.trim(), Pt.string) : typeof t == "object" && t !== null ? $t(t, Pt.object) : [null, void 0];
214
- }, bt = function(t, e) {
213
+ return typeof t == "string" ? Ht(t.trim(), $t.string) : typeof t == "object" && t !== null ? Ht(t, $t.object) : [null, void 0];
214
+ }, wt = function(t, e) {
215
215
  var n = it(t);
216
- return { h: n.h, s: K(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
217
- }, wt = function(t) {
216
+ return { h: n.h, s: Y(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
217
+ }, vt = function(t) {
218
218
  return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
219
- }, Ht = function(t, e) {
219
+ }, jt = function(t, e) {
220
220
  var n = it(t);
221
- return { h: n.h, s: n.s, l: K(n.l + 100 * e, 0, 100), a: n.a };
222
- }, jt = function() {
221
+ return { h: n.h, s: n.s, l: Y(n.l + 100 * e, 0, 100), a: n.a };
222
+ }, zt = function() {
223
223
  function t(e) {
224
224
  this.parsed = Ve(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
225
225
  }
226
226
  return t.prototype.isValid = function() {
227
227
  return this.parsed !== null;
228
228
  }, t.prototype.brightness = function() {
229
- return _(wt(this.rgba), 2);
229
+ return _(vt(this.rgba), 2);
230
230
  }, t.prototype.isDark = function() {
231
- return wt(this.rgba) < 0.5;
231
+ return vt(this.rgba) < 0.5;
232
232
  }, t.prototype.isLight = function() {
233
- return wt(this.rgba) >= 0.5;
233
+ return vt(this.rgba) >= 0.5;
234
234
  }, t.prototype.toHex = function() {
235
- return e = yt(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? lt(_(255 * r)) : "", "#" + lt(n) + lt(o) + lt(i) + a;
235
+ return e = bt(this.rgba), n = e.r, o = e.g, i = e.b, a = (r = e.a) < 1 ? dt(_(255 * r)) : "", "#" + dt(n) + dt(o) + dt(i) + a;
236
236
  var e, n, o, i, r, a;
237
237
  }, t.prototype.toRgb = function() {
238
- return yt(this.rgba);
238
+ return bt(this.rgba);
239
239
  }, t.prototype.toRgbString = function() {
240
- return e = yt(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
240
+ return e = bt(this.rgba), n = e.r, o = e.g, i = e.b, (r = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + r + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
241
241
  var e, n, o, i, r;
242
242
  }, t.prototype.toHsl = function() {
243
- return Kt(it(this.rgba));
243
+ return Xt(it(this.rgba));
244
244
  }, t.prototype.toHslString = function() {
245
- return e = Kt(it(this.rgba)), n = e.h, o = e.s, i = e.l, (r = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + r + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
245
+ return e = Xt(it(this.rgba)), n = e.h, o = e.s, i = e.l, (r = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + r + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
246
246
  var e, n, o, i, r;
247
247
  }, t.prototype.toHsv = function() {
248
- return e = re(this.rgba), { h: _(e.h), s: _(e.s), v: _(e.v), a: _(e.a, 3) };
248
+ return e = se(this.rgba), { h: _(e.h), s: _(e.s), v: _(e.v), a: _(e.a, 3) };
249
249
  var e;
250
250
  }, t.prototype.invert = function() {
251
- return X({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
251
+ return $({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
252
252
  var e;
253
253
  }, t.prototype.saturate = function(e) {
254
- return e === void 0 && (e = 0.1), X(bt(this.rgba, e));
254
+ return e === void 0 && (e = 0.1), $(wt(this.rgba, e));
255
255
  }, t.prototype.desaturate = function(e) {
256
- return e === void 0 && (e = 0.1), X(bt(this.rgba, -e));
256
+ return e === void 0 && (e = 0.1), $(wt(this.rgba, -e));
257
257
  }, t.prototype.grayscale = function() {
258
- return X(bt(this.rgba, -1));
258
+ return $(wt(this.rgba, -1));
259
259
  }, t.prototype.lighten = function(e) {
260
- return e === void 0 && (e = 0.1), X(Ht(this.rgba, e));
260
+ return e === void 0 && (e = 0.1), $(jt(this.rgba, e));
261
261
  }, t.prototype.darken = function(e) {
262
- return e === void 0 && (e = 0.1), X(Ht(this.rgba, -e));
262
+ return e === void 0 && (e = 0.1), $(jt(this.rgba, -e));
263
263
  }, t.prototype.rotate = function(e) {
264
264
  return e === void 0 && (e = 15), this.hue(this.hue() + e);
265
265
  }, t.prototype.alpha = function(e) {
266
- return typeof e == "number" ? X({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : _(this.rgba.a, 3);
266
+ return typeof e == "number" ? $({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : _(this.rgba.a, 3);
267
267
  var n;
268
268
  }, t.prototype.hue = function(e) {
269
269
  var n = it(this.rgba);
270
- return typeof e == "number" ? X({ h: e, s: n.s, l: n.l, a: n.a }) : _(n.h);
270
+ return typeof e == "number" ? $({ h: e, s: n.s, l: n.l, a: n.a }) : _(n.h);
271
271
  }, t.prototype.isEqual = function(e) {
272
- return this.toHex() === X(e).toHex();
272
+ return this.toHex() === $(e).toHex();
273
273
  }, t;
274
- }(), X = function(t) {
275
- return t instanceof jt ? t : new jt(t);
274
+ }(), $ = function(t) {
275
+ return t instanceof zt ? t : new zt(t);
276
276
  };
277
277
  const De = (t) => [
278
- `background-color:${X((t == null ? void 0 : t.fill) || q.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? q.fillOpacity : t.fillOpacity).toHex()}`,
278
+ `background-color:${$((t == null ? void 0 : t.fill) || q.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? q.fillOpacity : t.fillOpacity).toHex()}`,
279
279
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
280
280
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
281
281
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
282
282
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
283
- ].filter(Boolean).join(";"), Ye = () => {
283
+ ].filter(Boolean).join(";"), Ke = () => {
284
284
  const t = document.createElement("style");
285
285
  document.getElementsByTagName("head")[0].appendChild(t);
286
286
  let e = /* @__PURE__ */ new Set();
@@ -293,23 +293,23 @@ const De = (t) => [
293
293
  },
294
294
  redraw: (r, a, s, l) => {
295
295
  l && l.clear();
296
- const u = new Set(r.map((c) => c.annotation.id));
297
- Array.from(e).filter((c) => !u.has(c));
296
+ const f = new Set(r.map((c) => c.annotation.id));
297
+ Array.from(e).filter((c) => !f.has(c));
298
298
  const g = r.map((c) => {
299
299
  var x;
300
- const p = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (x = c.state) != null && x.selected ? gt : q, d = l && l.paint(c, a) || p;
301
- return `::highlight(_${c.annotation.id}) { ${De(d)} }`;
300
+ const p = s ? typeof s == "function" ? s(c.annotation, c.state) : s : (x = c.state) != null && x.selected ? mt : q, u = l && l.paint(c, a) || p;
301
+ return `::highlight(_${c.annotation.id}) { ${De(u)} }`;
302
302
  });
303
303
  t.innerHTML = g.join(`
304
304
  `), CSS.highlights.clear(), r.forEach(({ annotation: c }) => {
305
- const p = c.target.selector.map((x) => x.range), d = new Highlight(...p);
306
- CSS.highlights.set(`_${c.id}`, d);
307
- }), e = u;
305
+ const p = c.target.selector.map((x) => x.range), u = new Highlight(...p);
306
+ CSS.highlights.set(`_${c.id}`, u);
307
+ }), e = f;
308
308
  }
309
309
  };
310
- }, Ke = (t, e, n) => _t(t, e, n, Ye());
311
- var zt = Object.prototype.hasOwnProperty;
312
- function Bt(t, e) {
310
+ }, Ye = (t, e, n) => Ut(t, e, n, Ke());
311
+ var Ft = Object.prototype.hasOwnProperty;
312
+ function Mt(t, e) {
313
313
  var n, o;
314
314
  if (t === e) return !0;
315
315
  if (t && e && (n = t.constructor) === e.constructor) {
@@ -317,13 +317,13 @@ function Bt(t, e) {
317
317
  if (n === RegExp) return t.toString() === e.toString();
318
318
  if (n === Array) {
319
319
  if ((o = t.length) === e.length)
320
- for (; o-- && Bt(t[o], e[o]); ) ;
320
+ for (; o-- && Mt(t[o], e[o]); ) ;
321
321
  return o === -1;
322
322
  }
323
323
  if (!n || typeof t == "object") {
324
324
  o = 0;
325
325
  for (n in t)
326
- if (zt.call(t, n) && ++o && !zt.call(e, n) || !(n in e) || !Bt(t[n], e[n])) return !1;
326
+ if (Ft.call(t, n) && ++o && !Ft.call(e, n) || !(n in e) || !Mt(t[n], e[n])) return !1;
327
327
  return Object.keys(e).length === o;
328
328
  }
329
329
  }
@@ -341,47 +341,51 @@ const Xe = (t, e) => {
341
341
  destroy: () => {
342
342
  e.remove();
343
343
  },
344
- redraw: (a, s, l, u, g) => {
345
- const p = !(Bt(n, a) && g);
346
- !u && !p || (p && (e.innerHTML = ""), a.forEach((d) => {
347
- d.rects.map((x) => {
348
- const v = Xe(x, a), b = Ae(d, s, l, u, v);
344
+ redraw: (a, s, l, f, g) => {
345
+ const p = !(Mt(n, a) && g);
346
+ if (!f && !p) return;
347
+ p && (e.innerHTML = ""), [...a].sort((x, b) => {
348
+ const { annotation: { target: { created: v } } } = x, { annotation: { target: { created: h } } } = b;
349
+ return v.getTime() - h.getTime();
350
+ }).forEach((x) => {
351
+ x.rects.map((b) => {
352
+ const v = Xe(b, a), h = Ae(x, s, l, f, v);
349
353
  if (p) {
350
- const h = document.createElement("span");
351
- h.className = "r6o-annotation", h.dataset.annotation = d.annotation.id, h.style.left = `${x.x}px`, h.style.top = `${x.y}px`, h.style.width = `${x.width}px`, h.style.height = `${x.height}px`, h.style.backgroundColor = X((b == null ? void 0 : b.fill) || q.fill).alpha((b == null ? void 0 : b.fillOpacity) === void 0 ? q.fillOpacity : b.fillOpacity).toHex(), b.underlineStyle && (h.style.borderStyle = b.underlineStyle), b.underlineColor && (h.style.borderColor = b.underlineColor), b.underlineThickness && (h.style.borderBottomWidth = `${b.underlineThickness}px`), b.underlineOffset && (h.style.paddingBottom = `${b.underlineOffset}px`), e.appendChild(h);
354
+ const d = document.createElement("span");
355
+ d.className = "r6o-annotation", d.dataset.annotation = x.annotation.id, d.style.left = `${b.x}px`, d.style.top = `${b.y}px`, d.style.width = `${b.width}px`, d.style.height = `${b.height}px`, d.style.backgroundColor = $((h == null ? void 0 : h.fill) || q.fill).alpha((h == null ? void 0 : h.fillOpacity) === void 0 ? q.fillOpacity : h.fillOpacity).toHex(), h.underlineStyle && (d.style.borderStyle = h.underlineStyle), h.underlineColor && (d.style.borderColor = h.underlineColor), h.underlineThickness && (d.style.borderBottomWidth = `${h.underlineThickness}px`), h.underlineOffset && (d.style.paddingBottom = `${h.underlineOffset}px`), e.appendChild(d);
352
356
  }
353
357
  });
354
- }), n = a);
358
+ }), n = a;
355
359
  },
356
360
  setVisible: (a) => {
357
361
  a ? e.classList.remove("hidden") : e.classList.add("hidden");
358
362
  }
359
363
  };
360
- }, $e = (t, e, n) => _t(t, e, n, Pe(t));
364
+ }, $e = (t, e, n) => Ut(t, e, n, Pe(t));
361
365
  var U = [];
362
- for (var vt = 0; vt < 256; ++vt)
363
- U.push((vt + 256).toString(16).slice(1));
366
+ for (var xt = 0; xt < 256; ++xt)
367
+ U.push((xt + 256).toString(16).slice(1));
364
368
  function He(t, e = 0) {
365
369
  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();
366
370
  }
367
- var dt, je = new Uint8Array(16);
371
+ var ut, je = new Uint8Array(16);
368
372
  function ze() {
369
- if (!dt && (dt = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !dt))
373
+ if (!ut && (ut = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ut))
370
374
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
371
- return dt(je);
375
+ return ut(je);
372
376
  }
373
377
  var Fe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
374
- const Ft = {
378
+ const Wt = {
375
379
  randomUUID: Fe
376
380
  };
377
- function ae(t, e, n) {
378
- if (Ft.randomUUID && !e && !t)
379
- return Ft.randomUUID();
381
+ function ce(t, e, n) {
382
+ if (Wt.randomUUID && !e && !t)
383
+ return Wt.randomUUID();
380
384
  t = t || {};
381
385
  var o = t.random || (t.rng || ze)();
382
386
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, He(o);
383
387
  }
384
- var Wt = Object.prototype.hasOwnProperty;
388
+ var qt = Object.prototype.hasOwnProperty;
385
389
  function Z(t, e) {
386
390
  var n, o;
387
391
  if (t === e) return !0;
@@ -396,29 +400,29 @@ function Z(t, e) {
396
400
  if (!n || typeof t == "object") {
397
401
  o = 0;
398
402
  for (n in t)
399
- if (Wt.call(t, n) && ++o && !Wt.call(e, n) || !(n in e) || !Z(t[n], e[n])) return !1;
403
+ if (qt.call(t, n) && ++o && !qt.call(e, n) || !(n in e) || !Z(t[n], e[n])) return !1;
400
404
  return Object.keys(e).length === o;
401
405
  }
402
406
  }
403
407
  return t !== t && e !== e;
404
408
  }
405
- function xt() {
409
+ function At() {
406
410
  }
407
411
  function We(t, e) {
408
412
  return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
409
413
  }
410
414
  const G = [];
411
- function Ut(t, e = xt) {
415
+ function Vt(t, e = At) {
412
416
  let n;
413
417
  const o = /* @__PURE__ */ new Set();
414
418
  function i(s) {
415
419
  if (We(t, s) && (t = s, n)) {
416
420
  const l = !G.length;
417
- for (const u of o)
418
- u[1](), G.push(u, t);
421
+ for (const f of o)
422
+ f[1](), G.push(f, t);
419
423
  if (l) {
420
- for (let u = 0; u < G.length; u += 2)
421
- G[u][0](G[u + 1]);
424
+ for (let f = 0; f < G.length; f += 2)
425
+ G[f][0](G[f + 1]);
422
426
  G.length = 0;
423
427
  }
424
428
  }
@@ -426,16 +430,16 @@ function Ut(t, e = xt) {
426
430
  function r(s) {
427
431
  i(s(t));
428
432
  }
429
- function a(s, l = xt) {
430
- const u = [s, l];
431
- return o.add(u), o.size === 1 && (n = e(i, r) || xt), s(t), () => {
432
- o.delete(u), o.size === 0 && n && (n(), n = null);
433
+ function a(s, l = At) {
434
+ const f = [s, l];
435
+ return o.add(f), o.size === 1 && (n = e(i, r) || At), s(t), () => {
436
+ o.delete(f), o.size === 0 && n && (n(), n = null);
433
437
  };
434
438
  }
435
439
  return { set: i, update: r, subscribe: a };
436
440
  }
437
441
  const qe = (t) => {
438
- const { subscribe: e, set: n } = Ut();
442
+ const { subscribe: e, set: n } = Vt();
439
443
  let o;
440
444
  return e((i) => o = i), t.observe(({ changes: i }) => {
441
445
  if (o) {
@@ -452,50 +456,50 @@ const qe = (t) => {
452
456
  };
453
457
  };
454
458
  var Ge = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(Ge || {});
455
- const At = { selected: [] }, Qe = (t, e = "EDIT") => {
456
- const { subscribe: n, set: o } = Ut(At);
457
- let i = e, r = At;
458
- n((d) => r = d);
459
- const a = () => o(At), s = () => {
460
- var d;
461
- return ((d = r.selected) == null ? void 0 : d.length) === 0;
462
- }, l = (d) => {
459
+ const Et = { selected: [] }, Qe = (t, e = "EDIT") => {
460
+ const { subscribe: n, set: o } = Vt(Et);
461
+ let i = e, r = Et;
462
+ n((u) => r = u);
463
+ const a = () => o(Et), s = () => {
464
+ var u;
465
+ return ((u = r.selected) == null ? void 0 : u.length) === 0;
466
+ }, l = (u) => {
463
467
  if (s())
464
468
  return !1;
465
- const x = typeof d == "string" ? d : d.id;
466
- return r.selected.some((v) => v.id === x);
467
- }, u = (d, x) => {
468
- const v = t.getAnnotation(d);
469
- if (!v) {
470
- console.warn("Invalid selection: " + d);
469
+ const x = typeof u == "string" ? u : u.id;
470
+ return r.selected.some((b) => b.id === x);
471
+ }, f = (u, x) => {
472
+ const b = t.getAnnotation(u);
473
+ if (!b) {
474
+ console.warn("Invalid selection: " + u);
471
475
  return;
472
476
  }
473
- switch (qt(v, i)) {
477
+ switch (Gt(b, i)) {
474
478
  case "EDIT":
475
- o({ selected: [{ id: d, editable: !0 }], event: x });
479
+ o({ selected: [{ id: u, editable: !0 }], event: x });
476
480
  break;
477
481
  case "SELECT":
478
- o({ selected: [{ id: d }], event: x });
482
+ o({ selected: [{ id: u }], event: x });
479
483
  break;
480
484
  default:
481
485
  o({ selected: [], event: x });
482
486
  }
483
- }, g = (d, x) => {
484
- const v = Array.isArray(d) ? d : [d], b = v.map((h) => t.getAnnotation(h)).filter((h) => !!h);
487
+ }, g = (u, x) => {
488
+ const b = Array.isArray(u) ? u : [u], v = b.map((h) => t.getAnnotation(h)).filter((h) => !!h);
485
489
  o({
486
- selected: b.map((h) => {
487
- const f = x === void 0 ? qt(h, i) === "EDIT" : x;
488
- return { id: h.id, editable: f };
490
+ selected: v.map((h) => {
491
+ const d = x === void 0 ? Gt(h, i) === "EDIT" : x;
492
+ return { id: h.id, editable: d };
489
493
  })
490
- }), b.length !== v.length && console.warn("Invalid selection", d);
491
- }, c = (d) => {
494
+ }), v.length !== b.length && console.warn("Invalid selection", u);
495
+ }, c = (u) => {
492
496
  if (s())
493
497
  return !1;
494
498
  const { selected: x } = r;
495
- x.some(({ id: v }) => d.includes(v)) && o({ selected: x.filter(({ id: v }) => !d.includes(v)) });
496
- }, p = (d) => i = d;
499
+ x.some(({ id: b }) => u.includes(b)) && o({ selected: x.filter(({ id: b }) => !u.includes(b)) });
500
+ }, p = (u) => i = u;
497
501
  return t.observe(
498
- ({ changes: d }) => c((d.deleted || []).map((x) => x.id))
502
+ ({ changes: u }) => c((u.deleted || []).map((x) => x.id))
499
503
  ), {
500
504
  get event() {
501
505
  return r ? r.event : null;
@@ -509,28 +513,28 @@ const At = { selected: [] }, Qe = (t, e = "EDIT") => {
509
513
  setSelected: g,
510
514
  setUserSelectAction: p,
511
515
  subscribe: n,
512
- userSelect: u
516
+ userSelect: f
513
517
  };
514
- }, qt = (t, e) => typeof e == "function" ? e(t) : e || "EDIT";
518
+ }, Gt = (t, e) => typeof e == "function" ? e(t) : e || "EDIT";
515
519
  var V = [];
516
- for (var Et = 0; Et < 256; ++Et)
517
- V.push((Et + 256).toString(16).slice(1));
520
+ for (var St = 0; St < 256; ++St)
521
+ V.push((St + 256).toString(16).slice(1));
518
522
  function Je(t, e = 0) {
519
523
  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();
520
524
  }
521
- var ut, Ze = new Uint8Array(16);
525
+ var ft, Ze = new Uint8Array(16);
522
526
  function tn() {
523
- if (!ut && (ut = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ut))
527
+ if (!ft && (ft = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ft))
524
528
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
525
- return ut(Ze);
529
+ return ft(Ze);
526
530
  }
527
531
  var en = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
528
- const Gt = {
532
+ const Qt = {
529
533
  randomUUID: en
530
534
  };
531
535
  function nn(t, e, n) {
532
- if (Gt.randomUUID && !e && !t)
533
- return Gt.randomUUID();
536
+ if (Qt.randomUUID && !e && !t)
537
+ return Qt.randomUUID();
534
538
  t = t || {};
535
539
  var o = t.random || (t.rng || tn)();
536
540
  return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Je(o);
@@ -550,7 +554,7 @@ const Eo = (t, e, n, o) => ({
550
554
  }, sn = (t, e) => e.bodies.map((n) => {
551
555
  const o = t.bodies.find((i) => i.id === n.id);
552
556
  return { newBody: n, oldBody: o && !Z(o, n) ? o : void 0 };
553
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), an = (t, e) => !Z(t.target, e.target), ce = (t, e) => {
557
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), an = (t, e) => !Z(t.target, e.target), le = (t, e) => {
554
558
  const n = on(t, e), o = rn(t, e), i = sn(t, e);
555
559
  return {
556
560
  oldValue: t,
@@ -570,8 +574,8 @@ const cn = (t, e) => {
570
574
  if (t.options.ignore) {
571
575
  const { ignore: a } = t.options, s = (l) => l && l.length > 0;
572
576
  if (!(s(i.created) || s(i.deleted))) {
573
- const l = (n = i.updated) == null ? void 0 : n.some((g) => s(g.bodiesCreated) || s(g.bodiesDeleted) || s(g.bodiesUpdated)), u = (o = i.updated) == null ? void 0 : o.some((g) => g.targetUpdated);
574
- if (a === "BODY_ONLY" && l && !u || a === "TARGET_ONLY" && u && !l)
577
+ const l = (n = i.updated) == null ? void 0 : n.some((g) => s(g.bodiesCreated) || s(g.bodiesDeleted) || s(g.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((g) => g.targetUpdated);
578
+ if (a === "BODY_ONLY" && l && !f || a === "TARGET_ONLY" && f && !l)
575
579
  return !1;
576
580
  }
577
581
  }
@@ -588,180 +592,180 @@ const cn = (t, e) => {
588
592
  const n = new Set((t.created || []).map((c) => c.id)), o = new Set((t.updated || []).map(({ newValue: c }) => c.id)), i = new Set((e.created || []).map((c) => c.id)), r = new Set((e.deleted || []).map((c) => c.id)), a = new Set((e.updated || []).map(({ oldValue: c }) => c.id)), s = new Set((e.updated || []).filter(({ oldValue: c }) => n.has(c.id) || o.has(c.id)).map(({ oldValue: c }) => c.id)), l = [
589
593
  ...(t.created || []).filter((c) => !r.has(c.id)).map((c) => a.has(c.id) ? e.updated.find(({ oldValue: p }) => p.id === c.id).newValue : c),
590
594
  ...e.created || []
591
- ], u = [
595
+ ], f = [
592
596
  ...(t.deleted || []).filter((c) => !i.has(c.id)),
593
597
  ...(e.deleted || []).filter((c) => !n.has(c.id))
594
598
  ], g = [
595
599
  ...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
596
- const { oldValue: p, newValue: d } = c;
597
- if (a.has(d.id)) {
598
- const x = e.updated.find((v) => v.oldValue.id === d.id).newValue;
599
- return ce(p, x);
600
+ const { oldValue: p, newValue: u } = c;
601
+ if (a.has(u.id)) {
602
+ const x = e.updated.find((b) => b.oldValue.id === u.id).newValue;
603
+ return le(p, x);
600
604
  } else
601
605
  return c;
602
606
  }),
603
607
  ...(e.updated || []).filter(({ oldValue: c }) => !s.has(c.id))
604
608
  ];
605
- return { created: l, deleted: u, updated: g };
609
+ return { created: l, deleted: f, updated: g };
606
610
  }, dn = (t) => t.id !== void 0, un = () => {
607
- const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, A = {}) => n.push({ onChange: m, options: A }), i = (m) => {
608
- const A = n.findIndex((S) => S.onChange == m);
609
- A > -1 && n.splice(A, 1);
610
- }, r = (m, A) => {
611
- const S = {
611
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (m, w = {}) => n.push({ onChange: m, options: w }), i = (m) => {
612
+ const w = n.findIndex((E) => E.onChange == m);
613
+ w > -1 && n.splice(w, 1);
614
+ }, r = (m, w) => {
615
+ const E = {
612
616
  origin: m,
613
617
  changes: {
614
- created: A.created || [],
615
- updated: A.updated || [],
616
- deleted: A.deleted || []
618
+ created: w.created || [],
619
+ updated: w.updated || [],
620
+ deleted: w.deleted || []
617
621
  },
618
622
  state: [...t.values()]
619
623
  };
620
- n.forEach((C) => {
621
- cn(C, S) && C.onChange(S);
624
+ n.forEach((L) => {
625
+ cn(L, E) && L.onChange(E);
622
626
  });
623
- }, a = (m, A = M.LOCAL) => {
627
+ }, a = (m, w = M.LOCAL) => {
624
628
  if (t.get(m.id))
625
629
  throw Error(`Cannot add annotation ${m.id} - exists already`);
626
- t.set(m.id, m), m.bodies.forEach((S) => e.set(S.id, m.id)), r(A, { created: [m] });
627
- }, s = (m, A) => {
628
- const S = typeof m == "string" ? A : m, C = typeof m == "string" ? m : m.id, R = t.get(C);
629
- if (R) {
630
- const N = ce(R, S);
631
- return C === S.id ? t.set(C, S) : (t.delete(C), t.set(S.id, S)), R.bodies.forEach(($) => e.delete($.id)), S.bodies.forEach(($) => e.set($.id, S.id)), N;
630
+ t.set(m.id, m), m.bodies.forEach((E) => e.set(E.id, m.id)), r(w, { created: [m] });
631
+ }, s = (m, w) => {
632
+ const E = typeof m == "string" ? w : m, L = typeof m == "string" ? m : m.id, T = t.get(L);
633
+ if (T) {
634
+ const N = le(T, E);
635
+ return L === E.id ? t.set(L, E) : (t.delete(L), t.set(E.id, E)), T.bodies.forEach((K) => e.delete(K.id)), E.bodies.forEach((K) => e.set(K.id, E.id)), N;
632
636
  } else
633
- console.warn(`Cannot update annotation ${C} - does not exist`);
634
- }, l = (m, A = M.LOCAL, S = M.LOCAL) => {
635
- const C = dn(A) ? S : A, R = s(m, A);
636
- R && r(C, { updated: [R] });
637
- }, u = (m, A = M.LOCAL) => {
638
- const S = m.reduce((C, R) => {
639
- const N = s(R);
640
- return N ? [...C, N] : C;
637
+ console.warn(`Cannot update annotation ${L} - does not exist`);
638
+ }, l = (m, w = M.LOCAL, E = M.LOCAL) => {
639
+ const L = dn(w) ? E : w, T = s(m, w);
640
+ T && r(L, { updated: [T] });
641
+ }, f = (m, w = M.LOCAL) => {
642
+ const E = m.reduce((L, T) => {
643
+ const N = s(T);
644
+ return N ? [...L, N] : L;
641
645
  }, []);
642
- S.length > 0 && r(A, { updated: S });
643
- }, g = (m, A = M.LOCAL) => {
644
- const S = t.get(m.annotation);
645
- if (S) {
646
- const C = {
647
- ...S,
648
- bodies: [...S.bodies, m]
646
+ E.length > 0 && r(w, { updated: E });
647
+ }, g = (m, w = M.LOCAL) => {
648
+ const E = t.get(m.annotation);
649
+ if (E) {
650
+ const L = {
651
+ ...E,
652
+ bodies: [...E.bodies, m]
649
653
  };
650
- t.set(S.id, C), e.set(m.id, C.id), r(A, { updated: [{
651
- oldValue: S,
652
- newValue: C,
654
+ t.set(E.id, L), e.set(m.id, L.id), r(w, { updated: [{
655
+ oldValue: E,
656
+ newValue: L,
653
657
  bodiesCreated: [m]
654
658
  }] });
655
659
  } else
656
660
  console.warn(`Attempt to add body to missing annotation: ${m.annotation}`);
657
661
  }, c = () => [...t.values()], p = (m = M.LOCAL) => {
658
- const A = [...t.values()];
659
- t.clear(), e.clear(), r(m, { deleted: A });
660
- }, d = (m, A = !0, S = M.LOCAL) => {
661
- if (A) {
662
- const C = [...t.values()];
663
- t.clear(), e.clear(), m.forEach((R) => {
664
- t.set(R.id, R), R.bodies.forEach((N) => e.set(N.id, R.id));
665
- }), r(S, { created: m, deleted: C });
662
+ const w = [...t.values()];
663
+ t.clear(), e.clear(), r(m, { deleted: w });
664
+ }, u = (m, w = !0, E = M.LOCAL) => {
665
+ if (w) {
666
+ const L = [...t.values()];
667
+ t.clear(), e.clear(), m.forEach((T) => {
668
+ t.set(T.id, T), T.bodies.forEach((N) => e.set(N.id, T.id));
669
+ }), r(E, { created: m, deleted: L });
666
670
  } else {
667
- const C = m.reduce((R, N) => {
668
- const $ = t.get(N.id);
669
- return $ ? [...R, $] : R;
671
+ const L = m.reduce((T, N) => {
672
+ const K = t.get(N.id);
673
+ return K ? [...T, K] : T;
670
674
  }, []);
671
- if (C.length > 0)
672
- throw Error(`Bulk insert would overwrite the following annotations: ${C.map((R) => R.id).join(", ")}`);
673
- m.forEach((R) => {
674
- t.set(R.id, R), R.bodies.forEach((N) => e.set(N.id, R.id));
675
- }), r(S, { created: m });
675
+ if (L.length > 0)
676
+ throw Error(`Bulk insert would overwrite the following annotations: ${L.map((T) => T.id).join(", ")}`);
677
+ m.forEach((T) => {
678
+ t.set(T.id, T), T.bodies.forEach((N) => e.set(N.id, T.id));
679
+ }), r(E, { created: m });
676
680
  }
677
681
  }, x = (m) => {
678
- const A = typeof m == "string" ? m : m.id, S = t.get(A);
679
- if (S)
680
- return t.delete(A), S.bodies.forEach((C) => e.delete(C.id)), S;
681
- console.warn(`Attempt to delete missing annotation: ${A}`);
682
- }, v = (m, A = M.LOCAL) => {
683
- const S = x(m);
684
- S && r(A, { deleted: [S] });
685
- }, b = (m, A = M.LOCAL) => {
686
- const S = m.reduce((C, R) => {
687
- const N = x(R);
688
- return N ? [...C, N] : C;
682
+ const w = typeof m == "string" ? m : m.id, E = t.get(w);
683
+ if (E)
684
+ return t.delete(w), E.bodies.forEach((L) => e.delete(L.id)), E;
685
+ console.warn(`Attempt to delete missing annotation: ${w}`);
686
+ }, b = (m, w = M.LOCAL) => {
687
+ const E = x(m);
688
+ E && r(w, { deleted: [E] });
689
+ }, v = (m, w = M.LOCAL) => {
690
+ const E = m.reduce((L, T) => {
691
+ const N = x(T);
692
+ return N ? [...L, N] : L;
689
693
  }, []);
690
- S.length > 0 && r(A, { deleted: S });
694
+ E.length > 0 && r(w, { deleted: E });
691
695
  }, h = (m) => {
692
- const A = t.get(m.annotation);
693
- if (A) {
694
- const S = A.bodies.find((C) => C.id === m.id);
695
- if (S) {
696
- e.delete(S.id);
697
- const C = {
698
- ...A,
699
- bodies: A.bodies.filter((R) => R.id !== m.id)
696
+ const w = t.get(m.annotation);
697
+ if (w) {
698
+ const E = w.bodies.find((L) => L.id === m.id);
699
+ if (E) {
700
+ e.delete(E.id);
701
+ const L = {
702
+ ...w,
703
+ bodies: w.bodies.filter((T) => T.id !== m.id)
700
704
  };
701
- return t.set(A.id, C), {
702
- oldValue: A,
703
- newValue: C,
704
- bodiesDeleted: [S]
705
+ return t.set(w.id, L), {
706
+ oldValue: w,
707
+ newValue: L,
708
+ bodiesDeleted: [E]
705
709
  };
706
710
  } else
707
711
  console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`);
708
712
  } else
709
713
  console.warn(`Attempt to delete body from missing annotation ${m.annotation}`);
710
- }, f = (m, A = M.LOCAL) => {
711
- const S = h(m);
712
- S && r(A, { updated: [S] });
713
- }, y = (m, A = M.LOCAL) => {
714
- const S = m.map((C) => h(C)).filter(Boolean);
715
- S.length > 0 && r(A, { updated: S });
716
- }, E = (m) => {
717
- const A = t.get(m);
718
- return A ? { ...A } : void 0;
719
- }, w = (m) => {
720
- const A = e.get(m);
721
- if (A) {
722
- const S = E(A).bodies.find((C) => C.id === m);
723
- if (S)
724
- return S;
714
+ }, d = (m, w = M.LOCAL) => {
715
+ const E = h(m);
716
+ E && r(w, { updated: [E] });
717
+ }, y = (m, w = M.LOCAL) => {
718
+ const E = m.map((L) => h(L)).filter(Boolean);
719
+ E.length > 0 && r(w, { updated: E });
720
+ }, A = (m) => {
721
+ const w = t.get(m);
722
+ return w ? { ...w } : void 0;
723
+ }, C = (m) => {
724
+ const w = e.get(m);
725
+ if (w) {
726
+ const E = A(w).bodies.find((L) => L.id === m);
727
+ if (E)
728
+ return E;
725
729
  console.error(`Store integrity error: body ${m} in index, but not in annotation`);
726
730
  } else
727
731
  console.warn(`Attempt to retrieve missing body: ${m}`);
728
- }, O = (m, A) => {
729
- if (m.annotation !== A.annotation)
732
+ }, S = (m, w) => {
733
+ if (m.annotation !== w.annotation)
730
734
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
731
- const S = t.get(m.annotation);
732
- if (S) {
733
- const C = S.bodies.find((N) => N.id === m.id), R = {
734
- ...S,
735
- bodies: S.bodies.map((N) => N.id === C.id ? A : N)
735
+ const E = t.get(m.annotation);
736
+ if (E) {
737
+ const L = E.bodies.find((N) => N.id === m.id), T = {
738
+ ...E,
739
+ bodies: E.bodies.map((N) => N.id === L.id ? w : N)
736
740
  };
737
- return t.set(S.id, R), C.id !== A.id && (e.delete(C.id), e.set(A.id, R.id)), {
738
- oldValue: S,
739
- newValue: R,
740
- bodiesUpdated: [{ oldBody: C, newBody: A }]
741
+ return t.set(E.id, T), L.id !== w.id && (e.delete(L.id), e.set(w.id, T.id)), {
742
+ oldValue: E,
743
+ newValue: T,
744
+ bodiesUpdated: [{ oldBody: L, newBody: w }]
741
745
  };
742
746
  } else
743
747
  console.warn(`Attempt to add body to missing annotation ${m.annotation}`);
744
- }, B = (m, A, S = M.LOCAL) => {
745
- const C = O(m, A);
746
- C && r(S, { updated: [C] });
747
- }, L = (m, A = M.LOCAL) => {
748
- const S = m.map((C) => O({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
749
- r(A, { updated: S });
750
- }, T = (m) => {
751
- const A = t.get(m.annotation);
752
- if (A) {
753
- const S = {
754
- ...A,
748
+ }, R = (m, w, E = M.LOCAL) => {
749
+ const L = S(m, w);
750
+ L && r(E, { updated: [L] });
751
+ }, O = (m, w = M.LOCAL) => {
752
+ const E = m.map((L) => S({ id: L.id, annotation: L.annotation }, L)).filter(Boolean);
753
+ r(w, { updated: E });
754
+ }, B = (m) => {
755
+ const w = t.get(m.annotation);
756
+ if (w) {
757
+ const E = {
758
+ ...w,
755
759
  target: {
756
- ...A.target,
760
+ ...w.target,
757
761
  ...m
758
762
  }
759
763
  };
760
- return t.set(A.id, S), {
761
- oldValue: A,
762
- newValue: S,
764
+ return t.set(w.id, E), {
765
+ oldValue: w,
766
+ newValue: E,
763
767
  targetUpdated: {
764
- oldTarget: A.target,
768
+ oldTarget: w.target,
765
769
  newTarget: m
766
770
  }
767
771
  };
@@ -772,27 +776,27 @@ const cn = (t, e) => {
772
776
  addAnnotation: a,
773
777
  addBody: g,
774
778
  all: c,
775
- bulkAddAnnotation: d,
776
- bulkDeleteAnnotation: b,
779
+ bulkAddAnnotation: u,
780
+ bulkDeleteAnnotation: v,
777
781
  bulkDeleteBodies: y,
778
- bulkUpdateAnnotation: u,
779
- bulkUpdateBodies: L,
780
- bulkUpdateTargets: (m, A = M.LOCAL) => {
781
- const S = m.map((C) => T(C)).filter(Boolean);
782
- S.length > 0 && r(A, { updated: S });
782
+ bulkUpdateAnnotation: f,
783
+ bulkUpdateBodies: O,
784
+ bulkUpdateTargets: (m, w = M.LOCAL) => {
785
+ const E = m.map((L) => B(L)).filter(Boolean);
786
+ E.length > 0 && r(w, { updated: E });
783
787
  },
784
788
  clear: p,
785
- deleteAnnotation: v,
786
- deleteBody: f,
787
- getAnnotation: E,
788
- getBody: w,
789
+ deleteAnnotation: b,
790
+ deleteBody: d,
791
+ getAnnotation: A,
792
+ getBody: C,
789
793
  observe: o,
790
794
  unobserve: i,
791
795
  updateAnnotation: l,
792
- updateBody: B,
793
- updateTarget: (m, A = M.LOCAL) => {
794
- const S = T(m);
795
- S && r(A, { updated: [S] });
796
+ updateBody: R,
797
+ updateTarget: (m, w = M.LOCAL) => {
798
+ const E = B(m);
799
+ E && r(w, { updated: [E] });
796
800
  }
797
801
  };
798
802
  };
@@ -813,115 +817,115 @@ let fn = () => ({
813
817
  const hn = 250, pn = (t) => {
814
818
  const e = fn(), n = [];
815
819
  let o = -1, i = !1, r = 0;
816
- const a = (d) => {
820
+ const a = (u) => {
817
821
  if (!i) {
818
- const { changes: x } = d, v = performance.now();
819
- if (v - r > hn)
822
+ const { changes: x } = u, b = performance.now();
823
+ if (b - r > hn)
820
824
  n.splice(o + 1), n.push(x), o = n.length - 1;
821
825
  else {
822
- const b = n.length - 1;
823
- n[b] = ln(n[b], x);
826
+ const v = n.length - 1;
827
+ n[v] = ln(n[v], x);
824
828
  }
825
- r = v;
829
+ r = b;
826
830
  }
827
831
  i = !1;
828
832
  };
829
833
  t.observe(a, { origin: M.LOCAL });
830
- const s = (d) => d && d.length > 0 && t.bulkDeleteAnnotation(d), l = (d) => d && d.length > 0 && t.bulkAddAnnotation(d, !1), u = (d) => d && d.length > 0 && t.bulkUpdateAnnotation(d.map(({ oldValue: x }) => x)), g = (d) => d && d.length > 0 && t.bulkUpdateAnnotation(d.map(({ newValue: x }) => x)), c = (d) => d && d.length > 0 && t.bulkAddAnnotation(d, !1), p = (d) => d && d.length > 0 && t.bulkDeleteAnnotation(d);
834
+ const s = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u), l = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), f = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ oldValue: x }) => x)), g = (u) => u && u.length > 0 && t.bulkUpdateAnnotation(u.map(({ newValue: x }) => x)), c = (u) => u && u.length > 0 && t.bulkAddAnnotation(u, !1), p = (u) => u && u.length > 0 && t.bulkDeleteAnnotation(u);
831
835
  return {
832
836
  canRedo: () => n.length - 1 > o,
833
837
  canUndo: () => o > -1,
834
838
  destroy: () => t.unobserve(a),
835
- on: (d, x) => e.on(d, x),
839
+ on: (u, x) => e.on(u, x),
836
840
  redo: () => {
837
841
  if (n.length - 1 > o) {
838
842
  i = !0;
839
- const { created: d, updated: x, deleted: v } = n[o + 1];
840
- l(d), g(x), p(v), e.emit("redo", n[o + 1]), o += 1;
843
+ const { created: u, updated: x, deleted: b } = n[o + 1];
844
+ l(u), g(x), p(b), e.emit("redo", n[o + 1]), o += 1;
841
845
  }
842
846
  },
843
847
  undo: () => {
844
848
  if (o > -1) {
845
849
  i = !0;
846
- const { created: d, updated: x, deleted: v } = n[o];
847
- s(d), u(x), c(v), e.emit("undo", n[o]), o -= 1;
850
+ const { created: u, updated: x, deleted: b } = n[o];
851
+ s(u), f(x), c(b), e.emit("undo", n[o]), o -= 1;
848
852
  }
849
853
  }
850
854
  };
851
855
  }, gn = () => {
852
- const { subscribe: t, set: e } = Ut([]);
856
+ const { subscribe: t, set: e } = Vt([]);
853
857
  return {
854
858
  subscribe: t,
855
859
  set: e
856
860
  };
857
861
  }, mn = (t, e, n, o) => {
858
862
  const { store: i, selection: r, hover: a, viewport: s } = t, l = /* @__PURE__ */ new Map();
859
- let u = [], g;
860
- const c = (v, b) => {
861
- l.has(v) ? l.get(v).push(b) : l.set(v, [b]);
862
- }, p = (v, b) => {
863
- const h = l.get(v);
863
+ let f = [], g;
864
+ const c = (b, v) => {
865
+ l.has(b) ? l.get(b).push(v) : l.set(b, [v]);
866
+ }, p = (b, v) => {
867
+ const h = l.get(b);
864
868
  if (h) {
865
- const f = h.indexOf(b);
866
- f !== -1 && h.splice(f, 1);
869
+ const d = h.indexOf(v);
870
+ d !== -1 && h.splice(d, 1);
867
871
  }
868
- }, d = (v, b, h) => {
869
- l.has(v) && setTimeout(() => {
870
- l.get(v).forEach((f) => {
872
+ }, u = (b, v, h) => {
873
+ l.has(b) && setTimeout(() => {
874
+ l.get(b).forEach((d) => {
871
875
  if (n) {
872
- const y = Array.isArray(b) ? b.map((w) => n.serialize(w)) : n.serialize(b), E = h ? h instanceof PointerEvent ? h : n.serialize(h) : void 0;
873
- f(y, E);
876
+ const y = Array.isArray(v) ? v.map((C) => n.serialize(C)) : n.serialize(v), A = h ? h instanceof PointerEvent ? h : n.serialize(h) : void 0;
877
+ d(y, A);
874
878
  } else
875
- f(b, h);
879
+ d(v, h);
876
880
  });
877
881
  }, 1);
878
882
  };
879
- r.subscribe(({ selected: v }) => {
880
- if (!(u.length === 0 && v.length === 0)) {
881
- if (u.length === 0 && v.length > 0)
882
- u = v.map(({ id: b }) => i.getAnnotation(b));
883
- else if (u.length > 0 && v.length === 0)
884
- u.forEach((b) => {
885
- const h = i.getAnnotation(b.id);
886
- h && !Z(h, b) && d("updateAnnotation", h, b);
887
- }), u = [];
883
+ r.subscribe(({ selected: b }) => {
884
+ if (!(f.length === 0 && b.length === 0)) {
885
+ if (f.length === 0 && b.length > 0)
886
+ f = b.map(({ id: v }) => i.getAnnotation(v));
887
+ else if (f.length > 0 && b.length === 0)
888
+ f.forEach((v) => {
889
+ const h = i.getAnnotation(v.id);
890
+ h && !Z(h, v) && u("updateAnnotation", h, v);
891
+ }), f = [];
888
892
  else {
889
- const b = new Set(u.map((f) => f.id)), h = new Set(v.map(({ id: f }) => f));
890
- u.filter((f) => !h.has(f.id)).forEach((f) => {
891
- const y = i.getAnnotation(f.id);
892
- y && !Z(y, f) && d("updateAnnotation", y, f);
893
- }), u = [
893
+ const v = new Set(f.map((d) => d.id)), h = new Set(b.map(({ id: d }) => d));
894
+ f.filter((d) => !h.has(d.id)).forEach((d) => {
895
+ const y = i.getAnnotation(d.id);
896
+ y && !Z(y, d) && u("updateAnnotation", y, d);
897
+ }), f = [
894
898
  // Remove annotations that were deselected
895
- ...u.filter((f) => h.has(f.id)),
899
+ ...f.filter((d) => h.has(d.id)),
896
900
  // Add editable annotations that were selected
897
- ...v.filter(({ id: f }) => !b.has(f)).map(({ id: f }) => i.getAnnotation(f))
901
+ ...b.filter(({ id: d }) => !v.has(d)).map(({ id: d }) => i.getAnnotation(d))
898
902
  ];
899
903
  }
900
- d("selectionChanged", u);
904
+ u("selectionChanged", f);
901
905
  }
902
- }), a.subscribe((v) => {
903
- !g && v ? d("mouseEnterAnnotation", i.getAnnotation(v)) : g && !v ? d("mouseLeaveAnnotation", i.getAnnotation(g)) : g && v && (d("mouseLeaveAnnotation", i.getAnnotation(g)), d("mouseEnterAnnotation", i.getAnnotation(v))), g = v;
904
- }), s == null || s.subscribe((v) => d("viewportIntersect", v.map((b) => i.getAnnotation(b)))), i.observe((v) => {
905
- const { created: b, deleted: h } = v.changes;
906
- (b || []).forEach((f) => d("createAnnotation", f)), (h || []).forEach((f) => d("deleteAnnotation", f)), (v.changes.updated || []).filter((f) => [
907
- ...f.bodiesCreated || [],
908
- ...f.bodiesDeleted || [],
909
- ...f.bodiesUpdated || []
910
- ].length > 0).forEach(({ oldValue: f, newValue: y }) => {
911
- const E = u.find((w) => w.id === f.id) || f;
912
- u = u.map((w) => w.id === f.id ? y : w), d("updateAnnotation", y, E);
906
+ }), a.subscribe((b) => {
907
+ !g && b ? u("mouseEnterAnnotation", i.getAnnotation(b)) : g && !b ? u("mouseLeaveAnnotation", i.getAnnotation(g)) : g && b && (u("mouseLeaveAnnotation", i.getAnnotation(g)), u("mouseEnterAnnotation", i.getAnnotation(b))), g = b;
908
+ }), s == null || s.subscribe((b) => u("viewportIntersect", b.map((v) => i.getAnnotation(v)))), i.observe((b) => {
909
+ const { created: v, deleted: h } = b.changes;
910
+ (v || []).forEach((d) => u("createAnnotation", d)), (h || []).forEach((d) => u("deleteAnnotation", d)), (b.changes.updated || []).filter((d) => [
911
+ ...d.bodiesCreated || [],
912
+ ...d.bodiesDeleted || [],
913
+ ...d.bodiesUpdated || []
914
+ ].length > 0).forEach(({ oldValue: d, newValue: y }) => {
915
+ const A = f.find((C) => C.id === d.id) || d;
916
+ f = f.map((C) => C.id === d.id ? y : C), u("updateAnnotation", y, A);
913
917
  });
914
- }, { origin: M.LOCAL }), i.observe((v) => {
915
- if (u) {
916
- const b = new Set(u.map((f) => f.id)), h = (v.changes.updated || []).filter(({ newValue: f }) => b.has(f.id)).map(({ newValue: f }) => f);
917
- h.length > 0 && (u = u.map((f) => h.find((E) => E.id === f.id) || f));
918
+ }, { origin: M.LOCAL }), i.observe((b) => {
919
+ if (f) {
920
+ const v = new Set(f.map((d) => d.id)), h = (b.changes.updated || []).filter(({ newValue: d }) => v.has(d.id)).map(({ newValue: d }) => d);
921
+ h.length > 0 && (f = f.map((d) => h.find((A) => A.id === d.id) || d));
918
922
  }
919
923
  }, { origin: M.REMOTE });
920
- const x = (v) => (b) => {
921
- const { updated: h } = b;
922
- v ? (h || []).forEach((f) => d("updateAnnotation", f.oldValue, f.newValue)) : (h || []).forEach((f) => d("updateAnnotation", f.newValue, f.oldValue));
924
+ const x = (b) => (v) => {
925
+ const { updated: h } = v;
926
+ b ? (h || []).forEach((d) => u("updateAnnotation", d.oldValue, d.newValue)) : (h || []).forEach((d) => u("updateAnnotation", d.newValue, d.oldValue));
923
927
  };
924
- return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: p, emit: d };
928
+ return e.on("undo", x(!0)), e.on("redo", x(!1)), { on: c, off: p, emit: u };
925
929
  }, yn = (t) => (e) => e.reduce((n, o) => {
926
930
  const { parsed: i, error: r } = t.parse(o);
927
931
  return r ? {
@@ -936,44 +940,44 @@ const hn = 250, pn = (t) => {
936
940
  }, { parsed: [], failed: [] }), bn = (t, e, n) => {
937
941
  const { store: o, selection: i } = t, r = (h) => {
938
942
  if (n) {
939
- const { parsed: f, error: y } = n.parse(h);
940
- f ? o.addAnnotation(f, M.REMOTE) : console.error(y);
943
+ const { parsed: d, error: y } = n.parse(h);
944
+ d ? o.addAnnotation(d, M.REMOTE) : console.error(y);
941
945
  } else
942
946
  o.addAnnotation(h, M.REMOTE);
943
947
  }, a = () => i.clear(), s = () => o.clear(), l = (h) => {
944
- const f = o.getAnnotation(h);
945
- return n && f ? n.serialize(f) : f;
946
- }, u = () => n ? o.all().map(n.serialize) : o.all(), g = () => {
948
+ const d = o.getAnnotation(h);
949
+ return n && d ? n.serialize(d) : d;
950
+ }, f = () => n ? o.all().map(n.serialize) : o.all(), g = () => {
947
951
  var h;
948
- const f = (((h = i.selected) == null ? void 0 : h.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
949
- return n ? f.map(n.serialize) : f;
950
- }, c = (h, f = !0) => fetch(h).then((y) => y.json()).then((y) => (d(y, f), y)), p = (h) => {
952
+ const d = (((h = i.selected) == null ? void 0 : h.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
953
+ return n ? d.map(n.serialize) : d;
954
+ }, c = (h, d = !0) => fetch(h).then((y) => y.json()).then((y) => (u(y, d), y)), p = (h) => {
951
955
  if (typeof h == "string") {
952
- const f = o.getAnnotation(h);
953
- if (o.deleteAnnotation(h), f)
954
- return n ? n.serialize(f) : f;
956
+ const d = o.getAnnotation(h);
957
+ if (o.deleteAnnotation(h), d)
958
+ return n ? n.serialize(d) : d;
955
959
  } else {
956
- const f = n ? n.parse(h).parsed : h;
957
- if (f)
958
- return o.deleteAnnotation(f), h;
960
+ const d = n ? n.parse(h).parsed : h;
961
+ if (d)
962
+ return o.deleteAnnotation(d), h;
959
963
  }
960
- }, d = (h, f = !0) => {
964
+ }, u = (h, d = !0) => {
961
965
  if (n) {
962
- const { parsed: y, failed: E } = yn(n)(h);
963
- E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotation(y, f, M.REMOTE);
966
+ const { parsed: y, failed: A } = yn(n)(h);
967
+ A.length > 0 && console.warn(`Discarded ${A.length} invalid annotations`, A), o.bulkAddAnnotation(y, d, M.REMOTE);
964
968
  } else
965
- o.bulkAddAnnotation(h, f, M.REMOTE);
966
- }, x = (h, f) => {
967
- h ? i.setSelected(h, f) : i.clear();
968
- }, v = (h) => {
969
- i.clear(), i.setUserSelectAction(h);
969
+ o.bulkAddAnnotation(h, d, M.REMOTE);
970
+ }, x = (h, d) => {
971
+ h ? i.setSelected(h, d) : i.clear();
970
972
  }, b = (h) => {
973
+ i.clear(), i.setUserSelectAction(h);
974
+ }, v = (h) => {
971
975
  if (n) {
972
- const f = n.parse(h).parsed, y = n.serialize(o.getAnnotation(f.id));
973
- return o.updateAnnotation(f), y;
976
+ const d = n.parse(h).parsed, y = n.serialize(o.getAnnotation(d.id));
977
+ return o.updateAnnotation(d), y;
974
978
  } else {
975
- const f = o.getAnnotation(h.id);
976
- return o.updateAnnotation(h), f;
979
+ const d = o.getAnnotation(h.id);
980
+ return o.updateAnnotation(h), d;
977
981
  }
978
982
  };
979
983
  return {
@@ -983,16 +987,16 @@ const hn = 250, pn = (t) => {
983
987
  canUndo: e.canUndo,
984
988
  clearAnnotations: s,
985
989
  getAnnotationById: l,
986
- getAnnotations: u,
990
+ getAnnotations: f,
987
991
  getSelected: g,
988
992
  loadAnnotations: c,
989
993
  redo: e.redo,
990
994
  removeAnnotation: p,
991
- setAnnotations: d,
995
+ setAnnotations: u,
992
996
  setSelected: x,
993
- setUserSelectAction: v,
997
+ setUserSelectAction: b,
994
998
  undo: e.undo,
995
- updateAnnotation: b
999
+ updateAnnotation: v
996
1000
  };
997
1001
  }, wn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
998
1002
  let vn = (t) => crypto.getRandomValues(new Uint8Array(t)), xn = (t, e, n) => {
@@ -1019,15 +1023,15 @@ const Sn = () => ({ isGuest: !0, id: An("1234567890abcdefghijklmnopqrstuvwxyzABC
1019
1023
  n = (n << 5) - n + r, n |= 0;
1020
1024
  }
1021
1025
  return `${n}`;
1022
- }, le = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Ln = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1023
- const { id: o, type: i, purpose: r, value: a, created: s, modified: l, creator: u, ...g } = n;
1026
+ }, de = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Ln = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
1027
+ const { id: o, type: i, purpose: r, value: a, created: s, modified: l, creator: f, ...g } = n;
1024
1028
  return {
1025
1029
  id: o || `temp-${Cn(n)}`,
1026
1030
  annotation: e,
1027
1031
  type: i,
1028
1032
  purpose: r,
1029
1033
  value: a,
1030
- creator: le(u),
1034
+ creator: de(f),
1031
1035
  created: s ? new Date(s) : void 0,
1032
1036
  updated: l ? new Date(l) : void 0,
1033
1037
  ...g
@@ -1042,7 +1046,7 @@ const Sn = () => ({ isGuest: !0, id: An("1234567890abcdefghijklmnopqrstuvwxyzABC
1042
1046
  return (n = s.id) != null && n.startsWith("temp-") && delete s.id, s;
1043
1047
  });
1044
1048
  En();
1045
- const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1049
+ const ue = "not-annotatable", H = `.${ue}`, Tn = (t) => {
1046
1050
  var n;
1047
1051
  const e = t.commonAncestorContainer;
1048
1052
  return e instanceof HTMLElement ? !e.closest(H) : !((n = e.parentElement) != null && n.closest(H));
@@ -1050,7 +1054,7 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1050
1054
  const e = document.createNodeIterator(
1051
1055
  t.commonAncestorContainer,
1052
1056
  NodeFilter.SHOW_ELEMENT,
1053
- (o) => o instanceof HTMLElement && o.classList.contains(de) && !o.parentElement.closest(H) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
1057
+ (o) => o instanceof HTMLElement && o.classList.contains(ue) && !o.parentElement.closest(H) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
1054
1058
  );
1055
1059
  let n;
1056
1060
  for (; n = e.nextNode(); )
@@ -1068,7 +1072,7 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1068
1072
  o.setStartAfter(n), o.collapsed || e.push(o);
1069
1073
  }
1070
1074
  return e.length > 0 ? e : [t];
1071
- }, Mt = (t) => {
1075
+ }, kt = (t) => {
1072
1076
  const e = t.cloneContents();
1073
1077
  return e.querySelectorAll(H).forEach((n) => n.remove()), e;
1074
1078
  }, Mn = (t) => t.addEventListener("click", (e) => {
@@ -1079,7 +1083,7 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1079
1083
  }, So = (t) => {
1080
1084
  const e = t.cloneContents();
1081
1085
  return e.querySelectorAll(H).forEach((n) => n.remove()), e;
1082
- }, Qt = (t, e) => {
1086
+ }, Jt = (t, e) => {
1083
1087
  const n = document.createNodeIterator(e);
1084
1088
  let o = 0, i = n.nextNode();
1085
1089
  for (; i !== null; ) {
@@ -1087,7 +1091,7 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1087
1091
  return o;
1088
1092
  o += 1, i = n.nextNode();
1089
1093
  }
1090
- }, Jt = (t, e) => {
1094
+ }, Zt = (t, e) => {
1091
1095
  const n = document.createNodeIterator(e);
1092
1096
  let o = null;
1093
1097
  for (let i = 0; i < t + 1; i++)
@@ -1103,11 +1107,11 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1103
1107
  } = t, a = Array.from(e.childNodes).map((c) => {
1104
1108
  const p = c.cloneNode(!0);
1105
1109
  return c.nodeName === "CANVAS" ? c : p;
1106
- }), s = Qt(n, e), l = Qt(i, e), u = () => {
1110
+ }), s = Jt(n, e), l = Jt(i, e), f = () => {
1107
1111
  const c = e;
1108
1112
  c.replaceChildren(...a);
1109
- const p = Jt(s, c), d = Jt(l, c);
1110
- return t.setStart(p, o), t.setEnd(d, r), t;
1113
+ const p = Zt(s, c), u = Zt(l, c);
1114
+ return t.setStart(p, o), t.setEnd(u, r), t;
1111
1115
  }, g = (c) => {
1112
1116
  const p = document.createElement("SPAN");
1113
1117
  return c.surroundContents(p), p;
@@ -1117,14 +1121,14 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1117
1121
  {
1118
1122
  const c = document.createRange();
1119
1123
  c.selectNodeContents(n), c.setStart(n, o);
1120
- const p = g(c), d = document.createRange();
1121
- d.selectNode(i), d.setEnd(i, r);
1122
- const x = g(d), b = In(t).reverse().map((h) => {
1124
+ const p = g(c), u = document.createRange();
1125
+ u.selectNode(i), u.setEnd(i, r);
1126
+ const x = g(u), v = In(t).reverse().map((h) => {
1123
1127
  var y;
1124
- const f = document.createElement("SPAN");
1125
- return (y = h.parentNode) == null || y.insertBefore(f, h), f.appendChild(h), f;
1128
+ const d = document.createElement("SPAN");
1129
+ return (y = h.parentNode) == null || y.insertBefore(d, h), d.appendChild(h), d;
1126
1130
  });
1127
- return { unwrap: u, nodes: [p, ...b, x] };
1131
+ return { unwrap: f, nodes: [p, ...v, x] };
1128
1132
  }
1129
1133
  }, In = (t) => {
1130
1134
  const {
@@ -1148,9 +1152,9 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1148
1152
  }, _n = (t, e, n = 10, o) => {
1149
1153
  const i = o ? t.startContainer.parentElement.closest(o) : e, r = document.createRange();
1150
1154
  r.setStart(i, 0), r.setEnd(t.startContainer, t.startOffset);
1151
- const a = Mt(r).textContent, s = document.createRange();
1155
+ const a = kt(r).textContent, s = document.createRange();
1152
1156
  s.setStart(t.endContainer, t.endOffset), i === document.body ? s.setEnd(i, i.childNodes.length) : s.setEndAfter(i);
1153
- const l = Mt(s).textContent;
1157
+ const l = kt(s).textContent;
1154
1158
  return {
1155
1159
  prefix: a.substring(a.length - n),
1156
1160
  suffix: l.substring(0, n)
@@ -1179,17 +1183,17 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1179
1183
  return "block-contains";
1180
1184
  } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
1181
1185
  return "block-is-contained";
1182
- }, Yn = (t, e) => {
1186
+ }, Kn = (t, e) => {
1183
1187
  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);
1184
1188
  return new DOMRect(n, i, o - n, r - i);
1185
- }, Kn = (t) => t.reduce((e, n) => {
1189
+ }, Yn = (t) => t.reduce((e, n) => {
1186
1190
  if (n.width === 0 || n.height === 0)
1187
1191
  return e;
1188
1192
  let o = [...e], i = !1;
1189
1193
  for (const r of e) {
1190
1194
  const a = Dn(n, r);
1191
1195
  if (a === "inline-adjacent") {
1192
- o = o.map((s) => s === r ? Yn(n, r) : s), i = !0;
1196
+ o = o.map((s) => s === r ? Kn(n, r) : s), i = !0;
1193
1197
  break;
1194
1198
  } else if (a === "inline-contains") {
1195
1199
  o = o.map((s) => s === r ? n : s), i = !0;
@@ -1213,25 +1217,25 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1213
1217
  }), Xn = (t, e, n) => {
1214
1218
  const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
1215
1219
  o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
1216
- const r = Mt(o).textContent, a = t.toString(), s = r.length || 0, l = s + a.length;
1220
+ const r = kt(o).textContent, a = t.toString(), s = r.length || 0, l = s + a.length;
1217
1221
  return n ? { quote: a, start: s, end: l, range: t, offsetReference: i } : { quote: a, start: s, end: l, range: t };
1218
- }, ue = (t, e) => {
1222
+ }, fe = (t, e) => {
1219
1223
  var g, c;
1220
1224
  const { start: n, end: o } = t, i = t.offsetReference || e, r = document.createNodeIterator(
1221
1225
  e,
1222
1226
  NodeFilter.SHOW_TEXT,
1223
1227
  (p) => {
1224
- var d;
1225
- return (d = p.parentElement) != null && d.closest(H) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
1228
+ var u;
1229
+ return (u = p.parentElement) != null && u.closest(H) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
1226
1230
  }
1227
1231
  );
1228
1232
  let a = 0;
1229
1233
  const s = document.createRange();
1230
1234
  let l = r.nextNode();
1231
1235
  l === null && console.error("Could not revive annotation target. Content missing.");
1232
- let u = !i;
1236
+ let f = !i;
1233
1237
  for (; l !== null; ) {
1234
- if (u || (u = i == null ? void 0 : i.contains(l)), u) {
1238
+ if (f || (f = i == null ? void 0 : i.contains(l)), f) {
1235
1239
  const p = ((g = l.textContent) == null ? void 0 : g.length) || 0;
1236
1240
  if (a + p > n) {
1237
1241
  s.setStart(l, n - a);
@@ -1253,10 +1257,10 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1253
1257
  ...t,
1254
1258
  range: s
1255
1259
  };
1256
- }, mt = (t, e) => W(t.selector) ? t : {
1260
+ }, yt = (t, e) => W(t.selector) ? t : {
1257
1261
  ...t,
1258
- selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : ue(n, e))
1259
- }, St = (t, e) => W(t.target.selector) ? t : { ...t, target: mt(t.target, e) }, Pn = (t, e) => {
1262
+ selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : fe(n, e))
1263
+ }, Ct = (t, e) => W(t.target.selector) ? t : { ...t, target: yt(t.target, e) }, Pn = (t, e) => {
1260
1264
  const n = t.cloneRange();
1261
1265
  return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
1262
1266
  }, $n = (t, e) => {
@@ -1321,7 +1325,7 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1321
1325
  if (a.length === 0)
1322
1326
  return { error: Error(`No targets found for annotation: ${t.id}`) };
1323
1327
  const s = {
1324
- creator: le(n),
1328
+ creator: de(n),
1325
1329
  created: o ? new Date(o) : void 0,
1326
1330
  updated: i ? new Date(i) : void 0,
1327
1331
  annotation: e,
@@ -1352,7 +1356,7 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1352
1356
  }
1353
1357
  return { parsed: s };
1354
1358
  }, Wn = (t) => {
1355
- const e = t.id || ae(), {
1359
+ const e = t.id || ce(), {
1356
1360
  creator: n,
1357
1361
  created: o,
1358
1362
  modified: i,
@@ -1372,18 +1376,18 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1372
1376
  selector: a,
1373
1377
  creator: s,
1374
1378
  created: l,
1375
- updated: u,
1379
+ updated: f,
1376
1380
  ...g
1377
1381
  } = i, c = a.map((p) => {
1378
- const { quote: d, start: x, end: v, range: b } = p, { prefix: h, suffix: f } = _n(b, n), y = [{
1382
+ const { quote: u, start: x, end: b, range: v } = p, { prefix: h, suffix: d } = _n(v, n), y = [{
1379
1383
  type: "TextQuoteSelector",
1380
- exact: d,
1384
+ exact: u,
1381
1385
  prefix: h,
1382
- suffix: f
1386
+ suffix: d
1383
1387
  }, {
1384
1388
  type: "TextPositionSelector",
1385
1389
  start: x,
1386
- end: v
1390
+ end: b
1387
1391
  }];
1388
1392
  return {
1389
1393
  ...g,
@@ -1400,15 +1404,15 @@ const de = "not-annotatable", H = `.${de}`, Tn = (t) => {
1400
1404
  body: On(t.bodies),
1401
1405
  creator: s,
1402
1406
  created: l == null ? void 0 : l.toISOString(),
1403
- modified: u == null ? void 0 : u.toISOString(),
1407
+ modified: f == null ? void 0 : f.toISOString(),
1404
1408
  target: c
1405
1409
  };
1406
1410
  };
1407
- function fe(t, e, n = 0, o = t.length - 1, i = Gn) {
1411
+ function he(t, e, n = 0, o = t.length - 1, i = Gn) {
1408
1412
  for (; o > n; ) {
1409
1413
  if (o - n > 600) {
1410
- const l = o - n + 1, u = e - n + 1, g = Math.log(l), c = 0.5 * Math.exp(2 * g / 3), p = 0.5 * Math.sqrt(g * c * (l - c) / l) * (u - l / 2 < 0 ? -1 : 1), d = Math.max(n, Math.floor(e - u * c / l + p)), x = Math.min(o, Math.floor(e + (l - u) * c / l + p));
1411
- fe(t, e, d, x, i);
1414
+ const l = o - n + 1, f = e - n + 1, g = Math.log(l), c = 0.5 * Math.exp(2 * g / 3), p = 0.5 * Math.sqrt(g * c * (l - c) / l) * (f - l / 2 < 0 ? -1 : 1), u = Math.max(n, Math.floor(e - f * c / l + p)), x = Math.min(o, Math.floor(e + (l - f) * c / l + p));
1415
+ he(t, e, u, x, i);
1412
1416
  }
1413
1417
  const r = t[e];
1414
1418
  let a = n, s = o;
@@ -1436,12 +1440,12 @@ class Qn {
1436
1440
  search(e) {
1437
1441
  let n = this.data;
1438
1442
  const o = [];
1439
- if (!ht(e, n)) return o;
1443
+ if (!pt(e, n)) return o;
1440
1444
  const i = this.toBBox, r = [];
1441
1445
  for (; n; ) {
1442
1446
  for (let a = 0; a < n.children.length; a++) {
1443
1447
  const s = n.children[a], l = n.leaf ? i(s) : s;
1444
- ht(e, l) && (n.leaf ? o.push(s) : Lt(e, l) ? this._all(s, o) : r.push(s));
1448
+ pt(e, l) && (n.leaf ? o.push(s) : Ot(e, l) ? this._all(s, o) : r.push(s));
1445
1449
  }
1446
1450
  n = r.pop();
1447
1451
  }
@@ -1449,13 +1453,13 @@ class Qn {
1449
1453
  }
1450
1454
  collides(e) {
1451
1455
  let n = this.data;
1452
- if (!ht(e, n)) return !1;
1456
+ if (!pt(e, n)) return !1;
1453
1457
  const o = [];
1454
1458
  for (; n; ) {
1455
1459
  for (let i = 0; i < n.children.length; i++) {
1456
1460
  const r = n.children[i], a = n.leaf ? this.toBBox(r) : r;
1457
- if (ht(e, a)) {
1458
- if (n.leaf || Lt(e, a)) return !0;
1461
+ if (pt(e, a)) {
1462
+ if (n.leaf || Ot(e, a)) return !0;
1459
1463
  o.push(r);
1460
1464
  }
1461
1465
  }
@@ -1494,14 +1498,14 @@ class Qn {
1494
1498
  if (!e) return this;
1495
1499
  let o = this.data;
1496
1500
  const i = this.toBBox(e), r = [], a = [];
1497
- let s, l, u;
1501
+ let s, l, f;
1498
1502
  for (; o || r.length; ) {
1499
- if (o || (o = r.pop(), l = r[r.length - 1], s = a.pop(), u = !0), o.leaf) {
1503
+ if (o || (o = r.pop(), l = r[r.length - 1], s = a.pop(), f = !0), o.leaf) {
1500
1504
  const g = Jn(e, o.children, n);
1501
1505
  if (g !== -1)
1502
1506
  return o.children.splice(g, 1), r.push(o), this._condense(r), this;
1503
1507
  }
1504
- !u && !o.leaf && Lt(o, i) ? (r.push(o), a.push(s), s = 0, l = o, o = o.children[0]) : l ? (s++, o = l.children[s], u = !1) : o = null;
1508
+ !f && !o.leaf && Ot(o, i) ? (r.push(o), a.push(s), s = 0, l = o, o = o.children[0]) : l ? (s++, o = l.children[s], f = !1) : o = null;
1505
1509
  }
1506
1510
  return this;
1507
1511
  }
@@ -1532,14 +1536,14 @@ class Qn {
1532
1536
  if (r <= a)
1533
1537
  return s = J(e.slice(n, o + 1)), Q(s, this.toBBox), s;
1534
1538
  i || (i = Math.ceil(Math.log(r) / Math.log(a)), a = Math.ceil(r / Math.pow(a, i - 1))), s = J([]), s.leaf = !1, s.height = i;
1535
- const l = Math.ceil(r / a), u = l * Math.ceil(Math.sqrt(a));
1536
- Zt(e, n, o, u, this.compareMinX);
1537
- for (let g = n; g <= o; g += u) {
1538
- const c = Math.min(g + u - 1, o);
1539
- Zt(e, g, c, l, this.compareMinY);
1539
+ const l = Math.ceil(r / a), f = l * Math.ceil(Math.sqrt(a));
1540
+ te(e, n, o, f, this.compareMinX);
1541
+ for (let g = n; g <= o; g += f) {
1542
+ const c = Math.min(g + f - 1, o);
1543
+ te(e, g, c, l, this.compareMinY);
1540
1544
  for (let p = g; p <= c; p += l) {
1541
- const d = Math.min(p + l - 1, c);
1542
- s.children.push(this._build(e, p, d, i - 1));
1545
+ const u = Math.min(p + l - 1, c);
1546
+ s.children.push(this._build(e, p, u, i - 1));
1543
1547
  }
1544
1548
  }
1545
1549
  return Q(s, this.toBBox), s;
@@ -1548,8 +1552,8 @@ class Qn {
1548
1552
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
1549
1553
  let r = 1 / 0, a = 1 / 0, s;
1550
1554
  for (let l = 0; l < n.children.length; l++) {
1551
- const u = n.children[l], g = Ct(u), c = eo(e, u) - g;
1552
- c < a ? (a = c, r = g < r ? g : r, s = u) : c === a && g < r && (r = g, s = u);
1555
+ const f = n.children[l], g = Lt(f), c = eo(e, f) - g;
1556
+ c < a ? (a = c, r = g < r ? g : r, s = f) : c === a && g < r && (r = g, s = f);
1553
1557
  }
1554
1558
  n = s || n.children[0];
1555
1559
  }
@@ -1574,7 +1578,7 @@ class Qn {
1574
1578
  _chooseSplitIndex(e, n, o) {
1575
1579
  let i, r = 1 / 0, a = 1 / 0;
1576
1580
  for (let s = n; s <= o - n; s++) {
1577
- const l = nt(e, 0, s, this.toBBox), u = nt(e, s, o, this.toBBox), g = no(l, u), c = Ct(l) + Ct(u);
1581
+ const l = nt(e, 0, s, this.toBBox), f = nt(e, s, o, this.toBBox), g = no(l, f), c = Lt(l) + Lt(f);
1578
1582
  g < r ? (r = g, i = s, a = c < a ? c : a) : g === r && c < a && (a = c, i = s);
1579
1583
  }
1580
1584
  return i || o - n;
@@ -1588,14 +1592,14 @@ class Qn {
1588
1592
  _allDistMargin(e, n, o, i) {
1589
1593
  e.children.sort(i);
1590
1594
  const r = this.toBBox, a = nt(e, 0, n, r), s = nt(e, o - n, o, r);
1591
- let l = ft(a) + ft(s);
1592
- for (let u = n; u < o - n; u++) {
1593
- const g = e.children[u];
1594
- ot(a, e.leaf ? r(g) : g), l += ft(a);
1595
+ let l = ht(a) + ht(s);
1596
+ for (let f = n; f < o - n; f++) {
1597
+ const g = e.children[f];
1598
+ ot(a, e.leaf ? r(g) : g), l += ht(a);
1595
1599
  }
1596
- for (let u = o - n - 1; u >= n; u--) {
1597
- const g = e.children[u];
1598
- ot(s, e.leaf ? r(g) : g), l += ft(s);
1600
+ for (let f = o - n - 1; f >= n; f--) {
1601
+ const g = e.children[f];
1602
+ ot(s, e.leaf ? r(g) : g), l += ht(s);
1599
1603
  }
1600
1604
  return l;
1601
1605
  }
@@ -1634,10 +1638,10 @@ function Zn(t, e) {
1634
1638
  function to(t, e) {
1635
1639
  return t.minY - e.minY;
1636
1640
  }
1637
- function Ct(t) {
1641
+ function Lt(t) {
1638
1642
  return (t.maxX - t.minX) * (t.maxY - t.minY);
1639
1643
  }
1640
- function ft(t) {
1644
+ function ht(t) {
1641
1645
  return t.maxX - t.minX + (t.maxY - t.minY);
1642
1646
  }
1643
1647
  function eo(t, e) {
@@ -1647,10 +1651,10 @@ function no(t, e) {
1647
1651
  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);
1648
1652
  return Math.max(0, i - n) * Math.max(0, r - o);
1649
1653
  }
1650
- function Lt(t, e) {
1654
+ function Ot(t, e) {
1651
1655
  return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
1652
1656
  }
1653
- function ht(t, e) {
1657
+ function pt(t, e) {
1654
1658
  return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
1655
1659
  }
1656
1660
  function J(t) {
@@ -1664,12 +1668,12 @@ function J(t) {
1664
1668
  maxY: -1 / 0
1665
1669
  };
1666
1670
  }
1667
- function Zt(t, e, n, o, i) {
1671
+ function te(t, e, n, o, i) {
1668
1672
  const r = [e, n];
1669
1673
  for (; r.length; ) {
1670
1674
  if (n = r.pop(), e = r.pop(), n - e <= o) continue;
1671
1675
  const a = e + Math.ceil((n - e) / o / 2) * o;
1672
- fe(t, a, e, n, i), r.push(e, a, a, n);
1676
+ he(t, a, e, n, i), r.push(e, a, a, n);
1673
1677
  }
1674
1678
  }
1675
1679
  let oo = () => ({
@@ -1687,132 +1691,132 @@ let oo = () => ({
1687
1691
  }
1688
1692
  });
1689
1693
  const io = (t, e) => {
1690
- const n = new Qn(), o = /* @__PURE__ */ new Map(), i = oo(), r = (y, E) => {
1691
- const w = y.selector.flatMap((B) => {
1692
- const L = W([B]) ? B.range : ue(B, e).range;
1693
- return Array.from(L.getClientRects());
1694
- }), O = Kn(w).map((B) => $n(B, E));
1695
- return O.map((B) => {
1696
- const { x: L, y: T, width: m, height: A } = B;
1694
+ const n = new Qn(), o = /* @__PURE__ */ new Map(), i = oo(), r = (y, A) => {
1695
+ const C = y.selector.flatMap((R) => {
1696
+ const O = W([R]) ? R.range : fe(R, e).range;
1697
+ return Array.from(O.getClientRects());
1698
+ }), S = Yn(C).map((R) => $n(R, A));
1699
+ return S.map((R) => {
1700
+ const { x: O, y: B, width: m, height: w } = R;
1697
1701
  return {
1698
- minX: L,
1699
- minY: T,
1700
- maxX: L + m,
1701
- maxY: T + A,
1702
+ minX: O,
1703
+ minY: B,
1704
+ maxX: O + m,
1705
+ maxY: B + w,
1702
1706
  annotation: {
1703
1707
  id: y.annotation,
1704
- rects: O
1708
+ rects: S
1705
1709
  }
1706
1710
  };
1707
1711
  });
1708
1712
  }, a = () => [...o.values()], s = () => {
1709
1713
  n.clear(), o.clear();
1710
1714
  }, l = (y) => {
1711
- const E = r(y, e.getBoundingClientRect());
1712
- E.forEach((w) => n.insert(w)), o.set(y.annotation, E);
1713
- }, u = (y) => {
1714
- const E = o.get(y.annotation);
1715
- E && (E.forEach((w) => n.remove(w)), o.delete(y.annotation));
1715
+ const A = r(y, e.getBoundingClientRect());
1716
+ A.forEach((C) => n.insert(C)), o.set(y.annotation, A);
1717
+ }, f = (y) => {
1718
+ const A = o.get(y.annotation);
1719
+ A && (A.forEach((C) => n.remove(C)), o.delete(y.annotation));
1716
1720
  }, g = (y) => {
1717
- u(y), l(y);
1718
- }, c = (y, E = !0) => {
1719
- E && s();
1720
- const w = e.getBoundingClientRect(), O = y.map((L) => ({ target: L, rects: r(L, w) }));
1721
- O.forEach(({ target: L, rects: T }) => o.set(L.annotation, T));
1722
- const B = O.flatMap(({ rects: L }) => L);
1723
- n.load(B);
1724
- }, p = (y, E, w = !1) => {
1725
- const O = n.search({
1721
+ f(y), l(y);
1722
+ }, c = (y, A = !0) => {
1723
+ A && s();
1724
+ const C = e.getBoundingClientRect(), S = y.map((O) => ({ target: O, rects: r(O, C) }));
1725
+ S.forEach(({ target: O, rects: B }) => o.set(O.annotation, B));
1726
+ const R = S.flatMap(({ rects: O }) => O);
1727
+ n.load(R);
1728
+ }, p = (y, A, C = !1) => {
1729
+ const S = n.search({
1726
1730
  minX: y,
1727
- minY: E,
1731
+ minY: A,
1728
1732
  maxX: y,
1729
- maxY: E
1730
- }), B = (L) => L.annotation.rects.reduce((T, m) => T + m.width * m.height, 0);
1731
- return O.length > 0 ? (O.sort((L, T) => B(L) - B(T)), w ? O.map((L) => L.annotation.id) : [O[0].annotation.id]) : [];
1732
- }, d = (y) => {
1733
- const E = x(y);
1734
- if (E.length === 0)
1733
+ maxY: A
1734
+ }), R = (O) => O.annotation.rects.reduce((B, m) => B + m.width * m.height, 0);
1735
+ return S.length > 0 ? (S.sort((O, B) => R(O) - R(B)), C ? S.map((O) => O.annotation.id) : [S[0].annotation.id]) : [];
1736
+ }, u = (y) => {
1737
+ const A = x(y);
1738
+ if (A.length === 0)
1735
1739
  return;
1736
- let w = E[0].left, O = E[0].top, B = E[0].right, L = E[0].bottom;
1737
- for (let T = 1; T < E.length; T++) {
1738
- const m = E[T];
1739
- w = Math.min(w, m.left), O = Math.min(O, m.top), B = Math.max(B, m.right), L = Math.max(L, m.bottom);
1740
+ let C = A[0].left, S = A[0].top, R = A[0].right, O = A[0].bottom;
1741
+ for (let B = 1; B < A.length; B++) {
1742
+ const m = A[B];
1743
+ C = Math.min(C, m.left), S = Math.min(S, m.top), R = Math.max(R, m.right), O = Math.max(O, m.bottom);
1740
1744
  }
1741
- return new DOMRect(w, O, B - w, L - O);
1745
+ return new DOMRect(C, S, R - C, O - S);
1742
1746
  }, x = (y) => {
1743
- const E = o.get(y);
1744
- return E ? E[0].annotation.rects : [];
1747
+ const A = o.get(y);
1748
+ return A ? A[0].annotation.rects : [];
1745
1749
  };
1746
1750
  return {
1747
1751
  all: a,
1748
1752
  clear: s,
1749
1753
  getAt: p,
1750
- getAnnotationBounds: d,
1754
+ getAnnotationBounds: u,
1751
1755
  getAnnotationRects: x,
1752
- getIntersecting: (y, E, w, O) => {
1753
- const B = n.search({ minX: y, minY: E, maxX: w, maxY: O }), L = new Set(B.map((T) => T.annotation.id));
1754
- return Array.from(L).map((T) => ({
1755
- annotation: t.getAnnotation(T),
1756
- rects: x(T)
1757
- })).filter((T) => !!T.annotation);
1756
+ getIntersecting: (y, A, C, S) => {
1757
+ const R = n.search({ minX: y, minY: A, maxX: C, maxY: S }), O = new Set(R.map((B) => B.annotation.id));
1758
+ return Array.from(O).map((B) => ({
1759
+ annotation: t.getAnnotation(B),
1760
+ rects: x(B)
1761
+ })).filter((B) => !!B.annotation);
1758
1762
  },
1759
1763
  insert: l,
1760
1764
  recalculate: () => {
1761
1765
  c(t.all().map((y) => y.target), !0), i.emit("recalculate");
1762
1766
  },
1763
- remove: u,
1767
+ remove: f,
1764
1768
  set: c,
1765
1769
  size: () => n.all().length,
1766
1770
  update: g,
1767
- on: (y, E) => i.on(y, E)
1771
+ on: (y, A) => i.on(y, A)
1768
1772
  };
1769
1773
  }, ro = (t, e) => {
1770
- const n = un(), o = io(n, t), i = Qe(n, e), r = qe(n), a = gn(), s = (b, h = M.LOCAL) => {
1771
- const f = St(b, t), y = W(f.target.selector);
1772
- return y && n.addAnnotation(f, h), y;
1773
- }, l = (b, h = !0, f = M.LOCAL) => {
1774
- const y = b.map((w) => St(w, t)), E = y.filter((w) => !W(w.target.selector));
1775
- return E.length > 0 ? (console.warn("Could not revive all targets for these annotations:", E), n.bulkAddAnnotation(y, h, f), E) : (n.bulkAddAnnotation(y, h, f), []);
1776
- }, u = (b, h = M.LOCAL) => {
1777
- const f = b.map((E) => St(E, t)), y = f.filter((E) => !W(E.target.selector));
1778
- return y.length > 0 && console.warn("Could not revive all targets for these annotations:", y), f.forEach((E) => {
1779
- n.getAnnotation(E.id) ? n.updateAnnotation(E, h) : n.addAnnotation(E, h);
1774
+ const n = un(), o = io(n, t), i = Qe(n, e), r = qe(n), a = gn(), s = (v, h = M.LOCAL) => {
1775
+ const d = Ct(v, t), y = W(d.target.selector);
1776
+ return y && n.addAnnotation(d, h), y;
1777
+ }, l = (v, h = !0, d = M.LOCAL) => {
1778
+ const y = v.map((C) => Ct(C, t)), A = y.filter((C) => !W(C.target.selector));
1779
+ return A.length > 0 ? (console.warn("Could not revive all targets for these annotations:", A), n.bulkAddAnnotation(y, h, d), A) : (n.bulkAddAnnotation(y, h, d), []);
1780
+ }, f = (v, h = M.LOCAL) => {
1781
+ const d = v.map((A) => Ct(A, t)), y = d.filter((A) => !W(A.target.selector));
1782
+ return y.length > 0 && console.warn("Could not revive all targets for these annotations:", y), d.forEach((A) => {
1783
+ n.getAnnotation(A.id) ? n.updateAnnotation(A, h) : n.addAnnotation(A, h);
1780
1784
  }), y;
1781
- }, g = (b, h = M.LOCAL) => {
1782
- const f = mt(b, t);
1783
- n.updateTarget(f, h);
1784
- }, c = (b, h = M.LOCAL) => {
1785
- const f = b.map((y) => mt(y, t));
1786
- n.bulkUpdateTargets(f, h);
1787
- }, p = (b, h, f) => {
1788
- const y = o.getAt(b, h, !!f).map((w) => n.getAnnotation(w)), E = f ? y.filter(f) : y;
1789
- return E.length > 0 ? E[0] : void 0;
1790
- }, d = (b, h, f, y = 5) => {
1791
- const E = o.getAnnotationRects(b);
1792
- if (E.length !== 0) {
1793
- if (h && f) {
1794
- const w = E.find(({ top: O, right: B, bottom: L, left: T }) => h >= T - y && h <= B + y && f >= O - y && f <= L + y);
1795
- if (w) return w;
1785
+ }, g = (v, h = M.LOCAL) => {
1786
+ const d = yt(v, t);
1787
+ n.updateTarget(d, h);
1788
+ }, c = (v, h = M.LOCAL) => {
1789
+ const d = v.map((y) => yt(y, t));
1790
+ n.bulkUpdateTargets(d, h);
1791
+ }, p = (v, h, d) => {
1792
+ const y = o.getAt(v, h, !!d).map((C) => n.getAnnotation(C)), A = d ? y.filter(d) : y;
1793
+ return A.length > 0 ? A[0] : void 0;
1794
+ }, u = (v, h, d, y = 5) => {
1795
+ const A = o.getAnnotationRects(v);
1796
+ if (A.length !== 0) {
1797
+ if (h && d) {
1798
+ const C = A.find(({ top: S, right: R, bottom: O, left: B }) => h >= B - y && h <= R + y && d >= S - y && d <= O + y);
1799
+ if (C) return C;
1796
1800
  }
1797
- return o.getAnnotationBounds(b);
1801
+ return o.getAnnotationBounds(v);
1798
1802
  }
1799
- }, x = () => o.recalculate(), v = (b) => o.on("recalculate", b);
1800
- return n.observe(({ changes: b }) => {
1801
- const h = (b.deleted || []).filter((E) => W(E.target.selector)), f = (b.created || []).filter((E) => W(E.target.selector)), y = (b.updated || []).filter((E) => W(E.newValue.target.selector));
1802
- (h == null ? void 0 : h.length) > 0 && h.forEach((E) => o.remove(E.target)), f.length > 0 && o.set(f.map((E) => E.target), !1), (y == null ? void 0 : y.length) > 0 && y.forEach(({ newValue: E }) => o.update(E.target));
1803
+ }, x = () => o.recalculate(), b = (v) => o.on("recalculate", v);
1804
+ return n.observe(({ changes: v }) => {
1805
+ const h = (v.deleted || []).filter((A) => W(A.target.selector)), d = (v.created || []).filter((A) => W(A.target.selector)), y = (v.updated || []).filter((A) => W(A.newValue.target.selector));
1806
+ (h == null ? void 0 : h.length) > 0 && h.forEach((A) => o.remove(A.target)), d.length > 0 && o.set(d.map((A) => A.target), !1), (y == null ? void 0 : y.length) > 0 && y.forEach(({ newValue: A }) => o.update(A.target));
1803
1807
  }), {
1804
1808
  store: {
1805
1809
  ...n,
1806
1810
  addAnnotation: s,
1807
1811
  bulkAddAnnotation: l,
1808
1812
  bulkUpdateTargets: c,
1809
- bulkUpsertAnnotations: u,
1810
- getAnnotationBounds: d,
1813
+ bulkUpsertAnnotations: f,
1814
+ getAnnotationBounds: u,
1811
1815
  getAt: p,
1812
1816
  getIntersecting: o.getIntersecting.bind(o),
1813
1817
  getAnnotationRects: o.getAnnotationRects.bind(o),
1814
1818
  recalculatePositions: x,
1815
- onRecalculatePositions: v,
1819
+ onRecalculatePositions: b,
1816
1820
  updateTarget: g
1817
1821
  },
1818
1822
  selection: i,
@@ -1827,7 +1831,7 @@ const io = (t, e) => {
1827
1831
  }, ao = (t, e, n = {}) => {
1828
1832
  const o = so(), i = o.getContext("2d");
1829
1833
  document.body.appendChild(o);
1830
- const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([p, d]) => d.presenceKey === c.presenceKey).map(([p, d]) => p);
1834
+ const r = /* @__PURE__ */ new Map(), a = (c) => Array.from(r.entries()).filter(([p, u]) => u.presenceKey === c.presenceKey).map(([p, u]) => p);
1831
1835
  return e.on("selectionChange", (c, p) => {
1832
1836
  a(c).forEach((x) => r.delete(x)), p && p.forEach((x) => r.set(x, c));
1833
1837
  }), {
@@ -1838,16 +1842,16 @@ const io = (t, e) => {
1838
1842
  destroy: () => {
1839
1843
  o.remove();
1840
1844
  },
1841
- paint: (c, p, d) => {
1845
+ paint: (c, p, u) => {
1842
1846
  n.font && (i.font = n.font);
1843
1847
  const x = r.get(c.annotation.id);
1844
1848
  if (x) {
1845
- const { height: v } = c.rects[0], b = c.rects[0].x + p.left, h = c.rects[0].y + p.top;
1846
- i.fillStyle = x.appearance.color, i.fillRect(b - 2, h - 2.5, 2, v + 5);
1847
- const f = i.measureText(x.appearance.label), y = f.width + 6, E = f.actualBoundingBoxAscent + f.actualBoundingBoxDescent + 8, w = f.fontBoundingBoxAscent ? 8 : 6.5;
1848
- return i.fillRect(b - 2, h - 2.5 - E, y, E), i.fillStyle = "#fff", i.fillText(x.appearance.label, b + 1, h - w), {
1849
+ const { height: b } = c.rects[0], v = c.rects[0].x + p.left, h = c.rects[0].y + p.top;
1850
+ i.fillStyle = x.appearance.color, i.fillRect(v - 2, h - 2.5, 2, b + 5);
1851
+ const d = i.measureText(x.appearance.label), y = d.width + 6, A = d.actualBoundingBoxAscent + d.actualBoundingBoxDescent + 8, C = d.fontBoundingBoxAscent ? 8 : 6.5;
1852
+ return i.fillRect(v - 2, h - 2.5 - A, y, A), i.fillStyle = "#fff", i.fillText(x.appearance.label, v + 1, h - C), {
1849
1853
  fill: x.appearance.color,
1850
- fillOpacity: d ? 0.45 : 0.18
1854
+ fillOpacity: u ? 0.45 : 0.18
1851
1855
  };
1852
1856
  }
1853
1857
  },
@@ -1857,23 +1861,23 @@ const io = (t, e) => {
1857
1861
  c.scale(2, 2), c.translate(0.5, 0.5);
1858
1862
  }
1859
1863
  };
1860
- }, he = (t) => {
1864
+ }, pe = (t) => {
1861
1865
  if (t === null)
1862
1866
  return document.scrollingElement;
1863
1867
  const { overflowY: e } = window.getComputedStyle(t);
1864
- return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : he(t.parentElement);
1868
+ return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : pe(t.parentElement);
1865
1869
  }, co = (t, e) => (n) => {
1866
1870
  const o = typeof n == "string" ? n : n.id, i = (a) => {
1867
- const s = r.getBoundingClientRect(), l = r.clientHeight, u = r.clientWidth, g = a.selector[0].range.getBoundingClientRect(), { width: c, height: p } = e.getAnnotationBounds(o), d = g.top - s.top, x = g.left - s.left, v = r.parentElement ? r.scrollTop : 0, b = r.parentElement ? r.scrollLeft : 0, h = d + v - (l - p) / 2, f = x + b - (u - c) / 2;
1868
- r.scroll({ top: h, left: f, behavior: "smooth" });
1869
- }, r = he(t);
1871
+ const s = r.getBoundingClientRect(), l = r.clientHeight, f = r.clientWidth, g = a.selector[0].range.getBoundingClientRect(), { width: c, height: p } = e.getAnnotationBounds(o), u = g.top - s.top, x = g.left - s.left, b = r.parentElement ? r.scrollTop : 0, v = r.parentElement ? r.scrollLeft : 0, h = u + b - (l - p) / 2, d = x + v - (f - c) / 2;
1872
+ r.scroll({ top: h, left: d, behavior: "smooth" });
1873
+ }, r = pe(t);
1870
1874
  if (r) {
1871
1875
  const a = e.getAnnotation(o), { range: s } = a.target.selector[0];
1872
1876
  if (s && !s.collapsed)
1873
1877
  return i(a.target), !0;
1874
1878
  {
1875
- const l = mt(a.target, t), { range: u } = l.selector[0];
1876
- if (u && !u.collapsed)
1879
+ const l = yt(a.target, t), { range: f } = l.selector[0];
1880
+ if (f && !f.collapsed)
1877
1881
  return i(l), !0;
1878
1882
  }
1879
1883
  }
@@ -1882,19 +1886,19 @@ const io = (t, e) => {
1882
1886
  ...t,
1883
1887
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
1884
1888
  user: t.user || e.user
1885
- }), Ot = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1886
- function Tt(t, e, n, o) {
1889
+ }), Tt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
1890
+ function Rt(t, e, n, o) {
1887
1891
  t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
1888
1892
  }
1889
1893
  function et(t, e, n, o) {
1890
1894
  t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
1891
1895
  }
1892
- function pe(t, e) {
1896
+ function ge(t, e) {
1893
1897
  const n = e.slice(0, e.length - 1);
1894
1898
  for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
1895
1899
  return n;
1896
1900
  }
1897
- function ge(t) {
1901
+ function me(t) {
1898
1902
  typeof t != "string" && (t = ""), t = t.replace(/\s/g, "");
1899
1903
  const e = t.split(",");
1900
1904
  let n = e.lastIndexOf("");
@@ -1954,9 +1958,9 @@ const st = {
1954
1958
  ".": 190,
1955
1959
  "/": 191,
1956
1960
  "`": 192,
1957
- "-": Ot ? 173 : 189,
1958
- "=": Ot ? 61 : 187,
1959
- ";": Ot ? 59 : 186,
1961
+ "-": Tt ? 173 : 189,
1962
+ "=": Tt ? 61 : 187,
1963
+ ";": Tt ? 59 : 186,
1960
1964
  "'": 222,
1961
1965
  "[": 219,
1962
1966
  "]": 221,
@@ -1977,7 +1981,7 @@ const st = {
1977
1981
  "⌘": 91,
1978
1982
  cmd: 91,
1979
1983
  command: 91
1980
- }, kt = {
1984
+ }, Nt = {
1981
1985
  16: "shiftKey",
1982
1986
  18: "altKey",
1983
1987
  17: "ctrlKey",
@@ -1994,13 +1998,13 @@ const st = {
1994
1998
  }, I = {};
1995
1999
  for (let t = 1; t < 20; t++)
1996
2000
  st["f".concat(t)] = 111 + t;
1997
- let k = [], rt = null, me = "all";
2001
+ let k = [], rt = null, ye = "all";
1998
2002
  const F = /* @__PURE__ */ new Map(), ct = (t) => st[t.toLowerCase()] || j[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), fo = (t) => Object.keys(st).find((e) => st[e] === t), ho = (t) => Object.keys(j).find((e) => j[e] === t);
1999
- function ye(t) {
2000
- me = t || "all";
2003
+ function be(t) {
2004
+ ye = t || "all";
2001
2005
  }
2002
2006
  function at() {
2003
- return me || "all";
2007
+ return ye || "all";
2004
2008
  }
2005
2009
  function po() {
2006
2010
  return k.slice(0);
@@ -2048,34 +2052,34 @@ function wo(t, e) {
2048
2052
  let {
2049
2053
  element: s
2050
2054
  } = a;
2051
- return Vt(s);
2055
+ return Dt(s);
2052
2056
  }) : o++;
2053
- at() === t && ye(e || "all");
2057
+ at() === t && be(e || "all");
2054
2058
  }
2055
2059
  function vo(t) {
2056
2060
  let e = t.keyCode || t.which || t.charCode;
2057
2061
  const n = k.indexOf(e);
2058
2062
  if (n >= 0 && k.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && k.splice(0, k.length), (e === 93 || e === 224) && (e = 91), e in D) {
2059
2063
  D[e] = !1;
2060
- for (const o in j) j[o] === e && (P[o] = !1);
2064
+ for (const o in j) j[o] === e && (X[o] = !1);
2061
2065
  }
2062
2066
  }
2063
- function be(t) {
2067
+ function we(t) {
2064
2068
  if (typeof t > "u")
2065
2069
  Object.keys(I).forEach((i) => {
2066
- Array.isArray(I[i]) && I[i].forEach((r) => pt(r)), delete I[i];
2067
- }), Vt(null);
2070
+ Array.isArray(I[i]) && I[i].forEach((r) => gt(r)), delete I[i];
2071
+ }), Dt(null);
2068
2072
  else if (Array.isArray(t))
2069
2073
  t.forEach((i) => {
2070
- i.key && pt(i);
2074
+ i.key && gt(i);
2071
2075
  });
2072
2076
  else if (typeof t == "object")
2073
- t.key && pt(t);
2077
+ t.key && gt(t);
2074
2078
  else if (typeof t == "string") {
2075
2079
  for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
2076
2080
  n[o - 1] = arguments[o];
2077
2081
  let [i, r] = n;
2078
- typeof i == "function" && (r = i, i = ""), pt({
2082
+ typeof i == "function" && (r = i, i = ""), gt({
2079
2083
  key: t,
2080
2084
  scope: i,
2081
2085
  method: r,
@@ -2083,25 +2087,25 @@ function be(t) {
2083
2087
  });
2084
2088
  }
2085
2089
  }
2086
- const pt = (t) => {
2090
+ const gt = (t) => {
2087
2091
  let {
2088
2092
  key: e,
2089
2093
  scope: n,
2090
2094
  method: o,
2091
2095
  splitKey: i = "+"
2092
2096
  } = t;
2093
- ge(e).forEach((a) => {
2094
- const s = a.split(i), l = s.length, u = s[l - 1], g = u === "*" ? "*" : ct(u);
2097
+ me(e).forEach((a) => {
2098
+ const s = a.split(i), l = s.length, f = s[l - 1], g = f === "*" ? "*" : ct(f);
2095
2099
  if (!I[g]) return;
2096
2100
  n || (n = at());
2097
- const c = l > 1 ? pe(j, s) : [], p = [];
2098
- I[g] = I[g].filter((d) => {
2099
- const v = (o ? d.method === o : !0) && d.scope === n && uo(d.mods, c);
2100
- return v && p.push(d.element), !v;
2101
- }), p.forEach((d) => Vt(d));
2101
+ const c = l > 1 ? ge(j, s) : [], p = [];
2102
+ I[g] = I[g].filter((u) => {
2103
+ const b = (o ? u.method === o : !0) && u.scope === n && uo(u.mods, c);
2104
+ return b && p.push(u.element), !b;
2105
+ }), p.forEach((u) => Dt(u));
2102
2106
  });
2103
2107
  };
2104
- function te(t, e, n, o) {
2108
+ function ee(t, e, n, o) {
2105
2109
  if (e.element !== o)
2106
2110
  return;
2107
2111
  let i;
@@ -2112,46 +2116,46 @@ function te(t, e, n, o) {
2112
2116
  (e.mods.length === 0 && !D[16] && !D[18] && !D[17] && !D[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(k), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
2113
2117
  }
2114
2118
  }
2115
- function ee(t, e) {
2119
+ function ne(t, e) {
2116
2120
  const n = I["*"];
2117
2121
  let o = t.keyCode || t.which || t.charCode;
2118
- if (!P.filter.call(this, t)) return;
2122
+ if (!X.filter.call(this, t)) return;
2119
2123
  if ((o === 93 || o === 224) && (o = 91), k.indexOf(o) === -1 && o !== 229 && k.push(o), ["ctrlKey", "altKey", "shiftKey", "metaKey"].forEach((s) => {
2120
- const l = kt[s];
2124
+ const l = Nt[s];
2121
2125
  t[s] && k.indexOf(l) === -1 ? k.push(l) : !t[s] && k.indexOf(l) > -1 ? k.splice(k.indexOf(l), 1) : s === "metaKey" && t[s] && k.length === 3 && (t.ctrlKey || t.shiftKey || t.altKey || (k = k.slice(k.indexOf(l))));
2122
2126
  }), o in D) {
2123
2127
  D[o] = !0;
2124
2128
  for (const s in j)
2125
- j[s] === o && (P[s] = !0);
2129
+ j[s] === o && (X[s] = !0);
2126
2130
  if (!n) return;
2127
2131
  }
2128
2132
  for (const s in D)
2129
- Object.prototype.hasOwnProperty.call(D, s) && (D[s] = t[kt[s]]);
2133
+ Object.prototype.hasOwnProperty.call(D, s) && (D[s] = t[Nt[s]]);
2130
2134
  t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (k.indexOf(17) === -1 && k.push(17), k.indexOf(18) === -1 && k.push(18), D[17] = !0, D[18] = !0);
2131
2135
  const i = at();
2132
2136
  if (n)
2133
2137
  for (let s = 0; s < n.length; s++)
2134
- n[s].scope === i && (t.type === "keydown" && n[s].keydown || t.type === "keyup" && n[s].keyup) && te(t, n[s], i, e);
2138
+ n[s].scope === i && (t.type === "keydown" && n[s].keydown || t.type === "keyup" && n[s].keyup) && ee(t, n[s], i, e);
2135
2139
  if (!(o in I)) return;
2136
2140
  const r = I[o], a = r.length;
2137
2141
  for (let s = 0; s < a; s++)
2138
2142
  if ((t.type === "keydown" && r[s].keydown || t.type === "keyup" && r[s].keyup) && r[s].key) {
2139
2143
  const l = r[s], {
2140
- splitKey: u
2141
- } = l, g = l.key.split(u), c = [];
2144
+ splitKey: f
2145
+ } = l, g = l.key.split(f), c = [];
2142
2146
  for (let p = 0; p < g.length; p++)
2143
2147
  c.push(ct(g[p]));
2144
- c.sort().join("") === k.sort().join("") && te(t, l, i, e);
2148
+ c.sort().join("") === k.sort().join("") && ee(t, l, i, e);
2145
2149
  }
2146
2150
  }
2147
- function P(t, e, n) {
2151
+ function X(t, e, n) {
2148
2152
  k = [];
2149
- const o = ge(t);
2150
- let i = [], r = "all", a = document, s = 0, l = !1, u = !0, g = "+", c = !1, p = !1;
2151
- for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (u = e.keydown), e.capture !== void 0 && (c = e.capture), typeof e.splitKey == "string" && (g = e.splitKey), e.single === !0 && (p = !0)), typeof e == "string" && (r = e), p && be(t, r); s < o.length; s++)
2152
- t = o[s].split(g), i = [], t.length > 1 && (i = pe(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : ct(t), t in I || (I[t] = []), I[t].push({
2153
+ const o = me(t);
2154
+ let i = [], r = "all", a = document, s = 0, l = !1, f = !0, g = "+", c = !1, p = !1;
2155
+ for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (r = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (c = e.capture), typeof e.splitKey == "string" && (g = e.splitKey), e.single === !0 && (p = !0)), typeof e == "string" && (r = e), p && we(t, r); s < o.length; s++)
2156
+ t = o[s].split(g), i = [], t.length > 1 && (i = ge(j, t)), t = t[t.length - 1], t = t === "*" ? "*" : ct(t), t in I || (I[t] = []), I[t].push({
2153
2157
  keyup: l,
2154
- keydown: u,
2158
+ keydown: f,
2155
2159
  scope: r,
2156
2160
  mods: i,
2157
2161
  shortcut: o[s],
@@ -2162,27 +2166,27 @@ function P(t, e, n) {
2162
2166
  });
2163
2167
  if (typeof a < "u" && window) {
2164
2168
  if (!F.has(a)) {
2165
- const d = function() {
2166
- let v = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2167
- return ee(v, a);
2169
+ const u = function() {
2170
+ let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2171
+ return ne(b, a);
2168
2172
  }, x = function() {
2169
- let v = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2170
- ee(v, a), vo(v);
2173
+ let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
2174
+ ne(b, a), vo(b);
2171
2175
  };
2172
2176
  F.set(a, {
2173
- keydownListener: d,
2177
+ keydownListener: u,
2174
2178
  keyupListenr: x,
2175
2179
  capture: c
2176
- }), Tt(a, "keydown", d, c), Tt(a, "keyup", x, c);
2180
+ }), Rt(a, "keydown", u, c), Rt(a, "keyup", x, c);
2177
2181
  }
2178
2182
  if (!rt) {
2179
- const d = () => {
2183
+ const u = () => {
2180
2184
  k = [];
2181
2185
  };
2182
2186
  rt = {
2183
- listener: d,
2187
+ listener: u,
2184
2188
  capture: c
2185
- }, Tt(window, "focus", d, c);
2189
+ }, Rt(window, "focus", u, c);
2186
2190
  }
2187
2191
  }
2188
2192
  }
@@ -2194,7 +2198,7 @@ function xo(t) {
2194
2198
  });
2195
2199
  });
2196
2200
  }
2197
- function Vt(t) {
2201
+ function Dt(t) {
2198
2202
  const e = Object.values(I).flat();
2199
2203
  if (e.findIndex((o) => {
2200
2204
  let {
@@ -2224,9 +2228,9 @@ function Vt(t) {
2224
2228
  et(window, "focus", i, r), rt = null;
2225
2229
  }
2226
2230
  }
2227
- const Rt = {
2231
+ const Bt = {
2228
2232
  getPressedKeyString: go,
2229
- setScope: ye,
2233
+ setScope: be,
2230
2234
  getScope: at,
2231
2235
  deleteScope: wo,
2232
2236
  getPressedKeyCodes: po,
@@ -2234,147 +2238,149 @@ const Rt = {
2234
2238
  isPressed: bo,
2235
2239
  filter: yo,
2236
2240
  trigger: xo,
2237
- unbind: be,
2241
+ unbind: we,
2238
2242
  keyMap: st,
2239
2243
  modifier: j,
2240
- modifierMap: kt
2244
+ modifierMap: Nt
2241
2245
  };
2242
- for (const t in Rt)
2243
- Object.prototype.hasOwnProperty.call(Rt, t) && (P[t] = Rt[t]);
2246
+ for (const t in Bt)
2247
+ Object.prototype.hasOwnProperty.call(Bt, t) && (X[t] = Bt[t]);
2244
2248
  if (typeof window < "u") {
2245
2249
  const t = window.hotkeys;
2246
- P.noConflict = (e) => (e && window.hotkeys === P && (window.hotkeys = t), P), window.hotkeys = P;
2250
+ X.noConflict = (e) => (e && window.hotkeys === X && (window.hotkeys = t), X), window.hotkeys = X;
2247
2251
  }
2248
2252
  const Ao = (t, e, n) => {
2249
2253
  let o;
2250
- const i = (w) => o = w;
2254
+ const i = (S) => o = S;
2251
2255
  let r;
2252
- const a = (w) => r = w;
2256
+ const a = (S) => r = S;
2253
2257
  let s = !0;
2254
- const l = (w) => {
2255
- s = w, v.clear(), w || (c = void 0, p = void 0, d = void 0);
2256
- }, { store: u, selection: g } = e;
2257
- let c, p, d;
2258
- const x = (w) => {
2259
- var B;
2258
+ const l = (S) => {
2259
+ s = S, b.clear(), S || (c = void 0, p = void 0, u = void 0);
2260
+ }, { store: f, selection: g } = e;
2261
+ let c, p, u;
2262
+ const x = (S) => {
2263
+ var O;
2260
2264
  if (!s || p === !1)
2261
2265
  return;
2262
- c = !((B = w.target.parentElement) != null && B.closest(H)) ? {
2263
- annotation: ae(),
2266
+ c = !((O = S.target.parentElement) != null && O.closest(H)) ? {
2267
+ annotation: ce(),
2264
2268
  selector: [],
2265
2269
  creator: o,
2266
2270
  created: /* @__PURE__ */ new Date()
2267
2271
  } : void 0;
2268
2272
  };
2269
2273
  t.addEventListener("selectstart", x);
2270
- const v = It((w) => {
2271
- var C, R;
2274
+ const b = _t((S) => {
2275
+ var T, N;
2272
2276
  if (!s) return;
2273
- const O = document.getSelection();
2274
- if (!!((R = (C = O.anchorNode) == null ? void 0 : C.parentElement) != null && R.closest(H))) {
2277
+ const R = document.getSelection();
2278
+ if (!!((N = (T = R.anchorNode) == null ? void 0 : T.parentElement) != null && N.closest(H))) {
2275
2279
  c = void 0;
2276
2280
  return;
2277
2281
  }
2278
- if (w.timeStamp - ((d == null ? void 0 : d.timeStamp) || w.timeStamp) < 1e3 && !c && x(d || w), !c) return;
2279
- if (O.isCollapsed) {
2280
- u.getAnnotation(c.annotation) && (g.clear(), u.deleteAnnotation(c.annotation));
2282
+ if (S.timeStamp - ((u == null ? void 0 : u.timeStamp) || S.timeStamp) < 1e3 && !c && x(u || S), !c) return;
2283
+ if (R.isCollapsed) {
2284
+ f.getAnnotation(c.annotation) && (g.clear(), f.deleteAnnotation(c.annotation));
2281
2285
  return;
2282
2286
  }
2283
- const T = O.getRangeAt(0), m = Pn(T, t);
2284
- if (Vn(m)) return;
2285
- const A = Bn(m.cloneRange());
2286
- (A.length !== c.selector.length || A.some((N, $) => {
2287
- var Y;
2288
- return N.toString() !== ((Y = c.selector[$]) == null ? void 0 : Y.quote);
2287
+ const m = R.getRangeAt(0), w = Pn(m, t);
2288
+ if (Vn(w)) return;
2289
+ const E = Bn(w.cloneRange());
2290
+ (E.length !== c.selector.length || E.some((K, P) => {
2291
+ var lt;
2292
+ return K.toString() !== ((lt = c.selector[P]) == null ? void 0 : lt.quote);
2289
2293
  })) && (c = {
2290
2294
  ...c,
2291
- selector: A.map((N) => Xn(N, t, n)),
2295
+ selector: E.map((K) => Xn(K, t, n)),
2292
2296
  updated: /* @__PURE__ */ new Date()
2293
- }, u.getAnnotation(c.annotation) ? u.updateTarget(c, M.LOCAL) : (g.clear(), u.addAnnotation({
2297
+ }, f.getAnnotation(c.annotation) ? f.updateTarget(c, M.LOCAL) : (g.clear(), f.addAnnotation({
2294
2298
  id: c.annotation,
2295
2299
  bodies: [],
2296
2300
  target: c
2297
- }, M.LOCAL), g.userSelect(c.annotation, d)));
2301
+ }, M.LOCAL), g.userSelect(c.annotation, u)));
2298
2302
  }, 10);
2299
- document.addEventListener("selectionchange", v);
2300
- const b = (w) => {
2301
- d = Hn(w), p = d.button === 0, c = void 0;
2303
+ document.addEventListener("selectionchange", b);
2304
+ const v = (S) => {
2305
+ u = Hn(S), p = u.button === 0, c = void 0;
2302
2306
  };
2303
- document.addEventListener("pointerdown", b);
2304
- const h = (w) => {
2305
- var T;
2306
- if (!!((T = w.target.parentElement) != null && T.closest(H)) || !p)
2307
+ document.addEventListener("pointerdown", v);
2308
+ const h = (S) => {
2309
+ var m;
2310
+ if (!!((m = S.target.parentElement) != null && m.closest(H)) || !p)
2307
2311
  return;
2308
- const B = () => {
2309
- const { x: m, y: A } = t.getBoundingClientRect(), S = w.target instanceof Node && t.contains(w.target) && u.getAt(w.clientX - m, w.clientY - A, r);
2310
- if (S) {
2311
- const { selected: C } = g;
2312
- (C.length !== 1 || C[0].id !== S.id) && g.userSelect(S.id, w);
2312
+ const O = () => {
2313
+ const { x: w, y: E } = t.getBoundingClientRect(), L = S.target instanceof Node && t.contains(S.target) && f.getAt(S.clientX - w, S.clientY - E, r);
2314
+ if (L) {
2315
+ const { selected: T } = g;
2316
+ (T.length !== 1 || T[0].id !== L.id) && g.userSelect(L.id, S);
2313
2317
  } else g.isEmpty() || g.clear();
2314
- }, L = w.timeStamp - d.timeStamp;
2318
+ }, B = S.timeStamp - u.timeStamp;
2315
2319
  setTimeout(() => {
2316
- const m = document.getSelection();
2317
- m != null && m.isCollapsed && L < 300 ? B() : c && g.userSelect(c.annotation, w);
2320
+ const w = document.getSelection();
2321
+ w != null && w.isCollapsed && B < 300 ? O() : c && g.userSelect(c.annotation, S);
2318
2322
  });
2319
2323
  };
2320
2324
  document.addEventListener("pointerup", h);
2321
- const f = ["up", "down", "left", "right"], y = [
2322
- ...f.map((w) => `shift+${w}`),
2325
+ const d = ["up", "down", "left", "right"], y = [
2326
+ ...d.map((S) => `shift+${S}`),
2323
2327
  "ctrl+a",
2324
2328
  "⌘+a"
2325
2329
  ];
2326
- return P(y.join(","), { element: t, keydown: !0, keyup: !1 }, (w) => {
2327
- w.repeat || (d = jn(w));
2328
- }), P(f.join(","), { element: t, keydown: !0, keyup: !1 }, (w) => {
2329
- w.repeat || (c = void 0, g.clear());
2330
- }), {
2330
+ X(y.join(","), { element: t, keydown: !0, keyup: !1 }, (S) => {
2331
+ S.repeat || (u = jn(S));
2332
+ });
2333
+ const A = (S) => {
2334
+ S.repeat || (c = void 0, g.clear());
2335
+ };
2336
+ return X(d.join(","), { element: document.body, keydown: !0, keyup: !1 }, A), X(d.join(","), { element: t, keydown: !0, keyup: !1 }, A), {
2331
2337
  destroy: () => {
2332
- c = void 0, p = void 0, d = void 0, v.clear(), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", v), document.removeEventListener("pointerdown", b), document.removeEventListener("pointerup", h), P.unbind();
2338
+ c = void 0, p = void 0, u = void 0, b.clear(), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", b), document.removeEventListener("pointerdown", v), document.removeEventListener("pointerup", h), X.unbind();
2333
2339
  },
2334
2340
  setFilter: a,
2335
2341
  setUser: i,
2336
2342
  setAnnotatingEnabled: l
2337
2343
  };
2338
- }, ne = "SPANS", Ro = (t, e = {}) => {
2344
+ }, oe = "SPANS", Ro = (t, e = {}) => {
2339
2345
  Mn(t), kn(t);
2340
2346
  const n = lo(e, {
2341
2347
  annotatingEnabled: !0,
2342
2348
  user: Sn()
2343
2349
  }), o = ro(t, n.userSelectAction), { selection: i, viewport: r } = o, a = o.store, s = pn(a), l = mn(o, s, n.adapter);
2344
- let u = n.user;
2345
- const g = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ne : n.renderer || ne, c = g === "SPANS" ? $e(t, o, r) : g === "CSS_HIGHLIGHTS" ? Ke(t, o, r) : g === "CANVAS" ? Be(t, o, r) : void 0;
2350
+ let f = n.user;
2351
+ const g = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : oe : n.renderer || oe, c = g === "SPANS" ? $e(t, o, r) : g === "CSS_HIGHLIGHTS" ? Ye(t, o, r) : g === "CANVAS" ? Be(t, o, r) : void 0;
2346
2352
  if (!c)
2347
2353
  throw `Unknown renderer implementation: ${g}`;
2348
2354
  console.debug(`Using ${g} renderer`), n.style && c.setStyle(n.style);
2349
2355
  const p = Ao(t, o, n.offsetReferenceSelector);
2350
- p.setUser(u), p.setAnnotatingEnabled(n.annotatingEnabled);
2351
- const d = bn(o, s, n.adapter), x = () => u, v = (w) => {
2356
+ p.setUser(f), p.setAnnotatingEnabled(n.annotatingEnabled);
2357
+ const u = bn(o, s, n.adapter), x = () => f, b = (C) => {
2352
2358
  p.setAnnotatingEnabled(
2353
- w === void 0 ? !0 : w
2359
+ C === void 0 ? !0 : C
2354
2360
  );
2355
- }, b = (w) => {
2356
- c.setFilter(w), p.setFilter(w);
2357
- }, h = (w) => {
2358
- u = w, p.setUser(w);
2359
- }, f = (w) => {
2360
- w && (c.setPainter(ao(t, w, n.presence)), w.on("selectionChange", () => c.redraw()));
2361
- }, y = (w) => {
2362
- w ? i.setSelected(w) : i.clear();
2361
+ }, v = (C) => {
2362
+ c.setFilter(C), p.setFilter(C);
2363
+ }, h = (C) => {
2364
+ f = C, p.setUser(C);
2365
+ }, d = (C) => {
2366
+ C && (c.setPainter(ao(t, C, n.presence)), C.on("selectionChange", () => c.redraw()));
2367
+ }, y = (C) => {
2368
+ C ? i.setSelected(C) : i.clear();
2363
2369
  };
2364
2370
  return {
2365
- ...d,
2371
+ ...u,
2366
2372
  destroy: () => {
2367
2373
  c.destroy(), p.destroy(), s.destroy();
2368
2374
  },
2369
2375
  element: t,
2370
2376
  getUser: x,
2371
- setAnnotatingEnabled: v,
2372
- setFilter: b,
2377
+ setAnnotatingEnabled: b,
2378
+ setFilter: v,
2373
2379
  setStyle: c.setStyle.bind(c),
2374
2380
  redraw: c.redraw.bind(c),
2375
2381
  setUser: h,
2376
2382
  setSelected: y,
2377
- setPresenceProvider: f,
2383
+ setPresenceProvider: d,
2378
2384
  setVisible: c.setVisible.bind(c),
2379
2385
  on: l.on,
2380
2386
  off: l.off,
@@ -2383,9 +2389,9 @@ const Ao = (t, e, n) => {
2383
2389
  };
2384
2390
  };
2385
2391
  export {
2386
- gt as DEFAULT_SELECTED_STYLE,
2392
+ mt as DEFAULT_SELECTED_STYLE,
2387
2393
  q as DEFAULT_STYLE,
2388
- de as NOT_ANNOTATABLE_CLASS,
2394
+ ue as NOT_ANNOTATABLE_CLASS,
2389
2395
  H as NOT_ANNOTATABLE_SELECTOR,
2390
2396
  M as Origin,
2391
2397
  Ge as UserSelectAction,
@@ -2395,8 +2401,8 @@ export {
2395
2401
  Hn as clonePointerEvent,
2396
2402
  Eo as createBody,
2397
2403
  Be as createCanvasRenderer,
2398
- Ke as createHighlightsRenderer,
2399
- Ye as createRenderer,
2404
+ Ye as createHighlightsRenderer,
2405
+ Ke as createRenderer,
2400
2406
  $e as createSpansRenderer,
2401
2407
  Ro as createTextAnnotator,
2402
2408
  ro as createTextAnnotatorState,
@@ -2405,18 +2411,18 @@ export {
2405
2411
  So as getAnnotatableFragment,
2406
2412
  Co as getClientRectsPonyfill,
2407
2413
  _n as getQuoteContext,
2408
- Mt as getRangeAnnotatableContents,
2414
+ kt as getRangeAnnotatableContents,
2409
2415
  W as isRevived,
2410
2416
  Vn as isWhitespaceOrEmpty,
2411
- Kn as mergeClientRects,
2417
+ Yn as mergeClientRects,
2412
2418
  $n as normalizeRectWithOffset,
2413
2419
  Ae as paint,
2414
2420
  Wn as parseW3CTextAnnotation,
2415
2421
  kn as programmaticallyFocusable,
2416
2422
  Xn as rangeToSelector,
2417
- St as reviveAnnotation,
2418
- ue as reviveSelector,
2419
- mt as reviveTarget,
2423
+ Ct as reviveAnnotation,
2424
+ fe as reviveSelector,
2425
+ yt as reviveTarget,
2420
2426
  qn as serializeW3CTextAnnotation,
2421
2427
  Bn as splitAnnotatableRanges,
2422
2428
  Lo as toDomRectList,