@annotorious/annotorious 3.0.0-rc.21 → 3.0.0-rc.4

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 (77) hide show
  1. package/dist/Annotorious.d.ts +2 -5
  2. package/dist/Annotorious.d.ts.map +1 -1
  3. package/dist/AnnotoriousOpts.d.ts +3 -2
  4. package/dist/AnnotoriousOpts.d.ts.map +1 -1
  5. package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts.map +1 -1
  6. package/dist/annotation/editors/Handle.d.ts +14 -0
  7. package/dist/annotation/editors/Handle.d.ts.map +1 -0
  8. package/dist/annotation/editors/editorsRegistry.d.ts +1 -1
  9. package/dist/annotation/editors/editorsRegistry.d.ts.map +1 -1
  10. package/dist/annotation/editors/index.d.ts +1 -1
  11. package/dist/annotation/editors/index.d.ts.map +1 -1
  12. package/dist/annotation/tools/drawingToolsRegistry.d.ts +4 -4
  13. package/dist/annotation/tools/drawingToolsRegistry.d.ts.map +1 -1
  14. package/dist/annotation/utils/responsive.d.ts +1 -2
  15. package/dist/annotation/utils/responsive.d.ts.map +1 -1
  16. package/dist/annotation/utils/styling.d.ts +1 -1
  17. package/dist/annotation/utils/styling.d.ts.map +1 -1
  18. package/dist/annotation/utils/touch.d.ts.map +1 -1
  19. package/dist/annotorious.css +1 -1
  20. package/dist/annotorious.es.js +2046 -2300
  21. package/dist/annotorious.es.js.map +1 -1
  22. package/dist/annotorious.js +1 -1
  23. package/dist/annotorious.js.map +1 -1
  24. package/dist/index.d.ts +7 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/keyboardCommands.d.ts.map +1 -1
  27. package/dist/model/w3c/W3CImageFormatAdapter.d.ts +2 -3
  28. package/dist/model/w3c/W3CImageFormatAdapter.d.ts.map +1 -1
  29. package/dist/model/w3c/fragment/FragmentSelector.d.ts +2 -1
  30. package/dist/model/w3c/fragment/FragmentSelector.d.ts.map +1 -1
  31. package/dist/model/w3c/index.d.ts +0 -1
  32. package/dist/model/w3c/index.d.ts.map +1 -1
  33. package/dist/model/w3c/svg/SVG.d.ts.map +1 -1
  34. package/dist/model/w3c/svg/SVGSelector.d.ts +2 -1
  35. package/dist/model/w3c/svg/SVGSelector.d.ts.map +1 -1
  36. package/dist/state/ImageAnnotatorState.d.ts.map +1 -1
  37. package/dist/state/spatialTree.d.ts +1 -1
  38. package/dist/state/spatialTree.d.ts.map +1 -1
  39. package/package.json +16 -13
  40. package/src/Annotorious.css +5 -5
  41. package/src/Annotorious.ts +12 -21
  42. package/src/AnnotoriousOpts.ts +7 -7
  43. package/src/annotation/SVGAnnotationLayer.svelte +15 -21
  44. package/src/annotation/SVGAnnotationLayerPointerEvent.ts +2 -1
  45. package/src/annotation/Transform.ts +1 -1
  46. package/src/annotation/editors/Editor.svelte +11 -10
  47. package/src/annotation/editors/EditorMount.svelte +2 -2
  48. package/src/annotation/editors/Handle.ts +21 -0
  49. package/src/annotation/editors/index.ts +2 -2
  50. package/src/annotation/editors/polygon/PolygonEditor.svelte +16 -16
  51. package/src/annotation/editors/rectangle/RectangleEditor.svelte +43 -46
  52. package/src/annotation/shapes/Ellipse.svelte +2 -2
  53. package/src/annotation/shapes/Polygon.svelte +2 -2
  54. package/src/annotation/shapes/Rectangle.svelte +2 -2
  55. package/src/annotation/tools/ToolMount.svelte +3 -3
  56. package/src/annotation/tools/drawingToolsRegistry.ts +1 -2
  57. package/src/annotation/tools/polygon/RubberbandPolygon.svelte +11 -36
  58. package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +10 -16
  59. package/src/annotation/utils/responsive.ts +1 -1
  60. package/src/annotation/utils/touch.ts +1 -4
  61. package/src/index.ts +16 -23
  62. package/src/keyboardCommands.ts +4 -8
  63. package/src/model/w3c/W3CImageFormatAdapter.ts +22 -53
  64. package/src/model/w3c/fragment/FragmentSelector.ts +6 -5
  65. package/src/model/w3c/index.ts +0 -1
  66. package/src/model/w3c/svg/SVG.ts +2 -1
  67. package/src/model/w3c/svg/SVGSelector.ts +13 -11
  68. package/src/state/ImageAnnotatorState.ts +3 -3
  69. package/src/state/spatialTree.ts +2 -3
  70. package/src/themes/dark/index.css +2 -2
  71. package/src/themes/light/index.css +2 -2
  72. package/src/themes/smart/setTheme.ts +2 -2
  73. package/dist/annotation/editors/Handle.svelte.d.ts +0 -1
  74. package/dist/model/w3c/W3CImageAnnotation.d.ts +0 -11
  75. package/dist/model/w3c/W3CImageAnnotation.d.ts.map +0 -1
  76. package/src/annotation/editors/Handle.svelte +0 -66
  77. package/src/model/w3c/W3CImageAnnotation.ts +0 -17
