Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
ahws-dr-svg-sprites
Advanced tools
Create SVG sprites with PNG fallbacks at needed sizes
Minimal:
var builder = require("ahws-dr-svg-sprites");
var options = {
spriteElementPath: "img/logos",
spritePath: "img/sprites/logo-sprite.svg",
cssPath: "css/logo-sprite.css"
};
builder(options, function () {
// sprite was built
});
would yield the following files:
css/logo-sprite.css
img/sprites/logo-sprite.svg
img/sprites/logo-sprite.png
Advanced:
var builder = require("ahws-dr-svg-sprites");
var options = {
name: "tv",
prefix: "dr-logos",
spriteElementPath: "img/logos/tv",
spritePath: "img/sprites",
layout: "packed",
cssUrl: 'img'
cssPath: "css",
cssSuffix: "less",
cssUnit: "rem",
sizes: {
large: 24,
small: 16
},
refSize: "large"
};
builder(options, function () {
// sprite was built
});
would yield the following files:
css/dr-logos-tv-sprite.less
img/sprites/dr-logos-tv-sprite.svg
img/sprites/dr-logos-tv-sprite-large.png
img/sprites/dr-logos-tv-sprite-small.png
Type: String
Optional
Used when automatically building stylesheet and image filenames.
Type: String
The base path of the elements to be sprited.
Type: String
Destination path of the generated sprite images.
If the filename part (ending in .svg
) is omitted it will be built from options.prefix
, options.name
and "sprite"
.
Type: String
Default value: ""
Optional
The path where to built a preview page.
If the filename part (ending in .html
) is omitted it will be built from options.prefix
, options.name
and "sprite"
.
Default is no preview.
Type: String
Optional
Destination path of the generated stylesheet.
If a filename part is omitted it will get built from options.cssPrefix
, options.name
, "sprite"
and options.cssSuffix
.
If left blank only svg sprites and png fallbacks are generated.
Type: String
Default value: ""
Optional
Defines a prefix for the name of the sprite stylesheet, images and classnames.
Type: String
Default value: ""
Optional
Defines a prefix for the name of the sprite stylesheet (this overrides options.prefix
if set).
Only used when automatically building stylesheet filenames.
Type: String
Default value: "css"
Optional
Stylesheet filetype suffix.
Only used when automatically building stylesheet filenames.
Type: String
Default value: ".svg"
Optional
Defines a prefix for selectors to target svg sprites.
Type: String
Default value: ""
Optional
Defines a prefix for selectors to target png sprites.
Type: String
Default value: "px"
Optional
Defines the unit used for dimensions and positions in the stylesheet.
Only other unit that is supported (in a meaningful way) is "rem"
- which is used in combination with options.cssBaseFontSize
.
Type: String
Default value: 16
Optional
Used to calculate values when using options.cssUnit
set to "rem"
.
Type: Boolean
Default value: true
Optional
If set to false
width
and height
for the svg elements will be omitted from the stylesheet. Useful in combination with a options.layout
of "alt-diagonal"
.
Type: String
Default value: "../templates/stylesheet.hbs"
Optional
Defines the path of the Handlebars template to use for generating the stylesheet.
The data object passed to the Handlebars template is a Sprite
instance (see ./lib/Sprite.js
).
Templates have a few internal helpers at their disposal:
url
: Takes a path (String
) and returns a CSS appropriate path.unit
: Adds units to a value (Number
) if needed and also converts from px
to rem
.prefix
: Accepts an array of items (Sprite.sizes[].items
) and a selector prefix (String
). Returns a comma separated prefixed selector for all elements in a size.prefixAll
: Accepts an array of sizes (Sprite.sizes
) and a selector prefix (String
). Returns a comma separated prefixed selector for all elements for all sizes.Type: String
Default value: "horizontal"
Optional
Defines the layout of elements in the sprite. Possible values:
"horizontal"
: Elements are placed side-by-side."vertical"
: Elements are placed above eachother."packed"
: Elements are packed into smallest possible space."diagonal"
: Elements are distributed from top-left to bottom-right corner."alt-diagonal"
: Elements are distributed from bottom-left to top-right corner.Type: Object|Function
Default value: null
Optional
Can be used to translate svg element basenames (filename without extension) into desired names. Handy if the basenames don't make good classnames (or contain invalid chars).
If an object is supplied it will be used as a lookup table.
If a function is supplied it will be used to transform the svg element basename.
Type: Number
Default value: 10
Defines unit size of the grid the sprite elements snap to.
Type: String|Number
Optional
Defines the basic size of your source svg-elements. All other sizes will be calculated relating to this. It can either be a key from the sizes
option (which refers to a number) or just a raw number.
Notice how one source element is bigger than the refSize
; this ok - as every element is scaled proportionally.
Type: Object
Optional
A hash of size labels and values (Number
) that define the different sizes of the needed sprites.
var options = {
// some options
sizes: {
large: 39,
small: 13
},
refSize: "large",
// more options
};
1 SVG sprite is generated and 2 PNG sprites (1 per defined size).
FORKED
options.cssUrl
added.Features:
options.layout
added.options.map
added.options.template
added.options.previewPath
added.options.cssSvgPrefix
added.options.cssPngPrefix
added.options.cssUnit
added.options.cssBaseFontSize
added.options.cssIncludeElementSizes
added.Changes:
options.sizes
and options.refSize
are now optional (which also means no size tag is added to classnames if options.sizes
is omitted).options.spritePath
and options.cssPath
now also accept a full path including filename for simpler configuration.FAQs
Create SVG sprites with PNG fallbacks at needed sizes
We found that ahws-dr-svg-sprites demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.