Skip to content

Releases: svg/svgo

v3.0.2

18 Nov 16:50
Compare
Choose a tag to compare

Installing @types/csso no longer required

v3.0.1

11 Nov 10:26
Compare
Choose a tag to compare
  • store exposed types only in .d.ts files, no longer need to enable js checking
  • update svgo.browser.js
  • fixed "begin" attribute cleanup

Thanks to @Kreeg, @XhmikosR and @TrySound

v3.0.0

23 Oct 14:08
Compare
Choose a tag to compare

SVGO v3

Improvements and fixes

  • fixed datauri option when multipass is not enabled
  • improved default preset warnings

Breaking channges

  • Node.js 14+ is required for version
  • stable package is replaced with native stable sort (required node 12+)

Config

Typescript types are exposed out of the box. No longer need to install @types/svgo

// svgo.config.js
/**
 * @type {import('svgo').Config}
 */
export default {
  // svgo configuration
}

Active flag is no longer supported

export default {
  plugins: [
    {
      name: 'removeDoctype',
      active: true
    },
    {
      name: 'removeComments',
      active: false
    }
  ]
}

extendDefaultPlugins is removed, preset-default plugin should be used instead
when need to customize plugins defaults

export default {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          // plugins customization
        }
      }
    }
  ]
}

Enabled sortAttrs plugin by default to get better gzip compression.

<svg>
-  <rect fill-opacity="" stroke="" fill="" stroke-opacity="" />
+  <rect fill="" fill-opacity="" stroke="" stroke-opacity="" />
</svg>

Can be disabled if necessary

export default {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          sortAttrs: false
        }
      }
    }
  ]
}

cleanupIDs plugin is renamed to cleanupIds

export default {
  plugins: [
    'cleanupIds'
  ]
}
// or
export default {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          cleanupIds: {}
        }
      }
    }
  ]
}

Removed cleanupIds plugin "prefix" param, prefixIds should be used instead

export default {
  plugins: [
    'cleanupIds',
    {
      name: 'prefixIds',
      params: {
        prefix: 'my-prefix'
      }
    }
  ]
}

Public API

Removed width and height from optimization result.

const { width, height } = optimize(svg).info

Can be found with custom plugin

let width = null
let height = null
const plugin = {
  name: 'find-size',
  fn: () => {
    return {
      element: {
        enter: (node, parentNode) => {
          if (parentNode.type === 'root') {
            width = node.attributes.width
            height = node.attributes.height
          }
        }
      }
    }
  }
}
optimize(svg, {
  plugins: ['preset-default', plugin]
})

Removed error and modernError from optimization result

const {data, error, modernError } = optimize(svg)

Now all errors are thrown, parsing error can be checked by name

try {
  const { data } = optimize(svg)
} catch (error) {
  if (error.name === 'SvgoParserError') {
    // formatted error
    error.toString()
  } else {
    // runtime error
  }
}

Custom plugins

Removed full, perItem and perItemReverse plugin types.
visitor is the only supported plugin api so plugin.type
is no longer required.

Removed plugin.active flag.

Removed plugin.params used as default params, destructuring with defaults can be used instead

name and fn are only required now

const plugin = {
  name: 'my-custom-plugin',
  fn: (root, params) => {
    const { myParam = true } = params
    return {}
  }
}

Removed createContentItem and JSAPI class from nodes.
All nodes are now plain objects with one exception.
parentNode need to be defined to not break builtin plugins.

const plugin = {
  name: 'my-custom-plugin',
  fn: () => {
    return {
      element: {
        enter: (node) => {
          if (node === 'g') {
            const child = {
              type: 'element',
              name: 'g',
              attributes: {},
              children: []
            }
            Object.defineProperty(child, 'parentNode', {
              writable: true,
              value: node,
            })
            node.children.push(child)
          }
        }
      }
    }
  }
}

Thanks to @istarkov, @boidolr, @deining, @ranman, @mondeja, @liamcmitchell-sc, @rogierslag, @kriskowal, @hugolpz and @TrySound

v2.8.0

02 Nov 07:56
Compare
Choose a tag to compare

If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.

Join us in our discord

