@annotorious/annotorious 3.0.0-rc.19 → 3.0.0-rc.2
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 -4
- 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/Transform.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 +1999 -2373
- 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 +4 -2
- package/dist/index.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/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 -14
- package/src/Annotorious.css +5 -5
- package/src/Annotorious.ts +29 -44
- 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 +3 -5
- package/src/annotation/editors/Editor.svelte +11 -10
- package/src/annotation/editors/EditorMount.svelte +3 -3
- 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 +3 -3
- package/src/annotation/tools/ToolMount.svelte +3 -3
- package/src/annotation/tools/drawingToolsRegistry.ts +1 -2
- package/src/annotation/tools/polygon/RubberbandPolygon.svelte +32 -58
- package/src/annotation/tools/rectangle/RubberbandRectangle.svelte +16 -17
- package/src/annotation/utils/responsive.ts +1 -1
- package/src/annotation/utils/touch.ts +1 -4
- package/src/index.ts +8 -25
- package/src/model/w3c/W3CImageFormatAdapter.ts +20 -54
- 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/keyboardCommands.d.ts +0 -5
- package/dist/keyboardCommands.d.ts.map +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/keyboardCommands.ts +0 -50
- 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,11 +6,11 @@
|
|
|
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
|
|
|
13
|
-
|
|
13
|
+
const { x, y, w, h } = geom as RectangleGeometry;
|
|
14
14
|
</script>
|
|
15
15
|
|
|
16
16
|
<g data-id={annotation.id}>
|
|
@@ -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,7 +1,7 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script type="ts">
|
|
2
2
|
import { onMount, createEventDispatcher } from 'svelte';
|
|
3
3
|
import type { DrawingMode } from '../../../AnnotoriousOpts';
|
|
4
|
-
import { boundsFromPoints,
|
|
4
|
+
import { boundsFromPoints, ShapeType, type Polygon } from '../../../model';
|
|
5
5
|
import { distance } from '../../utils';
|
|
6
6
|
import type { Transform } from '../..';
|
|
7
7
|
|
|
@@ -13,31 +13,22 @@
|
|
|
13
13
|
export let transform: Transform;
|
|
14
14
|
export let viewportScale = 1;
|
|
15
15
|
|
|
16
|
-
let
|
|
16
|
+
let container: SVGGElement;
|
|
17
|
+
|
|
18
|
+
let lastPointerDown: number;
|
|
17
19
|
|
|
18
20
|
let points: [number, number][] = [];
|
|
19
21
|
|
|
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;
|
|
22
|
+
let cursor: [number, number] = null;
|
|
26
23
|
|
|
27
24
|
let isClosable: boolean = false;
|
|
28
25
|
|
|
29
26
|
const CLOSE_DISTANCE = 20;
|
|
30
27
|
|
|
31
|
-
const TOUCH_PAUSE_LIMIT = 1500;
|
|
32
|
-
|
|
33
28
|
$: handleSize = 10 / viewportScale;
|
|
34
29
|
|
|
35
|
-
const onPointerDown = (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// Note that the event itself is ephemeral!
|
|
39
|
-
const { timeStamp, offsetX, offsetY } = evt;
|
|
40
|
-
lastPointerDown = { timeStamp, offsetX, offsetY };
|
|
30
|
+
const onPointerDown = (evt: PointerEvent) => {
|
|
31
|
+
lastPointerDown = performance.now();
|
|
41
32
|
|
|
42
33
|
if (drawingMode === 'drag') {
|
|
43
34
|
if (points.length === 0) {
|
|
@@ -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,30 +48,19 @@
|
|
|
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
|
|
75
|
-
|
|
76
|
-
if (touchPauseTimer) clearTimeout(touchPauseTimer);
|
|
54
|
+
const onPointerUp = (evt: PointerEvent) => {
|
|
55
|
+
const timeDifference = performance.now() - lastPointerDown;
|
|
77
56
|
|
|
78
57
|
if (drawingMode === 'click') {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const d = distance(
|
|
82
|
-
[lastPointerDown.offsetX, lastPointerDown.offsetY],
|
|
83
|
-
[evt.offsetX, evt.offsetY]);
|
|
84
|
-
|
|
85
|
-
if (timeDifference > 300 || d > 15) // Not a single click - ignore
|
|
58
|
+
// Not a single click - ignore
|
|
59
|
+
if (timeDifference > 300)
|
|
86
60
|
return;
|
|
87
61
|
|
|
62
|
+
evt.stopPropagation();
|
|
63
|
+
|
|
88
64
|
if (isClosable) {
|
|
89
65
|
stopDrawing();
|
|
90
66
|
} else if (points.length === 0) {
|
|
@@ -94,17 +70,17 @@
|
|
|
94
70
|
|
|
95
71
|
cursor = point;
|
|
96
72
|
} else {
|
|
97
|
-
points.push(cursor
|
|
73
|
+
points.push(cursor);
|
|
98
74
|
}
|
|
99
75
|
} else {
|
|
100
76
|
// Require minimum drag of 4px
|
|
101
77
|
if (points.length === 1) {
|
|
102
|
-
const dist = distance(points[0], cursor
|
|
78
|
+
const dist = distance(points[0], cursor);
|
|
103
79
|
|
|
104
80
|
if (dist <= 4) {
|
|
105
81
|
// Cancel
|
|
106
82
|
points = [];
|
|
107
|
-
cursor =
|
|
83
|
+
cursor = null;
|
|
108
84
|
|
|
109
85
|
return;
|
|
110
86
|
}
|
|
@@ -116,33 +92,28 @@
|
|
|
116
92
|
if (isClosable) {
|
|
117
93
|
stopDrawing();
|
|
118
94
|
} else {
|
|
119
|
-
points.push(cursor
|
|
95
|
+
points.push(cursor);
|
|
120
96
|
}
|
|
121
97
|
}
|
|
122
98
|
}
|
|
123
99
|
|
|
124
100
|
const onDblClick = () => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// Require min 3 points (incl. cursor) and minimum
|
|
128
|
-
// polygon area
|
|
101
|
+
console.log('dblclick');
|
|
102
|
+
|
|
129
103
|
const p = [...points, cursor];
|
|
130
104
|
|
|
131
105
|
const shape: Polygon = {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
106
|
+
type: ShapeType.POLYGON,
|
|
107
|
+
geometry: {
|
|
108
|
+
bounds: boundsFromPoints(p),
|
|
109
|
+
points: p
|
|
110
|
+
}
|
|
136
111
|
}
|
|
137
|
-
}
|
|
138
112
|
|
|
139
|
-
const area = computeArea(shape);
|
|
140
|
-
if (area > 4) {
|
|
141
113
|
points = [];
|
|
142
|
-
cursor =
|
|
114
|
+
cursor = null;
|
|
143
115
|
|
|
144
116
|
dispatch('create', shape);
|
|
145
|
-
}
|
|
146
117
|
}
|
|
147
118
|
|
|
148
119
|
const stopDrawing = () => {
|
|
@@ -155,7 +126,7 @@
|
|
|
155
126
|
}
|
|
156
127
|
|
|
157
128
|
points = [];
|
|
158
|
-
cursor =
|
|
129
|
+
cursor = null;
|
|
159
130
|
|
|
160
131
|
dispatch('create', shape);
|
|
161
132
|
}
|
|
@@ -168,7 +139,10 @@
|
|
|
168
139
|
});
|
|
169
140
|
</script>
|
|
170
141
|
|
|
171
|
-
<g
|
|
142
|
+
<g
|
|
143
|
+
bind:this={container}
|
|
144
|
+
class="a9s-annotation a9s-rubberband">
|
|
145
|
+
|
|
172
146
|
{#if cursor}
|
|
173
147
|
{@const coords = (isClosable ? points : [...points, cursor]).map(xy => xy.join(',')).join(' ')}
|
|
174
148
|
<polygon
|
|
@@ -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';
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
export let addEventListener: (type: string, fn: EventListener, capture?: boolean) => void;
|
|
11
11
|
export let drawingMode: DrawingMode;
|
|
12
12
|
export let transform: Transform;
|
|
13
|
+
|
|
14
|
+
let container: SVGGElement;
|
|
13
15
|
|
|
14
16
|
let lastPointerDown: number;
|
|
15
17
|
|
|
16
|
-
let origin: [x: number, y: number]
|
|
18
|
+
let origin: [x: number, y: number];
|
|
17
19
|
|
|
18
|
-
let anchor: [number, number]
|
|
20
|
+
let anchor: [number, number];
|
|
19
21
|
|
|
20
22
|
let x: number, y: number, w: number, h: number;
|
|
21
23
|
|
|
22
|
-
const onPointerDown = (
|
|
23
|
-
const evt = event as PointerEvent;
|
|
24
|
-
|
|
24
|
+
const onPointerDown = (evt: PointerEvent) => {
|
|
25
25
|
lastPointerDown = performance.now();
|
|
26
26
|
|
|
27
27
|
if (drawingMode === 'drag') {
|
|
@@ -35,9 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const onPointerMove = (
|
|
39
|
-
const evt = event as PointerEvent;
|
|
40
|
-
|
|
38
|
+
const onPointerMove = (evt: PointerEvent) => {
|
|
41
39
|
if (origin) {
|
|
42
40
|
anchor = transform.elementToImage(evt.offsetX, evt.offsetY);
|
|
43
41
|
|
|
@@ -48,9 +46,7 @@
|
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
const onPointerUp = (
|
|
52
|
-
const evt = event as PointerEvent;
|
|
53
|
-
|
|
49
|
+
const onPointerUp = (evt: PointerEvent) => {
|
|
54
50
|
const timeDifference = performance.now() - lastPointerDown;
|
|
55
51
|
|
|
56
52
|
if (drawingMode === 'click') {
|
|
@@ -77,8 +73,8 @@
|
|
|
77
73
|
evt.stopPropagation();
|
|
78
74
|
stopDrawing();
|
|
79
75
|
} else {
|
|
80
|
-
origin =
|
|
81
|
-
anchor =
|
|
76
|
+
origin = null;
|
|
77
|
+
anchor = null;
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
80
|
}
|
|
@@ -102,8 +98,8 @@
|
|
|
102
98
|
dispatch('create', shape);
|
|
103
99
|
}
|
|
104
100
|
|
|
105
|
-
origin =
|
|
106
|
-
anchor =
|
|
101
|
+
origin = null;
|
|
102
|
+
anchor = null;
|
|
107
103
|
}
|
|
108
104
|
|
|
109
105
|
onMount(() => {
|
|
@@ -113,7 +109,10 @@
|
|
|
113
109
|
});
|
|
114
110
|
</script>
|
|
115
111
|
|
|
116
|
-
<g
|
|
112
|
+
<g
|
|
113
|
+
bind:this={container}
|
|
114
|
+
class="a9s-annotation a9s-rubberband">
|
|
115
|
+
|
|
117
116
|
{#if origin}
|
|
118
117
|
<rect
|
|
119
118
|
class="a9s-outer"
|
package/src/index.ts
CHANGED
|
@@ -5,33 +5,16 @@ export * from './themes';
|
|
|
5
5
|
export * from './annotation/tools';
|
|
6
6
|
export * from './Annotorious';
|
|
7
7
|
export * from './AnnotoriousOpts';
|
|
8
|
-
export * from './keyboardCommands';
|
|
9
8
|
|
|
10
|
-
//
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
AnnotatorState,
|
|
17
|
-
Appearance,
|
|
18
|
-
AppearanceProvider,
|
|
19
|
-
Color,
|
|
20
|
-
DrawingStyle,
|
|
21
|
-
Filter,
|
|
22
|
-
FormatAdapter,
|
|
9
|
+
// Re-export essentials from @annotorious/core utilities for convenience
|
|
10
|
+
export * from '@annotorious/core/src/model';
|
|
11
|
+
export * from '@annotorious/core/src/presence';
|
|
12
|
+
export * from '@annotorious/core/src/utils';
|
|
13
|
+
|
|
14
|
+
export type {
|
|
23
15
|
HoverState,
|
|
24
|
-
LifecycleEvents,
|
|
25
|
-
ParseResult,
|
|
26
|
-
PresentUser,
|
|
27
|
-
Purpose,
|
|
28
16
|
Selection,
|
|
29
17
|
SelectionState,
|
|
30
18
|
Store,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
User,
|
|
34
|
-
W3CAnnotation,
|
|
35
|
-
W3CAnnotationBody,
|
|
36
|
-
W3CAnnotationTarget
|
|
37
|
-
} from '@annotorious/core';
|
|
19
|
+
StoreObserver
|
|
20
|
+
} from '@annotorious/core/src/state';
|