@recogito/text-annotator 3.0.0-rc.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/src/SelectionHandler.d.ts +7 -0
- package/dist/src/TextAnnotator.d.ts +8 -0
- package/dist/src/TextAnnotatorOptions.d.ts +10 -0
- package/dist/src/api/index.d.ts +1 -0
- package/dist/src/api/scrollIntoView.d.ts +3 -0
- package/dist/src/highlight/HighlightPainter.d.ts +20 -0
- package/dist/src/highlight/highlightLayer.d.ts +9 -0
- package/dist/src/highlight/index.d.ts +2 -0
- package/dist/src/highlight/trackViewport.d.ts +3 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/model/TextAnnotation.d.ts +14 -0
- package/dist/src/model/index.d.ts +1 -0
- package/dist/src/presence/PresencePainter.d.ts +4 -0
- package/dist/src/presence/PresencePainterOptions.d.ts +3 -0
- package/dist/src/presence/index.d.ts +2 -0
- package/dist/src/state/TextAnnotationStore.d.ts +21 -0
- package/dist/src/state/TextAnnotatorState.d.ts +11 -0
- package/dist/src/state/index.d.ts +3 -0
- package/dist/src/state/reviveTarget.d.ts +9 -0
- package/dist/src/state/spatialTree.d.ts +26 -0
- package/dist/src/utils/getClientRectsPonyfill.d.ts +1 -0
- package/dist/src/utils/index.d.ts +3 -0
- package/dist/src/utils/mergeClientRects.d.ts +1 -0
- package/dist/src/utils/trimRange.d.ts +1 -0
- package/dist/text-annotator.css +1 -0
- package/dist/text-annotator.es.js +1242 -0
- package/dist/text-annotator.es.js.map +1 -0
- package/dist/text-annotator.umd.js +2 -0
- package/dist/text-annotator.umd.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type User } from '@annotorious/core';
|
|
2
|
+
import type { TextAnnotatorState } from './state';
|
|
3
|
+
import type { TextSelector } from './model';
|
|
4
|
+
export declare const rangeToSelector: (range: Range, container: HTMLElement, offsetReferenceSelector?: string) => TextSelector;
|
|
5
|
+
export declare const SelectionHandler: (container: HTMLElement, state: TextAnnotatorState, offsetReferenceSelector?: string) => {
|
|
6
|
+
setUser: (user: User) => User;
|
|
7
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Annotator } from '@annotorious/core';
|
|
2
|
+
import type { TextAnnotation } from './model';
|
|
3
|
+
import type { TextAnnotatorOptions } from './TextAnnotatorOptions';
|
|
4
|
+
export interface TextAnnotator<T extends unknown = TextAnnotation> extends Annotator<TextAnnotation, T> {
|
|
5
|
+
element: HTMLElement;
|
|
6
|
+
scrollIntoView(annotation: TextAnnotation): boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const createTextAnnotator: <E extends unknown = TextAnnotation>(container: HTMLElement, opts?: TextAnnotatorOptions<E>) => TextAnnotator<E>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DrawingStyle, FormatAdapter, PointerSelectAction } from '@annotorious/core';
|
|
2
|
+
import type { PresencePainterOptions } from './presence';
|
|
3
|
+
import type { TextAnnotation } from './model';
|
|
4
|
+
export interface TextAnnotatorOptions<T extends unknown = TextAnnotation> {
|
|
5
|
+
adapter?: FormatAdapter<TextAnnotation, T> | null;
|
|
6
|
+
offsetReferenceSelector?: string;
|
|
7
|
+
pointerAction?: PointerSelectAction | ((annotation: TextAnnotation) => PointerSelectAction);
|
|
8
|
+
presence?: PresencePainterOptions;
|
|
9
|
+
style?: DrawingStyle | ((annotation: TextAnnotation) => DrawingStyle);
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './scrollIntoView';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DrawingStyle } from '@annotorious/core';
|
|
2
|
+
import type { TextAnnotation } from '../model';
|
|
3
|
+
import type { Rect } from '../state';
|
|
4
|
+
/**
|
|
5
|
+
* A painter implements the actual CANVAS highlight drawing logic.
|
|
6
|
+
*/
|
|
7
|
+
export type HighlightPainter = {
|
|
8
|
+
paint(annotation: TextAnnotation, rects: Rect[], bg: CanvasRenderingContext2D, fg: CanvasRenderingContext2D, isSelected?: boolean, style?: DrawingStyle | ((annotation: TextAnnotation, selected?: boolean) => DrawingStyle)): void;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The default painter.
|
|
12
|
+
*/
|
|
13
|
+
export declare const defaultPainter: HighlightPainter;
|
|
14
|
+
export interface HighlightStyle {
|
|
15
|
+
fill?: string;
|
|
16
|
+
fillOpacity?: number;
|
|
17
|
+
underline?: string;
|
|
18
|
+
underlineOpacity?: number;
|
|
19
|
+
underlineWidth?: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DrawingStyle, ViewportState } from '@annotorious/core';
|
|
2
|
+
import type { TextAnnotation } from '../model';
|
|
3
|
+
import type { TextAnnotatorState } from '../state';
|
|
4
|
+
import { type HighlightPainter } from './HighlightPainter';
|
|
5
|
+
export declare const createHighlightLayer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState) => {
|
|
6
|
+
redraw: () => number;
|
|
7
|
+
setDrawingStyle: (style: DrawingStyle | ((a: TextAnnotation, selected?: boolean) => DrawingStyle)) => void;
|
|
8
|
+
setPainter: (painter: HighlightPainter) => HighlightPainter;
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './highlight';
|
|
2
|
+
export * from './model';
|
|
3
|
+
export * from './state';
|
|
4
|
+
export * from './presence/PresencePainterOptions';
|
|
5
|
+
export * from './TextAnnotator';
|
|
6
|
+
export * from './TextAnnotatorOptions';
|
|
7
|
+
export * from '@annotorious/core/src/model';
|
|
8
|
+
import { Origin as _Origin } from '@annotorious/core/src/state';
|
|
9
|
+
export declare const Origin: typeof _Origin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Annotation, AnnotationTarget } from '@annotorious/core';
|
|
2
|
+
export interface TextAnnotation extends Annotation {
|
|
3
|
+
target: TextAnnotationTarget;
|
|
4
|
+
}
|
|
5
|
+
export interface TextAnnotationTarget extends AnnotationTarget {
|
|
6
|
+
selector: TextSelector;
|
|
7
|
+
}
|
|
8
|
+
export interface TextSelector {
|
|
9
|
+
quote: string;
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
range: Range;
|
|
13
|
+
offsetReference?: HTMLElement;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TextAnnotation';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PresenceProvider } from '@annotorious/core';
|
|
2
|
+
import type { HighlightPainter } from '../highlight';
|
|
3
|
+
import type { PresencePainterOptions } from './PresencePainterOptions';
|
|
4
|
+
export declare const createPainter: (provider: PresenceProvider, opts?: PresencePainterOptions) => HighlightPainter;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Origin, Store } from '@annotorious/core';
|
|
2
|
+
import type { TextAnnotation } from '../model';
|
|
3
|
+
export interface TextAnnotationStore extends Omit<Store<TextAnnotation>, 'addAnnotation' | 'bulkAddAnnotation'> {
|
|
4
|
+
addAnnotation(annotation: TextAnnotation, origin: Origin): boolean;
|
|
5
|
+
bulkAddAnnotation(annotations: TextAnnotation[], replace: boolean, origin: Origin): TextAnnotation[];
|
|
6
|
+
getAnnotationBounds(id: string, hintX?: number, hintY?: number, buffer?: number): DOMRect;
|
|
7
|
+
getAt(x: number, y: number): TextAnnotation | undefined;
|
|
8
|
+
getIntersecting(minX: number, minY: number, maxX: number, maxY: number): TextAnnotation[];
|
|
9
|
+
getIntersectingRects(minX: number, minY: number, maxX: number, maxY: number): AnnotationRects[];
|
|
10
|
+
recalculatePositions(): void;
|
|
11
|
+
}
|
|
12
|
+
export interface AnnotationRects {
|
|
13
|
+
annotation: TextAnnotation;
|
|
14
|
+
rects: Rect[];
|
|
15
|
+
}
|
|
16
|
+
export interface Rect {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PointerSelectAction, ViewportState } from '@annotorious/core';
|
|
2
|
+
import { AnnotatorState, SelectionState, HoverState } from '@annotorious/core';
|
|
3
|
+
import type { TextAnnotation } from '../model';
|
|
4
|
+
import type { TextAnnotationStore } from './TextAnnotationStore';
|
|
5
|
+
export type TextAnnotatorState = AnnotatorState<TextAnnotation> & {
|
|
6
|
+
store: TextAnnotationStore;
|
|
7
|
+
selection: SelectionState<TextAnnotation>;
|
|
8
|
+
hover: HoverState<TextAnnotation>;
|
|
9
|
+
viewport: ViewportState;
|
|
10
|
+
};
|
|
11
|
+
export declare const createTextAnnotatorState: (container: HTMLElement, defaultPointerAction?: PointerSelectAction | ((annotation: TextAnnotation) => PointerSelectAction)) => TextAnnotatorState;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TextAnnotationTarget } from '../model';
|
|
2
|
+
/**
|
|
3
|
+
* Recalculates the DOM range from the given text annotation target.
|
|
4
|
+
*
|
|
5
|
+
* @param annotation the text annotation
|
|
6
|
+
* @param container the HTML container of the annotated content
|
|
7
|
+
* @returns the DOM range
|
|
8
|
+
*/
|
|
9
|
+
export declare const reviveTarget: (target: TextAnnotationTarget, container: HTMLElement) => TextAnnotationTarget;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Store } from '@annotorious/core';
|
|
2
|
+
import type { TextAnnotation, TextAnnotationTarget } from '../model';
|
|
3
|
+
export interface IndexedHighlightRect {
|
|
4
|
+
minX: number;
|
|
5
|
+
minY: number;
|
|
6
|
+
maxX: number;
|
|
7
|
+
maxY: number;
|
|
8
|
+
annotation: {
|
|
9
|
+
id: string;
|
|
10
|
+
rects: DOMRect[];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare const createSpatialTree: (store: Store<TextAnnotation>, container: HTMLElement) => {
|
|
14
|
+
all: () => IndexedHighlightRect[][];
|
|
15
|
+
clear: () => void;
|
|
16
|
+
getAt: (x: number, y: number) => string | undefined;
|
|
17
|
+
getBoundsForAnnotation: (id: string) => DOMRect;
|
|
18
|
+
getDOMRectsForAnnotation: (id: string) => DOMRect[];
|
|
19
|
+
getIntersectingRects: (minX: number, minY: number, maxX: number, maxY: number) => IndexedHighlightRect[];
|
|
20
|
+
insert: (target: TextAnnotationTarget) => void;
|
|
21
|
+
recalculate: () => void;
|
|
22
|
+
remove: (target: TextAnnotationTarget) => void;
|
|
23
|
+
set: (targets: TextAnnotationTarget[], replace?: boolean) => void;
|
|
24
|
+
size: () => number;
|
|
25
|
+
update: (target: TextAnnotationTarget) => void;
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getClientRectsPonyfill: (range: Range) => DOMRect[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mergeClientRects: (rects: DOMRect[]) => DOMRect[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const trimRange: (range: Range) => Range;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
html,body{overscroll-behavior-y:none}.r6o-annotatable,.r6o-annotatable *{position:relative}.r6o-annotatable.hovered{cursor:pointer}.r6o-highlight-layer{height:100vh;left:0;position:fixed;top:0;pointer-events:none;width:100vw}*::selection,::selection{background:rgba(0,128,255,.18)}::-moz-selection{background:rgba(0,128,255,.18)}
|