@recogito/text-annotator 3.0.0-rc.5 → 3.0.0-rc.6
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.
|
@@ -33,25 +33,25 @@ const mt = (e, t = 10) => {
|
|
|
33
33
|
const u = pt(n);
|
|
34
34
|
e.classList.add("r6o-annotatable");
|
|
35
35
|
const b = j("r6o-highlight-layer bg"), h = j("r6o-highlight-layer fg", !0), E = b.getContext("2d"), m = h.getContext("2d");
|
|
36
|
-
e.insertBefore(b, e.firstChild), e.appendChild(h), e.addEventListener("pointermove", (
|
|
37
|
-
const { x: T, y:
|
|
36
|
+
e.insertBefore(b, e.firstChild), e.appendChild(h), e.addEventListener("pointermove", (v) => {
|
|
37
|
+
const { x: T, y: M } = e.getBoundingClientRect(), f = o.getAt(v.clientX - T, v.clientY - M);
|
|
38
38
|
f && (!r || r(f)) ? s.current !== f.id && (e.classList.add("hovered"), s.set(f.id)) : s.current && (e.classList.remove("hovered"), s.set(null));
|
|
39
39
|
});
|
|
40
|
-
const
|
|
41
|
-
const { top:
|
|
42
|
-
return { top:
|
|
43
|
-
},
|
|
44
|
-
document.addEventListener("scroll",
|
|
45
|
-
const
|
|
40
|
+
const w = () => {
|
|
41
|
+
const { top: v, left: T } = e.getBoundingClientRect(), { innerWidth: M, innerHeight: f } = window, x = -T, A = -v, B = M - T, S = f - v;
|
|
42
|
+
return { top: v, left: T, minX: x, minY: A, maxX: B, maxY: S };
|
|
43
|
+
}, L = () => c();
|
|
44
|
+
document.addEventListener("scroll", L, { capture: !0, passive: !0 });
|
|
45
|
+
const y = mt(() => {
|
|
46
46
|
Z(b), Z(h, !0), o.recalculatePositions(), c();
|
|
47
47
|
});
|
|
48
|
-
window.addEventListener("resize",
|
|
48
|
+
window.addEventListener("resize", y), new ResizeObserver(y).observe(e);
|
|
49
49
|
const c = () => requestAnimationFrame(() => {
|
|
50
|
-
const { top:
|
|
50
|
+
const { top: v, left: T, minX: M, minY: f, maxX: x, maxY: A } = w(), B = r ? o.getIntersectingRects(M, f, x, A).filter(({ annotation: U }) => r(U)) : o.getIntersectingRects(M, f, x, A), { width: S, height: R } = h, X = new Set(i.selected.map(({ id: U }) => U));
|
|
51
51
|
m.clearRect(-0.5, -0.5, S + 1, R + 1), E.clearRect(-0.5, -0.5, S + 1, R + 1), B.forEach(({ annotation: U, rects: at }) => {
|
|
52
52
|
const rt = at.map(({ x: ct, y: dt, width: ut, height: ht }) => ({
|
|
53
53
|
x: ct + T,
|
|
54
|
-
y: dt +
|
|
54
|
+
y: dt + v,
|
|
55
55
|
width: ut,
|
|
56
56
|
height: ht
|
|
57
57
|
})), lt = X.has(U.id);
|
|
@@ -60,13 +60,13 @@ const mt = (e, t = 10) => {
|
|
|
60
60
|
});
|
|
61
61
|
return o.observe(() => c()), i.subscribe(() => c()), {
|
|
62
62
|
redraw: c,
|
|
63
|
-
setDrawingStyle: (
|
|
64
|
-
a =
|
|
63
|
+
setDrawingStyle: (v) => {
|
|
64
|
+
a = v, c();
|
|
65
65
|
},
|
|
66
|
-
setFilter: (
|
|
67
|
-
r =
|
|
66
|
+
setFilter: (v) => {
|
|
67
|
+
r = v, c();
|
|
68
68
|
},
|
|
69
|
-
setPainter: (
|
|
69
|
+
setPainter: (v) => d = v
|
|
70
70
|
};
|
|
71
71
|
}, k = (e, t) => {
|
|
72
72
|
const { start: n, end: o } = e.selector, i = e.selector.offsetReference ? e.selector.offsetReference : t;
|
|
@@ -177,7 +177,7 @@ const xt = (e) => {
|
|
|
177
177
|
subscribe: t,
|
|
178
178
|
set: n
|
|
179
179
|
};
|
|
180
|
-
}, q = { selected: [] },
|
|
180
|
+
}, q = { selected: [] }, wt = (e, t = "EDIT") => {
|
|
181
181
|
const { subscribe: n, set: o } = J(q);
|
|
182
182
|
let i = q;
|
|
183
183
|
n((h) => i = h);
|
|
@@ -192,13 +192,13 @@ const xt = (e) => {
|
|
|
192
192
|
}, d = (h, E) => {
|
|
193
193
|
const m = e.getAnnotation(h);
|
|
194
194
|
if (m) {
|
|
195
|
-
const
|
|
196
|
-
o(
|
|
195
|
+
const w = yt(m, t);
|
|
196
|
+
o(w === "EDIT" ? { selected: [{ id: h, editable: !0 }], pointerEvent: E } : w === "SELECT" ? { selected: [{ id: h }], pointerEvent: E } : { selected: [], pointerEvent: E });
|
|
197
197
|
} else
|
|
198
198
|
console.warn("Invalid selection: " + h);
|
|
199
199
|
}, u = (h, E = !0) => {
|
|
200
|
-
const m = Array.isArray(h) ? h : [h],
|
|
201
|
-
o({ selected:
|
|
200
|
+
const m = Array.isArray(h) ? h : [h], w = m.map((L) => e.getAnnotation(L)).filter((L) => L);
|
|
201
|
+
o({ selected: w.map(({ id: L }) => ({ id: L, editable: E })) }), w.length !== m.length && console.warn("Invalid selection", h);
|
|
202
202
|
}, b = (h) => {
|
|
203
203
|
if (i.selected.length === 0)
|
|
204
204
|
return !1;
|
|
@@ -219,9 +219,9 @@ const xt = (e) => {
|
|
|
219
219
|
setSelected: u,
|
|
220
220
|
subscribe: n
|
|
221
221
|
};
|
|
222
|
-
},
|
|
222
|
+
}, yt = (e, t) => typeof t == "function" ? t(e) || "EDIT" : t || "EDIT", vt = [];
|
|
223
223
|
for (let e = 0; e < 256; ++e)
|
|
224
|
-
|
|
224
|
+
vt.push((e + 256).toString(16).slice(1));
|
|
225
225
|
typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
226
226
|
const Et = (e, t) => {
|
|
227
227
|
const n = new Set(e.bodies.map((o) => o.id));
|
|
@@ -243,8 +243,8 @@ const Et = (e, t) => {
|
|
|
243
243
|
targetUpdated: St(e, t) ? { oldTarget: e.target, newTarget: t.target } : void 0
|
|
244
244
|
};
|
|
245
245
|
};
|
|
246
|
-
var
|
|
247
|
-
const
|
|
246
|
+
var C = /* @__PURE__ */ ((e) => (e.LOCAL = "LOCAL", e.REMOTE = "REMOTE", e))(C || {});
|
|
247
|
+
const Lt = (e, t) => {
|
|
248
248
|
var n, o;
|
|
249
249
|
const { changes: i, origin: s } = t;
|
|
250
250
|
if (!(!e.options.origin || e.options.origin === s))
|
|
@@ -266,7 +266,7 @@ const Ct = (e, t) => {
|
|
|
266
266
|
return !!(Array.isArray(e.options.annotations) ? e.options.annotations : [e.options.annotations]).find((r) => a.has(r));
|
|
267
267
|
} else
|
|
268
268
|
return !0;
|
|
269
|
-
},
|
|
269
|
+
}, Mt = (e, t) => {
|
|
270
270
|
const n = new Set((e.created || []).map((h) => h.id)), o = new Set((e.updated || []).map(({ newValue: h }) => h.id)), i = new Set((t.created || []).map((h) => h.id)), s = new Set((t.deleted || []).map((h) => h.id)), a = new Set((t.updated || []).map(({ oldValue: h }) => h.id)), r = new Set((t.updated || []).filter(({ oldValue: h }) => n.has(h.id) || o.has(h.id)).map(({ oldValue: h }) => h.id)), d = [
|
|
271
271
|
...(e.created || []).filter((h) => !s.has(h.id)).map((h) => a.has(h.id) ? t.updated.find(({ oldValue: E }) => E.id === h.id).newValue : h),
|
|
272
272
|
...t.created || []
|
|
@@ -277,15 +277,15 @@ const Ct = (e, t) => {
|
|
|
277
277
|
...(e.updated || []).filter(({ newValue: h }) => !s.has(h.id)).map((h) => {
|
|
278
278
|
const { oldValue: E, newValue: m } = h;
|
|
279
279
|
if (a.has(m.id)) {
|
|
280
|
-
const
|
|
281
|
-
return ot(E,
|
|
280
|
+
const w = t.updated.find((L) => L.oldValue.id === m.id).newValue;
|
|
281
|
+
return ot(E, w);
|
|
282
282
|
} else
|
|
283
283
|
return h;
|
|
284
284
|
}),
|
|
285
285
|
...(t.updated || []).filter(({ oldValue: h }) => !r.has(h.id))
|
|
286
286
|
];
|
|
287
287
|
return { created: d, deleted: u, updated: b };
|
|
288
|
-
},
|
|
288
|
+
}, Ct = (e) => e.id !== void 0, Rt = () => {
|
|
289
289
|
const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = [], o = (f, x = {}) => n.push({ onChange: f, options: x }), i = (f) => {
|
|
290
290
|
const x = n.findIndex((A) => A.onChange == f);
|
|
291
291
|
x > -1 && n.splice(x, 1);
|
|
@@ -300,9 +300,9 @@ const Ct = (e, t) => {
|
|
|
300
300
|
state: [...e.values()]
|
|
301
301
|
};
|
|
302
302
|
n.forEach((B) => {
|
|
303
|
-
|
|
303
|
+
Lt(B, A) && B.onChange(A);
|
|
304
304
|
});
|
|
305
|
-
}, a = (f, x =
|
|
305
|
+
}, a = (f, x = C.LOCAL) => {
|
|
306
306
|
if (e.get(f.id))
|
|
307
307
|
throw Error(`Cannot add annotation ${f.id} - exists already`);
|
|
308
308
|
e.set(f.id, f), f.bodies.forEach((A) => t.set(A.id, f.id)), s(x, { created: [f] });
|
|
@@ -313,16 +313,16 @@ const Ct = (e, t) => {
|
|
|
313
313
|
return B === A.id ? e.set(B, A) : (e.delete(B), e.set(A.id, A)), S.bodies.forEach((X) => t.delete(X.id)), A.bodies.forEach((X) => t.set(X.id, A.id)), R;
|
|
314
314
|
} else
|
|
315
315
|
console.warn(`Cannot update annotation ${B} - does not exist`);
|
|
316
|
-
}, d = (f, x =
|
|
317
|
-
const B =
|
|
316
|
+
}, d = (f, x = C.LOCAL, A = C.LOCAL) => {
|
|
317
|
+
const B = Ct(x) ? A : x, S = r(f, x);
|
|
318
318
|
S && s(B, { updated: [S] });
|
|
319
|
-
}, u = (f, x =
|
|
319
|
+
}, u = (f, x = C.LOCAL) => {
|
|
320
320
|
const A = f.reduce((B, S) => {
|
|
321
321
|
const R = r(S);
|
|
322
322
|
return R ? [...B, R] : B;
|
|
323
323
|
}, []);
|
|
324
324
|
A.length > 0 && s(x, { updated: A });
|
|
325
|
-
}, b = (f, x =
|
|
325
|
+
}, b = (f, x = C.LOCAL) => {
|
|
326
326
|
const A = e.get(f.annotation);
|
|
327
327
|
if (A) {
|
|
328
328
|
const B = {
|
|
@@ -336,10 +336,10 @@ const Ct = (e, t) => {
|
|
|
336
336
|
}] });
|
|
337
337
|
} else
|
|
338
338
|
console.warn(`Attempt to add body to missing annotation: ${f.annotation}`);
|
|
339
|
-
}, h = () => [...e.values()], E = (f =
|
|
339
|
+
}, h = () => [...e.values()], E = (f = C.LOCAL) => {
|
|
340
340
|
const x = [...e.values()];
|
|
341
341
|
e.clear(), t.clear(), s(f, { deleted: x });
|
|
342
|
-
}, m = (f, x = !0, A =
|
|
342
|
+
}, m = (f, x = !0, A = C.LOCAL) => {
|
|
343
343
|
if (x) {
|
|
344
344
|
const B = [...e.values()];
|
|
345
345
|
e.clear(), t.clear(), f.forEach((S) => {
|
|
@@ -356,21 +356,21 @@ const Ct = (e, t) => {
|
|
|
356
356
|
e.set(S.id, S), S.bodies.forEach((R) => t.set(R.id, S.id));
|
|
357
357
|
}), s(A, { created: f });
|
|
358
358
|
}
|
|
359
|
-
},
|
|
359
|
+
}, w = (f) => {
|
|
360
360
|
const x = typeof f == "string" ? f : f.id, A = e.get(x);
|
|
361
361
|
if (A)
|
|
362
362
|
return e.delete(x), A.bodies.forEach((B) => t.delete(B.id)), A;
|
|
363
363
|
console.warn(`Attempt to delete missing annotation: ${x}`);
|
|
364
|
-
},
|
|
365
|
-
const A =
|
|
364
|
+
}, L = (f, x = C.LOCAL) => {
|
|
365
|
+
const A = w(f);
|
|
366
366
|
A && s(x, { deleted: [A] });
|
|
367
|
-
},
|
|
367
|
+
}, y = (f, x = C.LOCAL) => {
|
|
368
368
|
const A = f.reduce((B, S) => {
|
|
369
|
-
const R =
|
|
369
|
+
const R = w(S);
|
|
370
370
|
return R ? [...B, R] : B;
|
|
371
371
|
}, []);
|
|
372
372
|
A.length > 0 && s(x, { deleted: A });
|
|
373
|
-
}, l = (f, x =
|
|
373
|
+
}, l = (f, x = C.LOCAL) => {
|
|
374
374
|
const A = e.get(f.annotation);
|
|
375
375
|
if (A) {
|
|
376
376
|
const B = A.bodies.find((S) => S.id === f.id);
|
|
@@ -417,13 +417,13 @@ const Ct = (e, t) => {
|
|
|
417
417
|
};
|
|
418
418
|
} else
|
|
419
419
|
console.warn(`Attempt to add body to missing annotation ${f.annotation}`);
|
|
420
|
-
},
|
|
420
|
+
}, v = (f, x, A = C.LOCAL) => {
|
|
421
421
|
const B = p(f, x);
|
|
422
422
|
s(A, { updated: [B] });
|
|
423
|
-
}, T = (f, x =
|
|
423
|
+
}, T = (f, x = C.LOCAL) => {
|
|
424
424
|
const A = f.map((B) => p({ id: B.id, annotation: B.annotation }, B));
|
|
425
425
|
s(x, { updated: A });
|
|
426
|
-
},
|
|
426
|
+
}, M = (f) => {
|
|
427
427
|
const x = e.get(f.annotation);
|
|
428
428
|
if (x) {
|
|
429
429
|
const A = {
|
|
@@ -449,24 +449,24 @@ const Ct = (e, t) => {
|
|
|
449
449
|
addBody: b,
|
|
450
450
|
all: h,
|
|
451
451
|
bulkAddAnnotation: m,
|
|
452
|
-
bulkDeleteAnnotation:
|
|
452
|
+
bulkDeleteAnnotation: y,
|
|
453
453
|
bulkUpdateAnnotation: u,
|
|
454
454
|
bulkUpdateBodies: T,
|
|
455
|
-
bulkUpdateTargets: (f, x =
|
|
456
|
-
const A = f.map(
|
|
455
|
+
bulkUpdateTargets: (f, x = C.LOCAL) => {
|
|
456
|
+
const A = f.map(M).filter((B) => B);
|
|
457
457
|
A.length > 0 && s(x, { updated: A });
|
|
458
458
|
},
|
|
459
459
|
clear: E,
|
|
460
|
-
deleteAnnotation:
|
|
460
|
+
deleteAnnotation: L,
|
|
461
461
|
deleteBody: l,
|
|
462
462
|
getAnnotation: c,
|
|
463
463
|
getBody: g,
|
|
464
464
|
observe: o,
|
|
465
465
|
unobserve: i,
|
|
466
466
|
updateAnnotation: d,
|
|
467
|
-
updateBody:
|
|
468
|
-
updateTarget: (f, x =
|
|
469
|
-
const A =
|
|
467
|
+
updateBody: v,
|
|
468
|
+
updateTarget: (f, x = C.LOCAL) => {
|
|
469
|
+
const A = M(f);
|
|
470
470
|
A && s(x, { updated: [A] });
|
|
471
471
|
}
|
|
472
472
|
};
|
|
@@ -491,36 +491,36 @@ const Xt = 250, Ut = (e) => {
|
|
|
491
491
|
let o = -1, i = !1, s = 0;
|
|
492
492
|
const a = (m) => {
|
|
493
493
|
if (!i) {
|
|
494
|
-
const { changes:
|
|
495
|
-
if (
|
|
496
|
-
n.splice(o + 1), n.push(
|
|
494
|
+
const { changes: w } = m, L = performance.now();
|
|
495
|
+
if (L - s > Xt)
|
|
496
|
+
n.splice(o + 1), n.push(w), o = n.length - 1;
|
|
497
497
|
else {
|
|
498
|
-
const
|
|
499
|
-
n[
|
|
498
|
+
const y = n.length - 1;
|
|
499
|
+
n[y] = Mt(n[y], w);
|
|
500
500
|
}
|
|
501
|
-
s =
|
|
501
|
+
s = L;
|
|
502
502
|
}
|
|
503
503
|
i = !1;
|
|
504
504
|
};
|
|
505
|
-
e.observe(a, { origin:
|
|
506
|
-
const r = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkDeleteAnnotation(m), d = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkAddAnnotation(m, !1), u = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkUpdateAnnotation(m.map(({ oldValue:
|
|
505
|
+
e.observe(a, { origin: C.LOCAL });
|
|
506
|
+
const r = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkDeleteAnnotation(m), d = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkAddAnnotation(m, !1), u = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkUpdateAnnotation(m.map(({ oldValue: w }) => w)), b = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkUpdateAnnotation(m.map(({ newValue: w }) => w)), h = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkAddAnnotation(m, !1), E = (m) => (m == null ? void 0 : m.length) > 0 && e.bulkDeleteAnnotation(m);
|
|
507
507
|
return {
|
|
508
508
|
canRedo: () => n.length - 1 > o,
|
|
509
509
|
canUndo: () => o > -1,
|
|
510
510
|
destroy: () => e.unobserve(a),
|
|
511
|
-
on: (m,
|
|
511
|
+
on: (m, w) => t.on(m, w),
|
|
512
512
|
redo: () => {
|
|
513
513
|
if (n.length - 1 > o) {
|
|
514
514
|
i = !0;
|
|
515
|
-
const { created: m, updated:
|
|
516
|
-
d(m), b(
|
|
515
|
+
const { created: m, updated: w, deleted: L } = n[o + 1];
|
|
516
|
+
d(m), b(w), E(L), t.emit("redo", n[o + 1]), o += 1;
|
|
517
517
|
}
|
|
518
518
|
},
|
|
519
519
|
undo: () => {
|
|
520
520
|
if (o > -1) {
|
|
521
521
|
i = !0;
|
|
522
|
-
const { created: m, updated:
|
|
523
|
-
r(m), u(
|
|
522
|
+
const { created: m, updated: w, deleted: L } = n[o];
|
|
523
|
+
r(m), u(w), h(L), t.emit("undo", n[o]), o -= 1;
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
};
|
|
@@ -538,22 +538,22 @@ const Xt = 250, Ut = (e) => {
|
|
|
538
538
|
}, m = (l, c) => {
|
|
539
539
|
const g = d.get(l);
|
|
540
540
|
g && g.indexOf(c) > 0 && g.splice(g.indexOf(c), 1);
|
|
541
|
-
},
|
|
541
|
+
}, w = (l, c, g) => {
|
|
542
542
|
d.has(l) && setTimeout(() => {
|
|
543
543
|
d.get(l).forEach((p) => {
|
|
544
544
|
if (n) {
|
|
545
|
-
const
|
|
546
|
-
p(
|
|
545
|
+
const v = Array.isArray(c) ? c.map((M) => n.serialize(M)) : n.serialize(c), T = g ? g instanceof PointerEvent ? g : n.serialize(g) : void 0;
|
|
546
|
+
p(v, T);
|
|
547
547
|
} else
|
|
548
548
|
p(c, g);
|
|
549
549
|
});
|
|
550
550
|
}, 1);
|
|
551
|
-
},
|
|
551
|
+
}, L = () => {
|
|
552
552
|
const { selected: l } = s, c = l.map(({ id: g }) => i.getAnnotation(g));
|
|
553
553
|
c.forEach((g) => {
|
|
554
|
-
const p = u.find((
|
|
555
|
-
(!p || !Y(p, g)) &&
|
|
556
|
-
}), u = u.map((g) => c.find(({ id:
|
|
554
|
+
const p = u.find((v) => v.id === g.id);
|
|
555
|
+
(!p || !Y(p, g)) && w("updateAnnotation", g, p);
|
|
556
|
+
}), u = u.map((g) => c.find(({ id: v }) => v === g.id) || g);
|
|
557
557
|
};
|
|
558
558
|
s.subscribe(({ selected: l }) => {
|
|
559
559
|
if (!(u.length === 0 && l.length === 0)) {
|
|
@@ -562,13 +562,13 @@ const Xt = 250, Ut = (e) => {
|
|
|
562
562
|
else if (u.length > 0 && l.length === 0)
|
|
563
563
|
u.forEach((c) => {
|
|
564
564
|
const g = i.getAnnotation(c.id);
|
|
565
|
-
g && !Y(g, c) &&
|
|
565
|
+
g && !Y(g, c) && w("updateAnnotation", g, c);
|
|
566
566
|
}), u = [];
|
|
567
567
|
else {
|
|
568
568
|
const c = new Set(u.map((p) => p.id)), g = new Set(l.map(({ id: p }) => p));
|
|
569
569
|
u.filter((p) => !g.has(p.id)).forEach((p) => {
|
|
570
|
-
const
|
|
571
|
-
|
|
570
|
+
const v = i.getAnnotation(p.id);
|
|
571
|
+
v && !Y(v, p) && w("updateAnnotation", v, p);
|
|
572
572
|
}), u = [
|
|
573
573
|
// Remove annotations that were deselected
|
|
574
574
|
...u.filter((p) => g.has(p.id)),
|
|
@@ -576,32 +576,32 @@ const Xt = 250, Ut = (e) => {
|
|
|
576
576
|
...l.filter(({ id: p }) => !c.has(p)).map(({ id: p }) => i.getAnnotation(p))
|
|
577
577
|
];
|
|
578
578
|
}
|
|
579
|
-
|
|
579
|
+
w("selectionChanged", u);
|
|
580
580
|
}
|
|
581
581
|
}), a.subscribe((l) => {
|
|
582
|
-
!b && l ?
|
|
583
|
-
}), r == null || r.subscribe((l) =>
|
|
584
|
-
o && (h && clearTimeout(h), h = setTimeout(
|
|
582
|
+
!b && l ? w("mouseEnterAnnotation", i.getAnnotation(l)) : b && !l ? w("mouseLeaveAnnotation", i.getAnnotation(b)) : b && l && (w("mouseLeaveAnnotation", i.getAnnotation(b)), w("mouseEnterAnnotation", i.getAnnotation(l))), b = l;
|
|
583
|
+
}), r == null || r.subscribe((l) => w("viewportIntersect", l.map(i.getAnnotation))), i.observe((l) => {
|
|
584
|
+
o && (h && clearTimeout(h), h = setTimeout(L, 1e3));
|
|
585
585
|
const { created: c, deleted: g } = l.changes;
|
|
586
|
-
c.forEach((p) =>
|
|
586
|
+
c.forEach((p) => w("createAnnotation", p)), g.forEach((p) => w("deleteAnnotation", p)), l.changes.updated.filter((p) => [
|
|
587
587
|
...p.bodiesCreated || [],
|
|
588
588
|
...p.bodiesDeleted || [],
|
|
589
589
|
...p.bodiesUpdated || []
|
|
590
|
-
].length > 0).forEach(({ oldValue: p, newValue:
|
|
591
|
-
const T = u.find((
|
|
592
|
-
u = u.map((
|
|
590
|
+
].length > 0).forEach(({ oldValue: p, newValue: v }) => {
|
|
591
|
+
const T = u.find((M) => M.id === p.id) || p;
|
|
592
|
+
u = u.map((M) => M.id === p.id ? v : M), w("updateAnnotation", v, T);
|
|
593
593
|
});
|
|
594
|
-
}, { origin:
|
|
594
|
+
}, { origin: C.LOCAL }), i.observe((l) => {
|
|
595
595
|
if (u) {
|
|
596
596
|
const c = new Set(u.map((p) => p.id)), g = l.changes.updated.filter(({ newValue: p }) => c.has(p.id)).map(({ newValue: p }) => p);
|
|
597
597
|
g.length > 0 && (u = u.map((p) => g.find((T) => T.id === p.id) || p));
|
|
598
598
|
}
|
|
599
|
-
}, { origin:
|
|
600
|
-
const
|
|
601
|
-
const { created: g, deleted: p, updated:
|
|
602
|
-
g.forEach((T) =>
|
|
599
|
+
}, { origin: C.REMOTE });
|
|
600
|
+
const y = (l) => (c) => {
|
|
601
|
+
const { created: g, deleted: p, updated: v } = c;
|
|
602
|
+
g.forEach((T) => w("createAnnotation", T)), p.forEach((T) => w("deleteAnnotation", T)), l ? v.forEach((T) => w("updateAnnotation", T.oldValue, T.newValue)) : v.forEach((T) => w("updateAnnotation", T.newValue, T.oldValue));
|
|
603
603
|
};
|
|
604
|
-
return t.on("undo",
|
|
604
|
+
return t.on("undo", y(!0)), t.on("redo", y(!1)), { on: E, off: m, emit: w };
|
|
605
605
|
}, It = (e) => (t) => t.reduce((n, o) => {
|
|
606
606
|
const { parsed: i, error: s } = e.parse(o);
|
|
607
607
|
return s ? {
|
|
@@ -612,42 +612,42 @@ const Xt = 250, Ut = (e) => {
|
|
|
612
612
|
failed: n.failed
|
|
613
613
|
};
|
|
614
614
|
}, { parsed: [], failed: [] }), Vt = (e, t, n) => {
|
|
615
|
-
const { store: o, selection: i } = e, s = (
|
|
615
|
+
const { store: o, selection: i } = e, s = (y) => {
|
|
616
616
|
if (n) {
|
|
617
|
-
const { parsed: l, error: c } = n.parse(
|
|
618
|
-
l ? o.addAnnotation(l,
|
|
617
|
+
const { parsed: l, error: c } = n.parse(y);
|
|
618
|
+
l ? o.addAnnotation(l, C.REMOTE) : console.error(c);
|
|
619
619
|
} else
|
|
620
|
-
o.addAnnotation(
|
|
621
|
-
}, a = () => i.clear(), r = () => o.clear(), d = (
|
|
622
|
-
const l = o.getAnnotation(
|
|
620
|
+
o.addAnnotation(y, C.REMOTE);
|
|
621
|
+
}, a = () => i.clear(), r = () => o.clear(), d = (y) => {
|
|
622
|
+
const l = o.getAnnotation(y);
|
|
623
623
|
return n && l ? n.serialize(l) : l;
|
|
624
624
|
}, u = () => n ? o.all().map(n.serialize) : o.all(), b = () => {
|
|
625
|
-
var
|
|
626
|
-
const l = (((
|
|
625
|
+
var y;
|
|
626
|
+
const l = (((y = i.selected) == null ? void 0 : y.map((c) => c.id)) || []).map((c) => o.getAnnotation(c));
|
|
627
627
|
return n ? l.map(n.serialize) : l;
|
|
628
|
-
}, h = (
|
|
629
|
-
if (typeof
|
|
630
|
-
const l = o.getAnnotation(
|
|
631
|
-
return o.deleteAnnotation(
|
|
628
|
+
}, h = (y) => fetch(y).then((l) => l.json()).then((l) => (m(l), l)), E = (y) => {
|
|
629
|
+
if (typeof y == "string") {
|
|
630
|
+
const l = o.getAnnotation(y);
|
|
631
|
+
return o.deleteAnnotation(y), n ? n.serialize(l) : l;
|
|
632
632
|
} else {
|
|
633
|
-
const l = n ? n.parse(
|
|
634
|
-
return o.deleteAnnotation(l),
|
|
633
|
+
const l = n ? n.parse(y).parsed : y;
|
|
634
|
+
return o.deleteAnnotation(l), y;
|
|
635
635
|
}
|
|
636
|
-
}, m = (
|
|
636
|
+
}, m = (y) => {
|
|
637
637
|
if (n) {
|
|
638
|
-
const { parsed: l, failed: c } = It(n)(
|
|
639
|
-
c.length > 0 && console.warn(`Discarded ${c.length} invalid annotations`, c), o.bulkAddAnnotation(l, !0,
|
|
638
|
+
const { parsed: l, failed: c } = It(n)(y);
|
|
639
|
+
c.length > 0 && console.warn(`Discarded ${c.length} invalid annotations`, c), o.bulkAddAnnotation(l, !0, C.REMOTE);
|
|
640
640
|
} else
|
|
641
|
-
o.bulkAddAnnotation(
|
|
642
|
-
},
|
|
643
|
-
|
|
644
|
-
},
|
|
641
|
+
o.bulkAddAnnotation(y, !0, C.REMOTE);
|
|
642
|
+
}, w = (y) => {
|
|
643
|
+
y ? i.setSelected(y) : i.clear();
|
|
644
|
+
}, L = (y) => {
|
|
645
645
|
if (n) {
|
|
646
|
-
const l = n.parse(
|
|
646
|
+
const l = n.parse(y).parsed, c = n.serialize(o.getAnnotation(l.id));
|
|
647
647
|
return o.updateAnnotation(l), c;
|
|
648
648
|
} else {
|
|
649
|
-
const l = o.getAnnotation(
|
|
650
|
-
return o.updateAnnotation(
|
|
649
|
+
const l = o.getAnnotation(y.id);
|
|
650
|
+
return o.updateAnnotation(y), l;
|
|
651
651
|
}
|
|
652
652
|
};
|
|
653
653
|
return {
|
|
@@ -663,9 +663,9 @@ const Xt = 250, Ut = (e) => {
|
|
|
663
663
|
redo: t.redo,
|
|
664
664
|
removeAnnotation: E,
|
|
665
665
|
setAnnotations: m,
|
|
666
|
-
setSelected:
|
|
666
|
+
setSelected: w,
|
|
667
667
|
undo: t.undo,
|
|
668
|
-
updateAnnotation:
|
|
668
|
+
updateAnnotation: L
|
|
669
669
|
};
|
|
670
670
|
};
|
|
671
671
|
let _t = (e) => crypto.getRandomValues(new Uint8Array(e)), kt = (e, t, n) => {
|
|
@@ -691,14 +691,14 @@ function it(e, t, n, o, i) {
|
|
|
691
691
|
var s = o - n + 1, a = t - n + 1, r = Math.log(s), d = 0.5 * Math.exp(2 * r / 3), u = 0.5 * Math.sqrt(r * d * (s - d) / s) * (a - s / 2 < 0 ? -1 : 1), b = Math.max(n, Math.floor(t - a * d / s + u)), h = Math.min(o, Math.floor(t + (s - a) * d / s + u));
|
|
692
692
|
it(e, t, b, h, i);
|
|
693
693
|
}
|
|
694
|
-
var E = e[t], m = n,
|
|
695
|
-
for (_(e, n, t), i(e[o], E) > 0 && _(e, n, o); m <
|
|
696
|
-
for (_(e, m,
|
|
694
|
+
var E = e[t], m = n, w = o;
|
|
695
|
+
for (_(e, n, t), i(e[o], E) > 0 && _(e, n, o); m < w; ) {
|
|
696
|
+
for (_(e, m, w), m++, w--; i(e[m], E) < 0; )
|
|
697
697
|
m++;
|
|
698
|
-
for (; i(e[
|
|
699
|
-
|
|
698
|
+
for (; i(e[w], E) > 0; )
|
|
699
|
+
w--;
|
|
700
700
|
}
|
|
701
|
-
i(e[n], E) === 0 ? _(e, n,
|
|
701
|
+
i(e[n], E) === 0 ? _(e, n, w) : (w++, _(e, w, o)), w <= t && (n = w + 1), t <= w && (o = w - 1);
|
|
702
702
|
}
|
|
703
703
|
}
|
|
704
704
|
function _(e, t, n) {
|
|
@@ -724,7 +724,7 @@ class $t {
|
|
|
724
724
|
for (; n; ) {
|
|
725
725
|
for (let a = 0; a < n.children.length; a++) {
|
|
726
726
|
const r = n.children[a], d = n.leaf ? i(r) : r;
|
|
727
|
-
H(t, d) && (n.leaf ? o.push(r) :
|
|
727
|
+
H(t, d) && (n.leaf ? o.push(r) : K(t, d) ? this._all(r, o) : s.push(r));
|
|
728
728
|
}
|
|
729
729
|
n = s.pop();
|
|
730
730
|
}
|
|
@@ -739,7 +739,7 @@ class $t {
|
|
|
739
739
|
for (let i = 0; i < n.children.length; i++) {
|
|
740
740
|
const s = n.children[i], a = n.leaf ? this.toBBox(s) : s;
|
|
741
741
|
if (H(t, a)) {
|
|
742
|
-
if (n.leaf ||
|
|
742
|
+
if (n.leaf || K(t, a))
|
|
743
743
|
return !0;
|
|
744
744
|
o.push(s);
|
|
745
745
|
}
|
|
@@ -788,7 +788,7 @@ class $t {
|
|
|
788
788
|
if (b !== -1)
|
|
789
789
|
return o.children.splice(b, 1), s.push(o), this._condense(s), this;
|
|
790
790
|
}
|
|
791
|
-
!u && !o.leaf &&
|
|
791
|
+
!u && !o.leaf && K(o, i) ? (s.push(o), a.push(r), r = 0, d = o, o = o.children[0]) : d ? (r++, o = d.children[r], u = !1) : o = null;
|
|
792
792
|
}
|
|
793
793
|
return this;
|
|
794
794
|
}
|
|
@@ -835,7 +835,7 @@ class $t {
|
|
|
835
835
|
for (; i.push(n), !(n.leaf || i.length - 1 === o); ) {
|
|
836
836
|
let s = 1 / 0, a = 1 / 0, r;
|
|
837
837
|
for (let d = 0; d < n.children.length; d++) {
|
|
838
|
-
const u = n.children[d], b =
|
|
838
|
+
const u = n.children[d], b = G(u), h = Kt(t, u) - b;
|
|
839
839
|
h < a ? (a = h, s = b < s ? b : s, r = u) : h === a && b < s && (s = b, r = u);
|
|
840
840
|
}
|
|
841
841
|
n = r || n.children[0];
|
|
@@ -861,14 +861,14 @@ class $t {
|
|
|
861
861
|
_chooseSplitIndex(t, n, o) {
|
|
862
862
|
let i, s = 1 / 0, a = 1 / 0;
|
|
863
863
|
for (let r = n; r <= o - n; r++) {
|
|
864
|
-
const d = N(t, 0, r, this.toBBox), u = N(t, r, o, this.toBBox), b = Jt(d, u), h =
|
|
864
|
+
const d = N(t, 0, r, this.toBBox), u = N(t, r, o, this.toBBox), b = Jt(d, u), h = G(d) + G(u);
|
|
865
865
|
b < s ? (s = b, i = r, a = h < a ? h : a) : b === s && h < a && (a = h, i = r);
|
|
866
866
|
}
|
|
867
867
|
return i || o - n;
|
|
868
868
|
}
|
|
869
869
|
// sorts node children by the best axis for split
|
|
870
870
|
_chooseSplitAxis(t, n, o) {
|
|
871
|
-
const i = t.leaf ? this.compareMinX : qt, s = t.leaf ? this.compareMinY :
|
|
871
|
+
const i = t.leaf ? this.compareMinX : qt, s = t.leaf ? this.compareMinY : Gt, a = this._allDistMargin(t, n, o, i), r = this._allDistMargin(t, n, o, s);
|
|
872
872
|
a < r && t.children.sort(i);
|
|
873
873
|
}
|
|
874
874
|
// total margin of all possible split distributions where each node is at least m full
|
|
@@ -920,23 +920,23 @@ function P(e, t) {
|
|
|
920
920
|
function qt(e, t) {
|
|
921
921
|
return e.minX - t.minX;
|
|
922
922
|
}
|
|
923
|
-
function
|
|
923
|
+
function Gt(e, t) {
|
|
924
924
|
return e.minY - t.minY;
|
|
925
925
|
}
|
|
926
|
-
function
|
|
926
|
+
function G(e) {
|
|
927
927
|
return (e.maxX - e.minX) * (e.maxY - e.minY);
|
|
928
928
|
}
|
|
929
929
|
function z(e) {
|
|
930
930
|
return e.maxX - e.minX + (e.maxY - e.minY);
|
|
931
931
|
}
|
|
932
|
-
function
|
|
932
|
+
function Kt(e, t) {
|
|
933
933
|
return (Math.max(t.maxX, e.maxX) - Math.min(t.minX, e.minX)) * (Math.max(t.maxY, e.maxY) - Math.min(t.minY, e.minY));
|
|
934
934
|
}
|
|
935
935
|
function Jt(e, t) {
|
|
936
936
|
const n = Math.max(e.minX, t.minX), o = Math.max(e.minY, t.minY), i = Math.min(e.maxX, t.maxX), s = Math.min(e.maxY, t.maxY);
|
|
937
937
|
return Math.max(0, i - n) * Math.max(0, s - o);
|
|
938
938
|
}
|
|
939
|
-
function
|
|
939
|
+
function K(e, t) {
|
|
940
940
|
return e.minX <= t.minX && e.minY <= t.minY && t.maxX <= e.maxX && t.maxY <= e.maxY;
|
|
941
941
|
}
|
|
942
942
|
function H(e, t) {
|
|
@@ -1025,9 +1025,9 @@ const jt = (e, t) => {
|
|
|
1025
1025
|
return e;
|
|
1026
1026
|
}, ee = (e, t) => {
|
|
1027
1027
|
const n = new $t(), o = /* @__PURE__ */ new Map(), i = (l) => {
|
|
1028
|
-
const c = t.getBoundingClientRect(), p = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : k(l, t),
|
|
1029
|
-
return T.map((
|
|
1030
|
-
const { x: f, y: x, width: A, height: B } =
|
|
1028
|
+
const c = t.getBoundingClientRect(), p = l.selector.range instanceof Range && !l.selector.range.collapsed && l.selector.range.startContainer.nodeType === Node.TEXT_NODE && l.selector.range.endContainer.nodeType === Node.TEXT_NODE ? l : k(l, t), v = Array.from(p.selector.range.getClientRects()), T = Qt(v);
|
|
1029
|
+
return T.map((M) => {
|
|
1030
|
+
const { x: f, y: x, width: A, height: B } = M;
|
|
1031
1031
|
return {
|
|
1032
1032
|
minX: f - c.x,
|
|
1033
1033
|
minY: x - c.y,
|
|
@@ -1050,9 +1050,9 @@ const jt = (e, t) => {
|
|
|
1050
1050
|
d(l), r(l);
|
|
1051
1051
|
}, b = (l, c = !0) => {
|
|
1052
1052
|
c && a();
|
|
1053
|
-
const g = l.map((
|
|
1054
|
-
g.forEach(({ target:
|
|
1055
|
-
const p = g.reduce((
|
|
1053
|
+
const g = l.map((v) => ({ target: v, rects: i(v) }));
|
|
1054
|
+
g.forEach(({ target: v, rects: T }) => o.set(v.annotation, T));
|
|
1055
|
+
const p = g.reduce((v, { rects: T }) => [...v, ...T], []);
|
|
1056
1056
|
n.load(p);
|
|
1057
1057
|
}, h = (l, c) => {
|
|
1058
1058
|
const g = n.search({
|
|
@@ -1060,19 +1060,19 @@ const jt = (e, t) => {
|
|
|
1060
1060
|
minY: c,
|
|
1061
1061
|
maxX: l,
|
|
1062
1062
|
maxY: c
|
|
1063
|
-
}), p = (
|
|
1063
|
+
}), p = (v) => v.annotation.rects.reduce((T, M) => T + M.width * M.height, 0);
|
|
1064
1064
|
if (g.length > 0)
|
|
1065
|
-
return g.sort((
|
|
1065
|
+
return g.sort((v, T) => p(v) - p(T)), g[0].annotation.id;
|
|
1066
1066
|
}, E = (l) => {
|
|
1067
1067
|
const c = m(l);
|
|
1068
1068
|
if (c.length === 0)
|
|
1069
1069
|
return;
|
|
1070
|
-
let g = c[0].left, p = c[0].top,
|
|
1071
|
-
for (let
|
|
1072
|
-
const f = c[
|
|
1073
|
-
g = Math.min(g, f.left), p = Math.min(p, f.top),
|
|
1070
|
+
let g = c[0].left, p = c[0].top, v = c[0].right, T = c[0].bottom;
|
|
1071
|
+
for (let M = 1; M < c.length; M++) {
|
|
1072
|
+
const f = c[M];
|
|
1073
|
+
g = Math.min(g, f.left), p = Math.min(p, f.top), v = Math.max(v, f.right), T = Math.max(T, f.bottom);
|
|
1074
1074
|
}
|
|
1075
|
-
return new DOMRect(g, p,
|
|
1075
|
+
return new DOMRect(g, p, v - g, T - p);
|
|
1076
1076
|
}, m = (l) => {
|
|
1077
1077
|
const c = o.get(l);
|
|
1078
1078
|
return c ? c[0].annotation.rects : [];
|
|
@@ -1095,47 +1095,47 @@ const jt = (e, t) => {
|
|
|
1095
1095
|
const { range: t } = e.target.selector;
|
|
1096
1096
|
return t instanceof Range && !t.collapsed;
|
|
1097
1097
|
}, ne = (e, t) => {
|
|
1098
|
-
const n = Rt(), o = ee(n, e), i =
|
|
1099
|
-
const c =
|
|
1098
|
+
const n = Rt(), o = ee(n, e), i = wt(n, t), s = xt(n), a = Yt(), r = (y, l = C.LOCAL) => {
|
|
1099
|
+
const c = y.target.selector.range instanceof Range ? y : { ...y, target: k(y.target, e) }, { range: g } = c.target.selector, p = g && !g.collapsed;
|
|
1100
1100
|
return p && n.addAnnotation(c, l), p;
|
|
1101
|
-
}, d = (
|
|
1102
|
-
const g =
|
|
1103
|
-
if (g.some((
|
|
1104
|
-
const
|
|
1105
|
-
return console.warn("Could not revive all targets"), console.warn(
|
|
1101
|
+
}, d = (y, l = !0, c = C.LOCAL) => {
|
|
1102
|
+
const g = y.map((v) => F(v) ? v : { ...v, target: k(v.target, e) });
|
|
1103
|
+
if (g.some((v) => v.target.selector.range.collapsed)) {
|
|
1104
|
+
const v = g.filter((T) => T.target.selector.range.collapsed);
|
|
1105
|
+
return console.warn("Could not revive all targets"), console.warn(v), n.bulkAddAnnotation(g, l, c), v;
|
|
1106
1106
|
} else
|
|
1107
1107
|
return n.bulkAddAnnotation(g, l, c), [];
|
|
1108
|
-
}, u = (
|
|
1109
|
-
const c =
|
|
1108
|
+
}, u = (y, l = C.LOCAL) => {
|
|
1109
|
+
const c = y.selector.range instanceof Range ? y : k(y, e);
|
|
1110
1110
|
n.updateTarget(c, l);
|
|
1111
|
-
}, b = (
|
|
1112
|
-
const c =
|
|
1111
|
+
}, b = (y, l = C.LOCAL) => {
|
|
1112
|
+
const c = y.map((g) => g.selector.range instanceof Range ? g : k(g, e));
|
|
1113
1113
|
n.bulkUpdateTargets(c, l);
|
|
1114
|
-
}, h = (
|
|
1115
|
-
const c = o.getAt(
|
|
1114
|
+
}, h = (y, l) => {
|
|
1115
|
+
const c = o.getAt(y, l);
|
|
1116
1116
|
return c ? n.getAnnotation(c) : void 0;
|
|
1117
|
-
}, E = (
|
|
1118
|
-
const p = o.getIntersectingRects(
|
|
1117
|
+
}, E = (y, l, c, g) => {
|
|
1118
|
+
const p = o.getIntersectingRects(y, l, c, g);
|
|
1119
1119
|
return Array.from(new Set(p.map((T) => T.annotation.id))).map((T) => n.getAnnotation(T)).filter((T) => T);
|
|
1120
|
-
}, m = (
|
|
1121
|
-
const p = o.getDOMRectsForAnnotation(
|
|
1120
|
+
}, m = (y, l, c, g = 5) => {
|
|
1121
|
+
const p = o.getDOMRectsForAnnotation(y);
|
|
1122
1122
|
if (p.length > 0) {
|
|
1123
1123
|
if (l && c) {
|
|
1124
|
-
const
|
|
1125
|
-
if (
|
|
1126
|
-
return
|
|
1124
|
+
const v = p.find(({ top: T, right: M, bottom: f, left: x }) => l >= x - g && l <= M + g && c >= T - g && c <= f + g);
|
|
1125
|
+
if (v)
|
|
1126
|
+
return v;
|
|
1127
1127
|
}
|
|
1128
|
-
return o.getBoundsForAnnotation(
|
|
1128
|
+
return o.getBoundsForAnnotation(y);
|
|
1129
1129
|
}
|
|
1130
|
-
},
|
|
1131
|
-
const
|
|
1132
|
-
return Object.entries(
|
|
1130
|
+
}, w = (y, l, c, g) => {
|
|
1131
|
+
const v = o.getIntersectingRects(y, l, c, g).reduce((T, M) => ((T[M.annotation.id] = T[M.annotation.id] || []).push(M), T), {});
|
|
1132
|
+
return Object.entries(v).map(([T, M]) => ({
|
|
1133
1133
|
annotation: n.getAnnotation(T),
|
|
1134
|
-
rects:
|
|
1134
|
+
rects: M.map(({ minX: f, minY: x, maxX: A, maxY: B }) => ({ x: f, y: x, width: A - f, height: B - x }))
|
|
1135
1135
|
}));
|
|
1136
|
-
},
|
|
1137
|
-
return n.observe(({ changes:
|
|
1138
|
-
const l = (
|
|
1136
|
+
}, L = () => o.recalculate();
|
|
1137
|
+
return n.observe(({ changes: y }) => {
|
|
1138
|
+
const l = (y.created || []).filter(F), c = (y.deleted || []).filter(F), g = (y.updated || []).filter((p) => F(p.newValue));
|
|
1139
1139
|
l.length > 0 && o.set(l.map((p) => p.target), !1), (c == null ? void 0 : c.length) > 0 && c.forEach((p) => o.remove(p.target)), (g == null ? void 0 : g.length) > 0 && g.forEach(({ newValue: p }) => o.update(p.target));
|
|
1140
1140
|
}), {
|
|
1141
1141
|
store: {
|
|
@@ -1146,8 +1146,8 @@ const jt = (e, t) => {
|
|
|
1146
1146
|
getAnnotationBounds: m,
|
|
1147
1147
|
getAt: h,
|
|
1148
1148
|
getIntersecting: E,
|
|
1149
|
-
getIntersectingRects:
|
|
1150
|
-
recalculatePositions:
|
|
1149
|
+
getIntersectingRects: w,
|
|
1150
|
+
recalculatePositions: L,
|
|
1151
1151
|
updateTarget: u
|
|
1152
1152
|
},
|
|
1153
1153
|
selection: i,
|
|
@@ -1162,10 +1162,10 @@ const jt = (e, t) => {
|
|
|
1162
1162
|
t.font && (d.font = t.font);
|
|
1163
1163
|
const h = n.get(s.id);
|
|
1164
1164
|
if (h) {
|
|
1165
|
-
const { x: E, y: m, height:
|
|
1166
|
-
d.fillStyle = h.appearance.color, d.fillRect(E - 2, m - 2.5, 2,
|
|
1167
|
-
const
|
|
1168
|
-
d.fillRect(E - 2, m - 2.5 - l,
|
|
1165
|
+
const { x: E, y: m, height: w } = a[0];
|
|
1166
|
+
d.fillStyle = h.appearance.color, d.fillRect(E - 2, m - 2.5, 2, w + 5);
|
|
1167
|
+
const L = d.measureText(h.appearance.label), y = L.width + 6, l = L.actualBoundingBoxAscent + L.actualBoundingBoxDescent + 8, c = L.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1168
|
+
d.fillRect(E - 2, m - 2.5 - l, y, l), d.fillStyle = "#fff", d.fillText(h.appearance.label, E + 1, m - c), r.fillStyle = h.appearance.color, r.globalAlpha = u ? 0.45 : 0.18, a.forEach(({ x: g, y: p, width: v, height: T }) => r.fillRect(g, p - 2.5, v, T + 5));
|
|
1169
1169
|
} else
|
|
1170
1170
|
nt.paint(s, a, r, d, u, b);
|
|
1171
1171
|
} };
|
|
@@ -1175,8 +1175,8 @@ const jt = (e, t) => {
|
|
|
1175
1175
|
const i = t.getAnnotation(n.id), { range: s } = i.target.selector;
|
|
1176
1176
|
if (!s || s.collapsed)
|
|
1177
1177
|
return !1;
|
|
1178
|
-
const a = o.getBoundingClientRect(), r = o.clientHeight, d = o.clientWidth, u = i.target.selector.range.getBoundingClientRect(), { width: b, height: h } = t.getAnnotationBounds(n.id), E = u.top - a.top, m = u.left - a.left,
|
|
1179
|
-
return o.scroll({ top:
|
|
1178
|
+
const a = o.getBoundingClientRect(), r = o.clientHeight, d = o.clientWidth, u = i.target.selector.range.getBoundingClientRect(), { width: b, height: h } = t.getAnnotationBounds(n.id), E = u.top - a.top, m = u.left - a.left, w = o.parentElement ? o.scrollTop : 0, L = o.parentElement ? o.scrollLeft : 0, y = E + w - (r - h) / 2, l = m + L - (d - b) / 2;
|
|
1179
|
+
return o.scroll({ top: y, left: l, behavior: "smooth" }), !0;
|
|
1180
1180
|
}
|
|
1181
1181
|
};
|
|
1182
1182
|
let $;
|
|
@@ -1233,14 +1233,14 @@ const de = (e, t, n) => {
|
|
|
1233
1233
|
b && clearTimeout(b), b = setTimeout(() => h(), 50);
|
|
1234
1234
|
});
|
|
1235
1235
|
const h = () => {
|
|
1236
|
-
var m,
|
|
1236
|
+
var m, w;
|
|
1237
1237
|
const E = document.getSelection();
|
|
1238
1238
|
if (!E.isCollapsed && d && a) {
|
|
1239
|
-
const
|
|
1240
|
-
te(
|
|
1239
|
+
const L = Array.from(Array(E.rangeCount).keys()).map((c) => E.getRangeAt(c));
|
|
1240
|
+
te(L[0]).toString() !== ((w = (m = a.selector) == null ? void 0 : m.range) == null ? void 0 : w.toString()) && (a = {
|
|
1241
1241
|
...a,
|
|
1242
|
-
selector: de(
|
|
1243
|
-
}, o.getAnnotation(a.annotation) ? o.updateTarget(a,
|
|
1242
|
+
selector: de(L[0], e, n)
|
|
1243
|
+
}, o.getAnnotation(a.annotation) ? o.updateTarget(a, C.LOCAL) : (o.addAnnotation({
|
|
1244
1244
|
id: a.annotation,
|
|
1245
1245
|
bodies: [],
|
|
1246
1246
|
target: a
|
|
@@ -1250,12 +1250,12 @@ const de = (e, t, n) => {
|
|
|
1250
1250
|
return e.addEventListener("pointerdown", (E) => {
|
|
1251
1251
|
u = E, d = E.button === 0;
|
|
1252
1252
|
}), document.addEventListener("pointerup", (E) => {
|
|
1253
|
-
var
|
|
1254
|
-
u = E, !((
|
|
1253
|
+
var w;
|
|
1254
|
+
u = E, !((w = E.target.parentElement) != null && w.closest(".not-annotatable") || !d) && setTimeout(() => {
|
|
1255
1255
|
if (a != null && a.selector)
|
|
1256
|
-
o.updateTarget(a,
|
|
1256
|
+
o.updateTarget(a, C.LOCAL), i.clickSelect(a.annotation, E), a = null, u = void 0;
|
|
1257
1257
|
else {
|
|
1258
|
-
const { x:
|
|
1258
|
+
const { x: L, y } = e.getBoundingClientRect(), l = o.getAt(E.clientX - L, E.clientY - y);
|
|
1259
1259
|
if (l) {
|
|
1260
1260
|
const { selected: c } = i;
|
|
1261
1261
|
(c.length !== 1 || c[0].id !== l.id) && (i.clickSelect(l.id, E), u = void 0);
|
|
@@ -1302,7 +1302,7 @@ const he = (e, t = {}) => {
|
|
|
1302
1302
|
};
|
|
1303
1303
|
};
|
|
1304
1304
|
export {
|
|
1305
|
-
|
|
1305
|
+
C as Origin,
|
|
1306
1306
|
bt as createHighlightLayer,
|
|
1307
1307
|
he as createTextAnnotator,
|
|
1308
1308
|
ne as createTextAnnotatorState,
|