@inweb/markup 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/LICENSE +20 -0
- package/README.md +7 -0
- package/dist/markup.js +13390 -0
- package/dist/markup.js.map +1 -0
- package/dist/markup.min.js +1 -0
- package/dist/markup.module.js +1838 -0
- package/dist/markup.module.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/markup/IMarkup.d.ts +130 -0
- package/lib/markup/IMarkupArrow.d.ts +52 -0
- package/lib/markup/IMarkupCloud.d.ts +50 -0
- package/lib/markup/IMarkupColorable.d.ts +15 -0
- package/lib/markup/IMarkupEllipse.d.ts +50 -0
- package/lib/markup/IMarkupImage.d.ts +50 -0
- package/lib/markup/IMarkupLine.d.ts +43 -0
- package/lib/markup/IMarkupObject.d.ts +47 -0
- package/lib/markup/IMarkupRectangle.d.ts +50 -0
- package/lib/markup/IMarkupText.d.ts +40 -0
- package/lib/markup/IWorldTransform.d.ts +39 -0
- package/lib/markup/Konva/KonvaArrow.d.ts +46 -0
- package/lib/markup/Konva/KonvaCloud.d.ts +35 -0
- package/lib/markup/Konva/KonvaEllipse.d.ts +40 -0
- package/lib/markup/Konva/KonvaImage.d.ts +36 -0
- package/lib/markup/Konva/KonvaLine.d.ts +35 -0
- package/lib/markup/Konva/KonvaMarkup.d.ts +82 -0
- package/lib/markup/Konva/KonvaRectangle.d.ts +38 -0
- package/lib/markup/Konva/KonvaText.d.ts +37 -0
- package/lib/markup/Konva/MarkupColor.d.ts +38 -0
- package/package.json +40 -0
- package/src/index.ts +35 -0
- package/src/markup/IMarkup.ts +173 -0
- package/src/markup/IMarkupArrow.ts +69 -0
- package/src/markup/IMarkupCloud.ts +78 -0
- package/src/markup/IMarkupColorable.ts +39 -0
- package/src/markup/IMarkupEllipse.ts +78 -0
- package/src/markup/IMarkupImage.ts +78 -0
- package/src/markup/IMarkupLine.ts +70 -0
- package/src/markup/IMarkupObject.ts +78 -0
- package/src/markup/IMarkupRectangle.ts +78 -0
- package/src/markup/IMarkupText.ts +66 -0
- package/src/markup/IWorldTransform.ts +46 -0
- package/src/markup/Konva/KonvaArrow.ts +147 -0
- package/src/markup/Konva/KonvaCloud.ts +213 -0
- package/src/markup/Konva/KonvaEllipse.ts +150 -0
- package/src/markup/Konva/KonvaImage.ts +149 -0
- package/src/markup/Konva/KonvaLine.ts +136 -0
- package/src/markup/Konva/KonvaMarkup.ts +1264 -0
- package/src/markup/Konva/KonvaRectangle.ts +149 -0
- package/src/markup/Konva/KonvaText.ts +141 -0
- package/src/markup/Konva/MarkupColor.ts +82 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Markup object
|
|
26
|
+
*/
|
|
27
|
+
export interface IMarkupObject {
|
|
28
|
+
/**
|
|
29
|
+
* Link to Library object (Konva, VisualizeJS)
|
|
30
|
+
*/
|
|
31
|
+
ref(): any;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get an internal identificator of the object. Not unique
|
|
35
|
+
*/
|
|
36
|
+
id(): string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Set Mouse editing feature
|
|
40
|
+
*
|
|
41
|
+
* @param value true / false
|
|
42
|
+
*/
|
|
43
|
+
enableMouseEditing(value: boolean);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get type of the Markup object
|
|
47
|
+
*/
|
|
48
|
+
type(): string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get rotation of the Markup object
|
|
52
|
+
*/
|
|
53
|
+
getRotation(): number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Set rotation of the Markup object
|
|
57
|
+
*
|
|
58
|
+
* @param degrees number of degress to rotate
|
|
59
|
+
*/
|
|
60
|
+
setRotation(degrees: number): void;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get Z-Index of the Markup object
|
|
64
|
+
*/
|
|
65
|
+
getZIndex(): number;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Set Z-Index of the Markup object
|
|
69
|
+
*
|
|
70
|
+
* @param zIndex integer value of Z-Index
|
|
71
|
+
*/
|
|
72
|
+
setZIndex(zIndex: number): void;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Delete current Markup object
|
|
76
|
+
*/
|
|
77
|
+
delete(): void;
|
|
78
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { IMarkupObject } from "./IMarkupObject";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Rectangle Markup object
|
|
28
|
+
*/
|
|
29
|
+
export interface IMarkupRectangle extends IMarkupObject {
|
|
30
|
+
/**
|
|
31
|
+
* Get position of the Rectangle
|
|
32
|
+
*/
|
|
33
|
+
getPosition(): { x: number; y: number };
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Set position of the Rectangle
|
|
37
|
+
*
|
|
38
|
+
* @param x - value of X coordinate
|
|
39
|
+
* @param y - value of Y coordinate
|
|
40
|
+
*/
|
|
41
|
+
setPosition(x: number, y: number);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get width of the Rectangle. Default value is 200
|
|
45
|
+
*/
|
|
46
|
+
getWidth(): number;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Set width of the Rectangle
|
|
50
|
+
*
|
|
51
|
+
* @param w - value of width. Default value is 200
|
|
52
|
+
*/
|
|
53
|
+
setWidth(w: number);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get height of the Rectangle. Default value is 200
|
|
57
|
+
*/
|
|
58
|
+
getHeigth(): number;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Set height of the Rectangle
|
|
62
|
+
*
|
|
63
|
+
* @param h - value of height. Default value is 200
|
|
64
|
+
*/
|
|
65
|
+
setHeight(h: number);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get line width of the Rectangle. Defailt value is 4
|
|
69
|
+
*/
|
|
70
|
+
getLineWidth(): number;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Set line width of the Rectangle
|
|
74
|
+
*
|
|
75
|
+
* @param size - value of width. Defailt value is 4
|
|
76
|
+
*/
|
|
77
|
+
setLineWidth(size: number);
|
|
78
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { IMarkupObject } from "./IMarkupObject";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Text Markup object
|
|
28
|
+
*/
|
|
29
|
+
export interface IMarkupText extends IMarkupObject {
|
|
30
|
+
/**
|
|
31
|
+
* Get Text value
|
|
32
|
+
*/
|
|
33
|
+
getText(): string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Set Text value
|
|
37
|
+
*
|
|
38
|
+
* @param text - string value
|
|
39
|
+
*/
|
|
40
|
+
setText(text: string): void;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get position of the Text
|
|
44
|
+
*/
|
|
45
|
+
getPosition(): { x: number; y: number };
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Set position of the Text
|
|
49
|
+
*
|
|
50
|
+
* @param x - value of X coordinate
|
|
51
|
+
* @param y - value of Y coordinate
|
|
52
|
+
*/
|
|
53
|
+
setPosition(x: number, y: number);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get font size. Default value is 34
|
|
57
|
+
*/
|
|
58
|
+
getFontSize();
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Set font size. Default value is 34
|
|
62
|
+
*
|
|
63
|
+
* @param size
|
|
64
|
+
*/
|
|
65
|
+
setFontSize(size: number);
|
|
66
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Viewer coordiate system transformer.
|
|
26
|
+
*/
|
|
27
|
+
export interface IWorldTransform {
|
|
28
|
+
/**
|
|
29
|
+
* Transforms `position` from screen space into world space.
|
|
30
|
+
*
|
|
31
|
+
* @param position - screen position in pixels.
|
|
32
|
+
*/
|
|
33
|
+
screenToWorld(position: { x: number; y: number }): { x: number; y: number; z: number };
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Transforms `position` from world space into screen space.
|
|
37
|
+
*
|
|
38
|
+
* @param position - position in world space coordinates.
|
|
39
|
+
*/
|
|
40
|
+
worldToScreen(position: { x: number; y: number; z: number }): { x: number; y: number };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the scaling factors for each axis in world space.
|
|
44
|
+
*/
|
|
45
|
+
getScale(): { x: number; y: number; z: number };
|
|
46
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import Konva from "konva";
|
|
25
|
+
import { IMarkupArrow } from "../IMarkupArrow";
|
|
26
|
+
import { IMarkupColorable } from "../IMarkupColorable";
|
|
27
|
+
|
|
28
|
+
export class KonvaArrow implements IMarkupArrow, IMarkupColorable {
|
|
29
|
+
private _ref: Konva.Arrow;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
params: {
|
|
33
|
+
start: { x: number; y: number };
|
|
34
|
+
end: { x: number; y: number };
|
|
35
|
+
color?: string;
|
|
36
|
+
id?: string;
|
|
37
|
+
},
|
|
38
|
+
ref = null
|
|
39
|
+
) {
|
|
40
|
+
if (ref) {
|
|
41
|
+
this._ref = ref;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!params.start || !params.end) return;
|
|
46
|
+
|
|
47
|
+
this._ref = new Konva.Arrow({
|
|
48
|
+
stroke: params.color ?? "#ff0000",
|
|
49
|
+
fill: params.color ?? "#ff0000",
|
|
50
|
+
strokeWidth: 4,
|
|
51
|
+
globalCompositeOperation: "source-over",
|
|
52
|
+
lineCap: "round",
|
|
53
|
+
lineJoin: "round",
|
|
54
|
+
points: [params.start.x, params.start.y, params.end.x, params.end.y],
|
|
55
|
+
draggable: true,
|
|
56
|
+
strokeScaleEnabled: false,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this._ref.on("transform", (e) => {
|
|
60
|
+
const attrs = e.target.attrs;
|
|
61
|
+
|
|
62
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
this._ref.id(this._ref._id.toString());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
ref() {
|
|
69
|
+
return this._ref;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
id(): string {
|
|
73
|
+
return this._ref.id();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
enableMouseEditing(value: boolean) {
|
|
77
|
+
this._ref.draggable(value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type(): string {
|
|
81
|
+
return "arrow";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getColor(): string {
|
|
85
|
+
return this._ref.stroke() as string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setColor(hex: string) {
|
|
89
|
+
this._ref.stroke(hex);
|
|
90
|
+
this._ref.fill(hex);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getRotation(): number {
|
|
94
|
+
return this._ref.rotation();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setRotation(degrees: number): void {
|
|
98
|
+
this._ref.rotation(degrees);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getZIndex(): number {
|
|
102
|
+
return this._ref.zIndex();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
setZIndex(zIndex: number): void {
|
|
106
|
+
this._ref.zIndex(zIndex);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
delete() {
|
|
110
|
+
this._ref.destroy();
|
|
111
|
+
this._ref = null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getPoints(): { x: number; y: number }[] {
|
|
115
|
+
const points = this._ref.points();
|
|
116
|
+
return [
|
|
117
|
+
{ x: points[0], y: points[1] },
|
|
118
|
+
{ x: points[2], y: points[3] },
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setPoints(points: { x: number; y: number }[]) {
|
|
123
|
+
if (points.length === 2) {
|
|
124
|
+
this._ref.points([points[0].x, points[0].y, points[1].x, points[1].y]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
getStartPoint(): { x: number; y: number } {
|
|
129
|
+
const points = this._ref.points();
|
|
130
|
+
return { x: points[0], y: points[1] };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setStartPoint(x: number, y: number) {
|
|
134
|
+
const points = this._ref.points();
|
|
135
|
+
this._ref.points([x, y, points[2], points[3]]);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
getEndPoint(): { x: number; y: number } {
|
|
139
|
+
const points = this._ref.points();
|
|
140
|
+
return { x: points[2], y: points[3] };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
setEndPoint(x: number, y: number) {
|
|
144
|
+
const points = this._ref.points();
|
|
145
|
+
this._ref.points([points[0], points[1], x, y]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
}
|