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