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