@recogito/text-annotator 3.1.2 → 3.1.3

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