@recogito/text-annotator 3.0.5 → 3.1.1
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,13 +1,13 @@
|
|
|
1
|
-
const re = "not-annotatable",
|
|
1
|
+
const re = "not-annotatable", nt = `.${re}`, rt = (t) => {
|
|
2
2
|
var n;
|
|
3
|
-
return !!(t instanceof HTMLElement ? t.closest(
|
|
3
|
+
return !!(t instanceof HTMLElement ? t.closest(nt) : (n = t.parentElement) == null ? void 0 : n.closest(nt));
|
|
4
4
|
}, Ce = (t) => {
|
|
5
5
|
const e = t.commonAncestorContainer;
|
|
6
|
-
return !
|
|
6
|
+
return !rt(e);
|
|
7
7
|
}, Le = (t) => t.addEventListener("click", (e) => {
|
|
8
8
|
// Allow clicks within not-annotatable elements
|
|
9
|
-
!e.target.closest(
|
|
10
|
-
}),
|
|
9
|
+
!e.target.closest(nt) && !e.target.closest("a") && e.preventDefault();
|
|
10
|
+
}), Et = (t) => ({
|
|
11
11
|
...t,
|
|
12
12
|
type: t.type,
|
|
13
13
|
x: t.x,
|
|
@@ -33,7 +33,7 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
33
33
|
pointerId: t.pointerId,
|
|
34
34
|
pointerType: t.pointerType,
|
|
35
35
|
timeStamp: t.timeStamp
|
|
36
|
-
}),
|
|
36
|
+
}), gt = (t) => ({
|
|
37
37
|
...t,
|
|
38
38
|
type: t.type,
|
|
39
39
|
key: t.key,
|
|
@@ -52,16 +52,16 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
52
52
|
}), Te = typeof navigator < "u" && // @ts-ignore
|
|
53
53
|
/mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform), Oe = (t) => {
|
|
54
54
|
!t.hasAttribute("tabindex") && t.tabIndex < 0 && t.setAttribute("tabindex", "-1"), t.classList.add("no-focus-outline");
|
|
55
|
-
},
|
|
55
|
+
}, Kt = (t, e = 10) => {
|
|
56
56
|
let n;
|
|
57
|
-
return (...o) => {
|
|
57
|
+
return ((...o) => {
|
|
58
58
|
clearTimeout(n), n = setTimeout(() => t.apply(void 0, o), e);
|
|
59
|
-
};
|
|
59
|
+
});
|
|
60
60
|
}, Re = function* (t) {
|
|
61
61
|
const e = document.createNodeIterator(
|
|
62
62
|
t.commonAncestorContainer,
|
|
63
63
|
NodeFilter.SHOW_ELEMENT,
|
|
64
|
-
(o) => o instanceof HTMLElement && o.classList.contains(re) && !o.parentElement.closest(
|
|
64
|
+
(o) => o instanceof HTMLElement && o.classList.contains(re) && !o.parentElement.closest(nt) && t.intersectsNode(o) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
|
|
65
65
|
);
|
|
66
66
|
let n;
|
|
67
67
|
for (; n = e.nextNode(); )
|
|
@@ -79,20 +79,20 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
79
79
|
o.setStartAfter(n), o.collapsed || e.push(o);
|
|
80
80
|
}
|
|
81
81
|
return e.length > 0 ? e : [t];
|
|
82
|
-
},
|
|
82
|
+
}, Vt = (t) => {
|
|
83
83
|
const e = t.cloneContents();
|
|
84
|
-
return e.querySelectorAll(
|
|
85
|
-
},
|
|
84
|
+
return e.querySelectorAll(nt).forEach((n) => n.remove()), e;
|
|
85
|
+
}, ke = (t, e, n = 10, o) => {
|
|
86
86
|
const i = o ? t.startContainer.parentElement.closest(o) : e, s = document.createRange();
|
|
87
87
|
s.setStart(i, 0), s.setEnd(t.startContainer, t.startOffset);
|
|
88
|
-
const a =
|
|
88
|
+
const a = Vt(s).textContent, r = document.createRange();
|
|
89
89
|
r.setStart(t.endContainer, t.endOffset), i === document.body ? r.setEnd(i, i.childNodes.length) : r.setEndAfter(i);
|
|
90
|
-
const
|
|
90
|
+
const d = Vt(r).textContent;
|
|
91
91
|
return {
|
|
92
92
|
prefix: a.substring(a.length - n),
|
|
93
|
-
suffix:
|
|
93
|
+
suffix: d.substring(0, n)
|
|
94
94
|
};
|
|
95
|
-
}, q = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed),
|
|
95
|
+
}, q = (t) => t.every((e) => e.range instanceof Range && !e.range.collapsed), Be = /^\s*$/, Ie = (t) => Be.test(t.toString()), Ue = (t, e) => {
|
|
96
96
|
const n = (s) => Math.round(s * 10) / 10, o = {
|
|
97
97
|
top: n(t.top),
|
|
98
98
|
bottom: n(t.bottom),
|
|
@@ -116,7 +116,7 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
116
116
|
return "block-contains";
|
|
117
117
|
} else if (o.top >= i.top && o.bottom <= i.bottom && o.left >= i.left && o.right <= i.right)
|
|
118
118
|
return "block-is-contained";
|
|
119
|
-
},
|
|
119
|
+
}, _e = (t, e) => {
|
|
120
120
|
const n = Math.min(t.left, e.left), o = Math.max(t.right, e.right), i = Math.min(t.top, e.top), s = Math.max(t.bottom, e.bottom);
|
|
121
121
|
return new DOMRect(n, i, o - n, s - i);
|
|
122
122
|
}, Ne = (t) => t.reduce((e, n) => {
|
|
@@ -124,9 +124,9 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
124
124
|
return e;
|
|
125
125
|
let o = [...e], i = !1;
|
|
126
126
|
for (const s of e) {
|
|
127
|
-
const a =
|
|
127
|
+
const a = Ue(n, s);
|
|
128
128
|
if (a === "inline-adjacent") {
|
|
129
|
-
o = o.map((r) => r === s ?
|
|
129
|
+
o = o.map((r) => r === s ? _e(n, s) : r), i = !0;
|
|
130
130
|
break;
|
|
131
131
|
} else if (a === "inline-contains") {
|
|
132
132
|
o = o.map((r) => r === s ? n : r), i = !0;
|
|
@@ -140,7 +140,7 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
return i ? o : [...o, n];
|
|
143
|
-
}, []),
|
|
143
|
+
}, []), xo = (t) => ({
|
|
144
144
|
length: t.length,
|
|
145
145
|
item: (e) => t[e],
|
|
146
146
|
[Symbol.iterator]: function* () {
|
|
@@ -150,41 +150,41 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
150
150
|
}), Ve = (t, e, n) => {
|
|
151
151
|
const o = document.createRange(), i = n ? t.startContainer.parentElement.closest(n) : e;
|
|
152
152
|
o.setStart(i, 0), o.setEnd(t.startContainer, t.startOffset);
|
|
153
|
-
const s =
|
|
154
|
-
return n ? { quote: a, start: r, end:
|
|
153
|
+
const s = Vt(o).textContent, a = t.toString(), r = s.length || 0, d = r + a.length;
|
|
154
|
+
return n ? { quote: a, start: r, end: d, range: t, offsetReference: i } : { quote: a, start: r, end: d, range: t };
|
|
155
155
|
}, ae = (t, e) => {
|
|
156
|
-
var
|
|
156
|
+
var g, u;
|
|
157
157
|
const { start: n, end: o } = t, i = t.offsetReference || e, s = document.createNodeIterator(
|
|
158
158
|
e,
|
|
159
159
|
NodeFilter.SHOW_TEXT,
|
|
160
|
-
(
|
|
160
|
+
(h) => {
|
|
161
161
|
var v;
|
|
162
|
-
return (v =
|
|
162
|
+
return (v = h.parentElement) != null && v.closest(nt) ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
|
|
163
163
|
}
|
|
164
164
|
);
|
|
165
165
|
let a = 0;
|
|
166
166
|
const r = document.createRange();
|
|
167
|
-
let
|
|
168
|
-
|
|
167
|
+
let d = s.nextNode();
|
|
168
|
+
d === null && console.error("Could not revive annotation target. Content missing.");
|
|
169
169
|
let f = !i;
|
|
170
|
-
for (;
|
|
171
|
-
if (f || (f = typeof (i == null ? void 0 : i.contains) == "function" ? i.contains(
|
|
172
|
-
const
|
|
173
|
-
if (a +
|
|
174
|
-
r.setStart(
|
|
170
|
+
for (; d !== null; ) {
|
|
171
|
+
if (f || (f = typeof (i == null ? void 0 : i.contains) == "function" ? i.contains(d) : !1), f) {
|
|
172
|
+
const h = ((g = d.textContent) == null ? void 0 : g.length) || 0;
|
|
173
|
+
if (a + h > n) {
|
|
174
|
+
r.setStart(d, n - a);
|
|
175
175
|
break;
|
|
176
176
|
}
|
|
177
|
-
a +=
|
|
177
|
+
a += h;
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
d = s.nextNode();
|
|
180
180
|
}
|
|
181
|
-
for (;
|
|
182
|
-
const
|
|
183
|
-
if (a +
|
|
184
|
-
r.setEnd(
|
|
181
|
+
for (; d !== null; ) {
|
|
182
|
+
const h = ((u = d.textContent) == null ? void 0 : u.length) || 0;
|
|
183
|
+
if (a + h >= o) {
|
|
184
|
+
r.setEnd(d, o - a);
|
|
185
185
|
break;
|
|
186
186
|
}
|
|
187
|
-
a +=
|
|
187
|
+
a += h, d = s.nextNode();
|
|
188
188
|
}
|
|
189
189
|
return {
|
|
190
190
|
...t,
|
|
@@ -193,19 +193,19 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
193
193
|
}, At = (t, e) => q(t.selector) ? t : {
|
|
194
194
|
...t,
|
|
195
195
|
selector: t.selector.map((n) => n.range instanceof Range && !n.range.collapsed ? n : ae(n, e))
|
|
196
|
-
},
|
|
196
|
+
}, St = (t, e) => q(t.target.selector) ? t : { ...t, target: At(t.target, e) }, De = (t, e) => {
|
|
197
197
|
const n = t.cloneRange();
|
|
198
198
|
return e.contains(n.startContainer) || n.setStart(e, 0), e.contains(n.endContainer) || n.setEnd(e, e.childNodes.length), n;
|
|
199
|
-
},
|
|
199
|
+
}, le = (t) => {
|
|
200
200
|
if (t === null)
|
|
201
201
|
return document.scrollingElement;
|
|
202
202
|
const { overflowY: e } = window.getComputedStyle(t);
|
|
203
|
-
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t :
|
|
204
|
-
},
|
|
205
|
-
const o = typeof n == "string" ? n : n.id, i = (
|
|
206
|
-
const u = s.getBoundingClientRect(),
|
|
207
|
-
s.scroll({ top: E, left:
|
|
208
|
-
}, s =
|
|
203
|
+
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : le(t.parentElement);
|
|
204
|
+
}, Ke = (t, e) => (n) => {
|
|
205
|
+
const o = typeof n == "string" ? n : n.id, i = (g) => {
|
|
206
|
+
const u = s.getBoundingClientRect(), h = s.clientHeight, v = s.clientWidth, b = g.selector[0].range.getBoundingClientRect(), { width: p, height: x } = e.getAnnotationBounds(o), c = b.top - u.top, l = b.left - u.left, m = s.parentElement ? s.scrollTop : 0, S = s.parentElement ? s.scrollLeft : 0, E = c + m - (h - x) / 2, L = l + S - (v - p) / 2;
|
|
207
|
+
s.scroll({ top: E, left: L, behavior: "smooth" });
|
|
208
|
+
}, s = le(t);
|
|
209
209
|
if (!s)
|
|
210
210
|
return console.warn(`The scroll parent is missing for the annotation: ${o}`, { container: t }), !1;
|
|
211
211
|
const a = e.getAnnotation(o);
|
|
@@ -214,21 +214,21 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
214
214
|
const { range: r } = a.target.selector[0];
|
|
215
215
|
if (r && !r.collapsed)
|
|
216
216
|
return i(a.target), !0;
|
|
217
|
-
const
|
|
218
|
-
return f && !f.collapsed ? (i(
|
|
217
|
+
const d = At(a.target, t), { range: f } = d.selector[0];
|
|
218
|
+
return f && !f.collapsed ? (i(d), !0) : !1;
|
|
219
219
|
}, G = {
|
|
220
220
|
fill: "rgb(0, 128, 255)",
|
|
221
221
|
fillOpacity: 0.18
|
|
222
|
-
},
|
|
222
|
+
}, vt = {
|
|
223
223
|
fill: "rgb(0, 128, 255)",
|
|
224
224
|
fillOpacity: 0.45
|
|
225
|
-
},
|
|
225
|
+
}, Ye = (t, e, n, o, i) => {
|
|
226
226
|
var a, r;
|
|
227
|
-
const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ?
|
|
227
|
+
const s = n ? typeof n == "function" ? n(t.annotation, t.state, i) || ((a = t.state) != null && a.selected ? vt : G) : n : (r = t.state) != null && r.selected ? vt : G;
|
|
228
228
|
return o && o.paint(t, e) || s;
|
|
229
229
|
}, Xe = (t) => {
|
|
230
|
-
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n,
|
|
231
|
-
return { top: e, left: n, minX: s, minY: a, maxX: r, maxY:
|
|
230
|
+
const { top: e, left: n } = t.getBoundingClientRect(), { innerWidth: o, innerHeight: i } = window, s = -n, a = -e, r = o - n, d = i - e;
|
|
231
|
+
return { top: e, left: n, minX: s, minY: a, maxX: r, maxY: d };
|
|
232
232
|
}, Pe = (t) => {
|
|
233
233
|
let e = /* @__PURE__ */ new Set();
|
|
234
234
|
return (o) => {
|
|
@@ -237,45 +237,49 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
237
237
|
};
|
|
238
238
|
}, Yt = (t, e, n, o) => {
|
|
239
239
|
const { store: i, selection: s, hover: a } = e;
|
|
240
|
-
let r,
|
|
241
|
-
const
|
|
242
|
-
const { x: T, y:
|
|
243
|
-
|
|
240
|
+
let r, d, f;
|
|
241
|
+
const g = Pe(n), u = (V) => {
|
|
242
|
+
const { x: T, y: M } = t.getBoundingClientRect(), y = i.getAt(V.clientX - T, V.clientY - M, !1, d);
|
|
243
|
+
y ? a.current !== y.id && (t.classList.add("hovered"), a.set(y.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
|
|
244
244
|
};
|
|
245
245
|
t.addEventListener("pointermove", u);
|
|
246
|
-
const
|
|
246
|
+
const h = (V = !1) => {
|
|
247
247
|
f && f.clear();
|
|
248
|
-
const T = Xe(t), { minX:
|
|
249
|
-
const
|
|
250
|
-
return {
|
|
248
|
+
const T = Xe(t), { minX: M, minY: y, maxX: w, maxY: A } = T, C = d ? i.getIntersecting(M, y, w, A).filter(({ annotation: k }) => d(k)) : i.getIntersecting(M, y, w, A), I = s.selected.map(({ id: k }) => k), O = C.map(({ annotation: k, rects: P }) => {
|
|
249
|
+
const Q = I.includes(k.id), Se = k.id === a.current;
|
|
250
|
+
return {
|
|
251
|
+
annotation: k,
|
|
252
|
+
rects: P,
|
|
253
|
+
state: { selected: Q, hovered: Se }
|
|
254
|
+
};
|
|
251
255
|
});
|
|
252
|
-
o.redraw(
|
|
253
|
-
}, v = (
|
|
254
|
-
f =
|
|
255
|
-
},
|
|
256
|
-
r =
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
},
|
|
260
|
-
i.observe(
|
|
261
|
-
const
|
|
262
|
-
document.addEventListener("scroll",
|
|
263
|
-
const
|
|
264
|
-
i.recalculatePositions(), f && f.reset(),
|
|
256
|
+
o.redraw(O, T, r, f, V), setTimeout(() => g(C.map(({ annotation: k }) => k)), 1);
|
|
257
|
+
}, v = (V) => {
|
|
258
|
+
f = V, h();
|
|
259
|
+
}, b = (V) => {
|
|
260
|
+
r = V, h();
|
|
261
|
+
}, p = (V) => {
|
|
262
|
+
d = V, h(!1);
|
|
263
|
+
}, x = () => h();
|
|
264
|
+
i.observe(x);
|
|
265
|
+
const c = s.subscribe(() => h()), l = a.subscribe(() => h()), m = () => h(!0);
|
|
266
|
+
document.addEventListener("scroll", m, { capture: !0, passive: !0 });
|
|
267
|
+
const S = Kt(() => {
|
|
268
|
+
i.recalculatePositions(), f && f.reset(), h();
|
|
265
269
|
});
|
|
266
|
-
window.addEventListener("resize",
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
|
|
270
|
+
window.addEventListener("resize", S);
|
|
271
|
+
const E = new ResizeObserver(S);
|
|
272
|
+
E.observe(t);
|
|
273
|
+
const L = { attributes: !0, childList: !0, subtree: !0 }, R = new MutationObserver((V) => {
|
|
274
|
+
V.every((M) => M.target === t || t.contains(M.target)) || h(!0);
|
|
271
275
|
});
|
|
272
|
-
return
|
|
276
|
+
return R.observe(document.body, L), {
|
|
273
277
|
destroy: () => {
|
|
274
|
-
t.removeEventListener("pointermove", u), o.destroy(), i.unobserve(
|
|
278
|
+
t.removeEventListener("pointermove", u), o.destroy(), i.unobserve(x), c(), l(), document.removeEventListener("scroll", m), window.removeEventListener("resize", S), E.disconnect(), R.disconnect();
|
|
275
279
|
},
|
|
276
|
-
redraw:
|
|
277
|
-
setStyle:
|
|
278
|
-
setFilter:
|
|
280
|
+
redraw: h,
|
|
281
|
+
setStyle: b,
|
|
282
|
+
setFilter: p,
|
|
279
283
|
setPainter: v,
|
|
280
284
|
setVisible: o.setVisible
|
|
281
285
|
};
|
|
@@ -288,32 +292,32 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
288
292
|
t.classList.add("r6o-annotatable");
|
|
289
293
|
const e = $e(), n = e.getContext("2d");
|
|
290
294
|
document.body.appendChild(e);
|
|
291
|
-
const o = (r,
|
|
292
|
-
const { width: u, height:
|
|
293
|
-
n.clearRect(-0.5, -0.5, u + 1,
|
|
294
|
-
const { top: v, left:
|
|
295
|
-
[...r].sort((
|
|
296
|
-
const { annotation: { target: { created:
|
|
297
|
-
return
|
|
298
|
-
}).forEach((
|
|
295
|
+
const o = (r, d, f, g) => requestAnimationFrame(() => {
|
|
296
|
+
const { width: u, height: h } = e;
|
|
297
|
+
n.clearRect(-0.5, -0.5, u + 1, h + 1), g && g.clear();
|
|
298
|
+
const { top: v, left: b } = d;
|
|
299
|
+
[...r].sort((x, c) => {
|
|
300
|
+
const { annotation: { target: { created: l } } } = x, { annotation: { target: { created: m } } } = c;
|
|
301
|
+
return l.getTime() - m.getTime();
|
|
302
|
+
}).forEach((x) => {
|
|
299
303
|
var S;
|
|
300
|
-
const
|
|
301
|
-
x: E +
|
|
302
|
-
y:
|
|
304
|
+
const c = f ? typeof f == "function" ? f(x.annotation, x.state) : f : (S = x.state) != null && S.selected ? vt : G, l = g && g.paint(x, d) || c, m = x.rects.map(({ x: E, y: L, width: R, height: U }) => ({
|
|
305
|
+
x: E + b,
|
|
306
|
+
y: L + v,
|
|
303
307
|
width: R,
|
|
304
|
-
height:
|
|
308
|
+
height: U
|
|
305
309
|
}));
|
|
306
|
-
if (n.fillStyle =
|
|
307
|
-
({ x: E, y:
|
|
308
|
-
),
|
|
309
|
-
n.globalAlpha = 1, n.strokeStyle =
|
|
310
|
-
const E =
|
|
311
|
-
|
|
312
|
-
n.beginPath(), n.moveTo(
|
|
310
|
+
if (n.fillStyle = l.fill, n.globalAlpha = l.fillOpacity || 1, m.forEach(
|
|
311
|
+
({ x: E, y: L, width: R, height: U }) => n.fillRect(E, L, R, U)
|
|
312
|
+
), l.underlineColor) {
|
|
313
|
+
n.globalAlpha = 1, n.strokeStyle = l.underlineColor, n.lineWidth = l.underlineThickness ?? 1;
|
|
314
|
+
const E = l.underlineOffset ?? 0;
|
|
315
|
+
m.forEach(({ x: L, y: R, width: U, height: V }) => {
|
|
316
|
+
n.beginPath(), n.moveTo(L, R + V + E), n.lineTo(L + U, R + V + E), n.stroke();
|
|
313
317
|
});
|
|
314
318
|
}
|
|
315
319
|
});
|
|
316
|
-
}), i =
|
|
320
|
+
}), i = Kt(() => {
|
|
317
321
|
He(e);
|
|
318
322
|
});
|
|
319
323
|
return window.addEventListener("resize", i), {
|
|
@@ -328,16 +332,16 @@ const re = "not-annotatable", et = `.${re}`, it = (t) => {
|
|
|
328
332
|
}, ze = (t, e, n) => Yt(t, e, n, je(t));
|
|
329
333
|
var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
|
|
330
334
|
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
331
|
-
},
|
|
335
|
+
}, D = function(t, e, n) {
|
|
332
336
|
return e === void 0 && (e = 0), n === void 0 && (n = Math.pow(10, e)), Math.round(n * t) / n + 0;
|
|
333
337
|
}, $ = function(t, e, n) {
|
|
334
338
|
return e === void 0 && (e = 0), n === void 0 && (n = 1), t > n ? n : t > e ? t : e;
|
|
335
|
-
},
|
|
339
|
+
}, ce = function(t) {
|
|
336
340
|
return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
|
|
337
|
-
},
|
|
341
|
+
}, $t = function(t) {
|
|
338
342
|
return { r: $(t.r, 0, 255), g: $(t.g, 0, 255), b: $(t.b, 0, 255), a: $(t.a) };
|
|
339
|
-
},
|
|
340
|
-
return { r:
|
|
343
|
+
}, Ct = function(t) {
|
|
344
|
+
return { r: D(t.r), g: D(t.g), b: D(t.b), a: D(t.a, 3) };
|
|
341
345
|
}, We = /^#([0-9a-f]{3,8})$/i, pt = function(t) {
|
|
342
346
|
var e = t.toString(16);
|
|
343
347
|
return e.length < 2 ? "0" + e : e;
|
|
@@ -347,114 +351,114 @@ var Fe = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, F = function(t) {
|
|
|
347
351
|
}, ue = function(t) {
|
|
348
352
|
var e = t.h, n = t.s, o = t.v, i = t.a;
|
|
349
353
|
e = e / 360 * 6, n /= 100, o /= 100;
|
|
350
|
-
var s = Math.floor(e), a = o * (1 - n), r = o * (1 - (e - s) * n),
|
|
351
|
-
return { r: 255 * [o, r, a, a,
|
|
352
|
-
}, $t = function(t) {
|
|
353
|
-
return { h: le(t.h), s: $(t.s, 0, 100), l: $(t.l, 0, 100), a: $(t.a) };
|
|
354
|
+
var s = Math.floor(e), a = o * (1 - n), r = o * (1 - (e - s) * n), d = o * (1 - (1 - e + s) * n), f = s % 6;
|
|
355
|
+
return { r: 255 * [o, r, a, a, d, o][f], g: 255 * [d, o, o, r, a, a][f], b: 255 * [a, a, d, o, o, r][f], a: i };
|
|
354
356
|
}, Ht = function(t) {
|
|
355
|
-
return { h:
|
|
357
|
+
return { h: ce(t.h), s: $(t.s, 0, 100), l: $(t.l, 0, 100), a: $(t.a) };
|
|
356
358
|
}, jt = function(t) {
|
|
359
|
+
return { h: D(t.h), s: D(t.s), l: D(t.l), a: D(t.a, 3) };
|
|
360
|
+
}, zt = function(t) {
|
|
357
361
|
return ue((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 }));
|
|
358
362
|
var e, n, o;
|
|
359
|
-
},
|
|
363
|
+
}, dt = function(t) {
|
|
360
364
|
return { h: (e = de(t)).h, s: (i = (200 - (n = e.s)) * (o = e.v) / 100) > 0 && i < 200 ? n * o / 100 / (i <= 100 ? i : 200 - i) * 100 : 0, l: i / 2, a: e.a };
|
|
361
365
|
var e, n, o, i;
|
|
362
|
-
}, qe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Qe = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Je = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,
|
|
366
|
+
}, qe = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ge = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Qe = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Je = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Ft = { string: [[function(t) {
|
|
363
367
|
var e = We.exec(t);
|
|
364
|
-
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 ?
|
|
368
|
+
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 ? D(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 ? D(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
|
|
365
369
|
}, "hex"], [function(t) {
|
|
366
370
|
var e = Qe.exec(t) || Je.exec(t);
|
|
367
|
-
return e ? e[2] !== e[4] || e[4] !== e[6] ? null :
|
|
371
|
+
return e ? e[2] !== e[4] || e[4] !== e[6] ? null : $t({ 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;
|
|
368
372
|
}, "rgb"], [function(t) {
|
|
369
373
|
var e = qe.exec(t) || Ge.exec(t);
|
|
370
374
|
if (!e) return null;
|
|
371
|
-
var n, o, i =
|
|
372
|
-
return
|
|
375
|
+
var n, o, i = Ht({ h: (n = e[1], o = e[2], o === void 0 && (o = "deg"), Number(n) * (Fe[o] || 1)), s: Number(e[3]), l: Number(e[4]), a: e[5] === void 0 ? 1 : Number(e[5]) / (e[6] ? 100 : 1) });
|
|
376
|
+
return zt(i);
|
|
373
377
|
}, "hsl"]], object: [[function(t) {
|
|
374
378
|
var e = t.r, n = t.g, o = t.b, i = t.a, s = i === void 0 ? 1 : i;
|
|
375
|
-
return F(e) && F(n) && F(o) ?
|
|
379
|
+
return F(e) && F(n) && F(o) ? $t({ r: Number(e), g: Number(n), b: Number(o), a: Number(s) }) : null;
|
|
376
380
|
}, "rgb"], [function(t) {
|
|
377
381
|
var e = t.h, n = t.s, o = t.l, i = t.a, s = i === void 0 ? 1 : i;
|
|
378
382
|
if (!F(e) || !F(n) || !F(o)) return null;
|
|
379
|
-
var a =
|
|
380
|
-
return
|
|
383
|
+
var a = Ht({ h: Number(e), s: Number(n), l: Number(o), a: Number(s) });
|
|
384
|
+
return zt(a);
|
|
381
385
|
}, "hsl"], [function(t) {
|
|
382
386
|
var e = t.h, n = t.s, o = t.v, i = t.a, s = i === void 0 ? 1 : i;
|
|
383
387
|
if (!F(e) || !F(n) || !F(o)) return null;
|
|
384
|
-
var a = function(r) {
|
|
385
|
-
return { h:
|
|
386
|
-
}({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
|
|
388
|
+
var a = (function(r) {
|
|
389
|
+
return { h: ce(r.h), s: $(r.s, 0, 100), v: $(r.v, 0, 100), a: $(r.a) };
|
|
390
|
+
})({ h: Number(e), s: Number(n), v: Number(o), a: Number(s) });
|
|
387
391
|
return ue(a);
|
|
388
|
-
}, "hsv"]] },
|
|
392
|
+
}, "hsv"]] }, Wt = function(t, e) {
|
|
389
393
|
for (var n = 0; n < e.length; n++) {
|
|
390
394
|
var o = e[n][0](t);
|
|
391
395
|
if (o) return [o, e[n][1]];
|
|
392
396
|
}
|
|
393
397
|
return [null, void 0];
|
|
394
398
|
}, Ze = function(t) {
|
|
395
|
-
return typeof t == "string" ?
|
|
396
|
-
},
|
|
397
|
-
var n =
|
|
399
|
+
return typeof t == "string" ? Wt(t.trim(), Ft.string) : typeof t == "object" && t !== null ? Wt(t, Ft.object) : [null, void 0];
|
|
400
|
+
}, Lt = function(t, e) {
|
|
401
|
+
var n = dt(t);
|
|
398
402
|
return { h: n.h, s: $(n.s + 100 * e, 0, 100), l: n.l, a: n.a };
|
|
399
|
-
},
|
|
403
|
+
}, Tt = function(t) {
|
|
400
404
|
return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
|
|
401
|
-
},
|
|
402
|
-
var n =
|
|
405
|
+
}, qt = function(t, e) {
|
|
406
|
+
var n = dt(t);
|
|
403
407
|
return { h: n.h, s: n.s, l: $(n.l + 100 * e, 0, 100), a: n.a };
|
|
404
|
-
},
|
|
408
|
+
}, Gt = (function() {
|
|
405
409
|
function t(e) {
|
|
406
410
|
this.parsed = Ze(e)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
|
|
407
411
|
}
|
|
408
412
|
return t.prototype.isValid = function() {
|
|
409
413
|
return this.parsed !== null;
|
|
410
414
|
}, t.prototype.brightness = function() {
|
|
411
|
-
return
|
|
415
|
+
return D(Tt(this.rgba), 2);
|
|
412
416
|
}, t.prototype.isDark = function() {
|
|
413
|
-
return
|
|
417
|
+
return Tt(this.rgba) < 0.5;
|
|
414
418
|
}, t.prototype.isLight = function() {
|
|
415
|
-
return
|
|
419
|
+
return Tt(this.rgba) >= 0.5;
|
|
416
420
|
}, t.prototype.toHex = function() {
|
|
417
|
-
return e =
|
|
421
|
+
return e = Ct(this.rgba), n = e.r, o = e.g, i = e.b, a = (s = e.a) < 1 ? pt(D(255 * s)) : "", "#" + pt(n) + pt(o) + pt(i) + a;
|
|
418
422
|
var e, n, o, i, s, a;
|
|
419
423
|
}, t.prototype.toRgb = function() {
|
|
420
|
-
return
|
|
424
|
+
return Ct(this.rgba);
|
|
421
425
|
}, t.prototype.toRgbString = function() {
|
|
422
|
-
return e =
|
|
426
|
+
return e = Ct(this.rgba), n = e.r, o = e.g, i = e.b, (s = e.a) < 1 ? "rgba(" + n + ", " + o + ", " + i + ", " + s + ")" : "rgb(" + n + ", " + o + ", " + i + ")";
|
|
423
427
|
var e, n, o, i, s;
|
|
424
428
|
}, t.prototype.toHsl = function() {
|
|
425
|
-
return
|
|
429
|
+
return jt(dt(this.rgba));
|
|
426
430
|
}, t.prototype.toHslString = function() {
|
|
427
|
-
return e =
|
|
431
|
+
return e = jt(dt(this.rgba)), n = e.h, o = e.s, i = e.l, (s = e.a) < 1 ? "hsla(" + n + ", " + o + "%, " + i + "%, " + s + ")" : "hsl(" + n + ", " + o + "%, " + i + "%)";
|
|
428
432
|
var e, n, o, i, s;
|
|
429
433
|
}, t.prototype.toHsv = function() {
|
|
430
|
-
return e = de(this.rgba), { h:
|
|
434
|
+
return e = de(this.rgba), { h: D(e.h), s: D(e.s), v: D(e.v), a: D(e.a, 3) };
|
|
431
435
|
var e;
|
|
432
436
|
}, t.prototype.invert = function() {
|
|
433
437
|
return j({ r: 255 - (e = this.rgba).r, g: 255 - e.g, b: 255 - e.b, a: e.a });
|
|
434
438
|
var e;
|
|
435
439
|
}, t.prototype.saturate = function(e) {
|
|
436
|
-
return e === void 0 && (e = 0.1), j(
|
|
440
|
+
return e === void 0 && (e = 0.1), j(Lt(this.rgba, e));
|
|
437
441
|
}, t.prototype.desaturate = function(e) {
|
|
438
|
-
return e === void 0 && (e = 0.1), j(
|
|
442
|
+
return e === void 0 && (e = 0.1), j(Lt(this.rgba, -e));
|
|
439
443
|
}, t.prototype.grayscale = function() {
|
|
440
|
-
return j(
|
|
444
|
+
return j(Lt(this.rgba, -1));
|
|
441
445
|
}, t.prototype.lighten = function(e) {
|
|
442
|
-
return e === void 0 && (e = 0.1), j(
|
|
446
|
+
return e === void 0 && (e = 0.1), j(qt(this.rgba, e));
|
|
443
447
|
}, t.prototype.darken = function(e) {
|
|
444
|
-
return e === void 0 && (e = 0.1), j(
|
|
448
|
+
return e === void 0 && (e = 0.1), j(qt(this.rgba, -e));
|
|
445
449
|
}, t.prototype.rotate = function(e) {
|
|
446
450
|
return e === void 0 && (e = 15), this.hue(this.hue() + e);
|
|
447
451
|
}, t.prototype.alpha = function(e) {
|
|
448
|
-
return typeof e == "number" ? j({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) :
|
|
452
|
+
return typeof e == "number" ? j({ r: (n = this.rgba).r, g: n.g, b: n.b, a: e }) : D(this.rgba.a, 3);
|
|
449
453
|
var n;
|
|
450
454
|
}, t.prototype.hue = function(e) {
|
|
451
|
-
var n =
|
|
452
|
-
return typeof e == "number" ? j({ h: e, s: n.s, l: n.l, a: n.a }) :
|
|
455
|
+
var n = dt(this.rgba);
|
|
456
|
+
return typeof e == "number" ? j({ h: e, s: n.s, l: n.l, a: n.a }) : D(n.h);
|
|
453
457
|
}, t.prototype.isEqual = function(e) {
|
|
454
458
|
return this.toHex() === j(e).toHex();
|
|
455
459
|
}, t;
|
|
456
|
-
}(), j = function(t) {
|
|
457
|
-
return t instanceof
|
|
460
|
+
})(), j = function(t) {
|
|
461
|
+
return t instanceof Gt ? t : new Gt(t);
|
|
458
462
|
};
|
|
459
463
|
const tn = (t) => [
|
|
460
464
|
`background-color:${j((t == null ? void 0 : t.fill) || G.fill).alpha((t == null ? void 0 : t.fillOpacity) === void 0 ? G.fillOpacity : t.fillOpacity).toHex()}`,
|
|
@@ -473,25 +477,25 @@ const tn = (t) => [
|
|
|
473
477
|
setVisible: (s) => {
|
|
474
478
|
console.log("setVisible not implemented on CSS Custom Highlights renderer");
|
|
475
479
|
},
|
|
476
|
-
redraw: (s, a, r,
|
|
477
|
-
|
|
480
|
+
redraw: (s, a, r, d) => {
|
|
481
|
+
d && d.clear();
|
|
478
482
|
const f = new Set(s.map((u) => u.annotation.id));
|
|
479
483
|
Array.from(e).filter((u) => !f.has(u));
|
|
480
|
-
const
|
|
481
|
-
var
|
|
482
|
-
const
|
|
484
|
+
const g = s.map((u) => {
|
|
485
|
+
var b;
|
|
486
|
+
const h = r ? typeof r == "function" ? r(u.annotation, u.state) : r : (b = u.state) != null && b.selected ? vt : G, v = d && d.paint(u, a) || h;
|
|
483
487
|
return `::highlight(_${u.annotation.id}) { ${tn(v)} }`;
|
|
484
488
|
});
|
|
485
|
-
t.innerHTML =
|
|
489
|
+
t.innerHTML = g.join(`
|
|
486
490
|
`), CSS.highlights.clear(), s.forEach(({ annotation: u }) => {
|
|
487
|
-
const
|
|
491
|
+
const h = u.target.selector.map((b) => b.range), v = new Highlight(...h);
|
|
488
492
|
CSS.highlights.set(`_${u.id}`, v);
|
|
489
493
|
}), e = f;
|
|
490
494
|
}
|
|
491
495
|
};
|
|
492
496
|
}, nn = (t, e, n) => Yt(t, e, n, en());
|
|
493
|
-
var
|
|
494
|
-
function
|
|
497
|
+
var Qt = Object.prototype.hasOwnProperty;
|
|
498
|
+
function Dt(t, e) {
|
|
495
499
|
var n, o;
|
|
496
500
|
if (t === e) return !0;
|
|
497
501
|
if (t && e && (n = t.constructor) === e.constructor) {
|
|
@@ -499,13 +503,13 @@ function Vt(t, e) {
|
|
|
499
503
|
if (n === RegExp) return t.toString() === e.toString();
|
|
500
504
|
if (n === Array) {
|
|
501
505
|
if ((o = t.length) === e.length)
|
|
502
|
-
for (; o-- &&
|
|
506
|
+
for (; o-- && Dt(t[o], e[o]); ) ;
|
|
503
507
|
return o === -1;
|
|
504
508
|
}
|
|
505
509
|
if (!n || typeof t == "object") {
|
|
506
510
|
o = 0;
|
|
507
511
|
for (n in t)
|
|
508
|
-
if (
|
|
512
|
+
if (Qt.call(t, n) && ++o && !Qt.call(e, n) || !(n in e) || !Dt(t[n], e[n])) return !1;
|
|
509
513
|
return Object.keys(e).length === o;
|
|
510
514
|
}
|
|
511
515
|
}
|
|
@@ -523,18 +527,18 @@ const on = (t, e) => {
|
|
|
523
527
|
destroy: () => {
|
|
524
528
|
e.remove();
|
|
525
529
|
},
|
|
526
|
-
redraw: (a, r,
|
|
527
|
-
const
|
|
528
|
-
if (!f && !
|
|
529
|
-
|
|
530
|
-
const { annotation: { target: { created:
|
|
531
|
-
return
|
|
532
|
-
}).forEach((
|
|
533
|
-
|
|
534
|
-
const
|
|
535
|
-
if (
|
|
536
|
-
const
|
|
537
|
-
|
|
530
|
+
redraw: (a, r, d, f, g) => {
|
|
531
|
+
const h = !(Dt(n, a) && g);
|
|
532
|
+
if (!f && !h) return;
|
|
533
|
+
h && (e.innerHTML = ""), [...a].sort((b, p) => {
|
|
534
|
+
const { annotation: { target: { created: x } } } = b, { annotation: { target: { created: c } } } = p;
|
|
535
|
+
return x && c ? x.getTime() - c.getTime() : 0;
|
|
536
|
+
}).forEach((b) => {
|
|
537
|
+
b.rects.map((p) => {
|
|
538
|
+
const x = on(p, a), c = Ye(b, r, d, f, x);
|
|
539
|
+
if (h) {
|
|
540
|
+
const l = document.createElement("span");
|
|
541
|
+
l.className = "r6o-annotation", l.dataset.annotation = b.annotation.id, l.style.left = `${p.x}px`, l.style.top = `${p.y}px`, l.style.width = `${p.width}px`, l.style.height = `${p.height}px`, l.style.backgroundColor = j((c == null ? void 0 : c.fill) || G.fill).alpha((c == null ? void 0 : c.fillOpacity) === void 0 ? G.fillOpacity : c.fillOpacity).toHex(), c.underlineStyle && (l.style.borderStyle = c.underlineStyle), c.underlineColor && (l.style.borderColor = c.underlineColor), c.underlineThickness && (l.style.borderBottomWidth = `${c.underlineThickness}px`), c.underlineOffset && (l.style.paddingBottom = `${c.underlineOffset}px`), e.appendChild(l);
|
|
538
542
|
}
|
|
539
543
|
});
|
|
540
544
|
}), n = a;
|
|
@@ -543,35 +547,35 @@ const on = (t, e) => {
|
|
|
543
547
|
a ? e.classList.remove("hidden") : e.classList.add("hidden");
|
|
544
548
|
}
|
|
545
549
|
};
|
|
546
|
-
}, rn = (t, e, n) => Yt(t, e, n, sn(t)),
|
|
550
|
+
}, rn = (t, e, n) => Yt(t, e, n, sn(t)), K = [];
|
|
547
551
|
for (let t = 0; t < 256; ++t)
|
|
548
|
-
|
|
552
|
+
K.push((t + 256).toString(16).slice(1));
|
|
549
553
|
function an(t, e = 0) {
|
|
550
|
-
return (
|
|
554
|
+
return (K[t[e + 0]] + K[t[e + 1]] + K[t[e + 2]] + K[t[e + 3]] + "-" + K[t[e + 4]] + K[t[e + 5]] + "-" + K[t[e + 6]] + K[t[e + 7]] + "-" + K[t[e + 8]] + K[t[e + 9]] + "-" + K[t[e + 10]] + K[t[e + 11]] + K[t[e + 12]] + K[t[e + 13]] + K[t[e + 14]] + K[t[e + 15]]).toLowerCase();
|
|
551
555
|
}
|
|
552
|
-
let
|
|
553
|
-
const
|
|
554
|
-
function
|
|
555
|
-
if (!
|
|
556
|
+
let Ot;
|
|
557
|
+
const ln = new Uint8Array(16);
|
|
558
|
+
function cn() {
|
|
559
|
+
if (!Ot) {
|
|
556
560
|
if (typeof crypto > "u" || !crypto.getRandomValues)
|
|
557
561
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
558
|
-
|
|
562
|
+
Ot = crypto.getRandomValues.bind(crypto);
|
|
559
563
|
}
|
|
560
|
-
return
|
|
564
|
+
return Ot(ln);
|
|
561
565
|
}
|
|
562
|
-
const dn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto),
|
|
566
|
+
const dn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Jt = { randomUUID: dn };
|
|
563
567
|
function fe(t, e, n) {
|
|
564
568
|
var i;
|
|
565
|
-
if (
|
|
566
|
-
return
|
|
569
|
+
if (Jt.randomUUID && !t)
|
|
570
|
+
return Jt.randomUUID();
|
|
567
571
|
t = t || {};
|
|
568
|
-
const o = t.random ?? ((i = t.rng) == null ? void 0 : i.call(t)) ??
|
|
572
|
+
const o = t.random ?? ((i = t.rng) == null ? void 0 : i.call(t)) ?? cn();
|
|
569
573
|
if (o.length < 16)
|
|
570
574
|
throw new Error("Random bytes length must be >= 16");
|
|
571
575
|
return o[6] = o[6] & 15 | 64, o[8] = o[8] & 63 | 128, an(o);
|
|
572
576
|
}
|
|
573
|
-
var
|
|
574
|
-
function
|
|
577
|
+
var Zt = Object.prototype.hasOwnProperty;
|
|
578
|
+
function J(t, e) {
|
|
575
579
|
var n, o;
|
|
576
580
|
if (t === e) return !0;
|
|
577
581
|
if (t && e && (n = t.constructor) === e.constructor) {
|
|
@@ -579,52 +583,52 @@ function Q(t, e) {
|
|
|
579
583
|
if (n === RegExp) return t.toString() === e.toString();
|
|
580
584
|
if (n === Array) {
|
|
581
585
|
if ((o = t.length) === e.length)
|
|
582
|
-
for (; o-- &&
|
|
586
|
+
for (; o-- && J(t[o], e[o]); ) ;
|
|
583
587
|
return o === -1;
|
|
584
588
|
}
|
|
585
589
|
if (!n || typeof t == "object") {
|
|
586
590
|
o = 0;
|
|
587
591
|
for (n in t)
|
|
588
|
-
if (
|
|
592
|
+
if (Zt.call(t, n) && ++o && !Zt.call(e, n) || !(n in e) || !J(t[n], e[n])) return !1;
|
|
589
593
|
return Object.keys(e).length === o;
|
|
590
594
|
}
|
|
591
595
|
}
|
|
592
596
|
return t !== t && e !== e;
|
|
593
597
|
}
|
|
594
|
-
function
|
|
598
|
+
function Rt() {
|
|
595
599
|
}
|
|
596
600
|
function un(t, e) {
|
|
597
601
|
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
598
602
|
}
|
|
599
|
-
const
|
|
600
|
-
function
|
|
603
|
+
const Z = [];
|
|
604
|
+
function Xt(t, e = Rt) {
|
|
601
605
|
let n;
|
|
602
606
|
const o = /* @__PURE__ */ new Set();
|
|
603
607
|
function i(r) {
|
|
604
608
|
if (un(t, r) && (t = r, n)) {
|
|
605
|
-
const
|
|
609
|
+
const d = !Z.length;
|
|
606
610
|
for (const f of o)
|
|
607
|
-
f[1](),
|
|
608
|
-
if (
|
|
609
|
-
for (let f = 0; f <
|
|
610
|
-
|
|
611
|
-
|
|
611
|
+
f[1](), Z.push(f, t);
|
|
612
|
+
if (d) {
|
|
613
|
+
for (let f = 0; f < Z.length; f += 2)
|
|
614
|
+
Z[f][0](Z[f + 1]);
|
|
615
|
+
Z.length = 0;
|
|
612
616
|
}
|
|
613
617
|
}
|
|
614
618
|
}
|
|
615
619
|
function s(r) {
|
|
616
620
|
i(r(t));
|
|
617
621
|
}
|
|
618
|
-
function a(r,
|
|
619
|
-
const f = [r,
|
|
620
|
-
return o.add(f), o.size === 1 && (n = e(i, s) ||
|
|
622
|
+
function a(r, d = Rt) {
|
|
623
|
+
const f = [r, d];
|
|
624
|
+
return o.add(f), o.size === 1 && (n = e(i, s) || Rt), r(t), () => {
|
|
621
625
|
o.delete(f), o.size === 0 && n && (n(), n = null);
|
|
622
626
|
};
|
|
623
627
|
}
|
|
624
628
|
return { set: i, update: s, subscribe: a };
|
|
625
629
|
}
|
|
626
630
|
const fn = (t) => {
|
|
627
|
-
const { subscribe: e, set: n } =
|
|
631
|
+
const { subscribe: e, set: n } = Xt();
|
|
628
632
|
let o;
|
|
629
633
|
return e((i) => o = i), t.observe(({ changes: i }) => {
|
|
630
634
|
if (o) {
|
|
@@ -641,58 +645,58 @@ const fn = (t) => {
|
|
|
641
645
|
};
|
|
642
646
|
};
|
|
643
647
|
var hn = /* @__PURE__ */ ((t) => (t.EDIT = "EDIT", t.SELECT = "SELECT", t.NONE = "NONE", t))(hn || {});
|
|
644
|
-
const
|
|
645
|
-
const { subscribe: o, set: i } =
|
|
646
|
-
let s = e, a =
|
|
647
|
-
o((
|
|
648
|
+
const mt = { selected: [] }, gn = (t, e, n) => {
|
|
649
|
+
const { subscribe: o, set: i } = Xt(mt);
|
|
650
|
+
let s = e, a = mt;
|
|
651
|
+
o((p) => a = p);
|
|
648
652
|
const r = () => {
|
|
649
|
-
|
|
650
|
-
},
|
|
651
|
-
var
|
|
652
|
-
return ((
|
|
653
|
-
}, f = (
|
|
654
|
-
if (
|
|
653
|
+
J(a, mt) || i(mt);
|
|
654
|
+
}, d = () => {
|
|
655
|
+
var p;
|
|
656
|
+
return ((p = a.selected) == null ? void 0 : p.length) === 0;
|
|
657
|
+
}, f = (p) => {
|
|
658
|
+
if (d())
|
|
655
659
|
return !1;
|
|
656
|
-
const
|
|
657
|
-
return a.selected.some((
|
|
658
|
-
},
|
|
659
|
-
let
|
|
660
|
-
if (Array.isArray(
|
|
661
|
-
if (
|
|
662
|
-
console.warn("Invalid selection: " +
|
|
660
|
+
const x = typeof p == "string" ? p : p.id;
|
|
661
|
+
return a.selected.some((c) => c.id === x);
|
|
662
|
+
}, g = (p, x) => {
|
|
663
|
+
let c;
|
|
664
|
+
if (Array.isArray(p)) {
|
|
665
|
+
if (c = p.map((m) => t.getAnnotation(m)).filter(Boolean), c.length < p.length) {
|
|
666
|
+
console.warn("Invalid selection: " + p.filter((m) => !c.some((S) => S.id === m)));
|
|
663
667
|
return;
|
|
664
668
|
}
|
|
665
669
|
} else {
|
|
666
|
-
const
|
|
667
|
-
if (!
|
|
668
|
-
console.warn("Invalid selection: " +
|
|
670
|
+
const m = t.getAnnotation(p);
|
|
671
|
+
if (!m) {
|
|
672
|
+
console.warn("Invalid selection: " + p);
|
|
669
673
|
return;
|
|
670
674
|
}
|
|
671
|
-
|
|
675
|
+
c = [m];
|
|
672
676
|
}
|
|
673
|
-
const
|
|
674
|
-
const
|
|
675
|
-
return
|
|
677
|
+
const l = c.reduce((m, S) => {
|
|
678
|
+
const E = b(S);
|
|
679
|
+
return E === "EDIT" ? [...m, { id: S.id, editable: !0 }] : E === "SELECT" ? [...m, { id: S.id }] : m;
|
|
676
680
|
}, []);
|
|
677
|
-
i({ selected:
|
|
678
|
-
}, u = (
|
|
679
|
-
const
|
|
681
|
+
i({ selected: l, event: x });
|
|
682
|
+
}, u = (p, x) => {
|
|
683
|
+
const c = Array.isArray(p) ? p : [p], l = c.map((m) => t.getAnnotation(m)).filter((m) => !!m);
|
|
680
684
|
i({
|
|
681
|
-
selected:
|
|
682
|
-
const
|
|
683
|
-
return { id:
|
|
685
|
+
selected: l.map((m) => {
|
|
686
|
+
const S = x === void 0 ? b(m) === "EDIT" : x;
|
|
687
|
+
return { id: m.id, editable: S };
|
|
684
688
|
})
|
|
685
|
-
}),
|
|
686
|
-
},
|
|
687
|
-
if (
|
|
689
|
+
}), l.length !== c.length && console.warn("Invalid selection", p);
|
|
690
|
+
}, h = (p) => {
|
|
691
|
+
if (d())
|
|
688
692
|
return !1;
|
|
689
|
-
const { selected:
|
|
690
|
-
|
|
691
|
-
}, v = (
|
|
692
|
-
s =
|
|
693
|
-
};
|
|
693
|
+
const { selected: x } = a;
|
|
694
|
+
x.some(({ id: c }) => p.includes(c)) && i({ selected: x.filter(({ id: c }) => !p.includes(c)) });
|
|
695
|
+
}, v = (p) => {
|
|
696
|
+
s = p, u(a.selected.map(({ id: x }) => x));
|
|
697
|
+
}, b = (p) => pn(p, s, n);
|
|
694
698
|
return t.observe(
|
|
695
|
-
({ changes:
|
|
699
|
+
({ changes: p }) => h((p.deleted || []).map((x) => x.id))
|
|
696
700
|
), {
|
|
697
701
|
get event() {
|
|
698
702
|
return a ? a.event : null;
|
|
@@ -704,44 +708,45 @@ const gt = { selected: [] }, pn = (t, e, n) => {
|
|
|
704
708
|
return s;
|
|
705
709
|
},
|
|
706
710
|
clear: r,
|
|
707
|
-
|
|
711
|
+
evalSelectAction: b,
|
|
712
|
+
isEmpty: d,
|
|
708
713
|
isSelected: f,
|
|
709
714
|
setSelected: u,
|
|
710
715
|
setUserSelectAction: v,
|
|
711
716
|
subscribe: o,
|
|
712
|
-
userSelect:
|
|
717
|
+
userSelect: g
|
|
713
718
|
};
|
|
714
|
-
},
|
|
719
|
+
}, pn = (t, e, n) => {
|
|
715
720
|
const o = n ? n.serialize(t) : t;
|
|
716
721
|
return typeof e == "function" ? e(o) : e || "EDIT";
|
|
717
|
-
},
|
|
722
|
+
}, Y = [];
|
|
718
723
|
for (let t = 0; t < 256; ++t)
|
|
719
|
-
|
|
720
|
-
function
|
|
721
|
-
return (
|
|
724
|
+
Y.push((t + 256).toString(16).slice(1));
|
|
725
|
+
function mn(t, e = 0) {
|
|
726
|
+
return (Y[t[e + 0]] + Y[t[e + 1]] + Y[t[e + 2]] + Y[t[e + 3]] + "-" + Y[t[e + 4]] + Y[t[e + 5]] + "-" + Y[t[e + 6]] + Y[t[e + 7]] + "-" + Y[t[e + 8]] + Y[t[e + 9]] + "-" + Y[t[e + 10]] + Y[t[e + 11]] + Y[t[e + 12]] + Y[t[e + 13]] + Y[t[e + 14]] + Y[t[e + 15]]).toLowerCase();
|
|
722
727
|
}
|
|
723
|
-
let
|
|
724
|
-
const
|
|
725
|
-
function
|
|
726
|
-
if (!
|
|
728
|
+
let Mt;
|
|
729
|
+
const yn = new Uint8Array(16);
|
|
730
|
+
function bn() {
|
|
731
|
+
if (!Mt) {
|
|
727
732
|
if (typeof crypto > "u" || !crypto.getRandomValues)
|
|
728
733
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
729
|
-
|
|
734
|
+
Mt = crypto.getRandomValues.bind(crypto);
|
|
730
735
|
}
|
|
731
|
-
return
|
|
736
|
+
return Mt(yn);
|
|
732
737
|
}
|
|
733
|
-
const
|
|
738
|
+
const wn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), te = { randomUUID: wn };
|
|
734
739
|
function he(t, e, n) {
|
|
735
740
|
var o;
|
|
736
741
|
if (te.randomUUID && !t)
|
|
737
742
|
return te.randomUUID();
|
|
738
743
|
t = t || {};
|
|
739
|
-
const i = t.random ?? ((o = t.rng) == null ? void 0 : o.call(t)) ??
|
|
744
|
+
const i = t.random ?? ((o = t.rng) == null ? void 0 : o.call(t)) ?? bn();
|
|
740
745
|
if (i.length < 16)
|
|
741
746
|
throw new Error("Random bytes length must be >= 16");
|
|
742
|
-
return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128,
|
|
747
|
+
return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, mn(i);
|
|
743
748
|
}
|
|
744
|
-
const
|
|
749
|
+
const kt = (t) => {
|
|
745
750
|
const e = (n) => {
|
|
746
751
|
const o = { ...n };
|
|
747
752
|
return n.created && typeof n.created == "string" && (o.created = new Date(n.created)), n.updated && typeof n.updated == "string" && (o.updated = new Date(n.updated)), o;
|
|
@@ -757,37 +762,37 @@ const Mt = (t) => {
|
|
|
757
762
|
created: n || /* @__PURE__ */ new Date(),
|
|
758
763
|
creator: o,
|
|
759
764
|
...e
|
|
760
|
-
}),
|
|
765
|
+
}), xn = (t, e) => {
|
|
761
766
|
const n = new Set(t.bodies.map((o) => o.id));
|
|
762
767
|
return e.bodies.filter((o) => !n.has(o.id));
|
|
763
768
|
}, An = (t, e) => {
|
|
764
769
|
const n = new Set(e.bodies.map((o) => o.id));
|
|
765
770
|
return t.bodies.filter((o) => !n.has(o.id));
|
|
766
|
-
},
|
|
771
|
+
}, vn = (t, e) => e.bodies.map((n) => {
|
|
767
772
|
const o = t.bodies.find((i) => i.id === n.id);
|
|
768
|
-
return { newBody: n, oldBody: o && !
|
|
769
|
-
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })),
|
|
770
|
-
const n =
|
|
773
|
+
return { newBody: n, oldBody: o && !J(o, n) ? o : void 0 };
|
|
774
|
+
}).filter(({ oldBody: n }) => n).map(({ oldBody: n, newBody: o }) => ({ oldBody: n, newBody: o })), En = (t, e) => !J(t.target, e.target), ge = (t, e) => {
|
|
775
|
+
const n = xn(t, e), o = An(t, e), i = vn(t, e);
|
|
771
776
|
return {
|
|
772
777
|
oldValue: t,
|
|
773
778
|
newValue: e,
|
|
774
779
|
bodiesCreated: n.length > 0 ? n : void 0,
|
|
775
780
|
bodiesDeleted: o.length > 0 ? o : void 0,
|
|
776
781
|
bodiesUpdated: i.length > 0 ? i : void 0,
|
|
777
|
-
targetUpdated:
|
|
782
|
+
targetUpdated: En(t, e) ? { oldTarget: t.target, newTarget: e.target } : void 0
|
|
778
783
|
};
|
|
779
784
|
};
|
|
780
|
-
var
|
|
781
|
-
const
|
|
785
|
+
var B = /* @__PURE__ */ ((t) => (t.LOCAL = "LOCAL", t.REMOTE = "REMOTE", t.SILENT = "SILENT", t))(B || {});
|
|
786
|
+
const Sn = (t, e) => {
|
|
782
787
|
var n, o;
|
|
783
788
|
const { changes: i, origin: s } = e;
|
|
784
789
|
if (!(t.options.origin ? t.options.origin === s : s !== "SILENT"))
|
|
785
790
|
return !1;
|
|
786
791
|
if (t.options.ignore) {
|
|
787
|
-
const { ignore: a } = t.options, r = (
|
|
792
|
+
const { ignore: a } = t.options, r = (d) => d && d.length > 0;
|
|
788
793
|
if (!(r(i.created) || r(i.deleted))) {
|
|
789
|
-
const
|
|
790
|
-
if (a === "BODY_ONLY" &&
|
|
794
|
+
const d = (n = i.updated) == null ? void 0 : n.some((g) => r(g.bodiesCreated) || r(g.bodiesDeleted) || r(g.bodiesUpdated)), f = (o = i.updated) == null ? void 0 : o.some((g) => g.targetUpdated);
|
|
795
|
+
if (a === "BODY_ONLY" && d && !f || a === "TARGET_ONLY" && f && !d)
|
|
791
796
|
return !1;
|
|
792
797
|
}
|
|
793
798
|
}
|
|
@@ -800,26 +805,26 @@ const En = (t, e) => {
|
|
|
800
805
|
return !!(Array.isArray(t.options.annotations) ? t.options.annotations : [t.options.annotations]).find((r) => a.has(r));
|
|
801
806
|
} else
|
|
802
807
|
return !0;
|
|
803
|
-
},
|
|
804
|
-
const n = new Set((t.created || []).map((u) => u.id)), o = new Set((t.updated || []).map(({ newValue: u }) => u.id)), i = new Set((e.created || []).map((u) => u.id)), s = new Set((e.deleted || []).map((u) => u.id)), a = new Set((e.updated || []).map(({ oldValue: u }) => u.id)), r = new Set((e.updated || []).filter(({ oldValue: u }) => n.has(u.id) || o.has(u.id)).map(({ oldValue: u }) => u.id)),
|
|
805
|
-
...(t.created || []).filter((u) => !s.has(u.id)).map((u) => a.has(u.id) ? e.updated.find(({ oldValue:
|
|
808
|
+
}, Cn = (t, e) => {
|
|
809
|
+
const n = new Set((t.created || []).map((u) => u.id)), o = new Set((t.updated || []).map(({ newValue: u }) => u.id)), i = new Set((e.created || []).map((u) => u.id)), s = new Set((e.deleted || []).map((u) => u.id)), a = new Set((e.updated || []).map(({ oldValue: u }) => u.id)), r = new Set((e.updated || []).filter(({ oldValue: u }) => n.has(u.id) || o.has(u.id)).map(({ oldValue: u }) => u.id)), d = [
|
|
810
|
+
...(t.created || []).filter((u) => !s.has(u.id)).map((u) => a.has(u.id) ? e.updated.find(({ oldValue: h }) => h.id === u.id).newValue : u),
|
|
806
811
|
...e.created || []
|
|
807
812
|
], f = [
|
|
808
813
|
...(t.deleted || []).filter((u) => !i.has(u.id)),
|
|
809
814
|
...(e.deleted || []).filter((u) => !n.has(u.id))
|
|
810
|
-
],
|
|
815
|
+
], g = [
|
|
811
816
|
...(t.updated || []).filter(({ newValue: u }) => !s.has(u.id)).map((u) => {
|
|
812
|
-
const { oldValue:
|
|
817
|
+
const { oldValue: h, newValue: v } = u;
|
|
813
818
|
if (a.has(v.id)) {
|
|
814
|
-
const
|
|
815
|
-
return
|
|
819
|
+
const b = e.updated.find((p) => p.oldValue.id === v.id).newValue;
|
|
820
|
+
return ge(h, b);
|
|
816
821
|
} else
|
|
817
822
|
return u;
|
|
818
823
|
}),
|
|
819
824
|
...(e.updated || []).filter(({ oldValue: u }) => !r.has(u.id))
|
|
820
825
|
];
|
|
821
|
-
return { created:
|
|
822
|
-
},
|
|
826
|
+
return { created: d, deleted: f, updated: g };
|
|
827
|
+
}, yt = (t) => {
|
|
823
828
|
const e = t.id === void 0 ? he() : t.id;
|
|
824
829
|
return {
|
|
825
830
|
...t,
|
|
@@ -833,215 +838,215 @@ const En = (t, e) => {
|
|
|
833
838
|
annotation: e
|
|
834
839
|
}
|
|
835
840
|
};
|
|
836
|
-
},
|
|
837
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (
|
|
838
|
-
n.push({ onChange:
|
|
839
|
-
}, i = (
|
|
840
|
-
const
|
|
841
|
-
|
|
842
|
-
}, s = (
|
|
843
|
-
const
|
|
844
|
-
origin:
|
|
841
|
+
}, Ln = (t) => t.id !== void 0, Tn = () => {
|
|
842
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (y, w = {}) => {
|
|
843
|
+
n.push({ onChange: y, options: w });
|
|
844
|
+
}, i = (y) => {
|
|
845
|
+
const w = n.findIndex((A) => A.onChange == y);
|
|
846
|
+
w > -1 && n.splice(w, 1);
|
|
847
|
+
}, s = (y, w) => {
|
|
848
|
+
const A = {
|
|
849
|
+
origin: y,
|
|
845
850
|
changes: {
|
|
846
|
-
created:
|
|
847
|
-
updated:
|
|
848
|
-
deleted:
|
|
851
|
+
created: w.created || [],
|
|
852
|
+
updated: w.updated || [],
|
|
853
|
+
deleted: w.deleted || []
|
|
849
854
|
},
|
|
850
855
|
state: [...t.values()]
|
|
851
856
|
};
|
|
852
|
-
n.forEach((
|
|
853
|
-
|
|
857
|
+
n.forEach((C) => {
|
|
858
|
+
Sn(C, A) && C.onChange(A);
|
|
854
859
|
});
|
|
855
|
-
}, a = (
|
|
856
|
-
if (
|
|
857
|
-
throw Error(`Cannot add annotation ${
|
|
860
|
+
}, a = (y, w = B.LOCAL) => {
|
|
861
|
+
if (y.id && t.get(y.id))
|
|
862
|
+
throw Error(`Cannot add annotation ${y.id} - exists already`);
|
|
858
863
|
{
|
|
859
|
-
const
|
|
860
|
-
t.set(
|
|
864
|
+
const A = yt(y);
|
|
865
|
+
t.set(A.id, A), A.bodies.forEach((C) => e.set(C.id, A.id)), s(w, { created: [A] });
|
|
861
866
|
}
|
|
862
|
-
}, r = (
|
|
863
|
-
const
|
|
864
|
-
if (
|
|
865
|
-
const O =
|
|
866
|
-
return
|
|
867
|
+
}, r = (y, w) => {
|
|
868
|
+
const A = yt(typeof y == "string" ? w : y), C = typeof y == "string" ? y : y.id, I = C && t.get(C);
|
|
869
|
+
if (I) {
|
|
870
|
+
const O = ge(I, A);
|
|
871
|
+
return C === A.id ? t.set(C, A) : (t.delete(C), t.set(A.id, A)), I.bodies.forEach((k) => e.delete(k.id)), A.bodies.forEach((k) => e.set(k.id, A.id)), O;
|
|
867
872
|
} else
|
|
868
|
-
console.warn(`Cannot update annotation ${
|
|
869
|
-
},
|
|
870
|
-
const
|
|
871
|
-
|
|
872
|
-
}, f = (
|
|
873
|
-
t.get(
|
|
874
|
-
},
|
|
875
|
-
const
|
|
876
|
-
const O = r(
|
|
877
|
-
return O ? [...
|
|
873
|
+
console.warn(`Cannot update annotation ${C} - does not exist`);
|
|
874
|
+
}, d = (y, w = B.LOCAL, A = B.LOCAL) => {
|
|
875
|
+
const C = Ln(w) ? A : w, I = r(y, w);
|
|
876
|
+
I && s(C, { updated: [I] });
|
|
877
|
+
}, f = (y, w = B.LOCAL) => {
|
|
878
|
+
t.get(y.id) ? d(y, w) : a(y, w);
|
|
879
|
+
}, g = (y, w = B.LOCAL) => {
|
|
880
|
+
const A = y.reduce((C, I) => {
|
|
881
|
+
const O = r(I);
|
|
882
|
+
return O ? [...C, O] : C;
|
|
878
883
|
}, []);
|
|
879
|
-
|
|
880
|
-
}, u = (
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
t.set(
|
|
884
|
-
}), s(
|
|
885
|
-
},
|
|
886
|
-
const
|
|
887
|
-
if (
|
|
888
|
-
const
|
|
889
|
-
...
|
|
890
|
-
bodies: [...
|
|
884
|
+
A.length > 0 && s(w, { updated: A });
|
|
885
|
+
}, u = (y, w = B.LOCAL) => {
|
|
886
|
+
const A = y.map(yt), { toAdd: C, toUpdate: I } = A.reduce((k, P) => t.get(P.id) ? { ...k, toUpdate: [...k.toUpdate, P] } : { ...k, toAdd: [...k.toAdd, P] }, { toAdd: [], toUpdate: [] }), O = I.map((k) => r(k, w)).filter(Boolean);
|
|
887
|
+
C.forEach((k) => {
|
|
888
|
+
t.set(k.id, k), k.bodies.forEach((P) => e.set(P.id, k.id));
|
|
889
|
+
}), s(w, { created: C, updated: O });
|
|
890
|
+
}, h = (y, w = B.LOCAL) => {
|
|
891
|
+
const A = t.get(y.annotation);
|
|
892
|
+
if (A) {
|
|
893
|
+
const C = {
|
|
894
|
+
...A,
|
|
895
|
+
bodies: [...A.bodies, y]
|
|
891
896
|
};
|
|
892
|
-
t.set(
|
|
893
|
-
oldValue:
|
|
894
|
-
newValue:
|
|
895
|
-
bodiesCreated: [
|
|
897
|
+
t.set(A.id, C), e.set(y.id, C.id), s(w, { updated: [{
|
|
898
|
+
oldValue: A,
|
|
899
|
+
newValue: C,
|
|
900
|
+
bodiesCreated: [y]
|
|
896
901
|
}] });
|
|
897
902
|
} else
|
|
898
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
899
|
-
}, v = () => [...t.values()],
|
|
900
|
-
const
|
|
901
|
-
t.clear(), e.clear(), s(
|
|
902
|
-
},
|
|
903
|
-
const
|
|
904
|
-
if (
|
|
905
|
-
const
|
|
906
|
-
t.clear(), e.clear(),
|
|
907
|
-
t.set(O.id, O), O.bodies.forEach((
|
|
908
|
-
}), s(
|
|
903
|
+
console.warn(`Attempt to add body to missing annotation: ${y.annotation}`);
|
|
904
|
+
}, v = () => [...t.values()], b = (y = B.LOCAL) => {
|
|
905
|
+
const w = [...t.values()];
|
|
906
|
+
t.clear(), e.clear(), s(y, { deleted: w });
|
|
907
|
+
}, p = (y, w = !0, A = B.LOCAL) => {
|
|
908
|
+
const C = y.map(yt);
|
|
909
|
+
if (w) {
|
|
910
|
+
const I = [...t.values()];
|
|
911
|
+
t.clear(), e.clear(), C.forEach((O) => {
|
|
912
|
+
t.set(O.id, O), O.bodies.forEach((k) => e.set(k.id, O.id));
|
|
913
|
+
}), s(A, { created: C, deleted: I });
|
|
909
914
|
} else {
|
|
910
|
-
const
|
|
911
|
-
const P =
|
|
915
|
+
const I = y.reduce((O, k) => {
|
|
916
|
+
const P = k.id && t.get(k.id);
|
|
912
917
|
return P ? [...O, P] : O;
|
|
913
918
|
}, []);
|
|
914
|
-
if (
|
|
915
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${
|
|
916
|
-
|
|
917
|
-
t.set(O.id, O), O.bodies.forEach((
|
|
918
|
-
}), s(
|
|
919
|
+
if (I.length > 0)
|
|
920
|
+
throw Error(`Bulk insert would overwrite the following annotations: ${I.map((O) => O.id).join(", ")}`);
|
|
921
|
+
C.forEach((O) => {
|
|
922
|
+
t.set(O.id, O), O.bodies.forEach((k) => e.set(k.id, O.id));
|
|
923
|
+
}), s(A, { created: C });
|
|
919
924
|
}
|
|
920
|
-
},
|
|
921
|
-
const
|
|
922
|
-
if (
|
|
923
|
-
return t.delete(
|
|
924
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
925
|
-
},
|
|
926
|
-
const
|
|
927
|
-
|
|
928
|
-
},
|
|
929
|
-
const
|
|
930
|
-
const O =
|
|
931
|
-
return O ? [...
|
|
925
|
+
}, x = (y) => {
|
|
926
|
+
const w = typeof y == "string" ? y : y.id, A = t.get(w);
|
|
927
|
+
if (A)
|
|
928
|
+
return t.delete(w), A.bodies.forEach((C) => e.delete(C.id)), A;
|
|
929
|
+
console.warn(`Attempt to delete missing annotation: ${w}`);
|
|
930
|
+
}, c = (y, w = B.LOCAL) => {
|
|
931
|
+
const A = x(y);
|
|
932
|
+
A && s(w, { deleted: [A] });
|
|
933
|
+
}, l = (y, w = B.LOCAL) => {
|
|
934
|
+
const A = y.reduce((C, I) => {
|
|
935
|
+
const O = x(I);
|
|
936
|
+
return O ? [...C, O] : C;
|
|
932
937
|
}, []);
|
|
933
|
-
|
|
934
|
-
},
|
|
935
|
-
const
|
|
936
|
-
if (
|
|
937
|
-
const
|
|
938
|
-
if (
|
|
939
|
-
e.delete(
|
|
940
|
-
const
|
|
941
|
-
...
|
|
942
|
-
bodies:
|
|
938
|
+
A.length > 0 && s(w, { deleted: A });
|
|
939
|
+
}, m = (y) => {
|
|
940
|
+
const w = t.get(y.annotation);
|
|
941
|
+
if (w) {
|
|
942
|
+
const A = w.bodies.find((C) => C.id === y.id);
|
|
943
|
+
if (A) {
|
|
944
|
+
e.delete(A.id);
|
|
945
|
+
const C = {
|
|
946
|
+
...w,
|
|
947
|
+
bodies: w.bodies.filter((I) => I.id !== y.id)
|
|
943
948
|
};
|
|
944
|
-
return t.set(
|
|
945
|
-
oldValue:
|
|
946
|
-
newValue:
|
|
947
|
-
bodiesDeleted: [
|
|
949
|
+
return t.set(w.id, C), {
|
|
950
|
+
oldValue: w,
|
|
951
|
+
newValue: C,
|
|
952
|
+
bodiesDeleted: [A]
|
|
948
953
|
};
|
|
949
954
|
} else
|
|
950
|
-
console.warn(`Attempt to delete missing body ${
|
|
955
|
+
console.warn(`Attempt to delete missing body ${y.id} from annotation ${y.annotation}`);
|
|
951
956
|
} else
|
|
952
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
953
|
-
}, S = (
|
|
954
|
-
const
|
|
955
|
-
|
|
956
|
-
}, E = (
|
|
957
|
-
const
|
|
958
|
-
|
|
959
|
-
},
|
|
960
|
-
const
|
|
961
|
-
return
|
|
962
|
-
}, R = (
|
|
963
|
-
const
|
|
964
|
-
if (
|
|
965
|
-
const
|
|
966
|
-
if (
|
|
967
|
-
return
|
|
968
|
-
console.error(`Store integrity error: body ${
|
|
957
|
+
console.warn(`Attempt to delete body from missing annotation ${y.annotation}`);
|
|
958
|
+
}, S = (y, w = B.LOCAL) => {
|
|
959
|
+
const A = m(y);
|
|
960
|
+
A && s(w, { updated: [A] });
|
|
961
|
+
}, E = (y, w = B.LOCAL) => {
|
|
962
|
+
const A = y.map((C) => m(C)).filter(Boolean);
|
|
963
|
+
A.length > 0 && s(w, { updated: A });
|
|
964
|
+
}, L = (y) => {
|
|
965
|
+
const w = t.get(y);
|
|
966
|
+
return w ? { ...w } : void 0;
|
|
967
|
+
}, R = (y) => {
|
|
968
|
+
const w = e.get(y);
|
|
969
|
+
if (w) {
|
|
970
|
+
const A = L(w).bodies.find((C) => C.id === y);
|
|
971
|
+
if (A)
|
|
972
|
+
return A;
|
|
973
|
+
console.error(`Store integrity error: body ${y} in index, but not in annotation`);
|
|
969
974
|
} else
|
|
970
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
971
|
-
},
|
|
972
|
-
if (
|
|
975
|
+
console.warn(`Attempt to retrieve missing body: ${y}`);
|
|
976
|
+
}, U = (y, w) => {
|
|
977
|
+
if (y.annotation !== w.annotation)
|
|
973
978
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
974
|
-
const
|
|
975
|
-
if (
|
|
976
|
-
const
|
|
977
|
-
...
|
|
978
|
-
bodies:
|
|
979
|
+
const A = t.get(y.annotation);
|
|
980
|
+
if (A) {
|
|
981
|
+
const C = A.bodies.find((O) => O.id === y.id), I = {
|
|
982
|
+
...A,
|
|
983
|
+
bodies: A.bodies.map((O) => O.id === C.id ? w : O)
|
|
979
984
|
};
|
|
980
|
-
return t.set(
|
|
981
|
-
oldValue:
|
|
982
|
-
newValue:
|
|
983
|
-
bodiesUpdated: [{ oldBody:
|
|
985
|
+
return t.set(A.id, I), C.id !== w.id && (e.delete(C.id), e.set(w.id, I.id)), {
|
|
986
|
+
oldValue: A,
|
|
987
|
+
newValue: I,
|
|
988
|
+
bodiesUpdated: [{ oldBody: C, newBody: w }]
|
|
984
989
|
};
|
|
985
990
|
} else
|
|
986
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
987
|
-
},
|
|
988
|
-
const
|
|
989
|
-
|
|
990
|
-
},
|
|
991
|
-
const
|
|
992
|
-
s(
|
|
993
|
-
},
|
|
994
|
-
const
|
|
995
|
-
if (
|
|
996
|
-
const
|
|
997
|
-
...
|
|
991
|
+
console.warn(`Attempt to add body to missing annotation ${y.annotation}`);
|
|
992
|
+
}, V = (y, w, A = B.LOCAL) => {
|
|
993
|
+
const C = U(y, w);
|
|
994
|
+
C && s(A, { updated: [C] });
|
|
995
|
+
}, T = (y, w = B.LOCAL) => {
|
|
996
|
+
const A = y.map((C) => U({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
|
|
997
|
+
s(w, { updated: A });
|
|
998
|
+
}, M = (y) => {
|
|
999
|
+
const w = t.get(y.annotation);
|
|
1000
|
+
if (w) {
|
|
1001
|
+
const A = {
|
|
1002
|
+
...w,
|
|
998
1003
|
target: {
|
|
999
|
-
...
|
|
1000
|
-
...
|
|
1004
|
+
...w.target,
|
|
1005
|
+
...y
|
|
1001
1006
|
}
|
|
1002
1007
|
};
|
|
1003
|
-
return t.set(
|
|
1004
|
-
oldValue:
|
|
1005
|
-
newValue:
|
|
1008
|
+
return t.set(w.id, A), {
|
|
1009
|
+
oldValue: w,
|
|
1010
|
+
newValue: A,
|
|
1006
1011
|
targetUpdated: {
|
|
1007
|
-
oldTarget:
|
|
1008
|
-
newTarget:
|
|
1012
|
+
oldTarget: w.target,
|
|
1013
|
+
newTarget: y
|
|
1009
1014
|
}
|
|
1010
1015
|
};
|
|
1011
1016
|
} else
|
|
1012
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
1017
|
+
console.warn(`Attempt to update target on missing annotation: ${y.annotation}`);
|
|
1013
1018
|
};
|
|
1014
1019
|
return {
|
|
1015
1020
|
addAnnotation: a,
|
|
1016
|
-
addBody:
|
|
1021
|
+
addBody: h,
|
|
1017
1022
|
all: v,
|
|
1018
|
-
bulkAddAnnotations:
|
|
1019
|
-
bulkDeleteAnnotations:
|
|
1023
|
+
bulkAddAnnotations: p,
|
|
1024
|
+
bulkDeleteAnnotations: l,
|
|
1020
1025
|
bulkDeleteBodies: E,
|
|
1021
|
-
bulkUpdateAnnotations:
|
|
1022
|
-
bulkUpdateBodies:
|
|
1023
|
-
bulkUpdateTargets: (
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
+
bulkUpdateAnnotations: g,
|
|
1027
|
+
bulkUpdateBodies: T,
|
|
1028
|
+
bulkUpdateTargets: (y, w = B.LOCAL) => {
|
|
1029
|
+
const A = y.map((C) => M(C)).filter(Boolean);
|
|
1030
|
+
A.length > 0 && s(w, { updated: A });
|
|
1026
1031
|
},
|
|
1027
1032
|
bulkUpsertAnnotations: u,
|
|
1028
|
-
clear:
|
|
1029
|
-
deleteAnnotation:
|
|
1033
|
+
clear: b,
|
|
1034
|
+
deleteAnnotation: c,
|
|
1030
1035
|
deleteBody: S,
|
|
1031
|
-
getAnnotation:
|
|
1036
|
+
getAnnotation: L,
|
|
1032
1037
|
getBody: R,
|
|
1033
1038
|
observe: o,
|
|
1034
1039
|
unobserve: i,
|
|
1035
|
-
updateAnnotation:
|
|
1036
|
-
updateBody:
|
|
1037
|
-
updateTarget: (
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
+
updateAnnotation: d,
|
|
1041
|
+
updateBody: V,
|
|
1042
|
+
updateTarget: (y, w = B.LOCAL) => {
|
|
1043
|
+
const A = M(y);
|
|
1044
|
+
A && s(w, { updated: [A] });
|
|
1040
1045
|
},
|
|
1041
1046
|
upsertAnnotation: f
|
|
1042
1047
|
};
|
|
1043
1048
|
};
|
|
1044
|
-
let
|
|
1049
|
+
let On = () => ({
|
|
1045
1050
|
emit(t, ...e) {
|
|
1046
1051
|
for (let n = this.events[t] || [], o = 0, i = n.length; o < i; o++)
|
|
1047
1052
|
n[o](...e);
|
|
@@ -1055,120 +1060,120 @@ let Tn = () => ({
|
|
|
1055
1060
|
};
|
|
1056
1061
|
}
|
|
1057
1062
|
});
|
|
1058
|
-
const
|
|
1059
|
-
const n =
|
|
1063
|
+
const Rn = 250, Mn = (t, e) => {
|
|
1064
|
+
const n = On(), o = [];
|
|
1060
1065
|
let i = -1, s = !1, a = 0;
|
|
1061
|
-
const r = (
|
|
1066
|
+
const r = (b) => {
|
|
1062
1067
|
if (!s) {
|
|
1063
|
-
const { changes:
|
|
1064
|
-
if (
|
|
1065
|
-
o.splice(i + 1), o.push(
|
|
1068
|
+
const { changes: p } = b, x = performance.now();
|
|
1069
|
+
if (x - a > Rn)
|
|
1070
|
+
o.splice(i + 1), o.push(p), i = o.length - 1;
|
|
1066
1071
|
else {
|
|
1067
|
-
const
|
|
1068
|
-
o[
|
|
1072
|
+
const c = o.length - 1;
|
|
1073
|
+
o[c] = Cn(o[c], p);
|
|
1069
1074
|
}
|
|
1070
|
-
a =
|
|
1075
|
+
a = x;
|
|
1071
1076
|
}
|
|
1072
1077
|
s = !1;
|
|
1073
1078
|
};
|
|
1074
|
-
t.observe(r, { origin:
|
|
1075
|
-
const
|
|
1079
|
+
t.observe(r, { origin: B.LOCAL });
|
|
1080
|
+
const d = (b) => b && b.length > 0 && t.bulkDeleteAnnotations(b), f = (b) => b && b.length > 0 && t.bulkAddAnnotations(b, !1), g = (b) => b && b.length > 0 && t.bulkUpdateAnnotations(b.map(({ oldValue: p }) => p)), u = (b) => b && b.length > 0 && t.bulkUpdateAnnotations(b.map(({ newValue: p }) => p)), h = (b) => b && b.length > 0 && t.bulkAddAnnotations(b, !1), v = (b) => b && b.length > 0 && t.bulkDeleteAnnotations(b);
|
|
1076
1081
|
return {
|
|
1077
1082
|
canRedo: () => o.length - 1 > i,
|
|
1078
1083
|
canUndo: () => i > -1,
|
|
1079
1084
|
destroy: () => t.unobserve(r),
|
|
1080
1085
|
getHistory: () => ({ changes: [...o], pointer: i }),
|
|
1081
|
-
on: (
|
|
1086
|
+
on: (b, p) => n.on(b, p),
|
|
1082
1087
|
redo: () => {
|
|
1083
1088
|
if (o.length - 1 > i) {
|
|
1084
1089
|
s = !0;
|
|
1085
|
-
const { created:
|
|
1086
|
-
f(
|
|
1090
|
+
const { created: b, updated: p, deleted: x } = o[i + 1];
|
|
1091
|
+
f(b), u(p), v(x), n.emit("redo", o[i + 1]), i += 1;
|
|
1087
1092
|
}
|
|
1088
1093
|
},
|
|
1089
1094
|
undo: () => {
|
|
1090
1095
|
if (i > -1) {
|
|
1091
1096
|
s = !0;
|
|
1092
|
-
const { created:
|
|
1093
|
-
|
|
1097
|
+
const { created: b, updated: p, deleted: x } = o[i];
|
|
1098
|
+
d(b), g(p), h(x), n.emit("undo", o[i]), i -= 1;
|
|
1094
1099
|
}
|
|
1095
1100
|
}
|
|
1096
1101
|
};
|
|
1097
|
-
},
|
|
1098
|
-
const { subscribe: t, set: e } =
|
|
1102
|
+
}, kn = () => {
|
|
1103
|
+
const { subscribe: t, set: e } = Xt([]);
|
|
1099
1104
|
return {
|
|
1100
1105
|
subscribe: t,
|
|
1101
1106
|
set: e
|
|
1102
1107
|
};
|
|
1103
1108
|
}, Bn = (t, e, n, o) => {
|
|
1104
|
-
const { hover: i, selection: s, store: a, viewport: r } = t,
|
|
1105
|
-
let f = [],
|
|
1106
|
-
const u = (
|
|
1107
|
-
|
|
1108
|
-
},
|
|
1109
|
-
const
|
|
1110
|
-
if (
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1109
|
+
const { hover: i, selection: s, store: a, viewport: r } = t, d = /* @__PURE__ */ new Map();
|
|
1110
|
+
let f = [], g;
|
|
1111
|
+
const u = (p, x) => {
|
|
1112
|
+
d.has(p) ? d.get(p).push(x) : d.set(p, [x]);
|
|
1113
|
+
}, h = (p, x) => {
|
|
1114
|
+
const c = d.get(p);
|
|
1115
|
+
if (c) {
|
|
1116
|
+
const l = c.indexOf(x);
|
|
1117
|
+
l !== -1 && c.splice(l, 1);
|
|
1113
1118
|
}
|
|
1114
|
-
}, v = (
|
|
1115
|
-
|
|
1116
|
-
|
|
1119
|
+
}, v = (p, x, c) => {
|
|
1120
|
+
d.has(p) && setTimeout(() => {
|
|
1121
|
+
d.get(p).forEach((l) => {
|
|
1117
1122
|
if (n) {
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1123
|
+
const m = Array.isArray(x) ? x.map((E) => n.serialize(E)) : n.serialize(x), S = c ? c instanceof PointerEvent ? c : n.serialize(c) : void 0;
|
|
1124
|
+
l(m, S);
|
|
1120
1125
|
} else
|
|
1121
|
-
|
|
1126
|
+
l(x, c);
|
|
1122
1127
|
});
|
|
1123
1128
|
}, 1);
|
|
1124
1129
|
};
|
|
1125
|
-
s.subscribe(({ selected:
|
|
1126
|
-
if (!(f.length === 0 &&
|
|
1127
|
-
if (f.length === 0 &&
|
|
1128
|
-
f =
|
|
1129
|
-
else if (f.length > 0 &&
|
|
1130
|
-
f.forEach((
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1130
|
+
s.subscribe(({ selected: p }) => {
|
|
1131
|
+
if (!(f.length === 0 && p.length === 0)) {
|
|
1132
|
+
if (f.length === 0 && p.length > 0)
|
|
1133
|
+
f = p.map(({ id: x }) => a.getAnnotation(x));
|
|
1134
|
+
else if (f.length > 0 && p.length === 0)
|
|
1135
|
+
f.forEach((x) => {
|
|
1136
|
+
const c = a.getAnnotation(x.id);
|
|
1137
|
+
c && !J(c, x) && v("updateAnnotation", c, x);
|
|
1133
1138
|
}), f = [];
|
|
1134
1139
|
else {
|
|
1135
|
-
const
|
|
1136
|
-
f.filter((
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1140
|
+
const x = new Set(f.map((l) => l.id)), c = new Set(p.map(({ id: l }) => l));
|
|
1141
|
+
f.filter((l) => !c.has(l.id)).forEach((l) => {
|
|
1142
|
+
const m = a.getAnnotation(l.id);
|
|
1143
|
+
m && !J(m, l) && v("updateAnnotation", m, l);
|
|
1139
1144
|
}), f = [
|
|
1140
1145
|
// Remove annotations that were deselected
|
|
1141
|
-
...f.filter((
|
|
1146
|
+
...f.filter((l) => c.has(l.id)),
|
|
1142
1147
|
// Add editable annotations that were selected
|
|
1143
|
-
...
|
|
1148
|
+
...p.filter(({ id: l }) => !x.has(l)).map(({ id: l }) => a.getAnnotation(l))
|
|
1144
1149
|
];
|
|
1145
1150
|
}
|
|
1146
1151
|
v("selectionChanged", f);
|
|
1147
1152
|
}
|
|
1148
|
-
}), i.subscribe((
|
|
1149
|
-
!
|
|
1150
|
-
}), r == null || r.subscribe((
|
|
1151
|
-
const { created:
|
|
1152
|
-
(
|
|
1153
|
-
...
|
|
1154
|
-
...
|
|
1155
|
-
...
|
|
1156
|
-
].length > 0).forEach(({ oldValue:
|
|
1157
|
-
const S = f.find((E) => E.id ===
|
|
1158
|
-
f = f.map((E) => E.id ===
|
|
1153
|
+
}), i.subscribe((p) => {
|
|
1154
|
+
!g && p ? v("mouseEnterAnnotation", a.getAnnotation(p)) : g && !p ? v("mouseLeaveAnnotation", a.getAnnotation(g)) : g && p && (v("mouseLeaveAnnotation", a.getAnnotation(g)), v("mouseEnterAnnotation", a.getAnnotation(p))), g = p;
|
|
1155
|
+
}), r == null || r.subscribe((p) => v("viewportIntersect", p.map((x) => a.getAnnotation(x)))), a.observe((p) => {
|
|
1156
|
+
const { created: x, deleted: c } = p.changes;
|
|
1157
|
+
(x || []).forEach((l) => v("createAnnotation", l)), (c || []).forEach((l) => v("deleteAnnotation", l)), (p.changes.updated || []).filter((l) => [
|
|
1158
|
+
...l.bodiesCreated || [],
|
|
1159
|
+
...l.bodiesDeleted || [],
|
|
1160
|
+
...l.bodiesUpdated || []
|
|
1161
|
+
].length > 0).forEach(({ oldValue: l, newValue: m }) => {
|
|
1162
|
+
const S = f.find((E) => E.id === l.id) || l;
|
|
1163
|
+
f = f.map((E) => E.id === l.id ? m : E), v("updateAnnotation", m, S);
|
|
1159
1164
|
});
|
|
1160
|
-
}, { origin:
|
|
1165
|
+
}, { origin: B.LOCAL }), a.observe((p) => {
|
|
1161
1166
|
if (f) {
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1167
|
+
const x = new Set(f.map((l) => l.id)), c = (p.changes.updated || []).filter(({ newValue: l }) => x.has(l.id)).map(({ newValue: l }) => l);
|
|
1168
|
+
c.length > 0 && (f = f.map((l) => c.find((S) => S.id === l.id) || l));
|
|
1164
1169
|
}
|
|
1165
|
-
}, { origin:
|
|
1166
|
-
const
|
|
1167
|
-
const { updated:
|
|
1168
|
-
|
|
1170
|
+
}, { origin: B.REMOTE });
|
|
1171
|
+
const b = (p) => (x) => {
|
|
1172
|
+
const { updated: c } = x;
|
|
1173
|
+
p ? (c || []).forEach((l) => v("updateAnnotation", l.oldValue, l.newValue)) : (c || []).forEach((l) => v("updateAnnotation", l.newValue, l.oldValue));
|
|
1169
1174
|
};
|
|
1170
|
-
return e.on("undo",
|
|
1171
|
-
},
|
|
1175
|
+
return e.on("undo", b(!0)), e.on("redo", b(!1)), { on: u, off: h, emit: v };
|
|
1176
|
+
}, In = (t) => (e) => e.reduce((n, o) => {
|
|
1172
1177
|
const { parsed: i, error: s } = t.parse(o);
|
|
1173
1178
|
return s ? {
|
|
1174
1179
|
parsed: n.parsed,
|
|
@@ -1179,47 +1184,47 @@ const On = 250, Rn = (t, e) => {
|
|
|
1179
1184
|
} : {
|
|
1180
1185
|
...n
|
|
1181
1186
|
};
|
|
1182
|
-
}, { parsed: [], failed: [] }),
|
|
1183
|
-
const { store: o, selection: i } = t, s = (
|
|
1187
|
+
}, { parsed: [], failed: [] }), Un = (t, e, n) => {
|
|
1188
|
+
const { store: o, selection: i } = t, s = (c) => {
|
|
1184
1189
|
if (n) {
|
|
1185
|
-
const { parsed:
|
|
1186
|
-
|
|
1190
|
+
const { parsed: l, error: m } = n.parse(c);
|
|
1191
|
+
l ? o.addAnnotation(l, B.REMOTE) : console.error(m);
|
|
1187
1192
|
} else
|
|
1188
|
-
o.addAnnotation(
|
|
1189
|
-
}, a = () => i.clear(), r = () => o.clear(),
|
|
1190
|
-
const
|
|
1191
|
-
return n &&
|
|
1192
|
-
}, f = () => n ? o.all().map(n.serialize) : o.all(),
|
|
1193
|
-
var
|
|
1194
|
-
const
|
|
1195
|
-
return n ?
|
|
1196
|
-
}, u = (
|
|
1197
|
-
if (typeof
|
|
1198
|
-
const
|
|
1199
|
-
if (o.deleteAnnotation(
|
|
1200
|
-
return n ? n.serialize(
|
|
1193
|
+
o.addAnnotation(kt(c), B.REMOTE);
|
|
1194
|
+
}, a = () => i.clear(), r = () => o.clear(), d = (c) => {
|
|
1195
|
+
const l = o.getAnnotation(c);
|
|
1196
|
+
return n && l ? n.serialize(l) : l;
|
|
1197
|
+
}, f = () => n ? o.all().map(n.serialize) : o.all(), g = () => {
|
|
1198
|
+
var c;
|
|
1199
|
+
const l = (((c = i.selected) == null ? void 0 : c.map((m) => m.id)) || []).map((m) => o.getAnnotation(m)).filter(Boolean);
|
|
1200
|
+
return n ? l.map(n.serialize) : l;
|
|
1201
|
+
}, u = (c, l = !0) => fetch(c).then((m) => m.json()).then((m) => (v(m, l), m)), h = (c) => {
|
|
1202
|
+
if (typeof c == "string") {
|
|
1203
|
+
const l = o.getAnnotation(c);
|
|
1204
|
+
if (o.deleteAnnotation(c), l)
|
|
1205
|
+
return n ? n.serialize(l) : l;
|
|
1201
1206
|
} else {
|
|
1202
|
-
const
|
|
1203
|
-
if (
|
|
1204
|
-
return o.deleteAnnotation(
|
|
1207
|
+
const l = n ? n.parse(c).parsed : c;
|
|
1208
|
+
if (l)
|
|
1209
|
+
return o.deleteAnnotation(l), c;
|
|
1205
1210
|
}
|
|
1206
|
-
}, v = (
|
|
1211
|
+
}, v = (c, l = !0) => {
|
|
1207
1212
|
if (n) {
|
|
1208
|
-
const
|
|
1209
|
-
E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotations(S,
|
|
1213
|
+
const m = n.parseAll || In(n), { parsed: S, failed: E } = m(c);
|
|
1214
|
+
E.length > 0 && console.warn(`Discarded ${E.length} invalid annotations`, E), o.bulkAddAnnotations(S, l, B.REMOTE);
|
|
1210
1215
|
} else
|
|
1211
|
-
o.bulkAddAnnotations(
|
|
1212
|
-
},
|
|
1213
|
-
|
|
1214
|
-
},
|
|
1215
|
-
i.clear(), i.setUserSelectAction(
|
|
1216
|
-
},
|
|
1216
|
+
o.bulkAddAnnotations(c.map(kt), l, B.REMOTE);
|
|
1217
|
+
}, b = (c, l) => {
|
|
1218
|
+
c ? i.setSelected(c, l) : i.clear();
|
|
1219
|
+
}, p = (c) => {
|
|
1220
|
+
i.clear(), i.setUserSelectAction(c);
|
|
1221
|
+
}, x = (c) => {
|
|
1217
1222
|
if (n) {
|
|
1218
|
-
const
|
|
1219
|
-
return o.updateAnnotation(
|
|
1223
|
+
const l = n.parse(c).parsed, m = n.serialize(o.getAnnotation(l.id));
|
|
1224
|
+
return o.updateAnnotation(l), m;
|
|
1220
1225
|
} else {
|
|
1221
|
-
const
|
|
1222
|
-
return o.updateAnnotation(
|
|
1226
|
+
const l = o.getAnnotation(c.id);
|
|
1227
|
+
return o.updateAnnotation(kt(c)), l;
|
|
1223
1228
|
}
|
|
1224
1229
|
};
|
|
1225
1230
|
return {
|
|
@@ -1228,37 +1233,37 @@ const On = 250, Rn = (t, e) => {
|
|
|
1228
1233
|
canRedo: e.canRedo,
|
|
1229
1234
|
canUndo: e.canUndo,
|
|
1230
1235
|
clearAnnotations: r,
|
|
1231
|
-
getAnnotationById:
|
|
1236
|
+
getAnnotationById: d,
|
|
1232
1237
|
getAnnotations: f,
|
|
1233
1238
|
getHistory: e.getHistory,
|
|
1234
|
-
getSelected:
|
|
1239
|
+
getSelected: g,
|
|
1235
1240
|
loadAnnotations: u,
|
|
1236
1241
|
redo: e.redo,
|
|
1237
|
-
removeAnnotation:
|
|
1242
|
+
removeAnnotation: h,
|
|
1238
1243
|
setAnnotations: v,
|
|
1239
|
-
setSelected:
|
|
1240
|
-
setUserSelectAction:
|
|
1244
|
+
setSelected: b,
|
|
1245
|
+
setUserSelectAction: p,
|
|
1241
1246
|
undo: e.undo,
|
|
1242
|
-
updateAnnotation:
|
|
1247
|
+
updateAnnotation: x
|
|
1243
1248
|
};
|
|
1244
1249
|
}, _n = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1245
|
-
let
|
|
1250
|
+
let Nn = (t) => crypto.getRandomValues(new Uint8Array(t)), Vn = (t, e, n) => {
|
|
1246
1251
|
let o = (2 << Math.log2(t.length - 1)) - 1, i = -~(1.6 * o * e / t.length);
|
|
1247
1252
|
return (s = e) => {
|
|
1248
1253
|
let a = "";
|
|
1249
1254
|
for (; ; ) {
|
|
1250
|
-
let r = n(i),
|
|
1251
|
-
for (;
|
|
1252
|
-
if (a += t[r[
|
|
1255
|
+
let r = n(i), d = i | 0;
|
|
1256
|
+
for (; d--; )
|
|
1257
|
+
if (a += t[r[d] & o] || "", a.length >= s) return a;
|
|
1253
1258
|
}
|
|
1254
1259
|
};
|
|
1255
|
-
},
|
|
1260
|
+
}, Dn = (t, e = 21) => Vn(t, e | 0, Nn), Kn = (t = 21) => {
|
|
1256
1261
|
let e = "", n = crypto.getRandomValues(new Uint8Array(t |= 0));
|
|
1257
1262
|
for (; t--; )
|
|
1258
1263
|
e += _n[n[t] & 63];
|
|
1259
1264
|
return e;
|
|
1260
1265
|
};
|
|
1261
|
-
const Yn = () => ({ isGuest: !0, id:
|
|
1266
|
+
const Yn = () => ({ isGuest: !0, id: Dn("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", 20)() }), Xn = (t) => {
|
|
1262
1267
|
const e = JSON.stringify(t);
|
|
1263
1268
|
let n = 0;
|
|
1264
1269
|
for (let o = 0, i = e.length; o < i; o++) {
|
|
@@ -1266,20 +1271,20 @@ const Yn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1266
1271
|
n = (n << 5) - n + s, n |= 0;
|
|
1267
1272
|
}
|
|
1268
1273
|
return `${n}`;
|
|
1269
|
-
},
|
|
1270
|
-
const { id: o, type: i, purpose: s, value: a, created: r, modified:
|
|
1274
|
+
}, pe = (t) => t ? typeof t == "object" ? { ...t } : t : void 0, Pn = (t, e) => (Array.isArray(t) ? t : [t]).map((n) => {
|
|
1275
|
+
const { id: o, type: i, purpose: s, value: a, created: r, modified: d, creator: f, ...g } = n;
|
|
1271
1276
|
return {
|
|
1272
|
-
id: o || `temp-${
|
|
1277
|
+
id: o || `temp-${Xn(n)}`,
|
|
1273
1278
|
annotation: e,
|
|
1274
1279
|
type: i,
|
|
1275
1280
|
purpose: s,
|
|
1276
1281
|
value: a,
|
|
1277
|
-
creator:
|
|
1282
|
+
creator: pe(f),
|
|
1278
1283
|
created: r ? new Date(r) : void 0,
|
|
1279
|
-
updated:
|
|
1280
|
-
...
|
|
1284
|
+
updated: d ? new Date(d) : void 0,
|
|
1285
|
+
...g
|
|
1281
1286
|
};
|
|
1282
|
-
}),
|
|
1287
|
+
}), $n = (t) => t.map((e) => {
|
|
1283
1288
|
var n;
|
|
1284
1289
|
const { annotation: o, created: i, updated: s, ...a } = e, r = {
|
|
1285
1290
|
...a,
|
|
@@ -1288,11 +1293,11 @@ const Yn = () => ({ isGuest: !0, id: Vn("1234567890abcdefghijklmnopqrstuvwxyzABC
|
|
|
1288
1293
|
};
|
|
1289
1294
|
return (n = r.id) != null && n.startsWith("temp-") && delete r.id, r;
|
|
1290
1295
|
});
|
|
1291
|
-
|
|
1292
|
-
const
|
|
1293
|
-
parse: (n) =>
|
|
1294
|
-
serialize: (n) =>
|
|
1295
|
-
}),
|
|
1296
|
+
Kn();
|
|
1297
|
+
const vo = (t, e) => ({
|
|
1298
|
+
parse: (n) => zn(n),
|
|
1299
|
+
serialize: (n) => Fn(n, t, e)
|
|
1300
|
+
}), Hn = (t) => t.quote !== void 0 && t.start !== void 0 && t.end !== void 0, jn = (t) => {
|
|
1296
1301
|
const {
|
|
1297
1302
|
id: e,
|
|
1298
1303
|
creator: n,
|
|
@@ -1303,7 +1308,7 @@ const xo = (t, e) => ({
|
|
|
1303
1308
|
if (a.length === 0)
|
|
1304
1309
|
return { error: Error(`No targets found for annotation: ${t.id}`) };
|
|
1305
1310
|
const r = {
|
|
1306
|
-
creator:
|
|
1311
|
+
creator: pe(n),
|
|
1307
1312
|
created: o ? new Date(o) : void 0,
|
|
1308
1313
|
updated: i ? new Date(i) : void 0,
|
|
1309
1314
|
annotation: e,
|
|
@@ -1311,80 +1316,80 @@ const xo = (t, e) => ({
|
|
|
1311
1316
|
// @ts-expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
|
|
1312
1317
|
styleClass: "styleClass" in a[0] ? a[0].styleClass : void 0
|
|
1313
1318
|
};
|
|
1314
|
-
for (const
|
|
1315
|
-
const
|
|
1316
|
-
switch (
|
|
1319
|
+
for (const d of a) {
|
|
1320
|
+
const g = (Array.isArray(d.selector) ? d.selector : [d.selector]).reduce((u, h) => {
|
|
1321
|
+
switch (h.type) {
|
|
1317
1322
|
case "TextQuoteSelector":
|
|
1318
|
-
u.quote =
|
|
1323
|
+
u.quote = h.exact;
|
|
1319
1324
|
break;
|
|
1320
1325
|
case "TextPositionSelector":
|
|
1321
|
-
u.start =
|
|
1326
|
+
u.start = h.start, u.end = h.end;
|
|
1322
1327
|
break;
|
|
1323
1328
|
}
|
|
1324
1329
|
return u;
|
|
1325
1330
|
}, {});
|
|
1326
|
-
if (
|
|
1331
|
+
if (Hn(g))
|
|
1327
1332
|
r.selector.push(
|
|
1328
1333
|
{
|
|
1329
|
-
...
|
|
1330
|
-
id:
|
|
1334
|
+
...g,
|
|
1335
|
+
id: d.id,
|
|
1331
1336
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
1332
|
-
scope:
|
|
1337
|
+
scope: d.scope
|
|
1333
1338
|
}
|
|
1334
1339
|
);
|
|
1335
1340
|
else {
|
|
1336
1341
|
const u = [
|
|
1337
|
-
|
|
1338
|
-
|
|
1342
|
+
g.start ? void 0 : "TextPositionSelector",
|
|
1343
|
+
g.quote ? void 0 : "TextQuoteSelector"
|
|
1339
1344
|
].filter(Boolean);
|
|
1340
1345
|
return { error: Error(`Missing selector types: ${u.join(" and ")} for annotation: ${t.id}`) };
|
|
1341
1346
|
}
|
|
1342
1347
|
}
|
|
1343
1348
|
return { parsed: r };
|
|
1344
|
-
},
|
|
1349
|
+
}, zn = (t) => {
|
|
1345
1350
|
const e = t.id || fe(), {
|
|
1346
1351
|
creator: n,
|
|
1347
1352
|
created: o,
|
|
1348
1353
|
modified: i,
|
|
1349
1354
|
body: s,
|
|
1350
1355
|
...a
|
|
1351
|
-
} = t, r =
|
|
1352
|
-
return "error" in
|
|
1356
|
+
} = t, r = Pn(s, e), d = jn(t);
|
|
1357
|
+
return "error" in d ? { error: d.error } : {
|
|
1353
1358
|
parsed: {
|
|
1354
1359
|
...a,
|
|
1355
1360
|
id: e,
|
|
1356
1361
|
bodies: r,
|
|
1357
|
-
target:
|
|
1362
|
+
target: d.parsed
|
|
1358
1363
|
}
|
|
1359
1364
|
};
|
|
1360
|
-
},
|
|
1365
|
+
}, Fn = (t, e, n) => {
|
|
1361
1366
|
const { bodies: o, target: i, ...s } = t, {
|
|
1362
1367
|
selector: a,
|
|
1363
1368
|
creator: r,
|
|
1364
|
-
created:
|
|
1369
|
+
created: d,
|
|
1365
1370
|
updated: f,
|
|
1366
|
-
...
|
|
1367
|
-
} = i, u = a.map((
|
|
1368
|
-
const { id: v, quote:
|
|
1371
|
+
...g
|
|
1372
|
+
} = i, u = a.map((h) => {
|
|
1373
|
+
const { id: v, quote: b, start: p, end: x, range: c } = h, l = {
|
|
1369
1374
|
type: "TextQuoteSelector",
|
|
1370
|
-
exact:
|
|
1375
|
+
exact: b
|
|
1371
1376
|
};
|
|
1372
1377
|
if (n) {
|
|
1373
|
-
const { prefix: S, suffix: E } =
|
|
1374
|
-
|
|
1378
|
+
const { prefix: S, suffix: E } = ke(c, n);
|
|
1379
|
+
l.prefix = S, l.suffix = E;
|
|
1375
1380
|
}
|
|
1376
|
-
const
|
|
1381
|
+
const m = {
|
|
1377
1382
|
type: "TextPositionSelector",
|
|
1378
|
-
start:
|
|
1379
|
-
end:
|
|
1383
|
+
start: p,
|
|
1384
|
+
end: x
|
|
1380
1385
|
};
|
|
1381
1386
|
return {
|
|
1382
|
-
...
|
|
1387
|
+
...g,
|
|
1383
1388
|
id: v,
|
|
1384
1389
|
// @ts-expect-error: `scope` is not part of the core `TextSelector` type
|
|
1385
|
-
scope: "scope" in
|
|
1390
|
+
scope: "scope" in h ? h.scope : void 0,
|
|
1386
1391
|
source: e,
|
|
1387
|
-
selector: [
|
|
1392
|
+
selector: [l, m]
|
|
1388
1393
|
};
|
|
1389
1394
|
});
|
|
1390
1395
|
return {
|
|
@@ -1392,36 +1397,36 @@ const xo = (t, e) => ({
|
|
|
1392
1397
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
1393
1398
|
id: t.id,
|
|
1394
1399
|
type: "Annotation",
|
|
1395
|
-
body:
|
|
1400
|
+
body: $n(t.bodies),
|
|
1396
1401
|
creator: r,
|
|
1397
|
-
created:
|
|
1402
|
+
created: d == null ? void 0 : d.toISOString(),
|
|
1398
1403
|
modified: f == null ? void 0 : f.toISOString(),
|
|
1399
1404
|
target: u
|
|
1400
1405
|
};
|
|
1401
1406
|
};
|
|
1402
|
-
function me(t, e, n = 0, o = t.length - 1, i =
|
|
1407
|
+
function me(t, e, n = 0, o = t.length - 1, i = Wn) {
|
|
1403
1408
|
for (; o > n; ) {
|
|
1404
1409
|
if (o - n > 600) {
|
|
1405
|
-
const
|
|
1406
|
-
me(t, e, v,
|
|
1410
|
+
const d = o - n + 1, f = e - n + 1, g = Math.log(d), u = 0.5 * Math.exp(2 * g / 3), h = 0.5 * Math.sqrt(g * u * (d - u) / d) * (f - d / 2 < 0 ? -1 : 1), v = Math.max(n, Math.floor(e - f * u / d + h)), b = Math.min(o, Math.floor(e + (d - f) * u / d + h));
|
|
1411
|
+
me(t, e, v, b, i);
|
|
1407
1412
|
}
|
|
1408
1413
|
const s = t[e];
|
|
1409
1414
|
let a = n, r = o;
|
|
1410
|
-
for (
|
|
1411
|
-
for (
|
|
1415
|
+
for (it(t, n, e), i(t[o], s) > 0 && it(t, n, o); a < r; ) {
|
|
1416
|
+
for (it(t, a, r), a++, r--; i(t[a], s) < 0; ) a++;
|
|
1412
1417
|
for (; i(t[r], s) > 0; ) r--;
|
|
1413
1418
|
}
|
|
1414
|
-
i(t[n], s) === 0 ?
|
|
1419
|
+
i(t[n], s) === 0 ? it(t, n, r) : (r++, it(t, r, o)), r <= e && (n = r + 1), e <= r && (o = r - 1);
|
|
1415
1420
|
}
|
|
1416
1421
|
}
|
|
1417
|
-
function
|
|
1422
|
+
function it(t, e, n) {
|
|
1418
1423
|
const o = t[e];
|
|
1419
1424
|
t[e] = t[n], t[n] = o;
|
|
1420
1425
|
}
|
|
1421
|
-
function
|
|
1426
|
+
function Wn(t, e) {
|
|
1422
1427
|
return t < e ? -1 : t > e ? 1 : 0;
|
|
1423
1428
|
}
|
|
1424
|
-
class
|
|
1429
|
+
class qn {
|
|
1425
1430
|
constructor(e = 9) {
|
|
1426
1431
|
this._maxEntries = Math.max(4, e), this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4)), this.clear();
|
|
1427
1432
|
}
|
|
@@ -1431,12 +1436,12 @@ class Wn {
|
|
|
1431
1436
|
search(e) {
|
|
1432
1437
|
let n = this.data;
|
|
1433
1438
|
const o = [];
|
|
1434
|
-
if (!
|
|
1439
|
+
if (!wt(e, n)) return o;
|
|
1435
1440
|
const i = this.toBBox, s = [];
|
|
1436
1441
|
for (; n; ) {
|
|
1437
1442
|
for (let a = 0; a < n.children.length; a++) {
|
|
1438
|
-
const r = n.children[a],
|
|
1439
|
-
|
|
1443
|
+
const r = n.children[a], d = n.leaf ? i(r) : r;
|
|
1444
|
+
wt(e, d) && (n.leaf ? o.push(r) : It(e, d) ? this._all(r, o) : s.push(r));
|
|
1440
1445
|
}
|
|
1441
1446
|
n = s.pop();
|
|
1442
1447
|
}
|
|
@@ -1444,13 +1449,13 @@ class Wn {
|
|
|
1444
1449
|
}
|
|
1445
1450
|
collides(e) {
|
|
1446
1451
|
let n = this.data;
|
|
1447
|
-
if (!
|
|
1452
|
+
if (!wt(e, n)) return !1;
|
|
1448
1453
|
const o = [];
|
|
1449
1454
|
for (; n; ) {
|
|
1450
1455
|
for (let i = 0; i < n.children.length; i++) {
|
|
1451
1456
|
const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
|
|
1452
|
-
if (
|
|
1453
|
-
if (n.leaf ||
|
|
1457
|
+
if (wt(e, a)) {
|
|
1458
|
+
if (n.leaf || It(e, a)) return !0;
|
|
1454
1459
|
o.push(s);
|
|
1455
1460
|
}
|
|
1456
1461
|
}
|
|
@@ -1483,20 +1488,20 @@ class Wn {
|
|
|
1483
1488
|
return e && this._insert(e, this.data.height - 1), this;
|
|
1484
1489
|
}
|
|
1485
1490
|
clear() {
|
|
1486
|
-
return this.data =
|
|
1491
|
+
return this.data = et([]), this;
|
|
1487
1492
|
}
|
|
1488
1493
|
remove(e, n) {
|
|
1489
1494
|
if (!e) return this;
|
|
1490
1495
|
let o = this.data;
|
|
1491
1496
|
const i = this.toBBox(e), s = [], a = [];
|
|
1492
|
-
let r,
|
|
1497
|
+
let r, d, f;
|
|
1493
1498
|
for (; o || s.length; ) {
|
|
1494
|
-
if (o || (o = s.pop(),
|
|
1495
|
-
const
|
|
1496
|
-
if (
|
|
1497
|
-
return o.children.splice(
|
|
1499
|
+
if (o || (o = s.pop(), d = s[s.length - 1], r = a.pop(), f = !0), o.leaf) {
|
|
1500
|
+
const g = Gn(e, o.children, n);
|
|
1501
|
+
if (g !== -1)
|
|
1502
|
+
return o.children.splice(g, 1), s.push(o), this._condense(s), this;
|
|
1498
1503
|
}
|
|
1499
|
-
!f && !o.leaf &&
|
|
1504
|
+
!f && !o.leaf && It(o, i) ? (s.push(o), a.push(r), r = 0, d = o, o = o.children[0]) : d ? (r++, o = d.children[r], f = !1) : o = null;
|
|
1500
1505
|
}
|
|
1501
1506
|
return this;
|
|
1502
1507
|
}
|
|
@@ -1525,26 +1530,26 @@ class Wn {
|
|
|
1525
1530
|
const s = o - n + 1;
|
|
1526
1531
|
let a = this._maxEntries, r;
|
|
1527
1532
|
if (s <= a)
|
|
1528
|
-
return r =
|
|
1529
|
-
i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r =
|
|
1530
|
-
const
|
|
1533
|
+
return r = et(e.slice(n, o + 1)), tt(r, this.toBBox), r;
|
|
1534
|
+
i || (i = Math.ceil(Math.log(s) / Math.log(a)), a = Math.ceil(s / Math.pow(a, i - 1))), r = et([]), r.leaf = !1, r.height = i;
|
|
1535
|
+
const d = Math.ceil(s / a), f = d * Math.ceil(Math.sqrt(a));
|
|
1531
1536
|
ee(e, n, o, f, this.compareMinX);
|
|
1532
|
-
for (let
|
|
1533
|
-
const u = Math.min(
|
|
1534
|
-
ee(e,
|
|
1535
|
-
for (let
|
|
1536
|
-
const v = Math.min(
|
|
1537
|
-
r.children.push(this._build(e,
|
|
1537
|
+
for (let g = n; g <= o; g += f) {
|
|
1538
|
+
const u = Math.min(g + f - 1, o);
|
|
1539
|
+
ee(e, g, u, d, this.compareMinY);
|
|
1540
|
+
for (let h = g; h <= u; h += d) {
|
|
1541
|
+
const v = Math.min(h + d - 1, u);
|
|
1542
|
+
r.children.push(this._build(e, h, v, i - 1));
|
|
1538
1543
|
}
|
|
1539
1544
|
}
|
|
1540
|
-
return
|
|
1545
|
+
return tt(r, this.toBBox), r;
|
|
1541
1546
|
}
|
|
1542
1547
|
_chooseSubtree(e, n, o, i) {
|
|
1543
1548
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
1544
1549
|
let s = 1 / 0, a = 1 / 0, r;
|
|
1545
|
-
for (let
|
|
1546
|
-
const f = n.children[
|
|
1547
|
-
u < a ? (a = u, s =
|
|
1550
|
+
for (let d = 0; d < n.children.length; d++) {
|
|
1551
|
+
const f = n.children[d], g = Bt(f), u = Zn(e, f) - g;
|
|
1552
|
+
u < a ? (a = u, s = g < s ? g : s, r = f) : u === a && g < s && (s = g, r = f);
|
|
1548
1553
|
}
|
|
1549
1554
|
n = r || n.children[0];
|
|
1550
1555
|
}
|
|
@@ -1552,7 +1557,7 @@ class Wn {
|
|
|
1552
1557
|
}
|
|
1553
1558
|
_insert(e, n, o) {
|
|
1554
1559
|
const i = o ? e : this.toBBox(e), s = [], a = this._chooseSubtree(i, this.data, n, s);
|
|
1555
|
-
for (a.children.push(e),
|
|
1560
|
+
for (a.children.push(e), lt(a, i); n >= 0 && s[n].children.length > this._maxEntries; )
|
|
1556
1561
|
this._split(s, n), n--;
|
|
1557
1562
|
this._adjustParentBBoxes(i, s, n);
|
|
1558
1563
|
}
|
|
@@ -1560,95 +1565,95 @@ class Wn {
|
|
|
1560
1565
|
_split(e, n) {
|
|
1561
1566
|
const o = e[n], i = o.children.length, s = this._minEntries;
|
|
1562
1567
|
this._chooseSplitAxis(o, s, i);
|
|
1563
|
-
const a = this._chooseSplitIndex(o, s, i), r =
|
|
1564
|
-
r.height = o.height, r.leaf = o.leaf,
|
|
1568
|
+
const a = this._chooseSplitIndex(o, s, i), r = et(o.children.splice(a, o.children.length - a));
|
|
1569
|
+
r.height = o.height, r.leaf = o.leaf, tt(o, this.toBBox), tt(r, this.toBBox), n ? e[n - 1].children.push(r) : this._splitRoot(o, r);
|
|
1565
1570
|
}
|
|
1566
1571
|
_splitRoot(e, n) {
|
|
1567
|
-
this.data =
|
|
1572
|
+
this.data = et([e, n]), this.data.height = e.height + 1, this.data.leaf = !1, tt(this.data, this.toBBox);
|
|
1568
1573
|
}
|
|
1569
1574
|
_chooseSplitIndex(e, n, o) {
|
|
1570
1575
|
let i, s = 1 / 0, a = 1 / 0;
|
|
1571
1576
|
for (let r = n; r <= o - n; r++) {
|
|
1572
|
-
const
|
|
1573
|
-
|
|
1577
|
+
const d = at(e, 0, r, this.toBBox), f = at(e, r, o, this.toBBox), g = to(d, f), u = Bt(d) + Bt(f);
|
|
1578
|
+
g < s ? (s = g, i = r, a = u < a ? u : a) : g === s && u < a && (a = u, i = r);
|
|
1574
1579
|
}
|
|
1575
1580
|
return i || o - n;
|
|
1576
1581
|
}
|
|
1577
1582
|
// sorts node children by the best axis for split
|
|
1578
1583
|
_chooseSplitAxis(e, n, o) {
|
|
1579
|
-
const i = e.leaf ? this.compareMinX :
|
|
1584
|
+
const i = e.leaf ? this.compareMinX : Qn, s = e.leaf ? this.compareMinY : Jn, a = this._allDistMargin(e, n, o, i), r = this._allDistMargin(e, n, o, s);
|
|
1580
1585
|
a < r && e.children.sort(i);
|
|
1581
1586
|
}
|
|
1582
1587
|
// total margin of all possible split distributions where each node is at least m full
|
|
1583
1588
|
_allDistMargin(e, n, o, i) {
|
|
1584
1589
|
e.children.sort(i);
|
|
1585
|
-
const s = this.toBBox, a =
|
|
1586
|
-
let
|
|
1590
|
+
const s = this.toBBox, a = at(e, 0, n, s), r = at(e, o - n, o, s);
|
|
1591
|
+
let d = bt(a) + bt(r);
|
|
1587
1592
|
for (let f = n; f < o - n; f++) {
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1593
|
+
const g = e.children[f];
|
|
1594
|
+
lt(a, e.leaf ? s(g) : g), d += bt(a);
|
|
1590
1595
|
}
|
|
1591
1596
|
for (let f = o - n - 1; f >= n; f--) {
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1597
|
+
const g = e.children[f];
|
|
1598
|
+
lt(r, e.leaf ? s(g) : g), d += bt(r);
|
|
1594
1599
|
}
|
|
1595
|
-
return
|
|
1600
|
+
return d;
|
|
1596
1601
|
}
|
|
1597
1602
|
_adjustParentBBoxes(e, n, o) {
|
|
1598
1603
|
for (let i = o; i >= 0; i--)
|
|
1599
|
-
|
|
1604
|
+
lt(n[i], e);
|
|
1600
1605
|
}
|
|
1601
1606
|
_condense(e) {
|
|
1602
1607
|
for (let n = e.length - 1, o; n >= 0; n--)
|
|
1603
|
-
e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() :
|
|
1608
|
+
e[n].children.length === 0 ? n > 0 ? (o = e[n - 1].children, o.splice(o.indexOf(e[n]), 1)) : this.clear() : tt(e[n], this.toBBox);
|
|
1604
1609
|
}
|
|
1605
1610
|
}
|
|
1606
|
-
function
|
|
1611
|
+
function Gn(t, e, n) {
|
|
1607
1612
|
if (!n) return e.indexOf(t);
|
|
1608
1613
|
for (let o = 0; o < e.length; o++)
|
|
1609
1614
|
if (n(t, e[o])) return o;
|
|
1610
1615
|
return -1;
|
|
1611
1616
|
}
|
|
1612
|
-
function
|
|
1613
|
-
|
|
1617
|
+
function tt(t, e) {
|
|
1618
|
+
at(t, 0, t.children.length, e, t);
|
|
1614
1619
|
}
|
|
1615
|
-
function
|
|
1616
|
-
i || (i =
|
|
1620
|
+
function at(t, e, n, o, i) {
|
|
1621
|
+
i || (i = et(null)), i.minX = 1 / 0, i.minY = 1 / 0, i.maxX = -1 / 0, i.maxY = -1 / 0;
|
|
1617
1622
|
for (let s = e; s < n; s++) {
|
|
1618
1623
|
const a = t.children[s];
|
|
1619
|
-
|
|
1624
|
+
lt(i, t.leaf ? o(a) : a);
|
|
1620
1625
|
}
|
|
1621
1626
|
return i;
|
|
1622
1627
|
}
|
|
1623
|
-
function
|
|
1628
|
+
function lt(t, e) {
|
|
1624
1629
|
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;
|
|
1625
1630
|
}
|
|
1626
|
-
function
|
|
1631
|
+
function Qn(t, e) {
|
|
1627
1632
|
return t.minX - e.minX;
|
|
1628
1633
|
}
|
|
1629
|
-
function
|
|
1634
|
+
function Jn(t, e) {
|
|
1630
1635
|
return t.minY - e.minY;
|
|
1631
1636
|
}
|
|
1632
1637
|
function Bt(t) {
|
|
1633
1638
|
return (t.maxX - t.minX) * (t.maxY - t.minY);
|
|
1634
1639
|
}
|
|
1635
|
-
function
|
|
1640
|
+
function bt(t) {
|
|
1636
1641
|
return t.maxX - t.minX + (t.maxY - t.minY);
|
|
1637
1642
|
}
|
|
1638
|
-
function
|
|
1643
|
+
function Zn(t, e) {
|
|
1639
1644
|
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));
|
|
1640
1645
|
}
|
|
1641
|
-
function
|
|
1646
|
+
function to(t, e) {
|
|
1642
1647
|
const n = Math.max(t.minX, e.minX), o = Math.max(t.minY, e.minY), i = Math.min(t.maxX, e.maxX), s = Math.min(t.maxY, e.maxY);
|
|
1643
1648
|
return Math.max(0, i - n) * Math.max(0, s - o);
|
|
1644
1649
|
}
|
|
1645
|
-
function
|
|
1650
|
+
function It(t, e) {
|
|
1646
1651
|
return t.minX <= e.minX && t.minY <= e.minY && e.maxX <= t.maxX && e.maxY <= t.maxY;
|
|
1647
1652
|
}
|
|
1648
|
-
function
|
|
1653
|
+
function wt(t, e) {
|
|
1649
1654
|
return e.minX <= t.maxX && e.minY <= t.maxY && e.maxX >= t.minX && e.maxY >= t.minY;
|
|
1650
1655
|
}
|
|
1651
|
-
function
|
|
1656
|
+
function et(t) {
|
|
1652
1657
|
return {
|
|
1653
1658
|
children: t,
|
|
1654
1659
|
height: 1,
|
|
@@ -1667,177 +1672,177 @@ function ee(t, e, n, o, i) {
|
|
|
1667
1672
|
me(t, a, e, n, i), s.push(e, a, a, n);
|
|
1668
1673
|
}
|
|
1669
1674
|
}
|
|
1670
|
-
const
|
|
1671
|
-
const n = new
|
|
1672
|
-
const
|
|
1673
|
-
const
|
|
1674
|
-
return Array.from(
|
|
1675
|
-
}), S = Ne(
|
|
1675
|
+
const eo = (t, e) => {
|
|
1676
|
+
const n = new qn(), o = /* @__PURE__ */ new Map(), i = (c, l) => {
|
|
1677
|
+
const m = c.selector.flatMap((E) => {
|
|
1678
|
+
const L = q([E]) ? E.range : ae(E, e).range;
|
|
1679
|
+
return Array.from(L.getClientRects());
|
|
1680
|
+
}), S = Ne(m).map(({ left: E, top: L, right: R, bottom: U }) => new DOMRect(E - l.left, L - l.top, R - E, U - L));
|
|
1676
1681
|
return S.map((E) => {
|
|
1677
|
-
const { x:
|
|
1682
|
+
const { x: L, y: R, width: U, height: V } = E;
|
|
1678
1683
|
return {
|
|
1679
|
-
minX:
|
|
1684
|
+
minX: L,
|
|
1680
1685
|
minY: R,
|
|
1681
|
-
maxX:
|
|
1682
|
-
maxY: R +
|
|
1686
|
+
maxX: L + U,
|
|
1687
|
+
maxY: R + V,
|
|
1683
1688
|
annotation: {
|
|
1684
|
-
id:
|
|
1689
|
+
id: c.annotation,
|
|
1685
1690
|
rects: S
|
|
1686
1691
|
}
|
|
1687
1692
|
};
|
|
1688
1693
|
});
|
|
1689
1694
|
}, s = () => [...o.values()], a = () => {
|
|
1690
1695
|
n.clear(), o.clear();
|
|
1691
|
-
}, r = (
|
|
1692
|
-
const
|
|
1693
|
-
|
|
1694
|
-
},
|
|
1695
|
-
const
|
|
1696
|
-
|
|
1697
|
-
}, f = (
|
|
1698
|
-
|
|
1699
|
-
},
|
|
1700
|
-
|
|
1701
|
-
const
|
|
1702
|
-
S.forEach(({ target:
|
|
1703
|
-
R.length > 0 && o.set(
|
|
1696
|
+
}, r = (c) => {
|
|
1697
|
+
const l = i(c, e.getBoundingClientRect());
|
|
1698
|
+
l.length !== 0 && (l.forEach((m) => n.insert(m)), o.set(c.annotation, l));
|
|
1699
|
+
}, d = (c) => {
|
|
1700
|
+
const l = o.get(c.annotation);
|
|
1701
|
+
l && (l.forEach((m) => n.remove(m)), o.delete(c.annotation));
|
|
1702
|
+
}, f = (c) => {
|
|
1703
|
+
d(c), r(c);
|
|
1704
|
+
}, g = (c, l = !0) => {
|
|
1705
|
+
l && a();
|
|
1706
|
+
const m = e.getBoundingClientRect(), S = c.map((L) => ({ target: L, rects: i(L, m) }));
|
|
1707
|
+
S.forEach(({ target: L, rects: R }) => {
|
|
1708
|
+
R.length > 0 && o.set(L.annotation, R);
|
|
1704
1709
|
});
|
|
1705
|
-
const E = S.flatMap(({ rects:
|
|
1710
|
+
const E = S.flatMap(({ rects: L }) => L);
|
|
1706
1711
|
n.load(E);
|
|
1707
|
-
}, u = (
|
|
1712
|
+
}, u = (c, l, m = !1) => {
|
|
1708
1713
|
const S = n.search({
|
|
1709
|
-
minX:
|
|
1710
|
-
minY:
|
|
1711
|
-
maxX:
|
|
1712
|
-
maxY:
|
|
1713
|
-
}), E = (
|
|
1714
|
-
return S.length > 0 ? (S.sort((
|
|
1715
|
-
},
|
|
1716
|
-
const
|
|
1717
|
-
if (
|
|
1714
|
+
minX: c,
|
|
1715
|
+
minY: l,
|
|
1716
|
+
maxX: c,
|
|
1717
|
+
maxY: l
|
|
1718
|
+
}), E = (L) => L.annotation.rects.reduce((R, U) => R + U.width * U.height, 0);
|
|
1719
|
+
return S.length > 0 ? (S.sort((L, R) => E(L) - E(R)), m ? S.map((L) => L.annotation.id) : [S[0].annotation.id]) : [];
|
|
1720
|
+
}, h = (c) => {
|
|
1721
|
+
const l = v(c);
|
|
1722
|
+
if (l.length === 0)
|
|
1718
1723
|
return;
|
|
1719
|
-
let
|
|
1720
|
-
for (let R = 1; R <
|
|
1721
|
-
const
|
|
1722
|
-
|
|
1724
|
+
let m = l[0].left, S = l[0].top, E = l[0].right, L = l[0].bottom;
|
|
1725
|
+
for (let R = 1; R < l.length; R++) {
|
|
1726
|
+
const U = l[R];
|
|
1727
|
+
m = Math.min(m, U.left), S = Math.min(S, U.top), E = Math.max(E, U.right), L = Math.max(L, U.bottom);
|
|
1723
1728
|
}
|
|
1724
|
-
return new DOMRect(
|
|
1725
|
-
}, v = (
|
|
1726
|
-
const
|
|
1727
|
-
return
|
|
1729
|
+
return new DOMRect(m, S, E - m, L - S);
|
|
1730
|
+
}, v = (c) => {
|
|
1731
|
+
const l = o.get(c);
|
|
1732
|
+
return l ? l[0].annotation.rects : [];
|
|
1728
1733
|
};
|
|
1729
1734
|
return {
|
|
1730
1735
|
all: s,
|
|
1731
1736
|
clear: a,
|
|
1732
1737
|
getAt: u,
|
|
1733
|
-
getAnnotationBounds:
|
|
1738
|
+
getAnnotationBounds: h,
|
|
1734
1739
|
getAnnotationRects: v,
|
|
1735
|
-
getIntersecting: (
|
|
1736
|
-
const E = n.search({ minX:
|
|
1737
|
-
return Array.from(
|
|
1740
|
+
getIntersecting: (c, l, m, S) => {
|
|
1741
|
+
const E = n.search({ minX: c, minY: l, maxX: m, maxY: S }), L = new Set(E.map((R) => R.annotation.id));
|
|
1742
|
+
return Array.from(L).map((R) => ({
|
|
1738
1743
|
annotation: t.getAnnotation(R),
|
|
1739
1744
|
rects: v(R)
|
|
1740
1745
|
})).filter((R) => !!R.annotation);
|
|
1741
1746
|
},
|
|
1742
1747
|
insert: r,
|
|
1743
|
-
recalculate: () =>
|
|
1744
|
-
remove:
|
|
1745
|
-
set:
|
|
1748
|
+
recalculate: () => g(t.all().map((c) => c.target), !0),
|
|
1749
|
+
remove: d,
|
|
1750
|
+
set: g,
|
|
1746
1751
|
size: () => n.all().length,
|
|
1747
1752
|
update: f
|
|
1748
1753
|
};
|
|
1749
|
-
},
|
|
1750
|
-
const n =
|
|
1751
|
-
const
|
|
1752
|
-
return S && n.addAnnotation(
|
|
1753
|
-
},
|
|
1754
|
-
const S =
|
|
1755
|
-
return n.bulkAddAnnotations(S,
|
|
1756
|
-
}, f = (
|
|
1757
|
-
const
|
|
1758
|
-
return
|
|
1759
|
-
n.getAnnotation(E.id) ? n.updateAnnotation(E,
|
|
1754
|
+
}, no = (t, e) => {
|
|
1755
|
+
const n = Tn(), o = eo(n, t), i = gn(n, e.userSelectAction, e.adapter), s = fn(n), a = kn(), r = (c, l = B.LOCAL) => {
|
|
1756
|
+
const m = St(c, t), S = q(m.target.selector);
|
|
1757
|
+
return S && n.addAnnotation(m, l), S;
|
|
1758
|
+
}, d = (c, l = !0, m = B.LOCAL) => {
|
|
1759
|
+
const S = c.map((L) => St(L, t)), E = S.filter((L) => !q(L.target.selector));
|
|
1760
|
+
return n.bulkAddAnnotations(S, l, m), E;
|
|
1761
|
+
}, f = (c, l = B.LOCAL) => {
|
|
1762
|
+
const m = c.map((E) => St(E, t)), S = m.filter((E) => !q(E.target.selector));
|
|
1763
|
+
return m.forEach((E) => {
|
|
1764
|
+
n.getAnnotation(E.id) ? n.updateAnnotation(E, l) : n.addAnnotation(E, l);
|
|
1760
1765
|
}), S;
|
|
1761
|
-
},
|
|
1762
|
-
const
|
|
1763
|
-
n.updateTarget(
|
|
1764
|
-
}, u = (
|
|
1765
|
-
const
|
|
1766
|
-
n.bulkUpdateTargets(
|
|
1766
|
+
}, g = (c, l = B.LOCAL) => {
|
|
1767
|
+
const m = At(c, t);
|
|
1768
|
+
n.updateTarget(m, l);
|
|
1769
|
+
}, u = (c, l = B.LOCAL) => {
|
|
1770
|
+
const m = c.map((S) => At(S, t));
|
|
1771
|
+
n.bulkUpdateTargets(m, l);
|
|
1767
1772
|
};
|
|
1768
|
-
function
|
|
1769
|
-
const E =
|
|
1773
|
+
function h(c, l, m, S) {
|
|
1774
|
+
const E = m || !!S, L = o.getAt(c, l, E).map((U) => n.getAnnotation(U)), R = S ? L.filter(S) : L;
|
|
1770
1775
|
if (R.length !== 0)
|
|
1771
|
-
return
|
|
1776
|
+
return m ? R : R[0];
|
|
1772
1777
|
}
|
|
1773
|
-
const v = (
|
|
1774
|
-
if (o.getAnnotationRects(
|
|
1775
|
-
return o.getAnnotationBounds(
|
|
1776
|
-
},
|
|
1777
|
-
return n.observe(({ changes:
|
|
1778
|
-
const
|
|
1779
|
-
(
|
|
1778
|
+
const v = (c) => {
|
|
1779
|
+
if (o.getAnnotationRects(c).length !== 0)
|
|
1780
|
+
return o.getAnnotationBounds(c);
|
|
1781
|
+
}, b = (c, l, m, S) => o.getIntersecting(c, l, m, S), p = (c) => o.getAnnotationRects(c), x = () => o.recalculate();
|
|
1782
|
+
return n.observe(({ changes: c }) => {
|
|
1783
|
+
const l = (c.deleted || []).filter((E) => q(E.target.selector)), m = (c.created || []).filter((E) => q(E.target.selector)), S = (c.updated || []).filter((E) => q(E.newValue.target.selector));
|
|
1784
|
+
(l == null ? void 0 : l.length) > 0 && l.forEach((E) => o.remove(E.target)), m.length > 0 && o.set(m.map((E) => E.target), !1), (S == null ? void 0 : S.length) > 0 && S.forEach(({ newValue: E }) => o.update(E.target));
|
|
1780
1785
|
}), {
|
|
1781
1786
|
store: {
|
|
1782
1787
|
...n,
|
|
1783
1788
|
addAnnotation: r,
|
|
1784
|
-
bulkAddAnnotations:
|
|
1789
|
+
bulkAddAnnotations: d,
|
|
1785
1790
|
bulkUpdateTargets: u,
|
|
1786
1791
|
bulkUpsertAnnotations: f,
|
|
1787
1792
|
getAnnotationBounds: v,
|
|
1788
|
-
getAnnotationRects:
|
|
1789
|
-
getIntersecting:
|
|
1790
|
-
getAt:
|
|
1791
|
-
recalculatePositions:
|
|
1792
|
-
updateTarget:
|
|
1793
|
+
getAnnotationRects: p,
|
|
1794
|
+
getIntersecting: b,
|
|
1795
|
+
getAt: h,
|
|
1796
|
+
recalculatePositions: x,
|
|
1797
|
+
updateTarget: g
|
|
1793
1798
|
},
|
|
1794
1799
|
selection: i,
|
|
1795
1800
|
hover: s,
|
|
1796
1801
|
viewport: a
|
|
1797
1802
|
};
|
|
1798
|
-
},
|
|
1803
|
+
}, oo = () => {
|
|
1799
1804
|
const t = document.createElement("canvas");
|
|
1800
1805
|
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
|
|
1801
1806
|
const e = t.getContext("2d");
|
|
1802
1807
|
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
1803
|
-
},
|
|
1804
|
-
const n =
|
|
1808
|
+
}, io = (t, e = {}) => {
|
|
1809
|
+
const n = oo(), o = n.getContext("2d");
|
|
1805
1810
|
document.body.appendChild(n);
|
|
1806
|
-
const i = /* @__PURE__ */ new Map(), s = (
|
|
1807
|
-
return t.on("selectionChange", (
|
|
1808
|
-
s(
|
|
1811
|
+
const i = /* @__PURE__ */ new Map(), s = (g) => Array.from(i.entries()).filter(([u, h]) => h.presenceKey === g.presenceKey).map(([u, h]) => u);
|
|
1812
|
+
return t.on("selectionChange", (g, u) => {
|
|
1813
|
+
s(g).forEach((v) => i.delete(v)), u && u.forEach((v) => i.set(v, g));
|
|
1809
1814
|
}), {
|
|
1810
1815
|
clear: () => {
|
|
1811
|
-
const { width:
|
|
1812
|
-
o.clearRect(-0.5, -0.5,
|
|
1816
|
+
const { width: g, height: u } = n;
|
|
1817
|
+
o.clearRect(-0.5, -0.5, g + 1, u + 1);
|
|
1813
1818
|
},
|
|
1814
1819
|
destroy: () => {
|
|
1815
1820
|
n.remove();
|
|
1816
1821
|
},
|
|
1817
|
-
paint: (
|
|
1822
|
+
paint: (g, u, h) => {
|
|
1818
1823
|
e.font && (o.font = e.font);
|
|
1819
|
-
const v = i.get(
|
|
1824
|
+
const v = i.get(g.annotation.id);
|
|
1820
1825
|
if (v) {
|
|
1821
|
-
const { height:
|
|
1822
|
-
o.fillStyle = v.appearance.color, o.fillRect(
|
|
1823
|
-
const
|
|
1824
|
-
return o.fillRect(
|
|
1826
|
+
const { height: b } = g.rects[0], p = g.rects[0].x + u.left, x = g.rects[0].y + u.top;
|
|
1827
|
+
o.fillStyle = v.appearance.color, o.fillRect(p - 2, x - 2.5, 2, b + 5);
|
|
1828
|
+
const c = o.measureText(v.appearance.label), l = c.width + 6, m = c.actualBoundingBoxAscent + c.actualBoundingBoxDescent + 8, S = c.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1829
|
+
return o.fillRect(p - 2, x - 2.5 - m, l, m), o.fillStyle = "#fff", o.fillText(v.appearance.label, p + 1, x - S), {
|
|
1825
1830
|
fill: v.appearance.color,
|
|
1826
|
-
fillOpacity:
|
|
1831
|
+
fillOpacity: h ? 0.45 : 0.18
|
|
1827
1832
|
};
|
|
1828
1833
|
}
|
|
1829
1834
|
},
|
|
1830
1835
|
reset: () => {
|
|
1831
1836
|
n.width = 2 * window.innerWidth, n.height = 2 * window.innerHeight;
|
|
1832
|
-
const
|
|
1833
|
-
|
|
1837
|
+
const g = n.getContext("2d");
|
|
1838
|
+
g.scale(2, 2), g.translate(0.5, 0.5);
|
|
1834
1839
|
}
|
|
1835
1840
|
};
|
|
1836
|
-
},
|
|
1841
|
+
}, Ut = typeof navigator < "u" ? navigator.userAgent.toLowerCase().indexOf("firefox") > 0 : !1;
|
|
1837
1842
|
function _t(t, e, n, o) {
|
|
1838
1843
|
t.addEventListener ? t.addEventListener(e, n, o) : t.attachEvent && t.attachEvent("on".concat(e), n);
|
|
1839
1844
|
}
|
|
1840
|
-
function
|
|
1845
|
+
function st(t, e, n, o) {
|
|
1841
1846
|
t.removeEventListener ? t.removeEventListener(e, n, o) : t.detachEvent && t.detachEvent("on".concat(e), n);
|
|
1842
1847
|
}
|
|
1843
1848
|
function ye(t, e) {
|
|
@@ -1853,14 +1858,14 @@ function be(t) {
|
|
|
1853
1858
|
e[n - 1] += ",", e.splice(n, 1), n = e.lastIndexOf("");
|
|
1854
1859
|
return e;
|
|
1855
1860
|
}
|
|
1856
|
-
function
|
|
1861
|
+
function so(t, e) {
|
|
1857
1862
|
const n = t.length >= e.length ? t : e, o = t.length >= e.length ? e : t;
|
|
1858
1863
|
let i = !0;
|
|
1859
1864
|
for (let s = 0; s < n.length; s++)
|
|
1860
1865
|
o.indexOf(n[s]) === -1 && (i = !1);
|
|
1861
1866
|
return i;
|
|
1862
1867
|
}
|
|
1863
|
-
const
|
|
1868
|
+
const ft = {
|
|
1864
1869
|
backspace: 8,
|
|
1865
1870
|
"⌫": 8,
|
|
1866
1871
|
tab: 9,
|
|
@@ -1875,6 +1880,11 @@ const dt = {
|
|
|
1875
1880
|
up: 38,
|
|
1876
1881
|
right: 39,
|
|
1877
1882
|
down: 40,
|
|
1883
|
+
/// https://w3c.github.io/uievents/#events-keyboard-key-location
|
|
1884
|
+
arrowup: 38,
|
|
1885
|
+
arrowdown: 40,
|
|
1886
|
+
arrowleft: 37,
|
|
1887
|
+
arrowright: 39,
|
|
1878
1888
|
del: 46,
|
|
1879
1889
|
delete: 46,
|
|
1880
1890
|
ins: 45,
|
|
@@ -1905,10 +1915,12 @@ const dt = {
|
|
|
1905
1915
|
".": 190,
|
|
1906
1916
|
"/": 191,
|
|
1907
1917
|
"`": 192,
|
|
1908
|
-
"-":
|
|
1909
|
-
"=":
|
|
1910
|
-
";":
|
|
1918
|
+
"-": Ut ? 173 : 189,
|
|
1919
|
+
"=": Ut ? 61 : 187,
|
|
1920
|
+
";": Ut ? 59 : 186,
|
|
1911
1921
|
"'": 222,
|
|
1922
|
+
"{": 219,
|
|
1923
|
+
"}": 221,
|
|
1912
1924
|
"[": 219,
|
|
1913
1925
|
"]": 221,
|
|
1914
1926
|
"\\": 220
|
|
@@ -1927,8 +1939,9 @@ const dt = {
|
|
|
1927
1939
|
// metaKey
|
|
1928
1940
|
"⌘": 91,
|
|
1929
1941
|
cmd: 91,
|
|
1942
|
+
meta: 91,
|
|
1930
1943
|
command: 91
|
|
1931
|
-
},
|
|
1944
|
+
}, ct = {
|
|
1932
1945
|
16: "shiftKey",
|
|
1933
1946
|
18: "altKey",
|
|
1934
1947
|
17: "ctrlKey",
|
|
@@ -1944,22 +1957,22 @@ const dt = {
|
|
|
1944
1957
|
91: !1
|
|
1945
1958
|
}, N = {};
|
|
1946
1959
|
for (let t = 1; t < 20; t++)
|
|
1947
|
-
|
|
1948
|
-
let
|
|
1949
|
-
const W = /* @__PURE__ */ new Map(),
|
|
1950
|
-
function
|
|
1960
|
+
ft["f".concat(t)] = 111 + t;
|
|
1961
|
+
let _ = [], ut = null, we = "all";
|
|
1962
|
+
const W = /* @__PURE__ */ new Map(), ot = (t) => ft[t.toLowerCase()] || z[t.toLowerCase()] || t.toUpperCase().charCodeAt(0), ro = (t) => Object.keys(ft).find((e) => ft[e] === t), ao = (t) => Object.keys(z).find((e) => z[e] === t);
|
|
1963
|
+
function xe(t) {
|
|
1951
1964
|
we = t || "all";
|
|
1952
1965
|
}
|
|
1953
|
-
function
|
|
1966
|
+
function ht() {
|
|
1954
1967
|
return we || "all";
|
|
1955
1968
|
}
|
|
1956
|
-
function
|
|
1957
|
-
return
|
|
1969
|
+
function lo() {
|
|
1970
|
+
return _.slice(0);
|
|
1958
1971
|
}
|
|
1959
1972
|
function co() {
|
|
1960
|
-
return
|
|
1973
|
+
return _.map((t) => ro(t) || ao(t) || String.fromCharCode(t));
|
|
1961
1974
|
}
|
|
1962
|
-
function
|
|
1975
|
+
function uo() {
|
|
1963
1976
|
const t = [];
|
|
1964
1977
|
return Object.keys(N).forEach((e) => {
|
|
1965
1978
|
N[e].forEach((n) => {
|
|
@@ -1973,12 +1986,12 @@ function lo() {
|
|
|
1973
1986
|
scope: i,
|
|
1974
1987
|
shortcut: a,
|
|
1975
1988
|
mods: s,
|
|
1976
|
-
keys: o.split("+").map((r) =>
|
|
1989
|
+
keys: o.split("+").map((r) => ot(r))
|
|
1977
1990
|
});
|
|
1978
1991
|
});
|
|
1979
1992
|
}), t;
|
|
1980
1993
|
}
|
|
1981
|
-
function
|
|
1994
|
+
function fo(t) {
|
|
1982
1995
|
const e = t.target || t.srcElement, {
|
|
1983
1996
|
tagName: n
|
|
1984
1997
|
} = e;
|
|
@@ -1986,12 +1999,12 @@ function uo(t) {
|
|
|
1986
1999
|
const i = n === "INPUT" && !["checkbox", "radio", "range", "button", "file", "reset", "submit", "color"].includes(e.type);
|
|
1987
2000
|
return (e.isContentEditable || (i || n === "TEXTAREA" || n === "SELECT") && !e.readOnly) && (o = !1), o;
|
|
1988
2001
|
}
|
|
1989
|
-
function
|
|
1990
|
-
return typeof t == "string" && (t =
|
|
2002
|
+
function ho(t) {
|
|
2003
|
+
return typeof t == "string" && (t = ot(t)), _.indexOf(t) !== -1;
|
|
1991
2004
|
}
|
|
1992
|
-
function
|
|
2005
|
+
function go(t, e) {
|
|
1993
2006
|
let n, o;
|
|
1994
|
-
t || (t =
|
|
2007
|
+
t || (t = ht());
|
|
1995
2008
|
for (const i in N)
|
|
1996
2009
|
if (Object.prototype.hasOwnProperty.call(N, i))
|
|
1997
2010
|
for (n = N[i], o = 0; o < n.length; )
|
|
@@ -1999,34 +2012,35 @@ function ho(t, e) {
|
|
|
1999
2012
|
let {
|
|
2000
2013
|
element: r
|
|
2001
2014
|
} = a;
|
|
2002
|
-
return
|
|
2015
|
+
return Pt(r);
|
|
2003
2016
|
}) : o++;
|
|
2004
|
-
|
|
2017
|
+
ht() === t && xe(e || "all");
|
|
2005
2018
|
}
|
|
2006
2019
|
function po(t) {
|
|
2007
2020
|
let e = t.keyCode || t.which || t.charCode;
|
|
2008
|
-
|
|
2009
|
-
|
|
2021
|
+
t.key && t.key.toLowerCase() === "capslock" && (e = ot(t.key));
|
|
2022
|
+
const n = _.indexOf(e);
|
|
2023
|
+
if (n >= 0 && _.splice(n, 1), t.key && t.key.toLowerCase() === "meta" && _.splice(0, _.length), (e === 93 || e === 224) && (e = 91), e in X) {
|
|
2010
2024
|
X[e] = !1;
|
|
2011
2025
|
for (const o in z) z[o] === e && (H[o] = !1);
|
|
2012
2026
|
}
|
|
2013
2027
|
}
|
|
2014
|
-
function
|
|
2028
|
+
function Ae(t) {
|
|
2015
2029
|
if (typeof t > "u")
|
|
2016
2030
|
Object.keys(N).forEach((i) => {
|
|
2017
|
-
Array.isArray(N[i]) && N[i].forEach((s) =>
|
|
2018
|
-
}),
|
|
2031
|
+
Array.isArray(N[i]) && N[i].forEach((s) => xt(s)), delete N[i];
|
|
2032
|
+
}), Pt(null);
|
|
2019
2033
|
else if (Array.isArray(t))
|
|
2020
2034
|
t.forEach((i) => {
|
|
2021
|
-
i.key &&
|
|
2035
|
+
i.key && xt(i);
|
|
2022
2036
|
});
|
|
2023
2037
|
else if (typeof t == "object")
|
|
2024
|
-
t.key &&
|
|
2038
|
+
t.key && xt(t);
|
|
2025
2039
|
else if (typeof t == "string") {
|
|
2026
2040
|
for (var e = arguments.length, n = new Array(e > 1 ? e - 1 : 0), o = 1; o < e; o++)
|
|
2027
2041
|
n[o - 1] = arguments[o];
|
|
2028
2042
|
let [i, s] = n;
|
|
2029
|
-
typeof i == "function" && (s = i, i = ""),
|
|
2043
|
+
typeof i == "function" && (s = i, i = ""), xt({
|
|
2030
2044
|
key: t,
|
|
2031
2045
|
scope: i,
|
|
2032
2046
|
method: s,
|
|
@@ -2034,7 +2048,7 @@ function xe(t) {
|
|
|
2034
2048
|
});
|
|
2035
2049
|
}
|
|
2036
2050
|
}
|
|
2037
|
-
const
|
|
2051
|
+
const xt = (t) => {
|
|
2038
2052
|
let {
|
|
2039
2053
|
key: e,
|
|
2040
2054
|
scope: n,
|
|
@@ -2042,14 +2056,14 @@ const wt = (t) => {
|
|
|
2042
2056
|
splitKey: i = "+"
|
|
2043
2057
|
} = t;
|
|
2044
2058
|
be(e).forEach((a) => {
|
|
2045
|
-
const r = a.split(i),
|
|
2046
|
-
if (!N[
|
|
2047
|
-
n || (n =
|
|
2048
|
-
const u =
|
|
2049
|
-
N[
|
|
2050
|
-
const
|
|
2051
|
-
return
|
|
2052
|
-
}),
|
|
2059
|
+
const r = a.split(i), d = r.length, f = r[d - 1], g = f === "*" ? "*" : ot(f);
|
|
2060
|
+
if (!N[g]) return;
|
|
2061
|
+
n || (n = ht());
|
|
2062
|
+
const u = d > 1 ? ye(z, r) : [], h = [];
|
|
2063
|
+
N[g] = N[g].filter((v) => {
|
|
2064
|
+
const p = (o ? v.method === o : !0) && v.scope === n && so(v.mods, u);
|
|
2065
|
+
return p && h.push(v.element), !p;
|
|
2066
|
+
}), h.forEach((v) => Pt(v));
|
|
2053
2067
|
});
|
|
2054
2068
|
};
|
|
2055
2069
|
function ne(t, e, n, o) {
|
|
@@ -2060,29 +2074,29 @@ function ne(t, e, n, o) {
|
|
|
2060
2074
|
i = e.mods.length > 0;
|
|
2061
2075
|
for (const s in X)
|
|
2062
2076
|
Object.prototype.hasOwnProperty.call(X, s) && (!X[s] && e.mods.indexOf(+s) > -1 || X[s] && e.mods.indexOf(+s) === -1) && (i = !1);
|
|
2063
|
-
(e.mods.length === 0 && !X[16] && !X[18] && !X[17] && !X[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(
|
|
2077
|
+
(e.mods.length === 0 && !X[16] && !X[18] && !X[17] && !X[91] || i || e.shortcut === "*") && (e.keys = [], e.keys = e.keys.concat(_), e.method(t, e) === !1 && (t.preventDefault ? t.preventDefault() : t.returnValue = !1, t.stopPropagation && t.stopPropagation(), t.cancelBubble && (t.cancelBubble = !0)));
|
|
2064
2078
|
}
|
|
2065
2079
|
}
|
|
2066
2080
|
function oe(t, e) {
|
|
2067
2081
|
const n = N["*"];
|
|
2068
2082
|
let o = t.keyCode || t.which || t.charCode;
|
|
2069
|
-
if (!H.filter.call(this, t)) return;
|
|
2070
|
-
if ((o === 93 || o === 224) && (o = 91),
|
|
2071
|
-
const
|
|
2072
|
-
t[r] &&
|
|
2083
|
+
if (t.key && t.key.toLowerCase() === "capslock" || !H.filter.call(this, t)) return;
|
|
2084
|
+
if ((o === 93 || o === 224) && (o = 91), _.indexOf(o) === -1 && o !== 229 && _.push(o), ["metaKey", "ctrlKey", "altKey", "shiftKey"].forEach((r) => {
|
|
2085
|
+
const d = ct[r];
|
|
2086
|
+
t[r] && _.indexOf(d) === -1 ? _.push(d) : !t[r] && _.indexOf(d) > -1 ? _.splice(_.indexOf(d), 1) : r === "metaKey" && t[r] && (_ = _.filter((f) => f in ct || f === o));
|
|
2073
2087
|
}), o in X) {
|
|
2074
2088
|
X[o] = !0;
|
|
2075
2089
|
for (const r in z)
|
|
2076
2090
|
if (Object.prototype.hasOwnProperty.call(z, r)) {
|
|
2077
|
-
const
|
|
2078
|
-
H[r] = t[
|
|
2091
|
+
const d = ct[z[r]];
|
|
2092
|
+
H[r] = t[d];
|
|
2079
2093
|
}
|
|
2080
2094
|
if (!n) return;
|
|
2081
2095
|
}
|
|
2082
2096
|
for (const r in X)
|
|
2083
|
-
Object.prototype.hasOwnProperty.call(X, r) && (X[r] = t[
|
|
2084
|
-
t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (
|
|
2085
|
-
const i =
|
|
2097
|
+
Object.prototype.hasOwnProperty.call(X, r) && (X[r] = t[ct[r]]);
|
|
2098
|
+
t.getModifierState && !(t.altKey && !t.ctrlKey) && t.getModifierState("AltGraph") && (_.indexOf(17) === -1 && _.push(17), _.indexOf(18) === -1 && _.push(18), X[17] = !0, X[18] = !0);
|
|
2099
|
+
const i = ht();
|
|
2086
2100
|
if (n)
|
|
2087
2101
|
for (let r = 0; r < n.length; r++)
|
|
2088
2102
|
n[r].scope === i && (t.type === "keydown" && n[r].keydown || t.type === "keyup" && n[r].keyup) && ne(t, n[r], i, e);
|
|
@@ -2090,57 +2104,57 @@ function oe(t, e) {
|
|
|
2090
2104
|
const s = N[o], a = s.length;
|
|
2091
2105
|
for (let r = 0; r < a; r++)
|
|
2092
2106
|
if ((t.type === "keydown" && s[r].keydown || t.type === "keyup" && s[r].keyup) && s[r].key) {
|
|
2093
|
-
const
|
|
2107
|
+
const d = s[r], {
|
|
2094
2108
|
splitKey: f
|
|
2095
|
-
} =
|
|
2096
|
-
for (let
|
|
2097
|
-
u.push(
|
|
2098
|
-
u.sort().join("") ===
|
|
2109
|
+
} = d, g = d.key.split(f), u = [];
|
|
2110
|
+
for (let h = 0; h < g.length; h++)
|
|
2111
|
+
u.push(ot(g[h]));
|
|
2112
|
+
u.sort().join("") === _.sort().join("") && ne(t, d, i, e);
|
|
2099
2113
|
}
|
|
2100
2114
|
}
|
|
2101
2115
|
function H(t, e, n) {
|
|
2102
|
-
|
|
2116
|
+
_ = [];
|
|
2103
2117
|
const o = be(t);
|
|
2104
|
-
let i = [], s = "all", a = document, r = 0,
|
|
2105
|
-
for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (
|
|
2106
|
-
t = o[r].split(
|
|
2107
|
-
keyup:
|
|
2118
|
+
let i = [], s = "all", a = document, r = 0, d = !1, f = !0, g = "+", u = !1, h = !1;
|
|
2119
|
+
for (n === void 0 && typeof e == "function" && (n = e), Object.prototype.toString.call(e) === "[object Object]" && (e.scope && (s = e.scope), e.element && (a = e.element), e.keyup && (d = e.keyup), e.keydown !== void 0 && (f = e.keydown), e.capture !== void 0 && (u = e.capture), typeof e.splitKey == "string" && (g = e.splitKey), e.single === !0 && (h = !0)), typeof e == "string" && (s = e), h && Ae(t, s); r < o.length; r++)
|
|
2120
|
+
t = o[r].split(g), i = [], t.length > 1 && (i = ye(z, t)), t = t[t.length - 1], t = t === "*" ? "*" : ot(t), t in N || (N[t] = []), N[t].push({
|
|
2121
|
+
keyup: d,
|
|
2108
2122
|
keydown: f,
|
|
2109
2123
|
scope: s,
|
|
2110
2124
|
mods: i,
|
|
2111
2125
|
shortcut: o[r],
|
|
2112
2126
|
method: n,
|
|
2113
2127
|
key: o[r],
|
|
2114
|
-
splitKey:
|
|
2128
|
+
splitKey: g,
|
|
2115
2129
|
element: a
|
|
2116
2130
|
});
|
|
2117
2131
|
if (typeof a < "u" && window) {
|
|
2118
2132
|
if (!W.has(a)) {
|
|
2119
2133
|
const v = function() {
|
|
2120
|
-
let
|
|
2121
|
-
return oe(
|
|
2122
|
-
},
|
|
2123
|
-
let
|
|
2124
|
-
oe(
|
|
2134
|
+
let p = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2135
|
+
return oe(p, a);
|
|
2136
|
+
}, b = function() {
|
|
2137
|
+
let p = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.event;
|
|
2138
|
+
oe(p, a), po(p);
|
|
2125
2139
|
};
|
|
2126
2140
|
W.set(a, {
|
|
2127
2141
|
keydownListener: v,
|
|
2128
|
-
keyupListenr:
|
|
2142
|
+
keyupListenr: b,
|
|
2129
2143
|
capture: u
|
|
2130
|
-
}), _t(a, "keydown", v, u), _t(a, "keyup",
|
|
2144
|
+
}), _t(a, "keydown", v, u), _t(a, "keyup", b, u);
|
|
2131
2145
|
}
|
|
2132
|
-
if (!
|
|
2146
|
+
if (!ut) {
|
|
2133
2147
|
const v = () => {
|
|
2134
|
-
|
|
2148
|
+
_ = [];
|
|
2135
2149
|
};
|
|
2136
|
-
|
|
2150
|
+
ut = {
|
|
2137
2151
|
listener: v,
|
|
2138
2152
|
capture: u
|
|
2139
2153
|
}, _t(window, "focus", v, u);
|
|
2140
2154
|
}
|
|
2141
2155
|
}
|
|
2142
2156
|
}
|
|
2143
|
-
function
|
|
2157
|
+
function mo(t) {
|
|
2144
2158
|
let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all";
|
|
2145
2159
|
Object.keys(N).forEach((n) => {
|
|
2146
2160
|
N[n].filter((i) => i.scope === e && i.shortcut === t).forEach((i) => {
|
|
@@ -2148,7 +2162,7 @@ function go(t) {
|
|
|
2148
2162
|
});
|
|
2149
2163
|
});
|
|
2150
2164
|
}
|
|
2151
|
-
function
|
|
2165
|
+
function Pt(t) {
|
|
2152
2166
|
const e = Object.values(N).flat();
|
|
2153
2167
|
if (e.findIndex((o) => {
|
|
2154
2168
|
let {
|
|
@@ -2161,7 +2175,7 @@ function Xt(t) {
|
|
|
2161
2175
|
keyupListenr: i,
|
|
2162
2176
|
capture: s
|
|
2163
2177
|
} = W.get(t) || {};
|
|
2164
|
-
o && i && (
|
|
2178
|
+
o && i && (st(t, "keyup", i, s), st(t, "keydown", o, s), W.delete(t));
|
|
2165
2179
|
}
|
|
2166
2180
|
if ((e.length <= 0 || W.size <= 0) && (Object.keys(W).forEach((i) => {
|
|
2167
2181
|
const {
|
|
@@ -2169,222 +2183,254 @@ function Xt(t) {
|
|
|
2169
2183
|
keyupListenr: a,
|
|
2170
2184
|
capture: r
|
|
2171
2185
|
} = W.get(i) || {};
|
|
2172
|
-
s && a && (
|
|
2173
|
-
}), W.clear(), Object.keys(N).forEach((i) => delete N[i]),
|
|
2186
|
+
s && a && (st(i, "keyup", a, r), st(i, "keydown", s, r), W.delete(i));
|
|
2187
|
+
}), W.clear(), Object.keys(N).forEach((i) => delete N[i]), ut)) {
|
|
2174
2188
|
const {
|
|
2175
2189
|
listener: i,
|
|
2176
2190
|
capture: s
|
|
2177
|
-
} =
|
|
2178
|
-
|
|
2191
|
+
} = ut;
|
|
2192
|
+
st(window, "focus", i, s), ut = null;
|
|
2179
2193
|
}
|
|
2180
2194
|
}
|
|
2181
|
-
const
|
|
2195
|
+
const Nt = {
|
|
2182
2196
|
getPressedKeyString: co,
|
|
2183
|
-
setScope:
|
|
2184
|
-
getScope:
|
|
2185
|
-
deleteScope:
|
|
2186
|
-
getPressedKeyCodes:
|
|
2187
|
-
getAllKeyCodes:
|
|
2188
|
-
isPressed:
|
|
2189
|
-
filter:
|
|
2190
|
-
trigger:
|
|
2191
|
-
unbind:
|
|
2192
|
-
keyMap:
|
|
2197
|
+
setScope: xe,
|
|
2198
|
+
getScope: ht,
|
|
2199
|
+
deleteScope: go,
|
|
2200
|
+
getPressedKeyCodes: lo,
|
|
2201
|
+
getAllKeyCodes: uo,
|
|
2202
|
+
isPressed: ho,
|
|
2203
|
+
filter: fo,
|
|
2204
|
+
trigger: mo,
|
|
2205
|
+
unbind: Ae,
|
|
2206
|
+
keyMap: ft,
|
|
2193
2207
|
modifier: z,
|
|
2194
|
-
modifierMap:
|
|
2208
|
+
modifierMap: ct
|
|
2195
2209
|
};
|
|
2196
|
-
for (const t in
|
|
2197
|
-
Object.prototype.hasOwnProperty.call(
|
|
2210
|
+
for (const t in Nt)
|
|
2211
|
+
Object.prototype.hasOwnProperty.call(Nt, t) && (H[t] = Nt[t]);
|
|
2198
2212
|
if (typeof window < "u") {
|
|
2199
2213
|
const t = window.hotkeys;
|
|
2200
2214
|
H.noConflict = (e) => (e && window.hotkeys === H && (window.hotkeys = t), H), window.hotkeys = H;
|
|
2201
2215
|
}
|
|
2202
|
-
const ie = 300, ve = ["up", "down", "left", "right"], Ee = Te ? "⌘+a" : "ctrl+a",
|
|
2216
|
+
const ie = 300, ve = ["up", "down", "left", "right"], Ee = Te ? "⌘+a" : "ctrl+a", yo = [
|
|
2203
2217
|
...ve.map((t) => `shift+${t}`),
|
|
2204
2218
|
Ee
|
|
2205
|
-
],
|
|
2219
|
+
], bo = (t, e, n) => {
|
|
2206
2220
|
let o;
|
|
2207
2221
|
const { annotatingEnabled: i, offsetReferenceSelector: s, selectionMode: a } = n, r = (T) => o = T;
|
|
2208
|
-
let
|
|
2209
|
-
const f = (T) =>
|
|
2210
|
-
let
|
|
2211
|
-
const
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2222
|
+
let d;
|
|
2223
|
+
const f = (T) => d = T, { store: g, selection: u } = e;
|
|
2224
|
+
let h, v, b;
|
|
2225
|
+
const p = (T) => {
|
|
2226
|
+
const M = T;
|
|
2227
|
+
return M.ctrlKey || M.metaKey;
|
|
2228
|
+
}, x = (T) => {
|
|
2229
|
+
if (v !== !1)
|
|
2230
|
+
if (rt(T.target))
|
|
2231
|
+
h = void 0;
|
|
2232
|
+
else {
|
|
2233
|
+
const { selected: M } = u;
|
|
2234
|
+
if (p({ ...T, ...b }) && M.length === 1 && M[0].editable) {
|
|
2235
|
+
const y = g.getAnnotation(M[0].id);
|
|
2236
|
+
h = {
|
|
2237
|
+
previous: {
|
|
2238
|
+
...y.target
|
|
2239
|
+
},
|
|
2240
|
+
next: {
|
|
2241
|
+
annotation: y.id,
|
|
2242
|
+
selector: [],
|
|
2243
|
+
created: y.target.created,
|
|
2244
|
+
creator: y.target.creator,
|
|
2245
|
+
updated: /* @__PURE__ */ new Date(),
|
|
2246
|
+
updatedBy: o
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
} else
|
|
2250
|
+
h = {
|
|
2251
|
+
next: {
|
|
2252
|
+
annotation: fe(),
|
|
2253
|
+
selector: [],
|
|
2254
|
+
created: /* @__PURE__ */ new Date(),
|
|
2255
|
+
creator: o
|
|
2256
|
+
}
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
}, c = Kt((T) => {
|
|
2260
|
+
const M = document.getSelection();
|
|
2261
|
+
if (!(M != null && M.anchorNode))
|
|
2221
2262
|
return;
|
|
2222
|
-
if (
|
|
2223
|
-
|
|
2263
|
+
if (rt(M.anchorNode)) {
|
|
2264
|
+
h = void 0;
|
|
2224
2265
|
return;
|
|
2225
2266
|
}
|
|
2226
|
-
const
|
|
2227
|
-
if ((
|
|
2228
|
-
if (
|
|
2229
|
-
|
|
2267
|
+
const y = T.timeStamp - ((b == null ? void 0 : b.timeStamp) || T.timeStamp);
|
|
2268
|
+
if ((b == null ? void 0 : b.type) === "pointerdown" && (y < 1e3 && !h || M.isCollapsed && y < ie) && x(b || T), !h) return;
|
|
2269
|
+
if (M.isCollapsed) {
|
|
2270
|
+
g.getAnnotation(h.next.annotation) && !p(b) && (u.clear(), g.deleteAnnotation(h.next.annotation));
|
|
2230
2271
|
return;
|
|
2231
2272
|
}
|
|
2232
|
-
const
|
|
2233
|
-
if (Ie(
|
|
2234
|
-
const
|
|
2235
|
-
(
|
|
2236
|
-
var
|
|
2237
|
-
return
|
|
2238
|
-
})) && (
|
|
2239
|
-
...
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2273
|
+
const A = Array.from(Array(M.rangeCount).keys()).map((O) => M.getRangeAt(O)).map((O) => De(O, t));
|
|
2274
|
+
if (A.every((O) => Ie(O))) return;
|
|
2275
|
+
const C = A.flatMap((O) => Me(O.cloneRange()));
|
|
2276
|
+
(C.length !== h.next.selector.length || C.some((O, k) => {
|
|
2277
|
+
var P;
|
|
2278
|
+
return O.toString() !== ((P = h.next.selector[k]) == null ? void 0 : P.quote);
|
|
2279
|
+
})) && (h = {
|
|
2280
|
+
...h,
|
|
2281
|
+
next: {
|
|
2282
|
+
...h.next,
|
|
2283
|
+
selector: [
|
|
2284
|
+
...h.previous ? h.previous.selector : [],
|
|
2285
|
+
...C.map((O) => Ve(O, t, s))
|
|
2286
|
+
],
|
|
2287
|
+
updated: /* @__PURE__ */ new Date()
|
|
2288
|
+
}
|
|
2289
|
+
}, g.getAnnotation(h.next.annotation) ? g.updateTarget(h.next, B.LOCAL) : p(b) || u.clear());
|
|
2290
|
+
}), l = (T) => {
|
|
2291
|
+
rt(T.target) || (b = Et(T), v = b.button === 0);
|
|
2292
|
+
}, m = (T) => {
|
|
2293
|
+
if (rt(T.target) || !v) return;
|
|
2294
|
+
const M = () => {
|
|
2295
|
+
const { x: w, y: A } = t.getBoundingClientRect(), C = T.target instanceof Node && t.contains(T.target) && g.getAt(T.clientX - w, T.clientY - A, a === "all", d);
|
|
2296
|
+
if (C) {
|
|
2297
|
+
const { selected: I } = u, O = new Set(I.map((Q) => Q.id)), k = Array.isArray(C) ? C.map((Q) => Q.id) : [C.id];
|
|
2298
|
+
(O.size !== k.length || !k.every((Q) => O.has(Q))) && u.userSelect(k, T);
|
|
2299
|
+
} else p(T) || u.clear();
|
|
2300
|
+
}, y = T.timeStamp - b.timeStamp;
|
|
2255
2301
|
setTimeout(() => {
|
|
2256
|
-
const
|
|
2257
|
-
|
|
2302
|
+
const w = document.getSelection();
|
|
2303
|
+
w != null && w.isCollapsed && y < ie ? (h = void 0, M()) : h && h.next.selector.length > 0 && (U(), u.userSelect(h.next.annotation, Et(T)));
|
|
2258
2304
|
});
|
|
2259
|
-
}, y = (T) => {
|
|
2260
|
-
const I = document.getSelection();
|
|
2261
|
-
I != null && I.isCollapsed || ((!p || p.selector.length === 0) && A(T), p && (R(), u.userSelect(p.annotation, vt(T))));
|
|
2262
2305
|
}, S = (T) => {
|
|
2263
|
-
|
|
2306
|
+
const M = document.getSelection();
|
|
2307
|
+
M != null && M.isCollapsed || ((!h || h.next.selector.length === 0) && c(T), h && (U(), u.userSelect(h.next.annotation, Et(T))));
|
|
2264
2308
|
}, E = (T) => {
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2309
|
+
T.key === "Shift" && h && (document.getSelection().isCollapsed || (U(), u.userSelect(h.next.annotation, gt(T))));
|
|
2310
|
+
}, L = (T) => {
|
|
2311
|
+
const M = () => setTimeout(() => {
|
|
2312
|
+
(h == null ? void 0 : h.next.selector.length) > 0 && (u.clear(), g.addAnnotation({
|
|
2313
|
+
id: h.next.annotation,
|
|
2268
2314
|
bodies: [],
|
|
2269
|
-
target:
|
|
2270
|
-
}), u.userSelect(
|
|
2315
|
+
target: h.next
|
|
2316
|
+
}), u.userSelect(h.next.annotation, gt(T))), document.removeEventListener("selectionchange", M);
|
|
2271
2317
|
}, 100);
|
|
2272
|
-
document.addEventListener("selectionchange",
|
|
2318
|
+
document.addEventListener("selectionchange", M), x(T);
|
|
2273
2319
|
};
|
|
2274
|
-
H(
|
|
2275
|
-
T.repeat || (
|
|
2320
|
+
H(yo.join(","), { element: t, keydown: !0, keyup: !1 }, (T) => {
|
|
2321
|
+
T.repeat || (b = gt(T));
|
|
2276
2322
|
}), H(Ee, { keydown: !0, keyup: !1 }, (T) => {
|
|
2277
|
-
|
|
2323
|
+
b = gt(T), L(T);
|
|
2278
2324
|
});
|
|
2279
|
-
const
|
|
2280
|
-
T.repeat || T.target !== t && T.target !== document.body || (
|
|
2325
|
+
const R = (T) => {
|
|
2326
|
+
T.repeat || T.target !== t && T.target !== document.body || (h = void 0, u.clear());
|
|
2281
2327
|
};
|
|
2282
|
-
H(ve.join(","), { keydown: !0, keyup: !1 },
|
|
2283
|
-
const
|
|
2284
|
-
const T =
|
|
2328
|
+
H(ve.join(","), { keydown: !0, keyup: !1 }, R);
|
|
2329
|
+
const U = () => {
|
|
2330
|
+
const T = g.getAnnotation(h.next.annotation);
|
|
2285
2331
|
if (!T) {
|
|
2286
|
-
|
|
2287
|
-
id:
|
|
2332
|
+
g.addAnnotation({
|
|
2333
|
+
id: h.next.annotation,
|
|
2288
2334
|
bodies: [],
|
|
2289
|
-
target:
|
|
2335
|
+
target: h.next
|
|
2290
2336
|
});
|
|
2291
2337
|
return;
|
|
2292
2338
|
}
|
|
2293
|
-
const { target: { updated:
|
|
2294
|
-
(!
|
|
2339
|
+
const { target: { updated: M } } = T, { updated: y } = h.next;
|
|
2340
|
+
(!M || !y || M < y) && g.updateTarget(h.next);
|
|
2295
2341
|
};
|
|
2296
|
-
return t.addEventListener("pointerdown",
|
|
2342
|
+
return t.addEventListener("pointerdown", l), document.addEventListener("pointerup", m), document.addEventListener("contextmenu", S), i && (t.addEventListener("keyup", E), t.addEventListener("selectstart", x), document.addEventListener("selectionchange", c)), {
|
|
2297
2343
|
destroy: () => {
|
|
2298
|
-
t.removeEventListener("pointerdown",
|
|
2344
|
+
t.removeEventListener("pointerdown", l), document.removeEventListener("pointerup", m), document.removeEventListener("contextmenu", S), t.removeEventListener("keyup", E), t.removeEventListener("selectstart", x), document.removeEventListener("selectionchange", c), H.unbind();
|
|
2299
2345
|
},
|
|
2300
2346
|
setFilter: f,
|
|
2301
2347
|
setUser: r
|
|
2302
2348
|
};
|
|
2303
|
-
},
|
|
2349
|
+
}, wo = (t, e) => ({
|
|
2304
2350
|
...t,
|
|
2305
2351
|
annotatingEnabled: t.annotatingEnabled ?? e.annotatingEnabled,
|
|
2306
2352
|
user: t.user || e.user
|
|
2307
|
-
}), se = "SPANS",
|
|
2353
|
+
}), se = "SPANS", Eo = (t, e = {}) => {
|
|
2308
2354
|
Le(t), Oe(t);
|
|
2309
|
-
const n =
|
|
2355
|
+
const n = wo(e, {
|
|
2310
2356
|
annotatingEnabled: !0,
|
|
2311
2357
|
user: Yn()
|
|
2312
|
-
}), o =
|
|
2358
|
+
}), o = no(t, n), { selection: i, viewport: s } = o, a = o.store, r = Mn(a), d = Bn(o, r, n.adapter);
|
|
2313
2359
|
let f = n.user;
|
|
2314
|
-
const
|
|
2360
|
+
const g = n.renderer === "CSS_HIGHLIGHTS" ? CSS.highlights ? "CSS_HIGHLIGHTS" : se : n.renderer || se, u = g === "SPANS" ? rn(t, o, s) : g === "CSS_HIGHLIGHTS" ? nn(t, o, s) : g === "CANVAS" ? ze(t, o, s) : void 0;
|
|
2315
2361
|
if (!u)
|
|
2316
|
-
throw `Unknown renderer implementation: ${
|
|
2317
|
-
console.debug(`Using ${
|
|
2318
|
-
const
|
|
2319
|
-
return
|
|
2320
|
-
...
|
|
2362
|
+
throw `Unknown renderer implementation: ${g}`;
|
|
2363
|
+
console.debug(`Using ${g} renderer`), n.style && u.setStyle(n.style);
|
|
2364
|
+
const h = bo(t, o, n);
|
|
2365
|
+
return h.setUser(f), {
|
|
2366
|
+
...Un(o, r, n.adapter),
|
|
2321
2367
|
destroy: () => {
|
|
2322
|
-
u.destroy(),
|
|
2368
|
+
u.destroy(), h.destroy(), r.destroy();
|
|
2323
2369
|
},
|
|
2324
2370
|
element: t,
|
|
2325
2371
|
getUser: () => f,
|
|
2326
|
-
setFilter: (
|
|
2327
|
-
u.setFilter(
|
|
2372
|
+
setFilter: (L) => {
|
|
2373
|
+
u.setFilter(L), h.setFilter(L);
|
|
2328
2374
|
},
|
|
2329
|
-
setStyle: (
|
|
2330
|
-
setUser: (
|
|
2331
|
-
f =
|
|
2375
|
+
setStyle: (L) => u.setStyle(L),
|
|
2376
|
+
setUser: (L) => {
|
|
2377
|
+
f = L, h.setUser(L);
|
|
2332
2378
|
},
|
|
2333
|
-
setSelected: (
|
|
2334
|
-
|
|
2379
|
+
setSelected: (L) => {
|
|
2380
|
+
L ? i.setSelected(L) : i.clear();
|
|
2335
2381
|
},
|
|
2336
|
-
setPresenceProvider: (
|
|
2337
|
-
|
|
2382
|
+
setPresenceProvider: (L) => {
|
|
2383
|
+
L && (u.setPainter(io(L, n.presence)), L.on("selectionChange", () => u.redraw()));
|
|
2338
2384
|
},
|
|
2339
|
-
setVisible: (
|
|
2340
|
-
on:
|
|
2341
|
-
off:
|
|
2342
|
-
scrollIntoView:
|
|
2385
|
+
setVisible: (L) => u.setVisible(L),
|
|
2386
|
+
on: d.on,
|
|
2387
|
+
off: d.off,
|
|
2388
|
+
scrollIntoView: Ke(t, a),
|
|
2343
2389
|
state: o
|
|
2344
2390
|
};
|
|
2345
2391
|
};
|
|
2346
2392
|
export {
|
|
2347
|
-
|
|
2393
|
+
vt as DEFAULT_SELECTED_STYLE,
|
|
2348
2394
|
G as DEFAULT_STYLE,
|
|
2349
2395
|
re as NOT_ANNOTATABLE_CLASS,
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2396
|
+
nt as NOT_ANNOTATABLE_SELECTOR,
|
|
2397
|
+
B as Origin,
|
|
2398
|
+
bo as SelectionHandler,
|
|
2353
2399
|
hn as UserSelectAction,
|
|
2354
|
-
|
|
2400
|
+
vo as W3CTextFormat,
|
|
2355
2401
|
Le as cancelSingleClickEvents,
|
|
2356
|
-
|
|
2357
|
-
|
|
2402
|
+
gt as cloneKeyboardEvent,
|
|
2403
|
+
Et as clonePointerEvent,
|
|
2358
2404
|
Ao as createBody,
|
|
2359
2405
|
ze as createCanvasRenderer,
|
|
2360
2406
|
nn as createHighlightsRenderer,
|
|
2361
|
-
|
|
2407
|
+
io as createPresencePainter,
|
|
2362
2408
|
en as createRenderer,
|
|
2363
2409
|
rn as createSpansRenderer,
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2410
|
+
Eo as createTextAnnotator,
|
|
2411
|
+
no as createTextAnnotatorState,
|
|
2412
|
+
Kt as debounce,
|
|
2413
|
+
wo as fillDefaults,
|
|
2414
|
+
ke as getQuoteContext,
|
|
2415
|
+
Vt as getRangeAnnotatableContents,
|
|
2370
2416
|
Te as isMac,
|
|
2371
|
-
|
|
2417
|
+
rt as isNotAnnotatable,
|
|
2372
2418
|
Ce as isRangeAnnotatable,
|
|
2373
2419
|
q as isRevived,
|
|
2374
2420
|
Ie as isWhitespaceOrEmpty,
|
|
2375
2421
|
Ne as mergeClientRects,
|
|
2376
|
-
|
|
2377
|
-
|
|
2422
|
+
Ye as paint,
|
|
2423
|
+
zn as parseW3CTextAnnotation,
|
|
2378
2424
|
Oe as programmaticallyFocusable,
|
|
2379
2425
|
Ve as rangeToSelector,
|
|
2380
|
-
|
|
2426
|
+
St as reviveAnnotation,
|
|
2381
2427
|
ae as reviveSelector,
|
|
2382
2428
|
At as reviveTarget,
|
|
2383
|
-
|
|
2384
|
-
|
|
2429
|
+
Ke as scrollIntoView,
|
|
2430
|
+
Fn as serializeW3CTextAnnotation,
|
|
2385
2431
|
Me as splitAnnotatableRanges,
|
|
2386
|
-
|
|
2432
|
+
xo as toDomRectList,
|
|
2387
2433
|
De as trimRangeToContainer,
|
|
2388
|
-
|
|
2434
|
+
Be as whitespaceOrEmptyRegex
|
|
2389
2435
|
};
|
|
2390
2436
|
//# sourceMappingURL=text-annotator.es.js.map
|