@annotorious/annotorious 3.0.0-rc.20 → 3.0.0-rc.3
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 -7
- package/dist/Annotorious.d.ts.map +1 -1
- package/dist/AnnotoriousOpts.d.ts +3 -4
- 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 +2087 -2359
- 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 +2 -2
- 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/dist/themes/smart/setTheme.d.ts +1 -3
- package/dist/themes/smart/setTheme.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/Annotorious.css +5 -5
- package/src/Annotorious.ts +28 -34
- package/src/AnnotoriousOpts.ts +6 -11
- 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 +13 -40
- 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 +7 -11
- package/src/model/w3c/W3CImageFormatAdapter.ts +21 -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 +6 -10
- 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,27 +1,27 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script type="ts">
|
|
2
2
|
import { boundsFromPoints } from '../../../model';
|
|
3
|
-
import type { Polygon
|
|
3
|
+
import type { Polygon } from '../../../model';
|
|
4
4
|
import type { Transform } from '../../Transform';
|
|
5
5
|
import { Editor, Handle } from '..';
|
|
6
6
|
|
|
7
7
|
/** Props */
|
|
8
8
|
export let shape: Polygon;
|
|
9
|
-
export let computedStyle: string
|
|
9
|
+
export let computedStyle: string = undefined;
|
|
10
10
|
export let transform: Transform;
|
|
11
11
|
export let viewportScale: number = 1;
|
|
12
12
|
|
|
13
13
|
$: geom = shape.geometry;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
let points: [number, number][];
|
|
15
|
+
$: handleSize = 10 / viewportScale;
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
const editor = (polygon: Polygon, handle: Handle, delta: [number, number]) => {
|
|
18
|
+
let points: [number, number][];
|
|
19
19
|
|
|
20
|
-
if (handle ===
|
|
21
|
-
points =
|
|
20
|
+
if (handle === Handle.SHAPE) {
|
|
21
|
+
points = polygon.geometry.points.map(([x, y]) => [x + delta[0], y + delta[1]]);
|
|
22
22
|
} else {
|
|
23
|
-
points =
|
|
24
|
-
handle ===
|
|
23
|
+
points = polygon.geometry.points.map(([x, y], idx) =>
|
|
24
|
+
handle === Handle(idx) ? [x + delta[0], y + delta[1]] : [x, y]
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -46,19 +46,19 @@
|
|
|
46
46
|
<polygon
|
|
47
47
|
class="a9s-outer"
|
|
48
48
|
style={computedStyle ? 'display:none;' : undefined}
|
|
49
|
-
on:pointerdown={grab(
|
|
49
|
+
on:pointerdown={grab(Handle.SHAPE)}
|
|
50
50
|
points={geom.points.map(xy => xy.join(',')).join(' ')} />
|
|
51
51
|
|
|
52
52
|
<polygon
|
|
53
53
|
class="a9s-inner a9s-shape-handle"
|
|
54
54
|
style={computedStyle}
|
|
55
|
-
on:pointerdown={grab(
|
|
55
|
+
on:pointerdown={grab(Handle.SHAPE)}
|
|
56
56
|
points={geom.points.map(xy => xy.join(',')).join(' ')} />
|
|
57
57
|
|
|
58
58
|
{#each geom.points as point, idx}
|
|
59
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
<rect
|
|
60
|
+
class="a9s-corner-handle"
|
|
61
|
+
on:pointerdown={grab(Handle(idx))}
|
|
62
|
+
x={point[0] - handleSize / 2} y={point[1] - handleSize / 2} height={handleSize} width={handleSize} />
|
|
63
63
|
{/each}
|
|
64
64
|
</Editor>
|
|
@@ -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';
|
|
@@ -13,31 +13,20 @@
|
|
|
13
13
|
export let transform: Transform;
|
|
14
14
|
export let viewportScale = 1;
|
|
15
15
|
|
|
16
|
-
let lastPointerDown:
|
|
16
|
+
let lastPointerDown: PointerEvent;
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
// Note that the event itself is ephemeral!
|
|
39
|
-
const { timeStamp, offsetX, offsetY } = evt;
|
|
40
|
-
lastPointerDown = { timeStamp, offsetX, offsetY };
|
|
28
|
+
const onPointerDown = (evt: PointerEvent) => {
|
|
29
|
+
lastPointerDown = {...evt};
|
|
41
30
|
|
|
42
31
|
if (drawingMode === 'drag') {
|
|
43
32
|
if (points.length === 0) {
|
|
@@ -49,11 +38,7 @@
|
|
|
49
38
|
}
|
|
50
39
|
}
|
|
51
40
|
|
|
52
|
-
const onPointerMove = (
|
|
53
|
-
const evt = event as PointerEvent;
|
|
54
|
-
|
|
55
|
-
if (touchPauseTimer) clearTimeout(touchPauseTimer);
|
|
56
|
-
|
|
41
|
+
const onPointerMove = (evt: PointerEvent) => {
|
|
57
42
|
if (points.length > 0) {
|
|
58
43
|
cursor = transform.elementToImage(evt.offsetX, evt.offsetY);
|
|
59
44
|
|
|
@@ -61,20 +46,10 @@
|
|
|
61
46
|
const d = distance(cursor, points[0]) * viewportScale;
|
|
62
47
|
isClosable = d < CLOSE_DISTANCE;
|
|
63
48
|
}
|
|
64
|
-
|
|
65
|
-
if (evt.pointerType === 'touch') {
|
|
66
|
-
touchPauseTimer = setTimeout(() => {
|
|
67
|
-
onDblClick();
|
|
68
|
-
}, TOUCH_PAUSE_LIMIT);
|
|
69
|
-
}
|
|
70
49
|
}
|
|
71
50
|
}
|
|
72
51
|
|
|
73
|
-
const onPointerUp = (
|
|
74
|
-
const evt = event as PointerEvent;
|
|
75
|
-
|
|
76
|
-
if (touchPauseTimer) clearTimeout(touchPauseTimer);
|
|
77
|
-
|
|
52
|
+
const onPointerUp = (evt: PointerEvent) => {
|
|
78
53
|
if (drawingMode === 'click') {
|
|
79
54
|
const timeDifference = evt.timeStamp - lastPointerDown.timeStamp;
|
|
80
55
|
|
|
@@ -94,17 +69,17 @@
|
|
|
94
69
|
|
|
95
70
|
cursor = point;
|
|
96
71
|
} else {
|
|
97
|
-
points.push(cursor
|
|
72
|
+
points.push(cursor);
|
|
98
73
|
}
|
|
99
74
|
} else {
|
|
100
75
|
// Require minimum drag of 4px
|
|
101
76
|
if (points.length === 1) {
|
|
102
|
-
const dist = distance(points[0], cursor
|
|
77
|
+
const dist = distance(points[0], cursor);
|
|
103
78
|
|
|
104
79
|
if (dist <= 4) {
|
|
105
80
|
// Cancel
|
|
106
81
|
points = [];
|
|
107
|
-
cursor =
|
|
82
|
+
cursor = null;
|
|
108
83
|
|
|
109
84
|
return;
|
|
110
85
|
}
|
|
@@ -116,14 +91,12 @@
|
|
|
116
91
|
if (isClosable) {
|
|
117
92
|
stopDrawing();
|
|
118
93
|
} else {
|
|
119
|
-
points.push(cursor
|
|
94
|
+
points.push(cursor);
|
|
120
95
|
}
|
|
121
96
|
}
|
|
122
97
|
}
|
|
123
98
|
|
|
124
99
|
const onDblClick = () => {
|
|
125
|
-
if (!cursor) return;
|
|
126
|
-
|
|
127
100
|
// Require min 3 points (incl. cursor) and minimum
|
|
128
101
|
// polygon area
|
|
129
102
|
const p = [...points, cursor];
|
|
@@ -139,7 +112,7 @@
|
|
|
139
112
|
const area = computeArea(shape);
|
|
140
113
|
if (area > 4) {
|
|
141
114
|
points = [];
|
|
142
|
-
cursor =
|
|
115
|
+
cursor = null;
|
|
143
116
|
|
|
144
117
|
dispatch('create', shape);
|
|
145
118
|
}
|
|
@@ -155,7 +128,7 @@
|
|
|
155
128
|
}
|
|
156
129
|
|
|
157
130
|
points = [];
|
|
158
|
-
cursor =
|
|
131
|
+
cursor = null;
|
|
159
132
|
|
|
160
133
|
dispatch('create', shape);
|
|
161
134
|
}
|
|
@@ -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
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { 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 = (
|
|
6
|
+
undoStack: UndoStack,
|
|
7
7
|
container?: Element
|
|
8
8
|
) => {
|
|
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()
|