@soomo/text-annotator 4.1.0-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 +16 -16
- 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,
|
|
@@ -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) => {
|
|
@@ -674,10 +674,10 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
674
674
|
return;
|
|
675
675
|
}
|
|
676
676
|
const _ = M.map((k) => Wt(k, t));
|
|
677
|
-
if (_.every((k) =>
|
|
677
|
+
if (_.every((k) => Ht(k))) return;
|
|
678
678
|
const I = _.flatMap((k) => Ft(t, k.cloneRange()));
|
|
679
679
|
if (!(I.length > 0 && !d || I.length !== d.selector.length || I.some((k, Y) => k.toString() !== d?.selector[Y]?.quote))) return;
|
|
680
|
-
const j = u(v) && L ?
|
|
680
|
+
const j = u(v) && L ? Pt([
|
|
681
681
|
...L.selector.map((k) => k.range),
|
|
682
682
|
...I
|
|
683
683
|
]) : I;
|
|
@@ -696,22 +696,22 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
696
696
|
(typeof g == "function" ? g(y, t) : g === "ALWAYS") && n.clear();
|
|
697
697
|
return;
|
|
698
698
|
}
|
|
699
|
-
const
|
|
699
|
+
const H = y.target instanceof Node && t.contains(y.target) && s.getAt(
|
|
700
700
|
y.clientX - _,
|
|
701
701
|
y.clientY - I,
|
|
702
702
|
m === "all",
|
|
703
703
|
E
|
|
704
704
|
);
|
|
705
|
-
if (
|
|
706
|
-
const { selected: j } = n, k = new Set(j.map((X) => X.id)), Y = Array.isArray(
|
|
707
|
-
(k.size !== Y.length || !Y.every((X) => k.has(X))) && (o.emit("clickAnnotation",
|
|
705
|
+
if (H) {
|
|
706
|
+
const { selected: j } = n, k = new Set(j.map((X) => X.id)), Y = Array.isArray(H) ? H.map((X) => X.id) : [H.id];
|
|
707
|
+
(k.size !== Y.length || !Y.every((X) => k.has(X))) && (o.emit("clickAnnotation", H), n.userSelect(Y, y));
|
|
708
708
|
} else
|
|
709
709
|
n.clear();
|
|
710
710
|
};
|
|
711
711
|
if (y.timeStamp - (v?.timeStamp || 0) < at) {
|
|
712
712
|
await C();
|
|
713
|
-
const _ = document.getSelection(), I = W(t, v?.target),
|
|
714
|
-
if (_?.isCollapsed || I &&
|
|
713
|
+
const _ = document.getSelection(), I = W(t, v?.target), H = W(t, y.target);
|
|
714
|
+
if (_?.isCollapsed || I && H) {
|
|
715
715
|
d = void 0, M();
|
|
716
716
|
return;
|
|
717
717
|
}
|
|
@@ -772,7 +772,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
772
772
|
setAnnotatingMode: b
|
|
773
773
|
};
|
|
774
774
|
}, fe = (t) => [
|
|
775
|
-
`background-color:${et(t?.fill ||
|
|
775
|
+
`background-color:${et(t?.fill || P.fill).alpha(t?.fillOpacity === void 0 ? P.fillOpacity : t.fillOpacity).toHex()}`,
|
|
776
776
|
t?.underlineThickness ? "text-decoration:underline" : void 0,
|
|
777
777
|
t?.underlineColor ? `text-decoration-color:${t.underlineColor}` : void 0,
|
|
778
778
|
t?.underlineOffset ? `text-underline-offset:${t.underlineOffset}px` : void 0,
|
|
@@ -874,7 +874,7 @@ const ut = typeof navigator < "u" && navigator.platform.startsWith("Mac"), ft =
|
|
|
874
874
|
};
|
|
875
875
|
export {
|
|
876
876
|
ot as DEFAULT_SELECTED_STYLE,
|
|
877
|
-
|
|
877
|
+
P as DEFAULT_STYLE,
|
|
878
878
|
ft as NOT_ANNOTATABLE_CLASS,
|
|
879
879
|
$ as NOT_ANNOTATABLE_SELECTOR,
|
|
880
880
|
Be as Origin,
|
|
@@ -902,10 +902,10 @@ export {
|
|
|
902
902
|
we as isNodeWhitespaceOrEmpty,
|
|
903
903
|
W as isNotAnnotatable,
|
|
904
904
|
gt as isRangeAnnotatable,
|
|
905
|
-
|
|
905
|
+
Ht as isRangeWhitespaceOrEmpty,
|
|
906
906
|
D as isRevived,
|
|
907
907
|
ne as mergeClientRects,
|
|
908
|
-
|
|
908
|
+
Pt as mergeRanges,
|
|
909
909
|
jt as parseW3CTextAnnotation,
|
|
910
910
|
Ut as programmaticallyFocusable,
|
|
911
911
|
Yt as rangeToSelector,
|