@recogito/text-annotator 3.3.2 → 3.4.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.
Files changed (56) hide show
  1. package/dist/SelectionHandler.d.ts +10 -0
  2. package/dist/TextAnnotator.d.ts +15 -0
  3. package/dist/TextAnnotatorOptions.d.ts +34 -0
  4. package/dist/api/index.d.ts +1 -0
  5. package/dist/api/scrollIntoView.d.ts +3 -0
  6. package/dist/highlight/Highlight.d.ts +5 -0
  7. package/dist/highlight/HighlightPainter.d.ts +11 -0
  8. package/dist/highlight/HighlightStyle.d.ts +11 -0
  9. package/dist/highlight/baseRenderer.d.ts +20 -0
  10. package/dist/highlight/canvas/canvasRenderer.d.ts +5 -0
  11. package/dist/highlight/canvas/index.d.ts +1 -0
  12. package/dist/highlight/highlights/highlightsRenderer.d.ts +6 -0
  13. package/dist/highlight/highlights/index.d.ts +1 -0
  14. package/dist/highlight/index.d.ts +6 -0
  15. package/dist/highlight/span/color.d.ts +2 -0
  16. package/dist/highlight/span/index.d.ts +1 -0
  17. package/dist/highlight/span/spansRenderer.d.ts +5 -0
  18. package/dist/highlight/viewport.d.ts +12 -0
  19. package/dist/index.d.ts +11 -0
  20. package/dist/model/core/TextAnnotation.d.ts +15 -0
  21. package/dist/model/core/index.d.ts +1 -0
  22. package/dist/model/index.d.ts +2 -0
  23. package/dist/model/w3c/W3CTextAnnotation.d.ts +34 -0
  24. package/dist/model/w3c/W3CTextFormatAdapter.d.ts +12 -0
  25. package/dist/model/w3c/index.d.ts +2 -0
  26. package/dist/presence/PresencePainter.d.ts +5 -0
  27. package/dist/presence/PresencePainterOptions.d.ts +3 -0
  28. package/dist/presence/index.d.ts +2 -0
  29. package/dist/src/utils/isWhitespaceOrEmpty.d.ts +1 -2
  30. package/dist/state/TextAnnotationStore.d.ts +25 -0
  31. package/dist/state/TextAnnotatorState.d.ts +12 -0
  32. package/dist/state/index.d.ts +2 -0
  33. package/dist/state/spatialTree.d.ts +28 -0
  34. package/dist/text-annotator.es.js +603 -579
  35. package/dist/text-annotator.es.js.map +1 -1
  36. package/dist/text-annotator.umd.js +2 -2
  37. package/dist/text-annotator.umd.js.map +1 -1
  38. package/dist/utils/cancelSingleClickEvents.d.ts +6 -0
  39. package/dist/utils/cloneEvents.d.ts +11 -0
  40. package/dist/utils/device.d.ts +1 -0
  41. package/dist/utils/getHighlightClientRects.d.ts +1 -0
  42. package/dist/utils/getQuoteContext.d.ts +4 -0
  43. package/dist/utils/index.d.ts +17 -0
  44. package/dist/utils/isNotAnnotatable.d.ts +4 -0
  45. package/dist/utils/isRevived.d.ts +2 -0
  46. package/dist/utils/isWhitespaceOrEmpty.d.ts +3 -0
  47. package/dist/utils/mergeClientRects.d.ts +2 -0
  48. package/dist/utils/programmaticallyFocusable.d.ts +6 -0
  49. package/dist/utils/rangeToSelector.d.ts +2 -0
  50. package/dist/utils/rectsToBounds.d.ts +8 -0
  51. package/dist/utils/reviveAnnotation.d.ts +2 -0
  52. package/dist/utils/reviveSelector.d.ts +11 -0
  53. package/dist/utils/reviveTarget.d.ts +2 -0
  54. package/dist/utils/splitAnnotatableRanges.d.ts +5 -0
  55. package/dist/utils/trimRangeToContainer.d.ts +1 -0
  56. package/package.json +6 -6
