@annotorious/annotorious 3.0.0-rc.5 → 3.0.0-rc.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/annotorious",
3
- "version": "3.0.0-rc.5",
3
+ "version": "3.0.0-rc.7",
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",
@@ -24,7 +24,7 @@ export interface ImageAnnotator<E extends unknown = ImageAnnotation> extends Ann
24
24
 
25
25
  registerShapeEditor(shapeType: ShapeType, editor: typeof SvelteComponent): void;
26
26
 
27
- setDrawingTool(tool: DrawingTool): void;
27
+ setDrawingTool(name: DrawingTool): void;
28
28
 
29
29
  setDrawingEnabled(enabled: boolean): void;
30
30
 
@@ -120,10 +120,13 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
120
120
  const registerShapeEditor = (shapeType: ShapeType, editor: typeof SvelteComponent) =>
121
121
  registerEditor(shapeType, editor);
122
122
 
123
- const setDrawingTool = (t: DrawingTool) => {
124
- const { tool, opts } = getTool(t);
125
- // @ts-ignore
126
- annotationLayer.$set({ tool, opts })
123
+ const setDrawingTool = (name: DrawingTool) => {
124
+ // Validate that the tool exists
125
+ const toolSpec = getTool(name);
126
+ if (!toolSpec)
127
+ throw `No drawing tool named ${name}`;
128
+
129
+ annotationLayer.$set({ toolName: name })
127
130
  }
128
131
 
129
132
  const setDrawingEnabled = (enabled: boolean) =>
@@ -6,7 +6,7 @@
6
6
  import type { ImageAnnotation, Shape} from '../model';
7
7
  import { getEditor, EditorMount } from './editors';
8
8
  import { Ellipse, Polygon, Rectangle} from './shapes';
9
- import { getTool, ToolMount } from './tools';
9
+ import { getTool, listDrawingTools, ToolMount } from './tools';
10
10
  import { enableResponsive } from './utils';
11
11
  import { createSVGTransform } from './Transform';
12
12
  import { addEventListeners } from './SVGAnnotationLayerPointerEvent';
@@ -19,9 +19,11 @@
19
19
  export let preferredDrawingMode: DrawingMode;
20
20
  export let state: SvelteImageAnnotatorState;
21
21
  export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
22
- export let { tool, opts } = getTool('rectangle');
22
+ export let toolName: string = listDrawingTools().length > 0 ? listDrawingTools()[0] : undefined;
23
23
  export let user: User;
24
24
 
25
+ $: ({ tool, opts } = getTool(toolName));
26
+
25
27
  $: drawingMode = opts?.drawingMode || preferredDrawingMode;
26
28
 
27
29
  /** Drawing tool layer **/
@@ -154,7 +156,7 @@
154
156
  {/key}
155
157
  {/each}
156
158
  {:else if (tool && drawingEnabled)}
157
- {#key tool}
159
+ {#key toolName}
158
160
  <ToolMount
159
161
  target={drawingEl}
160
162
  tool={tool}