@inweb/viewer-visualize 25.7.2 → 25.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/viewer-visualize.js +7358 -7450
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +3755 -3755
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Markup/MarkupFactory.d.ts +1 -1
- package/lib/Viewer/Markup/{Impl/Visualize → Visualize}/VisualizeMarkup.d.ts +1 -3
- package/lib/Viewer/Viewer.d.ts +1 -2
- package/lib/index.d.ts +1 -11
- package/package.json +5 -12
- package/src/Viewer/Markup/MarkupFactory.ts +2 -3
- package/src/Viewer/Markup/{Impl/Visualize → Visualize}/VisualizeMarkup.ts +4 -6
- package/src/Viewer/Viewer.ts +1 -2
- package/src/index.ts +1 -11
- package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +0 -52
- package/lib/Viewer/Markup/Api/IMarkupCloud.d.ts +0 -50
- package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +0 -15
- package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +0 -50
- package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +0 -50
- package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +0 -43
- package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +0 -47
- package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +0 -50
- package/lib/Viewer/Markup/Api/IMarkupText.d.ts +0 -40
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaArrow.d.ts +0 -46
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaCloud.d.ts +0 -35
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.d.ts +0 -40
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaImage.d.ts +0 -36
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +0 -35
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.d.ts +0 -38
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaText.d.ts +0 -37
- package/lib/Viewer/Markup/IMarkup.d.ts +0 -130
- package/lib/Viewer/Markup/IWorldTransform.d.ts +0 -39
- package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +0 -82
- package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +0 -38
- package/src/Viewer/Markup/Api/IMarkupArrow.ts +0 -69
- package/src/Viewer/Markup/Api/IMarkupCloud.ts +0 -78
- package/src/Viewer/Markup/Api/IMarkupColorable.ts +0 -39
- package/src/Viewer/Markup/Api/IMarkupEllipse.ts +0 -78
- package/src/Viewer/Markup/Api/IMarkupImage.ts +0 -78
- package/src/Viewer/Markup/Api/IMarkupLine.ts +0 -70
- package/src/Viewer/Markup/Api/IMarkupObject.ts +0 -78
- package/src/Viewer/Markup/Api/IMarkupRectangle.ts +0 -78
- package/src/Viewer/Markup/Api/IMarkupText.ts +0 -66
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +0 -147
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaCloud.ts +0 -213
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +0 -150
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +0 -149
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +0 -136
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +0 -149
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +0 -141
- package/src/Viewer/Markup/IMarkup.ts +0 -173
- package/src/Viewer/Markup/IWorldTransform.ts +0 -46
- package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +0 -1264
- package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +0 -82
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import Konva from "konva";
|
|
2
|
-
import { IMarkupColorable } from "../../IMarkupColorable";
|
|
3
|
-
import { IMarkupCloud } from "../../IMarkupCloud";
|
|
4
|
-
|
|
5
|
-
export class KonvaCloud implements IMarkupCloud, IMarkupColorable {
|
|
6
|
-
private _ref: Konva.Shape;
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
params: {
|
|
10
|
-
position: { x: number; y: number };
|
|
11
|
-
width?: number;
|
|
12
|
-
height?: number;
|
|
13
|
-
lineWidth?: number;
|
|
14
|
-
color?: string;
|
|
15
|
-
id?: string;
|
|
16
|
-
},
|
|
17
|
-
ref = null
|
|
18
|
-
) {
|
|
19
|
-
if (ref) {
|
|
20
|
-
this._ref = ref;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!params.position || !params.width || !params.height) return;
|
|
25
|
-
|
|
26
|
-
const arcRadius = 16;
|
|
27
|
-
|
|
28
|
-
this._ref = new Konva.Shape({
|
|
29
|
-
x: params.position.x,
|
|
30
|
-
y: params.position.y,
|
|
31
|
-
width: params.width ?? 200,
|
|
32
|
-
height: params.height ?? 200,
|
|
33
|
-
stroke: params.color ?? "#ff0000",
|
|
34
|
-
strokeWidth: params.lineWidth ?? 4,
|
|
35
|
-
draggable: true,
|
|
36
|
-
strokeScaleEnabled: false,
|
|
37
|
-
globalCompositeOperation: "source-over",
|
|
38
|
-
sceneFunc: (context, shape) => {
|
|
39
|
-
function calculateMidpoint(position, width, height) {
|
|
40
|
-
const midX = position.x + width / 2;
|
|
41
|
-
const midY = position.y + height / 2;
|
|
42
|
-
return { x: midX, y: midY };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const points = [
|
|
46
|
-
{ x: 0, y: 0 },
|
|
47
|
-
{ x: 0 + this._ref.width(), y: 0 },
|
|
48
|
-
{ x: 0 + this._ref.width(), y: 0 + this._ref.height() },
|
|
49
|
-
{ x: 0, y: 0 + this._ref.height() },
|
|
50
|
-
{ x: 0, y: 0 },
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
const midPoint = calculateMidpoint({ x: 0, y: 0 }, this._ref.width(), this._ref.height());
|
|
54
|
-
|
|
55
|
-
const baseArcLength = 30;
|
|
56
|
-
context.beginPath();
|
|
57
|
-
for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
|
|
58
|
-
let approxArcLength = baseArcLength;
|
|
59
|
-
const dx = points[iPoint + 1].x - points[iPoint].x;
|
|
60
|
-
const dy = points[iPoint + 1].y - points[iPoint].y;
|
|
61
|
-
const length = Math.sqrt(dx * dx + dy * dy);
|
|
62
|
-
|
|
63
|
-
const arcCount = Math.floor(length / approxArcLength);
|
|
64
|
-
const lengthMod = length % approxArcLength;
|
|
65
|
-
approxArcLength = baseArcLength + arcCount / lengthMod;
|
|
66
|
-
|
|
67
|
-
let pX = points[iPoint].x + dx / arcCount / 2;
|
|
68
|
-
let pY = points[iPoint].y + dy / arcCount / 2;
|
|
69
|
-
const pEndX = points[iPoint + 1].x;
|
|
70
|
-
const pEndY = points[iPoint + 1].y;
|
|
71
|
-
const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
|
|
72
|
-
const startAngle = endAngle + Math.PI;
|
|
73
|
-
const counterClockwise = pX > midPoint.x && pY > midPoint.y;
|
|
74
|
-
for (let iArc = 0; iArc < arcCount; iArc++) {
|
|
75
|
-
if (counterClockwise) {
|
|
76
|
-
context.arc(pX, pY, arcRadius, endAngle, startAngle);
|
|
77
|
-
} else {
|
|
78
|
-
context.arc(pX, pY, arcRadius, startAngle, endAngle);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
pX += dx / arcCount;
|
|
82
|
-
pY += dy / arcCount;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
context.closePath();
|
|
87
|
-
// (!) Konva specific method, it is very important
|
|
88
|
-
// it will apply are required styles
|
|
89
|
-
context.fillStrokeShape(shape);
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
this._ref.className = "Cloud";
|
|
94
|
-
|
|
95
|
-
this._ref.on("transform", (e) => {
|
|
96
|
-
const attrs = e.target.attrs;
|
|
97
|
-
|
|
98
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
99
|
-
|
|
100
|
-
const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
|
|
101
|
-
const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
|
|
102
|
-
|
|
103
|
-
let newWidth = this._ref.width();
|
|
104
|
-
if (scaleByX) newWidth *= attrs.scaleX;
|
|
105
|
-
let newHeight = this._ref.height();
|
|
106
|
-
if (scaleByY) newHeight *= attrs.scaleY;
|
|
107
|
-
|
|
108
|
-
const minWidth = 100;
|
|
109
|
-
const minHeight = 100;
|
|
110
|
-
|
|
111
|
-
if (newWidth < minWidth) newWidth = minWidth;
|
|
112
|
-
if (newHeight < minHeight) newHeight = minHeight;
|
|
113
|
-
|
|
114
|
-
if (scaleByX) {
|
|
115
|
-
this._ref.width(newWidth);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (scaleByY) {
|
|
119
|
-
this._ref.height(newHeight);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this._ref.scale({ x: 1, y: 1 });
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
this._ref.getSelfRect = () => {
|
|
126
|
-
return {
|
|
127
|
-
x: 0 - arcRadius,
|
|
128
|
-
y: 0 - arcRadius,
|
|
129
|
-
width: this._ref.width() + 2 * arcRadius,
|
|
130
|
-
height: this._ref.height() + 2 * arcRadius,
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
this._ref.id(this._ref._id.toString());
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
ref() {
|
|
138
|
-
return this._ref;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
id(): string {
|
|
142
|
-
return this._ref.id();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
enableMouseEditing(value: boolean) {
|
|
146
|
-
this._ref.draggable(value);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
type(): string {
|
|
150
|
-
return "cloud";
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getColor(): string {
|
|
154
|
-
return this._ref.stroke() as string;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
setColor(hex: string) {
|
|
158
|
-
this._ref.stroke(hex);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
getRotation(): number {
|
|
162
|
-
return this._ref.rotation();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
setRotation(degrees: number): void {
|
|
166
|
-
this._ref.rotation(degrees);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
getZIndex(): number {
|
|
170
|
-
return this._ref.zIndex();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
setZIndex(zIndex: number): void {
|
|
174
|
-
this._ref.zIndex(zIndex);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
delete() {
|
|
178
|
-
this._ref.destroy();
|
|
179
|
-
this._ref = null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
getPosition() {
|
|
183
|
-
return this._ref.position();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
setPosition(x: number, y: number) {
|
|
187
|
-
this._ref.position({ x, y });
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
getWidth(): number {
|
|
191
|
-
return this._ref.width();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
setWidth(w: number) {
|
|
195
|
-
this._ref.width(w);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
getHeigth(): number {
|
|
199
|
-
return this._ref.height();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
setHeight(h: number) {
|
|
203
|
-
this._ref.height(h);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
getLineWidth(): number {
|
|
207
|
-
return this._ref.strokeWidth();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
setLineWidth(size: number) {
|
|
211
|
-
this._ref.strokeWidth(size);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import Konva from "konva";
|
|
2
|
-
import { IMarkupEllipse } from "../../IMarkupEllipse";
|
|
3
|
-
import { IMarkupColorable } from "../../IMarkupColorable";
|
|
4
|
-
|
|
5
|
-
export class KonvaEllipse implements IMarkupEllipse, IMarkupColorable {
|
|
6
|
-
private _ref: Konva.Ellipse;
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
params: {
|
|
10
|
-
position: { x: number; y: number };
|
|
11
|
-
radius: { x: number; y: number };
|
|
12
|
-
lineWidth?: number;
|
|
13
|
-
color?: string;
|
|
14
|
-
id?: string;
|
|
15
|
-
},
|
|
16
|
-
ref = null
|
|
17
|
-
) {
|
|
18
|
-
if (ref) {
|
|
19
|
-
this._ref = ref;
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!params.position) return;
|
|
24
|
-
|
|
25
|
-
this._ref = new Konva.Ellipse({
|
|
26
|
-
stroke: params.color ?? "#ff0000",
|
|
27
|
-
strokeWidth: params.lineWidth ?? 4,
|
|
28
|
-
globalCompositeOperation: "source-over",
|
|
29
|
-
lineCap: "round",
|
|
30
|
-
lineJoin: "round",
|
|
31
|
-
x: params.position.x,
|
|
32
|
-
y: params.position.y,
|
|
33
|
-
radiusX: params.radius.x,
|
|
34
|
-
radiusY: params.radius.y,
|
|
35
|
-
draggable: true,
|
|
36
|
-
strokeScaleEnabled: false,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
this._ref.on("transform", (e) => {
|
|
40
|
-
const attrs = e.target.attrs;
|
|
41
|
-
|
|
42
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
43
|
-
|
|
44
|
-
const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
|
|
45
|
-
const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
|
|
46
|
-
|
|
47
|
-
let newRadiusX = this._ref.radiusX();
|
|
48
|
-
if (scaleByX) newRadiusX *= attrs.scaleX;
|
|
49
|
-
let newRadiusY = this._ref.radiusY();
|
|
50
|
-
if (scaleByY) newRadiusY *= attrs.scaleY;
|
|
51
|
-
|
|
52
|
-
const minRadiusX = 25;
|
|
53
|
-
const minRadiusY = 25;
|
|
54
|
-
|
|
55
|
-
if (newRadiusX < minRadiusX) newRadiusX = minRadiusX;
|
|
56
|
-
if (newRadiusY < minRadiusY) newRadiusY = minRadiusY;
|
|
57
|
-
|
|
58
|
-
if (e.evt.ctrlKey || e.evt.shiftKey) {
|
|
59
|
-
if (scaleByX) {
|
|
60
|
-
this._ref.radius({ x: newRadiusX, y: newRadiusX });
|
|
61
|
-
} else {
|
|
62
|
-
this._ref.radius({ x: newRadiusY, y: newRadiusY });
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
this._ref.radius({ x: newRadiusX, y: newRadiusY });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
this._ref.scale({ x: 1, y: 1 });
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
this._ref.id(this._ref._id.toString());
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getPosition(): { x: number; y: number } {
|
|
75
|
-
return this._ref.position();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
setPosition(x: number, y: number) {
|
|
79
|
-
this._ref.setPosition({ x, y });
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
getRadiusX(): number {
|
|
83
|
-
return this._ref.radiusX();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
setRadiusX(r: number) {
|
|
87
|
-
this._ref.radiusX(r);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
getRadiusY(): number {
|
|
91
|
-
return this._ref.radiusY();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
setRadiusY(r: number) {
|
|
95
|
-
this._ref.radiusY(r);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
getLineWidth(): number {
|
|
99
|
-
return this._ref.strokeWidth();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
setLineWidth(size: number) {
|
|
103
|
-
this._ref.strokeWidth(size);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
ref() {
|
|
107
|
-
return this._ref;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
id(): string {
|
|
111
|
-
return this._ref.id();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
enableMouseEditing(value: boolean) {
|
|
115
|
-
this._ref.draggable(value);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
type(): string {
|
|
119
|
-
return "ellipse";
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
getColor(): string {
|
|
123
|
-
return this._ref.stroke() as string;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
setColor(hex: string) {
|
|
127
|
-
this._ref.stroke(hex);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
getRotation(): number {
|
|
131
|
-
return this._ref.rotation();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
setRotation(degrees: number): void {
|
|
135
|
-
this._ref.rotation(degrees);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
getZIndex(): number {
|
|
139
|
-
return this._ref.zIndex();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
setZIndex(zIndex: number): void {
|
|
143
|
-
this._ref.zIndex(zIndex);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
delete() {
|
|
147
|
-
this._ref.destroy();
|
|
148
|
-
this._ref = null;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import Konva from "konva";
|
|
2
|
-
import { IMarkupImage } from "../../IMarkupImage";
|
|
3
|
-
|
|
4
|
-
export class KonvaImage implements IMarkupImage {
|
|
5
|
-
private _ref: Konva.Image;
|
|
6
|
-
private _canvasImage: HTMLImageElement;
|
|
7
|
-
private _ratio = 1;
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
params: { position: { x: number; y: number }; src: string; width: number; height: number; id?: string },
|
|
11
|
-
ref = null
|
|
12
|
-
) {
|
|
13
|
-
if (ref) {
|
|
14
|
-
if (ref.height() === 0 || ref.width() === 0) return;
|
|
15
|
-
|
|
16
|
-
this._ref = ref;
|
|
17
|
-
this._canvasImage = ref.image();
|
|
18
|
-
this._ratio = this._ref.height() / this._ref.width();
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!params.position || !params.src) return;
|
|
23
|
-
this._canvasImage = new Image();
|
|
24
|
-
|
|
25
|
-
this._ref = new Konva.Image({
|
|
26
|
-
x: params.position.x,
|
|
27
|
-
y: params.position.y,
|
|
28
|
-
image: this._canvasImage,
|
|
29
|
-
width: params.width,
|
|
30
|
-
height: params.height,
|
|
31
|
-
draggable: true,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
this._canvasImage.onload = () => {
|
|
35
|
-
this._ref.image(this._canvasImage);
|
|
36
|
-
if (this._ref.height() === 0) this._ref.height(this._canvasImage.height);
|
|
37
|
-
if (this._ref.width() === 0) this._ref.width(this._canvasImage.width);
|
|
38
|
-
this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
this._canvasImage.src = params.src;
|
|
42
|
-
|
|
43
|
-
this._ref.on("transform", (e) => {
|
|
44
|
-
const attrs = e.target.attrs;
|
|
45
|
-
|
|
46
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
47
|
-
|
|
48
|
-
const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
|
|
49
|
-
const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
|
|
50
|
-
|
|
51
|
-
let newWidth = this._ref.width();
|
|
52
|
-
if (scaleByX) newWidth *= attrs.scaleX;
|
|
53
|
-
let newHeight = this._ref.height();
|
|
54
|
-
if (scaleByY) newHeight *= attrs.scaleY;
|
|
55
|
-
|
|
56
|
-
if (e.evt.ctrlKey || e.evt.shiftKey) {
|
|
57
|
-
if (scaleByX) {
|
|
58
|
-
this._ref.width(newWidth);
|
|
59
|
-
this._ref.height(newWidth * this._ratio);
|
|
60
|
-
} else {
|
|
61
|
-
this._ref.width(newHeight / this._ratio);
|
|
62
|
-
this._ref.height(newHeight);
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
if (scaleByX) {
|
|
66
|
-
this._ref.width(newWidth);
|
|
67
|
-
}
|
|
68
|
-
if (scaleByY) {
|
|
69
|
-
this._ref.height(newHeight);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this._ref.scale({ x: 1, y: 1 });
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
this._ref.id(this._ref._id.toString());
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getSrc(): string {
|
|
80
|
-
return this._canvasImage.src;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
setSrc(src: any) {
|
|
84
|
-
this._canvasImage.src = src;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getWidth(): number {
|
|
88
|
-
return this._ref.width();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
setWidth(w: number) {
|
|
92
|
-
this._ref.width(w);
|
|
93
|
-
this._ref.height(w * this._ratio);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
getHeight(): number {
|
|
97
|
-
return this._ref.height();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
setHeight(h: number) {
|
|
101
|
-
this._ref.height(h);
|
|
102
|
-
this._ref.width(h / this._ratio);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
ref() {
|
|
106
|
-
return this._ref;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
id(): string {
|
|
110
|
-
return this._ref.id();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
enableMouseEditing(value: boolean) {
|
|
114
|
-
this._ref.draggable(value);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
type(): string {
|
|
118
|
-
return "image";
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
getRotation(): number {
|
|
122
|
-
return this._ref.rotation();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
setRotation(degrees: number): void {
|
|
126
|
-
this._ref.rotation(degrees);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
getZIndex(): number {
|
|
130
|
-
return this._ref.zIndex();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
setZIndex(zIndex: number): void {
|
|
134
|
-
this._ref.zIndex(zIndex);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
delete() {
|
|
138
|
-
this._ref.destroy();
|
|
139
|
-
this._ref = null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
getPosition(): { x: number; y: number } {
|
|
143
|
-
return this._ref.getPosition();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
setPosition(x: number, y: number) {
|
|
147
|
-
this._ref.setPosition({ x, y });
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import Konva from "konva";
|
|
2
|
-
import { IMarkupLine, MarkupLineType } from "../../IMarkupLine";
|
|
3
|
-
import { IMarkupColorable } from "../../IMarkupColorable";
|
|
4
|
-
|
|
5
|
-
const LineTypeSpecs = new Map<string, number[]>([
|
|
6
|
-
["solid", []],
|
|
7
|
-
["dot", [30, 30, 0.001, 30]],
|
|
8
|
-
["dash", [30, 30]],
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
export class KonvaLine implements IMarkupLine, IMarkupColorable {
|
|
12
|
-
private _ref: Konva.Line;
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
params: { points: { x: number; y: number }[]; type?: MarkupLineType; width?: number; color?: string; id?: string },
|
|
16
|
-
ref = null
|
|
17
|
-
) {
|
|
18
|
-
if (ref) {
|
|
19
|
-
this._ref = ref;
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!params.points) return;
|
|
24
|
-
|
|
25
|
-
const konvaPoints = [];
|
|
26
|
-
params.points.forEach((point) => konvaPoints.push(point.x, point.y));
|
|
27
|
-
|
|
28
|
-
this._ref = new Konva.Line({
|
|
29
|
-
stroke: params.color ?? "#ff0000",
|
|
30
|
-
strokeWidth: params.width ?? 4,
|
|
31
|
-
globalCompositeOperation: "source-over",
|
|
32
|
-
lineCap: "round",
|
|
33
|
-
lineJoin: "round",
|
|
34
|
-
points: konvaPoints,
|
|
35
|
-
draggable: true,
|
|
36
|
-
strokeScaleEnabled: false,
|
|
37
|
-
dash: LineTypeSpecs.get(params.type) || [],
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
this._ref.on("transform", (e) => {
|
|
41
|
-
const attrs = e.target.attrs;
|
|
42
|
-
|
|
43
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
this._ref.id(this._ref._id.toString());
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
ref() {
|
|
50
|
-
return this._ref;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
id(): string {
|
|
54
|
-
return this._ref.id();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
enableMouseEditing(value: boolean) {
|
|
58
|
-
this._ref.draggable(value);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type(): string {
|
|
62
|
-
return "line";
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getColor(): string {
|
|
66
|
-
return this._ref.stroke() as string;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
setColor(hex: string) {
|
|
70
|
-
this._ref.stroke(hex);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getRotation(): number {
|
|
74
|
-
return this._ref.rotation();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
setRotation(degrees: number): void {
|
|
78
|
-
this._ref.rotation(degrees);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
getZIndex(): number {
|
|
82
|
-
return this._ref.zIndex();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
setZIndex(zIndex: number): void {
|
|
86
|
-
this._ref.zIndex(zIndex);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
delete() {
|
|
90
|
-
this._ref.destroy();
|
|
91
|
-
this._ref = null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
getPoints(): number[] {
|
|
95
|
-
return this._ref.points();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
setLineWidth(size: number) {
|
|
99
|
-
this._ref.strokeWidth(size);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
getLineWidth(): number {
|
|
103
|
-
return this._ref.strokeWidth();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
getLineType(): string {
|
|
107
|
-
const typeSpecs = this._ref.dash() || [];
|
|
108
|
-
let type: MarkupLineType;
|
|
109
|
-
switch (typeSpecs) {
|
|
110
|
-
case LineTypeSpecs.get("dot"):
|
|
111
|
-
type = "dot";
|
|
112
|
-
break;
|
|
113
|
-
case LineTypeSpecs.get("dash"):
|
|
114
|
-
type = "dash";
|
|
115
|
-
break;
|
|
116
|
-
default:
|
|
117
|
-
type = "solid";
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
return type;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
setLineType(type: string) {
|
|
124
|
-
const specs = LineTypeSpecs.get(type);
|
|
125
|
-
if (specs) this._ref.dash(specs);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
addPoints(points: [{ x: number; y: number }]) {
|
|
129
|
-
let newPoints = this._ref.points();
|
|
130
|
-
points.forEach((point) => {
|
|
131
|
-
newPoints = newPoints.concat([point.x, point.y]);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
this._ref.points(newPoints);
|
|
135
|
-
}
|
|
136
|
-
}
|