clean up some methods

This commit is contained in:
Anton Lavrenov 2019-01-21 21:22:36 -05:00
parent 3a89a7a0c1
commit 41a46c8afe
7 changed files with 1343 additions and 170 deletions

View File

@ -15,6 +15,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Removed
* `Konva.Util.addMethods`
* `Konva.Util._removeLastLetter`
* `Konva.Util._getImage`
* `Konv.Util._getRGBAString`
### Fixed

1410
konva.js

File diff suppressed because it is too large Load Diff

2
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1740,7 +1740,7 @@ export abstract class Node {
}
var callback = config.callback;
delete config.callback;
Util._getImage(this.toDataURL(config), function(img) {
Util._urlToImage(this.toDataURL(config), function(img) {
callback(img);
});
}

View File

@ -13,8 +13,6 @@ export interface RectConf {
height: number;
}
// TODO: document collection and give examples
/**
* Collection constructor. Collection extends Array.
* This class is used in conjunction with {@link Konva.Container#find}
@ -590,44 +588,15 @@ export const Util = {
* arg can be an image object or image data
*/
// TODO: use it only for data url
_getImage(arg, callback) {
var imageObj, canvas;
_urlToImage(url, callback) {
var imageObj;
// if arg is null or undefined
if (!arg) {
callback(null);
} else if (this._isElement(arg)) {
// if arg is already an image object
callback(arg);
} else if (this._isString(arg)) {
// if arg is a string, then it's a data url
imageObj = new glob.Image();
imageObj.onload = function() {
callback(imageObj);
};
imageObj.src = arg;
} else if (arg.data) {
//if arg is an object that contains the data property, it's an image object
canvas = Util.createCanvasElement();
canvas.width = arg.width;
canvas.height = arg.height;
var _context = canvas.getContext(CONTEXT_2D);
_context.putImageData(arg, 0, 0);
this._getImage(canvas.toDataURL(), callback);
} else {
callback(null);
}
},
// TODO: remove
_getRGBAString(obj) {
var red = obj.red || 0,
green = obj.green || 0,
blue = obj.blue || 0,
alpha = obj.alpha || 1;
return ['rgba(', red, ',', green, ',', blue, ',', alpha, ')'].join(
EMPTY_STRING
);
imageObj.src = url;
},
_rgbToHex(r, g, b) {
return ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);

View File

@ -1,5 +1,8 @@
import * as Konva from './internals';
// add Konva to global viriable
// umd build will actually do it
// but it may now it case of modules and bundlers
Konva.glob.Konva = Konva;
export default Konva;

View File

@ -5,43 +5,6 @@ suite('Util', function() {
assert.equal(Konva.Util.get(undefined, { foo: 'bar' }).foo, 'bar');
});
test('test _getRGBString()', function() {
assert.equal(Konva.Util._getRGBAString({}), 'rgba(0,0,0,1)');
assert.equal(
Konva.Util._getRGBAString({
red: 100,
green: 150,
blue: 200,
alpha: 0.5
}),
'rgba(100,150,200,0.5)'
);
});
test('test colorToRGBA', function() {
assert.deepEqual(Konva.Util.colorToRGBA('black'), {
r: 0,
g: 0,
b: 0,
a: 1
});
assert.deepEqual(Konva.Util.colorToRGBA('#ffcc00'), {
r: 255,
g: 204,
b: 0,
a: 1
});
assert.deepEqual(Konva.Util.colorToRGBA(), {
r: 0,
g: 0,
b: 0,
a: 1
});
});
test('test _prepareToStringify', function() {
var o = {
a: 1,