Releases: svg/svgo
v2.3.0
Hey, everybody! We have a big release here.
- The new plugin is added for merging style elements into one. See #1381
Before:
<svg>
<style media="print">
.st0{ fill:red; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; }
</style>
<style>
.test { background: red; }
</style>
</svg>
After:
<svg>
<style>
@media print{
.st0{ fill:red; padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; }
}
.test { background: red; }
</style>
</svg>
- CLI got new
--exclude
flag which uses regexps to exclude some files from--folder
. See #1409
svgo --folder=svgs --exclude "invalid-icon" "bad-.+"
-
Internal AST is migrated to XAST. This spec makes maintaining plugins easier and may be used as interop with other tools like SVGR.
-
The new visitor plugin type combines features of "full", "perItem" and "perItemReverse" plugins without loosing simplicity. Eventually only visitor api will be supported. See #1454
Also small fixes
- override default floatPrecision in plugins with globally specified one (7389bcd)
- fix rendering -0 in path data (3d4adb6)
- make browser bundle 30% smaller (2799622)
- simplified convertPathData plugin (a04b27a and 6165743)
- prepared for more regression tests (d89d36e)
Thanks to @chambo-e, @strarsis, @XhmikosR, @omgovich and @TrySound
v2.2.2
v2.2.1
This is a big patch with new style computing (#1399) and landed to master regression tests
A lot of bugs are fixed
- fixed scientific notation parsing in paths (d6f972c)
- forbade invalid
<style>
type attribute in inlineStyles plugin (#1400) - fixed
<style>
support in removeHiddenElems plugin (#1399) - fixed noSpaceAfterFlags option support (0e02fd9)
- fixed floatPrecision when extending default plugins (d58a7e6)
- fixed
<style>
support when removing useless path commands (c21fef5) - fixed
<style>
support when combining path commands (ba7e9bd) - prevent removing filter primitive defaults (555a961)
- prevent merging paths with markers (de4fd79)
- prevent removing single point paths with markers (21c04e4)
- keep empty
<pattern>
when at least one argument is present (0e6b0c4) - keep
<marker>
with display none (d3e3726) - preserve empty conditional processing attributes (a2b0e73)
- preserve viewBox in nested
<svg>
(28c01cf)
435 of 526 regression tests are passing
v2.2.0
Wow, two minor releases in a row. There is a big reason for that. We got a new logo! See it in readme. Big thanks to @DerianAndre.
There were also implemented brand new path data parser and stringifier (#1378 and #1387) to do more reliable transformations and produce smaller svg.
A cup of small fixes
- fixed optimisation when stroke-linecap=round is specified (7901588)
- prevented transform applying when inline style is present (79dbb4b)
- apply transform to stroke-dasharray and stroke-dashoffset (dd37fcf)
- fixed removing hidden elements when descendant enables visibility (d06747a)
- fixed removing elements with zero opacity inside clipPath (9d67586)
- fixed removing empty mask which can hide elements by id (d14315b)
- fixed removing stroke-width when marker-end is specified (3639156)
- fixed
<tspan>
inside<a>
(091172a)
Thanks to @sk- @XhmikosR @deepsweet and @TrySound
v2.1.0
This release introduced two big changes
- we forked sax parser to fix issues inaccessible from public api (https://github.com/svg/sax)
- we added regression tests which already caught 4 bugs (WIP)
See fixed bugs
- fixed empty
<svg />
with enabled cleanupIDs plugin (9b97e06) - fail when file specified in
--config
flag does not exist or json string is specified (a855b40) - disabled convertStyleToAttrs by default (#1365)
- preserve whitespace in elements containing text (#1220)
- fixed removing
xml:space="preserve"
(776ec1e) - preserve whitespace in nested textual elements (9de471a)
- keep empty
<g>
whenfilter
attribute is specified (c1d5f0f) - fixed parsing xml entities (#1371 isaacs/sax-js#200)
Thanks to @XhmikosR @sk- @chromakode @devongovett and @TrySound
v2.0.3
- reduced browser build size 1450kB -> 820kB (82778c8)
- fixed adding empty
<defs>
by reusePaths plugin (#1201) - fixed reporting parsing errors (ea82cc2)
- fixed convertEllipseToCircle plugin when
rx
orry
attributes are not specified (7f4e052) - fixed removing mask-type on
<mask>
(4490d62) - fixed removing elements when class is empty in removeElementsByAttr plugin (d9f68d3)
- disable removing spaces in
<path>
by default to support many broken non-browser environments (#1353) - fixed error message in addAttributesToSVGElement plugin (c1edce4)
v2.0.2
v2.0.1
v2.0.0
Happy to introduce SVGO 2.0. Package size was drastically reduced. Configuration
is heavily simplified. Node 10.13+ is required.
- smaller install size
- simplified config format
- added browser ready es module bundle
- API is synchronous
- support only svgo.config.js for external configuration
Config changes
Since early versions plugins configuration was affected by yaml syntax.
Though it was not practial in json or javascript for writing and for internal
work.
plugins:
- removeViewBox: true
- removeAttr:
attrs: '(fill|stroke)'
{
plugins: [
{
removeViewBox: true
},
{
removeAttr: {
attrs: '(fill|stroke)'
}
}
]
}
In the new version plugins configuration is closer to internal representation.
{
plugins: [
{
name: 'removeViewBox'
},
{
name: 'removeAttr',
params: {
attrs: '(fill|stroke)'
}
}
]
}
In v1 full
flag allowed to disable all default plugins and run only specified
in plugins list. In v2 it's default behaviour. To extend default plugins list
you can use extendDefaultPlugins
utility.
{
plugins: extendDefaultPlugins([
{
name: 'removeViewBox',
active: false,
}
])
}
Loading custom plugin by path was removed in favour of manual import or require.
+const customPlugin = require('./custom-plugin.js')
{
plugins: [
{
name: 'customPlugin',
- path: './custom-plugin.js'
+ ...customPlugin
}
]
}
CLI changes
Painful coa
was replaced with well maintained commander
.
--enable
and --disable
flags are removed. In later versions we will explore
plugins setup via CLI.
Inlined json config is no longer suppored. CLI flags should be used instead.
--config="{multipass:true}"
By default SVGO CLI will search for svgo.config.js
. --config
flag allows
to specify js config with any name.
YAML and JSON configuration is no longer supported for the sake of simplicity
and less dependencies.
Node API changes
Initially SVGO was implemented with callback style api to fit sax recommendation.
Though in practice api was synchronous and allowed to access the result assigned
in callback right after optimisation.
For v1 callback style was replaced with promise api which cannot longer be run
synchronously. This was a pain point for many tools and required hacking svgo.
In v2 this pain is considered and api is now synchronous. No hacks necessary.
SVGO class is replaced with optimize
function.
-const { SVGO } = require('svgo')
-const svgo = new SVGO({
- // config
- multipass: true
-})
-svgo.optimize(svgstring, { path: './file.svg' }).then(result => {
- ...
-})
+const { optimize, extendDefaultPlugins } = require('svgo')
+optimize(svgstring, {
+ path: './file.svg',
+ multipass: true,
+})
Some tools require the same logic for resolving svgo config as SVGO CLI.
const { loadConfig, optimize } = require('svgo')
...
const config = await loadConfig()
optimize(svgstring, { path: './file.svg', ...config })
Browser ready bundle
There were a lot of request for this feature in the past.
Now tools like svgomg may use official and tested es module for browsers with optimize
, extendDefaultPlugins
and createContentItem
support.
import {
optimize,
extendDefaultPlugins,
createContentItem
} from 'svgo/dist/svgo.browser.js'
1.3.2 / 30.10.2019
- Fixed TypeError: Cannot set property 'multipassCount' of undefined