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