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