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

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