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