@soomo/text-annotator 4.1.1-staging.0 → 4.1.2-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.
- package/dist/model/w3c/w3c-text-annotation.d.ts +0 -2
- package/dist/rendering/base-renderer.d.ts +8 -8
- package/dist/rendering/highlight-style.d.ts +2 -2
- package/dist/text-annotator-options.d.ts +1 -1
- package/dist/text-annotator.d.ts +2 -2
- package/dist/text-annotator.es.js +20 -19
- package/dist/text-annotator.es.js.map +1 -1
- package/dist/text-annotator.umd.js +2 -2
- package/dist/text-annotator.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,8 +7,6 @@ export interface W3CTextAnnotationTarget extends W3CAnnotationTarget {
|
|
|
7
7
|
selector: W3CTextSelector | W3CTextSelector[];
|
|
8
8
|
styleClass?: string;
|
|
9
9
|
scope?: string;
|
|
10
|
-
outdated?: boolean;
|
|
11
|
-
migrationPending?: boolean;
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
14
12
|
* Matches the `Text Quote Selector` spec
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { type Unsubscribe } from 'nanoevents';
|
|
2
|
-
import { type
|
|
3
|
-
import type { TextAnnotation } from '../model';
|
|
2
|
+
import { type AnnotatorState, type Filter, type ViewportState } from '@annotorious/core';
|
|
3
|
+
import type { TextAnnotation, TextAnnotationLike } from '../model';
|
|
4
4
|
import type { TextAnnotatorState } from '../state';
|
|
5
5
|
import { type Highlight, type HighlightStyleExpression, type ViewportBounds } from './';
|
|
6
6
|
/**
|
|
7
7
|
* The renderer runtime interface.
|
|
8
8
|
*/
|
|
9
|
-
export interface Renderer {
|
|
9
|
+
export interface Renderer<I extends TextAnnotationLike = TextAnnotation> {
|
|
10
10
|
destroy(): void;
|
|
11
11
|
on: <E extends keyof RendererEvents>(event: E, callback: RendererEvents[E]) => Unsubscribe;
|
|
12
12
|
redraw(force?: boolean): void;
|
|
13
|
-
setStyle(style?: HighlightStyleExpression
|
|
13
|
+
setStyle(style?: HighlightStyleExpression<I>, id?: string): void;
|
|
14
14
|
setFilter(filter?: Filter<any>): void;
|
|
15
15
|
setVisible(visible: boolean): void;
|
|
16
16
|
}
|
|
17
17
|
export interface RendererEvents {
|
|
18
18
|
onRedraw(): void;
|
|
19
19
|
}
|
|
20
|
-
export type RendererFactory<T extends
|
|
20
|
+
export type RendererFactory<T extends TextAnnotationLike> = (container: HTMLElement, state: AnnotatorState<T, any>, viewport: ViewportState) => Renderer<T>;
|
|
21
21
|
/**
|
|
22
22
|
* A utility interface. Instead of implementing a Renderer from scratch,
|
|
23
23
|
* implementers can simply implement a painter, and wrap it in the
|
|
24
24
|
* BaseRenderer, which will handle common concerns.
|
|
25
25
|
*/
|
|
26
|
-
export interface Painter {
|
|
26
|
+
export interface Painter<I extends TextAnnotationLike = TextAnnotation> {
|
|
27
27
|
destroy(): void;
|
|
28
|
-
redraw(highlights: Highlight[], bounds: ViewportBounds, style?: HighlightStyleExpression
|
|
28
|
+
redraw(highlights: Highlight[], bounds: ViewportBounds, style?: HighlightStyleExpression<I>, styleOverrides?: Map<string, HighlightStyleExpression<I>>, force?: boolean): void;
|
|
29
29
|
setVisible(visible: boolean): void;
|
|
30
30
|
}
|
|
31
|
-
export declare const createRenderer: <T extends TextAnnotatorState = TextAnnotatorState<TextAnnotation, any
|
|
31
|
+
export declare const createRenderer: <T extends TextAnnotatorState = TextAnnotatorState<TextAnnotation, any>, I extends TextAnnotationLike = TextAnnotation>(painter: Painter<I>, container: HTMLElement, state: T, viewport: ViewportState) => Renderer<I>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnnotationState, Color, DrawingStyle } from '@annotorious/core';
|
|
2
|
-
import type { TextAnnotation } from '../model';
|
|
2
|
+
import type { TextAnnotation, TextAnnotationLike } from '../model';
|
|
3
3
|
import type { Highlight } from './';
|
|
4
4
|
export interface HighlightStyle extends Pick<DrawingStyle, 'fill' | 'fillOpacity'> {
|
|
5
5
|
underlineStyle?: string;
|
|
@@ -7,7 +7,7 @@ export interface HighlightStyle extends Pick<DrawingStyle, 'fill' | 'fillOpacity
|
|
|
7
7
|
underlineOffset?: number;
|
|
8
8
|
underlineThickness?: number;
|
|
9
9
|
}
|
|
10
|
-
export type HighlightStyleExpression
|
|
10
|
+
export type HighlightStyleExpression<I extends TextAnnotationLike = TextAnnotation> = HighlightStyle | ((annotation: I, state: AnnotationState, zIndex?: number) => HighlightStyle | undefined);
|
|
11
11
|
export declare const DEFAULT_STYLE: HighlightStyle;
|
|
12
12
|
export declare const DEFAULT_SELECTED_STYLE: HighlightStyle;
|
|
13
13
|
export declare const getBackgroundColor: (style?: HighlightStyle) => string;
|
|
@@ -24,7 +24,7 @@ export interface TextAnnotatorOptions<I extends TextAnnotationLike = TextAnnotat
|
|
|
24
24
|
offsetReferenceSelector?: string;
|
|
25
25
|
renderer?: RendererType | RendererFactory<I>;
|
|
26
26
|
selectionMode?: 'shortest' | 'all';
|
|
27
|
-
style?: HighlightStyleExpression
|
|
27
|
+
style?: HighlightStyleExpression<I>;
|
|
28
28
|
user?: User;
|
|
29
29
|
userSelectAction?: UserSelectActionExpression<E>;
|
|
30
30
|
}
|
package/dist/text-annotator.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { type TextAnnotatorOptions } from './text-annotator-options';
|
|
|
6
6
|
import './text-annotator.css';
|
|
7
7
|
export interface TextAnnotator<I extends TextAnnotationLike = TextAnnotation, E extends unknown = TextAnnotation> extends Omit<Annotator<I, E>, 'setStyle' | 'state'> {
|
|
8
8
|
element: HTMLElement;
|
|
9
|
-
renderer: Renderer
|
|
10
|
-
setStyle(style?: HighlightStyleExpression
|
|
9
|
+
renderer: Renderer<I>;
|
|
10
|
+
setStyle(style?: HighlightStyleExpression<I>, id?: string): void;
|
|
11
11
|
scrollIntoView(annotationOrId: I | string, scrollParentOrId?: string | Element): boolean;
|
|
12
12
|
setAnnotatingEnabled(enabled?: boolean): void;
|
|
13
13
|
setAnnotatingMode(mode?: AnnotatingMode): void;
|
|
@@ -11,7 +11,7 @@ import { poll as Dt } from "poll";
|
|
|
11
11
|
const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft = "not-annotatable", $ = `.${ft}`, W = (t, e) => t.contains(e) ? !!(e instanceof HTMLElement ? e.closest($) : e.parentElement?.closest($)) : !0, gt = (t, e) => {
|
|
12
12
|
const o = e.commonAncestorContainer;
|
|
13
13
|
return !W(t, o);
|
|
14
|
-
}, mt = /^\s*$/,
|
|
14
|
+
}, mt = /^\s*$/, Ht = (t) => mt.test(t.toString()), we = (t) => mt.test(t.textContent || ""), Pt = (t) => {
|
|
15
15
|
if (t.length === 0) return [];
|
|
16
16
|
if (t.length === 1) return [t[0]];
|
|
17
17
|
t.sort((s, n) => {
|
|
@@ -156,7 +156,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
156
156
|
}
|
|
157
157
|
return E;
|
|
158
158
|
}, {});
|
|
159
|
-
if (
|
|
159
|
+
if (Vt(g))
|
|
160
160
|
a.selector.push(
|
|
161
161
|
{
|
|
162
162
|
...g,
|
|
@@ -293,11 +293,11 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
293
293
|
e.addEventListener("pointermove", h);
|
|
294
294
|
const A = tt((S = !1) => requestAnimationFrame(() => {
|
|
295
295
|
const C = ie(e), { minX: O, minY: B, maxX: V, maxY: z } = C, K = g ? s.getIntersecting(O, B, V, z).filter(({ annotation: y }) => g?.(y)) : s.getIntersecting(O, B, V, z), st = n.selected.map(({ id: y }) => y), f = K.map(({ annotation: y, rects: M }) => {
|
|
296
|
-
const
|
|
296
|
+
const U = st.includes(y.id), _ = y.id === r.current;
|
|
297
297
|
return {
|
|
298
298
|
annotation: y,
|
|
299
299
|
rects: M,
|
|
300
|
-
state: { selected:
|
|
300
|
+
state: { selected: U, hovered: _ }
|
|
301
301
|
};
|
|
302
302
|
});
|
|
303
303
|
t.redraw(f, C, l, m, S), setTimeout(() => {
|
|
@@ -338,13 +338,13 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
338
338
|
setFilter: L,
|
|
339
339
|
setVisible: t.setVisible.bind(t)
|
|
340
340
|
};
|
|
341
|
-
},
|
|
341
|
+
}, P = {
|
|
342
342
|
fill: "rgb(0, 128, 255)",
|
|
343
343
|
fillOpacity: 0.18
|
|
344
344
|
}, ot = {
|
|
345
345
|
fill: "rgb(0, 128, 255)",
|
|
346
346
|
fillOpacity: 0.45
|
|
347
|
-
}, Qt = (t) => t?.fillOpacity !== void 0 ? et(t?.fill ||
|
|
347
|
+
}, Qt = (t) => t?.fillOpacity !== void 0 ? et(t?.fill || P.fill).alpha(t.fillOpacity).toHex() : t?.fill ? t.fill : et(P.fill).alpha(P.fillOpacity).toHex(), St = (t, e, o) => e ? typeof e == "function" ? e(t.annotation, t.state, o) || (t.state?.selected ? ot : P) : e : t.state?.selected ? ot : P, Zt = (t, e) => {
|
|
348
348
|
const o = (n, r) => n.x <= r.x + r.width && n.x + n.width >= r.x && n.y <= r.y + r.height && n.y + n.height >= r.y, i = (n) => n.rects.reduce((r, a) => r + a.width, 0), s = e.filter(({ rects: n }) => n.some((r) => o(t, r)));
|
|
349
349
|
return s.sort((n, r) => i(r) - i(n)), s.findIndex((n) => n.rects.includes(t));
|
|
350
350
|
}, Jt = (t) => {
|
|
@@ -661,22 +661,23 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
661
661
|
if (!h) return;
|
|
662
662
|
const y = document.getSelection();
|
|
663
663
|
if (!y?.anchorNode) return;
|
|
664
|
-
const
|
|
665
|
-
if (
|
|
664
|
+
const M = Array.from(Array(y.rangeCount).keys()).map((k) => y.getRangeAt(k));
|
|
665
|
+
if (M.every((k) => !gt(t, k))) {
|
|
666
666
|
d = void 0;
|
|
667
667
|
return;
|
|
668
668
|
}
|
|
669
|
-
const
|
|
670
|
-
if (v?.type === "pointerdown" && (
|
|
669
|
+
const U = f.timeStamp - (v?.timeStamp || f.timeStamp);
|
|
670
|
+
if (v?.type === "pointerdown" && (U < 1e3 && !d || y.isCollapsed && U < at) && T(), !d && (T(), !d))
|
|
671
671
|
return;
|
|
672
672
|
if (y.isCollapsed) {
|
|
673
673
|
s.getAnnotation(d.annotation) && !(u(v) || A === "REPLACE_CURRENT") && (n.clear(), s.deleteAnnotation(d.annotation));
|
|
674
674
|
return;
|
|
675
675
|
}
|
|
676
|
-
|
|
677
|
-
|
|
676
|
+
const _ = M.map((k) => Wt(k, t));
|
|
677
|
+
if (_.every((k) => Ht(k))) return;
|
|
678
|
+
const I = _.flatMap((k) => Ft(t, k.cloneRange()));
|
|
678
679
|
if (!(I.length > 0 && !d || I.length !== d.selector.length || I.some((k, Y) => k.toString() !== d?.selector[Y]?.quote))) return;
|
|
679
|
-
const j = u(v) && L ?
|
|
680
|
+
const j = u(v) && L ? Pt([
|
|
680
681
|
...L.selector.map((k) => k.range),
|
|
681
682
|
...I
|
|
682
683
|
]) : I;
|
|
@@ -719,8 +720,8 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
719
720
|
}, C = async () => {
|
|
720
721
|
const f = document.getSelection();
|
|
721
722
|
let y = !1, M = f?.isCollapsed;
|
|
722
|
-
const
|
|
723
|
-
return setTimeout(() => y = !0, 50), Dt(() => M = f?.isCollapsed, _,
|
|
723
|
+
const U = () => M || y, _ = 1;
|
|
724
|
+
return setTimeout(() => y = !0, 50), Dt(() => M = f?.isCollapsed, _, U);
|
|
724
725
|
}, O = (f) => {
|
|
725
726
|
document.getSelection()?.isCollapsed || ((!d || d.selector.length === 0) && R(f), d && (K(), n.userSelect(d.annotation, J(f))));
|
|
726
727
|
}, B = (f) => {
|
|
@@ -771,7 +772,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
771
772
|
setAnnotatingMode: b
|
|
772
773
|
};
|
|
773
774
|
}, fe = (t) => [
|
|
774
|
-
`background-color:${et(t?.fill ||
|
|
775
|
+
`background-color:${et(t?.fill || P.fill).alpha(t?.fillOpacity === void 0 ? P.fillOpacity : t.fillOpacity).toHex()}`,
|
|
775
776
|
t?.underlineThickness ? "text-decoration:underline" : void 0,
|
|
776
777
|
t?.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
777
778
|
t?.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
@@ -873,7 +874,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
873
874
|
};
|
|
874
875
|
export {
|
|
875
876
|
ot as DEFAULT_SELECTED_STYLE,
|
|
876
|
-
|
|
877
|
+
P as DEFAULT_STYLE,
|
|
877
878
|
ft as NOT_ANNOTATABLE_CLASS,
|
|
878
879
|
$ as NOT_ANNOTATABLE_SELECTOR,
|
|
879
880
|
Be as Origin,
|
|
@@ -901,10 +902,10 @@ export {
|
|
|
901
902
|
we as isNodeWhitespaceOrEmpty,
|
|
902
903
|
W as isNotAnnotatable,
|
|
903
904
|
gt as isRangeAnnotatable,
|
|
904
|
-
|
|
905
|
+
Ht as isRangeWhitespaceOrEmpty,
|
|
905
906
|
D as isRevived,
|
|
906
907
|
ne as mergeClientRects,
|
|
907
|
-
|
|
908
|
+
Pt as mergeRanges,
|
|
908
909
|
jt as parseW3CTextAnnotation,
|
|
909
910
|
Ut as programmaticallyFocusable,
|
|
910
911
|
Yt as rangeToSelector,
|