mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Add color object to accept array of rgb(a)
This commit is contained in:
parent
15dd95c15c
commit
010cadb6f1
18
dist/html2canvas.js
vendored
18
dist/html2canvas.js
vendored
@ -826,7 +826,8 @@ function Color(value) {
|
||||
this.g = 0;
|
||||
this.b = 0;
|
||||
this.a = null;
|
||||
var result = this.namedColor(value) ||
|
||||
var result = this.fromArray(value) ||
|
||||
this.namedColor(value) ||
|
||||
this.rgb(value) ||
|
||||
this.rgba(value) ||
|
||||
this.hex6(value) ||
|
||||
@ -837,6 +838,19 @@ Color.prototype.isTransparent = function() {
|
||||
return this.a === 0;
|
||||
};
|
||||
|
||||
Color.prototype.fromArray = function(array) {
|
||||
if (Array.isArray(array)) {
|
||||
this.r = array[0];
|
||||
this.g = array[1];
|
||||
this.b = array[2];
|
||||
if (array.length > 3) {
|
||||
this.a = array[3];
|
||||
}
|
||||
}
|
||||
|
||||
return (Array.isArray(array));
|
||||
};
|
||||
|
||||
var _hex3 = /^#([a-f0-9]{3})$/i;
|
||||
|
||||
Color.prototype.hex3 = function(value) {
|
||||
@ -888,7 +902,7 @@ Color.prototype.rgba = function(value) {
|
||||
};
|
||||
|
||||
Color.prototype.toString = function() {
|
||||
return this.a !== null ?
|
||||
return this.a !== null && this.a !== 1 ?
|
||||
"rgba(" + [this.r, this.g, this.b, this.a].join(",") + ")" :
|
||||
"rgb(" + [this.r, this.g, this.b].join(",") + ")";
|
||||
};
|
||||
|
2
dist/html2canvas.min.js
vendored
2
dist/html2canvas.min.js
vendored
File diff suppressed because one or more lines are too long
18
src/color.js
18
src/color.js
@ -5,7 +5,8 @@ function Color(value) {
|
||||
this.g = 0;
|
||||
this.b = 0;
|
||||
this.a = null;
|
||||
var result = this.namedColor(value) ||
|
||||
var result = this.fromArray(value) ||
|
||||
this.namedColor(value) ||
|
||||
this.rgb(value) ||
|
||||
this.rgba(value) ||
|
||||
this.hex6(value) ||
|
||||
@ -16,6 +17,19 @@ Color.prototype.isTransparent = function() {
|
||||
return this.a === 0;
|
||||
};
|
||||
|
||||
Color.prototype.fromArray = function(array) {
|
||||
if (Array.isArray(array)) {
|
||||
this.r = array[0];
|
||||
this.g = array[1];
|
||||
this.b = array[2];
|
||||
if (array.length > 3) {
|
||||
this.a = array[3];
|
||||
}
|
||||
}
|
||||
|
||||
return (Array.isArray(array));
|
||||
};
|
||||
|
||||
var _hex3 = /^#([a-f0-9]{3})$/i;
|
||||
|
||||
Color.prototype.hex3 = function(value) {
|
||||
@ -67,7 +81,7 @@ Color.prototype.rgba = function(value) {
|
||||
};
|
||||
|
||||
Color.prototype.toString = function() {
|
||||
return this.a !== null ?
|
||||
return this.a !== null && this.a !== 1 ?
|
||||
"rgba(" + [this.r, this.g, this.b, this.a].join(",") + ")" :
|
||||
"rgb(" + [this.r, this.g, this.b].join(",") + ")";
|
||||
};
|
||||
|
@ -86,6 +86,26 @@
|
||||
});
|
||||
});
|
||||
|
||||
describe("from array", function() {
|
||||
it("[1,2,3]", function () {
|
||||
var c = new Color([1,2,3]);
|
||||
assertColor(c, 1, 2, 3, null);
|
||||
expect(c.isTransparent()).to.equal(false);
|
||||
});
|
||||
|
||||
it("[5,6,7,1]", function () {
|
||||
var c = new Color([5,6,7, 1]);
|
||||
assertColor(c, 5, 6, 7, 1);
|
||||
expect(c.isTransparent()).to.equal(false);
|
||||
});
|
||||
|
||||
it("[5,6,7,0]", function () {
|
||||
var c = new Color([5,6,7, 0]);
|
||||
assertColor(c, 5, 6, 7, 0);
|
||||
expect(c.isTransparent()).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transparency", function() {
|
||||
it("transparent", function () {
|
||||
var c = new Color("transparent");
|
||||
|
Loading…
x
Reference in New Issue
Block a user