@nasser-sw/fabric 7.0.1-beta3 → 7.0.1-beta5

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.
Files changed (105) hide show
  1. package/0 +0 -0
  2. package/dist/index.js +345 -162
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/index.min.mjs +1 -1
  7. package/dist/index.min.mjs.map +1 -1
  8. package/dist/index.mjs +345 -162
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/index.node.cjs +345 -162
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.mjs +345 -162
  13. package/dist/index.node.mjs.map +1 -1
  14. package/dist/package.json.min.mjs +1 -1
  15. package/dist/package.json.mjs +1 -1
  16. package/dist/src/shapes/Line.d.ts +32 -86
  17. package/dist/src/shapes/Line.d.ts.map +1 -1
  18. package/dist/src/shapes/Line.min.mjs +1 -1
  19. package/dist/src/shapes/Line.min.mjs.map +1 -1
  20. package/dist/src/shapes/Line.mjs +345 -161
  21. package/dist/src/shapes/Line.mjs.map +1 -1
  22. package/dist-extensions/src/shapes/CustomLine.d.ts +10 -0
  23. package/dist-extensions/src/shapes/CustomLine.d.ts.map +1 -0
  24. package/dist-extensions/src/shapes/Line.d.ts +32 -86
  25. package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
  26. package/fabric-test-editor.html +157 -8
  27. package/fabric-test2.html +513 -0
  28. package/fabric.ts +182 -182
  29. package/package.json +1 -1
  30. package/src/shapes/Line.ts +397 -164
  31. package/debug/konva/CHANGELOG.md +0 -1474
  32. package/debug/konva/LICENSE +0 -22
  33. package/debug/konva/README.md +0 -205
  34. package/debug/konva/gulpfile.mjs +0 -110
  35. package/debug/konva/package.json +0 -139
  36. package/debug/konva/release.sh +0 -65
  37. package/debug/konva/resources/doc-includes/ContainerParams.txt +0 -6
  38. package/debug/konva/resources/doc-includes/NodeParams.txt +0 -20
  39. package/debug/konva/resources/doc-includes/ShapeParams.txt +0 -53
  40. package/debug/konva/resources/jsdoc.conf.json +0 -28
  41. package/debug/konva/rollup.config.mjs +0 -32
  42. package/debug/konva/src/Animation.ts +0 -237
  43. package/debug/konva/src/BezierFunctions.ts +0 -826
  44. package/debug/konva/src/Canvas.ts +0 -193
  45. package/debug/konva/src/Container.ts +0 -649
  46. package/debug/konva/src/Context.ts +0 -1017
  47. package/debug/konva/src/Core.ts +0 -5
  48. package/debug/konva/src/DragAndDrop.ts +0 -173
  49. package/debug/konva/src/Factory.ts +0 -246
  50. package/debug/konva/src/FastLayer.ts +0 -29
  51. package/debug/konva/src/Global.ts +0 -210
  52. package/debug/konva/src/Group.ts +0 -31
  53. package/debug/konva/src/Layer.ts +0 -546
  54. package/debug/konva/src/Node.ts +0 -3477
  55. package/debug/konva/src/PointerEvents.ts +0 -67
  56. package/debug/konva/src/Shape.ts +0 -2081
  57. package/debug/konva/src/Stage.ts +0 -1000
  58. package/debug/konva/src/Tween.ts +0 -811
  59. package/debug/konva/src/Util.ts +0 -1123
  60. package/debug/konva/src/Validators.ts +0 -210
  61. package/debug/konva/src/_CoreInternals.ts +0 -85
  62. package/debug/konva/src/_FullInternals.ts +0 -171
  63. package/debug/konva/src/canvas-backend.ts +0 -36
  64. package/debug/konva/src/filters/Blur.ts +0 -388
  65. package/debug/konva/src/filters/Brighten.ts +0 -48
  66. package/debug/konva/src/filters/Brightness.ts +0 -30
  67. package/debug/konva/src/filters/Contrast.ts +0 -75
  68. package/debug/konva/src/filters/Emboss.ts +0 -207
  69. package/debug/konva/src/filters/Enhance.ts +0 -154
  70. package/debug/konva/src/filters/Grayscale.ts +0 -25
  71. package/debug/konva/src/filters/HSL.ts +0 -108
  72. package/debug/konva/src/filters/HSV.ts +0 -106
  73. package/debug/konva/src/filters/Invert.ts +0 -23
  74. package/debug/konva/src/filters/Kaleidoscope.ts +0 -274
  75. package/debug/konva/src/filters/Mask.ts +0 -220
  76. package/debug/konva/src/filters/Noise.ts +0 -44
  77. package/debug/konva/src/filters/Pixelate.ts +0 -107
  78. package/debug/konva/src/filters/Posterize.ts +0 -46
  79. package/debug/konva/src/filters/RGB.ts +0 -82
  80. package/debug/konva/src/filters/RGBA.ts +0 -103
  81. package/debug/konva/src/filters/Sepia.ts +0 -27
  82. package/debug/konva/src/filters/Solarize.ts +0 -29
  83. package/debug/konva/src/filters/Threshold.ts +0 -44
  84. package/debug/konva/src/index.ts +0 -3
  85. package/debug/konva/src/shapes/Arc.ts +0 -176
  86. package/debug/konva/src/shapes/Arrow.ts +0 -231
  87. package/debug/konva/src/shapes/Circle.ts +0 -76
  88. package/debug/konva/src/shapes/Ellipse.ts +0 -121
  89. package/debug/konva/src/shapes/Image.ts +0 -319
  90. package/debug/konva/src/shapes/Label.ts +0 -386
  91. package/debug/konva/src/shapes/Line.ts +0 -364
  92. package/debug/konva/src/shapes/Path.ts +0 -1013
  93. package/debug/konva/src/shapes/Rect.ts +0 -79
  94. package/debug/konva/src/shapes/RegularPolygon.ts +0 -167
  95. package/debug/konva/src/shapes/Ring.ts +0 -94
  96. package/debug/konva/src/shapes/Sprite.ts +0 -370
  97. package/debug/konva/src/shapes/Star.ts +0 -125
  98. package/debug/konva/src/shapes/Text.ts +0 -1065
  99. package/debug/konva/src/shapes/TextPath.ts +0 -583
  100. package/debug/konva/src/shapes/Transformer.ts +0 -1889
  101. package/debug/konva/src/shapes/Wedge.ts +0 -129
  102. package/debug/konva/src/skia-backend.ts +0 -35
  103. package/debug/konva/src/types.ts +0 -84
  104. package/debug/konva/tsconfig.json +0 -31
  105. package/debug/konva/tsconfig.test.json +0 -7
