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

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.
@@ -1,5 +1,5 @@
1
- import type { UndoStack } from '@annotorious/core';
2
- export declare const initKeyboardCommands: (undoStack: UndoStack, container?: Element) => {
1
+ import type { Annotation, UndoStack } from '@annotorious/core';
2
+ export declare const initKeyboardCommands: <T extends Annotation>(undoStack: UndoStack<T>, container?: Element) => {
3
3
  destroy: () => void;
4
4
  };
5
5
  //# sourceMappingURL=keyboardCommands.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyboardCommands.d.ts","sourceRoot":"","sources":["../src/keyboardCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD,eAAO,MAAM,oBAAoB,cACpB,SAAS,cACR,OAAO;;CAuCpB,CAAA"}
1
+ {"version":3,"file":"keyboardCommands.d.ts","sourceRoot":"","sources":["../src/keyboardCommands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI/D,eAAO,MAAM,oBAAoB,8DAEnB,OAAO;;CAuCpB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"W3CImageFormatAdapter.d.ts","sourceRoot":"","sources":["../../../src/model/w3c/W3CImageFormatAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEnF,OAAO,KAAK,EAAE,eAAe,EAAqB,MAAM,SAAS,CAAC;AAMlE,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AAElF,eAAO,MAAM,cAAc,WACjB,MAAM,YACL,OAAO,0BAUjB,CAAA;AAED,eAAO,MAAM,uBAAuB,eACtB,aAAa,YAChB,OAAO,KACf,YAAY,eAAe,CA+B7B,CAAA;AAED,eAAO,MAAM,2BAA2B,eAC1B,eAAe,UACnB,MAAM,KACb,aAmBF,CAAC"}
1
+ {"version":3,"file":"W3CImageFormatAdapter.d.ts","sourceRoot":"","sources":["../../../src/model/w3c/W3CImageFormatAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEnF,OAAO,KAAK,EAAE,eAAe,EAAqB,MAAM,SAAS,CAAC;AAMlE,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AAElF,eAAO,MAAM,cAAc,WACjB,MAAM,YACL,OAAO,0BAUjB,CAAA;AAED,eAAO,MAAM,uBAAuB,eACtB,aAAa,YAChB,OAAO,KACf,YAAY,eAAe,CAgC7B,CAAA;AAED,eAAO,MAAM,2BAA2B,eAC1B,eAAe,UACnB,MAAM,KACb,aAmBF,CAAC"}
@@ -1,3 +1,5 @@
1
+ import type { Theme } from '../../AnnotoriousOpts';
1
2
  export declare const sampleBrightness: (imageOrCanvas: HTMLElement) => number;
2
- export declare const setTheme: (imageOrCanvas: HTMLElement, container: HTMLElement) => void;
3
+ export declare const detectTheme: (imageOrCanvas: HTMLElement) => "dark" | "light";
4
+ export declare const setTheme: (imageOrCanvas: HTMLElement, container: HTMLElement, theme: Theme) => void;
3
5
  //# sourceMappingURL=setTheme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"setTheme.d.ts","sourceRoot":"","sources":["../../../src/themes/smart/setTheme.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,kBAAmB,WAAW,WAmC1D,CAAA;AAED,eAAO,MAAM,QAAQ,kBAAmB,WAAW,aAAa,WAAW,SAQ1E,CAAA"}
1
+ {"version":3,"file":"setTheme.d.ts","sourceRoot":"","sources":["../../../src/themes/smart/setTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,eAAO,MAAM,gBAAgB,kBAAmB,WAAW,WAmC1D,CAAA;AAED,eAAO,MAAM,WAAW,kBAAmB,WAAW,qBAOrD,CAAA;AAED,eAAO,MAAM,QAAQ,kBAAmB,WAAW,aAAa,WAAW,SAAS,KAAK,SACI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/annotorious",
3
- "version": "3.0.0-rc.3",
3
+ "version": "3.0.0-rc.5",
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",
@@ -48,6 +48,9 @@
48
48
  "vite-plugin-dts": "^3.6.0",
49
49
  "vitest": "^0.34.6"
50
50
  },
51
+ "peerDependencies": {
52
+ "@annotorious/core": "*"
53
+ },
51
54
  "dependencies": {
52
55
  "rbush": "^3.0.1",
53
56
  "uuid": "^9.0.1"
@@ -7,8 +7,8 @@ import { SVGAnnotationLayer } from './annotation';
7
7
  import type { DrawingToolOpts, SVGAnnotationLayerPointerEvent } from './annotation';
8
8
  import type { ImageAnnotation, ShapeType } from './model';
9
9
  import { createSvelteImageAnnotatorState } from './state';
10
- import { setTheme } from './themes';
11
- import { fillDefaults } from './AnnotoriousOpts';
10
+ import { setTheme as _setTheme } from './themes';
11
+ import { fillDefaults, type Theme } from './AnnotoriousOpts';
12
12
  import type { AnnotoriousOpts } from './AnnotoriousOpts';
13
13
  import { initKeyboardCommands } from './keyboardCommands';
14
14
 
@@ -28,6 +28,8 @@ export interface ImageAnnotator<E extends unknown = ImageAnnotation> extends Ann
28
28
 
29
29
  setDrawingEnabled(enabled: boolean): void;
30
30
 
31
+ setTheme(theme: Theme): void;
32
+
31
33
  }
32
34
 
33
35
  export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
@@ -45,13 +47,14 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
45
47
 
46
48
  const state = createSvelteImageAnnotatorState(opts);
47
49
 
48
- const { hover, selection, store } = state;
49
-
50
- const lifecycle = createLifecyleObserver<ImageAnnotation, E>(
51
- store, selection, hover, undefined, opts.adapter, opts.autoSave);
50
+ const { selection, store } = state;
52
51
 
53
52
  const undoStack = createUndoStack(store);
54
53
 
54
+ const lifecycle = createLifecyleObserver<ImageAnnotation, E>(
55
+ state, undoStack, opts.adapter, opts.autoSave
56
+ );
57
+
55
58
  // We'll wrap the image in a container DIV.
56
59
  const container = document.createElement('DIV');
57
60
  container.style.position = 'relative';
@@ -67,7 +70,7 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
67
70
 
68
71
  let currentUser: User = createAnonymousGuest();
69
72
 
70
- setTheme(img, container);
73
+ _setTheme(img, container, opts.theme);
71
74
 
72
75
  const annotationLayer = new SVGAnnotationLayer({
73
76
  target: container,
@@ -94,7 +97,7 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
94
97
  /******++++++*************/
95
98
 
96
99
  // Most of the external API functions are covered in the base annotator
97
- const base = createBaseAnnotator<ImageAnnotation, E>(store, undoStack, opts.adapter);
100
+ const base = createBaseAnnotator<ImageAnnotation, E>(state, undoStack, opts.adapter);
98
101
 
99
102
  const destroy = () => {
100
103
  // Destroy Svelte annotation layer
@@ -130,17 +133,11 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
130
133
  console.warn('Filter not implemented yet');
131
134
  }
132
135
 
133
- const setSelected = (arg?: string | string[]) => {
134
- if (arg) {
135
- selection.setSelected(arg);
136
- } else {
137
- selection.clear();
138
- }
139
- }
140
-
141
136
  const setStyle = (style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined) =>
142
137
  annotationLayer.$set({ style });
143
138
 
139
+ const setTheme = (theme: Theme) => _setTheme(img, container, theme);
140
+
144
141
  const setUser = (user: User) => {
145
142
  currentUser = user;
146
143
  annotationLayer.$set({ user });
@@ -158,8 +155,8 @@ export const createImageAnnotator = <E extends unknown = ImageAnnotation>(
158
155
  setDrawingEnabled,
159
156
  setDrawingTool,
160
157
  setFilter,
161
- setSelected,
162
158
  setStyle,
159
+ setTheme,
163
160
  setUser,
164
161
  state
165
162
  }
@@ -18,10 +18,14 @@ export interface AnnotoriousOpts<I extends Annotation = ImageAnnotation, E exten
18
18
 
19
19
  style?: DrawingStyle | ((annotation: I) => DrawingStyle);
20
20
 
21
+ theme?: Theme;
22
+
21
23
  }
22
24
 
23
25
  export type DrawingMode = 'click' | 'drag';
24
26
 
27
+ export type Theme = 'dark' | 'light' | 'auto';
28
+
25
29
  export const fillDefaults = <I extends ImageAnnotation = ImageAnnotation, E extends unknown = ImageAnnotation> (
26
30
  opts: AnnotoriousOpts<I, E>
27
31
  ): AnnotoriousOpts<I, E> => {
@@ -30,7 +34,8 @@ export const fillDefaults = <I extends ImageAnnotation = ImageAnnotation, E exte
30
34
  ...opts,
31
35
  drawingEnabled: opts.drawingEnabled === undefined ? true : opts.drawingEnabled,
32
36
  drawingMode: opts.drawingMode || 'drag',
33
- pointerSelectAction: opts.pointerSelectAction || PointerSelectAction.EDIT
37
+ pointerSelectAction: opts.pointerSelectAction || PointerSelectAction.EDIT,
38
+ theme: opts.theme || 'light'
34
39
  };
35
40
 
36
41
  };
@@ -13,7 +13,7 @@
13
13
  export let transform: Transform;
14
14
  export let viewportScale = 1;
15
15
 
16
- let lastPointerDown: PointerEvent;
16
+ let lastPointerDown: { timeStamp: number, offsetX: number, offsetY: number };
17
17
 
18
18
  let points: [number, number][] = [];
19
19
 
@@ -26,7 +26,9 @@
26
26
  $: handleSize = 10 / viewportScale;
27
27
 
28
28
  const onPointerDown = (evt: PointerEvent) => {
29
- lastPointerDown = {...evt};
29
+ // Note that the event itself is ephemeral!
30
+ const { timeStamp, offsetX, offsetY } = evt;
31
+ lastPointerDown = { timeStamp, offsetX, offsetY };
30
32
 
31
33
  if (drawingMode === 'drag') {
32
34
  if (points.length === 0) {
@@ -1,9 +1,9 @@
1
- import type { UndoStack } from '@annotorious/core';
1
+ import type { Annotation, UndoStack } from '@annotorious/core';
2
2
 
3
3
  const isMac = navigator.userAgent.indexOf('Mac OS X') !== -1;
4
4
 
5
- export const initKeyboardCommands = (
6
- undoStack: UndoStack,
5
+ export const initKeyboardCommands = <T extends Annotation>(
6
+ undoStack: UndoStack<T>,
7
7
  container?: Element
8
8
  ) => {
9
9
 
@@ -50,12 +50,13 @@ export const parseW3CImageAnnotation = (
50
50
  id: annotationId,
51
51
  bodies,
52
52
  target: {
53
+ ...rest.target,
53
54
  annotation: annotationId,
54
55
  selector
55
56
  }
56
57
  }
57
58
  } : {
58
- error: Error(`Unknown selector type: ${selector.type}`)
59
+ error: Error(`Unknown selector type: ${w3cSelector.type}`)
59
60
  };
60
61
 
61
62
  }
@@ -1,3 +1,5 @@
1
+ import type { Theme } from '../../AnnotoriousOpts';
2
+
1
3
  export const sampleBrightness = (imageOrCanvas: HTMLElement) => {
2
4
 
3
5
  let canvas: HTMLCanvasElement;
@@ -35,12 +37,14 @@ export const sampleBrightness = (imageOrCanvas: HTMLElement) => {
35
37
  return totalBrightness / 81;
36
38
  }
37
39
 
38
- export const setTheme = (imageOrCanvas: HTMLElement, container: HTMLElement) => {
40
+ export const detectTheme = (imageOrCanvas: HTMLElement) => {
39
41
  const brightness = sampleBrightness(imageOrCanvas);
40
-
41
42
  const theme = brightness > 0.6 ? 'dark' : 'light'
42
43
 
43
44
  console.log(`[Annotorious] Image brightness: ${brightness.toFixed(1)}. Setting ${theme} theme.`);
44
45
 
45
- container.setAttribute('data-theme', theme);
46
- }
46
+ return theme;
47
+ }
48
+
49
+ export const setTheme = (imageOrCanvas: HTMLElement, container: HTMLElement, theme: Theme) =>
50
+ container.setAttribute('data-theme', theme === 'auto' ? detectTheme(imageOrCanvas) : theme);