@soomo/text-annotator 3.0.0-staging.28 → 3.0.0-staging.29
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextAnnotatorState } from 'src/state';
|
|
2
1
|
import { ViewportState } from '@annotorious/core';
|
|
2
|
+
import { TextAnnotatorState } from '../../state';
|
|
3
3
|
|
|
4
4
|
export declare const createCanvasRenderer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState) => import('../baseRenderer').Renderer;
|
package/dist/text-annotator.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.r6o-highlight-layer{position:fixed;top:0;bottom:0;left:0;width:100vw;height:100vh;pointer-events:none}.r6o-highlight-layer.bg{
|
|
1
|
+
.r6o-canvas-highlight-layer{position:fixed;top:0;bottom:0;left:0;width:100vw;height:100vh;pointer-events:none}.r6o-canvas-highlight-layer.bg{mix-blend-mode:multiply;z-index:1}.r6o-annotatable .r6o-span-highlight-layer{position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none}.r6o-annotatable .r6o-span-highlight-layer.hidden{display:none}.r6o-annotatable .r6o-span-highlight-layer .r6o-annotation{position:absolute;display:block;border-width:0;border-style:solid}.r6o-annotation{box-sizing:content-box}.r6o-presence-layer{left:0;position:fixed;top:0;bottom:0;width:100vw;pointer-events:none}html,body{overscroll-behavior-y:none}.r6o-annotatable{-webkit-tap-highlight-color:transparent}.r6o-annotatable,.r6o-annotatable *{position:relative}.hovered *{cursor:pointer}*::selection,::selection{background:#0080ff2e}::-moz-selection{background:#0080ff2e}
|
|
@@ -239,7 +239,7 @@ const P = {
|
|
|
239
239
|
t.addEventListener("pointermove", l);
|
|
240
240
|
const p = (B = !1) => {
|
|
241
241
|
h && h.clear();
|
|
242
|
-
const M = de(t), { minX: b, minY: x, maxX: A, maxY:
|
|
242
|
+
const M = de(t), { minX: b, minY: x, maxX: A, maxY: S } = M, R = u ? i.getIntersecting(b, x, A, S).filter(({ annotation: _ }) => u(_)) : i.getIntersecting(b, x, A, S), O = r.selected.map(({ id: _ }) => _), H = R.map(({ annotation: _, rects: qt }) => {
|
|
243
243
|
const jt = O.includes(_.id), Gt = _.id === s.current;
|
|
244
244
|
return { annotation: _, rects: qt, state: { selected: jt, hover: Gt } };
|
|
245
245
|
});
|
|
@@ -258,14 +258,14 @@ const P = {
|
|
|
258
258
|
i.recalculatePositions(), h && h.reset(), p();
|
|
259
259
|
});
|
|
260
260
|
window.addEventListener("resize", y);
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
const L = { attributes: !0, childList: !0, subtree: !0 },
|
|
261
|
+
const E = new ResizeObserver(y);
|
|
262
|
+
E.observe(t);
|
|
263
|
+
const L = { attributes: !0, childList: !0, subtree: !0 }, C = new MutationObserver((B) => {
|
|
264
264
|
B.every((b) => b.target === t || t.contains(b.target)) || p(!0);
|
|
265
265
|
});
|
|
266
|
-
return
|
|
266
|
+
return C.observe(document.body, L), {
|
|
267
267
|
destroy: () => {
|
|
268
|
-
t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(g), d(), document.removeEventListener("scroll", a), window.removeEventListener("resize", y),
|
|
268
|
+
t.removeEventListener("pointermove", l), o.destroy(), i.unobserve(g), d(), document.removeEventListener("scroll", a), window.removeEventListener("resize", y), E.disconnect(), C.disconnect();
|
|
269
269
|
},
|
|
270
270
|
redraw: p,
|
|
271
271
|
setStyle: w,
|
|
@@ -275,7 +275,7 @@ const P = {
|
|
|
275
275
|
};
|
|
276
276
|
}, he = () => {
|
|
277
277
|
const t = document.createElement("canvas");
|
|
278
|
-
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-highlight-layer bg", t;
|
|
278
|
+
return t.width = window.innerWidth, t.height = window.innerHeight, t.className = "r6o-canvas-highlight-layer bg", t;
|
|
279
279
|
}, fe = (t, e) => {
|
|
280
280
|
t.width = window.innerWidth, t.height = window.innerHeight;
|
|
281
281
|
}, pe = (t) => {
|
|
@@ -290,20 +290,20 @@ const P = {
|
|
|
290
290
|
const { annotation: { target: { created: a } } } = g, { annotation: { target: { created: y } } } = d;
|
|
291
291
|
return a.getTime() - y.getTime();
|
|
292
292
|
}).forEach((g) => {
|
|
293
|
-
var
|
|
294
|
-
const d = h ? typeof h == "function" ? h(g.annotation, g.state) : h : (
|
|
293
|
+
var E;
|
|
294
|
+
const d = h ? typeof h == "function" ? h(g.annotation, g.state) : h : (E = g.state) != null && E.selected ? ot : P, a = m && m.paint(g, u) || d, y = g.rects.map(({ x: L, y: C, width: T, height: B }) => ({
|
|
295
295
|
x: L + w,
|
|
296
|
-
y:
|
|
296
|
+
y: C + f,
|
|
297
297
|
width: T,
|
|
298
298
|
height: B
|
|
299
299
|
}));
|
|
300
300
|
if (n.fillStyle = a.fill, n.globalAlpha = a.fillOpacity || 1, y.forEach(
|
|
301
|
-
({ x: L, y:
|
|
301
|
+
({ x: L, y: C, width: T, height: B }) => n.fillRect(L, C, T, B)
|
|
302
302
|
), a.underlineColor) {
|
|
303
303
|
n.globalAlpha = 1, n.strokeStyle = a.underlineColor, n.lineWidth = a.underlineThickness ?? 1;
|
|
304
304
|
const L = a.underlineOffset ?? 0;
|
|
305
|
-
y.forEach(({ x:
|
|
306
|
-
n.beginPath(), n.moveTo(
|
|
305
|
+
y.forEach(({ x: C, y: T, width: B, height: M }) => {
|
|
306
|
+
n.beginPath(), n.moveTo(C, T + M + L), n.lineTo(C + B, T + M + L), n.stroke();
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
309
|
});
|
|
@@ -527,7 +527,7 @@ const Le = (t, e) => {
|
|
|
527
527
|
const g = Le(v, f), d = Kt(w, c, u, h, g);
|
|
528
528
|
if (p) {
|
|
529
529
|
const a = document.createElement("span");
|
|
530
|
-
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`, a.style.backgroundColor = Y((d == null ? void 0 : d.fill) || P.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? P.fillOpacity : d.fillOpacity).toHex(), 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.
|
|
530
|
+
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`, a.style.backgroundColor = Y((d == null ? void 0 : d.fill) || P.fill).alpha((d == null ? void 0 : d.fillOpacity) === void 0 ? P.fillOpacity : d.fillOpacity).toHex(), 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);
|
|
531
531
|
}
|
|
532
532
|
});
|
|
533
533
|
}), n = s;
|
|
@@ -784,39 +784,39 @@ const We = (t, e) => {
|
|
|
784
784
|
},
|
|
785
785
|
state: [...t.values()]
|
|
786
786
|
};
|
|
787
|
-
n.forEach((
|
|
788
|
-
We(
|
|
787
|
+
n.forEach((S) => {
|
|
788
|
+
We(S, A) && S.onChange(A);
|
|
789
789
|
});
|
|
790
790
|
}, s = (b, x = N.LOCAL) => {
|
|
791
791
|
if (t.get(b.id))
|
|
792
792
|
throw Error(`Cannot add annotation ${b.id} - exists already`);
|
|
793
793
|
t.set(b.id, b), b.bodies.forEach((A) => e.set(A.id, b.id)), r(x, { created: [b] });
|
|
794
794
|
}, c = (b, x) => {
|
|
795
|
-
const A = typeof b == "string" ? x : b,
|
|
795
|
+
const A = typeof b == "string" ? x : b, S = typeof b == "string" ? b : b.id, R = t.get(S);
|
|
796
796
|
if (R) {
|
|
797
797
|
const O = Pt(R, A);
|
|
798
|
-
return
|
|
798
|
+
return S === A.id ? t.set(S, A) : (t.delete(S), t.set(A.id, A)), R.bodies.forEach((H) => e.delete(H.id)), A.bodies.forEach((H) => e.set(H.id, A.id)), O;
|
|
799
799
|
} else
|
|
800
|
-
console.warn(`Cannot update annotation ${
|
|
800
|
+
console.warn(`Cannot update annotation ${S} - does not exist`);
|
|
801
801
|
}, u = (b, x = N.LOCAL, A = N.LOCAL) => {
|
|
802
|
-
const
|
|
803
|
-
R && r(
|
|
802
|
+
const S = je(x) ? A : x, R = c(b, x);
|
|
803
|
+
R && r(S, { updated: [R] });
|
|
804
804
|
}, h = (b, x = N.LOCAL) => {
|
|
805
|
-
const A = b.reduce((
|
|
805
|
+
const A = b.reduce((S, R) => {
|
|
806
806
|
const O = c(R);
|
|
807
|
-
return O ? [...
|
|
807
|
+
return O ? [...S, O] : S;
|
|
808
808
|
}, []);
|
|
809
809
|
A.length > 0 && r(x, { updated: A });
|
|
810
810
|
}, m = (b, x = N.LOCAL) => {
|
|
811
811
|
const A = t.get(b.annotation);
|
|
812
812
|
if (A) {
|
|
813
|
-
const
|
|
813
|
+
const S = {
|
|
814
814
|
...A,
|
|
815
815
|
bodies: [...A.bodies, b]
|
|
816
816
|
};
|
|
817
|
-
t.set(A.id,
|
|
817
|
+
t.set(A.id, S), e.set(b.id, S.id), r(x, { updated: [{
|
|
818
818
|
oldValue: A,
|
|
819
|
-
newValue:
|
|
819
|
+
newValue: S,
|
|
820
820
|
bodiesCreated: [b]
|
|
821
821
|
}] });
|
|
822
822
|
} else
|
|
@@ -826,17 +826,17 @@ const We = (t, e) => {
|
|
|
826
826
|
t.clear(), e.clear(), r(b, { deleted: x });
|
|
827
827
|
}, f = (b, x = !0, A = N.LOCAL) => {
|
|
828
828
|
if (x) {
|
|
829
|
-
const
|
|
829
|
+
const S = [...t.values()];
|
|
830
830
|
t.clear(), e.clear(), b.forEach((R) => {
|
|
831
831
|
t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
|
|
832
|
-
}), r(A, { created: b, deleted:
|
|
832
|
+
}), r(A, { created: b, deleted: S });
|
|
833
833
|
} else {
|
|
834
|
-
const
|
|
834
|
+
const S = b.reduce((R, O) => {
|
|
835
835
|
const H = t.get(O.id);
|
|
836
836
|
return H ? [...R, H] : R;
|
|
837
837
|
}, []);
|
|
838
|
-
if (
|
|
839
|
-
throw Error(`Bulk insert would overwrite the following annotations: ${
|
|
838
|
+
if (S.length > 0)
|
|
839
|
+
throw Error(`Bulk insert would overwrite the following annotations: ${S.map((R) => R.id).join(", ")}`);
|
|
840
840
|
b.forEach((R) => {
|
|
841
841
|
t.set(R.id, R), R.bodies.forEach((O) => e.set(O.id, R.id));
|
|
842
842
|
}), r(A, { created: b });
|
|
@@ -844,30 +844,30 @@ const We = (t, e) => {
|
|
|
844
844
|
}, w = (b) => {
|
|
845
845
|
const x = typeof b == "string" ? b : b.id, A = t.get(x);
|
|
846
846
|
if (A)
|
|
847
|
-
return t.delete(x), A.bodies.forEach((
|
|
847
|
+
return t.delete(x), A.bodies.forEach((S) => e.delete(S.id)), A;
|
|
848
848
|
console.warn(`Attempt to delete missing annotation: ${x}`);
|
|
849
849
|
}, v = (b, x = N.LOCAL) => {
|
|
850
850
|
const A = w(b);
|
|
851
851
|
A && r(x, { deleted: [A] });
|
|
852
852
|
}, g = (b, x = N.LOCAL) => {
|
|
853
|
-
const A = b.reduce((
|
|
853
|
+
const A = b.reduce((S, R) => {
|
|
854
854
|
const O = w(R);
|
|
855
|
-
return O ? [...
|
|
855
|
+
return O ? [...S, O] : S;
|
|
856
856
|
}, []);
|
|
857
857
|
A.length > 0 && r(x, { deleted: A });
|
|
858
858
|
}, d = (b) => {
|
|
859
859
|
const x = t.get(b.annotation);
|
|
860
860
|
if (x) {
|
|
861
|
-
const A = x.bodies.find((
|
|
861
|
+
const A = x.bodies.find((S) => S.id === b.id);
|
|
862
862
|
if (A) {
|
|
863
863
|
e.delete(A.id);
|
|
864
|
-
const
|
|
864
|
+
const S = {
|
|
865
865
|
...x,
|
|
866
866
|
bodies: x.bodies.filter((R) => R.id !== b.id)
|
|
867
867
|
};
|
|
868
|
-
return t.set(x.id,
|
|
868
|
+
return t.set(x.id, S), {
|
|
869
869
|
oldValue: x,
|
|
870
|
-
newValue:
|
|
870
|
+
newValue: S,
|
|
871
871
|
bodiesDeleted: [A]
|
|
872
872
|
};
|
|
873
873
|
} else
|
|
@@ -878,41 +878,41 @@ const We = (t, e) => {
|
|
|
878
878
|
const A = d(b);
|
|
879
879
|
A && r(x, { updated: [A] });
|
|
880
880
|
}, y = (b, x = N.LOCAL) => {
|
|
881
|
-
const A = b.map((
|
|
881
|
+
const A = b.map((S) => d(S)).filter(Boolean);
|
|
882
882
|
A.length > 0 && r(x, { updated: A });
|
|
883
|
-
},
|
|
883
|
+
}, E = (b) => {
|
|
884
884
|
const x = t.get(b);
|
|
885
885
|
return x ? { ...x } : void 0;
|
|
886
886
|
}, L = (b) => {
|
|
887
887
|
const x = e.get(b);
|
|
888
888
|
if (x) {
|
|
889
|
-
const A =
|
|
889
|
+
const A = E(x).bodies.find((S) => S.id === b);
|
|
890
890
|
if (A)
|
|
891
891
|
return A;
|
|
892
892
|
console.error(`Store integrity error: body ${b} in index, but not in annotation`);
|
|
893
893
|
} else
|
|
894
894
|
console.warn(`Attempt to retrieve missing body: ${b}`);
|
|
895
|
-
},
|
|
895
|
+
}, C = (b, x) => {
|
|
896
896
|
if (b.annotation !== x.annotation)
|
|
897
897
|
throw "Annotation integrity violation: annotation ID must be the same when updating bodies";
|
|
898
898
|
const A = t.get(b.annotation);
|
|
899
899
|
if (A) {
|
|
900
|
-
const
|
|
900
|
+
const S = A.bodies.find((O) => O.id === b.id), R = {
|
|
901
901
|
...A,
|
|
902
|
-
bodies: A.bodies.map((O) => O.id ===
|
|
902
|
+
bodies: A.bodies.map((O) => O.id === S.id ? x : O)
|
|
903
903
|
};
|
|
904
|
-
return t.set(A.id, R),
|
|
904
|
+
return t.set(A.id, R), S.id !== x.id && (e.delete(S.id), e.set(x.id, R.id)), {
|
|
905
905
|
oldValue: A,
|
|
906
906
|
newValue: R,
|
|
907
|
-
bodiesUpdated: [{ oldBody:
|
|
907
|
+
bodiesUpdated: [{ oldBody: S, newBody: x }]
|
|
908
908
|
};
|
|
909
909
|
} else
|
|
910
910
|
console.warn(`Attempt to add body to missing annotation ${b.annotation}`);
|
|
911
911
|
}, T = (b, x, A = N.LOCAL) => {
|
|
912
|
-
const
|
|
913
|
-
|
|
912
|
+
const S = C(b, x);
|
|
913
|
+
S && r(A, { updated: [S] });
|
|
914
914
|
}, B = (b, x = N.LOCAL) => {
|
|
915
|
-
const A = b.map((
|
|
915
|
+
const A = b.map((S) => C({ id: S.id, annotation: S.annotation }, S)).filter(Boolean);
|
|
916
916
|
r(x, { updated: A });
|
|
917
917
|
}, M = (b) => {
|
|
918
918
|
const x = t.get(b.annotation);
|
|
@@ -945,13 +945,13 @@ const We = (t, e) => {
|
|
|
945
945
|
bulkUpdateAnnotation: h,
|
|
946
946
|
bulkUpdateBodies: B,
|
|
947
947
|
bulkUpdateTargets: (b, x = N.LOCAL) => {
|
|
948
|
-
const A = b.map((
|
|
948
|
+
const A = b.map((S) => M(S)).filter(Boolean);
|
|
949
949
|
A.length > 0 && r(x, { updated: A });
|
|
950
950
|
},
|
|
951
951
|
clear: p,
|
|
952
952
|
deleteAnnotation: v,
|
|
953
953
|
deleteBody: a,
|
|
954
|
-
getAnnotation:
|
|
954
|
+
getAnnotation: E,
|
|
955
955
|
getBody: L,
|
|
956
956
|
observe: o,
|
|
957
957
|
unobserve: i,
|
|
@@ -1036,8 +1036,8 @@ const Qe = 250, Je = (t) => {
|
|
|
1036
1036
|
u.has(v) && setTimeout(() => {
|
|
1037
1037
|
u.get(v).forEach((a) => {
|
|
1038
1038
|
if (n) {
|
|
1039
|
-
const y = Array.isArray(g) ? g.map((L) => n.serialize(L)) : n.serialize(g),
|
|
1040
|
-
a(y,
|
|
1039
|
+
const y = Array.isArray(g) ? g.map((L) => n.serialize(L)) : n.serialize(g), E = d ? d instanceof PointerEvent ? d : n.serialize(d) : void 0;
|
|
1040
|
+
a(y, E);
|
|
1041
1041
|
} else
|
|
1042
1042
|
a(g, d);
|
|
1043
1043
|
});
|
|
@@ -1075,13 +1075,13 @@ const Qe = 250, Je = (t) => {
|
|
|
1075
1075
|
...a.bodiesDeleted || [],
|
|
1076
1076
|
...a.bodiesUpdated || []
|
|
1077
1077
|
].length > 0).forEach(({ oldValue: a, newValue: y }) => {
|
|
1078
|
-
const
|
|
1079
|
-
h = h.map((L) => L.id === a.id ? y : L), f("updateAnnotation", y,
|
|
1078
|
+
const E = h.find((L) => L.id === a.id) || a;
|
|
1079
|
+
h = h.map((L) => L.id === a.id ? y : L), f("updateAnnotation", y, E);
|
|
1080
1080
|
});
|
|
1081
1081
|
}, { origin: N.LOCAL }), i.observe((v) => {
|
|
1082
1082
|
if (h) {
|
|
1083
1083
|
const g = new Set(h.map((a) => a.id)), d = (v.changes.updated || []).filter(({ newValue: a }) => g.has(a.id)).map(({ newValue: a }) => a);
|
|
1084
|
-
d.length > 0 && (h = h.map((a) => d.find((
|
|
1084
|
+
d.length > 0 && (h = h.map((a) => d.find((E) => E.id === a.id) || a));
|
|
1085
1085
|
}
|
|
1086
1086
|
}, { origin: N.REMOTE });
|
|
1087
1087
|
const w = (v) => (g) => {
|
|
@@ -1576,19 +1576,19 @@ function Ut(t, e, n, o, i) {
|
|
|
1576
1576
|
const Cn = (t, e) => {
|
|
1577
1577
|
const n = new yn(), o = /* @__PURE__ */ new Map(), i = (d, a) => {
|
|
1578
1578
|
const y = d.selector.flatMap((L) => {
|
|
1579
|
-
const
|
|
1580
|
-
return Array.from(
|
|
1581
|
-
}),
|
|
1582
|
-
return
|
|
1583
|
-
const { x:
|
|
1579
|
+
const C = $([L]) ? L.range : Dt(L, e).range;
|
|
1580
|
+
return Array.from(C.getClientRects());
|
|
1581
|
+
}), E = ce(y).map(({ left: L, top: C, right: T, bottom: B }) => new DOMRect(L - a.left, C - a.top, T - L, B - C));
|
|
1582
|
+
return E.map((L) => {
|
|
1583
|
+
const { x: C, y: T, width: B, height: M } = L;
|
|
1584
1584
|
return {
|
|
1585
|
-
minX:
|
|
1585
|
+
minX: C,
|
|
1586
1586
|
minY: T,
|
|
1587
|
-
maxX:
|
|
1587
|
+
maxX: C + B,
|
|
1588
1588
|
maxY: T + M,
|
|
1589
1589
|
annotation: {
|
|
1590
1590
|
id: d.annotation,
|
|
1591
|
-
rects:
|
|
1591
|
+
rects: E
|
|
1592
1592
|
}
|
|
1593
1593
|
};
|
|
1594
1594
|
});
|
|
@@ -1604,28 +1604,28 @@ const Cn = (t, e) => {
|
|
|
1604
1604
|
u(d), c(d);
|
|
1605
1605
|
}, m = (d, a = !0) => {
|
|
1606
1606
|
a && s();
|
|
1607
|
-
const y = e.getBoundingClientRect(),
|
|
1608
|
-
|
|
1609
|
-
const L =
|
|
1607
|
+
const y = e.getBoundingClientRect(), E = d.map((C) => ({ target: C, rects: i(C, y) }));
|
|
1608
|
+
E.forEach(({ target: C, rects: T }) => o.set(C.annotation, T));
|
|
1609
|
+
const L = E.flatMap(({ rects: C }) => C);
|
|
1610
1610
|
n.load(L);
|
|
1611
1611
|
}, l = (d, a, y = !1) => {
|
|
1612
|
-
const
|
|
1612
|
+
const E = n.search({
|
|
1613
1613
|
minX: d,
|
|
1614
1614
|
minY: a,
|
|
1615
1615
|
maxX: d,
|
|
1616
1616
|
maxY: a
|
|
1617
|
-
}), L = (
|
|
1618
|
-
return
|
|
1617
|
+
}), L = (C) => C.annotation.rects.reduce((T, B) => T + B.width * B.height, 0);
|
|
1618
|
+
return E.length > 0 ? (E.sort((C, T) => L(C) - L(T)), y ? E.map((C) => C.annotation.id) : [E[0].annotation.id]) : [];
|
|
1619
1619
|
}, p = (d) => {
|
|
1620
1620
|
const a = f(d);
|
|
1621
1621
|
if (a.length === 0)
|
|
1622
1622
|
return;
|
|
1623
|
-
let y = a[0].left,
|
|
1623
|
+
let y = a[0].left, E = a[0].top, L = a[0].right, C = a[0].bottom;
|
|
1624
1624
|
for (let T = 1; T < a.length; T++) {
|
|
1625
1625
|
const B = a[T];
|
|
1626
|
-
y = Math.min(y, B.left),
|
|
1626
|
+
y = Math.min(y, B.left), E = Math.min(E, B.top), L = Math.max(L, B.right), C = Math.max(C, B.bottom);
|
|
1627
1627
|
}
|
|
1628
|
-
return new DOMRect(y,
|
|
1628
|
+
return new DOMRect(y, E, L - y, C - E);
|
|
1629
1629
|
}, f = (d) => {
|
|
1630
1630
|
const a = o.get(d);
|
|
1631
1631
|
return a ? a[0].annotation.rects : [];
|
|
@@ -1636,9 +1636,9 @@ const Cn = (t, e) => {
|
|
|
1636
1636
|
getAt: l,
|
|
1637
1637
|
getAnnotationBounds: p,
|
|
1638
1638
|
getAnnotationRects: f,
|
|
1639
|
-
getIntersecting: (d, a, y,
|
|
1640
|
-
const L = n.search({ minX: d, minY: a, maxX: y, maxY:
|
|
1641
|
-
return Array.from(
|
|
1639
|
+
getIntersecting: (d, a, y, E) => {
|
|
1640
|
+
const L = n.search({ minX: d, minY: a, maxX: y, maxY: E }), C = new Set(L.map((T) => T.annotation.id));
|
|
1641
|
+
return Array.from(C).map((T) => ({
|
|
1642
1642
|
annotation: t.getAnnotation(T),
|
|
1643
1643
|
rects: f(T)
|
|
1644
1644
|
})).filter((T) => !!T.annotation);
|
|
@@ -1655,7 +1655,7 @@ const Cn = (t, e) => {
|
|
|
1655
1655
|
const d = rt(v, t), a = $(d.target.selector);
|
|
1656
1656
|
return a && n.addAnnotation(d, g), a;
|
|
1657
1657
|
}, u = (v, g = !0, d = N.LOCAL) => {
|
|
1658
|
-
const a = v.map((
|
|
1658
|
+
const a = v.map((E) => rt(E, t)), y = a.filter((E) => !$(E.target.selector));
|
|
1659
1659
|
return y.length > 0 ? (console.warn("Could not revive all targets for these annotations:", y), n.bulkAddAnnotation(a, g, d), y) : (n.bulkAddAnnotation(a, g, d), []);
|
|
1660
1660
|
}, h = (v, g = N.LOCAL) => {
|
|
1661
1661
|
const d = v.map((y) => rt(y, t)), a = d.filter((y) => !$(y.target.selector));
|
|
@@ -1669,14 +1669,14 @@ const Cn = (t, e) => {
|
|
|
1669
1669
|
const d = v.map((a) => it(a, t));
|
|
1670
1670
|
n.bulkUpdateTargets(d, g);
|
|
1671
1671
|
}, p = (v, g, d) => {
|
|
1672
|
-
const a = o.getAt(v, g, !!d).map((
|
|
1672
|
+
const a = o.getAt(v, g, !!d).map((E) => n.getAnnotation(E)), y = d ? a.filter(d) : a;
|
|
1673
1673
|
return y.length > 0 ? y[0] : void 0;
|
|
1674
1674
|
}, f = (v, g, d, a = 5) => {
|
|
1675
1675
|
const y = o.getAnnotationRects(v);
|
|
1676
1676
|
if (y.length !== 0) {
|
|
1677
1677
|
if (g && d) {
|
|
1678
|
-
const
|
|
1679
|
-
if (
|
|
1678
|
+
const E = y.find(({ top: L, right: C, bottom: T, left: B }) => g >= B - a && g <= C + a && d >= L - a && d <= T + a);
|
|
1679
|
+
if (E) return E;
|
|
1680
1680
|
}
|
|
1681
1681
|
return o.getAnnotationBounds(v);
|
|
1682
1682
|
}
|
|
@@ -1703,7 +1703,7 @@ const Cn = (t, e) => {
|
|
|
1703
1703
|
};
|
|
1704
1704
|
}, Bn = () => {
|
|
1705
1705
|
const t = document.createElement("canvas");
|
|
1706
|
-
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-
|
|
1706
|
+
t.width = 2 * window.innerWidth, t.height = 2 * window.innerHeight, t.className = "r6o-presence-layer";
|
|
1707
1707
|
const e = t.getContext("2d");
|
|
1708
1708
|
return e.scale(2, 2), e.translate(0.5, 0.5), t;
|
|
1709
1709
|
}, Tn = (t, e, n = {}) => {
|
|
@@ -1726,8 +1726,8 @@ const Cn = (t, e) => {
|
|
|
1726
1726
|
if (w) {
|
|
1727
1727
|
const { height: v } = l.rects[0], g = l.rects[0].x + p.left, d = l.rects[0].y + p.top;
|
|
1728
1728
|
i.fillStyle = w.appearance.color, i.fillRect(g - 2, d - 2.5, 2, v + 5);
|
|
1729
|
-
const a = i.measureText(w.appearance.label), y = a.width + 6,
|
|
1730
|
-
return i.fillRect(g - 2, d - 2.5 -
|
|
1729
|
+
const a = i.measureText(w.appearance.label), y = a.width + 6, E = a.actualBoundingBoxAscent + a.actualBoundingBoxDescent + 8, L = a.fontBoundingBoxAscent ? 8 : 6.5;
|
|
1730
|
+
return i.fillRect(g - 2, d - 2.5 - E, y, E), i.fillStyle = "#fff", i.fillText(w.appearance.label, g + 1, d - L), {
|
|
1731
1731
|
fill: w.appearance.color,
|
|
1732
1732
|
fillOpacity: f ? 0.45 : 0.18
|
|
1733
1733
|
};
|
|
@@ -1771,9 +1771,9 @@ const Cn = (t, e) => {
|
|
|
1771
1771
|
const c = (a) => s = a, { store: u, selection: h } = e;
|
|
1772
1772
|
let m, l = !1, p;
|
|
1773
1773
|
const f = (a) => {
|
|
1774
|
-
var
|
|
1774
|
+
var E;
|
|
1775
1775
|
if (!l) return;
|
|
1776
|
-
!((
|
|
1776
|
+
!((E = a.target.parentElement) != null && E.closest(D)) ? m = {
|
|
1777
1777
|
annotation: Ht(),
|
|
1778
1778
|
selector: [],
|
|
1779
1779
|
creator: i,
|
|
@@ -1791,13 +1791,13 @@ const Cn = (t, e) => {
|
|
|
1791
1791
|
if (a.timeStamp - ((p == null ? void 0 : p.timeStamp) || a.timeStamp) < 1e3 && !m && f(p), y.isCollapsed || !l || !m) return;
|
|
1792
1792
|
const L = y.getRangeAt(0);
|
|
1793
1793
|
if (re(L)) return;
|
|
1794
|
-
const
|
|
1795
|
-
(
|
|
1794
|
+
const C = Zt(L.cloneRange());
|
|
1795
|
+
(C.length !== m.selector.length || C.some((b, x) => {
|
|
1796
1796
|
var A;
|
|
1797
1797
|
return b.toString() !== ((A = m.selector[x]) == null ? void 0 : A.quote);
|
|
1798
1798
|
})) && (m = {
|
|
1799
1799
|
...m,
|
|
1800
|
-
selector:
|
|
1800
|
+
selector: C.map((b) => le(b, t, o)),
|
|
1801
1801
|
updated: /* @__PURE__ */ new Date()
|
|
1802
1802
|
}, u.getAnnotation(m.annotation) ? u.updateTarget(m, N.LOCAL) : (h.clear(), u.addAnnotation({
|
|
1803
1803
|
id: m.annotation,
|
|
@@ -1807,22 +1807,22 @@ const Cn = (t, e) => {
|
|
|
1807
1807
|
});
|
|
1808
1808
|
n && document.addEventListener("selectionchange", w);
|
|
1809
1809
|
const v = (a) => {
|
|
1810
|
-
const { target: y, timeStamp:
|
|
1811
|
-
p = { ...a, target: y, timeStamp:
|
|
1810
|
+
const { target: y, timeStamp: E, offsetX: L, offsetY: C, type: T } = a;
|
|
1811
|
+
p = { ...a, target: y, timeStamp: E, offsetX: L, offsetY: C, type: T }, l = a.button === 0;
|
|
1812
1812
|
};
|
|
1813
1813
|
t.addEventListener("pointerdown", v);
|
|
1814
1814
|
const g = (a) => {
|
|
1815
|
-
var
|
|
1816
|
-
if (!!((
|
|
1815
|
+
var C;
|
|
1816
|
+
if (!!((C = a.target.parentElement) != null && C.closest(D)) || !l)
|
|
1817
1817
|
return;
|
|
1818
|
-
const
|
|
1818
|
+
const E = () => {
|
|
1819
1819
|
const { x: T, y: B } = t.getBoundingClientRect(), M = u.getAt(a.clientX - T, a.clientY - B, s);
|
|
1820
1820
|
if (M) {
|
|
1821
1821
|
const { selected: b } = h;
|
|
1822
1822
|
(b.length !== 1 || b[0].id !== M.id) && h.clickSelect(M.id, a);
|
|
1823
1823
|
} else h.isEmpty() || h.clear();
|
|
1824
1824
|
}, L = a.timeStamp - p.timeStamp;
|
|
1825
|
-
document.getSelection().isCollapsed && L < 300 ? (m = void 0,
|
|
1825
|
+
document.getSelection().isCollapsed && L < 300 ? (m = void 0, E()) : m && h.clickSelect(m.annotation, a);
|
|
1826
1826
|
};
|
|
1827
1827
|
return document.addEventListener("pointerup", g), {
|
|
1828
1828
|
destroy: () => {
|
|
@@ -1846,13 +1846,13 @@ const Cn = (t, e) => {
|
|
|
1846
1846
|
p.setUser(h);
|
|
1847
1847
|
const f = nn(o, c, n.adapter), w = () => h, v = (E) => {
|
|
1848
1848
|
l.setFilter(E), p.setFilter(E);
|
|
1849
|
-
}, g = (E) =>
|
|
1849
|
+
}, g = (E) => {
|
|
1850
1850
|
h = E, p.setUser(E);
|
|
1851
|
-
},
|
|
1851
|
+
}, d = (E) => {
|
|
1852
1852
|
E && (l.setPainter(Tn(t, E, n.presence)), E.on("selectionChange", () => l.redraw()));
|
|
1853
|
-
},
|
|
1853
|
+
}, a = (E) => {
|
|
1854
1854
|
E ? i.setSelected(E) : i.clear();
|
|
1855
|
-
}
|
|
1855
|
+
};
|
|
1856
1856
|
return {
|
|
1857
1857
|
...f,
|
|
1858
1858
|
destroy: () => {
|
|
@@ -1861,12 +1861,13 @@ const Cn = (t, e) => {
|
|
|
1861
1861
|
element: t,
|
|
1862
1862
|
getUser: w,
|
|
1863
1863
|
setFilter: v,
|
|
1864
|
-
setStyle:
|
|
1864
|
+
setStyle: l.setStyle.bind(l),
|
|
1865
|
+
redraw: l.redraw.bind(l),
|
|
1865
1866
|
redraw: l.redraw.bind(l),
|
|
1866
|
-
setUser:
|
|
1867
|
-
setSelected:
|
|
1868
|
-
setPresenceProvider:
|
|
1869
|
-
setVisible:
|
|
1867
|
+
setUser: g,
|
|
1868
|
+
setSelected: a,
|
|
1869
|
+
setPresenceProvider: d,
|
|
1870
|
+
setVisible: l.setVisible.bind(l),
|
|
1870
1871
|
on: u.on,
|
|
1871
1872
|
off: u.off,
|
|
1872
1873
|
scrollIntoView: Rn(t, s),
|