@operato/image-marker 8.0.0-alpha.17 → 8.0.0-alpha.22
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 +18 -0
- package/dist/src/base-image-marker.d.ts +16 -4
- package/dist/src/base-image-marker.js +96 -15
- package/dist/src/base-image-marker.js.map +1 -1
- package/dist/src/ox-image-marker-mode.js +2 -2
- package/dist/src/ox-image-marker-mode.js.map +1 -1
- package/dist/src/ox-image-marker-view.js +2 -2
- package/dist/src/ox-image-marker-view.js.map +1 -1
- package/dist/src/ox-image-marker.d.ts +9 -4
- package/dist/src/ox-image-marker.js +162 -92
- package/dist/src/ox-image-marker.js.map +1 -1
- package/dist/stories/ox-image-marker.stories.js +16 -0
- package/dist/stories/ox-image-marker.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/base-image-marker.ts +114 -19
- package/src/ox-image-marker-mode.ts +2 -2
- package/src/ox-image-marker-view.ts +2 -2
- package/src/ox-image-marker.ts +181 -100
- package/stories/ox-image-marker.stories.ts +16 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [8.0.0-alpha.22](https://github.com/hatiolab/operato/compare/v8.0.0-alpha.21...v8.0.0-alpha.22) (2024-10-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### :bug: Bug Fix
|
|
10
|
+
|
|
11
|
+
* support touch gesture for ox-image-markers ([d1d8cc2](https://github.com/hatiolab/operato/commit/d1d8cc2fa385e2147172300f13cff49a195ce49f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## [8.0.0-alpha.18](https://github.com/hatiolab/operato/compare/v8.0.0-alpha.17...v8.0.0-alpha.18) (2024-10-04)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### :bug: Bug Fix
|
|
19
|
+
|
|
20
|
+
* ox-image-marker ([ae56c0a](https://github.com/hatiolab/operato/commit/ae56c0a28af20d029e907181af0babe63526cae5))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## [8.0.0-alpha.17](https://github.com/hatiolab/operato/compare/v8.0.0-alpha.16...v8.0.0-alpha.17) (2024-10-04)
|
|
7
25
|
|
|
8
26
|
|
|
@@ -13,12 +13,24 @@ export declare class BaseImageMarker extends LitElement {
|
|
|
13
13
|
y: number;
|
|
14
14
|
};
|
|
15
15
|
protected initialViewBox: string;
|
|
16
|
+
private initialPinchDistance;
|
|
17
|
+
private initialZoomLevel;
|
|
16
18
|
protected svg: SVGSVGElement;
|
|
17
19
|
protected onImageLoad(event: Event): void;
|
|
18
|
-
protected
|
|
20
|
+
protected onSvgWheel(event: WheelEvent): void;
|
|
19
21
|
protected onSvgMouseDown(event: MouseEvent): void;
|
|
20
|
-
protected
|
|
21
|
-
protected
|
|
22
|
-
protected
|
|
22
|
+
protected onSvgTouchStart: (event: TouchEvent) => void;
|
|
23
|
+
protected startPinchZooming(event: TouchEvent): void;
|
|
24
|
+
protected onZoomTouchMove: (event: TouchEvent) => void;
|
|
25
|
+
protected onZoomTouchEnd: (event: TouchEvent) => void;
|
|
26
|
+
protected applyZoom(): void;
|
|
27
|
+
protected onSvgDoubleClick(): void;
|
|
28
|
+
protected startPanning(event: MouseEvent | TouchEvent): void;
|
|
29
|
+
protected onPanMouseMove: (event: MouseEvent | TouchEvent) => void;
|
|
30
|
+
protected onPanMouseUp: (event: MouseEvent | TouchEvent) => void;
|
|
23
31
|
protected renderShape(shape: Shape): import("lit-html").TemplateResult<2> | typeof nothing;
|
|
32
|
+
protected getPointFromEvent(event: MouseEvent | TouchEvent): {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
};
|
|
24
36
|
}
|
|
@@ -12,11 +12,42 @@ export class BaseImageMarker extends LitElement {
|
|
|
12
12
|
this.isPanning = false;
|
|
13
13
|
this.panStart = { x: 0, y: 0 };
|
|
14
14
|
this.initialViewBox = '0 0 800 600';
|
|
15
|
+
this.initialPinchDistance = null;
|
|
16
|
+
this.initialZoomLevel = 1;
|
|
17
|
+
this.onSvgTouchStart = (event) => {
|
|
18
|
+
if (event.touches.length === 1) {
|
|
19
|
+
this.startPanning(event);
|
|
20
|
+
}
|
|
21
|
+
else if (event.touches.length === 2) {
|
|
22
|
+
this.startPinchZooming(event);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
this.onZoomTouchMove = (event) => {
|
|
26
|
+
if (event.touches.length === 2 && this.initialPinchDistance) {
|
|
27
|
+
const touch1 = event.touches[0];
|
|
28
|
+
const touch2 = event.touches[1];
|
|
29
|
+
const dx = touch2.clientX - touch1.clientX;
|
|
30
|
+
const dy = touch2.clientY - touch1.clientY;
|
|
31
|
+
const currentPinchDistance = Math.sqrt(dx * dx + dy * dy);
|
|
32
|
+
const scaleFactor = currentPinchDistance / this.initialPinchDistance;
|
|
33
|
+
this.zoomLevel = this.initialZoomLevel * scaleFactor;
|
|
34
|
+
this.applyZoom();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
this.onZoomTouchEnd = (event) => {
|
|
38
|
+
if (event.touches.length < 2) {
|
|
39
|
+
this.initialPinchDistance = null;
|
|
40
|
+
}
|
|
41
|
+
this.svg.removeEventListener('touchmove', this.onZoomTouchMove);
|
|
42
|
+
this.svg.removeEventListener('touchend', this.onZoomTouchEnd);
|
|
43
|
+
};
|
|
15
44
|
this.onPanMouseMove = (event) => {
|
|
16
|
-
if (!this.isPanning)
|
|
45
|
+
if (!this.isPanning) {
|
|
17
46
|
return;
|
|
18
|
-
|
|
19
|
-
const
|
|
47
|
+
}
|
|
48
|
+
const { x, y } = this.getPointFromEvent(event);
|
|
49
|
+
const dx = x - this.panStart.x;
|
|
50
|
+
const dy = y - this.panStart.y;
|
|
20
51
|
const [vbX, vbY, vbWidth, vbHeight] = this.viewBox.split(' ').map(Number);
|
|
21
52
|
const scaleX = vbWidth / this.svg.clientWidth;
|
|
22
53
|
const scaleY = vbHeight / this.svg.clientHeight;
|
|
@@ -24,14 +55,20 @@ export class BaseImageMarker extends LitElement {
|
|
|
24
55
|
const newVbX = vbX - dx * scale;
|
|
25
56
|
const newVbY = vbY - dy * scale;
|
|
26
57
|
this.viewBox = `${newVbX} ${newVbY} ${vbWidth} ${vbHeight}`;
|
|
27
|
-
this.panStart = { x
|
|
58
|
+
this.panStart = { x, y };
|
|
28
59
|
};
|
|
29
|
-
this.onPanMouseUp = () => {
|
|
60
|
+
this.onPanMouseUp = (event) => {
|
|
30
61
|
const svg = this.svg;
|
|
31
62
|
this.isPanning = false;
|
|
32
63
|
svg.classList.remove('dragging');
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
if ('touches' in event) {
|
|
65
|
+
svg.removeEventListener('touchmove', this.onPanMouseMove);
|
|
66
|
+
svg.removeEventListener('touchend', this.onPanMouseUp);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
svg.removeEventListener('mousemove', this.onPanMouseMove);
|
|
70
|
+
svg.removeEventListener('mouseup', this.onPanMouseUp);
|
|
71
|
+
}
|
|
35
72
|
};
|
|
36
73
|
}
|
|
37
74
|
static { this.styles = [
|
|
@@ -65,7 +102,7 @@ export class BaseImageMarker extends LitElement {
|
|
|
65
102
|
};
|
|
66
103
|
img.src = this.imageUrl;
|
|
67
104
|
}
|
|
68
|
-
|
|
105
|
+
onSvgWheel(event) {
|
|
69
106
|
event.preventDefault();
|
|
70
107
|
const { offsetX, offsetY, deltaY } = event;
|
|
71
108
|
const scale = deltaY > 0 ? 1 - this.zoomFactor : 1 + this.zoomFactor;
|
|
@@ -80,17 +117,47 @@ export class BaseImageMarker extends LitElement {
|
|
|
80
117
|
this.viewBox = `${newVbX} ${newVbY} ${newVbWidth} ${newVbHeight}`;
|
|
81
118
|
}
|
|
82
119
|
onSvgMouseDown(event) {
|
|
83
|
-
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
120
|
+
this.startPanning(event);
|
|
121
|
+
this.svg.addEventListener('mousemove', this.onPanMouseMove);
|
|
122
|
+
this.svg.addEventListener('mouseup', this.onPanMouseUp);
|
|
123
|
+
}
|
|
124
|
+
startPinchZooming(event) {
|
|
125
|
+
const touch1 = event.touches[0];
|
|
126
|
+
const touch2 = event.touches[1];
|
|
127
|
+
const dx = touch2.clientX - touch1.clientX;
|
|
128
|
+
const dy = touch2.clientY - touch1.clientY;
|
|
129
|
+
this.initialPinchDistance = Math.sqrt(dx * dx + dy * dy);
|
|
130
|
+
this.initialZoomLevel = this.zoomLevel;
|
|
131
|
+
this.svg.addEventListener('touchmove', this.onZoomTouchMove);
|
|
132
|
+
this.svg.addEventListener('touchend', this.onZoomTouchEnd);
|
|
133
|
+
}
|
|
134
|
+
applyZoom() {
|
|
135
|
+
const [vbX, vbY, vbWidth, vbHeight] = this.viewBox.split(' ').map(Number);
|
|
136
|
+
const initialViewBoxNumbers = this.initialViewBox.split(' ').map(Number);
|
|
137
|
+
const newVbWidth = initialViewBoxNumbers[2] / this.zoomLevel;
|
|
138
|
+
const newVbHeight = initialViewBoxNumbers[3] / this.zoomLevel;
|
|
139
|
+
const newVbX = vbX + (vbWidth - newVbWidth) / 2;
|
|
140
|
+
const newVbY = vbY + (vbHeight - newVbHeight) / 2;
|
|
141
|
+
this.viewBox = `${newVbX} ${newVbY} ${newVbWidth} ${newVbHeight}`;
|
|
89
142
|
}
|
|
90
|
-
|
|
143
|
+
onSvgDoubleClick() {
|
|
91
144
|
this.viewBox = this.initialViewBox;
|
|
92
145
|
this.zoomLevel = 1;
|
|
93
146
|
}
|
|
147
|
+
startPanning(event) {
|
|
148
|
+
const { x, y } = this.getPointFromEvent(event);
|
|
149
|
+
this.isPanning = true;
|
|
150
|
+
this.panStart = { x, y };
|
|
151
|
+
this.svg.classList.add('dragging');
|
|
152
|
+
if ('touches' in event) {
|
|
153
|
+
this.svg.addEventListener('touchmove', this.onPanMouseMove);
|
|
154
|
+
this.svg.addEventListener('touchend', this.onPanMouseUp);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
this.svg.addEventListener('mousemove', this.onPanMouseMove);
|
|
158
|
+
this.svg.addEventListener('mouseup', this.onPanMouseUp);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
94
161
|
renderShape(shape) {
|
|
95
162
|
const commonAttrs = {
|
|
96
163
|
stroke: 'red',
|
|
@@ -118,6 +185,20 @@ export class BaseImageMarker extends LitElement {
|
|
|
118
185
|
return nothing;
|
|
119
186
|
}
|
|
120
187
|
}
|
|
188
|
+
getPointFromEvent(event) {
|
|
189
|
+
if ('touches' in event) {
|
|
190
|
+
return {
|
|
191
|
+
x: event.touches[0].clientX,
|
|
192
|
+
y: event.touches[0].clientY
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
return {
|
|
197
|
+
x: event.clientX,
|
|
198
|
+
y: event.clientY
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
121
202
|
}
|
|
122
203
|
__decorate([
|
|
123
204
|
property({ type: String })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-image-marker.js","sourceRoot":"","sources":["../../src/base-image-marker.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAQ,GAAG,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAI1D,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAA/C;;QAuB8B,aAAQ,GAAW,EAAE,CAAA;QACtB,WAAM,GAAY,EAAE,CAAA;QAE5B,YAAO,GAAG,aAAa,CAAA;QACvB,cAAS,GAAG,CAAC,CAAA;QAEtB,eAAU,GAAG,GAAG,CAA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C,KAAK,CAAC,EAAE,YAAY,CAAA;YAC5M;gBACE,OAAO,OAAO,CAAA;QAClB,CAAC;IACH,CAAC;;AAlH2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDAAsB;AACtB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;+CAAqB;AAE5B;IAAlB,KAAK,EAAE;gDAAkC;AACvB;IAAlB,KAAK,EAAE;kDAAwB;AAOR;IAAvB,KAAK,CAAC,KAAK,CAAC;4CAA8B","sourcesContent":["import { LitElement, css, html, svg, nothing } from 'lit'\nimport { property, state, query } from 'lit/decorators.js'\n\nimport { Shape } from './types'\n\nexport class BaseImageMarker extends LitElement {\n static styles = [\n css`\n :host {\n display: flex;\n }\n\n .container {\n flex: 1;\n position: relative;\n }\n\n svg {\n position: absolute;\n top: 0;\n left: 0;\n cursor: pointer;\n width: 100%;\n height: 100%;\n }\n `\n ]\n\n @property({ type: String }) imageUrl: string = ''\n @property({ type: Array }) shapes: Shape[] = []\n\n @state() protected viewBox = '0 0 800 600'\n @state() protected zoomLevel = 1\n\n protected zoomFactor = 0.1\n protected isPanning = false\n protected panStart = { x: 0, y: 0 }\n protected initialViewBox = '0 0 800 600'\n\n @query('svg') protected svg!: SVGSVGElement\n\n protected onImageLoad(event: Event) {\n const img = new Image()\n img.onload = () => {\n const width = img.naturalWidth\n const height = img.naturalHeight\n this.viewBox = `0 0 ${width} ${height}`\n this.initialViewBox = `0 0 ${width} ${height}`\n }\n img.src = this.imageUrl\n }\n\n protected onWheel(event: WheelEvent) {\n event.preventDefault()\n\n const { offsetX, offsetY, deltaY } = event\n const scale = deltaY > 0 ? 1 - this.zoomFactor : 1 + this.zoomFactor\n this.zoomLevel *= scale\n\n const [vbX, vbY, vbWidth, vbHeight] = this.viewBox.split(' ').map(Number)\n const mouseX = vbX + (offsetX / this.svg.clientWidth) * vbWidth\n const mouseY = vbY + (offsetY / this.svg.clientHeight) * vbHeight\n\n const newVbWidth = vbWidth / scale\n const newVbHeight = vbHeight / scale\n\n const newVbX = mouseX - (offsetX / this.svg.clientWidth) * newVbWidth\n const newVbY = mouseY - (offsetY / this.svg.clientHeight) * newVbHeight\n\n this.viewBox = `${newVbX} ${newVbY} ${newVbWidth} ${newVbHeight}`\n }\n\n protected onSvgMouseDown(event: MouseEvent) {\n const svg = this.svg\n\n this.isPanning = true\n this.panStart = { x: event.clientX, y: event.clientY }\n svg.classList.add('dragging')\n\n svg.addEventListener('mousemove', this.onPanMouseMove)\n svg.addEventListener('mouseup', this.onPanMouseUp)\n }\n\n protected onPanMouseMove = (event: MouseEvent) => {\n if (!this.isPanning) return\n\n const dx = event.clientX - this.panStart.x\n const dy = event.clientY - this.panStart.y\n\n const [vbX, vbY, vbWidth, vbHeight] = this.viewBox.split(' ').map(Number)\n const scaleX = vbWidth / this.svg.clientWidth\n const scaleY = vbHeight / this.svg.clientHeight\n const scale = Math.max(scaleX, scaleY)\n\n const newVbX = vbX - dx * scale\n const newVbY = vbY - dy * scale\n\n this.viewBox = `${newVbX} ${newVbY} ${vbWidth} ${vbHeight}`\n this.panStart = { x: event.clientX, y: event.clientY }\n }\n\n protected onPanMouseUp = () => {\n const svg = this.svg\n\n this.isPanning = false\n svg.classList.remove('dragging')\n svg.removeEventListener('mousemove', this.onPanMouseMove)\n svg.removeEventListener('mouseup', this.onPanMouseUp)\n }\n\n protected onDoubleClick() {\n this.viewBox = this.initialViewBox\n this.zoomLevel = 1\n }\n\n protected renderShape(shape: Shape) {\n const commonAttrs = {\n stroke: 'red',\n 'stroke-width': 1,\n fill: 'transparent'\n }\n\n switch (shape.type) {\n case 'text':\n return svg`<text x=\"${shape.x}\" y=\"${shape.y}\" text-anchor=\"middle\" alignment-baseline=\"middle\" fill=\"black\">${shape.text}</text>`\n case 'rectangle':\n return svg`<rect x=\"${shape.x}\" y=\"${shape.y}\" width=\"${shape.width}\" height=\"${shape.height}\" stroke=\"${commonAttrs.stroke}\" stroke-width=\"${commonAttrs['stroke-width']}\" fill=\"${commonAttrs.fill}\"></rect>`\n case 'circle':\n return svg`<circle cx=\"${shape.cx}\" cy=\"${shape.cy}\" r=\"${shape.r}\" stroke=\"${commonAttrs.stroke}\" stroke-width=\"${commonAttrs['stroke-width']}\" fill=\"${commonAttrs.fill}\"></circle>`\n case 'line':\n return svg`<line x1=\"${shape.x1}\" y1=\"${shape.y1}\" x2=\"${shape.x2}\" y2=\"${shape.y2}\" stroke=\"${commonAttrs.stroke}\" stroke-width=\"${commonAttrs['stroke-width']}\"></line>`\n case 'arrow':\n return svg`\n <defs>\n <marker id=\"arrowhead-${shape.id}\" markerWidth=\"10\" markerHeight=\"7\" refX=\"10\" refY=\"3.5\" orient=\"auto\">\n <polygon points=\"0 0, 10 3.5, 0 7\" fill=\"${commonAttrs.stroke}\"></polygon>\n </marker>\n </defs>\n <line x1=\"${shape.x1}\" y1=\"${shape.y1}\" x2=\"${shape.x2}\" y2=\"${shape.y2}\" stroke=\"${commonAttrs.stroke}\" stroke-width=\"${commonAttrs['stroke-width']}\" marker-end=\"url(#arrowhead-${shape.id})\"></line>`\n default:\n return nothing\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base-image-marker.js","sourceRoot":"","sources":["../../src/base-image-marker.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAQ,GAAG,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAI1D,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAA/C;;QAuB8B,aAAQ,GAAW,EAAE,CAAA;QACtB,WAAM,GAAY,EAAE,CAAA;QAE5B,YAAO,GAAG,aAAa,CAAA;QACvB,cAAS,GAAG,CAAC,CAAA;QAEtB,eAAU,GAAG,GAAG,CAAA;QAChB,cAAS,GAAG,KAAK,CAAA;QACjB,aAAQ,GAAG,EAAE,CAA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OAAO,OAAO,CAAA;QAClB,CAAC;IACH,CAAC;IAES,iBAAiB,CAAC,KAA8B;QACxD,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;YACvB,OAAO;gBACL,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO;gBAC3B,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO;aAC5B,CAAA;QACH,CAAC;aAAM,CAAC;YACN,OAAO;gBACL,CAAC,EAAE,KAAK,CAAC,OAAO;gBAChB,CAAC,EAAE,KAAK,CAAC,OAAO;aACjB,CAAA;QACH,CAAC;IACH,CAAC;;AAjN2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDAAsB;AACtB;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;+CAAqB;AAE5B;IAAlB,KAAK,EAAE;gDAAkC;AACvB;IAAlB,KAAK,EAAE;kDAAwB;AASR;IAAvB,KAAK,CAAC,KAAK,CAAC;4CAA8B","sourcesContent":["import { LitElement, css, html, svg, nothing } from 'lit'\nimport { property, state, query } from 'lit/decorators.js'\n\nimport { Shape } from './types'\n\nexport class BaseImageMarker extends LitElement {\n static styles = [\n css`\n :host {\n display: flex;\n }\n\n .container {\n flex: 1;\n position: relative;\n }\n\n svg {\n position: absolute;\n top: 0;\n left: 0;\n cursor: pointer;\n width: 100%;\n height: 100%;\n }\n `\n ]\n\n @property({ type: String }) imageUrl: string = ''\n @property({ type: Array }) shapes: Shape[] = []\n\n @state() protected viewBox = '0 0 800 600'\n @state() protected zoomLevel = 1\n\n protected zoomFactor = 0.1\n protected isPanning = false\n protected panStart = { x: 0, y: 0 }\n protected initialViewBox = '0 0 800 600'\n private initialPinchDistance: number | null = null\n private initialZoomLevel: number = 1\n\n @query('svg') protected svg!: SVGSVGElement\n\n protected onImageLoad(event: Event) {\n const img = new Image()\n img.onload = () => {\n const width = img.naturalWidth\n const height = img.naturalHeight\n this.viewBox = `0 0 ${width} ${height}`\n this.initialViewBox = `0 0 ${width} ${height}`\n }\n img.src = this.imageUrl\n }\n\n protected onSvgWheel(event: WheelEvent) {\n event.preventDefault()\n\n const { offsetX, offsetY, deltaY } = event\n const scale = deltaY > 0 ? 1 - this.zoomFactor : 1 + this.zoomFactor\n this.zoomLevel *= scale\n\n const [vbX, vbY, vbWidth, vbHeight] = this.viewBox.split(' ').map(Number)\n const mouseX = vbX + (offsetX / this.svg.clientWidth) * vbWidth\n const mouseY = vbY + (offsetY / this.svg.clientHeight) * vbHeight\n\n const newVbWidth = vbWidth / scale\n const newVbHeight = vbHeight / scale\n\n const newVbX = mouseX - (offsetX / this.svg.clientWidth) * newVbWidth\n const newVbY = mouseY - (offsetY / this.svg.clientHeight) * newVbHeight\n\n this.viewBox = `${newVbX} ${newVbY} ${newVbWidth} ${newVbHeight}`\n }\n\n protected onSvgMouseDown(event: MouseEvent) {\n this.startPanning(event)\n\n this.svg.addEventListener('mousemove', this.onPanMouseMove)\n this.svg.addEventListener('mouseup', this.onPanMouseUp)\n }\n\n protected onSvgTouchStart = (event: TouchEvent) => {\n if (event.touches.length === 1) {\n this.startPanning(event)\n } else if (event.touches.length === 2) {\n this.startPinchZooming(event)\n }\n }\n\n protected startPinchZooming(event: TouchEvent) {\n const touch1 = event.touches[0]\n const touch2 = event.touches[1]\n\n const dx = touch2.clientX - touch1.clientX\n const dy = touch2.clientY - touch1.clientY\n\n this.initialPinchDistance = Math.sqrt(dx * dx + dy * dy)\n this.initialZoomLevel = this.zoomLevel\n\n this.svg.addEventListener('touchmove', this.onZoomTouchMove)\n this.svg.addEventListener('touchend', this.onZoomTouchEnd)\n }\n\n protected onZoomTouchMove = (event: TouchEvent) => {\n if (event.touches.length === 2 && this.initialPinchDistance) {\n const touch1 = event.touches[0]\n const touch2 = event.touches[1]\n const dx = touch2.clientX - touch1.clientX\n const dy = touch2.clientY - touch1.clientY\n const currentPinchDistance = Math.sqrt(dx * dx + dy * dy)\n\n const scaleFactor = currentPinchDistance / this.initialPinchDistance\n this.zoomLevel = this.initialZoomLevel * scaleFactor\n\n this.applyZoom()\n }\n }\n\n protected onZoomTouchEnd = (event: TouchEvent) => {\n if (event.touches.length < 2) {\n this.initialPinchDistance = null\n }\n\n this.svg.removeEventListener('touchmove', this.onZoomTouchMove)\n this.svg.removeEventListener('touchend', this.onZoomTouchEnd)\n }\n\n protected applyZoom() {\n const [vbX, vbY, vbWidth, vbHeight] = this.viewBox.split(' ').map(Number)\n const initialViewBoxNumbers = this.initialViewBox.split(' ').map(Number)\n const newVbWidth = initialViewBoxNumbers[2] / this.zoomLevel\n const newVbHeight = initialViewBoxNumbers[3] / this.zoomLevel\n const newVbX = vbX + (vbWidth - newVbWidth) / 2\n const newVbY = vbY + (vbHeight - newVbHeight) / 2\n\n this.viewBox = `${newVbX} ${newVbY} ${newVbWidth} ${newVbHeight}`\n }\n\n protected onSvgDoubleClick() {\n this.viewBox = this.initialViewBox\n this.zoomLevel = 1\n }\n\n protected startPanning(event: MouseEvent | TouchEvent) {\n const { x, y } = this.getPointFromEvent(event)\n\n this.isPanning = true\n this.panStart = { x, y }\n this.svg.classList.add('dragging')\n\n if ('touches' in event) {\n this.svg.addEventListener('touchmove', this.onPanMouseMove)\n this.svg.addEventListener('touchend', this.onPanMouseUp)\n } else {\n this.svg.addEventListener('mousemove', this.onPanMouseMove)\n this.svg.addEventListener('mouseup', this.onPanMouseUp)\n }\n }\n\n protected onPanMouseMove = (event: MouseEvent | TouchEvent) => {\n if (!this.isPanning) {\n return\n }\n\n const { x, y } = this.getPointFromEvent(event)\n\n const dx = x - this.panStart.x\n const dy = y - this.panStart.y\n\n const [vbX, vbY, vbWidth, vbHeight] = this.viewBox.split(' ').map(Number)\n const scaleX = vbWidth / this.svg.clientWidth\n const scaleY = vbHeight / this.svg.clientHeight\n const scale = Math.max(scaleX, scaleY)\n\n const newVbX = vbX - dx * scale\n const newVbY = vbY - dy * scale\n\n this.viewBox = `${newVbX} ${newVbY} ${vbWidth} ${vbHeight}`\n this.panStart = { x, y }\n }\n\n protected onPanMouseUp = (event: MouseEvent | TouchEvent) => {\n const svg = this.svg\n\n this.isPanning = false\n svg.classList.remove('dragging')\n\n if ('touches' in event) {\n svg.removeEventListener('touchmove', this.onPanMouseMove)\n svg.removeEventListener('touchend', this.onPanMouseUp)\n } else {\n svg.removeEventListener('mousemove', this.onPanMouseMove)\n svg.removeEventListener('mouseup', this.onPanMouseUp)\n }\n }\n\n protected renderShape(shape: Shape) {\n const commonAttrs = {\n stroke: 'red',\n 'stroke-width': 1,\n fill: 'transparent'\n }\n\n switch (shape.type) {\n case 'text':\n return svg`<text x=\"${shape.x}\" y=\"${shape.y}\" text-anchor=\"middle\" alignment-baseline=\"middle\" fill=\"black\">${shape.text}</text>`\n case 'rectangle':\n return svg`<rect x=\"${shape.x}\" y=\"${shape.y}\" width=\"${shape.width}\" height=\"${shape.height}\" stroke=\"${commonAttrs.stroke}\" stroke-width=\"${commonAttrs['stroke-width']}\" fill=\"${commonAttrs.fill}\"></rect>`\n case 'circle':\n return svg`<circle cx=\"${shape.cx}\" cy=\"${shape.cy}\" r=\"${shape.r}\" stroke=\"${commonAttrs.stroke}\" stroke-width=\"${commonAttrs['stroke-width']}\" fill=\"${commonAttrs.fill}\"></circle>`\n case 'line':\n return svg`<line x1=\"${shape.x1}\" y1=\"${shape.y1}\" x2=\"${shape.x2}\" y2=\"${shape.y2}\" stroke=\"${commonAttrs.stroke}\" stroke-width=\"${commonAttrs['stroke-width']}\"></line>`\n case 'arrow':\n return svg`\n <defs>\n <marker id=\"arrowhead-${shape.id}\" markerWidth=\"10\" markerHeight=\"7\" refX=\"10\" refY=\"3.5\" orient=\"auto\">\n <polygon points=\"0 0, 10 3.5, 0 7\" fill=\"${commonAttrs.stroke}\"></polygon>\n </marker>\n </defs>\n <line x1=\"${shape.x1}\" y1=\"${shape.y1}\" x2=\"${shape.x2}\" y2=\"${shape.y2}\" stroke=\"${commonAttrs.stroke}\" stroke-width=\"${commonAttrs['stroke-width']}\" marker-end=\"url(#arrowhead-${shape.id})\"></line>`\n default:\n return nothing\n }\n }\n\n protected getPointFromEvent(event: MouseEvent | TouchEvent) {\n if ('touches' in event) {\n return {\n x: event.touches[0].clientX,\n y: event.touches[0].clientY\n }\n } else {\n return {\n x: event.clientX,\n y: event.clientY\n }\n }\n }\n}\n"]}
|
|
@@ -115,13 +115,13 @@ let OxImageMarkerMode = class OxImageMarkerMode extends LitElement {
|
|
|
115
115
|
}));
|
|
116
116
|
}
|
|
117
117
|
onClickDelete() {
|
|
118
|
-
this.dispatchEvent(new CustomEvent('
|
|
118
|
+
this.dispatchEvent(new CustomEvent('tap-delete', {
|
|
119
119
|
bubbles: true,
|
|
120
120
|
composed: true
|
|
121
121
|
}));
|
|
122
122
|
}
|
|
123
123
|
onClickSave() {
|
|
124
|
-
this.dispatchEvent(new CustomEvent('
|
|
124
|
+
this.dispatchEvent(new CustomEvent('tap-save', {
|
|
125
125
|
bubbles: true,
|
|
126
126
|
composed: true
|
|
127
127
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ox-image-marker-mode.js","sourceRoot":"","sources":["../../src/ox-image-marker-mode.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAIpD,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,UAAU;IAA1C;;QAiCuB,gBAAW,GAAoB,QAAQ,CAAA;IAwGrE,CAAC;aAxIQ,WAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BlB,AA9BY,CA8BZ;IAKD,MAAM;QACJ,OAAO,IAAI,CAAA;;;;sBAIO,IAAI,CAAC,WAAW,KAAK,MAAM;m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itElement, html, css } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { ImageMarkerMode, ShapeType } from './types'\n\n@customElement('ox-image-marker-mode')\nexport class OxImageMarkerMode extends LitElement {\n static styles = css`\n :host {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-medium);\n }\n\n .palette {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-small);\n justify-content: center;\n margin: var(--spacing-medium);\n\n --md-icon-size: 16px;\n }\n\n .palette > * {\n padding: var(--spacing-small);\n cursor: pointer;\n background-color: #f0f0f0;\n border: 1px solid #ccc;\n border-radius: 4px;\n width: 12px;\n height: 12px;\n }\n\n .palette [selected] {\n background-color: #d0d0d0;\n }\n `\n\n @property({ type: String }) currentMode: ImageMarkerMode = 'select'\n @property({ type: String }) currentShapeType?: ShapeType\n\n render() {\n return html`\n <div class=\"palette\">\n <md-icon\n title=\"Move or Select\"\n ?selected=${this.currentMode !== 'draw'}\n @click=${() => this.setMode(this.currentMode !== 'select' ? 'select' : 'move')}\n >${this.currentMode !== 'move' ? 'select' : 'drag_pan'}</md-icon\n >\n\n <md-icon\n title=\"Text\"\n ?selected=${this.currentMode === 'draw' && this.currentShapeType === 'text'}\n @click=${() => this.setShape('text')}\n >match_case</md-icon\n >\n\n <md-icon\n title=\"Rectangle\"\n ?selected=${this.currentMode === 'draw' && this.currentShapeType === 'rectangle'}\n @click=${() => this.setShape('rectangle')}\n >rectangle</md-icon\n >\n\n <md-icon\n title=\"Circle\"\n ?selected=${this.currentMode === 'draw' && this.currentShapeType === 'circle'}\n @click=${() => this.setShape('circle')}\n >circle</md-icon\n >\n\n <md-icon\n title=\"Triangle\"\n ?selected=${this.currentMode === 'draw' && this.currentShapeType === 'triangle'}\n @click=${() => this.setShape('triangle')}\n >change_history</md-icon\n >\n\n <md-icon\n title=\"Line\"\n ?selected=${this.currentMode === 'draw' && this.currentShapeType === 'line'}\n @click=${() => this.setShape('line')}\n >shape_line</md-icon\n >\n\n <md-icon\n title=\"Arrow\"\n ?selected=${this.currentMode === 'draw' && this.currentShapeType === 'arrow'}\n @click=${() => this.setShape('arrow')}\n >line_end_arrow</md-icon\n >\n </div>\n\n <div class=\"palette\">\n <md-icon title=\"Delete\" @click=${() => this.onClickDelete()}>delete</md-icon>\n <md-icon title=\"Save\" @click=${() => this.onClickSave()}>save</md-icon>\n </div>\n `\n }\n\n private setMode(mode: ImageMarkerMode) {\n this.currentMode = mode\n\n this.dispatchEvent(\n new CustomEvent('mode-changed', {\n detail: { mode: this.currentMode, shapeType: this.currentShapeType },\n bubbles: true,\n composed: true\n })\n )\n }\n\n private setShape(shapeType: ShapeType) {\n this.currentMode = 'draw'\n this.currentShapeType = shapeType\n this.dispatchEvent(\n new CustomEvent('mode-changed', {\n detail: { mode: 'draw', shapeType: this.currentShapeType },\n bubbles: true,\n composed: true\n })\n )\n }\n\n private onClickDelete() {\n this.dispatchEvent(\n new CustomEvent('tap-delete', {\n bubbles: true,\n composed: true\n })\n )\n }\n\n private onClickSave() {\n this.dispatchEvent(\n new CustomEvent('tap-save', {\n bubbles: true,\n composed: true\n })\n )\n }\n}\n"]}
|
|
@@ -7,9 +7,9 @@ let OxImageMarkerView = class OxImageMarkerView extends BaseImageMarker {
|
|
|
7
7
|
return html `
|
|
8
8
|
<div class="container">
|
|
9
9
|
<svg
|
|
10
|
-
@wheel=${this.
|
|
10
|
+
@wheel=${this.onSvgWheel}
|
|
11
11
|
@mousedown=${this.onSvgMouseDown}
|
|
12
|
-
@dblclick=${this.
|
|
12
|
+
@dblclick=${this.onSvgDoubleClick}
|
|
13
13
|
viewBox=${this.viewBox}
|
|
14
14
|
>
|
|
15
15
|
<image href=${this.imageUrl} @load=${this.onImageLoad}></image>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ox-image-marker-view.js","sourceRoot":"","sources":["../../src/ox-image-marker-view.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAGjD,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,eAAe;IACpD,MAAM;QACJ,OAAO,IAAI,CAAA;;;mBAGI,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"ox-image-marker-view.js","sourceRoot":"","sources":["../../src/ox-image-marker-view.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAGjD,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,eAAe;IACpD,MAAM;QACJ,OAAO,IAAI,CAAA;;;mBAGI,IAAI,CAAC,UAAU;uBACX,IAAI,CAAC,cAAc;sBACpB,IAAI,CAAC,gBAAgB;oBACvB,IAAI,CAAC,OAAO;;wBAER,IAAI,CAAC,QAAQ,UAAU,IAAI,CAAC,WAAW;YACnD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;;;KAGxD,CAAA;IACH,CAAC;CACF,CAAA;AAhBY,iBAAiB;IAD7B,aAAa,CAAC,sBAAsB,CAAC;GACzB,iBAAiB,CAgB7B","sourcesContent":["import { html } from 'lit'\nimport { customElement } from 'lit/decorators.js'\n\nimport { BaseImageMarker } from './base-image-marker.js'\n\n@customElement('ox-image-marker-view')\nexport class OxImageMarkerView extends BaseImageMarker {\n render() {\n return html`\n <div class=\"container\">\n <svg\n @wheel=${this.onSvgWheel}\n @mousedown=${this.onSvgMouseDown}\n @dblclick=${this.onSvgDoubleClick}\n viewBox=${this.viewBox}\n >\n <image href=${this.imageUrl} @load=${this.onImageLoad}></image>\n ${this.shapes.map(shape => this.renderShape(shape))}\n </svg>\n </div>\n `\n }\n}\n"]}
|
|
@@ -12,19 +12,20 @@ export declare class OxImageMarker extends BaseImageMarker {
|
|
|
12
12
|
private startY;
|
|
13
13
|
private offsetX;
|
|
14
14
|
private offsetY;
|
|
15
|
+
connectedCallback(): void;
|
|
16
|
+
disconnectedCallback(): void;
|
|
15
17
|
render(): import("lit-html").TemplateResult<1>;
|
|
16
18
|
protected onSvgMouseDown(event: MouseEvent): void;
|
|
17
|
-
|
|
19
|
+
protected onSvgTouchStart: (event: TouchEvent) => void;
|
|
18
20
|
private startDrawing;
|
|
19
21
|
private setMode;
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
+
private onDrawingMouseMove;
|
|
23
|
+
private onDrawingMouseUp;
|
|
22
24
|
private getSvgPoint;
|
|
23
25
|
protected renderShape(shape: Shape): import("lit-html").TemplateResult<2> | typeof nothing;
|
|
24
26
|
private onShapeMouseDown;
|
|
25
27
|
private onShapeMouseMove;
|
|
26
28
|
private onShapeMouseUp;
|
|
27
|
-
private getScale;
|
|
28
29
|
private renderResizeHandles;
|
|
29
30
|
private onHandleMouseDown;
|
|
30
31
|
private onHandleMouseMove;
|
|
@@ -33,4 +34,8 @@ export declare class OxImageMarker extends BaseImageMarker {
|
|
|
33
34
|
private showTextInput;
|
|
34
35
|
private adjustInputWidth;
|
|
35
36
|
private measureTextWidth;
|
|
37
|
+
private onFocus;
|
|
38
|
+
private onBlur;
|
|
39
|
+
private handleKeyDown;
|
|
40
|
+
private deleteSelectedShape;
|
|
36
41
|
}
|