New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grunt-svg-spriter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-svg-spriter - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

demo/icons-png.html

25

icons/assets/generator.json
{
"classPrefix": "icon--",
"prefix": "icon",
"delimiter": "--",
"defaultColor": "#333",
"sizes": [
{
"name": "xsm",
"suffix": "--xsm",
"suffix": "xsm",
"width": 16,

@@ -12,3 +14,3 @@ "height": 16

"name": "sm",
"suffix": "--sm",
"suffix": "sm",
"width": 24,

@@ -23,20 +25,3 @@ "height": 24

}
],
"colors": [
{
"name": "default",
"suffix": "",
"color": "#333"
},
{
"name": "blue",
"suffix": "--blue",
"color": "#12b"
},
{
"name": "white",
"suffix": "--white",
"color": "#fff"
}
]
}

3

package.json
{
"name": "grunt-svg-spriter",
"version": "0.2.1",
"version": "0.3.0",
"description": "Creates svg sprite in symbols and creates png fallback",
"dependencies": {
"async": "^1.4.0",
"each-async": "^1.0.0",
"phantomjs": "~1.9.0",

@@ -9,0 +8,0 @@ "svgo": "^0.5.0"

var fs = require('fs'),
system = require('system'),
page = require('webpage').create(),
items = JSON.parse(system.stdin.read()),
async = require('async'),
total = items.length,
next = 0,
file, svgdata, frag, svg, width, height;
file;

@@ -23,37 +23,71 @@

svgdata = fs.read(src) || '';
frag = window.document.createElement('div');
frag.innerHTML = svgdata;
if (typeof(item.collection.sizes) === 'object') {
svg = frag.querySelector('svg');
var sizes = item.collection.sizes;
width = svg.getAttribute('width');
height = svg.getAttribute('height');
if (!width && !height) {
var viewbox = svg.getAttribute('viewBox');
var dimensions = viewbox.split(' ');
width = dimensions[2] - dimensions[0];
height = dimensions[3] - dimensions[1];
}
page.viewportSize = {
width: parseFloat(width),
height: parseFloat(height)
};
var nextSize = 0;
var totalSize = sizes.length;
var nextSizeRasterize = function () {
var size;
item.folder = item.path.variations;
item.generated = item.folder + item.png;
if (nextSize >= totalSize) {
nextFile();
return;
}
page.open(src, function (status) {
//page.evaluate(function(){
// document.querySelector('svg').style.fill = '#12f';
//});
page.render(dest);
console.log(JSON.stringify({ 'file': item, 'status': status }));
nextFile();
});
size = sizes[nextSize++];
var page = require('webpage').create();
dest = item.path.dest + size.name + '/' + item.png;
page.viewportSize = {
width: parseFloat(size.width),
height: parseFloat(size.height)
};
page.open(src, function(status) {
page.render(dest);
console.log(JSON.stringify({ 'file': item.path.variations + size.name + '/' + item.png , 'status': status}));
page.close();
nextSizeRasterize();
});
};
nextSizeRasterize();
} else {
var svgdata = fs.read(src) || '';
var frag = window.document.createElement('div');
frag.innerHTML = svgdata;
var svg = frag.querySelector('svg');
var width = svg.getAttribute('width');
var height = svg.getAttribute('height');
if (!width && !height) {
var viewbox = svg.getAttribute('viewBox');
var dimensions = viewbox.split(' ');
width = dimensions[2] - dimensions[0];
height = dimensions[3] - dimensions[1];
}
var page = require('webpage').create();
page.viewportSize = {
width: parseFloat(width),
height: parseFloat(height)
};
page.open(src, function(status) {
page.render(dest);
console.log(JSON.stringify({ 'file': item.path.variations + item.png, 'status': status }));
nextFile();
});
}
};
nextFile();

@@ -28,4 +28,15 @@ /**

items.forEach(function(item) {
var collection = {};
try {
collection = JSON.parse(grunt.file.read(path.resolve(item.path.src + 'generator.json')));
} catch (e) {
collection.prefix = 'icon';
collection.delimiter = '--';
}
item.path.src = options.tasks.compress ? path.resolve(item.path.compressed) + '/' : path.resolve(item.path.src) + '/';
item.path.dest = path.resolve(item.path.variations) + '/';
item.collection = collection;
});

@@ -45,7 +56,6 @@

if (result.status) {
grunt.log.writeln(result.file.generated + ' generated');
grunt.log.writeln(result.file + ' generated');
}
} catch (e) {
grunt.log.error(buffer);
done();
}

@@ -52,0 +62,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc