@recogito/text-annotator 3.0.0-rc.10 → 3.0.0-rc.11

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,607 +1,611 @@
1
- const ft = { fill: "rgb(0, 128, 255", fillOpacity: 0.18 }, pt = { fill: "rgb(0, 128, 255)", fillOpacity: 0.45 }, nt = {
2
- paint: (e, t, n, o, i, s) => {
3
- const a = s ? typeof s == "function" ? s(e, i) : s : i ? pt : ft;
4
- n.fillStyle = a.fill, n.globalAlpha = a.fillOpacity || 1, t.forEach(({ x: r, y: d, width: h, height: w }) => n.fillRect(r, d - 2.5, h, w + 5));
1
+ const yt = { fill: "rgb(0, 128, 255", fillOpacity: 0.18 }, vt = { fill: "rgb(0, 128, 255)", fillOpacity: 0.45 }, at = {
2
+ paint: (t, e, n, o, i, s) => {
3
+ const r = s ? typeof s == "function" ? s(t, i) : s : i ? vt : yt;
4
+ n.fillStyle = r.fill, n.globalAlpha = r.fillOpacity || 1, e.forEach(({ x: a, y: l, width: d, height: x }) => n.fillRect(a, l - 2.5, d, x + 5));
5
5
  }
6
- }, gt = (e) => {
7
- let t = /* @__PURE__ */ new Set();
6
+ }, Et = (t) => {
7
+ let e = /* @__PURE__ */ new Set();
8
8
  return (o) => {
9
9
  const i = o.map((s) => s.id);
10
- (t.size !== i.length || i.some((s) => !t.has(s))) && e.set(i), t = new Set(i);
10
+ (e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
11
11
  };
12
- }, mt = (e, t = 10) => {
12
+ }, St = (t, e = 10) => {
13
13
  let n;
14
14
  return (...o) => {
15
- clearTimeout(n), n = setTimeout(() => e.apply(void 0, o), t);
15
+ clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
16
16
  };
17
- }, j = (e, t) => {
17
+ }, nt = (t, e) => {
18
18
  const n = document.createElement("canvas");
19
- if (n.width = t ? 2 * window.innerWidth : window.innerWidth, n.height = t ? 2 * window.innerHeight : window.innerHeight, n.className = e, t) {
19
+ if (n.width = e ? 2 * window.innerWidth : window.innerWidth, n.height = e ? 2 * window.innerHeight : window.innerHeight, n.className = t, e) {
20
20
  const o = n.getContext("2d");
21
21
  o.scale(2, 2), o.translate(0.5, 0.5);
22
22
  }
23
23
  return n;
24
- }, Z = (e, t) => {
25
- if (e.width = t ? 2 * window.innerWidth : window.innerWidth, e.height = t ? 2 * window.innerHeight : window.innerHeight, t) {
26
- const n = e.getContext("2d");
24
+ }, ot = (t, e) => {
25
+ if (t.width = e ? 2 * window.innerWidth : window.innerWidth, t.height = e ? 2 * window.innerHeight : window.innerHeight, e) {
26
+ const n = t.getContext("2d");
27
27
  n.scale(2, 2), n.translate(0.5, 0.5);
28
28
  }
29
- }, bt = (e, t, n) => {
30
- const { store: o, selection: i, hover: s } = t;
31
- let a, r, d = nt;
32
- const h = gt(n);
33
- e.classList.add("r6o-annotatable");
34
- const w = j("r6o-highlight-layer bg"), f = j("r6o-highlight-layer fg", !0), T = w.getContext("2d"), g = f.getContext("2d");
35
- e.insertBefore(w, e.firstChild), e.appendChild(f), e.addEventListener("pointermove", (E) => {
36
- const { x: v, y: C } = e.getBoundingClientRect(), p = o.getAt(E.clientX - v, E.clientY - C);
37
- p && (!r || r(p)) ? s.current !== p.id && (e.classList.add("hovered"), s.set(p.id)) : s.current && (e.classList.remove("hovered"), s.set(null));
38
- });
39
- const y = () => {
40
- const { top: E, left: v } = e.getBoundingClientRect(), { innerWidth: C, innerHeight: p } = window, x = -v, b = -E, S = C - v, M = p - E;
41
- return { top: E, left: v, minX: x, minY: b, maxX: S, maxY: M };
42
- }, B = () => c();
43
- document.addEventListener("scroll", B, { capture: !0, passive: !0 });
44
- const A = mt(() => {
45
- Z(w), Z(f, !0), o.recalculatePositions(), c();
46
- });
47
- window.addEventListener("resize", A), new ResizeObserver(A).observe(e);
48
- const c = () => requestAnimationFrame(() => {
49
- const { top: E, left: v, minX: C, minY: p, maxX: x, maxY: b } = y(), S = r ? o.getIntersectingRects(C, p, x, b).filter(({ annotation: Y }) => r(Y)) : o.getIntersectingRects(C, p, x, b), { width: M, height: R } = f, X = new Set(i.selected.map(({ id: Y }) => Y));
50
- g.clearRect(-0.5, -0.5, M + 1, R + 1), T.clearRect(-0.5, -0.5, M + 1, R + 1), S.forEach(({ annotation: Y, rects: at }) => {
51
- const rt = at.map(({ x: ct, y: dt, width: ut, height: ht }) => ({
52
- x: ct + v,
53
- y: dt + E,
54
- width: ut,
55
- height: ht
56
- })), lt = X.has(Y.id);
57
- d.paint(Y, rt, T, g, lt, a);
58
- }), setTimeout(() => h(S.map(({ annotation: Y }) => Y)), 1);
29
+ }, Tt = (t, e, n) => {
30
+ const { store: o, selection: i, hover: s } = e;
31
+ let r, a, l = at;
32
+ const d = Et(n);
33
+ t.classList.add("r6o-annotatable");
34
+ const x = nt("r6o-highlight-layer bg"), u = nt("r6o-highlight-layer fg", !0), T = x.getContext("2d"), h = u.getContext("2d");
35
+ t.insertBefore(x, t.firstChild), t.appendChild(u);
36
+ const w = (v) => {
37
+ const { x: C, y: L } = t.getBoundingClientRect(), X = o.getAt(v.clientX - C, v.clientY - L);
38
+ X && (!a || a(X)) ? s.current !== X.id && (t.classList.add("hovered"), s.set(X.id)) : s.current && (t.classList.remove("hovered"), s.set(null));
39
+ };
40
+ t.addEventListener("pointermove", w);
41
+ const B = () => {
42
+ const { top: v, left: C } = t.getBoundingClientRect(), { innerWidth: L, innerHeight: X } = window, k = -C, H = -v, $ = L - C, F = X - v;
43
+ return { top: v, left: C, minX: k, minY: H, maxX: $, maxY: F };
44
+ }, b = () => requestAnimationFrame(() => {
45
+ const { top: v, left: C, minX: L, minY: X, maxX: k, maxY: H } = B(), $ = a ? o.getIntersectingRects(L, X, k, H).filter(({ annotation: Y }) => a(Y)) : o.getIntersectingRects(L, X, k, H), { width: F, height: et } = u, ft = new Set(i.selected.map(({ id: Y }) => Y));
46
+ h.clearRect(-0.5, -0.5, F + 1, et + 1), T.clearRect(-0.5, -0.5, F + 1, et + 1), $.forEach(({ annotation: Y, rects: pt }) => {
47
+ const gt = pt.map(({ x: bt, y: wt, width: xt, height: At }) => ({
48
+ x: bt + C,
49
+ y: wt + v,
50
+ width: xt,
51
+ height: At
52
+ })), mt = ft.has(Y.id);
53
+ l.paint(Y, gt, T, h, mt, r);
54
+ }), setTimeout(() => d($.map(({ annotation: Y }) => Y)), 1);
55
+ }), c = (v) => {
56
+ r = v, b();
57
+ }, f = (v) => {
58
+ a = v, b();
59
+ }, p = () => b();
60
+ o.observe(p);
61
+ const m = i.subscribe(() => b()), E = () => b();
62
+ document.addEventListener("scroll", E, { capture: !0, passive: !0 });
63
+ const S = St(() => {
64
+ console.log("onresize!"), ot(x), ot(u, !0), o.recalculatePositions(), b();
59
65
  });
60
- return o.observe(() => c()), i.subscribe(() => c()), {
61
- redraw: c,
62
- setDrawingStyle: (E) => {
63
- a = E, c();
64
- },
65
- setFilter: (E) => {
66
- r = E, c();
66
+ window.addEventListener("resize", S);
67
+ const M = new ResizeObserver(S);
68
+ M.observe(t);
69
+ const g = { attributes: !0, childList: !0, subtree: !0 }, y = new MutationObserver(S);
70
+ return y.observe(document.body, g), {
71
+ destroy: () => {
72
+ t.removeEventListener("pointermove", w), t.removeChild(u), t.appendChild(x), o.unobserve(p), m(), document.removeEventListener("scroll", E), window.removeEventListener("resize", S), M.disconnect(), y.disconnect();
67
73
  },
68
- setPainter: (E) => d = E
74
+ redraw: b,
75
+ setDrawingStyle: c,
76
+ setFilter: f,
77
+ setPainter: (v) => l = v
69
78
  };
70
- }, _ = (e, t) => {
71
- const { start: n, end: o } = e.selector, i = e.selector.offsetReference ? e.selector.offsetReference : t;
72
- if (!i)
79
+ };
80
+ let W;
81
+ const Bt = new Uint8Array(16);
82
+ function Ct() {
83
+ if (!W && (W = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !W))
84
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
85
+ return W(Bt);
86
+ }
87
+ const R = [];
88
+ for (let t = 0; t < 256; ++t)
89
+ R.push((t + 256).toString(16).slice(1));
90
+ function Mt(t, e = 0) {
91
+ return R[t[e + 0]] + R[t[e + 1]] + R[t[e + 2]] + R[t[e + 3]] + "-" + R[t[e + 4]] + R[t[e + 5]] + "-" + R[t[e + 6]] + R[t[e + 7]] + "-" + R[t[e + 8]] + R[t[e + 9]] + "-" + R[t[e + 10]] + R[t[e + 11]] + R[t[e + 12]] + R[t[e + 13]] + R[t[e + 14]] + R[t[e + 15]];
92
+ }
93
+ const Lt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), it = {
94
+ randomUUID: Lt
95
+ };
96
+ function ct(t, e, n) {
97
+ if (it.randomUUID && !e && !t)
98
+ return it.randomUUID();
99
+ t = t || {};
100
+ const o = t.random || (t.rng || Ct)();
101
+ if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, e) {
102
+ n = n || 0;
103
+ for (let i = 0; i < 16; ++i)
104
+ e[n + i] = o[i];
73
105
  return e;
74
- const s = document.createNodeIterator(t, NodeFilter.SHOW_TEXT);
75
- let a = 0, r = document.createRange(), d = s.nextNode();
76
- d === null && console.error("Could not revive annotation target. Content missing.");
77
- let h = !i;
78
- for (; d !== null; ) {
79
- const w = d.textContent.length;
80
- if (!h && i && (h = i.contains(d)), h) {
81
- if (a + w > n) {
82
- r.setStart(d, n - a);
83
- break;
84
- }
85
- a += w;
86
- }
87
- d = s.nextNode();
88
- }
89
- for (; d !== null; ) {
90
- const w = d.textContent.length;
91
- if (a + w > o) {
92
- r.setEnd(d, o - a);
93
- break;
94
- }
95
- a += w, d = s.nextNode();
96
106
  }
97
- return {
98
- ...e,
99
- selector: {
100
- ...e.selector,
101
- range: r
102
- }
103
- };
104
- };
105
- var Q = Object.prototype.hasOwnProperty;
106
- function U(e, t) {
107
+ return Mt(o);
108
+ }
109
+ var st = Object.prototype.hasOwnProperty;
110
+ function U(t, e) {
107
111
  var n, o;
108
- if (e === t)
112
+ if (t === e)
109
113
  return !0;
110
- if (e && t && (n = e.constructor) === t.constructor) {
114
+ if (t && e && (n = t.constructor) === e.constructor) {
111
115
  if (n === Date)
112
- return e.getTime() === t.getTime();
116
+ return t.getTime() === e.getTime();
113
117
  if (n === RegExp)
114
- return e.toString() === t.toString();
118
+ return t.toString() === e.toString();
115
119
  if (n === Array) {
116
- if ((o = e.length) === t.length)
117
- for (; o-- && U(e[o], t[o]); )
120
+ if ((o = t.length) === e.length)
121
+ for (; o-- && U(t[o], e[o]); )
118
122
  ;
119
123
  return o === -1;
120
124
  }
121
- if (!n || typeof e == "object") {
125
+ if (!n || typeof t == "object") {
122
126
  o = 0;
123
- for (n in e)
124
- if (Q.call(e, n) && ++o && !Q.call(t, n) || !(n in t) || !U(e[n], t[n]))
127
+ for (n in t)
128
+ if (st.call(t, n) && ++o && !st.call(e, n) || !(n in e) || !U(t[n], e[n]))
125
129
  return !1;
126
- return Object.keys(t).length === o;
130
+ return Object.keys(e).length === o;
127
131
  }
128
132
  }
129
- return e !== e && t !== t;
133
+ return t !== t && e !== e;
130
134
  }
131
- function W() {
135
+ function G() {
132
136
  }
133
- function wt(e, t) {
134
- return e != e ? t == t : e !== t || e && typeof e == "object" || typeof e == "function";
137
+ function Ot(t, e) {
138
+ return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
135
139
  }
136
- const D = [];
137
- function J(e, t = W) {
140
+ const I = [];
141
+ function tt(t, e = G) {
138
142
  let n;
139
143
  const o = /* @__PURE__ */ new Set();
140
- function i(r) {
141
- if (wt(e, r) && (e = r, n)) {
142
- const d = !D.length;
143
- for (const h of o)
144
- h[1](), D.push(h, e);
145
- if (d) {
146
- for (let h = 0; h < D.length; h += 2)
147
- D[h][0](D[h + 1]);
148
- D.length = 0;
144
+ function i(a) {
145
+ if (Ot(t, a) && (t = a, n)) {
146
+ const l = !I.length;
147
+ for (const d of o)
148
+ d[1](), I.push(d, t);
149
+ if (l) {
150
+ for (let d = 0; d < I.length; d += 2)
151
+ I[d][0](I[d + 1]);
152
+ I.length = 0;
149
153
  }
150
154
  }
151
155
  }
152
- function s(r) {
153
- i(r(e));
156
+ function s(a) {
157
+ i(a(t));
154
158
  }
155
- function a(r, d = W) {
156
- const h = [r, d];
157
- return o.add(h), o.size === 1 && (n = t(i, s) || W), r(e), () => {
158
- o.delete(h), o.size === 0 && n && (n(), n = null);
159
+ function r(a, l = G) {
160
+ const d = [a, l];
161
+ return o.add(d), o.size === 1 && (n = e(i, s) || G), a(t), () => {
162
+ o.delete(d), o.size === 0 && n && (n(), n = null);
159
163
  };
160
164
  }
161
- return { set: i, update: s, subscribe: a };
165
+ return { set: i, update: s, subscribe: r };
162
166
  }
163
- const At = (e) => {
164
- const { subscribe: t, set: n } = J();
167
+ const Rt = (t) => {
168
+ const { subscribe: e, set: n } = tt();
165
169
  let o;
166
- return t((i) => o = i), e.observe(({ changes: i }) => {
170
+ return e((i) => o = i), t.observe(({ changes: i }) => {
167
171
  if (o) {
168
- (i.deleted || []).some((a) => a.id === o) && n(void 0);
169
- const s = (i.updated || []).find(({ oldValue: a }) => a.id === o);
172
+ (i.deleted || []).some((r) => r.id === o) && n(void 0);
173
+ const s = (i.updated || []).find(({ oldValue: r }) => r.id === o);
170
174
  s && n(s.newValue.id);
171
175
  }
172
176
  }), {
173
177
  get current() {
174
178
  return o;
175
179
  },
176
- subscribe: t,
180
+ subscribe: e,
177
181
  set: n
178
182
  };
179
- }, q = { selected: [] }, xt = (e, t = "EDIT") => {
180
- const { subscribe: n, set: o } = J(q);
181
- let i = q;
182
- n((f) => i = f);
183
- const s = () => o(q), a = () => {
184
- var f;
185
- return ((f = i.selected) == null ? void 0 : f.length) === 0;
186
- }, r = (f) => {
183
+ }, J = { selected: [] }, Xt = (t, e = "EDIT") => {
184
+ const { subscribe: n, set: o } = tt(J);
185
+ let i = J;
186
+ n((u) => i = u);
187
+ const s = () => o(J), r = () => {
188
+ var u;
189
+ return ((u = i.selected) == null ? void 0 : u.length) === 0;
190
+ }, a = (u) => {
187
191
  if (i.selected.length === 0)
188
192
  return !1;
189
- const T = typeof f == "string" ? f : f.id;
190
- return i.selected.some((g) => g.id === T);
191
- }, d = (f, T) => {
192
- const g = e.getAnnotation(f);
193
- if (g) {
194
- const y = yt(g, t);
195
- o(y === "EDIT" ? { selected: [{ id: f, editable: !0 }], pointerEvent: T } : y === "SELECT" ? { selected: [{ id: f }], pointerEvent: T } : { selected: [], pointerEvent: T });
193
+ const T = typeof u == "string" ? u : u.id;
194
+ return i.selected.some((h) => h.id === T);
195
+ }, l = (u, T) => {
196
+ const h = t.getAnnotation(u);
197
+ if (h) {
198
+ const w = Yt(h, e);
199
+ o(w === "EDIT" ? { selected: [{ id: u, editable: !0 }], pointerEvent: T } : w === "SELECT" ? { selected: [{ id: u }], pointerEvent: T } : { selected: [], pointerEvent: T });
196
200
  } else
197
- console.warn("Invalid selection: " + f);
198
- }, h = (f, T = !0) => {
199
- const g = Array.isArray(f) ? f : [f], y = g.map((B) => e.getAnnotation(B)).filter(Boolean);
200
- o({ selected: y.map(({ id: B }) => ({ id: B, editable: T })) }), y.length !== g.length && console.warn("Invalid selection", f);
201
- }, w = (f) => {
201
+ console.warn("Invalid selection: " + u);
202
+ }, d = (u, T = !0) => {
203
+ const h = Array.isArray(u) ? u : [u], w = h.map((B) => t.getAnnotation(B)).filter(Boolean);
204
+ o({ selected: w.map(({ id: B }) => ({ id: B, editable: T })) }), w.length !== h.length && console.warn("Invalid selection", u);
205
+ }, x = (u) => {
202
206
  if (i.selected.length === 0)
203
207
  return !1;
204
208
  const { selected: T } = i;
205
- T.filter(({ id: g }) => f.includes(g)).length > 0 && o({ selected: T.filter(({ id: g }) => !f.includes(g)) });
209
+ T.filter(({ id: h }) => u.includes(h)).length > 0 && o({ selected: T.filter(({ id: h }) => !u.includes(h)) });
206
210
  };
207
- return e.observe(({ changes: f }) => w((f.deleted || []).map((T) => T.id))), {
211
+ return t.observe(({ changes: u }) => x((u.deleted || []).map((T) => T.id))), {
208
212
  clear: s,
209
- clickSelect: d,
213
+ clickSelect: l,
210
214
  get selected() {
211
215
  return i ? [...i.selected] : null;
212
216
  },
213
217
  get pointerEvent() {
214
218
  return i ? i.pointerEvent : null;
215
219
  },
216
- isEmpty: a,
217
- isSelected: r,
218
- setSelected: h,
220
+ isEmpty: r,
221
+ isSelected: a,
222
+ setSelected: d,
219
223
  subscribe: n
220
224
  };
221
- }, yt = (e, t) => typeof t == "function" ? t(e) || "EDIT" : t || "EDIT", Et = [];
222
- for (let e = 0; e < 256; ++e)
223
- Et.push((e + 256).toString(16).slice(1));
225
+ }, Yt = (t, e) => typeof e == "function" ? e(t) || "EDIT" : e || "EDIT", Dt = [];
226
+ for (let t = 0; t < 256; ++t)
227
+ Dt.push((t + 256).toString(16).slice(1));
224
228
  typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
225
- const vt = (e, t) => {
226
- const n = new Set(e.bodies.map((o) => o.id));
227
- return t.bodies.filter((o) => !n.has(o.id));
228
- }, St = (e, t) => {
229
+ const Ut = (t, e) => {
229
230
  const n = new Set(t.bodies.map((o) => o.id));
230
231
  return e.bodies.filter((o) => !n.has(o.id));
231
- }, Tt = (e, t) => t.bodies.map((n) => {
232
- const o = e.bodies.find((i) => i.id === n.id);
232
+ }, It = (t, e) => {
233
+ const n = new Set(e.bodies.map((o) => o.id));
234
+ return t.bodies.filter((o) => !n.has(o.id));
235
+ }, Vt = (t, e) => e.bodies.map((n) => {
236
+ const o = t.bodies.find((i) => i.id === n.id);
233
237
  return { newBody: n, oldBody: o && !U(o, n) ? o : void 0 };
234
- }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), Bt = (e, t) => !U(e.target, t.target), ot = (e, t) => {
235
- const n = vt(e, t), o = St(e, t), i = Tt(e, t);
238
+ }).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), _t = (t, e) => !U(t.target, e.target), lt = (t, e) => {
239
+ const n = Ut(t, e), o = It(t, e), i = Vt(t, e);
236
240
  return {
237
- oldValue: e,
238
- newValue: t,
241
+ oldValue: t,
242
+ newValue: e,
239
243
  bodiesCreated: n.length > 0 ? n : void 0,
240
244
  bodiesDeleted: o.length > 0 ? o : void 0,
241
245
  bodiesUpdated: i.length > 0 ? i : void 0,
242
- targetUpdated: Bt(e, t) ? { oldTarget: e.target, newTarget: t.target } : void 0
246
+ targetUpdated: _t(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
243
247
  };
244
248
  };
245
- var L = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e))(L || {});
246
- const Mt = (e, t) => {
249
+ var O = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t))(O || {});
250
+ const kt = (t, e) => {
247
251
  var n, o;
248
- const { changes: i, origin: s } = t;
249
- if (!(!e.options.origin || e.options.origin === s))
252
+ const { changes: i, origin: s } = e;
253
+ if (!(!t.options.origin || t.options.origin === s))
250
254
  return !1;
251
- if (e.options.ignore) {
252
- const { ignore: a } = e.options, r = (d) => d && d.length > 0;
253
- if (!(r(i.created) || r(i.deleted))) {
254
- const d = (n = i.updated) == null ? void 0 : n.some((w) => r(w.bodiesCreated) || r(w.bodiesDeleted) || r(w.bodiesUpdated)), h = (o = i.updated) == null ? void 0 : o.some((w) => w.targetUpdated);
255
- if (a === "BODY_ONLY" && d && !h || a === "TARGET_ONLY" && h && !d)
255
+ if (t.options.ignore) {
256
+ const { ignore: r } = t.options, a = (l) => l && l.length > 0;
257
+ if (!(a(i.created) || a(i.deleted))) {
258
+ const l = (n = i.updated) == null ? void 0 : n.some((x) => a(x.bodiesCreated) || a(x.bodiesDeleted) || a(x.bodiesUpdated)), d = (o = i.updated) == null ? void 0 : o.some((x) => x.targetUpdated);
259
+ if (r === "BODY_ONLY" && l && !d || r === "TARGET_ONLY" && d && !l)
256
260
  return !1;
257
261
  }
258
262
  }
259
- if (e.options.annotations) {
260
- const a = /* @__PURE__ */ new Set([
261
- ...(i.created || []).map((r) => r.id),
262
- ...(i.deleted || []).map((r) => r.id),
263
- ...(i.updated || []).map(({ oldValue: r }) => r.id)
263
+ if (t.options.annotations) {
264
+ const r = /* @__PURE__ */ new Set([
265
+ ...(i.created || []).map((a) => a.id),
266
+ ...(i.deleted || []).map((a) => a.id),
267
+ ...(i.updated || []).map(({ oldValue: a }) => a.id)
264
268
  ]);
265
- return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((r) => a.has(r));
269
+ return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((a) => r.has(a));
266
270
  } else
267
271
  return !0;
268
- }, Ct = (e, t) => {
269
- const n = new Set((e.created || []).map((f) => f.id)), o = new Set((e.updated || []).map(({ newValue: f }) => f.id)), i = new Set((t.created || []).map((f) => f.id)), s = new Set((t.deleted || []).map((f) => f.id)), a = new Set((t.updated || []).map(({ oldValue: f }) => f.id)), r = new Set((t.updated || []).filter(({ oldValue: f }) => n.has(f.id) || o.has(f.id)).map(({ oldValue: f }) => f.id)), d = [
270
- ...(e.created || []).filter((f) => !s.has(f.id)).map((f) => a.has(f.id) ? t.updated.find(({ oldValue: T }) => T.id === f.id).newValue : f),
271
- ...t.created || []
272
- ], h = [
273
- ...(e.deleted || []).filter((f) => !i.has(f.id)),
274
- ...(t.deleted || []).filter((f) => !n.has(f.id))
275
- ], w = [
276
- ...(e.updated || []).filter(({ newValue: f }) => !s.has(f.id)).map((f) => {
277
- const { oldValue: T, newValue: g } = f;
278
- if (a.has(g.id)) {
279
- const y = t.updated.find((B) => B.oldValue.id === g.id).newValue;
280
- return ot(T, y);
272
+ }, Nt = (t, e) => {
273
+ const n = new Set((t.created || []).map((u) => u.id)), o = new Set((t.updated || []).map(({ newValue: u }) => u.id)), i = new Set((e.created || []).map((u) => u.id)), s = new Set((e.deleted || []).map((u) => u.id)), r = new Set((e.updated || []).map(({ oldValue: u }) => u.id)), a = new Set((e.updated || []).filter(({ oldValue: u }) => n.has(u.id) || o.has(u.id)).map(({ oldValue: u }) => u.id)), l = [
274
+ ...(t.created || []).filter((u) => !s.has(u.id)).map((u) => r.has(u.id) ? e.updated.find(({ oldValue: T }) => T.id === u.id).newValue : u),
275
+ ...e.created || []
276
+ ], d = [
277
+ ...(t.deleted || []).filter((u) => !i.has(u.id)),
278
+ ...(e.deleted || []).filter((u) => !n.has(u.id))
279
+ ], x = [
280
+ ...(t.updated || []).filter(({ newValue: u }) => !s.has(u.id)).map((u) => {
281
+ const { oldValue: T, newValue: h } = u;
282
+ if (r.has(h.id)) {
283
+ const w = e.updated.find((B) => B.oldValue.id === h.id).newValue;
284
+ return lt(T, w);
281
285
  } else
282
- return f;
286
+ return u;
283
287
  }),
284
- ...(t.updated || []).filter(({ oldValue: f }) => !r.has(f.id))
288
+ ...(e.updated || []).filter(({ oldValue: u }) => !a.has(u.id))
285
289
  ];
286
- return { created: d, deleted: h, updated: w };
287
- }, Lt = (e) => e.id !== void 0, Rt = () => {
288
- const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = [], o = (p, x = {}) => n.push({ onChange: p, options: x }), i = (p) => {
289
- const x = n.findIndex((b) => b.onChange == p);
290
- x > -1 && n.splice(x, 1);
291
- }, s = (p, x) => {
292
- const b = {
293
- origin: p,
290
+ return { created: l, deleted: d, updated: x };
291
+ }, Pt = (t) => t.id !== void 0, zt = () => {
292
+ const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (g, y = {}) => n.push({ onChange: g, options: y }), i = (g) => {
293
+ const y = n.findIndex((A) => A.onChange == g);
294
+ y > -1 && n.splice(y, 1);
295
+ }, s = (g, y) => {
296
+ const A = {
297
+ origin: g,
294
298
  changes: {
295
- created: x.created || [],
296
- updated: x.updated || [],
297
- deleted: x.deleted || []
299
+ created: y.created || [],
300
+ updated: y.updated || [],
301
+ deleted: y.deleted || []
298
302
  },
299
- state: [...e.values()]
303
+ state: [...t.values()]
300
304
  };
301
- n.forEach((S) => {
302
- Mt(S, b) && S.onChange(b);
305
+ n.forEach((v) => {
306
+ kt(v, A) && v.onChange(A);
303
307
  });
304
- }, a = (p, x = L.LOCAL) => {
305
- if (e.get(p.id))
306
- throw Error(`Cannot add annotation ${p.id} - exists already`);
307
- e.set(p.id, p), p.bodies.forEach((b) => t.set(b.id, p.id)), s(x, { created: [p] });
308
- }, r = (p, x) => {
309
- const b = typeof p == "string" ? x : p, S = typeof p == "string" ? p : p.id, M = e.get(S);
310
- if (M) {
311
- const R = ot(M, b);
312
- return S === b.id ? e.set(S, b) : (e.delete(S), e.set(b.id, b)), M.bodies.forEach((X) => t.delete(X.id)), b.bodies.forEach((X) => t.set(X.id, b.id)), R;
308
+ }, r = (g, y = O.LOCAL) => {
309
+ if (t.get(g.id))
310
+ throw Error(`Cannot add annotation ${g.id} - exists already`);
311
+ t.set(g.id, g), g.bodies.forEach((A) => e.set(A.id, g.id)), s(y, { created: [g] });
312
+ }, a = (g, y) => {
313
+ const A = typeof g == "string" ? y : g, v = typeof g == "string" ? g : g.id, C = t.get(v);
314
+ if (C) {
315
+ const L = lt(C, A);
316
+ return v === A.id ? t.set(v, A) : (t.delete(v), t.set(A.id, A)), C.bodies.forEach((X) => e.delete(X.id)), A.bodies.forEach((X) => e.set(X.id, A.id)), L;
313
317
  } else
314
- console.warn(`Cannot update annotation ${S} - does not exist`);
315
- }, d = (p, x = L.LOCAL, b = L.LOCAL) => {
316
- const S = Lt(x) ? b : x, M = r(p, x);
317
- M && s(S, { updated: [M] });
318
- }, h = (p, x = L.LOCAL) => {
319
- const b = p.reduce((S, M) => {
320
- const R = r(M);
321
- return R ? [...S, R] : S;
318
+ console.warn(`Cannot update annotation ${v} - does not exist`);
319
+ }, l = (g, y = O.LOCAL, A = O.LOCAL) => {
320
+ const v = Pt(y) ? A : y, C = a(g, y);
321
+ C && s(v, { updated: [C] });
322
+ }, d = (g, y = O.LOCAL) => {
323
+ const A = g.reduce((v, C) => {
324
+ const L = a(C);
325
+ return L ? [...v, L] : v;
322
326
  }, []);
323
- b.length > 0 && s(x, { updated: b });
324
- }, w = (p, x = L.LOCAL) => {
325
- const b = e.get(p.annotation);
326
- if (b) {
327
- const S = {
328
- ...b,
329
- bodies: [...b.bodies, p]
327
+ A.length > 0 && s(y, { updated: A });
328
+ }, x = (g, y = O.LOCAL) => {
329
+ const A = t.get(g.annotation);
330
+ if (A) {
331
+ const v = {
332
+ ...A,
333
+ bodies: [...A.bodies, g]
330
334
  };
331
- e.set(b.id, S), t.set(p.id, S.id), s(x, { updated: [{
332
- oldValue: b,
333
- newValue: S,
334
- bodiesCreated: [p]
335
+ t.set(A.id, v), e.set(g.id, v.id), s(y, { updated: [{
336
+ oldValue: A,
337
+ newValue: v,
338
+ bodiesCreated: [g]
335
339
  }] });
336
340
  } else
337
- console.warn(`Attempt to add body to missing annotation: ${p.annotation}`);
338
- }, f = () => [...e.values()], T = (p = L.LOCAL) => {
339
- const x = [...e.values()];
340
- e.clear(), t.clear(), s(p, { deleted: x });
341
- }, g = (p, x = !0, b = L.LOCAL) => {
342
- if (x) {
343
- const S = [...e.values()];
344
- e.clear(), t.clear(), p.forEach((M) => {
345
- e.set(M.id, M), M.bodies.forEach((R) => t.set(R.id, M.id));
346
- }), s(b, { created: p, deleted: S });
341
+ console.warn(`Attempt to add body to missing annotation: ${g.annotation}`);
342
+ }, u = () => [...t.values()], T = (g = O.LOCAL) => {
343
+ const y = [...t.values()];
344
+ t.clear(), e.clear(), s(g, { deleted: y });
345
+ }, h = (g, y = !0, A = O.LOCAL) => {
346
+ if (y) {
347
+ const v = [...t.values()];
348
+ t.clear(), e.clear(), g.forEach((C) => {
349
+ t.set(C.id, C), C.bodies.forEach((L) => e.set(L.id, C.id));
350
+ }), s(A, { created: g, deleted: v });
347
351
  } else {
348
- const S = p.reduce((M, R) => {
349
- const X = e.get(R.id);
350
- return X ? [...M, X] : M;
352
+ const v = g.reduce((C, L) => {
353
+ const X = t.get(L.id);
354
+ return X ? [...C, X] : C;
351
355
  }, []);
352
- if (S.length > 0)
353
- throw Error(`Bulk insert would overwrite the following annotations: ${S.map((M) => M.id).join(", ")}`);
354
- p.forEach((M) => {
355
- e.set(M.id, M), M.bodies.forEach((R) => t.set(R.id, M.id));
356
- }), s(b, { created: p });
356
+ if (v.length > 0)
357
+ throw Error(`Bulk insert would overwrite the following annotations: ${v.map((C) => C.id).join(", ")}`);
358
+ g.forEach((C) => {
359
+ t.set(C.id, C), C.bodies.forEach((L) => e.set(L.id, C.id));
360
+ }), s(A, { created: g });
357
361
  }
358
- }, y = (p) => {
359
- const x = typeof p == "string" ? p : p.id, b = e.get(x);
360
- if (b)
361
- return e.delete(x), b.bodies.forEach((S) => t.delete(S.id)), b;
362
- console.warn(`Attempt to delete missing annotation: ${x}`);
363
- }, B = (p, x = L.LOCAL) => {
364
- const b = y(p);
365
- b && s(x, { deleted: [b] });
366
- }, A = (p, x = L.LOCAL) => {
367
- const b = p.reduce((S, M) => {
368
- const R = y(M);
369
- return R ? [...S, R] : S;
362
+ }, w = (g) => {
363
+ const y = typeof g == "string" ? g : g.id, A = t.get(y);
364
+ if (A)
365
+ return t.delete(y), A.bodies.forEach((v) => e.delete(v.id)), A;
366
+ console.warn(`Attempt to delete missing annotation: ${y}`);
367
+ }, B = (g, y = O.LOCAL) => {
368
+ const A = w(g);
369
+ A && s(y, { deleted: [A] });
370
+ }, b = (g, y = O.LOCAL) => {
371
+ const A = g.reduce((v, C) => {
372
+ const L = w(C);
373
+ return L ? [...v, L] : v;
370
374
  }, []);
371
- b.length > 0 && s(x, { deleted: b });
372
- }, l = (p, x = L.LOCAL) => {
373
- const b = e.get(p.annotation);
374
- if (b) {
375
- const S = b.bodies.find((M) => M.id === p.id);
376
- if (S) {
377
- t.delete(S.id);
378
- const M = {
379
- ...b,
380
- bodies: b.bodies.filter((R) => R.id !== p.id)
375
+ A.length > 0 && s(y, { deleted: A });
376
+ }, c = (g, y = O.LOCAL) => {
377
+ const A = t.get(g.annotation);
378
+ if (A) {
379
+ const v = A.bodies.find((C) => C.id === g.id);
380
+ if (v) {
381
+ e.delete(v.id);
382
+ const C = {
383
+ ...A,
384
+ bodies: A.bodies.filter((L) => L.id !== g.id)
381
385
  };
382
- e.set(b.id, M), s(x, { updated: [{
383
- oldValue: b,
384
- newValue: M,
385
- bodiesDeleted: [S]
386
+ t.set(A.id, C), s(y, { updated: [{
387
+ oldValue: A,
388
+ newValue: C,
389
+ bodiesDeleted: [v]
386
390
  }] });
387
391
  } else
388
- console.warn(`Attempt to delete missing body ${p.id} from annotation ${p.annotation}`);
392
+ console.warn(`Attempt to delete missing body ${g.id} from annotation ${g.annotation}`);
389
393
  } else
390
- console.warn(`Attempt to delete body from missing annotation ${p.annotation}`);
391
- }, c = (p) => {
392
- const x = e.get(p);
393
- return x ? { ...x } : void 0;
394
- }, u = (p) => {
395
- const x = t.get(p);
396
- if (x) {
397
- const b = c(x).bodies.find((S) => S.id === p);
398
- if (b)
399
- return b;
400
- console.error(`Store integrity error: body ${p} in index, but not in annotation`);
394
+ console.warn(`Attempt to delete body from missing annotation ${g.annotation}`);
395
+ }, f = (g) => {
396
+ const y = t.get(g);
397
+ return y ? { ...y } : void 0;
398
+ }, p = (g) => {
399
+ const y = e.get(g);
400
+ if (y) {
401
+ const A = f(y).bodies.find((v) => v.id === g);
402
+ if (A)
403
+ return A;
404
+ console.error(`Store integrity error: body ${g} in index, but not in annotation`);
401
405
  } else
402
- console.warn(`Attempt to retrieve missing body: ${p}`);
403
- }, m = (p, x) => {
404
- if (p.annotation !== x.annotation)
406
+ console.warn(`Attempt to retrieve missing body: ${g}`);
407
+ }, m = (g, y) => {
408
+ if (g.annotation !== y.annotation)
405
409
  throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
406
- const b = e.get(p.annotation);
407
- if (b) {
408
- const S = b.bodies.find((R) => R.id === p.id), M = {
409
- ...b,
410
- bodies: b.bodies.map((R) => R.id === S.id ? x : R)
410
+ const A = t.get(g.annotation);
411
+ if (A) {
412
+ const v = A.bodies.find((L) => L.id === g.id), C = {
413
+ ...A,
414
+ bodies: A.bodies.map((L) => L.id === v.id ? y : L)
411
415
  };
412
- return e.set(b.id, M), S.id !== x.id && (t.delete(S.id), t.set(x.id, M.id)), {
413
- oldValue: b,
414
- newValue: M,
415
- bodiesUpdated: [{ oldBody: S, newBody: x }]
416
+ return t.set(A.id, C), v.id !== y.id && (e.delete(v.id), e.set(y.id, C.id)), {
417
+ oldValue: A,
418
+ newValue: C,
419
+ bodiesUpdated: [{ oldBody: v, newBody: y }]
416
420
  };
417
421
  } else
418
- console.warn(`Attempt to add body to missing annotation ${p.annotation}`);
419
- }, E = (p, x, b = L.LOCAL) => {
420
- const S = m(p, x);
421
- S && s(b, { updated: [S] });
422
- }, v = (p, x = L.LOCAL) => {
423
- const b = p.map((S) => m({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
424
- s(x, { updated: b });
425
- }, C = (p) => {
426
- const x = e.get(p.annotation);
427
- if (x) {
428
- const b = {
429
- ...x,
422
+ console.warn(`Attempt to add body to missing annotation ${g.annotation}`);
423
+ }, E = (g, y, A = O.LOCAL) => {
424
+ const v = m(g, y);
425
+ v && s(A, { updated: [v] });
426
+ }, S = (g, y = O.LOCAL) => {
427
+ const A = g.map((v) => m({ id: v.id, annotation: v.annotation }, v)).filter(Boolean);
428
+ s(y, { updated: A });
429
+ }, M = (g) => {
430
+ const y = t.get(g.annotation);
431
+ if (y) {
432
+ const A = {
433
+ ...y,
430
434
  target: {
431
- ...x.target,
432
- ...p
435
+ ...y.target,
436
+ ...g
433
437
  }
434
438
  };
435
- return e.set(x.id, b), {
436
- oldValue: x,
437
- newValue: b,
439
+ return t.set(y.id, A), {
440
+ oldValue: y,
441
+ newValue: A,
438
442
  targetUpdated: {
439
- oldTarget: x.target,
440
- newTarget: p
443
+ oldTarget: y.target,
444
+ newTarget: g
441
445
  }
442
446
  };
443
447
  } else
444
- console.warn(`Attempt to update target on missing annotation: ${p.annotation}`);
448
+ console.warn(`Attempt to update target on missing annotation: ${g.annotation}`);
445
449
  };
446
450
  return {
447
- addAnnotation: a,
448
- addBody: w,
449
- all: f,
450
- bulkAddAnnotation: g,
451
- bulkDeleteAnnotation: A,
452
- bulkUpdateAnnotation: h,
453
- bulkUpdateBodies: v,
454
- bulkUpdateTargets: (p, x = L.LOCAL) => {
455
- const b = p.map((S) => C(S)).filter(Boolean);
456
- b.length > 0 && s(x, { updated: b });
451
+ addAnnotation: r,
452
+ addBody: x,
453
+ all: u,
454
+ bulkAddAnnotation: h,
455
+ bulkDeleteAnnotation: b,
456
+ bulkUpdateAnnotation: d,
457
+ bulkUpdateBodies: S,
458
+ bulkUpdateTargets: (g, y = O.LOCAL) => {
459
+ const A = g.map((v) => M(v)).filter(Boolean);
460
+ A.length > 0 && s(y, { updated: A });
457
461
  },
458
462
  clear: T,
459
463
  deleteAnnotation: B,
460
- deleteBody: l,
461
- getAnnotation: c,
462
- getBody: u,
464
+ deleteBody: c,
465
+ getAnnotation: f,
466
+ getBody: p,
463
467
  observe: o,
464
468
  unobserve: i,
465
- updateAnnotation: d,
469
+ updateAnnotation: l,
466
470
  updateBody: E,
467
- updateTarget: (p, x = L.LOCAL) => {
468
- const b = C(p);
469
- b && s(x, { updated: [b] });
471
+ updateTarget: (g, y = O.LOCAL) => {
472
+ const A = M(g);
473
+ A && s(y, { updated: [A] });
470
474
  }
471
475
  };
472
476
  };
473
- let Ot = () => ({
474
- emit(e, ...t) {
475
- for (let n = 0, o = this.events[e] || [], i = o.length; n < i; n++)
476
- o[n](...t);
477
+ let Ht = () => ({
478
+ emit(t, ...e) {
479
+ for (let n = 0, o = this.events[t] || [], i = o.length; n < i; n++)
480
+ o[n](...e);
477
481
  },
478
482
  events: {},
479
- on(e, t) {
483
+ on(t, e) {
480
484
  var n;
481
- return ((n = this.events)[e] || (n[e] = [])).push(t), () => {
485
+ return ((n = this.events)[t] || (n[t] = [])).push(e), () => {
482
486
  var o;
483
- this.events[e] = (o = this.events[e]) == null ? void 0 : o.filter((i) => t !== i);
487
+ this.events[t] = (o = this.events[t]) == null ? void 0 : o.filter((i) => e !== i);
484
488
  };
485
489
  }
486
490
  });
487
- const Xt = 250, Yt = (e) => {
488
- const t = Ot(), n = [];
491
+ const $t = 250, Ft = (t) => {
492
+ const e = Ht(), n = [];
489
493
  let o = -1, i = !1, s = 0;
490
- const a = (g) => {
494
+ const r = (h) => {
491
495
  if (!i) {
492
- const { changes: y } = g, B = performance.now();
493
- if (B - s > Xt)
494
- n.splice(o + 1), n.push(y), o = n.length - 1;
496
+ const { changes: w } = h, B = performance.now();
497
+ if (B - s > $t)
498
+ n.splice(o + 1), n.push(w), o = n.length - 1;
495
499
  else {
496
- const A = n.length - 1;
497
- n[A] = Ct(n[A], y);
500
+ const b = n.length - 1;
501
+ n[b] = Nt(n[b], w);
498
502
  }
499
503
  s = B;
500
504
  }
501
505
  i = !1;
502
506
  };
503
- e.observe(a, { origin: L.LOCAL });
504
- const r = (g) => g && g.length > 0 && e.bulkDeleteAnnotation(g), d = (g) => g && g.length > 0 && e.bulkAddAnnotation(g, !1), h = (g) => g && g.length > 0 && e.bulkUpdateAnnotation(g.map(({ oldValue: y }) => y)), w = (g) => g && g.length > 0 && e.bulkUpdateAnnotation(g.map(({ newValue: y }) => y)), f = (g) => g && g.length > 0 && e.bulkAddAnnotation(g, !1), T = (g) => g && g.length > 0 && e.bulkDeleteAnnotation(g);
507
+ t.observe(r, { origin: O.LOCAL });
508
+ const a = (h) => h && h.length > 0 && t.bulkDeleteAnnotation(h), l = (h) => h && h.length > 0 && t.bulkAddAnnotation(h, !1), d = (h) => h && h.length > 0 && t.bulkUpdateAnnotation(h.map(({ oldValue: w }) => w)), x = (h) => h && h.length > 0 && t.bulkUpdateAnnotation(h.map(({ newValue: w }) => w)), u = (h) => h && h.length > 0 && t.bulkAddAnnotation(h, !1), T = (h) => h && h.length > 0 && t.bulkDeleteAnnotation(h);
505
509
  return {
506
510
  canRedo: () => n.length - 1 > o,
507
511
  canUndo: () => o > -1,
508
- destroy: () => e.unobserve(a),
509
- on: (g, y) => t.on(g, y),
512
+ destroy: () => t.unobserve(r),
513
+ on: (h, w) => e.on(h, w),
510
514
  redo: () => {
511
515
  if (n.length - 1 > o) {
512
516
  i = !0;
513
- const { created: g, updated: y, deleted: B } = n[o + 1];
514
- d(g), w(y), T(B), t.emit("redo", n[o + 1]), o += 1;
517
+ const { created: h, updated: w, deleted: B } = n[o + 1];
518
+ l(h), x(w), T(B), e.emit("redo", n[o + 1]), o += 1;
515
519
  }
516
520
  },
517
521
  undo: () => {
518
522
  if (o > -1) {
519
523
  i = !0;
520
- const { created: g, updated: y, deleted: B } = n[o];
521
- r(g), h(y), f(B), t.emit("undo", n[o]), o -= 1;
524
+ const { created: h, updated: w, deleted: B } = n[o];
525
+ a(h), d(w), u(B), e.emit("undo", n[o]), o -= 1;
522
526
  }
523
527
  }
524
528
  };
525
- }, Ut = () => {
526
- const { subscribe: e, set: t } = J([]);
529
+ }, Wt = () => {
530
+ const { subscribe: t, set: e } = tt([]);
527
531
  return {
528
- subscribe: e,
529
- set: t
532
+ subscribe: t,
533
+ set: e
530
534
  };
531
- }, Dt = (e, t, n, o) => {
532
- const { store: i, selection: s, hover: a, viewport: r } = e, d = /* @__PURE__ */ new Map();
533
- let h = [], w, f;
534
- const T = (l, c) => {
535
- d.has(l) ? d.get(l).push(c) : d.set(l, [c]);
536
- }, g = (l, c) => {
537
- const u = d.get(l);
538
- u && u.indexOf(c) > 0 && u.splice(u.indexOf(c), 1);
539
- }, y = (l, c, u) => {
540
- d.has(l) && setTimeout(() => {
541
- d.get(l).forEach((m) => {
535
+ }, qt = (t, e, n, o) => {
536
+ const { store: i, selection: s, hover: r, viewport: a } = t, l = /* @__PURE__ */ new Map();
537
+ let d = [], x, u;
538
+ const T = (c, f) => {
539
+ l.has(c) ? l.get(c).push(f) : l.set(c, [f]);
540
+ }, h = (c, f) => {
541
+ const p = l.get(c);
542
+ p && p.indexOf(f) > 0 && p.splice(p.indexOf(f), 1);
543
+ }, w = (c, f, p) => {
544
+ l.has(c) && setTimeout(() => {
545
+ l.get(c).forEach((m) => {
542
546
  if (n) {
543
- const E = Array.isArray(c) ? c.map((C) => n.serialize(C)) : n.serialize(c), v = u ? u instanceof PointerEvent ? u : n.serialize(u) : void 0;
544
- m(E, v);
547
+ const E = Array.isArray(f) ? f.map((M) => n.serialize(M)) : n.serialize(f), S = p ? p instanceof PointerEvent ? p : n.serialize(p) : void 0;
548
+ m(E, S);
545
549
  } else
546
- m(c, u);
550
+ m(f, p);
547
551
  });
548
552
  }, 1);
549
553
  }, B = () => {
550
- const { selected: l } = s, c = (l || []).map(({ id: u }) => i.getAnnotation(u));
551
- c.forEach((u) => {
552
- const m = h.find((E) => E.id === u.id);
553
- (!m || !U(m, u)) && y("updateAnnotation", u, m);
554
- }), h = h.map((u) => c.find(({ id: E }) => E === u.id) || u);
554
+ const { selected: c } = s, f = (c || []).map(({ id: p }) => i.getAnnotation(p));
555
+ f.forEach((p) => {
556
+ const m = d.find((E) => E.id === p.id);
557
+ (!m || !U(m, p)) && w("updateAnnotation", p, m);
558
+ }), d = d.map((p) => f.find(({ id: E }) => E === p.id) || p);
555
559
  };
556
- s.subscribe(({ selected: l }) => {
557
- if (!(h.length === 0 && l.length === 0)) {
558
- if (h.length === 0 && l.length > 0)
559
- h = l.map(({ id: c }) => i.getAnnotation(c));
560
- else if (h.length > 0 && l.length === 0)
561
- h.forEach((c) => {
562
- const u = i.getAnnotation(c.id);
563
- u && !U(u, c) && y("updateAnnotation", u, c);
564
- }), h = [];
560
+ s.subscribe(({ selected: c }) => {
561
+ if (!(d.length === 0 && c.length === 0)) {
562
+ if (d.length === 0 && c.length > 0)
563
+ d = c.map(({ id: f }) => i.getAnnotation(f));
564
+ else if (d.length > 0 && c.length === 0)
565
+ d.forEach((f) => {
566
+ const p = i.getAnnotation(f.id);
567
+ p && !U(p, f) && w("updateAnnotation", p, f);
568
+ }), d = [];
565
569
  else {
566
- const c = new Set(h.map((m) => m.id)), u = new Set(l.map(({ id: m }) => m));
567
- h.filter((m) => !u.has(m.id)).forEach((m) => {
570
+ const f = new Set(d.map((m) => m.id)), p = new Set(c.map(({ id: m }) => m));
571
+ d.filter((m) => !p.has(m.id)).forEach((m) => {
568
572
  const E = i.getAnnotation(m.id);
569
- E && !U(E, m) && y("updateAnnotation", E, m);
570
- }), h = [
573
+ E && !U(E, m) && w("updateAnnotation", E, m);
574
+ }), d = [
571
575
  // Remove annotations that were deselected
572
- ...h.filter((m) => u.has(m.id)),
576
+ ...d.filter((m) => p.has(m.id)),
573
577
  // Add editable annotations that were selected
574
- ...l.filter(({ id: m }) => !c.has(m)).map(({ id: m }) => i.getAnnotation(m))
578
+ ...c.filter(({ id: m }) => !f.has(m)).map(({ id: m }) => i.getAnnotation(m))
575
579
  ];
576
580
  }
577
- y("selectionChanged", h);
581
+ w("selectionChanged", d);
578
582
  }
579
- }), a.subscribe((l) => {
580
- !w && l ? y("mouseEnterAnnotation", i.getAnnotation(l)) : w && !l ? y("mouseLeaveAnnotation", i.getAnnotation(w)) : w && l && (y("mouseLeaveAnnotation", i.getAnnotation(w)), y("mouseEnterAnnotation", i.getAnnotation(l))), w = l;
581
- }), r == null || r.subscribe((l) => y("viewportIntersect", l.map((c) => i.getAnnotation(c)))), i.observe((l) => {
582
- o && (f && clearTimeout(f), f = setTimeout(B, 1e3));
583
- const { created: c, deleted: u } = l.changes;
584
- (c || []).forEach((m) => y("createAnnotation", m)), (u || []).forEach((m) => y("deleteAnnotation", m)), (l.changes.updated || []).filter((m) => [
583
+ }), r.subscribe((c) => {
584
+ !x && c ? w("mouseEnterAnnotation", i.getAnnotation(c)) : x && !c ? w("mouseLeaveAnnotation", i.getAnnotation(x)) : x && c && (w("mouseLeaveAnnotation", i.getAnnotation(x)), w("mouseEnterAnnotation", i.getAnnotation(c))), x = c;
585
+ }), a == null || a.subscribe((c) => w("viewportIntersect", c.map((f) => i.getAnnotation(f)))), i.observe((c) => {
586
+ o && (u && clearTimeout(u), u = setTimeout(B, 1e3));
587
+ const { created: f, deleted: p } = c.changes;
588
+ (f || []).forEach((m) => w("createAnnotation", m)), (p || []).forEach((m) => w("deleteAnnotation", m)), (c.changes.updated || []).filter((m) => [
585
589
  ...m.bodiesCreated || [],
586
590
  ...m.bodiesDeleted || [],
587
591
  ...m.bodiesUpdated || []
588
592
  ].length > 0).forEach(({ oldValue: m, newValue: E }) => {
589
- const v = h.find((C) => C.id === m.id) || m;
590
- h = h.map((C) => C.id === m.id ? E : C), y("updateAnnotation", E, v);
593
+ const S = d.find((M) => M.id === m.id) || m;
594
+ d = d.map((M) => M.id === m.id ? E : M), w("updateAnnotation", E, S);
591
595
  });
592
- }, { origin: L.LOCAL }), i.observe((l) => {
593
- if (h) {
594
- const c = new Set(h.map((m) => m.id)), u = (l.changes.updated || []).filter(({ newValue: m }) => c.has(m.id)).map(({ newValue: m }) => m);
595
- u.length > 0 && (h = h.map((m) => u.find((v) => v.id === m.id) || m));
596
+ }, { origin: O.LOCAL }), i.observe((c) => {
597
+ if (d) {
598
+ const f = new Set(d.map((m) => m.id)), p = (c.changes.updated || []).filter(({ newValue: m }) => f.has(m.id)).map(({ newValue: m }) => m);
599
+ p.length > 0 && (d = d.map((m) => p.find((S) => S.id === m.id) || m));
596
600
  }
597
- }, { origin: L.REMOTE });
598
- const A = (l) => (c) => {
599
- const { created: u, deleted: m, updated: E } = c;
600
- (u || []).forEach((v) => y("createAnnotation", v)), (m || []).forEach((v) => y("deleteAnnotation", v)), l ? (E || []).forEach((v) => y("updateAnnotation", v.oldValue, v.newValue)) : (E || []).forEach((v) => y("updateAnnotation", v.newValue, v.oldValue));
601
+ }, { origin: O.REMOTE });
602
+ const b = (c) => (f) => {
603
+ const { created: p, deleted: m, updated: E } = f;
604
+ (p || []).forEach((S) => w("createAnnotation", S)), (m || []).forEach((S) => w("deleteAnnotation", S)), c ? (E || []).forEach((S) => w("updateAnnotation", S.oldValue, S.newValue)) : (E || []).forEach((S) => w("updateAnnotation", S.newValue, S.oldValue));
601
605
  };
602
- return t.on("undo", A(!0)), t.on("redo", A(!1)), { on: T, off: g, emit: y };
603
- }, It = (e) => (t) => t.reduce((n, o) => {
604
- const { parsed: i, error: s } = e.parse(o);
606
+ return e.on("undo", b(!0)), e.on("redo", b(!1)), { on: T, off: h, emit: w };
607
+ }, jt = (t) => (e) => e.reduce((n, o) => {
608
+ const { parsed: i, error: s } = t.parse(o);
605
609
  return s ? {
606
610
  parsed: n.parsed,
607
611
  failed: [...n.failed, o]
@@ -611,137 +615,196 @@ const Xt = 250, Yt = (e) => {
611
615
  } : {
612
616
  ...n
613
617
  };
614
- }, { parsed: [], failed: [] }), Vt = (e, t, n) => {
615
- const { store: o, selection: i } = e, s = (A) => {
618
+ }, { parsed: [], failed: [] }), Qt = (t, e, n) => {
619
+ const { store: o, selection: i } = t, s = (b) => {
616
620
  if (n) {
617
- const { parsed: l, error: c } = n.parse(A);
618
- l ? o.addAnnotation(l, L.REMOTE) : console.error(c);
621
+ const { parsed: c, error: f } = n.parse(b);
622
+ c ? o.addAnnotation(c, O.REMOTE) : console.error(f);
619
623
  } else
620
- o.addAnnotation(A, L.REMOTE);
621
- }, a = () => i.clear(), r = () => o.clear(), d = (A) => {
622
- const l = o.getAnnotation(A);
623
- return n && l ? n.serialize(l) : l;
624
- }, h = () => n ? o.all().map(n.serialize) : o.all(), w = () => {
625
- var A;
626
- const l = (((A = i.selected) == null ? void 0 : A.map((c) => c.id)) || []).map((c) => o.getAnnotation(c)).filter(Boolean);
627
- return n ? l.map(n.serialize) : l;
628
- }, f = (A) => fetch(A).then((l) => l.json()).then((l) => (g(l), l)), T = (A) => {
629
- if (typeof A == "string") {
630
- const l = o.getAnnotation(A);
631
- if (o.deleteAnnotation(A), l)
632
- return n ? n.serialize(l) : l;
624
+ o.addAnnotation(b, O.REMOTE);
625
+ }, r = () => i.clear(), a = () => o.clear(), l = (b) => {
626
+ const c = o.getAnnotation(b);
627
+ return n && c ? n.serialize(c) : c;
628
+ }, d = () => n ? o.all().map(n.serialize) : o.all(), x = () => {
629
+ var b;
630
+ const c = (((b = i.selected) == null ? void 0 : b.map((f) => f.id)) || []).map((f) => o.getAnnotation(f)).filter(Boolean);
631
+ return n ? c.map(n.serialize) : c;
632
+ }, u = (b) => fetch(b).then((c) => c.json()).then((c) => (h(c), c)), T = (b) => {
633
+ if (typeof b == "string") {
634
+ const c = o.getAnnotation(b);
635
+ if (o.deleteAnnotation(b), c)
636
+ return n ? n.serialize(c) : c;
633
637
  } else {
634
- const l = n ? n.parse(A).parsed : A;
635
- if (l)
636
- return o.deleteAnnotation(l), A;
638
+ const c = n ? n.parse(b).parsed : b;
639
+ if (c)
640
+ return o.deleteAnnotation(c), b;
637
641
  }
638
- }, g = (A) => {
642
+ }, h = (b) => {
639
643
  if (n) {
640
- const { parsed: l, failed: c } = It(n)(A);
641
- c.length > 0 && console.warn(`Discarded ${c.length} invalid annotations`, c), o.bulkAddAnnotation(l, !0, L.REMOTE);
644
+ const { parsed: c, failed: f } = jt(n)(b);
645
+ f.length > 0 && console.warn(`Discarded ${f.length} invalid annotations`, f), o.bulkAddAnnotation(c, !0, O.REMOTE);
642
646
  } else
643
- o.bulkAddAnnotation(A, !0, L.REMOTE);
644
- }, y = (A) => {
645
- A ? i.setSelected(A) : i.clear();
646
- }, B = (A) => {
647
+ o.bulkAddAnnotation(b, !0, O.REMOTE);
648
+ }, w = (b) => {
649
+ b ? i.setSelected(b) : i.clear();
650
+ }, B = (b) => {
647
651
  if (n) {
648
- const l = n.parse(A).parsed, c = n.serialize(o.getAnnotation(l.id));
649
- return o.updateAnnotation(l), c;
652
+ const c = n.parse(b).parsed, f = n.serialize(o.getAnnotation(c.id));
653
+ return o.updateAnnotation(c), f;
650
654
  } else {
651
- const l = o.getAnnotation(A.id);
652
- return o.updateAnnotation(A), l;
655
+ const c = o.getAnnotation(b.id);
656
+ return o.updateAnnotation(b), c;
653
657
  }
654
658
  };
655
659
  return {
656
660
  addAnnotation: s,
657
- cancelSelected: a,
658
- canRedo: t.canRedo,
659
- canUndo: t.canUndo,
660
- clearAnnotations: r,
661
- getAnnotationById: d,
662
- getAnnotations: h,
663
- getSelected: w,
664
- loadAnnotations: f,
665
- redo: t.redo,
661
+ cancelSelected: r,
662
+ canRedo: e.canRedo,
663
+ canUndo: e.canUndo,
664
+ clearAnnotations: a,
665
+ getAnnotationById: l,
666
+ getAnnotations: d,
667
+ getSelected: x,
668
+ loadAnnotations: u,
669
+ redo: e.redo,
666
670
  removeAnnotation: T,
667
- setAnnotations: g,
668
- setSelected: y,
669
- undo: t.undo,
671
+ setAnnotations: h,
672
+ setSelected: w,
673
+ undo: e.undo,
670
674
  updateAnnotation: B
671
675
  };
672
676
  };
673
- let _t = (e) => crypto.getRandomValues(new Uint8Array(e)), kt = (e, t, n) => {
674
- let o = (2 << Math.log(e.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * t / e.length);
675
- return (s = t) => {
676
- let a = "";
677
+ let Gt = (t) => crypto.getRandomValues(new Uint8Array(t)), Jt = (t, e, n) => {
678
+ let o = (2 << Math.log(t.length - 1) / Math.LN2) - 1, i = -~(1.6 * o * e / t.length);
679
+ return (s = e) => {
680
+ let r = "";
677
681
  for (; ; ) {
678
- let r = n(i), d = i;
679
- for (; d--; )
680
- if (a += e[r[d] & o] || "", a.length === s)
681
- return a;
682
+ let a = n(i), l = i;
683
+ for (; l--; )
684
+ if (r += t[a[l] & o] || "", r.length === s)
685
+ return r;
686
+ }
687
+ };
688
+ }, Kt = (t, e = 21) => Jt(t, e, Gt), Zt = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce((e, n) => (n &= 63, n < 36 ? e += n.toString(36) : n < 62 ? e += (n - 26).toString(36).toUpperCase() : n > 62 ? e += "-" : e += "_", e), "");
689
+ const te = () => ({ isGuest: !0, id: Kt("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), ee = (t) => {
690
+ const e = JSON.stringify(t);
691
+ let n = 0;
692
+ for (let o = 0, i = e.length; o < i; o++) {
693
+ let s = e.charCodeAt(o);
694
+ n = (n << 5) - n + s, n |= 0;
695
+ }
696
+ return `${n}`;
697
+ }, dt = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, ne = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
698
+ const { id: o, type: i, purpose: s, value: r, created: a, creator: l, ...d } = n;
699
+ return {
700
+ id: o || `temp-${ee(n)}`,
701
+ annotation: e,
702
+ type: i,
703
+ purpose: s,
704
+ value: r,
705
+ created: a ? new Date(a) : void 0,
706
+ creator: dt(l),
707
+ ...d
708
+ };
709
+ }), oe = (t) => t.map((e) => {
710
+ var n, o;
711
+ const i = { ...e };
712
+ return delete i.annotation, (n = i.id) != null && n.startsWith("temp-") && delete i.id, { ...i, created: (o = i.created) == null ? void 0 : o.toISOString() };
713
+ });
714
+ Zt();
715
+ const D = (t, e) => {
716
+ const { start: n, end: o } = t.selector, i = t.selector.offsetReference ? t.selector.offsetReference : e;
717
+ if (!i)
718
+ return t;
719
+ const s = document.createNodeIterator(e, NodeFilter.SHOW_TEXT);
720
+ let r = 0, a = document.createRange(), l = s.nextNode();
721
+ l === null && console.error("Could not revive annotation target. Content missing.");
722
+ let d = !i;
723
+ for (; l !== null; ) {
724
+ const x = l.textContent.length;
725
+ if (!d && i && (d = i.contains(l)), d) {
726
+ if (r + x > n) {
727
+ a.setStart(l, n - r);
728
+ break;
729
+ }
730
+ r += x;
731
+ }
732
+ l = s.nextNode();
733
+ }
734
+ for (; l !== null; ) {
735
+ const x = l.textContent.length;
736
+ if (r + x > o) {
737
+ a.setEnd(l, o - r);
738
+ break;
739
+ }
740
+ r += x, l = s.nextNode();
741
+ }
742
+ return {
743
+ ...t,
744
+ selector: {
745
+ ...t.selector,
746
+ range: a
682
747
  }
683
748
  };
684
- }, Nt = (e, t = 21) => kt(e, t, _t), Pt = (e = 21) => crypto.getRandomValues(new Uint8Array(e)).reduce((t, n) => (n &= 63, n < 36 ? t += n.toString(36) : n < 62 ? t += (n - 26).toString(36).toUpperCase() : n > 62 ? t += "-" : t += "_", t), "");
685
- const zt = () => ({ isGuest: !0, id: Nt("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() });
686
- Pt();
687
- function Ht(e, t, n, o, i) {
688
- it(e, t, n || 0, o || e.length - 1, i || Ft);
749
+ };
750
+ function ie(t, e, n, o, i) {
751
+ ut(t, e, n || 0, o || t.length - 1, i || se);
689
752
  }
690
- function it(e, t, n, o, i) {
753
+ function ut(t, e, n, o, i) {
691
754
  for (; o > n; ) {
692
755
  if (o - n > 600) {
693
- var s = o - n + 1, a = t - n + 1, r = Math.log(s), d = 0.5 * Math.exp(2 * r / 3), h = 0.5 * Math.sqrt(r * d * (s - d) / s) * (a - s / 2 < 0 ? -1 : 1), w = Math.max(n, Math.floor(t - a * d / s + h)), f = Math.min(o, Math.floor(t + (s - a) * d / s + h));
694
- it(e, t, w, f, i);
756
+ var s = o - n + 1, r = e - n + 1, a = Math.log(s), l = 0.5 * Math.exp(2 * a / 3), d = 0.5 * Math.sqrt(a * l * (s - l) / s) * (r - s / 2 < 0 ? -1 : 1), x = Math.max(n, Math.floor(e - r * l / s + d)), u = Math.min(o, Math.floor(e + (s - r) * l / s + d));
757
+ ut(t, e, x, u, i);
695
758
  }
696
- var T = e[t], g = n, y = o;
697
- for (k(e, n, t), i(e[o], T) > 0 && k(e, n, o); g < y; ) {
698
- for (k(e, g, y), g++, y--; i(e[g], T) < 0; )
699
- g++;
700
- for (; i(e[y], T) > 0; )
701
- y--;
759
+ var T = t[e], h = n, w = o;
760
+ for (N(t, n, e), i(t[o], T) > 0 && N(t, n, o); h < w; ) {
761
+ for (N(t, h, w), h++, w--; i(t[h], T) < 0; )
762
+ h++;
763
+ for (; i(t[w], T) > 0; )
764
+ w--;
702
765
  }
703
- i(e[n], T) === 0 ? k(e, n, y) : (y++, k(e, y, o)), y <= t && (n = y + 1), t <= y && (o = y - 1);
766
+ i(t[n], T) === 0 ? N(t, n, w) : (w++, N(t, w, o)), w <= e && (n = w + 1), e <= w && (o = w - 1);
704
767
  }
705
768
  }
706
- function k(e, t, n) {
707
- var o = e[t];
708
- e[t] = e[n], e[n] = o;
769
+ function N(t, e, n) {
770
+ var o = t[e];
771
+ t[e] = t[n], t[n] = o;
709
772
  }
710
- function Ft(e, t) {
711
- return e < t ? -1 : e > t ? 1 : 0;
773
+ function se(t, e) {
774
+ return t < e ? -1 : t > e ? 1 : 0;
712
775
  }
713
- class $t {
714
- constructor(t = 9) {
715
- this._maxEntries = Math.max(4, t), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
776
+ class re {
777
+ constructor(e = 9) {
778
+ this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
716
779
  }
717
780
  all() {
718
781
  return this._all(this.data, []);
719
782
  }
720
- search(t) {
783
+ search(e) {
721
784
  let n = this.data;
722
785
  const o = [];
723
- if (!H(t, n))
786
+ if (!j(e, n))
724
787
  return o;
725
788
  const i = this.toBBox, s = [];
726
789
  for (; n; ) {
727
- for (let a = 0; a < n.children.length; a++) {
728
- const r = n.children[a], d = n.leaf ? i(r) : r;
729
- H(t, d) && (n.leaf ? o.push(r) : K(t, d) ? this._all(r, o) : s.push(r));
790
+ for (let r = 0; r < n.children.length; r++) {
791
+ const a = n.children[r], l = n.leaf ? i(a) : a;
792
+ j(e, l) && (n.leaf ? o.push(a) : Z(e, l) ? this._all(a, o) : s.push(a));
730
793
  }
731
794
  n = s.pop();
732
795
  }
733
796
  return o;
734
797
  }
735
- collides(t) {
798
+ collides(e) {
736
799
  let n = this.data;
737
- if (!H(t, n))
800
+ if (!j(e, n))
738
801
  return !1;
739
802
  const o = [];
740
803
  for (; n; ) {
741
804
  for (let i = 0; i < n.children.length; i++) {
742
- const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
743
- if (H(t, a)) {
744
- if (n.leaf || K(t, a))
805
+ const s = n.children[i], r = n.leaf ? this.toBBox(s) : s;
806
+ if (j(e, r)) {
807
+ if (n.leaf || Z(e, r))
745
808
  return !0;
746
809
  o.push(s);
747
810
  }
@@ -750,15 +813,15 @@ class $t {
750
813
  }
751
814
  return !1;
752
815
  }
753
- load(t) {
754
- if (!(t && t.length))
816
+ load(e) {
817
+ if (!(e && e.length))
755
818
  return this;
756
- if (t.length < this._minEntries) {
757
- for (let o = 0; o < t.length; o++)
758
- this.insert(t[o]);
819
+ if (e.length < this._minEntries) {
820
+ for (let o = 0; o < e.length; o++)
821
+ this.insert(e[o]);
759
822
  return this;
760
823
  }
761
- let n = this._build(t.slice(), 0, t.length - 1, 0);
824
+ let n = this._build(e.slice(), 0, e.length - 1, 0);
762
825
  if (!this.data.children.length)
763
826
  this.data = n;
764
827
  else if (this.data.height === n.height)
@@ -772,181 +835,181 @@ class $t {
772
835
  }
773
836
  return this;
774
837
  }
775
- insert(t) {
776
- return t && this._insert(t, this.data.height - 1), this;
838
+ insert(e) {
839
+ return e && this._insert(e, this.data.height - 1), this;
777
840
  }
778
841
  clear() {
779
- return this.data = V([]), this;
842
+ return this.data = _([]), this;
780
843
  }
781
- remove(t, n) {
782
- if (!t)
844
+ remove(e, n) {
845
+ if (!e)
783
846
  return this;
784
847
  let o = this.data;
785
- const i = this.toBBox(t), s = [], a = [];
786
- let r, d, h;
848
+ const i = this.toBBox(e), s = [], r = [];
849
+ let a, l, d;
787
850
  for (; o || s.length; ) {
788
- if (o || (o = s.pop(), d = s[s.length - 1], r = a.pop(), h = !0), o.leaf) {
789
- const w = Wt(t, o.children, n);
790
- if (w !== -1)
791
- return o.children.splice(w, 1), s.push(o), this._condense(s), this;
851
+ if (o || (o = s.pop(), l = s[s.length - 1], a = r.pop(), d = !0), o.leaf) {
852
+ const x = ae(e, o.children, n);
853
+ if (x !== -1)
854
+ return o.children.splice(x, 1), s.push(o), this._condense(s), this;
792
855
  }
793
- !h && !o.leaf && K(o, i) ? (s.push(o), a.push(r), r = 0, d = o, o = o.children[0]) : d ? (r++, o = d.children[r], h = !1) : o = null;
856
+ !d && !o.leaf && Z(o, i) ? (s.push(o), r.push(a), a = 0, l = o, o = o.children[0]) : l ? (a++, o = l.children[a], d = !1) : o = null;
794
857
  }
795
858
  return this;
796
859
  }
797
- toBBox(t) {
798
- return t;
860
+ toBBox(e) {
861
+ return e;
799
862
  }
800
- compareMinX(t, n) {
801
- return t.minX - n.minX;
863
+ compareMinX(e, n) {
864
+ return e.minX - n.minX;
802
865
  }
803
- compareMinY(t, n) {
804
- return t.minY - n.minY;
866
+ compareMinY(e, n) {
867
+ return e.minY - n.minY;
805
868
  }
806
869
  toJSON() {
807
870
  return this.data;
808
871
  }
809
- fromJSON(t) {
810
- return this.data = t, this;
872
+ fromJSON(e) {
873
+ return this.data = e, this;
811
874
  }
812
- _all(t, n) {
875
+ _all(e, n) {
813
876
  const o = [];
814
- for (; t; )
815
- t.leaf ? n.push(...t.children) : o.push(...t.children), t = o.pop();
877
+ for (; e; )
878
+ e.leaf ? n.push(...e.children) : o.push(...e.children), e = o.pop();
816
879
  return n;
817
880
  }
818
- _build(t, n, o, i) {
881
+ _build(e, n, o, i) {
819
882
  const s = o - n + 1;
820
- let a = this._maxEntries, r;
821
- if (s <= a)
822
- return r = V(t.slice(n, o + 1)), I(r, this.toBBox), r;
823
- i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = V([]), r.leaf = !1, r.height = i;
824
- const d = Math.ceil(s / a), h = d * Math.ceil(Math.sqrt(a));
825
- tt(t, n, o, h, this.compareMinX);
826
- for (let w = n; w <= o; w += h) {
827
- const f = Math.min(w + h - 1, o);
828
- tt(t, w, f, d, this.compareMinY);
829
- for (let T = w; T <= f; T += d) {
830
- const g = Math.min(T + d - 1, f);
831
- r.children.push(this._build(t, T, g, i - 1));
883
+ let r = this._maxEntries, a;
884
+ if (s <= r)
885
+ return a = _(e.slice(n, o + 1)), V(a, this.toBBox), a;
886
+ i || (i = Math.ceil(Math.log(s) / Math.log(r)), r = Math.ceil(s / Math.pow(r, i - 1))), a = _([]), a.leaf = !1, a.height = i;
887
+ const l = Math.ceil(s / r), d = l * Math.ceil(Math.sqrt(r));
888
+ rt(e, n, o, d, this.compareMinX);
889
+ for (let x = n; x <= o; x += d) {
890
+ const u = Math.min(x + d - 1, o);
891
+ rt(e, x, u, l, this.compareMinY);
892
+ for (let T = x; T <= u; T += l) {
893
+ const h = Math.min(T + l - 1, u);
894
+ a.children.push(this._build(e, T, h, i - 1));
832
895
  }
833
896
  }
834
- return I(r, this.toBBox), r;
897
+ return V(a, this.toBBox), a;
835
898
  }
836
- _chooseSubtree(t, n, o, i) {
899
+ _chooseSubtree(e, n, o, i) {
837
900
  for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
838
- let s = 1 / 0, a = 1 / 0, r;
839
- for (let d = 0; d < n.children.length; d++) {
840
- const h = n.children[d], w = G(h), f = Kt(t, h) - w;
841
- f < a ? (a = f, s = w < s ? w : s, r = h) : f === a && w < s && (s = w, r = h);
901
+ let s = 1 / 0, r = 1 / 0, a;
902
+ for (let l = 0; l < n.children.length; l++) {
903
+ const d = n.children[l], x = K(d), u = de(e, d) - x;
904
+ u < r ? (r = u, s = x < s ? x : s, a = d) : u === r && x < s && (s = x, a = d);
842
905
  }
843
- n = r || n.children[0];
906
+ n = a || n.children[0];
844
907
  }
845
908
  return n;
846
909
  }
847
- _insert(t, n, o) {
848
- const i = o ? t : this.toBBox(t), s = [], a = this._chooseSubtree(i, this.data, n, s);
849
- for (a.children.push(t), P(a, i); n >= 0 && s[n].children.length > this._maxEntries; )
910
+ _insert(e, n, o) {
911
+ const i = o ? e : this.toBBox(e), s = [], r = this._chooseSubtree(i, this.data, n, s);
912
+ for (r.children.push(e), z(r, i); n >= 0 && s[n].children.length > this._maxEntries; )
850
913
  this._split(s, n), n--;
851
914
  this._adjustParentBBoxes(i, s, n);
852
915
  }
853
916
  // split overflowed node into two
854
- _split(t, n) {
855
- const o = t[n], i = o.children.length, s = this._minEntries;
917
+ _split(e, n) {
918
+ const o = e[n], i = o.children.length, s = this._minEntries;
856
919
  this._chooseSplitAxis(o, s, i);
857
- const a = this._chooseSplitIndex(o, s, i), r = V(o.children.splice(a, o.children.length - a));
858
- r.height = o.height, r.leaf = o.leaf, I(o, this.toBBox), I(r, this.toBBox), n ? t[n - 1].children.push(r) : this._splitRoot(o, r);
920
+ const r = this._chooseSplitIndex(o, s, i), a = _(o.children.splice(r, o.children.length - r));
921
+ a.height = o.height, a.leaf = o.leaf, V(o, this.toBBox), V(a, this.toBBox), n ? e[n - 1].children.push(a) : this._splitRoot(o, a);
859
922
  }
860
- _splitRoot(t, n) {
861
- this.data = V([t, n]), this.data.height = t.height + 1, this.data.leaf = !1, I(this.data, this.toBBox);
923
+ _splitRoot(e, n) {
924
+ this.data = _([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, V(this.data, this.toBBox);
862
925
  }
863
- _chooseSplitIndex(t, n, o) {
864
- let i, s = 1 / 0, a = 1 / 0;
865
- for (let r = n; r <= o - n; r++) {
866
- const d = N(t, 0, r, this.toBBox), h = N(t, r, o, this.toBBox), w = Jt(d, h), f = G(d) + G(h);
867
- w < s ? (s = w, i = r, a = f < a ? f : a) : w === s && f < a && (a = f, i = r);
926
+ _chooseSplitIndex(e, n, o) {
927
+ let i, s = 1 / 0, r = 1 / 0;
928
+ for (let a = n; a <= o - n; a++) {
929
+ const l = P(e, 0, a, this.toBBox), d = P(e, a, o, this.toBBox), x = ue(l, d), u = K(l) + K(d);
930
+ x < s ? (s = x, i = a, r = u < r ? u : r) : x === s && u < r && (r = u, i = a);
868
931
  }
869
932
  return i || o - n;
870
933
  }
871
934
  // sorts node children by the best axis for split
872
- _chooseSplitAxis(t, n, o) {
873
- const i = t.leaf ? this.compareMinX : qt, s = t.leaf ? this.compareMinY : Gt, a = this._allDistMargin(t, n, o, i), r = this._allDistMargin(t, n, o, s);
874
- a < r && t.children.sort(i);
935
+ _chooseSplitAxis(e, n, o) {
936
+ const i = e.leaf ? this.compareMinX : ce, s = e.leaf ? this.compareMinY : le, r = this._allDistMargin(e, n, o, i), a = this._allDistMargin(e, n, o, s);
937
+ r < a && e.children.sort(i);
875
938
  }
876
939
  // total margin of all possible split distributions where each node is at least m full
877
- _allDistMargin(t, n, o, i) {
878
- t.children.sort(i);
879
- const s = this.toBBox, a = N(t, 0, n, s), r = N(t, o - n, o, s);
880
- let d = z(a) + z(r);
881
- for (let h = n; h < o - n; h++) {
882
- const w = t.children[h];
883
- P(a, t.leaf ? s(w) : w), d += z(a);
940
+ _allDistMargin(e, n, o, i) {
941
+ e.children.sort(i);
942
+ const s = this.toBBox, r = P(e, 0, n, s), a = P(e, o - n, o, s);
943
+ let l = q(r) + q(a);
944
+ for (let d = n; d < o - n; d++) {
945
+ const x = e.children[d];
946
+ z(r, e.leaf ? s(x) : x), l += q(r);
884
947
  }
885
- for (let h = o - n - 1; h >= n; h--) {
886
- const w = t.children[h];
887
- P(r, t.leaf ? s(w) : w), d += z(r);
948
+ for (let d = o - n - 1; d >= n; d--) {
949
+ const x = e.children[d];
950
+ z(a, e.leaf ? s(x) : x), l += q(a);
888
951
  }
889
- return d;
952
+ return l;
890
953
  }
891
- _adjustParentBBoxes(t, n, o) {
954
+ _adjustParentBBoxes(e, n, o) {
892
955
  for (let i = o; i >= 0; i--)
893
- P(n[i], t);
956
+ z(n[i], e);
894
957
  }
895
- _condense(t) {
896
- for (let n = t.length - 1, o; n >= 0; n--)
897
- t[n].children.length === 0 ? n > 0 ? (o = t[n - 1].children, o.splice(o.indexOf(t[n]), 1)) : this.clear() : I(t[n], this.toBBox);
958
+ _condense(e) {
959
+ for (let n = e.length - 1, o; n >= 0; n--)
960
+ e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : V(e[n], this.toBBox);
898
961
  }
899
962
  }
900
- function Wt(e, t, n) {
963
+ function ae(t, e, n) {
901
964
  if (!n)
902
- return t.indexOf(e);
903
- for (let o = 0; o < t.length; o++)
904
- if (n(e, t[o]))
965
+ return e.indexOf(t);
966
+ for (let o = 0; o < e.length; o++)
967
+ if (n(t, e[o]))
905
968
  return o;
906
969
  return -1;
907
970
  }
908
- function I(e, t) {
909
- N(e, 0, e.children.length, t, e);
971
+ function V(t, e) {
972
+ P(t, 0, t.children.length, e, t);
910
973
  }
911
- function N(e, t, n, o, i) {
912
- i || (i = V(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
913
- for (let s = t; s < n; s++) {
914
- const a = e.children[s];
915
- P(i, e.leaf ? o(a) : a);
974
+ function P(t, e, n, o, i) {
975
+ i || (i = _(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
976
+ for (let s = e; s < n; s++) {
977
+ const r = t.children[s];
978
+ z(i, t.leaf ? o(r) : r);
916
979
  }
917
980
  return i;
918
981
  }
919
- function P(e, t) {
920
- return e.minX = Math.min(e.minX, t.minX), e.minY = Math.min(e.minY, t.minY), e.maxX = Math.max(e.maxX, t.maxX), e.maxY = Math.max(e.maxY, t.maxY), e;
982
+ function z(t, e) {
983
+ return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
921
984
  }
922
- function qt(e, t) {
923
- return e.minX - t.minX;
985
+ function ce(t, e) {
986
+ return t.minX - e.minX;
924
987
  }
925
- function Gt(e, t) {
926
- return e.minY - t.minY;
988
+ function le(t, e) {
989
+ return t.minY - e.minY;
927
990
  }
928
- function G(e) {
929
- return (e.maxX - e.minX) * (e.maxY - e.minY);
991
+ function K(t) {
992
+ return (t.maxX - t.minX) * (t.maxY - t.minY);
930
993
  }
931
- function z(e) {
932
- return e.maxX - e.minX + (e.maxY - e.minY);
994
+ function q(t) {
995
+ return t.maxX - t.minX + (t.maxY - t.minY);
933
996
  }
934
- function Kt(e, t) {
935
- return (Math.max(t.maxX, e.maxX) - Math.min(t.minX, e.minX)) * (Math.max(t.maxY, e.maxY) - Math.min(t.minY, e.minY));
997
+ function de(t, e) {
998
+ return (Math.max(e.maxX, t.maxX) - Math.min(e.minX, t.minX)) * (Math.max(e.maxY, t.maxY) - Math.min(e.minY, t.minY));
936
999
  }
937
- function Jt(e, t) {
938
- const n = Math.max(e.minX, t.minX), o = Math.max(e.minY, t.minY), i = Math.min(e.maxX, t.maxX), s = Math.min(e.maxY, t.maxY);
1000
+ function ue(t, e) {
1001
+ const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), s = Math.min(t.maxY, e.maxY);
939
1002
  return Math.max(0, i - n) * Math.max(0, s - o);
940
1003
  }
941
- function K(e, t) {
942
- return e.minX <= t.minX && e.minY <= t.minY && t.maxX <= e.maxX && t.maxY <= e.maxY;
1004
+ function Z(t, e) {
1005
+ return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
943
1006
  }
944
- function H(e, t) {
945
- return t.minX <= e.maxX && t.minY <= e.maxY && t.maxX >= e.minX && t.maxY >= e.minY;
1007
+ function j(t, e) {
1008
+ return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
946
1009
  }
947
- function V(e) {
1010
+ function _(t) {
948
1011
  return {
949
- children: e,
1012
+ children: t,
950
1013
  height: 1,
951
1014
  leaf: !0,
952
1015
  minX: 1 / 0,
@@ -955,26 +1018,36 @@ function V(e) {
955
1018
  maxY: -1 / 0
956
1019
  };
957
1020
  }
958
- function tt(e, t, n, o, i) {
959
- const s = [t, n];
1021
+ function rt(t, e, n, o, i) {
1022
+ const s = [e, n];
960
1023
  for (; s.length; ) {
961
- if (n = s.pop(), t = s.pop(), n - t <= o)
1024
+ if (n = s.pop(), e = s.pop(), n - e <= o)
962
1025
  continue;
963
- const a = t + Math.ceil((n - t) / o / 2) * o;
964
- Ht(e, a, t, n, i), s.push(t, a, a, n);
1026
+ const r = e + Math.ceil((n - e) / o / 2) * o;
1027
+ ie(t, r, e, n, i), s.push(e, r, r, n);
965
1028
  }
966
1029
  }
967
- const jt = (e, t) => {
1030
+ const he = (t, e, n = 10, o) => {
1031
+ const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
1032
+ s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
1033
+ const r = s.toString(), a = document.createRange();
1034
+ a.setStart(t.endContainer, t.endOffset), i === document.body ? a.setEnd(i, i.childNodes.length) : a.setEndAfter(i);
1035
+ const l = a.toString();
1036
+ return {
1037
+ prefix: r.substring(r.length - n),
1038
+ suffix: l.substring(0, n)
1039
+ };
1040
+ }, fe = (t, e) => {
968
1041
  const n = (s) => Math.round(s * 10) / 10, o = {
969
- top: n(e.top),
970
- bottom: n(e.bottom),
971
- left: n(e.left),
972
- right: n(e.right)
973
- }, i = {
974
1042
  top: n(t.top),
975
1043
  bottom: n(t.bottom),
976
1044
  left: n(t.left),
977
1045
  right: n(t.right)
1046
+ }, i = {
1047
+ top: n(e.top),
1048
+ bottom: n(e.bottom),
1049
+ left: n(e.left),
1050
+ right: n(e.right)
978
1051
  };
979
1052
  if (Math.abs(o.top - i.top) < 0.5 && Math.abs(o.bottom - i.bottom) < 0.5) {
980
1053
  if (Math.abs(o.left - i.right) < 0.5 || Math.abs(o.right - i.left) < 0.5)
@@ -988,340 +1061,392 @@ const jt = (e, t) => {
988
1061
  return "block-contains";
989
1062
  } else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
990
1063
  return "block-is-contained";
991
- }, Zt = (e, t) => {
992
- const n = Math.min(e.left, t.left), o = Math.max(e.right, t.right), i = Math.min(e.top, t.top), s = Math.max(e.bottom, t.bottom);
1064
+ }, pe = (t, e) => {
1065
+ const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
993
1066
  return new DOMRect(n, i, o - n, s - i);
994
- }, Qt = (e) => e.reduce((t, n) => {
1067
+ }, ge = (t) => t.reduce((e, n) => {
995
1068
  if (n.width === 0 || n.height === 0)
996
- return t;
997
- let o = [...t], i = !1;
998
- for (const s of t) {
999
- const a = jt(n, s);
1000
- if (a === "inline-adjacent") {
1001
- o = o.map((r) => r === s ? Zt(n, s) : r), i = !0;
1069
+ return e;
1070
+ let o = [...e], i = !1;
1071
+ for (const s of e) {
1072
+ const r = fe(n, s);
1073
+ if (r === "inline-adjacent") {
1074
+ o = o.map((a) => a === s ? pe(n, s) : a), i = !0;
1002
1075
  break;
1003
- } else if (a === "inline-contains") {
1004
- o = o.map((r) => r === s ? n : r), i = !0;
1076
+ } else if (r === "inline-contains") {
1077
+ o = o.map((a) => a === s ? n : a), i = !0;
1005
1078
  break;
1006
- } else if (a === "inline-is-contained") {
1079
+ } else if (r === "inline-is-contained") {
1007
1080
  i = !0;
1008
1081
  break;
1009
- } else if (a === "block-contains" || a === "block-is-contained") {
1010
- n.width < s.width && (o = o.map((r) => r === s ? n : r)), i = !0;
1082
+ } else if (r === "block-contains" || r === "block-is-contained") {
1083
+ n.width < s.width && (o = o.map((a) => a === s ? n : a)), i = !0;
1011
1084
  break;
1012
1085
  }
1013
1086
  }
1014
1087
  return i ? o : [...o, n];
1015
- }, []), te = (e) => {
1016
- const { startContainer: t, endContainer: n } = e;
1017
- if (t.nodeType === Node.TEXT_NODE && n.nodeType === Node.TEXT_NODE)
1018
- return e;
1019
- if (t.nodeType !== Node.TEXT_NODE) {
1020
- const i = t.nextSibling || t.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((a) => a.nodeType === Node.TEXT_NODE).shift();
1021
- e.setEnd(s, 0);
1088
+ }, []), me = (t) => {
1089
+ var i;
1090
+ const { startContainer: e, endContainer: n } = t;
1091
+ if (e.nodeType === Node.TEXT_NODE && n.nodeType === Node.TEXT_NODE)
1092
+ return t;
1093
+ if (e.nodeType !== Node.TEXT_NODE) {
1094
+ const s = e.nextSibling || e.parentNode, r = (s == null ? void 0 : s.nodeType) === Node.TEXT_NODE ? s : Array.from(s.childNodes).filter((a) => a.nodeType === Node.TEXT_NODE).shift();
1095
+ t.setEnd(r, 0);
1022
1096
  }
1023
1097
  if (n.nodeType !== Node.TEXT_NODE) {
1024
- const i = n.previousSibling || n.parentNode, s = i.nodeType === Node.TEXT_NODE ? i : Array.from(i.childNodes).filter((a) => a.nodeType === Node.TEXT_NODE).pop();
1025
- e.setEnd(s, s.textContent.length);
1098
+ const s = n.previousSibling || n.parentNode, r = (s == null ? void 0 : s.nodeType) === Node.TEXT_NODE ? s : Array.from(s.childNodes).filter((a) => a.nodeType === Node.TEXT_NODE).pop();
1099
+ t.setEnd(r, ((i = r == null ? void 0 : r.textContent) == null ? void 0 : i.length) || 0);
1026
1100
  }
1027
- return e;
1028
- }, ee = (e, t) => {
1029
- const n = new $t(), o = /* @__PURE__ */ new Map(), i = (l) => {
1030
- const c = t.getBoundingClientRect(), m = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : _(l, t), E = Array.from(m.selector.range.getClientRects()), v = Qt(E);
1031
- return v.map((C) => {
1032
- const { x: p, y: x, width: b, height: S } = C;
1101
+ return t;
1102
+ }, be = (t, e) => {
1103
+ const n = new re(), o = /* @__PURE__ */ new Map(), i = (c) => {
1104
+ const f = e.getBoundingClientRect(), m = c.selector.range instanceof Range && !c.selector.range.collapsed && c.selector.range.startContainer.nodeType === Node.TEXT_NODE && c.selector.range.endContainer.nodeType === Node.TEXT_NODE ? c : D(c, e), E = Array.from(m.selector.range.getClientRects()), S = ge(E);
1105
+ return S.map((M) => {
1106
+ const { x: g, y, width: A, height: v } = M;
1033
1107
  return {
1034
- minX: p - c.x,
1035
- minY: x - c.y,
1036
- maxX: p - c.x + b,
1037
- maxY: x - c.y + S,
1108
+ minX: g - f.x,
1109
+ minY: y - f.y,
1110
+ maxX: g - f.x + A,
1111
+ maxY: y - f.y + v,
1038
1112
  annotation: {
1039
- id: l.annotation,
1040
- rects: v
1113
+ id: c.annotation,
1114
+ rects: S
1041
1115
  }
1042
1116
  };
1043
1117
  });
1044
- }, s = () => [...o.values()], a = () => {
1118
+ }, s = () => [...o.values()], r = () => {
1045
1119
  n.clear(), o.clear();
1046
- }, r = (l) => {
1047
- const c = i(l);
1048
- c.forEach((u) => n.insert(u)), o.set(l.annotation, c);
1049
- }, d = (l) => {
1050
- o.get(l.annotation).forEach((u) => n.remove(u)), o.delete(l.annotation);
1051
- }, h = (l) => {
1052
- d(l), r(l);
1053
- }, w = (l, c = !0) => {
1054
- c && a();
1055
- const u = l.map((E) => ({ target: E, rects: i(E) }));
1056
- u.forEach(({ target: E, rects: v }) => o.set(E.annotation, v));
1057
- const m = u.reduce((E, { rects: v }) => [...E, ...v], []);
1120
+ }, a = (c) => {
1121
+ const f = i(c);
1122
+ f.forEach((p) => n.insert(p)), o.set(c.annotation, f);
1123
+ }, l = (c) => {
1124
+ o.get(c.annotation).forEach((p) => n.remove(p)), o.delete(c.annotation);
1125
+ }, d = (c) => {
1126
+ l(c), a(c);
1127
+ }, x = (c, f = !0) => {
1128
+ f && r();
1129
+ const p = c.map((E) => ({ target: E, rects: i(E) }));
1130
+ p.forEach(({ target: E, rects: S }) => o.set(E.annotation, S));
1131
+ const m = p.reduce((E, { rects: S }) => [...E, ...S], []);
1058
1132
  n.load(m);
1059
- }, f = (l, c) => {
1060
- const u = n.search({
1061
- minX: l,
1062
- minY: c,
1063
- maxX: l,
1064
- maxY: c
1065
- }), m = (E) => E.annotation.rects.reduce((v, C) => v + C.width * C.height, 0);
1066
- if (u.length > 0)
1067
- return u.sort((E, v) => m(E) - m(v)), u[0].annotation.id;
1068
- }, T = (l) => {
1069
- const c = g(l);
1070
- if (c.length === 0)
1133
+ }, u = (c, f) => {
1134
+ const p = n.search({
1135
+ minX: c,
1136
+ minY: f,
1137
+ maxX: c,
1138
+ maxY: f
1139
+ }), m = (E) => E.annotation.rects.reduce((S, M) => S + M.width * M.height, 0);
1140
+ if (p.length > 0)
1141
+ return p.sort((E, S) => m(E) - m(S)), p[0].annotation.id;
1142
+ }, T = (c) => {
1143
+ const f = h(c);
1144
+ if (f.length === 0)
1071
1145
  return;
1072
- let u = c[0].left, m = c[0].top, E = c[0].right, v = c[0].bottom;
1073
- for (let C = 1; C < c.length; C++) {
1074
- const p = c[C];
1075
- u = Math.min(u, p.left), m = Math.min(m, p.top), E = Math.max(E, p.right), v = Math.max(v, p.bottom);
1146
+ let p = f[0].left, m = f[0].top, E = f[0].right, S = f[0].bottom;
1147
+ for (let M = 1; M < f.length; M++) {
1148
+ const g = f[M];
1149
+ p = Math.min(p, g.left), m = Math.min(m, g.top), E = Math.max(E, g.right), S = Math.max(S, g.bottom);
1076
1150
  }
1077
- return new DOMRect(u, m, E - u, v - m);
1078
- }, g = (l) => {
1079
- const c = o.get(l);
1080
- return c ? c[0].annotation.rects : [];
1151
+ return new DOMRect(p, m, E - p, S - m);
1152
+ }, h = (c) => {
1153
+ const f = o.get(c);
1154
+ return f ? f[0].annotation.rects : [];
1081
1155
  };
1082
1156
  return {
1083
1157
  all: s,
1084
- clear: a,
1085
- getAt: f,
1158
+ clear: r,
1159
+ getAt: u,
1086
1160
  getBoundsForAnnotation: T,
1087
- getDOMRectsForAnnotation: g,
1088
- getIntersectingRects: (l, c, u, m) => n.search({ minX: l, minY: c, maxX: u, maxY: m }),
1089
- insert: r,
1090
- recalculate: () => w(e.all().map((l) => l.target), !0),
1091
- remove: d,
1092
- set: w,
1161
+ getDOMRectsForAnnotation: h,
1162
+ getIntersectingRects: (c, f, p, m) => n.search({ minX: c, minY: f, maxX: p, maxY: m }),
1163
+ insert: a,
1164
+ recalculate: () => x(t.all().map((c) => c.target), !0),
1165
+ remove: l,
1166
+ set: x,
1093
1167
  size: () => n.all().length,
1094
- update: h
1168
+ update: d
1095
1169
  };
1096
- }, F = (e) => {
1097
- const { range: t } = e.target.selector;
1098
- return t instanceof Range && !t.collapsed;
1099
- }, ne = (e, t) => {
1100
- const n = Rt(), o = ee(n, e), i = xt(n, t), s = At(n), a = Ut(), r = (A, l = L.LOCAL) => {
1101
- const c = A.target.selector.range instanceof Range ? A : { ...A, target: _(A.target, e) }, { range: u } = c.target.selector, m = u && !u.collapsed;
1102
- return m && n.addAnnotation(c, l), m;
1103
- }, d = (A, l = !0, c = L.LOCAL) => {
1104
- const u = A.map((E) => F(E) ? E : { ...E, target: _(E.target, e) });
1105
- if (u.some((E) => E.target.selector.range.collapsed)) {
1106
- const E = u.filter((v) => v.target.selector.range.collapsed);
1107
- return console.warn("Could not revive all targets"), console.warn(E), n.bulkAddAnnotation(u, l, c), E;
1170
+ }, Q = (t) => {
1171
+ const { range: e } = t.target.selector;
1172
+ return e instanceof Range && !e.collapsed;
1173
+ }, we = (t, e) => {
1174
+ const n = zt(), o = be(n, t), i = Xt(n, e), s = Rt(n), r = Wt(), a = (b, c = O.LOCAL) => {
1175
+ const f = b.target.selector.range instanceof Range ? b : { ...b, target: D(b.target, t) }, { range: p } = f.target.selector, m = p && !p.collapsed;
1176
+ return m && n.addAnnotation(f, c), m;
1177
+ }, l = (b, c = !0, f = O.LOCAL) => {
1178
+ const p = b.map((E) => Q(E) ? E : { ...E, target: D(E.target, t) });
1179
+ if (p.some((E) => E.target.selector.range.collapsed)) {
1180
+ const E = p.filter((S) => S.target.selector.range.collapsed);
1181
+ return console.warn("Could not revive all targets"), console.warn(E), n.bulkAddAnnotation(p, c, f), E;
1108
1182
  } else
1109
- return n.bulkAddAnnotation(u, l, c), [];
1110
- }, h = (A, l = L.LOCAL) => {
1111
- const c = A.selector.range instanceof Range ? A : _(A, e);
1112
- n.updateTarget(c, l);
1113
- }, w = (A, l = L.LOCAL) => {
1114
- const c = A.map((u) => u.selector.range instanceof Range ? u : _(u, e));
1115
- n.bulkUpdateTargets(c, l);
1116
- }, f = (A, l) => {
1117
- const c = o.getAt(A, l);
1118
- return c ? n.getAnnotation(c) : void 0;
1119
- }, T = (A, l, c, u) => {
1120
- const m = o.getIntersectingRects(A, l, c, u);
1121
- return Array.from(new Set(m.map((v) => v.annotation.id))).map((v) => n.getAnnotation(v)).filter((v) => v);
1122
- }, g = (A, l, c, u = 5) => {
1123
- const m = o.getDOMRectsForAnnotation(A);
1183
+ return n.bulkAddAnnotation(p, c, f), [];
1184
+ }, d = (b, c = O.LOCAL) => {
1185
+ const f = b.selector.range instanceof Range ? b : D(b, t);
1186
+ n.updateTarget(f, c);
1187
+ }, x = (b, c = O.LOCAL) => {
1188
+ const f = b.map((p) => p.selector.range instanceof Range ? p : D(p, t));
1189
+ n.bulkUpdateTargets(f, c);
1190
+ }, u = (b, c) => {
1191
+ const f = o.getAt(b, c);
1192
+ return f ? n.getAnnotation(f) : void 0;
1193
+ }, T = (b, c, f, p) => {
1194
+ const m = o.getIntersectingRects(b, c, f, p);
1195
+ return Array.from(new Set(m.map((S) => S.annotation.id))).map((S) => n.getAnnotation(S)).filter((S) => S);
1196
+ }, h = (b, c, f, p = 5) => {
1197
+ const m = o.getDOMRectsForAnnotation(b);
1124
1198
  if (m.length > 0) {
1125
- if (l && c) {
1126
- const E = m.find(({ top: v, right: C, bottom: p, left: x }) => l >= x - u && l <= C + u && c >= v - u && c <= p + u);
1199
+ if (c && f) {
1200
+ const E = m.find(({ top: S, right: M, bottom: g, left: y }) => c >= y - p && c <= M + p && f >= S - p && f <= g + p);
1127
1201
  if (E)
1128
1202
  return E;
1129
1203
  }
1130
- return o.getBoundsForAnnotation(A);
1204
+ return o.getBoundsForAnnotation(b);
1131
1205
  }
1132
- }, y = (A, l, c, u) => {
1133
- const E = o.getIntersectingRects(A, l, c, u).reduce((v, C) => ((v[C.annotation.id] = v[C.annotation.id] || []).push(C), v), {});
1134
- return Object.entries(E).map(([v, C]) => ({
1135
- annotation: n.getAnnotation(v),
1136
- rects: C.map(({ minX: p, minY: x, maxX: b, maxY: S }) => ({ x: p, y: x, width: b - p, height: S - x }))
1206
+ }, w = (b, c, f, p) => {
1207
+ const E = o.getIntersectingRects(b, c, f, p).reduce((S, M) => ((S[M.annotation.id] = S[M.annotation.id] || []).push(M), S), {});
1208
+ return Object.entries(E).map(([S, M]) => ({
1209
+ annotation: n.getAnnotation(S),
1210
+ rects: M.map(({ minX: g, minY: y, maxX: A, maxY: v }) => ({ x: g, y, width: A - g, height: v - y }))
1137
1211
  }));
1138
1212
  }, B = () => o.recalculate();
1139
- return n.observe(({ changes: A }) => {
1140
- const l = (A.created || []).filter(F), c = (A.deleted || []).filter(F), u = (A.updated || []).filter((m) => F(m.newValue));
1141
- l.length > 0 && o.set(l.map((m) => m.target), !1), (c == null ? void 0 : c.length) > 0 && c.forEach((m) => o.remove(m.target)), (u == null ? void 0 : u.length) > 0 && u.forEach(({ newValue: m }) => o.update(m.target));
1213
+ return n.observe(({ changes: b }) => {
1214
+ const c = (b.created || []).filter(Q), f = (b.deleted || []).filter(Q), p = (b.updated || []).filter((m) => Q(m.newValue));
1215
+ c.length > 0 && o.set(c.map((m) => m.target), !1), (f == null ? void 0 : f.length) > 0 && f.forEach((m) => o.remove(m.target)), (p == null ? void 0 : p.length) > 0 && p.forEach(({ newValue: m }) => o.update(m.target));
1142
1216
  }), {
1143
1217
  store: {
1144
1218
  ...n,
1145
- addAnnotation: r,
1146
- bulkAddAnnotation: d,
1147
- bulkUpdateTargets: w,
1148
- getAnnotationBounds: g,
1149
- getAt: f,
1219
+ addAnnotation: a,
1220
+ bulkAddAnnotation: l,
1221
+ bulkUpdateTargets: x,
1222
+ getAnnotationBounds: h,
1223
+ getAt: u,
1150
1224
  getIntersecting: T,
1151
- getIntersectingRects: y,
1225
+ getIntersectingRects: w,
1152
1226
  recalculatePositions: B,
1153
- updateTarget: h
1227
+ updateTarget: d
1154
1228
  },
1155
1229
  selection: i,
1156
1230
  hover: s,
1157
- viewport: a
1231
+ viewport: r
1232
+ };
1233
+ }, Te = (t, e) => ({
1234
+ parse: (n) => xe(n, e),
1235
+ serialize: (n) => Ae(n, t, e)
1236
+ }), xe = (t, e) => {
1237
+ const n = t.id || ct(), {
1238
+ creator: o,
1239
+ created: i,
1240
+ modified: s,
1241
+ body: r,
1242
+ ...a
1243
+ } = t, l = ne(r, n), d = Array.isArray(t.target) ? t.target[0] : t.target, u = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((h, w) => {
1244
+ switch (w.type) {
1245
+ case "TextQuoteSelector":
1246
+ h.quote = w.exact;
1247
+ break;
1248
+ case "TextPositionSelector":
1249
+ h.start = w.start, h.end = w.end;
1250
+ break;
1251
+ }
1252
+ return h;
1253
+ }, {});
1254
+ if (((h) => h.quote !== void 0 && h.start !== void 0 && h.end !== void 0)(u))
1255
+ return {
1256
+ parsed: {
1257
+ ...a,
1258
+ id: n,
1259
+ bodies: l,
1260
+ target: D({
1261
+ ...a.target,
1262
+ created: i ? new Date(i) : void 0,
1263
+ creator: dt(o),
1264
+ updated: s ? new Date(s) : void 0,
1265
+ annotation: n,
1266
+ selector: u
1267
+ }, e)
1268
+ }
1269
+ };
1270
+ {
1271
+ const h = [
1272
+ u.start ? void 0 : "TextPositionSelector",
1273
+ u.quote ? void 0 : "TextQuoteSelector"
1274
+ ].filter(Boolean);
1275
+ return {
1276
+ error: Error(`Missing selector types: ${h.join(" and ")}`)
1277
+ };
1278
+ }
1279
+ }, Ae = (t, e, n) => {
1280
+ const { bodies: o, target: i, ...s } = t, {
1281
+ selector: r,
1282
+ creator: a,
1283
+ created: l,
1284
+ updated: d,
1285
+ ...x
1286
+ } = i, { quote: u, start: T, end: h, range: w } = r, { prefix: B, suffix: b } = he(w, n), c = [{
1287
+ type: "TextQuoteSelector",
1288
+ exact: u,
1289
+ prefix: B,
1290
+ suffix: b
1291
+ }, {
1292
+ type: "TextPositionSelector",
1293
+ start: T,
1294
+ end: h
1295
+ }];
1296
+ return {
1297
+ ...s,
1298
+ "@context": "http://www.w3.org/ns/anno.jsonld",
1299
+ id: t.id,
1300
+ type: "Annotation",
1301
+ body: oe(t.bodies),
1302
+ creator: a,
1303
+ created: l == null ? void 0 : l.toISOString(),
1304
+ modified: d == null ? void 0 : d.toISOString(),
1305
+ target: {
1306
+ ...x,
1307
+ source: e,
1308
+ selector: c
1309
+ }
1158
1310
  };
1159
- }, oe = (e, t = {}) => {
1160
- const n = /* @__PURE__ */ new Map(), o = (s) => Array.from(n.entries()).filter(([a, r]) => r.presenceKey === s.presenceKey).map(([a, r]) => a);
1161
- return e.on("selectionChange", (s, a) => {
1162
- o(s).forEach((d) => n.delete(d)), a && a.forEach((d) => n.set(d, s));
1163
- }), { paint: (s, a, r, d, h, w) => {
1164
- t.font && (d.font = t.font);
1165
- const f = n.get(s.id);
1166
- if (f) {
1167
- const { x: T, y: g, height: y } = a[0];
1168
- d.fillStyle = f.appearance.color, d.fillRect(T - 2, g - 2.5, 2, y + 5);
1169
- const B = d.measureText(f.appearance.label), A = B.width + 6, l = B.actualBoundingBoxAscent + B.actualBoundingBoxDescent + 8, c = B.fontBoundingBoxAscent ? 8 : 6.5;
1170
- d.fillRect(T - 2, g - 2.5 - l, A, l), d.fillStyle = "#fff", d.fillText(f.appearance.label, T + 1, g - c), r.fillStyle = f.appearance.color, r.globalAlpha = h ? 0.45 : 0.18, a.forEach(({ x: u, y: m, width: E, height: v }) => r.fillRect(u, m - 2.5, E, v + 5));
1311
+ }, ye = (t, e = {}) => {
1312
+ const n = /* @__PURE__ */ new Map(), o = (s) => Array.from(n.entries()).filter(([r, a]) => a.presenceKey === s.presenceKey).map(([r, a]) => r);
1313
+ return t.on("selectionChange", (s, r) => {
1314
+ o(s).forEach((l) => n.delete(l)), r && r.forEach((l) => n.set(l, s));
1315
+ }), { paint: (s, r, a, l, d, x) => {
1316
+ e.font && (l.font = e.font);
1317
+ const u = n.get(s.id);
1318
+ if (u) {
1319
+ const { x: T, y: h, height: w } = r[0];
1320
+ l.fillStyle = u.appearance.color, l.fillRect(T - 2, h - 2.5, 2, w + 5);
1321
+ const B = l.measureText(u.appearance.label), b = B.width + 6, c = B.actualBoundingBoxAscent + B.actualBoundingBoxDescent + 8, f = B.fontBoundingBoxAscent ? 8 : 6.5;
1322
+ l.fillRect(T - 2, h - 2.5 - c, b, c), l.fillStyle = "#fff", l.fillText(u.appearance.label, T + 1, h - f), a.fillStyle = u.appearance.color, a.globalAlpha = d ? 0.45 : 0.18, r.forEach(({ x: p, y: m, width: E, height: S }) => a.fillRect(p, m - 2.5, E, S + 5));
1171
1323
  } else
1172
- nt.paint(s, a, r, d, h, w);
1324
+ at.paint(s, r, a, l, d, x);
1173
1325
  } };
1174
- }, st = (e) => {
1175
- if (e === null)
1326
+ }, ht = (t) => {
1327
+ if (t === null)
1176
1328
  return document.scrollingElement;
1177
- const { overflowY: t } = window.getComputedStyle(e);
1178
- return t !== "visible" && t !== "hidden" && e.scrollHeight > e.clientHeight ? e : st(e.parentElement);
1179
- }, ie = (e, t) => (n) => {
1329
+ const { overflowY: e } = window.getComputedStyle(t);
1330
+ return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ht(t.parentElement);
1331
+ }, ve = (t, e) => (n) => {
1180
1332
  const o = (s) => {
1181
- const a = i.getBoundingClientRect(), r = i.clientHeight, d = i.clientWidth, h = s.selector.range.getBoundingClientRect(), { width: w, height: f } = t.getAnnotationBounds(n.id), T = h.top - a.top, g = h.left - a.left, y = i.parentElement ? i.scrollTop : 0, B = i.parentElement ? i.scrollLeft : 0, A = T + y - (r - f) / 2, l = g + B - (d - w) / 2;
1182
- i.scroll({ top: A, left: l, behavior: "smooth" });
1183
- }, i = st(e);
1333
+ const r = i.getBoundingClientRect(), a = i.clientHeight, l = i.clientWidth, d = s.selector.range.getBoundingClientRect(), { width: x, height: u } = e.getAnnotationBounds(n.id), T = d.top - r.top, h = d.left - r.left, w = i.parentElement ? i.scrollTop : 0, B = i.parentElement ? i.scrollLeft : 0, b = T + w - (a - u) / 2, c = h + B - (l - x) / 2;
1334
+ i.scroll({ top: b, left: c, behavior: "smooth" });
1335
+ }, i = ht(t);
1184
1336
  if (i) {
1185
- const s = t.getAnnotation(n.id), { range: a } = s.target.selector;
1186
- if (a && !a.collapsed)
1337
+ const s = e.getAnnotation(n.id), { range: r } = s.target.selector;
1338
+ if (r && !r.collapsed)
1187
1339
  return o(s.target), !0;
1188
1340
  {
1189
- const r = _(s.target, e);
1190
- if (r.selector.range && !r.selector.range.collapsed)
1191
- return o(r), !0;
1341
+ const a = D(s.target, t);
1342
+ if (a.selector.range && !a.selector.range.collapsed)
1343
+ return o(a), !0;
1192
1344
  }
1193
1345
  }
1194
1346
  return !1;
1195
- };
1196
- let $;
1197
- const se = new Uint8Array(16);
1198
- function ae() {
1199
- if (!$ && ($ = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !$))
1200
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1201
- return $(se);
1202
- }
1203
- const O = [];
1204
- for (let e = 0; e < 256; ++e)
1205
- O.push((e + 256).toString(16).slice(1));
1206
- function re(e, t = 0) {
1207
- return O[e[t + 0]] + O[e[t + 1]] + O[e[t + 2]] + O[e[t + 3]] + "-" + O[e[t + 4]] + O[e[t + 5]] + "-" + O[e[t + 6]] + O[e[t + 7]] + "-" + O[e[t + 8]] + O[e[t + 9]] + "-" + O[e[t + 10]] + O[e[t + 11]] + O[e[t + 12]] + O[e[t + 13]] + O[e[t + 14]] + O[e[t + 15]];
1208
- }
1209
- const le = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), et = {
1210
- randomUUID: le
1211
- };
1212
- function ce(e, t, n) {
1213
- if (et.randomUUID && !t && !e)
1214
- return et.randomUUID();
1215
- e = e || {};
1216
- const o = e.random || (e.rng || ae)();
1217
- if (o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, t) {
1218
- n = n || 0;
1219
- for (let i = 0; i < 16; ++i)
1220
- t[n + i] = o[i];
1221
- return t;
1222
- }
1223
- return re(o);
1224
- }
1225
- const de = (e, t, n) => {
1226
- const o = document.createRange(), i = n ? e.startContainer.parentElement.closest(n) : t;
1227
- o.setStart(i, 0), o.setEnd(e.startContainer, e.startOffset);
1228
- const s = e.toString(), a = o.toString().length, r = a + s.length;
1229
- return n ? { quote: s, start: a, end: r, range: e, offsetReference: i } : { quote: s, start: a, end: r, range: e };
1230
- }, ue = (e, t, n) => {
1231
- const { store: o, selection: i } = t;
1232
- let s, a;
1233
- const r = (g) => s = g;
1234
- let d = !1, h;
1235
- const w = (g) => {
1347
+ }, Ee = (t, e, n) => {
1348
+ const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
1349
+ o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
1350
+ const s = t.toString(), r = o.toString().length, a = r + s.length;
1351
+ return n ? { quote: s, start: r, end: a, range: t, offsetReference: i } : { quote: s, start: r, end: a, range: t };
1352
+ }, Se = (t, e, n) => {
1353
+ const { store: o, selection: i } = e;
1354
+ let s, r;
1355
+ const a = (h) => s = h;
1356
+ let l = !1, d;
1357
+ const x = (h) => {
1236
1358
  var B;
1237
- if (!d)
1359
+ if (!l)
1238
1360
  return;
1239
- !((B = g.target.parentElement) != null && B.closest(".not-annotatable")) ? a = {
1240
- annotation: ce(),
1361
+ !((B = h.target.parentElement) != null && B.closest(".not-annotatable")) ? r = {
1362
+ annotation: ct(),
1241
1363
  selector: void 0,
1242
1364
  creator: s,
1243
1365
  created: /* @__PURE__ */ new Date()
1244
- } : a = void 0;
1366
+ } : r = void 0;
1245
1367
  };
1246
- e.addEventListener("selectstart", w);
1247
- let f;
1248
- const T = (g) => {
1368
+ t.addEventListener("selectstart", x);
1369
+ let u;
1370
+ const T = (h) => {
1249
1371
  var B;
1250
- const y = document.getSelection();
1251
- if (g.timeStamp - h.timeStamp < 1e3 && !a && w(h), !y.isCollapsed && d && a) {
1252
- const A = Array.from(Array(y.rangeCount).keys()).map((u) => y.getRangeAt(u));
1253
- te(A[0]).toString() !== ((B = a.selector) == null ? void 0 : B.quote) && (a = {
1254
- ...a,
1255
- selector: de(A[0], e, n)
1256
- }, o.getAnnotation(a.annotation) ? o.updateTarget(a, L.LOCAL) : (o.addAnnotation({
1257
- id: a.annotation,
1372
+ const w = document.getSelection();
1373
+ if (h.timeStamp - d.timeStamp < 1e3 && !r && x(d), !w.isCollapsed && l && r) {
1374
+ const b = Array.from(Array(w.rangeCount).keys()).map((p) => w.getRangeAt(p));
1375
+ me(b[0]).toString() !== ((B = r.selector) == null ? void 0 : B.quote) && (r = {
1376
+ ...r,
1377
+ selector: Ee(b[0], t, n)
1378
+ }, o.getAnnotation(r.annotation) ? o.updateTarget(r, O.LOCAL) : (o.addAnnotation({
1379
+ id: r.annotation,
1258
1380
  bodies: [],
1259
- target: a
1260
- }), i.clickSelect(a.annotation, h)));
1381
+ target: r
1382
+ }), i.clickSelect(r.annotation, d)));
1261
1383
  }
1262
1384
  };
1263
- return document.addEventListener("selectionchange", (g) => {
1264
- f && clearTimeout(f), f = setTimeout(() => T(g), 10);
1265
- }), e.addEventListener("pointerdown", (g) => {
1266
- const { target: y, timeStamp: B, offsetX: A, offsetY: l, type: c } = g;
1267
- h = { ...g, target: y, timeStamp: B, offsetX: A, offsetY: l, type: c }, d = g.button === 0;
1268
- }), document.addEventListener("pointerup", (g) => {
1269
- var l;
1270
- if (!!((l = g.target.parentElement) != null && l.closest(".not-annotatable")) || !d)
1385
+ return document.addEventListener("selectionchange", (h) => {
1386
+ u && clearTimeout(u), u = setTimeout(() => T(h), 10);
1387
+ }), t.addEventListener("pointerdown", (h) => {
1388
+ const { target: w, timeStamp: B, offsetX: b, offsetY: c, type: f } = h;
1389
+ d = { ...h, target: w, timeStamp: B, offsetX: b, offsetY: c, type: f }, l = h.button === 0;
1390
+ }), document.addEventListener("pointerup", (h) => {
1391
+ var c;
1392
+ if (!!((c = h.target.parentElement) != null && c.closest(".not-annotatable")) || !l)
1271
1393
  return;
1272
1394
  const B = () => {
1273
- const { x: c, y: u } = e.getBoundingClientRect(), m = o.getAt(g.clientX - c, g.clientY - u);
1395
+ const { x: f, y: p } = t.getBoundingClientRect(), m = o.getAt(h.clientX - f, h.clientY - p);
1274
1396
  if (m) {
1275
1397
  const { selected: E } = i;
1276
- (E.length !== 1 || E[0].id !== m.id) && i.clickSelect(m.id, g);
1398
+ (E.length !== 1 || E[0].id !== m.id) && i.clickSelect(m.id, h);
1277
1399
  } else
1278
1400
  i.isEmpty() || i.clear();
1279
- }, A = g.timeStamp - h.timeStamp;
1280
- document.getSelection().isCollapsed && A < 300 ? (a = void 0, B()) : i.clickSelect(a.annotation, g);
1401
+ }, b = h.timeStamp - d.timeStamp;
1402
+ document.getSelection().isCollapsed && b < 300 ? (r = void 0, B()) : i.clickSelect(r.annotation, h);
1281
1403
  }), {
1282
- setUser: r
1404
+ setUser: a
1283
1405
  };
1284
- }, he = (e, t = {}) => {
1285
- e.addEventListener("click", (u) => u.preventDefault());
1286
- const n = ne(e, t.pointerAction), { selection: o, viewport: i } = n, s = n.store, a = Yt(s), r = Dt(
1406
+ }, Be = (t, e = {}) => {
1407
+ t.addEventListener("click", (p) => p.preventDefault());
1408
+ const n = we(t, e.pointerAction), { selection: o, viewport: i } = n, s = n.store, r = Ft(s), a = qt(
1287
1409
  n,
1288
- a,
1289
- t.adapter
1410
+ r,
1411
+ e.adapter
1290
1412
  );
1291
- let d = zt();
1292
- const h = bt(e, n, i);
1293
- t.style && h.setDrawingStyle(t.style);
1294
- const w = ue(e, n, t.offsetReferenceSelector);
1295
- return w.setUser(d), {
1296
- ...Vt(n, a, t.adapter),
1413
+ let l = te();
1414
+ const d = Tt(t, n, i);
1415
+ e.style && d.setDrawingStyle(e.style);
1416
+ const x = Se(t, n, e.offsetReferenceSelector);
1417
+ return x.setUser(l), {
1418
+ ...Qt(n, r, e.adapter),
1297
1419
  destroy: () => {
1298
1420
  throw "Not implemented yet";
1299
1421
  },
1300
- element: e,
1301
- getUser: () => d,
1302
- setFilter: (u) => h.setFilter(u),
1303
- setStyle: (u) => h.setDrawingStyle(u),
1304
- setUser: (u) => {
1305
- d = u, w.setUser(u);
1422
+ element: t,
1423
+ getUser: () => l,
1424
+ setFilter: (p) => d.setFilter(p),
1425
+ setStyle: (p) => d.setDrawingStyle(p),
1426
+ setUser: (p) => {
1427
+ l = p, x.setUser(p);
1306
1428
  },
1307
- setSelected: (u) => {
1308
- u ? o.setSelected(u) : o.clear();
1429
+ setSelected: (p) => {
1430
+ p ? o.setSelected(p) : o.clear();
1309
1431
  },
1310
- setPresenceProvider: (u) => {
1311
- u && (h.setPainter(oe(u, t.presence)), u.on("selectionChange", () => h.redraw()));
1432
+ setPresenceProvider: (p) => {
1433
+ p && (d.setPainter(ye(p, e.presence)), p.on("selectionChange", () => d.redraw()));
1312
1434
  },
1313
- on: r.on,
1314
- off: r.off,
1315
- scrollIntoView: ie(e, s),
1435
+ on: a.on,
1436
+ off: a.off,
1437
+ scrollIntoView: ve(t, s),
1316
1438
  state: n
1317
1439
  };
1318
1440
  };
1319
1441
  export {
1320
- L as Origin,
1321
- bt as createHighlightLayer,
1322
- he as createTextAnnotator,
1323
- ne as createTextAnnotatorState,
1324
- nt as defaultPainter,
1325
- _ as reviveTarget
1442
+ O as Origin,
1443
+ Te as W3CTextFormat,
1444
+ Tt as createHighlightLayer,
1445
+ Be as createTextAnnotator,
1446
+ we as createTextAnnotatorState,
1447
+ at as defaultPainter,
1448
+ xe as parseW3CTextAnnotation,
1449
+ D as reviveTarget,
1450
+ Ae as serializeW3CTextAnnotation
1326
1451
  };
1327
1452
  //# sourceMappingURL=text-annotator.es.js.map