@recogito/text-annotator 3.0.0-rc.17 → 3.0.0-rc.19

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 (41) hide show
  1. package/dist/src/SelectionHandler.d.ts +3 -2
  2. package/dist/src/TextAnnotator.d.ts +7 -5
  3. package/dist/src/TextAnnotatorOptions.d.ts +8 -5
  4. package/dist/src/api/scrollIntoView.d.ts +3 -2
  5. package/dist/src/highlight/Highlight.d.ts +6 -0
  6. package/dist/src/highlight/HighlightPainter.d.ts +7 -4
  7. package/dist/src/highlight/HighlightStyle.d.ts +7 -4
  8. package/dist/src/highlight/baseRenderer.d.ts +21 -0
  9. package/dist/src/highlight/canvas/canvasRenderer.d.ts +4 -0
  10. package/dist/src/highlight/canvas/index.d.ts +1 -1
  11. package/dist/src/highlight/highlights/highlightsRenderer.d.ts +6 -0
  12. package/dist/src/highlight/highlights/index.d.ts +1 -0
  13. package/dist/src/highlight/index.d.ts +2 -1
  14. package/dist/src/highlight/span/index.d.ts +1 -0
  15. package/dist/src/highlight/span/spansRenderer.d.ts +4 -0
  16. package/dist/src/highlight/viewport.d.ts +3 -2
  17. package/dist/src/index.d.ts +1 -1
  18. package/dist/src/model/core/TextAnnotation.d.ts +3 -1
  19. package/dist/src/model/w3c/W3CTextAnnotation.d.ts +2 -1
  20. package/dist/src/model/w3c/W3CTextFormatAdapter.d.ts +5 -4
  21. package/dist/src/presence/PresencePainter.d.ts +4 -3
  22. package/dist/src/state/TextAnnotationStore.d.ts +7 -7
  23. package/dist/src/state/TextAnnotatorState.d.ts +6 -6
  24. package/dist/src/state/spatialTree.d.ts +9 -6
  25. package/dist/src/utils/isRevived.d.ts +2 -1
  26. package/dist/src/utils/rangeToSelector.d.ts +2 -1
  27. package/dist/src/utils/reviveAnnotation.d.ts +2 -1
  28. package/dist/src/utils/reviveSelector.d.ts +2 -1
  29. package/dist/src/utils/reviveTarget.d.ts +2 -1
  30. package/dist/src/utils/splitAnnotatableRanges.d.ts +1 -1
  31. package/dist/test/model/w3c/fixtures.d.ts +2 -1
  32. package/dist/text-annotator.css +1 -1
  33. package/dist/text-annotator.es.js +1099 -1029
  34. package/dist/text-annotator.es.js.map +1 -1
  35. package/dist/text-annotator.umd.js +2 -2
  36. package/dist/text-annotator.umd.js.map +1 -1
  37. package/package.json +9 -8
  38. package/dist/src/highlight/canvas/highlightRenderer.d.ts +0 -11
  39. package/dist/src/highlight/css/highlightRenderer.d.ts +0 -11
  40. package/dist/src/highlight/css/highlights.d.ts +0 -10
  41. package/dist/src/highlight/css/index.d.ts +0 -1
