@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,150 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
}
|