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

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