@recogito/text-annotator 3.0.0-rc.33 → 3.0.0-rc.35
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.
|
@@ -90,12 +90,12 @@ const P = {
|
|
|
90
90
|
l.selectNodeContents(n), l.setStart(n, o);
|
|
91
91
|
const g = m(l), f = document.createRange();
|
|
92
92
|
f.selectNode(i), f.setEnd(i, r);
|
|
93
|
-
const
|
|
93
|
+
const w = m(f), p = ne(t).reverse().map((d) => {
|
|
94
94
|
var y;
|
|
95
95
|
const a = document.createElement("SPAN");
|
|
96
96
|
return (y = d.parentNode) == null || y.insertBefore(a, d), a.appendChild(d), a;
|
|
97
97
|
});
|
|
98
|
-
return { unwrap: h, nodes: [g, ...p,
|
|
98
|
+
return { unwrap: h, nodes: [g, ...p, w] };
|
|
99
99
|
}
|
|
100
100
|
}, ne = (t) => {
|
|
101
101
|
const {
|
|
@@ -233,20 +233,20 @@ const P = {
|
|
|
233
233
|
const { store: i, selection: r, hover: c } = e;
|
|
234
234
|
let s, u, h;
|
|
235
235
|
const m = ue(n), l = (B) => {
|
|
236
|
-
const { x: M, y: b } = t.getBoundingClientRect(),
|
|
237
|
-
|
|
236
|
+
const { x: M, y: b } = t.getBoundingClientRect(), x = i.getAt(B.clientX - M, B.clientY - b, u);
|
|
237
|
+
x ? c.current !== x.id && (t.classList.add("hovered"), c.set(x.id)) : c.current && (t.classList.remove("hovered"), c.set(null));
|
|
238
238
|
};
|
|
239
239
|
t.addEventListener("pointermove", l);
|
|
240
240
|
const g = (B = !1) => {
|
|
241
241
|
h && h.clear();
|
|
242
|
-
const M = de(t), { minX: b, minY:
|
|
242
|
+
const M = de(t), { minX: b, minY: x, maxX: A, maxY: C } = M, R = u ? i.getIntersecting(b, x, A, C).filter(({ annotation: _ }) => u(_)) : i.getIntersecting(b, x, A, C), O = r.selected.map(({ id: _ }) => _), H = R.map(({ annotation: _, rects: qt }) => {
|
|
243
243
|
const jt = O.includes(_.id), Gt = _.id === c.current;
|
|
244
244
|
return { annotation: _, rects: qt, state: { selected: jt, hover: Gt } };
|
|
245
245
|
});
|
|
246
246
|
o.redraw(H, M, s, h, B), setTimeout(() => m(R.map(({ annotation: _ }) => _)), 1);
|
|
247
247
|
}, f = (B) => {
|
|
248
248
|
h = B, g();
|
|
249
|
-
},
|
|
249
|
+
}, w = (B) => {
|
|
250
250
|
s = B, g();
|
|
251
251
|
}, v = (B) => {
|
|
252
252
|
u = B, g(!1);
|
|
@@ -268,7 +268,7 @@ const P = {
|
|
|
268
268
|
t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(p), d(), document.removeEventListener("scroll", a), window.removeEventListener("resize", y), S.disconnect(), E.disconnect();
|
|
269
269
|
},
|
|
270
270
|
redraw: g,
|
|
271
|
-
setStyle:
|
|
271
|
+
setStyle: w,
|
|
272
272
|
setFilter: v,
|
|
273
273
|
setPainter: f,
|
|
274
274
|
setVisible: o.setVisible
|
|
@@ -285,14 +285,14 @@ const P = {
|
|
|
285
285
|
const o = (s, u, h, m) => requestAnimationFrame(() => {
|
|
286
286
|
const { width: l, height: g } = e;
|
|
287
287
|
n.clearRect(-0.5, -0.5, l + 1, g + 1), m && m.clear();
|
|
288
|
-
const { top: f, left:
|
|
288
|
+
const { top: f, left: w } = u;
|
|
289
289
|
[...s].sort((p, d) => {
|
|
290
290
|
const { annotation: { target: { created: a } } } = p, { annotation: { target: { created: y } } } = d;
|
|
291
291
|
return a.getTime() - y.getTime();
|
|
292
292
|
}).forEach((p) => {
|
|
293
293
|
var L;
|
|
294
294
|
const d = h ? typeof h == "function" ? h(p.annotation, p.state) : h : (L = p.state) != null && L.selected ? ot : P, a = m && m.paint(p, u) || d, y = p.rects.map(({ x: E, y: T, width: B, height: M }) => ({
|
|
295
|
-
x: E +
|
|
295
|
+
x: E + w,
|
|
296
296
|
y: T + f,
|
|
297
297
|
width: B,
|
|
298
298
|
height: M
|
|
@@ -479,13 +479,13 @@ const Ee = (t) => [
|
|
|
479
479
|
const h = new Set(r.map((l) => l.annotation.id));
|
|
480
480
|
Array.from(e).filter((l) => !h.has(l));
|
|
481
481
|
const m = r.map((l) => {
|
|
482
|
-
var
|
|
483
|
-
const g = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (
|
|
482
|
+
var w;
|
|
483
|
+
const g = s ? typeof s == "function" ? s(l.annotation, l.state) : s : (w = l.state) != null && w.selected ? ot : P, f = u && u.paint(l, c) || g;
|
|
484
484
|
return `::highlight(_${l.annotation.id}) { ${Ee(f)} }`;
|
|
485
485
|
});
|
|
486
486
|
t.innerHTML = m.join(`
|
|
487
487
|
`), CSS.highlights.clear(), r.forEach(({ annotation: l }) => {
|
|
488
|
-
const g = l.target.selector.map((
|
|
488
|
+
const g = l.target.selector.map((w) => w.range), f = new Highlight(...g);
|
|
489
489
|
CSS.highlights.set(`_${l.id}`, f);
|
|
490
490
|
}), e = h;
|
|
491
491
|
}
|
|
@@ -528,13 +528,13 @@ const Le = (t, e) => {
|
|
|
528
528
|
const g = !(mt(n, c) && m);
|
|
529
529
|
if (!h && !g) return;
|
|
530
530
|
g && (e.innerHTML = "");
|
|
531
|
-
const f = c.reduce((
|
|
532
|
-
c.forEach((
|
|
533
|
-
|
|
534
|
-
const p = Le(v, f), d = Kt(
|
|
531
|
+
const f = c.reduce((w, { rects: v }) => [...w, ...v], []);
|
|
532
|
+
c.forEach((w) => {
|
|
533
|
+
w.rects.map((v) => {
|
|
534
|
+
const p = Le(v, f), d = Kt(w, s, u, h, p);
|
|
535
535
|
if (g) {
|
|
536
536
|
const a = document.createElement("span");
|
|
537
|
-
a.className = "r6o-annotation", a.dataset.annotation =
|
|
537
|
+
a.className = "r6o-annotation", a.dataset.annotation = w.annotation.id, a.style.left = `${v.x}px`, a.style.top = `${v.y}px`, a.style.width = `${v.width}px`, a.style.height = `${v.height}px`;
|
|
538
538
|
const y = Y((d == null ? void 0 : d.fill) || P.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? P.fillOpacity : d.fillOpacity).toHex();
|
|
539
539
|
a.style.backgroundColor = y, d.underlineStyle && (a.style.borderStyle = d.underlineStyle), d.underlineColor && (a.style.borderColor = d.underlineColor), d.underlineThickness && (a.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (a.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(a);
|
|
540
540
|
}
|
|
@@ -655,18 +655,18 @@ const ut = { selected: [] }, ke = (t, e = "EDIT") => {
|
|
|
655
655
|
}, u = (l, g) => {
|
|
656
656
|
const f = t.getAnnotation(l);
|
|
657
657
|
if (f) {
|
|
658
|
-
const
|
|
659
|
-
o(
|
|
658
|
+
const w = It(f, e);
|
|
659
|
+
o(w === "EDIT" ? { selected: [{ id: l, editable: !0 }], pointerEvent: g } : w === "SELECT" ? { selected: [{ id: l }], pointerEvent: g } : { selected: [], pointerEvent: g });
|
|
660
660
|
} else
|
|
661
661
|
console.warn("Invalid selection: " + l);
|
|
662
662
|
}, h = (l, g) => {
|
|
663
|
-
const f = Array.isArray(l) ? l : [l],
|
|
663
|
+
const f = Array.isArray(l) ? l : [l], w = f.map((v) => t.getAnnotation(v)).filter(Boolean);
|
|
664
664
|
o({
|
|
665
|
-
selected:
|
|
665
|
+
selected: w.map((v) => {
|
|
666
666
|
const p = g === void 0 ? It(v, e) === "EDIT" : g;
|
|
667
667
|
return { id: v.id, editable: p };
|
|
668
668
|
})
|
|
669
|
-
}),
|
|
669
|
+
}), w.length !== f.length && console.warn("Invalid selection", l);
|
|
670
670
|
}, m = (l) => {
|
|
671
671
|
if (i.selected.length === 0)
|
|
672
672
|
return !1;
|
|
@@ -771,8 +771,8 @@ const We = (t, e) => {
|
|
|
771
771
|
...(t.updated || []).filter(({ newValue: l }) => !r.has(l.id)).map((l) => {
|
|
772
772
|
const { oldValue: g, newValue: f } = l;
|
|
773
773
|
if (c.has(f.id)) {
|
|
774
|
-
const
|
|
775
|
-
return Pt(g,
|
|
774
|
+
const w = e.updated.find((v) => v.oldValue.id === f.id).newValue;
|
|
775
|
+
return Pt(g, w);
|
|
776
776
|
} else
|
|
777
777
|
return l;
|
|
778
778
|
}),
|
|
@@ -780,50 +780,50 @@ const We = (t, e) => {
|
|
|
780
780
|
];
|
|
781
781
|
return { created: u, deleted: h, updated: m };
|
|
782
782
|
}, je = (t) => t.id !== void 0, Ge = () => {
|
|
783
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b,
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
}, r = (b,
|
|
783
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (b, x = {}) => n.push({ onChange: b, options: x }), i = (b) => {
|
|
784
|
+
const x = n.findIndex((A) => A.onChange == b);
|
|
785
|
+
x > -1 && n.splice(x, 1);
|
|
786
|
+
}, r = (b, x) => {
|
|
787
787
|
const A = {
|
|
788
788
|
origin: b,
|
|
789
789
|
changes: {
|
|
790
|
-
created:
|
|
791
|
-
updated:
|
|
792
|
-
deleted:
|
|
790
|
+
created: x.created || [],
|
|
791
|
+
updated: x.updated || [],
|
|
792
|
+
deleted: x.deleted || []
|
|
793
793
|
},
|
|
794
794
|
state: [...t.values()]
|
|
795
795
|
};
|
|
796
796
|
n.forEach((C) => {
|
|
797
797
|
We(C, A) && C.onChange(A);
|
|
798
798
|
});
|
|
799
|
-
}, c = (b,
|
|
799
|
+
}, c = (b, x = N.LOCAL) => {
|
|
800
800
|
if (t.get(b.id))
|
|
801
801
|
throw Error(`Cannot add annotation ${b.id} - exists already`);
|
|
802
|
-
t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(
|
|
803
|
-
}, s = (b,
|
|
804
|
-
const A = typeof b == "string" ?
|
|
802
|
+
t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(x, { created: [b] });
|
|
803
|
+
}, s = (b, x) => {
|
|
804
|
+
const A = typeof b == "string" ? x : b, C = typeof b == "string" ? b : b.id, R = t.get(C);
|
|
805
805
|
if (R) {
|
|
806
806
|
const O = Pt(R, A);
|
|
807
807
|
return C === A.id ? t.set(C, A) : (t.delete(C), t.set(A.id, A)), R.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), O;
|
|
808
808
|
} else
|
|
809
809
|
console.warn(`Cannot update annotation ${C} - does not exist`);
|
|
810
|
-
}, u = (b,
|
|
811
|
-
const C = je(
|
|
810
|
+
}, u = (b, x = N.LOCAL, A = N.LOCAL) => {
|
|
811
|
+
const C = je(x) ? A : x, R = s(b, x);
|
|
812
812
|
R && r(C, { updated: [R] });
|
|
813
|
-
}, h = (b,
|
|
813
|
+
}, h = (b, x = N.LOCAL) => {
|
|
814
814
|
const A = b.reduce((C, R) => {
|
|
815
815
|
const O = s(R);
|
|
816
816
|
return O ? [...C, O] : C;
|
|
817
817
|
}, []);
|
|
818
|
-
A.length > 0 && r(
|
|
819
|
-
}, m = (b,
|
|
818
|
+
A.length > 0 && r(x, { updated: A });
|
|
819
|
+
}, m = (b, x = N.LOCAL) => {
|
|
820
820
|
const A = t.get(b.annotation);
|
|
821
821
|
if (A) {
|
|
822
822
|
const C = {
|
|
823
823
|
...A,
|
|
824
824
|
bodies: [...A.bodies, b]
|
|
825
825
|
};
|
|
826
|
-
t.set(A.id, C), e.set(b.id, C.id), r(
|
|
826
|
+
t.set(A.id, C), e.set(b.id, C.id), r(x, { updated: [{
|
|
827
827
|
oldValue: A,
|
|
828
828
|
newValue: C,
|
|
829
829
|
bodiesCreated: [b]
|
|
@@ -831,10 +831,10 @@ const We = (t, e) => {
|
|
|
831
831
|
} else
|
|
832
832
|
console.warn(`Attempt to add body to missing annotation: ${b.annotation}`);
|
|
833
833
|
}, l = () => [...t.values()], g = (b = N.LOCAL) => {
|
|
834
|
-
const
|
|
835
|
-
t.clear(), e.clear(), r(b, { deleted:
|
|
836
|
-
}, f = (b,
|
|
837
|
-
if (
|
|
834
|
+
const x = [...t.values()];
|
|
835
|
+
t.clear(), e.clear(), r(b, { deleted: x });
|
|
836
|
+
}, f = (b, x = !0, A = N.LOCAL) => {
|
|
837
|
+
if (x) {
|
|
838
838
|
const C = [...t.values()];
|
|
839
839
|
t.clear(), e.clear(), b.forEach((R) => {
|
|
840
840
|
t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
|
|
@@ -850,32 +850,32 @@ const We = (t, e) => {
|
|
|
850
850
|
t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
|
|
851
851
|
}), r(A, { created: b });
|
|
852
852
|
}
|
|
853
|
-
},
|
|
854
|
-
const
|
|
853
|
+
}, w = (b) => {
|
|
854
|
+
const x = typeof b == "string" ? b : b.id, A = t.get(x);
|
|
855
855
|
if (A)
|
|
856
|
-
return t.delete(
|
|
857
|
-
console.warn(`Attempt to delete missing annotation: ${
|
|
858
|
-
}, v = (b,
|
|
859
|
-
const A =
|
|
860
|
-
A && r(
|
|
861
|
-
}, p = (b,
|
|
856
|
+
return t.delete(x), A.bodies.forEach((C) => e.delete(C.id)), A;
|
|
857
|
+
console.warn(`Attempt to delete missing annotation: ${x}`);
|
|
858
|
+
}, v = (b, x = N.LOCAL) => {
|
|
859
|
+
const A = w(b);
|
|
860
|
+
A && r(x, { deleted: [A] });
|
|
861
|
+
}, p = (b, x = N.LOCAL) => {
|
|
862
862
|
const A = b.reduce((C, R) => {
|
|
863
|
-
const O =
|
|
863
|
+
const O = w(R);
|
|
864
864
|
return O ? [...C, O] : C;
|
|
865
865
|
}, []);
|
|
866
|
-
A.length > 0 && r(
|
|
866
|
+
A.length > 0 && r(x, { deleted: A });
|
|
867
867
|
}, d = (b) => {
|
|
868
|
-
const
|
|
869
|
-
if (
|
|
870
|
-
const A =
|
|
868
|
+
const x = t.get(b.annotation);
|
|
869
|
+
if (x) {
|
|
870
|
+
const A = x.bodies.find((C) => C.id === b.id);
|
|
871
871
|
if (A) {
|
|
872
872
|
e.delete(A.id);
|
|
873
873
|
const C = {
|
|
874
|
-
...
|
|
875
|
-
bodies:
|
|
874
|
+
...x,
|
|
875
|
+
bodies: x.bodies.filter((R) => R.id !== b.id)
|
|
876
876
|
};
|
|
877
|
-
return t.set(
|
|
878
|
-
oldValue:
|
|
877
|
+
return t.set(x.id, C), {
|
|
878
|
+
oldValue: x,
|
|
879
879
|
newValue: C,
|
|
880
880
|
bodiesDeleted: [A]
|
|
881
881
|
};
|
|
@@ -883,61 +883,61 @@ const We = (t, e) => {
|
|
|
883
883
|
console.warn(`Attempt to delete missing body ${b.id} from annotation ${b.annotation}`);
|
|
884
884
|
} else
|
|
885
885
|
console.warn(`Attempt to delete body from missing annotation ${b.annotation}`);
|
|
886
|
-
}, a = (b,
|
|
886
|
+
}, a = (b, x = N.LOCAL) => {
|
|
887
887
|
const A = d(b);
|
|
888
|
-
A && r(
|
|
889
|
-
}, y = (b,
|
|
888
|
+
A && r(x, { updated: [A] });
|
|
889
|
+
}, y = (b, x = N.LOCAL) => {
|
|
890
890
|
const A = b.map((C) => d(C)).filter(Boolean);
|
|
891
|
-
A.length > 0 && r(
|
|
891
|
+
A.length > 0 && r(x, { updated: A });
|
|
892
892
|
}, S = (b) => {
|
|
893
|
-
const
|
|
894
|
-
return
|
|
893
|
+
const x = t.get(b);
|
|
894
|
+
return x ? { ...x } : void 0;
|
|
895
895
|
}, L = (b) => {
|
|
896
|
-
const
|
|
897
|
-
if (
|
|
898
|
-
const A = S(
|
|
896
|
+
const x = e.get(b);
|
|
897
|
+
if (x) {
|
|
898
|
+
const A = S(x).bodies.find((C) => C.id === b);
|
|
899
899
|
if (A)
|
|
900
900
|
return A;
|
|
901
901
|
console.error(`Store integrity error: body ${b} in index, but not in annotation`);
|
|
902
902
|
} else
|
|
903
903
|
console.warn(`Attempt to retrieve missing body: ${b}`);
|
|
904
|
-
}, E = (b,
|
|
905
|
-
if (b.annotation !==
|
|
904
|
+
}, E = (b, x) => {
|
|
905
|
+
if (b.annotation !== x.annotation)
|
|
906
906
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
907
907
|
const A = t.get(b.annotation);
|
|
908
908
|
if (A) {
|
|
909
909
|
const C = A.bodies.find((O) => O.id === b.id), R = {
|
|
910
910
|
...A,
|
|
911
|
-
bodies: A.bodies.map((O) => O.id === C.id ?
|
|
911
|
+
bodies: A.bodies.map((O) => O.id === C.id ? x : O)
|
|
912
912
|
};
|
|
913
|
-
return t.set(A.id, R), C.id !==
|
|
913
|
+
return t.set(A.id, R), C.id !== x.id && (e.delete(C.id), e.set(x.id, R.id)), {
|
|
914
914
|
oldValue: A,
|
|
915
915
|
newValue: R,
|
|
916
|
-
bodiesUpdated: [{ oldBody: C, newBody:
|
|
916
|
+
bodiesUpdated: [{ oldBody: C, newBody: x }]
|
|
917
917
|
};
|
|
918
918
|
} else
|
|
919
919
|
console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
|
|
920
|
-
}, T = (b,
|
|
921
|
-
const C = E(b,
|
|
920
|
+
}, T = (b, x, A = N.LOCAL) => {
|
|
921
|
+
const C = E(b, x);
|
|
922
922
|
C && r(A, { updated: [C] });
|
|
923
|
-
}, B = (b,
|
|
923
|
+
}, B = (b, x = N.LOCAL) => {
|
|
924
924
|
const A = b.map((C) => E({ id: C.id, annotation: C.annotation }, C)).filter(Boolean);
|
|
925
|
-
r(
|
|
925
|
+
r(x, { updated: A });
|
|
926
926
|
}, M = (b) => {
|
|
927
|
-
const
|
|
928
|
-
if (
|
|
927
|
+
const x = t.get(b.annotation);
|
|
928
|
+
if (x) {
|
|
929
929
|
const A = {
|
|
930
|
-
...
|
|
930
|
+
...x,
|
|
931
931
|
target: {
|
|
932
|
-
...
|
|
932
|
+
...x.target,
|
|
933
933
|
...b
|
|
934
934
|
}
|
|
935
935
|
};
|
|
936
|
-
return t.set(
|
|
937
|
-
oldValue:
|
|
936
|
+
return t.set(x.id, A), {
|
|
937
|
+
oldValue: x,
|
|
938
938
|
newValue: A,
|
|
939
939
|
targetUpdated: {
|
|
940
|
-
oldTarget:
|
|
940
|
+
oldTarget: x.target,
|
|
941
941
|
newTarget: b
|
|
942
942
|
}
|
|
943
943
|
};
|
|
@@ -953,9 +953,9 @@ const We = (t, e) => {
|
|
|
953
953
|
bulkDeleteBodies: y,
|
|
954
954
|
bulkUpdateAnnotation: h,
|
|
955
955
|
bulkUpdateBodies: B,
|
|
956
|
-
bulkUpdateTargets: (b,
|
|
956
|
+
bulkUpdateTargets: (b, x = N.LOCAL) => {
|
|
957
957
|
const A = b.map((C) => M(C)).filter(Boolean);
|
|
958
|
-
A.length > 0 && r(
|
|
958
|
+
A.length > 0 && r(x, { updated: A });
|
|
959
959
|
},
|
|
960
960
|
clear: g,
|
|
961
961
|
deleteAnnotation: v,
|
|
@@ -966,9 +966,9 @@ const We = (t, e) => {
|
|
|
966
966
|
unobserve: i,
|
|
967
967
|
updateAnnotation: u,
|
|
968
968
|
updateBody: T,
|
|
969
|
-
updateTarget: (b,
|
|
969
|
+
updateTarget: (b, x = N.LOCAL) => {
|
|
970
970
|
const A = M(b);
|
|
971
|
-
A && r(
|
|
971
|
+
A && r(x, { updated: [A] });
|
|
972
972
|
}
|
|
973
973
|
};
|
|
974
974
|
};
|
|
@@ -991,36 +991,36 @@ const Qe = 250, Je = (t) => {
|
|
|
991
991
|
let o = -1, i = !1, r = 0;
|
|
992
992
|
const c = (f) => {
|
|
993
993
|
if (!i) {
|
|
994
|
-
const { changes:
|
|
994
|
+
const { changes: w } = f, v = performance.now();
|
|
995
995
|
if (v - r > Qe)
|
|
996
|
-
n.splice(o + 1), n.push(
|
|
996
|
+
n.splice(o + 1), n.push(w), o = n.length - 1;
|
|
997
997
|
else {
|
|
998
998
|
const p = n.length - 1;
|
|
999
|
-
n[p] = qe(n[p],
|
|
999
|
+
n[p] = qe(n[p], w);
|
|
1000
1000
|
}
|
|
1001
1001
|
r = v;
|
|
1002
1002
|
}
|
|
1003
1003
|
i = !1;
|
|
1004
1004
|
};
|
|
1005
1005
|
t.observe(c, { origin: N.LOCAL });
|
|
1006
|
-
const s = (f) => f && f.length > 0 && t.bulkDeleteAnnotation(f), u = (f) => f && f.length > 0 && t.bulkAddAnnotation(f, !1), h = (f) => f && f.length > 0 && t.bulkUpdateAnnotation(f.map(({ oldValue:
|
|
1006
|
+
const s = (f) => f && f.length > 0 && t.bulkDeleteAnnotation(f), u = (f) => f && f.length > 0 && t.bulkAddAnnotation(f, !1), h = (f) => f && f.length > 0 && t.bulkUpdateAnnotation(f.map(({ oldValue: w }) => w)), m = (f) => f && f.length > 0 && t.bulkUpdateAnnotation(f.map(({ newValue: w }) => w)), l = (f) => f && f.length > 0 && t.bulkAddAnnotation(f, !1), g = (f) => f && f.length > 0 && t.bulkDeleteAnnotation(f);
|
|
1007
1007
|
return {
|
|
1008
1008
|
canRedo: () => n.length - 1 > o,
|
|
1009
1009
|
canUndo: () => o > -1,
|
|
1010
1010
|
destroy: () => t.unobserve(c),
|
|
1011
|
-
on: (f,
|
|
1011
|
+
on: (f, w) => e.on(f, w),
|
|
1012
1012
|
redo: () => {
|
|
1013
1013
|
if (n.length - 1 > o) {
|
|
1014
1014
|
i = !0;
|
|
1015
|
-
const { created: f, updated:
|
|
1016
|
-
u(f), m(
|
|
1015
|
+
const { created: f, updated: w, deleted: v } = n[o + 1];
|
|
1016
|
+
u(f), m(w), g(v), e.emit("redo", n[o + 1]), o += 1;
|
|
1017
1017
|
}
|
|
1018
1018
|
},
|
|
1019
1019
|
undo: () => {
|
|
1020
1020
|
if (o > -1) {
|
|
1021
1021
|
i = !0;
|
|
1022
|
-
const { created: f, updated:
|
|
1023
|
-
s(f), h(
|
|
1022
|
+
const { created: f, updated: w, deleted: v } = n[o];
|
|
1023
|
+
s(f), h(w), l(v), e.emit("undo", n[o]), o -= 1;
|
|
1024
1024
|
}
|
|
1025
1025
|
}
|
|
1026
1026
|
};
|
|
@@ -1093,11 +1093,11 @@ const Qe = 250, Je = (t) => {
|
|
|
1093
1093
|
d.length > 0 && (h = h.map((a) => d.find((S) => S.id === a.id) || a));
|
|
1094
1094
|
}
|
|
1095
1095
|
}, { origin: N.REMOTE });
|
|
1096
|
-
const
|
|
1096
|
+
const w = (v) => (p) => {
|
|
1097
1097
|
const { updated: d } = p;
|
|
1098
1098
|
v ? (d || []).forEach((a) => f("updateAnnotation", a.oldValue, a.newValue)) : (d || []).forEach((a) => f("updateAnnotation", a.newValue, a.oldValue));
|
|
1099
1099
|
};
|
|
1100
|
-
return e.on("undo",
|
|
1100
|
+
return e.on("undo", w(!0)), e.on("redo", w(!1)), { on: l, off: g, emit: f };
|
|
1101
1101
|
}, en = (t) => (e) => e.reduce((n, o) => {
|
|
1102
1102
|
const { parsed: i, error: r } = t.parse(o);
|
|
1103
1103
|
return r ? {
|
|
@@ -1139,7 +1139,7 @@ const Qe = 250, Je = (t) => {
|
|
|
1139
1139
|
y.length > 0 && console.warn(`Discarded ${y.length} invalid annotations`, y), o.bulkAddAnnotation(a, d, N.REMOTE);
|
|
1140
1140
|
} else
|
|
1141
1141
|
o.bulkAddAnnotation(p, d, N.REMOTE);
|
|
1142
|
-
},
|
|
1142
|
+
}, w = (p, d) => {
|
|
1143
1143
|
p ? i.setSelected(p, d) : i.clear();
|
|
1144
1144
|
}, v = (p) => {
|
|
1145
1145
|
if (n) {
|
|
@@ -1163,7 +1163,7 @@ const Qe = 250, Je = (t) => {
|
|
|
1163
1163
|
redo: e.redo,
|
|
1164
1164
|
removeAnnotation: g,
|
|
1165
1165
|
setAnnotations: f,
|
|
1166
|
-
setSelected:
|
|
1166
|
+
setSelected: w,
|
|
1167
1167
|
undo: e.undo,
|
|
1168
1168
|
updateAnnotation: v
|
|
1169
1169
|
};
|
|
@@ -1279,14 +1279,14 @@ const Un = (t, e) => ({
|
|
|
1279
1279
|
updated: h,
|
|
1280
1280
|
...m
|
|
1281
1281
|
} = i, l = c.map((g) => {
|
|
1282
|
-
const { quote: f, start:
|
|
1282
|
+
const { quote: f, start: w, end: v, range: p } = g, { prefix: d, suffix: a } = oe(p, n), y = [{
|
|
1283
1283
|
type: "TextQuoteSelector",
|
|
1284
1284
|
exact: f,
|
|
1285
1285
|
prefix: d,
|
|
1286
1286
|
suffix: a
|
|
1287
1287
|
}, {
|
|
1288
1288
|
type: "TextPositionSelector",
|
|
1289
|
-
start:
|
|
1289
|
+
start: w,
|
|
1290
1290
|
end: v
|
|
1291
1291
|
}];
|
|
1292
1292
|
return {
|
|
@@ -1317,12 +1317,12 @@ function zt(t, e, n, o, i) {
|
|
|
1317
1317
|
var r = o - n + 1, c = e - n + 1, s = Math.log(r), u = 0.5 * Math.exp(2 * s / 3), h = 0.5 * Math.sqrt(s * u * (r - u) / r) * (c - r / 2 < 0 ? -1 : 1), m = Math.max(n, Math.floor(e - c * u / r + h)), l = Math.min(o, Math.floor(e + (r - c) * u / r + h));
|
|
1318
1318
|
zt(t, e, m, l, i);
|
|
1319
1319
|
}
|
|
1320
|
-
var g = t[e], f = n,
|
|
1321
|
-
for (j(t, n, e), i(t[o], g) > 0 && j(t, n, o); f <
|
|
1322
|
-
for (j(t, f,
|
|
1323
|
-
for (; i(t[
|
|
1320
|
+
var g = t[e], f = n, w = o;
|
|
1321
|
+
for (j(t, n, e), i(t[o], g) > 0 && j(t, n, o); f < w; ) {
|
|
1322
|
+
for (j(t, f, w), f++, w--; i(t[f], g) < 0; ) f++;
|
|
1323
|
+
for (; i(t[w], g) > 0; ) w--;
|
|
1324
1324
|
}
|
|
1325
|
-
i(t[n], g) === 0 ? j(t, n,
|
|
1325
|
+
i(t[n], g) === 0 ? j(t, n, w) : (w++, j(t, w, o)), w <= e && (n = w + 1), e <= w && (o = w - 1);
|
|
1326
1326
|
}
|
|
1327
1327
|
}
|
|
1328
1328
|
function j(t, e, n) {
|
|
@@ -1685,7 +1685,7 @@ const Cn = (t, e) => {
|
|
|
1685
1685
|
}
|
|
1686
1686
|
return o.getAnnotationBounds(v);
|
|
1687
1687
|
}
|
|
1688
|
-
},
|
|
1688
|
+
}, w = () => o.recalculate();
|
|
1689
1689
|
return n.observe(({ changes: v }) => {
|
|
1690
1690
|
const p = (v.deleted || []).filter((y) => $(y.target.selector)), d = (v.created || []).filter((y) => $(y.target.selector)), a = (v.updated || []).filter((y) => $(y.newValue.target.selector));
|
|
1691
1691
|
(p == null ? void 0 : p.length) > 0 && p.forEach((y) => o.remove(y.target)), d.length > 0 && o.set(d.map((y) => y.target), !1), (a == null ? void 0 : a.length) > 0 && a.forEach(({ newValue: y }) => o.update(y.target));
|
|
@@ -1699,7 +1699,7 @@ const Cn = (t, e) => {
|
|
|
1699
1699
|
getAnnotationBounds: f,
|
|
1700
1700
|
getAt: g,
|
|
1701
1701
|
getIntersecting: o.getIntersecting,
|
|
1702
|
-
recalculatePositions:
|
|
1702
|
+
recalculatePositions: w,
|
|
1703
1703
|
updateTarget: m
|
|
1704
1704
|
},
|
|
1705
1705
|
selection: i,
|
|
@@ -1716,7 +1716,7 @@ const Cn = (t, e) => {
|
|
|
1716
1716
|
t.appendChild(o);
|
|
1717
1717
|
const r = /* @__PURE__ */ new Map(), c = (l) => Array.from(r.entries()).filter(([g, f]) => f.presenceKey === l.presenceKey).map(([g, f]) => g);
|
|
1718
1718
|
return e.on("selectionChange", (l, g) => {
|
|
1719
|
-
c(l).forEach((
|
|
1719
|
+
c(l).forEach((w) => r.delete(w)), g && g.forEach((w) => r.set(w, l));
|
|
1720
1720
|
}), {
|
|
1721
1721
|
clear: () => {
|
|
1722
1722
|
const { width: l, height: g } = o;
|
|
@@ -1727,13 +1727,13 @@ const Cn = (t, e) => {
|
|
|
1727
1727
|
},
|
|
1728
1728
|
paint: (l, g, f) => {
|
|
1729
1729
|
n.font && (i.font = n.font);
|
|
1730
|
-
const
|
|
1731
|
-
if (
|
|
1730
|
+
const w = r.get(l.annotation.id);
|
|
1731
|
+
if (w) {
|
|
1732
1732
|
const { height: v } = l.rects[0], p = l.rects[0].x + g.left, d = l.rects[0].y + g.top;
|
|
1733
|
-
i.fillStyle =
|
|
1734
|
-
const a = i.measureText(
|
|
1735
|
-
return i.fillRect(p - 2, d - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(
|
|
1736
|
-
fill:
|
|
1733
|
+
i.fillStyle = w.appearance.color, i.fillRect(p - 2, d - 2.5, 2, v + 5);
|
|
1734
|
+
const a = i.measureText(w.appearance.label), y = a.width + 6, S = a.actualBoundingBoxAscent + a.actualBoundingBoxDescent + 8, L = a.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1735
|
+
return i.fillRect(p - 2, d - 2.5 - S, y, S), i.fillStyle = "#fff", i.fillText(w.appearance.label, p + 1, d - L), {
|
|
1736
|
+
fill: w.appearance.color,
|
|
1737
1737
|
fillOpacity: f ? 0.45 : 0.18
|
|
1738
1738
|
};
|
|
1739
1739
|
}
|
|
@@ -1751,7 +1751,7 @@ const Cn = (t, e) => {
|
|
|
1751
1751
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Wt(t.parentElement);
|
|
1752
1752
|
}, Rn = (t, e) => (n) => {
|
|
1753
1753
|
const o = typeof n == "string" ? n : n.id, i = (c) => {
|
|
1754
|
-
const s = r.getBoundingClientRect(), u = r.clientHeight, h = r.clientWidth, m = c.selector[0].range.getBoundingClientRect(), { width: l, height: g } = e.getAnnotationBounds(o), f = m.top - s.top,
|
|
1754
|
+
const s = r.getBoundingClientRect(), u = r.clientHeight, h = r.clientWidth, m = c.selector[0].range.getBoundingClientRect(), { width: l, height: g } = e.getAnnotationBounds(o), f = m.top - s.top, w = m.left - s.left, v = r.parentElement ? r.scrollTop : 0, p = r.parentElement ? r.scrollLeft : 0, d = f + v - (u - g) / 2, a = w + p - (h - l) / 2;
|
|
1755
1755
|
r.scroll({ top: d, left: a, behavior: "smooth" });
|
|
1756
1756
|
}, r = Wt(t);
|
|
1757
1757
|
if (r) {
|
|
@@ -1785,7 +1785,7 @@ const Cn = (t, e) => {
|
|
|
1785
1785
|
} : m = void 0;
|
|
1786
1786
|
};
|
|
1787
1787
|
n && t.addEventListener("selectstart", f);
|
|
1788
|
-
const
|
|
1788
|
+
const w = bt((a) => {
|
|
1789
1789
|
var B, M;
|
|
1790
1790
|
const y = document.getSelection();
|
|
1791
1791
|
if (!!((M = (B = y.anchorNode) == null ? void 0 : B.parentElement) != null && M.closest(D))) {
|
|
@@ -1796,9 +1796,9 @@ const Cn = (t, e) => {
|
|
|
1796
1796
|
const L = y.getRangeAt(0);
|
|
1797
1797
|
if (re(L)) return;
|
|
1798
1798
|
const E = Zt(L.cloneRange());
|
|
1799
|
-
(E.length !== m.selector.length || E.some((b,
|
|
1799
|
+
(E.length !== m.selector.length || E.some((b, x) => {
|
|
1800
1800
|
var A;
|
|
1801
|
-
return b.toString() !== ((A = m.selector[
|
|
1801
|
+
return b.toString() !== ((A = m.selector[x]) == null ? void 0 : A.quote);
|
|
1802
1802
|
})) && (m = {
|
|
1803
1803
|
...m,
|
|
1804
1804
|
selector: E.map((b) => le(b, t, o)),
|
|
@@ -1809,7 +1809,7 @@ const Cn = (t, e) => {
|
|
|
1809
1809
|
target: m
|
|
1810
1810
|
}), h.clickSelect(m.annotation, g)));
|
|
1811
1811
|
});
|
|
1812
|
-
n && document.addEventListener("selectionchange",
|
|
1812
|
+
n && document.addEventListener("selectionchange", w);
|
|
1813
1813
|
const v = (a) => {
|
|
1814
1814
|
const { target: y, timeStamp: S, offsetX: L, offsetY: E, type: T } = a;
|
|
1815
1815
|
g = { ...a, target: y, timeStamp: S, offsetX: L, offsetY: E, type: T }, l = a.button === 0;
|
|
@@ -1830,7 +1830,7 @@ const Cn = (t, e) => {
|
|
|
1830
1830
|
};
|
|
1831
1831
|
return document.addEventListener("pointerup", p), {
|
|
1832
1832
|
destroy: () => {
|
|
1833
|
-
t.removeEventListener("selectstart", f), document.removeEventListener("selectionchange",
|
|
1833
|
+
t.removeEventListener("selectstart", f), document.removeEventListener("selectionchange", w), t.removeEventListener("pointerdown", v), document.removeEventListener("pointerup", p);
|
|
1834
1834
|
},
|
|
1835
1835
|
setFilter: s,
|
|
1836
1836
|
setUser: r
|