From 9c4f2d273a52a3065c2db1c6cb3ef7ccb083f941 Mon Sep 17 00:00:00 2001 From: Daniel Brodin Date: Tue, 7 Nov 2017 14:23:50 +0100 Subject: [PATCH] Add check for stop-color in inline styles --- index.js | 13 +++++++------ test/index.js | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 6160de0..8a69339 100644 --- a/index.js +++ b/index.js @@ -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))) } diff --git a/test/index.js b/test/index.js index d89cb85..5ab29e6 100644 --- a/test/index.js +++ b/test/index.js @@ -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() {