Skip to content

Commit

Permalink
Add check for stop-color in inline styles
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrodin committed Nov 10, 2017
1 parent 1582d33 commit 9c4f2d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 7 additions & 6 deletions index.js
Expand Up @@ -34,17 +34,18 @@ module.exports = function getSvgColors(input, options) {
return color($(this).attr('stroke'))
}).get()

// Find `fill` and `stroke` within inline styles
$('[style]').each(function (i, el) {
fills.push(color($(this).css('fill')))
strokes.push(color($(this).css('stroke')))
})

// Find elements with a `stop-color` attribute (gradients)
var stops = $('[stop-color]').map(function (i, el) {
return color($(this).attr('stop-color'))
}).get()

// Find `fill`, `stroke` and `stops` within inline styles
$('[style]').each(function (i, el) {
fills.push(color($(this).css('fill')))
strokes.push(color($(this).css('stroke')))
stops.push(color($(this).css('stop-color')))
})

if (options && options.flat) {
return compact(uniq(fills.concat(strokes).concat(stops)))
}
Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Expand Up @@ -42,8 +42,10 @@ describe('get-svg-colors', function(){
var colors = getColors(__dirname + '/fixtures/inline-styles.svg')
var fills = colors.fills.map(color => color.hex())
var strokes = colors.strokes.map(color => color.hex())
var stops = colors.stops.map(color => color.hex())
assert(fills.indexOf('#ffcc00') > -1)
assert(strokes.indexOf('#803300') > -1)
assert(stops.indexOf('#000000') > -1)
})

it('supports radial gradients', function() {
Expand Down

0 comments on commit 9c4f2d2

Please sign in to comment.