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