1
0
mirror of https://github.com/svg/svgo.git synced 2025-04-19 10:22:15 +03:00

38 Commits

Author SHA1 Message Date
Bogdan Chadkin
07f8d606e0
Implement preset-default plugin (#1513)
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
        }
      }
    }
  ]
}
```
2021-08-13 19:07:08 +03:00
Bogdan Chadkin
4cacd9e676
Migrate ast traversing into xast module (#1434)
Replaced JSAPI methods with new utilities

- querySelectorAll(node, selector)
- querySelector(node, selector)
- matches(node, selector)
- closestByName(node, elementName)
- traverse(node, fn)

New traverse replaced many in-place implementations.
2021-03-19 11:06:41 +03:00
Bogdan Chadkin
6f2f62c5ee
Access attributes directly (#1433)
Got rid from `.attrs`, `.attr()` and `.addAttr()` usages
2021-03-18 18:53:20 +03:00
Bogdan Chadkin
07928fc77e
Replace removeAttr with delete operator (#1432)
delete operator is more explicit and not much harder to use.
2021-03-17 21:40:06 +03:00
Bogdan Chadkin
8098ab7fb6
Replace attributes iterators with for/of (#1431)
These iterators allows to directly manipulate passed value
which does not let us to get rid from legacy "attrs" field.

Object.entries makes it easier to get an access to both attribute
name and value.
2021-03-17 12:50:16 +03:00
Bogdan Chadkin
5314c12c99 Convert element children to xast
Ref https://github.com/syntax-tree/xast

Renamed content to children to match xast spec.
2021-03-11 12:29:13 +03:00
Bogdan Chadkin
e82a672bbf Prepare root and element nodes for xast
Ref https://github.com/syntax-tree/xast

- added type: root | element
- renamed elem to name
- replaced "elem" property checks with check for correct type
2021-03-10 18:49:26 +03:00
Bogdan Chadkin
d1d6e5efe8
Remove prefix/local support in elements and attributes (#1413)
These parts of element and attribute name are easy to extract.
Now we can easily replace attrs with xast attributes object.
2021-03-10 13:26:15 +03:00
Bogdan Chadkin
00ec0f71fe Format all plugins with prettier 2021-03-09 19:58:00 +03:00
Bogdan Chadkin
9b97e06ef6 Fix empty <svg /> in cleanupIDs plugin 2021-02-21 14:50:55 +03:00
alexpavlovich
77464801e7 Fix cleanupIDs if defs is last elem of svg 2019-11-09 21:41:17 +03:00
Cyrille David
1152257505 Perform cleanupIDs optimization when style/script tag is empty
cleanupIDs plugin is disabled when a script or style tag is present. I
assume that this is because they might contain an id.

If these tags are empty there is no point in not cleaning the id though.
When running svgo with the option `multipass: true`, it allows us to
first run `inlineStyles` plugin to empty the style tag. Then, we can run
`cleanupIDs` plugin.
2019-11-08 22:58:43 +03:00
James Thomson
0e6b0ad8e5 Fix 'cleanupIDs' minify bug due to preserved IDs
Prevent 'cleanupIDs' plugin from producing a preserved ID, including one
which matches a preserved prefix, when minifying.

Closes #1158
2019-10-29 22:54:36 +03:00
Brad Kotsopoulos
7eeb5d064d Add config to preserve IDs based on prefix matching (#1060)
add parameter to preserve IDs based on prefix matching
2019-02-24 21:02:03 +03:00
GreLI
f8234fd3f8 Prevent removing IDs in SVGs only with defs 2017-10-22 18:41:35 +03:00
Cyril Auburtin
661e6d1570 Update cleanupIDs.js
begin an be `"0s;third.end"`

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/begin
2017-08-10 16:16:30 +02:00
GreLI
2608ae1467 Use Map/Set in cleanupIDs 2017-02-05 22:59:19 +03:00
Velenir
f3bff1fd32 Add tests for force=true in cleanupIDs
Add parameter force to ignore style and script in cleanupIDs

Add tests for except=[ids] in cleanupIDs

Add parameter except in cleanupIDs to skip cleaning up specific ids
2016-10-08 22:00:21 +03:00
Lev Solntsev
8abdef7742 Revert changes in cleanupIDs requiring 0.12. Fixes #602 2016-09-27 11:25:14 +03:00
GreLI
c6f77d99ec Linter fixes 2016-08-25 22:20:14 +03:00
GreLI
cf20f5c6ca Loosed fixes 2016-08-25 22:18:04 +03:00
GreLI
d9e670c210 Use maps in cleanupIDs. Fixes #562 2016-08-25 22:14:34 +03:00
Tom Bigelajzen
4865892f6e When minify:false cleanupIds deletes too many ids
when running cleanupIds with minify:false option it does not save a reference to all ids and removes ids that shouldn't be removed.
This fix adds a var that keeps a ref to the original id even if minify is not defined
2016-08-19 18:38:23 +03:00
GreLI
619aaf8481 Check ‘style’ attr for id reference. Fixes #515 2016-03-12 15:27:34 +03:00
GreLI
c3e0eb6b00 Check for "href’ by local name 2016-03-11 13:31:30 +03:00
GreLI
c19511ef7a stop cleanupIDs if there is style or script 2015-09-13 15:29:32 +03:00
Bo Lopker
176d0329a4 Clean up cleanupID logic, use null prototype for maps
Reduce string creation

Add test for __proto__
2015-09-13 15:29:32 +03:00
GreLI
a7f62d8984 Formatting 2015-06-21 19:13:41 +03:00
GreLI
2c2f9e7e26 Use first item of few with same ID (as browsers do). Remove subsequent IDs. Resolves #378 2015-06-21 18:32:50 +03:00
GreLI
20e2a30773 Update ID in animateMotion ‘begin’ attribute. Fixes #373 2015-06-21 18:20:44 +03:00
GreLI
b5d4166fa9 Fixed removing id with quoted reference. Fixes #372 2015-06-21 17:17:04 +03:00
Yoshiya Hinosawa
8e6b365c40 Add --show-plugins option 2015-06-07 19:35:49 +09:00
GreLI
73ca6b2cb7 Fix cleanupIDs not working for style references 2015-03-15 13:01:11 +03:00
GreLI
54f4b33e26 Fix for id prefixing 2015-02-01 22:58:43 +03:00
GreLI
ad538aac46 Prefix IDs in a dictionary to avoid breaking on some reserved keywords. Fixes #309 2015-02-01 15:39:57 +03:00
Daniel Mazurkiewicz
72a7186fcc Update cleanupIDs.js
added "prefix" parameter to solve problem of combining multiple svg into one svg or html file
2014-04-06 19:05:34 +02:00
deepsweet
2816424ed7 global refactoring dump 2013-04-09 22:06:27 +03:00
deepsweet
40ab77680a plugins/cleanupIDs: renamed from removeUnusedIDs; minify used IDs (fix #7) 2012-12-17 22:32:00 +02:00