Skip to content

Commit

Permalink
Merge branch 'master' into object-assign
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Mar 5, 2021
2 parents f3aa3c8 + 1889498 commit 82e48e3
Show file tree
Hide file tree
Showing 28 changed files with 323 additions and 342 deletions.
Empty file modified .editorconfig
100755 → 100644
Empty file.
34 changes: 34 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,34 @@
name: Lint

on: [push, pull_request]

env:
FORCE_COLOR: 2
NODE: 14 # The Node.js version to run lint on

jobs:
run:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE }}

- name: Set up npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
- name: Install npm dependencies
run: npm ci

- name: Run lint
run: npm run lint
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Expand Up @@ -4,10 +4,10 @@ on: [push, pull_request]

env:
FORCE_COLOR: 2
NODE_COV: 10 # The Node.js version to run coveralls on
NODE_COV: 14 # The Node.js version to run coveralls on

jobs:
run:
test:
name: Node ${{ matrix.node }}
runs-on: ubuntu-latest

Expand Down Expand Up @@ -36,9 +36,6 @@ jobs:
- name: Install npm dependencies
run: npm ci

- name: Run lint
run: npm run lint

- name: Run tests
run: npm test
if: matrix.node != env.NODE_COV
Expand All @@ -56,6 +53,6 @@ jobs:

