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