@@ -1,5 +1,6 @@
1
- import { type User } from '@annotorious/core';
2
- import type { TextAnnotatorState } from './state';
1
+ import { TextAnnotatorState } from './state';
2
+ import { User } from '@annotorious/core';
3
+
3
4
  export declare const SelectionHandler: (container: HTMLElement, state: TextAnnotatorState, offsetReferenceSelector?: string) => {
4
5
  destroy: () => void;
5
6
  setUser: (user: User) => User;
@@ -1,9 +1,11 @@
1
- import type { Annotator } from '@annotorious/core';
2
- import type { TextAnnotation } from './model';
3
- import type { TextAnnotatorOptions } from './TextAnnotatorOptions';
4
- import './TextAnnotator.css';
5
- export interface TextAnnotator<T extends unknown = TextAnnotation> extends Annotator<TextAnnotation, T> {
1
+ import { TextAnnotatorOptions } from './TextAnnotatorOptions';
2
+ import { TextAnnotation } from './model';
3
+ import { TextAnnotatorState } from './state';
4
+ import { Annotator } from '@annotorious/core';
5
+
6
+ export interface TextAnnotator<E extends unknown = TextAnnotation> extends Annotator<TextAnnotation, E> {
6
7
  element: HTMLElement;
7
8
  scrollIntoView(annotation: TextAnnotation): boolean;
9
+ state: TextAnnotatorState;
8
10
  }
9
11
  export declare const createTextAnnotator: <E extends unknown = TextAnnotation>(container: HTMLElement, opts?: TextAnnotatorOptions<E>) => TextAnnotator<E>;
@@ -1,11 +1,14 @@
1
- import type { DrawingStyle, FormatAdapter, PointerSelectAction } from '@annotorious/core';
2
- import type { PresencePainterOptions } from './presence';
3
- import type { TextAnnotation } from './model';
1
+ import { HighlightStyleExpression } from './highlight/HighlightStyle';
2
+ import { TextAnnotation } from './model';
3
+ import { PresencePainterOptions } from './presence';
4
+ import { FormatAdapter, PointerSelectAction } from '@annotorious/core';
5
+
4
6
  export interface TextAnnotatorOptions<T extends unknown = TextAnnotation> {
5
7
  adapter?: FormatAdapter<TextAnnotation, T> | null;
6
- experimentalCSSRenderer?: boolean;
8
+ renderer?: RendererType;
7
9
  offsetReferenceSelector?: string;
8
10
  pointerAction?: PointerSelectAction | ((annotation: TextAnnotation) => PointerSelectAction);
9
11
  presence?: PresencePainterOptions;
10
- style?: DrawingStyle | ((annotation: TextAnnotation) => DrawingStyle);
12
+ style?: HighlightStyleExpression;
11
13
  }
14
+ export type RendererType = 'SPANS' | 'CANVAS' | 'CSS_HIGHLIGHTS';
@@ -1,3 +1,4 @@
1
- import type { TextAnnotationStore } from '../state';
2
- import type { TextAnnotation } from '../model';
1
+ import { TextAnnotation } from '../model';
2
+ import { TextAnnotationStore } from '../state';
3
+
3
4
  export declare const scrollIntoView: (container: HTMLElement, store: TextAnnotationStore) => (annotation: TextAnnotation) => boolean;
@@ -0,0 +1,6 @@
1
+ import { AnnotationRects } from '../state';
2
+ import { AnnotationState } from '@annotorious/core';
3
+
4
+ export interface Highlight extends AnnotationRects {
5
+ state: AnnotationState;
6
+ }
@@ -1,9 +1,12 @@
1
- import type { AnnotationRects } from '../state';
2
- import type { HighlightStyle } from './HighlightStyle';
3
- import type { ViewportBounds } from './viewport';
1
+ import { ViewportBounds } from './viewport';
2
+ import { HighlightStyle, HighlightStyleExpression } from './HighlightStyle';
3
+ import { Highlight } from './Highlight';
4
+
4
5
  export interface HighlightPainter {
5
6
  clear(): void;
6
7
  destroy(): void;
7
- paint(annotation: AnnotationRects, viewportBounds: ViewportBounds, isSelected?: boolean): HighlightStyle;
8
+ paint(highlight: Highlight, viewportBounds: ViewportBounds): HighlightStyle;
8
9
  reset(): void;
9
10
  }
11
+ /** Helper **/
12
+ export declare const paint: (highlight: Highlight, viewportBounds: ViewportBounds, style?: HighlightStyleExpression, painter?: HighlightPainter, zIndex?: number) => HighlightStyle;
@@ -1,9 +1,12 @@
1
- import type { DrawingStyle } from '@annotorious/core';
2
- export declare const DEFAULT_STYLE: DrawingStyle;
3
- export declare const DEFAULT_SELECTED_STYLE: DrawingStyle;
1
+ import { TextAnnotation } from 'src/model';
2
+ import { AnnotationState, Color, DrawingStyle } from '@annotorious/core';
3
+
4
4
  export interface HighlightStyle extends Pick<DrawingStyle, 'fill' | 'fillOpacity'> {
5
5
  underlineStyle?: string;
6
- underlineColor?: number;
6
+ underlineColor?: Color;
7
7
  underlineOffset?: number;
8
8
  underlineThickness?: number;
9
9
  }
10
+ export type HighlightStyleExpression = HighlightStyle | ((annotation: TextAnnotation, state: AnnotationState, zIndex?: number) => HighlightStyle);
11
+ export declare const DEFAULT_STYLE: HighlightStyle;
12
+ export declare const DEFAULT_SELECTED_STYLE: HighlightStyle;
@@ -0,0 +1,21 @@
1
+ import { HighlightStyleExpression } from './HighlightStyle';
2
+ import { Highlight } from './Highlight';
3
+ import { HighlightPainter } from './HighlightPainter';
4
+ import { ViewportBounds } from './viewport';
5
+ import { TextAnnotatorState } from '../state';
6
+ import { Filter, ViewportState } from '@annotorious/core';
7
+
8
+ export interface RendererImplementation {
9
+ destroy(): void;
10
+ redraw(highlights: Highlight[], bounds: ViewportBounds, style?: HighlightStyleExpression, painter?: HighlightPainter, force?: boolean): void;
11
+ setVisible(visible: boolean): void;
12
+ }
13
+ export interface Renderer {
14
+ destroy(): void;
15
+ redraw(force?: boolean): void;
16
+ setStyle(style?: HighlightStyleExpression): void;
17
+ setFilter(filter?: Filter): void;
18
+ setPainter(painter?: HighlightPainter): void;
19
+ setVisible(visible: boolean): void;
20
+ }
21
+ export declare const createBaseRenderer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState, renderer: RendererImplementation) => Renderer;
@@ -0,0 +1,4 @@
1
+ import { ViewportState } from '@annotorious/core';
2
+ import { TextAnnotatorState } from 'src/state';
3
+
4
+ export declare const createCanvasRenderer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState) => import('../baseRenderer').Renderer;
@@ -1 +1 @@
1
- export * from './highlightRenderer';
1
+ export * from './canvasRenderer';
@@ -0,0 +1,6 @@
1
+ import { RendererImplementation } from '../baseRenderer';
2
+ import { TextAnnotatorState } from 'src/state';
3
+ import { ViewportState } from '@annotorious/core';
4
+
5
+ export declare const createRenderer: () => RendererImplementation;
6
+ export declare const createHighlightsRenderer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState) => import('../baseRenderer').Renderer;
@@ -0,0 +1 @@
1
+ export * from './highlightsRenderer';
@@ -1,2 +1,3 @@
1
1
  export * from './canvas';
