Open Azeirah opened 7 years ago
I can't reproduce this; when I try that first statement (with ctx set to {}
), I get the correct output.
@avg Oh it might actually be that I'm running an older version, I'll get back to you in a bit.
@avp The version was not the problem. It's important that you use an actual ctx, since assigning a Spectra color to the ctx calls .toString on that object because it expects a string, doing the same but with a plain object doesn't call toString, since nesting objects is perfectly valid.
See the following two examples, that illustrate the problem even on the currently most recent Spectra v0.2.4. The transparency of the color is definitely lost in interpretation, which is not nice :(
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
var color = Spectra("rgba(255, 0, 0, 0.5)");
ctx.strokeStyle = color;
console.log(ctx.strokeStyle); // expect "rgba(255,0,0,0.5)"
var color = Spectra("rgba(255, 0, 0, 0.5)");
console.log(color.toString()); // expect "rgba(255,0,0,0.5)"
I would expect the last statement to print "rgba(255,0,0,0.5)".
By far the easiest fix would be to let .toString() equal .rgbaString(). A slightly more sophisticated fix would be to let .toString equal the input type: