@soomo/text-annotator 3.1.0-staging.24 → 3.1.0-staging.25
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/model/w3c/W3CTextAnnotation.d.ts +1 -0
- package/dist/text-annotator.css +1 -72
- package/dist/text-annotator.es.js +2327 -1287
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -1432
- package/dist/text-annotator.umd.js.map +1 -1
- package/package.json +6 -7
|
@@ -1,1430 +1,2470 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const closestNotAnnotatable = node instanceof HTMLElement ? node.closest(NOT_ANNOTATABLE_SELECTOR) : (_a = node.parentElement) == null ? void 0 : _a.closest(NOT_ANNOTATABLE_SELECTOR);
|
|
16
|
-
return Boolean(closestNotAnnotatable);
|
|
17
|
-
};
|
|
18
|
-
const isRangeAnnotatable = (range) => {
|
|
19
|
-
const ancestor = range.commonAncestorContainer;
|
|
20
|
-
return !isNotAnnotatable(ancestor);
|
|
21
|
-
};
|
|
22
|
-
const cancelSingleClickEvents = (container) => container.addEventListener("click", (event) => {
|
|
23
|
-
const targetElement = event.target;
|
|
24
|
-
const shouldPrevent = (
|
|
25
|
-
// Allow clicks within not-annotatable elements
|
|
26
|
-
!targetElement.closest(NOT_ANNOTATABLE_SELECTOR) && !event.target.closest("a")
|
|
27
|
-
);
|
|
28
|
-
if (shouldPrevent)
|
|
29
|
-
event.preventDefault();
|
|
30
|
-
});
|
|
31
|
-
const isMac = /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform);
|
|
32
|
-
const programmaticallyFocusable = (container) => {
|
|
33
|
-
if (!container.hasAttribute("tabindex") && container.tabIndex < 0) {
|
|
34
|
-
container.setAttribute("tabindex", "-1");
|
|
35
|
-
}
|
|
36
|
-
container.classList.add("no-focus-outline");
|
|
37
|
-
};
|
|
38
|
-
const iterateNotAnnotatableElements = function* (range) {
|
|
39
|
-
const notAnnotatableIterator = document.createNodeIterator(
|
|
40
|
-
range.commonAncestorContainer,
|
|
1
|
+
const ue = "not-annotatable", et = `.${ue}`, st = (t) => {
|
|
2
|
+
var n;
|
|
3
|
+
return !!(t instanceof HTMLElement ? t.closest(et) : (n = t.parentElement) == null ? void 0 : n.closest(et));
|
|
4
|
+
}, Re = (t) => {
|
|
5
|
+
const e = t.commonAncestorContainer;
|
|
6
|
+
return !st(e);
|
|
7
|
+
}, Me = (t) => t.addEventListener("click", (e) => {
|
|
8
|
+
// Allow clicks within not-annotatable elements
|
|
9
|
+
!e.target.closest(et) && !e.target.closest("a") && e.preventDefault();
|
|
10
|
+
}), ke = /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform), Ie = (t) => {
|
|
11
|
+
!t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
12
|
+
}, Ne = function* (t) {
|
|
13
|
+
const e = document.createNodeIterator(
|
|
14
|
+
t.commonAncestorContainer,
|
|
41
15
|
NodeFilter.SHOW_ELEMENT,
|
|
42
|
-
(
|
|
16
|
+
(o) => o instanceof HTMLElement && o.classList.contains(ue) && !o.parentElement.closest(et) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
43
17
|
);
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
18
|
+
let n;
|
|
19
|
+
for (; n = e.nextNode(); )
|
|
20
|
+
n instanceof HTMLElement && (yield n);
|
|
21
|
+
}, _e = (t) => {
|
|
22
|
+
if (!Re(t)) return [];
|
|
23
|
+
const e = [];
|
|
24
|
+
let n = null;
|
|
25
|
+
for (const o of Ne(t)) {
|
|
26
|
+
let i;
|
|
27
|
+
n ? (i = document.createRange(), i.setStartAfter(n), i.setEndBefore(o)) : (i = t.cloneRange(), i.setEndBefore(o)), i.collapsed || e.push(i), n = o;
|
|
49
28
|
}
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const annotatableRanges = [];
|
|
54
|
-
let prevNotAnnotatable = null;
|
|
55
|
-
for (const notAnnotatable of iterateNotAnnotatableElements(range)) {
|
|
56
|
-
let subRange;
|
|
57
|
-
if (!prevNotAnnotatable) {
|
|
58
|
-
subRange = range.cloneRange();
|
|
59
|
-
subRange.setEndBefore(notAnnotatable);
|
|
60
|
-
} else {
|
|
61
|
-
subRange = document.createRange();
|
|
62
|
-
subRange.setStartAfter(prevNotAnnotatable);
|
|
63
|
-
subRange.setEndBefore(notAnnotatable);
|
|
64
|
-
}
|
|
65
|
-
if (!subRange.collapsed)
|
|
66
|
-
annotatableRanges.push(subRange);
|
|
67
|
-
prevNotAnnotatable = notAnnotatable;
|
|
29
|
+
if (n) {
|
|
30
|
+
const o = t.cloneRange();
|
|
31
|
+
o.setStartAfter(n), o.collapsed || e.push(o);
|
|
68
32
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
const contents = range.cloneContents();
|
|
80
|
-
contents.querySelectorAll(NOT_ANNOTATABLE_SELECTOR).forEach((el) => el.remove());
|
|
81
|
-
return contents;
|
|
82
|
-
};
|
|
83
|
-
const getQuoteContext = (range, container, length = 10, offsetReferenceSelector) => {
|
|
84
|
-
const offsetReference = offsetReferenceSelector ? range.startContainer.parentElement.closest(offsetReferenceSelector) : container;
|
|
85
|
-
const rangeBefore = document.createRange();
|
|
86
|
-
rangeBefore.setStart(offsetReference, 0);
|
|
87
|
-
rangeBefore.setEnd(range.startContainer, range.startOffset);
|
|
88
|
-
const before = getRangeAnnotatableContents(rangeBefore).textContent;
|
|
89
|
-
const rangeAfter = document.createRange();
|
|
90
|
-
rangeAfter.setStart(range.endContainer, range.endOffset);
|
|
91
|
-
if (offsetReference === document.body)
|
|
92
|
-
rangeAfter.setEnd(offsetReference, offsetReference.childNodes.length);
|
|
93
|
-
else
|
|
94
|
-
rangeAfter.setEndAfter(offsetReference);
|
|
95
|
-
const after = getRangeAnnotatableContents(rangeAfter).textContent;
|
|
33
|
+
return e.length > 0 ? e : [t];
|
|
34
|
+
}, Kt = (t) => {
|
|
35
|
+
const e = t.cloneContents();
|
|
36
|
+
return e.querySelectorAll(et).forEach((n) => n.remove()), e;
|
|
37
|
+
}, Ue = (t, e, n = 10, o) => {
|
|
38
|
+
const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
|
|
39
|
+
s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
|
|
40
|
+
const a = Kt(s).textContent, r = document.createRange();
|
|
41
|
+
r.setStart(t.endContainer, t.endOffset), i === document.body ? r.setEnd(i, i.childNodes.length) : r.setEndAfter(i);
|
|
42
|
+
const l = Kt(r).textContent;
|
|
96
43
|
return {
|
|
97
|
-
prefix:
|
|
98
|
-
suffix:
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
top:
|
|
108
|
-
bottom:
|
|
109
|
-
left:
|
|
110
|
-
right:
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
bottom: round(rectB.bottom),
|
|
115
|
-
left: round(rectB.left),
|
|
116
|
-
right: round(rectB.right)
|
|
117
|
-
};
|
|
118
|
-
if (Math.abs(a.top - b.top) < 0.5 && Math.abs(a.bottom - b.bottom) < 0.5) {
|
|
119
|
-
if (Math.abs(a.left - b.right) < 0.5 || Math.abs(a.right - b.left) < 0.5)
|
|
44
|
+
prefix: a.substring(a.length - n),
|
|
45
|
+
suffix: l.substring(0, n)
|
|
46
|
+
};
|
|
47
|
+
}, F = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), De = /^\s*$/, Ve = (t) => De.test(t.toString()), Ye = (t, e) => {
|
|
48
|
+
const n = (s) => Math.round(s * 10) / 10, o = {
|
|
49
|
+
top: n(t.top),
|
|
50
|
+
bottom: n(t.bottom),
|
|
51
|
+
left: n(t.left),
|
|
52
|
+
right: n(t.right)
|
|
53
|
+
}, i = {
|
|
54
|
+
top: n(e.top),
|
|
55
|
+
bottom: n(e.bottom),
|
|
56
|
+
left: n(e.left),
|
|
57
|
+
right: n(e.right)
|
|
58
|
+
};
|
|
59
|
+
if (Math.abs(o.top - i.top) < 0.5 && Math.abs(o.bottom - i.bottom) < 0.5) {
|
|
60
|
+
if (Math.abs(o.left - i.right) < 0.5 || Math.abs(o.right - i.left) < 0.5)
|
|
120
61
|
return "inline-adjacent";
|
|
121
|
-
if (
|
|
62
|
+
if (o.left >= i.left && o.right <= i.right)
|
|
122
63
|
return "inline-is-contained";
|
|
123
|
-
if (
|
|
64
|
+
if (o.left <= i.left && o.right >= i.right)
|
|
124
65
|
return "inline-contains";
|
|
125
|
-
} else {
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const bottom = Math.max(a.bottom, b.bottom);
|
|
142
|
-
return new DOMRect(left, top, right - left, bottom - top);
|
|
143
|
-
};
|
|
144
|
-
const mergeClientRects = (rects) => rects.reduce((merged, rectA) => {
|
|
145
|
-
if (rectA.width === 0 || rectA.height === 0)
|
|
146
|
-
return merged;
|
|
147
|
-
let next = [...merged];
|
|
148
|
-
let wasMerged = false;
|
|
149
|
-
for (const rectB of merged) {
|
|
150
|
-
const relation = getRelation(rectA, rectB);
|
|
151
|
-
if (relation === "inline-adjacent") {
|
|
152
|
-
next = next.map((r) => r === rectB ? union(rectA, rectB) : r);
|
|
153
|
-
wasMerged = true;
|
|
66
|
+
} else if (o.top <= i.top && o.bottom >= i.bottom) {
|
|
67
|
+
if (o.left <= i.left && o.right >= i.right)
|
|
68
|
+
return "block-contains";
|
|
69
|
+
} else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
|
|
70
|
+
return "block-is-contained";
|
|
71
|
+
}, Ke = (t, e) => {
|
|
72
|
+
const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
|
|
73
|
+
return new DOMRect(n, i, o - n, s - i);
|
|
74
|
+
}, Pe = (t) => t.reduce((e, n) => {
|
|
75
|
+
if (n.width === 0 || n.height === 0)
|
|
76
|
+
return e;
|
|
77
|
+
let o = [...e], i = !1;
|
|
78
|
+
for (const s of e) {
|
|
79
|
+
const a = Ye(n, s);
|
|
80
|
+
if (a === "inline-adjacent") {
|
|
81
|
+
o = o.map((r) => r === s ? Ke(n, s) : r), i = !0;
|
|
154
82
|
break;
|
|
155
|
-
} else if (
|
|
156
|
-
|
|
157
|
-
wasMerged = true;
|
|
83
|
+
} else if (a === "inline-contains") {
|
|
84
|
+
o = o.map((r) => r === s ? n : r), i = !0;
|
|
158
85
|
break;
|
|
159
|
-
} else if (
|
|
160
|
-
|
|
86
|
+
} else if (a === "inline-is-contained") {
|
|
87
|
+
i = !0;
|
|
161
88
|
break;
|
|
162
|
-
} else if (
|
|
163
|
-
|
|
164
|
-
next = next.map((r) => r === rectB ? rectA : r);
|
|
165
|
-
}
|
|
166
|
-
wasMerged = true;
|
|
89
|
+
} else if (a === "block-contains" || a === "block-is-contained") {
|
|
90
|
+
n.width < s.width && (o = o.map((r) => r === s ? n : r)), i = !0;
|
|
167
91
|
break;
|
|
168
92
|
}
|
|
169
93
|
}
|
|
170
|
-
return
|
|
171
|
-
}, [])
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
item: (index) => rects[index],
|
|
94
|
+
return i ? o : [...o, n];
|
|
95
|
+
}, []), Mo = (t) => ({
|
|
96
|
+
length: t.length,
|
|
97
|
+
item: (e) => t[e],
|
|
175
98
|
[Symbol.iterator]: function* () {
|
|
176
|
-
for (let
|
|
177
|
-
yield this.item(
|
|
99
|
+
for (let e = 0; e < this.length; e++)
|
|
100
|
+
yield this.item(e);
|
|
178
101
|
}
|
|
179
|
-
})
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
const end = start + quote.length;
|
|
189
|
-
return offsetReferenceSelector ? { quote, start, end, range, offsetReference } : { quote, start, end, range };
|
|
190
|
-
};
|
|
191
|
-
const reviveSelector = (selector, container) => {
|
|
192
|
-
var _a, _b;
|
|
193
|
-
const { start, end } = selector;
|
|
194
|
-
const offsetReference = selector.offsetReference || container;
|
|
195
|
-
const iterator = document.createNodeIterator(
|
|
196
|
-
container,
|
|
102
|
+
}), Xe = (t, e, n) => {
|
|
103
|
+
const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
|
|
104
|
+
o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
105
|
+
const s = Kt(o).textContent, a = t.toString(), r = s.length || 0, l = r + a.length;
|
|
106
|
+
return n ? { quote: a, start: r, end: l, range: t, offsetReference: i } : { quote: a, start: r, end: l, range: t };
|
|
107
|
+
}, fe = (t, e) => {
|
|
108
|
+
var g, u;
|
|
109
|
+
const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
|
|
110
|
+
e,
|
|
197
111
|
NodeFilter.SHOW_TEXT,
|
|
198
|
-
(
|
|
199
|
-
var
|
|
200
|
-
return (
|
|
112
|
+
(f) => {
|
|
113
|
+
var A;
|
|
114
|
+
return (A = f.parentElement) != null && A.closest(et) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
201
115
|
}
|
|
202
116
|
);
|
|
203
|
-
let
|
|
204
|
-
const
|
|
205
|
-
let
|
|
206
|
-
|
|
207
|
-
let
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
range.setStart(n, start - runningOffset);
|
|
117
|
+
let a = 0;
|
|
118
|
+
const r = document.createRange();
|
|
119
|
+
let l = s.nextNode();
|
|
120
|
+
l === null && console.error("Could not revive annotation target. Content missing.");
|
|
121
|
+
let d = !i;
|
|
122
|
+
for (; l !== null; ) {
|
|
123
|
+
if (d || (d = i == null ? void 0 : i.contains(l)), d) {
|
|
124
|
+
const f = ((g = l.textContent) == null ? void 0 : g.length) || 0;
|
|
125
|
+
if (a + f > n) {
|
|
126
|
+
r.setStart(l, n - a);
|
|
214
127
|
break;
|
|
215
128
|
}
|
|
216
|
-
|
|
129
|
+
a += f;
|
|
217
130
|
}
|
|
218
|
-
|
|
131
|
+
l = s.nextNode();
|
|
219
132
|
}
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
|
|
133
|
+
for (; l !== null; ) {
|
|
134
|
+
const f = ((u = l.textContent) == null ? void 0 : u.length) || 0;
|
|
135
|
+
if (a + f >= o) {
|
|
136
|
+
r.setEnd(l, o - a);
|
|
224
137
|
break;
|
|
225
138
|
}
|
|
226
|
-
|
|
227
|
-
n = iterator.nextNode();
|
|
139
|
+
a += f, l = s.nextNode();
|
|
228
140
|
}
|
|
229
141
|
return {
|
|
230
|
-
...
|
|
231
|
-
range
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
142
|
+
...t,
|
|
143
|
+
range: r
|
|
144
|
+
};
|
|
145
|
+
}, vt = (t, e) => F(t.selector) ? t : {
|
|
146
|
+
...t,
|
|
147
|
+
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : fe(n, e))
|
|
148
|
+
}, Ct = (t, e) => F(t.target.selector) ? t : { ...t, target: vt(t.target, e) }, he = (t, e) => {
|
|
149
|
+
if (t.isEqualNode(e))
|
|
150
|
+
return !0;
|
|
151
|
+
for (let n of t.childNodes)
|
|
152
|
+
if (he(n, e))
|
|
153
|
+
return !0;
|
|
154
|
+
return !1;
|
|
155
|
+
}, $e = (t, e) => {
|
|
156
|
+
const n = t.cloneContents();
|
|
157
|
+
return he(n, e);
|
|
158
|
+
}, He = (t, e) => {
|
|
159
|
+
const n = t.cloneRange(), o = e.contains(n.startContainer), i = e.contains(n.endContainer);
|
|
160
|
+
return !o && !i && !$e(n, e) ? (n.collapse(), n) : (o || n.setStart(e, 0), i || n.setEnd(e, e.childNodes.length), n);
|
|
161
|
+
}, Lt = (t) => ({
|
|
162
|
+
...t,
|
|
163
|
+
type: t.type,
|
|
164
|
+
x: t.x,
|
|
165
|
+
y: t.y,
|
|
166
|
+
clientX: t.clientX,
|
|
167
|
+
clientY: t.clientY,
|
|
168
|
+
offsetX: t.offsetX,
|
|
169
|
+
offsetY: t.offsetY,
|
|
170
|
+
screenX: t.screenX,
|
|
171
|
+
screenY: t.screenY,
|
|
172
|
+
isPrimary: t.isPrimary,
|
|
173
|
+
altKey: t.altKey,
|
|
174
|
+
ctrlKey: t.ctrlKey,
|
|
175
|
+
metaKey: t.metaKey,
|
|
176
|
+
shiftKey: t.shiftKey,
|
|
177
|
+
button: t.button,
|
|
178
|
+
buttons: t.buttons,
|
|
179
|
+
currentTarget: t.currentTarget,
|
|
180
|
+
target: t.target,
|
|
181
|
+
defaultPrevented: t.defaultPrevented,
|
|
182
|
+
detail: t.detail,
|
|
183
|
+
eventPhase: t.eventPhase,
|
|
184
|
+
pointerId: t.pointerId,
|
|
185
|
+
pointerType: t.pointerType,
|
|
186
|
+
timeStamp: t.timeStamp
|
|
187
|
+
}), pt = (t) => ({
|
|
188
|
+
...t,
|
|
189
|
+
type: t.type,
|
|
190
|
+
key: t.key,
|
|
191
|
+
code: t.code,
|
|
192
|
+
location: t.location,
|
|
193
|
+
repeat: t.repeat,
|
|
194
|
+
altKey: t.altKey,
|
|
195
|
+
ctrlKey: t.ctrlKey,
|
|
196
|
+
metaKey: t.metaKey,
|
|
197
|
+
shiftKey: t.shiftKey,
|
|
198
|
+
currentTarget: t.currentTarget,
|
|
199
|
+
target: t.target,
|
|
200
|
+
defaultPrevented: t.defaultPrevented,
|
|
201
|
+
detail: t.detail,
|
|
202
|
+
timeStamp: t.timeStamp
|
|
203
|
+
}), je = (t, e) => {
|
|
204
|
+
const { left: n, top: o, right: i, bottom: s } = t;
|
|
205
|
+
return new DOMRect(n - e.left, o - e.top, i - n, s - o);
|
|
206
|
+
}, ko = (t, e) => {
|
|
207
|
+
const { left: n, top: o, right: i, bottom: s } = t;
|
|
208
|
+
return new DOMRect(n + e.left, o + e.top, i - n, s - o);
|
|
209
|
+
}, pe = (t) => {
|
|
210
|
+
if (t === null)
|
|
211
|
+
return document.scrollingElement;
|
|
212
|
+
const { overflowY: e } = window.getComputedStyle(t);
|
|
213
|
+
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : pe(t.parentElement);
|
|
214
|
+
}, ze = (t, e) => (n) => {
|
|
215
|
+
const o = typeof n == "string" ? n : n.id, i = (a) => {
|
|
216
|
+
const r = s.getBoundingClientRect(), l = s.clientHeight, d = s.clientWidth, g = a.selector[0].range.getBoundingClientRect(), { width: u, height: f } = e.getAnnotationBounds(o), A = g.top - r.top, p = g.left - r.left, b = s.parentElement ? s.scrollTop : 0, x = s.parentElement ? s.scrollLeft : 0, m = A + b - (l - f) / 2, c = p + x - (d - u) / 2;
|
|
217
|
+
s.scroll({ top: m, left: c, behavior: "smooth" });
|
|
218
|
+
}, s = pe(t);
|
|
219
|
+
if (s) {
|
|
220
|
+
const a = e.getAnnotation(o), { range: r } = a.target.selector[0];
|
|
221
|
+
if (r && !r.collapsed)
|
|
222
|
+
return i(a.target), !0;
|
|
223
|
+
{
|
|
224
|
+
const l = vt(a.target, t), { range: d } = l.selector[0];
|
|
225
|
+
if (d && !d.collapsed)
|
|
226
|
+
return i(l), !0;
|
|
246
227
|
}
|
|
247
228
|
}
|
|
248
|
-
return
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
229
|
+
return !1;
|
|
230
|
+
}, q = {
|
|
231
|
+
fill: "rgb(0, 128, 255)",
|
|
232
|
+
fillOpacity: 0.18
|
|
233
|
+
}, Et = {
|
|
234
|
+
fill: "rgb(0, 128, 255)",
|
|
235
|
+
fillOpacity: 0.45
|
|
236
|
+
}, Fe = (t, e, n, o, i) => {
|
|
237
|
+
var a, r;
|
|
238
|
+
const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? Et : q) : n : (r = t.state) != null && r.selected ? Et : q;
|
|
239
|
+
return o && o.paint(t, e) || s;
|
|
253
240
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
241
|
+
function We(t) {
|
|
242
|
+
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
243
|
+
}
|
|
244
|
+
var gt = { exports: {} }, zt;
|
|
245
|
+
function qe() {
|
|
246
|
+
if (zt) return gt.exports;
|
|
247
|
+
zt = 1;
|
|
248
|
+
function t(e, n = 100, o = {}) {
|
|
249
|
+
if (typeof e != "function")
|
|
250
|
+
throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);
|
|
251
|
+
if (n < 0)
|
|
252
|
+
throw new RangeError("`wait` must not be negative.");
|
|
253
|
+
const { immediate: i } = typeof o == "boolean" ? { immediate: o } : o;
|
|
254
|
+
let s, a, r, l, d;
|
|
255
|
+
function g() {
|
|
256
|
+
const A = s, p = a;
|
|
257
|
+
return s = void 0, a = void 0, d = e.apply(A, p), d;
|
|
263
258
|
}
|
|
259
|
+
function u() {
|
|
260
|
+
const A = Date.now() - l;
|
|
261
|
+
A < n && A >= 0 ? r = setTimeout(u, n - A) : (r = void 0, i || (d = g()));
|
|
262
|
+
}
|
|
263
|
+
const f = function(...A) {
|
|
264
|
+
if (s && this !== s && Object.getPrototypeOf(this) === Object.getPrototypeOf(s))
|
|
265
|
+
throw new Error("Debounced method called with different contexts of the same prototype.");
|
|
266
|
+
s = this, a = A, l = Date.now();
|
|
267
|
+
const p = i && !r;
|
|
268
|
+
return r || (r = setTimeout(u, n)), p && (d = g()), d;
|
|
269
|
+
};
|
|
270
|
+
return Object.defineProperty(f, "isPending", {
|
|
271
|
+
get() {
|
|
272
|
+
return r !== void 0;
|
|
273
|
+
}
|
|
274
|
+
}), f.clear = () => {
|
|
275
|
+
r && (clearTimeout(r), r = void 0);
|
|
276
|
+
}, f.flush = () => {
|
|
277
|
+
r && f.trigger();
|
|
278
|
+
}, f.trigger = () => {
|
|
279
|
+
d = g(), f.clear();
|
|
280
|
+
}, f;
|
|
264
281
|
}
|
|
265
|
-
|
|
266
|
-
|
|
282
|
+
return gt.exports.debounce = t, gt.exports = t, gt.exports;
|
|
283
|
+
}
|
|
284
|
+
var Ge = /* @__PURE__ */ qe();
|
|
285
|
+
const Xt = /* @__PURE__ */ We(Ge), Qe = (t) => {
|
|
286
|
+
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n, l = i - e;
|
|
287
|
+
return { top: e, left: n, minX: s, minY: a, maxX: r, maxY: l };
|
|
288
|
+
}, Je = (t) => {
|
|
289
|
+
let e = /* @__PURE__ */ new Set();
|
|
290
|
+
return (o) => {
|
|
291
|
+
const i = o.map((s) => s.id);
|
|
292
|
+
(e.size !== i.length || i.some((s) => !e.has(s))) && t.set(i), e = new Set(i);
|
|
293
|
+
};
|
|
294
|
+
}, $t = (t, e, n, o) => {
|
|
295
|
+
const { store: i, selection: s, hover: a } = e;
|
|
296
|
+
let r, l, d;
|
|
297
|
+
const g = Je(n), u = (T) => {
|
|
298
|
+
const { x: R, y: w } = t.getBoundingClientRect(), v = i.getAt(T.clientX - R, T.clientY - w, !1, l);
|
|
299
|
+
v ? a.current !== v.id && (t.classList.add("hovered"), a.set(v.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
|
|
300
|
+
};
|
|
301
|
+
t.addEventListener("pointermove", u);
|
|
302
|
+
const f = (T = !1) => {
|
|
303
|
+
d && d.clear();
|
|
304
|
+
const R = Qe(t), { minX: w, minY: v, maxX: h, maxY: E } = R, M = l ? i.getIntersecting(w, v, h, E).filter(({ annotation: _ }) => l(_)) : i.getIntersecting(w, v, h, E), O = s.selected.map(({ id: _ }) => _), U = M.map(({ annotation: _, rects: ht }) => {
|
|
305
|
+
const W = O.includes(_.id), G = _.id === a.current;
|
|
306
|
+
return { annotation: _, rects: ht, state: { selected: W, hover: G } };
|
|
307
|
+
});
|
|
308
|
+
o.redraw(U, R, r, d, T), setTimeout(() => g(M.map(({ annotation: _ }) => _)), 1);
|
|
309
|
+
}, A = (T) => {
|
|
310
|
+
d = T, f();
|
|
311
|
+
}, p = (T) => {
|
|
312
|
+
r = T, f();
|
|
313
|
+
}, b = (T) => {
|
|
314
|
+
l = T, f(!1);
|
|
315
|
+
}, x = () => f();
|
|
316
|
+
i.observe(x);
|
|
317
|
+
const m = s.subscribe(() => f()), c = () => f(!0);
|
|
318
|
+
document.addEventListener("scroll", c, { capture: !0, passive: !0 });
|
|
319
|
+
const y = Xt(() => {
|
|
320
|
+
i.recalculatePositions(), d == null || d.reset(), f();
|
|
321
|
+
}, 10);
|
|
322
|
+
window.addEventListener("resize", y);
|
|
323
|
+
const C = new ResizeObserver(y);
|
|
324
|
+
C.observe(t);
|
|
325
|
+
const S = { attributes: !0, childList: !0, subtree: !0 }, L = new MutationObserver((T) => {
|
|
326
|
+
T.every((w) => w.target === t || t.contains(w.target)) || f(!0);
|
|
327
|
+
});
|
|
328
|
+
return L.observe(document.body, S), {
|
|
329
|
+
destroy: () => {
|
|
330
|
+
t.removeEventListener("pointermove", u), o.destroy(), i.unobserve(x), m(), document.removeEventListener("scroll", c), y.clear(), window.removeEventListener("resize", y), C.disconnect(), L.disconnect();
|
|
331
|
+
},
|
|
332
|
+
redraw: f,
|
|
333
|
+
setStyle: p,
|
|
334
|
+
setFilter: b,
|
|
335
|
+
setPainter: A,
|
|
336
|
+
setVisible: o.setVisible
|
|
337
|
+
};
|
|
338
|
+
}, Ze = () => {
|
|
339
|
+
const t = document.createElement("canvas");
|
|
340
|
+
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
|
|
341
|
+
}, tn = (t, e) => {
|
|
342
|
+
t.width = window.innerWidth, t.height = window.innerHeight;
|
|
343
|
+
}, en = (t) => {
|
|
344
|
+
t.classList.add("r6o-annotatable");
|
|
345
|
+
const e = Ze(), n = e.getContext("2d");
|
|
346
|
+
document.body.appendChild(e);
|
|
347
|
+
const o = (r, l, d, g) => requestAnimationFrame(() => {
|
|
348
|
+
const { width: u, height: f } = e;
|
|
349
|
+
n.clearRect(-0.5, -0.5, u + 1, f + 1), g && g.clear();
|
|
350
|
+
const { top: A, left: p } = l;
|
|
351
|
+
[...r].sort((x, m) => {
|
|
352
|
+
const { annotation: { target: { created: c } } } = x, { annotation: { target: { created: y } } } = m;
|
|
353
|
+
return c.getTime() - y.getTime();
|
|
354
|
+
}).forEach((x) => {
|
|
355
|
+
var C;
|
|
356
|
+
const m = d ? typeof d == "function" ? d(x.annotation, x.state) : d : (C = x.state) != null && C.selected ? Et : q, c = g && g.paint(x, l) || m, y = x.rects.map(({ x: S, y: L, width: B, height: T }) => ({
|
|
357
|
+
x: S + p,
|
|
358
|
+
y: L + A,
|
|
359
|
+
width: B,
|
|
360
|
+
height: T
|
|
361
|
+
}));
|
|
362
|
+
if (n.fillStyle = c.fill, n.globalAlpha = c.fillOpacity || 1, y.forEach(
|
|
363
|
+
({ x: S, y: L, width: B, height: T }) => n.fillRect(S, L, B, T)
|
|
364
|
+
), c.underlineColor) {
|
|
365
|
+
n.globalAlpha = 1, n.strokeStyle = c.underlineColor, n.lineWidth = c.underlineThickness ?? 1;
|
|
366
|
+
const S = c.underlineOffset ?? 0;
|
|
367
|
+
y.forEach(({ x: L, y: B, width: T, height: R }) => {
|
|
368
|
+
n.beginPath(), n.moveTo(L, B + R + S), n.lineTo(L + T, B + R + S), n.stroke();
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}), i = Xt(() => tn(e), 10);
|
|
373
|
+
return window.addEventListener("resize", i), {
|
|
374
|
+
destroy: () => {
|
|
375
|
+
e.remove(), i.clear(), window.removeEventListener("resize", i);
|
|
376
|
+
},
|
|
377
|
+
setVisible: (r) => {
|
|
378
|
+
console.log("setVisible not implemented on Canvas renderer");
|
|
379
|
+
},
|
|
380
|
+
redraw: o
|
|
381
|
+
};
|
|
382
|
+
}, nn = (t, e, n) => $t(t, e, n, en(t));
|
|
383
|
+
var on = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, j = function(t) {
|
|
384
|
+
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
385
|
+
}, D = function(t, e, n) {
|
|
386
|
+
return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
|
|
387
|
+
}, P = function(t, e, n) {
|
|
388
|
+
return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
|
|
389
|
+
}, ge = function(t) {
|
|
390
|
+
return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
|
|
391
|
+
}, Ft = function(t) {
|
|
392
|
+
return { r: P(t.r, 0, 255), g: P(t.g, 0, 255), b: P(t.b, 0, 255), a: P(t.a) };
|
|
393
|
+
}, Tt = function(t) {
|
|
394
|
+
return { r: D(t.r), g: D(t.g), b: D(t.b), a: D(t.a, 3) };
|
|
395
|
+
}, sn = /^#([0-9a-f]{3,8})$/i, mt = function(t) {
|
|
396
|
+
var e = t.toString(16);
|
|
397
|
+
return e.length < 2 ? "0" + e : e;
|
|
398
|
+
}, me = function(t) {
|
|
399
|
+
var e = t.r, n = t.g, o = t.b, i = t.a, s = Math.max(e, n, o), a = s - Math.min(e, n, o), r = a ? s === e ? (n - o) / a : s === n ? 2 + (o - e) / a : 4 + (e - n) / a : 0;
|
|
400
|
+
return { h: 60 * (r < 0 ? r + 6 : r), s: s ? a / s * 100 : 0, v: s / 255 * 100, a: i };
|
|
401
|
+
}, ye = function(t) {
|
|
402
|
+
var e = t.h, n = t.s, o = t.v, i = t.a;
|
|
403
|
+
e = e / 360 * 6, n /= 100, o /= 100;
|
|
404
|
+
var s = Math.floor(e), a = o * (1 - n), r = o * (1 - (e - s) * n), l = o * (1 - (1 - e + s) * n), d = s % 6;
|
|
405
|
+
return { r: 255 * [o, r, a, a, l, o][d], g: 255 * [l, o, o, r, a, a][d], b: 255 * [a, a, l, o, o, r][d], a: i };
|
|
406
|
+
}, Wt = function(t) {
|
|
407
|
+
return { h: ge(t.h), s: P(t.s, 0, 100), l: P(t.l, 0, 100), a: P(t.a) };
|
|
408
|
+
}, qt = function(t) {
|
|
409
|
+
return { h: D(t.h), s: D(t.s), l: D(t.l), a: D(t.a, 3) };
|
|
410
|
+
}, Gt = function(t) {
|
|
411
|
+
return ye((n = (e = t).s, { h: e.h, s: (n *= ((o = e.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * n / (o + n) * 100 : 0, v: o + n, a: e.a }));
|
|
412
|
+
var e, n, o;
|
|
413
|
+
}, ct = function(t) {
|
|
414
|
+
return { h: (e = me(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
|
|
415
|
+
var e, n, o, i;
|
|
416
|
+
}, rn = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, an = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, cn = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ln = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Qt = { string: [[function(t) {
|
|
417
|
+
var e = sn.exec(t);
|
|
418
|
+
return e ? (t = e[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? D(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? D(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
|
|
419
|
+
}, "hex"], [function(t) {
|
|
420
|
+
var e = cn.exec(t) || ln.exec(t);
|
|
421
|
+
return e ? e[2] !== e[4] || e[4] !== e[6] ? null : Ft({ r: Number(e[1]) / (e[2] ? 100 / 255 : 1), g: Number(e[3]) / (e[4] ? 100 / 255 : 1), b: Number(e[5]) / (e[6] ? 100 / 255 : 1), a: e[7] === void 0 ? 1 : Number(e[7]) / (e[8] ? 100 : 1) }) : null;
|
|
422
|
+
}, "rgb"], [function(t) {
|
|
423
|
+
var e = rn.exec(t) || an.exec(t);
|
|
424
|
+
if (!e) return null;
|
|
425
|
+
var n, o, i = Wt({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (on[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
|
|
426
|
+
return Gt(i);
|
|
427
|
+
}, "hsl"]], object: [[function(t) {
|
|
428
|
+
var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
|
|
429
|
+
return j(e) && j(n) && j(o) ? Ft({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
|
|
430
|
+
}, "rgb"], [function(t) {
|
|
431
|
+
var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
|
|
432
|
+
if (!j(e) || !j(n) || !j(o)) return null;
|
|
433
|
+
var a = Wt({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
|
|
434
|
+
return Gt(a);
|
|
435
|
+
}, "hsl"], [function(t) {
|
|
436
|
+
var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
|
|
437
|
+
if (!j(e) || !j(n) || !j(o)) return null;
|
|
438
|
+
var a = function(r) {
|
|
439
|
+
return { h: ge(r.h), s: P(r.s, 0, 100), v: P(r.v, 0, 100), a: P(r.a) };
|
|
440
|
+
}({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
|
|
441
|
+
return ye(a);
|
|
442
|
+
}, "hsv"]] }, Jt = function(t, e) {
|
|
443
|
+
for (var n = 0; n < e.length; n++) {
|
|
444
|
+
var o = e[n][0](t);
|
|
445
|
+
if (o) return [o, e[n][1]];
|
|
267
446
|
}
|
|
268
|
-
|
|
269
|
-
|
|
447
|
+
return [null, void 0];
|
|
448
|
+
}, dn = function(t) {
|
|
449
|
+
return typeof t == "string" ? Jt(t.trim(), Qt.string) : typeof t == "object" && t !== null ? Jt(t, Qt.object) : [null, void 0];
|
|
450
|
+
}, Ot = function(t, e) {
|
|
451
|
+
var n = ct(t);
|
|
452
|
+
return { h: n.h, s: P(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
|
|
453
|
+
}, Bt = function(t) {
|
|
454
|
+
return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
|
|
455
|
+
}, Zt = function(t, e) {
|
|
456
|
+
var n = ct(t);
|
|
457
|
+
return { h: n.h, s: n.s, l: P(n.l + 100 * e, 0, 100), a: n.a };
|
|
458
|
+
}, te = function() {
|
|
459
|
+
function t(e) {
|
|
460
|
+
this.parsed = dn(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
|
|
270
461
|
}
|
|
271
|
-
return
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
462
|
+
return t.prototype.isValid = function() {
|
|
463
|
+
return this.parsed !== null;
|
|
464
|
+
}, t.prototype.brightness = function() {
|
|
465
|
+
return D(Bt(this.rgba), 2);
|
|
466
|
+
}, t.prototype.isDark = function() {
|
|
467
|
+
return Bt(this.rgba) < 0.5;
|
|
468
|
+
}, t.prototype.isLight = function() {
|
|
469
|
+
return Bt(this.rgba) >= 0.5;
|
|
470
|
+
}, t.prototype.toHex = function() {
|
|
471
|
+
return e = Tt(this.rgba), n = e.r, o = e.g, i = e.b, a = (s = e.a) < 1 ? mt(D(255 * s)) : "", "#" + mt(n) + mt(o) + mt(i) + a;
|
|
472
|
+
var e, n, o, i, s, a;
|
|
473
|
+
}, t.prototype.toRgb = function() {
|
|
474
|
+
return Tt(this.rgba);
|
|
475
|
+
}, t.prototype.toRgbString = function() {
|
|
476
|
+
return e = Tt(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
|
|
477
|
+
var e, n, o, i, s;
|
|
478
|
+
}, t.prototype.toHsl = function() {
|
|
479
|
+
return qt(ct(this.rgba));
|
|
480
|
+
}, t.prototype.toHslString = function() {
|
|
481
|
+
return e = qt(ct(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
|
|
482
|
+
var e, n, o, i, s;
|
|
483
|
+
}, t.prototype.toHsv = function() {
|
|
484
|
+
return e = me(this.rgba), { h: D(e.h), s: D(e.s), v: D(e.v), a: D(e.a, 3) };
|
|
485
|
+
var e;
|
|
486
|
+
}, t.prototype.invert = function() {
|
|
487
|
+
return $({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
|
|
488
|
+
var e;
|
|
489
|
+
}, t.prototype.saturate = function(e) {
|
|
490
|
+
return e === void 0 && (e = 0.1), $(Ot(this.rgba, e));
|
|
491
|
+
}, t.prototype.desaturate = function(e) {
|
|
492
|
+
return e === void 0 && (e = 0.1), $(Ot(this.rgba, -e));
|
|
493
|
+
}, t.prototype.grayscale = function() {
|
|
494
|
+
return $(Ot(this.rgba, -1));
|
|
495
|
+
}, t.prototype.lighten = function(e) {
|
|
496
|
+
return e === void 0 && (e = 0.1), $(Zt(this.rgba, e));
|
|
497
|
+
}, t.prototype.darken = function(e) {
|
|
498
|
+
return e === void 0 && (e = 0.1), $(Zt(this.rgba, -e));
|
|
499
|
+
}, t.prototype.rotate = function(e) {
|
|
500
|
+
return e === void 0 && (e = 15), this.hue(this.hue() + e);
|
|
501
|
+
}, t.prototype.alpha = function(e) {
|
|
502
|
+
return typeof e == "number" ? $({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : D(this.rgba.a, 3);
|
|
503
|
+
var n;
|
|
504
|
+
}, t.prototype.hue = function(e) {
|
|
505
|
+
var n = ct(this.rgba);
|
|
506
|
+
return typeof e == "number" ? $({ h: e, s: n.s, l: n.l, a: n.a }) : D(n.h);
|
|
507
|
+
}, t.prototype.isEqual = function(e) {
|
|
508
|
+
return this.toHex() === $(e).toHex();
|
|
509
|
+
}, t;
|
|
510
|
+
}(), $ = function(t) {
|
|
511
|
+
return t instanceof te ? t : new te(t);
|
|
320
512
|
};
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
513
|
+
const un = (t) => [
|
|
514
|
+
`background-color:${$((t == null ? void 0 : t.fill) || q.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? q.fillOpacity : t.fillOpacity).toHex()}`,
|
|
515
|
+
t != null && t.underlineThickness ? "text-decoration:underline" : void 0,
|
|
516
|
+
t != null && t.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
517
|
+
t != null && t.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
518
|
+
t != null && t.underlineThickness ? `text-decoration-thickness:${t.underlineThickness}px` : void 0
|
|
519
|
+
].filter(Boolean).join(";"), fn = () => {
|
|
520
|
+
const t = document.createElement("style");
|
|
521
|
+
document.getElementsByTagName("head")[0].appendChild(t);
|
|
522
|
+
let e = /* @__PURE__ */ new Set();
|
|
523
|
+
return {
|
|
524
|
+
destroy: () => {
|
|
525
|
+
CSS.highlights.clear(), t.remove();
|
|
526
|
+
},
|
|
527
|
+
setVisible: (s) => {
|
|
528
|
+
console.log("setVisible not implemented on CSS Custom Highlights renderer");
|
|
529
|
+
},
|
|
530
|
+
redraw: (s, a, r, l) => {
|
|
531
|
+
l && l.clear();
|
|
532
|
+
const d = new Set(s.map((u) => u.annotation.id));
|
|
533
|
+
Array.from(e).filter((u) => !d.has(u));
|
|
534
|
+
const g = s.map((u) => {
|
|
535
|
+
var p;
|
|
536
|
+
const f = r ? typeof r == "function" ? r(u.annotation, u.state) : r : (p = u.state) != null && p.selected ? Et : q, A = l && l.paint(u, a) || f;
|
|
537
|
+
return `::highlight(_${u.annotation.id}) { ${un(A)} }`;
|
|
538
|
+
});
|
|
539
|
+
t.innerHTML = g.join(`
|
|
540
|
+
`), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
|
|
541
|
+
const f = u.target.selector.map((p) => p.range), A = new Highlight(...f);
|
|
542
|
+
CSS.highlights.set(`_${u.id}`, A);
|
|
543
|
+
}), e = d;
|
|
544
|
+
}
|
|
350
545
|
};
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
546
|
+
}, hn = (t, e, n) => $t(t, e, n, fn());
|
|
547
|
+
var ee = Object.prototype.hasOwnProperty;
|
|
548
|
+
function Pt(t, e) {
|
|
549
|
+
var n, o;
|
|
550
|
+
if (t === e) return !0;
|
|
551
|
+
if (t && e && (n = t.constructor) === e.constructor) {
|
|
552
|
+
if (n === Date) return t.getTime() === e.getTime();
|
|
553
|
+
if (n === RegExp) return t.toString() === e.toString();
|
|
554
|
+
if (n === Array) {
|
|
555
|
+
if ((o = t.length) === e.length)
|
|
556
|
+
for (; o-- && Pt(t[o], e[o]); ) ;
|
|
557
|
+
return o === -1;
|
|
558
|
+
}
|
|
559
|
+
if (!n || typeof t == "object") {
|
|
560
|
+
o = 0;
|
|
561
|
+
for (n in t)
|
|
562
|
+
if (ee.call(t, n) && ++o && !ee.call(e, n) || !(n in e) || !Pt(t[n], e[n])) return !1;
|
|
563
|
+
return Object.keys(e).length === o;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return t !== t && e !== e;
|
|
567
|
+
}
|
|
568
|
+
const pn = (t, e) => {
|
|
569
|
+
const n = (s, a) => s.x <= a.x + a.width && s.x + s.width >= a.x && s.y <= a.y + a.height && s.y + s.height >= a.y, o = (s) => s.rects.reduce((a, r) => a + r.width, 0), i = e.filter(({ rects: s }) => s.some((a) => n(t, a)));
|
|
570
|
+
return i.sort((s, a) => o(a) - o(s)), i.findIndex((s) => s.rects.includes(t));
|
|
571
|
+
}, gn = (t) => {
|
|
572
|
+
t.classList.add("r6o-annotatable");
|
|
573
|
+
const e = document.createElement("div");
|
|
574
|
+
e.className = "r6o-span-highlight-layer", t.insertBefore(e, t.firstChild);
|
|
575
|
+
let n = [];
|
|
576
|
+
return {
|
|
577
|
+
destroy: () => {
|
|
578
|
+
e.remove();
|
|
579
|
+
},
|
|
580
|
+
redraw: (a, r, l, d, g) => {
|
|
581
|
+
const f = !(Pt(n, a) && g);
|
|
582
|
+
if (!d && !f) return;
|
|
583
|
+
f && (e.innerHTML = ""), [...a].sort((p, b) => {
|
|
584
|
+
const { annotation: { target: { created: x } } } = p, { annotation: { target: { created: m } } } = b;
|
|
585
|
+
return x && m ? x.getTime() - m.getTime() : 0;
|
|
586
|
+
}).forEach((p) => {
|
|
587
|
+
p.rects.map((b) => {
|
|
588
|
+
const x = pn(b, a), m = Fe(p, r, l, d, x);
|
|
589
|
+
if (f) {
|
|
590
|
+
const c = document.createElement("span");
|
|
591
|
+
c.className = "r6o-annotation", c.dataset.annotation = p.annotation.id, c.style.left = `${b.x}px`, c.style.top = `${b.y}px`, c.style.width = `${b.width}px`, c.style.height = `${b.height}px`, c.style.backgroundColor = $((m == null ? void 0 : m.fill) || q.fill).alpha((m == null ? void 0 : m.fillOpacity) === void 0 ? q.fillOpacity : m.fillOpacity).toHex(), m.underlineStyle && (c.style.borderStyle = m.underlineStyle), m.underlineColor && (c.style.borderColor = m.underlineColor), m.underlineThickness && (c.style.borderBottomWidth = `${m.underlineThickness}px`), m.underlineOffset && (c.style.paddingBottom = `${m.underlineOffset}px`), e.appendChild(c);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}), n = a;
|
|
595
|
+
},
|
|
596
|
+
setVisible: (a) => {
|
|
597
|
+
a ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
}, mn = (t, e, n) => $t(t, e, n, gn(t)), V = [];
|
|
601
|
+
for (let t = 0; t < 256; ++t)
|
|
602
|
+
V.push((t + 256).toString(16).slice(1));
|
|
603
|
+
function yn(t, e = 0) {
|
|
604
|
+
return (V[t[e + 0]] + V[t[e + 1]] + V[t[e + 2]] + V[t[e + 3]] + "-" + V[t[e + 4]] + V[t[e + 5]] + "-" + V[t[e + 6]] + V[t[e + 7]] + "-" + V[t[e + 8]] + V[t[e + 9]] + "-" + V[t[e + 10]] + V[t[e + 11]] + V[t[e + 12]] + V[t[e + 13]] + V[t[e + 14]] + V[t[e + 15]]).toLowerCase();
|
|
605
|
+
}
|
|
606
|
+
let Rt;
|
|
607
|
+
const bn = new Uint8Array(16);
|
|
608
|
+
function wn() {
|
|
609
|
+
if (!Rt) {
|
|
610
|
+
if (typeof crypto > "u" || !crypto.getRandomValues)
|
|
611
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
612
|
+
Rt = crypto.getRandomValues.bind(crypto);
|
|
613
|
+
}
|
|
614
|
+
return Rt(bn);
|
|
615
|
+
}
|
|
616
|
+
const An = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ne = { randomUUID: An };
|
|
617
|
+
function be(t, e, n) {
|
|
618
|
+
if (ne.randomUUID && !e && !t)
|
|
619
|
+
return ne.randomUUID();
|
|
620
|
+
t = t || {};
|
|
621
|
+
const o = t.random || (t.rng || wn)();
|
|
622
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, yn(o);
|
|
623
|
+
}
|
|
624
|
+
var oe = Object.prototype.hasOwnProperty;
|
|
625
|
+
function Q(t, e) {
|
|
626
|
+
var n, o;
|
|
627
|
+
if (t === e) return !0;
|
|
628
|
+
if (t && e && (n = t.constructor) === e.constructor) {
|
|
629
|
+
if (n === Date) return t.getTime() === e.getTime();
|
|
630
|
+
if (n === RegExp) return t.toString() === e.toString();
|
|
631
|
+
if (n === Array) {
|
|
632
|
+
if ((o = t.length) === e.length)
|
|
633
|
+
for (; o-- && Q(t[o], e[o]); ) ;
|
|
634
|
+
return o === -1;
|
|
635
|
+
}
|
|
636
|
+
if (!n || typeof t == "object") {
|
|
637
|
+
o = 0;
|
|
638
|
+
for (n in t)
|
|
639
|
+
if (oe.call(t, n) && ++o && !oe.call(e, n) || !(n in e) || !Q(t[n], e[n])) return !1;
|
|
640
|
+
return Object.keys(e).length === o;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return t !== t && e !== e;
|
|
644
|
+
}
|
|
645
|
+
function Mt() {
|
|
646
|
+
}
|
|
647
|
+
function xn(t, e) {
|
|
648
|
+
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
649
|
+
}
|
|
650
|
+
const J = [];
|
|
651
|
+
function Ht(t, e = Mt) {
|
|
652
|
+
let n;
|
|
653
|
+
const o = /* @__PURE__ */ new Set();
|
|
654
|
+
function i(r) {
|
|
655
|
+
if (xn(t, r) && (t = r, n)) {
|
|
656
|
+
const l = !J.length;
|
|
657
|
+
for (const d of o)
|
|
658
|
+
d[1](), J.push(d, t);
|
|
659
|
+
if (l) {
|
|
660
|
+
for (let d = 0; d < J.length; d += 2)
|
|
661
|
+
J[d][0](J[d + 1]);
|
|
662
|
+
J.length = 0;
|
|
364
663
|
}
|
|
365
664
|
}
|
|
366
665
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const minY = -top;
|
|
387
|
-
const maxX = innerWidth - left;
|
|
388
|
-
const maxY = innerHeight - top;
|
|
389
|
-
return { top, left, minX, minY, maxX, maxY };
|
|
390
|
-
};
|
|
391
|
-
const trackViewport = (viewport) => {
|
|
392
|
-
let visible = /* @__PURE__ */ new Set();
|
|
393
|
-
const onDraw = (annotations) => {
|
|
394
|
-
const ids = annotations.map((a) => a.id);
|
|
395
|
-
if (visible.size !== ids.length || ids.some((id) => !visible.has(id))) {
|
|
396
|
-
viewport.set(ids);
|
|
666
|
+
function s(r) {
|
|
667
|
+
i(r(t));
|
|
668
|
+
}
|
|
669
|
+
function a(r, l = Mt) {
|
|
670
|
+
const d = [r, l];
|
|
671
|
+
return o.add(d), o.size === 1 && (n = e(i, s) || Mt), r(t), () => {
|
|
672
|
+
o.delete(d), o.size === 0 && n && (n(), n = null);
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
return { set: i, update: s, subscribe: a };
|
|
676
|
+
}
|
|
677
|
+
const vn = (t) => {
|
|
678
|
+
const { subscribe: e, set: n } = Ht();
|
|
679
|
+
let o;
|
|
680
|
+
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
681
|
+
if (o) {
|
|
682
|
+
(i.deleted || []).some((a) => a.id === o) && n(void 0);
|
|
683
|
+
const s = (i.updated || []).find(({ oldValue: a }) => a.id === o);
|
|
684
|
+
s && n(s.newValue.id);
|
|
397
685
|
}
|
|
398
|
-
|
|
686
|
+
}), {
|
|
687
|
+
get current() {
|
|
688
|
+
return o;
|
|
689
|
+
},
|
|
690
|
+
subscribe: e,
|
|
691
|
+
set: n
|
|
399
692
|
};
|
|
400
|
-
return onDraw;
|
|
401
693
|
};
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
let
|
|
406
|
-
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
694
|
+
var En = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(En || {});
|
|
695
|
+
const yt = { selected: [] }, Sn = (t, e, n) => {
|
|
696
|
+
const { subscribe: o, set: i } = Ht(yt);
|
|
697
|
+
let s = e, a = yt;
|
|
698
|
+
o((p) => a = p);
|
|
699
|
+
const r = () => {
|
|
700
|
+
Q(a, yt) || i(yt);
|
|
701
|
+
}, l = () => {
|
|
702
|
+
var p;
|
|
703
|
+
return ((p = a.selected) == null ? void 0 : p.length) === 0;
|
|
704
|
+
}, d = (p) => {
|
|
705
|
+
if (l())
|
|
706
|
+
return !1;
|
|
707
|
+
const b = typeof p == "string" ? p : p.id;
|
|
708
|
+
return a.selected.some((x) => x.id === b);
|
|
709
|
+
}, g = (p, b) => {
|
|
710
|
+
let x;
|
|
711
|
+
if (Array.isArray(p)) {
|
|
712
|
+
if (x = p.map((c) => t.getAnnotation(c)).filter(Boolean), x.length < p.length) {
|
|
713
|
+
console.warn("Invalid selection: " + p.filter((c) => !x.some((y) => y.id === c)));
|
|
714
|
+
return;
|
|
415
715
|
}
|
|
416
716
|
} else {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
717
|
+
const c = t.getAnnotation(p);
|
|
718
|
+
if (!c) {
|
|
719
|
+
console.warn("Invalid selection: " + p);
|
|
720
|
+
return;
|
|
420
721
|
}
|
|
722
|
+
x = [c];
|
|
421
723
|
}
|
|
724
|
+
const m = x.reduce((c, y) => {
|
|
725
|
+
const C = ie(y, s, n);
|
|
726
|
+
return C === "EDIT" ? [...c, { id: y.id, editable: !0 }] : C === "SELECT" ? [...c, { id: y.id }] : c;
|
|
727
|
+
}, []);
|
|
728
|
+
i({ selected: m, event: b });
|
|
729
|
+
}, u = (p, b) => {
|
|
730
|
+
const x = Array.isArray(p) ? p : [p], m = x.map((c) => t.getAnnotation(c)).filter((c) => !!c);
|
|
731
|
+
i({
|
|
732
|
+
selected: m.map((c) => {
|
|
733
|
+
const y = b === void 0 ? ie(c, s, n) === "EDIT" : b;
|
|
734
|
+
return { id: c.id, editable: y };
|
|
735
|
+
})
|
|
736
|
+
}), m.length !== x.length && console.warn("Invalid selection", p);
|
|
737
|
+
}, f = (p) => {
|
|
738
|
+
if (l())
|
|
739
|
+
return !1;
|
|
740
|
+
const { selected: b } = a;
|
|
741
|
+
b.some(({ id: x }) => p.includes(x)) && i({ selected: b.filter(({ id: x }) => !p.includes(x)) });
|
|
742
|
+
}, A = (p) => s = p;
|
|
743
|
+
return t.observe(
|
|
744
|
+
({ changes: p }) => f((p.deleted || []).map((b) => b.id))
|
|
745
|
+
), {
|
|
746
|
+
get event() {
|
|
747
|
+
return a ? a.event : null;
|
|
748
|
+
},
|
|
749
|
+
get selected() {
|
|
750
|
+
return a ? [...a.selected] : null;
|
|
751
|
+
},
|
|
752
|
+
get userSelectAction() {
|
|
753
|
+
return s;
|
|
754
|
+
},
|
|
755
|
+
clear: r,
|
|
756
|
+
isEmpty: l,
|
|
757
|
+
isSelected: d,
|
|
758
|
+
setSelected: u,
|
|
759
|
+
setUserSelectAction: A,
|
|
760
|
+
subscribe: o,
|
|
761
|
+
userSelect: g
|
|
762
|
+
};
|
|
763
|
+
}, ie = (t, e, n) => {
|
|
764
|
+
const o = n ? n.serialize(t) : t;
|
|
765
|
+
return typeof e == "function" ? e(o) : e || "EDIT";
|
|
766
|
+
}, Y = [];
|
|
767
|
+
for (let t = 0; t < 256; ++t)
|
|
768
|
+
Y.push((t + 256).toString(16).slice(1));
|
|
769
|
+
function Cn(t, e = 0) {
|
|
770
|
+
return (Y[t[e + 0]] + Y[t[e + 1]] + Y[t[e + 2]] + Y[t[e + 3]] + "-" + Y[t[e + 4]] + Y[t[e + 5]] + "-" + Y[t[e + 6]] + Y[t[e + 7]] + "-" + Y[t[e + 8]] + Y[t[e + 9]] + "-" + Y[t[e + 10]] + Y[t[e + 11]] + Y[t[e + 12]] + Y[t[e + 13]] + Y[t[e + 14]] + Y[t[e + 15]]).toLowerCase();
|
|
771
|
+
}
|
|
772
|
+
let kt;
|
|
773
|
+
const Ln = new Uint8Array(16);
|
|
774
|
+
function Tn() {
|
|
775
|
+
if (!kt) {
|
|
776
|
+
if (typeof crypto > "u" || !crypto.getRandomValues)
|
|
777
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
778
|
+
kt = crypto.getRandomValues.bind(crypto);
|
|
779
|
+
}
|
|
780
|
+
return kt(Ln);
|
|
781
|
+
}
|
|
782
|
+
const On = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), se = { randomUUID: On };
|
|
783
|
+
function we(t, e, n) {
|
|
784
|
+
if (se.randomUUID && !e && !t)
|
|
785
|
+
return se.randomUUID();
|
|
786
|
+
t = t || {};
|
|
787
|
+
const o = t.random || (t.rng || Tn)();
|
|
788
|
+
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, Cn(o);
|
|
789
|
+
}
|
|
790
|
+
const It = (t) => {
|
|
791
|
+
const e = (n) => {
|
|
792
|
+
const o = { ...n };
|
|
793
|
+
return n.created && typeof n.created == "string" && (o.created = new Date(n.created)), n.updated && typeof n.updated == "string" && (o.updated = new Date(n.updated)), o;
|
|
422
794
|
};
|
|
423
|
-
container.addEventListener("pointermove", onPointerMove);
|
|
424
|
-
const redraw = (lazy = false) => {
|
|
425
|
-
if (currentPainter)
|
|
426
|
-
currentPainter.clear();
|
|
427
|
-
const bounds = getViewportBounds(container);
|
|
428
|
-
const { minX, minY, maxX, maxY } = bounds;
|
|
429
|
-
const annotationsInView = currentFilter ? store.getIntersecting(minX, minY, maxX, maxY).filter(({ annotation }) => currentFilter(annotation)) : store.getIntersecting(minX, minY, maxX, maxY);
|
|
430
|
-
const selectedIds = selection.selected.map(({ id }) => id);
|
|
431
|
-
const highlights = annotationsInView.map(({ annotation, rects }) => {
|
|
432
|
-
const selected = selectedIds.includes(annotation.id);
|
|
433
|
-
const hovered = annotation.id === hover.current;
|
|
434
|
-
return { annotation, rects, state: { selected, hover: hovered } };
|
|
435
|
-
});
|
|
436
|
-
renderer.redraw(highlights, bounds, currentStyle, currentPainter, lazy);
|
|
437
|
-
setTimeout(() => onDraw(annotationsInView.map(({ annotation }) => annotation)), 1);
|
|
438
|
-
};
|
|
439
|
-
const setPainter = (painter) => {
|
|
440
|
-
currentPainter = painter;
|
|
441
|
-
redraw();
|
|
442
|
-
};
|
|
443
|
-
const setStyle = (style) => {
|
|
444
|
-
currentStyle = style;
|
|
445
|
-
redraw();
|
|
446
|
-
};
|
|
447
|
-
const setFilter = (filter) => {
|
|
448
|
-
currentFilter = filter;
|
|
449
|
-
redraw(false);
|
|
450
|
-
};
|
|
451
|
-
const onStoreChange = () => redraw();
|
|
452
|
-
store.observe(onStoreChange);
|
|
453
|
-
const unsubscribeSelection = selection.subscribe(() => redraw());
|
|
454
|
-
const onScroll = () => redraw(true);
|
|
455
|
-
document.addEventListener("scroll", onScroll, { capture: true, passive: true });
|
|
456
|
-
const onResize = debounce(() => {
|
|
457
|
-
store.recalculatePositions();
|
|
458
|
-
currentPainter == null ? void 0 : currentPainter.reset();
|
|
459
|
-
redraw();
|
|
460
|
-
}, 10);
|
|
461
|
-
window.addEventListener("resize", onResize);
|
|
462
|
-
const resizeObserver = new ResizeObserver(onResize);
|
|
463
|
-
resizeObserver.observe(container);
|
|
464
|
-
const config = { attributes: true, childList: true, subtree: true };
|
|
465
|
-
const mutationObserver = new MutationObserver((records) => {
|
|
466
|
-
const isInternal = records.every((record) => record.target === container || container.contains(record.target));
|
|
467
|
-
if (!isInternal) redraw(true);
|
|
468
|
-
});
|
|
469
|
-
mutationObserver.observe(document.body, config);
|
|
470
|
-
const destroy = () => {
|
|
471
|
-
container.removeEventListener("pointermove", onPointerMove);
|
|
472
|
-
renderer.destroy();
|
|
473
|
-
store.unobserve(onStoreChange);
|
|
474
|
-
unsubscribeSelection();
|
|
475
|
-
document.removeEventListener("scroll", onScroll);
|
|
476
|
-
onResize.clear();
|
|
477
|
-
window.removeEventListener("resize", onResize);
|
|
478
|
-
resizeObserver.disconnect();
|
|
479
|
-
mutationObserver.disconnect();
|
|
480
|
-
};
|
|
481
795
|
return {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
796
|
+
...t,
|
|
797
|
+
bodies: (t.bodies || []).map(e),
|
|
798
|
+
target: e(t.target)
|
|
799
|
+
};
|
|
800
|
+
}, Io = (t, e, n, o) => ({
|
|
801
|
+
id: we(),
|
|
802
|
+
annotation: typeof t == "string" ? t : t.id,
|
|
803
|
+
created: n || /* @__PURE__ */ new Date(),
|
|
804
|
+
creator: o,
|
|
805
|
+
...e
|
|
806
|
+
}), Bn = (t, e) => {
|
|
807
|
+
const n = new Set(t.bodies.map((o) => o.id));
|
|
808
|
+
return e.bodies.filter((o) => !n.has(o.id));
|
|
809
|
+
}, Rn = (t, e) => {
|
|
810
|
+
const n = new Set(e.bodies.map((o) => o.id));
|
|
811
|
+
return t.bodies.filter((o) => !n.has(o.id));
|
|
812
|
+
}, Mn = (t, e) => e.bodies.map((n) => {
|
|
813
|
+
const o = t.bodies.find((i) => i.id === n.id);
|
|
814
|
+
return { newBody: n, oldBody: o && !Q(o, n) ? o : void 0 };
|
|
815
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), kn = (t, e) => !Q(t.target, e.target), Ae = (t, e) => {
|
|
816
|
+
const n = Bn(t, e), o = Rn(t, e), i = Mn(t, e);
|
|
817
|
+
return {
|
|
818
|
+
oldValue: t,
|
|
819
|
+
newValue: e,
|
|
820
|
+
bodiesCreated: n.length > 0 ? n : void 0,
|
|
821
|
+
bodiesDeleted: o.length > 0 ? o : void 0,
|
|
822
|
+
bodiesUpdated: i.length > 0 ? i : void 0,
|
|
823
|
+
targetUpdated: kn(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
|
|
488
824
|
};
|
|
489
825
|
};
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
ctx.strokeStyle = style.underlineColor;
|
|
535
|
-
ctx.lineWidth = style.underlineThickness ?? 1;
|
|
536
|
-
const underlineOffset = style.underlineOffset ?? 0;
|
|
537
|
-
offsetRects.forEach(({ x, y, width: width2, height: height2 }) => {
|
|
538
|
-
ctx.beginPath();
|
|
539
|
-
ctx.moveTo(x, y + height2 + underlineOffset);
|
|
540
|
-
ctx.lineTo(x + width2, y + height2 + underlineOffset);
|
|
541
|
-
ctx.stroke();
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
});
|
|
546
|
-
const onResize = debounce(() => resetCanvas(canvas), 10);
|
|
547
|
-
window.addEventListener("resize", onResize);
|
|
548
|
-
const setVisible = (visible) => {
|
|
549
|
-
console.log("setVisible not implemented on Canvas renderer");
|
|
550
|
-
};
|
|
551
|
-
const destroy = () => {
|
|
552
|
-
canvas.remove();
|
|
553
|
-
onResize.clear();
|
|
554
|
-
window.removeEventListener("resize", onResize);
|
|
555
|
-
};
|
|
826
|
+
var k = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(k || {});
|
|
827
|
+
const In = (t, e) => {
|
|
828
|
+
var n, o;
|
|
829
|
+
const { changes: i, origin: s } = e;
|
|
830
|
+
if (!(t.options.origin ? t.options.origin === s : s !== "SILENT"))
|
|
831
|
+
return !1;
|
|
832
|
+
if (t.options.ignore) {
|
|
833
|
+
const { ignore: a } = t.options, r = (l) => l && l.length > 0;
|
|
834
|
+
if (!(r(i.created) || r(i.deleted))) {
|
|
835
|
+
const l = (n = i.updated) == null ? void 0 : n.some((g) => r(g.bodiesCreated) || r(g.bodiesDeleted) || r(g.bodiesUpdated)), d = (o = i.updated) == null ? void 0 : o.some((g) => g.targetUpdated);
|
|
836
|
+
if (a === "BODY_ONLY" && l && !d || a === "TARGET_ONLY" && d && !l)
|
|
837
|
+
return !1;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (t.options.annotations) {
|
|
841
|
+
const a = /* @__PURE__ */ new Set([
|
|
842
|
+
...(i.created || []).map((r) => r.id),
|
|
843
|
+
...(i.deleted || []).map((r) => r.id),
|
|
844
|
+
...(i.updated || []).map(({ oldValue: r }) => r.id)
|
|
845
|
+
]);
|
|
846
|
+
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((r) => a.has(r));
|
|
847
|
+
} else
|
|
848
|
+
return !0;
|
|
849
|
+
}, Nn = (t, e) => {
|
|
850
|
+
const n = new Set((t.created || []).map((u) => u.id)), o = new Set((t.updated || []).map(({ newValue: u }) => u.id)), i = new Set((e.created || []).map((u) => u.id)), s = new Set((e.deleted || []).map((u) => u.id)), a = new Set((e.updated || []).map(({ oldValue: u }) => u.id)), r = new Set((e.updated || []).filter(({ oldValue: u }) => n.has(u.id) || o.has(u.id)).map(({ oldValue: u }) => u.id)), l = [
|
|
851
|
+
...(t.created || []).filter((u) => !s.has(u.id)).map((u) => a.has(u.id) ? e.updated.find(({ oldValue: f }) => f.id === u.id).newValue : u),
|
|
852
|
+
...e.created || []
|
|
853
|
+
], d = [
|
|
854
|
+
...(t.deleted || []).filter((u) => !i.has(u.id)),
|
|
855
|
+
...(e.deleted || []).filter((u) => !n.has(u.id))
|
|
856
|
+
], g = [
|
|
857
|
+
...(t.updated || []).filter(({ newValue: u }) => !s.has(u.id)).map((u) => {
|
|
858
|
+
const { oldValue: f, newValue: A } = u;
|
|
859
|
+
if (a.has(A.id)) {
|
|
860
|
+
const p = e.updated.find((b) => b.oldValue.id === A.id).newValue;
|
|
861
|
+
return Ae(f, p);
|
|
862
|
+
} else
|
|
863
|
+
return u;
|
|
864
|
+
}),
|
|
865
|
+
...(e.updated || []).filter(({ oldValue: u }) => !r.has(u.id))
|
|
866
|
+
];
|
|
867
|
+
return { created: l, deleted: d, updated: g };
|
|
868
|
+
}, Nt = (t) => {
|
|
869
|
+
const e = t.id === void 0 ? we() : t.id;
|
|
556
870
|
return {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
871
|
+
...t,
|
|
872
|
+
id: e,
|
|
873
|
+
bodies: t.bodies === void 0 ? [] : t.bodies.map((n) => ({
|
|
874
|
+
...n,
|
|
875
|
+
annotation: e
|
|
876
|
+
})),
|
|
877
|
+
target: {
|
|
878
|
+
...t.target,
|
|
879
|
+
annotation: e
|
|
880
|
+
}
|
|
560
881
|
};
|
|
561
|
-
}
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
if (painter)
|
|
580
|
-
painter.clear();
|
|
581
|
-
const nextRendered = new Set(highlights.map((h) => h.annotation.id));
|
|
582
|
-
Array.from(currentRendered).filter((id) => !nextRendered.has(id));
|
|
583
|
-
const updatedCSS = highlights.map((h) => {
|
|
584
|
-
var _a;
|
|
585
|
-
const base = currentStyle ? typeof currentStyle === "function" ? currentStyle(h.annotation, h.state) : currentStyle : ((_a = h.state) == null ? void 0 : _a.selected) ? DEFAULT_SELECTED_STYLE : DEFAULT_STYLE;
|
|
586
|
-
const style = painter ? painter.paint(h, viewportBounds) || base : base;
|
|
587
|
-
return `::highlight(_${h.annotation.id}) { ${toCSS(style)} }`;
|
|
588
|
-
});
|
|
589
|
-
elem.innerHTML = updatedCSS.join("\n");
|
|
590
|
-
CSS.highlights.clear();
|
|
591
|
-
highlights.forEach(({ annotation }) => {
|
|
592
|
-
const ranges = annotation.target.selector.map((s) => s.range);
|
|
593
|
-
const highlights2 = new Highlight(...ranges);
|
|
594
|
-
CSS.highlights.set(`_${annotation.id}`, highlights2);
|
|
882
|
+
}, _n = (t) => t.id !== void 0, Un = () => {
|
|
883
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (w, v = {}) => {
|
|
884
|
+
n.push({ onChange: w, options: v });
|
|
885
|
+
}, i = (w) => {
|
|
886
|
+
const v = n.findIndex((h) => h.onChange == w);
|
|
887
|
+
v > -1 && n.splice(v, 1);
|
|
888
|
+
}, s = (w, v) => {
|
|
889
|
+
const h = {
|
|
890
|
+
origin: w,
|
|
891
|
+
changes: {
|
|
892
|
+
created: v.created || [],
|
|
893
|
+
updated: v.updated || [],
|
|
894
|
+
deleted: v.deleted || []
|
|
895
|
+
},
|
|
896
|
+
state: [...t.values()]
|
|
897
|
+
};
|
|
898
|
+
n.forEach((E) => {
|
|
899
|
+
In(E, h) && E.onChange(h);
|
|
595
900
|
});
|
|
596
|
-
|
|
901
|
+
}, a = (w, v = k.LOCAL) => {
|
|
902
|
+
if (w.id && t.get(w.id))
|
|
903
|
+
throw Error(`Cannot add annotation ${w.id} - exists already`);
|
|
904
|
+
{
|
|
905
|
+
const h = Nt(w);
|
|
906
|
+
t.set(h.id, h), h.bodies.forEach((E) => e.set(E.id, h.id)), s(v, { created: [h] });
|
|
907
|
+
}
|
|
908
|
+
}, r = (w, v) => {
|
|
909
|
+
const h = Nt(typeof w == "string" ? v : w), E = typeof w == "string" ? w : w.id, M = E && t.get(E);
|
|
910
|
+
if (M) {
|
|
911
|
+
const O = Ae(M, h);
|
|
912
|
+
return E === h.id ? t.set(E, h) : (t.delete(E), t.set(h.id, h)), M.bodies.forEach((U) => e.delete(U.id)), h.bodies.forEach((U) => e.set(U.id, h.id)), O;
|
|
913
|
+
} else
|
|
914
|
+
console.warn(`Cannot update annotation ${E} - does not exist`);
|
|
915
|
+
}, l = (w, v = k.LOCAL, h = k.LOCAL) => {
|
|
916
|
+
const E = _n(v) ? h : v, M = r(w, v);
|
|
917
|
+
M && s(E, { updated: [M] });
|
|
918
|
+
}, d = (w, v = k.LOCAL) => {
|
|
919
|
+
const h = w.reduce((E, M) => {
|
|
920
|
+
const O = r(M);
|
|
921
|
+
return O ? [...E, O] : E;
|
|
922
|
+
}, []);
|
|
923
|
+
h.length > 0 && s(v, { updated: h });
|
|
924
|
+
}, g = (w, v = k.LOCAL) => {
|
|
925
|
+
const h = t.get(w.annotation);
|
|
926
|
+
if (h) {
|
|
927
|
+
const E = {
|
|
928
|
+
...h,
|
|
929
|
+
bodies: [...h.bodies, w]
|
|
930
|
+
};
|
|
931
|
+
t.set(h.id, E), e.set(w.id, E.id), s(v, { updated: [{
|
|
932
|
+
oldValue: h,
|
|
933
|
+
newValue: E,
|
|
934
|
+
bodiesCreated: [w]
|
|
935
|
+
}] });
|
|
936
|
+
} else
|
|
937
|
+
console.warn(`Attempt to add body to missing annotation: ${w.annotation}`);
|
|
938
|
+
}, u = () => [...t.values()], f = (w = k.LOCAL) => {
|
|
939
|
+
const v = [...t.values()];
|
|
940
|
+
t.clear(), e.clear(), s(w, { deleted: v });
|
|
941
|
+
}, A = (w, v = !0, h = k.LOCAL) => {
|
|
942
|
+
const E = w.map(Nt);
|
|
943
|
+
if (v) {
|
|
944
|
+
const M = [...t.values()];
|
|
945
|
+
t.clear(), e.clear(), E.forEach((O) => {
|
|
946
|
+
t.set(O.id, O), O.bodies.forEach((U) => e.set(U.id, O.id));
|
|
947
|
+
}), s(h, { created: E, deleted: M });
|
|
948
|
+
} else {
|
|
949
|
+
const M = w.reduce((O, U) => {
|
|
950
|
+
const _ = U.id && t.get(U.id);
|
|
951
|
+
return _ ? [...O, _] : O;
|
|
952
|
+
}, []);
|
|
953
|
+
if (M.length > 0)
|
|
954
|
+
throw Error(`Bulk insert would overwrite the following annotations: ${M.map((O) => O.id).join(", ")}`);
|
|
955
|
+
E.forEach((O) => {
|
|
956
|
+
t.set(O.id, O), O.bodies.forEach((U) => e.set(U.id, O.id));
|
|
957
|
+
}), s(h, { created: E });
|
|
958
|
+
}
|
|
959
|
+
}, p = (w) => {
|
|
960
|
+
const v = typeof w == "string" ? w : w.id, h = t.get(v);
|
|
961
|
+
if (h)
|
|
962
|
+
return t.delete(v), h.bodies.forEach((E) => e.delete(E.id)), h;
|
|
963
|
+
console.warn(`Attempt to delete missing annotation: ${v}`);
|
|
964
|
+
}, b = (w, v = k.LOCAL) => {
|
|
965
|
+
const h = p(w);
|
|
966
|
+
h && s(v, { deleted: [h] });
|
|
967
|
+
}, x = (w, v = k.LOCAL) => {
|
|
968
|
+
const h = w.reduce((E, M) => {
|
|
969
|
+
const O = p(M);
|
|
970
|
+
return O ? [...E, O] : E;
|
|
971
|
+
}, []);
|
|
972
|
+
h.length > 0 && s(v, { deleted: h });
|
|
973
|
+
}, m = (w) => {
|
|
974
|
+
const v = t.get(w.annotation);
|
|
975
|
+
if (v) {
|
|
976
|
+
const h = v.bodies.find((E) => E.id === w.id);
|
|
977
|
+
if (h) {
|
|
978
|
+
e.delete(h.id);
|
|
979
|
+
const E = {
|
|
980
|
+
...v,
|
|
981
|
+
bodies: v.bodies.filter((M) => M.id !== w.id)
|
|
982
|
+
};
|
|
983
|
+
return t.set(v.id, E), {
|
|
984
|
+
oldValue: v,
|
|
985
|
+
newValue: E,
|
|
986
|
+
bodiesDeleted: [h]
|
|
987
|
+
};
|
|
988
|
+
} else
|
|
989
|
+
console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`);
|
|
990
|
+
} else
|
|
991
|
+
console.warn(`Attempt to delete body from missing annotation ${w.annotation}`);
|
|
992
|
+
}, c = (w, v = k.LOCAL) => {
|
|
993
|
+
const h = m(w);
|
|
994
|
+
h && s(v, { updated: [h] });
|
|
995
|
+
}, y = (w, v = k.LOCAL) => {
|
|
996
|
+
const h = w.map((E) => m(E)).filter(Boolean);
|
|
997
|
+
h.length > 0 && s(v, { updated: h });
|
|
998
|
+
}, C = (w) => {
|
|
999
|
+
const v = t.get(w);
|
|
1000
|
+
return v ? { ...v } : void 0;
|
|
1001
|
+
}, S = (w) => {
|
|
1002
|
+
const v = e.get(w);
|
|
1003
|
+
if (v) {
|
|
1004
|
+
const h = C(v).bodies.find((E) => E.id === w);
|
|
1005
|
+
if (h)
|
|
1006
|
+
return h;
|
|
1007
|
+
console.error(`Store integrity error: body ${w} in index, but not in annotation`);
|
|
1008
|
+
} else
|
|
1009
|
+
console.warn(`Attempt to retrieve missing body: ${w}`);
|
|
1010
|
+
}, L = (w, v) => {
|
|
1011
|
+
if (w.annotation !== v.annotation)
|
|
1012
|
+
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
1013
|
+
const h = t.get(w.annotation);
|
|
1014
|
+
if (h) {
|
|
1015
|
+
const E = h.bodies.find((O) => O.id === w.id), M = {
|
|
1016
|
+
...h,
|
|
1017
|
+
bodies: h.bodies.map((O) => O.id === E.id ? v : O)
|
|
1018
|
+
};
|
|
1019
|
+
return t.set(h.id, M), E.id !== v.id && (e.delete(E.id), e.set(v.id, M.id)), {
|
|
1020
|
+
oldValue: h,
|
|
1021
|
+
newValue: M,
|
|
1022
|
+
bodiesUpdated: [{ oldBody: E, newBody: v }]
|
|
1023
|
+
};
|
|
1024
|
+
} else
|
|
1025
|
+
console.warn(`Attempt to add body to missing annotation ${w.annotation}`);
|
|
1026
|
+
}, B = (w, v, h = k.LOCAL) => {
|
|
1027
|
+
const E = L(w, v);
|
|
1028
|
+
E && s(h, { updated: [E] });
|
|
1029
|
+
}, T = (w, v = k.LOCAL) => {
|
|
1030
|
+
const h = w.map((E) => L({ id: E.id, annotation: E.annotation }, E)).filter(Boolean);
|
|
1031
|
+
s(v, { updated: h });
|
|
1032
|
+
}, R = (w) => {
|
|
1033
|
+
const v = t.get(w.annotation);
|
|
1034
|
+
if (v) {
|
|
1035
|
+
const h = {
|
|
1036
|
+
...v,
|
|
1037
|
+
target: {
|
|
1038
|
+
...v.target,
|
|
1039
|
+
...w
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
return t.set(v.id, h), {
|
|
1043
|
+
oldValue: v,
|
|
1044
|
+
newValue: h,
|
|
1045
|
+
targetUpdated: {
|
|
1046
|
+
oldTarget: v.target,
|
|
1047
|
+
newTarget: w
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
} else
|
|
1051
|
+
console.warn(`Attempt to update target on missing annotation: ${w.annotation}`);
|
|
597
1052
|
};
|
|
598
|
-
|
|
599
|
-
|
|
1053
|
+
return {
|
|
1054
|
+
addAnnotation: a,
|
|
1055
|
+
addBody: g,
|
|
1056
|
+
all: u,
|
|
1057
|
+
bulkAddAnnotation: A,
|
|
1058
|
+
bulkDeleteAnnotation: x,
|
|
1059
|
+
bulkDeleteBodies: y,
|
|
1060
|
+
bulkUpdateAnnotation: d,
|
|
1061
|
+
bulkUpdateBodies: T,
|
|
1062
|
+
bulkUpdateTargets: (w, v = k.LOCAL) => {
|
|
1063
|
+
const h = w.map((E) => R(E)).filter(Boolean);
|
|
1064
|
+
h.length > 0 && s(v, { updated: h });
|
|
1065
|
+
},
|
|
1066
|
+
clear: f,
|
|
1067
|
+
deleteAnnotation: b,
|
|
1068
|
+
deleteBody: c,
|
|
1069
|
+
getAnnotation: C,
|
|
1070
|
+
getBody: S,
|
|
1071
|
+
observe: o,
|
|
1072
|
+
unobserve: i,
|
|
1073
|
+
updateAnnotation: l,
|
|
1074
|
+
updateBody: B,
|
|
1075
|
+
updateTarget: (w, v = k.LOCAL) => {
|
|
1076
|
+
const h = R(w);
|
|
1077
|
+
h && s(v, { updated: [h] });
|
|
1078
|
+
}
|
|
600
1079
|
};
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
1080
|
+
};
|
|
1081
|
+
let Dn = () => ({
|
|
1082
|
+
emit(t, ...e) {
|
|
1083
|
+
for (let n = this.events[t] || [], o = 0, i = n.length; o < i; o++)
|
|
1084
|
+
n[o](...e);
|
|
1085
|
+
},
|
|
1086
|
+
events: {},
|
|
1087
|
+
on(t, e) {
|
|
1088
|
+
var n;
|
|
1089
|
+
return ((n = this.events)[t] || (n[t] = [])).push(e), () => {
|
|
1090
|
+
var o;
|
|
1091
|
+
this.events[t] = (o = this.events[t]) == null ? void 0 : o.filter((i) => e !== i);
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
const Vn = 250, Yn = (t, e) => {
|
|
1096
|
+
const n = Dn(), o = [];
|
|
1097
|
+
let i = -1, s = !1, a = 0;
|
|
1098
|
+
const r = (p) => {
|
|
1099
|
+
if (!s) {
|
|
1100
|
+
const { changes: b } = p, x = performance.now();
|
|
1101
|
+
if (x - a > Vn)
|
|
1102
|
+
o.splice(i + 1), o.push(b), i = o.length - 1;
|
|
1103
|
+
else {
|
|
1104
|
+
const m = o.length - 1;
|
|
1105
|
+
o[m] = Nn(o[m], b);
|
|
1106
|
+
}
|
|
1107
|
+
a = x;
|
|
1108
|
+
}
|
|
1109
|
+
s = !1;
|
|
604
1110
|
};
|
|
1111
|
+
t.observe(r, { origin: k.LOCAL });
|
|
1112
|
+
const l = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p), d = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), g = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ oldValue: b }) => b)), u = (p) => p && p.length > 0 && t.bulkUpdateAnnotation(p.map(({ newValue: b }) => b)), f = (p) => p && p.length > 0 && t.bulkAddAnnotation(p, !1), A = (p) => p && p.length > 0 && t.bulkDeleteAnnotation(p);
|
|
605
1113
|
return {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
1114
|
+
canRedo: () => o.length - 1 > i,
|
|
1115
|
+
canUndo: () => i > -1,
|
|
1116
|
+
destroy: () => t.unobserve(r),
|
|
1117
|
+
getHistory: () => ({ changes: [...o], pointer: i }),
|
|
1118
|
+
on: (p, b) => n.on(p, b),
|
|
1119
|
+
redo: () => {
|
|
1120
|
+
if (o.length - 1 > i) {
|
|
1121
|
+
s = !0;
|
|
1122
|
+
const { created: p, updated: b, deleted: x } = o[i + 1];
|
|
1123
|
+
d(p), u(b), A(x), n.emit("redo", o[i + 1]), i += 1;
|
|
1124
|
+
}
|
|
1125
|
+
},
|
|
1126
|
+
undo: () => {
|
|
1127
|
+
if (i > -1) {
|
|
1128
|
+
s = !0;
|
|
1129
|
+
const { created: p, updated: b, deleted: x } = o[i];
|
|
1130
|
+
l(p), g(b), f(x), n.emit("undo", o[i]), i -= 1;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
609
1133
|
};
|
|
610
|
-
}
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
});
|
|
636
|
-
sorted.forEach((highlight) => {
|
|
637
|
-
highlight.rects.map((rect) => {
|
|
638
|
-
const zIndex = computeZIndex(rect, highlights);
|
|
639
|
-
const style = paint(highlight, viewportBounds, currentStyle, painter, zIndex);
|
|
640
|
-
if (shouldRedraw) {
|
|
641
|
-
const span = document.createElement("span");
|
|
642
|
-
span.className = "r6o-annotation";
|
|
643
|
-
span.dataset.annotation = highlight.annotation.id;
|
|
644
|
-
span.style.left = `${rect.x}px`;
|
|
645
|
-
span.style.top = `${rect.y}px`;
|
|
646
|
-
span.style.width = `${rect.width}px`;
|
|
647
|
-
span.style.height = `${rect.height}px`;
|
|
648
|
-
span.style.backgroundColor = colord((style == null ? void 0 : style.fill) || DEFAULT_STYLE.fill).alpha((style == null ? void 0 : style.fillOpacity) === void 0 ? DEFAULT_STYLE.fillOpacity : style.fillOpacity).toHex();
|
|
649
|
-
if (style.underlineStyle)
|
|
650
|
-
span.style.borderStyle = style.underlineStyle;
|
|
651
|
-
if (style.underlineColor)
|
|
652
|
-
span.style.borderColor = style.underlineColor;
|
|
653
|
-
if (style.underlineThickness)
|
|
654
|
-
span.style.borderBottomWidth = `${style.underlineThickness}px`;
|
|
655
|
-
if (style.underlineOffset)
|
|
656
|
-
span.style.paddingBottom = `${style.underlineOffset}px`;
|
|
657
|
-
highlightLayer.appendChild(span);
|
|
658
|
-
}
|
|
1134
|
+
}, Kn = () => {
|
|
1135
|
+
const { subscribe: t, set: e } = Ht([]);
|
|
1136
|
+
return {
|
|
1137
|
+
subscribe: t,
|
|
1138
|
+
set: e
|
|
1139
|
+
};
|
|
1140
|
+
}, Pn = (t, e, n, o) => {
|
|
1141
|
+
const { hover: i, selection: s, store: a, viewport: r } = t, l = /* @__PURE__ */ new Map();
|
|
1142
|
+
let d = [], g;
|
|
1143
|
+
const u = (b, x) => {
|
|
1144
|
+
l.has(b) ? l.get(b).push(x) : l.set(b, [x]);
|
|
1145
|
+
}, f = (b, x) => {
|
|
1146
|
+
const m = l.get(b);
|
|
1147
|
+
if (m) {
|
|
1148
|
+
const c = m.indexOf(x);
|
|
1149
|
+
c !== -1 && m.splice(c, 1);
|
|
1150
|
+
}
|
|
1151
|
+
}, A = (b, x, m) => {
|
|
1152
|
+
l.has(b) && setTimeout(() => {
|
|
1153
|
+
l.get(b).forEach((c) => {
|
|
1154
|
+
if (n) {
|
|
1155
|
+
const y = Array.isArray(x) ? x.map((S) => n.serialize(S)) : n.serialize(x), C = m ? m instanceof PointerEvent ? m : n.serialize(m) : void 0;
|
|
1156
|
+
c(y, C);
|
|
1157
|
+
} else
|
|
1158
|
+
c(x, m);
|
|
659
1159
|
});
|
|
1160
|
+
}, 1);
|
|
1161
|
+
};
|
|
1162
|
+
s.subscribe(({ selected: b }) => {
|
|
1163
|
+
if (!(d.length === 0 && b.length === 0)) {
|
|
1164
|
+
if (d.length === 0 && b.length > 0)
|
|
1165
|
+
d = b.map(({ id: x }) => a.getAnnotation(x));
|
|
1166
|
+
else if (d.length > 0 && b.length === 0)
|
|
1167
|
+
d.forEach((x) => {
|
|
1168
|
+
const m = a.getAnnotation(x.id);
|
|
1169
|
+
m && !Q(m, x) && A("updateAnnotation", m, x);
|
|
1170
|
+
}), d = [];
|
|
1171
|
+
else {
|
|
1172
|
+
const x = new Set(d.map((c) => c.id)), m = new Set(b.map(({ id: c }) => c));
|
|
1173
|
+
d.filter((c) => !m.has(c.id)).forEach((c) => {
|
|
1174
|
+
const y = a.getAnnotation(c.id);
|
|
1175
|
+
y && !Q(y, c) && A("updateAnnotation", y, c);
|
|
1176
|
+
}), d = [
|
|
1177
|
+
// Remove annotations that were deselected
|
|
1178
|
+
...d.filter((c) => m.has(c.id)),
|
|
1179
|
+
// Add editable annotations that were selected
|
|
1180
|
+
...b.filter(({ id: c }) => !x.has(c)).map(({ id: c }) => a.getAnnotation(c))
|
|
1181
|
+
];
|
|
1182
|
+
}
|
|
1183
|
+
A("selectionChanged", d);
|
|
1184
|
+
}
|
|
1185
|
+
}), i.subscribe((b) => {
|
|
1186
|
+
!g && b ? A("mouseEnterAnnotation", a.getAnnotation(b)) : g && !b ? A("mouseLeaveAnnotation", a.getAnnotation(g)) : g && b && (A("mouseLeaveAnnotation", a.getAnnotation(g)), A("mouseEnterAnnotation", a.getAnnotation(b))), g = b;
|
|
1187
|
+
}), r == null || r.subscribe((b) => A("viewportIntersect", b.map((x) => a.getAnnotation(x)))), a.observe((b) => {
|
|
1188
|
+
const { created: x, deleted: m } = b.changes;
|
|
1189
|
+
(x || []).forEach((c) => A("createAnnotation", c)), (m || []).forEach((c) => A("deleteAnnotation", c)), (b.changes.updated || []).filter((c) => [
|
|
1190
|
+
...c.bodiesCreated || [],
|
|
1191
|
+
...c.bodiesDeleted || [],
|
|
1192
|
+
...c.bodiesUpdated || []
|
|
1193
|
+
].length > 0).forEach(({ oldValue: c, newValue: y }) => {
|
|
1194
|
+
const C = d.find((S) => S.id === c.id) || c;
|
|
1195
|
+
d = d.map((S) => S.id === c.id ? y : S), A("updateAnnotation", y, C);
|
|
660
1196
|
});
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
1197
|
+
}, { origin: k.LOCAL }), a.observe((b) => {
|
|
1198
|
+
if (d) {
|
|
1199
|
+
const x = new Set(d.map((c) => c.id)), m = (b.changes.updated || []).filter(({ newValue: c }) => x.has(c.id)).map(({ newValue: c }) => c);
|
|
1200
|
+
m.length > 0 && (d = d.map((c) => m.find((C) => C.id === c.id) || c));
|
|
1201
|
+
}
|
|
1202
|
+
}, { origin: k.REMOTE });
|
|
1203
|
+
const p = (b) => (x) => {
|
|
1204
|
+
const { updated: m } = x;
|
|
1205
|
+
b ? (m || []).forEach((c) => A("updateAnnotation", c.oldValue, c.newValue)) : (m || []).forEach((c) => A("updateAnnotation", c.newValue, c.oldValue));
|
|
1206
|
+
};
|
|
1207
|
+
return e.on("undo", p(!0)), e.on("redo", p(!1)), { on: u, off: f, emit: A };
|
|
1208
|
+
}, Xn = (t) => (e) => e.reduce((n, o) => {
|
|
1209
|
+
const { parsed: i, error: s } = t.parse(o);
|
|
1210
|
+
return s ? {
|
|
1211
|
+
parsed: n.parsed,
|
|
1212
|
+
failed: [...n.failed, o]
|
|
1213
|
+
} : i ? {
|
|
1214
|
+
parsed: [...n.parsed, i],
|
|
1215
|
+
failed: n.failed
|
|
1216
|
+
} : {
|
|
1217
|
+
...n
|
|
1218
|
+
};
|
|
1219
|
+
}, { parsed: [], failed: [] }), $n = (t, e, n) => {
|
|
1220
|
+
const { store: o, selection: i } = t, s = (m) => {
|
|
1221
|
+
if (n) {
|
|
1222
|
+
const { parsed: c, error: y } = n.parse(m);
|
|
1223
|
+
c ? o.addAnnotation(c, k.REMOTE) : console.error(y);
|
|
1224
|
+
} else
|
|
1225
|
+
o.addAnnotation(It(m), k.REMOTE);
|
|
1226
|
+
}, a = () => i.clear(), r = () => o.clear(), l = (m) => {
|
|
1227
|
+
const c = o.getAnnotation(m);
|
|
1228
|
+
return n && c ? n.serialize(c) : c;
|
|
1229
|
+
}, d = () => n ? o.all().map(n.serialize) : o.all(), g = () => {
|
|
1230
|
+
var m;
|
|
1231
|
+
const c = (((m = i.selected) == null ? void 0 : m.map((y) => y.id)) || []).map((y) => o.getAnnotation(y)).filter(Boolean);
|
|
1232
|
+
return n ? c.map(n.serialize) : c;
|
|
1233
|
+
}, u = (m, c = !0) => fetch(m).then((y) => y.json()).then((y) => (A(y, c), y)), f = (m) => {
|
|
1234
|
+
if (typeof m == "string") {
|
|
1235
|
+
const c = o.getAnnotation(m);
|
|
1236
|
+
if (o.deleteAnnotation(m), c)
|
|
1237
|
+
return n ? n.serialize(c) : c;
|
|
1238
|
+
} else {
|
|
1239
|
+
const c = n ? n.parse(m).parsed : m;
|
|
1240
|
+
if (c)
|
|
1241
|
+
return o.deleteAnnotation(c), m;
|
|
1242
|
+
}
|
|
1243
|
+
}, A = (m, c = !0) => {
|
|
1244
|
+
if (n) {
|
|
1245
|
+
const y = n.parseAll || Xn(n), { parsed: C, failed: S } = y(m);
|
|
1246
|
+
S.length > 0 && console.warn(`Discarded ${S.length} invalid annotations`, S), o.bulkAddAnnotation(C, c, k.REMOTE);
|
|
1247
|
+
} else
|
|
1248
|
+
o.bulkAddAnnotation(m.map(It), c, k.REMOTE);
|
|
1249
|
+
}, p = (m, c) => {
|
|
1250
|
+
m ? i.setSelected(m, c) : i.clear();
|
|
1251
|
+
}, b = (m) => {
|
|
1252
|
+
i.clear(), i.setUserSelectAction(m);
|
|
1253
|
+
}, x = (m) => {
|
|
1254
|
+
if (n) {
|
|
1255
|
+
const c = n.parse(m).parsed, y = n.serialize(o.getAnnotation(c.id));
|
|
1256
|
+
return o.updateAnnotation(c), y;
|
|
1257
|
+
} else {
|
|
1258
|
+
const c = o.getAnnotation(m.id);
|
|
1259
|
+
return o.updateAnnotation(It(m)), c;
|
|
1260
|
+
}
|
|
671
1261
|
};
|
|
672
1262
|
return {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
1263
|
+
addAnnotation: s,
|
|
1264
|
+
cancelSelected: a,
|
|
1265
|
+
canRedo: e.canRedo,
|
|
1266
|
+
canUndo: e.canUndo,
|
|
1267
|
+
clearAnnotations: r,
|
|
1268
|
+
getAnnotationById: l,
|
|
1269
|
+
getAnnotations: d,
|
|
1270
|
+
getHistory: e.getHistory,
|
|
1271
|
+
getSelected: g,
|
|
1272
|
+
loadAnnotations: u,
|
|
1273
|
+
redo: e.redo,
|
|
1274
|
+
removeAnnotation: f,
|
|
1275
|
+
setAnnotations: A,
|
|
1276
|
+
setSelected: p,
|
|
1277
|
+
setUserSelectAction: b,
|
|
1278
|
+
undo: e.undo,
|
|
1279
|
+
updateAnnotation: x
|
|
1280
|
+
};
|
|
1281
|
+
}, Hn = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1282
|
+
let jn = (t) => crypto.getRandomValues(new Uint8Array(t)), zn = (t, e, n) => {
|
|
1283
|
+
let o = (2 << Math.log2(t.length - 1)) - 1, i = -~(1.6 * o * e / t.length);
|
|
1284
|
+
return (s = e) => {
|
|
1285
|
+
let a = "";
|
|
1286
|
+
for (; ; ) {
|
|
1287
|
+
let r = n(i), l = i | 0;
|
|
1288
|
+
for (; l--; )
|
|
1289
|
+
if (a += t[r[l] & o] || "", a.length >= s) return a;
|
|
1290
|
+
}
|
|
676
1291
|
};
|
|
1292
|
+
}, Fn = (t, e = 21) => zn(t, e | 0, jn), Wn = (t = 21) => {
|
|
1293
|
+
let e = "", n = crypto.getRandomValues(new Uint8Array(t |= 0));
|
|
1294
|
+
for (; t--; )
|
|
1295
|
+
e += Hn[n[t] & 63];
|
|
1296
|
+
return e;
|
|
677
1297
|
};
|
|
678
|
-
const
|
|
679
|
-
const
|
|
680
|
-
|
|
681
|
-
|
|
1298
|
+
const qn = () => ({ isGuest: !0, id: Fn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Gn = (t) => {
|
|
1299
|
+
const e = JSON.stringify(t);
|
|
1300
|
+
let n = 0;
|
|
1301
|
+
for (let o = 0, i = e.length; o < i; o++) {
|
|
1302
|
+
let s = e.charCodeAt(o);
|
|
1303
|
+
n = (n << 5) - n + s, n |= 0;
|
|
1304
|
+
}
|
|
1305
|
+
return `${n}`;
|
|
1306
|
+
}, xe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Qn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1307
|
+
const { id: o, type: i, purpose: s, value: a, created: r, modified: l, creator: d, ...g } = n;
|
|
1308
|
+
return {
|
|
1309
|
+
id: o || `temp-${Gn(n)}`,
|
|
1310
|
+
annotation: e,
|
|
1311
|
+
type: i,
|
|
1312
|
+
purpose: s,
|
|
1313
|
+
value: a,
|
|
1314
|
+
creator: xe(d),
|
|
1315
|
+
created: r ? new Date(r) : void 0,
|
|
1316
|
+
updated: l ? new Date(l) : void 0,
|
|
1317
|
+
...g
|
|
1318
|
+
};
|
|
1319
|
+
}), Jn = (t) => t.map((e) => {
|
|
1320
|
+
var n;
|
|
1321
|
+
const { annotation: o, created: i, updated: s, ...a } = e, r = {
|
|
1322
|
+
...a,
|
|
1323
|
+
created: i == null ? void 0 : i.toISOString(),
|
|
1324
|
+
modified: s == null ? void 0 : s.toISOString()
|
|
1325
|
+
};
|
|
1326
|
+
return (n = r.id) != null && n.startsWith("temp-") && delete r.id, r;
|
|
682
1327
|
});
|
|
683
|
-
|
|
684
|
-
const
|
|
1328
|
+
Wn();
|
|
1329
|
+
const No = (t, e) => ({
|
|
1330
|
+
parse: (n) => eo(n),
|
|
1331
|
+
serialize: (n) => no(n, t, e)
|
|
1332
|
+
}), Zn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, to = (t) => {
|
|
685
1333
|
const {
|
|
686
|
-
id:
|
|
687
|
-
creator,
|
|
688
|
-
created,
|
|
689
|
-
modified,
|
|
690
|
-
target
|
|
691
|
-
} =
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
updated: modified ? new Date(modified) : void 0,
|
|
700
|
-
annotation: annotationId,
|
|
1334
|
+
id: e,
|
|
1335
|
+
creator: n,
|
|
1336
|
+
created: o,
|
|
1337
|
+
modified: i,
|
|
1338
|
+
target: s
|
|
1339
|
+
} = t, a = Array.isArray(s) ? s : [s];
|
|
1340
|
+
if (a.length === 0)
|
|
1341
|
+
return { error: Error(`No targets found for annotation: ${t.id}`) };
|
|
1342
|
+
const r = {
|
|
1343
|
+
creator: xe(n),
|
|
1344
|
+
created: o ? new Date(o) : void 0,
|
|
1345
|
+
updated: i ? new Date(i) : void 0,
|
|
1346
|
+
annotation: e,
|
|
701
1347
|
selector: [],
|
|
702
1348
|
// @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
|
|
703
|
-
styleClass: "styleClass" in
|
|
1349
|
+
styleClass: "styleClass" in a[0] ? a[0].styleClass : void 0
|
|
704
1350
|
};
|
|
705
|
-
for (const
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
switch (w3cSelector.type) {
|
|
1351
|
+
for (const l of a) {
|
|
1352
|
+
const g = (Array.isArray(l.selector) ? l.selector : [l.selector]).reduce((u, f) => {
|
|
1353
|
+
switch (f.type) {
|
|
709
1354
|
case "TextQuoteSelector":
|
|
710
|
-
|
|
1355
|
+
u.quote = f.exact;
|
|
711
1356
|
break;
|
|
712
1357
|
case "TextPositionSelector":
|
|
713
|
-
|
|
714
|
-
s.end = w3cSelector.end;
|
|
1358
|
+
u.start = f.start, u.end = f.end;
|
|
715
1359
|
break;
|
|
716
1360
|
}
|
|
717
|
-
return
|
|
1361
|
+
return u;
|
|
718
1362
|
}, {});
|
|
719
|
-
if (
|
|
720
|
-
|
|
1363
|
+
if (Zn(g))
|
|
1364
|
+
"outdated" in l && l.outdated, r.selector.push(
|
|
721
1365
|
{
|
|
722
|
-
...
|
|
723
|
-
id:
|
|
1366
|
+
...g,
|
|
1367
|
+
id: l.id,
|
|
724
1368
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
725
|
-
scope:
|
|
1369
|
+
scope: l.scope
|
|
726
1370
|
}
|
|
727
1371
|
);
|
|
728
|
-
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
1372
|
+
else {
|
|
1373
|
+
const u = [
|
|
1374
|
+
g.start ? void 0 : "TextPositionSelector",
|
|
1375
|
+
g.quote ? void 0 : "TextQuoteSelector"
|
|
732
1376
|
].filter(Boolean);
|
|
733
|
-
return { error: Error(`Missing selector types: ${
|
|
1377
|
+
return { error: Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`) };
|
|
734
1378
|
}
|
|
735
1379
|
}
|
|
736
|
-
return { parsed };
|
|
737
|
-
}
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
} = annotation;
|
|
747
|
-
const bodies = parseW3CBodies(body, annotationId);
|
|
748
|
-
const target = parseW3CTextTargets(annotation);
|
|
749
|
-
const parseResult = "error" in target ? { error: target.error } : {
|
|
1380
|
+
return { parsed: r };
|
|
1381
|
+
}, eo = (t) => {
|
|
1382
|
+
const e = t.id || be(), {
|
|
1383
|
+
creator: n,
|
|
1384
|
+
created: o,
|
|
1385
|
+
modified: i,
|
|
1386
|
+
body: s,
|
|
1387
|
+
...a
|
|
1388
|
+
} = t, r = Qn(s, e), l = to(t);
|
|
1389
|
+
return "error" in l ? { error: l.error } : {
|
|
750
1390
|
parsed: {
|
|
751
|
-
...
|
|
752
|
-
id:
|
|
753
|
-
bodies,
|
|
754
|
-
target:
|
|
1391
|
+
...a,
|
|
1392
|
+
id: e,
|
|
1393
|
+
bodies: r,
|
|
1394
|
+
target: l.parsed
|
|
755
1395
|
}
|
|
756
1396
|
};
|
|
757
|
-
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
...targetRest
|
|
767
|
-
} = target;
|
|
768
|
-
const w3cTargets = selector.map((s) => {
|
|
769
|
-
const { id, quote, start, end, range } = s;
|
|
770
|
-
const { prefix, suffix } = getQuoteContext(range, container);
|
|
771
|
-
const w3cSelectors = [{
|
|
1397
|
+
}, no = (t, e, n) => {
|
|
1398
|
+
const { bodies: o, target: i, ...s } = t, {
|
|
1399
|
+
selector: a,
|
|
1400
|
+
creator: r,
|
|
1401
|
+
created: l,
|
|
1402
|
+
updated: d,
|
|
1403
|
+
...g
|
|
1404
|
+
} = i, u = a.map((f) => {
|
|
1405
|
+
const { id: A, quote: p, start: b, end: x, range: m } = f, { prefix: c, suffix: y } = Ue(m, n), C = [{
|
|
772
1406
|
type: "TextQuoteSelector",
|
|
773
|
-
exact:
|
|
774
|
-
prefix,
|
|
775
|
-
suffix
|
|
1407
|
+
exact: p,
|
|
1408
|
+
prefix: c,
|
|
1409
|
+
suffix: y
|
|
776
1410
|
}, {
|
|
777
1411
|
type: "TextPositionSelector",
|
|
778
|
-
start,
|
|
779
|
-
end
|
|
1412
|
+
start: b,
|
|
1413
|
+
end: x
|
|
780
1414
|
}];
|
|
781
1415
|
return {
|
|
782
|
-
...
|
|
783
|
-
id,
|
|
1416
|
+
...g,
|
|
1417
|
+
id: A,
|
|
1418
|
+
// @ts-expect-error: `outdated` is not part of the core `TextSelector` type
|
|
1419
|
+
outdated: "outdated" in f ? f.outdated : void 0,
|
|
784
1420
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
785
|
-
scope: "scope" in
|
|
786
|
-
source,
|
|
787
|
-
selector:
|
|
1421
|
+
scope: "scope" in f ? f.scope : void 0,
|
|
1422
|
+
source: e,
|
|
1423
|
+
selector: C
|
|
788
1424
|
};
|
|
789
1425
|
});
|
|
790
1426
|
return {
|
|
791
|
-
...
|
|
1427
|
+
...s,
|
|
792
1428
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
793
|
-
id:
|
|
1429
|
+
id: t.id,
|
|
794
1430
|
type: "Annotation",
|
|
795
|
-
body:
|
|
796
|
-
creator,
|
|
797
|
-
created:
|
|
798
|
-
modified:
|
|
799
|
-
target:
|
|
1431
|
+
body: Jn(t.bodies),
|
|
1432
|
+
creator: r,
|
|
1433
|
+
created: l == null ? void 0 : l.toISOString(),
|
|
1434
|
+
modified: d == null ? void 0 : d.toISOString(),
|
|
1435
|
+
target: u
|
|
800
1436
|
};
|
|
801
1437
|
};
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
1438
|
+
function ve(t, e, n = 0, o = t.length - 1, i = oo) {
|
|
1439
|
+
for (; o > n; ) {
|
|
1440
|
+
if (o - n > 600) {
|
|
1441
|
+
const l = o - n + 1, d = e - n + 1, g = Math.log(l), u = 0.5 * Math.exp(2 * g / 3), f = 0.5 * Math.sqrt(g * u * (l - u) / l) * (d - l / 2 < 0 ? -1 : 1), A = Math.max(n, Math.floor(e - d * u / l + f)), p = Math.min(o, Math.floor(e + (l - d) * u / l + f));
|
|
1442
|
+
ve(t, e, A, p, i);
|
|
1443
|
+
}
|
|
1444
|
+
const s = t[e];
|
|
1445
|
+
let a = n, r = o;
|
|
1446
|
+
for (ot(t, n, e), i(t[o], s) > 0 && ot(t, n, o); a < r; ) {
|
|
1447
|
+
for (ot(t, a, r), a++, r--; i(t[a], s) < 0; ) a++;
|
|
1448
|
+
for (; i(t[r], s) > 0; ) r--;
|
|
1449
|
+
}
|
|
1450
|
+
i(t[n], s) === 0 ? ot(t, n, r) : (r++, ot(t, r, o)), r <= e && (n = r + 1), e <= r && (o = r - 1);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
function ot(t, e, n) {
|
|
1454
|
+
const o = t[e];
|
|
1455
|
+
t[e] = t[n], t[n] = o;
|
|
1456
|
+
}
|
|
1457
|
+
function oo(t, e) {
|
|
1458
|
+
return t < e ? -1 : t > e ? 1 : 0;
|
|
1459
|
+
}
|
|
1460
|
+
class io {
|
|
1461
|
+
constructor(e = 9) {
|
|
1462
|
+
this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
|
|
1463
|
+
}
|
|
1464
|
+
all() {
|
|
1465
|
+
return this._all(this.data, []);
|
|
1466
|
+
}
|
|
1467
|
+
search(e) {
|
|
1468
|
+
let n = this.data;
|
|
1469
|
+
const o = [];
|
|
1470
|
+
if (!wt(e, n)) return o;
|
|
1471
|
+
const i = this.toBBox, s = [];
|
|
1472
|
+
for (; n; ) {
|
|
1473
|
+
for (let a = 0; a < n.children.length; a++) {
|
|
1474
|
+
const r = n.children[a], l = n.leaf ? i(r) : r;
|
|
1475
|
+
wt(e, l) && (n.leaf ? o.push(r) : Ut(e, l) ? this._all(r, o) : s.push(r));
|
|
1476
|
+
}
|
|
1477
|
+
n = s.pop();
|
|
1478
|
+
}
|
|
1479
|
+
return o;
|
|
1480
|
+
}
|
|
1481
|
+
collides(e) {
|
|
1482
|
+
let n = this.data;
|
|
1483
|
+
if (!wt(e, n)) return !1;
|
|
1484
|
+
const o = [];
|
|
1485
|
+
for (; n; ) {
|
|
1486
|
+
for (let i = 0; i < n.children.length; i++) {
|
|
1487
|
+
const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
|
|
1488
|
+
if (wt(e, a)) {
|
|
1489
|
+
if (n.leaf || Ut(e, a)) return !0;
|
|
1490
|
+
o.push(s);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
n = o.pop();
|
|
1494
|
+
}
|
|
1495
|
+
return !1;
|
|
1496
|
+
}
|
|
1497
|
+
load(e) {
|
|
1498
|
+
if (!(e && e.length)) return this;
|
|
1499
|
+
if (e.length < this._minEntries) {
|
|
1500
|
+
for (let o = 0; o < e.length; o++)
|
|
1501
|
+
this.insert(e[o]);
|
|
1502
|
+
return this;
|
|
1503
|
+
}
|
|
1504
|
+
let n = this._build(e.slice(), 0, e.length - 1, 0);
|
|
1505
|
+
if (!this.data.children.length)
|
|
1506
|
+
this.data = n;
|
|
1507
|
+
else if (this.data.height === n.height)
|
|
1508
|
+
this._splitRoot(this.data, n);
|
|
1509
|
+
else {
|
|
1510
|
+
if (this.data.height < n.height) {
|
|
1511
|
+
const o = this.data;
|
|
1512
|
+
this.data = n, n = o;
|
|
1513
|
+
}
|
|
1514
|
+
this._insert(n, this.data.height - n.height - 1, !0);
|
|
1515
|
+
}
|
|
1516
|
+
return this;
|
|
1517
|
+
}
|
|
1518
|
+
insert(e) {
|
|
1519
|
+
return e && this._insert(e, this.data.height - 1), this;
|
|
1520
|
+
}
|
|
1521
|
+
clear() {
|
|
1522
|
+
return this.data = tt([]), this;
|
|
1523
|
+
}
|
|
1524
|
+
remove(e, n) {
|
|
1525
|
+
if (!e) return this;
|
|
1526
|
+
let o = this.data;
|
|
1527
|
+
const i = this.toBBox(e), s = [], a = [];
|
|
1528
|
+
let r, l, d;
|
|
1529
|
+
for (; o || s.length; ) {
|
|
1530
|
+
if (o || (o = s.pop(), l = s[s.length - 1], r = a.pop(), d = !0), o.leaf) {
|
|
1531
|
+
const g = so(e, o.children, n);
|
|
1532
|
+
if (g !== -1)
|
|
1533
|
+
return o.children.splice(g, 1), s.push(o), this._condense(s), this;
|
|
1534
|
+
}
|
|
1535
|
+
!d && !o.leaf && Ut(o, i) ? (s.push(o), a.push(r), r = 0, l = o, o = o.children[0]) : l ? (r++, o = l.children[r], d = !1) : o = null;
|
|
1536
|
+
}
|
|
1537
|
+
return this;
|
|
1538
|
+
}
|
|
1539
|
+
toBBox(e) {
|
|
1540
|
+
return e;
|
|
1541
|
+
}
|
|
1542
|
+
compareMinX(e, n) {
|
|
1543
|
+
return e.minX - n.minX;
|
|
1544
|
+
}
|
|
1545
|
+
compareMinY(e, n) {
|
|
1546
|
+
return e.minY - n.minY;
|
|
1547
|
+
}
|
|
1548
|
+
toJSON() {
|
|
1549
|
+
return this.data;
|
|
1550
|
+
}
|
|
1551
|
+
fromJSON(e) {
|
|
1552
|
+
return this.data = e, this;
|
|
1553
|
+
}
|
|
1554
|
+
_all(e, n) {
|
|
1555
|
+
const o = [];
|
|
1556
|
+
for (; e; )
|
|
1557
|
+
e.leaf ? n.push(...e.children) : o.push(...e.children), e = o.pop();
|
|
1558
|
+
return n;
|
|
1559
|
+
}
|
|
1560
|
+
_build(e, n, o, i) {
|
|
1561
|
+
const s = o - n + 1;
|
|
1562
|
+
let a = this._maxEntries, r;
|
|
1563
|
+
if (s <= a)
|
|
1564
|
+
return r = tt(e.slice(n, o + 1)), Z(r, this.toBBox), r;
|
|
1565
|
+
i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = tt([]), r.leaf = !1, r.height = i;
|
|
1566
|
+
const l = Math.ceil(s / a), d = l * Math.ceil(Math.sqrt(a));
|
|
1567
|
+
re(e, n, o, d, this.compareMinX);
|
|
1568
|
+
for (let g = n; g <= o; g += d) {
|
|
1569
|
+
const u = Math.min(g + d - 1, o);
|
|
1570
|
+
re(e, g, u, l, this.compareMinY);
|
|
1571
|
+
for (let f = g; f <= u; f += l) {
|
|
1572
|
+
const A = Math.min(f + l - 1, u);
|
|
1573
|
+
r.children.push(this._build(e, f, A, i - 1));
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
return Z(r, this.toBBox), r;
|
|
1577
|
+
}
|
|
1578
|
+
_chooseSubtree(e, n, o, i) {
|
|
1579
|
+
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1580
|
+
let s = 1 / 0, a = 1 / 0, r;
|
|
1581
|
+
for (let l = 0; l < n.children.length; l++) {
|
|
1582
|
+
const d = n.children[l], g = _t(d), u = co(e, d) - g;
|
|
1583
|
+
u < a ? (a = u, s = g < s ? g : s, r = d) : u === a && g < s && (s = g, r = d);
|
|
1584
|
+
}
|
|
1585
|
+
n = r || n.children[0];
|
|
1586
|
+
}
|
|
1587
|
+
return n;
|
|
1588
|
+
}
|
|
1589
|
+
_insert(e, n, o) {
|
|
1590
|
+
const i = o ? e : this.toBBox(e), s = [], a = this._chooseSubtree(i, this.data, n, s);
|
|
1591
|
+
for (a.children.push(e), at(a, i); n >= 0 && s[n].children.length > this._maxEntries; )
|
|
1592
|
+
this._split(s, n), n--;
|
|
1593
|
+
this._adjustParentBBoxes(i, s, n);
|
|
1594
|
+
}
|
|
1595
|
+
// split overflowed node into two
|
|
1596
|
+
_split(e, n) {
|
|
1597
|
+
const o = e[n], i = o.children.length, s = this._minEntries;
|
|
1598
|
+
this._chooseSplitAxis(o, s, i);
|
|
1599
|
+
const a = this._chooseSplitIndex(o, s, i), r = tt(o.children.splice(a, o.children.length - a));
|
|
1600
|
+
r.height = o.height, r.leaf = o.leaf, Z(o, this.toBBox), Z(r, this.toBBox), n ? e[n - 1].children.push(r) : this._splitRoot(o, r);
|
|
1601
|
+
}
|
|
1602
|
+
_splitRoot(e, n) {
|
|
1603
|
+
this.data = tt([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, Z(this.data, this.toBBox);
|
|
1604
|
+
}
|
|
1605
|
+
_chooseSplitIndex(e, n, o) {
|
|
1606
|
+
let i, s = 1 / 0, a = 1 / 0;
|
|
1607
|
+
for (let r = n; r <= o - n; r++) {
|
|
1608
|
+
const l = rt(e, 0, r, this.toBBox), d = rt(e, r, o, this.toBBox), g = lo(l, d), u = _t(l) + _t(d);
|
|
1609
|
+
g < s ? (s = g, i = r, a = u < a ? u : a) : g === s && u < a && (a = u, i = r);
|
|
1610
|
+
}
|
|
1611
|
+
return i || o - n;
|
|
1612
|
+
}
|
|
1613
|
+
// sorts node children by the best axis for split
|
|
1614
|
+
_chooseSplitAxis(e, n, o) {
|
|
1615
|
+
const i = e.leaf ? this.compareMinX : ro, s = e.leaf ? this.compareMinY : ao, a = this._allDistMargin(e, n, o, i), r = this._allDistMargin(e, n, o, s);
|
|
1616
|
+
a < r && e.children.sort(i);
|
|
1617
|
+
}
|
|
1618
|
+
// total margin of all possible split distributions where each node is at least m full
|
|
1619
|
+
_allDistMargin(e, n, o, i) {
|
|
1620
|
+
e.children.sort(i);
|
|
1621
|
+
const s = this.toBBox, a = rt(e, 0, n, s), r = rt(e, o - n, o, s);
|
|
1622
|
+
let l = bt(a) + bt(r);
|
|
1623
|
+
for (let d = n; d < o - n; d++) {
|
|
1624
|
+
const g = e.children[d];
|
|
1625
|
+
at(a, e.leaf ? s(g) : g), l += bt(a);
|
|
1626
|
+
}
|
|
1627
|
+
for (let d = o - n - 1; d >= n; d--) {
|
|
1628
|
+
const g = e.children[d];
|
|
1629
|
+
at(r, e.leaf ? s(g) : g), l += bt(r);
|
|
1630
|
+
}
|
|
1631
|
+
return l;
|
|
1632
|
+
}
|
|
1633
|
+
_adjustParentBBoxes(e, n, o) {
|
|
1634
|
+
for (let i = o; i >= 0; i--)
|
|
1635
|
+
at(n[i], e);
|
|
1636
|
+
}
|
|
1637
|
+
_condense(e) {
|
|
1638
|
+
for (let n = e.length - 1, o; n >= 0; n--)
|
|
1639
|
+
e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : Z(e[n], this.toBBox);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
function so(t, e, n) {
|
|
1643
|
+
if (!n) return e.indexOf(t);
|
|
1644
|
+
for (let o = 0; o < e.length; o++)
|
|
1645
|
+
if (n(t, e[o])) return o;
|
|
1646
|
+
return -1;
|
|
1647
|
+
}
|
|
1648
|
+
function Z(t, e) {
|
|
1649
|
+
rt(t, 0, t.children.length, e, t);
|
|
1650
|
+
}
|
|
1651
|
+
function rt(t, e, n, o, i) {
|
|
1652
|
+
i || (i = tt(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
|
|
1653
|
+
for (let s = e; s < n; s++) {
|
|
1654
|
+
const a = t.children[s];
|
|
1655
|
+
at(i, t.leaf ? o(a) : a);
|
|
1656
|
+
}
|
|
1657
|
+
return i;
|
|
1658
|
+
}
|
|
1659
|
+
function at(t, e) {
|
|
1660
|
+
return t.minX = Math.min(t.minX, e.minX), t.minY = Math.min(t.minY, e.minY), t.maxX = Math.max(t.maxX, e.maxX), t.maxY = Math.max(t.maxY, e.maxY), t;
|
|
1661
|
+
}
|
|
1662
|
+
function ro(t, e) {
|
|
1663
|
+
return t.minX - e.minX;
|
|
1664
|
+
}
|
|
1665
|
+
function ao(t, e) {
|
|
1666
|
+
return t.minY - e.minY;
|
|
1667
|
+
}
|
|
1668
|
+
function _t(t) {
|
|
1669
|
+
return (t.maxX - t.minX) * (t.maxY - t.minY);
|
|
1670
|
+
}
|
|
1671
|
+
function bt(t) {
|
|
1672
|
+
return t.maxX - t.minX + (t.maxY - t.minY);
|
|
1673
|
+
}
|
|
1674
|
+
function co(t, e) {
|
|
1675
|
+
return (Math.max(e.maxX, t.maxX) - Math.min(e.minX, t.minX)) * (Math.max(e.maxY, t.maxY) - Math.min(e.minY, t.minY));
|
|
1676
|
+
}
|
|
1677
|
+
function lo(t, e) {
|
|
1678
|
+
const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), s = Math.min(t.maxY, e.maxY);
|
|
1679
|
+
return Math.max(0, i - n) * Math.max(0, s - o);
|
|
1680
|
+
}
|
|
1681
|
+
function Ut(t, e) {
|
|
1682
|
+
return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
|
|
1683
|
+
}
|
|
1684
|
+
function wt(t, e) {
|
|
1685
|
+
return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
|
|
1686
|
+
}
|
|
1687
|
+
function tt(t) {
|
|
1688
|
+
return {
|
|
1689
|
+
children: t,
|
|
1690
|
+
height: 1,
|
|
1691
|
+
leaf: !0,
|
|
1692
|
+
minX: 1 / 0,
|
|
1693
|
+
minY: 1 / 0,
|
|
1694
|
+
maxX: -1 / 0,
|
|
1695
|
+
maxY: -1 / 0
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
function re(t, e, n, o, i) {
|
|
1699
|
+
const s = [e, n];
|
|
1700
|
+
for (; s.length; ) {
|
|
1701
|
+
if (n = s.pop(), e = s.pop(), n - e <= o) continue;
|
|
1702
|
+
const a = e + Math.ceil((n - e) / o / 2) * o;
|
|
1703
|
+
ve(t, a, e, n, i), s.push(e, a, a, n);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
let uo = () => ({
|
|
1707
|
+
emit(t, ...e) {
|
|
1708
|
+
for (let n = this.events[t] || [], o = 0, i = n.length; o < i; o++)
|
|
1709
|
+
n[o](...e);
|
|
1710
|
+
},
|
|
1711
|
+
events: {},
|
|
1712
|
+
on(t, e) {
|
|
1713
|
+
var n;
|
|
1714
|
+
return ((n = this.events)[t] || (n[t] = [])).push(e), () => {
|
|
1715
|
+
var o;
|
|
1716
|
+
this.events[t] = (o = this.events[t]) == null ? void 0 : o.filter((i) => e !== i);
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
const fo = (t, e) => {
|
|
1721
|
+
const n = new io(), o = /* @__PURE__ */ new Map(), i = uo(), s = (y, C) => {
|
|
1722
|
+
const S = y.selector.flatMap((B) => {
|
|
1723
|
+
const T = F([B]) ? B.range : fe(B, e).range;
|
|
1724
|
+
return Array.from(T.getClientRects());
|
|
1725
|
+
}), L = Pe(S).map((B) => je(B, C));
|
|
1726
|
+
return L.map((B) => {
|
|
1727
|
+
const { x: T, y: R, width: w, height: v } = B;
|
|
814
1728
|
return {
|
|
815
|
-
minX:
|
|
816
|
-
minY:
|
|
817
|
-
maxX:
|
|
818
|
-
maxY:
|
|
1729
|
+
minX: T,
|
|
1730
|
+
minY: R,
|
|
1731
|
+
maxX: T + w,
|
|
1732
|
+
maxY: R + v,
|
|
819
1733
|
annotation: {
|
|
820
|
-
id:
|
|
821
|
-
rects:
|
|
1734
|
+
id: y.annotation,
|
|
1735
|
+
rects: L
|
|
822
1736
|
}
|
|
823
1737
|
};
|
|
824
1738
|
});
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
rects.forEach((rect) => tree.remove(rect));
|
|
841
|
-
index.delete(target.annotation);
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
const update = (target) => {
|
|
845
|
-
remove(target);
|
|
846
|
-
insert(target);
|
|
847
|
-
};
|
|
848
|
-
const set = (targets, replace = true) => {
|
|
849
|
-
if (replace)
|
|
850
|
-
clear();
|
|
851
|
-
const offset = container.getBoundingClientRect();
|
|
852
|
-
const rectsByTarget = targets.map((target) => ({ target, rects: toItems(target, offset) }));
|
|
853
|
-
rectsByTarget.forEach(({ target, rects }) => {
|
|
854
|
-
if (rects.length > 0)
|
|
855
|
-
index.set(target.annotation, rects);
|
|
856
|
-
});
|
|
857
|
-
const allRects = rectsByTarget.flatMap(({ rects }) => rects);
|
|
858
|
-
tree.load(allRects);
|
|
859
|
-
};
|
|
860
|
-
const getAt = (x, y, all2 = false) => {
|
|
861
|
-
const hits = tree.search({
|
|
862
|
-
minX: x,
|
|
863
|
-
minY: y,
|
|
864
|
-
maxX: x,
|
|
865
|
-
maxY: y
|
|
1739
|
+
}, a = () => [...o.values()], r = () => {
|
|
1740
|
+
n.clear(), o.clear();
|
|
1741
|
+
}, l = (y) => {
|
|
1742
|
+
const C = s(y, e.getBoundingClientRect());
|
|
1743
|
+
C.length !== 0 && (C.forEach((S) => n.insert(S)), o.set(y.annotation, C));
|
|
1744
|
+
}, d = (y) => {
|
|
1745
|
+
const C = o.get(y.annotation);
|
|
1746
|
+
C && (C.forEach((S) => n.remove(S)), o.delete(y.annotation));
|
|
1747
|
+
}, g = (y) => {
|
|
1748
|
+
d(y), l(y);
|
|
1749
|
+
}, u = (y, C = !0) => {
|
|
1750
|
+
C && r();
|
|
1751
|
+
const S = e.getBoundingClientRect(), L = y.map((T) => ({ target: T, rects: s(T, S) }));
|
|
1752
|
+
L.forEach(({ target: T, rects: R }) => {
|
|
1753
|
+
R.length > 0 && o.set(T.annotation, R);
|
|
866
1754
|
});
|
|
867
|
-
const
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
let right =
|
|
882
|
-
let
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
left = Math.min(left, rect.left);
|
|
886
|
-
top = Math.min(top, rect.top);
|
|
887
|
-
right = Math.max(right, rect.right);
|
|
888
|
-
bottom = Math.max(bottom, rect.bottom);
|
|
889
|
-
}
|
|
890
|
-
return new DOMRect(left, top, right - left, bottom - top);
|
|
891
|
-
};
|
|
892
|
-
const getAnnotationRects = (id) => {
|
|
893
|
-
const indexed = index.get(id);
|
|
894
|
-
if (indexed) {
|
|
895
|
-
return indexed[0].annotation.rects;
|
|
896
|
-
} else {
|
|
897
|
-
return [];
|
|
1755
|
+
const B = L.flatMap(({ rects: T }) => T);
|
|
1756
|
+
n.load(B);
|
|
1757
|
+
}, f = (y, C, S = !1) => {
|
|
1758
|
+
const L = n.search({
|
|
1759
|
+
minX: y,
|
|
1760
|
+
minY: C,
|
|
1761
|
+
maxX: y,
|
|
1762
|
+
maxY: C
|
|
1763
|
+
}), B = (T) => T.annotation.rects.reduce((R, w) => R + w.width * w.height, 0);
|
|
1764
|
+
return L.length > 0 ? (L.sort((T, R) => B(T) - B(R)), S ? L.map((T) => T.annotation.id) : [L[0].annotation.id]) : [];
|
|
1765
|
+
}, A = (y) => {
|
|
1766
|
+
const C = p(y);
|
|
1767
|
+
if (C.length === 0)
|
|
1768
|
+
return;
|
|
1769
|
+
let S = C[0].left, L = C[0].top, B = C[0].right, T = C[0].bottom;
|
|
1770
|
+
for (let R = 1; R < C.length; R++) {
|
|
1771
|
+
const w = C[R];
|
|
1772
|
+
S = Math.min(S, w.left), L = Math.min(L, w.top), B = Math.max(B, w.right), T = Math.max(T, w.bottom);
|
|
898
1773
|
}
|
|
1774
|
+
return new DOMRect(S, L, B - S, T - L);
|
|
1775
|
+
}, p = (y) => {
|
|
1776
|
+
const C = o.get(y);
|
|
1777
|
+
return C ? C[0].annotation.rects : [];
|
|
899
1778
|
};
|
|
900
|
-
const getIntersecting = (minX, minY, maxX, maxY) => {
|
|
901
|
-
const rects = tree.search({ minX, minY, maxX, maxY });
|
|
902
|
-
const annotationIds = new Set(rects.map((rect) => rect.annotation.id));
|
|
903
|
-
return Array.from(annotationIds).map((annotationId) => ({
|
|
904
|
-
annotation: store.getAnnotation(annotationId),
|
|
905
|
-
rects: getAnnotationRects(annotationId)
|
|
906
|
-
})).filter((t) => Boolean(t.annotation));
|
|
907
|
-
};
|
|
908
|
-
const size = () => tree.all().length;
|
|
909
|
-
const recalculate = () => {
|
|
910
|
-
set(store.all().map((a) => a.target), true);
|
|
911
|
-
emitter.emit("recalculate");
|
|
912
|
-
};
|
|
913
|
-
const on = (event, callback) => emitter.on(event, callback);
|
|
914
1779
|
return {
|
|
915
|
-
all,
|
|
916
|
-
clear,
|
|
917
|
-
getAt,
|
|
918
|
-
getAnnotationBounds,
|
|
919
|
-
getAnnotationRects,
|
|
920
|
-
getIntersecting,
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
const
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
const
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
const updateTarget = (target, origin = Origin.LOCAL) => {
|
|
961
|
-
const revived = reviveTarget(target, container);
|
|
962
|
-
store.updateTarget(revived, origin);
|
|
963
|
-
};
|
|
964
|
-
const bulkUpdateTargets = (targets, origin = Origin.LOCAL) => {
|
|
965
|
-
const revived = targets.map((t) => reviveTarget(t, container));
|
|
966
|
-
store.bulkUpdateTargets(revived, origin);
|
|
967
|
-
};
|
|
968
|
-
function getAt(x, y, all, filter) {
|
|
969
|
-
const getAll = all || Boolean(filter);
|
|
970
|
-
const annotations = tree.getAt(x, y, getAll).map((id) => store.getAnnotation(id));
|
|
971
|
-
const filtered = filter ? annotations.filter(filter) : annotations;
|
|
972
|
-
if (filtered.length === 0)
|
|
973
|
-
return void 0;
|
|
974
|
-
return all ? filtered : filtered[0];
|
|
1780
|
+
all: a,
|
|
1781
|
+
clear: r,
|
|
1782
|
+
getAt: f,
|
|
1783
|
+
getAnnotationBounds: A,
|
|
1784
|
+
getAnnotationRects: p,
|
|
1785
|
+
getIntersecting: (y, C, S, L) => {
|
|
1786
|
+
const B = n.search({ minX: y, minY: C, maxX: S, maxY: L }), T = new Set(B.map((R) => R.annotation.id));
|
|
1787
|
+
return Array.from(T).map((R) => ({
|
|
1788
|
+
annotation: t.getAnnotation(R),
|
|
1789
|
+
rects: p(R)
|
|
1790
|
+
})).filter((R) => !!R.annotation);
|
|
1791
|
+
},
|
|
1792
|
+
insert: l,
|
|
1793
|
+
recalculate: () => {
|
|
1794
|
+
u(t.all().map((y) => y.target), !0), i.emit("recalculate");
|
|
1795
|
+
},
|
|
1796
|
+
remove: d,
|
|
1797
|
+
set: u,
|
|
1798
|
+
size: () => n.all().length,
|
|
1799
|
+
update: g,
|
|
1800
|
+
on: (y, C) => i.on(y, C)
|
|
1801
|
+
};
|
|
1802
|
+
}, ho = (t, e) => {
|
|
1803
|
+
const n = Un(), o = fo(n, t), i = Sn(n, e.userSelectAction, e.adapter), s = vn(n), a = Kn(), r = (c, y = k.LOCAL) => {
|
|
1804
|
+
const C = Ct(c, t), S = F(C.target.selector);
|
|
1805
|
+
return S && n.addAnnotation(C, y), S;
|
|
1806
|
+
}, l = (c, y = !0, C = k.LOCAL) => {
|
|
1807
|
+
const S = c.map((B) => Ct(B, t)), L = S.filter((B) => !F(B.target.selector));
|
|
1808
|
+
return n.bulkAddAnnotation(S, y, C), L;
|
|
1809
|
+
}, d = (c, y = k.LOCAL) => {
|
|
1810
|
+
const C = c.map((L) => Ct(L, t)), S = C.filter((L) => !F(L.target.selector));
|
|
1811
|
+
return C.forEach((L) => {
|
|
1812
|
+
n.getAnnotation(L.id) ? n.updateAnnotation(L, y) : n.addAnnotation(L, y);
|
|
1813
|
+
}), S;
|
|
1814
|
+
}, g = (c, y = k.LOCAL) => {
|
|
1815
|
+
const C = vt(c, t);
|
|
1816
|
+
n.updateTarget(C, y);
|
|
1817
|
+
}, u = (c, y = k.LOCAL) => {
|
|
1818
|
+
const C = c.map((S) => vt(S, t));
|
|
1819
|
+
n.bulkUpdateTargets(C, y);
|
|
1820
|
+
};
|
|
1821
|
+
function f(c, y, C, S) {
|
|
1822
|
+
const L = C || !!S, B = o.getAt(c, y, L).map((R) => n.getAnnotation(R)), T = S ? B.filter(S) : B;
|
|
1823
|
+
if (T.length !== 0)
|
|
1824
|
+
return C ? T : T[0];
|
|
975
1825
|
}
|
|
976
|
-
const getAnnotationBounds = (
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
const getAnnotationRects = (id) => tree.getAnnotationRects(id);
|
|
982
|
-
const recalculatePositions = () => tree.recalculate();
|
|
983
|
-
const onRecalculatePositions = (callback) => tree.on("recalculate", callback);
|
|
984
|
-
store.observe(({ changes }) => {
|
|
985
|
-
const deleted = (changes.deleted || []).filter((a) => isRevived(a.target.selector));
|
|
986
|
-
const created = (changes.created || []).filter((a) => isRevived(a.target.selector));
|
|
987
|
-
const updated = (changes.updated || []).filter((u) => isRevived(u.newValue.target.selector));
|
|
988
|
-
if ((deleted == null ? void 0 : deleted.length) > 0)
|
|
989
|
-
deleted.forEach((a) => tree.remove(a.target));
|
|
990
|
-
if (created.length > 0)
|
|
991
|
-
tree.set(created.map((a) => a.target), false);
|
|
992
|
-
if ((updated == null ? void 0 : updated.length) > 0)
|
|
993
|
-
updated.forEach(({ newValue }) => tree.update(newValue.target));
|
|
994
|
-
});
|
|
995
|
-
return {
|
|
1826
|
+
const A = (c) => o.getAnnotationRects(c).length > 0 ? o.getAnnotationBounds(c) : void 0, p = (c, y, C, S) => o.getIntersecting(c, y, C, S), b = (c) => o.getAnnotationRects(c), x = () => o.recalculate(), m = (c) => o.on("recalculate", c);
|
|
1827
|
+
return n.observe(({ changes: c }) => {
|
|
1828
|
+
const y = (c.deleted || []).filter((L) => F(L.target.selector)), C = (c.created || []).filter((L) => F(L.target.selector)), S = (c.updated || []).filter((L) => F(L.newValue.target.selector));
|
|
1829
|
+
(y == null ? void 0 : y.length) > 0 && y.forEach((L) => o.remove(L.target)), C.length > 0 && o.set(C.map((L) => L.target), !1), (S == null ? void 0 : S.length) > 0 && S.forEach(({ newValue: L }) => o.update(L.target));
|
|
1830
|
+
}), {
|
|
996
1831
|
store: {
|
|
997
|
-
...
|
|
998
|
-
addAnnotation,
|
|
999
|
-
bulkAddAnnotation,
|
|
1000
|
-
bulkUpdateTargets,
|
|
1001
|
-
bulkUpsertAnnotations,
|
|
1002
|
-
getAnnotationBounds,
|
|
1003
|
-
getAnnotationRects,
|
|
1004
|
-
getIntersecting,
|
|
1005
|
-
getAt,
|
|
1006
|
-
recalculatePositions,
|
|
1007
|
-
onRecalculatePositions,
|
|
1008
|
-
updateTarget
|
|
1832
|
+
...n,
|
|
1833
|
+
addAnnotation: r,
|
|
1834
|
+
bulkAddAnnotation: l,
|
|
1835
|
+
bulkUpdateTargets: u,
|
|
1836
|
+
bulkUpsertAnnotations: d,
|
|
1837
|
+
getAnnotationBounds: A,
|
|
1838
|
+
getAnnotationRects: b,
|
|
1839
|
+
getIntersecting: p,
|
|
1840
|
+
getAt: f,
|
|
1841
|
+
recalculatePositions: x,
|
|
1842
|
+
onRecalculatePositions: m,
|
|
1843
|
+
updateTarget: g
|
|
1844
|
+
},
|
|
1845
|
+
selection: i,
|
|
1846
|
+
hover: s,
|
|
1847
|
+
viewport: a
|
|
1848
|
+
};
|
|
1849
|
+
}, po = () => {
|
|
1850
|
+
const t = document.createElement("canvas");
|
|
1851
|
+
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
|
|
1852
|
+
const e = t.getContext("2d");
|
|
1853
|
+
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
1854
|
+
}, go = (t, e = {}) => {
|
|
1855
|
+
const n = po(), o = n.getContext("2d");
|
|
1856
|
+
document.body.appendChild(n);
|
|
1857
|
+
const i = /* @__PURE__ */ new Map(), s = (g) => Array.from(i.entries()).filter(([u, f]) => f.presenceKey === g.presenceKey).map(([u, f]) => u);
|
|
1858
|
+
return t.on("selectionChange", (g, u) => {
|
|
1859
|
+
s(g).forEach((A) => i.delete(A)), u && u.forEach((A) => i.set(A, g));
|
|
1860
|
+
}), {
|
|
1861
|
+
clear: () => {
|
|
1862
|
+
const { width: g, height: u } = n;
|
|
1863
|
+
o.clearRect(-0.5, -0.5, g + 1, u + 1);
|
|
1864
|
+
},
|
|
1865
|
+
destroy: () => {
|
|
1866
|
+
n.remove();
|
|
1867
|
+
},
|
|
1868
|
+
paint: (g, u, f) => {
|
|
1869
|
+
e.font && (o.font = e.font);
|
|
1870
|
+
const A = i.get(g.annotation.id);
|
|
1871
|
+
if (A) {
|
|
1872
|
+
const { height: p } = g.rects[0], b = g.rects[0].x + u.left, x = g.rects[0].y + u.top;
|
|
1873
|
+
o.fillStyle = A.appearance.color, o.fillRect(b - 2, x - 2.5, 2, p + 5);
|
|
1874
|
+
const m = o.measureText(A.appearance.label), c = m.width + 6, y = m.actualBoundingBoxAscent + m.actualBoundingBoxDescent + 8, C = m.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1875
|
+
return o.fillRect(b - 2, x - 2.5 - y, c, y), o.fillStyle = "#fff", o.fillText(A.appearance.label, b + 1, x - C), {
|
|
1876
|
+
fill: A.appearance.color,
|
|
1877
|
+
fillOpacity: f ? 0.45 : 0.18
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1009
1880
|
},
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1881
|
+
reset: () => {
|
|
1882
|
+
n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
|
|
1883
|
+
const g = n.getContext("2d");
|
|
1884
|
+
g.scale(2, 2), g.translate(0.5, 0.5);
|
|
1885
|
+
}
|
|
1013
1886
|
};
|
|
1014
|
-
};
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1887
|
+
}, Dt = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
|
|
1888
|
+
function Vt(t, e, n, o) {
|
|
1889
|
+
t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
|
|
1890
|
+
}
|
|
1891
|
+
function it(t, e, n, o) {
|
|
1892
|
+
t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
|
|
1893
|
+
}
|
|
1894
|
+
function Ee(t, e) {
|
|
1895
|
+
const n = e.slice(0, e.length - 1);
|
|
1896
|
+
for (let o = 0; o < n.length; o++) n[o] = t[n[o].toLowerCase()];
|
|
1897
|
+
return n;
|
|
1898
|
+
}
|
|
1899
|
+
function Se(t) {
|
|
1900
|
+
typeof t != "string" && (t = ""), t = t.replace(/\s/g, "");
|
|
1901
|
+
const e = t.split(",");
|
|
1902
|
+
let n = e.lastIndexOf("");
|
|
1903
|
+
for (; n >= 0; )
|
|
1904
|
+
e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
|
|
1905
|
+
return e;
|
|
1906
|
+
}
|
|
1907
|
+
function mo(t, e) {
|
|
1908
|
+
const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
|
|
1909
|
+
let i = !0;
|
|
1910
|
+
for (let s = 0; s < n.length; s++)
|
|
1911
|
+
o.indexOf(n[s]) === -1 && (i = !1);
|
|
1912
|
+
return i;
|
|
1913
|
+
}
|
|
1914
|
+
const dt = {
|
|
1915
|
+
backspace: 8,
|
|
1916
|
+
"⌫": 8,
|
|
1917
|
+
tab: 9,
|
|
1918
|
+
clear: 12,
|
|
1919
|
+
enter: 13,
|
|
1920
|
+
"↩": 13,
|
|
1921
|
+
return: 13,
|
|
1922
|
+
esc: 27,
|
|
1923
|
+
escape: 27,
|
|
1924
|
+
space: 32,
|
|
1925
|
+
left: 37,
|
|
1926
|
+
up: 38,
|
|
1927
|
+
right: 39,
|
|
1928
|
+
down: 40,
|
|
1929
|
+
del: 46,
|
|
1930
|
+
delete: 46,
|
|
1931
|
+
ins: 45,
|
|
1932
|
+
insert: 45,
|
|
1933
|
+
home: 36,
|
|
1934
|
+
end: 35,
|
|
1935
|
+
pageup: 33,
|
|
1936
|
+
pagedown: 34,
|
|
1937
|
+
capslock: 20,
|
|
1938
|
+
num_0: 96,
|
|
1939
|
+
num_1: 97,
|
|
1940
|
+
num_2: 98,
|
|
1941
|
+
num_3: 99,
|
|
1942
|
+
num_4: 100,
|
|
1943
|
+
num_5: 101,
|
|
1944
|
+
num_6: 102,
|
|
1945
|
+
num_7: 103,
|
|
1946
|
+
num_8: 104,
|
|
1947
|
+
num_9: 105,
|
|
1948
|
+
num_multiply: 106,
|
|
1949
|
+
num_add: 107,
|
|
1950
|
+
num_enter: 108,
|
|
1951
|
+
num_subtract: 109,
|
|
1952
|
+
num_decimal: 110,
|
|
1953
|
+
num_divide: 111,
|
|
1954
|
+
"⇪": 20,
|
|
1955
|
+
",": 188,
|
|
1956
|
+
".": 190,
|
|
1957
|
+
"/": 191,
|
|
1958
|
+
"`": 192,
|
|
1959
|
+
"-": Dt ? 173 : 189,
|
|
1960
|
+
"=": Dt ? 61 : 187,
|
|
1961
|
+
";": Dt ? 59 : 186,
|
|
1962
|
+
"'": 222,
|
|
1963
|
+
"[": 219,
|
|
1964
|
+
"]": 221,
|
|
1965
|
+
"\\": 220
|
|
1966
|
+
}, H = {
|
|
1967
|
+
// shiftKey
|
|
1968
|
+
"⇧": 16,
|
|
1969
|
+
shift: 16,
|
|
1970
|
+
// altKey
|
|
1971
|
+
"⌥": 18,
|
|
1972
|
+
alt: 18,
|
|
1973
|
+
option: 18,
|
|
1974
|
+
// ctrlKey
|
|
1975
|
+
"⌃": 17,
|
|
1976
|
+
ctrl: 17,
|
|
1977
|
+
control: 17,
|
|
1978
|
+
// metaKey
|
|
1979
|
+
"⌘": 91,
|
|
1980
|
+
cmd: 91,
|
|
1981
|
+
command: 91
|
|
1982
|
+
}, xt = {
|
|
1983
|
+
16: "shiftKey",
|
|
1984
|
+
18: "altKey",
|
|
1985
|
+
17: "ctrlKey",
|
|
1986
|
+
91: "metaKey",
|
|
1987
|
+
shiftKey: 16,
|
|
1988
|
+
ctrlKey: 17,
|
|
1989
|
+
altKey: 18,
|
|
1990
|
+
metaKey: 91
|
|
1991
|
+
}, K = {
|
|
1992
|
+
16: !1,
|
|
1993
|
+
18: !1,
|
|
1994
|
+
17: !1,
|
|
1995
|
+
91: !1
|
|
1996
|
+
}, N = {};
|
|
1997
|
+
for (let t = 1; t < 20; t++)
|
|
1998
|
+
dt["f".concat(t)] = 111 + t;
|
|
1999
|
+
let I = [], lt = null, Ce = "all";
|
|
2000
|
+
const z = /* @__PURE__ */ new Map(), ft = (t) => dt[t.toLowerCase()] || H[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), yo = (t) => Object.keys(dt).find((e) => dt[e] === t), bo = (t) => Object.keys(H).find((e) => H[e] === t);
|
|
2001
|
+
function Le(t) {
|
|
2002
|
+
Ce = t || "all";
|
|
2003
|
+
}
|
|
2004
|
+
function ut() {
|
|
2005
|
+
return Ce || "all";
|
|
2006
|
+
}
|
|
2007
|
+
function wo() {
|
|
2008
|
+
return I.slice(0);
|
|
2009
|
+
}
|
|
2010
|
+
function Ao() {
|
|
2011
|
+
return I.map((t) => yo(t) || bo(t) || String.fromCharCode(t));
|
|
2012
|
+
}
|
|
2013
|
+
function xo() {
|
|
2014
|
+
const t = [];
|
|
2015
|
+
return Object.keys(N).forEach((e) => {
|
|
2016
|
+
N[e].forEach((n) => {
|
|
2017
|
+
let {
|
|
2018
|
+
key: o,
|
|
2019
|
+
scope: i,
|
|
2020
|
+
mods: s,
|
|
2021
|
+
shortcut: a
|
|
2022
|
+
} = n;
|
|
2023
|
+
t.push({
|
|
2024
|
+
scope: i,
|
|
2025
|
+
shortcut: a,
|
|
2026
|
+
mods: s,
|
|
2027
|
+
keys: o.split("+").map((r) => ft(r))
|
|
2028
|
+
});
|
|
2029
|
+
});
|
|
2030
|
+
}), t;
|
|
2031
|
+
}
|
|
2032
|
+
function vo(t) {
|
|
2033
|
+
const e = t.target || t.srcElement, {
|
|
2034
|
+
tagName: n
|
|
2035
|
+
} = e;
|
|
2036
|
+
let o = !0;
|
|
2037
|
+
const i = n === "INPUT" && !["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes(e.type);
|
|
2038
|
+
return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = !1), o;
|
|
2039
|
+
}
|
|
2040
|
+
function Eo(t) {
|
|
2041
|
+
return typeof t == "string" && (t = ft(t)), I.indexOf(t) !== -1;
|
|
2042
|
+
}
|
|
2043
|
+
function So(t, e) {
|
|
2044
|
+
let n, o;
|
|
2045
|
+
t || (t = ut());
|
|
2046
|
+
for (const i in N)
|
|
2047
|
+
if (Object.prototype.hasOwnProperty.call(N, i))
|
|
2048
|
+
for (n = N[i], o = 0; o < n.length; )
|
|
2049
|
+
n[o].scope === t ? n.splice(o, 1).forEach((a) => {
|
|
2050
|
+
let {
|
|
2051
|
+
element: r
|
|
2052
|
+
} = a;
|
|
2053
|
+
return jt(r);
|
|
2054
|
+
}) : o++;
|
|
2055
|
+
ut() === t && Le(e || "all");
|
|
2056
|
+
}
|
|
2057
|
+
function Co(t) {
|
|
2058
|
+
let e = t.keyCode || t.which || t.charCode;
|
|
2059
|
+
const n = I.indexOf(e);
|
|
2060
|
+
if (n >= 0 && I.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && I.splice(0, I.length), (e === 93 || e === 224) && (e = 91), e in K) {
|
|
2061
|
+
K[e] = !1;
|
|
2062
|
+
for (const o in H) H[o] === e && (X[o] = !1);
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
function Te(t) {
|
|
2066
|
+
if (typeof t > "u")
|
|
2067
|
+
Object.keys(N).forEach((i) => {
|
|
2068
|
+
Array.isArray(N[i]) && N[i].forEach((s) => At(s)), delete N[i];
|
|
2069
|
+
}), jt(null);
|
|
2070
|
+
else if (Array.isArray(t))
|
|
2071
|
+
t.forEach((i) => {
|
|
2072
|
+
i.key && At(i);
|
|
2073
|
+
});
|
|
2074
|
+
else if (typeof t == "object")
|
|
2075
|
+
t.key && At(t);
|
|
2076
|
+
else if (typeof t == "string") {
|
|
2077
|
+
for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
|
|
2078
|
+
n[o - 1] = arguments[o];
|
|
2079
|
+
let [i, s] = n;
|
|
2080
|
+
typeof i == "function" && (s = i, i = ""), At({
|
|
2081
|
+
key: t,
|
|
2082
|
+
scope: i,
|
|
2083
|
+
method: s,
|
|
2084
|
+
splitKey: "+"
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
const At = (t) => {
|
|
2089
|
+
let {
|
|
2090
|
+
key: e,
|
|
2091
|
+
scope: n,
|
|
2092
|
+
method: o,
|
|
2093
|
+
splitKey: i = "+"
|
|
2094
|
+
} = t;
|
|
2095
|
+
Se(e).forEach((a) => {
|
|
2096
|
+
const r = a.split(i), l = r.length, d = r[l - 1], g = d === "*" ? "*" : ft(d);
|
|
2097
|
+
if (!N[g]) return;
|
|
2098
|
+
n || (n = ut());
|
|
2099
|
+
const u = l > 1 ? Ee(H, r) : [], f = [];
|
|
2100
|
+
N[g] = N[g].filter((A) => {
|
|
2101
|
+
const b = (o ? A.method === o : !0) && A.scope === n && mo(A.mods, u);
|
|
2102
|
+
return b && f.push(A.element), !b;
|
|
2103
|
+
}), f.forEach((A) => jt(A));
|
|
1036
2104
|
});
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
2105
|
+
};
|
|
2106
|
+
function ae(t, e, n, o) {
|
|
2107
|
+
if (e.element !== o)
|
|
2108
|
+
return;
|
|
2109
|
+
let i;
|
|
2110
|
+
if (e.scope === n || e.scope === "all") {
|
|
2111
|
+
i = e.mods.length > 0;
|
|
2112
|
+
for (const s in K)
|
|
2113
|
+
Object.prototype.hasOwnProperty.call(K, s) && (!K[s] && e.mods.indexOf(+s) > -1 || K[s] && e.mods.indexOf(+s) === -1) && (i = !1);
|
|
2114
|
+
(e.mods.length === 0 && !K[16] && !K[18] && !K[17] && !K[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(I), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
function ce(t, e) {
|
|
2118
|
+
const n = N["*"];
|
|
2119
|
+
let o = t.keyCode || t.which || t.charCode;
|
|
2120
|
+
if (!X.filter.call(this, t)) return;
|
|
2121
|
+
if ((o === 93 || o === 224) && (o = 91), I.indexOf(o) === -1 && o !== 229 && I.push(o), ["metaKey", "ctrlKey", "altKey", "shiftKey"].forEach((r) => {
|
|
2122
|
+
const l = xt[r];
|
|
2123
|
+
t[r] && I.indexOf(l) === -1 ? I.push(l) : !t[r] && I.indexOf(l) > -1 ? I.splice(I.indexOf(l), 1) : r === "metaKey" && t[r] && (I = I.filter((d) => d in xt || d === o));
|
|
2124
|
+
}), o in K) {
|
|
2125
|
+
K[o] = !0;
|
|
2126
|
+
for (const r in H)
|
|
2127
|
+
H[r] === o && (X[r] = !0);
|
|
2128
|
+
if (!n) return;
|
|
2129
|
+
}
|
|
2130
|
+
for (const r in K)
|
|
2131
|
+
Object.prototype.hasOwnProperty.call(K, r) && (K[r] = t[xt[r]]);
|
|
2132
|
+
t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (I.indexOf(17) === -1 && I.push(17), I.indexOf(18) === -1 && I.push(18), K[17] = !0, K[18] = !0);
|
|
2133
|
+
const i = ut();
|
|
2134
|
+
if (n)
|
|
2135
|
+
for (let r = 0; r < n.length; r++)
|
|
2136
|
+
n[r].scope === i && (t.type === "keydown" && n[r].keydown || t.type === "keyup" && n[r].keyup) && ae(t, n[r], i, e);
|
|
2137
|
+
if (!(o in N)) return;
|
|
2138
|
+
const s = N[o], a = s.length;
|
|
2139
|
+
for (let r = 0; r < a; r++)
|
|
2140
|
+
if ((t.type === "keydown" && s[r].keydown || t.type === "keyup" && s[r].keyup) && s[r].key) {
|
|
2141
|
+
const l = s[r], {
|
|
2142
|
+
splitKey: d
|
|
2143
|
+
} = l, g = l.key.split(d), u = [];
|
|
2144
|
+
for (let f = 0; f < g.length; f++)
|
|
2145
|
+
u.push(ft(g[f]));
|
|
2146
|
+
u.sort().join("") === I.sort().join("") && ae(t, l, i, e);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
function X(t, e, n) {
|
|
2150
|
+
I = [];
|
|
2151
|
+
const o = Se(t);
|
|
2152
|
+
let i = [], s = "all", a = document, r = 0, l = !1, d = !0, g = "+", u = !1, f = !1;
|
|
2153
|
+
for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (l = e.keyup), e.keydown !== void 0 && (d = e.keydown), e.capture !== void 0 && (u = e.capture), typeof e.splitKey == "string" && (g = e.splitKey), e.single === !0 && (f = !0)), typeof e == "string" && (s = e), f && Te(t, s); r < o.length; r++)
|
|
2154
|
+
t = o[r].split(g), i = [], t.length > 1 && (i = Ee(H, t)), t = t[t.length - 1], t = t === "*" ? "*" : ft(t), t in N || (N[t] = []), N[t].push({
|
|
2155
|
+
keyup: l,
|
|
2156
|
+
keydown: d,
|
|
2157
|
+
scope: s,
|
|
2158
|
+
mods: i,
|
|
2159
|
+
shortcut: o[r],
|
|
2160
|
+
method: n,
|
|
2161
|
+
key: o[r],
|
|
2162
|
+
splitKey: g,
|
|
2163
|
+
element: a
|
|
2164
|
+
});
|
|
2165
|
+
if (typeof a < "u" && window) {
|
|
2166
|
+
if (!z.has(a)) {
|
|
2167
|
+
const A = function() {
|
|
2168
|
+
let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2169
|
+
return ce(b, a);
|
|
2170
|
+
}, p = function() {
|
|
2171
|
+
let b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2172
|
+
ce(b, a), Co(b);
|
|
1061
2173
|
};
|
|
2174
|
+
z.set(a, {
|
|
2175
|
+
keydownListener: A,
|
|
2176
|
+
keyupListenr: p,
|
|
2177
|
+
capture: u
|
|
2178
|
+
}), Vt(a, "keydown", A, u), Vt(a, "keyup", p, u);
|
|
1062
2179
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
const destroy = () => {
|
|
1072
|
-
canvas.remove();
|
|
1073
|
-
};
|
|
1074
|
-
return {
|
|
1075
|
-
clear,
|
|
1076
|
-
destroy,
|
|
1077
|
-
paint: paint2,
|
|
1078
|
-
reset
|
|
1079
|
-
};
|
|
1080
|
-
};
|
|
1081
|
-
const CLICK_TIMEOUT = 300;
|
|
1082
|
-
const ARROW_KEYS = ["up", "down", "left", "right"];
|
|
1083
|
-
const SELECT_ALL = isMac ? "⌘+a" : "ctrl+a";
|
|
1084
|
-
const SELECTION_KEYS = [
|
|
1085
|
-
...ARROW_KEYS.map((key) => `shift+${key}`),
|
|
1086
|
-
SELECT_ALL
|
|
1087
|
-
];
|
|
1088
|
-
const createSelectionHandler = (container, state, options) => {
|
|
1089
|
-
const { store, selection } = state;
|
|
1090
|
-
let currentUser;
|
|
1091
|
-
const { annotatingEnabled, offsetReferenceSelector, selectionMode } = options;
|
|
1092
|
-
const setUser = (user) => currentUser = user;
|
|
1093
|
-
let currentFilter;
|
|
1094
|
-
const setFilter = (filter) => currentFilter = filter;
|
|
1095
|
-
let currentTarget;
|
|
1096
|
-
let isLeftClick;
|
|
1097
|
-
let lastDownEvent;
|
|
1098
|
-
let currentAnnotatingEnabled = annotatingEnabled;
|
|
1099
|
-
const setAnnotatingEnabled = (enabled) => {
|
|
1100
|
-
currentAnnotatingEnabled = enabled;
|
|
1101
|
-
onSelectionChange.clear();
|
|
1102
|
-
if (!enabled) {
|
|
1103
|
-
currentTarget = void 0;
|
|
1104
|
-
isLeftClick = void 0;
|
|
1105
|
-
lastDownEvent = void 0;
|
|
2180
|
+
if (!lt) {
|
|
2181
|
+
const A = () => {
|
|
2182
|
+
I = [];
|
|
2183
|
+
};
|
|
2184
|
+
lt = {
|
|
2185
|
+
listener: A,
|
|
2186
|
+
capture: u
|
|
2187
|
+
}, Vt(window, "focus", A, u);
|
|
1106
2188
|
}
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
function Lo(t) {
|
|
2192
|
+
let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
|
|
2193
|
+
Object.keys(N).forEach((n) => {
|
|
2194
|
+
N[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
|
|
2195
|
+
i && i.method && i.method();
|
|
2196
|
+
});
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
function jt(t) {
|
|
2200
|
+
const e = Object.values(N).flat();
|
|
2201
|
+
if (e.findIndex((o) => {
|
|
2202
|
+
let {
|
|
2203
|
+
element: i
|
|
2204
|
+
} = o;
|
|
2205
|
+
return i === t;
|
|
2206
|
+
}) < 0) {
|
|
2207
|
+
const {
|
|
2208
|
+
keydownListener: o,
|
|
2209
|
+
keyupListenr: i,
|
|
2210
|
+
capture: s
|
|
2211
|
+
} = z.get(t) || {};
|
|
2212
|
+
o && i && (it(t, "keyup", i, s), it(t, "keydown", o, s), z.delete(t));
|
|
2213
|
+
}
|
|
2214
|
+
if ((e.length <= 0 || z.size <= 0) && (Object.keys(z).forEach((i) => {
|
|
2215
|
+
const {
|
|
2216
|
+
keydownListener: s,
|
|
2217
|
+
keyupListenr: a,
|
|
2218
|
+
capture: r
|
|
2219
|
+
} = z.get(i) || {};
|
|
2220
|
+
s && a && (it(i, "keyup", a, r), it(i, "keydown", s, r), z.delete(i));
|
|
2221
|
+
}), z.clear(), Object.keys(N).forEach((i) => delete N[i]), lt)) {
|
|
2222
|
+
const {
|
|
2223
|
+
listener: i,
|
|
2224
|
+
capture: s
|
|
2225
|
+
} = lt;
|
|
2226
|
+
it(window, "focus", i, s), lt = null;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
const Yt = {
|
|
2230
|
+
getPressedKeyString: Ao,
|
|
2231
|
+
setScope: Le,
|
|
2232
|
+
getScope: ut,
|
|
2233
|
+
deleteScope: So,
|
|
2234
|
+
getPressedKeyCodes: wo,
|
|
2235
|
+
getAllKeyCodes: xo,
|
|
2236
|
+
isPressed: Eo,
|
|
2237
|
+
filter: vo,
|
|
2238
|
+
trigger: Lo,
|
|
2239
|
+
unbind: Te,
|
|
2240
|
+
keyMap: dt,
|
|
2241
|
+
modifier: H,
|
|
2242
|
+
modifierMap: xt
|
|
2243
|
+
};
|
|
2244
|
+
for (const t in Yt)
|
|
2245
|
+
Object.prototype.hasOwnProperty.call(Yt, t) && (X[t] = Yt[t]);
|
|
2246
|
+
if (typeof window < "u") {
|
|
2247
|
+
const t = window.hotkeys;
|
|
2248
|
+
X.noConflict = (e) => (e && window.hotkeys === X && (window.hotkeys = t), X), window.hotkeys = X;
|
|
2249
|
+
}
|
|
2250
|
+
async function To(t, e, n = () => !1) {
|
|
2251
|
+
do {
|
|
2252
|
+
if (await t(), await n()) break;
|
|
2253
|
+
const o = e;
|
|
2254
|
+
await new Promise((i) => setTimeout(i, Math.max(0, o)));
|
|
2255
|
+
} while (!await n());
|
|
2256
|
+
}
|
|
2257
|
+
const le = 300, Oe = ["up", "down", "left", "right"], Be = ke ? "⌘+a" : "ctrl+a", Oo = [
|
|
2258
|
+
...Oe.map((t) => `shift+${t}`),
|
|
2259
|
+
Be
|
|
2260
|
+
], Bo = (t, e, n) => {
|
|
2261
|
+
const { store: o, selection: i } = e;
|
|
2262
|
+
let s;
|
|
2263
|
+
const { annotatingEnabled: a, offsetReferenceSelector: r, selectionMode: l } = n, d = (h) => s = h;
|
|
2264
|
+
let g;
|
|
2265
|
+
const u = (h) => g = h;
|
|
2266
|
+
let f, A, p, b = a;
|
|
2267
|
+
const x = (h) => {
|
|
2268
|
+
b = h, c.clear(), h || (f = void 0, A = void 0, p = void 0);
|
|
2269
|
+
}, m = (h) => {
|
|
2270
|
+
b && A !== !1 && (f = st(h.target) ? void 0 : {
|
|
2271
|
+
annotation: be(),
|
|
1113
2272
|
selector: [],
|
|
1114
|
-
creator:
|
|
2273
|
+
creator: s,
|
|
1115
2274
|
created: /* @__PURE__ */ new Date()
|
|
1116
|
-
};
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
if (!(sel == null ? void 0 : sel.anchorNode)) {
|
|
2275
|
+
});
|
|
2276
|
+
}, c = Xt((h) => {
|
|
2277
|
+
if (!b) return;
|
|
2278
|
+
const E = document.getSelection();
|
|
2279
|
+
if (!(E != null && E.anchorNode))
|
|
1122
2280
|
return;
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
currentTarget = void 0;
|
|
2281
|
+
if (st(E.anchorNode)) {
|
|
2282
|
+
f = void 0;
|
|
1126
2283
|
return;
|
|
1127
2284
|
}
|
|
1128
|
-
const
|
|
1129
|
-
if ((
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
} else if (sel.isCollapsed && timeDifference < CLICK_TIMEOUT) {
|
|
1133
|
-
onSelectStart(lastDownEvent || evt);
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
if (!currentTarget) return;
|
|
1137
|
-
if (sel.isCollapsed) {
|
|
1138
|
-
if (store.getAnnotation(currentTarget.annotation)) {
|
|
1139
|
-
selection.clear();
|
|
1140
|
-
store.deleteAnnotation(currentTarget.annotation);
|
|
1141
|
-
}
|
|
2285
|
+
const M = h.timeStamp - ((p == null ? void 0 : p.timeStamp) || h.timeStamp);
|
|
2286
|
+
if ((p == null ? void 0 : p.type) === "pointerdown" && (M < 1e3 && !f || E.isCollapsed && M < le) && m(p || h), !f) return;
|
|
2287
|
+
if (E.isCollapsed) {
|
|
2288
|
+
o.getAnnotation(f.annotation) && (i.clear(), o.deleteAnnotation(f.annotation));
|
|
1142
2289
|
return;
|
|
1143
2290
|
}
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
currentTarget = {
|
|
1154
|
-
...currentTarget,
|
|
1155
|
-
selector: annotatableRanges.map((r) => rangeToSelector(r, container, offsetReferenceSelector)),
|
|
2291
|
+
const O = E.getRangeAt(0), U = He(O, t);
|
|
2292
|
+
if (Ve(U)) return;
|
|
2293
|
+
const _ = _e(U.cloneRange());
|
|
2294
|
+
(_.length !== f.selector.length || _.some((W, G) => {
|
|
2295
|
+
var St;
|
|
2296
|
+
return W.toString() !== ((St = f.selector[G]) == null ? void 0 : St.quote);
|
|
2297
|
+
})) && (f = {
|
|
2298
|
+
...f,
|
|
2299
|
+
selector: _.map((W) => Xe(W, t, r)),
|
|
1156
2300
|
updated: /* @__PURE__ */ new Date()
|
|
2301
|
+
}, o.getAnnotation(f.annotation) ? o.updateTarget(f, k.LOCAL) : i.clear());
|
|
2302
|
+
}, 10), y = (h) => {
|
|
2303
|
+
st(h.target) || (p = Lt(h), A = p.button === 0);
|
|
2304
|
+
}, C = async (h) => {
|
|
2305
|
+
if (st(h.target) || !A) return;
|
|
2306
|
+
const E = () => {
|
|
2307
|
+
const { x: O, y: U } = t.getBoundingClientRect(), _ = h.target instanceof Node && t.contains(h.target) && o.getAt(h.clientX - O, h.clientY - U, l === "all", g);
|
|
2308
|
+
if (_) {
|
|
2309
|
+
const { selected: ht } = i, W = new Set(ht.map((nt) => nt.id)), G = Array.isArray(_) ? _.map((nt) => nt.id) : [_.id];
|
|
2310
|
+
(W.size !== G.length || !G.every((nt) => W.has(nt))) && i.userSelect(G, h);
|
|
2311
|
+
} else
|
|
2312
|
+
i.clear();
|
|
1157
2313
|
};
|
|
1158
|
-
if (
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
}, 10);
|
|
1164
|
-
const onPointerDown = (evt) => {
|
|
1165
|
-
if (isNotAnnotatable(evt.target)) return;
|
|
1166
|
-
lastDownEvent = clonePointerEvent(evt);
|
|
1167
|
-
isLeftClick = lastDownEvent.button === 0;
|
|
1168
|
-
};
|
|
1169
|
-
const onPointerUp = async (evt) => {
|
|
1170
|
-
if (isNotAnnotatable(evt.target) || !isLeftClick) return;
|
|
1171
|
-
const clickSelect = () => {
|
|
1172
|
-
const { x, y } = container.getBoundingClientRect();
|
|
1173
|
-
const hovered = evt.target instanceof Node && container.contains(evt.target) && store.getAt(evt.clientX - x, evt.clientY - y, selectionMode === "all", currentFilter);
|
|
1174
|
-
if (hovered) {
|
|
1175
|
-
const { selected } = selection;
|
|
1176
|
-
const currentIds = new Set(selected.map((s) => s.id));
|
|
1177
|
-
const nextIds = Array.isArray(hovered) ? hovered.map((a) => a.id) : [hovered.id];
|
|
1178
|
-
const hasChanged = currentIds.size !== nextIds.length || !nextIds.every((id) => currentIds.has(id));
|
|
1179
|
-
if (hasChanged)
|
|
1180
|
-
selection.userSelect(nextIds, evt);
|
|
1181
|
-
} else {
|
|
1182
|
-
selection.clear();
|
|
1183
|
-
}
|
|
1184
|
-
};
|
|
1185
|
-
const timeDifference = evt.timeStamp - lastDownEvent.timeStamp;
|
|
1186
|
-
if (timeDifference < CLICK_TIMEOUT) {
|
|
1187
|
-
await pollSelectionCollapsed();
|
|
1188
|
-
const sel = document.getSelection();
|
|
1189
|
-
if (sel == null ? void 0 : sel.isCollapsed) {
|
|
1190
|
-
currentTarget = void 0;
|
|
1191
|
-
clickSelect();
|
|
2314
|
+
if (h.timeStamp - p.timeStamp < le) {
|
|
2315
|
+
await S();
|
|
2316
|
+
const O = document.getSelection();
|
|
2317
|
+
if (O != null && O.isCollapsed) {
|
|
2318
|
+
f = void 0, E();
|
|
1192
2319
|
return;
|
|
1193
2320
|
}
|
|
1194
2321
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
setTimeout(() =>
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
if (!currentTarget || currentTarget.selector.length === 0) {
|
|
1214
|
-
onSelectionChange(evt);
|
|
1215
|
-
}
|
|
1216
|
-
upsertCurrentTarget();
|
|
1217
|
-
selection.userSelect(currentTarget.annotation, clonePointerEvent(evt));
|
|
1218
|
-
};
|
|
1219
|
-
const onKeyup = (evt) => {
|
|
1220
|
-
if (!currentAnnotatingEnabled) return;
|
|
1221
|
-
if (evt.key === "Shift" && currentTarget) {
|
|
1222
|
-
const sel = document.getSelection();
|
|
1223
|
-
if (!sel.isCollapsed) {
|
|
1224
|
-
upsertCurrentTarget();
|
|
1225
|
-
selection.userSelect(currentTarget.annotation, cloneKeyboardEvent(evt));
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
};
|
|
1229
|
-
const onSelectAll = (evt) => {
|
|
1230
|
-
const onSelected = () => setTimeout(() => {
|
|
1231
|
-
if ((currentTarget == null ? void 0 : currentTarget.selector.length) > 0) {
|
|
1232
|
-
selection.clear();
|
|
1233
|
-
store.addAnnotation({
|
|
1234
|
-
id: currentTarget.annotation,
|
|
1235
|
-
bodies: [],
|
|
1236
|
-
target: currentTarget
|
|
1237
|
-
});
|
|
1238
|
-
selection.userSelect(currentTarget.annotation, cloneKeyboardEvent(evt));
|
|
1239
|
-
}
|
|
1240
|
-
document.removeEventListener("selectionchange", onSelected);
|
|
2322
|
+
f && f.selector.length > 0 && (w(), i.userSelect(f.annotation, Lt(h)));
|
|
2323
|
+
}, S = async () => {
|
|
2324
|
+
const h = document.getSelection();
|
|
2325
|
+
let E = !1, M = h == null ? void 0 : h.isCollapsed;
|
|
2326
|
+
const O = () => M || E, U = 1;
|
|
2327
|
+
return setTimeout(() => E = !0, 50), To(() => M = h == null ? void 0 : h.isCollapsed, U, O);
|
|
2328
|
+
}, L = (h) => {
|
|
2329
|
+
const E = document.getSelection();
|
|
2330
|
+
E != null && E.isCollapsed || ((!f || f.selector.length === 0) && c(h), w(), i.userSelect(f.annotation, Lt(h)));
|
|
2331
|
+
}, B = (h) => {
|
|
2332
|
+
b && h.key === "Shift" && f && (document.getSelection().isCollapsed || (w(), i.userSelect(f.annotation, pt(h))));
|
|
2333
|
+
}, T = (h) => {
|
|
2334
|
+
const E = () => setTimeout(() => {
|
|
2335
|
+
(f == null ? void 0 : f.selector.length) > 0 && (i.clear(), o.addAnnotation({
|
|
2336
|
+
id: f.annotation,
|
|
2337
|
+
bodies: [],
|
|
2338
|
+
target: f
|
|
2339
|
+
}), i.userSelect(f.annotation, pt(h))), document.removeEventListener("selectionchange", E);
|
|
1241
2340
|
}, 100);
|
|
1242
|
-
document.addEventListener("selectionchange",
|
|
1243
|
-
onSelectStart(evt);
|
|
2341
|
+
document.addEventListener("selectionchange", E), m(h);
|
|
1244
2342
|
};
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
hotkeys(SELECT_ALL, { keydown: true, keyup: false }, (evt) => {
|
|
1250
|
-
lastDownEvent = cloneKeyboardEvent(evt);
|
|
1251
|
-
onSelectAll(evt);
|
|
2343
|
+
X(Oo.join(","), { element: t, keydown: !0, keyup: !1 }, (h) => {
|
|
2344
|
+
h.repeat || (p = pt(h));
|
|
2345
|
+
}), X(Be, { keydown: !0, keyup: !1 }, (h) => {
|
|
2346
|
+
p = pt(h), T(h);
|
|
1252
2347
|
});
|
|
1253
|
-
const
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
const existingAnnotation = store.getAnnotation(currentTarget.annotation);
|
|
1263
|
-
if (!existingAnnotation) {
|
|
1264
|
-
store.addAnnotation({
|
|
1265
|
-
id: currentTarget.annotation,
|
|
2348
|
+
const R = (h) => {
|
|
2349
|
+
h.repeat || h.target !== t && h.target !== document.body || (f = void 0, i.clear());
|
|
2350
|
+
};
|
|
2351
|
+
X(Oe.join(","), { keydown: !0, keyup: !1 }, R);
|
|
2352
|
+
const w = () => {
|
|
2353
|
+
const h = o.getAnnotation(f.annotation);
|
|
2354
|
+
if (!h) {
|
|
2355
|
+
o.addAnnotation({
|
|
2356
|
+
id: f.annotation,
|
|
1266
2357
|
bodies: [],
|
|
1267
|
-
target:
|
|
2358
|
+
target: f
|
|
1268
2359
|
});
|
|
1269
2360
|
return;
|
|
1270
2361
|
}
|
|
1271
|
-
const { target: { updated:
|
|
1272
|
-
|
|
1273
|
-
if (!existingTargetUpdated || !currentTargetUpdated || existingTargetUpdated < currentTargetUpdated) {
|
|
1274
|
-
store.updateTarget(currentTarget);
|
|
1275
|
-
}
|
|
1276
|
-
};
|
|
1277
|
-
document.addEventListener("pointerdown", onPointerDown);
|
|
1278
|
-
document.addEventListener("pointerup", onPointerUp);
|
|
1279
|
-
document.addEventListener("contextmenu", onContextMenu);
|
|
1280
|
-
container.addEventListener("keyup", onKeyup);
|
|
1281
|
-
container.addEventListener("selectstart", onSelectStart);
|
|
1282
|
-
document.addEventListener("selectionchange", onSelectionChange);
|
|
1283
|
-
const destroy = () => {
|
|
1284
|
-
currentTarget = void 0;
|
|
1285
|
-
isLeftClick = void 0;
|
|
1286
|
-
lastDownEvent = void 0;
|
|
1287
|
-
onSelectionChange.clear();
|
|
1288
|
-
document.removeEventListener("pointerdown", onPointerDown);
|
|
1289
|
-
document.removeEventListener("pointerup", onPointerUp);
|
|
1290
|
-
document.removeEventListener("contextmenu", onContextMenu);
|
|
1291
|
-
container.removeEventListener("keyup", onKeyup);
|
|
1292
|
-
container.removeEventListener("selectstart", onSelectStart);
|
|
1293
|
-
document.removeEventListener("selectionchange", onSelectionChange);
|
|
1294
|
-
hotkeys.unbind();
|
|
2362
|
+
const { target: { updated: E } } = h, { updated: M } = f;
|
|
2363
|
+
(!E || !M || E < M) && o.updateTarget(f);
|
|
1295
2364
|
};
|
|
1296
|
-
return {
|
|
1297
|
-
destroy
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
if (!highlightRenderer)
|
|
1325
|
-
throw `Unknown renderer implementation: ${useRenderer}`;
|
|
1326
|
-
console.debug(`Using ${useRenderer} renderer`);
|
|
1327
|
-
if (opts.style)
|
|
1328
|
-
highlightRenderer.setStyle(opts.style);
|
|
1329
|
-
const selectionHandler = createSelectionHandler(container, state, opts);
|
|
1330
|
-
selectionHandler.setUser(currentUser);
|
|
1331
|
-
selectionHandler.setAnnotatingEnabled(opts.annotatingEnabled);
|
|
1332
|
-
const base = createBaseAnnotator(state, undoStack, opts.adapter);
|
|
1333
|
-
const getUser = () => currentUser;
|
|
1334
|
-
const setAnnotatingEnabled = (enabled) => {
|
|
1335
|
-
selectionHandler.setAnnotatingEnabled(
|
|
1336
|
-
enabled === void 0 ? true : enabled
|
|
2365
|
+
return document.addEventListener("pointerdown", y), document.addEventListener("pointerup", C), document.addEventListener("contextmenu", L), t.addEventListener("keyup", B), t.addEventListener("selectstart", m), document.addEventListener("selectionchange", c), {
|
|
2366
|
+
destroy: () => {
|
|
2367
|
+
f = void 0, A = void 0, p = void 0, c.clear(), document.removeEventListener("pointerdown", y), document.removeEventListener("pointerup", C), document.removeEventListener("contextmenu", L), t.removeEventListener("keyup", B), t.removeEventListener("selectstart", m), document.removeEventListener("selectionchange", c), X.unbind();
|
|
2368
|
+
},
|
|
2369
|
+
setFilter: u,
|
|
2370
|
+
setUser: d,
|
|
2371
|
+
setAnnotatingEnabled: x
|
|
2372
|
+
};
|
|
2373
|
+
}, Ro = (t, e) => ({
|
|
2374
|
+
...t,
|
|
2375
|
+
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
2376
|
+
user: t.user || e.user
|
|
2377
|
+
}), de = "SPANS", _o = (t, e = {}) => {
|
|
2378
|
+
Me(t), Ie(t);
|
|
2379
|
+
const n = Ro(e, {
|
|
2380
|
+
annotatingEnabled: !0,
|
|
2381
|
+
user: qn()
|
|
2382
|
+
}), o = ho(t, n), { selection: i, viewport: s } = o, a = o.store, r = Yn(a), l = Pn(o, r, n.adapter);
|
|
2383
|
+
let d = n.user;
|
|
2384
|
+
const g = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : de : n.renderer || de, u = g === "SPANS" ? mn(t, o, s) : g === "CSS_HIGHLIGHTS" ? hn(t, o, s) : g === "CANVAS" ? nn(t, o, s) : void 0;
|
|
2385
|
+
if (!u)
|
|
2386
|
+
throw `Unknown renderer implementation: ${g}`;
|
|
2387
|
+
console.debug(`Using ${g} renderer`), n.style && u.setStyle(n.style);
|
|
2388
|
+
const f = Bo(t, o, n);
|
|
2389
|
+
f.setUser(d), f.setAnnotatingEnabled(n.annotatingEnabled);
|
|
2390
|
+
const A = $n(o, r, n.adapter), p = () => d, b = (S) => {
|
|
2391
|
+
f.setAnnotatingEnabled(
|
|
2392
|
+
S === void 0 ? !0 : S
|
|
1337
2393
|
);
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
};
|
|
1347
|
-
const setPresenceProvider = (provider) => {
|
|
1348
|
-
if (provider) {
|
|
1349
|
-
highlightRenderer.setPainter(createPresencePainter(provider, opts.presence));
|
|
1350
|
-
provider.on("selectionChange", () => highlightRenderer.redraw());
|
|
1351
|
-
}
|
|
1352
|
-
};
|
|
1353
|
-
const setSelected = (arg) => {
|
|
1354
|
-
if (arg) {
|
|
1355
|
-
selection.setSelected(arg);
|
|
1356
|
-
} else {
|
|
1357
|
-
selection.clear();
|
|
1358
|
-
}
|
|
1359
|
-
};
|
|
1360
|
-
const destroy = () => {
|
|
1361
|
-
highlightRenderer.destroy();
|
|
1362
|
-
selectionHandler.destroy();
|
|
1363
|
-
undoStack.destroy();
|
|
2394
|
+
}, x = (S) => {
|
|
2395
|
+
u.setFilter(S), f.setFilter(S);
|
|
2396
|
+
}, m = (S) => {
|
|
2397
|
+
d = S, f.setUser(S);
|
|
2398
|
+
}, c = (S) => {
|
|
2399
|
+
S && (u.setPainter(go(S, n.presence)), S.on("selectionChange", () => u.redraw()));
|
|
2400
|
+
}, y = (S) => {
|
|
2401
|
+
S ? i.setSelected(S) : i.clear();
|
|
1364
2402
|
};
|
|
1365
2403
|
return {
|
|
1366
|
-
...
|
|
1367
|
-
destroy
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
2404
|
+
...A,
|
|
2405
|
+
destroy: () => {
|
|
2406
|
+
u.destroy(), f.destroy(), r.destroy();
|
|
2407
|
+
},
|
|
2408
|
+
element: t,
|
|
2409
|
+
getUser: p,
|
|
2410
|
+
setAnnotatingEnabled: b,
|
|
2411
|
+
setFilter: x,
|
|
2412
|
+
setStyle: u.setStyle.bind(u),
|
|
2413
|
+
redraw: u.redraw.bind(u),
|
|
2414
|
+
setUser: m,
|
|
2415
|
+
setSelected: y,
|
|
2416
|
+
setPresenceProvider: c,
|
|
2417
|
+
setVisible: u.setVisible.bind(u),
|
|
2418
|
+
on: l.on,
|
|
2419
|
+
off: l.off,
|
|
2420
|
+
scrollIntoView: ze(t, a),
|
|
2421
|
+
state: o
|
|
1382
2422
|
};
|
|
1383
2423
|
};
|
|
1384
2424
|
export {
|
|
1385
|
-
DEFAULT_SELECTED_STYLE,
|
|
1386
|
-
DEFAULT_STYLE,
|
|
1387
|
-
NOT_ANNOTATABLE_CLASS,
|
|
1388
|
-
NOT_ANNOTATABLE_SELECTOR,
|
|
1389
|
-
|
|
1390
|
-
UserSelectAction,
|
|
1391
|
-
W3CTextFormat,
|
|
1392
|
-
cancelSingleClickEvents,
|
|
1393
|
-
cloneKeyboardEvent,
|
|
1394
|
-
clonePointerEvent,
|
|
1395
|
-
createBody,
|
|
1396
|
-
createCanvasRenderer,
|
|
1397
|
-
createHighlightsRenderer,
|
|
1398
|
-
createPresencePainter,
|
|
1399
|
-
|
|
1400
|
-
createSelectionHandler,
|
|
1401
|
-
createSpansRenderer,
|
|
1402
|
-
createTextAnnotator,
|
|
1403
|
-
createTextAnnotatorState,
|
|
1404
|
-
fillDefaults,
|
|
1405
|
-
getQuoteContext,
|
|
1406
|
-
getRangeAnnotatableContents,
|
|
1407
|
-
isMac,
|
|
1408
|
-
isNotAnnotatable,
|
|
1409
|
-
isRangeAnnotatable,
|
|
1410
|
-
isRevived,
|
|
1411
|
-
isWhitespaceOrEmpty,
|
|
1412
|
-
mergeClientRects,
|
|
1413
|
-
paint,
|
|
1414
|
-
parseW3CTextAnnotation,
|
|
1415
|
-
programmaticallyFocusable,
|
|
1416
|
-
rangeContains,
|
|
1417
|
-
rangeToSelector,
|
|
1418
|
-
reviveAnnotation,
|
|
1419
|
-
reviveSelector,
|
|
1420
|
-
reviveTarget,
|
|
1421
|
-
scrollIntoView,
|
|
1422
|
-
serializeW3CTextAnnotation,
|
|
1423
|
-
splitAnnotatableRanges,
|
|
1424
|
-
toDomRectList,
|
|
1425
|
-
toParentBounds,
|
|
1426
|
-
toViewportBounds,
|
|
1427
|
-
trimRangeToContainer,
|
|
1428
|
-
whitespaceOrEmptyRegex
|
|
2425
|
+
Et as DEFAULT_SELECTED_STYLE,
|
|
2426
|
+
q as DEFAULT_STYLE,
|
|
2427
|
+
ue as NOT_ANNOTATABLE_CLASS,
|
|
2428
|
+
et as NOT_ANNOTATABLE_SELECTOR,
|
|
2429
|
+
k as Origin,
|
|
2430
|
+
En as UserSelectAction,
|
|
2431
|
+
No as W3CTextFormat,
|
|
2432
|
+
Me as cancelSingleClickEvents,
|
|
2433
|
+
pt as cloneKeyboardEvent,
|
|
2434
|
+
Lt as clonePointerEvent,
|
|
2435
|
+
Io as createBody,
|
|
2436
|
+
nn as createCanvasRenderer,
|
|
2437
|
+
hn as createHighlightsRenderer,
|
|
2438
|
+
go as createPresencePainter,
|
|
2439
|
+
fn as createRenderer,
|
|
2440
|
+
Bo as createSelectionHandler,
|
|
2441
|
+
mn as createSpansRenderer,
|
|
2442
|
+
_o as createTextAnnotator,
|
|
2443
|
+
ho as createTextAnnotatorState,
|
|
2444
|
+
Ro as fillDefaults,
|
|
2445
|
+
Ue as getQuoteContext,
|
|
2446
|
+
Kt as getRangeAnnotatableContents,
|
|
2447
|
+
ke as isMac,
|
|
2448
|
+
st as isNotAnnotatable,
|
|
2449
|
+
Re as isRangeAnnotatable,
|
|
2450
|
+
F as isRevived,
|
|
2451
|
+
Ve as isWhitespaceOrEmpty,
|
|
2452
|
+
Pe as mergeClientRects,
|
|
2453
|
+
Fe as paint,
|
|
2454
|
+
eo as parseW3CTextAnnotation,
|
|
2455
|
+
Ie as programmaticallyFocusable,
|
|
2456
|
+
$e as rangeContains,
|
|
2457
|
+
Xe as rangeToSelector,
|
|
2458
|
+
Ct as reviveAnnotation,
|
|
2459
|
+
fe as reviveSelector,
|
|
2460
|
+
vt as reviveTarget,
|
|
2461
|
+
ze as scrollIntoView,
|
|
2462
|
+
no as serializeW3CTextAnnotation,
|
|
2463
|
+
_e as splitAnnotatableRanges,
|
|
2464
|
+
Mo as toDomRectList,
|
|
2465
|
+
je as toParentBounds,
|
|
2466
|
+
ko as toViewportBounds,
|
|
2467
|
+
He as trimRangeToContainer,
|
|
2468
|
+
De as whitespaceOrEmptyRegex
|
|
1429
2469
|
};
|
|
1430
2470
|
//# sourceMappingURL=text-annotator.es.js.map
|