@soomo/text-annotator 3.4.1-staging.0 → 3.4.2-staging.1

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 (55) hide show
  1. package/dist/SelectionHandler.d.ts +10 -0
  2. package/dist/TextAnnotator.d.ts +15 -0
  3. package/dist/TextAnnotatorOptions.d.ts +34 -0
  4. package/dist/api/index.d.ts +1 -0
  5. package/dist/api/scrollIntoView.d.ts +3 -0
  6. package/dist/highlight/Highlight.d.ts +5 -0
  7. package/dist/highlight/HighlightPainter.d.ts +11 -0
  8. package/dist/highlight/HighlightStyle.d.ts +11 -0
  9. package/dist/highlight/baseRenderer.d.ts +20 -0
  10. package/dist/highlight/canvas/canvasRenderer.d.ts +5 -0
  11. package/dist/highlight/canvas/index.d.ts +1 -0
  12. package/dist/highlight/highlights/highlightsRenderer.d.ts +6 -0
  13. package/dist/highlight/highlights/index.d.ts +1 -0
  14. package/dist/highlight/index.d.ts +6 -0
  15. package/dist/highlight/span/color.d.ts +2 -0
  16. package/dist/highlight/span/index.d.ts +1 -0
  17. package/dist/highlight/span/spansRenderer.d.ts +5 -0
  18. package/dist/highlight/viewport.d.ts +12 -0
  19. package/dist/index.d.ts +11 -0
  20. package/dist/model/core/TextAnnotation.d.ts +15 -0
  21. package/dist/model/core/index.d.ts +1 -0
  22. package/dist/model/index.d.ts +2 -0
  23. package/dist/model/w3c/W3CTextAnnotation.d.ts +35 -0
  24. package/dist/model/w3c/W3CTextFormatAdapter.d.ts +12 -0
  25. package/dist/model/w3c/index.d.ts +2 -0
  26. package/dist/presence/PresencePainter.d.ts +5 -0
  27. package/dist/presence/PresencePainterOptions.d.ts +3 -0
  28. package/dist/presence/index.d.ts +2 -0
  29. package/dist/state/TextAnnotationStore.d.ts +28 -0
  30. package/dist/state/TextAnnotatorState.d.ts +12 -0
  31. package/dist/state/index.d.ts +2 -0
  32. package/dist/state/spatialTree.d.ts +33 -0
  33. package/dist/text-annotator.es.js +295 -282
  34. package/dist/text-annotator.es.js.map +1 -1
  35. package/dist/text-annotator.umd.js +2 -2
  36. package/dist/text-annotator.umd.js.map +1 -1
  37. package/dist/utils/cancelSingleClickEvents.d.ts +6 -0
  38. package/dist/utils/cloneEvents.d.ts +11 -0
  39. package/dist/utils/device.d.ts +1 -0
  40. package/dist/utils/getHighlightClientRects.d.ts +1 -0
  41. package/dist/utils/getQuoteContext.d.ts +4 -0
  42. package/dist/utils/index.d.ts +17 -0
  43. package/dist/utils/isNotAnnotatable.d.ts +4 -0
  44. package/dist/utils/isRevived.d.ts +2 -0
  45. package/dist/utils/isWhitespaceOrEmpty.d.ts +3 -0
  46. package/dist/utils/mergeClientRects.d.ts +2 -0
  47. package/dist/utils/programmaticallyFocusable.d.ts +6 -0
  48. package/dist/utils/rangeToSelector.d.ts +2 -0
  49. package/dist/utils/rectsToBounds.d.ts +8 -0
  50. package/dist/utils/reviveAnnotation.d.ts +2 -0
  51. package/dist/utils/reviveSelector.d.ts +11 -0
  52. package/dist/utils/reviveTarget.d.ts +2 -0
  53. package/dist/utils/splitAnnotatableRanges.d.ts +5 -0
  54. package/dist/utils/trimRangeToContainer.d.ts +1 -0
  55. package/package.json +5 -6
