Skip to content

Commit

Permalink
Updated docs. (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 authored Oct 3, 2024
1 parent 6b0d646 commit f01342c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
28 changes: 28 additions & 0 deletions docs/plugins/cleanupStyleAttributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# cleanupStyleAttributes

Removes invalid style properties and unreferenced class attribute names.

## 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.

### `style` Attributes

Properties that are not valid for a particular element are removed.

For `<g>` elements whose only children are shapes, properties relating to text and fonts are removed.

The `style` attribute is removed from all animation elements.

The list of allowable properties comes from https://www.w3.org/TR/SVG2/styling.html#PresentationAttributes, and also includes the `font` shorthand property.

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

### `class` Attributes

Any class names in the `class` attribute which are not referenced by a style selector are removed. If all class names are removed, the class attribute is removed.

Class attributes are not changed if the document has attribute selectors on the `class` attribute.
31 changes: 25 additions & 6 deletions docs/plugins/removeUnknownsAndDefaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,44 @@
Removes unknown elements and attributes, as well as attributes that are set to their default value.
It also removes the the `standalone` declaration from the DTD if [`standalone`](https://www.w3.org/TR/REC-xml/#sec-rmd) is set to `no`.

## 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 not processed:
The following elements and attributes are not processed:

- Any element with a namespace prefix.
- Any `<foreignObject>` elements and their children.
- Any attributes whose name starts with `aria-` or `data-i`.
- `xmlns` attributes are never removed.
- Attribues with a namespace prefix are never removed unless the prefix is `xml` or `xlink`.
- Attributes with a namespace prefix are never removed unless the prefix is `xml` or `xlink`.

### Elements

Elements are removed if:

- They are not allowed as children of their parents.

Attributes set to a default value are removed if:
### `style` attributes

Style attribute properties are removed if they are not in an element which is referenced by a `<use>` element (or are a child of any such element), and removing the property does not change the effective style on the element.

### Other attributes

Attributes are always removed if there is a `style` attribute property which overrides the attribute.

Attributes are removed if they are not valid for the element.

Otherwise attributes are removed if both:

- They are either

- not inheritable, and are set to a default value, or
- inheritable, and either have the same value as the parent element, or have a default value, and are not overriding the value of the parent element

and

- They are not overriding a value set by an ancestor, and
- they are not in an element that has an id (e.g., a `linearGradient` or similar element which may be referenced elsewhere)
- they are not in an element which is referenced by a `<use>` element (or a child of any such element).
- they are not in an element which is referenced by a `<use>` element (or are a child of any such element).
5 changes: 2 additions & 3 deletions docs/preset-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

## Plugins List

The following plugins are included in `preset-default`, in the order that they're executed:
The following plugins are included in `preset-default`, in the order that they are executed:

- removeDoctype
- removeXMLProcInst
- removeComments
- removeMetadata
- removeEditorsNSData
- removeDesc
- cleanupAttrs
- [cleanupXlink](./plugins/cleanupXlink.md)
- cleanupStyleAttributes
- [cleanupStyleAttributes](./plugins/cleanupStyleAttributes.md)
- combineStyleElements
- [inlineStyles](./plugins/inlineStyles.md)
- minifyStyles
Expand Down
5 changes: 2 additions & 3 deletions docs/preset-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@

## Plugins List

The following plugins are included in `preset-next`, in the order that they're executed:
The following plugins are included in `preset-next`, in the order that they are executed:

- removeDoctype
- removeXMLProcInst
- removeComments
- removeMetadata
- removeEditorsNSData
- removeDesc
- cleanupAttrs
- [cleanupXlink](./plugins/cleanupXlink.md)
- cleanupStyleAttributes
- [cleanupStyleAttributes](./plugins/cleanupStyleAttributes.md)
- combineStyleElements
- [inlineStyles](./plugins/inlineStyles.md)
- minifyStyles
Expand Down
2 changes: 0 additions & 2 deletions plugins/preset-default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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';
Expand Down Expand Up @@ -40,7 +39,6 @@ const presetDefault = createPreset({
removeMetadata,
removeEditorsNSData,
removeDesc,
cleanupAttrs,
cleanupXlink,
cleanupStyleAttributes,
combineStyleElements,
Expand Down

0 comments on commit f01342c

Please sign in to comment.