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