Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assetgraph-sprite

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assetgraph-sprite - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

79

lib/index.js
var _ = require('underscore'),
child_process = require('child_process'),
seq = require('seq'),
Canvas = require('canvas'),
passError = require('./util/passError'),
urlTools = require('assetgraph/lib/util/urlTools'),
packers = require('./packers');

@@ -10,3 +10,3 @@

function getCanvasImageFromBuffer(buffer, cb) {
function getCanvasImageFromImageAsset(imageAsset, cb) {
var canvasImage = new Canvas.Image();

@@ -23,27 +23,5 @@ canvasImage.onerror = function (err) {

};
canvasImage.src = buffer;
canvasImage.src = imageAsset.rawSrc;
}
function getCanvasImageFromImageAsset(imageAsset, cb) {
imageAsset.getSerializedSrc(passError(cb, function (src) {
if (imageAsset.type === 'Png' || imageAsset.type === 'Jpeg') {
getCanvasImageFromBuffer(src, cb);
} else {
// Use GraphicsMagick while waiting for gif support: https://github.com/LearnBoost/node-canvas/issues/78
var buffers = [],
convertProcess = child_process.spawn('gm', ['convert', imageAsset.type.toLowerCase() + ':-', 'png:-']);
convertProcess.stdout.on('data', function (buffer) {
buffers.push(buffer);
});
convertProcess.on('exit', function () {
getCanvasImageFromBuffer(Buffer.concat(buffers), cb);
}).on('error', cb);
convertProcess.stdin.write(src);
convertProcess.stdin.end();
}
}));
}
function calculateSpritePadding(paddingStr) {

@@ -111,25 +89,21 @@ if (paddingStr) {

seq(assetGraph.findAssets({type: 'Css'}))
.parEach(function (cssAsset) {
cssAsset.getParseTree(this);
})
.parEach(function (cssAsset) {
assets.Css.eachRuleInParseTree(cssAsset.parseTree, function (cssRule) {
if ((assets.Css.vendorPrefix + '-sprite-selector-for-group') in cssRule.style) {
var spriteInfo = assets.Css.extractInfoFromRule(cssRule, assets.Css.vendorPrefix + '-sprite-'),
spriteGroupName = spriteInfo.selectorForGroup;
if (spriteGroupName in spriteGroups) {
if (spriteGroups[spriteGroupName].placeHolder) {
console.warn("assetgraph-sprite: Multiple definitions of " + spriteGroupName + " sprite");
}
spriteGroups[spriteGroupName].placeHolder = _.extend(spriteInfo, {
asset: cssAsset,
cssRule: cssRule
});
assetGraph.findAssets({type: 'Css'}).forEach(function (cssAsset) {
assets.Css.eachRuleInParseTree(cssAsset.parseTree, function (cssRule) {
if ((assets.Css.vendorPrefix + '-sprite-selector-for-group') in cssRule.style) {
var spriteInfo = assets.Css.extractInfoFromRule(cssRule, assets.Css.vendorPrefix + '-sprite-'),
spriteGroupName = spriteInfo.selectorForGroup;
if (spriteGroupName in spriteGroups) {
if (spriteGroups[spriteGroupName].placeHolder) {
console.warn("assetgraph-sprite: Multiple definitions of " + spriteGroupName + " sprite");
}
spriteGroups[spriteGroupName].placeHolder = _.extend(spriteInfo, {
asset: cssAsset,
cssRule: cssRule
});
}
});
this();
})
.set(_.keys(spriteGroups))
}
});
});
seq(_.keys(spriteGroups))
.seqEach(function (spriteGroupName) {

@@ -151,3 +125,3 @@ var callback = this,

});
process.nextTick(this);
this();
})

@@ -177,3 +151,3 @@ .seq(function () {

});
spriteAsset.url = assetGraph.root + spriteAsset.id + spriteAsset.defaultExtension; // FIXME
spriteAsset.url = urlTools.resolveUrl(assetGraph.root, spriteAsset.id + spriteAsset.defaultExtension);
assetGraph.addAsset(spriteAsset);

@@ -188,4 +162,3 @@ if (spriteGroup.placeHolder) {

});
cssRule.style.setProperty('background-image', 'url(...)',
spriteGroup.placeHolder.important && 'important');
cssRule.style.setProperty('background-image', 'url(...)', spriteGroup.placeHolder.important && 'important');
// I can't see why the ordering of CssImage relations should be significant...

@@ -195,3 +168,3 @@ assetGraph.addRelation(relation, 'last');

['selector-for-group', 'packer', 'image-format', 'background-color'].forEach(function (propertyName) {
spriteGroup.placeHolder.cssRule.style.removeProperty(assets.Css.vendorPrefix + '-sprite-' + propertyName);
spriteGroup.placeHolder.cssRule.style.removeProperty(assets.Css.vendorPrefix + '-sprite-' + propertyName);
});

@@ -201,3 +174,3 @@ }

imageInfo.incomingRelations.forEach(function (incomingRelation) {
assetGraph.markAssetDirty(incomingRelation.from);
incomingRelation.from.markDirty();
var relationSpriteInfo = assets.Css.extractInfoFromRule(incomingRelation.cssRule, assets.Css.vendorPrefix + '-sprite-');

@@ -210,3 +183,3 @@ incomingRelation.cssRule.style.setProperty('background-position',

incomingRelation.cssRule.style.removeProperty(assets.Css.vendorPrefix + '-sprite-' + propertyName);
}, this);
});
if (relationSpriteInfo.noGroupSelector) {

@@ -213,0 +186,0 @@ // The user specified that this selector needs its own background-image/background

@@ -5,3 +5,3 @@ {

"repository": "git://github.com/One-com/assetgraph-sprite.git",
"version": "0.0.4",
"version": "0.1.0",
"maintainers": [

@@ -14,13 +14,13 @@ {

"dependencies": {
"underscore": ">=1.1.3",
"bufferjs": "=1.0.1",
"canvas": "=0.6.0",
"seq": ">=0.3.0 <0.4"
"underscore": ">= 1.1.3",
"bufferjs": "= 1.0.1",
"canvas": "~ 0.7.0",
"seq": ">= 0.3.0 < 0.4"
},
"devDependencies": {
"assetgraph": ">= 0.1.2",
"vows": ">=0.5.6"
"assetgraph": "~ 0.2.0",
"vows": ">= 0.5.6"
},
"engines": {
"node": ">=0.4.8"
"node": ">= 0.4.8"
},

@@ -27,0 +27,0 @@ "directories": {

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