@@ -19,23 +19,78 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
19
19
  }, Nt = (t) => t.addEventListener("click", (e) => {
20
20
  // Allow clicks within not-annotatable elements
21
21
  !e.target.closest(W) && !e.target.closest("a") && e.preventDefault();
22
+ }), G = (t) => ({
23
+ ...t,
24
+ type: t.type,
25
+ x: t.x,
26
+ y: t.y,
27
+ clientX: t.clientX,
28
+ clientY: t.clientY,
29
+ offsetX: t.offsetX,
30
+ offsetY: t.offsetY,
31
+ screenX: t.screenX,
32
+ screenY: t.screenY,
33
+ isPrimary: t.isPrimary,
34
+ altKey: t.altKey,
35
+ ctrlKey: t.ctrlKey,
36
+ metaKey: t.metaKey,
37
+ shiftKey: t.shiftKey,
38
+ button: t.button,
39
+ buttons: t.buttons,
40
+ currentTarget: t.currentTarget,
41
+ target: t.target,
42
+ defaultPrevented: t.defaultPrevented,
43
+ detail: t.detail,
44
+ eventPhase: t.eventPhase,
45
+ pointerId: t.pointerId,
46
+ pointerType: t.pointerType,
47
+ timeStamp: t.timeStamp
48
+ }), X = (t) => ({
49
+ ...t,
50
+ type: t.type,
51
+ key: t.key,
52
+ code: t.code,
53
+ location: t.location,
54
+ repeat: t.repeat,
55
+ altKey: t.altKey,
56
+ ctrlKey: t.ctrlKey,
57
+ metaKey: t.metaKey,
58
+ shiftKey: t.shiftKey,
59
+ currentTarget: t.currentTarget,
60
+ target: t.target,
61
+ defaultPrevented: t.defaultPrevented,
62
+ detail: t.detail,
63
+ timeStamp: t.timeStamp
22
64
  }), Ot = ft(), kt = Ot.os.is(ut.MACOS), Bt = (t) => {
23
65
  !t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
24
- }, it = /^\s*$/, It = (t) => it.test(t.toString()), Mt = (t) => it.test(t.textContent || ""), Ht = (t) => {
25
- const e = [], n = document.createNodeIterator(t.commonAncestorContainer, NodeFilter.SHOW_TEXT);
66
+ }, It = (t) => {
67
+ const e = [], n = document.createNodeIterator(
68
+ t.commonAncestorContainer,
69
+ NodeFilter.SHOW_TEXT
70
+ );
26
71
  let r;
27
72
  for (; r = n.nextNode(); )
28
- t.intersectsNode(r) && !Mt(r) && e.push(r);
73
+ t.intersectsNode(r) && e.push(r);
29
74
  if (e.length < 2)
30
75
  return Array.from(t.getClientRects());
31
76
  {
32
77
  const o = e[0], s = e[e.length - 1], i = document.createRange();
33
- i.selectNode(o), t.startContainer.nodeType === Node.TEXT_NODE ? i.setStart(o, t.startOffset) : i.setStartAfter(t.startContainer);
78
+ if (i.selectNode(o), t.startContainer.nodeType === Node.TEXT_NODE)
79
+ i.setStart(o, t.startOffset);
80
+ else {
81
+ const f = t.startContainer.childNodes[t.startOffset];
82
+ f ? i.setStartBefore(f) : i.setStartAfter(t.startContainer);
83
+ }
34
84
  const c = document.createRange();
35
- c.selectNode(s), t.endContainer.nodeType === Node.TEXT_NODE ? c.setEnd(s, t.endOffset) : c.setEndBefore(t.endContainer);
36
- const l = (u) => {
85
+ if (c.selectNode(s), t.endContainer.nodeType === Node.TEXT_NODE)
86
+ c.setEnd(s, t.endOffset);
87
+ else {
88
+ const f = t.endContainer.childNodes[t.endOffset];
89
+ f ? c.setEndBefore(f) : c.setEndAfter(t.endContainer);
90
+ }
91
+ const l = (f) => {
37
92
  const p = document.createRange();
38
- return p.selectNode(u), Array.from(p.getClientRects());
93
+ return p.selectNode(f), Array.from(p.getClientRects());
39
94
  };
40
95
  return [
41
96
  ...Array.from(i.getClientRects()),
@@ -43,7 +98,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
43
98
  ...Array.from(c.getClientRects())
44
99
  ];
45
100
  }
46
- }, Pt = function* (t) {
101
+ }, Mt = function* (t) {
47
102
  const e = document.createNodeIterator(
48
103
  t.commonAncestorContainer,
49
104
  NodeFilter.SHOW_ELEMENT,
@@ -52,11 +107,11 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
52
107
  let n;
53
108
  for (; n = e.nextNode(); )
54
109
  n instanceof HTMLElement && (yield n);
55
- }, _t = (t, e) => {
110
+ }, Ht = (t, e) => {
56
111
  if (!Lt(t, e)) return [];
57
112
  const n = [];
58
113
  let r = null;
59
- for (const o of Pt(e)) {
114
+ for (const o of Mt(e)) {
60
115
  let s;
61
116
  r ? (s = document.createRange(), s.setStartAfter(r), s.setEndBefore(o)) : (s = e.cloneRange(), s.setEndBefore(o)), s.collapsed || n.push(s), r = o;
62
117
  }
@@ -68,7 +123,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
68
123
  }, J = (t) => {
69
124
  const e = t.cloneContents();
70
125
  return e.querySelectorAll(W).forEach((n) => n.remove()), e;
71
- }, Dt = (t, e, n = 10, r) => {
126
+ }, Pt = (t, e, n = 10, r) => {
72
127
  const o = r ? t.startContainer.parentElement.closest(r) : e, s = document.createRange();
73
128
  s.setStart(o, 0), s.setEnd(t.startContainer, t.startOffset);
74
129
  const i = J(s).textContent, c = document.createRange();
@@ -78,7 +133,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
78
133
  prefix: i.substring(i.length - n),
79
134
  suffix: l.substring(0, n)
80
135
  };
81
- }, P = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), Ut = (t, e, n, r) => {
136
+ }, P = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), it = /^\s*$/, _t = (t) => it.test(t.toString()), Le = (t) => it.test(t.textContent || ""), Dt = (t, e, n, r) => {
82
137
  const o = (c) => Math.round(c * 10) / 10, s = {
83
138
  top: o(t.top),
84
139
  bottom: o(t.bottom),
@@ -102,26 +157,26 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
102
157
  return "block-contains";
103
158
  } else if (s.top >= i.top && s.bottom <= i.bottom && s.left >= i.left && s.right <= i.right)
104
159
  return "block-is-contained";
105
- }, Ft = (t, e) => {
160
+ }, Ut = (t, e) => {
106
161
  const n = Math.min(t.left, e.left), r = Math.max(t.right, e.right), o = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
107
162
  return new DOMRect(n, o, r - n, s - o);
108
- }, Kt = (t, e = 0.5, n = 0.5) => t.reduce((r, o) => {
163
+ }, Ft = (t, e = 0.5, n = 0.5) => t.reduce((r, o) => {
109
164
  if (o.width === 0 || o.height === 0)
110
165
  return r;
111
166
  let s = [...r], i = !1;
112
167
  for (const c of r) {
113
- const l = Ut(o, c, e, n);
168
+ const l = Dt(o, c, e, n);
114
169
  if (l === "inline-adjacent") {
115
- s = s.map((u) => u === c ? Ft(o, c) : u), i = !0;
170
+ s = s.map((f) => f === c ? Ut(o, c) : f), i = !0;
116
171
  break;
117
172
  } else if (l === "inline-contains") {
118
- s = s.map((u) => u === c ? o : u), i = !0;
173
+ s = s.map((f) => f === c ? o : f), i = !0;
119
174
  break;
120
175
  } else if (l === "inline-is-contained") {
121
176
  i = !0;
122
177
  break;
123
178
  } else if (l === "block-contains" || l === "block-is-contained") {
124
- o.width < c.width && (s = s.map((u) => u === c ? o : u)), o.width === c.width && o.height < c.width && (s = s.map((u) => u === c ? o : u)), i = !0;
179
+ o.width < c.width && (s = s.map((f) => f === c ? o : f)), o.width === c.width && o.height < c.width && (s = s.map((f) => f === c ? o : f)), i = !0;
125
180
  break;
126
181
  }
127
182
  }
@@ -133,44 +188,50 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
133
188
  for (let e = 0; e < this.length; e++)
134
189
  yield this.item(e);
135
190
  }
136
- }), $t = (t, e, n) => {
191
+ }), Kt = (t, e, n) => {
137
192
  const r = document.createRange(), o = n ? t.startContainer.parentElement.closest(n) : e;
138
193
  r.setStart(o, 0), r.setEnd(t.startContainer, t.startOffset);
139
194
  const s = J(r).textContent, i = t.toString(), c = s.length || 0, l = c + i.length;
140
195
  return n ? { quote: i, start: c, end: l, range: t, offsetReference: o } : { quote: i, start: c, end: l, range: t };
196
+ }, $t = (t, e) => {
197
+ const { left: n, top: r, right: o, bottom: s } = t;
198
+ return new DOMRect(n - e.left, r - e.top, o - n, s - r);
199
+ }, Oe = (t, e) => {
200
+ const { left: n, top: r, right: o, bottom: s } = t;
201
+ return new DOMRect(n + e.left, r + e.top, o - n, s - r);
141
202
  }, at = (t, e) => {
142
- var p, f;
203
+ var p, u;
143
204
  const { start: n, end: r } = t, o = t.offsetReference || e, s = document.createNodeIterator(
144
205
  e,
145
206
  NodeFilter.SHOW_TEXT,
146
- (g) => {
207
+ (m) => {
147
208
  var d;
148
- return (d = g.parentElement) != null && d.closest(W) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
209
+ return (d = m.parentElement) != null && d.closest(W) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
149
210
  }
150
211
  );
151
212
  let i = 0;
152
213
  const c = document.createRange();
153
214
  let l = s.nextNode();
154
215
  l === null && console.error("Could not revive annotation target. Content missing.");
155
- let u = !o;
216
+ let f = !o;
156
217
  for (; l !== null; ) {
157
- if (u || (u = typeof (o == null ? void 0 : o.contains) == "function" ? o.contains(l) : !1), u) {
158
- const g = ((p = l.textContent) == null ? void 0 : p.length) || 0;
159
- if (i + g > n) {
218
+ if (f || (f = typeof (o == null ? void 0 : o.contains) == "function" ? o.contains(l) : !1), f) {
219
+ const m = ((p = l.textContent) == null ? void 0 : p.length) || 0;
220
+ if (i + m > n) {
160
221
  c.setStart(l, n - i);
161
222
  break;
162
223
  }
163
- i += g;
224
+ i += m;
164
225
  }
165
226
  l = s.nextNode();
166
227
  }
167
228
  for (; l !== null; ) {
168
- const g = ((f = l.textContent) == null ? void 0 : f.length) || 0;
169
- if (i + g >= r) {
229
+ const m = ((u = l.textContent) == null ? void 0 : u.length) || 0;
230
+ if (i + m >= r) {
170
231
  c.setEnd(l, r - i);
171
232
  break;
172
233
  }
173
- i += g, l = s.nextNode();
234
+ i += m, l = s.nextNode();
174
235
  }
175
236
  return {
176
237
  ...t,
@@ -179,66 +240,18 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
179
240
  }, q = (t, e) => P(t.selector) ? t : {
180
241
  ...t,
181
242
  selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : at(n, e))
182
- }, G = (t, e) => P(t.target.selector) ? t : { ...t, target: q(t.target, e) }, Wt = (t, e) => {
243
+ }, Q = (t, e) => P(t.target.selector) ? t : { ...t, target: q(t.target, e) }, Wt = (t, e) => {
183
244
  const n = t.cloneRange();
184
245
  return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
185
- }, Q = (t) => ({
186
- ...t,
187
- type: t.type,
188
- x: t.x,
189
- y: t.y,
190
- clientX: t.clientX,
191
- clientY: t.clientY,
192
- offsetX: t.offsetX,
193
- offsetY: t.offsetY,
194
- screenX: t.screenX,
195
- screenY: t.screenY,
196
- isPrimary: t.isPrimary,
197
- altKey: t.altKey,
198
- ctrlKey: t.ctrlKey,
199
- metaKey: t.metaKey,
200
- shiftKey: t.shiftKey,
201
- button: t.button,
202
- buttons: t.buttons,
203
- currentTarget: t.currentTarget,
204
- target: t.target,
205
- defaultPrevented: t.defaultPrevented,
206
- detail: t.detail,
207
- eventPhase: t.eventPhase,
208
- pointerId: t.pointerId,
209
- pointerType: t.pointerType,
210
- timeStamp: t.timeStamp
211
- }), X = (t) => ({
212
- ...t,
213
- type: t.type,
214
- key: t.key,
215
- code: t.code,
216
- location: t.location,
217
- repeat: t.repeat,
218
- altKey: t.altKey,
219
- ctrlKey: t.ctrlKey,
220
- metaKey: t.metaKey,
221
- shiftKey: t.shiftKey,
222
- currentTarget: t.currentTarget,
223
- target: t.target,
224
- defaultPrevented: t.defaultPrevented,
225
- detail: t.detail,
226
- timeStamp: t.timeStamp
227
- }), Vt = (t, e) => {
228
- const { left: n, top: r, right: o, bottom: s } = t;
229
- return new DOMRect(n - e.left, r - e.top, o - n, s - r);
230
- }, Oe = (t, e) => {
231
- const { left: n, top: r, right: o, bottom: s } = t;
232
- return new DOMRect(n + e.left, r + e.top, o - n, s - r);
233
246
  }, ct = (t) => {
234
247
  if (!t)
235
248
  return document.scrollingElement;
236
249
  const { overflowY: e } = window.getComputedStyle(t);
237
250
  return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : ct(t.parentElement);
238
251
  }, et = (t, e, n) => {
239
- const r = n.getBoundingClientRect(), o = n.clientHeight, s = n.clientWidth, i = e.selector[0].range.getBoundingClientRect(), { width: c, height: l } = t.getAnnotationBounds(e.annotation), u = i.top - r.top, p = i.left - r.left, f = n.parentElement ? n.scrollTop : 0, g = n.parentElement ? n.scrollLeft : 0, d = u + f - (o - l) / 2, L = p + g - (s - c) / 2;
252
+ const r = n.getBoundingClientRect(), o = n.clientHeight, s = n.clientWidth, i = e.selector[0].range.getBoundingClientRect(), { width: c, height: l } = t.getAnnotationBounds(e.annotation), f = i.top - r.top, p = i.left - r.left, u = n.parentElement ? n.scrollTop : 0, m = n.parentElement ? n.scrollLeft : 0, d = f + u - (o - l) / 2, L = p + m - (s - c) / 2;
240
253
  n.scroll({ top: d, left: L, behavior: "smooth" });
241
- }, Yt = (t, e) => (n, r) => {
254
+ }, Vt = (t, e) => (n, r) => {
242
255
  const o = typeof n == "string" ? n : n.id, s = r ? typeof r == "string" ? document.getElementById(r) : r : ct(t);
243
256
  if (!s)
244
257
  return console.warn(`The scroll parent is missing for the annotation: ${o}`, { container: t }), !1;
@@ -248,22 +261,22 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
248
261
  const { range: c } = i.target.selector[0];
249
262
  if (c && !c.collapsed)
250
263
  return et(e, i.target, s), !0;
251
- const l = q(i.target, t), { range: u } = l.selector[0];
252
- return u && !u.collapsed ? (et(e, l, s), !0) : !1;
264
+ const l = q(i.target, t), { range: f } = l.selector[0];
265
+ return f && !f.collapsed ? (et(e, l, s), !0) : !1;
253
266
  }, _ = {
254
267
  fill: "rgb(0, 128, 255)",
255
268
  fillOpacity: 0.18
256
269
  }, j = {
257
270
  fill: "rgb(0, 128, 255)",
258
271
  fillOpacity: 0.45
259
- }, Xt = (t, e, n, r, o) => {
272
+ }, Yt = (t, e, n, r, o) => {
260
273
  var i, c;
261
274
  const s = n ? typeof n == "function" ? n(t.annotation, t.state, o) || ((i = t.state) != null && i.selected ? j : _) : n : (c = t.state) != null && c.selected ? j : _;
262
275
  return r && r.paint(t, e) || s;
263
- }, zt = (t) => {
276
+ }, Xt = (t) => {
264
277
  const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: r, innerHeight: o } = window, s = -n, i = -e, c = r - n, l = o - e;
265
278
  return { top: e, left: n, minX: s, minY: i, maxX: c, maxY: l };
266
- }, qt = (t) => {
279
+ }, zt = (t) => {
267
280
  let e = /* @__PURE__ */ new Set();
268
281
  return (r) => {
269
282
  const o = r.map((s) => s.id);
@@ -271,15 +284,15 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
271
284
  };
272
285
  }, tt = (t, e, n, r) => {
273
286
  const { store: o, selection: s, hover: i } = e;
274
- let c, l, u;
275
- const p = qt(n), f = $((S) => {
287
+ let c, l, f;
288
+ const p = zt(n), u = $((S) => {
276
289
  const { x: A, y: T } = t.getBoundingClientRect(), B = o.getAt(S.clientX - A, S.clientY - T, !1, l);
277
290
  B ? i.current !== B.id && (t.classList.add("hovered"), i.set(B.id)) : i.current && (t.classList.remove("hovered"), i.set(null));
278
291
  }, 10);
279
- t.addEventListener("pointermove", f);
280
- const g = $((S = !1) => requestAnimationFrame(() => {
281
- u && u.clear();
282
- const A = zt(t), { minX: T, minY: B, maxX: y, maxY: v } = A, I = l ? o.getIntersecting(T, B, y, v).filter(({ annotation: O }) => l(O)) : o.getIntersecting(T, B, y, v), D = s.selected.map(({ id: O }) => O), M = I.map(({ annotation: O, rects: H }) => {
292
+ t.addEventListener("pointermove", u);
293
+ const m = $((S = !1) => requestAnimationFrame(() => {
294
+ f && f.clear();
295
+ const A = Xt(t), { minX: T, minY: B, maxX: y, maxY: v } = A, I = l ? o.getIntersecting(T, B, y, v).filter(({ annotation: O }) => l(O)) : o.getIntersecting(T, B, y, v), D = s.selected.map(({ id: O }) => O), M = I.map(({ annotation: O, rects: H }) => {
283
296
  const k = D.includes(O.id), U = O.id === i.current;
284
297
  return {
285
298
  annotation: O,
@@ -287,71 +300,71 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
287
300
  state: { selected: k, hovered: U }
288
301
  };
289
302
  });
290
- r.redraw(M, A, c, u, S), setTimeout(() => p(I.map(({ annotation: O }) => O)), 1);
303
+ r.redraw(M, A, c, f, S), setTimeout(() => p(I.map(({ annotation: O }) => O)), 1);
291
304
  }), 10), d = (S) => {
292
- u = S, g();
305
+ f = S, m();
293
306
  }, L = (S) => {
294
- c = S, g();
307
+ c = S, m();
295
308
  }, w = (S) => {
296
- l = S, g(!1);
297
- }, x = () => g();
309
+ l = S, m(!1);
310
+ }, x = () => m();
298
311
  o.observe(x);
299
- const R = s.subscribe(() => g()), C = i.subscribe(() => g()), N = () => g(!0);
312
+ const R = s.subscribe(() => m()), C = i.subscribe(() => m()), N = () => m(!0);
300
313
  document.addEventListener("scroll", N, { capture: !0, passive: !0 });
301
314
  const E = $(() => {
302
- o.recalculatePositions(), u == null || u.reset(), g();
315
+ o.recalculatePositions(), f == null || f.reset(), m();
303
316
  }, 10);
304
317
  window.addEventListener("resize", E);
305
318
  const a = new ResizeObserver(E);
306
319
  a.observe(t);
307
- const m = { attributes: !0, childList: !0, subtree: !0 }, b = new MutationObserver($((S) => {
308
- S.every((T) => T.target === t || t.contains(T.target)) || g(!0);
320
+ const g = { attributes: !0, childList: !0, subtree: !0 }, b = new MutationObserver($((S) => {
321
+ S.every((T) => T.target === t || t.contains(T.target)) || m(!0);
309
322
  }, 150));
310
- return b.observe(document.body, m), {
323
+ return b.observe(document.body, g), {
311
324
  destroy: () => {
312
- t.removeEventListener("pointermove", f), r.destroy(), o.unobserve(x), R(), C(), document.removeEventListener("scroll", N), E.clear(), window.removeEventListener("resize", E), a.disconnect(), b.disconnect();
325
+ t.removeEventListener("pointermove", u), r.destroy(), o.unobserve(x), R(), C(), document.removeEventListener("scroll", N), E.clear(), window.removeEventListener("resize", E), a.disconnect(), b.disconnect();
313
326
  },
314
- redraw: g,
327
+ redraw: m,
315
328
  setStyle: L,
316
329
  setFilter: w,
317
330
  setPainter: d,
318
331
  setVisible: r.setVisible
319
332
  };
320
- }, jt = () => {
333
+ }, qt = () => {
321
334
  const t = document.createElement("canvas");
322
335
  return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
323
- }, Gt = (t, e) => {
336
+ }, jt = (t, e) => {
324
337
  t.width = window.innerWidth, t.height = window.innerHeight;
325
- }, Qt = (t) => {
338
+ }, Gt = (t) => {
326
339
  t.classList.add("r6o-annotatable");
327
- const e = jt(), n = e.getContext("2d");
340
+ const e = qt(), n = e.getContext("2d");
328
341
  document.body.appendChild(e);
329
- const r = (c, l, u, p) => requestAnimationFrame(() => {
330
- const { width: f, height: g } = e;
331
- n.clearRect(-0.5, -0.5, f + 1, g + 1), p && p.clear();
342
+ const r = (c, l, f, p) => requestAnimationFrame(() => {
343
+ const { width: u, height: m } = e;
344
+ n.clearRect(-0.5, -0.5, u + 1, m + 1), p && p.clear();
332
345
  const { top: d, left: L } = l;
333
346
  [...c].sort((x, R) => {
334
347
  const { annotation: { target: { created: C } } } = x, { annotation: { target: { created: N } } } = R;
335
348
  return C.getTime() - N.getTime();
336
349
  }).forEach((x) => {
337
350
  var E;
338
- const R = u ? typeof u == "function" ? u(x.annotation, x.state) : u : (E = x.state) != null && E.selected ? j : _, C = p && p.paint(x, l) || R, N = x.rects.map(({ x: a, y: m, width: b, height: h }) => ({
351
+ const R = f ? typeof f == "function" ? f(x.annotation, x.state) : f : (E = x.state) != null && E.selected ? j : _, C = p && p.paint(x, l) || R, N = x.rects.map(({ x: a, y: g, width: b, height: h }) => ({
339
352
  x: a + L,
340
- y: m + d,
353
+ y: g + d,
341
354
  width: b,
342
355
  height: h
343
356
  }));
344
357
  if (n.fillStyle = C.fill, n.globalAlpha = C.fillOpacity || 1, N.forEach(
345
- ({ x: a, y: m, width: b, height: h }) => n.fillRect(a, m, b, h)
358
+ ({ x: a, y: g, width: b, height: h }) => n.fillRect(a, g, b, h)
346
359
  ), C.underlineColor) {
347
360
  n.globalAlpha = 1, n.strokeStyle = C.underlineColor, n.lineWidth = C.underlineThickness ?? 1;
348
361
  const a = C.underlineOffset ?? 0;
349
- N.forEach(({ x: m, y: b, width: h, height: S }) => {
350
- n.beginPath(), n.moveTo(m, b + S + a), n.lineTo(m + h, b + S + a), n.stroke();
362
+ N.forEach(({ x: g, y: b, width: h, height: S }) => {
363
+ n.beginPath(), n.moveTo(g, b + S + a), n.lineTo(g + h, b + S + a), n.stroke();
351
364
  });
352
365
  }
353
366
  });
354
- }), o = $(() => Gt(e), 10);
367
+ }), o = $(() => jt(e), 10);
355
368
  return window.addEventListener("resize", o), {
356
369
  destroy: () => {
357
370
  e.remove(), o.clear(), window.removeEventListener("resize", o);
@@ -361,13 +374,13 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
361
374
  },
362
375
  redraw: r
363
376
  };
364
- }, Zt = (t, e, n) => tt(t, e, n, Qt(t)), Jt = (t) => [
377
+ }, Qt = (t, e, n) => tt(t, e, n, Gt(t)), Zt = (t) => [
365
378
  `background-color:${Z((t == null ? void 0 : t.fill) || _.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? _.fillOpacity : t.fillOpacity).toHex()}`,
366
379
  t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
367
380
  t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
368
381
  t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
369
382
  t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
370
- ].filter(Boolean).join(";"), te = () => {
383
+ ].filter(Boolean).join(";"), Jt = () => {
371
384
  const t = document.createElement("style");
372
385
  document.getElementsByTagName("head")[0].appendChild(t);
373
386
  let e = /* @__PURE__ */ new Set();
@@ -380,24 +393,24 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
380
393
  },
381
394
  redraw: (s, i, c, l) => {
382
395
  l && l.clear();
383
- const u = new Set(s.map((f) => f.annotation.id));
384
- Array.from(e).filter((f) => !u.has(f));
385
- const p = s.map((f) => {
396
+ const f = new Set(s.map((u) => u.annotation.id));
397
+ Array.from(e).filter((u) => !f.has(u));
398
+ const p = s.map((u) => {
386
399
  var L;
387
- const g = c ? typeof c == "function" ? c(f.annotation, f.state) : c : (L = f.state) != null && L.selected ? j : _, d = l && l.paint(f, i) || g;
388
- return `::highlight(_${f.annotation.id}) { ${Jt(d)} }`;
400
+ const m = c ? typeof c == "function" ? c(u.annotation, u.state) : c : (L = u.state) != null && L.selected ? j : _, d = l && l.paint(u, i) || m;
401
+ return `::highlight(_${u.annotation.id}) { ${Zt(d)} }`;
389
402
  });
390
403
  t.innerHTML = p.join(`
391
- `), CSS.highlights.clear(), s.forEach(({ annotation: f }) => {
392
- const g = f.target.selector.map((L) => L.range), d = new Highlight(...g);
393
- CSS.highlights.set(`_${f.id}`, d);
394
- }), e = u;
404
+ `), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
405
+ const m = u.target.selector.map((L) => L.range), d = new Highlight(...m);
406
+ CSS.highlights.set(`_${u.id}`, d);
407
+ }), e = f;
395
408
  }
396
409
  };
397
- }, ee = (t, e, n) => tt(t, e, n, te()), ne = (t) => (t == null ? void 0 : t.fillOpacity) !== void 0 ? Z((t == null ? void 0 : t.fill) || _.fill).alpha(t.fillOpacity).toHex() : t != null && t.fill ? t.fill : Z(_.fill).alpha(_.fillOpacity).toHex(), oe = (t, e) => {
410
+ }, te = (t, e, n) => tt(t, e, n, Jt()), ee = (t) => (t == null ? void 0 : t.fillOpacity) !== void 0 ? Z((t == null ? void 0 : t.fill) || _.fill).alpha(t.fillOpacity).toHex() : t != null && t.fill ? t.fill : Z(_.fill).alpha(_.fillOpacity).toHex(), ne = (t, e) => {
398
411
  const n = (s, i) => s.x <= i.x + i.width && s.x + s.width >= i.x && s.y <= i.y + i.height && s.y + s.height >= i.y, r = (s) => s.rects.reduce((i, c) => i + c.width, 0), o = e.filter(({ rects: s }) => s.some((i) => n(t, i)));
399
412
  return o.sort((s, i) => r(i) - r(s)), o.findIndex((s) => s.rects.includes(t));
400
- }, se = (t) => {
413
+ }, oe = (t) => {
401
414
  t.classList.add("r6o-annotatable");
402
415
  const e = document.createElement("div");
403
416
  e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
@@ -406,18 +419,18 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
406
419
  destroy: () => {
407
420
  e.remove();
408
421
  },
409
- redraw: (i, c, l, u, p) => {
410
- const g = !(gt(n, i) && p);
411
- if (!u && !g) return;
412
- g && (e.innerHTML = ""), [...i].sort((L, w) => {
422
+ redraw: (i, c, l, f, p) => {
423
+ const m = !(gt(n, i) && p);
424
+ if (!f && !m) return;
425
+ m && (e.innerHTML = ""), [...i].sort((L, w) => {
413
426
  const { annotation: { target: { created: x } } } = L, { annotation: { target: { created: R } } } = w;
414
427
  return x && R ? x.getTime() - R.getTime() : 0;
415
428
  }).forEach((L) => {
416
429
  L.rects.map((w) => {
417
- const x = oe(w, i), R = Xt(L, c, l, u, x);
418
- if (g) {
430
+ const x = ne(w, i), R = Yt(L, c, l, f, x);
431
+ if (m) {
419
432
  const C = document.createElement("span");
420
- C.className = "r6o-annotation", C.dataset.annotation = L.annotation.id, C.style.left = `${w.x}px`, C.style.top = `${w.y}px`, C.style.width = `${w.width}px`, C.style.height = `${w.height}px`, C.style.backgroundColor = ne(R), R.underlineStyle && (C.style.borderStyle = R.underlineStyle), R.underlineColor && (C.style.borderColor = R.underlineColor), R.underlineThickness && (C.style.borderBottomWidth = `${R.underlineThickness}px`), R.underlineOffset && (C.style.paddingBottom = `${R.underlineOffset}px`), e.appendChild(C);
433
+ C.className = "r6o-annotation", C.dataset.annotation = L.annotation.id, C.style.left = `${w.x}px`, C.style.top = `${w.y}px`, C.style.width = `${w.width}px`, C.style.height = `${w.height}px`, C.style.backgroundColor = ee(R), R.underlineStyle && (C.style.borderStyle = R.underlineStyle), R.underlineColor && (C.style.borderColor = R.underlineColor), R.underlineThickness && (C.style.borderBottomWidth = `${R.underlineThickness}px`), R.underlineOffset && (C.style.paddingBottom = `${R.underlineOffset}px`), e.appendChild(C);
421
434
  }
422
435
  });
423
436
  }), n = i;
@@ -426,10 +439,10 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
426
439
  i ? e.classList.remove("hidden") : e.classList.add("hidden");
427
440
  }
428
441
  };
429
- }, re = (t, e, n) => tt(t, e, n, se(t)), ke = (t, e) => ({
430
- parse: (n) => ce(n),
431
- serialize: (n) => le(n, t, e)
432
- }), ie = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, ae = (t) => {
442
+ }, se = (t, e, n) => tt(t, e, n, oe(t)), ke = (t, e) => ({
443
+ parse: (n) => ae(n),
444
+ serialize: (n) => ce(n, t, e)
445
+ }), re = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, ie = (t) => {
433
446
  const {
434
447
  id: e,
435
448
  creator: n,
@@ -449,18 +462,18 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
449
462
  styleClass: "styleClass" in i[0] ? i[0].styleClass : void 0
450
463
  };
451
464
  for (const l of i) {
452
- const p = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((f, g) => {
453
- switch (g.type) {
465
+ const p = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((u, m) => {
466
+ switch (m.type) {
454
467
  case "TextQuoteSelector":
455
- f.quote = g.exact;
468
+ u.quote = m.exact;
456
469
  break;
457
470
  case "TextPositionSelector":
458
- f.start = g.start, f.end = g.end;
471
+ u.start = m.start, u.end = m.end;
459
472
  break;
460
473
  }
461
- return f;
474
+ return u;
462
475
  }, {});
463
- if (c.outdated || (c.outdated = "outdated" in l ? l.outdated : void 0), ie(p))
476
+ if (c.outdated || (c.outdated = "outdated" in l ? l.outdated : void 0), re(p))
464
477
  c.selector.push(
465
478
  {
466
479
  ...p,
@@ -470,22 +483,22 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
470
483
  }
471
484
  );
472
485
  else {
473
- const f = [
486
+ const u = [
474
487
  p.start ? void 0 : "TextPositionSelector",
475
488
  p.quote ? void 0 : "TextQuoteSelector"
476
489
  ].filter(Boolean);
477
- return { error: Error(`Missing selector types: ${f.join(" and ")} for annotation: ${t.id}`) };
490
+ return { error: Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`) };
478
491
  }
479
492
  }
480
493
  return { parsed: c };
481
- }, ce = (t) => {
494
+ }, ae = (t) => {
482
495
  const e = t.id || st(), {
483
496
  creator: n,
484
497
  created: r,
485
498
  modified: o,
486
499
  body: s,
487
500
  ...i
488
- } = t, c = pt(s, e), l = ae(t);
501
+ } = t, c = pt(s, e), l = ie(t);
489
502
  return "error" in l ? { error: l.error } : {
490
503
  parsed: {
491
504
  ...i,
@@ -494,20 +507,20 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
494
507
  target: l.parsed
495
508
  }
496
509
  };
497
- }, le = (t, e, n) => {
510
+ }, ce = (t, e, n) => {
498
511
  const { bodies: r, target: o, ...s } = t, {
499
512
  selector: i,
500
513
  creator: c,
501
514
  created: l,
502
- updated: u,
515
+ updated: f,
503
516
  ...p
504
- } = o, f = i.map((g) => {
505
- const { id: d, quote: L, start: w, end: x, range: R } = g, C = {
517
+ } = o, u = i.map((m) => {
518
+ const { id: d, quote: L, start: w, end: x, range: R } = m, C = {
506
519
  type: "TextQuoteSelector",
507
520
  exact: L
508
521
  };
509
522
  if (n) {
510
- const { prefix: E, suffix: a } = Dt(R, n);
523
+ const { prefix: E, suffix: a } = Pt(R, n);
511
524
  C.prefix = E, C.suffix = a;
512
525
  }
513
526
  const N = {
@@ -519,7 +532,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
519
532
  ...p,
520
533
  id: d,
521
534
  // @ts-expect-error: `scope` is not part of the core `TextSelector` type
522
- scope: "scope" in g ? g.scope : void 0,
535
+ scope: "scope" in m ? m.scope : void 0,
523
536
  source: e,
524
537
  selector: [C, N]
525
538
  };
@@ -532,15 +545,15 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
532
545
  body: mt(t.bodies),
533
546
  creator: c,
534
547
  created: l == null ? void 0 : l.toISOString(),
535
- modified: u == null ? void 0 : u.toISOString(),
536
- target: f
548
+ modified: f == null ? void 0 : f.toISOString(),
549
+ target: u
537
550
  };
538
- }, de = (t, e, n, r) => {
539
- const o = new xt(), s = /* @__PURE__ */ new Map(), i = Tt(), c = (a, m) => {
551
+ }, le = (t, e, n, r) => {
552
+ const o = new xt(), s = /* @__PURE__ */ new Map(), i = Tt(), c = (a, g) => {
540
553
  const b = a.selector.flatMap((S) => {
541
554
  const A = P([S]) ? S.range : at(S, e).range;
542
- return Ht(A);
543
- }), h = Kt(b, n, r).map((S) => Vt(S, m));
555
+ return It(A);
556
+ }), h = Ft(b, n, r).map((S) => $t(S, g));
544
557
  return h.map((S) => {
545
558
  const { x: A, y: T, width: B, height: y } = S;
546
559
  return {
@@ -554,54 +567,54 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
554
567
  }
555
568
  };
556
569
  });
557
- }, l = () => [...s.values()], u = () => {
570
+ }, l = () => [...s.values()], f = () => {
558
571
  o.clear(), s.clear();
559
572
  }, p = (a) => {
560
- const m = c(a, e.getBoundingClientRect());
561
- m.length !== 0 && (m.forEach((b) => o.insert(b)), s.set(a.annotation, m));
562
- }, f = (a) => {
563
- const m = s.get(a.annotation);
564
- m && (m.forEach((b) => o.remove(b)), s.delete(a.annotation));
565
- }, g = (a) => {
566
- f(a), p(a);
567
- }, d = (a, m = !0) => {
568
- m && u();
573
+ const g = c(a, e.getBoundingClientRect());
574
+ g.length !== 0 && (g.forEach((b) => o.insert(b)), s.set(a.annotation, g));
575
+ }, u = (a) => {
576
+ const g = s.get(a.annotation);
577
+ g && (g.forEach((b) => o.remove(b)), s.delete(a.annotation));
578
+ }, m = (a) => {
579
+ u(a), p(a);
580
+ }, d = (a, g = !0) => {
581
+ g && f();
569
582
  const b = e.getBoundingClientRect(), h = a.map((A) => ({ target: A, rects: c(A, b) }));
570
583
  h.forEach(({ target: A, rects: T }) => {
571
584
  T.length > 0 && s.set(A.annotation, T);
572
585
  });
573
586
  const S = h.flatMap(({ rects: A }) => A);
574
587
  o.load(S);
575
- }, L = (a, m, b = !1) => {
588
+ }, L = (a, g, b = !1) => {
576
589
  const h = o.search({
577
590
  minX: a,
578
- minY: m,
591
+ minY: g,
579
592
  maxX: a,
580
- maxY: m
593
+ maxY: g
581
594
  }), S = (A) => A.annotation.rects.reduce((T, B) => T + B.width * B.height, 0);
582
595
  return h.length > 0 ? (h.sort((A, T) => S(A) - S(T)), b ? h.map((A) => A.annotation.id) : [h[0].annotation.id]) : [];
583
596
  }, w = (a) => {
584
- const m = x(a);
585
- if (m.length === 0)
597
+ const g = x(a);
598
+ if (g.length === 0)
586
599
  return;
587
- let b = m[0].left, h = m[0].top, S = m[0].right, A = m[0].bottom;
588
- for (let T = 1; T < m.length; T++) {
589
- const B = m[T];
600
+ let b = g[0].left, h = g[0].top, S = g[0].right, A = g[0].bottom;
601
+ for (let T = 1; T < g.length; T++) {
602
+ const B = g[T];
590
603
  b = Math.min(b, B.left), h = Math.min(h, B.top), S = Math.max(S, B.right), A = Math.max(A, B.bottom);
591
604
  }
592
605
  return new DOMRect(b, h, S - b, A - h);
593
606
  }, x = (a) => {
594
- const m = s.get(a);
595
- return m ? m[0].annotation.rects : [];
607
+ const g = s.get(a);
608
+ return g ? g[0].annotation.rects : [];
596
609
  };
597
610
  return {
598
611
  all: l,
599
- clear: u,
612
+ clear: f,
600
613
  getAt: L,
601
614
  getAnnotationBounds: w,
602
615
  getAnnotationRects: x,
603
- getIntersecting: (a, m, b, h) => {
604
- const S = o.search({ minX: a, minY: m, maxX: b, maxY: h }), A = new Set(S.map((T) => T.annotation.id));
616
+ getIntersecting: (a, g, b, h) => {
617
+ const S = o.search({ minX: a, minY: g, maxX: b, maxY: h }), A = new Set(S.map((T) => T.annotation.id));
605
618
  return Array.from(A).map((T) => ({
606
619
  annotation: t.getAnnotation(T),
607
620
  rects: x(T)
@@ -611,52 +624,52 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
611
624
  recalculate: () => {
612
625
  d(t.all().map((a) => a.target), !0), i.emit("recalculate");
613
626
  },
614
- remove: f,
627
+ remove: u,
615
628
  set: d,
616
629
  size: () => o.all().length,
617
- update: g,
618
- on: (a, m) => i.on(a, m)
630
+ update: m,
631
+ on: (a, g) => i.on(a, g)
619
632
  };
620
- }, fe = (t, e) => {
633
+ }, de = (t, e) => {
621
634
  var C, N;
622
- const n = bt(), r = de(n, t, (C = e.mergeHighlights) == null ? void 0 : C.horizontalTolerance, (N = e.mergeHighlights) == null ? void 0 : N.verticalTolerance), o = yt(n, e.userSelectAction, e.adapter), s = St(n), i = Ct(), c = (E, a = K.LOCAL) => {
623
- const m = G(E, t), b = P(m.target.selector);
624
- return b && n.addAnnotation(m, a), b;
625
- }, l = (E, a = !0, m = K.LOCAL) => {
626
- const b = E.map((S) => G(S, t)), h = b.filter((S) => !P(S.target.selector));
627
- return n.bulkAddAnnotations(b, a, m), h;
628
- }, u = (E, a = K.LOCAL) => {
629
- const m = E.map((h) => G(h, t)), b = m.filter((h) => !P(h.target.selector));
630
- return m.forEach((h) => {
635
+ const n = bt(), r = le(n, t, (C = e.mergeHighlights) == null ? void 0 : C.horizontalTolerance, (N = e.mergeHighlights) == null ? void 0 : N.verticalTolerance), o = yt(n, e.userSelectAction, e.adapter), s = St(n), i = Ct(), c = (E, a = K.LOCAL) => {
636
+ const g = Q(E, t), b = P(g.target.selector);
637
+ return b && n.addAnnotation(g, a), b;
638
+ }, l = (E, a = !0, g = K.LOCAL) => {
639
+ const b = E.map((S) => Q(S, t)), h = b.filter((S) => !P(S.target.selector));
640
+ return n.bulkAddAnnotations(b, a, g), h;
641
+ }, f = (E, a = K.LOCAL) => {
642
+ const g = E.map((h) => Q(h, t)), b = g.filter((h) => !P(h.target.selector));
643
+ return g.forEach((h) => {
631
644
  n.getAnnotation(h.id) ? n.updateAnnotation(h, a) : n.addAnnotation(h, a);
632
645
  }), b;
633
646
  }, p = (E, a = K.LOCAL) => {
634
- const m = q(E, t);
635
- n.updateTarget(m, a);
636
- }, f = (E, a = K.LOCAL) => {
637
- const m = E.map((b) => q(b, t));
638
- n.bulkUpdateTargets(m, a);
647
+ const g = q(E, t);
648
+ n.updateTarget(g, a);
649
+ }, u = (E, a = K.LOCAL) => {
650
+ const g = E.map((b) => q(b, t));
651
+ n.bulkUpdateTargets(g, a);
639
652
  };
640
- function g(E, a, m, b) {
641
- const h = m || !!b, S = r.getAt(E, a, h).map((T) => n.getAnnotation(T)), A = b ? S.filter(b) : S;
653
+ function m(E, a, g, b) {
654
+ const h = g || !!b, S = r.getAt(E, a, h).map((T) => n.getAnnotation(T)), A = b ? S.filter(b) : S;
642
655
  if (A.length !== 0)
643
- return m ? A : A[0];
656
+ return g ? A : A[0];
644
657
  }
645
- const d = (E) => r.getAnnotationRects(E).length > 0 ? r.getAnnotationBounds(E) : void 0, L = (E, a, m, b) => r.getIntersecting(E, a, m, b), w = (E) => r.getAnnotationRects(E), x = () => r.recalculate(), R = (E) => r.on("recalculate", E);
658
+ const d = (E) => r.getAnnotationRects(E).length > 0 ? r.getAnnotationBounds(E) : void 0, L = (E, a, g, b) => r.getIntersecting(E, a, g, b), w = (E) => r.getAnnotationRects(E), x = () => r.recalculate(), R = (E) => r.on("recalculate", E);
646
659
  return n.observe(({ changes: E }) => {
647
- const a = (E.deleted || []).filter((h) => P(h.target.selector)), m = (E.created || []).filter((h) => P(h.target.selector)), b = (E.updated || []).filter((h) => P(h.newValue.target.selector));
648
- (a == null ? void 0 : a.length) > 0 && a.forEach((h) => r.remove(h.target)), m.length > 0 && r.set(m.map((h) => h.target), !1), (b == null ? void 0 : b.length) > 0 && b.forEach(({ newValue: h }) => r.update(h.target));
660
+ const a = (E.deleted || []).filter((h) => P(h.target.selector)), g = (E.created || []).filter((h) => P(h.target.selector)), b = (E.updated || []).filter((h) => P(h.newValue.target.selector));
661
+ (a == null ? void 0 : a.length) > 0 && a.forEach((h) => r.remove(h.target)), g.length > 0 && r.set(g.map((h) => h.target), !1), (b == null ? void 0 : b.length) > 0 && b.forEach(({ newValue: h }) => r.update(h.target));
649
662
  }), {
650
663
  store: {
651
664
  ...n,
652
665
  addAnnotation: c,
653
666
  bulkAddAnnotations: l,
654
- bulkUpdateTargets: f,
655
- bulkUpsertAnnotations: u,
667
+ bulkUpdateTargets: u,
668
+ bulkUpsertAnnotations: f,
656
669
  getAnnotationBounds: d,
657
670
  getAnnotationRects: w,
658
671
  getIntersecting: L,
659
- getAt: g,
672
+ getAt: m,
660
673
  recalculatePositions: x,
661
674
  onRecalculatePositions: R,
662
675
  updateTarget: p
@@ -665,35 +678,35 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
665
678
  hover: s,
666
679
  viewport: i
667
680
  };
668
- }, ue = () => {
681
+ }, fe = () => {
669
682
  const t = document.createElement("canvas");
670
683
  t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
671
684
  const e = t.getContext("2d");
672
685
  return e.scale(2, 2), e.translate(0.5, 0.5), t;
673
- }, ge = (t, e = {}) => {
674
- const n = ue(), r = n.getContext("2d");
686
+ }, ue = (t, e = {}) => {
687
+ const n = fe(), r = n.getContext("2d");
675
688
  document.body.appendChild(n);
676
- const o = /* @__PURE__ */ new Map(), s = (p) => Array.from(o.entries()).filter(([f, g]) => g.presenceKey === p.presenceKey).map(([f, g]) => f);
677
- return t.on("selectionChange", (p, f) => {
678
- s(p).forEach((d) => o.delete(d)), f && f.forEach((d) => o.set(d, p));
689
+ const o = /* @__PURE__ */ new Map(), s = (p) => Array.from(o.entries()).filter(([u, m]) => m.presenceKey === p.presenceKey).map(([u, m]) => u);
690
+ return t.on("selectionChange", (p, u) => {
691
+ s(p).forEach((d) => o.delete(d)), u && u.forEach((d) => o.set(d, p));
679
692
  }), {
680
693
  clear: () => {
681
- const { width: p, height: f } = n;
682
- r.clearRect(-0.5, -0.5, p + 1, f + 1);
694
+ const { width: p, height: u } = n;
695
+ r.clearRect(-0.5, -0.5, p + 1, u + 1);
683
696
  },
684
697
  destroy: () => {
685
698
  n.remove();
686
699
  },
687
- paint: (p, f, g) => {
700
+ paint: (p, u, m) => {
688
701
  e.font && (r.font = e.font);
689
702
  const d = o.get(p.annotation.id);
690
703
  if (d) {
691
- const { height: L } = p.rects[0], w = p.rects[0].x + f.left, x = p.rects[0].y + f.top;
704
+ const { height: L } = p.rects[0], w = p.rects[0].x + u.left, x = p.rects[0].y + u.top;
692
705
  r.fillStyle = d.appearance.color, r.fillRect(w - 2, x - 2.5, 2, L + 5);
693
706
  const R = r.measureText(d.appearance.label), C = R.width + 6, N = R.actualBoundingBoxAscent + R.actualBoundingBoxDescent + 8, E = R.fontBoundingBoxAscent ? 8 : 6.5;
694
707
  return r.fillRect(w - 2, x - 2.5 - N, C, N), r.fillStyle = "#fff", r.fillText(d.appearance.label, w + 1, x - E), {
695
708
  fill: d.appearance.color,
696
- fillOpacity: g ? 0.45 : 0.18
709
+ fillOpacity: m ? 0.45 : 0.18
697
710
  };
698
711
  }
699
712
  },
@@ -703,20 +716,20 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
703
716
  p.scale(2, 2), p.translate(0.5, 0.5);
704
717
  }
705
718
  };
706
- }, nt = 300, lt = ["up", "down", "left", "right"], dt = kt ? "⌘+a" : "ctrl+a", me = [
719
+ }, nt = 300, lt = ["up", "down", "left", "right"], dt = kt ? "⌘+a" : "ctrl+a", ge = [
707
720
  ...lt.map((t) => `shift+${t}`),
708
721
  dt
709
- ], pe = (t, e, n) => {
722
+ ], me = (t, e, n) => {
710
723
  const { store: r, selection: o } = e;
711
724
  let s;
712
725
  const {
713
726
  annotatingEnabled: i,
714
727
  offsetReferenceSelector: c,
715
728
  selectionMode: l,
716
- dismissOnNotAnnotatable: u = "NEVER"
729
+ dismissOnNotAnnotatable: f = "NEVER"
717
730
  } = n, p = (y) => s = y;
718
- let f;
719
- const g = (y) => f = y;
731
+ let u;
732
+ const m = (y) => u = y;
720
733
  let d, L, w, x = i;
721
734
  const R = (y) => {
722
735
  x = y, N.clear(), y || (d = void 0, L = void 0, w = void 0);
@@ -743,31 +756,31 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
743
756
  return;
744
757
  }
745
758
  const M = I.map((k) => Wt(k, t));
746
- if (M.every((k) => It(k))) return;
747
- const O = M.flatMap((k) => _t(t, k.cloneRange()));
759
+ if (M.every((k) => _t(k))) return;
760
+ const O = M.flatMap((k) => Ht(t, k.cloneRange()));
748
761
  (O.length > 0 && !d || O.length !== d.selector.length || O.some((k, U) => {
749
762
  var F;
750
763
  return k.toString() !== ((F = d.selector[U]) == null ? void 0 : F.quote);
751
764
  })) && (d = {
752
765
  ...d,
753
- selector: O.map((k) => $t(k, t, c)),
766
+ selector: O.map((k) => Kt(k, t, c)),
754
767
  updated: /* @__PURE__ */ new Date()
755
768
  }, r.getAnnotation(d.annotation) ? r.updateTarget(d, K.LOCAL) : o.clear());
756
769
  }, 10), E = (y) => {
757
- w = Q(y), L = w.button === 0;
770
+ w = G(y), L = w.button === 0;
758
771
  }, a = async (y) => {
759
772
  if (!L) return;
760
- const v = Q(y), I = () => {
773
+ const v = G(y), I = () => {
761
774
  const { x: M, y: O } = t.getBoundingClientRect();
762
775
  if (z(t, v.target)) {
763
- (typeof u == "function" ? u(v, t) : u === "ALWAYS") && o.clear();
776
+ (typeof f == "function" ? f(v, t) : f === "ALWAYS") && o.clear();
764
777
  return;
765
778
  }
766
779
  const H = v.target instanceof Node && t.contains(v.target) && r.getAt(
767
780
  v.clientX - M,
768
781
  v.clientY - O,
769
782
  l === "all",
770
- f
783
+ u
771
784
  );
772
785
  if (H) {
773
786
  const { selected: k } = o, U = new Set(k.map((V) => V.id)), F = Array.isArray(H) ? H.map((V) => V.id) : [H.id];
@@ -776,7 +789,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
776
789
  o.clear();
777
790
  };
778
791
  if (v.timeStamp - w.timeStamp < nt) {
779
- await m();
792
+ await g();
780
793
  const M = document.getSelection(), O = z(t, w.target), H = z(t, v.target);
781
794
  if (M != null && M.isCollapsed || O && H) {
782
795
  d = void 0, I();
@@ -784,14 +797,14 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
784
797
  }
785
798
  }
786
799
  d && d.selector.length > 0 && (T(), o.userSelect(d.annotation, v));
787
- }, m = async () => {
800
+ }, g = async () => {
788
801
  const y = document.getSelection();
789
802
  let v = !1, I = y == null ? void 0 : y.isCollapsed;
790
803
  const D = () => I || v, M = 1;
791
804
  return setTimeout(() => v = !0, 50), Rt(() => I = y == null ? void 0 : y.isCollapsed, M, D);
792
805
  }, b = (y) => {
793
806
  const v = document.getSelection();
794
- v != null && v.isCollapsed || ((!d || d.selector.length === 0) && N(y), d && (T(), o.userSelect(d.annotation, Q(y))));
807
+ v != null && v.isCollapsed || ((!d || d.selector.length === 0) && N(y), d && (T(), o.userSelect(d.annotation, G(y))));
795
808
  }, h = (y) => {
796
809
  x && y.key === "Shift" && d && (document.getSelection().isCollapsed || (T(), o.userSelect(d.annotation, X(y))));
797
810
  }, S = (y) => {
@@ -804,7 +817,7 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
804
817
  }, 100);
805
818
  document.addEventListener("selectionchange", v), C();
806
819
  };
807
- Y(me.join(","), { element: t, keydown: !0, keyup: !1 }, (y) => {
820
+ Y(ge.join(","), { element: t, keydown: !0, keyup: !1 }, (y) => {
808
821
  y.repeat || (w = X(y));
809
822
  }), Y(dt, { keydown: !0, keyup: !1 }, (y) => {
810
823
  w = X(y), S(y);
@@ -830,58 +843,58 @@ const rt = "not-annotatable", W = `.${rt}`, z = (t, e) => {
830
843
  destroy: () => {
831
844
  d = void 0, L = void 0, w = void 0, N.clear(), document.removeEventListener("pointerdown", E), document.removeEventListener("pointerup", a), document.removeEventListener("contextmenu", b), t.removeEventListener("keyup", h), t.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", N), Y.unbind();
832
845
  },
833
- setFilter: g,
846
+ setFilter: m,
834
847
  setUser: p,
835
848
  setAnnotatingEnabled: R
836
849
  };
837
- }, he = (t, e) => ({
850
+ }, pe = (t, e) => ({
838
851
  ...t,
839
852
  annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
840
853
  user: t.user || e.user
841
854
  }), ot = "SPANS", Be = (t, e = {}) => {
842
855
  Nt(t), Bt(t);
843
- const n = he(e, {
856
+ const n = pe(e, {
844
857
  annotatingEnabled: !0,
845
858
  user: Et()
846
- }), r = fe(t, n), { selection: o, viewport: s } = r, i = r.store, c = wt(i), l = At(r, c, n.adapter);
847
- let u = n.user;
848
- const p = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ot : n.renderer || ot, f = p === "SPANS" ? re(t, r, s) : p === "CSS_HIGHLIGHTS" ? ee(t, r, s) : p === "CANVAS" ? Zt(t, r, s) : void 0;
849
- if (!f)
859
+ }), r = de(t, n), { selection: o, viewport: s } = r, i = r.store, c = wt(i), l = At(r, c, n.adapter);
860
+ let f = n.user;
861
+ const p = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : ot : n.renderer || ot, u = p === "SPANS" ? se(t, r, s) : p === "CSS_HIGHLIGHTS" ? te(t, r, s) : p === "CANVAS" ? Qt(t, r, s) : void 0;
862
+ if (!u)
850
863
  throw `Unknown renderer implementation: ${p}`;
851
- console.debug(`Using ${p} renderer`), n.style && f.setStyle(n.style);
852
- const g = pe(t, r, n);
853
- g.setUser(u), g.setAnnotatingEnabled(n.annotatingEnabled);
854
- const d = vt(r, c, n.adapter), L = () => u, w = (a) => {
855
- g.setAnnotatingEnabled(
864
+ console.debug(`Using ${p} renderer`), n.style && u.setStyle(n.style);
865
+ const m = me(t, r, n);
866
+ m.setUser(f);
867
+ const d = vt(r, c, n.adapter), L = () => f, w = (a) => {
868
+ m.setAnnotatingEnabled(
856
869
  a === void 0 ? !0 : a
857
870
  );
858
871
  }, x = (a) => {
859
- f.setFilter(a), g.setFilter(a);
872
+ u.setFilter(a), m.setFilter(a);
860
873
  }, R = (a) => {
861
- u = a, g.setUser(a);
874
+ f = a, m.setUser(a);
862
875
  }, C = (a) => {
863
- a && (f.setPainter(ge(a, n.presence)), a.on("selectionChange", () => f.redraw()));
876
+ a && (u.setPainter(ue(a, n.presence)), a.on("selectionChange", () => u.redraw()));
864
877
  }, N = (a) => {
865
878
  a ? o.setSelected(a) : o.clear();
866
879
  };
867
880
  return {
868
881
  ...d,
869
882
  destroy: () => {
870
- f.destroy(), g.destroy(), c.destroy();
883
+ u.destroy(), m.destroy(), c.destroy();
871
884
  },
872
885
  element: t,
873
886
  getUser: L,
874
887
  setAnnotatingEnabled: w,
875
888
  setFilter: x,
876
- setStyle: f.setStyle.bind(f),
877
- redraw: f.redraw.bind(f),
889
+ setStyle: u.setStyle.bind(u),
890
+ redraw: u.redraw.bind(u),
878
891
  setUser: R,
879
892
  setSelected: N,
880
893
  setPresenceProvider: C,
881
- setVisible: f.setVisible.bind(f),
894
+ setVisible: u.setVisible.bind(u),
882
895
  on: l.on,
883
896
  off: l.off,
884
- scrollIntoView: Yt(t, i),
897
+ scrollIntoView: Vt(t, i),
885
898
  state: r
886
899
  };
887
900
  };
@@ -895,39 +908,39 @@ export {
895
908
  ke as W3CTextFormat,
896
909
  Nt as cancelSingleClickEvents,
897
910
  X as cloneKeyboardEvent,
898
- Q as clonePointerEvent,
911
+ G as clonePointerEvent,
899
912
  _e as createBody,
900
- Zt as createCanvasRenderer,
901
- ee as createHighlightsRenderer,
902
- ge as createPresencePainter,
903
- te as createRenderer,
904
- pe as createSelectionHandler,
905
- re as createSpansRenderer,
913
+ Qt as createCanvasRenderer,
914
+ te as createHighlightsRenderer,
915
+ ue as createPresencePainter,
916
+ Jt as createRenderer,
917
+ me as createSelectionHandler,
918
+ se as createSpansRenderer,
906
919
  Be as createTextAnnotator,
907
- fe as createTextAnnotatorState,
908
- he as fillDefaults,
909
- Ht as getHighlightClientRects,
910
- Dt as getQuoteContext,
920
+ de as createTextAnnotatorState,
921
+ pe as fillDefaults,
922
+ It as getHighlightClientRects,
923
+ Pt as getQuoteContext,
911
924
  J as getRangeAnnotatableContents,
912
925
  kt as isMac,
913
- Mt as isNodeWhitespaceOrEmpty,
926
+ Le as isNodeWhitespaceOrEmpty,
914
927
  z as isNotAnnotatable,
915
928
  Lt as isRangeAnnotatable,
916
- It as isRangeWhitespaceOrEmpty,
929
+ _t as isRangeWhitespaceOrEmpty,
917
930
  P as isRevived,
918
- Kt as mergeClientRects,
919
- Xt as paint,
920
- ce as parseW3CTextAnnotation,
931
+ Ft as mergeClientRects,
932
+ Yt as paint,
933
+ ae as parseW3CTextAnnotation,
921
934
  Bt as programmaticallyFocusable,
922
- $t as rangeToSelector,
923
- G as reviveAnnotation,
935
+ Kt as rangeToSelector,
936
+ Q as reviveAnnotation,
924
937
  at as reviveSelector,
925
938
  q as reviveTarget,
926
- Yt as scrollIntoView,
927
- le as serializeW3CTextAnnotation,
928
- _t as splitAnnotatableRanges,
939
+ Vt as scrollIntoView,
940
+ ce as serializeW3CTextAnnotation,
941
+ Ht as splitAnnotatableRanges,
929
942
  Ne as toDomRectList,
930
- Vt as toParentBounds,
943
+ $t as toParentBounds,
931
944
  Oe as toViewportBounds,
932
945
  Wt as trimRangeToContainer,
933
946
  it as whitespaceOrEmptyRegex