Merge branch 'master' of github.com:konvajs/konva

This commit is contained in:
Anton Lavrenov 2018-08-09 12:31:48 +07:00
commit b518ae0dac
3 changed files with 47 additions and 10 deletions

1
konva.d.ts vendored
View File

@ -956,6 +956,7 @@ declare namespace Konva {
animations: any; animations: any;
frameIndex?: number; frameIndex?: number;
image: HTMLImageElement; image: HTMLImageElement;
frameRate?: number;
} }
class Sprite extends Shape { class Sprite extends Shape {

View File

@ -10,6 +10,7 @@
* @param {Object} config.animations animation map * @param {Object} config.animations animation map
* @param {Integer} [config.frameIndex] animation frame index * @param {Integer} [config.frameIndex] animation frame index
* @param {Image} config.image image object * @param {Image} config.image image object
* @param {Integer} [config.frameRate] animation frame rate
* @@shapeParams * @@shapeParams
* @@nodeParams * @@nodeParams
* @example * @example

View File

@ -1,12 +1,10 @@
(function(Konva) { (function(Konva) {
'use strict'; 'use strict';
var BASE_BOX_WIDTH = 10;
var BASE_BOX_HEIGHT = 10;
var ATTR_CHANGE_LIST = [ var ATTR_CHANGE_LIST = [
'resizeEnabledChange', 'resizeEnabledChange',
'rotateHandlerOffsetChange' 'rotateHandlerOffsetChange',
'anchorSizeChange'
].join(' '); ].join(' ');
var NODE_RECT = 'nodeRect'; var NODE_RECT = 'nodeRect';
@ -114,6 +112,7 @@
* @param {Boolean} [config.keepRatio] Should we keep ratio when we are moving edges? Default is true * @param {Boolean} [config.keepRatio] Should we keep ratio when we are moving edges? Default is true
* @param {Array} [config.enabledHandlers] Array of names of enabled handles * @param {Array} [config.enabledHandlers] Array of names of enabled handles
* @param {Function} [config.boundBoxFunc] Bounding box function * @param {Function} [config.boundBoxFunc] Bounding box function
* @param {Number} [config.anchorSize] Default is 10
* @example * @example
* var transformer = new Konva.Transformer({ * var transformer = new Konva.Transformer({
* node: rectangle, * node: rectangle,
@ -297,11 +296,7 @@
stroke: 'rgb(0, 161, 255)', stroke: 'rgb(0, 161, 255)',
fill: 'white', fill: 'white',
strokeWidth: 1, strokeWidth: 1,
name: name, name: name + ' _anchor',
width: BASE_BOX_WIDTH,
height: BASE_BOX_HEIGHT,
offsetX: BASE_BOX_WIDTH / 2,
offsetY: BASE_BOX_HEIGHT / 2,
dragDistance: 0, dragDistance: 0,
draggable: true draggable: true
}); });
@ -387,7 +382,7 @@
}, },
_handleMouseDown: function(e) { _handleMouseDown: function(e) {
this.movingResizer = e.target.name(); this.movingResizer = e.target.name().split(' ')[0];
// var node = this.getNode(); // var node = this.getNode();
var attrs = this._getNodeRect(); var attrs = this._getNodeRect();
@ -672,6 +667,14 @@
var resizeEnabled = this.resizeEnabled(); var resizeEnabled = this.resizeEnabled();
var padding = this.getPadding(); var padding = this.getPadding();
var anchorSize = this.getAnchorSize();
this.find('._anchor').setAttrs({
width: anchorSize,
height: anchorSize,
offsetX: anchorSize / 2,
offsetY: anchorSize / 2
});
this.findOne('.top-left').setAttrs({ this.findOne('.top-left').setAttrs({
x: -padding, x: -padding,
y: -padding, y: -padding,
@ -826,6 +829,38 @@
*/ */
Konva.Factory.addGetterSetter(Konva.Transformer, 'resizeEnabled', true); Konva.Factory.addGetterSetter(Konva.Transformer, 'resizeEnabled', true);
function validateAnchors(val) {
if (isNaN(val)) {
Konva.Util.warn('anchorSize value should be a Number');
}
if (val < 10) {
Konva.Util.warn('Anchor must be a minimum of 10');
return 10;
}
return val;
}
/**
* get/set anchor size. Default is 10
* @name validateAnchors
* @method
* @memberof Konva.Transformer.prototype
* @param {Number} 10
* @returns {Number}
* @example
* // get
* var anchorSize = transformer.anchorSize();
*
* // set
* transformer.anchorSize(20)
*/
Konva.Factory.addGetterSetter(
Konva.Transformer,
'anchorSize',
10,
validateAnchors
);
/** /**
* get/set ability to rotate. * get/set ability to rotate.
* @name rotateEnabled * @name rotateEnabled