1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-27 07:02:06 +03:00
Commit Graph

98 Commits

Author SHA1 Message Date
Kendell R
14bdacc2df feat(convertPathData): replace with z and remove z when optimal (#1822) 2023-11-12 13:52:01 +00:00
Marvin Hagemeister
c641da2734 Speed up strongRound by avoiding string casting (#1716)
I'm currently profiling my build pipeline and noticed that the
`strongRound` function showed up a couple of times, followed immediately
with a bit of GC cleanup shortly after. We can speed up that function by
avoiding the string casting caused by `Number.prototype.toFixed()`.

In my project's build pipeline with lots of svg icons this saves about
1.4s in total.

<img width="792" alt="js-tools-strongRound"
src="https://user-images.githubusercontent.com/1062408/204393563-666be3e0-e0ee-4608-9b7d-9ea8352bd36b.png">
2022-11-30 11:53:39 +03:00
Bogdan Chadkin
e2e65cfc1e Move plugin types into d.ts 2022-11-11 12:19:38 +03:00
Bogdan Chadkin
f5d1dd06cc Loosly cover with types convertPathData 2022-10-16 14:53:04 +03:00
Bogdan Chadkin
e6bd703b0a Remove unused active and type fields from plugins 2022-10-08 23:39:58 +03:00
Bogdan Chadkin
954faf3c87 Remove default plugin.params support 2022-10-02 19:43:06 +03:00
Bogdan Chadkin
068db0e894 Refactor applyTransforms (#1637)
- applyTransforms is prepared to be a separate plugin, in v3 I will
  remove it from convertPathData
- migrated to tsdoc
- removed optimisation with stroke-width inside id (still not idea how
  it worked)
- added deoptimisation when id is on element to fix redefining in `<use>`

Note: review with hidden whitespaces
2022-01-19 20:41:10 +03:00
Bogdan Chadkin
539237ce87 Normalize path data structure (#1538)
Use modern path data structure in all plugins.
Will be easier to cover with types.
2021-08-24 00:01:18 +03:00
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
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
Bogdan Chadkin
3d79f57a10 Convert convertPathData to visitor 2021-03-29 11:01:13 +03:00
Bogdan Chadkin
316a002299 Remove hasAttr and hasAttrLocal usages (#1447)
In most cases simple check for null is enough.
2021-03-22 01:24:59 +03:00
Bogdan Chadkin
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
Bogdan Chadkin
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
Bogdan Chadkin
ba7e9bdc0d Fix collapsing repeated with marker-mid in style rule 2021-03-06 01:36:18 +03:00
Bogdan Chadkin
c21fef54e1 Remove useless path commands considering static styles 2021-03-05 18:08:02 +03:00
Bogdan Chadkin
7901588a9f Fix path optimisation with stroke-linecap round
Ref https://github.com/svg/svgo/issues/890
2021-02-28 15:22:27 +03:00
XhmikosR
1310210d4e Use https when possible and fix an inactive domain (#1374) 2021-02-25 13:48:18 +03:00
Bogdan Chadkin
9263d9ab90 Fix svg spec urls in plugins 2021-02-24 11:18:48 +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
jlherren
dfe649fa8d Fix collapsing of repeated commands in convertPathData plugin
This fixes #1166
2019-11-05 19:22:43 +03:00
GreLI
8671c4c3df Fix incorrect prev arc segment angle calculation.
Close #1109
2019-07-14 12:07:59 +03:00
GreLI
258fecfa6b Remove spaces after ‘arcto’ path command flags 2019-07-13 16:18:08 +03:00
GreLI
5800635226 Fix converting to large arcs from nearly straight lines curves
Fix #842
2018-09-16 17:12:06 +03:00
GreLI
831f95fccc Fix empty path segments removing with stroke-linecap
Fix #1017
2018-09-16 15:36:41 +03:00
Mikuláš Sychra
e928c1f050 Update convertPathData.js (#906)
Added parameter forceAbsolutePath to get absolute SVG path (even when the relative path is shorter).
2018-09-15 14:40:34 +03:00
David Leston
cd8a405aa2 Removed an assigned value that's never used. Also fixed typos. (#764) 2017-09-14 21:25:51 +03:00
GreLI
4e320d9d56 Apply smart rounding only if need to round.
Fixes #508. Resolves #284.
2016-03-20 20:52:37 +03:00
GreLI
0f599b670d Fixed regression due to angle calculation changes. Fixes #517 2016-03-20 12:30:06 +03:00
GreLI
1335334cc7 Fixed crashing on invoking rounding several times. Closes #480 2016-01-13 17:17:26 +03:00
GreLI
044fc3b168 Correct all angle calculations to use circle radii instead of curves control points 2016-01-09 19:35:18 +03:00
GreLI
1b0051ad1c Fixed angle calculation with zero length curve control point.
Fixes #477
2016-01-06 13:57:19 +03:00
GreLI
3a7f4ea070 New optimization in paths: curves to arcs 2015-11-08 18:23:45 +03:00
GreLI
97bbd21553 Simplified straight curve checking function 2015-09-18 19:16:44 +03:00
GreLI
40b57f3980 Fixed shortand curve distortion due to converted prev curve. Resolves #415 2015-09-18 18:50:17 +03:00
GreLI
a7f62d8984 Formatting 2015-06-21 19:13:41 +03:00
Yoshiya Hinosawa
73c5a73900 Modify jshint rules 2015-06-13 18:32:19 +09:00
Yoshiya Hinosawa
3f8e6fd15c Fix lint 2015-06-12 00:25:32 +09:00
Yoshiya Hinosawa
8e6b365c40 Add --show-plugins option 2015-06-07 19:35:49 +09:00
GreLI
ff5e89d5bf Reworked transform manipulation 2015-05-24 20:50:47 +03:00
GreLI
e220b6cad0 Path data processing improvements.
Improved path data saving.
Collapse repeated now works at writing path data and doesn't affect pathJS to make further processing easier.
Resolves #204.
2015-03-17 22:03:17 +03:00
GreLI
5e7caa49dc Code styling 2015-02-08 19:31:55 +03:00
Samar Panda
1ccdc0d76b Adding a sanity check before proceeding 2014-12-18 10:53:33 +05:30
GreLI
ccce15312c Applied ‘moveto’ command collapsing to starting ‘M‘ as well 2014-11-04 15:44:35 +03:00
GreLI
6eb271683b Fixed misplacing due to incorrect collapsing of path ‘moveto’ commands, fixes #189 2014-11-03 01:28:07 +03:00
GreLI
25d123134d Added ‘index’ for linked path item and a test for path translation after ‘z’ 2014-11-02 14:16:14 +03:00
GreLI
10146b5498 Fixed bug with translate not applied to path after ‘z’ command 2014-11-02 14:02:33 +03:00
GreLI
2b235f9fe2 Linked filtered out path segments to previous for next checks 2014-11-01 22:26:34 +03:00
GreLI
06028a69de Path data optimization improvements.
Writes absolute coordinates if it's shorter.
Relative coordinates rounding now takes in account accumulating error. Points will be closer to original values.
Rounding is smarter like 2.49 to 2.5.
2014-07-31 20:13:57 +04:00
Kalashnikov Igor
4c4ced858d skip data concatenation for z instruction in collapseRepeated 2014-01-02 23:04:35 +04:00