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