Features and bug fixes

  • added --no-color flag for testing purposes but you may find it useful (#1588)
  • handle url() in style attributes properly (#1592)
  • removeXMLNS plugin now removes xmlns:xlink attribute (#1508)
  • load .cjs configuration only with require to fix segfaults in linux (#1605)

Refactorings

  • simplified and covered with types svg stringifier (#1593)
  • migrated to visitor api and covered with types removeEmptyAttrs plugin (#1594)
  • migrated to visitor api and covered with types inlineStyles plugin (#1601)
  • migrated to picocolors (#1606)

DX

I found some users are trying to enable plugins which are not part of default preset, for example

{
  name: 'preset-default',
  params: {
    overrides: {
      cleanupListOfValues: true
    }
  }
}

To fix this I made docs more concrete about plugin (5165ccb)
and introduced a warning when true is specified in overrides (cb7e9be).
Please give us feedback if you still have issues.

Thanks to @IlyaSkriblovsky, @devongovett, @matheus1lva, @omgovich, @renatorib and @TrySound

v2.7.0

23 Sep 21:20
Compare
Choose a tag to compare

If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.

Join us in our discord

ES Modules support

This release adds support for es modules in svgo.config.js when package.json type field is "module".
For projects with mixed cjs and esm svgo.config.mjs and svgo.config.cjs are also supported as fallback.

See #1583

export default {
  plugins: [
    'preset-default'
  ]
}

Fixes

  • added validation to removeAttrs plugin (#1582)

Refactorings

Follwing plugins are migrated to the new visitor plugin api and covered with tsdoc

Other internal changes

  • covered svg parser with tsdoc (#1584)
  • avoided parentNode in style manager which makes us one step closer to releasing new plugin api publicly (#1576)
  • replaced colorette with nanocolors (#1586)

Thanks to @renatorib, @matheus1lva, @omgovich, @deepsweet, @ai, @samouss and @TrySound

v2.6.1

15 Sep 20:26
Compare
Choose a tag to compare
  • fixed optimize(svg) usage without config (#1573)
  • added missing filter primitives to collections (#1571)
  • migrated to visitor plugin api and covered with tsdoc removeEmptyContainers plugin (#1570)

Thanks to @XhmikosR, @thewilkybarkid, @renatorib, @matheus1lva, @omgovich and @TrySound

v2.6.0

13 Sep 13:59
Compare
Choose a tag to compare

If you enjoy SVGO and would like to support our work, consider sponsoring us directly via our OpenCollective.

We have some good stuff in this release

Better syntax errors (#1553)

Before people struggled to figure out what and why happens with such cryptic error

Error: Error in parsing SVG: Unquoted attribute value
Line: 1
Column: 29
Char: 6
File: input.svg

This gives too little information when a lot of svgs are transformed.

New errors look like this, include context and point to exact location with the issue.
We hope this will solve many issues when dealing with bundlers and other tools integrations.

Error: SvgoParserError: input.svg:2:29: Unquoted attribute value

  1 | <svg viewBox="0 0 120 120">
> 2 |   <circle fill="#ff0000" cx=60.444444" cy="60" r="50"/>
    |                             ^
  3 | </svg>
  4 |

pefixIds plugin is now idempotent (#1561)

To get better compression results SVGO uses multipass option. This option is used
to run prefixIds plugin only once to prefix ids and classes properly.

Though sometimes users run svgo manually a few times which leads to duplicated
prefixes and make code much bigger. To solves this prefixIds was redesigned
to add prefix only when it does not exit in ids and classes.

Eventually all plugins are planned to be determenistic and idempotent
so multipass option would not be necessary and single pass compression
could be as effective as possible.

New js2svg options (#1546)

js2svg.eol: 'lf' | 'crlf'

Allows to customize end of line characters which is usually resolved by os.EOL in node.

finalNewline: boolean

Ensures SVG output has a final newline which is required for some tools like git.

Fixes and refactorings

Follwing plugins are migrated to the new visitor plugin api and covered with tsdoc

Also fixed a few bugs

  • add xmlns:xlink in reusePaths plugin when missing (#1555)
  • fixed removeNone param in removeUselessStrokeAndFill plugin (#1549)

Thanks to @XhmikosR, @matheus1lva, @deepsweet, @omgovich, @adalinesimonian and @TrySound

v2.5.0

28 Aug 09:17
Compare
Choose a tag to compare

In this release we have a couple of fixes

  • fixed removing transform-origin attribute (680e143)
  • fixed applying transform to path arc with zero radius (ac8edba)

Visitor api now get parentNode in enter and exit callback

return {
  element: {
    enter: (node, parentNode) => {
    },
    exit: (node, parentNode) => {
    }
  }
}

And a lot of plugins are migrated to visitor api and covered them with tsdoc

  • addAttributesToSVGElement
  • addClassesToSVGElement
  • cleanupAttrs
  • cleanupEnableBackground
  • cleanupListOfValues
  • cleanupNumericValues
  • convertColors
  • convertEllipseToCircle
  • convertShapeToPath
  • convertTransform
  • mergePaths
  • removeAttributesBySelector
  • removeAttrs
  • removeComments
  • removeDesc
  • removeDoctype
  • removeElementsByAttr
  • removeEmptyText
  • removeMetadata
  • removeRasterImages
  • removeScriptElement
  • removeStyleElement
  • removeTitle
  • removeXMLProcInst
  • removeHiddenElems
  • removeViewBox
  • removeUselessDefs
  • removeOffCanvasPaths
  • removeUnknownsAndDefaults
  • sortDefsChildren

Thanks to @XhmikosR, @morganney, @oBusk, @matheus1lva and @TrySound

v2.4.0

13 Aug 17:18
Compare
Choose a tag to compare

Hey everybody!

In this release I happy to introduce the new plugin "preset-default" which allows to declaratively setup and customize default set of plugins. Previous solution extendDefaultPlugins utility prevented parcel users from using cachable json config, svgo-loader and svgo-jsx required svgo to be installed locally. "preset-default" plugin is just another builtin plugi.

module.exports = {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          // customize options
          builtinPluginName: {
            optionName: 'optionValue',
          },
          // or disable plugins
          anotherBuiltinPlugin: false,
        },
      },
    },
  ],
};

We also fixed a few bugs

  • performance is improved by ~37% for svg with styles (#1456)
  • reset cursor after "closeto" command when applying transformation (9e578b5)
  • fixed usage of removed internal methods (#1479)
  • chalk is replaced with smaller colorette (#1511)
  • test files are excluded from published package (#1458)
  • remove more spaces around flag in arc command #1484

Thanks to @TrySound, @ydaniv, @ludofischer, @XhmikosR and @joseprio

v2.3.1

26 Jun 07:51
Compare
Choose a tag to compare

Fixed vulnerability in css-select dependency (#1485)

Thanks to @ericcornelissen