@@ -0,0 +1,10 @@
1
+ import { type Filter, type User } from '@annotorious/core';
2
+ import type { TextAnnotatorState } from './state';
3
+ import type { TextAnnotation } from './model';
4
+ import type { TextAnnotatorOptions } from './TextAnnotatorOptions';
5
+ export declare const createSelectionHandler: (container: HTMLElement, state: TextAnnotatorState<TextAnnotation, unknown>, options: TextAnnotatorOptions<TextAnnotation, unknown>) => {
6
+ destroy: () => void;
7
+ setFilter: (filter?: Filter) => Filter;
8
+ setUser: (user?: User) => User;
9
+ setAnnotatingEnabled: (enabled: boolean) => void;
10
+ };
@@ -0,0 +1,15 @@
1
+ import type { Annotator } from '@annotorious/core';
2
+ import { type HighlightStyleExpression } from './highlight';
3
+ import { type TextAnnotatorState } from './state';
4
+ import type { TextAnnotation } from './model';
5
+ import { type TextAnnotatorOptions } from './TextAnnotatorOptions';
6
+ import './TextAnnotator.css';
7
+ export interface TextAnnotator<I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation> extends Annotator<I, E> {
8
+ element: HTMLElement;
9
+ setStyle(style: HighlightStyleExpression | undefined): void;
10
+ redraw(lazy?: boolean): void;
11
+ scrollIntoView(annotationOrId: I | string, scrollParentOrId?: string | Element): boolean;
12
+ setAnnotatingEnabled: (enabled: boolean) => void;
13
+ state: TextAnnotatorState<I, E>;
14
+ }
15
+ export declare const createTextAnnotator: <I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation>(container: HTMLElement, options?: TextAnnotatorOptions<I, E>) => TextAnnotator<I, E>;
@@ -0,0 +1,34 @@
1
+ import type { FormatAdapter, UserSelectActionExpression, User } from '@annotorious/core';
2
+ import type { PresencePainterOptions } from './presence';
3
+ import type { TextAnnotation } from './model';
4
+ import type { HighlightStyleExpression } from './highlight';
5
+ export interface TextAnnotatorOptions<I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation> {
6
+ adapter?: FormatAdapter<I, E> | null;
7
+ annotatingEnabled?: boolean;
8
+ /**
9
+ * Determines whether an active selection should be dismissed
10
+ * when a user ends their interaction (click, selection)
11
+ * on a non-annotatable element.
12
+ * - NEVER - don't dismiss the selection, ignore the action.
13
+ * - ALWAYS - dismiss the selection.
14
+ * - function - a custom matcher that takes an event and container as arguments.
15
+ * Returns `true` if the selection should be dismissed.
16
+ *
17
+ * @defaut NEVER
18
+ */
19
+ dismissOnNotAnnotatable?: DismissOnNotAnnotatableExpression;
20
+ mergeHighlights?: {
21
+ horizontalTolerance?: number;
22
+ verticalTolerance?: number;
23
+ };
24
+ offsetReferenceSelector?: string;
25
+ presence?: PresencePainterOptions;
26
+ renderer?: RendererType;
27
+ selectionMode?: 'shortest' | 'all';
28
+ style?: HighlightStyleExpression;
29
+ user?: User;
30
+ userSelectAction?: UserSelectActionExpression<E>;
31
+ }
32
+ export type RendererType = 'SPANS' | 'CANVAS' | 'CSS_HIGHLIGHTS';
33
+ export type DismissOnNotAnnotatableExpression = 'NEVER' | 'ALWAYS' | ((event: Event, container: HTMLElement) => boolean);
34
+ export declare const fillDefaults: <I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation>(opts: TextAnnotatorOptions<I, E>, defaults: TextAnnotatorOptions<I, E>) => TextAnnotatorOptions<I, E>;
@@ -0,0 +1 @@
1
+ export * from './scrollIntoView';
@@ -0,0 +1,3 @@
1
+ import type { TextAnnotationStore } from '../state';
2
+ import type { TextAnnotation } from '../model';
3
+ export declare const scrollIntoView: <I extends TextAnnotation = TextAnnotation>(container: HTMLElement, store: TextAnnotationStore<I>) => <E extends Element = Element>(annotationOrId: string | I, scrollParentOrId?: string | E) => boolean;
@@ -0,0 +1,5 @@
1
+ import type { AnnotationState } from '@annotorious/core';
2
+ import type { AnnotationRects } from '../state';
3
+ export interface Highlight extends AnnotationRects {
4
+ state: AnnotationState;
5
+ }
@@ -0,0 +1,11 @@
1
+ import type { Highlight } from './Highlight';
2
+ import type { HighlightStyle, HighlightStyleExpression } from './HighlightStyle';
3
+ import type { ViewportBounds } from './viewport';
4
+ export interface HighlightPainter {
5
+ clear(): void;
6
+ destroy(): void;
7
+ paint(highlight: Highlight, viewportBounds: ViewportBounds): HighlightStyle;
8
+ reset(): void;
9
+ }
10
+ /** Helper **/
11
+ export declare const paint: (highlight: Highlight, viewportBounds: ViewportBounds, style?: HighlightStyleExpression, painter?: HighlightPainter, zIndex?: number) => HighlightStyle;
@@ -0,0 +1,11 @@
1
+ import type { AnnotationState, Color, DrawingStyle } from '@annotorious/core';
2
+ import type { TextAnnotation } from 'src/model';
3
+ export interface HighlightStyle extends Pick<DrawingStyle, 'fill' | 'fillOpacity'> {
4
+ underlineStyle?: string;
5
+ underlineColor?: Color;
6
+ underlineOffset?: number;
7
+ underlineThickness?: number;
8
+ }
9
+ export type HighlightStyleExpression = HighlightStyle | (<I extends TextAnnotation = TextAnnotation>(annotation: I, state: AnnotationState, zIndex?: number) => HighlightStyle | undefined);
10
+ export declare const DEFAULT_STYLE: HighlightStyle;
11
+ export declare const DEFAULT_SELECTED_STYLE: HighlightStyle;
@@ -0,0 +1,20 @@
1
+ import type { Filter, ViewportState } from '@annotorious/core';
2
+ import type { TextAnnotatorState } from '../state';
3
+ import { type ViewportBounds } from './viewport';
4
+ import type { HighlightPainter } from './HighlightPainter';
5
+ import type { Highlight } from './Highlight';
6
+ import type { HighlightStyleExpression } from './HighlightStyle';
7
+ export interface RendererImplementation {
8
+ destroy(): void;
9
+ redraw(highlights: Highlight[], bounds: ViewportBounds, style?: HighlightStyleExpression, painter?: HighlightPainter, lazy?: boolean): void;
10
+ setVisible(visible: boolean): void;
11
+ }
12
+ export interface Renderer {
13
+ destroy(): void;
14
+ redraw(force?: boolean): void;
15
+ setStyle(style?: HighlightStyleExpression): void;
16
+ setFilter(filter?: Filter): void;
17
+ setPainter(painter?: HighlightPainter): void;
18
+ setVisible(visible: boolean): void;
19
+ }
20
+ export declare const createBaseRenderer: <T extends TextAnnotatorState = TextAnnotatorState>(container: HTMLElement, state: T, viewport: ViewportState, renderer: RendererImplementation) => Renderer;
@@ -0,0 +1,5 @@
1
+ import type { ViewportState } from '@annotorious/core';
2
+ import type { TextAnnotatorState } from '../../state';
3
+ import type { TextAnnotation } from 'src/model';
4
+ import './canvasRenderer.css';
5
+ export declare const createCanvasRenderer: (container: HTMLElement, state: TextAnnotatorState<TextAnnotation, unknown>, viewport: ViewportState) => import("../baseRenderer").Renderer;
@@ -0,0 +1 @@
1
+ export * from './canvasRenderer';
@@ -0,0 +1,6 @@
1
+ import type { ViewportState } from '@annotorious/core';
2
+ import type { TextAnnotatorState } from 'src/state';
3
+ import { type RendererImplementation } from '../baseRenderer';
4
+ import type { TextAnnotation } from 'src/model';
5
+ export declare const createRenderer: () => RendererImplementation;
6
+ export declare const createHighlightsRenderer: (container: HTMLElement, state: TextAnnotatorState<TextAnnotation, unknown>, viewport: ViewportState) => import("../baseRenderer").Renderer;
@@ -0,0 +1 @@
1
+ export * from './highlightsRenderer';
@@ -0,0 +1,6 @@
1
+ export * from './Highlight';
2
+ export * from './HighlightStyle';
3
+ export * from './HighlightPainter';
4
+ export * from './canvas';
5
+ export * from './highlights';
6
+ export * from './span';
@@ -0,0 +1,2 @@
1
+ import { type HighlightStyle } from '../HighlightStyle';
2
+ export declare const getBackgroundColor: (style?: HighlightStyle) => string;
@@ -0,0 +1 @@
1
+ export * from './spansRenderer';
@@ -0,0 +1,5 @@
1
+ import type { ViewportState } from '@annotorious/core';
2
+ import type { TextAnnotation } from '../../model';
3
+ import type { TextAnnotatorState } from '../../state';
4
+ import './spansRenderer.css';
5
+ export declare const createSpansRenderer: (container: HTMLElement, state: TextAnnotatorState<TextAnnotation, unknown>, viewport: ViewportState) => import("../baseRenderer").Renderer;
@@ -0,0 +1,12 @@
1
+ import type { ViewportState } from '@annotorious/core';
2
+ import type { TextAnnotation } from '../model';
3
+ export interface ViewportBounds {
4
+ top: number;
5
+ left: number;
6
+ minX: number;
7
+ minY: number;
8
+ maxX: number;
9
+ maxY: number;
10
+ }
11
+ export declare const getViewportBounds: (container: HTMLElement) => ViewportBounds;
12
+ export declare const trackViewport: (viewport: ViewportState) => (annotations: TextAnnotation[]) => void;
@@ -0,0 +1,11 @@
1
+ export * from './api';
2
+ export * from './highlight';
3
+ export * from './model';
4
+ export * from './state';
5
+ export * from './utils';
6
+ export * from './presence';
7
+ export * from './SelectionHandler';
8
+ export * from './TextAnnotator';
9
+ export * from './TextAnnotatorOptions';
10
+ export type { Annotation, AnnotationBody, AnnotationTarget, Annotator, AnnotatorState, Color, Filter, FormatAdapter, HoverState, Selection, SelectionState, Store, StoreChangeEvent, StoreObserver, ParseResult, User, UserSelectActionExpression, ViewportState, W3CAnnotation, W3CAnnotationBody, W3CAnnotationTarget } from '@annotorious/core';
11
+ export { createBody, Origin, UserSelectAction } from '@annotorious/core';
@@ -0,0 +1,15 @@
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
+ id?: string;
10
+ quote: string;
11
+ start: number;
12
+ end: number;
13
+ range: Range;
14
+ offsetReference?: HTMLElement;
15
+ }
@@ -0,0 +1 @@
1
+ export * from './TextAnnotation';
@@ -0,0 +1,2 @@
1
+ export * from './core';
2
+ export * from './w3c';
@@ -0,0 +1,34 @@
1
+ import type { W3CAnnotation, W3CAnnotationTarget } from '@annotorious/core';
2
+ export interface W3CTextAnnotation extends W3CAnnotation {
3
+ target: W3CTextAnnotationTarget | W3CTextAnnotationTarget[];
4
+ stylesheet?: W3CAnnotationStylesheet;
5
+ }
6
+ export interface W3CTextAnnotationTarget extends W3CAnnotationTarget {
7
+ selector: W3CTextSelector | W3CTextSelector[];
8
+ styleClass?: string;
9
+ scope?: string;
10
+ }
11
+ /**
12
+ * Matches the `Text Quote Selector` spec
13
+ * @see https://www.w3.org/TR/annotation-model/#text-quote-selector
14
+ */
15
+ export interface W3CTextQuoteSelector {
16
+ type: 'TextQuoteSelector';
17
+ exact: string;
18
+ prefix?: string;
19
+ suffix?: string;
20
+ }
21
+ /**
22
+ * Matches the `Text Position Selector` spec
23
+ * @see https://www.w3.org/TR/annotation-model/#text-position-selector
24
+ */
25
+ export interface W3CTextPositionSelector {
26
+ type: 'TextPositionSelector';
27
+ start: number;
28
+ end: number;
29
+ }
30
+ export type W3CTextSelector = W3CTextQuoteSelector | W3CTextPositionSelector;
31
+ export type W3CAnnotationStylesheet = string | {
32
+ type: 'CssStylesheet';
33
+ value: string;
34
+ };
@@ -0,0 +1,12 @@
1
+ import { type FormatAdapter, type ParseResult } from '@annotorious/core';
2
+ import type { TextAnnotation } from '../core';
3
+ import type { W3CTextAnnotation } from '../w3c';
4
+ export type W3CTextFormatAdapter<I extends TextAnnotation = TextAnnotation, E extends W3CTextAnnotation = W3CTextAnnotation> = FormatAdapter<I, E>;
5
+ /**
6
+ * @param source - the IRI of the annotated content
7
+ * @param container - the HTML container of the annotated content,
8
+ * Required to locate the content's `range` within the DOM
9
+ */
10
+ export declare const W3CTextFormat: <I extends TextAnnotation = TextAnnotation, E extends W3CTextAnnotation = W3CTextAnnotation>(source: string, container?: HTMLElement) => W3CTextFormatAdapter<I, E>;
11
+ export declare const parseW3CTextAnnotation: <I extends TextAnnotation = TextAnnotation, E extends W3CTextAnnotation = W3CTextAnnotation>(annotation: E) => ParseResult<I>;
12
+ export declare const serializeW3CTextAnnotation: <I extends TextAnnotation = TextAnnotation, E extends W3CTextAnnotation = W3CTextAnnotation>(annotation: I, source: string, container?: HTMLElement) => E;
@@ -0,0 +1,2 @@
1
+ export * from './W3CTextAnnotation';
2
+ export * from './W3CTextFormatAdapter';
@@ -0,0 +1,5 @@
1
+ import type { PresenceProvider } from '@annotorious/core';
2
+ import type { HighlightPainter } from '../highlight';
3
+ import type { PresencePainterOptions } from '../presence';
4
+ import './PresencePainter.css';
5
+ export declare const createPresencePainter: (provider: PresenceProvider, opts?: PresencePainterOptions) => HighlightPainter;
@@ -0,0 +1,3 @@
1
+ export interface PresencePainterOptions {
2
+ font?: string;
3
+ }
@@ -0,0 +1,2 @@
1
+ export * from './PresencePainter';
2
+ export * from './PresencePainterOptions';
@@ -1,3 +1,2 @@
1
1
  export declare const whitespaceOrEmptyRegex: RegExp;
