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

530 Commits

Author SHA1 Message Date
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
0e02fd9fde Fix noSpaceAfterFlags support 2021-03-04 13:15:36 +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
a896d5de13 Format plugins utilities with prettier (#1394)
Note: review with hidden whitespaces
2021-03-03 01:33:44 +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
4086e31334 Implement new path parser (#1378)
Regexps are quite leaky for complex parsing. Regression tests caught
a few issues related to path parser.

In this diff I implemented the new spec-compliant parser which solves
2 regression cases and covers many edge cases hard to handle with
regexps.
2021-02-28 22:10:57 +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
0394bf0ea6 refactor: replace uses of for in (#1382)
Replace the uses of `for in` with `for of` and `Object.entries`/`Object.values`/`Object.keys`.

One case was further simplified by using a spread.
2021-02-27 23:17:30 +03:00
1310210d4e Use https when possible and fix an inactive domain (#1374) 2021-02-25 13:48:18 +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
9263d9ab90 Fix svg spec urls in plugins 2021-02-24 11:18:48 +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
a1fcd034fe Disable convertStyleToAttrs plugin by default (#1365)
Ref https://github.com/svg/svgo/issues/1362 https://github.com/svg/svgo/issues/1360

From the [spec](https://www.w3.org/TR/SVG11/styling.html#UsingPresentationAttributes):

> Presentation attributes have lower priority than other CSS style rules specified in author style sheets or ‘style’ attributes.

Though we replace inline styles with attributes without checking if
thare is any `<style>` element. This makes the plugin unsafe and it
should not be enabled by default.
2021-02-23 00:28:09 +03:00
9b97e06ef6 Fix empty <svg /> in cleanupIDs plugin 2021-02-21 14:50:55 +03:00
727646e6a7 convertTransform: remove unused assignment (#1354) 2021-02-20 22:31:56 +03:00
c1edce4d2d Fix error message in addAttributesToSVGElement plugin
Ref https://github.com/svg/svgo/issues/1352
2021-02-20 19:04:46 +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
6c0f8c5efb reusePaths: fix redundant variable assignment (#1349) 2021-02-20 17:31:34 +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
4490d62ee9 Add mask-type to the list of <mask> attributes
Ref https://github.com/svg/svgo/issues/1254
2021-02-20 13:59:21 +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
136a52cdb6 convertStyleToAttrs: fix wrong character class (#1338) 2021-02-19 02:30:05 +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
fd5e6406b1 Upgrade css-select 2021-02-16 19:14:20 +03:00
d273b26605 Provide es module bundle for browser (#1326)
The was a lot of requests to provide browser compatible module. In this
diff I added `svgo/dist/svgo.browser.js` bundle and tested it with
playwright.
2021-02-16 19:11:01 +03:00
70d1f2b2f8 Upgrade css-tree and csso 2021-02-16 18:14:10 +03:00
225bfbb053 Move config processing into optimize 2021-02-15 16:57:01 +03:00
2965e8ccdb Drop plugin by path support and load builtins statically 2021-02-15 12:00:45 +03:00
77464801e7 Fix cleanupIDs if defs is last elem of svg 2019-11-09 21:41:17 +03:00
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
fafcbd7bd0 Fix prefixIds plugin error with animations
Fix #848
2019-11-08 18:36:45 +03:00
dfe649fa8d Fix collapsing of repeated commands in convertPathData plugin
This fixes #1166
2019-11-05 19:22:43 +03:00
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
71c7fe74b9 Add multipassCount to info object passed to the plugins.
Use info object to skip subsequent passes in prefixIds plugin to prevent unintended, multiple prefixing.
2019-10-29 22:50:59 +03:00
023013abf9 Use ’force’ option in ‘mergePaths’ only for paths with same attributes 2019-07-14 19:22:59 +03:00
e1dd31cf84 Fix 180deg ‘convertTransform’
Fix NaN after Math.acos due to error making illegal value out of bounds
Fix #1101
2019-07-14 18:51:50 +03:00
8671c4c3df Fix incorrect prev arc segment angle calculation.
Close #1109
2019-07-14 12:07:59 +03:00
5ee68c4808 Add options to prefixIds plugin for selectively prefixing IDs and/or classes. 2019-07-13 22:51:06 +03:00