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