1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-01 18:21:40 +03:00
Commit Graph

530 Commits

Author SHA1 Message Date
6cb2f7034f Drop node.style usages (#1534)
Parsing inline styles with csstree in place is easier.
Caching does not add much value here.
2021-08-22 16:18:55 +03:00
98c023bdb0 Drop node.class usages (#1533)
We are gonna remove everything outside of xast.
Here's dropped class prop.
2021-08-21 19:42:32 +03:00
e4918ccdd1 Covert removeHiddenElems with types (#1532)
Covered removeHiddenElems plugin and big part of our code
- path parser and stringifier
- style manager
2021-08-21 14:55:05 +03:00
75ec2943b0 Update minor and patch dependencies (#1528)
* @rollup/plugin-node-resolve  ^11.2.0  →  ^11.2.1
* @types/jest                  ^27.0.0  →  ^27.0.1
* colorette                     ^1.2.2  →   ^1.3.0
* commander                     ^7.1.0  →   ^7.2.0
* css-tree                      ^1.1.2  →   ^1.1.3
* eslint                       ^7.22.0  →  ^7.32.0
* playwright                    ^1.9.2  →  ^1.14.0
* prettier                      ^2.2.1  →   ^2.3.2
* rollup                       ^2.42.1  →  ^2.56.2
* typescript                    ^4.2.3  →   ^4.3.5
2021-08-15 13:57:58 +03:00
9b8f13e911 Add plugin types (#1527)
Covered following plugins
- addAttributesToSVGElement.js 
- addClassesToSVGElement.js 
- cleanupAttrs.js 
- convertEllipseToCircle.js 
- removeAttributesBySelector.js 
- removeAttrs.js 
- removeComments.js 
- removeDesc.js 
- removeDoctype.js 
- removeElementsByAttr.js 
- removeEmptyText.js 
- removeMetadata.js 
- removeRasterImages.js 
- removeScriptElement.js 
- removeStyleElement.js 
- removeTitle.js 
- removeXMLProcInst.js
2021-08-15 13:52:41 +03:00
7ec255719c Refactor adhoc plugins with visitor api (#1526)
- addAttributesToSVGElement
- addClassesToSVGElement
- removeAttributesBySelector
- removeAttrs
- removeElementsByAttr
2021-08-14 16:48:39 +03:00
e6b441aca0 Convert cleanupListOfValues and cleanupNumericValues to visitor (#1521)
SLightly refactored
2021-08-14 16:48:32 +03:00
7b6e73048f moveElemsAttrsToGroup.js: fix missing return value in Array.every() (#1525) 2021-08-14 13:12:23 +03:00
b41c6fe473 removeUselessStrokeAndFill.js: use String.startsWith() (#1522) 2021-08-14 13:09:57 +03:00
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
9e578b515a Reset current cursor on Z
Ref https://github.com/svg/svgo/issues/1510
2021-08-13 18:39:55 +03:00
9892e28a71 Refactor convertShapeToPath with visitor api (#1519)
This plugin also removes invalid polyline and polygon.
Looks like out of pluginn scope.
2021-08-12 21:21:38 +03:00
f00bd727b0 Refactor basic plugins with visitor api (#1518)
- cleanupAttrs
- convertEllipseToCircle
- removeDesc
- removeDoctype
- removeEmptyText
- removeMetadata
- removeRasterImages
- removeScriptElement
- removeStyleElement
- removeTitle
- removeXMLProcInst
2021-08-12 14:57:36 +03:00
35b7356ff0 Pass parent node to visitor (#1517)
Wrapping each node with JSAPI class and passing parent to it is not
reliable. Parent may be changed but the reference will stay.

Here I wasn't able to detach comment from parent node for some reason.
Explicit parent node inferred while ast traverse is easier to debug and
work with. Eventually we will not need to wrap each node with JSAPI class.
2021-08-12 13:05:09 +03:00
2c0c361074 Collect stylesheet once per plugin (#1456)
computeStyle(node) in isolation is quite slow utility because it
collects style elements across whole document, parses and sort them.

In this diff I splitted it into `collectStylesheet(root)` and
`computeStyle(stylesheet, node)` which are easy integrate with new
visitor plugin api.
2021-08-12 03:08:39 +03:00
3d79f57a10 Convert convertPathData to visitor 2021-03-29 11:01:13 +03:00
06110b4fc0 Convert mergePaths to visitor 2021-03-29 03:08:15 +03:00
368a67b70f Convert removeHiddenElems to visitor 2021-03-29 02:34:34 +03:00
27bef1a954 Add "visitor" plugins support (#1454)
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.
2021-03-28 11:20:17 +03:00
19c77d2398 Add mergeStyles plugin (#1381) 2021-03-27 16:59:56 +03:00
316a002299 Remove hasAttr and hasAttrLocal usages (#1447)
In most cases simple check for null is enough.
2021-03-22 01:24:59 +03:00
447f82ca6b Convert addAttributesToSVGElement to item plugin (#1448)
"full" plugins prevents from possible optimisation. We need to migrate
all plugins to "perItem" type and later implement visitor plugin api to
allow state.
2021-03-22 01:24:41 +03:00
21d24006fd Remove the executable flag from files. (#1439) 2021-03-20 20:46:26 +03:00
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
6f2f62c5ee Access attributes directly (#1433)
Got rid from `.attrs`, `.attr()` and `.addAttr()` usages
2021-03-18 18:53:20 +03:00
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
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
c925e4da0a Fix ts 2021-03-15 21:34:36 +03:00
61657433e1 Refactor apply transforms
- handle each command separately
- handle both relative and absolute commands
- moved into _applyTransforms.js to convert eventually into plugin
- apply transforms before converting into relative

These changes makes code independent and easy to work with.
2021-03-15 21:24:23 +03:00
92053c7ed8 Remove broken optimisation 2021-03-15 15:07:28 +03:00
a04b27a1df Refactor convertToRelative
Slight code simplification. Each command is processed exclusively
without assumtions. Removed moveto and closepath common coords
reference, handle in applyTransform instead. Rely on new path data
naming.
2021-03-15 13:41:12 +03:00
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
3e1bfd528d Convert attributes to xast with proxy fallback
There is a lot of attributes manipulation which is hard to remove at
once. In this diff I added `attributes` object and wrapped it as proxy
for `attrs` field.
2021-03-10 23:11:09 +03:00
685d9fa55e Fix lint 2021-03-10 18:51:50 +03:00
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
194058b9eb Clarify condition and add todo with new plugin 2021-03-10 16:22:37 +03:00
c50decb438 Convert cdata and text nodes to xast
Ref https://github.com/syntax-tree/xast

More consistent naming and distinction by type looks a bit cleaner.
2021-03-10 16:16:11 +03:00
5161156418 Fix types 2021-03-10 14:22:38 +03:00
8622a5f31b Convert to xast doctype, instruction and comment nodes
Here we add [xast](https://github.com/syntax-tree/xast) support
to three basic nodes: doctype, instruction and comment

Some tests are rewritten instead of checking each field to `.include`
assertion which is able to match shape of object.
2021-03-10 14:10:40 +03:00
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
2458b70f31 Remove licenses 2021-03-09 23:40:36 +03:00
00ec0f71fe Format all plugins with prettier 2021-03-09 19:58:00 +03:00
28c01cfe65 Preverve viewBox in nested <svg> 2021-03-06 13:39:31 +03:00
a2b0e73767 Preserve conditional processing attributes 2021-03-06 13:18:53 +03:00
d3e3726ac4 Keep markers with display: none 2021-03-06 11:21:47 +03:00
0e6b0c4a01 Allow empty pattern when any attribute is present 2021-03-06 02:33:19 +03:00
ba7e9bdc0d Fix collapsing repeated with marker-mid in style rule 2021-03-06 01:36:18 +03:00
21c04e4d8a Keep single point path for markers 2021-03-06 01:01:32 +03:00
de4fd79b57 Prevent merging path when marker-end style is specified
Ref https://github.com/svg/svgo/issues/1217 https://github.com/svg/svgo/issues/958 https://github.com/svg/svgo/issues/872
2021-03-06 00:37:03 +03:00
555a9619db Remove incorrect filter region assumption
Ref https://www.w3.org/TR/SVG11/filters.html

Spec says filter region is not always 100% 100% by default
2021-03-05 21:31:41 +03:00