@recogito/text-annotator 3.0.0-rc.19 → 3.0.0-rc.2

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