@recogito/text-annotator 3.4.1 → 3.4.2

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