@operato/image-marker 8.0.0-alpha.23 → 8.0.0-alpha.24
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/CHANGELOG.md +9 -0
- package/dist/src/ox-image-marker-mode.d.ts +2 -2
- package/dist/src/ox-image-marker-mode.js +13 -13
- package/dist/src/ox-image-marker-mode.js.map +1 -1
- package/dist/src/ox-image-marker.d.ts +11 -8
- package/dist/src/ox-image-marker.js +111 -81
- package/dist/src/ox-image-marker.js.map +1 -1
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/ox-image-marker-mode.ts +15 -15
- package/src/ox-image-marker.ts +116 -81
- package/src/types.ts +1 -1
|
@@ -38,57 +38,57 @@ export class OxImageMarkerMode extends LitElement {
|
|
|
38
38
|
}
|
|
39
39
|
`
|
|
40
40
|
|
|
41
|
-
@property({ type: String }) currentMode: ImageMarkerMode = '
|
|
41
|
+
@property({ type: String }) currentMode: ImageMarkerMode = 'edit'
|
|
42
42
|
@property({ type: String }) currentShapeType?: ShapeType
|
|
43
43
|
|
|
44
44
|
render() {
|
|
45
45
|
return html`
|
|
46
46
|
<div class="palette">
|
|
47
47
|
<md-icon
|
|
48
|
-
title="
|
|
49
|
-
?selected=${this.currentMode !== '
|
|
50
|
-
@click=${() => this.setMode(this.currentMode !== '
|
|
51
|
-
>${this.currentMode !== '
|
|
48
|
+
title="Edit or View"
|
|
49
|
+
?selected=${this.currentMode !== 'shape'}
|
|
50
|
+
@click=${() => this.setMode(this.currentMode !== 'edit' ? 'edit' : 'view')}
|
|
51
|
+
>${this.currentMode !== 'view' ? 'brush' : 'drag_pan'}</md-icon
|
|
52
52
|
>
|
|
53
53
|
|
|
54
54
|
<md-icon
|
|
55
55
|
title="Text"
|
|
56
|
-
?selected=${this.currentMode === '
|
|
56
|
+
?selected=${this.currentMode === 'shape' && this.currentShapeType === 'text'}
|
|
57
57
|
@click=${() => this.setShape('text')}
|
|
58
58
|
>match_case</md-icon
|
|
59
59
|
>
|
|
60
60
|
|
|
61
61
|
<md-icon
|
|
62
62
|
title="Rectangle"
|
|
63
|
-
?selected=${this.currentMode === '
|
|
63
|
+
?selected=${this.currentMode === 'shape' && this.currentShapeType === 'rectangle'}
|
|
64
64
|
@click=${() => this.setShape('rectangle')}
|
|
65
65
|
>rectangle</md-icon
|
|
66
66
|
>
|
|
67
67
|
|
|
68
68
|
<md-icon
|
|
69
69
|
title="Circle"
|
|
70
|
-
?selected=${this.currentMode === '
|
|
70
|
+
?selected=${this.currentMode === 'shape' && this.currentShapeType === 'circle'}
|
|
71
71
|
@click=${() => this.setShape('circle')}
|
|
72
72
|
>circle</md-icon
|
|
73
73
|
>
|
|
74
74
|
|
|
75
75
|
<md-icon
|
|
76
76
|
title="Triangle"
|
|
77
|
-
?selected=${this.currentMode === '
|
|
77
|
+
?selected=${this.currentMode === 'shape' && this.currentShapeType === 'triangle'}
|
|
78
78
|
@click=${() => this.setShape('triangle')}
|
|
79
79
|
>change_history</md-icon
|
|
80
80
|
>
|
|
81
81
|
|
|
82
82
|
<md-icon
|
|
83
83
|
title="Line"
|
|
84
|
-
?selected=${this.currentMode === '
|
|
84
|
+
?selected=${this.currentMode === 'shape' && this.currentShapeType === 'line'}
|
|
85
85
|
@click=${() => this.setShape('line')}
|
|
86
86
|
>shape_line</md-icon
|
|
87
87
|
>
|
|
88
88
|
|
|
89
89
|
<md-icon
|
|
90
90
|
title="Arrow"
|
|
91
|
-
?selected=${this.currentMode === '
|
|
91
|
+
?selected=${this.currentMode === 'shape' && this.currentShapeType === 'arrow'}
|
|
92
92
|
@click=${() => this.setShape('arrow')}
|
|
93
93
|
>line_end_arrow</md-icon
|
|
94
94
|
>
|
|
@@ -105,7 +105,7 @@ export class OxImageMarkerMode extends LitElement {
|
|
|
105
105
|
`
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
public setMode(mode: ImageMarkerMode) {
|
|
109
109
|
this.currentMode = mode
|
|
110
110
|
|
|
111
111
|
this.dispatchEvent(
|
|
@@ -117,12 +117,12 @@ export class OxImageMarkerMode extends LitElement {
|
|
|
117
117
|
)
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
this.currentMode = '
|
|
120
|
+
protected setShape(shapeType: ShapeType) {
|
|
121
|
+
this.currentMode = 'shape'
|
|
122
122
|
this.currentShapeType = shapeType
|
|
123
123
|
this.dispatchEvent(
|
|
124
124
|
new CustomEvent('mode-changed', {
|
|
125
|
-
detail: { mode: '
|
|
125
|
+
detail: { mode: 'shape', shapeType: this.currentShapeType },
|
|
126
126
|
bubbles: true,
|
|
127
127
|
composed: true
|
|
128
128
|
})
|
package/src/ox-image-marker.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import './ox-image-marker-mode'
|
|
2
2
|
|
|
3
3
|
import { html, css, svg, nothing } from 'lit'
|
|
4
|
-
import { state, customElement } from 'lit/decorators.js'
|
|
4
|
+
import { query, state, customElement } from 'lit/decorators.js'
|
|
5
5
|
import { ifDefined } from 'lit/directives/if-defined.js'
|
|
6
6
|
import { keyed } from 'lit/directives/keyed.js'
|
|
7
7
|
|
|
8
8
|
import { ImageMarkerMode, Shape, ShapeType } from './types'
|
|
9
9
|
import { BaseImageMarker } from './base-image-marker'
|
|
10
|
+
import { OxImageMarkerMode } from './ox-image-marker-mode'
|
|
10
11
|
|
|
11
12
|
@customElement('ox-image-marker')
|
|
12
13
|
export class OxImageMarker extends BaseImageMarker {
|
|
@@ -27,11 +28,11 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
svg {
|
|
30
|
-
cursor:
|
|
31
|
+
cursor: default;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
svg
|
|
34
|
-
cursor:
|
|
34
|
+
svg[drawing] {
|
|
35
|
+
cursor: crosshair;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
.resize-handle {
|
|
@@ -41,9 +42,11 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
41
42
|
]
|
|
42
43
|
|
|
43
44
|
@state() private currentShapeType?: ShapeType
|
|
44
|
-
@state() private currentMode: ImageMarkerMode = '
|
|
45
|
+
@state() private currentMode: ImageMarkerMode = 'edit'
|
|
45
46
|
@state() private selectedShape: Shape | null = null
|
|
46
47
|
|
|
48
|
+
@query('ox-image-marker-mode') imageMarkerMode!: OxImageMarkerMode
|
|
49
|
+
|
|
47
50
|
private drawing = false
|
|
48
51
|
private startX = 0
|
|
49
52
|
private startY = 0
|
|
@@ -72,6 +75,7 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
72
75
|
@wheel=${this.onSvgWheel}
|
|
73
76
|
@dblclick=${this.onSvgDoubleClick}
|
|
74
77
|
viewBox=${this.viewBox}
|
|
78
|
+
?drawing=${this.currentMode == 'shape'}
|
|
75
79
|
>
|
|
76
80
|
<image href=${this.imageUrl} @load=${this.onImageLoad}></image>
|
|
77
81
|
${this.shapes.map(shape => keyed(shape.id, this.renderShape(shape)))}
|
|
@@ -103,15 +107,12 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
103
107
|
protected onSvgMouseDown(event: MouseEvent) {
|
|
104
108
|
event.preventDefault()
|
|
105
109
|
|
|
106
|
-
this.
|
|
107
|
-
this.shapes = this.shapes.map(s => {
|
|
108
|
-
return { ...s, selected: false }
|
|
109
|
-
})
|
|
110
|
+
this.setSelectedShape(null)
|
|
110
111
|
|
|
111
|
-
if (this.currentMode === '
|
|
112
|
-
this.startPanning(event)
|
|
113
|
-
} else if (this.currentMode === 'draw') {
|
|
112
|
+
if (this.currentMode === 'shape') {
|
|
114
113
|
this.startDrawing(event)
|
|
114
|
+
} else {
|
|
115
|
+
this.startPanning(event)
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
|
|
@@ -123,15 +124,12 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
if (event.touches.length === 1) {
|
|
126
|
-
this.
|
|
127
|
-
this.shapes = this.shapes.map(s => {
|
|
128
|
-
return { ...s, selected: false }
|
|
129
|
-
})
|
|
127
|
+
this.setSelectedShape(null)
|
|
130
128
|
|
|
131
|
-
if (this.currentMode === '
|
|
132
|
-
this.startPanning(event)
|
|
133
|
-
} else if (this.currentMode === 'draw') {
|
|
129
|
+
if (this.currentMode === 'shape') {
|
|
134
130
|
this.startDrawing(event)
|
|
131
|
+
} else {
|
|
132
|
+
this.startPanning(event)
|
|
135
133
|
}
|
|
136
134
|
} else if (event.touches.length === 2) {
|
|
137
135
|
this.startPinchZooming(event)
|
|
@@ -160,20 +158,24 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
if ('touches' in event) {
|
|
163
|
-
this.svg.addEventListener('touchmove', this.
|
|
164
|
-
this.svg.addEventListener('touchend', this.
|
|
161
|
+
this.svg.addEventListener('touchmove', this.onMouseMoveForDrawing)
|
|
162
|
+
this.svg.addEventListener('touchend', this.onMouseUpForDrawing)
|
|
165
163
|
} else {
|
|
166
|
-
this.svg.addEventListener('mousemove', this.
|
|
167
|
-
this.svg.addEventListener('mouseup', this.
|
|
164
|
+
this.svg.addEventListener('mousemove', this.onMouseMoveForDrawing)
|
|
165
|
+
this.svg.addEventListener('mouseup', this.onMouseUpForDrawing)
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
168
|
|
|
171
169
|
private setMode(mode: ImageMarkerMode, shapeType: ShapeType) {
|
|
170
|
+
if (mode == 'view') {
|
|
171
|
+
this.setSelectedShape(null)
|
|
172
|
+
}
|
|
173
|
+
|
|
172
174
|
this.currentMode = mode
|
|
173
175
|
this.currentShapeType = shapeType
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
private
|
|
178
|
+
private onMouseMoveForDrawing = (event: MouseEvent | TouchEvent) => {
|
|
177
179
|
if (!this.drawing) {
|
|
178
180
|
return
|
|
179
181
|
}
|
|
@@ -243,8 +245,8 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
243
245
|
return
|
|
244
246
|
}
|
|
245
247
|
|
|
246
|
-
this.selectedShape = newShape
|
|
247
248
|
this.shapes = [...this.shapes, newShape]
|
|
249
|
+
this.setSelectedShape(newShape)
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
if (this.selectedShape) {
|
|
@@ -278,7 +280,7 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
278
280
|
}
|
|
279
281
|
}
|
|
280
282
|
|
|
281
|
-
private
|
|
283
|
+
private onMouseUpForDrawing = (event: MouseEvent | TouchEvent) => {
|
|
282
284
|
event.preventDefault()
|
|
283
285
|
|
|
284
286
|
this.drawing = false
|
|
@@ -286,20 +288,30 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
286
288
|
const svg = this.svg as SVGSVGElement
|
|
287
289
|
|
|
288
290
|
if ('touches' in event) {
|
|
289
|
-
svg.removeEventListener('touchmove', this.
|
|
290
|
-
svg.removeEventListener('touchend', this.
|
|
291
|
+
svg.removeEventListener('touchmove', this.onMouseMoveForDrawing)
|
|
292
|
+
svg.removeEventListener('touchend', this.onMouseUpForDrawing)
|
|
291
293
|
} else {
|
|
292
|
-
svg.removeEventListener('mousemove', this.
|
|
293
|
-
svg.removeEventListener('mouseup', this.
|
|
294
|
+
svg.removeEventListener('mousemove', this.onMouseMoveForDrawing)
|
|
295
|
+
svg.removeEventListener('mouseup', this.onMouseUpForDrawing)
|
|
294
296
|
}
|
|
295
297
|
|
|
296
|
-
|
|
297
|
-
this.selectedShape.selected = true
|
|
298
|
-
}
|
|
298
|
+
this.imageMarkerMode.setMode('edit')
|
|
299
299
|
|
|
300
300
|
this.requestUpdate()
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
private setSelectedShape(shape: Shape | null) {
|
|
304
|
+
this.selectedShape = shape
|
|
305
|
+
|
|
306
|
+
if (!shape) {
|
|
307
|
+
this.shapes = this.shapes.map(s => {
|
|
308
|
+
return { ...s, selected: false }
|
|
309
|
+
})
|
|
310
|
+
} else {
|
|
311
|
+
this.selectedShape!.selected = true
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
303
315
|
private getSvgPoint(event: MouseEvent | TouchEvent) {
|
|
304
316
|
const { x, y } = this.getPointFromEvent(event)
|
|
305
317
|
|
|
@@ -328,8 +340,8 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
328
340
|
y="${shape.y!}"
|
|
329
341
|
fill="${commonAttrs.stroke}"
|
|
330
342
|
style="cursor: ${commonAttrs.cursor}; font-size: 16px;"
|
|
331
|
-
@mousedown="${(e: MouseEvent) => this.
|
|
332
|
-
@touchstart="${(e: TouchEvent) => this.
|
|
343
|
+
@mousedown="${(e: MouseEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
344
|
+
@touchstart="${(e: TouchEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
333
345
|
@dblclick="${(e: MouseEvent) => this.onTextDoubleClick(e, shape)}"
|
|
334
346
|
>${shape.text}</text>
|
|
335
347
|
`
|
|
@@ -345,8 +357,8 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
345
357
|
stroke-width="${commonAttrs['stroke-width']}"
|
|
346
358
|
fill="${commonAttrs.fill}"
|
|
347
359
|
style="cursor: ${commonAttrs.cursor}"
|
|
348
|
-
@mousedown="${(e: MouseEvent) => this.
|
|
349
|
-
@touchstart="${(e: TouchEvent) => this.
|
|
360
|
+
@mousedown="${(e: MouseEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
361
|
+
@touchstart="${(e: TouchEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
350
362
|
></rect>
|
|
351
363
|
${shape.selected ? this.renderResizeHandles(shape) : ''}
|
|
352
364
|
`
|
|
@@ -361,8 +373,8 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
361
373
|
stroke-width="${commonAttrs['stroke-width']}"
|
|
362
374
|
fill="${commonAttrs.fill}"
|
|
363
375
|
style="cursor: ${commonAttrs.cursor}"
|
|
364
|
-
@mousedown="${(e: MouseEvent) => this.
|
|
365
|
-
@touchstart="${(e: TouchEvent) => this.
|
|
376
|
+
@mousedown="${(e: MouseEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
377
|
+
@touchstart="${(e: TouchEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
366
378
|
></circle>
|
|
367
379
|
${shape.selected ? this.renderResizeHandles(shape) : ''}
|
|
368
380
|
`
|
|
@@ -375,8 +387,8 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
375
387
|
stroke-width="${commonAttrs['stroke-width']}"
|
|
376
388
|
fill="${commonAttrs.fill}"
|
|
377
389
|
style="cursor: ${commonAttrs.cursor}"
|
|
378
|
-
@mousedown="${(e: MouseEvent) => this.
|
|
379
|
-
@touchstart="${(e: TouchEvent) => this.
|
|
390
|
+
@mousedown="${(e: MouseEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
391
|
+
@touchstart="${(e: TouchEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
380
392
|
></polygon>
|
|
381
393
|
${shape.selected ? this.renderResizeHandles(shape) : ''}
|
|
382
394
|
`
|
|
@@ -391,8 +403,20 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
391
403
|
stroke="${commonAttrs.stroke}"
|
|
392
404
|
stroke-width="${commonAttrs['stroke-width']}"
|
|
393
405
|
style="cursor: ${commonAttrs.cursor}"
|
|
394
|
-
|
|
395
|
-
|
|
406
|
+
></line>
|
|
407
|
+
<line
|
|
408
|
+
x1="${shape.x1!}"
|
|
409
|
+
y1="${shape.y1!}"
|
|
410
|
+
x2="${shape.x2 ?? shape.x1}"
|
|
411
|
+
y2="${shape.y2 ?? shape.y1}"
|
|
412
|
+
stroke="${commonAttrs.stroke}"
|
|
413
|
+
stroke-width="25"
|
|
414
|
+
stroke-opacity="0"
|
|
415
|
+
pointer-events="stroke"
|
|
416
|
+
@mousedown="${(e: MouseEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
417
|
+
@touchstart="${(e: TouchEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
418
|
+
@mouseenter="${() => (this.svg.style.cursor = 'pointer')}"
|
|
419
|
+
@mouseleave="${() => (this.svg.style.cursor = 'default')}"
|
|
396
420
|
></line>
|
|
397
421
|
${shape.selected ? this.renderResizeHandles(shape) : ''}
|
|
398
422
|
`
|
|
@@ -413,8 +437,20 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
413
437
|
stroke-width="${commonAttrs['stroke-width']}"
|
|
414
438
|
marker-end="url(#arrowhead-${shape.id})"
|
|
415
439
|
style="cursor: ${commonAttrs.cursor}"
|
|
416
|
-
|
|
417
|
-
|
|
440
|
+
></line>
|
|
441
|
+
<line
|
|
442
|
+
x1="${shape.x1!}"
|
|
443
|
+
y1="${shape.y1!}"
|
|
444
|
+
x2="${shape.x2 ?? shape.x1}"
|
|
445
|
+
y2="${shape.y2 ?? shape.y1}"
|
|
446
|
+
stroke="${commonAttrs.stroke}"
|
|
447
|
+
stroke-width="25"
|
|
448
|
+
stroke-opacity="0"
|
|
449
|
+
pointer-events="stroke"
|
|
450
|
+
@mousedown="${(e: MouseEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
451
|
+
@touchstart="${(e: TouchEvent) => this.onMouseDownOnShape(e, shape)}"
|
|
452
|
+
@mouseenter="${() => (this.svg.style.cursor = 'pointer')}"
|
|
453
|
+
@mouseleave="${() => (this.svg.style.cursor = 'default')}"
|
|
418
454
|
></line>
|
|
419
455
|
${shape.selected ? this.renderResizeHandles(shape) : ''}
|
|
420
456
|
`
|
|
@@ -424,7 +460,11 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
424
460
|
}
|
|
425
461
|
}
|
|
426
462
|
|
|
427
|
-
private
|
|
463
|
+
private onMouseDownOnShape(event: MouseEvent | TouchEvent, shape: Shape) {
|
|
464
|
+
if (this.currentMode !== 'edit') {
|
|
465
|
+
return
|
|
466
|
+
}
|
|
467
|
+
|
|
428
468
|
event.stopPropagation()
|
|
429
469
|
event.preventDefault()
|
|
430
470
|
|
|
@@ -433,7 +473,7 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
433
473
|
selected: s.id === shape.id
|
|
434
474
|
}))
|
|
435
475
|
|
|
436
|
-
this.
|
|
476
|
+
this.setSelectedShape(this.shapes.find(s => s.id == shape.id)!)
|
|
437
477
|
|
|
438
478
|
const { x, y } = this.getSvgPoint(event)
|
|
439
479
|
|
|
@@ -446,7 +486,7 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
446
486
|
break
|
|
447
487
|
|
|
448
488
|
case 'triangle':
|
|
449
|
-
const points = this.selectedShape
|
|
489
|
+
const points = this.selectedShape!.points!.split(' ').map(p => p.split(',').map(Number))
|
|
450
490
|
const [px, py] = points[0] || [0, 0]
|
|
451
491
|
|
|
452
492
|
this.offsetX = x - px
|
|
@@ -464,15 +504,15 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
464
504
|
const svg = this.svg as SVGSVGElement
|
|
465
505
|
|
|
466
506
|
if ('touches' in event) {
|
|
467
|
-
svg.addEventListener('touchmove', this.
|
|
468
|
-
svg.addEventListener('touchend', this.
|
|
507
|
+
svg.addEventListener('touchmove', this.onMouseMoveOnShape)
|
|
508
|
+
svg.addEventListener('touchend', this.onMouseUpOnShape)
|
|
469
509
|
} else {
|
|
470
|
-
svg.addEventListener('mousemove', this.
|
|
471
|
-
svg.addEventListener('mouseup', this.
|
|
510
|
+
svg.addEventListener('mousemove', this.onMouseMoveOnShape)
|
|
511
|
+
svg.addEventListener('mouseup', this.onMouseUpOnShape)
|
|
472
512
|
}
|
|
473
513
|
}
|
|
474
514
|
|
|
475
|
-
private
|
|
515
|
+
private onMouseMoveOnShape = (event: MouseEvent | TouchEvent) => {
|
|
476
516
|
if (!this.selectedShape) {
|
|
477
517
|
return
|
|
478
518
|
}
|
|
@@ -515,17 +555,17 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
515
555
|
this.requestUpdate()
|
|
516
556
|
}
|
|
517
557
|
|
|
518
|
-
private
|
|
558
|
+
private onMouseUpOnShape = (event: MouseEvent | TouchEvent) => {
|
|
519
559
|
event.preventDefault()
|
|
520
560
|
|
|
521
561
|
const svg = this.svg as SVGSVGElement
|
|
522
562
|
|
|
523
563
|
if ('touches' in event) {
|
|
524
|
-
svg.removeEventListener('touchmove', this.
|
|
525
|
-
svg.removeEventListener('touchend', this.
|
|
564
|
+
svg.removeEventListener('touchmove', this.onMouseMoveOnShape)
|
|
565
|
+
svg.removeEventListener('touchend', this.onMouseUpOnShape)
|
|
526
566
|
} else {
|
|
527
|
-
svg.removeEventListener('mousemove', this.
|
|
528
|
-
svg.removeEventListener('mouseup', this.
|
|
567
|
+
svg.removeEventListener('mousemove', this.onMouseMoveOnShape)
|
|
568
|
+
svg.removeEventListener('mouseup', this.onMouseUpOnShape)
|
|
529
569
|
}
|
|
530
570
|
}
|
|
531
571
|
|
|
@@ -579,8 +619,8 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
579
619
|
stroke="black"
|
|
580
620
|
class="resize-handle"
|
|
581
621
|
style="cursor: ${handle.cursor};"
|
|
582
|
-
@mousedown="${(e: MouseEvent) => this.
|
|
583
|
-
@touchstart="${(e: TouchEvent) => this.
|
|
622
|
+
@mousedown="${(e: MouseEvent) => this.onResizeHandleMouseDown(e, shape, handle)}"
|
|
623
|
+
@touchstart="${(e: TouchEvent) => this.onResizeHandleMouseDown(e, shape, handle)}"
|
|
584
624
|
></rect>
|
|
585
625
|
</g>
|
|
586
626
|
`
|
|
@@ -588,25 +628,26 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
588
628
|
`
|
|
589
629
|
}
|
|
590
630
|
|
|
591
|
-
private
|
|
631
|
+
private onResizeHandleMouseDown(event: MouseEvent | TouchEvent, shape: Shape, handle: any) {
|
|
592
632
|
event.stopPropagation()
|
|
593
633
|
event.preventDefault()
|
|
594
634
|
|
|
595
|
-
this.
|
|
635
|
+
this.setSelectedShape(shape)
|
|
636
|
+
|
|
596
637
|
this.offsetX = handle.x
|
|
597
638
|
this.offsetY = handle.y
|
|
598
639
|
const svg = this.svg as SVGSVGElement
|
|
599
640
|
|
|
600
641
|
if ('touches' in event) {
|
|
601
|
-
svg.addEventListener('touchmove', this.
|
|
602
|
-
svg.addEventListener('touchend', this.
|
|
642
|
+
svg.addEventListener('touchmove', this.onResizeHandleMouseMove)
|
|
643
|
+
svg.addEventListener('touchend', this.onResizeHandleMouseUp)
|
|
603
644
|
} else {
|
|
604
|
-
svg.addEventListener('mousemove', this.
|
|
605
|
-
svg.addEventListener('mouseup', this.
|
|
645
|
+
svg.addEventListener('mousemove', this.onResizeHandleMouseMove)
|
|
646
|
+
svg.addEventListener('mouseup', this.onResizeHandleMouseUp)
|
|
606
647
|
}
|
|
607
648
|
}
|
|
608
649
|
|
|
609
|
-
private
|
|
650
|
+
private onResizeHandleMouseMove = (event: MouseEvent | TouchEvent) => {
|
|
610
651
|
if (!this.selectedShape) {
|
|
611
652
|
return
|
|
612
653
|
}
|
|
@@ -616,12 +657,6 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
616
657
|
const { x, y } = this.getSvgPoint(event)
|
|
617
658
|
|
|
618
659
|
switch (this.selectedShape.type) {
|
|
619
|
-
// case 'text':
|
|
620
|
-
// this.selectedShape.width = Math.abs(x - this.selectedShape.x!)
|
|
621
|
-
// this.selectedShape.height = Math.abs(y - this.selectedShape.y!)
|
|
622
|
-
// if (x < this.selectedShape.x!) this.selectedShape.x = x
|
|
623
|
-
// if (y < this.selectedShape.y!) this.selectedShape.y = y
|
|
624
|
-
// break
|
|
625
660
|
case 'rectangle':
|
|
626
661
|
const startX = this.selectedShape.x!
|
|
627
662
|
const startY = this.selectedShape.y!
|
|
@@ -691,20 +726,18 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
691
726
|
this.requestUpdate()
|
|
692
727
|
}
|
|
693
728
|
|
|
694
|
-
private
|
|
729
|
+
private onResizeHandleMouseUp = (event: MouseEvent | TouchEvent) => {
|
|
695
730
|
event.preventDefault()
|
|
696
731
|
|
|
697
732
|
const svg = this.svg as SVGSVGElement
|
|
698
733
|
|
|
699
734
|
if ('touches' in event) {
|
|
700
|
-
svg.removeEventListener('touchmove', this.
|
|
701
|
-
svg.removeEventListener('touchend', this.
|
|
735
|
+
svg.removeEventListener('touchmove', this.onResizeHandleMouseMove)
|
|
736
|
+
svg.removeEventListener('touchend', this.onResizeHandleMouseUp)
|
|
702
737
|
} else {
|
|
703
|
-
svg.removeEventListener('mousemove', this.
|
|
704
|
-
svg.removeEventListener('mouseup', this.
|
|
738
|
+
svg.removeEventListener('mousemove', this.onResizeHandleMouseMove)
|
|
739
|
+
svg.removeEventListener('mouseup', this.onResizeHandleMouseUp)
|
|
705
740
|
}
|
|
706
|
-
|
|
707
|
-
this.selectedShape = null
|
|
708
741
|
}
|
|
709
742
|
|
|
710
743
|
private onTextDoubleClick(event: MouseEvent, shape: Shape) {
|
|
@@ -849,7 +882,9 @@ export class OxImageMarker extends BaseImageMarker {
|
|
|
849
882
|
private deleteSelectedShape() {
|
|
850
883
|
if (this.selectedShape) {
|
|
851
884
|
this.shapes = this.shapes.filter(s => s.id !== this.selectedShape!.id)
|
|
852
|
-
|
|
885
|
+
|
|
886
|
+
this.setSelectedShape(null)
|
|
887
|
+
|
|
853
888
|
this.requestUpdate()
|
|
854
889
|
}
|
|
855
890
|
}
|
package/src/types.ts
CHANGED