2
- export declare const isRangeWhitespaceOrEmpty: (range: Range) => boolean;
3
- export declare const isNodeWhitespaceOrEmpty: (node: Node) => boolean;
2
+ export declare const isWhitespaceOrEmpty: (range: Range) => boolean;
@@ -0,0 +1,25 @@
1
+ import type { Filter, Origin, Store } from '@annotorious/core';
2
+ import type { TextAnnotation } from '../model';
3
+ export interface TextAnnotationStore<T extends TextAnnotation = TextAnnotation> extends Omit<Store<T>, 'addAnnotation' | 'bulkAddAnnotation'> {
4
+ addAnnotation(annotation: T, origin?: Origin): boolean;
5
+ bulkAddAnnotations(annotations: T[], replace: boolean, origin?: Origin): T[];
6
+ bulkUpsertAnnotations(annotations: T[], origin?: Origin): T[];
7
+ getAnnotationRects(id: string): DOMRect[];
8
+ getAnnotationBounds(id: string): DOMRect | undefined;
9
+ getAnnotationRects(id: string): DOMRect[];
10
+ getAt(x: number, y: number, all: true, filter?: Filter): T[] | undefined;
11
+ getAt(x: number, y: number, all: false, filter?: Filter): T | undefined;
12
+ getAt(x: number, y: number, all?: boolean, filter?: Filter): T | T[] | undefined;
13
+ getIntersecting(minX: number, minY: number, maxX: number, maxY: number): AnnotationRects<T>[];
14
+ recalculatePositions(): void;
15
+ }
16
+ export interface AnnotationRects<T extends TextAnnotation = TextAnnotation> {
17
+ annotation: T;
18
+ rects: Rect[];
19
+ }
20
+ export interface Rect {
21
+ x: number;
22
+ y: number;
23
+ width: number;
24
+ height: number;
25
+ }
@@ -0,0 +1,12 @@
1
+ import type { ViewportState } from '@annotorious/core';
2
+ import type { AnnotatorState, SelectionState, HoverState } from '@annotorious/core';
3
+ import type { TextAnnotation } from '../model';
4
+ import type { TextAnnotationStore } from './TextAnnotationStore';
5
+ import type { TextAnnotatorOptions } from '../TextAnnotatorOptions';
6
+ export interface TextAnnotatorState<I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation> extends AnnotatorState<I, E> {
7
+ store: TextAnnotationStore<I>;
8
+ selection: SelectionState<I, E>;
9
+ hover: HoverState<I>;
10
+ viewport: ViewportState;
11
+ }
12
+ export declare const createTextAnnotatorState: <I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation>(container: HTMLElement, opts: TextAnnotatorOptions<I, E>) => TextAnnotatorState<I, E>;
@@ -0,0 +1,2 @@
1
+ export * from './TextAnnotationStore';
2
+ export * from './TextAnnotatorState';
@@ -0,0 +1,28 @@
1
+ import type { Store } from '@annotorious/core';
2
+ import type { TextAnnotation, TextAnnotationTarget } from '../model';
3
+ import type { AnnotationRects } from './TextAnnotationStore';
4
+ interface IndexedHighlightRect {
5
+ minX: number;
6
+ minY: number;
7
+ maxX: number;
8
+ maxY: number;
9
+ annotation: {
10
+ id: string;
11
+ rects: DOMRect[];
12
+ };
13
+ }
14
+ export declare const createSpatialTree: <T extends TextAnnotation>(store: Store<T>, container: HTMLElement, hMergeTolerance?: number, vMergeTolerance?: number) => {
15
+ all: () => IndexedHighlightRect[][];
16
+ clear: () => void;
17
+ getAt: (x: number, y: number, all?: boolean) => string[];
18
+ getAnnotationBounds: (id: string) => DOMRect;
19
+ getAnnotationRects: (id: string) => DOMRect[];
20
+ getIntersecting: (minX: number, minY: number, maxX: number, maxY: number) => AnnotationRects<T>[];
21
+ insert: (target: TextAnnotationTarget) => void;
22
+ recalculate: () => void;
23
+ remove: (target: TextAnnotationTarget) => void;
24
+ set: (targets: TextAnnotationTarget[], replace?: boolean) => void;
25
+ size: () => number;
26
+ update: (target: TextAnnotationTarget) => void;
27
+ };
28
+ export {};