@nasser-sw/fabric 7.0.1-beta8 → 7.0.1-beta9
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/debug/konva-master/CHANGELOG.md +1475 -0
- package/debug/konva-master/LICENSE +22 -0
- package/debug/konva-master/README.md +209 -0
- package/debug/konva-master/gulpfile.mjs +110 -0
- package/debug/konva-master/package.json +139 -0
- package/debug/konva-master/release.sh +62 -0
- package/debug/konva-master/resources/doc-includes/ContainerParams.txt +6 -0
- package/debug/konva-master/resources/doc-includes/NodeParams.txt +20 -0
- package/debug/konva-master/resources/doc-includes/ShapeParams.txt +53 -0
- package/debug/konva-master/resources/jsdoc.conf.json +28 -0
- package/debug/konva-master/rollup.config.mjs +32 -0
- package/debug/konva-master/src/Animation.ts +237 -0
- package/debug/konva-master/src/BezierFunctions.ts +826 -0
- package/debug/konva-master/src/Canvas.ts +230 -0
- package/debug/konva-master/src/Container.ts +649 -0
- package/debug/konva-master/src/Context.ts +1017 -0
- package/debug/konva-master/src/Core.ts +5 -0
- package/debug/konva-master/src/DragAndDrop.ts +173 -0
- package/debug/konva-master/src/Factory.ts +246 -0
- package/debug/konva-master/src/FastLayer.ts +29 -0
- package/debug/konva-master/src/Global.ts +210 -0
- package/debug/konva-master/src/Group.ts +31 -0
- package/debug/konva-master/src/Layer.ts +546 -0
- package/debug/konva-master/src/Node.ts +3477 -0
- package/debug/konva-master/src/PointerEvents.ts +67 -0
- package/debug/konva-master/src/Shape.ts +2081 -0
- package/debug/konva-master/src/Stage.ts +1000 -0
- package/debug/konva-master/src/Tween.ts +811 -0
- package/debug/konva-master/src/Util.ts +1123 -0
- package/debug/konva-master/src/Validators.ts +210 -0
- package/debug/konva-master/src/_CoreInternals.ts +85 -0
- package/debug/konva-master/src/_FullInternals.ts +171 -0
- package/debug/konva-master/src/canvas-backend.ts +36 -0
- package/debug/konva-master/src/filters/Blur.ts +388 -0
- package/debug/konva-master/src/filters/Brighten.ts +48 -0
- package/debug/konva-master/src/filters/Brightness.ts +30 -0
- package/debug/konva-master/src/filters/Contrast.ts +75 -0
- package/debug/konva-master/src/filters/Emboss.ts +207 -0
- package/debug/konva-master/src/filters/Enhance.ts +154 -0
- package/debug/konva-master/src/filters/Grayscale.ts +25 -0
- package/debug/konva-master/src/filters/HSL.ts +108 -0
- package/debug/konva-master/src/filters/HSV.ts +106 -0
- package/debug/konva-master/src/filters/Invert.ts +23 -0
- package/debug/konva-master/src/filters/Kaleidoscope.ts +274 -0
- package/debug/konva-master/src/filters/Mask.ts +220 -0
- package/debug/konva-master/src/filters/Noise.ts +44 -0
- package/debug/konva-master/src/filters/Pixelate.ts +107 -0
- package/debug/konva-master/src/filters/Posterize.ts +46 -0
- package/debug/konva-master/src/filters/RGB.ts +82 -0
- package/debug/konva-master/src/filters/RGBA.ts +103 -0
- package/debug/konva-master/src/filters/Sepia.ts +27 -0
- package/debug/konva-master/src/filters/Solarize.ts +29 -0
- package/debug/konva-master/src/filters/Threshold.ts +44 -0
- package/debug/konva-master/src/index.ts +3 -0
- package/debug/konva-master/src/shapes/Arc.ts +176 -0
- package/debug/konva-master/src/shapes/Arrow.ts +231 -0
- package/debug/konva-master/src/shapes/Circle.ts +76 -0
- package/debug/konva-master/src/shapes/Ellipse.ts +121 -0
- package/debug/konva-master/src/shapes/Image.ts +319 -0
- package/debug/konva-master/src/shapes/Label.ts +386 -0
- package/debug/konva-master/src/shapes/Line.ts +364 -0
- package/debug/konva-master/src/shapes/Path.ts +1013 -0
- package/debug/konva-master/src/shapes/Rect.ts +79 -0
- package/debug/konva-master/src/shapes/RegularPolygon.ts +167 -0
- package/debug/konva-master/src/shapes/Ring.ts +94 -0
- package/debug/konva-master/src/shapes/Sprite.ts +370 -0
- package/debug/konva-master/src/shapes/Star.ts +125 -0
- package/debug/konva-master/src/shapes/Text.ts +1065 -0
- package/debug/konva-master/src/shapes/TextPath.ts +583 -0
- package/debug/konva-master/src/shapes/Transformer.ts +1889 -0
- package/debug/konva-master/src/shapes/Wedge.ts +129 -0
- package/debug/konva-master/src/skia-backend.ts +35 -0
- package/debug/konva-master/src/types.ts +84 -0
- package/debug/konva-master/tsconfig.json +31 -0
- package/debug/konva-master/tsconfig.test.json +7 -0
- package/dist/index.js +915 -23
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +915 -23
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +915 -23
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +915 -23
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/shapes/Text/Text.d.ts +19 -0
- package/dist/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist/src/shapes/Text/Text.min.mjs +1 -1
- package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.mjs +238 -4
- package/dist/src/shapes/Text/Text.mjs.map +1 -1
- package/dist/src/shapes/Textbox.d.ts +38 -1
- package/dist/src/shapes/Textbox.d.ts.map +1 -1
- package/dist/src/shapes/Textbox.min.mjs +1 -1
- package/dist/src/shapes/Textbox.min.mjs.map +1 -1
- package/dist/src/shapes/Textbox.mjs +497 -15
- package/dist/src/shapes/Textbox.mjs.map +1 -1
- package/dist/src/text/examples/arabicTextExample.d.ts +60 -0
- package/dist/src/text/examples/arabicTextExample.d.ts.map +1 -0
- package/dist/src/text/measure.d.ts +9 -0
- package/dist/src/text/measure.d.ts.map +1 -1
- package/dist/src/text/measure.min.mjs +1 -1
- package/dist/src/text/measure.min.mjs.map +1 -1
- package/dist/src/text/measure.mjs +175 -4
- package/dist/src/text/measure.mjs.map +1 -1
- package/dist/src/text/overlayEditor.d.ts.map +1 -1
- package/dist/src/text/overlayEditor.min.mjs +1 -1
- package/dist/src/text/overlayEditor.min.mjs.map +1 -1
- package/dist/src/text/overlayEditor.mjs +7 -0
- package/dist/src/text/overlayEditor.mjs.map +1 -1
- package/dist/src/text/scriptUtils.d.ts +142 -0
- package/dist/src/text/scriptUtils.d.ts.map +1 -0
- package/dist/src/text/scriptUtils.min.mjs +2 -0
- package/dist/src/text/scriptUtils.min.mjs.map +1 -0
- package/dist/src/text/scriptUtils.mjs +212 -0
- package/dist/src/text/scriptUtils.mjs.map +1 -0
- package/dist-extensions/src/shapes/Text/Text.d.ts +19 -0
- package/dist-extensions/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Textbox.d.ts +38 -1
- package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
- package/dist-extensions/src/text/measure.d.ts +9 -0
- package/dist-extensions/src/text/measure.d.ts.map +1 -1
- package/dist-extensions/src/text/overlayEditor.d.ts.map +1 -1
- package/dist-extensions/src/text/scriptUtils.d.ts +142 -0
- package/dist-extensions/src/text/scriptUtils.d.ts.map +1 -0
- package/fabric-test-editor.html +2401 -46
- package/fonts/STV Bold.ttf +0 -0
- package/fonts/STV Light.ttf +0 -0
- package/fonts/STV Regular.ttf +0 -0
- package/package.json +1 -1
- package/src/shapes/Text/Text.ts +238 -5
- package/src/shapes/Textbox.ts +521 -11
- package/src/text/measure.ts +200 -50
- package/src/text/overlayEditor.ts +7 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Factory } from '../Factory.ts';
|
|
2
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
3
|
+
import { Shape } from '../Shape.ts';
|
|
4
|
+
import type { GetSet } from '../types.ts';
|
|
5
|
+
import { getNumberValidator } from '../Validators.ts';
|
|
6
|
+
import { _registerNode } from '../Global.ts';
|
|
7
|
+
import type { Context } from '../Context.ts';
|
|
8
|
+
|
|
9
|
+
export interface CircleConfig extends ShapeConfig {
|
|
10
|
+
radius?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Circle constructor
|
|
15
|
+
* @constructor
|
|
16
|
+
* @memberof Konva
|
|
17
|
+
* @augments Konva.Shape
|
|
18
|
+
* @param {Object} config
|
|
19
|
+
* @param {Number} config.radius
|
|
20
|
+
* @@shapeParams
|
|
21
|
+
* @@nodeParams
|
|
22
|
+
* @example
|
|
23
|
+
* // create circle
|
|
24
|
+
* var circle = new Konva.Circle({
|
|
25
|
+
* radius: 40,
|
|
26
|
+
* fill: 'red',
|
|
27
|
+
* stroke: 'black',
|
|
28
|
+
* strokeWidth: 5
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
export class Circle extends Shape<CircleConfig> {
|
|
32
|
+
_sceneFunc(context: Context) {
|
|
33
|
+
context.beginPath();
|
|
34
|
+
context.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, false);
|
|
35
|
+
context.closePath();
|
|
36
|
+
context.fillStrokeShape(this);
|
|
37
|
+
}
|
|
38
|
+
getWidth() {
|
|
39
|
+
return this.radius() * 2;
|
|
40
|
+
}
|
|
41
|
+
getHeight() {
|
|
42
|
+
return this.radius() * 2;
|
|
43
|
+
}
|
|
44
|
+
setWidth(width: number) {
|
|
45
|
+
if (this.radius() !== width / 2) {
|
|
46
|
+
this.radius(width / 2);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
setHeight(height: number) {
|
|
50
|
+
if (this.radius() !== height / 2) {
|
|
51
|
+
this.radius(height / 2);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
radius: GetSet<number, this>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Circle.prototype._centroid = true;
|
|
59
|
+
Circle.prototype.className = 'Circle';
|
|
60
|
+
Circle.prototype._attrsAffectingSize = ['radius'];
|
|
61
|
+
_registerNode(Circle);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* get/set radius
|
|
65
|
+
* @name Konva.Circle#radius
|
|
66
|
+
* @method
|
|
67
|
+
* @param {Number} radius
|
|
68
|
+
* @returns {Number}
|
|
69
|
+
* @example
|
|
70
|
+
* // get radius
|
|
71
|
+
* var radius = circle.radius();
|
|
72
|
+
*
|
|
73
|
+
* // set radius
|
|
74
|
+
* circle.radius(10);
|
|
75
|
+
*/
|
|
76
|
+
Factory.addGetterSetter(Circle, 'radius', 0, getNumberValidator());
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Factory } from '../Factory.ts';
|
|
2
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
3
|
+
import { Shape } from '../Shape.ts';
|
|
4
|
+
import { getNumberValidator } from '../Validators.ts';
|
|
5
|
+
import { _registerNode } from '../Global.ts';
|
|
6
|
+
import type { Context } from '../Context.ts';
|
|
7
|
+
|
|
8
|
+
import type { GetSet, Vector2d } from '../types.ts';
|
|
9
|
+
|
|
10
|
+
export interface EllipseConfig extends ShapeConfig {
|
|
11
|
+
radiusX: number;
|
|
12
|
+
radiusY: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Ellipse constructor
|
|
17
|
+
* @constructor
|
|
18
|
+
* @memberof Konva
|
|
19
|
+
* @augments Konva.Shape
|
|
20
|
+
* @param {Object} config
|
|
21
|
+
* @param {Object} config.radius defines x and y radius
|
|
22
|
+
* @@shapeParams
|
|
23
|
+
* @@nodeParams
|
|
24
|
+
* @example
|
|
25
|
+
* var ellipse = new Konva.Ellipse({
|
|
26
|
+
* radius : {
|
|
27
|
+
* x : 50,
|
|
28
|
+
* y : 50
|
|
29
|
+
* },
|
|
30
|
+
* fill: 'red'
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
export class Ellipse extends Shape<EllipseConfig> {
|
|
34
|
+
_sceneFunc(context: Context) {
|
|
35
|
+
const rx = this.radiusX(),
|
|
36
|
+
ry = this.radiusY();
|
|
37
|
+
|
|
38
|
+
context.beginPath();
|
|
39
|
+
context.save();
|
|
40
|
+
if (rx !== ry) {
|
|
41
|
+
context.scale(1, ry / rx);
|
|
42
|
+
}
|
|
43
|
+
context.arc(0, 0, rx, 0, Math.PI * 2, false);
|
|
44
|
+
context.restore();
|
|
45
|
+
context.closePath();
|
|
46
|
+
context.fillStrokeShape(this);
|
|
47
|
+
}
|
|
48
|
+
getWidth() {
|
|
49
|
+
return this.radiusX() * 2;
|
|
50
|
+
}
|
|
51
|
+
getHeight() {
|
|
52
|
+
return this.radiusY() * 2;
|
|
53
|
+
}
|
|
54
|
+
setWidth(width: number) {
|
|
55
|
+
this.radiusX(width / 2);
|
|
56
|
+
}
|
|
57
|
+
setHeight(height: number) {
|
|
58
|
+
this.radiusY(height / 2);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
radius: GetSet<Vector2d, this>;
|
|
62
|
+
radiusX: GetSet<number, this>;
|
|
63
|
+
radiusY: GetSet<number, this>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Ellipse.prototype.className = 'Ellipse';
|
|
67
|
+
Ellipse.prototype._centroid = true;
|
|
68
|
+
Ellipse.prototype._attrsAffectingSize = ['radiusX', 'radiusY'];
|
|
69
|
+
_registerNode(Ellipse);
|
|
70
|
+
|
|
71
|
+
// add getters setters
|
|
72
|
+
Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* get/set radius
|
|
76
|
+
* @name Konva.Ellipse#radius
|
|
77
|
+
* @method
|
|
78
|
+
* @param {Object} radius
|
|
79
|
+
* @param {Number} radius.x
|
|
80
|
+
* @param {Number} radius.y
|
|
81
|
+
* @returns {Object}
|
|
82
|
+
* @example
|
|
83
|
+
* // get radius
|
|
84
|
+
* var radius = ellipse.radius();
|
|
85
|
+
*
|
|
86
|
+
* // set radius
|
|
87
|
+
* ellipse.radius({
|
|
88
|
+
* x: 200,
|
|
89
|
+
* y: 100
|
|
90
|
+
* });
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
Factory.addGetterSetter(Ellipse, 'radiusX', 0, getNumberValidator());
|
|
94
|
+
/**
|
|
95
|
+
* get/set radius x
|
|
96
|
+
* @name Konva.Ellipse#radiusX
|
|
97
|
+
* @method
|
|
98
|
+
* @param {Number} x
|
|
99
|
+
* @returns {Number}
|
|
100
|
+
* @example
|
|
101
|
+
* // get radius x
|
|
102
|
+
* var radiusX = ellipse.radiusX();
|
|
103
|
+
*
|
|
104
|
+
* // set radius x
|
|
105
|
+
* ellipse.radiusX(200);
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
Factory.addGetterSetter(Ellipse, 'radiusY', 0, getNumberValidator());
|
|
109
|
+
/**
|
|
110
|
+
* get/set radius y
|
|
111
|
+
* @name Konva.Ellipse#radiusY
|
|
112
|
+
* @method
|
|
113
|
+
* @param {Number} y
|
|
114
|
+
* @returns {Number}
|
|
115
|
+
* @example
|
|
116
|
+
* // get radius y
|
|
117
|
+
* var radiusY = ellipse.radiusY();
|
|
118
|
+
*
|
|
119
|
+
* // set radius y
|
|
120
|
+
* ellipse.radiusY(200);
|
|
121
|
+
*/
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { Util } from '../Util.ts';
|
|
2
|
+
import { Factory } from '../Factory.ts';
|
|
3
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
4
|
+
import { Shape } from '../Shape.ts';
|
|
5
|
+
import { _registerNode } from '../Global.ts';
|
|
6
|
+
import {
|
|
7
|
+
getNumberOrArrayOfNumbersValidator,
|
|
8
|
+
getNumberValidator,
|
|
9
|
+
} from '../Validators.ts';
|
|
10
|
+
|
|
11
|
+
import type { GetSet, IRect } from '../types.ts';
|
|
12
|
+
import type { Context } from '../Context.ts';
|
|
13
|
+
|
|
14
|
+
export interface ImageConfig extends ShapeConfig {
|
|
15
|
+
image: CanvasImageSource | undefined;
|
|
16
|
+
crop?: IRect;
|
|
17
|
+
cornerRadius?: number | number[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Image constructor
|
|
22
|
+
* @constructor
|
|
23
|
+
* @memberof Konva
|
|
24
|
+
* @augments Konva.Shape
|
|
25
|
+
* @param {Object} config
|
|
26
|
+
* @param {Image} config.image
|
|
27
|
+
* @param {Object} [config.crop]
|
|
28
|
+
* @@shapeParams
|
|
29
|
+
* @@nodeParams
|
|
30
|
+
* @example
|
|
31
|
+
* var imageObj = new Image();
|
|
32
|
+
* imageObj.onload = function() {
|
|
33
|
+
* var image = new Konva.Image({
|
|
34
|
+
* x: 200,
|
|
35
|
+
* y: 50,
|
|
36
|
+
* image: imageObj,
|
|
37
|
+
* width: 100,
|
|
38
|
+
* height: 100
|
|
39
|
+
* });
|
|
40
|
+
* };
|
|
41
|
+
* imageObj.src = '/path/to/image.jpg'
|
|
42
|
+
*/
|
|
43
|
+
export class Image extends Shape<ImageConfig> {
|
|
44
|
+
private _loadListener: () => void;
|
|
45
|
+
|
|
46
|
+
constructor(attrs: ImageConfig) {
|
|
47
|
+
super(attrs);
|
|
48
|
+
this._loadListener = () => {
|
|
49
|
+
this._requestDraw();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
this.on('imageChange.konva', (props: any) => {
|
|
53
|
+
this._removeImageLoad(props.oldVal);
|
|
54
|
+
this._setImageLoad();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this._setImageLoad();
|
|
58
|
+
}
|
|
59
|
+
_setImageLoad() {
|
|
60
|
+
const image = this.image() as any;
|
|
61
|
+
// check is image is already loaded
|
|
62
|
+
if (image && image.complete) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// check is video is already loaded
|
|
66
|
+
if (image && image.readyState === 4) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (image && image['addEventListener']) {
|
|
70
|
+
image['addEventListener']('load', this._loadListener);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
_removeImageLoad(image: any) {
|
|
74
|
+
if (image && image['removeEventListener']) {
|
|
75
|
+
image['removeEventListener']('load', this._loadListener);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
destroy() {
|
|
79
|
+
this._removeImageLoad(this.image());
|
|
80
|
+
super.destroy();
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
_useBufferCanvas() {
|
|
84
|
+
const hasCornerRadius = !!this.cornerRadius();
|
|
85
|
+
const hasShadow = this.hasShadow();
|
|
86
|
+
if (hasCornerRadius && hasShadow) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return super._useBufferCanvas(true);
|
|
90
|
+
}
|
|
91
|
+
_sceneFunc(context: Context) {
|
|
92
|
+
const width = this.getWidth();
|
|
93
|
+
const height = this.getHeight();
|
|
94
|
+
const cornerRadius = this.cornerRadius();
|
|
95
|
+
const image = this.attrs.image;
|
|
96
|
+
let params;
|
|
97
|
+
|
|
98
|
+
if (image) {
|
|
99
|
+
const cropWidth = this.attrs.cropWidth;
|
|
100
|
+
const cropHeight = this.attrs.cropHeight;
|
|
101
|
+
if (cropWidth && cropHeight) {
|
|
102
|
+
params = [
|
|
103
|
+
image,
|
|
104
|
+
this.cropX(),
|
|
105
|
+
this.cropY(),
|
|
106
|
+
cropWidth,
|
|
107
|
+
cropHeight,
|
|
108
|
+
0,
|
|
109
|
+
0,
|
|
110
|
+
width,
|
|
111
|
+
height,
|
|
112
|
+
];
|
|
113
|
+
} else {
|
|
114
|
+
params = [image, 0, 0, width, height];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (this.hasFill() || this.hasStroke() || cornerRadius) {
|
|
119
|
+
context.beginPath();
|
|
120
|
+
cornerRadius
|
|
121
|
+
? Util.drawRoundedRectPath(context, width, height, cornerRadius)
|
|
122
|
+
: context.rect(0, 0, width, height);
|
|
123
|
+
context.closePath();
|
|
124
|
+
context.fillStrokeShape(this);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (image) {
|
|
128
|
+
if (cornerRadius) {
|
|
129
|
+
context.clip();
|
|
130
|
+
}
|
|
131
|
+
context.drawImage.apply(context, params);
|
|
132
|
+
}
|
|
133
|
+
// If you need to draw later, you need to execute save/restore
|
|
134
|
+
}
|
|
135
|
+
_hitFunc(context: Context) {
|
|
136
|
+
const width = this.width(),
|
|
137
|
+
height = this.height(),
|
|
138
|
+
cornerRadius = this.cornerRadius();
|
|
139
|
+
|
|
140
|
+
context.beginPath();
|
|
141
|
+
if (!cornerRadius) {
|
|
142
|
+
context.rect(0, 0, width, height);
|
|
143
|
+
} else {
|
|
144
|
+
Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
145
|
+
}
|
|
146
|
+
context.closePath();
|
|
147
|
+
context.fillStrokeShape(this);
|
|
148
|
+
}
|
|
149
|
+
getWidth() {
|
|
150
|
+
return this.attrs.width ?? (this.image() as any)?.width;
|
|
151
|
+
}
|
|
152
|
+
getHeight() {
|
|
153
|
+
return this.attrs.height ?? (this.image() as any)?.height;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* load image from given url and create `Konva.Image` instance
|
|
158
|
+
* @method
|
|
159
|
+
* @memberof Konva.Image
|
|
160
|
+
* @param {String} url image source
|
|
161
|
+
* @param {Function} callback with Konva.Image instance as first argument
|
|
162
|
+
* @param {Function} onError optional error handler
|
|
163
|
+
* @example
|
|
164
|
+
* Konva.Image.fromURL(imageURL, function(image){
|
|
165
|
+
* // image is Konva.Image instance
|
|
166
|
+
* layer.add(image);
|
|
167
|
+
* });
|
|
168
|
+
*/
|
|
169
|
+
static fromURL(
|
|
170
|
+
url: string,
|
|
171
|
+
callback: (img: Image) => void,
|
|
172
|
+
onError: OnErrorEventHandler = null
|
|
173
|
+
) {
|
|
174
|
+
const img = Util.createImageElement();
|
|
175
|
+
img.onload = function () {
|
|
176
|
+
const image = new Image({
|
|
177
|
+
image: img,
|
|
178
|
+
});
|
|
179
|
+
callback(image);
|
|
180
|
+
};
|
|
181
|
+
img.onerror = onError;
|
|
182
|
+
img.crossOrigin = 'Anonymous';
|
|
183
|
+
img.src = url;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
image: GetSet<CanvasImageSource | undefined, this>;
|
|
187
|
+
crop: GetSet<IRect, this>;
|
|
188
|
+
cropX: GetSet<number, this>;
|
|
189
|
+
cropY: GetSet<number, this>;
|
|
190
|
+
cropWidth: GetSet<number, this>;
|
|
191
|
+
cropHeight: GetSet<number, this>;
|
|
192
|
+
cornerRadius: GetSet<number | number[], this>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
Image.prototype.className = 'Image';
|
|
196
|
+
_registerNode(Image);
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* get/set corner radius
|
|
200
|
+
* @method
|
|
201
|
+
* @name Konva.Image#cornerRadius
|
|
202
|
+
* @param {Number} cornerRadius
|
|
203
|
+
* @returns {Number}
|
|
204
|
+
* @example
|
|
205
|
+
* // get corner radius
|
|
206
|
+
* var cornerRadius = image.cornerRadius();
|
|
207
|
+
*
|
|
208
|
+
* // set corner radius
|
|
209
|
+
* image.cornerRadius(10);
|
|
210
|
+
*
|
|
211
|
+
* // set different corner radius values
|
|
212
|
+
* // top-left, top-right, bottom-right, bottom-left
|
|
213
|
+
* image.cornerRadius([0, 10, 20, 30]);
|
|
214
|
+
*/
|
|
215
|
+
Factory.addGetterSetter(
|
|
216
|
+
Image,
|
|
217
|
+
'cornerRadius',
|
|
218
|
+
0,
|
|
219
|
+
getNumberOrArrayOfNumbersValidator(4)
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* get/set image source. It can be image, canvas or video element
|
|
224
|
+
* @name Konva.Image#image
|
|
225
|
+
* @method
|
|
226
|
+
* @param {Object} image source
|
|
227
|
+
* @returns {Object}
|
|
228
|
+
* @example
|
|
229
|
+
* // get value
|
|
230
|
+
* var image = shape.image();
|
|
231
|
+
*
|
|
232
|
+
* // set value
|
|
233
|
+
* shape.image(img);
|
|
234
|
+
*/
|
|
235
|
+
Factory.addGetterSetter(Image, 'image');
|
|
236
|
+
|
|
237
|
+
Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
|
|
238
|
+
/**
|
|
239
|
+
* get/set crop
|
|
240
|
+
* @method
|
|
241
|
+
* @name Konva.Image#crop
|
|
242
|
+
* @param {Object} crop
|
|
243
|
+
* @param {Number} crop.x
|
|
244
|
+
* @param {Number} crop.y
|
|
245
|
+
* @param {Number} crop.width
|
|
246
|
+
* @param {Number} crop.height
|
|
247
|
+
* @returns {Object}
|
|
248
|
+
* @example
|
|
249
|
+
* // get crop
|
|
250
|
+
* var crop = image.crop();
|
|
251
|
+
*
|
|
252
|
+
* // set crop
|
|
253
|
+
* image.crop({
|
|
254
|
+
* x: 20,
|
|
255
|
+
* y: 20,
|
|
256
|
+
* width: 20,
|
|
257
|
+
* height: 20
|
|
258
|
+
* });
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator());
|
|
262
|
+
/**
|
|
263
|
+
* get/set crop x
|
|
264
|
+
* @method
|
|
265
|
+
* @name Konva.Image#cropX
|
|
266
|
+
* @param {Number} x
|
|
267
|
+
* @returns {Number}
|
|
268
|
+
* @example
|
|
269
|
+
* // get crop x
|
|
270
|
+
* var cropX = image.cropX();
|
|
271
|
+
*
|
|
272
|
+
* // set crop x
|
|
273
|
+
* image.cropX(20);
|
|
274
|
+
*/
|
|
275
|
+
|
|
276
|
+
Factory.addGetterSetter(Image, 'cropY', 0, getNumberValidator());
|
|
277
|
+
/**
|
|
278
|
+
* get/set crop y
|
|
279
|
+
* @name Konva.Image#cropY
|
|
280
|
+
* @method
|
|
281
|
+
* @param {Number} y
|
|
282
|
+
* @returns {Number}
|
|
283
|
+
* @example
|
|
284
|
+
* // get crop y
|
|
285
|
+
* var cropY = image.cropY();
|
|
286
|
+
*
|
|
287
|
+
* // set crop y
|
|
288
|
+
* image.cropY(20);
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
Factory.addGetterSetter(Image, 'cropWidth', 0, getNumberValidator());
|
|
292
|
+
/**
|
|
293
|
+
* get/set crop width
|
|
294
|
+
* @name Konva.Image#cropWidth
|
|
295
|
+
* @method
|
|
296
|
+
* @param {Number} width
|
|
297
|
+
* @returns {Number}
|
|
298
|
+
* @example
|
|
299
|
+
* // get crop width
|
|
300
|
+
* var cropWidth = image.cropWidth();
|
|
301
|
+
*
|
|
302
|
+
* // set crop width
|
|
303
|
+
* image.cropWidth(20);
|
|
304
|
+
*/
|
|
305
|
+
|
|
306
|
+
Factory.addGetterSetter(Image, 'cropHeight', 0, getNumberValidator());
|
|
307
|
+
/**
|
|
308
|
+
* get/set crop height
|
|
309
|
+
* @name Konva.Image#cropHeight
|
|
310
|
+
* @method
|
|
311
|
+
* @param {Number} height
|
|
312
|
+
* @returns {Number}
|
|
313
|
+
* @example
|
|
314
|
+
* // get crop height
|
|
315
|
+
* var cropHeight = image.cropHeight();
|
|
316
|
+
*
|
|
317
|
+
* // set crop height
|
|
318
|
+
* image.cropHeight(20);
|
|
319
|
+
*/
|