@soomo/text-annotator 4.1.3-staging.0 → 4.3.0-staging.0

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