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

assetgraph-sprite

Package Overview
Dependencies
Maintainers
2
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.6.0 to 0.6.1

8

lib/packers/jimScott.js

@@ -70,5 +70,3 @@ /*

height: config.maxHeight || 999999
},
packingWidth = 0,
packingHeight = 0;
};

@@ -89,3 +87,3 @@ // Sort by area, descending:

if (imageInfo.padding && imageInfo.padding.some(function (v) {return v > 0;})) {
throw new Error("jimScott.pack: Sprite padding not supported");
throw new Error('jimScott.pack: Sprite padding not supported');
}

@@ -99,3 +97,3 @@ // Perform the search

} else {
throw new Error("jimScott.pack: Cannot fit image");
throw new Error('jimScott.pack: Cannot fit image');
}

@@ -102,0 +100,0 @@ _.extend(imageInfo, coords);

@@ -17,3 +17,3 @@ var URL = require('url'),

process.nextTick(function () {
err.message += ' (' + imageAsset.toString() + ')';
err.message += ' (' + imageAsset.urlOrDescription + ')';
cb(err);

@@ -90,3 +90,3 @@ });

});
info[keyName] = cssRule.style[propertyName].replace(/^([\'\"])(.*)\1$/, "$2");
info[keyName] = cssRule.style[propertyName].replace(/^([\'\"])(.*)\1$/, '$2');
}

@@ -101,3 +101,3 @@ }

if (!Canvas) {
console.warn("assetgraph-sprite: Canvas not found, skipping");
assetGraph.emit('warn', new Error('assetgraph-sprite: Canvas not found, skipping'));
return cb();

@@ -107,7 +107,7 @@ }

// Waiting for https://github.com/LearnBoost/node-canvas/issues/52
var cairoVersion = Canvas.cairoVersion.split(".").map(function (str) {
var cairoVersion = Canvas.cairoVersion.split('.').map(function (str) {
return parseInt(str, 10);
});
if (cairoVersion[0] < 1 || cairoVersion[1] < 10) {
console.warn("assetgraph-sprite: Cannot create sprites due to missing canvas.getContext('2d').drawImage() support. Please compile node-canvas with Cairo version 1.10.0 or above.");
assetGraph.emit('warn', new Error('assetgraph-sprite: Cannot create sprites due to missing canvas.getContext("2d").drawImage() support. Please compile node-canvas with Cairo version 1.10.0 or above.'));
return cb();

@@ -139,3 +139,3 @@ }

}
if (('-sprite-selector-for-group') in cssRule.style) {
if ('-sprite-selector-for-group' in cssRule.style) {
var spriteInfo = extractInfoFromCssRule(cssRule, '-sprite-'),

@@ -150,9 +150,40 @@ spriteGroupName = spriteInfo.selectorForGroup;

if (spriteGroupName in spriteGroups) {
if (spriteGroups[spriteGroupName].placeHolder) {
console.warn("assetgraph-sprite: Multiple definitions of " + spriteGroupName + " sprite");
var group = spriteGroups[spriteGroupName];
if (!Array.isArray(group.placeHolders)) {
group.placeHolders = [];
}
spriteGroups[spriteGroupName].placeHolder = _.extend(spriteInfo, {
asset: cssAsset,
cssRule: cssRule
});
if (group.placeHolders.length > 0) {
var err;
if (Object.keys(group.placeHolders[0]).every(function (key) {
if (['asset', 'cssRule'].indexOf(key) !== -1) {
return true;
}
return group.placeHolders[0][key] === spriteInfo[key];
})) {
err = new Error('assetgraph-sprite: Multiple identical definitions of ' + spriteGroupName + ' sprite.\nThis might happen if you duplicate CSS using a preprocessor.');
err.asset = cssAsset;
assetGraph.emit('info', err);
group.placeHolders.push(_.extend(spriteInfo, {
asset: cssAsset,
cssRule: cssRule
}));
} else {
err = new Error('assetgraph-sprite: Multiple differing definitions of ' + spriteGroupName + ' sprite.\nThis is most likely an error.');
err.asset = cssAsset;
assetGraph.emit('warn', err);
}
} else {
group.placeHolders.push(_.extend(spriteInfo, {
asset: cssAsset,
cssRule: cssRule
}));
}
}

@@ -168,3 +199,3 @@ }

imageInfos = _.values(spriteGroup.imageInfosById),
spriteInfo = spriteGroup.placeHolder || {};
spriteInfo = spriteGroup.placeHolders && spriteGroup.placeHolders[0] || {};

@@ -203,7 +234,8 @@ seq(imageInfos)

.seq(function (spriteAsset) {
var baseUrl,
var baseUrl = assetGraph.root,
href = spriteAsset.id + spriteAsset.defaultExtension;
if (spriteGroup.placeHolder) {
baseUrl = spriteGroup.placeHolder.asset.nonInlineAncestor.url;
var location = spriteGroup.placeHolder.location;
if (Array.isArray(spriteGroup.placeHolders)) {
var location = spriteGroup.placeHolders[0].location;
if (location) {

@@ -216,45 +248,47 @@ if (/^[?#]/.test(location)) {

}
} else {
baseUrl = assetGraph.root;
}
spriteAsset.url = URL.resolve(baseUrl, href);
assetGraph.addAsset(spriteAsset);
if (spriteGroup.placeHolder) {
var cssRule = spriteGroup.placeHolder.cssRule,
relation = new assetGraph.CssImage({
cssRule: cssRule,
from: spriteGroup.placeHolder.asset,
to: spriteAsset
});
['background-image', 'background' ].forEach(function (propertyName) {
if (!relation.propertyName && cssRule.style[propertyName]) {
relation.propertyName = propertyName;
var propertyValue = cssRule.style.getPropertyValue(propertyName),
propertyPriority = cssRule.style.getPropertyPriority(propertyName);
if (propertyValue === '!important') {
// Hack so that an existing value of "!important" will DTRT
propertyPriority = 'important';
propertyValue = 'url(...)';
} else if (/^\s*$/.test(propertyValue)) {
propertyValue = 'url(...)';
} else {
var existingUrlTokens = propertyValue.match(relation.tokenRegExp);
if (existingUrlTokens) {
relation.tokenNumber = existingUrlTokens.length;
if (Array.isArray(spriteGroup.placeHolders)) {
spriteGroup.placeHolders.forEach(function (spriteInfo) {
var cssRule = spriteInfo.cssRule,
relation = new assetGraph.CssImage({
cssRule: cssRule,
from: spriteInfo.asset,
to: spriteAsset
});
['background-image', 'background' ].forEach(function (propertyName) {
if (!relation.propertyName && cssRule.style[propertyName]) {
relation.propertyName = propertyName;
var propertyValue = cssRule.style.getPropertyValue(propertyName),
propertyPriority = cssRule.style.getPropertyPriority(propertyName);
if (propertyValue === '!important') {
// Hack so that an existing value of "!important" will DTRT
propertyPriority = 'important';
propertyValue = 'url(...)';
} else if (/^\s*$/.test(propertyValue)) {
propertyValue = 'url(...)';
} else {
var existingUrlTokens = propertyValue.match(relation.tokenRegExp);
if (existingUrlTokens) {
relation.tokenNumber = existingUrlTokens.length;
}
propertyValue += ' url(...)';
}
propertyValue += ' url(...)';
cssRule.style.setProperty(propertyName, propertyValue, propertyPriority);
}
cssRule.style.setProperty(propertyName, propertyValue, propertyPriority);
});
if (!relation.propertyName) {
relation.propertyName = 'background-image';
cssRule.style.setProperty('background-image', 'url(...)');
}
// I can't see why the ordering of CssImage relations should be significant...
assetGraph.addRelation(relation, 'last');
relation.refreshHref();
['selector-for-group', 'packer', 'image-format', 'background-color', 'important'].forEach(function (propertyName) {
spriteInfo.cssRule.style.removeProperty('-sprite-' + propertyName);
});
});
if (!relation.propertyName) {
relation.propertyName = 'background-image';
cssRule.style.setProperty('background-image', 'url(...)');
}
// I can't see why the ordering of CssImage relations should be significant...
assetGraph.addRelation(relation, 'last');
relation.refreshHref();
['selector-for-group', 'packer', 'image-format', 'background-color', 'important'].forEach(function (propertyName) {
spriteGroup.placeHolder.cssRule.style.removeProperty('-sprite-' + propertyName);
});
}

@@ -267,3 +301,3 @@ imageInfos.forEach(function (imageInfo) {

existingBackgroundPositionValue = style['background-position'],
existingBackgroundValue = style['background'],
existingBackgroundValue = style.background,
backgroundOffsetsWereUpdated = false,

@@ -273,8 +307,9 @@ offsets = [

imageInfo.y
];
],
existingOffsets;
if (existingBackgroundValue) {
var backgroundTokens = existingBackgroundValue.split(/\s+/),
positionTokenIndices = [],
existingOffsets = [];
positionTokenIndices = [];
existingOffsets = [];
backgroundTokens.forEach(function (existingBackgroundValueToken, i) {

@@ -310,3 +345,3 @@ if (/^(?:-?\d+px|0)$/i.test(existingBackgroundValueToken)) {

// FIXME: Silently ignores other units than px
var existingOffsets = existingBackgroundPositionValue.split(' ').map(function (item) {
existingOffsets = existingBackgroundPositionValue.split(' ').map(function (item) {
return parseInt(item, 10);

@@ -316,8 +351,4 @@ });

if (existingOffsets.length !== 2 || isNaN(existingOffsets[0]) || isNaN(existingOffsets[1])) {
console.warn(
'WARNING: trying to sprite',
imageInfo.asset.url,
'with background-position:',
existingBackgroundPositionValue
);
var err = new Error('WARNING: trying to sprite ' + imageInfo.asset.url + ' with background-position: ' + existingBackgroundPositionValue);
assetGraph.emit('warn', err);
} else {

@@ -336,3 +367,3 @@ offsets[0] -= existingOffsets[0];

});
if (relationSpriteInfo.noGroup || !spriteGroup.placeHolder) {
if (relationSpriteInfo.noGroup || !spriteGroup.placeHolders) {
// The user specified that this selector needs its own background-image/background

@@ -339,0 +370,0 @@ // property pointing at the sprite rather than relying on the Html elements also being

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

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

@@ -11,2 +11,6 @@ {

"email": "andreas@one.com"
},
{
"name": "Peter Müller",
"email": "munter@fumle.dk"
}

@@ -17,2 +21,5 @@ ],

},
"files": [
"lib"
],
"dependencies": {

@@ -27,4 +34,10 @@ "passerror": "=0.0.1",

"devDependencies": {
"assetgraph": "=1.2.3",
"vows": ">=0.6.2"
"assetgraph": "^1.6.42",
"coveralls": "^2.11.1",
"istanbul": "^0.3.0",
"jshint": "=2.5.1",
"mocha": "=1.19.0",
"mocha-lcov-reporter": "0.0.1",
"unexpected": "=3.2.0",
"urltools": "=0.1.0"
},

@@ -38,5 +51,8 @@ "engines": {

"scripts": {
"prepublish": "vows"
"lint": "jshint .",
"test": "npm run lint && mocha",
"travis": "npm run lint && NODE_ENV=development ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"coverage": "NODE_ENV=development ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot"
},
"main": "lib/spriteBackgroundImages.js"
}
AssetGraph-sprite
=================
[![NPM version](https://badge.fury.io/js/assetgraph-sprite.png)](http://badge.fury.io/js/assetgraph-sprite)
[![Build Status](https://travis-ci.org/assetgraph/assetgraph-sprite.png?branch=master)](https://travis-ci.org/assetgraph/assetgraph-sprite)
[![Dependency Status](https://david-dm.org/assetgraph/assetgraph-sprite.png)](https://david-dm.org/assetgraph/assetgraph-sprite)
[![Coverage Status](https://coveralls.io/repos/assetgraph/assetgraph-sprite/badge.png)](https://coveralls.io/r/assetgraph/assetgraph-sprite)

@@ -4,0 +8,0 @@ A plugin (or "transform") for <a

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