1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00
Commit Graph

388 Commits

Author SHA1 Message Date
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
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
c3695ae533 Migrate to jest (#1520)
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.
2021-08-12 18:06:10 +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
17aaf3617f Cleanup collapseGroups tests 2021-03-28 20:23:39 +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
d89d36eace Split regression extracter and runner (#1451)
A lot of new sources of regression tests may come and it's important to
make debug simpler.

Now regression-extract.js downloads and write svg files into
test/regression-fixtures. regression.js run each svg in this folder.
Mismatched svg diff is written into test/regression-diffs.
2021-03-25 00:12:13 +03:00
eb934b40f6 Serve svg for regressions and cache w3c test suite 2021-03-23 00:29:29 +03:00
7389bcddbf Override default floatPrecision with global
Ref https://github.com/svg/svgo/issues/1426

Previously extendDefaultPlugins incorrectly overrided global
floatPrecision.
2021-03-22 19:36:05 +03:00
3d4adb6b04 Simplify number rendering and fix -0 in path
Ref https://github.com/svg/svgo/issues/1422
2021-03-22 14:38:06 +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
13a0ad056b Specify --ignore-path for ESLint (#1443)
Otherwise, all files are included
2021-03-21 17:57:55 +03:00
bc5c4ea29c Add a test for removeXMLNS plugin (#1444) 2021-03-21 17:30:36 +03:00
3390df1186 removeOffCanvasPaths: Add one more test (#1445) 2021-03-21 13:30:20 +03:00
f44612e7a2 addClassesToSVGElement: add one more test (#1441) 2021-03-21 10:26:57 +03:00
21d24006fd Remove the executable flag from files. (#1439) 2021-03-20 20:46:26 +03:00
b903de9554 test/config/_index.js: fix find usage (#1438) 2021-03-20 19:51:33 +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
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
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
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
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
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
c21fef54e1 Remove useless path commands considering static styles 2021-03-05 18:08:02 +03:00
d58a7e6089 Pass floatPrecision to implemented plugin 2021-03-05 17:48:19 +03:00
e2ec7e8bd2 [convertShapeToPath] round path numbers with precision (#1404)
Ref https://github.com/svg/svgo/issues/1051

Note: review with hidden whitespaces
2021-03-05 01:12:50 +03:00
4d0ee0c330 Test regressions with W3C SVG 1.1 Test Suite (#1357)
Visual regressions tests will give us more confidence in SVGO stability.
Test cases are downloaded from w3.org, screenshooted with playwright and
compared with pixelmatch.
2021-03-04 18:00:15 +03:00
be28d65d78 Implement style computing (#1399)
Ref https://github.com/svg/svgo/issues/777

Currently a lot of optimisations are attributes specific and may be
broken because of inline or shared styles.

In this diff I'm trying to solve the problem with getComputedStyle
analog.

`computeStyle` collects attributes, shared css rules, inline styles
and inherited styles and checks whether they can be statically optimised
or left as deoptimisation.
2021-03-04 13:13:44 +03:00
318bd5b8fa Forbid invalid <style> type attribute (#1400)
This fixes one more case in regression tests.
Also I added support for description in test cases.
This will let make tests more atomic.
2021-03-03 13:20:55 +03:00
66bb0fb2ad Commit fixtures 2021-03-03 12:32:43 +03:00
04b2ae9a37 Implement path stringify (#1387)
Ref https://github.com/svg/svgo/issues/32

Added `stringifyPathData` utility to produce small as possible path by
- matching leading moveto and line to commands (m -> l, M -> L)
- combining moveto and lineto commands
- avoiding space before decimal numbers if possible
2021-03-02 01:07:26 +03:00
7901588a9f Fix path optimisation with stroke-linecap round
Ref https://github.com/svg/svgo/issues/890
2021-02-28 15:22:27 +03:00
79dbb4bf6e Prevent applyTransform when inline style present
Ref https://github.com/svg/svgo/issues/1385

With disabled convertStyleToAttrs applyTransform fails to transform
inline styles. They are considered as deoptimisation for now.
Future style manager should fix the problem.
2021-02-28 14:46:32 +03:00
a99cc08e4f Format tests with prettier (#1380)
Will format the code with prettier in a few commits.
2021-02-27 23:17:47 +03:00
dd37fcfebb Apply scale to stroke-dasharray and stroke-dashoffset 2021-02-25 13:45:03 +03:00
d06747abca Keep hidden elements if any descendant enables visibility 2021-02-25 00:05:26 +03:00
9d67586787 Keep transparent elements inside <clipPath> 2021-02-24 22:58:00 +03:00
d14315b68f Keep empty <mask> which can hide element by id 2021-02-24 21:13:30 +03:00