Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

env:
FORCE_COLOR: 2
NODE: 20
NODE: 22

on:
pull_request:
Expand Down Expand Up @@ -31,9 +31,9 @@ jobs:
fail-fast: false
matrix:
node-version:
- 24
- 22
- 20
- 18
os:
- ubuntu-latest
- windows-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# svgo-ll [![npm](https://img.shields.io/npm/v/svgo-ll)](https://npmjs.org/package/svgo-ll)

**svgo-ll** is a Node.js library and command-line application for optimizing SVG files, evolved from the [SVGO](https://www.npmjs.com/package/svgo) package. **svgo-ll** is focused on lossless optimization and compression.
**svgo-ll** is a Node.js library and command-line application for optimizing SVG files, evolved from the [SVGO](https://www.npmjs.com/package/svgo) package. **svgo-ll** is focused on lossless optimization and compression. See the [summary of differences between **svgo-ll** and SVGO](https://github.com/svg-utils/svgo-ll/blob/main/docs/diffs-from-svgo.md) for more details.

## Why?

Expand Down
38 changes: 0 additions & 38 deletions docs/01-index.mdx

This file was deleted.

17 changes: 0 additions & 17 deletions docs/04-plugins/index.mdx

This file was deleted.

22 changes: 0 additions & 22 deletions docs/04-plugins/removeEmptyContainers.mdx

This file was deleted.

6 changes: 6 additions & 0 deletions docs/command-line-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ If `--folder` is specified, process files in all sub-folders recursively.
`--exclude <PATTERN...>`
If `--folder` is specified, exclude files matching any of the specified regular expression patterns.

<a id="plugins"></a>

## Plugin and Compression Options

<a id="preset"></a>
`--preset <default | next | none>`
Specify which set of predefined plugins to use. If this option is not used, and no plugins are define by the `--config` option,
[preset-default](./preset-default.md) is used.
Expand All @@ -33,13 +36,16 @@ Specify one or more builtin plugins to run in addition to those specified by `--
` --options <FILENAME>`
Path to a [JSON file](https://www.json.org) containing configuration parameters for enabled plugins. The JSON file should contain an object whose keys are the names of plugins, and whose values are the parameters to pass to that plugin. This option cannot be used if the [`--config` option](#config) is specified.

<a id="disable"></a>
`--disable <plugin...>`
Specify one or more plugins specified by `--preset` or `--config` which should not be run.

<a id="config"></a>
`--config <FILENAME>`
Specifies a [custom configuration file](./custom-config-file.md).

<a id="max-passes"></a>

`--max-passes <INTEGER>`
Maximum number of iterations over the plugins. Must be an integer between 1 and 10. Default is 10.

Expand Down
60 changes: 60 additions & 0 deletions docs/diffs-from-svgo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Differences Between **svgo-ll** and SVGO version 4

**svgo-ll** originated as a clone of an [SVGO](https://github.com/svg/svgo) version 4 release candidate. Since then, numerous changes have been made to prioritize lossless compression, fix bugs, and improve performance. Some of these changes are discussed below.

## Rounding and Precision

In SVGO, rounding of decimal values is enabled by default and integrated into many plugins in ways that are not possible to disable. In **svgo-ll**, default plugins do not do any rounding. Rounding is opt-in and handled by a [separate plugin](./plugins/round.md).

## Plugins

The following SVGO default plugins have been removed from **svgo-ll**:

- **cleanupAttrs**
- **cleanupEnableBackground**
- **cleanupNumericValues**
- **convertColors** - similar functionality is in the new **[minifyColors](./plugins/minifyColors.md)** plugin
- **convertPathData** - most of the lossless functionality of this plugin has been preserved in the new **[minifyPathData](./plugins/minifyPathData.md)** plugin
- **convertTransform** - some of the benefits of this plugin are achieved with the new **[minifyTransforms](./plugins/minifyTransforms.md)** plugin
- **mergePaths** - some of the benefits of **mergePaths** are achieved with the new **[createGroups](./plugins/createGroups.md)** plugin
- **mergeStyles**
- **moveElemsAttrsToGroup**
- **moveGroupAttrsToElems**
- **removeDeprecatedAttrs**
- **removeEmptyAttrs**
- **removeEmptyText** - now handled by [removeEmptyContainers](./plugins/removeEmptyContainers.md)
- **sortAttrs**
- **sortDefsChildren**

The following new default plugins have been added to **svgo-ll**:

- **[cleanupStyleAttributes](./plugins/cleanupStyleAttributes.md)**
- **[cleanupTextElements](./plugins/cleanupTextElements.md)**
- **[cleanupXlink](./plugins/cleanupXlink.md)**
- **combineStyleElements**
- **[createGroups](./plugins/createGroups.md)**
- **[mergeGradients](./plugins/mergeGradients.md)**
- **[minifyColors](./plugins/minifyColors.md)**
- **[minifyGradients](./plugins/minifyGradients.md)**
- **[minifyPathData](./plugins/minifyPathData.md)**
- **[minifyTransforms](./plugins/minifyTransforms.md)**
- **moveElemsStylesToGroup**

## CSS

In SVGO, many plugins do not account for the impact of CSS. Many transformations are not safe when styles are used; when `<style>` elements are present, it can be difficult to determine whether a transformation is safe. All **svgo-ll** plugins check for the presence of `<style>` elements and the types of selectors they use; depending on whether `<style>` elements are present and the complexity of selectors, they may disable all or part of their functionality. For more details, see the [scalability](#scalability) section.

## Configuration

Plugins can be [enabled, disabled, and configured](./command-line-options.md#plugins) from the command line without writing code.

The `--multipass` option has been deprecated and replaced by [`--max-passes`](./command-line-options.md#max-passes). By default **svgo-ll** will make up to 10 passes, the equivalent of using the `--multipass` option in SVGO.

<a id="scalability"></a>

## Scalability

A number of architectural changes have been made to improve performance and scalability. These include:

- Deprecating `detachNodeFromParent()` - see discussion in SVGO issues [1969](https://github.com/svg/svgo/issues/1969) and [2080](https://github.com/svg/svgo/issues/2080).
- Recording data which is expensive to calculate outside of the optimization loop (particularly `<style>` data) and passing this data to each plugin. Plugins which modify the data (e.g. `inlineStyles`) are responsible for updating the data.
2 changes: 2 additions & 0 deletions docs/plugins/cleanupStyleAttributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The list of allowable properties comes from https://www.w3.org/TR/SVG2/styling.h

Empty `style` attributes are removed.

Numeric values in style properties are written in the most compact form.

Style attributes are not changed if the document has attribute selectors on the `style` attribute.

### `class` Attributes
Expand Down
16 changes: 16 additions & 0 deletions docs/plugins/mergeGradients.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# mergeGradients

Removes duplicate `<linearGradient>` and `<radialGradient>` elements.

## Details

The plugin has no effect if:

- The document has scripts.
- The document has `<style>` elements with CSS which **svgo-ll** is not able to process.

If identical gradients are found, all but one is removed, and all references to the removed gradients are replaced with a reference to the remaining gradient.

Gradient elements are not considered identical unless all of their children are `<stop>` elements.

Gradients whose `id` attributes are referenced by a CSS id selector are ignored.
17 changes: 17 additions & 0 deletions docs/plugins/minifyTransforms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# minifyTransforms

Make transform expressions as short as possible.

## Details

For all `transform`, `gradientTransform`, `patternTransform` attributes, rewrite them in a shorter form if possible.

The following transformations are performed:

- All numbers in the transform expressions are written in the most compact form.
- Default values are removed (e.g., `translate(2,0)` becomes `translate(2)`).
- If equivalent expressions are possible, the shortest one is used (e.g., `matrix(1 0 0 1 10 20)` becomes `translate(10 20)`).
- Adjacent `translate()` functions are merged (e.g., `translate(2 3)translate(4)` becomes `translate(6 3)`).
- Adjacent `scale()` functions are merged (e.g., `scale(2.1)scale(2.2)` becomes `scale(4.62)`).
- Adjacent `rotate()` functions are merged (e.g., `rotate(23)rotate(24)` becomes `rotate(47)`).
- Attributes with meaningless transforms are removed (e.g., `transform="rotate(0)"`).
33 changes: 33 additions & 0 deletions docs/plugins/removeEmptyContainers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# removeEmptyContainers

Removes empty elements which do not affect rendering.

## Details

The plugin has no effect if:

- The document has scripts.
- The document has `<style>` elements with CSS which **svgo-ll** is not able to process.

The following elements are removed:

- `<a>`,
`<defs>`,
`<foreignObject>`,
`<g>`,
`<marker>`,
`<mask>`,
`<missing-glyph>`,
`<pattern>`,
`<switch>`,
`<symbol>`,
`<text>`, and
`<tspan>` elements which have no children.
- `<use>` elements which reference empty containers.

The following empty elements are not removed:

- `<pattern>` elements with attributes.
- `<g>` elements with a filter.
- `<mask>` elements with an `id` attribute.
- Elements which are children of a `<switch>` element.
8 changes: 4 additions & 4 deletions docs/preset-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ The following plugins are included in `preset-default`, in the order that they a
- removeNonInheritableGroupAttrs
- removeUselessStrokeAndFill
- [removeHiddenElems](./plugins/removeHiddenElems.md)
- removeEmptyText
- minifyTransforms
- [minifyTransforms](./plugins/minifyTransforms.md)
- convertEllipseToCircle
- moveElemsStylesToGroup
- collapseGroups
- convertShapeToPath
- [minifyPathData](./plugins/minifyPathData.md)
- removeEmptyContainers
- [mergeGradients](./plugins/mergeGradients.md)
- [removeEmptyContainers](./plugins/removeEmptyContainers.md)
- removeUnusedNS
- [createGroups](./plugins/createGroups.md)
- collapseGroups
- [cleanupTextElements](./plugins/cleanupTextElements.md)
8 changes: 4 additions & 4 deletions docs/preset-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ The following plugins are included in `preset-next`, in the order that they are
- removeNonInheritableGroupAttrs
- removeUselessStrokeAndFill
- [removeHiddenElems](./plugins/removeHiddenElems.md)
- removeEmptyText
- minifyTransforms
- [minifyTransforms](./plugins/minifyTransforms.md)
- convertEllipseToCircle
- moveElemsStylesToGroup
- collapseGroups
- convertShapeToPath
- [minifyPathData](./plugins/minifyPathData.md)
- removeEmptyContainers
- [mergeGradients](./plugins/mergeGradients.md)
- [removeEmptyContainers](./plugins/removeEmptyContainers.md)
- removeUnusedNS
- [createGroups](./plugins/createGroups.md)
- collapseGroups
- [cleanupTextElements](./plugins/cleanupTextElements.md)
4 changes: 2 additions & 2 deletions lib/svgo/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function deleteChildren(childrenToDeleteByParent) {
/**
* @param {number} n
* @param {number} m
* @deprecated
* @deprecated use ExactNum instead
*/
export function exactAdd(n, m) {
const d1 = getNumberOfDecimalDigits(n);
Expand All @@ -161,7 +161,7 @@ export function exactAdd(n, m) {
/**
* @param {number} n
* @param {number} m
* @deprecated
* @deprecated use ExactNum instead
*/
export function exactMul(n, m) {
const d1 = getNumberOfDecimalDigits(n);
Expand Down
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/** Version of SVGO. */
export const VERSION = '5.6.1-alpha.1';
export const VERSION = '5.7.0';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"packageManager": "yarn@3.8.2",
"name": "svgo-ll",
"version": "5.6.1-alpha.1",
"version": "5.7.0",
"description": "svgo-ll is a Node.js library and command-line application for optimizing SVG images.",
"license": "MIT",
"type": "module",
Expand Down
1 change: 0 additions & 1 deletion plugins/minifyTransforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function normalize(transforms) {
*/
function mergeAdjacentScaleRotate(transforms) {
/**
*
* @param {TransformItem} origRotate
* @param {TransformItem} origScale
*/
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/files/overlap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading