@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.
- package/dist/Annotorious.d.ts +2 -5
- package/dist/Annotorious.d.ts.map +1 -1
- package/dist/AnnotoriousOpts.d.ts +3 -2
- package/dist/AnnotoriousOpts.d.ts.map +1 -1
- package/dist/annotation/SVGAnnotationLayerPointerEvent.d.ts.map +1 -1
- package/dist/annotation/editors/Handle.d.ts +14 -0
- package/dist/annotation/editors/Handle.d.ts.map +1 -0
- package/dist/annotation/editors/editorsRegistry.d.ts +1 -1
- package/dist/annotation/editors/editorsRegistry.d.ts.map +1 -1
- package/dist/annotation/editors/index.d.ts +1 -1
- package/dist/annotation/editors/index.d.ts.map +1 -1
- package/dist/annotation/tools/drawingToolsRegistry.d.ts +4 -4
- package/dist/annotation/tools/drawingToolsRegistry.d.ts.map +1 -1
- package/dist/annotation/utils/responsive.d.ts +1 -2
- package/dist/annotation/utils/responsive.d.ts.map +1 -1
- package/dist/annotation/utils/styling.d.ts +1 -1
- package/dist/annotation/utils/styling.d.ts.map +1 -1
- package/dist/annotation/utils/touch.d.ts.map +1 -1
- package/dist/annotorious.css +1 -1
- package/dist/annotorious.es.js +2046 -2300
- package/dist/annotorious.es.js.map +1 -1
- package/dist/annotorious.js +1 -1
- package/dist/annotorious.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/keyboardCommands.d.ts.map +1 -1
- package/dist/model/w3c/W3CImageFormatAdapter.d.ts +2 -3
- package/dist/model/w3c/W3CImageFormatAdapter.d.ts.map +1 -1
- package/dist/model/w3c/fragment/FragmentSelector.d.ts +2 -1
- package/dist/model/w3c/fragment/FragmentSelector.d.ts.map +1 -1
- package/dist/model/w3c/index.d.ts +0 -1
- package/dist/model/w3c/index.d.ts.map +1 -1
- package/dist/model/w3c/svg/SVG.d.ts.map +1 -1
- package/dist/model/w3c/svg/SVGSelector.d.ts +2 -1
- package/dist/model/w3c/svg/SVGSelector.d.ts.map +1 -1
- package/dist/state/ImageAnnotatorState.d.ts.map +1 -1
- package/dist/state/spatialTree.d.ts +1 -1
- package/dist/state/spatialTree.d.ts.map +1 -1
- package/package.json +16 -13
- package/src/Annotorious.css +5 -5
- package/src/Annotorious.ts +12 -21
- package/src/AnnotoriousOpts.ts +7 -7
- package/src/annotation/SVGAnnotationLayer.svelte +15 -21
- package/src/annotation/SVGAnnotationLayerPointerEvent.ts +2 -1
- package/src/annotation/Transform.ts +1 -1
- package/src/annotation/editors/Editor.svelte +11 -10
- package/src/annotation/editors/EditorMount.svelte +2 -2
- package/src/annotation/editors/Handle.ts +21 -0
- package/src/annotation/editors/index.ts +2 -2
- package/src/annotation/editors/polygon/PolygonEditor.svelte +16 -16
- package/src/annotation/editors/rectangle/RectangleEditor.svelte +43 -46
- package/src/annotation/shapes/Ellipse.svelte +2 -2
- package/src/annotation/shapes/Polygon.svelte +2 -2
- package/src/annotation/shapes/Rectangle.svelte +2 -2
- package/src/annotation/tools/ToolMount.svelte +3 -3
- package/src/annotation/tools/drawingToolsRegistry.ts +1 -2
- package/src/annotation/tools/polygon/RubberbandPolygon.svelte +11 -36
- package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +10 -16
- package/src/annotation/utils/responsive.ts +1 -1
- package/src/annotation/utils/touch.ts +1 -4
- package/src/index.ts +16 -23
- package/src/keyboardCommands.ts +4 -8
- package/src/model/w3c/W3CImageFormatAdapter.ts +22 -53
- package/src/model/w3c/fragment/FragmentSelector.ts +6 -5
- package/src/model/w3c/index.ts +0 -1
- package/src/model/w3c/svg/SVG.ts +2 -1
- package/src/model/w3c/svg/SVGSelector.ts +13 -11
- package/src/state/ImageAnnotatorState.ts +3 -3
- package/src/state/spatialTree.ts +2 -3
- package/src/themes/dark/index.css +2 -2
- package/src/themes/light/index.css +2 -2
- package/src/themes/smart/setTheme.ts +2 -2
- package/dist/annotation/editors/Handle.svelte.d.ts +0 -1
- package/dist/model/w3c/W3CImageAnnotation.d.ts +0 -11
- package/dist/model/w3c/W3CImageAnnotation.d.ts.map +0 -1
- package/src/annotation/editors/Handle.svelte +0 -66
- package/src/model/w3c/W3CImageAnnotation.ts +0 -17
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
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
|
|
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
|
-
|
|
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 ===
|
|
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
|
|
31
|
-
case
|
|
32
|
-
case
|
|
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
|
|
38
|
-
case
|
|
39
|
-
case
|
|
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
|
|
47
|
-
case
|
|
48
|
-
case
|
|
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
|
|
54
|
-
case
|
|
55
|
-
case
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
121
|
+
on:pointerdown={grab(Handle.LEFT)}
|
|
121
122
|
x={geom.x} y={geom.y} height={geom.h} width={1} />
|
|
122
123
|
|
|
123
|
-
<
|
|
124
|
-
class="a9s-corner-handle-topleft"
|
|
125
|
-
on:pointerdown={grab(
|
|
126
|
-
x={geom.x} y={geom.y}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
<
|
|
136
|
-
class="a9s-corner-handle-bottomright"
|
|
137
|
-
on:pointerdown={grab(
|
|
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
|
-
<
|
|
142
|
-
class="a9s-corner-handle-bottomleft"
|
|
143
|
-
on:pointerdown={grab(
|
|
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
|
|
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)
|
|
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
|
|
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)
|
|
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
|
|
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)
|
|
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:
|
|
27
|
-
svg
|
|
28
|
-
cleanup.push(() => svg
|
|
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]:
|
|
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
|
|
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]
|
|
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 = (
|
|
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 = (
|
|
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 = (
|
|
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 =
|
|
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 =
|
|
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 =
|
|
133
|
+
cursor = null;
|
|
159
134
|
|
|
160
135
|
dispatch('create', shape);
|
|
161
136
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script
|
|
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]
|
|
16
|
+
let origin: [x: number, y: number];
|
|
17
17
|
|
|
18
|
-
let anchor: [number, number]
|
|
18
|
+
let anchor: [number, number];
|
|
19
19
|
|
|
20
20
|
let x: number, y: number, w: number, h: number;
|
|
21
21
|
|
|
22
|
-
const onPointerDown = (
|
|
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 = (
|
|
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 = (
|
|
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 =
|
|
81
|
-
anchor =
|
|
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 =
|
|
106
|
-
anchor =
|
|
99
|
+
origin = null;
|
|
100
|
+
anchor = null;
|
|
107
101
|
}
|
|
108
102
|
|
|
109
103
|
onMount(() => {
|
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
|
-
//
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 };
|
package/src/keyboardCommands.ts
CHANGED
|
@@ -9,19 +9,15 @@ export const initKeyboardCommands = <T extends Annotation>(
|
|
|
9
9
|
|
|
10
10
|
const el = container || document;
|
|
11
11
|
|
|
12
|
-
const onWinKeyDown = (
|
|
13
|
-
|
|
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 === '
|
|
15
|
+
} else if (event.key === 'Y' && event.ctrlKey) {
|
|
18
16
|
undoStack.redo()
|
|
19
17
|
}
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
const onMacKeyDown = (
|
|
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 {
|
|
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,
|
|
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
|
|
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(
|
|
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
|
|
42
|
+
w3cSelector.type === 'FragmentSelector' ?
|
|
52
43
|
parseFragmentSelector(w3cSelector as FragmentSelector, invertY) :
|
|
53
|
-
w3cSelector
|
|
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
|
-
|
|
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(`
|
|
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
|
-
):
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
|
83
|
+
selector
|
|
107
84
|
}
|
|
108
|
-
}
|
|
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 {
|
|
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
|
+
};
|
package/src/model/w3c/index.ts
CHANGED