@recogito/text-annotator 4.1.1 → 4.2.1
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/index.d.ts +1 -1
- package/dist/model/core/text-annotation.d.ts +44 -15
- package/dist/model/w3c/w3c-text-format-adapter.d.ts +5 -5
- package/dist/rendering/base-renderer.d.ts +1 -1
- package/dist/rendering/highlight-style.d.ts +7 -4
- package/dist/rendering/highlight.d.ts +2 -2
- package/dist/rendering/renderer-css-highlight/css-highlight-renderer.d.ts +2 -2
- package/dist/selection-handler.d.ts +2 -2
- package/dist/state/spatial-tree.d.ts +7 -7
- package/dist/state/text-annotation-store.d.ts +5 -5
- package/dist/state/text-annotator-state.d.ts +2 -2
- package/dist/text-annotator-options.d.ts +7 -2
- package/dist/text-annotator.d.ts +1 -1
- package/dist/text-annotator.es.js +491 -476
- 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/dist/utils/annotation/range-to-selector.d.ts +2 -2
- package/dist/utils/annotation/revive-annotation.d.ts +4 -5
- package/dist/utils/annotation/scroll-into-view.d.ts +2 -2
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export * from './utils/highlight';
|
|
|
8
8
|
export * from './selection-handler';
|
|
9
9
|
export * from './text-annotator';
|
|
10
10
|
export * from './text-annotator-options';
|
|
11
|
-
export type { Annotation, AnnotationBody, AnnotationTarget, Annotator, AnnotatorState,
|
|
11
|
+
export type { Annotation, AnnotationBody, AnnotationTarget, Annotator, AnnotatorState, Filter, FormatAdapter, HoverState, Selection, SelectionState, Store, StoreChangeEvent, StoreObserver, ParseResult, User, UserSelectActionExpression, ViewportState, W3CAnnotation, W3CAnnotationBody, W3CAnnotationTarget } from '@annotorious/core';
|
|
12
12
|
export { createBody, Origin, UserSelectAction } from '@annotorious/core';
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import type { Annotation, AnnotationTarget } from '@annotorious/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end: number;
|
|
13
|
-
range: Range;
|
|
14
|
-
offsetReference?: HTMLElement;
|
|
15
|
-
}
|
|
2
|
+
/**
|
|
3
|
+
* The Text Annotator model is becoming slightly complex. But it seems
|
|
4
|
+
* justified since we need to dealing with two orthogonal issues:
|
|
5
|
+
*
|
|
6
|
+
* - Annotations come in "revived" and "unrevived" states (with or without
|
|
7
|
+
* resolved DOM elements: Range and offset element)
|
|
8
|
+
* - Annotations can be "plain" HTML/text annotations with `start` and `end`
|
|
9
|
+
* character offset fields, or annotations from extensions (TEI/XML, PDF)
|
|
10
|
+
* which handle the serializable anchoring differently (XPath, pages)
|
|
11
|
+
*/
|
|
16
12
|
export interface TextAnnotationLike extends Annotation {
|
|
17
13
|
target: TextAnnotationTargetLike;
|
|
18
14
|
}
|
|
@@ -22,6 +18,39 @@ export interface TextAnnotationTargetLike extends AnnotationTarget {
|
|
|
22
18
|
export interface TextSelectorLike {
|
|
23
19
|
id?: string;
|
|
24
20
|
quote: string;
|
|
25
|
-
range: Range;
|
|
26
21
|
offsetReference?: HTMLElement;
|
|
27
22
|
}
|
|
23
|
+
export interface RevivedTextSelectorLike extends TextSelectorLike {
|
|
24
|
+
range: Range;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Core classes - this is what most parts of the core deal with:
|
|
28
|
+
* a TextAnnotationLike with all-revived selectors
|
|
29
|
+
*/
|
|
30
|
+
export type RevivedTextAnnotationLike<T extends TextAnnotationLike = TextAnnotationLike> = T & {
|
|
31
|
+
target: RevivedTextAnnotationTargetLike<T['target']>;
|
|
32
|
+
};
|
|
33
|
+
export type RevivedTextAnnotationTargetLike<T extends TextAnnotationTargetLike = TextAnnotationTargetLike> = Omit<T, 'selector'> & {
|
|
34
|
+
selector: RevivedTextSelectorLike[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Default specialization of TextAnnotationLike
|
|
38
|
+
*/
|
|
39
|
+
export interface TextAnnotation extends TextAnnotationLike {
|
|
40
|
+
target: TextAnnotationTarget;
|
|
41
|
+
}
|
|
42
|
+
export interface TextAnnotationTarget extends TextAnnotationTargetLike {
|
|
43
|
+
selector: TextSelector[];
|
|
44
|
+
}
|
|
45
|
+
export interface TextSelector extends TextSelectorLike {
|
|
46
|
+
start: number;
|
|
47
|
+
end: number;
|
|
48
|
+
}
|
|
49
|
+
export type RevivedTextSelector = TextSelector & RevivedTextSelectorLike;
|
|
50
|
+
/**
|
|
51
|
+
* Utility type guards
|
|
52
|
+
*/
|
|
53
|
+
export declare const isRevivedAnnotation: (annotation: TextAnnotationLike) => annotation is RevivedTextAnnotationLike;
|
|
54
|
+
export declare const isRevivedTarget: (target: TextAnnotationTargetLike) => target is RevivedTextAnnotationTargetLike;
|
|
55
|
+
export declare function isRevived(selector: TextSelectorLike): selector is RevivedTextSelectorLike;
|
|
56
|
+
export declare function isRevived(selectors: TextSelectorLike[]): selectors is RevivedTextSelectorLike[];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TextAnnotationLike } from '../core';
|
|
2
2
|
import type { W3CTextAnnotation } from './';
|
|
3
3
|
import { type FormatAdapter, type ParseResult } from '@annotorious/core';
|
|
4
|
-
export type W3CTextFormatAdapter<I extends
|
|
4
|
+
export type W3CTextFormatAdapter<I extends TextAnnotationLike = TextAnnotationLike, E extends W3CTextAnnotation = W3CTextAnnotation> = FormatAdapter<I, E>;
|
|
5
5
|
/**
|
|
6
6
|
* @param source - the IRI of the annotated content
|
|
7
7
|
* @param container - the HTML container of the annotated content,
|
|
8
8
|
* Required to locate the content's `range` within the DOM
|
|
9
9
|
*/
|
|
10
|
-
export declare const W3CTextFormat: <I extends
|
|
11
|
-
export declare const parseW3CTextAnnotation: <I extends
|
|
12
|
-
export declare const serializeW3CTextAnnotation: <I extends
|
|
10
|
+
export declare const W3CTextFormat: <I extends TextAnnotationLike = TextAnnotationLike, E extends W3CTextAnnotation = W3CTextAnnotation>(source: string, container?: HTMLElement) => W3CTextFormatAdapter<I, E>;
|
|
11
|
+
export declare const parseW3CTextAnnotation: <I extends TextAnnotationLike = TextAnnotationLike, E extends W3CTextAnnotation = W3CTextAnnotation>(annotation: E) => ParseResult<I>;
|
|
12
|
+
export declare const serializeW3CTextAnnotation: <I extends TextAnnotationLike = TextAnnotationLike, E extends W3CTextAnnotation = W3CTextAnnotation>(annotation: I, source: string, container?: HTMLElement) => E;
|
|
@@ -10,7 +10,7 @@ export interface Renderer {
|
|
|
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<I extends TextAnnotationLike = TextAnnotationLike>(style?: HighlightStyleExpression<I>, id?: string): void;
|
|
14
14
|
setFilter(filter?: Filter<any>): void;
|
|
15
15
|
setVisible(visible: boolean): void;
|
|
16
16
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type { AnnotationState
|
|
1
|
+
import type { AnnotationState } from '@annotorious/core';
|
|
2
2
|
import type { TextAnnotationLike } from '../model';
|
|
3
3
|
import type { Highlight } from './';
|
|
4
|
-
export
|
|
4
|
+
export type CSSColor = string;
|
|
5
|
+
export interface HighlightStyle {
|
|
6
|
+
fill?: CSSColor;
|
|
7
|
+
fillOpacity?: number;
|
|
5
8
|
underlineStyle?: string;
|
|
6
|
-
underlineColor?:
|
|
9
|
+
underlineColor?: CSSColor;
|
|
7
10
|
underlineOffset?: number;
|
|
8
11
|
underlineThickness?: number;
|
|
9
12
|
}
|
|
10
|
-
export type HighlightStyleExpression
|
|
13
|
+
export type HighlightStyleExpression<I extends TextAnnotationLike = TextAnnotationLike> = HighlightStyle | ((annotation: I, state: AnnotationState, zIndex?: number) => HighlightStyle | undefined);
|
|
11
14
|
export declare const DEFAULT_STYLE: HighlightStyle;
|
|
12
15
|
export declare const DEFAULT_SELECTED_STYLE: HighlightStyle;
|
|
13
16
|
export declare const getBackgroundColor: (style?: HighlightStyle) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnnotationState } from '@annotorious/core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RevivedTextAnnotationLike } from '../model';
|
|
3
3
|
import type { AnnotationRects } from '../state';
|
|
4
|
-
export interface Highlight extends AnnotationRects<
|
|
4
|
+
export interface Highlight extends AnnotationRects<RevivedTextAnnotationLike> {
|
|
5
5
|
state: AnnotationState;
|
|
6
6
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TextAnnotationLike } from '../../model';
|
|
2
2
|
import { type Painter, type RendererFactory } from '../';
|
|
3
3
|
/**
|
|
4
4
|
* EXPERIMENTAL!
|
|
5
5
|
*/
|
|
6
6
|
export declare const createCSSHighlightPainter: () => Painter;
|
|
7
|
-
export declare const createCSSHighlightRenderer: RendererFactory<
|
|
7
|
+
export declare const createCSSHighlightRenderer: RendererFactory<TextAnnotationLike>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Filter, Lifecycle, User } from '@annotorious/core';
|
|
2
2
|
import type { TextAnnotatorState } from './state';
|
|
3
|
-
import type {
|
|
3
|
+
import type { RevivedTextAnnotationLike, TextAnnotationLike } from './model';
|
|
4
4
|
import type { AnnotatingMode } from './text-annotator';
|
|
5
5
|
import type { TextAnnotatorOptions } from './text-annotator-options';
|
|
6
|
-
export declare const createSelectionHandler:
|
|
6
|
+
export declare const createSelectionHandler: (container: HTMLElement, state: TextAnnotatorState<RevivedTextAnnotationLike, any>, lifecycle: Lifecycle<TextAnnotationLike, any>, options: TextAnnotatorOptions<TextAnnotationLike, any>) => {
|
|
7
7
|
destroy: () => void;
|
|
8
8
|
setFilter: (filter?: Filter<any>) => Filter<any>;
|
|
9
9
|
setUser: (user?: User) => User;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Store } from '@annotorious/core';
|
|
2
2
|
import { type Unsubscribe } from 'nanoevents';
|
|
3
|
-
import type { TextAnnotationLike, TextAnnotationTarget } from '../model';
|
|
4
3
|
import type { AnnotationRects } from '../state/text-annotation-store';
|
|
4
|
+
import type { RevivedTextAnnotationLike, RevivedTextSelectorLike, TextAnnotationLike, TextAnnotationTargetLike } from '../model';
|
|
5
5
|
interface IndexedHighlightRect {
|
|
6
6
|
minX: number;
|
|
7
7
|
minY: number;
|
|
@@ -15,19 +15,19 @@ interface IndexedHighlightRect {
|
|
|
15
15
|
export interface SpatialTreeEvents {
|
|
16
16
|
recalculate(): void;
|
|
17
17
|
}
|
|
18
|
-
export declare const createSpatialTree: <T extends TextAnnotationLike>(store: Store<T>, container: HTMLElement, hMergeTolerance?: number, vMergeTolerance?: number) => {
|
|
18
|
+
export declare const createSpatialTree: <T extends TextAnnotationLike>(store: Store<T>, container: HTMLElement, hMergeTolerance?: number, vMergeTolerance?: number, selectorReviveFn?: (arg: T["target"]["selector"][number], container: HTMLElement) => RevivedTextSelectorLike) => {
|
|
19
19
|
all: () => IndexedHighlightRect[][];
|
|
20
20
|
clear: () => void;
|
|
21
21
|
getAt: (x: number, y: number, all?: boolean) => string[];
|
|
22
22
|
getAnnotationBounds: (id: string) => DOMRect | undefined;
|
|
23
23
|
getAnnotationRects: (id: string) => DOMRect[];
|
|
24
|
-
getIntersecting: (minX: number, minY: number, maxX: number, maxY: number) => AnnotationRects<T
|
|
25
|
-
insert: (target:
|
|
24
|
+
getIntersecting: (minX: number, minY: number, maxX: number, maxY: number) => AnnotationRects<RevivedTextAnnotationLike<T>>[];
|
|
25
|
+
insert: (target: TextAnnotationTargetLike) => void;
|
|
26
26
|
recalculate: () => void;
|
|
27
|
-
remove: (target:
|
|
28
|
-
set: (targets:
|
|
27
|
+
remove: (target: TextAnnotationTargetLike) => void;
|
|
28
|
+
set: (targets: TextAnnotationTargetLike[], replace?: boolean) => void;
|
|
29
29
|
size: () => number;
|
|
30
|
-
update: (target:
|
|
30
|
+
update: (target: TextAnnotationTargetLike) => void;
|
|
31
31
|
on: <E extends keyof SpatialTreeEvents>(event: E, callback: SpatialTreeEvents[E]) => Unsubscribe;
|
|
32
32
|
};
|
|
33
33
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Unsubscribe } from 'nanoevents';
|
|
2
2
|
import type { Filter, Origin, Store } from '@annotorious/core';
|
|
3
|
-
import type { TextAnnotation, TextAnnotationLike } from '../model';
|
|
3
|
+
import type { RevivedTextAnnotationLike, TextAnnotation, TextAnnotationLike } from '../model';
|
|
4
4
|
import type { SpatialTreeEvents } from '../state/spatial-tree';
|
|
5
5
|
export interface TextAnnotationStore<T extends TextAnnotationLike = TextAnnotation> extends Omit<Store<T>, 'addAnnotation' | 'bulkAddAnnotations' | 'bulkUpsertAnnotations'> {
|
|
6
6
|
addAnnotation(annotation: T, origin?: Origin): boolean;
|
|
@@ -9,10 +9,10 @@ export interface TextAnnotationStore<T extends TextAnnotationLike = TextAnnotati
|
|
|
9
9
|
getAnnotationRects(id: string): DOMRect[];
|
|
10
10
|
getAnnotationBounds(id: string): DOMRect | undefined;
|
|
11
11
|
getAnnotationRects(id: string): DOMRect[];
|
|
12
|
-
getAt(x: number, y: number, all: true, filter?: Filter): T[] | undefined;
|
|
13
|
-
getAt(x: number, y: number, all: false, filter?: Filter): T | undefined;
|
|
14
|
-
getAt(x: number, y: number, all?: boolean, filter?: Filter): T | T[] | undefined;
|
|
15
|
-
getIntersecting(minX: number, minY: number, maxX: number, maxY: number): AnnotationRects<T
|
|
12
|
+
getAt(x: number, y: number, all: true, filter?: Filter): RevivedTextAnnotationLike<T>[] | undefined;
|
|
13
|
+
getAt(x: number, y: number, all: false, filter?: Filter): RevivedTextAnnotationLike<T> | undefined;
|
|
14
|
+
getAt(x: number, y: number, all?: boolean, filter?: Filter): RevivedTextAnnotationLike<T> | RevivedTextAnnotationLike<T>[] | undefined;
|
|
15
|
+
getIntersecting(minX: number, minY: number, maxX: number, maxY: number): AnnotationRects<RevivedTextAnnotationLike<T>>[];
|
|
16
16
|
recalculatePositions(): void;
|
|
17
17
|
onRecalculatePositions(callback: SpatialTreeEvents['recalculate']): Unsubscribe;
|
|
18
18
|
}
|
|
@@ -3,10 +3,10 @@ import type { AnnotatorState, SelectionState, HoverState } from '@annotorious/co
|
|
|
3
3
|
import type { TextAnnotation, TextAnnotationLike } from '../model';
|
|
4
4
|
import type { TextAnnotationStore } from '../state/text-annotation-store';
|
|
5
5
|
import type { TextAnnotatorOptions } from '../text-annotator-options';
|
|
6
|
-
export interface TextAnnotatorState<I extends TextAnnotationLike =
|
|
6
|
+
export interface TextAnnotatorState<I extends TextAnnotationLike = TextAnnotationLike, E extends unknown = TextAnnotation> extends Omit<AnnotatorState<I, E>, 'store'> {
|
|
7
7
|
store: TextAnnotationStore<I>;
|
|
8
8
|
selection: SelectionState<I, E>;
|
|
9
9
|
hover: HoverState<I>;
|
|
10
10
|
viewport: ViewportState;
|
|
11
11
|
}
|
|
12
|
-
export declare const createTextAnnotatorState: <I extends
|
|
12
|
+
export declare const createTextAnnotatorState: <I extends TextAnnotationLike = TextAnnotation, E extends unknown = TextAnnotation>(container: HTMLElement, opts: TextAnnotatorOptions<I, E>) => TextAnnotatorState<I, E>;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { FormatAdapter, UserSelectActionExpression, User } from '@annotorious/core';
|
|
2
2
|
import type { HighlightStyleExpression, RendererFactory } from './rendering';
|
|
3
|
-
import type { TextAnnotation, TextAnnotationLike } from './model';
|
|
3
|
+
import type { RevivedTextSelectorLike, TextAnnotation, TextAnnotationLike } from './model';
|
|
4
4
|
export interface TextAnnotatorOptions<I extends TextAnnotationLike = TextAnnotation, E extends unknown = TextAnnotation> {
|
|
5
5
|
adapter?: FormatAdapter<I, E>;
|
|
6
6
|
allowModifierSelect?: boolean;
|
|
7
7
|
annotatingEnabled?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Custom function that turns a stored selector into a revived one (with a live DOM `range`).
|
|
10
|
+
* Used by sub-formats such as PDF to map their selector shape to a text range.
|
|
11
|
+
*/
|
|
12
|
+
selectorReviveFn?: (arg: I['target']['selector'][number], container: HTMLElement) => RevivedTextSelectorLike;
|
|
8
13
|
/**
|
|
9
14
|
* Determines whether an active selection should be dismissed
|
|
10
15
|
* when a user ends their interaction (click, selection)
|
|
@@ -24,7 +29,7 @@ export interface TextAnnotatorOptions<I extends TextAnnotationLike = TextAnnotat
|
|
|
24
29
|
offsetReferenceSelector?: string;
|
|
25
30
|
renderer?: RendererType | RendererFactory<I>;
|
|
26
31
|
selectionMode?: 'shortest' | 'all';
|
|
27
|
-
style?: HighlightStyleExpression
|
|
32
|
+
style?: HighlightStyleExpression<I>;
|
|
28
33
|
user?: User;
|
|
29
34
|
userSelectAction?: UserSelectActionExpression<E>;
|
|
30
35
|
}
|
package/dist/text-annotator.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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
9
|
renderer: Renderer;
|
|
10
|
-
setStyle(style?: HighlightStyleExpression
|
|
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;
|