@recogito/text-annotator 3.1.4 → 3.1.6

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