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

auto-sprites

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-sprites - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

25

auto-sprites.js

@@ -56,7 +56,15 @@ var path = require('path'),

/**
*
* @param config
* @param config.data {Object} Css string data
* @param config.path {String} Image save position
* @param config.root {String} Image root
* @param config.fileName {String} Generate image name
* @param config.base64 {Boolean} Use base64 encode
* @constructor AutoSprites
*/
var AutoSprites = function (config) {
this.data = config.data;
this.path = config.path;
this.files = config.files;
this.fileName = this.getFileName(config.fileName);

@@ -70,7 +78,14 @@ this.root = config.root;

constructor: AutoSprites,
/**
* Get image save name
* @param fileName
* @returns {*}
*/
getFileName: function (fileName) {
return crypto.createHash('md5').update(fileName).digest("hex");
},
/**
* Parse css then generate css sprites
* @param callback {Function} After generate css sprites execute callback
*/
parse: function (callback) {

@@ -101,3 +116,3 @@ var cssDom = cssom.parse(this.data),

next();
});
});
}

@@ -104,0 +119,0 @@ }, function () {

30

horizontal-packer.js

@@ -1,2 +0,2 @@

var HorizontalPacker = function(){
var HorizontalPacker = function () {

@@ -9,3 +9,3 @@ };

//[w:10,h:10]
fit:function(blocks){
fit: function (blocks) {
var n, node, block, len = blocks.length;

@@ -15,19 +15,19 @@ var w = len > 0 ? blocks[0].w : 0;

// this.root = { x: 0, y: 0, w: w, h: h };
for (n = 0; n < len ; n++) {
for (n = 0; n < len; n++) {
block = blocks[n];
if(!this.root){
this.root = {x:0,y:0,w:block.w,h:block.h};
if (!this.root) {
this.root = {x: 0, y: 0, w: block.w, h: block.h};
block.fit = this.root;
}else{
} else {
this.root = {
x:0,
y:0,
w:this.root.w+block.w,
h:this.root.h+Math.abs(this.root.h-block.h),
right:{
x:this.root.w,
y:0,
w:block.w,
h:block.h
x: 0,
y: 0,
w: this.root.w + block.w,
h: this.root.h + Math.abs(this.root.h - block.h),
right: {
x: this.root.w,
y: 0,
w: block.w,
h: block.h
}

@@ -34,0 +34,0 @@ }

var path = require('path'),
//gd = require('node-gd'),
nodeImages = require('node-images'),

@@ -35,21 +34,4 @@ fs = require('fs'),

} else {
/* gd.openPng(url, function (err, png) {
if (err) {
next();
} else {
if (png) {
imageMeta.image = png;
imageMeta.width = png.width;
imageMeta.height = png.height;
size = self.getRulesMaxSize(smartItem,imageMeta);
smartItem.w = size.w;
smartItem.h = size.h;
self._imageMetaCache[url] = imageMeta;
smartItem.imageMeta = imageMeta;
next();
}
}
}); */
try {
console.log(url)
console.log('Get css background ---> '+ url );
var png = nodeImages(url);

@@ -82,2 +64,3 @@ if (png) {

imageHeight = imageMeta.height;
smartItem.cssRules.forEach(function (cssRule) {

@@ -111,6 +94,6 @@ w = parseInt(cssRule.width),

var imageUrl = path.join(self.path , self.fileName + '-' + self.type + '.png'),
spritesImageName =path.join( self.root , imageUrl );
var imageUrl = path.join(self.path , self.fileName + '-' + self.type + '.png').split(path.sep).join('/'),
spritesImageName = path.join( self.root , imageUrl);
console.log(spritesImageName);
console.log('Save Image to ---> '+ spritesImageName );

@@ -127,6 +110,3 @@ asyncUtil.forEach(position, function (index, style, go) {

self.replaceBackgroundInfo(imageUrl, style);
/* image.copyResampled(spritesImage, imageMeta.fit.x,
imageMeta.fit.y, 0, 0, image.width,
image.height, image.width, image.height); */
//image = nodeImages(image,0,0,image.width,image.height);
spritesImage.draw(image, imageMeta.fit.x, imageMeta.fit.y);

@@ -137,5 +117,2 @@ }

self.makeDirSync(path.dirname(spritesImageName));
/*spritesImage.savePng(spritesImageName, 8, function (err) {
next();
}); */

@@ -158,15 +135,2 @@ spritesImage.save(spritesImageName);

/* var img = gd.createTrueColor(w, h);
if (img) {
transparent = //format == "gif" && img.colorAllocate(112, 121, 211) ||
img.colorAllocateAlpha(0, 0, 0, 127);
img.fill(0, 0, transparent);
img.colorTransparent(transparent);
//if(format == "png"){
img.alphaBlending(0);
img.saveAlpha(1);
}
//}
return img; */
return nodeImages(w, h);

@@ -255,3 +219,5 @@ },

bgColor = rule.getPropertyValue('background-color'),
bgRepeat = rule.getPropertyValue('background-repeat');
bgRepeat = rule.getPropertyValue('background-repeat'),
positionX,
positionY;

@@ -268,6 +234,9 @@ var position = rule['background-position'];

bgPosition = (position[0] - style.fit.x) + 'px ' +
(position[1] - style.fit.y) + 'px';
positionX = (position[0] - style.fit.x);
positionY = (position[1] - style.fit.y);
bgPosition = (positionX == 0 ? 0 + ' ' : positionX + 'px ') +
(positionY == 0 ? 0 : positionY + 'px');
//合并样式 替换成background的形式

@@ -274,0 +243,0 @@ rule.removeProperty('background-layout');

{
"name": "auto-sprites",
"version": "0.1.5",
"version": "0.1.6",
"description": "自动合并图片的模块",

@@ -9,12 +9,27 @@ "main": "index.js",

},
"dependencies":{
"css-parser":"*",
"node-images":"*"
"dependencies": {
"css-parser": "*",
"node-images": "*"
},
"bin":{
"sprites":"./bin/boot"
"bin": {
"sprites": "./bin/boot"
},
"repository": "https://github.com/windyGex/auto-sprites.git",
"author": "windy ge",
"license": "BSD"
"repository": {
"type": "git",
"url": "https://github.com/windyGex/auto-sprites.git"
},
"author": {
"name": "windy ge"
},
"license": "BSD",
"bugs": {
"url": "https://github.com/windyGex/auto-sprites/issues"
},
"readme": "ERROR: No README data found!",
"_id": "auto-sprites@0.1.6",
"dist": {
"shasum": "c0d4ecc2fefe174c3bbd4730a62b8d76f10a4dde"
},
"_from": "auto-sprites@",
"_resolved": "https://registry.npmjs.org/auto-sprites/-/auto-sprites-0.1.5.tgz"
}

@@ -19,2 +19,10 @@ var path = require('path'),

{
reg: /\?ignore/,
callback: function (result) {
result['background-layout'] = 'ignore';
}
},
{
reg: /(url\(['"]?.*?['"]?\))/,

@@ -36,3 +44,3 @@ callback: function (result, match) {

//10px 10px
reg: /([0-1][0-9]{0,2}%|left|right|center|0|-\d+px)\s+([0-1][0-9]{0,2}%|top|center|bottom|0|-\d+px)/,
reg: /(-?\d+%|left|right|center|0|-?\d+px)\s+(-?\d+%|top|center|bottom|0|-?\d+px)/,
callback: function (result, match) {

@@ -61,3 +69,3 @@ result['background-position'] = match[0];

//匹配rgb的颜色的正则
reg: /rgb\([0-9]{0,3}\,[0-9]{0,3}\,[0-9]{0,3}\)/,
reg: /rgb\s*\(\s*[0-9]{0,3}\s*\,\s*[0-9]{0,3}\s*\,\s*[0-9]{0,3}\s*\)/,
callback: function (result, match) {

@@ -68,3 +76,3 @@ result['background-color'] = match[0];

{ //匹配rgba的颜色的正则
reg: /rgba\([0-9]{0,3}\,[0-9]{0,3}\,[0-9]{0,3}\,0?\.[0-9]{1}\)/,
reg: /rgba\s*\(\s*[0-9]{0,3}\s*\,\s*[0-9]{0,3}\s*\,\s*[0-9]{0,3}\s*\,\s*0?\.[0-9]{1}\s*\)/,
callback: function (result, match) {

@@ -75,2 +83,5 @@ result['background-color'] = match[0];

{
//If image url contains these words,may be make a mistake
//eg background:url(test_white.png) no-repeat;
//fix it
reg: /qua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow|orange|transparent/,

@@ -82,3 +93,4 @@ callback: function (result, match) {

],
bgImageReg = /url\s*\(\s*(["']?)([^"']+?\.(?:png)(?:\?[^"']+?)?)\1\s*\)/;
// (quote)(url)(extname)(stamp)(quote)
bgImageReg = /url\s*\(\s*(["']?)([^"']+?\.(?:png|gif|jpeg|jpg)(?:\?[^"']+?)?)\1\s*\)/;

@@ -100,3 +112,3 @@ var ParseRules = function (config) {

getBackgroundInfo: function (background) {
var result = {};
var result = {}, backgroundReplace = background;
backgroundRegExp.forEach(function (regExpItem) {

@@ -106,6 +118,7 @@ var regExp = regExpItem.reg,

callback = regExpItem.callback;
if (match = background.match(regExp)) {
if (match = backgroundReplace.match(regExp)) {
if (callback(result, match) === false) {
return false;
}
backgroundReplace = backgroundReplace.replace(regExp, '');
}

@@ -208,3 +221,8 @@ });

if (style['background-image']) {
if (style['background-repeat'] == 'repeat' || !style['background-repeat'] || (style['background-position'] && style['background-position'].match(/center|right|bottom/))) {
if (style['background-repeat'] == 'repeat'
|| !style['background-repeat']
|| (style['background-position'] && style['background-position'].match(/center|right|bottom/))
|| style['background-layout'] == 'ignore'
) {
style.removeProperty('background-layout');
return;

@@ -211,0 +229,0 @@ }

@@ -1,2 +0,2 @@

var VerticalPacker = function(){
var VerticalPacker = function () {

@@ -8,3 +8,3 @@ };

//[w:10,h:10]
fit:function(blocks){
fit: function (blocks) {
var n, node, block, len = blocks.length;

@@ -14,19 +14,19 @@ var w = len > 0 ? blocks[0].w : 0;

// this.root = { x: 0, y: 0, w: w, h: h };
for (n = 0; n < len ; n++) {
for (n = 0; n < len; n++) {
block = blocks[n];
if(!this.root){
this.root = {x:0,y:0,w:block.w,h:block.h};
if (!this.root) {
this.root = {x: 0, y: 0, w: block.w, h: block.h};
block.fit = this.root;
}else{
} else {
this.root = {
x:0,
y:0,
w:this.root.w+Math.abs(this.root.w-block.w),
h:this.root.h+block.h,
down:{
x:0,
y:this.root.h,
w:block.w,
h:block.h
x: 0,
y: 0,
w: this.root.w + Math.abs(this.root.w - block.w),
h: this.root.h + block.h,
down: {
x: 0,
y: this.root.h,
w: block.w,
h: block.h
}

@@ -33,0 +33,0 @@ }

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