- name: Run Coveralls
uses: coverallsapp/github-action@master
if: github.repository == 'svg-sprite/svg-sprite' && matrix.node == env.NODE_COV
if: matrix.node == env.NODE_COV
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
10 changes: 5 additions & 5 deletions CHANGELOG.md
100755 → 100644
Expand Up @@ -151,7 +151,7 @@
* Introduced "icon" box sizing strategy ([#57](https://github.com/svg-sprite/svg-sprite/pull/57), [grunt-svg-sprite #35](https://github.com/jkphl/grunt-svg-sprite/issues/35#issuecomment-74232726))

## 1.2.1 Bugfix release (2015-06-04)
* Fixed broken NPM publish settings
* Fixed broken npm publish settings

## 1.2.0 Feature release (2015-06-04)
* Updated dependencies & development dependencies ([#67](https://github.com/svg-sprite/svg-sprite/pull/67), [#82](https://github.com/svg-sprite/svg-sprite/issues/82))
Expand Down Expand Up @@ -263,7 +263,7 @@
* Improved error handling

## 1.0.1 Maintenance release
* Updated module depencencies
* Updated module dependencies

## 1.0.0 Next generation release
* Rewritten from scratch ([#23](https://github.com/svg-sprite/svg-sprite/issues/23), [#30](https://github.com/svg-sprite/svg-sprite/issues/30))
Expand All @@ -286,8 +286,8 @@ About

The [original svg-sprite](https://github.com/svg-sprite/svg-sprite/tree/bbd051e940e7b6373ed56277251a8affb03b1c10) was my first-ever Node.js module and featured CSS sprites only. The `1.0` release is **rewritten from scratch** and introduces a bunch of new features like **less dependencies** (for improved Mac OS and Windows compatibility), support for **inline sprite formats** and the **removal of file-system access** so that other libraries can build on top of it more easily. Derived libraries include:

* [grunt-svg-sprite](https://github.com/jkphl/grunt-svg-sprite) (a [Grunt](http://gruntjs.com) wrapper around *svg-sprite*)
* [gulp-svg-sprite](https://github.com/jkphl/gulp-svg-sprite) (a [Gulp](http://gulpjs.com) wrapper around *svg-sprite*)
* [grunt-svg-sprite](https://github.com/jkphl/grunt-svg-sprite) (a [Grunt](https://gruntjs.com/) wrapper around *svg-sprite*)
* [gulp-svg-sprite](https://github.com/jkphl/gulp-svg-sprite) (a [Gulp](https://gulpjs.com/) wrapper around *svg-sprite*)
* [svg-sprite-data](https://github.com/shakyShane/svg-sprite-data) by [Shane Osbourne](https://github.com/shakyShane) (based on the original svg-sprite)

**_iconizr_**, another project of mine, is based on *svg-sprite* and adds PNG fallbacks for the sprites so you can use them as universal icon systems for websites ([Node.js module](https://github.com/jkphl/node-iconizr), [Grunt plugin](https://github.com/jkphl/grunt-iconizr), [PHP version](https://github.com/jkphl/iconizr) and [online service](http://iconizr.com)).
**_iconizr_**, another project of mine, is based on *svg-sprite* and adds PNG fallbacks for the sprites so you can use them as universal icon systems for websites ([Node.js module](https://github.com/jkphl/node-iconizr), [Grunt plugin](https://github.com/jkphl/grunt-iconizr), [PHP version](https://github.com/jkphl/iconizr) and [online service](https://iconizr.com/)).
75 changes: 33 additions & 42 deletions README.md
@@ -1,26 +1,24 @@
svg-sprite [![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads]][npm-url] [![Build Status][ci-image]][ci-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] [![Development Dependency Status][devdepstat-image]][devdepstat-url]
====================================================================================================================================================================================================================================================================================================================================================================================================
# svg-sprite [![npm version][npm-image]][npm-url] [![npm downloads][npm-downloads]][npm-url] [![Build Status][ci-image]][ci-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] [![Development Dependency Status][devdepstat-image]][devdepstat-url]

is a low-level [Node.js](http://nodejs.org/) module that **takes a bunch of [SVG](http://www.w3.org/TR/SVG/) files**, optimizes them and bakes them into **SVG sprites** of several types:
svg-sprite is a low-level [Node.js](https://nodejs.org/) module that **takes a bunch of [SVG](https://www.w3.org/TR/SVG/) files**, optimizes them and bakes them into **SVG sprites** of several types:

* Traditional [CSS sprites](http://en.wikipedia.org/wiki/Sprite_(computer_graphics)#Sprites_by_CSS) for use as background images,
* Traditional [CSS sprites](https://en.wikipedia.org/wiki/Sprite_(computer_graphics)#Sprites_by_CSS) for use as background images,
* CSS sprites with **pre-defined `<view>` elements**, useful for foreground images as well,
* inline sprites using the **`<defs>` element**,
* inline sprites using the **`<symbol>` element**
* and [SVG stacks](http://simurai.com/blog/2012/04/02/svg-stacks).
* and [SVG stacks](https://simurai.com/blog/2012/04/02/svg-stacks).

It comes with a set of [Mustache](http://mustache.github.io/) templates for creating stylesheets in good ol' [CSS](http://www.w3.org/Style/CSS/) or one of the major **pre-processor formats** ([Sass](http://sass-lang.com/), [Less](http://lesscss.org/) and [Stylus](http://learnboost.github.io/stylus/)). Tweaking the templates or even adding your own **custom output format** is really easy, just as switching on the generation of an **HTML example document** along with your sprite.
It comes with a set of [Mustache](https://mustache.github.io/) templates for creating stylesheets in good ol' [CSS](https://www.w3.org/Style/CSS/) or one of the major **pre-processor formats** ([Sass](https://sass-lang.com/), [Less](http://lesscss.org/) and [Stylus](https://stylus-lang.com/)). Tweaking the templates or even adding your own **custom output format** is really easy, just as switching on the generation of an **HTML example document** along with your sprite.

For an up-to-date list of browsers supporting [SVG in general](http://caniuse.com/#feat=svg) respectively [SVG fragment identifiers](http://caniuse.com/#feat=svg-fragment) in particular (required for `<defs>` and `<symbol>` sprites as well as SVG stacks) please refer to [caniuse.com](http://caniuse.com/).
For an up-to-date list of browsers supporting [SVG in general](https://caniuse.com/svg) respectively [SVG fragment identifiers](https://caniuse.com/svg-fragment) in particular (required for `<defs>` and `<symbol>` sprites as well as SVG stacks) please refer to [caniuse.com](https://caniuse.com/).

Grunt, Gulp & Co.
-----------------
## Grunt, Gulp & Co.

Being a low-level library with support for [Node.js streams](https://github.com/substack/stream-handbook), *svg-sprite* doesn't take on the part of accessing the file system (i.e. reading the source SVGs from and writing the sprites and CSS files to disk). If you don't want to take care of this stuff yourself, you might rather have a look at the available wrappers for **Grunt** ([grunt-svg-sprite](https://github.com/jkphl/grunt-svg-sprite)) and **Gulp** ([gulp-svg-sprite](https://github.com/jkphl/gulp-svg-sprite)). *svg-sprite* is also the foundation of the **[iconizr](https://github.com/jkphl/node-iconizr)** project, which serves high-quality SVG based **CSS icon kits with PNG fallbacks**.


Table of contents
-----------------
## Table of contents

* [Installation](#installation)
* [Getting started](#getting-started)
* [Usage pattern](#usage-pattern)
Expand All @@ -34,7 +32,7 @@ Table of contents
* [Output destinations](#output-destinations)
* [Pre-processor formats and the sprite location](#pre-processor-formats-and-the-sprite-location)
* [Full configuration documentation](docs/configuration.md)
* [Online configurator & project kickstarter](http://jkphl.github.io/svg-sprite)
* [Online configurator & project kickstarter](https://svg-sprite.github.io/svg-sprite/)
* [Advanced techniques](#advanced-techniques)
* [Meta data injection](docs/meta-data.md)
* [Aligning and duplicating shapes](docs/shape-alignment.md)
Expand All @@ -45,8 +43,7 @@ Table of contents
* [Legal](#legal)


Installation
------------
## Installation

To install *svg-sprite* globally, run

Expand All @@ -57,8 +54,7 @@ npm install svg-sprite -g
on the command line.


Getting started
---------------
## Getting started

Crafting a sprite with *svg-sprite* typically follows these steps:

Expand All @@ -85,18 +81,17 @@ spriter.compile(function(error, result) {
/* Write `result` files to disk (or do whatever with them ...) */
for (var mode in result) {
for (var resource in result[mode]) {
mkdirp.sync(path.dirname(result[mode][resource].path));
fs.mkdirSync(path.dirname(result[mode][resource].path), { recursive: true });
fs.writeFileSync(result[mode][resource].path, result[mode][resource].contents);
}
}
});
```

As you can see, big parts of the above are dealing with disk I/O. In this regard you can make your life easier by [using the Grunt or Gulp wrappers](docs/grunt-gulp.md) instead of the [standard API](docs/api.md).
As you can see, big parts of the above are dealing with disk I/O. In this regard, you can make your life easier by [using the Grunt or Gulp wrappers](docs/grunt-gulp.md) instead of the [standard API](docs/api.md).


Configuration basics
--------------------
## Configuration basics

Of course you noticed the `config` variable passed to the constructor in the above example. This is *svg-sprite*'s **main configuration** — an `Object` with the following properties:

Expand All @@ -111,7 +106,7 @@ Of course you noticed the `config` variable passed to the constructor in the abo
}
```

If you don't provide a configuration object altogether, *svg-sprite* uses built-in defaults for these properties, so in fact they are all optional. However, you will need to enable at least one **output mode** (`mode` property) to get reasonable results (i.e. a sprite of some type).
If you don't provide a configuration object altogether, *svg-sprite* uses built-in defaults for these properties, so in fact, they are all optional. However, you will need to enable at least one **output mode** (`mode` property) to get reasonable results (i.e. a sprite of some type).


### General configuration options
Expand Down Expand Up @@ -162,7 +157,7 @@ Please refer to the [configuration documentation](docs/configuration.md) for det

### Output modes

At the moment, *svg-sprite* supports **five different output modes** (i.e. sprite types), each of them having it's own characteristics and use cases. It's up to you to decide which sprite type is the best choice for your project. The `mode` option controls which sprite types are created. You may enable more than one output mode at a time — *svg-sprite* will happily create several sprites in parallel.
At the moment, *svg-sprite* supports **five different output modes** (i.e. sprite types), each of them has its own characteristics and use cases. It's up to you to decide which sprite type is the best choice for your project. The `mode` option controls which sprite types are created. You may enable more than one output mode at a time — *svg-sprite* will happily create several sprites in parallel.

To enable the creation of a specific sprite type with default values, simply set the appropriate `mode` property to `true`:

Expand Down Expand Up @@ -297,11 +292,11 @@ var config = {

### Output destinations

Depending on your particular configuration, *svg-sprite* creates a lot of files that partly refer to each other. There are several configuration options controlling the exact location of each file, and you are well advised to spend a moment on understanding how they interrelate with each other.
Depending on your particular configuration, *svg-sprite* creates a lot of files that partly refer to each other. Several configuration options are controlling the exact location of each file, and you are well advised to spend a moment understanding how they interrelate with each other.

Relative destination paths refer to their ancestors as shown in the following scheme, with the current working directory being the ultimate base.

```
```text
Destination option Default Comment
---------------------------------------------------------------------------------------------
cwd $ <dest>/ . Main output directory
Expand All @@ -321,11 +316,11 @@ By default, stylesheet resources are generated directly into the respective **mo

#### Pre-processor formats and the sprite location

Special care needs to be taken when you create a **CSS sprite** («css» or «view» mode) along with a stylesheet in one of the **pre-processor formats** (Sass, LESS, Stylus etc.). In this case, calculating the correct relative SVG sprite path as used by the stylesheets can become tricky, as your (future) plain CSS compilation doesn't necessarily lie side by side with the pre-processor file. *svg-sprite* doesn't know anything about your pre-processor workflow, so it might have to estimate the location of the CSS file:
Special care needs to be taken when you create a **CSS sprite** («css» or «view» mode) along with a stylesheet in one of the **pre-processor formats** (Sass, LESS, Stylus, etc.). In this case, calculating the correct relative SVG sprite path as used by the stylesheets can become tricky, as your (future) plain CSS compilation doesn't necessarily lie side by side with the pre-processor file. *svg-sprite* doesn't know anything about your pre-processor workflow, so it might have to estimate the location of the CSS file:

1. If you **truly configured CSS output** in addition to the pre-processor format, *svg-sprite* uses your custom `mode.<mode>.render.css.dest` as the CSS stylesheet location.
2. If you just **enabled CSS output** by setting `mode.<mode>.render.css` to `TRUE`, the default value applies, which is `mode.<mode>.dest / "sprite.css"`.
3. The same holds true when you **dont't enable CSS output** at all. *svg-sprite* then simply assumes that the CSS file will be created where the defaults would put it, which is again `mode.<mode>.dest / "sprite.css"`.
1. If you **truly configured CSS output** in addition to the pre-processor format, *svg-sprite* uses your custom `mode.<mode>.render.css.dest` as the CSS stylesheet location.
2. If you just **enabled CSS output** by setting `mode.<mode>.render.css` to `TRUE`, the default value applies, which is `mode.<mode>.dest / "sprite.css"`.
3. The same holds true when you **don't enable CSS output** at all. *svg-sprite* then simply assumes that the CSS file will be created where the defaults would put it, which is again `mode.<mode>.dest / "sprite.css"`.

So even if you don't enable plain CSS output explicitly, please make sure to set `mode.<mode>.dest` to **where your final CSS file is intended to be**.

Expand All @@ -337,11 +332,10 @@ The complete configuration documentation including all options [can be found her

### Online configurator & project kickstarter

To get you quickly off the ground, I made a simple [online configurator](http://jkphl.github.io/svg-sprite) that lets you create a custom *svg-sprite* configuration in seconds. You may download the results as plain JSON, Node.js project, Gruntfile or Gulpfile. Please visit the configurator at http://jkphl.github.io/svg-sprite.
To get you quickly off the ground, I made a simple [online configurator](https://svg-sprite.github.io/svg-sprite/) that lets you create a custom *svg-sprite* configuration in seconds. You may download the results as plain JSON, Node.js project, Gruntfile, or Gulpfile. Please visit the configurator at <https://svg-sprite.github.io/svg-sprite/>.


Advanced techniques
-------------------
## Advanced techniques


### Meta data injection
Expand All @@ -356,35 +350,32 @@ For CSS sprites using a `"horizontal"` or `"vertical"` layout it is sometimes de

### Tweaking and adding output formats

*svg-sprite* uses [Mustache](http://mustache.github.io/) templates for rendering the various CSS resources. This makes it very easy to tailor the generated CSS / Sass / LESS / Stylus resources to your needs or add completely new output formats. Please refer to the [templating guide](docs/templating.md) to learn about the details.
*svg-sprite* uses [Mustache](https://mustache.github.io/) templates for rendering the various CSS resources. This makes it very easy to tailor the generated CSS / Sass / LESS / Stylus resources to your needs or add completely new output formats. Please refer to the [templating guide](docs/templating.md) to learn about the details.


Command line usage
------------------
## Command line usage

*svg-sprite* comes with a pretty feature complete command line version. A typical example could look like this:

```bash
$ svg-sprite --css --css-render-css --css-example --dest=out assets/*.svg
svg-sprite --css --css-render-css --css-example --dest=out assets/*.svg
```

Please refer to the [CLI guide](docs/command-line.md) for further details.


Known problems / To-do
----------------------
## Known problems / To-do

* SVGO does not minify element IDs when there are `<style>` or `<script>` elements contained in the file


Changelog
---------
## Changelog

Please refer to the [changelog](CHANGELOG.md) for a complete release history.


Legal
-----
## Legal

Copyright © 2018 Joschi Kuphal <joschi@kuphal.net> / [@jkphl](https://twitter.com/jkphl). *svg-sprite* is licensed under the terms of the [MIT license](LICENSE.txt). The contained example SVG icons are part of the [Tango Icon Library](http://tango.freedesktop.org/Tango_Icon_Library) and belong to the Public Domain.


Expand All @@ -393,7 +384,7 @@ Copyright © 2018 Joschi Kuphal <joschi@kuphal.net> / [@jkphl](https://twitter.c
[npm-downloads]: https://img.shields.io/npm/dm/svg-sprite.svg

[ci-url]: https://github.com/svg-sprite/svg-sprite/actions?query=workflow%3ATests+branch%3Amaster
[ci-image]: https://github.com/svg-sprite/svg-sprite/workflows/Tests/badge.svg?branch=master
[ci-image]: https://img.shields.io/github/workflow/status/svg-sprite/svg-sprite/Tests/master

[coveralls-url]: https://coveralls.io/github/svg-sprite/svg-sprite?branch=master
[coveralls-image]: https://img.shields.io/coveralls/github/svg-sprite/svg-sprite/master
Expand Down

0 comments on commit 82e48e3

Please sign in to comment.