@recogito/text-annotator 3.4.0 → 3.4.2

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