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