@soomo/text-annotator 3.0.0-staging.17 → 3.0.0-staging.18
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.
|
@@ -92,9 +92,9 @@ const P = {
|
|
|
92
92
|
const p = m(c), g = document.createRange();
|
|
93
93
|
g.selectNode(i), g.setEnd(i, r);
|
|
94
94
|
const y = m(g), h = Zt(t).reverse().map((d) => {
|
|
95
|
-
var
|
|
95
|
+
var b;
|
|
96
96
|
const l = document.createElement("SPAN");
|
|
97
|
-
return (
|
|
97
|
+
return (b = d.parentNode) == null || b.insertBefore(l, d), l.appendChild(d), l;
|
|
98
98
|
});
|
|
99
99
|
return { unwrap: f, nodes: [p, ...h, y] };
|
|
100
100
|
}
|
|
@@ -234,13 +234,13 @@ const P = {
|
|
|
234
234
|
const { store: i, selection: r, hover: a } = e;
|
|
235
235
|
let s, u, f;
|
|
236
236
|
const m = ce(n), c = (T) => {
|
|
237
|
-
const { x: I, y:
|
|
237
|
+
const { x: I, y: v } = t.getBoundingClientRect(), x = i.getAt(T.clientX - I, T.clientY - v);
|
|
238
238
|
x && (!u || u(x)) ? a.current !== x.id && (t.classList.add("hovered"), a.set(x.id)) : a.current && (t.classList.remove("hovered"), a.set(null));
|
|
239
239
|
};
|
|
240
240
|
t.addEventListener("pointermove", c);
|
|
241
241
|
const p = (T = !1) => {
|
|
242
242
|
f && f.clear();
|
|
243
|
-
const I = ae(t), { minX:
|
|
243
|
+
const I = ae(t), { minX: v, minY: x, maxX: A, maxY: E } = I, R = u ? i.getIntersecting(v, x, A, E).filter(({ annotation: D }) => u(D)) : i.getIntersecting(v, x, A, E), O = r.selected.map(({ id: D }) => D), H = R.map(({ annotation: D, rects: zt }) => {
|
|
244
244
|
const Ft = O.includes(D.id), Wt = D.id === a.current;
|
|
245
245
|
return { annotation: D, rects: zt, state: { selected: Ft, hover: Wt } };
|
|
246
246
|
});
|
|
@@ -249,28 +249,28 @@ const P = {
|
|
|
249
249
|
f = T, p();
|
|
250
250
|
}, y = (T) => {
|
|
251
251
|
s = T, p();
|
|
252
|
-
},
|
|
252
|
+
}, w = (T) => {
|
|
253
253
|
u = T, p(!1);
|
|
254
254
|
}, h = () => p();
|
|
255
255
|
i.observe(h);
|
|
256
256
|
const d = r.subscribe(() => p()), l = () => p(!0);
|
|
257
257
|
document.addEventListener("scroll", l, { capture: !0, passive: !0 });
|
|
258
|
-
const
|
|
258
|
+
const b = pt(() => {
|
|
259
259
|
i.recalculatePositions(), f && f.reset(), p();
|
|
260
260
|
});
|
|
261
|
-
window.addEventListener("resize",
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
const L = { attributes: !0, childList: !0, subtree: !0 },
|
|
265
|
-
T.every((
|
|
261
|
+
window.addEventListener("resize", b);
|
|
262
|
+
const S = new ResizeObserver(b);
|
|
263
|
+
S.observe(t);
|
|
264
|
+
const L = { attributes: !0, childList: !0, subtree: !0 }, C = new MutationObserver((T) => {
|
|
265
|
+
T.every((v) => v.target === t || t.contains(v.target)) || p(!0);
|
|
266
266
|
});
|
|
267
|
-
return
|
|
267
|
+
return C.observe(document.body, L), {
|
|
268
268
|
destroy: () => {
|
|
269
|
-
t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", l), window.removeEventListener("resize",
|
|
269
|
+
t.removeEventListener("pointermove", c), o.destroy(), i.unobserve(h), d(), document.removeEventListener("scroll", l), window.removeEventListener("resize", b), S.disconnect(), C.disconnect();
|
|
270
270
|
},
|
|
271
271
|
redraw: p,
|
|
272
272
|
setStyle: y,
|
|
273
|
-
setFilter:
|
|
273
|
+
setFilter: w,
|
|
274
274
|
setPainter: g,
|
|
275
275
|
setVisible: o.setVisible
|
|
276
276
|
};
|
|
@@ -288,30 +288,30 @@ const P = {
|
|
|
288
288
|
n.clearRect(-0.5, -0.5, c + 1, p + 1), m && m.clear();
|
|
289
289
|
const { top: g, left: y } = u;
|
|
290
290
|
[...s].sort((h, d) => {
|
|
291
|
-
const { annotation: { target: { created: l } } } = h, { annotation: { target: { created:
|
|
292
|
-
return l.getTime() -
|
|
291
|
+
const { annotation: { target: { created: l } } } = h, { annotation: { target: { created: b } } } = d;
|
|
292
|
+
return l.getTime() - b.getTime();
|
|
293
293
|
}).forEach((h) => {
|
|
294
294
|
var L;
|
|
295
|
-
const d = f ? typeof f == "function" ? f(h.annotation, h.state) : f : (L = h.state) != null && L.selected ? ot : P, l = m && m.paint(h, u) || d,
|
|
296
|
-
x:
|
|
295
|
+
const d = f ? typeof f == "function" ? f(h.annotation, h.state) : f : (L = h.state) != null && L.selected ? ot : P, l = m && m.paint(h, u) || d, b = h.rects.map(({ x: C, y: B, width: T, height: I }) => ({
|
|
296
|
+
x: C + y,
|
|
297
297
|
y: B + g,
|
|
298
298
|
width: T,
|
|
299
299
|
height: I
|
|
300
300
|
}));
|
|
301
301
|
n.fillStyle = l.fill, n.globalAlpha = l.fillOpacity || 1;
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
304
|
-
({ x:
|
|
305
|
-
|
|
306
|
-
B -
|
|
302
|
+
const S = 5;
|
|
303
|
+
if (b.forEach(
|
|
304
|
+
({ x: C, y: B, width: T, height: I }) => n.fillRect(
|
|
305
|
+
C,
|
|
306
|
+
B - S / 2,
|
|
307
307
|
T,
|
|
308
|
-
I +
|
|
308
|
+
I + S
|
|
309
309
|
)
|
|
310
310
|
), l.underlineColor) {
|
|
311
311
|
n.globalAlpha = 1, n.strokeStyle = l.underlineColor, n.lineWidth = l.underlineThickness ?? 1;
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
n.beginPath(), n.moveTo(B, T +
|
|
312
|
+
const C = S / 2 + (l.underlineOffset ?? 0);
|
|
313
|
+
b.forEach(({ x: B, y: T, width: I, height: v }) => {
|
|
314
|
+
n.beginPath(), n.moveTo(B, T + v + C), n.lineTo(B + I, T + v + C), n.stroke();
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
317
|
});
|
|
@@ -539,15 +539,15 @@ const Ee = (t, e) => {
|
|
|
539
539
|
if (!f && !p)
|
|
540
540
|
return;
|
|
541
541
|
p && (e.innerHTML = "");
|
|
542
|
-
const g = a.reduce((y, { rects:
|
|
542
|
+
const g = a.reduce((y, { rects: w }) => [...y, ...w], []);
|
|
543
543
|
a.forEach((y) => {
|
|
544
|
-
y.rects.map((
|
|
545
|
-
const h = Ee(
|
|
544
|
+
y.rects.map((w) => {
|
|
545
|
+
const h = Ee(w, g), d = qt(y, s, u, f, h);
|
|
546
546
|
if (p) {
|
|
547
547
|
const l = document.createElement("span");
|
|
548
|
-
l.className = "r6o-annotation", l.dataset.annotation = y.annotation.id, l.style.left = `${
|
|
549
|
-
const
|
|
550
|
-
l.style.backgroundColor =
|
|
548
|
+
l.className = "r6o-annotation", l.dataset.annotation = y.annotation.id, l.style.left = `${w.x}px`, l.style.top = `${w.y}px`, l.style.width = `${w.width}px`, l.style.height = `${w.height}px`;
|
|
549
|
+
const b = Y((d == null ? void 0 : d.fill) || P.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? P.fillOpacity : d.fillOpacity).toHex();
|
|
550
|
+
l.style.backgroundColor = b, d.underlineStyle && (l.style.borderStyle = d.underlineStyle), d.underlineColor && (l.style.borderColor = d.underlineColor), d.underlineThickness && (l.style.borderBottomWidth = `${d.underlineThickness}px`), d.underlineOffset && (l.style.paddingBottom = `${d.underlineOffset}px`), e.appendChild(l);
|
|
551
551
|
}
|
|
552
552
|
});
|
|
553
553
|
}), n = a;
|
|
@@ -676,8 +676,8 @@ const dt = { selected: [] }, Me = (t, e = "EDIT") => {
|
|
|
676
676
|
} else
|
|
677
677
|
console.warn("Invalid selection: " + c);
|
|
678
678
|
}, f = (c, p = !0) => {
|
|
679
|
-
const g = Array.isArray(c) ? c : [c], y = g.map((
|
|
680
|
-
o({ selected: y.map(({ id:
|
|
679
|
+
const g = Array.isArray(c) ? c : [c], y = g.map((w) => t.getAnnotation(w)).filter(Boolean);
|
|
680
|
+
o({ selected: y.map(({ id: w }) => ({ id: w, editable: p })) }), y.length !== g.length && console.warn("Invalid selection", c);
|
|
681
681
|
}, m = (c) => {
|
|
682
682
|
if (i.selected.length === 0)
|
|
683
683
|
return !1;
|
|
@@ -782,7 +782,7 @@ const ze = (t, e) => {
|
|
|
782
782
|
...(t.updated || []).filter(({ newValue: c }) => !r.has(c.id)).map((c) => {
|
|
783
783
|
const { oldValue: p, newValue: g } = c;
|
|
784
784
|
if (a.has(g.id)) {
|
|
785
|
-
const y = e.updated.find((
|
|
785
|
+
const y = e.updated.find((w) => w.oldValue.id === g.id).newValue;
|
|
786
786
|
return Xt(p, y);
|
|
787
787
|
} else
|
|
788
788
|
return c;
|
|
@@ -791,12 +791,12 @@ const ze = (t, e) => {
|
|
|
791
791
|
];
|
|
792
792
|
return { created: u, deleted: f, updated: m };
|
|
793
793
|
}, We = (t) => t.id !== void 0, qe = () => {
|
|
794
|
-
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (
|
|
795
|
-
const x = n.findIndex((A) => A.onChange ==
|
|
794
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map(), n = [], o = (v, x = {}) => n.push({ onChange: v, options: x }), i = (v) => {
|
|
795
|
+
const x = n.findIndex((A) => A.onChange == v);
|
|
796
796
|
x > -1 && n.splice(x, 1);
|
|
797
|
-
}, r = (
|
|
797
|
+
}, r = (v, x) => {
|
|
798
798
|
const A = {
|
|
799
|
-
origin:
|
|
799
|
+
origin: v,
|
|
800
800
|
changes: {
|
|
801
801
|
created: x.created || [],
|
|
802
802
|
updated: x.updated || [],
|
|
@@ -804,144 +804,144 @@ const ze = (t, e) => {
|
|
|
804
804
|
},
|
|
805
805
|
state: [...t.values()]
|
|
806
806
|
};
|
|
807
|
-
n.forEach((
|
|
808
|
-
ze(
|
|
807
|
+
n.forEach((E) => {
|
|
808
|
+
ze(E, A) && E.onChange(A);
|
|
809
809
|
});
|
|
810
|
-
}, a = (
|
|
811
|
-
if (t.get(
|
|
812
|
-
throw Error(`Cannot add annotation ${
|
|
813
|
-
t.set(
|
|
814
|
-
}, s = (
|
|
815
|
-
const A = typeof
|
|
810
|
+
}, a = (v, x = N.LOCAL) => {
|
|
811
|
+
if (t.get(v.id))
|
|
812
|
+
throw Error(`Cannot add annotation ${v.id} - exists already`);
|
|
813
|
+
t.set(v.id, v), v.bodies.forEach((A) => e.set(A.id, v.id)), r(x, { created: [v] });
|
|
814
|
+
}, s = (v, x) => {
|
|
815
|
+
const A = typeof v == "string" ? x : v, E = typeof v == "string" ? v : v.id, R = t.get(E);
|
|
816
816
|
if (R) {
|
|
817
817
|
const O = Xt(R, A);
|
|
818
|
-
return
|
|
818
|
+
return E === A.id ? t.set(E, A) : (t.delete(E), t.set(A.id, A)), R.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), O;
|
|
819
819
|
} else
|
|
820
|
-
console.warn(`Cannot update annotation ${
|
|
821
|
-
}, u = (
|
|
822
|
-
const
|
|
823
|
-
R && r(
|
|
824
|
-
}, f = (
|
|
825
|
-
const A =
|
|
820
|
+
console.warn(`Cannot update annotation ${E} - does not exist`);
|
|
821
|
+
}, u = (v, x = N.LOCAL, A = N.LOCAL) => {
|
|
822
|
+
const E = We(x) ? A : x, R = s(v, x);
|
|
823
|
+
R && r(E, { updated: [R] });
|
|
824
|
+
}, f = (v, x = N.LOCAL) => {
|
|
825
|
+
const A = v.reduce((E, R) => {
|
|
826
826
|
const O = s(R);
|
|
827
|
-
return O ? [...
|
|
827
|
+
return O ? [...E, O] : E;
|
|
828
828
|
}, []);
|
|
829
829
|
A.length > 0 && r(x, { updated: A });
|
|
830
|
-
}, m = (
|
|
831
|
-
const A = t.get(
|
|
830
|
+
}, m = (v, x = N.LOCAL) => {
|
|
831
|
+
const A = t.get(v.annotation);
|
|
832
832
|
if (A) {
|
|
833
|
-
const
|
|
833
|
+
const E = {
|
|
834
834
|
...A,
|
|
835
|
-
bodies: [...A.bodies,
|
|
835
|
+
bodies: [...A.bodies, v]
|
|
836
836
|
};
|
|
837
|
-
t.set(A.id,
|
|
837
|
+
t.set(A.id, E), e.set(v.id, E.id), r(x, { updated: [{
|
|
838
838
|
oldValue: A,
|
|
839
|
-
newValue:
|
|
840
|
-
bodiesCreated: [
|
|
839
|
+
newValue: E,
|
|
840
|
+
bodiesCreated: [v]
|
|
841
841
|
}] });
|
|
842
842
|
} else
|
|
843
|
-
console.warn(`Attempt to add body to missing annotation: ${
|
|
844
|
-
}, c = () => [...t.values()], p = (
|
|
843
|
+
console.warn(`Attempt to add body to missing annotation: ${v.annotation}`);
|
|
844
|
+
}, c = () => [...t.values()], p = (v = N.LOCAL) => {
|
|
845
845
|
const x = [...t.values()];
|
|
846
|
-
t.clear(), e.clear(), r(
|
|
847
|
-
}, g = (
|
|
846
|
+
t.clear(), e.clear(), r(v, { deleted: x });
|
|
847
|
+
}, g = (v, x = !0, A = N.LOCAL) => {
|
|
848
848
|
if (x) {
|
|
849
|
-
const
|
|
850
|
-
t.clear(), e.clear(),
|
|
849
|
+
const E = [...t.values()];
|
|
850
|
+
t.clear(), e.clear(), v.forEach((R) => {
|
|
851
851
|
t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
|
|
852
|
-
}), r(A, { created:
|
|
852
|
+
}), r(A, { created: v, deleted: E });
|
|
853
853
|
} else {
|
|
854
|
-
const
|
|
854
|
+
const E = v.reduce((R, O) => {
|
|
855
855
|
const H = t.get(O.id);
|
|
856
856
|
return H ? [...R, H] : R;
|
|
857
857
|
}, []);
|
|
858
|
-
if (
|
|
859
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${
|
|
860
|
-
|
|
858
|
+
if (E.length > 0)
|
|
859
|
+
throw Error(`Bulk insert would overwrite the following annotations: ${E.map((R) => R.id).join(", ")}`);
|
|
860
|
+
v.forEach((R) => {
|
|
861
861
|
t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
|
|
862
|
-
}), r(A, { created:
|
|
862
|
+
}), r(A, { created: v });
|
|
863
863
|
}
|
|
864
|
-
}, y = (
|
|
865
|
-
const x = typeof
|
|
864
|
+
}, y = (v) => {
|
|
865
|
+
const x = typeof v == "string" ? v : v.id, A = t.get(x);
|
|
866
866
|
if (A)
|
|
867
|
-
return t.delete(x), A.bodies.forEach((
|
|
867
|
+
return t.delete(x), A.bodies.forEach((E) => e.delete(E.id)), A;
|
|
868
868
|
console.warn(`Attempt to delete missing annotation: ${x}`);
|
|
869
|
-
},
|
|
870
|
-
const A = y(
|
|
869
|
+
}, w = (v, x = N.LOCAL) => {
|
|
870
|
+
const A = y(v);
|
|
871
871
|
A && r(x, { deleted: [A] });
|
|
872
|
-
}, h = (
|
|
873
|
-
const A =
|
|
872
|
+
}, h = (v, x = N.LOCAL) => {
|
|
873
|
+
const A = v.reduce((E, R) => {
|
|
874
874
|
const O = y(R);
|
|
875
|
-
return O ? [...
|
|
875
|
+
return O ? [...E, O] : E;
|
|
876
876
|
}, []);
|
|
877
877
|
A.length > 0 && r(x, { deleted: A });
|
|
878
|
-
}, d = (
|
|
879
|
-
const x = t.get(
|
|
878
|
+
}, d = (v) => {
|
|
879
|
+
const x = t.get(v.annotation);
|
|
880
880
|
if (x) {
|
|
881
|
-
const A = x.bodies.find((
|
|
881
|
+
const A = x.bodies.find((E) => E.id === v.id);
|
|
882
882
|
if (A) {
|
|
883
883
|
e.delete(A.id);
|
|
884
|
-
const
|
|
884
|
+
const E = {
|
|
885
885
|
...x,
|
|
886
|
-
bodies: x.bodies.filter((R) => R.id !==
|
|
886
|
+
bodies: x.bodies.filter((R) => R.id !== v.id)
|
|
887
887
|
};
|
|
888
|
-
return t.set(x.id,
|
|
888
|
+
return t.set(x.id, E), {
|
|
889
889
|
oldValue: x,
|
|
890
|
-
newValue:
|
|
890
|
+
newValue: E,
|
|
891
891
|
bodiesDeleted: [A]
|
|
892
892
|
};
|
|
893
893
|
} else
|
|
894
|
-
console.warn(`Attempt to delete missing body ${
|
|
894
|
+
console.warn(`Attempt to delete missing body ${v.id} from annotation ${v.annotation}`);
|
|
895
895
|
} else
|
|
896
|
-
console.warn(`Attempt to delete body from missing annotation ${
|
|
897
|
-
}, l = (
|
|
898
|
-
const A = d(
|
|
896
|
+
console.warn(`Attempt to delete body from missing annotation ${v.annotation}`);
|
|
897
|
+
}, l = (v, x = N.LOCAL) => {
|
|
898
|
+
const A = d(v);
|
|
899
899
|
A && r(x, { updated: [A] });
|
|
900
|
-
},
|
|
901
|
-
const A =
|
|
900
|
+
}, b = (v, x = N.LOCAL) => {
|
|
901
|
+
const A = v.map((E) => d(E)).filter(Boolean);
|
|
902
902
|
A.length > 0 && r(x, { updated: A });
|
|
903
|
-
},
|
|
904
|
-
const x = t.get(
|
|
903
|
+
}, S = (v) => {
|
|
904
|
+
const x = t.get(v);
|
|
905
905
|
return x ? { ...x } : void 0;
|
|
906
|
-
}, L = (
|
|
907
|
-
const x = e.get(
|
|
906
|
+
}, L = (v) => {
|
|
907
|
+
const x = e.get(v);
|
|
908
908
|
if (x) {
|
|
909
|
-
const A =
|
|
909
|
+
const A = S(x).bodies.find((E) => E.id === v);
|
|
910
910
|
if (A)
|
|
911
911
|
return A;
|
|
912
|
-
console.error(`Store integrity error: body ${
|
|
912
|
+
console.error(`Store integrity error: body ${v} in index, but not in annotation`);
|
|
913
913
|
} else
|
|
914
|
-
console.warn(`Attempt to retrieve missing body: ${
|
|
915
|
-
},
|
|
916
|
-
if (
|
|
914
|
+
console.warn(`Attempt to retrieve missing body: ${v}`);
|
|
915
|
+
}, C = (v, x) => {
|
|
916
|
+
if (v.annotation !== x.annotation)
|
|
917
917
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
918
|
-
const A = t.get(
|
|
918
|
+
const A = t.get(v.annotation);
|
|
919
919
|
if (A) {
|
|
920
|
-
const
|
|
920
|
+
const E = A.bodies.find((O) => O.id === v.id), R = {
|
|
921
921
|
...A,
|
|
922
|
-
bodies: A.bodies.map((O) => O.id ===
|
|
922
|
+
bodies: A.bodies.map((O) => O.id === E.id ? x : O)
|
|
923
923
|
};
|
|
924
|
-
return t.set(A.id, R),
|
|
924
|
+
return t.set(A.id, R), E.id !== x.id && (e.delete(E.id), e.set(x.id, R.id)), {
|
|
925
925
|
oldValue: A,
|
|
926
926
|
newValue: R,
|
|
927
|
-
bodiesUpdated: [{ oldBody:
|
|
927
|
+
bodiesUpdated: [{ oldBody: E, newBody: x }]
|
|
928
928
|
};
|
|
929
929
|
} else
|
|
930
|
-
console.warn(`Attempt to add body to missing annotation ${
|
|
931
|
-
}, B = (
|
|
932
|
-
const
|
|
933
|
-
|
|
934
|
-
}, T = (
|
|
935
|
-
const A =
|
|
930
|
+
console.warn(`Attempt to add body to missing annotation ${v.annotation}`);
|
|
931
|
+
}, B = (v, x, A = N.LOCAL) => {
|
|
932
|
+
const E = C(v, x);
|
|
933
|
+
E && r(A, { updated: [E] });
|
|
934
|
+
}, T = (v, x = N.LOCAL) => {
|
|
935
|
+
const A = v.map((E) => C({ id: E.id, annotation: E.annotation }, E)).filter(Boolean);
|
|
936
936
|
r(x, { updated: A });
|
|
937
|
-
}, I = (
|
|
938
|
-
const x = t.get(
|
|
937
|
+
}, I = (v) => {
|
|
938
|
+
const x = t.get(v.annotation);
|
|
939
939
|
if (x) {
|
|
940
940
|
const A = {
|
|
941
941
|
...x,
|
|
942
942
|
target: {
|
|
943
943
|
...x.target,
|
|
944
|
-
...
|
|
944
|
+
...v
|
|
945
945
|
}
|
|
946
946
|
};
|
|
947
947
|
return t.set(x.id, A), {
|
|
@@ -949,11 +949,11 @@ const ze = (t, e) => {
|
|
|
949
949
|
newValue: A,
|
|
950
950
|
targetUpdated: {
|
|
951
951
|
oldTarget: x.target,
|
|
952
|
-
newTarget:
|
|
952
|
+
newTarget: v
|
|
953
953
|
}
|
|
954
954
|
};
|
|
955
955
|
} else
|
|
956
|
-
console.warn(`Attempt to update target on missing annotation: ${
|
|
956
|
+
console.warn(`Attempt to update target on missing annotation: ${v.annotation}`);
|
|
957
957
|
};
|
|
958
958
|
return {
|
|
959
959
|
addAnnotation: a,
|
|
@@ -961,24 +961,24 @@ const ze = (t, e) => {
|
|
|
961
961
|
all: c,
|
|
962
962
|
bulkAddAnnotation: g,
|
|
963
963
|
bulkDeleteAnnotation: h,
|
|
964
|
-
bulkDeleteBodies:
|
|
964
|
+
bulkDeleteBodies: b,
|
|
965
965
|
bulkUpdateAnnotation: f,
|
|
966
966
|
bulkUpdateBodies: T,
|
|
967
|
-
bulkUpdateTargets: (
|
|
968
|
-
const A =
|
|
967
|
+
bulkUpdateTargets: (v, x = N.LOCAL) => {
|
|
968
|
+
const A = v.map((E) => I(E)).filter(Boolean);
|
|
969
969
|
A.length > 0 && r(x, { updated: A });
|
|
970
970
|
},
|
|
971
971
|
clear: p,
|
|
972
|
-
deleteAnnotation:
|
|
972
|
+
deleteAnnotation: w,
|
|
973
973
|
deleteBody: l,
|
|
974
|
-
getAnnotation:
|
|
974
|
+
getAnnotation: S,
|
|
975
975
|
getBody: L,
|
|
976
976
|
observe: o,
|
|
977
977
|
unobserve: i,
|
|
978
978
|
updateAnnotation: u,
|
|
979
979
|
updateBody: B,
|
|
980
|
-
updateTarget: (
|
|
981
|
-
const A = I(
|
|
980
|
+
updateTarget: (v, x = N.LOCAL) => {
|
|
981
|
+
const A = I(v);
|
|
982
982
|
A && r(x, { updated: [A] });
|
|
983
983
|
}
|
|
984
984
|
};
|
|
@@ -1002,14 +1002,14 @@ const Ge = 250, Ke = (t) => {
|
|
|
1002
1002
|
let o = -1, i = !1, r = 0;
|
|
1003
1003
|
const a = (g) => {
|
|
1004
1004
|
if (!i) {
|
|
1005
|
-
const { changes: y } = g,
|
|
1006
|
-
if (
|
|
1005
|
+
const { changes: y } = g, w = performance.now();
|
|
1006
|
+
if (w - r > Ge)
|
|
1007
1007
|
n.splice(o + 1), n.push(y), o = n.length - 1;
|
|
1008
1008
|
else {
|
|
1009
1009
|
const h = n.length - 1;
|
|
1010
1010
|
n[h] = Fe(n[h], y);
|
|
1011
1011
|
}
|
|
1012
|
-
r =
|
|
1012
|
+
r = w;
|
|
1013
1013
|
}
|
|
1014
1014
|
i = !1;
|
|
1015
1015
|
};
|
|
@@ -1023,15 +1023,15 @@ const Ge = 250, Ke = (t) => {
|
|
|
1023
1023
|
redo: () => {
|
|
1024
1024
|
if (n.length - 1 > o) {
|
|
1025
1025
|
i = !0;
|
|
1026
|
-
const { created: g, updated: y, deleted:
|
|
1027
|
-
u(g), m(y), p(
|
|
1026
|
+
const { created: g, updated: y, deleted: w } = n[o + 1];
|
|
1027
|
+
u(g), m(y), p(w), e.emit("redo", n[o + 1]), o += 1;
|
|
1028
1028
|
}
|
|
1029
1029
|
},
|
|
1030
1030
|
undo: () => {
|
|
1031
1031
|
if (o > -1) {
|
|
1032
1032
|
i = !0;
|
|
1033
|
-
const { created: g, updated: y, deleted:
|
|
1034
|
-
s(g), f(y), c(
|
|
1033
|
+
const { created: g, updated: y, deleted: w } = n[o];
|
|
1034
|
+
s(g), f(y), c(w), e.emit("undo", n[o]), o -= 1;
|
|
1035
1035
|
}
|
|
1036
1036
|
}
|
|
1037
1037
|
};
|
|
@@ -1044,66 +1044,66 @@ const Ge = 250, Ke = (t) => {
|
|
|
1044
1044
|
}, Je = (t, e, n, o) => {
|
|
1045
1045
|
const { store: i, selection: r, hover: a, viewport: s } = t, u = /* @__PURE__ */ new Map();
|
|
1046
1046
|
let f = [], m;
|
|
1047
|
-
const c = (
|
|
1048
|
-
u.has(
|
|
1049
|
-
}, p = (
|
|
1050
|
-
const d = u.get(
|
|
1047
|
+
const c = (w, h) => {
|
|
1048
|
+
u.has(w) ? u.get(w).push(h) : u.set(w, [h]);
|
|
1049
|
+
}, p = (w, h) => {
|
|
1050
|
+
const d = u.get(w);
|
|
1051
1051
|
d && d.indexOf(h) > 0 && d.splice(d.indexOf(h), 1);
|
|
1052
|
-
}, g = (
|
|
1053
|
-
u.has(
|
|
1054
|
-
u.get(
|
|
1052
|
+
}, g = (w, h, d) => {
|
|
1053
|
+
u.has(w) && setTimeout(() => {
|
|
1054
|
+
u.get(w).forEach((l) => {
|
|
1055
1055
|
if (n) {
|
|
1056
|
-
const
|
|
1057
|
-
l(
|
|
1056
|
+
const b = Array.isArray(h) ? h.map((L) => n.serialize(L)) : n.serialize(h), S = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
|
|
1057
|
+
l(b, S);
|
|
1058
1058
|
} else
|
|
1059
1059
|
l(h, d);
|
|
1060
1060
|
});
|
|
1061
1061
|
}, 1);
|
|
1062
1062
|
};
|
|
1063
|
-
r.subscribe(({ selected:
|
|
1064
|
-
if (!(f.length === 0 &&
|
|
1065
|
-
if (f.length === 0 &&
|
|
1066
|
-
f =
|
|
1067
|
-
else if (f.length > 0 &&
|
|
1063
|
+
r.subscribe(({ selected: w }) => {
|
|
1064
|
+
if (!(f.length === 0 && w.length === 0)) {
|
|
1065
|
+
if (f.length === 0 && w.length > 0)
|
|
1066
|
+
f = w.map(({ id: h }) => i.getAnnotation(h));
|
|
1067
|
+
else if (f.length > 0 && w.length === 0)
|
|
1068
1068
|
f.forEach((h) => {
|
|
1069
1069
|
const d = i.getAnnotation(h.id);
|
|
1070
1070
|
d && !q(d, h) && g("updateAnnotation", d, h);
|
|
1071
1071
|
}), f = [];
|
|
1072
1072
|
else {
|
|
1073
|
-
const h = new Set(f.map((l) => l.id)), d = new Set(
|
|
1073
|
+
const h = new Set(f.map((l) => l.id)), d = new Set(w.map(({ id: l }) => l));
|
|
1074
1074
|
f.filter((l) => !d.has(l.id)).forEach((l) => {
|
|
1075
|
-
const
|
|
1076
|
-
|
|
1075
|
+
const b = i.getAnnotation(l.id);
|
|
1076
|
+
b && !q(b, l) && g("updateAnnotation", b, l);
|
|
1077
1077
|
}), f = [
|
|
1078
1078
|
// Remove annotations that were deselected
|
|
1079
1079
|
...f.filter((l) => d.has(l.id)),
|
|
1080
1080
|
// Add editable annotations that were selected
|
|
1081
|
-
...
|
|
1081
|
+
...w.filter(({ id: l }) => !h.has(l)).map(({ id: l }) => i.getAnnotation(l))
|
|
1082
1082
|
];
|
|
1083
1083
|
}
|
|
1084
1084
|
g("selectionChanged", f);
|
|
1085
1085
|
}
|
|
1086
|
-
}), a.subscribe((
|
|
1087
|
-
!m &&
|
|
1088
|
-
}), s == null || s.subscribe((
|
|
1089
|
-
const { created: h, deleted: d } =
|
|
1090
|
-
(h || []).forEach((l) => g("createAnnotation", l)), (d || []).forEach((l) => g("deleteAnnotation", l)), (
|
|
1086
|
+
}), a.subscribe((w) => {
|
|
1087
|
+
!m && w ? g("mouseEnterAnnotation", i.getAnnotation(w)) : m && !w ? g("mouseLeaveAnnotation", i.getAnnotation(m)) : m && w && (g("mouseLeaveAnnotation", i.getAnnotation(m)), g("mouseEnterAnnotation", i.getAnnotation(w))), m = w;
|
|
1088
|
+
}), s == null || s.subscribe((w) => g("viewportIntersect", w.map((h) => i.getAnnotation(h)))), i.observe((w) => {
|
|
1089
|
+
const { created: h, deleted: d } = w.changes;
|
|
1090
|
+
(h || []).forEach((l) => g("createAnnotation", l)), (d || []).forEach((l) => g("deleteAnnotation", l)), (w.changes.updated || []).filter((l) => [
|
|
1091
1091
|
...l.bodiesCreated || [],
|
|
1092
1092
|
...l.bodiesDeleted || [],
|
|
1093
1093
|
...l.bodiesUpdated || []
|
|
1094
|
-
].length > 0).forEach(({ oldValue: l, newValue:
|
|
1095
|
-
const
|
|
1096
|
-
f = f.map((L) => L.id === l.id ?
|
|
1094
|
+
].length > 0).forEach(({ oldValue: l, newValue: b }) => {
|
|
1095
|
+
const S = f.find((L) => L.id === l.id) || l;
|
|
1096
|
+
f = f.map((L) => L.id === l.id ? b : L), g("updateAnnotation", b, S);
|
|
1097
1097
|
});
|
|
1098
|
-
}, { origin: N.LOCAL }), i.observe((
|
|
1098
|
+
}, { origin: N.LOCAL }), i.observe((w) => {
|
|
1099
1099
|
if (f) {
|
|
1100
|
-
const h = new Set(f.map((l) => l.id)), d = (
|
|
1101
|
-
d.length > 0 && (f = f.map((l) => d.find((
|
|
1100
|
+
const h = new Set(f.map((l) => l.id)), d = (w.changes.updated || []).filter(({ newValue: l }) => h.has(l.id)).map(({ newValue: l }) => l);
|
|
1101
|
+
d.length > 0 && (f = f.map((l) => d.find((S) => S.id === l.id) || l));
|
|
1102
1102
|
}
|
|
1103
1103
|
}, { origin: N.REMOTE });
|
|
1104
|
-
const y = (
|
|
1104
|
+
const y = (w) => (h) => {
|
|
1105
1105
|
const { updated: d } = h;
|
|
1106
|
-
|
|
1106
|
+
w ? (d || []).forEach((l) => g("updateAnnotation", l.oldValue, l.newValue)) : (d || []).forEach((l) => g("updateAnnotation", l.newValue, l.oldValue));
|
|
1107
1107
|
};
|
|
1108
1108
|
return e.on("undo", y(!0)), e.on("redo", y(!1)), { on: c, off: p, emit: g };
|
|
1109
1109
|
}, Ze = (t) => (e) => e.reduce((n, o) => {
|
|
@@ -1143,13 +1143,13 @@ const Ge = 250, Ke = (t) => {
|
|
|
1143
1143
|
}
|
|
1144
1144
|
}, g = (h, d = !0) => {
|
|
1145
1145
|
if (n) {
|
|
1146
|
-
const { parsed: l, failed:
|
|
1147
|
-
|
|
1146
|
+
const { parsed: l, failed: b } = Ze(n)(h);
|
|
1147
|
+
b.length > 0 && console.warn(`Discarded ${b.length} invalid annotations`, b), o.bulkAddAnnotation(l, d, N.REMOTE);
|
|
1148
1148
|
} else
|
|
1149
1149
|
o.bulkAddAnnotation(h, d, N.REMOTE);
|
|
1150
1150
|
}, y = (h) => {
|
|
1151
1151
|
h ? i.setSelected(h) : i.clear();
|
|
1152
|
-
},
|
|
1152
|
+
}, w = (h) => {
|
|
1153
1153
|
if (n) {
|
|
1154
1154
|
const d = n.parse(h).parsed, l = n.serialize(o.getAnnotation(d.id));
|
|
1155
1155
|
return o.updateAnnotation(d), l;
|
|
@@ -1173,7 +1173,7 @@ const Ge = 250, Ke = (t) => {
|
|
|
1173
1173
|
setAnnotations: g,
|
|
1174
1174
|
setSelected: y,
|
|
1175
1175
|
undo: e.undo,
|
|
1176
|
-
updateAnnotation:
|
|
1176
|
+
updateAnnotation: w
|
|
1177
1177
|
};
|
|
1178
1178
|
}, en = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
1179
1179
|
let nn = (t) => crypto.getRandomValues(new Uint8Array(t)), on = (t, e, n) => {
|
|
@@ -1292,7 +1292,7 @@ const Mn = (t, e) => ({
|
|
|
1292
1292
|
updated: f,
|
|
1293
1293
|
...m
|
|
1294
1294
|
} = i, c = a.map((p) => {
|
|
1295
|
-
const { quote: g, start: y, end:
|
|
1295
|
+
const { quote: g, start: y, end: w, range: h } = p, { prefix: d, suffix: l } = te(h, n), b = [{
|
|
1296
1296
|
type: "TextQuoteSelector",
|
|
1297
1297
|
exact: g,
|
|
1298
1298
|
prefix: d,
|
|
@@ -1300,13 +1300,13 @@ const Mn = (t, e) => ({
|
|
|
1300
1300
|
}, {
|
|
1301
1301
|
type: "TextPositionSelector",
|
|
1302
1302
|
start: y,
|
|
1303
|
-
end:
|
|
1303
|
+
end: w
|
|
1304
1304
|
}];
|
|
1305
1305
|
return {
|
|
1306
1306
|
...m,
|
|
1307
1307
|
id: p.id,
|
|
1308
1308
|
source: e,
|
|
1309
|
-
selector:
|
|
1309
|
+
selector: b
|
|
1310
1310
|
};
|
|
1311
1311
|
});
|
|
1312
1312
|
return {
|
|
@@ -1603,20 +1603,20 @@ function It(t, e, n, o, i) {
|
|
|
1603
1603
|
}
|
|
1604
1604
|
const En = (t, e) => {
|
|
1605
1605
|
const n = new bn(), o = /* @__PURE__ */ new Map(), i = (d, l) => {
|
|
1606
|
-
const
|
|
1607
|
-
const
|
|
1608
|
-
return Array.from(
|
|
1609
|
-
}),
|
|
1610
|
-
return
|
|
1611
|
-
const { x:
|
|
1606
|
+
const b = d.selector.flatMap((L) => {
|
|
1607
|
+
const C = $([L]) ? L.range : Ut(L, e).range;
|
|
1608
|
+
return Array.from(C.getClientRects());
|
|
1609
|
+
}), S = re(b).map(({ left: L, top: C, right: B, bottom: T }) => new DOMRect(L - l.left, C - l.top, B - L, T - C));
|
|
1610
|
+
return S.map((L) => {
|
|
1611
|
+
const { x: C, y: B, width: T, height: I } = L;
|
|
1612
1612
|
return {
|
|
1613
|
-
minX:
|
|
1613
|
+
minX: C,
|
|
1614
1614
|
minY: B,
|
|
1615
|
-
maxX:
|
|
1615
|
+
maxX: C + T,
|
|
1616
1616
|
maxY: B + I,
|
|
1617
1617
|
annotation: {
|
|
1618
1618
|
id: d.annotation,
|
|
1619
|
-
rects:
|
|
1619
|
+
rects: S
|
|
1620
1620
|
}
|
|
1621
1621
|
};
|
|
1622
1622
|
});
|
|
@@ -1624,37 +1624,37 @@ const En = (t, e) => {
|
|
|
1624
1624
|
n.clear(), o.clear();
|
|
1625
1625
|
}, s = (d) => {
|
|
1626
1626
|
const l = i(d, e.getBoundingClientRect());
|
|
1627
|
-
l.forEach((
|
|
1627
|
+
l.forEach((b) => n.insert(b)), o.set(d.annotation, l);
|
|
1628
1628
|
}, u = (d) => {
|
|
1629
1629
|
const l = o.get(d.annotation);
|
|
1630
|
-
l && (l.forEach((
|
|
1630
|
+
l && (l.forEach((b) => n.remove(b)), o.delete(d.annotation));
|
|
1631
1631
|
}, f = (d) => {
|
|
1632
1632
|
u(d), s(d);
|
|
1633
1633
|
}, m = (d, l = !0) => {
|
|
1634
1634
|
l && a();
|
|
1635
|
-
const
|
|
1636
|
-
|
|
1637
|
-
const L =
|
|
1635
|
+
const b = e.getBoundingClientRect(), S = d.map((C) => ({ target: C, rects: i(C, b) }));
|
|
1636
|
+
S.forEach(({ target: C, rects: B }) => o.set(C.annotation, B));
|
|
1637
|
+
const L = S.reduce((C, { rects: B }) => [...C, ...B], []);
|
|
1638
1638
|
n.load(L);
|
|
1639
1639
|
}, c = (d, l) => {
|
|
1640
|
-
const
|
|
1640
|
+
const b = n.search({
|
|
1641
1641
|
minX: d,
|
|
1642
1642
|
minY: l,
|
|
1643
1643
|
maxX: d,
|
|
1644
1644
|
maxY: l
|
|
1645
|
-
}),
|
|
1646
|
-
if (
|
|
1647
|
-
return
|
|
1645
|
+
}), S = (L) => L.annotation.rects.reduce((C, B) => C + B.width * B.height, 0);
|
|
1646
|
+
if (b.length > 0)
|
|
1647
|
+
return b.sort((L, C) => S(L) - S(C)), b[0].annotation.id;
|
|
1648
1648
|
}, p = (d) => {
|
|
1649
1649
|
const l = g(d);
|
|
1650
1650
|
if (l.length === 0)
|
|
1651
1651
|
return;
|
|
1652
|
-
let
|
|
1652
|
+
let b = l[0].left, S = l[0].top, L = l[0].right, C = l[0].bottom;
|
|
1653
1653
|
for (let B = 1; B < l.length; B++) {
|
|
1654
1654
|
const T = l[B];
|
|
1655
|
-
|
|
1655
|
+
b = Math.min(b, T.left), S = Math.min(S, T.top), L = Math.max(L, T.right), C = Math.max(C, T.bottom);
|
|
1656
1656
|
}
|
|
1657
|
-
return new DOMRect(
|
|
1657
|
+
return new DOMRect(b, S, L - b, C - S);
|
|
1658
1658
|
}, g = (d) => {
|
|
1659
1659
|
const l = o.get(d);
|
|
1660
1660
|
return l ? l[0].annotation.rects : [];
|
|
@@ -1665,9 +1665,9 @@ const En = (t, e) => {
|
|
|
1665
1665
|
getAt: c,
|
|
1666
1666
|
getAnnotationBounds: p,
|
|
1667
1667
|
getAnnotationRects: g,
|
|
1668
|
-
getIntersecting: (d, l,
|
|
1669
|
-
const L = n.search({ minX: d, minY: l, maxX:
|
|
1670
|
-
return Array.from(
|
|
1668
|
+
getIntersecting: (d, l, b, S) => {
|
|
1669
|
+
const L = n.search({ minX: d, minY: l, maxX: b, maxY: S }), C = new Set(L.reduce((B, T) => [...B, T.annotation.id], []));
|
|
1670
|
+
return Array.from(C).map((B) => ({
|
|
1671
1671
|
annotation: t.getAnnotation(B),
|
|
1672
1672
|
rects: g(B)
|
|
1673
1673
|
})).filter((B) => !!B.annotation);
|
|
@@ -1680,40 +1680,40 @@ const En = (t, e) => {
|
|
|
1680
1680
|
update: f
|
|
1681
1681
|
};
|
|
1682
1682
|
}, Sn = (t, e) => {
|
|
1683
|
-
const n = qe(), o = En(n, t), i = Me(n, e), r = Oe(n), a = Qe(), s = (
|
|
1684
|
-
const d = rt(
|
|
1683
|
+
const n = qe(), o = En(n, t), i = Me(n, e), r = Oe(n), a = Qe(), s = (w, h = N.LOCAL) => {
|
|
1684
|
+
const d = rt(w, t), l = $(d.target.selector);
|
|
1685
1685
|
return l && n.addAnnotation(d, h), l;
|
|
1686
|
-
}, u = (
|
|
1687
|
-
const l =
|
|
1688
|
-
return
|
|
1689
|
-
}, f = (
|
|
1690
|
-
const d =
|
|
1691
|
-
return l.length > 0 && console.warn("Could not revive all targets for these annotations:", l), d.forEach((
|
|
1692
|
-
n.getAnnotation(
|
|
1686
|
+
}, u = (w, h = !0, d = N.LOCAL) => {
|
|
1687
|
+
const l = w.map((S) => rt(S, t)), b = l.filter((S) => !$(S.target.selector));
|
|
1688
|
+
return b.length > 0 ? (console.warn("Could not revive all targets for these annotations:", b), n.bulkAddAnnotation(l, h, d), b) : (n.bulkAddAnnotation(l, h, d), []);
|
|
1689
|
+
}, f = (w, h = N.LOCAL) => {
|
|
1690
|
+
const d = w.map((b) => rt(b, t)), l = d.filter((b) => !$(b.target.selector));
|
|
1691
|
+
return l.length > 0 && console.warn("Could not revive all targets for these annotations:", l), d.forEach((b) => {
|
|
1692
|
+
n.getAnnotation(b.id) ? n.updateAnnotation(b, h) : n.addAnnotation(b, h);
|
|
1693
1693
|
}), l;
|
|
1694
|
-
}, m = (
|
|
1695
|
-
const d = it(
|
|
1694
|
+
}, m = (w, h = N.LOCAL) => {
|
|
1695
|
+
const d = it(w, t);
|
|
1696
1696
|
n.updateTarget(d, h);
|
|
1697
|
-
}, c = (
|
|
1698
|
-
const d =
|
|
1697
|
+
}, c = (w, h = N.LOCAL) => {
|
|
1698
|
+
const d = w.map((l) => it(l, t));
|
|
1699
1699
|
n.bulkUpdateTargets(d, h);
|
|
1700
|
-
}, p = (
|
|
1701
|
-
const d = o.getAt(
|
|
1700
|
+
}, p = (w, h) => {
|
|
1701
|
+
const d = o.getAt(w, h);
|
|
1702
1702
|
return d ? n.getAnnotation(d) : void 0;
|
|
1703
|
-
}, g = (
|
|
1704
|
-
const
|
|
1705
|
-
if (
|
|
1703
|
+
}, g = (w, h, d, l = 5) => {
|
|
1704
|
+
const b = o.getAnnotationRects(w);
|
|
1705
|
+
if (b.length !== 0) {
|
|
1706
1706
|
if (h && d) {
|
|
1707
|
-
const
|
|
1708
|
-
if (
|
|
1709
|
-
return
|
|
1707
|
+
const S = b.find(({ top: L, right: C, bottom: B, left: T }) => h >= T - l && h <= C + l && d >= L - l && d <= B + l);
|
|
1708
|
+
if (S)
|
|
1709
|
+
return S;
|
|
1710
1710
|
}
|
|
1711
|
-
return o.getAnnotationBounds(
|
|
1711
|
+
return o.getAnnotationBounds(w);
|
|
1712
1712
|
}
|
|
1713
1713
|
}, y = () => o.recalculate();
|
|
1714
|
-
return n.observe(({ changes:
|
|
1715
|
-
const h = (
|
|
1716
|
-
h.length > 0 && o.set(h.map((
|
|
1714
|
+
return n.observe(({ changes: w }) => {
|
|
1715
|
+
const h = (w.created || []).filter((b) => $(b.target.selector)), d = (w.deleted || []).filter((b) => $(b.target.selector)), l = (w.updated || []).filter((b) => $(b.newValue.target.selector));
|
|
1716
|
+
h.length > 0 && o.set(h.map((b) => b.target), !1), (d == null ? void 0 : d.length) > 0 && d.forEach((b) => o.remove(b.target)), (l == null ? void 0 : l.length) > 0 && l.forEach(({ newValue: b }) => o.update(b.target));
|
|
1717
1717
|
}), {
|
|
1718
1718
|
store: {
|
|
1719
1719
|
...n,
|
|
@@ -1754,10 +1754,10 @@ const En = (t, e) => {
|
|
|
1754
1754
|
n.font && (i.font = n.font);
|
|
1755
1755
|
const y = r.get(c.annotation.id);
|
|
1756
1756
|
if (y) {
|
|
1757
|
-
const { height:
|
|
1758
|
-
i.fillStyle = y.appearance.color, i.fillRect(h - 2, d - 2.5, 2,
|
|
1759
|
-
const l = i.measureText(y.appearance.label),
|
|
1760
|
-
return i.fillRect(h - 2, d - 2.5 -
|
|
1757
|
+
const { height: w } = c.rects[0], h = c.rects[0].x + p.left, d = c.rects[0].y + p.top;
|
|
1758
|
+
i.fillStyle = y.appearance.color, i.fillRect(h - 2, d - 2.5, 2, w + 5);
|
|
1759
|
+
const l = i.measureText(y.appearance.label), b = l.width + 6, S = l.actualBoundingBoxAscent + l.actualBoundingBoxDescent + 8, L = l.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1760
|
+
return i.fillRect(h - 2, d - 2.5 - S, b, S), i.fillStyle = "#fff", i.fillText(y.appearance.label, h + 1, d - L), {
|
|
1761
1761
|
fill: y.appearance.color,
|
|
1762
1762
|
fillOpacity: g ? 0.45 : 0.18
|
|
1763
1763
|
};
|
|
@@ -1776,7 +1776,7 @@ const En = (t, e) => {
|
|
|
1776
1776
|
return e !== "visible" && e !== "hidden" && t.scrollHeight > t.clientHeight ? t : Pt(t.parentElement);
|
|
1777
1777
|
}, Bn = (t, e) => (n) => {
|
|
1778
1778
|
const o = (r) => {
|
|
1779
|
-
const a = i.getBoundingClientRect(), s = i.clientHeight, u = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: m, height: c } = e.getAnnotationBounds(n.id), p = f.top - a.top, g = f.left - a.left, y = i.parentElement ? i.scrollTop : 0,
|
|
1779
|
+
const a = i.getBoundingClientRect(), s = i.clientHeight, u = i.clientWidth, f = r.selector[0].range.getBoundingClientRect(), { width: m, height: c } = e.getAnnotationBounds(n.id), p = f.top - a.top, g = f.left - a.left, y = i.parentElement ? i.scrollTop : 0, w = i.parentElement ? i.scrollLeft : 0, h = p + y - (s - c) / 2, d = g + w - (u - m) / 2;
|
|
1780
1780
|
i.scroll({ top: h, left: d, behavior: "smooth" });
|
|
1781
1781
|
}, i = Pt(t);
|
|
1782
1782
|
if (i) {
|
|
@@ -1812,24 +1812,24 @@ const En = (t, e) => {
|
|
|
1812
1812
|
};
|
|
1813
1813
|
n && t.addEventListener("selectstart", c);
|
|
1814
1814
|
const p = pt((h) => {
|
|
1815
|
-
var
|
|
1815
|
+
var C, B;
|
|
1816
1816
|
const d = document.getSelection();
|
|
1817
|
-
if (!!((B = (
|
|
1817
|
+
if (!!((B = (C = d.anchorNode) == null ? void 0 : C.parentElement) != null && B.closest(_))) {
|
|
1818
1818
|
s = void 0;
|
|
1819
1819
|
return;
|
|
1820
1820
|
}
|
|
1821
1821
|
if (h.timeStamp - ((m == null ? void 0 : m.timeStamp) || h.timeStamp) < 1e3 && !s && c(m), d.isCollapsed || !f || !s)
|
|
1822
1822
|
return;
|
|
1823
|
-
const
|
|
1824
|
-
if (ne(
|
|
1823
|
+
const b = d.getRangeAt(0);
|
|
1824
|
+
if (ne(b))
|
|
1825
1825
|
return;
|
|
1826
|
-
const
|
|
1827
|
-
(
|
|
1828
|
-
var
|
|
1829
|
-
return T.toString() !== ((
|
|
1826
|
+
const S = Kt(b.cloneRange());
|
|
1827
|
+
(S.length !== s.selector.length || S.some((T, I) => {
|
|
1828
|
+
var v;
|
|
1829
|
+
return T.toString() !== ((v = s.selector[I]) == null ? void 0 : v.quote);
|
|
1830
1830
|
})) && (s = {
|
|
1831
1831
|
...s,
|
|
1832
|
-
selector:
|
|
1832
|
+
selector: S.map((T) => se(T, t, o)),
|
|
1833
1833
|
updated: /* @__PURE__ */ new Date()
|
|
1834
1834
|
}, i.getAnnotation(s.annotation) ? i.updateTarget(s, N.LOCAL) : (i.addAnnotation({
|
|
1835
1835
|
id: s.annotation,
|
|
@@ -1839,23 +1839,23 @@ const En = (t, e) => {
|
|
|
1839
1839
|
});
|
|
1840
1840
|
n && document.addEventListener("selectionchange", p);
|
|
1841
1841
|
const g = (h) => {
|
|
1842
|
-
const { target: d, timeStamp: l, offsetX:
|
|
1843
|
-
m = { ...h, target: d, timeStamp: l, offsetX:
|
|
1842
|
+
const { target: d, timeStamp: l, offsetX: b, offsetY: S, type: L } = h;
|
|
1843
|
+
m = { ...h, target: d, timeStamp: l, offsetX: b, offsetY: S, type: L }, f = h.button === 0;
|
|
1844
1844
|
};
|
|
1845
1845
|
t.addEventListener("pointerdown", g);
|
|
1846
1846
|
const y = (h) => {
|
|
1847
|
-
var
|
|
1848
|
-
if (!!((
|
|
1847
|
+
var S;
|
|
1848
|
+
if (!!((S = h.target.parentElement) != null && S.closest(_)) || !f)
|
|
1849
1849
|
return;
|
|
1850
1850
|
const l = () => {
|
|
1851
|
-
const { x: L, y:
|
|
1851
|
+
const { x: L, y: C } = t.getBoundingClientRect(), B = i.getAt(h.clientX - L, h.clientY - C);
|
|
1852
1852
|
if (B) {
|
|
1853
1853
|
const { selected: T } = r;
|
|
1854
1854
|
(T.length !== 1 || T[0].id !== B.id) && r.clickSelect(B.id, h);
|
|
1855
1855
|
} else
|
|
1856
1856
|
r.isEmpty() || r.clear();
|
|
1857
|
-
},
|
|
1858
|
-
document.getSelection().isCollapsed &&
|
|
1857
|
+
}, b = h.timeStamp - m.timeStamp;
|
|
1858
|
+
document.getSelection().isCollapsed && b < 300 ? (s = void 0, l()) : s && r.clickSelect(s.annotation, h);
|
|
1859
1859
|
};
|
|
1860
1860
|
return document.addEventListener("pointerup", y), {
|
|
1861
1861
|
destroy: () => {
|
|
@@ -1875,25 +1875,28 @@ const En = (t, e) => {
|
|
|
1875
1875
|
throw `Unknown renderer implementation: ${m}`;
|
|
1876
1876
|
console.debug(`Using ${m} renderer`), n.style && c.setStyle(n.style);
|
|
1877
1877
|
const p = Rn(t, o, n.annotationEnabled, n.offsetReferenceSelector);
|
|
1878
|
-
|
|
1879
|
-
|
|
1878
|
+
p.setUser(f);
|
|
1879
|
+
const g = tn(o, s, n.adapter), y = () => f, w = (b) => {
|
|
1880
|
+
f = b, p.setUser(b);
|
|
1881
|
+
}, h = (b) => {
|
|
1882
|
+
b && (c.setPainter(Ln(t, b, n.presence)), b.on("selectionChange", () => c.redraw()));
|
|
1883
|
+
}, d = (b) => {
|
|
1884
|
+
b ? i.setSelected(b) : i.clear();
|
|
1885
|
+
};
|
|
1886
|
+
return {
|
|
1887
|
+
...g,
|
|
1880
1888
|
destroy: () => {
|
|
1881
1889
|
c.destroy(), p.destroy(), s.destroy();
|
|
1882
1890
|
},
|
|
1883
1891
|
element: t,
|
|
1884
|
-
getUser:
|
|
1885
|
-
setFilter:
|
|
1886
|
-
setStyle:
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
},
|
|
1893
|
-
setPresenceProvider: (E) => {
|
|
1894
|
-
E && (c.setPainter(Ln(t, E, n.presence)), E.on("selectionChange", () => c.redraw()));
|
|
1895
|
-
},
|
|
1896
|
-
setVisible: (E) => c.setVisible(E),
|
|
1892
|
+
getUser: y,
|
|
1893
|
+
setFilter: c.setFilter.bind(c),
|
|
1894
|
+
setStyle: c.setStyle.bind(c),
|
|
1895
|
+
redraw: c.redraw.bind(c),
|
|
1896
|
+
setUser: w,
|
|
1897
|
+
setSelected: d,
|
|
1898
|
+
setPresenceProvider: h,
|
|
1899
|
+
setVisible: c.setVisible.bind(c),
|
|
1897
1900
|
on: u.on,
|
|
1898
1901
|
off: u.off,
|
|
1899
1902
|
scrollIntoView: Bn(t, a),
|