Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update preset-default and docs. #21

Merged
merged 6 commits into from
Sep 30, 2024
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
42 changes: 0 additions & 42 deletions docs/04-plugins/cleanupIds.mdx

This file was deleted.

19 changes: 0 additions & 19 deletions docs/04-plugins/inlineStyles.mdx

This file was deleted.

15 changes: 15 additions & 0 deletions docs/plugins/cleanupIds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# cleanupIds

Removes unreferenced `id` attributes, and minifies id values that remain.

## Options

- `preserve`: **string[]** - a list of id values that will not be removed or minified
- `preservePrefixes`: **string[]** - a list of prefixes; any id values that begin with one of these prefixes will not be removed or minified

## 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.
17 changes: 17 additions & 0 deletions docs/plugins/inlineStyles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# inlineStyles

Moves style properties from `<style>` elements to the `style` attribute of matching elements.

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.

Style properties are only moved if all of the following are true:

- The rule only matches a single element.
- The matched element does not already have a `style` attribute.
- The matching rule is not in a media query.
- The matching selector does not have pseudo-classes or pseudo-elements.

Any rules which are no longer necessary are removed from the `<style>` element.
11 changes: 11 additions & 0 deletions docs/plugins/minifyPathData.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# minifyPathData

Rewrites the `d` attribute of `path` elements in a more compact form.

## 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 `<style>` element has rules with an attribute selector on the `d` attribute.
7 changes: 4 additions & 3 deletions docs/preset-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ The following plugins are included in `preset-default`, in the order that they'r
- removeEditorsNSData
- removeDesc
- cleanupAttrs
- [cleanupXlink](./plugins/cleanupXlink.md)
- cleanupStyleAttributes
- combineStyleElements
- inlineStyles
- [inlineStyles](./plugins/inlineStyles.md)
- minifyStyles
- cleanupIds
- [cleanupIds](./plugins/cleanupIds.md)
- removeUselessDefs
- convertColors
- [removeUnknownsAndDefaults](./plugins/removeUnknownsAndDefaults.md)
Expand All @@ -30,7 +31,7 @@ The following plugins are included in `preset-default`, in the order that they'r
- collapseGroups
- convertShapeToPath
- combinePaths
- minifyPathData
- [minifyPathData](./plugins/minifyPathData.md)
- removeEmptyAttrs
- removeEmptyContainers
- removeUnusedNS
Expand Down
43 changes: 4 additions & 39 deletions docs/preset-next.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
`preset-next` is the set of plugins that will become the [defaults](./preset-default.md) in version 6. To enable these plugins, use the
`--preset=next` option on the command line.
`--preset=next` option on the [command line](./command-line-options.md).

## Plugins List

Expand All @@ -15,9 +15,9 @@ The following plugins are included in `preset-next`, in the order that they're e
- [cleanupXlink](./plugins/cleanupXlink.md)
- cleanupStyleAttributes
- combineStyleElements
- inlineStyles
- [inlineStyles](./plugins/inlineStyles.md)
- minifyStyles
- cleanupIds
- [cleanupIds](./plugins/cleanupIds.md)
- removeUselessDefs
- convertColors
- [removeUnknownsAndDefaults](./plugins/removeUnknownsAndDefaults.md)
Expand All @@ -32,42 +32,7 @@ The following plugins are included in `preset-next`, in the order that they're e
- collapseGroups
- convertShapeToPath
- combinePaths
- minifyPathData
- [minifyPathData](./plugins/minifyPathData.md)
- removeEmptyAttrs
- removeEmptyContainers
- removeUnusedNS

## Disable a Plugin

Sometimes a specific plugin might not be appropriate for your workflow. You can continue using `preset-default` while disabling any plugin by using the `overrides` parameter.

In `overrides`, reference the plugin ID and set it to `false` to disable it:

```js
module.exports = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
cleanupIds: false,
},
},
},
],
};
```

Alternatively, you can drop `preset-default` entirely, and configure your own plugin pipeline from scratch, with only the desirable plugins:

```js
module.exports = {
plugins: [
'removeDoctype',
'removeXMLProcInst',
'minifyStyles',
'sortAttrs',
'sortDefsChildren',
],
};
```
3 changes: 0 additions & 3 deletions plugins/plugins-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ type DefaultPlugins = {
};
cleanupEnableBackground: void;
cleanupIds: {
remove?: boolean;
minify?: boolean;
preserve?: string[];
preservePrefixes?: string[];
force?: boolean;
};
cleanupNumericValues: {
floatPrecision?: number;
Expand Down
2 changes: 2 additions & 0 deletions plugins/preset-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createPreset } from '../lib/svgo/plugins.js';
import * as cleanupAttrs from './cleanupAttrs.js';
import * as cleanupIds from './cleanupIds.js';
import * as cleanupStyleAttributes from './cleanupStyleAttributes.js';
import * as cleanupXlink from './cleanupXlink.js';
import * as collapseGroups from './collapseGroups.js';
import * as combinePaths from './combinePaths.js';
import * as combineStyleElements from './combineStyleElements.js';
Expand Down Expand Up @@ -40,6 +41,7 @@ const presetDefault = createPreset({
removeEditorsNSData,
removeDesc,
cleanupAttrs,
cleanupXlink,
cleanupStyleAttributes,
combineStyleElements,
inlineStyles,
Expand Down