konva 10.3.3 → 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 +1 -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 +12 -16
package/lib/Shape.js
CHANGED
|
@@ -6,6 +6,8 @@ import { getNumberValidator, getNumberOrAutoValidator, getStringValidator, getBo
|
|
|
6
6
|
import { _registerNode } from "./Global.js";
|
|
7
7
|
import * as PointerEvents from "./PointerEvents.js";
|
|
8
8
|
const HAS_SHADOW = 'hasShadow';
|
|
9
|
+
const HAS_FILL = 'hasFill';
|
|
10
|
+
const HAS_STROKE = 'hasStroke';
|
|
9
11
|
const SHADOW_RGBA = 'shadowRGBA';
|
|
10
12
|
const patternImage = 'patternImage';
|
|
11
13
|
const linearGradient = 'linearGradient';
|
|
@@ -31,21 +33,15 @@ function _fillFunc(context) {
|
|
|
31
33
|
function _strokeFunc(context) {
|
|
32
34
|
context.stroke();
|
|
33
35
|
}
|
|
34
|
-
function _fillFuncHit(context) {
|
|
35
|
-
const fillRule = this.attrs.fillRule;
|
|
36
|
-
if (fillRule) {
|
|
37
|
-
context.fill(fillRule);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
context.fill();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function _strokeFuncHit(context) {
|
|
44
|
-
context.stroke();
|
|
45
|
-
}
|
|
46
36
|
function _clearHasShadowCache() {
|
|
47
37
|
this._clearCache(HAS_SHADOW);
|
|
48
38
|
}
|
|
39
|
+
function _clearHasFillCache() {
|
|
40
|
+
this._clearCache(HAS_FILL);
|
|
41
|
+
}
|
|
42
|
+
function _clearHasStrokeCache() {
|
|
43
|
+
this._clearCache(HAS_STROKE);
|
|
44
|
+
}
|
|
49
45
|
function _clearGetShadowRGBACache() {
|
|
50
46
|
this._clearCache(SHADOW_RGBA);
|
|
51
47
|
}
|
|
@@ -58,9 +54,36 @@ function _clearLinearGradientCache() {
|
|
|
58
54
|
function _clearRadialGradientCache() {
|
|
59
55
|
this._clearCache(radialGradient);
|
|
60
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Shape constructor. Shapes are primitive objects such as rectangles,
|
|
59
|
+
* circles, text, lines, etc.
|
|
60
|
+
* @constructor
|
|
61
|
+
* @memberof Konva
|
|
62
|
+
* @augments Konva.Node
|
|
63
|
+
* @param {Object} config
|
|
64
|
+
* @@shapeParams
|
|
65
|
+
* @@nodeParams
|
|
66
|
+
* @example
|
|
67
|
+
* var customShape = new Konva.Shape({
|
|
68
|
+
* x: 5,
|
|
69
|
+
* y: 10,
|
|
70
|
+
* fill: 'red',
|
|
71
|
+
* // a Konva.Canvas renderer is passed into the sceneFunc function
|
|
72
|
+
* sceneFunc (context, shape) {
|
|
73
|
+
* context.beginPath();
|
|
74
|
+
* context.moveTo(200, 50);
|
|
75
|
+
* context.lineTo(420, 80);
|
|
76
|
+
* context.quadraticCurveTo(300, 100, 260, 170);
|
|
77
|
+
* context.closePath();
|
|
78
|
+
* // Konva specific method
|
|
79
|
+
* context.fillStrokeShape(shape);
|
|
80
|
+
* }
|
|
81
|
+
*});
|
|
82
|
+
*/
|
|
61
83
|
export class Shape extends Node {
|
|
62
84
|
constructor(config) {
|
|
63
85
|
super(config);
|
|
86
|
+
// set colorKey
|
|
64
87
|
let key;
|
|
65
88
|
let attempts = 0;
|
|
66
89
|
while (true) {
|
|
@@ -78,10 +101,16 @@ export class Shape extends Node {
|
|
|
78
101
|
this.colorKey = key;
|
|
79
102
|
shapes[key] = this;
|
|
80
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated
|
|
106
|
+
*/
|
|
81
107
|
getContext() {
|
|
82
108
|
Util.warn('shape.getContext() method is deprecated. Please do not use it.');
|
|
83
109
|
return this.getLayer().getContext();
|
|
84
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* @deprecated
|
|
113
|
+
*/
|
|
85
114
|
getCanvas() {
|
|
86
115
|
Util.warn('shape.getCanvas() method is deprecated. Please do not use it.');
|
|
87
116
|
return this.getLayer().getCanvas();
|
|
@@ -92,6 +121,12 @@ export class Shape extends Node {
|
|
|
92
121
|
getHitFunc() {
|
|
93
122
|
return this.attrs.hitFunc || this['_hitFunc'];
|
|
94
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* returns whether or not a shadow will be rendered
|
|
126
|
+
* @method
|
|
127
|
+
* @name Konva.Shape#hasShadow
|
|
128
|
+
* @returns {Boolean}
|
|
129
|
+
*/
|
|
95
130
|
hasShadow() {
|
|
96
131
|
return this._getCache(HAS_SHADOW, this._hasShadow);
|
|
97
132
|
}
|
|
@@ -119,12 +154,12 @@ export class Shape extends Node {
|
|
|
119
154
|
const m = tr.getMatrix();
|
|
120
155
|
const matrix = typeof DOMMatrix === 'undefined'
|
|
121
156
|
? {
|
|
122
|
-
a: m[0],
|
|
123
|
-
b: m[1],
|
|
124
|
-
c: m[2],
|
|
157
|
+
a: m[0], // Horizontal scaling. A value of 1 results in no scaling.
|
|
158
|
+
b: m[1], // Vertical skewing.
|
|
159
|
+
c: m[2], // Horizontal skewing.
|
|
125
160
|
d: m[3],
|
|
126
|
-
e: m[4],
|
|
127
|
-
f: m[5],
|
|
161
|
+
e: m[4], // Horizontal translation (moving).
|
|
162
|
+
f: m[5], // Vertical translation (moving).
|
|
128
163
|
}
|
|
129
164
|
: new DOMMatrix(m);
|
|
130
165
|
pattern.setTransform(matrix);
|
|
@@ -142,6 +177,7 @@ export class Shape extends Node {
|
|
|
142
177
|
const start = this.fillLinearGradientStartPoint();
|
|
143
178
|
const end = this.fillLinearGradientEndPoint();
|
|
144
179
|
const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
180
|
+
// build color stops
|
|
145
181
|
for (let n = 0; n < colorStops.length; n += 2) {
|
|
146
182
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
147
183
|
}
|
|
@@ -158,6 +194,7 @@ export class Shape extends Node {
|
|
|
158
194
|
const start = this.fillRadialGradientStartPoint();
|
|
159
195
|
const end = this.fillRadialGradientEndPoint();
|
|
160
196
|
const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
|
|
197
|
+
// build color stops
|
|
161
198
|
for (let n = 0; n < colorStops.length; n += 2) {
|
|
162
199
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
163
200
|
}
|
|
@@ -184,40 +221,59 @@ export class Shape extends Node {
|
|
|
184
221
|
')');
|
|
185
222
|
}
|
|
186
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* returns whether or not the shape will be filled
|
|
226
|
+
* @method
|
|
227
|
+
* @name Konva.Shape#hasFill
|
|
228
|
+
* @returns {Boolean}
|
|
229
|
+
*/
|
|
187
230
|
hasFill() {
|
|
188
|
-
return this.
|
|
189
|
-
'fillEnabled',
|
|
190
|
-
'fill',
|
|
191
|
-
'fillPatternImage',
|
|
192
|
-
'fillLinearGradientColorStops',
|
|
193
|
-
'fillRadialGradientColorStops',
|
|
194
|
-
], () => {
|
|
195
|
-
return (this.fillEnabled() &&
|
|
196
|
-
!!(this.fill() ||
|
|
197
|
-
this.fillPatternImage() ||
|
|
198
|
-
this.fillLinearGradientColorStops() ||
|
|
199
|
-
this.fillRadialGradientColorStops()));
|
|
200
|
-
});
|
|
231
|
+
return this._getCache(HAS_FILL, this._hasFill);
|
|
201
232
|
}
|
|
233
|
+
_hasFill() {
|
|
234
|
+
return (this.fillEnabled() &&
|
|
235
|
+
!!(this.fill() ||
|
|
236
|
+
this.fillPatternImage() ||
|
|
237
|
+
this.fillLinearGradientColorStops() ||
|
|
238
|
+
this.fillRadialGradientColorStops()));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* returns whether or not the shape will be stroked
|
|
242
|
+
* @method
|
|
243
|
+
* @name Konva.Shape#hasStroke
|
|
244
|
+
* @returns {Boolean}
|
|
245
|
+
*/
|
|
202
246
|
hasStroke() {
|
|
203
|
-
return this.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return (this.strokeEnabled() &&
|
|
210
|
-
this.strokeWidth() &&
|
|
211
|
-
!!(this.stroke() || this.strokeLinearGradientColorStops()));
|
|
212
|
-
});
|
|
247
|
+
return this._getCache(HAS_STROKE, this._hasStroke);
|
|
248
|
+
}
|
|
249
|
+
_hasStroke() {
|
|
250
|
+
return (this.strokeEnabled() &&
|
|
251
|
+
!!(this.strokeWidth() &&
|
|
252
|
+
(this.stroke() || this.strokeLinearGradientColorStops())));
|
|
213
253
|
}
|
|
214
254
|
hasHitStroke() {
|
|
215
255
|
const width = this.hitStrokeWidth();
|
|
256
|
+
// on auto just check by stroke
|
|
216
257
|
if (width === 'auto') {
|
|
217
258
|
return this.hasStroke();
|
|
218
259
|
}
|
|
260
|
+
// we should enable hit stroke if stroke is enabled
|
|
261
|
+
// and we have some value from width
|
|
219
262
|
return this.strokeEnabled() && !!width;
|
|
220
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* determines if point is in the shape, regardless if other shapes are on top of it. Note: because
|
|
266
|
+
* this method clears a temporary canvas and then redraws the shape, it performs very poorly if executed many times
|
|
267
|
+
* consecutively. Please use the {@link Konva.Stage#getIntersection} method if at all possible
|
|
268
|
+
* because it performs much better. A shape that is invisible, not listening or not on a stage
|
|
269
|
+
* never intersects
|
|
270
|
+
* @method
|
|
271
|
+
* @name Konva.Shape#intersects
|
|
272
|
+
* @param {Object} point
|
|
273
|
+
* @param {Number} point.x
|
|
274
|
+
* @param {Number} point.y
|
|
275
|
+
* @returns {Boolean}
|
|
276
|
+
*/
|
|
221
277
|
intersects(point) {
|
|
222
278
|
const stage = this.getStage();
|
|
223
279
|
if (!stage) {
|
|
@@ -225,8 +281,8 @@ export class Shape extends Node {
|
|
|
225
281
|
}
|
|
226
282
|
const bufferHitCanvas = stage._syncBufferSize(stage.bufferHitCanvas);
|
|
227
283
|
bufferHitCanvas.getContext().clear();
|
|
228
|
-
this.drawHit(bufferHitCanvas
|
|
229
|
-
const p = bufferHitCanvas.context.getImageData(Math.
|
|
284
|
+
this.drawHit(bufferHitCanvas);
|
|
285
|
+
const p = bufferHitCanvas.context.getImageData(Math.floor(point.x), Math.floor(point.y), 1, 1).data;
|
|
230
286
|
return p[3] > 0;
|
|
231
287
|
}
|
|
232
288
|
destroy() {
|
|
@@ -235,8 +291,15 @@ export class Shape extends Node {
|
|
|
235
291
|
delete this.colorKey;
|
|
236
292
|
return this;
|
|
237
293
|
}
|
|
294
|
+
// why do we need buffer canvas?
|
|
295
|
+
// it give better result when a shape has
|
|
296
|
+
// stroke with fill and with some opacity
|
|
238
297
|
_useBufferCanvas(forceFill) {
|
|
298
|
+
// image and sprite still has "fill" as image
|
|
299
|
+
// so they use that method with forced fill
|
|
300
|
+
// it probably will be simpler, then copy/paste the code
|
|
239
301
|
var _a;
|
|
302
|
+
// force skip buffer canvas
|
|
240
303
|
const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
|
|
241
304
|
if (!perfectDrawEnabled) {
|
|
242
305
|
return false;
|
|
@@ -271,6 +334,18 @@ export class Shape extends Node {
|
|
|
271
334
|
return true;
|
|
272
335
|
}
|
|
273
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* return self rectangle (x, y, width, height) of shape.
|
|
339
|
+
* This method are not taken into account transformation and styles.
|
|
340
|
+
* @method
|
|
341
|
+
* @name Konva.Shape#getSelfRect
|
|
342
|
+
* @returns {Object} rect with {x, y, width, height} properties
|
|
343
|
+
* @example
|
|
344
|
+
*
|
|
345
|
+
* rect.getSelfRect(); // return {x:0, y:0, width:rect.width(), height:rect.height()}
|
|
346
|
+
* circle.getSelfRect(); // return {x: - circle.width() / 2, y: - circle.height() / 2, width:circle.width(), height:circle.height()}
|
|
347
|
+
*
|
|
348
|
+
*/
|
|
274
349
|
getSelfRect() {
|
|
275
350
|
const size = this.size();
|
|
276
351
|
return {
|
|
@@ -281,17 +356,8 @@ export class Shape extends Node {
|
|
|
281
356
|
};
|
|
282
357
|
}
|
|
283
358
|
getClientRect(config = {}) {
|
|
284
|
-
let hasCachedParent = false;
|
|
285
|
-
let parent = this.getParent();
|
|
286
|
-
while (parent) {
|
|
287
|
-
if (parent.isCached()) {
|
|
288
|
-
hasCachedParent = true;
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
parent = parent.getParent();
|
|
292
|
-
}
|
|
293
359
|
const skipTransform = config.skipTransform;
|
|
294
|
-
const relativeTo = config.relativeTo
|
|
360
|
+
const relativeTo = config.relativeTo;
|
|
295
361
|
const fillRect = this.getSelfRect();
|
|
296
362
|
const applyStroke = !config.skipStroke && this.hasStroke();
|
|
297
363
|
const strokeWidth = (applyStroke && this.strokeWidth()) || 0;
|
|
@@ -321,14 +387,18 @@ export class Shape extends Node {
|
|
|
321
387
|
return rect;
|
|
322
388
|
}
|
|
323
389
|
drawScene(can, top, bufferCanvas) {
|
|
390
|
+
// basically there are 3 drawing modes
|
|
391
|
+
// 1 - simple drawing when nothing is cached.
|
|
392
|
+
// 2 - when we are caching current
|
|
393
|
+
// 3 - when node is cached and we need to draw it into layer
|
|
324
394
|
const layer = this.getLayer();
|
|
325
395
|
const canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow();
|
|
326
396
|
let stage;
|
|
327
|
-
const skipBuffer = false;
|
|
328
397
|
const cachingSelf = top === this;
|
|
329
398
|
if (!this.isVisible() && !cachingSelf) {
|
|
330
399
|
return this;
|
|
331
400
|
}
|
|
401
|
+
// if node is cached we just need to draw from cache
|
|
332
402
|
if (cachedCanvas) {
|
|
333
403
|
context.save();
|
|
334
404
|
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
@@ -341,23 +411,35 @@ export class Shape extends Node {
|
|
|
341
411
|
return this;
|
|
342
412
|
}
|
|
343
413
|
context.save();
|
|
344
|
-
if
|
|
414
|
+
// if buffer canvas is needed
|
|
415
|
+
if (this._useBufferCanvas()) {
|
|
345
416
|
stage = this.getStage();
|
|
346
417
|
const bc = bufferCanvas || stage._syncBufferSize(stage.bufferCanvas);
|
|
347
418
|
const bufferContext = bc.getContext();
|
|
348
|
-
if (bufferCanvas) {
|
|
419
|
+
if (!bufferCanvas) {
|
|
420
|
+
bufferContext.clear();
|
|
421
|
+
}
|
|
422
|
+
else if (!bc.width) {
|
|
423
|
+
// cache() and toCanvas() hand over an empty buffer: size it to the
|
|
424
|
+
// destination on first use and shift it to the buffer origin
|
|
425
|
+
bc.setSize(canvas._logicalWidth, canvas._logicalHeight);
|
|
426
|
+
bufferContext.translate(-bc.x, -bc.y);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
// the buffer is translated, so reset the transform before clearing
|
|
349
430
|
bufferContext.save();
|
|
350
431
|
bufferContext.setTransform(1, 0, 0, 1, 0, 0);
|
|
351
432
|
bufferContext.clearRect(0, 0, bc.width, bc.height);
|
|
352
433
|
bufferContext.restore();
|
|
353
434
|
}
|
|
354
|
-
else {
|
|
355
|
-
bufferContext.clear();
|
|
356
|
-
}
|
|
357
435
|
bufferContext.save();
|
|
436
|
+
// the buffer canvas is a separate context that does not inherit the
|
|
437
|
+
// destination `imageSmoothingEnabled` flag, so propagate it to keep
|
|
438
|
+
// pattern/image smoothing consistent with the target context.
|
|
358
439
|
bufferContext.imageSmoothingEnabled = context.imageSmoothingEnabled;
|
|
359
440
|
bufferContext._applyLineJoin(this);
|
|
360
441
|
bufferContext._applyMiterLimit(this);
|
|
442
|
+
// layer might be undefined if we are using cache before adding to layer
|
|
361
443
|
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
362
444
|
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
363
445
|
drawFunc.call(this, bufferContext, this);
|
|
@@ -366,11 +448,13 @@ export class Shape extends Node {
|
|
|
366
448
|
if (hasShadow) {
|
|
367
449
|
context._applyShadow(this);
|
|
368
450
|
}
|
|
451
|
+
// if we are caching self, we don't need to apply opacity and global composite operation
|
|
452
|
+
// because it will be applied in the cache
|
|
369
453
|
if (!cachingSelf) {
|
|
370
454
|
context._applyOpacity(this);
|
|
371
455
|
context._applyGlobalCompositeOperation(this);
|
|
372
456
|
}
|
|
373
|
-
context.drawImage(bc._canvas, bc.x
|
|
457
|
+
context.drawImage(bc._canvas, bc.x, bc.y, bc.width / ratio, bc.height / ratio);
|
|
374
458
|
}
|
|
375
459
|
else {
|
|
376
460
|
context._applyLineJoin(this);
|
|
@@ -389,8 +473,8 @@ export class Shape extends Node {
|
|
|
389
473
|
context.restore();
|
|
390
474
|
return this;
|
|
391
475
|
}
|
|
392
|
-
drawHit(can, top
|
|
393
|
-
if (!this.shouldDrawHit(top
|
|
476
|
+
drawHit(can, top) {
|
|
477
|
+
if (!this.shouldDrawHit(top)) {
|
|
394
478
|
return this;
|
|
395
479
|
}
|
|
396
480
|
const layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedHitCanvas = this._getCachedHitCanvas(top);
|
|
@@ -420,15 +504,29 @@ export class Shape extends Node {
|
|
|
420
504
|
context.restore();
|
|
421
505
|
return this;
|
|
422
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* draw hit graph using the cached scene canvas
|
|
509
|
+
* @method
|
|
510
|
+
* @name Konva.Shape#drawHitFromCache
|
|
511
|
+
* @param {Integer} alphaThreshold alpha channel threshold that determines whether or not
|
|
512
|
+
* a pixel should be drawn onto the hit graph. Must be a value between 0 and 255.
|
|
513
|
+
* The default is 0
|
|
514
|
+
* @returns {Konva.Shape}
|
|
515
|
+
* @example
|
|
516
|
+
* shape.cache();
|
|
517
|
+
* shape.drawHitFromCache();
|
|
518
|
+
*/
|
|
423
519
|
drawHitFromCache(alphaThreshold = 0) {
|
|
424
520
|
const sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = this._getCachedHitCanvas(), hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight();
|
|
425
521
|
hitContext.clear();
|
|
426
|
-
|
|
522
|
+
// the hit context is scaled by its pixel ratio, so it draws logical units
|
|
523
|
+
hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth / hitCanvas.pixelRatio, hitHeight / hitCanvas.pixelRatio);
|
|
427
524
|
try {
|
|
428
525
|
const hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
|
|
429
526
|
const hitData = hitImageData.data;
|
|
430
527
|
const len = hitData.length;
|
|
431
528
|
const rgbColorKey = Util._hexToRgb(this.colorKey);
|
|
529
|
+
// replace non transparent pixels with color key
|
|
432
530
|
for (let i = 0; i < len; i += 4) {
|
|
433
531
|
const alpha = hitData[i + 3];
|
|
434
532
|
if (alpha > alphaThreshold) {
|
|
@@ -460,101 +558,1037 @@ export class Shape extends Node {
|
|
|
460
558
|
}
|
|
461
559
|
Shape.prototype._fillFunc = _fillFunc;
|
|
462
560
|
Shape.prototype._strokeFunc = _strokeFunc;
|
|
463
|
-
|
|
464
|
-
Shape.prototype.
|
|
561
|
+
// the hit graph is filled and stroked the same way as the scene
|
|
562
|
+
Shape.prototype._fillFuncHit = _fillFunc;
|
|
563
|
+
Shape.prototype._strokeFuncHit = _strokeFunc;
|
|
465
564
|
Shape.prototype._centroid = false;
|
|
466
565
|
Shape.prototype.nodeType = 'Shape';
|
|
467
566
|
_registerNode(Shape);
|
|
468
|
-
Shape.prototype.
|
|
469
|
-
Shape.prototype.on('shadowColorChange.konva shadowBlurChange.konva shadowOffsetChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearHasShadowCache);
|
|
567
|
+
Shape.prototype.on('shadowColorChange.konva shadowBlurChange.konva shadowOffsetXChange.konva shadowOffsetYChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearHasShadowCache);
|
|
470
568
|
Shape.prototype.on('shadowColorChange.konva shadowOpacityChange.konva shadowEnabledChange.konva', _clearGetShadowRGBACache);
|
|
569
|
+
Shape.prototype.on('fillEnabledChange.konva fillChange.konva fillPatternImageChange.konva fillLinearGradientColorStopsChange.konva fillRadialGradientColorStopsChange.konva', _clearHasFillCache);
|
|
570
|
+
Shape.prototype.on('strokeEnabledChange.konva strokeWidthChange.konva strokeChange.konva strokeLinearGradientColorStopsChange.konva', _clearHasStrokeCache);
|
|
471
571
|
Shape.prototype.on('fillPriorityChange.konva fillPatternImageChange.konva fillPatternRepeatChange.konva fillPatternScaleXChange.konva fillPatternScaleYChange.konva fillPatternOffsetXChange.konva fillPatternOffsetYChange.konva fillPatternXChange.konva fillPatternYChange.konva fillPatternRotationChange.konva', _clearFillPatternCache);
|
|
472
572
|
Shape.prototype.on('fillPriorityChange.konva fillLinearGradientColorStopsChange.konva fillLinearGradientStartPointXChange.konva fillLinearGradientStartPointYChange.konva fillLinearGradientEndPointXChange.konva fillLinearGradientEndPointYChange.konva', _clearLinearGradientCache);
|
|
473
573
|
Shape.prototype.on('fillPriorityChange.konva fillRadialGradientColorStopsChange.konva fillRadialGradientStartPointXChange.konva fillRadialGradientStartPointYChange.konva fillRadialGradientEndPointXChange.konva fillRadialGradientEndPointYChange.konva fillRadialGradientStartRadiusChange.konva fillRadialGradientEndRadiusChange.konva', _clearRadialGradientCache);
|
|
574
|
+
// add getters and setters
|
|
474
575
|
Factory.addGetterSetter(Shape, 'stroke', undefined, getStringOrGradientValidator());
|
|
576
|
+
/**
|
|
577
|
+
* get/set stroke color
|
|
578
|
+
* @name Konva.Shape#stroke
|
|
579
|
+
* @method
|
|
580
|
+
* @param {String} color
|
|
581
|
+
* @returns {String}
|
|
582
|
+
* @example
|
|
583
|
+
* // get stroke color
|
|
584
|
+
* var stroke = shape.stroke();
|
|
585
|
+
*
|
|
586
|
+
* // set stroke color with color string
|
|
587
|
+
* shape.stroke('green');
|
|
588
|
+
*
|
|
589
|
+
* // set stroke color with hex
|
|
590
|
+
* shape.stroke('#00ff00');
|
|
591
|
+
*
|
|
592
|
+
* // set stroke color with rgb
|
|
593
|
+
* shape.stroke('rgb(0,255,0)');
|
|
594
|
+
*
|
|
595
|
+
* // set stroke color with rgba and make it 50% opaque
|
|
596
|
+
* shape.stroke('rgba(0,255,0,0.5');
|
|
597
|
+
*/
|
|
475
598
|
Factory.addGetterSetter(Shape, 'strokeWidth', 2, getNumberValidator());
|
|
599
|
+
/**
|
|
600
|
+
* get/set stroke width
|
|
601
|
+
* @name Konva.Shape#strokeWidth
|
|
602
|
+
* @method
|
|
603
|
+
* @param {Number} strokeWidth
|
|
604
|
+
* @returns {Number}
|
|
605
|
+
* @example
|
|
606
|
+
* // get stroke width
|
|
607
|
+
* var strokeWidth = shape.strokeWidth();
|
|
608
|
+
*
|
|
609
|
+
* // set stroke width
|
|
610
|
+
* shape.strokeWidth(10);
|
|
611
|
+
*/
|
|
476
612
|
Factory.addGetterSetter(Shape, 'fillAfterStrokeEnabled', false);
|
|
613
|
+
/**
|
|
614
|
+
* get/set fillAfterStrokeEnabled property. By default Konva is drawing filling first, then stroke on top of the fill.
|
|
615
|
+
* In rare situations you may want a different behavior. When you have a stroke first then fill on top of it.
|
|
616
|
+
* Especially useful for Text objects.
|
|
617
|
+
* Default is false.
|
|
618
|
+
* @name Konva.Shape#fillAfterStrokeEnabled
|
|
619
|
+
* @method
|
|
620
|
+
* @param {Boolean} fillAfterStrokeEnabled
|
|
621
|
+
* @returns {Boolean}
|
|
622
|
+
* @example
|
|
623
|
+
* // get stroke width
|
|
624
|
+
* var fillAfterStrokeEnabled = shape.fillAfterStrokeEnabled();
|
|
625
|
+
*
|
|
626
|
+
* // set stroke width
|
|
627
|
+
* shape.fillAfterStrokeEnabled(true);
|
|
628
|
+
*/
|
|
477
629
|
Factory.addGetterSetter(Shape, 'hitStrokeWidth', 'auto', getNumberOrAutoValidator());
|
|
630
|
+
/**
|
|
631
|
+
* get/set stroke width for hit detection. Default value is "auto", it means it will be equals to strokeWidth
|
|
632
|
+
* @name Konva.Shape#hitStrokeWidth
|
|
633
|
+
* @method
|
|
634
|
+
* @param {Number} hitStrokeWidth
|
|
635
|
+
* @returns {Number}
|
|
636
|
+
* @example
|
|
637
|
+
* // get stroke width
|
|
638
|
+
* var hitStrokeWidth = shape.hitStrokeWidth();
|
|
639
|
+
*
|
|
640
|
+
* // set hit stroke width
|
|
641
|
+
* shape.hitStrokeWidth(20);
|
|
642
|
+
* // set hit stroke width always equals to scene stroke width
|
|
643
|
+
* shape.hitStrokeWidth('auto');
|
|
644
|
+
*/
|
|
478
645
|
Factory.addGetterSetter(Shape, 'strokeHitEnabled', true, getBooleanValidator());
|
|
646
|
+
/**
|
|
647
|
+
* **deprecated, use hitStrokeWidth instead!** get/set strokeHitEnabled property. Useful for performance optimization.
|
|
648
|
+
* You may set `shape.strokeHitEnabled(false)`. In this case stroke will be no draw on hit canvas, so hit area
|
|
649
|
+
* of shape will be decreased (by lineWidth / 2). Remember that non closed line with `strokeHitEnabled = false`
|
|
650
|
+
* will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
|
|
651
|
+
* Default value is true.
|
|
652
|
+
* @name Konva.Shape#strokeHitEnabled
|
|
653
|
+
* @method
|
|
654
|
+
* @param {Boolean} strokeHitEnabled
|
|
655
|
+
* @returns {Boolean}
|
|
656
|
+
* @example
|
|
657
|
+
* // get strokeHitEnabled
|
|
658
|
+
* var strokeHitEnabled = shape.strokeHitEnabled();
|
|
659
|
+
*
|
|
660
|
+
* // set strokeHitEnabled
|
|
661
|
+
* shape.strokeHitEnabled();
|
|
662
|
+
*/
|
|
479
663
|
Factory.addGetterSetter(Shape, 'perfectDrawEnabled', true, getBooleanValidator());
|
|
664
|
+
/**
|
|
665
|
+
* get/set perfectDrawEnabled. If a shape has fill, stroke and opacity you may set `perfectDrawEnabled` to false to improve performance.
|
|
666
|
+
* See http://konvajs.org/docs/performance/Disable_Perfect_Draw.html for more information.
|
|
667
|
+
* Default value is true
|
|
668
|
+
* @name Konva.Shape#perfectDrawEnabled
|
|
669
|
+
* @method
|
|
670
|
+
* @param {Boolean} perfectDrawEnabled
|
|
671
|
+
* @returns {Boolean}
|
|
672
|
+
* @example
|
|
673
|
+
* // get perfectDrawEnabled
|
|
674
|
+
* var perfectDrawEnabled = shape.perfectDrawEnabled();
|
|
675
|
+
*
|
|
676
|
+
* // set perfectDrawEnabled
|
|
677
|
+
* shape.perfectDrawEnabled();
|
|
678
|
+
*/
|
|
480
679
|
Factory.addGetterSetter(Shape, 'shadowForStrokeEnabled', true, getBooleanValidator());
|
|
680
|
+
/**
|
|
681
|
+
* get/set shadowForStrokeEnabled. Useful for performance optimization.
|
|
682
|
+
* You may set `shape.shadowForStrokeEnabled(false)`. In this case stroke will no effect shadow.
|
|
683
|
+
* Remember if you set `shadowForStrokeEnabled = false` for non closed line - that line will have no shadow!.
|
|
684
|
+
* Default value is true
|
|
685
|
+
* @name Konva.Shape#shadowForStrokeEnabled
|
|
686
|
+
* @method
|
|
687
|
+
* @param {Boolean} shadowForStrokeEnabled
|
|
688
|
+
* @returns {Boolean}
|
|
689
|
+
* @example
|
|
690
|
+
* // get shadowForStrokeEnabled
|
|
691
|
+
* var shadowForStrokeEnabled = shape.shadowForStrokeEnabled();
|
|
692
|
+
*
|
|
693
|
+
* // set shadowForStrokeEnabled
|
|
694
|
+
* shape.shadowForStrokeEnabled();
|
|
695
|
+
*/
|
|
481
696
|
Factory.addGetterSetter(Shape, 'lineJoin');
|
|
697
|
+
/**
|
|
698
|
+
* get/set line join. Can be miter, round, or bevel. The
|
|
699
|
+
* default is miter
|
|
700
|
+
* @name Konva.Shape#lineJoin
|
|
701
|
+
* @method
|
|
702
|
+
* @param {String} lineJoin
|
|
703
|
+
* @returns {String}
|
|
704
|
+
* @example
|
|
705
|
+
* // get line join
|
|
706
|
+
* var lineJoin = shape.lineJoin();
|
|
707
|
+
*
|
|
708
|
+
* // set line join
|
|
709
|
+
* shape.lineJoin('round');
|
|
710
|
+
*/
|
|
482
711
|
Factory.addGetterSetter(Shape, 'lineCap');
|
|
712
|
+
/**
|
|
713
|
+
* get/set line cap. Can be butt, round, or square
|
|
714
|
+
* @name Konva.Shape#lineCap
|
|
715
|
+
* @method
|
|
716
|
+
* @param {String} lineCap
|
|
717
|
+
* @returns {String}
|
|
718
|
+
* @example
|
|
719
|
+
* // get line cap
|
|
720
|
+
* var lineCap = shape.lineCap();
|
|
721
|
+
*
|
|
722
|
+
* // set line cap
|
|
723
|
+
* shape.lineCap('round');
|
|
724
|
+
*/
|
|
483
725
|
Factory.addGetterSetter(Shape, 'miterLimit');
|
|
726
|
+
/**
|
|
727
|
+
* get/set miterLimit.
|
|
728
|
+
* @name Konva.Shape#miterLimit
|
|
729
|
+
* @method
|
|
730
|
+
* @param {Number} miterLimit
|
|
731
|
+
* @returns {Number}
|
|
732
|
+
* @example
|
|
733
|
+
* // get miter limit
|
|
734
|
+
* var miterLimit = shape.miterLimit();
|
|
735
|
+
*
|
|
736
|
+
* // set miter limit
|
|
737
|
+
* shape.miterLimit(10);
|
|
738
|
+
*/
|
|
484
739
|
Factory.addGetterSetter(Shape, 'sceneFunc');
|
|
740
|
+
/**
|
|
741
|
+
* get/set scene draw function. That function is used to draw the shape on a canvas.
|
|
742
|
+
* Also that function will be used to draw hit area of the shape, in case if hitFunc is not defined.
|
|
743
|
+
* @name Konva.Shape#sceneFunc
|
|
744
|
+
* @method
|
|
745
|
+
* @param {Function} drawFunc drawing function
|
|
746
|
+
* @returns {Function}
|
|
747
|
+
* @example
|
|
748
|
+
* // get scene draw function
|
|
749
|
+
* var sceneFunc = shape.sceneFunc();
|
|
750
|
+
*
|
|
751
|
+
* // set scene draw function
|
|
752
|
+
* shape.sceneFunc(function(context, shape) {
|
|
753
|
+
* context.beginPath();
|
|
754
|
+
* context.rect(0, 0, shape.width(), shape.height());
|
|
755
|
+
* context.closePath();
|
|
756
|
+
* // important Konva method that fill and stroke shape from its properties
|
|
757
|
+
* // like stroke and fill
|
|
758
|
+
* context.fillStrokeShape(shape);
|
|
759
|
+
* });
|
|
760
|
+
*/
|
|
485
761
|
Factory.addGetterSetter(Shape, 'hitFunc');
|
|
762
|
+
/**
|
|
763
|
+
* get/set hit draw function. That function is used to draw custom hit area of a shape.
|
|
764
|
+
* @name Konva.Shape#hitFunc
|
|
765
|
+
* @method
|
|
766
|
+
* @param {Function} drawFunc drawing function
|
|
767
|
+
* @returns {Function}
|
|
768
|
+
* @example
|
|
769
|
+
* // get hit draw function
|
|
770
|
+
* var hitFunc = shape.hitFunc();
|
|
771
|
+
*
|
|
772
|
+
* // set hit draw function
|
|
773
|
+
* shape.hitFunc(function(context) {
|
|
774
|
+
* context.beginPath();
|
|
775
|
+
* context.rect(0, 0, shape.width(), shape.height());
|
|
776
|
+
* context.closePath();
|
|
777
|
+
* // important Konva method that fill and stroke shape from its properties
|
|
778
|
+
* context.fillStrokeShape(shape);
|
|
779
|
+
* });
|
|
780
|
+
*/
|
|
486
781
|
Factory.addGetterSetter(Shape, 'dash');
|
|
782
|
+
/**
|
|
783
|
+
* get/set dash array for stroke.
|
|
784
|
+
* @name Konva.Shape#dash
|
|
785
|
+
* @method
|
|
786
|
+
* @param {Array} dash
|
|
787
|
+
* @returns {Array}
|
|
788
|
+
* @example
|
|
789
|
+
* // apply dashed stroke that is 10px long and 5 pixels apart
|
|
790
|
+
* line.dash([10, 5]);
|
|
791
|
+
* // apply dashed stroke that is made up of alternating dashed
|
|
792
|
+
* // lines that are 10px long and 20px apart, and dots that have
|
|
793
|
+
* // a radius of 5px and are 20px apart
|
|
794
|
+
* line.dash([10, 20, 0.001, 20]);
|
|
795
|
+
*/
|
|
487
796
|
Factory.addGetterSetter(Shape, 'dashOffset', 0, getNumberValidator());
|
|
797
|
+
/**
|
|
798
|
+
* get/set dash offset for stroke.
|
|
799
|
+
* @name Konva.Shape#dash
|
|
800
|
+
* @method
|
|
801
|
+
* @param {Number} dash offset
|
|
802
|
+
* @returns {Number}
|
|
803
|
+
* @example
|
|
804
|
+
* // apply dashed stroke that is 10px long and 5 pixels apart with an offset of 5px
|
|
805
|
+
* line.dash([10, 5]);
|
|
806
|
+
* line.dashOffset(5);
|
|
807
|
+
*/
|
|
488
808
|
Factory.addGetterSetter(Shape, 'shadowColor', undefined, getStringValidator());
|
|
809
|
+
/**
|
|
810
|
+
* get/set shadow color
|
|
811
|
+
* @name Konva.Shape#shadowColor
|
|
812
|
+
* @method
|
|
813
|
+
* @param {String} color
|
|
814
|
+
* @returns {String}
|
|
815
|
+
* @example
|
|
816
|
+
* // get shadow color
|
|
817
|
+
* var shadow = shape.shadowColor();
|
|
818
|
+
*
|
|
819
|
+
* // set shadow color with color string
|
|
820
|
+
* shape.shadowColor('green');
|
|
821
|
+
*
|
|
822
|
+
* // set shadow color with hex
|
|
823
|
+
* shape.shadowColor('#00ff00');
|
|
824
|
+
*
|
|
825
|
+
* // set shadow color with rgb
|
|
826
|
+
* shape.shadowColor('rgb(0,255,0)');
|
|
827
|
+
*
|
|
828
|
+
* // set shadow color with rgba and make it 50% opaque
|
|
829
|
+
* shape.shadowColor('rgba(0,255,0,0.5');
|
|
830
|
+
*/
|
|
489
831
|
Factory.addGetterSetter(Shape, 'shadowBlur', 0, getNumberValidator());
|
|
832
|
+
/**
|
|
833
|
+
* get/set shadow blur
|
|
834
|
+
* @name Konva.Shape#shadowBlur
|
|
835
|
+
* @method
|
|
836
|
+
* @param {Number} blur
|
|
837
|
+
* @returns {Number}
|
|
838
|
+
* @example
|
|
839
|
+
* // get shadow blur
|
|
840
|
+
* var shadowBlur = shape.shadowBlur();
|
|
841
|
+
*
|
|
842
|
+
* // set shadow blur
|
|
843
|
+
* shape.shadowBlur(10);
|
|
844
|
+
*/
|
|
490
845
|
Factory.addGetterSetter(Shape, 'shadowOpacity', 1, getNumberValidator());
|
|
846
|
+
/**
|
|
847
|
+
* get/set shadow opacity. must be a value between 0 and 1
|
|
848
|
+
* @name Konva.Shape#shadowOpacity
|
|
849
|
+
* @method
|
|
850
|
+
* @param {Number} opacity
|
|
851
|
+
* @returns {Number}
|
|
852
|
+
* @example
|
|
853
|
+
* // get shadow opacity
|
|
854
|
+
* var shadowOpacity = shape.shadowOpacity();
|
|
855
|
+
*
|
|
856
|
+
* // set shadow opacity
|
|
857
|
+
* shape.shadowOpacity(0.5);
|
|
858
|
+
*/
|
|
491
859
|
Factory.addComponentsGetterSetter(Shape, 'shadowOffset', ['x', 'y']);
|
|
860
|
+
/**
|
|
861
|
+
* get/set shadow offset
|
|
862
|
+
* @name Konva.Shape#shadowOffset
|
|
863
|
+
* @method
|
|
864
|
+
* @param {Object} offset
|
|
865
|
+
* @param {Number} offset.x
|
|
866
|
+
* @param {Number} offset.y
|
|
867
|
+
* @returns {Object}
|
|
868
|
+
* @example
|
|
869
|
+
* // get shadow offset
|
|
870
|
+
* var shadowOffset = shape.shadowOffset();
|
|
871
|
+
*
|
|
872
|
+
* // set shadow offset
|
|
873
|
+
* shape.shadowOffset({
|
|
874
|
+
* x: 20,
|
|
875
|
+
* y: 10
|
|
876
|
+
* });
|
|
877
|
+
*/
|
|
492
878
|
Factory.addGetterSetter(Shape, 'shadowOffsetX', 0, getNumberValidator());
|
|
879
|
+
/**
|
|
880
|
+
* get/set shadow offset x
|
|
881
|
+
* @name Konva.Shape#shadowOffsetX
|
|
882
|
+
* @method
|
|
883
|
+
* @param {Number} x
|
|
884
|
+
* @returns {Number}
|
|
885
|
+
* @example
|
|
886
|
+
* // get shadow offset x
|
|
887
|
+
* var shadowOffsetX = shape.shadowOffsetX();
|
|
888
|
+
*
|
|
889
|
+
* // set shadow offset x
|
|
890
|
+
* shape.shadowOffsetX(5);
|
|
891
|
+
*/
|
|
493
892
|
Factory.addGetterSetter(Shape, 'shadowOffsetY', 0, getNumberValidator());
|
|
893
|
+
/**
|
|
894
|
+
* get/set shadow offset y
|
|
895
|
+
* @name Konva.Shape#shadowOffsetY
|
|
896
|
+
* @method
|
|
897
|
+
* @param {Number} y
|
|
898
|
+
* @returns {Number}
|
|
899
|
+
* @example
|
|
900
|
+
* // get shadow offset y
|
|
901
|
+
* var shadowOffsetY = shape.shadowOffsetY();
|
|
902
|
+
*
|
|
903
|
+
* // set shadow offset y
|
|
904
|
+
* shape.shadowOffsetY(5);
|
|
905
|
+
*/
|
|
494
906
|
Factory.addGetterSetter(Shape, 'fillPatternImage');
|
|
907
|
+
/**
|
|
908
|
+
* get/set fill pattern image
|
|
909
|
+
* @name Konva.Shape#fillPatternImage
|
|
910
|
+
* @method
|
|
911
|
+
* @param {Image} image object
|
|
912
|
+
* @returns {Image}
|
|
913
|
+
* @example
|
|
914
|
+
* // get fill pattern image
|
|
915
|
+
* var fillPatternImage = shape.fillPatternImage();
|
|
916
|
+
*
|
|
917
|
+
* // set fill pattern image
|
|
918
|
+
* var imageObj = new Image();
|
|
919
|
+
* imageObj.onload = function() {
|
|
920
|
+
* shape.fillPatternImage(imageObj);
|
|
921
|
+
* };
|
|
922
|
+
* imageObj.src = 'path/to/image/jpg';
|
|
923
|
+
*/
|
|
495
924
|
Factory.addGetterSetter(Shape, 'fill', undefined, getStringOrGradientValidator());
|
|
925
|
+
/**
|
|
926
|
+
* get/set fill color
|
|
927
|
+
* @name Konva.Shape#fill
|
|
928
|
+
* @method
|
|
929
|
+
* @param {String} color
|
|
930
|
+
* @returns {String}
|
|
931
|
+
* @example
|
|
932
|
+
* // get fill color
|
|
933
|
+
* var fill = shape.fill();
|
|
934
|
+
*
|
|
935
|
+
* // set fill color with color string
|
|
936
|
+
* shape.fill('green');
|
|
937
|
+
*
|
|
938
|
+
* // set fill color with hex
|
|
939
|
+
* shape.fill('#00ff00');
|
|
940
|
+
*
|
|
941
|
+
* // set fill color with rgb
|
|
942
|
+
* shape.fill('rgb(0,255,0)');
|
|
943
|
+
*
|
|
944
|
+
* // set fill color with rgba and make it 50% opaque
|
|
945
|
+
* shape.fill('rgba(0,255,0,0.5');
|
|
946
|
+
*
|
|
947
|
+
* // shape without fill
|
|
948
|
+
* shape.fill(null);
|
|
949
|
+
*/
|
|
496
950
|
Factory.addGetterSetter(Shape, 'fillPatternX', 0, getNumberValidator());
|
|
951
|
+
/**
|
|
952
|
+
* get/set fill pattern x
|
|
953
|
+
* @name Konva.Shape#fillPatternX
|
|
954
|
+
* @method
|
|
955
|
+
* @param {Number} x
|
|
956
|
+
* @returns {Number}
|
|
957
|
+
* @example
|
|
958
|
+
* // get fill pattern x
|
|
959
|
+
* var fillPatternX = shape.fillPatternX();
|
|
960
|
+
* // set fill pattern x
|
|
961
|
+
* shape.fillPatternX(20);
|
|
962
|
+
*/
|
|
497
963
|
Factory.addGetterSetter(Shape, 'fillPatternY', 0, getNumberValidator());
|
|
964
|
+
/**
|
|
965
|
+
* get/set fill pattern y
|
|
966
|
+
* @name Konva.Shape#fillPatternY
|
|
967
|
+
* @method
|
|
968
|
+
* @param {Number} y
|
|
969
|
+
* @returns {Number}
|
|
970
|
+
* @example
|
|
971
|
+
* // get fill pattern y
|
|
972
|
+
* var fillPatternY = shape.fillPatternY();
|
|
973
|
+
* // set fill pattern y
|
|
974
|
+
* shape.fillPatternY(20);
|
|
975
|
+
*/
|
|
498
976
|
Factory.addGetterSetter(Shape, 'fillLinearGradientColorStops');
|
|
977
|
+
/**
|
|
978
|
+
* get/set fill linear gradient color stops
|
|
979
|
+
* @name Konva.Shape#fillLinearGradientColorStops
|
|
980
|
+
* @method
|
|
981
|
+
* @param {Array} colorStops
|
|
982
|
+
* @returns {Array} colorStops
|
|
983
|
+
* @example
|
|
984
|
+
* // get fill linear gradient color stops
|
|
985
|
+
* var colorStops = shape.fillLinearGradientColorStops();
|
|
986
|
+
*
|
|
987
|
+
* // create a linear gradient that starts with red, changes to blue
|
|
988
|
+
* // halfway through, and then changes to green
|
|
989
|
+
* shape.fillLinearGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
|
|
990
|
+
*/
|
|
499
991
|
Factory.addGetterSetter(Shape, 'strokeLinearGradientColorStops');
|
|
992
|
+
/**
|
|
993
|
+
* get/set stroke linear gradient color stops
|
|
994
|
+
* @name Konva.Shape#strokeLinearGradientColorStops
|
|
995
|
+
* @method
|
|
996
|
+
* @param {Array} colorStops
|
|
997
|
+
* @returns {Array} colorStops
|
|
998
|
+
* @example
|
|
999
|
+
* // get stroke linear gradient color stops
|
|
1000
|
+
* var colorStops = shape.strokeLinearGradientColorStops();
|
|
1001
|
+
*
|
|
1002
|
+
* // create a linear gradient that starts with red, changes to blue
|
|
1003
|
+
* // halfway through, and then changes to green
|
|
1004
|
+
* shape.strokeLinearGradientColorStops([0, 'red', 0.5, 'blue', 1, 'green']);
|
|
1005
|
+
*/
|
|
500
1006
|
Factory.addGetterSetter(Shape, 'fillRadialGradientStartRadius', 0);
|
|
1007
|
+
/**
|
|
1008
|
+
* get/set fill radial gradient start radius
|
|
1009
|
+
* @name Konva.Shape#fillRadialGradientStartRadius
|
|
1010
|
+
* @method
|
|
1011
|
+
* @param {Number} radius
|
|
1012
|
+
* @returns {Number}
|
|
1013
|
+
* @example
|
|
1014
|
+
* // get radial gradient start radius
|
|
1015
|
+
* var startRadius = shape.fillRadialGradientStartRadius();
|
|
1016
|
+
*
|
|
1017
|
+
* // set radial gradient start radius
|
|
1018
|
+
* shape.fillRadialGradientStartRadius(0);
|
|
1019
|
+
*/
|
|
501
1020
|
Factory.addGetterSetter(Shape, 'fillRadialGradientEndRadius', 0);
|
|
1021
|
+
/**
|
|
1022
|
+
* get/set fill radial gradient end radius
|
|
1023
|
+
* @name Konva.Shape#fillRadialGradientEndRadius
|
|
1024
|
+
* @method
|
|
1025
|
+
* @param {Number} radius
|
|
1026
|
+
* @returns {Number}
|
|
1027
|
+
* @example
|
|
1028
|
+
* // get radial gradient end radius
|
|
1029
|
+
* var endRadius = shape.fillRadialGradientEndRadius();
|
|
1030
|
+
*
|
|
1031
|
+
* // set radial gradient end radius
|
|
1032
|
+
* shape.fillRadialGradientEndRadius(100);
|
|
1033
|
+
*/
|
|
502
1034
|
Factory.addGetterSetter(Shape, 'fillRadialGradientColorStops');
|
|
1035
|
+
/**
|
|
1036
|
+
* get/set fill radial gradient color stops
|
|
1037
|
+
* @name Konva.Shape#fillRadialGradientColorStops
|
|
1038
|
+
* @method
|
|
1039
|
+
* @param {Number} colorStops
|
|
1040
|
+
* @returns {Array}
|
|
1041
|
+
* @example
|
|
1042
|
+
* // get fill radial gradient color stops
|
|
1043
|
+
* var colorStops = shape.fillRadialGradientColorStops();
|
|
1044
|
+
*
|
|
1045
|
+
* // create a radial gradient that starts with red, changes to blue
|
|
1046
|
+
* // halfway through, and then changes to green
|
|
1047
|
+
* shape.fillRadialGradientColorStops(0, 'red', 0.5, 'blue', 1, 'green');
|
|
1048
|
+
*/
|
|
503
1049
|
Factory.addGetterSetter(Shape, 'fillPatternRepeat', 'repeat');
|
|
1050
|
+
/**
|
|
1051
|
+
* get/set fill pattern repeat. Can be 'repeat', 'repeat-x', 'repeat-y', or 'no-repeat'. The default is 'repeat'
|
|
1052
|
+
* @name Konva.Shape#fillPatternRepeat
|
|
1053
|
+
* @method
|
|
1054
|
+
* @param {String} repeat
|
|
1055
|
+
* @returns {String}
|
|
1056
|
+
* @example
|
|
1057
|
+
* // get fill pattern repeat
|
|
1058
|
+
* var repeat = shape.fillPatternRepeat();
|
|
1059
|
+
*
|
|
1060
|
+
* // repeat pattern in x direction only
|
|
1061
|
+
* shape.fillPatternRepeat('repeat-x');
|
|
1062
|
+
*
|
|
1063
|
+
* // do not repeat the pattern
|
|
1064
|
+
* shape.fillPatternRepeat('no-repeat');
|
|
1065
|
+
*/
|
|
504
1066
|
Factory.addGetterSetter(Shape, 'fillEnabled', true);
|
|
1067
|
+
/**
|
|
1068
|
+
* get/set fill enabled flag
|
|
1069
|
+
* @name Konva.Shape#fillEnabled
|
|
1070
|
+
* @method
|
|
1071
|
+
* @param {Boolean} enabled
|
|
1072
|
+
* @returns {Boolean}
|
|
1073
|
+
* @example
|
|
1074
|
+
* // get fill enabled flag
|
|
1075
|
+
* var fillEnabled = shape.fillEnabled();
|
|
1076
|
+
*
|
|
1077
|
+
* // disable fill
|
|
1078
|
+
* shape.fillEnabled(false);
|
|
1079
|
+
*
|
|
1080
|
+
* // enable fill
|
|
1081
|
+
* shape.fillEnabled(true);
|
|
1082
|
+
*/
|
|
505
1083
|
Factory.addGetterSetter(Shape, 'strokeEnabled', true);
|
|
1084
|
+
/**
|
|
1085
|
+
* get/set stroke enabled flag
|
|
1086
|
+
* @name Konva.Shape#strokeEnabled
|
|
1087
|
+
* @method
|
|
1088
|
+
* @param {Boolean} enabled
|
|
1089
|
+
* @returns {Boolean}
|
|
1090
|
+
* @example
|
|
1091
|
+
* // get stroke enabled flag
|
|
1092
|
+
* var strokeEnabled = shape.strokeEnabled();
|
|
1093
|
+
*
|
|
1094
|
+
* // disable stroke
|
|
1095
|
+
* shape.strokeEnabled(false);
|
|
1096
|
+
*
|
|
1097
|
+
* // enable stroke
|
|
1098
|
+
* shape.strokeEnabled(true);
|
|
1099
|
+
*/
|
|
506
1100
|
Factory.addGetterSetter(Shape, 'shadowEnabled', true);
|
|
1101
|
+
/**
|
|
1102
|
+
* get/set shadow enabled flag
|
|
1103
|
+
* @name Konva.Shape#shadowEnabled
|
|
1104
|
+
* @method
|
|
1105
|
+
* @param {Boolean} enabled
|
|
1106
|
+
* @returns {Boolean}
|
|
1107
|
+
* @example
|
|
1108
|
+
* // get shadow enabled flag
|
|
1109
|
+
* var shadowEnabled = shape.shadowEnabled();
|
|
1110
|
+
*
|
|
1111
|
+
* // disable shadow
|
|
1112
|
+
* shape.shadowEnabled(false);
|
|
1113
|
+
*
|
|
1114
|
+
* // enable shadow
|
|
1115
|
+
* shape.shadowEnabled(true);
|
|
1116
|
+
*/
|
|
507
1117
|
Factory.addGetterSetter(Shape, 'dashEnabled', true);
|
|
1118
|
+
/**
|
|
1119
|
+
* get/set dash enabled flag
|
|
1120
|
+
* @name Konva.Shape#dashEnabled
|
|
1121
|
+
* @method
|
|
1122
|
+
* @param {Boolean} enabled
|
|
1123
|
+
* @returns {Boolean}
|
|
1124
|
+
* @example
|
|
1125
|
+
* // get dash enabled flag
|
|
1126
|
+
* var dashEnabled = shape.dashEnabled();
|
|
1127
|
+
*
|
|
1128
|
+
* // disable dash
|
|
1129
|
+
* shape.dashEnabled(false);
|
|
1130
|
+
*
|
|
1131
|
+
* // enable dash
|
|
1132
|
+
* shape.dashEnabled(true);
|
|
1133
|
+
*/
|
|
508
1134
|
Factory.addGetterSetter(Shape, 'strokeScaleEnabled', true);
|
|
1135
|
+
/**
|
|
1136
|
+
* get/set strokeScale enabled flag
|
|
1137
|
+
* @name Konva.Shape#strokeScaleEnabled
|
|
1138
|
+
* @method
|
|
1139
|
+
* @param {Boolean} enabled
|
|
1140
|
+
* @returns {Boolean}
|
|
1141
|
+
* @example
|
|
1142
|
+
* // get stroke scale enabled flag
|
|
1143
|
+
* var strokeScaleEnabled = shape.strokeScaleEnabled();
|
|
1144
|
+
*
|
|
1145
|
+
* // disable stroke scale
|
|
1146
|
+
* shape.strokeScaleEnabled(false);
|
|
1147
|
+
*
|
|
1148
|
+
* // enable stroke scale
|
|
1149
|
+
* shape.strokeScaleEnabled(true);
|
|
1150
|
+
*/
|
|
509
1151
|
Factory.addGetterSetter(Shape, 'fillPriority', 'color');
|
|
1152
|
+
/**
|
|
1153
|
+
* get/set fill priority. can be color, pattern, linear-gradient, or radial-gradient. The default is color.
|
|
1154
|
+
* This is handy if you want to toggle between different fill types.
|
|
1155
|
+
* @name Konva.Shape#fillPriority
|
|
1156
|
+
* @method
|
|
1157
|
+
* @param {String} priority
|
|
1158
|
+
* @returns {String}
|
|
1159
|
+
* @example
|
|
1160
|
+
* // get fill priority
|
|
1161
|
+
* var fillPriority = shape.fillPriority();
|
|
1162
|
+
*
|
|
1163
|
+
* // set fill priority
|
|
1164
|
+
* shape.fillPriority('linear-gradient');
|
|
1165
|
+
*/
|
|
510
1166
|
Factory.addComponentsGetterSetter(Shape, 'fillPatternOffset', ['x', 'y']);
|
|
1167
|
+
/**
|
|
1168
|
+
* get/set fill pattern offset
|
|
1169
|
+
* @name Konva.Shape#fillPatternOffset
|
|
1170
|
+
* @method
|
|
1171
|
+
* @param {Object} offset
|
|
1172
|
+
* @param {Number} offset.x
|
|
1173
|
+
* @param {Number} offset.y
|
|
1174
|
+
* @returns {Object}
|
|
1175
|
+
* @example
|
|
1176
|
+
* // get fill pattern offset
|
|
1177
|
+
* var patternOffset = shape.fillPatternOffset();
|
|
1178
|
+
*
|
|
1179
|
+
* // set fill pattern offset
|
|
1180
|
+
* shape.fillPatternOffset({
|
|
1181
|
+
* x: 20,
|
|
1182
|
+
* y: 10
|
|
1183
|
+
* });
|
|
1184
|
+
*/
|
|
511
1185
|
Factory.addGetterSetter(Shape, 'fillPatternOffsetX', 0, getNumberValidator());
|
|
1186
|
+
/**
|
|
1187
|
+
* get/set fill pattern offset x
|
|
1188
|
+
* @name Konva.Shape#fillPatternOffsetX
|
|
1189
|
+
* @method
|
|
1190
|
+
* @param {Number} x
|
|
1191
|
+
* @returns {Number}
|
|
1192
|
+
* @example
|
|
1193
|
+
* // get fill pattern offset x
|
|
1194
|
+
* var patternOffsetX = shape.fillPatternOffsetX();
|
|
1195
|
+
*
|
|
1196
|
+
* // set fill pattern offset x
|
|
1197
|
+
* shape.fillPatternOffsetX(20);
|
|
1198
|
+
*/
|
|
512
1199
|
Factory.addGetterSetter(Shape, 'fillPatternOffsetY', 0, getNumberValidator());
|
|
1200
|
+
/**
|
|
1201
|
+
* get/set fill pattern offset y
|
|
1202
|
+
* @name Konva.Shape#fillPatternOffsetY
|
|
1203
|
+
* @method
|
|
1204
|
+
* @param {Number} y
|
|
1205
|
+
* @returns {Number}
|
|
1206
|
+
* @example
|
|
1207
|
+
* // get fill pattern offset y
|
|
1208
|
+
* var patternOffsetY = shape.fillPatternOffsetY();
|
|
1209
|
+
*
|
|
1210
|
+
* // set fill pattern offset y
|
|
1211
|
+
* shape.fillPatternOffsetY(10);
|
|
1212
|
+
*/
|
|
513
1213
|
Factory.addComponentsGetterSetter(Shape, 'fillPatternScale', ['x', 'y']);
|
|
1214
|
+
/**
|
|
1215
|
+
* get/set fill pattern scale
|
|
1216
|
+
* @name Konva.Shape#fillPatternScale
|
|
1217
|
+
* @method
|
|
1218
|
+
* @param {Object} scale
|
|
1219
|
+
* @param {Number} scale.x
|
|
1220
|
+
* @param {Number} scale.y
|
|
1221
|
+
* @returns {Object}
|
|
1222
|
+
* @example
|
|
1223
|
+
* // get fill pattern scale
|
|
1224
|
+
* var patternScale = shape.fillPatternScale();
|
|
1225
|
+
*
|
|
1226
|
+
* // set fill pattern scale
|
|
1227
|
+
* shape.fillPatternScale({
|
|
1228
|
+
* x: 2,
|
|
1229
|
+
* y: 2
|
|
1230
|
+
* });
|
|
1231
|
+
*/
|
|
514
1232
|
Factory.addGetterSetter(Shape, 'fillPatternScaleX', 1, getNumberValidator());
|
|
1233
|
+
/**
|
|
1234
|
+
* get/set fill pattern scale x
|
|
1235
|
+
* @name Konva.Shape#fillPatternScaleX
|
|
1236
|
+
* @method
|
|
1237
|
+
* @param {Number} x
|
|
1238
|
+
* @returns {Number}
|
|
1239
|
+
* @example
|
|
1240
|
+
* // get fill pattern scale x
|
|
1241
|
+
* var patternScaleX = shape.fillPatternScaleX();
|
|
1242
|
+
*
|
|
1243
|
+
* // set fill pattern scale x
|
|
1244
|
+
* shape.fillPatternScaleX(2);
|
|
1245
|
+
*/
|
|
515
1246
|
Factory.addGetterSetter(Shape, 'fillPatternScaleY', 1, getNumberValidator());
|
|
1247
|
+
/**
|
|
1248
|
+
* get/set fill pattern scale y
|
|
1249
|
+
* @name Konva.Shape#fillPatternScaleY
|
|
1250
|
+
* @method
|
|
1251
|
+
* @param {Number} y
|
|
1252
|
+
* @returns {Number}
|
|
1253
|
+
* @example
|
|
1254
|
+
* // get fill pattern scale y
|
|
1255
|
+
* var patternScaleY = shape.fillPatternScaleY();
|
|
1256
|
+
*
|
|
1257
|
+
* // set fill pattern scale y
|
|
1258
|
+
* shape.fillPatternScaleY(2);
|
|
1259
|
+
*/
|
|
516
1260
|
Factory.addComponentsGetterSetter(Shape, 'fillLinearGradientStartPoint', [
|
|
517
1261
|
'x',
|
|
518
1262
|
'y',
|
|
519
1263
|
]);
|
|
1264
|
+
/**
|
|
1265
|
+
* get/set fill linear gradient start point
|
|
1266
|
+
* @name Konva.Shape#fillLinearGradientStartPoint
|
|
1267
|
+
* @method
|
|
1268
|
+
* @param {Object} startPoint
|
|
1269
|
+
* @param {Number} startPoint.x
|
|
1270
|
+
* @param {Number} startPoint.y
|
|
1271
|
+
* @returns {Object}
|
|
1272
|
+
* @example
|
|
1273
|
+
* // get fill linear gradient start point
|
|
1274
|
+
* var startPoint = shape.fillLinearGradientStartPoint();
|
|
1275
|
+
*
|
|
1276
|
+
* // set fill linear gradient start point
|
|
1277
|
+
* shape.fillLinearGradientStartPoint({
|
|
1278
|
+
* x: 20,
|
|
1279
|
+
* y: 10
|
|
1280
|
+
* });
|
|
1281
|
+
*/
|
|
520
1282
|
Factory.addComponentsGetterSetter(Shape, 'strokeLinearGradientStartPoint', [
|
|
521
1283
|
'x',
|
|
522
1284
|
'y',
|
|
523
1285
|
]);
|
|
1286
|
+
/**
|
|
1287
|
+
* get/set stroke linear gradient start point
|
|
1288
|
+
* @name Konva.Shape#strokeLinearGradientStartPoint
|
|
1289
|
+
* @method
|
|
1290
|
+
* @param {Object} startPoint
|
|
1291
|
+
* @param {Number} startPoint.x
|
|
1292
|
+
* @param {Number} startPoint.y
|
|
1293
|
+
* @returns {Object}
|
|
1294
|
+
* @example
|
|
1295
|
+
* // get stroke linear gradient start point
|
|
1296
|
+
* var startPoint = shape.strokeLinearGradientStartPoint();
|
|
1297
|
+
*
|
|
1298
|
+
* // set stroke linear gradient start point
|
|
1299
|
+
* shape.strokeLinearGradientStartPoint({
|
|
1300
|
+
* x: 20,
|
|
1301
|
+
* y: 10
|
|
1302
|
+
* });
|
|
1303
|
+
*/
|
|
524
1304
|
Factory.addGetterSetter(Shape, 'fillLinearGradientStartPointX', 0);
|
|
1305
|
+
/**
|
|
1306
|
+
* get/set fill linear gradient start point x
|
|
1307
|
+
* @name Konva.Shape#fillLinearGradientStartPointX
|
|
1308
|
+
* @method
|
|
1309
|
+
* @param {Number} x
|
|
1310
|
+
* @returns {Number}
|
|
1311
|
+
* @example
|
|
1312
|
+
* // get fill linear gradient start point x
|
|
1313
|
+
* var startPointX = shape.fillLinearGradientStartPointX();
|
|
1314
|
+
*
|
|
1315
|
+
* // set fill linear gradient start point x
|
|
1316
|
+
* shape.fillLinearGradientStartPointX(20);
|
|
1317
|
+
*/
|
|
525
1318
|
Factory.addGetterSetter(Shape, 'strokeLinearGradientStartPointX', 0);
|
|
1319
|
+
/**
|
|
1320
|
+
* get/set stroke linear gradient start point x
|
|
1321
|
+
* @name Konva.Shape#strokeLinearGradientStartPointX
|
|
1322
|
+
* @method
|
|
1323
|
+
* @param {Number} x
|
|
1324
|
+
* @returns {Number}
|
|
1325
|
+
* @example
|
|
1326
|
+
* // get stroke linear gradient start point x
|
|
1327
|
+
* var startPointX = shape.strokeLinearGradientStartPointX();
|
|
1328
|
+
*
|
|
1329
|
+
* // set stroke linear gradient start point x
|
|
1330
|
+
* shape.strokeLinearGradientStartPointX(20);
|
|
1331
|
+
*/
|
|
526
1332
|
Factory.addGetterSetter(Shape, 'fillLinearGradientStartPointY', 0);
|
|
1333
|
+
/**
|
|
1334
|
+
* get/set fill linear gradient start point y
|
|
1335
|
+
* @name Konva.Shape#fillLinearGradientStartPointY
|
|
1336
|
+
* @method
|
|
1337
|
+
* @param {Number} y
|
|
1338
|
+
* @returns {Number}
|
|
1339
|
+
* @example
|
|
1340
|
+
* // get fill linear gradient start point y
|
|
1341
|
+
* var startPointY = shape.fillLinearGradientStartPointY();
|
|
1342
|
+
*
|
|
1343
|
+
* // set fill linear gradient start point y
|
|
1344
|
+
* shape.fillLinearGradientStartPointY(20);
|
|
1345
|
+
*/
|
|
527
1346
|
Factory.addGetterSetter(Shape, 'strokeLinearGradientStartPointY', 0);
|
|
1347
|
+
/**
|
|
1348
|
+
* get/set stroke linear gradient start point y
|
|
1349
|
+
* @name Konva.Shape#strokeLinearGradientStartPointY
|
|
1350
|
+
* @method
|
|
1351
|
+
* @param {Number} y
|
|
1352
|
+
* @returns {Number}
|
|
1353
|
+
* @example
|
|
1354
|
+
* // get stroke linear gradient start point y
|
|
1355
|
+
* var startPointY = shape.strokeLinearGradientStartPointY();
|
|
1356
|
+
*
|
|
1357
|
+
* // set stroke linear gradient start point y
|
|
1358
|
+
* shape.strokeLinearGradientStartPointY(20);
|
|
1359
|
+
*/
|
|
528
1360
|
Factory.addComponentsGetterSetter(Shape, 'fillLinearGradientEndPoint', [
|
|
529
1361
|
'x',
|
|
530
1362
|
'y',
|
|
531
1363
|
]);
|
|
1364
|
+
/**
|
|
1365
|
+
* get/set fill linear gradient end point
|
|
1366
|
+
* @name Konva.Shape#fillLinearGradientEndPoint
|
|
1367
|
+
* @method
|
|
1368
|
+
* @param {Object} endPoint
|
|
1369
|
+
* @param {Number} endPoint.x
|
|
1370
|
+
* @param {Number} endPoint.y
|
|
1371
|
+
* @returns {Object}
|
|
1372
|
+
* @example
|
|
1373
|
+
* // get fill linear gradient end point
|
|
1374
|
+
* var endPoint = shape.fillLinearGradientEndPoint();
|
|
1375
|
+
*
|
|
1376
|
+
* // set fill linear gradient end point
|
|
1377
|
+
* shape.fillLinearGradientEndPoint({
|
|
1378
|
+
* x: 20,
|
|
1379
|
+
* y: 10
|
|
1380
|
+
* });
|
|
1381
|
+
*/
|
|
532
1382
|
Factory.addComponentsGetterSetter(Shape, 'strokeLinearGradientEndPoint', [
|
|
533
1383
|
'x',
|
|
534
1384
|
'y',
|
|
535
1385
|
]);
|
|
1386
|
+
/**
|
|
1387
|
+
* get/set stroke linear gradient end point
|
|
1388
|
+
* @name Konva.Shape#strokeLinearGradientEndPoint
|
|
1389
|
+
* @method
|
|
1390
|
+
* @param {Object} endPoint
|
|
1391
|
+
* @param {Number} endPoint.x
|
|
1392
|
+
* @param {Number} endPoint.y
|
|
1393
|
+
* @returns {Object}
|
|
1394
|
+
* @example
|
|
1395
|
+
* // get stroke linear gradient end point
|
|
1396
|
+
* var endPoint = shape.strokeLinearGradientEndPoint();
|
|
1397
|
+
*
|
|
1398
|
+
* // set stroke linear gradient end point
|
|
1399
|
+
* shape.strokeLinearGradientEndPoint({
|
|
1400
|
+
* x: 20,
|
|
1401
|
+
* y: 10
|
|
1402
|
+
* });
|
|
1403
|
+
*/
|
|
536
1404
|
Factory.addGetterSetter(Shape, 'fillLinearGradientEndPointX', 0);
|
|
1405
|
+
/**
|
|
1406
|
+
* get/set fill linear gradient end point x
|
|
1407
|
+
* @name Konva.Shape#fillLinearGradientEndPointX
|
|
1408
|
+
* @method
|
|
1409
|
+
* @param {Number} x
|
|
1410
|
+
* @returns {Number}
|
|
1411
|
+
* @example
|
|
1412
|
+
* // get fill linear gradient end point x
|
|
1413
|
+
* var endPointX = shape.fillLinearGradientEndPointX();
|
|
1414
|
+
*
|
|
1415
|
+
* // set fill linear gradient end point x
|
|
1416
|
+
* shape.fillLinearGradientEndPointX(20);
|
|
1417
|
+
*/
|
|
537
1418
|
Factory.addGetterSetter(Shape, 'strokeLinearGradientEndPointX', 0);
|
|
1419
|
+
/**
|
|
1420
|
+
* get/set fill linear gradient end point x
|
|
1421
|
+
* @name Konva.Shape#strokeLinearGradientEndPointX
|
|
1422
|
+
* @method
|
|
1423
|
+
* @param {Number} x
|
|
1424
|
+
* @returns {Number}
|
|
1425
|
+
* @example
|
|
1426
|
+
* // get stroke linear gradient end point x
|
|
1427
|
+
* var endPointX = shape.strokeLinearGradientEndPointX();
|
|
1428
|
+
*
|
|
1429
|
+
* // set stroke linear gradient end point x
|
|
1430
|
+
* shape.strokeLinearGradientEndPointX(20);
|
|
1431
|
+
*/
|
|
538
1432
|
Factory.addGetterSetter(Shape, 'fillLinearGradientEndPointY', 0);
|
|
1433
|
+
/**
|
|
1434
|
+
* get/set fill linear gradient end point y
|
|
1435
|
+
* @name Konva.Shape#fillLinearGradientEndPointY
|
|
1436
|
+
* @method
|
|
1437
|
+
* @param {Number} y
|
|
1438
|
+
* @returns {Number}
|
|
1439
|
+
* @example
|
|
1440
|
+
* // get fill linear gradient end point y
|
|
1441
|
+
* var endPointY = shape.fillLinearGradientEndPointY();
|
|
1442
|
+
*
|
|
1443
|
+
* // set fill linear gradient end point y
|
|
1444
|
+
* shape.fillLinearGradientEndPointY(20);
|
|
1445
|
+
*/
|
|
539
1446
|
Factory.addGetterSetter(Shape, 'strokeLinearGradientEndPointY', 0);
|
|
1447
|
+
/**
|
|
1448
|
+
* get/set stroke linear gradient end point y
|
|
1449
|
+
* @name Konva.Shape#strokeLinearGradientEndPointY
|
|
1450
|
+
* @method
|
|
1451
|
+
* @param {Number} y
|
|
1452
|
+
* @returns {Number}
|
|
1453
|
+
* @example
|
|
1454
|
+
* // get stroke linear gradient end point y
|
|
1455
|
+
* var endPointY = shape.strokeLinearGradientEndPointY();
|
|
1456
|
+
*
|
|
1457
|
+
* // set stroke linear gradient end point y
|
|
1458
|
+
* shape.strokeLinearGradientEndPointY(20);
|
|
1459
|
+
*/
|
|
540
1460
|
Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientStartPoint', [
|
|
541
1461
|
'x',
|
|
542
1462
|
'y',
|
|
543
1463
|
]);
|
|
1464
|
+
/**
|
|
1465
|
+
* get/set fill radial gradient start point
|
|
1466
|
+
* @name Konva.Shape#fillRadialGradientStartPoint
|
|
1467
|
+
* @method
|
|
1468
|
+
* @param {Object} startPoint
|
|
1469
|
+
* @param {Number} startPoint.x
|
|
1470
|
+
* @param {Number} startPoint.y
|
|
1471
|
+
* @returns {Object}
|
|
1472
|
+
* @example
|
|
1473
|
+
* // get fill radial gradient start point
|
|
1474
|
+
* var startPoint = shape.fillRadialGradientStartPoint();
|
|
1475
|
+
*
|
|
1476
|
+
* // set fill radial gradient start point
|
|
1477
|
+
* shape.fillRadialGradientStartPoint({
|
|
1478
|
+
* x: 20,
|
|
1479
|
+
* y: 10
|
|
1480
|
+
* });
|
|
1481
|
+
*/
|
|
544
1482
|
Factory.addGetterSetter(Shape, 'fillRadialGradientStartPointX', 0);
|
|
1483
|
+
/**
|
|
1484
|
+
* get/set fill radial gradient start point x
|
|
1485
|
+
* @name Konva.Shape#fillRadialGradientStartPointX
|
|
1486
|
+
* @method
|
|
1487
|
+
* @param {Number} x
|
|
1488
|
+
* @returns {Number}
|
|
1489
|
+
* @example
|
|
1490
|
+
* // get fill radial gradient start point x
|
|
1491
|
+
* var startPointX = shape.fillRadialGradientStartPointX();
|
|
1492
|
+
*
|
|
1493
|
+
* // set fill radial gradient start point x
|
|
1494
|
+
* shape.fillRadialGradientStartPointX(20);
|
|
1495
|
+
*/
|
|
545
1496
|
Factory.addGetterSetter(Shape, 'fillRadialGradientStartPointY', 0);
|
|
1497
|
+
/**
|
|
1498
|
+
* get/set fill radial gradient start point y
|
|
1499
|
+
* @name Konva.Shape#fillRadialGradientStartPointY
|
|
1500
|
+
* @method
|
|
1501
|
+
* @param {Number} y
|
|
1502
|
+
* @returns {Number}
|
|
1503
|
+
* @example
|
|
1504
|
+
* // get fill radial gradient start point y
|
|
1505
|
+
* var startPointY = shape.fillRadialGradientStartPointY();
|
|
1506
|
+
*
|
|
1507
|
+
* // set fill radial gradient start point y
|
|
1508
|
+
* shape.fillRadialGradientStartPointY(20);
|
|
1509
|
+
*/
|
|
546
1510
|
Factory.addComponentsGetterSetter(Shape, 'fillRadialGradientEndPoint', [
|
|
547
1511
|
'x',
|
|
548
1512
|
'y',
|
|
549
1513
|
]);
|
|
1514
|
+
/**
|
|
1515
|
+
* get/set fill radial gradient end point
|
|
1516
|
+
* @name Konva.Shape#fillRadialGradientEndPoint
|
|
1517
|
+
* @method
|
|
1518
|
+
* @param {Object} endPoint
|
|
1519
|
+
* @param {Number} endPoint.x
|
|
1520
|
+
* @param {Number} endPoint.y
|
|
1521
|
+
* @returns {Object}
|
|
1522
|
+
* @example
|
|
1523
|
+
* // get fill radial gradient end point
|
|
1524
|
+
* var endPoint = shape.fillRadialGradientEndPoint();
|
|
1525
|
+
*
|
|
1526
|
+
* // set fill radial gradient end point
|
|
1527
|
+
* shape.fillRadialGradientEndPoint({
|
|
1528
|
+
* x: 20,
|
|
1529
|
+
* y: 10
|
|
1530
|
+
* });
|
|
1531
|
+
*/
|
|
550
1532
|
Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointX', 0);
|
|
1533
|
+
/**
|
|
1534
|
+
* get/set fill radial gradient end point x
|
|
1535
|
+
* @name Konva.Shape#fillRadialGradientEndPointX
|
|
1536
|
+
* @method
|
|
1537
|
+
* @param {Number} x
|
|
1538
|
+
* @returns {Number}
|
|
1539
|
+
* @example
|
|
1540
|
+
* // get fill radial gradient end point x
|
|
1541
|
+
* var endPointX = shape.fillRadialGradientEndPointX();
|
|
1542
|
+
*
|
|
1543
|
+
* // set fill radial gradient end point x
|
|
1544
|
+
* shape.fillRadialGradientEndPointX(20);
|
|
1545
|
+
*/
|
|
551
1546
|
Factory.addGetterSetter(Shape, 'fillRadialGradientEndPointY', 0);
|
|
1547
|
+
/**
|
|
1548
|
+
* get/set fill radial gradient end point y
|
|
1549
|
+
* @name Konva.Shape#fillRadialGradientEndPointY
|
|
1550
|
+
* @method
|
|
1551
|
+
* @param {Number} y
|
|
1552
|
+
* @returns {Number}
|
|
1553
|
+
* @example
|
|
1554
|
+
* // get fill radial gradient end point y
|
|
1555
|
+
* var endPointY = shape.fillRadialGradientEndPointY();
|
|
1556
|
+
*
|
|
1557
|
+
* // set fill radial gradient end point y
|
|
1558
|
+
* shape.fillRadialGradientEndPointY(20);
|
|
1559
|
+
*/
|
|
552
1560
|
Factory.addGetterSetter(Shape, 'fillPatternRotation', 0);
|
|
1561
|
+
/**
|
|
1562
|
+
* get/set fill pattern rotation in degrees
|
|
1563
|
+
* @name Konva.Shape#fillPatternRotation
|
|
1564
|
+
* @method
|
|
1565
|
+
* @param {Number} rotation
|
|
1566
|
+
* @returns {Konva.Shape}
|
|
1567
|
+
* @example
|
|
1568
|
+
* // get fill pattern rotation
|
|
1569
|
+
* var patternRotation = shape.fillPatternRotation();
|
|
1570
|
+
*
|
|
1571
|
+
* // set fill pattern rotation
|
|
1572
|
+
* shape.fillPatternRotation(20);
|
|
1573
|
+
*/
|
|
553
1574
|
Factory.addGetterSetter(Shape, 'fillRule', undefined, getStringValidator());
|
|
1575
|
+
/**
|
|
1576
|
+
* get/set fill rule
|
|
1577
|
+
* @name Konva.Shape#fillRule
|
|
1578
|
+
* @method
|
|
1579
|
+
* @param {CanvasFillRule} rotation
|
|
1580
|
+
* @returns {Konva.Shape}
|
|
1581
|
+
* @example
|
|
1582
|
+
* // get fill rule
|
|
1583
|
+
* var fillRule = shape.fillRule();
|
|
1584
|
+
*
|
|
1585
|
+
* // set fill rule
|
|
1586
|
+
* shape.fillRule('evenodd');
|
|
1587
|
+
*/
|
|
554
1588
|
Factory.backCompat(Shape, {
|
|
555
1589
|
dashArray: 'dash',
|
|
556
1590
|
getDashArray: 'getDash',
|
|
557
|
-
setDashArray: '
|
|
1591
|
+
setDashArray: 'setDash',
|
|
558
1592
|
drawFunc: 'sceneFunc',
|
|
559
1593
|
getDrawFunc: 'getSceneFunc',
|
|
560
1594
|
setDrawFunc: 'setSceneFunc',
|