@soomo/text-annotator 3.4.11-staging.0 → 3.4.12-staging.0

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