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