Skip to content

Default color doesn't take into account transparency #29

@Azeirah

Description

@Azeirah
var color = Spectra("rgba(255, 0, 0, 0.5)");

ctx.fillStyle = color;
console.log(Spectra(ctx.fillStyle).rgbaString()); // rgba(255,0,0,1)

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:

function l(c) {
    ctx.fillStyle = c;
    console.log(Spectra(ctx.fillStyle).rgbaString());
}

var c1 = Spectra("rgb(255, 0,  0)");
var c2 = Spectra("hsl(120, 100%, 50%)");
var c3 = Spectra("rgba(255, 0, 0, 0.5)");
l(c1); // "rgb(255, 0, 0)"
l(c2); // "hsl(120, 100%, 50%)");
l(c3); // "rgba(255, 0, 0, 0.5)");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions