@soomo/text-annotator 3.0.0-staging.4 → 3.0.0-staging.40

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 (31) hide show
  1. package/dist/src/SelectionHandler.d.ts +5 -3
  2. package/dist/src/TextAnnotator.d.ts +7 -5
  3. package/dist/src/TextAnnotatorOptions.d.ts +7 -4
  4. package/dist/src/api/scrollIntoView.d.ts +2 -2
  5. package/dist/src/highlight/Highlight.d.ts +1 -1
  6. package/dist/src/highlight/HighlightPainter.d.ts +2 -2
  7. package/dist/src/highlight/HighlightStyle.d.ts +2 -2
  8. package/dist/src/highlight/baseRenderer.d.ts +5 -5
  9. package/dist/src/highlight/canvas/canvasRenderer.d.ts +1 -1
  10. package/dist/src/highlight/highlights/highlightsRenderer.d.ts +2 -2
  11. package/dist/src/highlight/span/spansRenderer.d.ts +1 -1
  12. package/dist/src/highlight/viewport.d.ts +1 -1
  13. package/dist/src/index.d.ts +2 -3
  14. package/dist/src/model/w3c/W3CTextFormatAdapter.d.ts +2 -2
  15. package/dist/src/presence/PresencePainter.d.ts +2 -2
  16. package/dist/src/state/TextAnnotationStore.d.ts +7 -3
  17. package/dist/src/state/TextAnnotatorState.d.ts +3 -3
  18. package/dist/src/state/spatialTree.d.ts +8 -3
  19. package/dist/src/utils/cancelSingleClickEvents.d.ts +6 -0
  20. package/dist/src/utils/cloneEvents.d.ts +11 -0
  21. package/dist/src/utils/index.d.ts +5 -0
  22. package/dist/src/utils/mergeClientRects.d.ts +1 -0
  23. package/dist/src/utils/normalizeRects.d.ts +2 -0
  24. package/dist/src/utils/programmaticallyFocusable.d.ts +6 -0
  25. package/dist/src/utils/trimRangeToContainer.d.ts +1 -0
  26. package/dist/text-annotator.css +1 -1
  27. package/dist/text-annotator.es.js +1668 -1152
  28. package/dist/text-annotator.es.js.map +1 -1
  29. package/dist/text-annotator.umd.js +2 -2
  30. package/dist/text-annotator.umd.js.map +1 -1
  31. package/package.json +14 -12
@@ -1,7 +1,9 @@
1
+ import { Filter, User } from '@annotorious/core';
1
2
  import { TextAnnotatorState } from './state';
2
- import { User } from '@annotorious/core';
3
3
 
