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

318 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
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
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
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
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
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
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
c21fef54e1 Remove useless path commands considering static styles 2021-03-05 18:08:02 +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
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
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
36391564f2 Preserve stroke-width when marker-end is specified 2021-02-24 17:29:29 +03:00
091172a392 Fix <tspan> inside of <a> 2021-02-24 14:10:33 +03:00
c1d5f0f7a9 Keep empty <g> when filter attributes is specified 2021-02-23 22:36:47 +03:00
776ec1e71b Fix incorrect xml:space default 2021-02-23 18:43:28 +03:00
9f084cc086 Preserve whitespace in elements containing text (#1220) 2021-02-23 18:25:30 +03:00
8d7cfa02c7 After ‘arcto’ path command(a or A) flags, spaces are no longer removed by default (#1353)
Co-authored-by: 壹丝 <jie.lijie@alibaba-inc.com>
2021-02-20 18:58:42 +03:00
d9f68d3be0 [removeElementsByAttr] fix removing elements when class is empty
Ref https://github.com/svg/svgo/issues/937

Regexp didn't not cover the case when class list is empty.
2021-02-20 16:54:46 +03:00
7f4e05297a [convertEllipseToCircle] fix ellipse without radius
Ref https://github.com/svg/svgo/issues/1264
2021-02-20 12:50:36 +03:00
b9880491b5 [reusePaths] fix excessive defs tag (#1201) 2021-02-19 23:56:20 +03:00
a7cc20bb43 Setup recommended eslint preset (#1345)
This is usually enough to prevent silly mistakes.
Formatting will be done by prettier after merging pull requests.
2021-02-19 15:26:07 +03:00
c9a3aea858 Path intersection was not checking paths with circles. (#1229)
As an optimization the path intersection was checking the paths had three or more elements, caliming that otherwise there was nothing to fill. However a semi circle would actually contain 2 points.

Fixes #1048.

This adds a simplified test case for the 2 offending files reported in the issue.
2021-02-17 23:50:08 +03:00
c9c7871e0d Simplify svgo api (#1325)
Dropped SVGO class and provided "optimize" function with svg and config
as inputs and "createContentItem".
2021-02-15 18:32:50 +03:00
1b776ffea5 Simplify plugins configuration (#1324)
- replaced named plugin object with "name" field
- dropped support for params in plugin object; use only params to pass plugin options
- dropped support for "boolean plugins"; use active field instead

```diff
-{
-  pluginName: {
-    fn,
-    params: {},
-    ...params
-  }
-}
+{
+  name: 'pluginName',
+  fn,
+  params: {}
+}
```
2021-02-15 14:30:09 +03:00
6cecd76f62 Remove config extending and full flag support 2021-02-15 13:12:29 +03:00
2965e8ccdb Drop plugin by path support and load builtins statically 2021-02-15 12:00:45 +03:00
8899f682b8 Remove coverage imports from tests 2021-02-15 02:41:28 +03:00
bc44ab3f29 Refactor assertions with chai expect 2021-02-14 15:12:41 +03:00
1dc5ee3ee1 Make optimize synchronous (#1322)
Ref https://github.com/svg/svgo/issues/1015

Looks like `sax` is synchronous and we do not need to listen "end"
event. This allows to avoid all callbacks and make `optimize` method
synchronous.
2021-02-14 14:59:50 +03:00