@@ -1,18 +1,19 @@
1
- <script lang="ts">
2
- import Handle from '../Handle.svelte';
3
- import type { Rectangle, Shape } from '../../../model';
1
+ <script type="ts">
2
+ import type { Rectangle } from '../../../model';
4
3
  import type { Transform } from '../../Transform';
5
- import { Editor } from '..';
4
+ import { Editor, Handle } from '..';
6
5
 
7
6
  /** Props */
8
7
  export let shape: Rectangle;
9
- export let computedStyle: string | undefined;
8
+ export let computedStyle: string = undefined;
10
9
  export let transform: Transform;
11
10
  export let viewportScale: number = 1;
12
11
 
13
12
  $: geom = shape.geometry;
14
13
 
15
- const editor = (rectangle: Shape, handle: string, delta: [number, number]) => {
14
+ $: handleSize = 10 / viewportScale;
15
+
16
+ const editor = (rectangle: Rectangle, handle: Handle, delta: [number, number]) => {
16
17
  const initialBounds = rectangle.geometry.bounds;
17
18
 
18
19
  let [x0, y0] = [initialBounds.minX, initialBounds.minY];
@@ -20,39 +21,39 @@
20
21
 
21
22
  const [dx, dy] = delta;
22
23
 
23
- if (handle === 'SHAPE') {
24
+ if (handle === Handle.SHAPE) {
24
25
  x0 += dx;
25
26
  x1 += dx;
26
27
  y0 += dy;
27
28
  y1 += dy;
28
29
  } else {
29
30
  switch (handle) {
30
- case 'TOP':
31
- case 'TOP_LEFT':
32
- case 'TOP_RIGHT': {
31
+ case Handle.TOP:
32
+ case Handle.TOP_LEFT:
33
+ case Handle.TOP_RIGHT: {
33
34
  y0 += dy;
34
35
  break;
35
36
  }
36
37
 
37
- case 'BOTTOM':
38
- case 'BOTTOM_LEFT':
39
- case 'BOTTOM_RIGHT': {
38
+ case Handle.BOTTOM:
39
+ case Handle.BOTTOM_LEFT:
40
+ case Handle.BOTTOM_RIGHT: {
40
41
  y1 += dy;
41
42
  break;
42
43
  }
43
44
  }
44
45
 
45
46
  switch (handle) {
46
- case 'LEFT':
47
- case 'TOP_LEFT':
48
- case 'BOTTOM_LEFT': {
47
+ case Handle.LEFT:
48
+ case Handle.TOP_LEFT:
49
+ case Handle.BOTTOM_LEFT: {
49
50
  x0 += dx;
50
51
  break;
51
52
  }
52
53
 
53
- case 'RIGHT':
54
- case 'TOP_RIGHT':
55
- case 'BOTTOM_RIGHT': {
54
+ case Handle.RIGHT:
55
+ case Handle.TOP_RIGHT:
56
+ case Handle.BOTTOM_RIGHT: {
56
57
  x1 += dx;
57
58
  break;
58
59
  }
@@ -91,56 +92,52 @@
91
92
  <rect
92
93
  class="a9s-outer"
93
94
  style={computedStyle ? 'display:none;' : undefined}
94
- on:pointerdown={grab('SHAPE')}
95
+ on:pointerdown={grab(Handle.SHAPE)}
95
96
  x={geom.x} y={geom.y} width={geom.w} height={geom.h} />
96
97
 
97
98
  <rect
98
99
  class="a9s-inner a9s-shape-handle"
99
100
  style={computedStyle}
100
- on:pointerdown={grab('SHAPE')}
101
+ on:pointerdown={grab(Handle.SHAPE)}
101
102
  x={geom.x} y={geom.y} width={geom.w} height={geom.h} />
102
103
 
103
104
  <rect
104
105
  class="a9s-edge-handle a9s-edge-handle-top"
105
- on:pointerdown={grab('TOP')}
106
+ on:pointerdown={grab(Handle.TOP)}
106
107
  x={geom.x} y={geom.y} height={1} width={geom.w} />
107
108
 
108
109
  <rect
109
110
  class="a9s-edge-handle a9s-edge-handle-right"
110
- on:pointerdown={grab('RIGHT')}
111
+ on:pointerdown={grab(Handle.RIGHT)}
111
112
  x={geom.x + geom.w} y={geom.y} height={geom.h} width={1}/>
112
113
 
113
114
  <rect
114
115
  class="a9s-edge-handle a9s-edge-handle-bottom"
115
- on:pointerdown={grab('BOTTOM')}
116
+ on:pointerdown={grab(Handle.BOTTOM)}
116
117
  x={geom.x} y={geom.y + geom.h} height={1} width={geom.w} />
117
118
 
118
119
  <rect
119
120
  class="a9s-edge-handle a9s-edge-handle-left"
120
- on:pointerdown={grab('LEFT')}
121
+ on:pointerdown={grab(Handle.LEFT)}
121
122
  x={geom.x} y={geom.y} height={geom.h} width={1} />
122
123
 
123
- <Handle
124
- class="a9s-corner-handle-topleft"
125
- on:pointerdown={grab('TOP_LEFT')}
126
- x={geom.x} y={geom.y}
127
- scale={viewportScale} />
128
-
129
- <Handle
130
- class="a9s-corner-handle-topright"
131
- on:pointerdown={grab('TOP_RIGHT')}
132
- x={geom.x + geom.w} y={geom.y}
133
- scale={viewportScale} />
124
+ <rect
125
+ class="a9s-corner-handle a9s-corner-handle-topleft"
126
+ on:pointerdown={grab(Handle.TOP_LEFT)}
127
+ x={geom.x - handleSize / 2} y={geom.y - handleSize / 2} height={handleSize} width={handleSize} />
128
+
129
+ <rect
130
+ class="a9s-corner-handle a9s-corner-handle-topright"
131
+ on:pointerdown={grab(Handle.TOP_RIGHT)}
132
+ x={geom.x + geom.w - handleSize / 2} y={geom.y - handleSize / 2} height={handleSize} width={handleSize} />
134
133
 
135
- <Handle
136
- class="a9s-corner-handle-bottomright"
137
- on:pointerdown={grab('BOTTOM_RIGHT')}
138
- x={geom.x + geom.w} y={geom.y + geom.h}
139
- scale={viewportScale} />
134
+ <rect
135
+ class="a9s-corner-handle a9s-corner-handle-bottomright"
136
+ on:pointerdown={grab(Handle.BOTTOM_RIGHT)}
137
+ x={geom.x + geom.w - handleSize / 2} y={geom.y + geom.h - handleSize / 2} height={handleSize} width={handleSize} />
140
138
 
141
- <Handle
142
- class="a9s-corner-handle-bottomleft"
143
- on:pointerdown={grab('BOTTOM_LEFT')}
144
- x={geom.x} y={geom.y + geom.h}
145
- scale={viewportScale} />
139
+ <rect
140
+ class="a9s-corner-handle a9s-corner-handle-bottomleft"
141
+ on:pointerdown={grab(Handle.BOTTOM_LEFT)}
142
+ x={geom.x - handleSize / 2} y={geom.y + geom.h - handleSize / 2} height={handleSize} width={handleSize} />
146
143
  </Editor>
@@ -1,4 +1,4 @@
1
- <script lang="ts">
1
+ <script type="ts">
2
2
  import type { DrawingStyle } from '@annotorious/core';
3
3
  import type { Geometry, EllipseGeometry, ImageAnnotation } from '../../model';
4
4
  import { computeStyle } from '../utils/styling';
@@ -6,7 +6,7 @@
6
6
  /** Props */
7
7
  export let annotation: ImageAnnotation;
8
8
  export let geom: Geometry;
9
- export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined;
9
+ export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
10
10
 
11
11
  $: computedStyle = computeStyle(annotation, style);
12
12
 
@@ -1,4 +1,4 @@
1
- <script lang="ts">
1
+ <script type="ts">
2
2
  import type { DrawingStyle } from '@annotorious/core';
3
3
  import type { Geometry, ImageAnnotation, PolygonGeometry } from '../../model';
4
4
  import { computeStyle } from '../utils/styling';
@@ -6,7 +6,7 @@
6
6
  /** Props **/
7
7
  export let annotation: ImageAnnotation;
8
8
  export let geom: Geometry;
9
- export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined;
9
+ export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
10
10
 
11
11
  $: computedStyle = computeStyle(annotation, style);
12
12
 
@@ -1,4 +1,4 @@
1
- <script lang="ts">
1
+ <script type="ts">
2
2
  import type { DrawingStyle } from '@annotorious/core';
3
3
  import type { Geometry, ImageAnnotation, RectangleGeometry } from '../../model';
4
4
  import { computeStyle } from '../utils/styling';
@@ -6,7 +6,7 @@
6
6
  /** Props **/
7
7
  export let annotation: ImageAnnotation;
8
8
  export let geom: Geometry;
9
- export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) | undefined;
9
+ export let style: DrawingStyle | ((annotation: ImageAnnotation) => DrawingStyle) = undefined;
10
10
 
11
11
  $: computedStyle = computeStyle(annotation, style);
12
12
 
@@ -23,9 +23,9 @@
23
23
 
24
24
  const cleanup: Function[] = [];
25
25
 
26
- const addEventListener = (name: keyof SVGSVGElementEventMap, handler: EventListenerOrEventListenerObject, capture?: boolean) => {
27
- svg?.addEventListener(name, handler, capture);
28
- cleanup.push(() => svg?.removeEventListener(name, handler, capture));
26
+ const addEventListener = (name: string, handler: (evt: PointerEvent) => void, capture?: boolean) => {
27
+ svg.addEventListener(name, handler, capture);
28
+ cleanup.push(() => svg.removeEventListener(name, handler, capture));
29
29
  }
30
30
 
31
31
  toolComponent = new tool({
@@ -9,11 +9,10 @@ export type DrawingToolOpts = {
9
9
 
10
10
  drawingMode?: DrawingMode;
11
11
 
12
- [key: string]: any;
12
+ [key: string]: string;
13
13
 
14
14
  }
15
15
 
16
- // @ts-ignore
17
16
  const REGISTERED = new Map<DrawingTool, { tool: typeof SvelteComponent, opts?: DrawingToolOpts }>([
18
17
  ['rectangle', { tool: RubberbandRectangle }],
19
18
  ['polygon', { tool: RubberbandPolygon }]
@@ -1,4 +1,4 @@
1
- <script lang="ts">
1
+ <script type="ts">
2
2
  import { onMount, createEventDispatcher } from 'svelte';
3
3
  import type { DrawingMode } from '../../../AnnotoriousOpts';
4
4
  import { boundsFromPoints, computeArea, ShapeType, type Polygon } from '../../../model';
@@ -17,24 +17,15 @@
17
17
 
18
18
  let points: [number, number][] = [];
19
19
 
20
- let cursor: [number, number] | undefined;
21
-
22
- // Keep track of the user keeping the finger
23
- // in place. Long pauses will be interpreted like a
24
- // double click and close the shape.
25
- let touchPauseTimer: number | undefined;
20
+ let cursor: [number, number] = null;
26
21
 
27
22
  let isClosable: boolean = false;
28
23
 
29
24
  const CLOSE_DISTANCE = 20;
30
25
 
31
- const TOUCH_PAUSE_LIMIT = 1500;
32
-
33
26
  $: handleSize = 10 / viewportScale;
34
27
 
35
- const onPointerDown = (event: Event) => {
36
- const evt = event as PointerEvent;
37
-
28
+ const onPointerDown = (evt: PointerEvent) => {
38
29
  // Note that the event itself is ephemeral!
39
30
  const { timeStamp, offsetX, offsetY } = evt;
40
31
  lastPointerDown = { timeStamp, offsetX, offsetY };
@@ -49,11 +40,7 @@
49
40
  }
50
41
  }
51
42
 
52
- const onPointerMove = (event: Event) => {
53
- const evt = event as PointerEvent;
54
-
55
- if (touchPauseTimer) clearTimeout(touchPauseTimer);
56
-
43
+ const onPointerMove = (evt: PointerEvent) => {
57
44
  if (points.length > 0) {
58
45
  cursor = transform.elementToImage(evt.offsetX, evt.offsetY);
59
46
 
@@ -61,20 +48,10 @@
61
48
  const d = distance(cursor, points[0]) * viewportScale;
62
49
  isClosable = d < CLOSE_DISTANCE;
63
50
  }
64
-
65
- if (evt.pointerType === 'touch') {
66
- touchPauseTimer = setTimeout(() => {
67
- onDblClick();
68
- }, TOUCH_PAUSE_LIMIT);
69
- }
70
51
  }
71
52
  }
72
53
 
73
- const onPointerUp = (event: Event) => {
74
- const evt = event as PointerEvent;
75
-
76
- if (touchPauseTimer) clearTimeout(touchPauseTimer);
77
-
54
+ const onPointerUp = (evt: PointerEvent) => {
78
55
  if (drawingMode === 'click') {
79
56
  const timeDifference = evt.timeStamp - lastPointerDown.timeStamp;
80
57
 
@@ -94,17 +71,17 @@
94
71
 
95
72
  cursor = point;
96
73
  } else {
97
- points.push(cursor!);
74
+ points.push(cursor);
98
75
  }
99
76
  } else {
100
77
  // Require minimum drag of 4px
101
78
  if (points.length === 1) {
102
- const dist = distance(points[0], cursor!);
79
+ const dist = distance(points[0], cursor);
103
80
 
104
81
  if (dist <= 4) {
105
82
  // Cancel
106
83
  points = [];
107
- cursor = undefined;
84
+ cursor = null;
108
85
 
109
86
  return;
110
87
  }
@@ -116,14 +93,12 @@
116
93
  if (isClosable) {
117
94
  stopDrawing();
118
95
  } else {
119
- points.push(cursor!);
96
+ points.push(cursor);
120
97
  }
121
98
  }
122
99
  }
123
100
 
124
101
  const onDblClick = () => {
125
- if (!cursor) return;
126
-
127
102
  // Require min 3 points (incl. cursor) and minimum
128
103
  // polygon area
129
104
  const p = [...points, cursor];
@@ -139,7 +114,7 @@
139
114
  const area = computeArea(shape);
140
115
  if (area > 4) {
141
116
  points = [];
142
- cursor = undefined;
117
+ cursor = null;
143
118
 
144
119
  dispatch('create', shape);
145
120
  }
@@ -155,7 +130,7 @@
155
130
  }
156
131
 
157
132
  points = [];
158
- cursor = undefined;
133
+ cursor = null;
159
134
 
160
135
  dispatch('create', shape);
161
136
  }
@@ -1,4 +1,4 @@
1
- <script lang="ts">
1
+ <script type="ts">
2
2
  import { createEventDispatcher, onMount } from 'svelte';
3
3
  import type { DrawingMode } from '../../../AnnotoriousOpts';
4
4
  import { ShapeType, type Rectangle } from '../../../model';
@@ -13,15 +13,13 @@
13
13
 
14
14
  let lastPointerDown: number;
15
15
 
16
- let origin: [x: number, y: number] | undefined;
16
+ let origin: [x: number, y: number];
17
17
 
18
- let anchor: [number, number] | undefined;
18
+ let anchor: [number, number];
19
19
 
20
20
  let x: number, y: number, w: number, h: number;
21
21
 
22
- const onPointerDown = (event: Event) => {
23
- const evt = event as PointerEvent;
24
-
22
+ const onPointerDown = (evt: PointerEvent) => {
25
23
  lastPointerDown = performance.now();
26
24
 
27
25
  if (drawingMode === 'drag') {
@@ -35,9 +33,7 @@
35
33
  }
36
34
  }
37
35
 
38
- const onPointerMove = (event: Event) => {
39
- const evt = event as PointerEvent;
40
-
36
+ const onPointerMove = (evt: PointerEvent) => {
41
37
  if (origin) {
42
38
  anchor = transform.elementToImage(evt.offsetX, evt.offsetY);
43
39
 
@@ -48,9 +44,7 @@
48
44
  }
49
45
  }
50
46
 
51
- const onPointerUp = (event: Event) => {
52
- const evt = event as PointerEvent;
53
-
47
+ const onPointerUp = (evt: PointerEvent) => {
54
48
  const timeDifference = performance.now() - lastPointerDown;
55
49
 
56
50
  if (drawingMode === 'click') {
@@ -77,8 +71,8 @@
77
71
  evt.stopPropagation();
78
72
  stopDrawing();
79
73
  } else {
80
- origin = undefined;
81
- anchor = undefined;
74
+ origin = null;
75
+ anchor = null;
82
76
  }
83
77
  }
84
78
  }
@@ -102,8 +96,8 @@
102
96
  dispatch('create', shape);
103
97
  }
104
98
 
105
- origin = undefined;
106
- anchor = undefined;
99
+ origin = null;
100
+ anchor = null;
107
101
  }
108
102
 
109
103
  onMount(() => {
@@ -42,7 +42,7 @@ export const enableResponsive = (image: HTMLImageElement | HTMLCanvasElement, sv
42
42
  set(scale);
43
43
  });
44
44
 
45
- resizeObserver.observe(svg.parentElement!);
45
+ resizeObserver.observe(svg.parentElement);
46
46
  }
47
47
 
48
48
  const destroy = () => {
@@ -1,4 +1 @@
1
- export const isTouch = 'ontouchstart' in window
2
- || navigator.maxTouchPoints > 0
3
- // @ts-ignore
4
- || navigator.msMaxTouchPoints > 0;
1
+ export const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
package/src/index.ts CHANGED
@@ -7,31 +7,24 @@ export * from './Annotorious';
7
7
  export * from './AnnotoriousOpts';
8
8
  export * from './keyboardCommands';
9
9
 
10
- // Essential re-exports from @annotorious/core
11
- export type {
12
- Annotation,
13
- AnnotationBody,
14
- AnnotationTarget,
15
- Annotator,
16
- AnnotatorState,
17
- Appearance,
18
- AppearanceProvider,
19
- Color,
20
- DrawingStyle,
21
- Filter,
22
- FormatAdapter,
10
+ // Re-export essentials from @annotorious/core utilities for convenience
11
+ export * from '@annotorious/core/src/model';
12
+ export * from '@annotorious/core/src/presence';
13
+ export * from '@annotorious/core/src/utils';
14
+
15
+ export type {
23
16
  HoverState,
24
- LifecycleEvents,
25
- ParseResult,
26
- PresentUser,
27
- Purpose,
28
17
  Selection,
29
18
  SelectionState,
30
19
  Store,
31
20
  StoreChangeEvent,
32
- StoreObserver,
33
- User,
34
- W3CAnnotation,
35
- W3CAnnotationBody,
36
- W3CAnnotationTarget
37
- } from '@annotorious/core';
21
+ StoreObserver
22
+ } from '@annotorious/core/src/state';
23
+
24
+ import {
25
+ Origin as _Origin,
26
+ PointerSelectAction as _PointerSelectAction
27
+ } from '@annotorious/core/src/state';
28
+
29
+ export { _Origin as Origin };
30
+ export { _PointerSelectAction as PointerSelectAction };
@@ -9,19 +9,15 @@ export const initKeyboardCommands = <T extends Annotation>(
9
9
 
10
10
  const el = container || document;
11
11
 
12
- const onWinKeyDown = (evt: Event) => {
13
- const event = evt as KeyboardEvent;
14
-
15
- if (event.key === 'z' && event.ctrlKey) {
12
+ const onWinKeyDown = (event: KeyboardEvent) => {
13
+ if (event.key === 'Z' && event.ctrlKey) {
16
14
  undoStack.undo();
17
- } else if (event.key === 'y' && event.ctrlKey) {
15
+ } else if (event.key === 'Y' && event.ctrlKey) {
18
16
  undoStack.redo()
19
17
  }
20
18
  };
21
19
 
22
- const onMacKeyDown = (evt: Event) => {
23
- const event = evt as KeyboardEvent;
24
-
20
+ const onMacKeyDown = (event: KeyboardEvent) => {
25
21
  if (event.key === 'z' && event.metaKey) {
26
22
  if (event.shiftKey) {
27
23
  undoStack.redo()
@@ -1,15 +1,14 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
- import { parseW3CUser, parseW3CBodies, serializeW3CBodies } from '@annotorious/core';
2
+ import { parseW3CBodies, serializeW3CBodies } from '@annotorious/core';
3
3
  import type { FormatAdapter, ParseResult, W3CAnnotation } from '@annotorious/core';
4
4
  import { ShapeType } from '../core';
5
5
  import type { ImageAnnotation, RectangleGeometry } from '../core';
6
- import type {FragmentSelector } from './fragment';
6
+ import type { FragmentSelector } from './fragment';
7
7
  import { parseFragmentSelector, serializeFragmentSelector } from './fragment';
8
8
  import type { SVGSelector } from './svg';
9
9
  import { parseSVGSelector, serializeSVGSelector } from './svg';
10
- import type { W3CImageAnnotation } from './W3CImageAnnotation';
11
10
 
12
- export type W3CImageFormatAdapter = FormatAdapter<ImageAnnotation, W3CImageAnnotation>;
11
+ export type W3CImageFormatAdapter = FormatAdapter<ImageAnnotation, W3CAnnotation>;
13
12
 
14
13
  export const W3CImageFormat = (
15
14
  source: string,
@@ -31,26 +30,18 @@ export const parseW3CImageAnnotation = (
31
30
  ): ParseResult<ImageAnnotation> => {
32
31
  const annotationId = annotation.id || uuidv4();
33
32
 
34
- const {
35
- creator,
36
- created,
37
- modified,
38
- body,
39
- ...rest
40
- } = annotation;
33
+ const { body, ...rest } = annotation;
41
34
 
42
35
  const bodies = parseW3CBodies(body, annotationId);
43
36
 
44
- const w3cTarget = Array.isArray(annotation.target)
45
- ? annotation.target[0] : annotation.target;
37
+ const target = Array.isArray(annotation.target) ? annotation.target[0] : annotation.target;
46
38
 
47
- const w3cSelector = Array.isArray(w3cTarget.selector)
48
- ? w3cTarget.selector[0] : w3cTarget.selector;
39
+ const w3cSelector = Array.isArray(target.selector) ? target.selector[0] : target.selector;
49
40
 
50
41
  const selector =
51
- w3cSelector?.type === 'FragmentSelector' ?
42
+ w3cSelector.type === 'FragmentSelector' ?
52
43
  parseFragmentSelector(w3cSelector as FragmentSelector, invertY) :
53
- w3cSelector?.type === 'SvgSelector' ?
44
+ w3cSelector.type === 'SvgSelector' ?
54
45
  parseSVGSelector(w3cSelector as SVGSelector) : undefined;
55
46
 
56
47
  return selector ? {
@@ -59,16 +50,13 @@ export const parseW3CImageAnnotation = (
59
50
  id: annotationId,
60
51
  bodies,
61
52
  target: {
62
- created: created ? new Date(created) : undefined,
63
- creator: parseW3CUser(creator),
64
- updated: modified ? new Date(modified) : undefined,
65
- ...(Array.isArray(rest.target) ? rest.target[0] : rest.target),
53
+ ...rest.target,
66
54
  annotation: annotationId,
67
55
  selector
68
56
  }
69
57
  }
70
58
  } : {
71
- error: Error(`Invalid selector: ${JSON.stringify(w3cSelector)}`)
59
+ error: Error(`Unknown selector type: ${w3cSelector.type}`)
72
60
  };
73
61
 
74
62
  }
@@ -76,42 +64,23 @@ export const parseW3CImageAnnotation = (
76
64
  export const serializeW3CImageAnnotation = (
77
65
  annotation: ImageAnnotation,
78
66
  source: string
79
- ): W3CImageAnnotation => {
80
- const {
81
- selector,
82
- creator,
83
- created,
84
- updated,
85
- updatedBy, // Excluded from serialization
86
- ...rest
87
- } = annotation.target;
88
-
89
- const w3CSelector =
90
- selector.type == ShapeType.RECTANGLE ?
91
- serializeFragmentSelector(selector.geometry as RectangleGeometry) :
92
- serializeSVGSelector(selector);
93
-
94
- const serialized = {
67
+ ): W3CAnnotation => {
68
+ const shape = annotation.target.selector;
69
+
70
+ const selector =
71
+ shape.type == ShapeType.RECTANGLE ?
72
+ serializeFragmentSelector(shape.geometry as RectangleGeometry) :
73
+ serializeSVGSelector(shape);
74
+
75
+ return {
95
76
  ...annotation,
96
77
  '@context': 'http://www.w3.org/ns/anno.jsonld',
97
78
  id: annotation.id,
98
79
  type: 'Annotation',
99
80
  body: serializeW3CBodies(annotation.bodies),
100
- created: created?.toISOString(),
101
- creator,
102
- modified: updated?.toISOString(),
103
81
  target: {
104
- ...rest,
105
82
  source,
106
- selector: w3CSelector
83
+ selector
107
84
  }
108
- } as W3CImageAnnotation;
109
-
110
- // Remove core properties that should not appear in the W3C annotation
111
- delete serialized.bodies;
112
-
113
- if ('annotation' in serialized.target)
114
- delete serialized.target.annotation;
115
-
116
- return serialized;
117
- }
85
+ };
86
+ };
@@ -1,14 +1,15 @@
1
- import type { Rectangle, RectangleGeometry } from '../../core';
1
+ import type { W3CSelector } from '@annotorious/core';
2
2
  import { ShapeType } from '../../core';
3
+ import type { Rectangle, RectangleGeometry } from '../../core';
3
4
 
4
- export interface FragmentSelector {
5
+ export interface FragmentSelector extends W3CSelector {
5
6
 
6
7
  type: 'FragmentSelector';
7
8
 
8
9
  conformsTo: 'http://www.w3.org/TR/media-frags/',
9
10
 
10
11
  value: string;
11
-
12
+
12
13
  }
13
14
 
14
15
  export const parseFragmentSelector = (
@@ -45,7 +46,7 @@ export const parseFragmentSelector = (
45
46
  }
46
47
  }
47
48
  }
48
- }
49
+ };
49
50
 
50
51
  export const serializeFragmentSelector = (geometry: RectangleGeometry): FragmentSelector => {
51
52
  const { x, y, w, h } = geometry;
@@ -55,4 +56,4 @@ export const serializeFragmentSelector = (geometry: RectangleGeometry): Fragment
55
56
  conformsTo: 'http://www.w3.org/TR/media-frags/',
56
57
  value: `xywh=pixel:${x},${y},${w},${h}`
57
58
  };
58
- }
59
+ };
@@ -1,4 +1,3 @@
1
1
  export * from './fragment';
2
2
  export * from './svg';
3
- export * from './W3CImageAnnotation';
4
3
  export * from './W3CImageFormatAdapter';