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