@recogito/text-annotator 4.2.2 → 4.2.4

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