@recogito/text-annotator 4.0.3-beta → 4.1.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.
@@ -13,3 +13,15 @@ export interface TextSelector {
13
13
  range: Range;
14
14
  offsetReference?: HTMLElement;
15
15
  }
16
+ export interface TextAnnotationLike extends Annotation {
17
+ target: TextAnnotationTargetLike;
18
+ }
19
+ export interface TextAnnotationTargetLike extends AnnotationTarget {
20
+ selector: TextSelectorLike[];
21
+ }
22
+ export interface TextSelectorLike {
23
+ id?: string;
24
+ quote: string;
25
+ range: Range;
26
+ offsetReference?: HTMLElement;
27
+ }
@@ -1,6 +1,6 @@
1
1
  import { type Unsubscribe } from 'nanoevents';
2
2
  import { type Filter, type ViewportState } from '@annotorious/core';
3
- import type { TextAnnotation } from '../model';
3
+ import type { TextAnnotationLike } from '../model';
4
4
  import type { TextAnnotatorState } from '../state';
5
5
  import { type Highlight, type HighlightStyleExpression, type ViewportBounds } from './';
6
6
  /**
@@ -17,7 +17,7 @@ export interface Renderer {
17
17
  export interface RendererEvents {
18
18
  onRedraw(): void;
19
19
  }
20
- export type RendererFactory<T extends TextAnnotation> = (container: HTMLElement, state: TextAnnotatorState<T, any>, viewport: ViewportState) => Renderer;
20
+ export type RendererFactory<T extends TextAnnotationLike> = (container: HTMLElement, state: TextAnnotatorState<T, any>, viewport: ViewportState) => Renderer;
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
@@ -28,4 +28,4 @@ export interface Painter {
28
28
  redraw(highlights: Highlight[], bounds: ViewportBounds, style?: HighlightStyleExpression, styleOverrides?: Map<string, HighlightStyleExpression>, force?: boolean): void;
29
29
  setVisible(visible: boolean): void;
30
30
  }
31
- export declare const createRenderer: <T extends TextAnnotatorState = TextAnnotatorState<TextAnnotation, any>>(painter: Painter, container: HTMLElement, state: T, viewport: ViewportState) => Renderer;
31
+ export declare const createRenderer: <T extends TextAnnotatorState<TextAnnotationLike, any>>(painter: Painter, container: HTMLElement, state: T, viewport: ViewportState) => Renderer;
@@ -1,5 +1,5 @@
1
1
  import type { AnnotationState, Color, DrawingStyle } from '@annotorious/core';
2
- import type { TextAnnotation } from '../model';
2
+ import type { 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 = HighlightStyle | (<I extends TextAnnotation = TextAnnotation>(annotation: I, state: AnnotationState, zIndex?: number) => HighlightStyle | undefined);
10
+ export type HighlightStyleExpression = HighlightStyle | (<I extends TextAnnotationLike = TextAnnotationLike>(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;
@@ -1,6 +1,6 @@
1
1
  import type { AnnotationState } from '@annotorious/core';
2
- import type { TextAnnotation } from '../model';
2
+ import type { TextAnnotationLike } from '../model';
3
3
  import type { AnnotationRects } from '../state';
4
- export interface Highlight extends AnnotationRects<TextAnnotation> {
4
+ export interface Highlight extends AnnotationRects<TextAnnotationLike> {
5
5
  state: AnnotationState;
6
6
  }
@@ -1,4 +1,4 @@
1
- import type { TextAnnotation } from '../../model';
1
+ import type { TextAnnotationLike } from '../../model';
2
2
  import { type RendererFactory } from '../';
3
3
  import './spans-renderer.css';
4
- export declare const createSpansRenderer: RendererFactory<TextAnnotation>;
4
+ export declare const createSpansRenderer: RendererFactory<TextAnnotationLike>;
@@ -1,5 +1,5 @@
1
1
  import type { ViewportState } from '@annotorious/core';
2
- import type { TextAnnotation } from '../model';
2
+ import type { TextAnnotationLike } from '../model';
3
3
  export interface ViewportBounds {
4
4
  top: number;
5
5
  left: number;
@@ -9,4 +9,4 @@ export interface ViewportBounds {
9
9
  maxY: number;
10
10
  }
11
11
  export declare const getViewportBounds: (container: HTMLElement) => ViewportBounds;
12
- export declare const trackViewport: (viewport: ViewportState) => (annotations: TextAnnotation[]) => void;
12
+ export declare const trackViewport: (viewport: ViewportState) => (annotations: TextAnnotationLike[]) => void;
@@ -1,6 +1,6 @@
1
1
  import type { Store } from '@annotorious/core';
2
2
  import { type Unsubscribe } from 'nanoevents';
3
- import type { TextAnnotation, TextAnnotationTarget } from '../model';
3
+ import type { TextAnnotationLike, TextAnnotationTarget } from '../model';
4
4
  import type { AnnotationRects } from '../state/text-annotation-store';
5
5
  interface IndexedHighlightRect {
6
6
  minX: number;
@@ -15,7 +15,7 @@ interface IndexedHighlightRect {
15
15
  export interface SpatialTreeEvents {
16
16
  recalculate(): void;
17
17
  }
18
- export declare const createSpatialTree: <T extends TextAnnotation>(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) => {
19
19
  all: () => IndexedHighlightRect[][];
20
20
  clear: () => void;
21
21
  getAt: (x: number, y: number, all?: boolean) => string[];
@@ -1,8 +1,8 @@
1
1
  import type { Unsubscribe } from 'nanoevents';
2
2
  import type { Filter, Origin, Store } from '@annotorious/core';
3
- import type { TextAnnotation } from '../model';
3
+ import type { TextAnnotation, TextAnnotationLike } from '../model';
4
4
  import type { SpatialTreeEvents } from '../state/spatial-tree';
5
- export interface TextAnnotationStore<T extends TextAnnotation = TextAnnotation> extends Omit<Store<T>, 'addAnnotation' | 'bulkAddAnnotations' | 'bulkUpsertAnnotations'> {
5
+ export interface TextAnnotationStore<T extends TextAnnotationLike = TextAnnotation> extends Omit<Store<T>, 'addAnnotation' | 'bulkAddAnnotations' | 'bulkUpsertAnnotations'> {
6
6
  addAnnotation(annotation: T, origin?: Origin): boolean;
7
7
  bulkAddAnnotations(annotations: T[], replace: boolean, origin?: Origin): T[];
8
8
  bulkUpsertAnnotations(annotations: T[], origin?: Origin): T[];
@@ -16,7 +16,7 @@ export interface TextAnnotationStore<T extends TextAnnotation = TextAnnotation>
16
16
  recalculatePositions(): void;
17
17
  onRecalculatePositions(callback: SpatialTreeEvents['recalculate']): Unsubscribe;
18
18
  }
19
- export interface AnnotationRects<T extends TextAnnotation = TextAnnotation> {
19
+ export interface AnnotationRects<T extends TextAnnotationLike = TextAnnotation> {
20
20
  annotation: T;
21
21
  rects: Rect[];
22
22
  }
@@ -1,9 +1,9 @@
1
1
  import type { ViewportState } from '@annotorious/core';
2
2
  import type { AnnotatorState, SelectionState, HoverState } from '@annotorious/core';
3
- import type { TextAnnotation } from '../model';
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 TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation> extends Omit<AnnotatorState<I, E>, 'store'> {
6
+ export interface TextAnnotatorState<I extends TextAnnotationLike = TextAnnotation, 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>;
@@ -1,7 +1,7 @@
1
1
  import type { FormatAdapter, UserSelectActionExpression, User } from '@annotorious/core';
2
2
  import type { HighlightStyleExpression, RendererFactory } from './rendering';
3
- import type { TextAnnotation } from './model';
4
- export interface TextAnnotatorOptions<I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation> {
3
+ import type { TextAnnotation, TextAnnotationLike } from './model';
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;
@@ -30,4 +30,4 @@ export interface TextAnnotatorOptions<I extends TextAnnotation = TextAnnotation,
30
30
  }
31
31
  export type RendererType = 'SPANS' | 'CSS_HIGHLIGHTS';
32
32
  export type DismissOnNotAnnotatableExpression = 'NEVER' | 'ALWAYS' | ((event: Event, container: HTMLElement) => boolean);
33
- export declare const fillDefaults: <I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation>(opts: TextAnnotatorOptions<I, E>, defaults: TextAnnotatorOptions<I, E>) => TextAnnotatorOptions<I, E>;
33
+ export declare const fillDefaults: <I extends TextAnnotationLike = TextAnnotation, E extends unknown = TextAnnotation>(opts: TextAnnotatorOptions<I, E>, defaults: TextAnnotatorOptions<I, E>) => TextAnnotatorOptions<I, E>;
@@ -1,10 +1,10 @@
1
1
  import { type Annotator } from '@annotorious/core';
2
2
  import type { HighlightStyleExpression, Renderer } from './rendering';
3
- import type { TextAnnotation } from './model';
3
+ import type { TextAnnotation, TextAnnotationLike } from './model';
4
4
  import { type TextAnnotatorState } from './state';
5
5
  import { type TextAnnotatorOptions } from './text-annotator-options';
6
6
  import './text-annotator.css';
7
- export interface TextAnnotator<I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation> extends Omit<Annotator<I, E>, 'setStyle' | 'state'> {
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
10
  setStyle(style?: HighlightStyleExpression, id?: string): void;
@@ -14,4 +14,4 @@ export interface TextAnnotator<I extends TextAnnotation = TextAnnotation, E exte
14
14
  state: TextAnnotatorState<I, E>;
15
15
  }
16
16
  export type AnnotatingMode = 'CREATE_NEW' | 'ADD_TO_CURRENT' | 'REPLACE_CURRENT';
17
- export declare const createTextAnnotator: <I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation>(container: HTMLElement, options?: TextAnnotatorOptions<I, E>) => TextAnnotator<I, E>;
17
+ export declare const createTextAnnotator: <I extends TextAnnotationLike = TextAnnotationLike, E extends unknown = TextAnnotationLike>(container: HTMLElement, options?: TextAnnotatorOptions<I, E>) => TextAnnotator<I, E>;