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