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