Skip to content

Commit

Permalink
getting the fill attribute from the source svg for the sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
alte0 committed Apr 17, 2022
1 parent bb0010e commit fabcb7a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
54 changes: 35 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,23 @@ var spriteSVG = function(options) {

// For each sprite
for (var i in data.sprites) {
var sprite = data.sprites[i],
// Create, initialise and populate an SVG
$svg = $('<svg/>')
.attr({
'height': sprite.h,
'viewBox': sprite.viewBox,
'width': sprite.w,
'x': Math.ceil(sprite.fit.x)+options.padding,
'y': Math.ceil(sprite.fit.y)+options.padding
})
.append(sprite.file);
var sprite = data.sprites[i];
// Create, initialise and populate an SVG
var spriteAttr = {
'height': sprite.h,
'viewBox': sprite.viewBox,
'width': sprite.w,
'x': Math.ceil(sprite.fit.x)+options.padding,
'y': Math.ceil(sprite.fit.y)+options.padding
};

if (sprite.fill){
Object.assign(spriteAttr, {'fill': sprite.fill});
}

var $svg = $('<svg/>')
.attr(spriteAttr)
.append(sprite.file);

// Check and set parent SVG width
if(sprite.fit.x+sprite.w+options.padding>data.width) {
Expand Down Expand Up @@ -168,15 +174,21 @@ var spriteSVG = function(options) {
sprite.y = y+options.padding;

// Create, initialise and populate an SVG
var svgSpriteAttrs = {
'height': sprite.h,
'viewBox': sprite.viewBox,
'width': sprite.w,
'x': Math.ceil(sprite.x),
'y': Math.ceil(sprite.y)
};

if (sprite.fill) {
Object.assign(svgSpriteAttrs, {'fill': sprite.fill});
}

var $svg = $('<svg/>')
.attr({
'height': sprite.h,
'viewBox': sprite.viewBox,
'width': sprite.w,
'x': Math.ceil(sprite.x),
'y': Math.ceil(sprite.y)
})
.append(sprite.file);
.attr(svgSpriteAttrs)
.append(sprite.file);

// Round up coordinates
sprite.h = Math.ceil(sprite.h);
Expand Down Expand Up @@ -250,6 +262,10 @@ var spriteSVG = function(options) {
w: parseFloat(width)
};

if ($file.attr('fill') !== undefined) {
Object.assign(sprite, {fill: $file.attr('fill')});
}

// Add the sprite to our array
data.sprites.push(sprite);

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gulp-svg-spritesheet",
"description": "Gulp SVG sprite sheet generator",
"version": "0.0.5",
"version": "0.0.6",
"author": "Darren Hall <[email protected]>",
"contributors": [
{
Expand Down

0 comments on commit fabcb7a

Please sign in to comment.