- applyTransforms is prepared to be a separate plugin, in v3 I will
remove it from convertPathData
- migrated to tsdoc
- removed optimisation with stroke-width inside id (still not idea how
it worked)
- added deoptimisation when id is on element to fix redefining in `<use>`
Note: review with hidden whitespaces
This is a big one
- got rid from another closestByName usage
- delegated removing empty defs elements to removeEmptyContainers plugin
- got rid from all css-tools usages (most inlineStyles code was there
for some reason)
- combined a few loops
- fixed useMqs option (I would remove it in v3 for simplicity as it
seems nobody use it)
- covered with tsdoc
- replace another closestByName usage with visitSkip symbol to skip
subtree instead of skipping element by ancestor
Better review with hidden whitespaces as most code just got bigger indent.
node.parentNode will be removed in v3 along with JSAPI class wrapper on
each node.
Style manager uses it to find inherited styles. To workaround this
I collected all parents along with all styles. This constraints style
manager to work only with initial ast which should not be a problem as
each plagin execution is isolated.
- covered with tsdoc
- migrated to visitor plugin api
- slightly simplified (hope so) logic by avoiding loop over order array
in every compare function call
- rewrote tests
Ref https://github.com/svg/svgo/issues/1499
- migrated to visitor plugin api
- covered with tsdoc
- made the plugin idempotent as requested a few times
Now even manually running svgo a few times will not duplicate
prefix in ids and classes
- run each plugin test twice to see which plugin need to run many times
ideally idempotent plugins will allow to get rid of multipass option in v3
Old SVGO errors were not very helpful. Packages like cssnano
(postcss-svgo) had to deal with a lot of issues which are hard to debug
with old errors.
```
Error: Error in parsing SVG: Unquoted attribute value
Line: 1
Column: 29
Char: 6
File: input.svg
```
New errors are more informative and may solve many struggles
```
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 |
```
I still did get how id generation works but data flow is clear now at
least.
- covered with types
- migrated to visitor plugin api
- got rid of traverse api
The logic is a little messy. Will be better when we drop node 12 support
and use optional chaining.
- migrated to visitor plugin api
- covered with types
- get rid from patching params as plugin state
- replaced many node.computedAttr() with style manager
- enabled and fixed removeNone param test (was merged as muted back in 2017)
- added ability to return null and not run visitor in plugins
- migrated to visitor plugin api; combination of enter and exit helped
to fit into single traverse
- got rid from the only node.clone() usage in the project so no need to
reimplement it
- the logic is a bit simplified
- got rid from two computeAttr usages
- got rid from node.parentNode usages
- avoided mutating global _collections objects
- refactored with visitor api
- covered with types
- skip whole foreignObject subtree not only its children
- refactored with visitor plugin api
- covered with types
- replaced parentNode traverse with visitSkip symbol
- replaced regex path parser with parsePathData
- get rid from global state which lead test case to invalid state
This should help to avoid node.parentNode and closestByName
in some cases by skiping visiting children of current node.
Works only in `enter` listener.
I saw complaints about `extendDefaultPlugins` api
- it cannot be used when svgo is installed globally
- it requires svgo to be installed when using svgo-loader or svgo-jsx
- it prevents using serializable config formats like json
In this diff I introduced the new plugin which is a bundle of all
default plugins.
```js
module.exports = {
plugins: [
'preset_default',
// or
{
name: 'preset_default',
floatPrecision: 4,
overrides: {
convertPathData: {
applyTransforms: false
}
}
}
]
}
```
Mocha doesn't have a lot of features provided by jest.
There is a great assertion library out of the box.
And the most cool feature is inline snapshots.
Mocha also hides errors which makes debugging a nightmare sometimes.
Visitor is a simple pattern which helps to avoid many type checks
and provide both "perItem" and "perItemReverse" functionality without
fragmentation.
The most important case is an ability to define state which in many
plugins specified either on module level or by polluting `params`.
In this diff I added visit and detachFromParent utilities and refactored
new mergeStyles plugin with it.
Also fixed bug when cdata content is merged into "text" node which is
not always valid.
Changed the TS config file to include all relevant folders and explicitly exclude those files that fail the type checks. In this way new files will be automatically type checked and we can see the list of files that need types improvements.
In this pass I also fixed some js files.
Added Typescript support via JSDoc comments for some files.
The code has really outdated type signatures, so in order to fully type the codebase the changes need to be incremental.
To check the types run:
npx tsc