@@ -1,79 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { ShapeConfig } from '../Shape.ts';
3
- import { Shape } from '../Shape.ts';
4
- import { _registerNode } from '../Global.ts';
5
-
6
- import { Util } from '../Util.ts';
7
- import type { GetSet } from '../types.ts';
8
- import type { Context } from '../Context.ts';
9
- import { getNumberOrArrayOfNumbersValidator } from '../Validators.ts';
10
-
11
- export interface RectConfig extends ShapeConfig {
12
- cornerRadius?: number | number[];
13
- }
14
-
15
- /**
16
- * Rect constructor
17
- * @constructor
18
- * @memberof Konva
19
- * @augments Konva.Shape
20
- * @param {Object} config
21
- * @param {Number} [config.cornerRadius]
22
- * @@shapeParams
23
- * @@nodeParams
24
- * @example
25
- * var rect = new Konva.Rect({
26
- * width: 100,
27
- * height: 50,
28
- * fill: 'red',
29
- * stroke: 'black',
30
- * strokeWidth: 5
31
- * });
32
- */
33
- export class Rect extends Shape<RectConfig> {
34
- _sceneFunc(context: Context) {
35
- const cornerRadius = this.cornerRadius(),
36
- width = this.width(),
37
- height = this.height();
38
-
39
- context.beginPath();
40
-
41
- if (!cornerRadius) {
42
- // simple rect - don't bother doing all that complicated maths stuff.
43
- context.rect(0, 0, width, height);
44
- } else {
45
- Util.drawRoundedRectPath(context, width, height, cornerRadius);
46
- }
47
- context.closePath();
48
- context.fillStrokeShape(this);
49
- }
50
-
51
- cornerRadius: GetSet<number | number[], this>;
52
- }
53
-
54
- Rect.prototype.className = 'Rect';
55
- _registerNode(Rect);
56
-
57
- /**
58
- * get/set corner radius
59
- * @method
60
- * @name Konva.Rect#cornerRadius
61
- * @param {Number} cornerRadius
62
- * @returns {Number}
63
- * @example
64
- * // get corner radius
65
- * var cornerRadius = rect.cornerRadius();
66
- *
67
- * // set corner radius
68
- * rect.cornerRadius(10);
69
- *
70
- * // set different corner radius values
71
- * // top-left, top-right, bottom-right, bottom-left
72
- * rect.cornerRadius([0, 10, 20, 30]);
73
- */
74
- Factory.addGetterSetter(
75
- Rect,
76
- 'cornerRadius',
77
- 0,
78
- getNumberOrArrayOfNumbersValidator(4)
79
- );
@@ -1,167 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { ShapeConfig } from '../Shape.ts';
3
- import { Shape } from '../Shape.ts';
4
- import type { GetSet, Vector2d } from '../types.ts';
5
- import {
6
- getNumberOrArrayOfNumbersValidator,
7
- getNumberValidator,
8
- } from '../Validators.ts';
9
- import { _registerNode } from '../Global.ts';
10
- import type { Context } from '../Context.ts';
11
- import { Util } from '../Util.ts';
12
-
13
- export interface RegularPolygonConfig extends ShapeConfig {
14
- sides: number;
15
- radius: number;
16
- cornerRadius?: number | number[];
17
- }
18
- /**
19
- * RegularPolygon constructor. Examples include triangles, squares, pentagons, hexagons, etc.
20
- * @constructor
21
- * @memberof Konva
22
- * @augments Konva.Shape
23
- * @param {Object} config
24
- * @param {Number} [config.cornerRadius]
25
- * @param {Number} config.sides
26
- * @param {Number} config.radius
27
- * @@shapeParams
28
- * @@nodeParams
29
- * @example
30
- * var hexagon = new Konva.RegularPolygon({
31
- * x: 100,
32
- * y: 200,
33
- * sides: 6,
34
- * radius: 70,
35
- * fill: 'red',
36
- * stroke: 'black',
37
- * strokeWidth: 4
38
- * });
39
- */
40
- export class RegularPolygon extends Shape<RegularPolygonConfig> {
41
- _sceneFunc(context: Context) {
42
- const points = this._getPoints(),
43
- radius = this.radius(),
44
- sides = this.sides(),
45
- cornerRadius = this.cornerRadius();
46
-
47
- context.beginPath();
48
-
49
- if (!cornerRadius) {
50
- context.moveTo(points[0].x, points[0].y);
51
- for (let n = 1; n < points.length; n++) {
52
- context.lineTo(points[n].x, points[n].y);
53
- }
54
- } else {
55
- Util.drawRoundedPolygonPath(context, points, sides, radius, cornerRadius);
56
- }
57
-
58
- context.closePath();
59
- context.fillStrokeShape(this);
60
- }
61
- _getPoints() {
62
- const sides = this.attrs.sides as number;
63
- const radius = this.attrs.radius || 0;
64
- const points: Vector2d[] = [];
65
- for (let n = 0; n < sides; n++) {
66
- points.push({
67
- x: radius * Math.sin((n * 2 * Math.PI) / sides),
68
- y: -1 * radius * Math.cos((n * 2 * Math.PI) / sides),
69
- });
70
- }
71
- return points;
72
- }
73
- getSelfRect() {
74
- const points = this._getPoints();
75
-
76
- let minX = points[0].x;
77
- let maxX = points[0].y;
78
- let minY = points[0].x;
79
- let maxY = points[0].y;
80
- points.forEach((point) => {
81
- minX = Math.min(minX, point.x);
82
- maxX = Math.max(maxX, point.x);
83
- minY = Math.min(minY, point.y);
84
- maxY = Math.max(maxY, point.y);
85
- });
86
- return {
87
- x: minX,
88
- y: minY,
89
- width: maxX - minX,
90
- height: maxY - minY,
91
- };
92
- }
93
- getWidth() {
94
- return this.radius() * 2;
95
- }
96
- getHeight() {
97
- return this.radius() * 2;
98
- }
99
- setWidth(width: number) {
100
- this.radius(width / 2);
101
- }
102
- setHeight(height: number) {
103
- this.radius(height / 2);
104
- }
105
-
106
- radius: GetSet<number, this>;
107
- sides: GetSet<number, this>;
108
- cornerRadius: GetSet<number | number[], this>;
109
- }
110
-
111
- RegularPolygon.prototype.className = 'RegularPolygon';
112
- RegularPolygon.prototype._centroid = true;
113
- RegularPolygon.prototype._attrsAffectingSize = ['radius'];
114
- _registerNode(RegularPolygon);
115
-
116
- /**
117
- * get/set radius
118
- * @method
119
- * @name Konva.RegularPolygon#radius
120
- * @param {Number} radius
121
- * @returns {Number}
122
- * @example
123
- * // get radius
124
- * var radius = shape.radius();
125
- *
126
- * // set radius
127
- * shape.radius(10);
128
- */
129
- Factory.addGetterSetter(RegularPolygon, 'radius', 0, getNumberValidator());
130
-
131
- /**
132
- * get/set sides
133
- * @method
134
- * @name Konva.RegularPolygon#sides
135
- * @param {Number} sides
136
- * @returns {Number}
137
- * @example
138
- * // get sides
139
- * var sides = shape.sides();
140
- *
141
- * // set sides
142
- * shape.sides(10);
143
- */
144
- Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator());
145
-
146
- /**
147
- * get/set corner radius
148
- * @method
149
- * @name Konva.RegularPolygon#cornerRadius
150
- * @param {Number} cornerRadius
151
- * @returns {Number}
152
- * @example
153
- * // get corner radius
154
- * var cornerRadius = poly.cornerRadius();
155
- *
156
- * // set corner radius
157
- * poly.cornerRadius(10);
158
- *
159
- * // set different corner radius values (pentagon)
160
- * poly.cornerRadius([0, 10, 20, 30, 40]);
161
- */
162
- Factory.addGetterSetter(
163
- RegularPolygon,
164
- 'cornerRadius',
165
- 0,
166
- getNumberOrArrayOfNumbersValidator(4)
167
- );
@@ -1,94 +0,0 @@
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 RingConfig extends ShapeConfig {
10
- innerRadius: number;
11
- outerRadius: number;
12
- }
13
-
14
- const PIx2 = Math.PI * 2;
15
- /**
16
- * Ring constructor
17
- * @constructor
18
- * @augments Konva.Shape
19
- * @memberof Konva
20
- * @param {Object} config
21
- * @param {Number} config.innerRadius
22
- * @param {Number} config.outerRadius
23
- * @@shapeParams
24
- * @@nodeParams
25
- * @example
26
- * var ring = new Konva.Ring({
27
- * innerRadius: 40,
28
- * outerRadius: 80,
29
- * fill: 'red',
30
- * stroke: 'black',
31
- * strokeWidth: 5
32
- * });
33
- */
34
- export class Ring extends Shape<RingConfig> {
35
- _sceneFunc(context: Context) {
36
- context.beginPath();
37
- context.arc(0, 0, this.innerRadius(), 0, PIx2, false);
38
- context.moveTo(this.outerRadius(), 0);
39
- context.arc(0, 0, this.outerRadius(), PIx2, 0, true);
40
- context.closePath();
41
- context.fillStrokeShape(this);
42
- }
43
- getWidth() {
44
- return this.outerRadius() * 2;
45
- }
46
- getHeight() {
47
- return this.outerRadius() * 2;
48
- }
49
- setWidth(width: number) {
50
- this.outerRadius(width / 2);
51
- }
52
- setHeight(height: number) {
53
- this.outerRadius(height / 2);
54
- }
55
-
56
- outerRadius: GetSet<number, this>;
57
- innerRadius: GetSet<number, this>;
58
- }
59
-
60
- Ring.prototype.className = 'Ring';
61
- Ring.prototype._centroid = true;
62
- Ring.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
63
- _registerNode(Ring);
64
-
65
- /**
66
- * get/set innerRadius
67
- * @method
68
- * @name Konva.Ring#innerRadius
69
- * @param {Number} innerRadius
70
- * @returns {Number}
71
- * @example
72
- * // get inner radius
73
- * var innerRadius = ring.innerRadius();
74
- *
75
- * // set inner radius
76
- * ring.innerRadius(20);
77
- */
78
-
79
- Factory.addGetterSetter(Ring, 'innerRadius', 0, getNumberValidator());
80
-
81
- /**
82
- * get/set outerRadius
83
- * @name Konva.Ring#outerRadius
84
- * @method
85
- * @param {Number} outerRadius
86
- * @returns {Number}
87
- * @example
88
- * // get outer radius
89
- * var outerRadius = ring.outerRadius();
90
- *
91
- * // set outer radius
92
- * ring.outerRadius(20);
93
- */
94
- Factory.addGetterSetter(Ring, 'outerRadius', 0, getNumberValidator());
@@ -1,370 +0,0 @@
1
- import { Factory } from '../Factory.ts';
2
- import type { Context } from '../Context.ts';
3
- import type { ShapeConfig } from '../Shape.ts';
4
- import { Shape } from '../Shape.ts';
5
- import { Animation } from '../Animation.ts';
6
- import { getNumberValidator } from '../Validators.ts';
7
- import { _registerNode } from '../Global.ts';
8
-
9
- import type { GetSet } from '../types.ts';
10
-
11
- export interface SpriteConfig extends ShapeConfig {
12
- animation: string;
13
- animations: any;
14
- frameIndex?: number;
15
- image: HTMLImageElement;
16
- frameRate?: number;
17
- }
18
-
19
- /**
20
- * Sprite constructor
21
- * @constructor
22
- * @memberof Konva
23
- * @augments Konva.Shape
24
- * @param {Object} config
25
- * @param {String} config.animation animation key
26
- * @param {Object} config.animations animation map
27
- * @param {Integer} [config.frameIndex] animation frame index
28
- * @param {Image} config.image image object
29
- * @param {Integer} [config.frameRate] animation frame rate
30
- * @@shapeParams
31
- * @@nodeParams
32
- * @example
33
- * var imageObj = new Image();
34
- * imageObj.onload = function() {
35
- * var sprite = new Konva.Sprite({
36
- * x: 200,
37
- * y: 100,
38
- * image: imageObj,
39
- * animation: 'standing',
40
- * animations: {
41
- * standing: [
42
- * // x, y, width, height (6 frames)
43
- * 0, 0, 49, 109,
44
- * 52, 0, 49, 109,
45
- * 105, 0, 49, 109,
46
- * 158, 0, 49, 109,
47
- * 210, 0, 49, 109,
48
- * 262, 0, 49, 109
49
- * ],
50
- * kicking: [
51
- * // x, y, width, height (6 frames)
52
- * 0, 109, 45, 98,
53
- * 45, 109, 45, 98,
54
- * 95, 109, 63, 98,
55
- * 156, 109, 70, 98,
56
- * 229, 109, 60, 98,
57
- * 287, 109, 41, 98
58
- * ]
59
- * },
60
- * frameRate: 7,
61
- * frameIndex: 0
62
- * });
63
- * };
64
- * imageObj.src = '/path/to/image.jpg'
65
- */
66
- export class Sprite extends Shape<SpriteConfig> {
67
- _updated = true;
68
- anim: Animation;
69
- interval: any;
70
- constructor(config: SpriteConfig) {
71
- super(config);
72
- this.anim = new Animation(() => {
73
- // if we don't need to redraw layer we should return false
74
- const updated = this._updated;
75
- this._updated = false;
76
- return updated;
77
- });
78
- this.on('animationChange.konva', function () {
79
- // reset index when animation changes
80
- this.frameIndex(0);
81
- });
82
- this.on('frameIndexChange.konva', function () {
83
- this._updated = true;
84
- });
85
- // smooth change for frameRate
86
- this.on('frameRateChange.konva', function () {
87
- if (!this.anim.isRunning()) {
88
- return;
89
- }
90
- clearInterval(this.interval);
91
- this._setInterval();
92
- });
93
- }
94
-
95
- _sceneFunc(context: Context) {
96
- const anim = this.animation(),
97
- index = this.frameIndex(),
98
- ix4 = index * 4,
99
- set = this.animations()[anim],
100
- offsets = this.frameOffsets(),
101
- x = set[ix4 + 0],
102
- y = set[ix4 + 1],
103
- width = set[ix4 + 2],
104
- height = set[ix4 + 3],
105
- image = this.image();
106
-
107
- if (this.hasFill() || this.hasStroke()) {
108
- context.beginPath();
109
- context.rect(0, 0, width, height);
110
- context.closePath();
111
- context.fillStrokeShape(this);
112
- }
113
-
114
- if (image) {
115
- if (offsets) {
116
- const offset = offsets[anim],
117
- ix2 = index * 2;
118
- context.drawImage(
119
- image,
120
- x,
121
- y,
122
- width,
123
- height,
124
- offset[ix2 + 0],
125
- offset[ix2 + 1],
126
- width,
127
- height
128
- );
129
- } else {
130
- context.drawImage(image, x, y, width, height, 0, 0, width, height);
131
- }
132
- }
133
- }
134
- _hitFunc(context: Context) {
135
- const anim = this.animation(),
136
- index = this.frameIndex(),
137
- ix4 = index * 4,
138
- set = this.animations()[anim],
139
- offsets = this.frameOffsets(),
140
- width = set[ix4 + 2],
141
- height = set[ix4 + 3];
142
-
143
- context.beginPath();
144
- if (offsets) {
145
- const offset = offsets[anim];
146
- const ix2 = index * 2;
147
- context.rect(offset[ix2 + 0], offset[ix2 + 1], width, height);
148
- } else {
149
- context.rect(0, 0, width, height);
150
- }
151
- context.closePath();
152
- context.fillShape(this);
153
- }
154
-
155
- _useBufferCanvas() {
156
- return super._useBufferCanvas(true);
157
- }
158
-
159
- _setInterval() {
160
- const that = this;
161
- this.interval = setInterval(function () {
162
- that._updateIndex();
163
- }, 1000 / this.frameRate());
164
- }
165
- /**
166
- * start sprite animation
167
- * @method
168
- * @name Konva.Sprite#start
169
- */
170
- start() {
171
- if (this.isRunning()) {
172
- return;
173
- }
174
- const layer = this.getLayer();
175
-
176
- /*
177
- * animation object has no executable function because
178
- * the updates are done with a fixed FPS with the setInterval
179
- * below. The anim object only needs the layer reference for
180
- * redraw
181
- */
182
- this.anim.setLayers(layer);
183
- this._setInterval();
184
- this.anim.start();
185
- }
186
- /**
187
- * stop sprite animation
188
- * @method
189
- * @name Konva.Sprite#stop
190
- */
191
- stop() {
192
- this.anim.stop();
193
- clearInterval(this.interval);
194
- }
195
- /**
196
- * determine if animation of sprite is running or not. returns true or false
197
- * @method
198
- * @name Konva.Sprite#isRunning
199
- * @returns {Boolean}
200
- */
201
- isRunning() {
202
- return this.anim.isRunning();
203
- }
204
- _updateIndex() {
205
- const index = this.frameIndex(),
206
- animation = this.animation(),
207
- animations = this.animations(),
208
- anim = animations[animation],
209
- len = anim.length / 4;
210
-
211
- if (index < len - 1) {
212
- this.frameIndex(index + 1);
213
- } else {
214
- this.frameIndex(0);
215
- }
216
- }
217
-
218
- frameIndex: GetSet<number, this>;
219
- animation: GetSet<string, this>;
220
- image: GetSet<CanvasImageSource, this>;
221
- animations: GetSet<any, this>;
222
- frameOffsets: GetSet<any, this>;
223
- frameRate: GetSet<number, this>;
224
- }
225
-
226
- Sprite.prototype.className = 'Sprite';
227
- _registerNode(Sprite);
228
-
229
- // add getters setters
230
- Factory.addGetterSetter(Sprite, 'animation');
231
-
232
- /**
233
- * get/set animation key
234
- * @name Konva.Sprite#animation
235
- * @method
236
- * @param {String} anim animation key
237
- * @returns {String}
238
- * @example
239
- * // get animation key
240
- * var animation = sprite.animation();
241
- *
242
- * // set animation key
243
- * sprite.animation('kicking');
244
- */
245
-
246
- Factory.addGetterSetter(Sprite, 'animations');
247
-
248
- /**
249
- * get/set animations map
250
- * @name Konva.Sprite#animations
251
- * @method
252
- * @param {Object} animations
253
- * @returns {Object}
254
- * @example
255
- * // get animations map
256
- * var animations = sprite.animations();
257
- *
258
- * // set animations map
259
- * sprite.animations({
260
- * standing: [
261
- * // x, y, width, height (6 frames)
262
- * 0, 0, 49, 109,
263
- * 52, 0, 49, 109,
264
- * 105, 0, 49, 109,
265
- * 158, 0, 49, 109,
266
- * 210, 0, 49, 109,
267
- * 262, 0, 49, 109
268
- * ],
269
- * kicking: [
270
- * // x, y, width, height (6 frames)
271
- * 0, 109, 45, 98,
272
- * 45, 109, 45, 98,
273
- * 95, 109, 63, 98,
274
- * 156, 109, 70, 98,
275
- * 229, 109, 60, 98,
276
- * 287, 109, 41, 98
277
- * ]
278
- * });
279
- */
280
-
281
- Factory.addGetterSetter(Sprite, 'frameOffsets');
282
-
283
- /**
284
- * get/set offsets map
285
- * @name Konva.Sprite#offsets
286
- * @method
287
- * @param {Object} offsets
288
- * @returns {Object}
289
- * @example
290
- * // get offsets map
291
- * var offsets = sprite.offsets();
292
- *
293
- * // set offsets map
294
- * sprite.offsets({
295
- * standing: [
296
- * // x, y (6 frames)
297
- * 0, 0,
298
- * 0, 0,
299
- * 5, 0,
300
- * 0, 0,
301
- * 0, 3,
302
- * 2, 0
303
- * ],
304
- * kicking: [
305
- * // x, y (6 frames)
306
- * 0, 5,
307
- * 5, 0,
308
- * 10, 0,
309
- * 0, 0,
310
- * 2, 1,
311
- * 0, 0
312
- * ]
313
- * });
314
- */
315
-
316
- Factory.addGetterSetter(Sprite, 'image');
317
-
318
- /**
319
- * get/set image
320
- * @name Konva.Sprite#image
321
- * @method
322
- * @param {Image} image
323
- * @returns {Image}
324
- * @example
325
- * // get image
326
- * var image = sprite.image();
327
- *
328
- * // set image
329
- * sprite.image(imageObj);
330
- */
331
-
332
- Factory.addGetterSetter(Sprite, 'frameIndex', 0, getNumberValidator());
333
-
334
- /**
335
- * set/set animation frame index
336
- * @name Konva.Sprite#frameIndex
337
- * @method
338
- * @param {Integer} frameIndex
339
- * @returns {Integer}
340
- * @example
341
- * // get animation frame index
342
- * var frameIndex = sprite.frameIndex();
343
- *
344
- * // set animation frame index
345
- * sprite.frameIndex(3);
346
- */
347
-
348
- Factory.addGetterSetter(Sprite, 'frameRate', 17, getNumberValidator());
349
-
350
- /**
351
- * get/set frame rate in frames per second. Increase this number to make the sprite
352
- * animation run faster, and decrease the number to make the sprite animation run slower
353
- * The default is 17 frames per second
354
- * @name Konva.Sprite#frameRate
355
- * @method
356
- * @param {Integer} frameRate
357
- * @returns {Integer}
358
- * @example
359
- * // get frame rate
360
- * var frameRate = sprite.frameRate();
361
- *
362
- * // set frame rate to 2 frames per second
363
- * sprite.frameRate(2);
364
- */
365
-
366
- Factory.backCompat(Sprite, {
367
- index: 'frameIndex',
368
- getIndex: 'getFrameIndex',
369
- setIndex: 'setFrameIndex',
370
- });