@annotorious/annotorious 3.0.5 → 3.0.6

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/index.d.ts CHANGED
@@ -7,3 +7,4 @@ export * from './Annotorious';
7
7
  export * from './AnnotoriousOpts';
8
8
  export * from './keyboardCommands';
9
9
  export type { Annotation, AnnotationBody, AnnotationTarget, Annotator, AnnotatorState, Appearance, AppearanceProvider, Color, DrawingStyle, Filter, FormatAdapter, HoverState, LifecycleEvents, ParseResult, PresentUser, Selection, SelectionState, Store, StoreChangeEvent, StoreObserver, User, W3CAnnotation, W3CAnnotationBody, W3CAnnotationTarget } from '@annotorious/core';
10
+ export { createBody, defaultColorProvider, UserSelectAction } from '@annotorious/core';
@@ -5,6 +5,6 @@ export type ImageAnnotationStore<I extends Annotation> = Store<I> & {
5
5
  getIntersecting(x: number, y: number, width: number, height: number): ImageAnnotation[];
6
6
  };
7
7
  export type SvelteImageAnnotationStore<I extends Annotation = Annotation> = SvelteStore<I> & ImageAnnotationStore<I>;
8
- export type SvelteImageAnnotatorState<I extends Annotation = Annotation> = SvelteAnnotatorState<I> & {
8
+ export type SvelteImageAnnotatorState<I extends Annotation = Annotation, E extends unknown = Annotation> = SvelteAnnotatorState<I, E> & {
9
9
  store: SvelteImageAnnotationStore<I>;
10
10
  };
@@ -2,10 +2,10 @@ import { ImageAnnotation } from '../model';
2
2
  import { AnnotoriousOpts } from '../AnnotoriousOpts';
3
3
  import { Annotation, AnnotatorState, HoverState, SelectionState } from '@annotorious/core';
4
4
  import { ImageAnnotationStore, SvelteImageAnnotatorState } from './ImageAnnotationStore';
5
- export type ImageAnnotatorState<I extends Annotation = ImageAnnotation> = AnnotatorState<I> & {
5
+ export type ImageAnnotatorState<I extends Annotation = ImageAnnotation, E extends unknown = ImageAnnotation> = AnnotatorState<I, E> & {
6
6
  store: ImageAnnotationStore<I>;
7
- selection: SelectionState<ImageAnnotation>;
8
- hover: HoverState<ImageAnnotation>;
7
+ selection: SelectionState<I, E>;
8
+ hover: HoverState<I>;
9
9
  };
10
- export declare const createImageAnnotatorState: <I extends Annotation, E extends unknown>(opts: AnnotoriousOpts<I, E>) => ImageAnnotatorState<I>;
11
- export declare const createSvelteImageAnnotatorState: <I extends Annotation, E extends unknown>(opts: AnnotoriousOpts<I, E>) => SvelteImageAnnotatorState<I>;
10
+ export declare const createImageAnnotatorState: <I extends Annotation, E extends unknown>(opts: AnnotoriousOpts<I, E>) => ImageAnnotatorState<I, E>;
11
+ export declare const createSvelteImageAnnotatorState: <I extends Annotation, E extends unknown>(opts: AnnotoriousOpts<I, E>) => SvelteImageAnnotatorState<I, E>;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@annotorious/annotorious",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "description": "Add image annotation functionality to any web page with a few lines of JavaScript",
5
5
  "author": "Rainer Simon",
6
6
  "license": "BSD-3-Clause",
7
7
  "homepage": "https://annotorious.dev",
8
+ "funding": "https://steadyhq.com/rainer-simon",
8
9
  "type": "module",
9
10
  "repository": {
10
11
  "type": "git",
@@ -42,13 +43,13 @@
42
43
  "jsdom": "^25.0.0",
43
44
  "svelte": "^4.2.19",
44
45
  "svelte-preprocess": "^6.0.2",
45
- "typescript": "5.5.4",
46
- "vite": "^5.4.3",
47
- "vite-plugin-dts": "^4.1.0",
48
- "vitest": "^2.0.5"
46
+ "typescript": "5.6.2",
47
+ "vite": "^5.4.6",
48
+ "vite-plugin-dts": "^4.2.1",
49
+ "vitest": "^2.1.1"
49
50
  },
50
51
  "dependencies": {
51
- "@annotorious/core": "3.0.5",
52
+ "@annotorious/core": "3.0.6",
52
53
  "rbush": "^4.0.1",
53
54
  "uuid": "^10.0.0"
54
55
  }
@@ -21,6 +21,12 @@ export interface ImageAnnotator<I extends Annotation = ImageAnnotation, E extend
21
21
 
22
22
  element: HTMLDivElement;
23
23
 
24
+ cancelDrawing(): void;
25
+
26
+ getDrawingTool(): string | undefined;
27
+
28
+ isDrawingEnabled(): boolean;
29
+
24
30
  listDrawingTools(): string[];
25
31
 
26
32
  registerDrawingTool(name: string, tool: typeof SvelteComponent, opts?: DrawingToolOpts): void;
@@ -108,6 +114,11 @@ export const createImageAnnotator = <I extends Annotation = ImageAnnotation, E e
108
114
  // Most of the external API functions are covered in the base annotator
109
115
  const base = createBaseAnnotator<I, E>(state, undoStack, opts.adapter);
110
116
 
117
+ const cancelDrawing = () => {
118
+ annotationLayer.$set({ drawingEnabled: false });
119
+ setTimeout(() => annotationLayer.$set({ drawingEnabled: true }), 1);
120
+ }
121
+
111
122
  const destroy = () => {
112
123
  // Destroy Svelte annotation layer
113
124
  annotationLayer.$destroy();
@@ -121,8 +132,14 @@ export const createImageAnnotator = <I extends Annotation = ImageAnnotation, E e
121
132
  undoStack.destroy();
122
133
  }
123
134
 
135
+ const getDrawingTool = () =>
136
+ annotationLayer.getDrawingTool();
137
+
124
138
  const getUser = () => currentUser;
125
139
 
140
+ const isDrawingEnabled = () =>
141
+ annotationLayer.isDrawingEnabled();
142
+
126
143
  const registerDrawingTool = (name: string, tool: typeof SvelteComponent, opts?: DrawingToolOpts) =>
127
144
  registerTool(name, tool, opts);
128
145
 
@@ -162,8 +179,11 @@ export const createImageAnnotator = <I extends Annotation = ImageAnnotation, E e
162
179
 
163
180
  return {
164
181
  ...base,
182
+ cancelDrawing,
165
183
  destroy,
184
+ getDrawingTool,
166
185
  getUser,
186
+ isDrawingEnabled,
167
187
  listDrawingTools,
168
188
  on: lifecycle.on,
169
189
  off: lifecycle.off,
@@ -13,7 +13,7 @@ export interface AnnotoriousOpts<I extends Annotation = ImageAnnotation, E exten
13
13
  // 'drag': starts drawing on drag, single click always selects
14
14
  drawingMode?: DrawingMode;
15
15
 
16
- userSelectAction?: UserSelectActionExpression<I>;
16
+ userSelectAction?: UserSelectActionExpression<E>;
17
17
 
18
18
  style?: DrawingStyleExpression<ImageAnnotation>;
19
19
 
@@ -1,4 +1,4 @@
1
- <script lang="ts" generics="T extends Annotation">
1
+ <script lang="ts" generics="I extends Annotation, E extends unknown">
2
2
  import { SvelteComponent, onMount } from 'svelte';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
  import type { Annotation, DrawingStyleExpression, StoreChangeEvent, User } from '@annotorious/core';
@@ -17,12 +17,16 @@
17
17
  export let drawingEnabled: boolean;
18
18
  export let image: HTMLImageElement | HTMLCanvasElement;
19
19
  export let preferredDrawingMode: DrawingMode;
20
- export let state: SvelteImageAnnotatorState<T>;
20
+ export let state: SvelteImageAnnotatorState<I, E>;
21
21
  export let style: DrawingStyleExpression<ImageAnnotation> | undefined = undefined;
22
22
  export let toolName: string = listDrawingTools()[0];
23
23
  export let user: User;
24
24
  export let visible = true;
25
25
 
26
+ /** API methods */
27
+ export const getDrawingTool = () => toolName;
28
+ export const isDrawingEnabled = () => drawingEnabled;
29
+
26
30
  $: ({ tool, opts } = getTool(toolName) || { tool: undefined, opts: undefined });
27
31
 
28
32
  $: drawingMode = opts?.drawingMode || preferredDrawingMode;
@@ -44,7 +48,7 @@
44
48
 
45
49
  $: ({ onPointerDown, onPointerUp } = addEventListeners(svgEl, store));
46
50
 
47
- let storeObserver: (event: StoreChangeEvent<T>) => void | undefined;
51
+ let storeObserver: (event: StoreChangeEvent<I>) => void | undefined;
48
52
 
49
53
  let editableAnnotations: ImageAnnotation[] | undefined;
50
54
 
@@ -67,7 +71,7 @@
67
71
  .filter(a => a && isImageAnnotation(a));
68
72
 
69
73
  // Track updates on the editable annotations
70
- storeObserver = (event: StoreChangeEvent<T>) => {
74
+ storeObserver = (event: StoreChangeEvent<I>) => {
71
75
  const { updated } = event.changes;
72
76
  editableAnnotations = updated?.map(change => change.newValue) as unknown as ImageAnnotation[];
73
77
  }
@@ -92,7 +96,7 @@
92
96
  }
93
97
  };
94
98
 
95
- store.addAnnotation(annotation as unknown as Partial<T>);
99
+ store.addAnnotation(annotation as unknown as Partial<I>);
96
100
 
97
101
  selection.setSelected(annotation.id);
98
102
  }
package/src/index.ts CHANGED
@@ -34,3 +34,9 @@ export type {
34
34
  W3CAnnotationBody,
35
35
  W3CAnnotationTarget
36
36
  } from '@annotorious/core';
37
+
38
+ export {
39
+ createBody,
40
+ defaultColorProvider,
41
+ UserSelectAction
42
+ } from '@annotorious/core';
@@ -11,7 +11,7 @@ export type ImageAnnotationStore<I extends Annotation> = Store<I> & {
11
11
 
12
12
  export type SvelteImageAnnotationStore<I extends Annotation = Annotation> = SvelteStore<I> & ImageAnnotationStore<I>;
13
13
 
14
- export type SvelteImageAnnotatorState<I extends Annotation = Annotation> = SvelteAnnotatorState<I> & {
14
+ export type SvelteImageAnnotatorState<I extends Annotation = Annotation, E extends unknown = Annotation> = SvelteAnnotatorState<I, E> & {
15
15
 
16
16
  store: SvelteImageAnnotationStore<I>;
17
17
 
@@ -20,25 +20,25 @@ import type {
20
20
  SvelteImageAnnotatorState
21
21
  } from './ImageAnnotationStore';
22
22
 
23
- export type ImageAnnotatorState<I extends Annotation = ImageAnnotation> = AnnotatorState<I> & {
23
+ export type ImageAnnotatorState<I extends Annotation = ImageAnnotation, E extends unknown = ImageAnnotation> = AnnotatorState<I, E> & {
24
24
 
25
25
  store: ImageAnnotationStore<I>;
26
26
 
27
- selection: SelectionState<ImageAnnotation>;
27
+ selection: SelectionState<I, E>;
28
28
 
29
- hover: HoverState<ImageAnnotation>;
29
+ hover: HoverState<I>;
30
30
 
31
31
  }
32
32
 
33
33
  export const createImageAnnotatorState = <I extends Annotation, E extends unknown> (
34
34
  opts: AnnotoriousOpts<I, E>
35
- ): ImageAnnotatorState<I> => {
35
+ ): ImageAnnotatorState<I, E> => {
36
36
 
37
37
  const store = createStore<I>();
38
38
 
39
39
  const tree = createSpatialTree();
40
40
 
41
- const selection = createSelectionState<I>(store, opts.userSelectAction);
41
+ const selection = createSelectionState<I, E>(store, opts.userSelectAction, opts.adapter);
42
42
 
43
43
  const hover = createHoverState(store);
44
44
 
@@ -70,15 +70,15 @@ export const createImageAnnotatorState = <I extends Annotation, E extends unknow
70
70
  selection,
71
71
  hover,
72
72
  viewport
73
- } as ImageAnnotatorState<I>;
73
+ } as ImageAnnotatorState<I, E>;
74
74
 
75
75
  }
76
76
 
77
77
  export const createSvelteImageAnnotatorState = <I extends Annotation, E extends unknown>(
78
78
  opts: AnnotoriousOpts<I, E>
79
- ): SvelteImageAnnotatorState<I> => {
79
+ ): SvelteImageAnnotatorState<I, E> => {
80
80
 
81
- const state = createImageAnnotatorState(opts);
81
+ const state = createImageAnnotatorState<I, E>(opts);
82
82
 
83
83
  return {
84
84
  ...state,