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