4
- export declare const SelectionHandler: (container: HTMLElement, state: TextAnnotatorState, offsetReferenceSelector?: string) => {
4
+ export declare const createSelectionHandler: (container: HTMLElement, state: TextAnnotatorState, offsetReferenceSelector?: string) => {
5
5
  destroy: () => void;
6
- setUser: (user: User) => User;
6
+ setFilter: (filter?: Filter) => Filter;
7
+ setUser: (user?: User) => User;
8
+ setAnnotatingEnabled: (enabled: boolean) => boolean;
7
9
  };
@@ -1,13 +1,15 @@
1
- import { TextAnnotatorOptions } from './TextAnnotatorOptions';
2
- import { TextAnnotation } from './model';
3
- import { TextAnnotatorState } from './state';
4
- import { HighlightStyleExpression } from './highlight';
5
1
  import { Annotator } from '@annotorious/core';
2
+ import { HighlightStyleExpression } from './highlight';
3
+ import { TextAnnotatorState } from './state';
4
+ import { TextAnnotation } from './model';
5
+ import { TextAnnotatorOptions } from './TextAnnotatorOptions';
6
6
 
7
7
  export interface TextAnnotator<E extends unknown = TextAnnotation> extends Annotator<TextAnnotation, E> {
8
8
  element: HTMLElement;
9
9
  setStyle(style: HighlightStyleExpression | undefined): void;
10
+ redraw(force?: boolean): void;
10
11
  scrollIntoView(annotation: TextAnnotation): boolean;
12
+ setAnnotatingEnabled: (enabled: boolean) => void;
11
13
  state: TextAnnotatorState;
12
14
  }
13
- export declare const createTextAnnotator: <E extends unknown = TextAnnotation>(container: HTMLElement, opts?: TextAnnotatorOptions<E>) => TextAnnotator<E>;
15
+ export declare const createTextAnnotator: <E extends unknown = TextAnnotation>(container: HTMLElement, options?: TextAnnotatorOptions<E>) => TextAnnotator<E>;
@@ -1,14 +1,17 @@
1
- import { HighlightStyleExpression } from './highlight';
2
- import { TextAnnotation } from './model';
1
+ import { FormatAdapter, UserSelectActionExpression, User } from '@annotorious/core';
3
2
  import { PresencePainterOptions } from './presence';
4
- import { FormatAdapter, PointerSelectAction } from '@annotorious/core';
3
+ import { TextAnnotation } from './model';
4
+ import { HighlightStyleExpression } from './highlight';
5
5
 
6
6
  export interface TextAnnotatorOptions<T extends unknown = TextAnnotation> {
7
7
  adapter?: FormatAdapter<TextAnnotation, T> | null;
8
+ annotatingEnabled?: boolean;
8
9
  renderer?: RendererType;
9
10
  offsetReferenceSelector?: string;
10
- pointerAction?: PointerSelectAction | ((annotation: TextAnnotation) => PointerSelectAction);
11
+ userSelectAction?: UserSelectActionExpression<TextAnnotation>;
11
12
  presence?: PresencePainterOptions;
12
13
  style?: HighlightStyleExpression;
14
+ user?: User;
13
15
  }
14
16
  export type RendererType = 'SPANS' | 'CANVAS' | 'CSS_HIGHLIGHTS';
17
+ export declare const fillDefaults: <T extends unknown = TextAnnotation>(opts: TextAnnotatorOptions<T>, defaults: TextAnnotatorOptions<T>) => TextAnnotatorOptions<T>;
@@ -1,4 +1,4 @@
1
- import { TextAnnotation } from '../model';
2
1
  import { TextAnnotationStore } from '../state';
2
+ import { TextAnnotation } from '../model';
3
3
 
4
- export declare const scrollIntoView: (container: HTMLElement, store: TextAnnotationStore) => (annotation: TextAnnotation) => boolean;
4
+ export declare const scrollIntoView: (container: HTMLElement, store: TextAnnotationStore) => (annotationOrId: string | TextAnnotation) => boolean;
@@ -1,5 +1,5 @@
1
- import { AnnotationRects } from '../state';
2
1
  import { AnnotationState } from '@annotorious/core';
2
+ import { AnnotationRects } from '../state';
3
3
 
4
4
  export interface Highlight extends AnnotationRects {
5
5
  state: AnnotationState;
@@ -1,6 +1,6 @@
1
- import { ViewportBounds } from './viewport';
2
- import { HighlightStyle, HighlightStyleExpression } from './HighlightStyle';
3
1
  import { Highlight } from './Highlight';
2
+ import { HighlightStyle, HighlightStyleExpression } from './HighlightStyle';
3
+ import { ViewportBounds } from './viewport';
4
4
 
5
5
  export interface HighlightPainter {
6
6
  clear(): void;
@@ -1,5 +1,5 @@
1
- import { TextAnnotation } from 'src/model';
2
1
  import { AnnotationState, Color, DrawingStyle } from '@annotorious/core';
2
+ import { TextAnnotation } from 'src/model';
3
3
 
4
4
  export interface HighlightStyle extends Pick<DrawingStyle, 'fill' | 'fillOpacity'> {
5
5
  underlineStyle?: string;
@@ -7,6 +7,6 @@ export interface HighlightStyle extends Pick<DrawingStyle, 'fill' | 'fillOpacity
7
7
  underlineOffset?: number;
8
8
  underlineThickness?: number;
9
9
  }
10
- export type HighlightStyleExpression = HighlightStyle | ((annotation: TextAnnotation, state: AnnotationState, zIndex?: number) => HighlightStyle);
10
+ export type HighlightStyleExpression = HighlightStyle | ((annotation: TextAnnotation, state: AnnotationState, zIndex?: number) => HighlightStyle | undefined);
11
11
  export declare const DEFAULT_STYLE: HighlightStyle;
12
12
  export declare const DEFAULT_SELECTED_STYLE: HighlightStyle;
@@ -1,9 +1,9 @@
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
1
  import { Filter, ViewportState } from '@annotorious/core';
2
+ import { TextAnnotatorState } from '../state';
3
+ import { ViewportBounds } from './viewport';
4
+ import { HighlightPainter } from './HighlightPainter';
5
+ import { Highlight } from './Highlight';
6
+ import { HighlightStyleExpression } from './HighlightStyle';
7
7
 
8
8
  export interface RendererImplementation {
9
9
  destroy(): void;
@@ -1,4 +1,4 @@
1
1
  import { ViewportState } from '@annotorious/core';
2
- import { TextAnnotatorState } from 'src/state';
2
+ import { TextAnnotatorState } from '../../state';
3
3
 
4
4
  export declare const createCanvasRenderer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState) => import('../baseRenderer').Renderer;
@@ -1,6 +1,6 @@
1
- import { RendererImplementation } from '../baseRenderer';
2
- import { TextAnnotatorState } from 'src/state';
3
1
  import { ViewportState } from '@annotorious/core';
2
+ import { TextAnnotatorState } from 'src/state';
3
+ import { RendererImplementation } from '../baseRenderer';
4
4
 
5
5
  export declare const createRenderer: () => RendererImplementation;
6
6
  export declare const createHighlightsRenderer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState) => import('../baseRenderer').Renderer;
@@ -1,4 +1,4 @@
1
- import { TextAnnotatorState } from '../../state';
2
1
  import { ViewportState } from '@annotorious/core';
2
+ import { TextAnnotatorState } from '../../state';
3
3
 
4
4
  export declare const createSpansRenderer: (container: HTMLElement, state: TextAnnotatorState, viewport: ViewportState) => import('../baseRenderer').Renderer;
@@ -1,5 +1,5 @@
1
- import { TextAnnotation } from '../model';
2
1
  import { ViewportState } from '@annotorious/core';
2
+ import { TextAnnotation } from '../model';
3
3
 
4
4
  export interface ViewportBounds {
5
5
  top: number;
@@ -1,4 +1,3 @@
1
- import { Origin as _Origin } from '@annotorious/core';
2
1
  export * from './highlight';
3
2
  export * from './model';
4
3
  export * from './state';
@@ -6,5 +5,5 @@ export * from './utils';
6
5
  export * from './presence/PresencePainterOptions';
7
6
  export * from './TextAnnotator';
8
7
  export * from './TextAnnotatorOptions';
9
- export type { Filter } from '@annotorious/core';
10
- export { _Origin as Origin };
8
+ export type { Annotation, AnnotationBody, AnnotationTarget, Annotator, AnnotatorState, Color, Filter, FormatAdapter, HoverState, Selection, SelectionState, Store, StoreChangeEvent, StoreObserver, ParseResult, User, UserSelectActionExpression, W3CAnnotation, W3CAnnotationBody, W3CAnnotationTarget } from '@annotorious/core';
9
+ export { createBody, Origin, UserSelectAction } from '@annotorious/core';
@@ -1,6 +1,6 @@
1
- import { W3CTextAnnotation } from '../w3c';
2
- import { TextAnnotation } from '../core';
3
1
  import { FormatAdapter, ParseResult } from '@annotorious/core';
2
+ import { TextAnnotation } from '../core';
3
+ import { W3CTextAnnotation } from '../w3c';
4
4
 
5
5
  export type W3CTextFormatAdapter = FormatAdapter<TextAnnotation, W3CTextAnnotation>;
6
6
  /**
@@ -1,5 +1,5 @@
1
- import { PresencePainterOptions } from 'src/presence';
2
- import { HighlightPainter } from '../highlight';
3
1
  import { PresenceProvider } from '@annotorious/core';
2
+ import { HighlightPainter } from '../highlight';
3
+ import { PresencePainterOptions } from '../presence';
4
4
 
5
5
  export declare const createPresencePainter: (container: HTMLElement, provider: PresenceProvider, opts?: PresencePainterOptions) => HighlightPainter;
@@ -1,14 +1,18 @@
1
+ import { Unsubscribe } from 'nanoevents';
2
+ import { Filter, Origin, Store } from '@annotorious/core';
1
3
  import { TextAnnotation } from '../model';
2
- import { Origin, Store } from '@annotorious/core';
4
+ import { SpatialTreeEvents } from './spatialTree';
3
5
 
4
6
  export interface TextAnnotationStore extends Omit<Store<TextAnnotation>, 'addAnnotation' | 'bulkAddAnnotation'> {
5
7
  addAnnotation(annotation: TextAnnotation, origin?: Origin): boolean;
6
8
  bulkAddAnnotation(annotations: TextAnnotation[], replace: boolean, origin?: Origin): TextAnnotation[];
7
9
  bulkUpsertAnnotations(annotations: TextAnnotation[], origin?: Origin): TextAnnotation[];
8
- getAnnotationBounds(id: string, hintX?: number, hintY?: number, buffer?: number): DOMRect;
9
- getAt(x: number, y: number): TextAnnotation | undefined;
10
+ getAnnotationRects(id: string): DOMRect[];
11
+ getAnnotationBounds(id: string, hintX?: number, hintY?: number, buffer?: number): DOMRect | undefined;
12
+ getAt(x: number, y: number, filter?: Filter): TextAnnotation | undefined;
10
13
  getIntersecting(minX: number, minY: number, maxX: number, maxY: number): AnnotationRects[];
11
14
  recalculatePositions(): void;
15
+ onRecalculatePositions(callback: SpatialTreeEvents['recalculate']): Unsubscribe;
12
16
  }
13
17
  export interface AnnotationRects {
14
18
  annotation: TextAnnotation;
@@ -1,6 +1,6 @@
1
- import { TextAnnotationStore } from './TextAnnotationStore';
1
+ import { ViewportState, UserSelectActionExpression, AnnotatorState, SelectionState, HoverState } from '@annotorious/core';
2
2
  import { TextAnnotation } from '../model';
3
- import { PointerSelectAction, ViewportState, AnnotatorState, SelectionState, HoverState } from '@annotorious/core';
3
+ import { TextAnnotationStore } from './TextAnnotationStore';
4
4
 
5
5
  export interface TextAnnotatorState extends AnnotatorState<TextAnnotation> {
6
6
  store: TextAnnotationStore;
@@ -8,4 +8,4 @@ export interface TextAnnotatorState extends AnnotatorState<TextAnnotation> {
8
8
  hover: HoverState<TextAnnotation>;
9
9
  viewport: ViewportState;
10
10
  }
11
- export declare const createTextAnnotatorState: (container: HTMLElement, defaultPointerAction?: PointerSelectAction | ((annotation: TextAnnotation) => PointerSelectAction)) => TextAnnotatorState;
11
+ export declare const createTextAnnotatorState: (container: HTMLElement, defaultUserSelectAction?: UserSelectActionExpression<TextAnnotation>) => TextAnnotatorState;
@@ -1,6 +1,7 @@
1
- import { AnnotationRects } from './TextAnnotationStore';
2
- import { TextAnnotation, TextAnnotationTarget } from '../model';
3
1
  import { Store } from '@annotorious/core';
2
+ import { Unsubscribe } from 'nanoevents';
3
+ import { TextAnnotation, TextAnnotationTarget } from '../model';
4
+ import { AnnotationRects } from './TextAnnotationStore';
4
5
 
5
6
  interface IndexedHighlightRect {
6
7
  minX: number;
@@ -12,10 +13,13 @@ interface IndexedHighlightRect {
12
13
  rects: DOMRect[];
13
14
  };
14
15
  }
16
+ export interface SpatialTreeEvents {
17
+ recalculate(): void;
18
+ }
15
19
  export declare const createSpatialTree: (store: Store<TextAnnotation>, container: HTMLElement) => {
16
20
  all: () => IndexedHighlightRect[][];
17
21
  clear: () => void;
18
- getAt: (x: number, y: number) => string | undefined;
22
+ getAt: (x: number, y: number, all?: boolean) => string[];
19
23
  getAnnotationBounds: (id: string) => DOMRect;
20
24
  getAnnotationRects: (id: string) => DOMRect[];
21
25
  getIntersecting: (minX: number, minY: number, maxX: number, maxY: number) => AnnotationRects[];
@@ -25,5 +29,6 @@ export declare const createSpatialTree: (store: Store<TextAnnotation>, container
25
29
  set: (targets: TextAnnotationTarget[], replace?: boolean) => void;
26
30
  size: () => number;
27
31
  update: (target: TextAnnotationTarget) => void;
32
+ on: <E extends keyof SpatialTreeEvents>(event: E, callback: SpatialTreeEvents[E]) => Unsubscribe;
28
33
  };
29
34
  export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Calls .preventDefault() on click events in annotable areas, in order
3
+ * to prevent problematic default browser behavior. (Specifically: keep
4
+ * Chrome Android from triggering word selection on single click.)
5
+ */
6
+ export declare const cancelSingleClickEvents: (container: HTMLElement) => void;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Events need to be manually mapped into new objects:
3
+ * 1. It preserves the `target` and `currentTarget` properties.
4
+ * Otherwise, they will be `null` when the event is read beyond the handler.
5
+ * 2. Spread operator can copy only own enumerable properties, not inherited ones.
6
+ * Therefore, we need to manually copy the props we're interested in.
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
8
+ * @see https://github.com/recogito/text-annotator-js/commit/65d13f3108c429311cf8c2523f6babbbc946013d#r144041390
9
+ */
10
+ export declare const clonePointerEvent: (event: PointerEvent) => PointerEvent;
11
+ export declare const cloneKeyboardEvent: (event: KeyboardEvent) => KeyboardEvent;
@@ -1,3 +1,5 @@
1
+ export * from './cancelSingleClickEvents';
2
+ export * from './programmaticallyFocusable';
1
3
  export * from './debounce';
2
4
  export * from './getAnnotatableFragment';
3
5
  export * from './getClientRectsPonyfill';
@@ -10,3 +12,6 @@ export * from './reviveAnnotation';
10
12
  export * from './reviveSelector';
11
13
  export * from './reviveTarget';
12
14
  export * from './splitAnnotatableRanges';
15
+ export * from './trimRangeToContainer';
16
+ export * from './normalizeRects';
17
+ export * from './cloneEvents';
@@ -1 +1,2 @@
1
1
  export declare const mergeClientRects: (rects: DOMRect[]) => DOMRect[];
2
+ export declare const toDomRectList: (rects: DOMRect[]) => DOMRectList;
@@ -0,0 +1,2 @@
1
+ export declare const normalizeRectWithOffset: (rect: DOMRect, offset: DOMRect) => DOMRect;
2
+ export declare const denormalizeRectWithOffset: (rect: DOMRect, offset: DOMRect) => DOMRect;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Makes an element programmatically focusable by adding a `tabindex="-1"` attribute.
3
+ * Or does nothing if the element is already focusable 🤷🏻
4
+ * It's required to process keyboard events on an element that is not natively focusable.
5
+ */
6
+ export declare const programmaticallyFocusable: (container: HTMLElement) => void;
@@ -0,0 +1 @@
1
+ export declare const trimRangeToContainer: (range: Range, container: HTMLElement) => Range;
@@ -1 +1 @@
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}
1
+ .r6o-canvas-highlight-layer{position:fixed;top:0;bottom:0;left:0;width:100vw;height:100vh;pointer-events:none}.r6o-canvas-highlight-layer.bg{mix-blend-mode:multiply;z-index:1}.r6o-annotatable .r6o-span-highlight-layer{position:absolute;top:0;left:0;width:100%;height:100%;mix-blend-mode:multiply;pointer-events:none;z-index:1}.r6o-annotatable .r6o-span-highlight-layer.hidden{display:none}.r6o-annotatable .r6o-span-highlight-layer .r6o-annotation{border-style:solid;border-width:0;box-sizing:content-box;display:block;position:absolute}.r6o-annotation{box-sizing:content-box}.r6o-presence-layer{left:0;position:fixed;top:0;bottom:0;width:100vw;pointer-events:none}html,body{overscroll-behavior-y:none}.r6o-annotatable{position:relative;-webkit-tap-highlight-color:transparent}.r6o-annotatable.no-focus-outline{outline:none}.hovered *{cursor:pointer}*::selection,::selection{background:#0080ff2e}::-moz-selection{background:#0080ff2e}