2
- export * from './css';
2
+ export * from './highlights';
3
+ export * from './span';
@@ -0,0 +1 @@
1
+ export * from './spansRenderer';
@@ -0,0 +1,4 @@
1
+ import { TextAnnotatorState } from '../../state';
2
+ import { ViewportState } from '@annotorious/core';
3
+
4
+ export declare const createSpansRenderer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState) => import('../baseRenderer').Renderer;
@@ -1,5 +1,6 @@
1
- import type { ViewportState } from '@annotorious/core';
2
- import type { TextAnnotation } from '../model';
1
+ import { TextAnnotation } from '../model';
2
+ import { ViewportState } from '@annotorious/core';
3
+
3
4
  export interface ViewportBounds {
4
5
  top: number;
5
6
  left: number;
@@ -1,3 +1,4 @@
1
+ import { _Origin } from '@annotorious/core';
1
2
  export * from './highlight';
2
3
  export * from './model';
3
4
  export * from './state';
@@ -6,5 +7,4 @@ export * from './presence/PresencePainterOptions';
6
7
  export * from './TextAnnotator';
7
8
  export * from './TextAnnotatorOptions';
8
9
  export type { Filter } from '@annotorious/core';
9
- import { Origin as _Origin } from '@annotorious/core';
10
10
  export { _Origin as Origin };
@@ -1,4 +1,5 @@
1
- import type { Annotation, AnnotationTarget } from '@annotorious/core';
1
+ import { Annotation, AnnotationTarget } from '@annotorious/core';
2
+
2
3
  export interface TextAnnotation extends Annotation {
3
4
  target: TextAnnotationTarget;
4
5
  }
@@ -6,6 +7,7 @@ export interface TextAnnotationTarget extends AnnotationTarget {
6
7
  selector: TextSelector[];
7
8
  }
8
9
  export interface TextSelector {
10
+ id?: string;
9
11
  quote: string;
10
12
  start: number;
11
13
  end: number;
@@ -1,4 +1,5 @@
1
- import type { W3CAnnotation, W3CAnnotationTarget } from '@annotorious/core';
1
+ import { W3CAnnotation, W3CAnnotationTarget } from '@annotorious/core';
2
+
2
3
  export interface W3CTextAnnotation extends W3CAnnotation {
3
4
  target: W3CTextAnnotationTarget | W3CTextAnnotationTarget[];
4
5
  stylesheet?: W3CAnnotationStylesheet;
@@ -1,6 +1,7 @@
1
- import { type FormatAdapter, ParseResult } from '@annotorious/core';
2
- import type { TextAnnotation } from '../core';
3
- import type { W3CTextAnnotation } from '../w3c';
1
+ import { W3CTextAnnotation } from '../w3c';
2
+ import { TextAnnotation } from '../core';
3
+ import { FormatAdapter, ParseResult } from '@annotorious/core';
4
+
4
5
  export type W3CTextFormatAdapter = FormatAdapter<TextAnnotation, W3CTextAnnotation>;
5
6
  /**
6
7
  * @param source - the IRI of the annotated content
@@ -8,5 +9,5 @@ export type W3CTextFormatAdapter = FormatAdapter<TextAnnotation, W3CTextAnnotati
8
9
  * Required to locate the content's `range` within the DOM
9
10
  */
10
11
  export declare const W3CTextFormat: (source: string, container: HTMLElement) => W3CTextFormatAdapter;
11
- export declare const parseW3CTextAnnotation: (annotation: W3CTextAnnotation, container: HTMLElement) => ParseResult<TextAnnotation>;
12
+ export declare const parseW3CTextAnnotation: (annotation: W3CTextAnnotation) => ParseResult<TextAnnotation>;
12
13
  export declare const serializeW3CTextAnnotation: (annotation: TextAnnotation, source: string, container: HTMLElement) => W3CTextAnnotation;
@@ -1,4 +1,5 @@
1
- import type { PresenceProvider } from '@annotorious/core';
2
- import type { HighlightPainter } from '../highlight/HighlightPainter';
3
- import type { PresencePainterOptions } from 'src/presence';
1
+ import { PresencePainterOptions } from 'src/presence';
2
+ import { HighlightPainter } from '../highlight/HighlightPainter';
3
+ import { PresenceProvider } from '@annotorious/core';
4
+
4
5
  export declare const createPresencePainter: (container: HTMLElement, provider: PresenceProvider, opts?: PresencePainterOptions) => HighlightPainter;
@@ -1,13 +1,13 @@
1
- import type { Origin, Store } from '@annotorious/core';
2
- import type { TextAnnotation } from '../model';
1
+ import { TextAnnotation } from '../model';
2
+ import { Origin, Store } from '@annotorious/core';
3
+
3
4
  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
- bulkUpsertAnnotations(annotations: TextAnnotation[], origin: Origin): TextAnnotation[];
5
+ addAnnotation(annotation: TextAnnotation, origin?: Origin): boolean;
6
+ bulkAddAnnotation(annotations: TextAnnotation[], replace: boolean, origin?: Origin): TextAnnotation[];
7
+ bulkUpsertAnnotations(annotations: TextAnnotation[], origin?: Origin): TextAnnotation[];
7
8
  getAnnotationBounds(id: string, hintX?: number, hintY?: number, buffer?: number): DOMRect;
8
9
  getAt(x: number, y: number): TextAnnotation | undefined;
9
- getIntersecting(minX: number, minY: number, maxX: number, maxY: number): TextAnnotation[];
10
- getIntersectingRects(minX: number, minY: number, maxX: number, maxY: number): AnnotationRects[];
10
+ getIntersecting(minX: number, minY: number, maxX: number, maxY: number): AnnotationRects[];
11
11
  recalculatePositions(): void;
12
12
  }
13
13
  export interface AnnotationRects {
@@ -1,11 +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> & {
1
+ import { TextAnnotationStore } from './TextAnnotationStore';
2
+ import { TextAnnotation } from '../model';
3
+ import { PointerSelectAction, ViewportState, AnnotatorState, SelectionState, HoverState } from '@annotorious/core';
4
+
5
+ export interface TextAnnotatorState extends AnnotatorState<TextAnnotation> {
6
6
  store: TextAnnotationStore;
7
7
  selection: SelectionState<TextAnnotation>;
8
8
  hover: HoverState<TextAnnotation>;
9
9
  viewport: ViewportState;
10
- };
10
+ }
11
11
  export declare const createTextAnnotatorState: (container: HTMLElement, defaultPointerAction?: PointerSelectAction | ((annotation: TextAnnotation) => PointerSelectAction)) => TextAnnotatorState;
@@ -1,6 +1,8 @@
1
- import type { Store } from '@annotorious/core';
2
- import type { TextAnnotation, TextAnnotationTarget } from '../model';
3
- export interface IndexedHighlightRect {
1
+ import { AnnotationRects } from './TextAnnotationStore';
2
+ import { TextAnnotation, TextAnnotationTarget } from '../model';
3
+ import { Store } from '@annotorious/core';
4
+
5
+ interface IndexedHighlightRect {
4
6
  minX: number;
5
7
  minY: number;
6
8
  maxX: number;
@@ -14,9 +16,9 @@ export declare const createSpatialTree: (store: Store<TextAnnotation>, container
14
16
  all: () => IndexedHighlightRect[][];
15
17
  clear: () => void;
16
18
  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[];
19
+ getAnnotationBounds: (id: string) => DOMRect;
20
+ getAnnotationRects: (id: string) => DOMRect[];
21
+ getIntersecting: (minX: number, minY: number, maxX: number, maxY: number) => AnnotationRects[];
20
22
  insert: (target: TextAnnotationTarget) => void;
21
23
  recalculate: () => void;
22
24
  remove: (target: TextAnnotationTarget) => void;
@@ -24,3 +26,4 @@ export declare const createSpatialTree: (store: Store<TextAnnotation>, container
24
26
  size: () => number;
25
27
  update: (target: TextAnnotationTarget) => void;
26
28
  };
29
+ export {};
@@ -1,2 +1,3 @@
1
- import type { TextSelector } from '../model';
1
+ import { TextSelector } from '../model';
2
+
2
3
  export declare const isRevived: (selector: TextSelector[]) => boolean;
@@ -1,2 +1,3 @@
1
- import type { TextSelector } from '../model';
1
+ import { TextSelector } from '../model';
2
+
2
3
  export declare const rangeToSelector: (range: Range, container: HTMLElement, offsetReferenceSelector?: string) => TextSelector;
@@ -1,2 +1,3 @@
1
- import type { TextAnnotation } from '../model';
1
+ import { TextAnnotation } from '../model';
2
+
2
3
  export declare const reviveAnnotation: (annotation: TextAnnotation, container: HTMLElement) => TextAnnotation;
@@ -1,4 +1,5 @@
1
- import type { TextSelector } from '../model';
1
+ import { TextSelector } from '../model';
2
+
2
3
  /**
3
4
  * Creates a new selector object with the revived DOM range from the given text annotation position
4
5
  * Only the annotatable elements are processed and counted towards the range
@@ -1,2 +1,3 @@
1
- import type { TextAnnotationTarget } from '../model';
1
+ import { TextAnnotationTarget } from '../model';
2
+
2
3
  export declare const reviveTarget: (target: TextAnnotationTarget, container: HTMLElement) => TextAnnotationTarget;
@@ -1,4 +1,4 @@
1
- export declare const NOT_ANNTOTATABLE_SELECTOR = ".not-annotatable";
1
+ export declare const NOT_ANNOTATABLE_SELECTOR = ".not-annotatable";
2
2
  /**
3
3
  * Splits a DOM Range into one or more ranges that span annotatable content only.
4
4
  */
@@ -1,3 +1,4 @@
1
- import type { W3CTextAnnotation } from '../../../src';
1
+ import { W3CTextAnnotation } from '../../../src';
2
+
2
3
  export declare const textAnnotation: W3CTextAnnotation;
3
4
  export declare const incompleteTextAnnotation: W3CTextAnnotation;
@@ -1 +1 @@
1
- html,body{overscroll-behavior-y:none}.r6o-annotatable{-webkit-tap-highlight-color:transparent}.r6o-annotatable,.r6o-annotatable *{position:relative}.hovered *{cursor:pointer}.r6o-highlight-layer{left:0;position:fixed;top:0;bottom:0;width:100vw;pointer-events:none}*::selection,::selection{background:#0080ff2e}::-moz-selection{background:#0080ff2e}
1
+ .r6o-annotatable .r6o-span-highlight-layer{height:100%;left:0;pointer-events:none;position:absolute;top:0;width:100%}.r6o-annotatable .r6o-span-highlight-layer.hidden{display:none}.r6o-annotatable .r6o-span-highlight-layer .r6o-annotation{border-style:solid;border-width:0;position:absolute;display:block}html,body{overscroll-behavior-y:none}.r6o-annotatable{-webkit-tap-highlight-color:transparent}.r6o-annotatable,.r6o-annotatable *{position:relative}.hovered *{cursor:pointer}.r6o-highlight-layer{left:0;position:fixed;top:0;bottom:0;width:100vw;pointer-events:none}*::selection,::selection{background:#0080ff2e}::-moz-selection{background:#0080ff2e}