@recogito/text-annotator 3.4.3 → 3.4.4

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