Permalink
Browse files

Merge pull request #345 from nvh/feature/fix-color-conversion-in-states

Feature/fix color conversion in states
  • Loading branch information...
koenbok committed Apr 19, 2016
2 parents dc4d622 + 41a7c08 commit c1d403ff0a42286e55678cc101ee9882dd7c0749
Showing with 15 additions and 3 deletions.
  1. +4 −3 framer/Color.coffee
  2. +11 −0 test/tests/ColorTest.coffee
@@ -1,3 +1,4 @@
{_} = require "./Underscore"
{BaseClass} = require "./BaseClass"
libhusl = require "husl"
@@ -67,7 +68,7 @@ class exports.Color extends BaseClass
g: Math.round(@_g)
b: Math.round(@_b)
a: @_a
return @_rgb
return _.clone(@_rgb)
toRgbString: ->
if @_a == 1 then "rgb(#{Utils.round(@_r, 0)}, #{Utils.round(@_g, 0)}, #{Utils.round(@_b, 0)})"
@@ -80,15 +81,15 @@ class exports.Color extends BaseClass
s: @s
l: @l
a: @a
return @_hsl
return _.clone(@_hsl)
toHusl: ->
if @_husl == undefined
c = libhusl._conv
husl = c.lch.husl c.luv.lch c.xyz.luv c.rgb.xyz([@r/255, @g/255, @b/255])
@_husl = { h: husl[0], s: husl[1], l: husl[2] }
return @_husl
return _.clone(@_husl)
toHslString: ->
if @_hslString == undefined
@@ -56,6 +56,17 @@ describe "Color", ->
mix.g.should.equal 255
mix.b.should.equal 255
describe "when changing the color", ->
testModifyFunction = (f) ->
it "with #{f}, it should not change the instance it is applied to", ->
color = new Color(10, 20, 30, 1)
first = color[f](10)
second = color[f](10)
first.isEqual(second).should.be.true
for f in ['lighten','brighten','darken','desaturate','saturate','grayscale']
testModifyFunction(f)
it "should brighten color", ->
orange = new Color "orange"

0 comments on commit c1d403f

Please sign in to comment.