konva 10.3.2 → 10.4.0
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/README.md +5 -1
- package/konva.js +1327 -1572
- package/konva.min.js +4 -4
- package/lib/Animation.d.ts +63 -3
- package/lib/Animation.js +86 -65
- package/lib/BezierFunctions.d.ts +10 -0
- package/lib/BezierFunctions.js +32 -0
- package/lib/Canvas.d.ts +53 -0
- package/lib/Canvas.js +93 -34
- package/lib/Container.d.ts +156 -9
- package/lib/Container.js +260 -25
- package/lib/Context.d.ts +247 -0
- package/lib/Context.js +312 -74
- package/lib/Core.js +1 -0
- package/lib/DragAndDrop.d.ts +1 -0
- package/lib/DragAndDrop.js +66 -17
- package/lib/Factory.d.ts +24 -1
- package/lib/Factory.js +14 -20
- package/lib/FastLayer.d.ts +14 -1
- package/lib/FastLayer.js +14 -1
- package/lib/Global.d.ts +114 -3
- package/lib/Global.js +134 -5
- package/lib/Group.d.ts +11 -0
- package/lib/Group.js +11 -0
- package/lib/Layer.d.ts +128 -3
- package/lib/Layer.js +260 -49
- package/lib/Node.d.ts +692 -30
- package/lib/Node.js +1534 -202
- package/lib/PointerEvents.d.ts +2 -1
- package/lib/PointerEvents.js +19 -1
- package/lib/Shape.d.ts +99 -14
- package/lib/Shape.js +1101 -67
- package/lib/Stage.d.ts +81 -1
- package/lib/Stage.js +166 -7
- package/lib/Tween.d.ts +159 -4
- package/lib/Tween.js +243 -24
- package/lib/Util.d.ts +147 -4
- package/lib/Util.js +332 -82
- package/lib/Validators.d.ts +0 -2
- package/lib/Validators.js +3 -25
- package/lib/_CoreInternals.d.ts +10 -6
- package/lib/_CoreInternals.js +1 -0
- package/lib/_FullInternals.d.ts +15 -6
- package/lib/_FullInternals.js +7 -0
- package/lib/canvas-backend.js +6 -0
- package/lib/filters/Blur.d.ts +18 -0
- package/lib/filters/Blur.js +97 -24
- package/lib/filters/Brighten.d.ts +21 -0
- package/lib/filters/Brighten.js +24 -0
- package/lib/filters/Brightness.d.ts +11 -0
- package/lib/filters/Brightness.js +16 -0
- package/lib/filters/Contrast.d.ts +10 -0
- package/lib/filters/Contrast.js +21 -0
- package/lib/filters/Emboss.d.ts +20 -0
- package/lib/filters/Emboss.js +68 -8
- package/lib/filters/Enhance.d.ts +14 -0
- package/lib/filters/Enhance.js +34 -0
- package/lib/filters/Grayscale.d.ts +9 -0
- package/lib/filters/Grayscale.js +12 -0
- package/lib/filters/HSL.d.ts +17 -0
- package/lib/filters/HSL.js +48 -5
- package/lib/filters/HSV.d.ts +18 -0
- package/lib/filters/HSV.js +49 -5
- package/lib/filters/Invert.d.ts +9 -0
- package/lib/filters/Invert.js +12 -0
- package/lib/filters/Kaleidoscope.d.ts +12 -0
- package/lib/filters/Kaleidoscope.js +83 -0
- package/lib/filters/Mask.d.ts +11 -0
- package/lib/filters/Mask.js +18 -0
- package/lib/filters/Noise.d.ts +19 -0
- package/lib/filters/Noise.js +19 -0
- package/lib/filters/Pixelate.d.ts +20 -0
- package/lib/filters/Pixelate.js +28 -1
- package/lib/filters/Posterize.d.ts +21 -0
- package/lib/filters/Posterize.js +22 -0
- package/lib/filters/RGB.d.ts +21 -0
- package/lib/filters/RGB.js +43 -28
- package/lib/filters/RGBA.d.ts +23 -0
- package/lib/filters/RGBA.js +28 -41
- package/lib/filters/Sepia.d.ts +9 -0
- package/lib/filters/Sepia.js +10 -0
- package/lib/filters/Solarize.d.ts +10 -0
- package/lib/filters/Solarize.js +11 -0
- package/lib/filters/Threshold.d.ts +22 -0
- package/lib/filters/Threshold.js +22 -0
- package/lib/shapes/Arc.d.ts +40 -0
- package/lib/shapes/Arc.js +89 -6
- package/lib/shapes/Arrow.d.ts +24 -1
- package/lib/shapes/Arrow.js +83 -0
- package/lib/shapes/Circle.d.ts +18 -0
- package/lib/shapes/Circle.js +36 -9
- package/lib/shapes/Ellipse.d.ts +34 -2
- package/lib/shapes/Ellipse.js +67 -9
- package/lib/shapes/Image.d.ts +49 -0
- package/lib/shapes/Image.js +151 -22
- package/lib/shapes/Label.d.ts +65 -1
- package/lib/shapes/Label.js +113 -20
- package/lib/shapes/Line.d.ts +50 -8
- package/lib/shapes/Line.js +116 -20
- package/lib/shapes/Path.d.ts +40 -6
- package/lib/shapes/Path.js +187 -128
- package/lib/shapes/Rect.d.ts +18 -0
- package/lib/shapes/Rect.js +36 -0
- package/lib/shapes/RegularPolygon.d.ts +22 -0
- package/lib/shapes/RegularPolygon.js +70 -0
- package/lib/shapes/Ring.d.ts +19 -0
- package/lib/shapes/Ring.js +51 -5
- package/lib/shapes/Sprite.d.ts +78 -0
- package/lib/shapes/Sprite.js +238 -25
- package/lib/shapes/Star.d.ts +23 -0
- package/lib/shapes/Star.js +62 -0
- package/lib/shapes/Text.d.ts +59 -1
- package/lib/shapes/Text.js +481 -97
- package/lib/shapes/TextPath.d.ts +49 -3
- package/lib/shapes/TextPath.js +278 -34
- package/lib/shapes/Transformer.d.ts +108 -11
- package/lib/shapes/Transformer.js +744 -102
- package/lib/shapes/Wedge.d.ts +22 -0
- package/lib/shapes/Wedge.js +67 -3
- package/lib/skia-backend.js +9 -0
- package/lib/types.d.ts +2 -23
- package/lib/types.js +1 -21
- package/package.json +24 -21
package/lib/shapes/Image.d.ts
CHANGED
|
@@ -7,6 +7,29 @@ export interface ImageConfig extends ShapeConfig {
|
|
|
7
7
|
crop?: IRect;
|
|
8
8
|
cornerRadius?: number | number[];
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Image constructor
|
|
12
|
+
* @constructor
|
|
13
|
+
* @memberof Konva
|
|
14
|
+
* @augments Konva.Shape
|
|
15
|
+
* @param {Object} config
|
|
16
|
+
* @param {Image} config.image
|
|
17
|
+
* @param {Object} [config.crop]
|
|
18
|
+
* @@shapeParams
|
|
19
|
+
* @@nodeParams
|
|
20
|
+
* @example
|
|
21
|
+
* var imageObj = new Image();
|
|
22
|
+
* imageObj.onload = function() {
|
|
23
|
+
* var image = new Konva.Image({
|
|
24
|
+
* x: 200,
|
|
25
|
+
* y: 50,
|
|
26
|
+
* image: imageObj,
|
|
27
|
+
* width: 100,
|
|
28
|
+
* height: 100
|
|
29
|
+
* });
|
|
30
|
+
* };
|
|
31
|
+
* imageObj.src = '/path/to/image.jpg'
|
|
32
|
+
*/
|
|
10
33
|
export declare class Image extends Shape<ImageConfig> {
|
|
11
34
|
private _loadListener;
|
|
12
35
|
constructor(attrs?: ImageConfig);
|
|
@@ -18,6 +41,19 @@ export declare class Image extends Shape<ImageConfig> {
|
|
|
18
41
|
_hitFunc(context: Context): void;
|
|
19
42
|
getWidth(): any;
|
|
20
43
|
getHeight(): any;
|
|
44
|
+
/**
|
|
45
|
+
* load image from given url and create `Konva.Image` instance
|
|
46
|
+
* @method
|
|
47
|
+
* @memberof Konva.Image
|
|
48
|
+
* @param {String} url image source
|
|
49
|
+
* @param {Function} callback with Konva.Image instance as first argument
|
|
50
|
+
* @param {Function} onError optional error handler
|
|
51
|
+
* @example
|
|
52
|
+
* Konva.Image.fromURL(imageURL, function(image){
|
|
53
|
+
* // image is Konva.Image instance
|
|
54
|
+
* layer.add(image);
|
|
55
|
+
* });
|
|
56
|
+
*/
|
|
21
57
|
static fromURL(url: string, callback: (img: Image) => void, onError?: OnErrorEventHandler): void;
|
|
22
58
|
image: GetSet<CanvasImageSource | undefined, this>;
|
|
23
59
|
crop: GetSet<IRect, this>;
|
|
@@ -27,3 +63,16 @@ export declare class Image extends Shape<ImageConfig> {
|
|
|
27
63
|
cropHeight: GetSet<number, this>;
|
|
28
64
|
cornerRadius: GetSet<number | number[], this>;
|
|
29
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* get/set crop height
|
|
68
|
+
* @name Konva.Image#cropHeight
|
|
69
|
+
* @method
|
|
70
|
+
* @param {Number} height
|
|
71
|
+
* @returns {Number}
|
|
72
|
+
* @example
|
|
73
|
+
* // get crop height
|
|
74
|
+
* var cropHeight = image.cropHeight();
|
|
75
|
+
*
|
|
76
|
+
* // set crop height
|
|
77
|
+
* image.cropHeight(20);
|
|
78
|
+
*/
|
package/lib/shapes/Image.js
CHANGED
|
@@ -3,6 +3,29 @@ import { Factory } from "../Factory.js";
|
|
|
3
3
|
import { Shape } from "../Shape.js";
|
|
4
4
|
import { _registerNode } from "../Global.js";
|
|
5
5
|
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from "../Validators.js";
|
|
6
|
+
/**
|
|
7
|
+
* Image constructor
|
|
8
|
+
* @constructor
|
|
9
|
+
* @memberof Konva
|
|
10
|
+
* @augments Konva.Shape
|
|
11
|
+
* @param {Object} config
|
|
12
|
+
* @param {Image} config.image
|
|
13
|
+
* @param {Object} [config.crop]
|
|
14
|
+
* @@shapeParams
|
|
15
|
+
* @@nodeParams
|
|
16
|
+
* @example
|
|
17
|
+
* var imageObj = new Image();
|
|
18
|
+
* imageObj.onload = function() {
|
|
19
|
+
* var image = new Konva.Image({
|
|
20
|
+
* x: 200,
|
|
21
|
+
* y: 50,
|
|
22
|
+
* image: imageObj,
|
|
23
|
+
* width: 100,
|
|
24
|
+
* height: 100
|
|
25
|
+
* });
|
|
26
|
+
* };
|
|
27
|
+
* imageObj.src = '/path/to/image.jpg'
|
|
28
|
+
*/
|
|
6
29
|
export class Image extends Shape {
|
|
7
30
|
constructor(attrs) {
|
|
8
31
|
super(attrs);
|
|
@@ -17,9 +40,11 @@ export class Image extends Shape {
|
|
|
17
40
|
}
|
|
18
41
|
_setImageLoad() {
|
|
19
42
|
const image = this.image();
|
|
43
|
+
// check is image is already loaded
|
|
20
44
|
if (image && image.complete) {
|
|
21
45
|
return;
|
|
22
46
|
}
|
|
47
|
+
// check is video is already loaded
|
|
23
48
|
if (image && image.readyState === 4) {
|
|
24
49
|
return;
|
|
25
50
|
}
|
|
@@ -50,27 +75,6 @@ export class Image extends Shape {
|
|
|
50
75
|
const height = this.getHeight();
|
|
51
76
|
const cornerRadius = this.cornerRadius();
|
|
52
77
|
const image = this.attrs.image;
|
|
53
|
-
let params;
|
|
54
|
-
if (image) {
|
|
55
|
-
const cropWidth = this.attrs.cropWidth;
|
|
56
|
-
const cropHeight = this.attrs.cropHeight;
|
|
57
|
-
if (cropWidth && cropHeight) {
|
|
58
|
-
params = [
|
|
59
|
-
image,
|
|
60
|
-
this.cropX(),
|
|
61
|
-
this.cropY(),
|
|
62
|
-
cropWidth,
|
|
63
|
-
cropHeight,
|
|
64
|
-
0,
|
|
65
|
-
0,
|
|
66
|
-
width,
|
|
67
|
-
height,
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
params = [image, 0, 0, width, height];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
78
|
if (this.hasFill() || this.hasStroke() || cornerRadius) {
|
|
75
79
|
context.beginPath();
|
|
76
80
|
cornerRadius
|
|
@@ -83,8 +87,16 @@ export class Image extends Shape {
|
|
|
83
87
|
if (cornerRadius) {
|
|
84
88
|
context.clip();
|
|
85
89
|
}
|
|
86
|
-
|
|
90
|
+
const cropWidth = this.attrs.cropWidth;
|
|
91
|
+
const cropHeight = this.attrs.cropHeight;
|
|
92
|
+
if (cropWidth && cropHeight) {
|
|
93
|
+
context.drawImage(image, this.cropX(), this.cropY(), cropWidth, cropHeight, 0, 0, width, height);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
context.drawImage(image, 0, 0, width, height);
|
|
97
|
+
}
|
|
87
98
|
}
|
|
99
|
+
// If you need to draw later, you need to execute save/restore
|
|
88
100
|
}
|
|
89
101
|
_hitFunc(context) {
|
|
90
102
|
const width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
|
|
@@ -106,6 +118,19 @@ export class Image extends Shape {
|
|
|
106
118
|
var _a, _b, _c;
|
|
107
119
|
return (_c = (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height) !== null && _c !== void 0 ? _c : 0;
|
|
108
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* load image from given url and create `Konva.Image` instance
|
|
123
|
+
* @method
|
|
124
|
+
* @memberof Konva.Image
|
|
125
|
+
* @param {String} url image source
|
|
126
|
+
* @param {Function} callback with Konva.Image instance as first argument
|
|
127
|
+
* @param {Function} onError optional error handler
|
|
128
|
+
* @example
|
|
129
|
+
* Konva.Image.fromURL(imageURL, function(image){
|
|
130
|
+
* // image is Konva.Image instance
|
|
131
|
+
* layer.add(image);
|
|
132
|
+
* });
|
|
133
|
+
*/
|
|
109
134
|
static fromURL(url, callback, onError = null) {
|
|
110
135
|
const img = Util.createImageElement();
|
|
111
136
|
img.onload = function () {
|
|
@@ -122,10 +147,114 @@ export class Image extends Shape {
|
|
|
122
147
|
Image.prototype.className = 'Image';
|
|
123
148
|
Image.prototype._attrsAffectingSize = ['image'];
|
|
124
149
|
_registerNode(Image);
|
|
150
|
+
/**
|
|
151
|
+
* get/set corner radius
|
|
152
|
+
* @method
|
|
153
|
+
* @name Konva.Image#cornerRadius
|
|
154
|
+
* @param {Number} cornerRadius
|
|
155
|
+
* @returns {Number}
|
|
156
|
+
* @example
|
|
157
|
+
* // get corner radius
|
|
158
|
+
* var cornerRadius = image.cornerRadius();
|
|
159
|
+
*
|
|
160
|
+
* // set corner radius
|
|
161
|
+
* image.cornerRadius(10);
|
|
162
|
+
*
|
|
163
|
+
* // set different corner radius values
|
|
164
|
+
* // top-left, top-right, bottom-right, bottom-left
|
|
165
|
+
* image.cornerRadius([0, 10, 20, 30]);
|
|
166
|
+
*/
|
|
125
167
|
Factory.addGetterSetter(Image, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
168
|
+
/**
|
|
169
|
+
* get/set image source. It can be image, canvas or video element
|
|
170
|
+
* @name Konva.Image#image
|
|
171
|
+
* @method
|
|
172
|
+
* @param {Object} image source
|
|
173
|
+
* @returns {Object}
|
|
174
|
+
* @example
|
|
175
|
+
* // get value
|
|
176
|
+
* var image = shape.image();
|
|
177
|
+
*
|
|
178
|
+
* // set value
|
|
179
|
+
* shape.image(img);
|
|
180
|
+
*/
|
|
126
181
|
Factory.addGetterSetter(Image, 'image');
|
|
127
182
|
Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
|
|
183
|
+
/**
|
|
184
|
+
* get/set crop
|
|
185
|
+
* @method
|
|
186
|
+
* @name Konva.Image#crop
|
|
187
|
+
* @param {Object} crop
|
|
188
|
+
* @param {Number} crop.x
|
|
189
|
+
* @param {Number} crop.y
|
|
190
|
+
* @param {Number} crop.width
|
|
191
|
+
* @param {Number} crop.height
|
|
192
|
+
* @returns {Object}
|
|
193
|
+
* @example
|
|
194
|
+
* // get crop
|
|
195
|
+
* var crop = image.crop();
|
|
196
|
+
*
|
|
197
|
+
* // set crop
|
|
198
|
+
* image.crop({
|
|
199
|
+
* x: 20,
|
|
200
|
+
* y: 20,
|
|
201
|
+
* width: 20,
|
|
202
|
+
* height: 20
|
|
203
|
+
* });
|
|
204
|
+
*/
|
|
128
205
|
Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator());
|
|
206
|
+
/**
|
|
207
|
+
* get/set crop x
|
|
208
|
+
* @method
|
|
209
|
+
* @name Konva.Image#cropX
|
|
210
|
+
* @param {Number} x
|
|
211
|
+
* @returns {Number}
|
|
212
|
+
* @example
|
|
213
|
+
* // get crop x
|
|
214
|
+
* var cropX = image.cropX();
|
|
215
|
+
*
|
|
216
|
+
* // set crop x
|
|
217
|
+
* image.cropX(20);
|
|
218
|
+
*/
|
|
129
219
|
Factory.addGetterSetter(Image, 'cropY', 0, getNumberValidator());
|
|
220
|
+
/**
|
|
221
|
+
* get/set crop y
|
|
222
|
+
* @name Konva.Image#cropY
|
|
223
|
+
* @method
|
|
224
|
+
* @param {Number} y
|
|
225
|
+
* @returns {Number}
|
|
226
|
+
* @example
|
|
227
|
+
* // get crop y
|
|
228
|
+
* var cropY = image.cropY();
|
|
229
|
+
*
|
|
230
|
+
* // set crop y
|
|
231
|
+
* image.cropY(20);
|
|
232
|
+
*/
|
|
130
233
|
Factory.addGetterSetter(Image, 'cropWidth', 0, getNumberValidator());
|
|
234
|
+
/**
|
|
235
|
+
* get/set crop width
|
|
236
|
+
* @name Konva.Image#cropWidth
|
|
237
|
+
* @method
|
|
238
|
+
* @param {Number} width
|
|
239
|
+
* @returns {Number}
|
|
240
|
+
* @example
|
|
241
|
+
* // get crop width
|
|
242
|
+
* var cropWidth = image.cropWidth();
|
|
243
|
+
*
|
|
244
|
+
* // set crop width
|
|
245
|
+
* image.cropWidth(20);
|
|
246
|
+
*/
|
|
131
247
|
Factory.addGetterSetter(Image, 'cropHeight', 0, getNumberValidator());
|
|
248
|
+
/**
|
|
249
|
+
* get/set crop height
|
|
250
|
+
* @name Konva.Image#cropHeight
|
|
251
|
+
* @method
|
|
252
|
+
* @param {Number} height
|
|
253
|
+
* @returns {Number}
|
|
254
|
+
* @example
|
|
255
|
+
* // get crop height
|
|
256
|
+
* var cropHeight = image.cropHeight();
|
|
257
|
+
*
|
|
258
|
+
* // set crop height
|
|
259
|
+
* image.cropHeight(20);
|
|
260
|
+
*/
|
package/lib/shapes/Label.d.ts
CHANGED
|
@@ -8,9 +8,61 @@ import type { Text } from './Text.ts';
|
|
|
8
8
|
export interface LabelConfig extends ContainerConfig {
|
|
9
9
|
}
|
|
10
10
|
declare const NONE = "none";
|
|
11
|
+
/**
|
|
12
|
+
* Label constructor. Labels are groups that contain a Text and Tag shape
|
|
13
|
+
* @constructor
|
|
14
|
+
* @memberof Konva
|
|
15
|
+
* @param {Object} config
|
|
16
|
+
* @@nodeParams
|
|
17
|
+
* @example
|
|
18
|
+
* // create label
|
|
19
|
+
* var label = new Konva.Label({
|
|
20
|
+
* x: 100,
|
|
21
|
+
* y: 100,
|
|
22
|
+
* draggable: true
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // add a tag to the label
|
|
26
|
+
* label.add(new Konva.Tag({
|
|
27
|
+
* fill: '#bbb',
|
|
28
|
+
* stroke: '#333',
|
|
29
|
+
* shadowColor: 'black',
|
|
30
|
+
* shadowBlur: 10,
|
|
31
|
+
* shadowOffset: [10, 10],
|
|
32
|
+
* shadowOpacity: 0.2,
|
|
33
|
+
* lineJoin: 'round',
|
|
34
|
+
* pointerDirection: 'up',
|
|
35
|
+
* pointerWidth: 20,
|
|
36
|
+
* pointerHeight: 20,
|
|
37
|
+
* cornerRadius: 5
|
|
38
|
+
* }));
|
|
39
|
+
*
|
|
40
|
+
* // add text to the label
|
|
41
|
+
* label.add(new Konva.Text({
|
|
42
|
+
* text: 'Hello World!',
|
|
43
|
+
* fontSize: 50,
|
|
44
|
+
* lineHeight: 1.2,
|
|
45
|
+
* padding: 10,
|
|
46
|
+
* fill: 'green'
|
|
47
|
+
* }));
|
|
48
|
+
*/
|
|
11
49
|
export declare class Label extends Group {
|
|
12
50
|
constructor(config?: LabelConfig);
|
|
51
|
+
/**
|
|
52
|
+
* get Text shape for the label. You need to access the Text shape in order to update
|
|
53
|
+
* the text properties
|
|
54
|
+
* @name Konva.Label#getText
|
|
55
|
+
* @method
|
|
56
|
+
* @example
|
|
57
|
+
* label.getText().fill('red')
|
|
58
|
+
*/
|
|
13
59
|
getText(): Text;
|
|
60
|
+
/**
|
|
61
|
+
* get Tag shape for the label. You need to access the Tag shape in order to update
|
|
62
|
+
* the pointer properties and the corner radius
|
|
63
|
+
* @name Konva.Label#getTag
|
|
64
|
+
* @method
|
|
65
|
+
*/
|
|
14
66
|
getTag(): Tag;
|
|
15
67
|
_addListeners(text: any): void;
|
|
16
68
|
getWidth(): number;
|
|
@@ -23,6 +75,18 @@ export interface TagConfig extends ShapeConfig {
|
|
|
23
75
|
pointerHeight?: number;
|
|
24
76
|
cornerRadius?: number | Array<number>;
|
|
25
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Tag constructor. A Tag can be configured
|
|
80
|
+
* to have a pointer element that points up, right, down, or left
|
|
81
|
+
* @constructor
|
|
82
|
+
* @memberof Konva
|
|
83
|
+
* @param {Object} config
|
|
84
|
+
* @param {String} [config.pointerDirection] can be up, right, down, left, or none; the default
|
|
85
|
+
* is none. When a pointer is present, the positioning of the label is relative to the tip of the pointer.
|
|
86
|
+
* @param {Number} [config.pointerWidth]
|
|
87
|
+
* @param {Number} [config.pointerHeight]
|
|
88
|
+
* @param {Number} [config.cornerRadius]
|
|
89
|
+
*/
|
|
26
90
|
export declare class Tag extends Shape<TagConfig> {
|
|
27
91
|
_sceneFunc(context: Context): void;
|
|
28
92
|
getSelfRect(): {
|
|
@@ -34,6 +98,6 @@ export declare class Tag extends Shape<TagConfig> {
|
|
|
34
98
|
pointerDirection: GetSet<'left' | 'up' | 'right' | 'down' | typeof NONE, this>;
|
|
35
99
|
pointerWidth: GetSet<number, this>;
|
|
36
100
|
pointerHeight: GetSet<number, this>;
|
|
37
|
-
cornerRadius: GetSet<number, this>;
|
|
101
|
+
cornerRadius: GetSet<number | number[], this>;
|
|
38
102
|
}
|
|
39
103
|
export {};
|
package/lib/shapes/Label.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Util } from "../Util.js";
|
|
2
3
|
import { Shape } from "../Shape.js";
|
|
3
4
|
import { Group } from "../Group.js";
|
|
4
5
|
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from "../Validators.js";
|
|
5
6
|
import { _registerNode } from "../Global.js";
|
|
7
|
+
// constants
|
|
6
8
|
const ATTR_CHANGE_LIST = [
|
|
7
9
|
'fontFamily',
|
|
8
10
|
'fontSize',
|
|
@@ -15,7 +17,47 @@ const ATTR_CHANGE_LIST = [
|
|
|
15
17
|
'pointerDirection',
|
|
16
18
|
'pointerWidth',
|
|
17
19
|
'pointerHeight',
|
|
18
|
-
], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left',
|
|
20
|
+
], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left',
|
|
21
|
+
// cached variables
|
|
22
|
+
attrChangeListLen = ATTR_CHANGE_LIST.length;
|
|
23
|
+
/**
|
|
24
|
+
* Label constructor. Labels are groups that contain a Text and Tag shape
|
|
25
|
+
* @constructor
|
|
26
|
+
* @memberof Konva
|
|
27
|
+
* @param {Object} config
|
|
28
|
+
* @@nodeParams
|
|
29
|
+
* @example
|
|
30
|
+
* // create label
|
|
31
|
+
* var label = new Konva.Label({
|
|
32
|
+
* x: 100,
|
|
33
|
+
* y: 100,
|
|
34
|
+
* draggable: true
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // add a tag to the label
|
|
38
|
+
* label.add(new Konva.Tag({
|
|
39
|
+
* fill: '#bbb',
|
|
40
|
+
* stroke: '#333',
|
|
41
|
+
* shadowColor: 'black',
|
|
42
|
+
* shadowBlur: 10,
|
|
43
|
+
* shadowOffset: [10, 10],
|
|
44
|
+
* shadowOpacity: 0.2,
|
|
45
|
+
* lineJoin: 'round',
|
|
46
|
+
* pointerDirection: 'up',
|
|
47
|
+
* pointerWidth: 20,
|
|
48
|
+
* pointerHeight: 20,
|
|
49
|
+
* cornerRadius: 5
|
|
50
|
+
* }));
|
|
51
|
+
*
|
|
52
|
+
* // add text to the label
|
|
53
|
+
* label.add(new Konva.Text({
|
|
54
|
+
* text: 'Hello World!',
|
|
55
|
+
* fontSize: 50,
|
|
56
|
+
* lineHeight: 1.2,
|
|
57
|
+
* padding: 10,
|
|
58
|
+
* fill: 'green'
|
|
59
|
+
* }));
|
|
60
|
+
*/
|
|
19
61
|
export class Label extends Group {
|
|
20
62
|
constructor(config) {
|
|
21
63
|
super(config);
|
|
@@ -24,9 +66,23 @@ export class Label extends Group {
|
|
|
24
66
|
this._sync();
|
|
25
67
|
});
|
|
26
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* get Text shape for the label. You need to access the Text shape in order to update
|
|
71
|
+
* the text properties
|
|
72
|
+
* @name Konva.Label#getText
|
|
73
|
+
* @method
|
|
74
|
+
* @example
|
|
75
|
+
* label.getText().fill('red')
|
|
76
|
+
*/
|
|
27
77
|
getText() {
|
|
28
78
|
return this.find('Text')[0];
|
|
29
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* get Tag shape for the label. You need to access the Tag shape in order to update
|
|
82
|
+
* the pointer properties and the corner radius
|
|
83
|
+
* @name Konva.Label#getTag
|
|
84
|
+
* @method
|
|
85
|
+
*/
|
|
30
86
|
getTag() {
|
|
31
87
|
return this.find('Tag')[0];
|
|
32
88
|
}
|
|
@@ -35,6 +91,7 @@ export class Label extends Group {
|
|
|
35
91
|
const func = function () {
|
|
36
92
|
that._sync();
|
|
37
93
|
};
|
|
94
|
+
// update text data for certain attr changes
|
|
38
95
|
for (n = 0; n < attrChangeListLen; n++) {
|
|
39
96
|
text.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, func);
|
|
40
97
|
}
|
|
@@ -88,26 +145,22 @@ export class Label extends Group {
|
|
|
88
145
|
}
|
|
89
146
|
Label.prototype.className = 'Label';
|
|
90
147
|
_registerNode(Label);
|
|
148
|
+
/**
|
|
149
|
+
* Tag constructor. A Tag can be configured
|
|
150
|
+
* to have a pointer element that points up, right, down, or left
|
|
151
|
+
* @constructor
|
|
152
|
+
* @memberof Konva
|
|
153
|
+
* @param {Object} config
|
|
154
|
+
* @param {String} [config.pointerDirection] can be up, right, down, left, or none; the default
|
|
155
|
+
* is none. When a pointer is present, the positioning of the label is relative to the tip of the pointer.
|
|
156
|
+
* @param {Number} [config.pointerWidth]
|
|
157
|
+
* @param {Number} [config.pointerHeight]
|
|
158
|
+
* @param {Number} [config.cornerRadius]
|
|
159
|
+
*/
|
|
91
160
|
export class Tag extends Shape {
|
|
92
161
|
_sceneFunc(context) {
|
|
93
162
|
const width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
|
|
94
|
-
|
|
95
|
-
let topRight = 0;
|
|
96
|
-
let bottomLeft = 0;
|
|
97
|
-
let bottomRight = 0;
|
|
98
|
-
if (typeof cornerRadius === 'number') {
|
|
99
|
-
topLeft =
|
|
100
|
-
topRight =
|
|
101
|
-
bottomLeft =
|
|
102
|
-
bottomRight =
|
|
103
|
-
Math.min(cornerRadius, width / 2, height / 2);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
|
107
|
-
topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
|
108
|
-
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
|
109
|
-
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
|
110
|
-
}
|
|
163
|
+
const [topLeft, topRight, bottomRight, bottomLeft] = Util._cornerRadii(cornerRadius, width, height);
|
|
111
164
|
context.beginPath();
|
|
112
165
|
context.moveTo(topLeft, 0);
|
|
113
166
|
if (pointerDirection === UP) {
|
|
@@ -151,11 +204,11 @@ export class Tag extends Shape {
|
|
|
151
204
|
height += pointerHeight;
|
|
152
205
|
}
|
|
153
206
|
else if (direction === LEFT) {
|
|
154
|
-
x -= pointerWidth
|
|
207
|
+
x -= pointerWidth;
|
|
155
208
|
width += pointerWidth;
|
|
156
209
|
}
|
|
157
210
|
else if (direction === RIGHT) {
|
|
158
|
-
width += pointerWidth
|
|
211
|
+
width += pointerWidth;
|
|
159
212
|
}
|
|
160
213
|
return {
|
|
161
214
|
x: x,
|
|
@@ -167,7 +220,47 @@ export class Tag extends Shape {
|
|
|
167
220
|
}
|
|
168
221
|
Tag.prototype.className = 'Tag';
|
|
169
222
|
_registerNode(Tag);
|
|
223
|
+
/**
|
|
224
|
+
* get/set pointer direction
|
|
225
|
+
* @name Konva.Tag#pointerDirection
|
|
226
|
+
* @method
|
|
227
|
+
* @param {String} pointerDirection can be up, right, down, left, or none. The default is none.
|
|
228
|
+
* @returns {String}
|
|
229
|
+
* @example
|
|
230
|
+
* tag.pointerDirection('right');
|
|
231
|
+
*/
|
|
170
232
|
Factory.addGetterSetter(Tag, 'pointerDirection', NONE);
|
|
233
|
+
/**
|
|
234
|
+
* get/set pointer width
|
|
235
|
+
* @name Konva.Tag#pointerWidth
|
|
236
|
+
* @method
|
|
237
|
+
* @param {Number} pointerWidth
|
|
238
|
+
* @returns {Number}
|
|
239
|
+
* @example
|
|
240
|
+
* tag.pointerWidth(20);
|
|
241
|
+
*/
|
|
171
242
|
Factory.addGetterSetter(Tag, 'pointerWidth', 0, getNumberValidator());
|
|
243
|
+
/**
|
|
244
|
+
* get/set pointer height
|
|
245
|
+
* @method
|
|
246
|
+
* @name Konva.Tag#pointerHeight
|
|
247
|
+
* @param {Number} pointerHeight
|
|
248
|
+
* @returns {Number}
|
|
249
|
+
* @example
|
|
250
|
+
* tag.pointerHeight(20);
|
|
251
|
+
*/
|
|
172
252
|
Factory.addGetterSetter(Tag, 'pointerHeight', 0, getNumberValidator());
|
|
253
|
+
/**
|
|
254
|
+
* get/set cornerRadius
|
|
255
|
+
* @name Konva.Tag#cornerRadius
|
|
256
|
+
* @method
|
|
257
|
+
* @param {Number} cornerRadius
|
|
258
|
+
* @returns {Number}
|
|
259
|
+
* @example
|
|
260
|
+
* tag.cornerRadius(20);
|
|
261
|
+
*
|
|
262
|
+
* // set different corner radius values
|
|
263
|
+
* // top-left, top-right, bottom-right, bottom-left
|
|
264
|
+
* tag.cornerRadius([0, 10, 20, 30]);
|
|
265
|
+
*/
|
|
173
266
|
Factory.addGetterSetter(Tag, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
package/lib/shapes/Line.d.ts
CHANGED
|
@@ -2,15 +2,46 @@ import type { ShapeConfig } from '../Shape.ts';
|
|
|
2
2
|
import { Shape } from '../Shape.ts';
|
|
3
3
|
import type { Context } from '../Context.ts';
|
|
4
4
|
import type { GetSet } from '../types.ts';
|
|
5
|
+
export type LinePoints = number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
|
5
6
|
export interface LineConfig extends ShapeConfig {
|
|
6
|
-
points?:
|
|
7
|
+
points?: LinePoints;
|
|
7
8
|
tension?: number;
|
|
8
9
|
closed?: boolean;
|
|
9
10
|
bezier?: boolean;
|
|
10
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Line constructor. Lines are defined by an array of points and
|
|
14
|
+
* a tension
|
|
15
|
+
* @constructor
|
|
16
|
+
* @memberof Konva
|
|
17
|
+
* @augments Konva.Shape
|
|
18
|
+
* @param {Object} config
|
|
19
|
+
* @param {Array} config.points Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].
|
|
20
|
+
* @param {Number} [config.tension] Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
|
|
21
|
+
* The default is 0
|
|
22
|
+
* @param {Boolean} [config.closed] defines whether or not the line shape is closed, creating a polygon or blob
|
|
23
|
+
* @param {Boolean} [config.bezier] if no tension is provided but bezier=true, we draw the line as a bezier using the passed points
|
|
24
|
+
* @@shapeParams
|
|
25
|
+
* @@nodeParams
|
|
26
|
+
* @example
|
|
27
|
+
* var line = new Konva.Line({
|
|
28
|
+
* x: 100,
|
|
29
|
+
* y: 50,
|
|
30
|
+
* points: [73, 70, 340, 23, 450, 60, 500, 20],
|
|
31
|
+
* stroke: 'red',
|
|
32
|
+
* tension: 1
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
11
35
|
export declare class Line<Config extends LineConfig = LineConfig> extends Shape<Config> {
|
|
12
36
|
constructor(config?: Config);
|
|
13
37
|
_hasTension(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Report every curve segment of a line with a tension, in draw order. Both
|
|
40
|
+
* the scene function and the bounding rect read the shape through this, so
|
|
41
|
+
* that they can not disagree about which curve the line is.
|
|
42
|
+
*
|
|
43
|
+
* The handlers take plain numbers, because this runs on every frame.
|
|
44
|
+
*/
|
|
14
45
|
_eachTensionSegment(onQuadratic: (x0: number, y0: number, cpx: number, cpy: number, x: number, y: number) => void, onCubic: (x0: number, y0: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number) => void): void;
|
|
15
46
|
_sceneFunc(context: Context): void;
|
|
16
47
|
getTensionPoints(): any;
|
|
@@ -18,14 +49,25 @@ export declare class Line<Config extends LineConfig = LineConfig> extends Shape<
|
|
|
18
49
|
_getTensionPointsClosed(): number[];
|
|
19
50
|
getWidth(): number;
|
|
20
51
|
getHeight(): number;
|
|
21
|
-
getSelfRect():
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
width: number;
|
|
25
|
-
height: number;
|
|
26
|
-
};
|
|
52
|
+
getSelfRect(): import("../types.ts").IRect;
|
|
27
53
|
closed: GetSet<boolean, this>;
|
|
28
54
|
bezier: GetSet<boolean, this>;
|
|
29
55
|
tension: GetSet<number, this>;
|
|
30
|
-
points: GetSet<number[], this>;
|
|
56
|
+
points: GetSet<number[], this, LinePoints>;
|
|
31
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* get/set points array. Points is a flat array [x1, y1, x2, y2]. It is flat for performance reasons.
|
|
60
|
+
* @name Konva.Line#points
|
|
61
|
+
* @method
|
|
62
|
+
* @param {Array} points
|
|
63
|
+
* @returns {Array}
|
|
64
|
+
* @example
|
|
65
|
+
* // get points
|
|
66
|
+
* var points = line.points();
|
|
67
|
+
*
|
|
68
|
+
* // set points
|
|
69
|
+
* line.points([10, 20, 30, 40, 50, 60]);
|
|
70
|
+
*
|
|
71
|
+
* // push a new point
|
|
72
|
+
* line.points(line.points().concat([70, 80]));
|
|
73
|
+
*/
|