konva 10.0.8 → 10.0.10
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/konva.js +95 -48
- package/konva.min.js +4 -4
- package/package.json +1 -1
- package/lib/Animation.d.ts +0 -24
- package/lib/Animation.js +0 -142
- package/lib/BezierFunctions.d.ts +0 -6
- package/lib/BezierFunctions.js +0 -784
- package/lib/Canvas.d.ts +0 -33
- package/lib/Canvas.js +0 -137
- package/lib/Container.d.ts +0 -54
- package/lib/Container.js +0 -316
- package/lib/Context.d.ts +0 -95
- package/lib/Context.js +0 -561
- package/lib/Core.d.ts +0 -3
- package/lib/Core.js +0 -3
- package/lib/DragAndDrop.d.ts +0 -17
- package/lib/DragAndDrop.js +0 -110
- package/lib/Factory.d.ts +0 -22
- package/lib/Factory.js +0 -123
- package/lib/FastLayer.d.ts +0 -4
- package/lib/FastLayer.js +0 -12
- package/lib/Global.d.ts +0 -37
- package/lib/Global.js +0 -66
- package/lib/Group.d.ts +0 -9
- package/lib/Group.js +0 -13
- package/lib/Layer.d.ts +0 -62
- package/lib/Layer.js +0 -305
- package/lib/Node.d.ts +0 -323
- package/lib/Node.js +0 -1532
- package/lib/PointerEvents.d.ts +0 -11
- package/lib/PointerEvents.js +0 -37
- package/lib/Shape.d.ts +0 -196
- package/lib/Shape.js +0 -548
- package/lib/Stage.d.ts +0 -86
- package/lib/Stage.js +0 -715
- package/lib/Tween.d.ts +0 -90
- package/lib/Tween.js +0 -531
- package/lib/Util.d.ts +0 -133
- package/lib/Util.js +0 -866
- package/lib/Validators.d.ts +0 -11
- package/lib/Validators.js +0 -178
- package/lib/_CoreInternals.d.ts +0 -220
- package/lib/_CoreInternals.js +0 -34
- package/lib/_FullInternals.d.ts +0 -302
- package/lib/_FullInternals.js +0 -80
- package/lib/canvas-backend.d.ts +0 -2
- package/lib/canvas-backend.js +0 -27
- package/lib/filters/Blur.d.ts +0 -2
- package/lib/filters/Blur.js +0 -235
- package/lib/filters/Brighten.d.ts +0 -2
- package/lib/filters/Brighten.js +0 -12
- package/lib/filters/Brightness.d.ts +0 -2
- package/lib/filters/Brightness.js +0 -8
- package/lib/filters/Contrast.d.ts +0 -2
- package/lib/filters/Contrast.js +0 -35
- package/lib/filters/Emboss.d.ts +0 -2
- package/lib/filters/Emboss.js +0 -101
- package/lib/filters/Enhance.d.ts +0 -2
- package/lib/filters/Enhance.js +0 -84
- package/lib/filters/Grayscale.d.ts +0 -2
- package/lib/filters/Grayscale.js +0 -9
- package/lib/filters/HSL.d.ts +0 -2
- package/lib/filters/HSL.js +0 -24
- package/lib/filters/HSV.d.ts +0 -2
- package/lib/filters/HSV.js +0 -23
- package/lib/filters/Invert.d.ts +0 -2
- package/lib/filters/Invert.js +0 -8
- package/lib/filters/Kaleidoscope.d.ts +0 -2
- package/lib/filters/Kaleidoscope.js +0 -133
- package/lib/filters/Mask.d.ts +0 -2
- package/lib/filters/Mask.js +0 -151
- package/lib/filters/Noise.d.ts +0 -2
- package/lib/filters/Noise.js +0 -12
- package/lib/filters/Pixelate.d.ts +0 -2
- package/lib/filters/Pixelate.js +0 -60
- package/lib/filters/Posterize.d.ts +0 -2
- package/lib/filters/Posterize.js +0 -10
- package/lib/filters/RGB.d.ts +0 -2
- package/lib/filters/RGB.js +0 -38
- package/lib/filters/RGBA.d.ts +0 -2
- package/lib/filters/RGBA.js +0 -49
- package/lib/filters/Sepia.d.ts +0 -2
- package/lib/filters/Sepia.js +0 -11
- package/lib/filters/Solarize.d.ts +0 -2
- package/lib/filters/Solarize.js +0 -14
- package/lib/filters/Threshold.d.ts +0 -2
- package/lib/filters/Threshold.js +0 -10
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/shapes/Arc.d.ts +0 -27
- package/lib/shapes/Arc.js +0 -60
- package/lib/shapes/Arrow.d.ts +0 -27
- package/lib/shapes/Arrow.js +0 -99
- package/lib/shapes/Circle.d.ts +0 -15
- package/lib/shapes/Circle.js +0 -33
- package/lib/shapes/Ellipse.d.ts +0 -18
- package/lib/shapes/Ellipse.js +0 -37
- package/lib/shapes/Image.d.ts +0 -29
- package/lib/shapes/Image.js +0 -131
- package/lib/shapes/Label.d.ts +0 -39
- package/lib/shapes/Label.js +0 -173
- package/lib/shapes/Line.d.ts +0 -29
- package/lib/shapes/Line.js +0 -156
- package/lib/shapes/Path.d.ts +0 -50
- package/lib/shapes/Path.js +0 -670
- package/lib/shapes/Rect.d.ts +0 -11
- package/lib/shapes/Rect.js +0 -22
- package/lib/shapes/RegularPolygon.d.ts +0 -26
- package/lib/shapes/RegularPolygon.js +0 -72
- package/lib/shapes/Ring.d.ts +0 -17
- package/lib/shapes/Ring.js +0 -33
- package/lib/shapes/Sprite.d.ts +0 -32
- package/lib/shapes/Sprite.js +0 -108
- package/lib/shapes/Star.d.ts +0 -19
- package/lib/shapes/Star.js +0 -38
- package/lib/shapes/Text.d.ts +0 -90
- package/lib/shapes/Text.js +0 -460
- package/lib/shapes/TextPath.d.ts +0 -72
- package/lib/shapes/TextPath.js +0 -268
- package/lib/shapes/Transformer.d.ts +0 -130
- package/lib/shapes/Transformer.js +0 -1009
- package/lib/shapes/Wedge.d.ts +0 -19
- package/lib/shapes/Wedge.js +0 -38
- package/lib/skia-backend.d.ts +0 -2
- package/lib/skia-backend.js +0 -24
- package/lib/types.d.ts +0 -56
- package/lib/types.js +0 -21
package/lib/shapes/Image.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { Util } from "../Util.js";
|
|
2
|
-
import { Factory } from "../Factory.js";
|
|
3
|
-
import { Shape } from "../Shape.js";
|
|
4
|
-
import { _registerNode } from "../Global.js";
|
|
5
|
-
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from "../Validators.js";
|
|
6
|
-
export class Image extends Shape {
|
|
7
|
-
constructor(attrs) {
|
|
8
|
-
super(attrs);
|
|
9
|
-
this._loadListener = () => {
|
|
10
|
-
this._requestDraw();
|
|
11
|
-
};
|
|
12
|
-
this.on('imageChange.konva', (props) => {
|
|
13
|
-
this._removeImageLoad(props.oldVal);
|
|
14
|
-
this._setImageLoad();
|
|
15
|
-
});
|
|
16
|
-
this._setImageLoad();
|
|
17
|
-
}
|
|
18
|
-
_setImageLoad() {
|
|
19
|
-
const image = this.image();
|
|
20
|
-
if (image && image.complete) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (image && image.readyState === 4) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (image && image['addEventListener']) {
|
|
27
|
-
image['addEventListener']('load', this._loadListener);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
_removeImageLoad(image) {
|
|
31
|
-
if (image && image['removeEventListener']) {
|
|
32
|
-
image['removeEventListener']('load', this._loadListener);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
destroy() {
|
|
36
|
-
this._removeImageLoad(this.image());
|
|
37
|
-
super.destroy();
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
_useBufferCanvas() {
|
|
41
|
-
const hasCornerRadius = !!this.cornerRadius();
|
|
42
|
-
const hasShadow = this.hasShadow();
|
|
43
|
-
if (hasCornerRadius && hasShadow) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
return super._useBufferCanvas(true);
|
|
47
|
-
}
|
|
48
|
-
_sceneFunc(context) {
|
|
49
|
-
const width = this.getWidth();
|
|
50
|
-
const height = this.getHeight();
|
|
51
|
-
const cornerRadius = this.cornerRadius();
|
|
52
|
-
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
|
-
if (this.hasFill() || this.hasStroke() || cornerRadius) {
|
|
75
|
-
context.beginPath();
|
|
76
|
-
cornerRadius
|
|
77
|
-
? Util.drawRoundedRectPath(context, width, height, cornerRadius)
|
|
78
|
-
: context.rect(0, 0, width, height);
|
|
79
|
-
context.closePath();
|
|
80
|
-
context.fillStrokeShape(this);
|
|
81
|
-
}
|
|
82
|
-
if (image) {
|
|
83
|
-
if (cornerRadius) {
|
|
84
|
-
context.clip();
|
|
85
|
-
}
|
|
86
|
-
context.drawImage.apply(context, params);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
_hitFunc(context) {
|
|
90
|
-
const width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
|
|
91
|
-
context.beginPath();
|
|
92
|
-
if (!cornerRadius) {
|
|
93
|
-
context.rect(0, 0, width, height);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
97
|
-
}
|
|
98
|
-
context.closePath();
|
|
99
|
-
context.fillStrokeShape(this);
|
|
100
|
-
}
|
|
101
|
-
getWidth() {
|
|
102
|
-
var _a, _b, _c;
|
|
103
|
-
return (_c = (_a = this.attrs.width) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0;
|
|
104
|
-
}
|
|
105
|
-
getHeight() {
|
|
106
|
-
var _a, _b, _c;
|
|
107
|
-
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
|
-
}
|
|
109
|
-
static fromURL(url, callback, onError = null) {
|
|
110
|
-
const img = Util.createImageElement();
|
|
111
|
-
img.onload = function () {
|
|
112
|
-
const image = new Image({
|
|
113
|
-
image: img,
|
|
114
|
-
});
|
|
115
|
-
callback(image);
|
|
116
|
-
};
|
|
117
|
-
img.onerror = onError;
|
|
118
|
-
img.crossOrigin = 'Anonymous';
|
|
119
|
-
img.src = url;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
Image.prototype.className = 'Image';
|
|
123
|
-
Image.prototype._attrsAffectingSize = ['image'];
|
|
124
|
-
_registerNode(Image);
|
|
125
|
-
Factory.addGetterSetter(Image, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
126
|
-
Factory.addGetterSetter(Image, 'image');
|
|
127
|
-
Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
|
|
128
|
-
Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator());
|
|
129
|
-
Factory.addGetterSetter(Image, 'cropY', 0, getNumberValidator());
|
|
130
|
-
Factory.addGetterSetter(Image, 'cropWidth', 0, getNumberValidator());
|
|
131
|
-
Factory.addGetterSetter(Image, 'cropHeight', 0, getNumberValidator());
|
package/lib/shapes/Label.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
-
import { Shape } from '../Shape.ts';
|
|
3
|
-
import { Group } from '../Group.ts';
|
|
4
|
-
import type { Context } from '../Context.ts';
|
|
5
|
-
import type { ContainerConfig } from '../Container.ts';
|
|
6
|
-
import type { GetSet } from '../types.ts';
|
|
7
|
-
import type { Text } from './Text.ts';
|
|
8
|
-
export interface LabelConfig extends ContainerConfig {
|
|
9
|
-
}
|
|
10
|
-
declare const NONE = "none";
|
|
11
|
-
export declare class Label extends Group {
|
|
12
|
-
constructor(config?: LabelConfig);
|
|
13
|
-
getText(): Text;
|
|
14
|
-
getTag(): Tag;
|
|
15
|
-
_addListeners(text: any): void;
|
|
16
|
-
getWidth(): number;
|
|
17
|
-
getHeight(): number;
|
|
18
|
-
_sync(): void;
|
|
19
|
-
}
|
|
20
|
-
export interface TagConfig extends ShapeConfig {
|
|
21
|
-
pointerDirection?: string;
|
|
22
|
-
pointerWidth?: number;
|
|
23
|
-
pointerHeight?: number;
|
|
24
|
-
cornerRadius?: number | Array<number>;
|
|
25
|
-
}
|
|
26
|
-
export declare class Tag extends Shape<TagConfig> {
|
|
27
|
-
_sceneFunc(context: Context): void;
|
|
28
|
-
getSelfRect(): {
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
width: number;
|
|
32
|
-
height: number;
|
|
33
|
-
};
|
|
34
|
-
pointerDirection: GetSet<'left' | 'up' | 'right' | 'down' | typeof NONE, this>;
|
|
35
|
-
pointerWidth: GetSet<number, this>;
|
|
36
|
-
pointerHeight: GetSet<number, this>;
|
|
37
|
-
cornerRadius: GetSet<number, this>;
|
|
38
|
-
}
|
|
39
|
-
export {};
|
package/lib/shapes/Label.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { Factory } from "../Factory.js";
|
|
2
|
-
import { Shape } from "../Shape.js";
|
|
3
|
-
import { Group } from "../Group.js";
|
|
4
|
-
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from "../Validators.js";
|
|
5
|
-
import { _registerNode } from "../Global.js";
|
|
6
|
-
const ATTR_CHANGE_LIST = [
|
|
7
|
-
'fontFamily',
|
|
8
|
-
'fontSize',
|
|
9
|
-
'fontStyle',
|
|
10
|
-
'padding',
|
|
11
|
-
'lineHeight',
|
|
12
|
-
'text',
|
|
13
|
-
'width',
|
|
14
|
-
'height',
|
|
15
|
-
'pointerDirection',
|
|
16
|
-
'pointerWidth',
|
|
17
|
-
'pointerHeight',
|
|
18
|
-
], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left', attrChangeListLen = ATTR_CHANGE_LIST.length;
|
|
19
|
-
export class Label extends Group {
|
|
20
|
-
constructor(config) {
|
|
21
|
-
super(config);
|
|
22
|
-
this.on('add.konva', function (evt) {
|
|
23
|
-
this._addListeners(evt.child);
|
|
24
|
-
this._sync();
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
getText() {
|
|
28
|
-
return this.find('Text')[0];
|
|
29
|
-
}
|
|
30
|
-
getTag() {
|
|
31
|
-
return this.find('Tag')[0];
|
|
32
|
-
}
|
|
33
|
-
_addListeners(text) {
|
|
34
|
-
let that = this, n;
|
|
35
|
-
const func = function () {
|
|
36
|
-
that._sync();
|
|
37
|
-
};
|
|
38
|
-
for (n = 0; n < attrChangeListLen; n++) {
|
|
39
|
-
text.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, func);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
getWidth() {
|
|
43
|
-
return this.getText().width();
|
|
44
|
-
}
|
|
45
|
-
getHeight() {
|
|
46
|
-
return this.getText().height();
|
|
47
|
-
}
|
|
48
|
-
_sync() {
|
|
49
|
-
let text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;
|
|
50
|
-
if (text && tag) {
|
|
51
|
-
width = text.width();
|
|
52
|
-
height = text.height();
|
|
53
|
-
pointerDirection = tag.pointerDirection();
|
|
54
|
-
pointerWidth = tag.pointerWidth();
|
|
55
|
-
pointerHeight = tag.pointerHeight();
|
|
56
|
-
x = 0;
|
|
57
|
-
y = 0;
|
|
58
|
-
switch (pointerDirection) {
|
|
59
|
-
case UP:
|
|
60
|
-
x = width / 2;
|
|
61
|
-
y = -1 * pointerHeight;
|
|
62
|
-
break;
|
|
63
|
-
case RIGHT:
|
|
64
|
-
x = width + pointerWidth;
|
|
65
|
-
y = height / 2;
|
|
66
|
-
break;
|
|
67
|
-
case DOWN:
|
|
68
|
-
x = width / 2;
|
|
69
|
-
y = height + pointerHeight;
|
|
70
|
-
break;
|
|
71
|
-
case LEFT:
|
|
72
|
-
x = -1 * pointerWidth;
|
|
73
|
-
y = height / 2;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
tag.setAttrs({
|
|
77
|
-
x: -1 * x,
|
|
78
|
-
y: -1 * y,
|
|
79
|
-
width: width,
|
|
80
|
-
height: height,
|
|
81
|
-
});
|
|
82
|
-
text.setAttrs({
|
|
83
|
-
x: -1 * x,
|
|
84
|
-
y: -1 * y,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
Label.prototype.className = 'Label';
|
|
90
|
-
_registerNode(Label);
|
|
91
|
-
export class Tag extends Shape {
|
|
92
|
-
_sceneFunc(context) {
|
|
93
|
-
const width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
|
|
94
|
-
let topLeft = 0;
|
|
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
|
-
}
|
|
111
|
-
context.beginPath();
|
|
112
|
-
context.moveTo(topLeft, 0);
|
|
113
|
-
if (pointerDirection === UP) {
|
|
114
|
-
context.lineTo((width - pointerWidth) / 2, 0);
|
|
115
|
-
context.lineTo(width / 2, -1 * pointerHeight);
|
|
116
|
-
context.lineTo((width + pointerWidth) / 2, 0);
|
|
117
|
-
}
|
|
118
|
-
context.lineTo(width - topRight, 0);
|
|
119
|
-
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
120
|
-
if (pointerDirection === RIGHT) {
|
|
121
|
-
context.lineTo(width, (height - pointerHeight) / 2);
|
|
122
|
-
context.lineTo(width + pointerWidth, height / 2);
|
|
123
|
-
context.lineTo(width, (height + pointerHeight) / 2);
|
|
124
|
-
}
|
|
125
|
-
context.lineTo(width, height - bottomRight);
|
|
126
|
-
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
127
|
-
if (pointerDirection === DOWN) {
|
|
128
|
-
context.lineTo((width + pointerWidth) / 2, height);
|
|
129
|
-
context.lineTo(width / 2, height + pointerHeight);
|
|
130
|
-
context.lineTo((width - pointerWidth) / 2, height);
|
|
131
|
-
}
|
|
132
|
-
context.lineTo(bottomLeft, height);
|
|
133
|
-
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
134
|
-
if (pointerDirection === LEFT) {
|
|
135
|
-
context.lineTo(0, (height + pointerHeight) / 2);
|
|
136
|
-
context.lineTo(-1 * pointerWidth, height / 2);
|
|
137
|
-
context.lineTo(0, (height - pointerHeight) / 2);
|
|
138
|
-
}
|
|
139
|
-
context.lineTo(0, topLeft);
|
|
140
|
-
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
141
|
-
context.closePath();
|
|
142
|
-
context.fillStrokeShape(this);
|
|
143
|
-
}
|
|
144
|
-
getSelfRect() {
|
|
145
|
-
let x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
|
|
146
|
-
if (direction === UP) {
|
|
147
|
-
y -= pointerHeight;
|
|
148
|
-
height += pointerHeight;
|
|
149
|
-
}
|
|
150
|
-
else if (direction === DOWN) {
|
|
151
|
-
height += pointerHeight;
|
|
152
|
-
}
|
|
153
|
-
else if (direction === LEFT) {
|
|
154
|
-
x -= pointerWidth * 1.5;
|
|
155
|
-
width += pointerWidth;
|
|
156
|
-
}
|
|
157
|
-
else if (direction === RIGHT) {
|
|
158
|
-
width += pointerWidth * 1.5;
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
x: x,
|
|
162
|
-
y: y,
|
|
163
|
-
width: width,
|
|
164
|
-
height: height,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
Tag.prototype.className = 'Tag';
|
|
169
|
-
_registerNode(Tag);
|
|
170
|
-
Factory.addGetterSetter(Tag, 'pointerDirection', NONE);
|
|
171
|
-
Factory.addGetterSetter(Tag, 'pointerWidth', 0, getNumberValidator());
|
|
172
|
-
Factory.addGetterSetter(Tag, 'pointerHeight', 0, getNumberValidator());
|
|
173
|
-
Factory.addGetterSetter(Tag, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
package/lib/shapes/Line.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
-
import { Shape } from '../Shape.ts';
|
|
3
|
-
import type { Context } from '../Context.ts';
|
|
4
|
-
import type { GetSet } from '../types.ts';
|
|
5
|
-
export interface LineConfig extends ShapeConfig {
|
|
6
|
-
points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
|
7
|
-
tension?: number;
|
|
8
|
-
closed?: boolean;
|
|
9
|
-
bezier?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare class Line<Config extends LineConfig = LineConfig> extends Shape<Config> {
|
|
12
|
-
constructor(config?: Config);
|
|
13
|
-
_sceneFunc(context: Context): void;
|
|
14
|
-
getTensionPoints(): any;
|
|
15
|
-
_getTensionPoints(): number[];
|
|
16
|
-
_getTensionPointsClosed(): number[];
|
|
17
|
-
getWidth(): number;
|
|
18
|
-
getHeight(): number;
|
|
19
|
-
getSelfRect(): {
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
width: number;
|
|
23
|
-
height: number;
|
|
24
|
-
};
|
|
25
|
-
closed: GetSet<boolean, this>;
|
|
26
|
-
bezier: GetSet<boolean, this>;
|
|
27
|
-
tension: GetSet<number, this>;
|
|
28
|
-
points: GetSet<number[], this>;
|
|
29
|
-
}
|
package/lib/shapes/Line.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { Factory } from "../Factory.js";
|
|
2
|
-
import { _registerNode } from "../Global.js";
|
|
3
|
-
import { Shape } from "../Shape.js";
|
|
4
|
-
import { getNumberArrayValidator, getNumberValidator } from "../Validators.js";
|
|
5
|
-
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
|
6
|
-
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = (t * d01) / (d01 + d12), fb = (t * d12) / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);
|
|
7
|
-
return [p1x, p1y, p2x, p2y];
|
|
8
|
-
}
|
|
9
|
-
function expandPoints(p, tension) {
|
|
10
|
-
const len = p.length, allPoints = [];
|
|
11
|
-
for (let n = 2; n < len - 2; n += 2) {
|
|
12
|
-
const cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
|
|
13
|
-
if (isNaN(cp[0])) {
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
allPoints.push(cp[0]);
|
|
17
|
-
allPoints.push(cp[1]);
|
|
18
|
-
allPoints.push(p[n]);
|
|
19
|
-
allPoints.push(p[n + 1]);
|
|
20
|
-
allPoints.push(cp[2]);
|
|
21
|
-
allPoints.push(cp[3]);
|
|
22
|
-
}
|
|
23
|
-
return allPoints;
|
|
24
|
-
}
|
|
25
|
-
export class Line extends Shape {
|
|
26
|
-
constructor(config) {
|
|
27
|
-
super(config);
|
|
28
|
-
this.on('pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva', function () {
|
|
29
|
-
this._clearCache('tensionPoints');
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
_sceneFunc(context) {
|
|
33
|
-
const points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier();
|
|
34
|
-
if (!length) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
let n = 0;
|
|
38
|
-
context.beginPath();
|
|
39
|
-
context.moveTo(points[0], points[1]);
|
|
40
|
-
if (tension !== 0 && length > 4) {
|
|
41
|
-
const tp = this.getTensionPoints();
|
|
42
|
-
const len = tp.length;
|
|
43
|
-
n = closed ? 0 : 4;
|
|
44
|
-
if (!closed) {
|
|
45
|
-
context.quadraticCurveTo(tp[0], tp[1], tp[2], tp[3]);
|
|
46
|
-
}
|
|
47
|
-
while (n < len - 2) {
|
|
48
|
-
context.bezierCurveTo(tp[n++], tp[n++], tp[n++], tp[n++], tp[n++], tp[n++]);
|
|
49
|
-
}
|
|
50
|
-
if (!closed) {
|
|
51
|
-
context.quadraticCurveTo(tp[len - 2], tp[len - 1], points[length - 2], points[length - 1]);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else if (bezier) {
|
|
55
|
-
n = 2;
|
|
56
|
-
while (n < length) {
|
|
57
|
-
context.bezierCurveTo(points[n++], points[n++], points[n++], points[n++], points[n++], points[n++]);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
for (n = 2; n < length; n += 2) {
|
|
62
|
-
context.lineTo(points[n], points[n + 1]);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (closed) {
|
|
66
|
-
context.closePath();
|
|
67
|
-
context.fillStrokeShape(this);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
context.strokeShape(this);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
getTensionPoints() {
|
|
74
|
-
return this._getCache('tensionPoints', this._getTensionPoints);
|
|
75
|
-
}
|
|
76
|
-
_getTensionPoints() {
|
|
77
|
-
if (this.closed()) {
|
|
78
|
-
return this._getTensionPointsClosed();
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return expandPoints(this.points(), this.tension());
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
_getTensionPointsClosed() {
|
|
85
|
-
const p = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]]
|
|
86
|
-
.concat(middle)
|
|
87
|
-
.concat([
|
|
88
|
-
lastControlPoints[0],
|
|
89
|
-
lastControlPoints[1],
|
|
90
|
-
p[len - 2],
|
|
91
|
-
p[len - 1],
|
|
92
|
-
lastControlPoints[2],
|
|
93
|
-
lastControlPoints[3],
|
|
94
|
-
firstControlPoints[0],
|
|
95
|
-
firstControlPoints[1],
|
|
96
|
-
p[0],
|
|
97
|
-
p[1],
|
|
98
|
-
]);
|
|
99
|
-
return tp;
|
|
100
|
-
}
|
|
101
|
-
getWidth() {
|
|
102
|
-
return this.getSelfRect().width;
|
|
103
|
-
}
|
|
104
|
-
getHeight() {
|
|
105
|
-
return this.getSelfRect().height;
|
|
106
|
-
}
|
|
107
|
-
getSelfRect() {
|
|
108
|
-
let points = this.points();
|
|
109
|
-
if (points.length < 4) {
|
|
110
|
-
return {
|
|
111
|
-
x: points[0] || 0,
|
|
112
|
-
y: points[1] || 0,
|
|
113
|
-
width: 0,
|
|
114
|
-
height: 0,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
if (this.tension() !== 0) {
|
|
118
|
-
points = [
|
|
119
|
-
points[0],
|
|
120
|
-
points[1],
|
|
121
|
-
...this._getTensionPoints(),
|
|
122
|
-
points[points.length - 2],
|
|
123
|
-
points[points.length - 1],
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
points = this.points();
|
|
128
|
-
}
|
|
129
|
-
let minX = points[0];
|
|
130
|
-
let maxX = points[0];
|
|
131
|
-
let minY = points[1];
|
|
132
|
-
let maxY = points[1];
|
|
133
|
-
let x, y;
|
|
134
|
-
for (let i = 0; i < points.length / 2; i++) {
|
|
135
|
-
x = points[i * 2];
|
|
136
|
-
y = points[i * 2 + 1];
|
|
137
|
-
minX = Math.min(minX, x);
|
|
138
|
-
maxX = Math.max(maxX, x);
|
|
139
|
-
minY = Math.min(minY, y);
|
|
140
|
-
maxY = Math.max(maxY, y);
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
x: minX,
|
|
144
|
-
y: minY,
|
|
145
|
-
width: maxX - minX,
|
|
146
|
-
height: maxY - minY,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
Line.prototype.className = 'Line';
|
|
151
|
-
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension'];
|
|
152
|
-
_registerNode(Line);
|
|
153
|
-
Factory.addGetterSetter(Line, 'closed', false);
|
|
154
|
-
Factory.addGetterSetter(Line, 'bezier', false);
|
|
155
|
-
Factory.addGetterSetter(Line, 'tension', 0, getNumberValidator());
|
|
156
|
-
Factory.addGetterSetter(Line, 'points', [], getNumberArrayValidator());
|
package/lib/shapes/Path.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
-
import { Shape } from '../Shape.ts';
|
|
3
|
-
import type { GetSet, PathSegment } from '../types.ts';
|
|
4
|
-
export interface PathConfig extends ShapeConfig {
|
|
5
|
-
data?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class Path extends Shape<PathConfig> {
|
|
8
|
-
dataArray: PathSegment[];
|
|
9
|
-
pathLength: number;
|
|
10
|
-
constructor(config?: PathConfig);
|
|
11
|
-
_readDataAttribute(): void;
|
|
12
|
-
_sceneFunc(context: any): void;
|
|
13
|
-
getSelfRect(): {
|
|
14
|
-
x: number;
|
|
15
|
-
y: number;
|
|
16
|
-
width: number;
|
|
17
|
-
height: number;
|
|
18
|
-
};
|
|
19
|
-
getLength(): number;
|
|
20
|
-
getPointAtLength(length: number): {
|
|
21
|
-
x: number;
|
|
22
|
-
y: number;
|
|
23
|
-
} | null;
|
|
24
|
-
data: GetSet<string, this>;
|
|
25
|
-
static getLineLength(x1: any, y1: any, x2: any, y2: any): number;
|
|
26
|
-
static getPathLength(dataArray: PathSegment[]): number;
|
|
27
|
-
static getPointAtLengthOfDataArray(length: number, dataArray: PathSegment[]): {
|
|
28
|
-
x: number;
|
|
29
|
-
y: number;
|
|
30
|
-
} | null;
|
|
31
|
-
static getPointOnLine(dist: number, P1x: number, P1y: number, P2x: number, P2y: number, fromX?: number, fromY?: number): {
|
|
32
|
-
x: number;
|
|
33
|
-
y: number;
|
|
34
|
-
};
|
|
35
|
-
static getPointOnCubicBezier(pct: number, P1x: number, P1y: number, P2x: number, P2y: number, P3x: number, P3y: number, P4x: number, P4y: number): {
|
|
36
|
-
x: number;
|
|
37
|
-
y: number;
|
|
38
|
-
};
|
|
39
|
-
static getPointOnQuadraticBezier(pct: any, P1x: any, P1y: any, P2x: any, P2y: any, P3x: any, P3y: any): {
|
|
40
|
-
x: number;
|
|
41
|
-
y: number;
|
|
42
|
-
};
|
|
43
|
-
static getPointOnEllipticalArc(cx: number, cy: number, rx: number, ry: number, theta: number, psi: number): {
|
|
44
|
-
x: number;
|
|
45
|
-
y: number;
|
|
46
|
-
};
|
|
47
|
-
static parsePathData(data: any): PathSegment[];
|
|
48
|
-
static calcLength(x: any, y: any, cmd: any, points: any): any;
|
|
49
|
-
static convertEndpointToCenterParameterization(x1: number, y1: number, x2: number, y2: number, fa: number, fs: number, rx: number, ry: number, psiDeg: number): number[];
|
|
50
|
-
}
|