Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsweet committed Dec 5, 2012
2 parents c4616ca + db48d1e commit af60c03
Show file tree
Hide file tree
Showing 15 changed files with 1,041 additions and 230 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,11 @@
### [ [>](https://github.com/svg/svgo/tree/v0.1.4) ] 0.1.4 / 05.12.2012
* plugins/_collections: more defaults
* `README.ru.md`
* `docs/how-it-works/ru.md`
* mocha + mocha-as-promised + chai + chai-as-promised + should + istanbul = <3
* update dependencies semvers in `package.json`
* `v0.1.x` and `v0.2.x` milestones

### [ [>](https://github.com/svg/svgo/tree/v0.1.3) ] 0.1.3 / 30.11.2012 ### [ [>](https://github.com/svg/svgo/tree/v0.1.3) ] 0.1.3 / 30.11.2012
* new plugin [plugins/cleanupNumericValues](https://github.com/svg/svgo/blob/master/plugins/cleanupNumericValues.js) (close [#8](https://github.com/svg/svgo/issues/8)) * new plugin [plugins/cleanupNumericValues](https://github.com/svg/svgo/blob/master/plugins/cleanupNumericValues.js) (close [#8](https://github.com/svg/svgo/issues/8))
* plugins/removeDefaultPx functionality now included in plugins/removeUnknownsAndDefaults * plugins/removeDefaultPx functionality now included in plugins/removeUnknownsAndDefaults
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,11 @@
**english** | [русский](https://github.com/svg/svgo/blob/master/README.ru.md)
- - -

<img src="http://soulshine.in/svgo/logo.svg?v3" width="200" height="200" alt="logo"/> <img src="http://soulshine.in/svgo/logo.svg?v3" width="200" height="200" alt="logo"/>


## SVGO v0.1.3 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo) ## SVGO v0.1.4 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo)


**SVG** **O**ptimizer is a Nodejs-based tool for optimizing SVG vector graphics files. **SVG** **O**ptimizer – это инструмент для оптимизации векторной графики в формате SVG, написанный на Node.js.
![](//mc.yandex.ru/watch/18431326) ![](//mc.yandex.ru/watch/18431326)


## Why? ## Why?
Expand All @@ -19,16 +22,16 @@ Today we have:
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeDoctype.js) ] remove doctype declaration * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeDoctype.js) ] remove doctype declaration
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeXMLProcInst.js) ] remove XML processing instructions * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeXMLProcInst.js) ] remove XML processing instructions
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeComments.js) ] remove comments * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeComments.js) ] remove comments
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeMetadata.js) ] remove metadata * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeMetadata.js) ] remove `<metadata>`
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEditorsNSData.js) ] remove editors namespaces, elements and attributes * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEditorsNSData.js) ] remove editors namespaces, elements and attributes
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyAttrs.js) ] remove empty attributes * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyAttrs.js) ] remove empty attributes
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeHiddenElems.js) ] remove hidden elements * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeHiddenElems.js) ] remove hidden elements
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyText.js) ] remove empty Text elements * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyText.js) ] remove empty Text elements
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyContainers.js) ] remove empty Container elements * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyContainers.js) ] remove empty Container elements
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeViewBox.js) ] remove viewBox attribute when possible * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeViewBox.js) ] remove `viewBox` attribute when possible
* [ [>](https://github.com/svg/svgo/blob/master/plugins/cleanupEnableBackground.js) ] remove or cleanup enable-background attribute when possible * [ [>](https://github.com/svg/svgo/blob/master/plugins/cleanupEnableBackground.js) ] remove or cleanup `enable-background` attribute when possible
* [ [>](https://github.com/svg/svgo/blob/master/plugins/convertStyleToAttrs.js) ] convert styles into attributes * [ [>](https://github.com/svg/svgo/blob/master/plugins/convertStyleToAttrs.js) ] convert styles into attributes
* [ [>](https://github.com/svg/svgo/blob/master/plugins/convertColors.js) ] convert colors (from rgb() to #rrggbb, from #rrggbb to #rgb) * [ [>](https://github.com/svg/svgo/blob/master/plugins/convertColors.js) ] convert colors (from `rgb()` to `#rrggbb`, from `#rrggbb` to `#rgb`)
* [ [>](https://github.com/svg/svgo/blob/master/plugins/convertPathData.js) ] convert Path data to relative, convert one segment to another, trim useless delimiters and much more * [ [>](https://github.com/svg/svgo/blob/master/plugins/convertPathData.js) ] convert Path data to relative, convert one segment to another, trim useless delimiters and much more
* [ [>](https://github.com/svg/svgo/blob/master/plugins/convertTransform.js) ] collapse multiple transforms into one, convert matrices to the short aliases and much more * [ [>](https://github.com/svg/svgo/blob/master/plugins/convertTransform.js) ] collapse multiple transforms into one, convert matrices to the short aliases and much more
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeUnknownsAndDefaults.js) ] remove unknown elements content and attributes, remove attrs with default values * [ [>](https://github.com/svg/svgo/blob/master/plugins/removeUnknownsAndDefaults.js) ] remove unknown elements content and attributes, remove attrs with default values
Expand Down Expand Up @@ -97,8 +100,8 @@ Arguments:


## TODO ## TODO


* [v0.1.4](https://github.com/svg/svgo/issues?milestone=6&state=open) * [v0.1.x](https://github.com/svg/svgo/issues?milestone=6&state=open)
* [v0.1.5](https://github.com/svg/svgo/issues?milestone=7&state=open) * [v0.2.x](https://github.com/svg/svgo/issues?milestone=7&state=open)




## License and copyrights ## License and copyrights
Expand Down
111 changes: 111 additions & 0 deletions README.ru.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,111 @@
[english](https://github.com/svg/svgo/blob/master/README.md) | **русский**
- - -

<img src="http://soulshine.in/svgo/logo.svg?v3" width="200" height="200" alt="logo"/>

## SVGO v0.1.4 [![Build Status](https://secure.travis-ci.org/svg/svgo.png)](http://travis-ci.org/svg/svgo)

**SVG** **O**ptimizer – это инструмент для оптимизации векторной графики в формате SVG, написанный на Node.js.
![](//mc.yandex.ru/watch/18431326)

## Зачем?

SVG файлы, особенно экспортированные из различных редакторов, содержат много избыточной и бесполезной информации, комментариев, скрытых элементов, неоптимальные или дефолтные значения и другой мусор, удаление которого безопасно и не влияет на конечный результат рендеринга.

## Возможности

SVGO имеет плагинную архитектуру, в которой практически каждая оптимизация является отдельным плагином.

Сегодня у нас есть:

* [ [>](https://github.com/svg/svgo/blob/master/plugins/cleanupAttrs.js) ] удаление переносов строк и лишних пробелов
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeDoctype.js) ] удаление doctype
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeXMLProcInst.js) ] удаление XML-инструкций
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeComments.js) ] удаление комментариев
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeMetadata.js) ] удаление `<metadata>`
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEditorsNSData.js) ] удаление пространств имён различных редакторов, их элементов и атрибутов
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyAttrs.js) ] удаление пустых атрибутов
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeHiddenElems.js) ] удаление скрытых элементов
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyText.js) ] удаление пустых текстовых элементов
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeEmptyContainers.js) ] удаление пустых элементов-контейнеров
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeViewBox.js) ] удаление атрибута `viewBox` когда это возможно
* [ [>](https://github.com/svg/svgo/blob/master/plugins/cleanupEnableBackground.js) ] удаление или оптимизация атрибута `enable-background` когда это возможно
* [ [>](https://github.com/svg/svgo/blob/master/plugins/convertStyleToAttrs.js) ] конвертирование стилей в атрибуте `style` в отдельные svg-атрибуты
* [ [>](https://github.com/svg/svgo/blob/master/plugins/convertColors.js) ] конвертирование цветовых значений (из `rgb()` в `#rrggbb`, из `#rrggbb` в `#rgb`)
* [ [>](https://github.com/svg/svgo/blob/master/plugins/convertPathData.js) ] конвертирование данных в Path в относительные координаты, конвертирование одних типов сегментов в другие, удаление ненужных разделителей и многое другое
* [ [>](https://github.com/svg/svgo/blob/master/plugins/convertTransform.js) ] схлопывание нескольких трансформаций в одну, конвертирование матриц в короткие алиасы и многое другое
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeUnknownsAndDefaults.js) ] удаление неизвестных элементов, контента и атрибутов
* [ [>](https://github.com/svg/svgo/blob/master/plugins/removeUnusedNS.js) ] удаление деклараций неиспользуемых пространств имён
* [ [>](https://github.com/svg/svgo/blob/master/plugins/cleanupNumericValues.js) ] округление дробных чисел до заданной точности, удаление `px` как единицы измерения по умолчанию
* [ [>](https://github.com/svg/svgo/blob/master/plugins/moveElemsAttrsToGroup.js) ] перемещение совпадающих атрибутов у всех элементов внутри группы `<g>`
* [ [>](https://github.com/svg/svgo/blob/master/plugins/collapseGroups.js) ] схлопывание бесполезных групп `<g>`

Хотите узнать, как это работает и как написать свой плагин? [Конечно же да](https://github.com/svg/svgo/blob/master/docs/how-it-works/ru.md).


## Как использовать

```sh
$ [sudo] npm install -g svgo
```

```
Usage:
svgo [OPTIONS] [ARGS]
Options:
-h, --help : Help
-v, --version : Version
-i INPUT, --input=INPUT : Input file, "-" for STDIN
-s STRING, --string=STRING : Input SVG data string
-f FOLDER, --folder=FOLDER : Input folder, optimize and rewrite all *.svg files
-o OUTPUT, --output=OUTPUT : Output file (by default the same as the input), "-" for STDOUT
-c CONFIG, --config=CONFIG : Local config file to extend default
--disable=DISABLE : Disable plugin by name
--enable=ENABLE : Enable plugin by name
--datauri : Output as Data URI base64 string
--pretty : Make SVG pretty printed
Arguments:
INPUT : Alias to --input
OUTPUT : Alias to --output
```

* с файлами:

$ svgo test.svg

или:

$ svgo test.svg test.min.svg

* с STDIN / STDOUT:

$ cat test.svg | svgo -i - -o - > test.min.svg

* с папками

$ svgo -f ../path/to/folder/with/svg/files

* со строками:

$ svgo -s '<svg version="1.1">test</svg>' -o test.min.svg

или даже с Data URI base64:

$ svgo -s 'data:image/svg+xml;base64,…' -o test.min.svg

* с помощью [GUI](https://github.com/svg/svgo-gui)
* как модуль Node.js – [examples](https://github.com/svg/svgo/tree/master/examples)

## TODO

* [v0.1.x](https://github.com/svg/svgo/issues?milestone=6&state=open)
* [v0.2.x](https://github.com/svg/svgo/issues?milestone=7&state=open)


## Лицензия и копирайты

Данное программное обеспечение выпускается под [лицензией MIT](https://github.com/svg/svgo/blob/master/LICENSE).

Логотип – [Егор Большаков](http://xizzzy.ru/).
16 changes: 8 additions & 8 deletions docs/how-it-works/en.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ It's important to note that every plugin:
- - - - - -


### 2. svg2js ### 2. svg2js
SVGO converts SVG-as-XML data into SVG-as-JS representation. Something like this: SVGO converts SVG-as-XML data into SVG-as-JS AST representation. Something like this:


```xml ```xml
<?xml version="1.0" standalone="no"?> <?xml version="1.0" standalone="no"?>
Expand Down Expand Up @@ -118,15 +118,15 @@ It's important to note that:
- - - - - -


### 3. plugins ### 3. plugins
SVGO applies all plugins from the config to SVG-as-JS data. See a lot of examples in the [plugins directory](https://github.com/svg/svgo/tree/master/plugins) above. SVGO applies all plugins from the config to AST data. See a lot of examples in the [plugins directory](https://github.com/svg/svgo/tree/master/plugins) above.




#### 3.1 types #### 3.1 types
In the simplest case plugins process can be represented as "each plugin runs over all SVG-as-JS data items and perform some actions". But 90% of typical optimizations requires some actions only on one (current) item from the data, so there is no sense to copypaste a recursive per-item loop every time on every plugin. And that's why we have a three types of plugins: In the simplest case plugins applying process can be represented as "each plugin runs over all AST data items and perform some actions". But 90% of typical optimizations requires some actions only on one (current) item from the data, so there is no sense to copypaste a recursive per-item loop every time on every plugin. And that's why we have a three types of plugins:


* `perItem` - plugin works only with one current item, inside a "from the outside into the depths" recursive loop (default) * `perItem` - plugin works only with one current item, inside a "from the outside into the depths" recursive loop (default)
* `perItemReverse` - plugin works only with one current item, inside a "from the depths to the outside" recursive loop (useful when you need to collapse elements one after other) * `perItemReverse` - plugin works only with one current item, inside a "from the depths to the outside" recursive loop (useful when you need to collapse elements one after other)
* `full` - plugin works with the full SVG-as-JS data and must returns the same * `full` - plugin works with the full AST and must returns the same


`perItem` and `perItemReverse` plugins runs inside the recursive `Array.prototype.filter` loop, so if a plugin wants to remove current item then it should just `return false`. `perItem` and `perItemReverse` plugins runs inside the recursive `Array.prototype.filter` loop, so if a plugin wants to remove current item then it should just `return false`.


Expand Down Expand Up @@ -182,9 +182,10 @@ And of course, writing plugins would not have been so cool without some sugar AP
* @param {Object} attr attribute object * @param {Object} attr attribute object
* @return {Object} created attribute * @return {Object} created attribute


##### eachAttr(callback) ##### eachAttr(callback, [context])
* Iterates over all attributes. * Iterates over all attributes.
* @param {Function} callback * @param {Function} callback
* @param {Object} [context] callback context
* @return {Boolean} false if there are no any attributes * @return {Boolean} false if there are no any attributes


#### 3.3 tests #### 3.3 tests
Expand All @@ -200,9 +201,8 @@ You can see a lot of examples in the [test/plugins directory](https://github.com
- - - - - -


### 4. js2svg ### 4. js2svg
SVGO converts SVG-as-JS representation into SVG-as-XML data string. SVGO converts AST back into SVG-as-XML data string.


## What's next ## What's next
1. Write your own plugin :) or 1. Write your own plugin :) or
2. Give me an idea of new plugin or API method 2. Give me an idea of new optimization or API method
3. Pull request my crooked english
Loading

0 comments on commit af60c03

Please sign in to comment.