@soomo/text-annotator 3.4.13-staging.0 → 3.4.15-staging.0
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.
|
@@ -5,9 +5,10 @@ export interface W3CTextAnnotation extends W3CAnnotation {
|
|
|
5
5
|
}
|
|
6
6
|
export interface W3CTextAnnotationTarget extends W3CAnnotationTarget {
|
|
7
7
|
selector: W3CTextSelector | W3CTextSelector[];
|
|
8
|
-
outdated?: boolean;
|
|
9
8
|
styleClass?: string;
|
|
10
9
|
scope?: string;
|
|
10
|
+
outdated?: boolean;
|
|
11
|
+
migrationPending?: boolean;
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Matches the `Text Quote Selector` spec
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import de from "debounce";
|
|
2
|
-
import { UserSelectAction as Ce,
|
|
2
|
+
import { UserSelectAction as Ce, parseW3CBodies as Se, serializeW3CBodies as Ae, parseW3CUser as we, createStore as Re, createSelectionState as Te, createHoverState as ve, createViewportState as xe, Origin as K, createAnonymousGuest as Le, createUndoStack as Ne, createLifecycleObserver as Oe, createBaseAnnotator as Be } from "@annotorious/core";
|
|
3
3
|
import { Origin as Ut, UserSelectAction as Kt, createBody as Wt } from "@annotorious/core";
|
|
4
4
|
import { colord as ne } from "colord";
|
|
5
5
|
import { dequal as ke } from "dequal/lite";
|
|
@@ -11,7 +11,7 @@ import { poll as _e } from "poll";
|
|
|
11
11
|
const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t instanceof HTMLElement ? t.closest($) : t.parentElement?.closest($)) : !0, ge = (e, t) => {
|
|
12
12
|
const n = t.commonAncestorContainer;
|
|
13
13
|
return !W(e, n);
|
|
14
|
-
},
|
|
14
|
+
}, Pe = (e) => e.addEventListener("click", (t) => {
|
|
15
15
|
// Allow clicks within not-annotatable elements
|
|
16
16
|
!t.target.closest($) && !t.target.closest("a") && t.preventDefault();
|
|
17
17
|
}), J = (e) => ({
|
|
@@ -61,9 +61,9 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
61
61
|
return ((...r) => {
|
|
62
62
|
clearTimeout(n), n = setTimeout(() => e.apply(void 0, r), t);
|
|
63
63
|
});
|
|
64
|
-
}, me = typeof navigator < "u" && navigator.platform.startsWith("Mac"),
|
|
64
|
+
}, me = typeof navigator < "u" && navigator.platform.startsWith("Mac"), He = (e) => {
|
|
65
65
|
(!e.hasAttribute("tabindex") || e.tabIndex < -1) && e.setAttribute("tabindex", "-1"), e.classList.add("no-focus-outline");
|
|
66
|
-
},
|
|
66
|
+
}, De = (e) => {
|
|
67
67
|
const t = [], n = document.createNodeIterator(
|
|
68
68
|
e.commonAncestorContainer,
|
|
69
69
|
NodeFilter.SHOW_TEXT
|
|
@@ -293,7 +293,7 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
293
293
|
e.addEventListener("pointermove", d);
|
|
294
294
|
const y = ee((A = !1) => requestAnimationFrame(() => {
|
|
295
295
|
f && f.clear();
|
|
296
|
-
const v = Qe(e), { minX: N, minY: O, maxX:
|
|
296
|
+
const v = Qe(e), { minX: N, minY: O, maxX: D, maxY: X } = v, z = l ? s.getIntersecting(N, O, D, X).filter(({ annotation: p }) => l(p)) : s.getIntersecting(N, O, D, X), F = o.selected.map(({ id: p }) => p), re = z.map(({ annotation: p, rects: T }) => {
|
|
297
297
|
const k = F.includes(p.id), U = p.id === i.current;
|
|
298
298
|
return {
|
|
299
299
|
annotation: p,
|
|
@@ -475,7 +475,7 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
475
475
|
}
|
|
476
476
|
return d;
|
|
477
477
|
}, {});
|
|
478
|
-
if (c.outdated ||= "outdated" in l ? l.outdated : void 0, ut(u))
|
|
478
|
+
if (c.outdated ||= "outdated" in l ? l.outdated : void 0, c.migrationPending ||= "migrationPending" in l ? l.migrationPending : void 0, ut(u))
|
|
479
479
|
c.selector.push(
|
|
480
480
|
{
|
|
481
481
|
...u,
|
|
@@ -500,7 +500,7 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
500
500
|
modified: s,
|
|
501
501
|
body: o,
|
|
502
502
|
...i
|
|
503
|
-
} = e, c =
|
|
503
|
+
} = e, c = Se(o, t), l = ft(e);
|
|
504
504
|
return "error" in l ? { error: l.error } : {
|
|
505
505
|
parsed: {
|
|
506
506
|
...i,
|
|
@@ -544,7 +544,7 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
544
544
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
|
545
545
|
id: e.id,
|
|
546
546
|
type: "Annotation",
|
|
547
|
-
body:
|
|
547
|
+
body: Ae(e.bodies),
|
|
548
548
|
creator: c,
|
|
549
549
|
created: l?.toISOString(),
|
|
550
550
|
modified: f?.toISOString(),
|
|
@@ -592,15 +592,15 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
592
592
|
const s = new Me(), o = /* @__PURE__ */ new Map(), i = Ie(), c = (m, a) => {
|
|
593
593
|
const C = m.selector.flatMap((A) => {
|
|
594
594
|
const v = I([A]) ? A.range : he(A, t).range;
|
|
595
|
-
return
|
|
595
|
+
return De(v);
|
|
596
596
|
}), L = Ye(C, n, r).map((A) => je(A, a));
|
|
597
597
|
return L.map((A) => {
|
|
598
|
-
const { x: v, y: N, width: O, height:
|
|
598
|
+
const { x: v, y: N, width: O, height: D } = A;
|
|
599
599
|
return {
|
|
600
600
|
minX: v,
|
|
601
601
|
minY: N,
|
|
602
602
|
maxX: v + O,
|
|
603
|
-
maxY: N +
|
|
603
|
+
maxY: N + D,
|
|
604
604
|
annotation: {
|
|
605
605
|
id: m.annotation,
|
|
606
606
|
rects: L
|
|
@@ -779,9 +779,9 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
779
779
|
s.getAnnotation(g.annotation) && !(a(b) || w === "REPLACE_CURRENT") && (o.clear(), s.deleteAnnotation(g.annotation));
|
|
780
780
|
return;
|
|
781
781
|
}
|
|
782
|
-
const
|
|
783
|
-
if (
|
|
784
|
-
const M =
|
|
782
|
+
const P = k.map((B) => qe(B, e));
|
|
783
|
+
if (P.every((B) => $e(B))) return;
|
|
784
|
+
const M = P.flatMap((B) => Ke(e, B.cloneRange()));
|
|
785
785
|
if (!(M.length > 0 && !g || M.length !== g.selector.length || M.some((B, V) => B.toString() !== g.selector[V]?.quote))) return;
|
|
786
786
|
const j = a(b) && x ? Xe([
|
|
787
787
|
...x.selector.map((B) => B.range),
|
|
@@ -797,27 +797,27 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
797
797
|
}, v = async (p) => {
|
|
798
798
|
if (!R) return;
|
|
799
799
|
const T = J(p), k = () => {
|
|
800
|
-
const { x:
|
|
800
|
+
const { x: P, y: M } = e.getBoundingClientRect();
|
|
801
801
|
if (W(e, T.target)) {
|
|
802
802
|
(typeof u == "function" ? u(T, e) : u === "ALWAYS") && o.clear();
|
|
803
803
|
return;
|
|
804
804
|
}
|
|
805
|
-
const
|
|
806
|
-
T.clientX -
|
|
805
|
+
const H = T.target instanceof Node && e.contains(T.target) && s.getAt(
|
|
806
|
+
T.clientX - P,
|
|
807
807
|
T.clientY - M,
|
|
808
808
|
f === "all",
|
|
809
809
|
d
|
|
810
810
|
);
|
|
811
|
-
if (
|
|
812
|
-
const { selected: j } = o, B = new Set(j.map((Y) => Y.id)), V = Array.isArray(
|
|
813
|
-
(B.size !== V.length || !V.every((Y) => B.has(Y))) && (n.emit("clickAnnotation",
|
|
811
|
+
if (H) {
|
|
812
|
+
const { selected: j } = o, B = new Set(j.map((Y) => Y.id)), V = Array.isArray(H) ? H.map((Y) => Y.id) : [H.id];
|
|
813
|
+
(B.size !== V.length || !V.every((Y) => B.has(Y))) && (n.emit("clickAnnotation", H), o.userSelect(V, T));
|
|
814
814
|
} else
|
|
815
815
|
o.clear();
|
|
816
816
|
};
|
|
817
817
|
if (T.timeStamp - b.timeStamp < ce) {
|
|
818
818
|
await N();
|
|
819
|
-
const
|
|
820
|
-
if (
|
|
819
|
+
const P = document.getSelection(), M = W(e, b.target), H = W(e, T.target);
|
|
820
|
+
if (P?.isCollapsed || M && H) {
|
|
821
821
|
g = void 0, k();
|
|
822
822
|
return;
|
|
823
823
|
}
|
|
@@ -826,11 +826,11 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
826
826
|
}, N = async () => {
|
|
827
827
|
const p = document.getSelection();
|
|
828
828
|
let T = !1, k = p?.isCollapsed;
|
|
829
|
-
const U = () => k || T,
|
|
830
|
-
return setTimeout(() => T = !0, 50), _e(() => k = p?.isCollapsed,
|
|
829
|
+
const U = () => k || T, P = 1;
|
|
830
|
+
return setTimeout(() => T = !0, 50), _e(() => k = p?.isCollapsed, P, U);
|
|
831
831
|
}, O = (p) => {
|
|
832
832
|
document.getSelection()?.isCollapsed || ((!g || g.selector.length === 0) && L(p), g && (F(), o.userSelect(g.annotation, J(p))));
|
|
833
|
-
},
|
|
833
|
+
}, D = (p) => {
|
|
834
834
|
y && (p.repeat || p.target instanceof Node && W(e, p.target) && p.target !== document.body || p.key === "Shift" && g && (document.getSelection().isCollapsed || (F(), o.userSelect(g.annotation, G(p)))));
|
|
835
835
|
}, X = (p) => {
|
|
836
836
|
const T = () => setTimeout(() => {
|
|
@@ -864,9 +864,9 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
864
864
|
(!T || !k || T < k) && s.updateTarget(g);
|
|
865
865
|
}
|
|
866
866
|
};
|
|
867
|
-
return document.addEventListener("pointerdown", A), document.addEventListener("pointerup", v), document.addEventListener("contextmenu", O), document.addEventListener("keyup",
|
|
867
|
+
return document.addEventListener("pointerdown", A), document.addEventListener("pointerup", v), document.addEventListener("contextmenu", O), document.addEventListener("keyup", D), e.addEventListener("selectstart", C), document.addEventListener("selectionchange", L), {
|
|
868
868
|
destroy: () => {
|
|
869
|
-
g = void 0, x = void 0, R = void 0, b = void 0, L.clear(), document.removeEventListener("pointerdown", A), document.removeEventListener("pointerup", v), document.removeEventListener("contextmenu", O), document.removeEventListener("keyup",
|
|
869
|
+
g = void 0, x = void 0, R = void 0, b = void 0, L.clear(), document.removeEventListener("pointerdown", A), document.removeEventListener("pointerup", v), document.removeEventListener("contextmenu", O), document.removeEventListener("keyup", D), e.removeEventListener("selectstart", C), document.removeEventListener("selectionchange", L), q.unbind();
|
|
870
870
|
},
|
|
871
871
|
setFilter: E,
|
|
872
872
|
setUser: m,
|
|
@@ -877,8 +877,8 @@ const fe = "not-annotatable", $ = `.${fe}`, W = (e, t) => e.contains(t) ? !!(t i
|
|
|
877
877
|
...e,
|
|
878
878
|
annotatingEnabled: e.annotatingEnabled ?? t.annotatingEnabled,
|
|
879
879
|
user: e.user || t.user
|
|
880
|
-
}), le = "SPANS",
|
|
881
|
-
|
|
880
|
+
}), le = "SPANS", Pt = (e, t = {}) => {
|
|
881
|
+
Pe(e), He(e);
|
|
882
882
|
const n = St(t, {
|
|
883
883
|
annotatingEnabled: !0,
|
|
884
884
|
user: Le()
|
|
@@ -935,7 +935,7 @@ export {
|
|
|
935
935
|
Ut as Origin,
|
|
936
936
|
Kt as UserSelectAction,
|
|
937
937
|
_t as W3CTextFormat,
|
|
938
|
-
|
|
938
|
+
Pe as cancelSingleClickEvents,
|
|
939
939
|
G as cloneKeyboardEvent,
|
|
940
940
|
J as clonePointerEvent,
|
|
941
941
|
se as createBaseRenderer,
|
|
@@ -946,12 +946,12 @@ export {
|
|
|
946
946
|
st as createRenderer,
|
|
947
947
|
Ct as createSelectionHandler,
|
|
948
948
|
dt as createSpansRenderer,
|
|
949
|
-
|
|
949
|
+
Pt as createTextAnnotator,
|
|
950
950
|
bt as createTextAnnotatorState,
|
|
951
951
|
ee as debounce,
|
|
952
952
|
St as fillDefaults,
|
|
953
953
|
it as getBackgroundColor,
|
|
954
|
-
|
|
954
|
+
De as getHighlightClientRects,
|
|
955
955
|
We as getQuoteContext,
|
|
956
956
|
oe as getRangeAnnotatableContents,
|
|
957
957
|
Qe as getViewportBounds,
|
|
@@ -965,7 +965,7 @@ export {
|
|
|
965
965
|
Xe as mergeRanges,
|
|
966
966
|
at as paint,
|
|
967
967
|
gt as parseW3CTextAnnotation,
|
|
968
|
-
|
|
968
|
+
He as programmaticallyFocusable,
|
|
969
969
|
ze as rangeToSelector,
|
|
970
970
|
te as reviveAnnotation,
|
|
971
971
|
he as reviveSelector,
|