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

1315 Commits

Author SHA1 Message Date
bb3f1a99ef [new plugin] reimplement inlineDefs
The code is taken from https://github.com/svg/svgo/pull/976, refactored
with new api, covered types and simplified.

Plugin has no dependencies so can be used without changing.

```
const inlineDefs = require('./inlineDefs.js');

module.exports = {
  plugins: [
    'preset-default',
    inlineDefs
  ]
};
```
2022-02-21 19:12:53 +03:00
238d3bf600 Refactor convertStyleToAttrs (#1635)
Did not rewrite much, just migrated to tsdoc and visitor plugin api.
This plugin will be obsolete eventually.
2022-01-20 10:55:01 +03:00
aaf1cfa5e7 Refactor removeNonInheritableGroupAttrs and moveGroupAttrsToElems (#1636)
Batched in one PR. Pretty simple changes. Just migrated to api and
added more safety checks for types.
2022-01-19 20:42:13 +03:00
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
bbc6baca78 Plugin definitive guide (#1624)
This is just initial thoughts. Feel free to suggest any changes.

Here are described only the new visitor plugins api. Old "full", "perItem", "perItemReverse" will be removed in v3. Old JSAPI class on every node will be also removed so nodes could be plain objects.
2022-01-09 14:27:04 +03:00
590b6b4205 Fix branch name in workflow 2022-01-09 14:20:31 +03:00
04abd6fc59 Correct typo in comment in removeDimensions plugin (#1633) 2021-12-28 16:15:55 +03:00
dfc5b982c9 Rename master branch to main 2021-12-25 15:09:34 +03:00
700f203169 Fix newline in tests 2021-12-25 15:03:29 +03:00
8ae65b7282 Improve configuration documentation
See https://github.com/svg/svgo/pull/1619

Thanks to @hugolpz
2021-12-25 14:45:15 +03:00
3a1c509b74 Fix extra newline at end of -o - output (#1237) 2021-12-23 14:16:48 +03:00
79d4babcaf Replace closestByName utility with visitSkip (#1613)
The last usage of closestByName utility based on node.parentNode
is removed here. One step closer to clean ast in v3.
2021-12-07 11:05:15 +03:00
656bb09ccd Shorter commands section (#1620)
In code short comments allows more concise tutorials.
2021-12-07 10:36:07 +03:00
b37d90e12a 2.8.0 v2.8.0 2021-11-02 10:54:54 +03:00
cb7e9be623 Add warning about enabling plugins in presets 2021-11-02 10:33:46 +03:00
5165ccb9d1 Make docs more descriptive 2021-11-02 10:29:48 +03:00
72b972261d Refactor inlineStyles (#1601)
This is a big one

- got rid from another closestByName usage
- delegated removing empty defs elements to removeEmptyContainers plugin
- got rid from all css-tools usages (most inlineStyles code was there
  for some reason)
- combined a few loops
- fixed useMqs option (I would remove it in v3 for simplicity as it
  seems nobody use it)
2021-10-30 01:31:52 +03:00
c7995035ef Load .cjs with require only (#1605)
Ref https://github.com/svg/svgo/issues/1596

At the moment dynamic import may randomly fail with segfault.
To workaround this for some users .cjs extension is loaded
exclusively with require.
2021-10-30 01:31:36 +03:00
4b4391fbe3 Refactor basic cli tests (#1595)
Moved some tests to cli.test.js and got rid from mock-stdin dependency.
2021-10-15 12:34:24 +03:00
2d6deeaf21 Remove xmlns:xlink in removeXMLNS plugin (#1508)
xmlns:xlink is also not required in SVGs embedded in HTML
2021-10-15 12:16:08 +03:00
d29cec48e3 Migrate to picocolors (#1606)
Ref https://github.com/ai/nanocolors#nano-colors

Nanocolors is deprecated in favour of picocolors to avoid drama.
All dependencies already migrated. Also fixed one vulnerability.

The main change is step away from named exports and dual modules
support in favour of smaller package.
2021-10-15 12:09:54 +03:00
4166c32eb8 Migrate to simple yarn cache (#1608)
Good advice https://twitter.com/sitnikcode/status/1448634966326325255
2021-10-15 12:01:04 +03:00
4377ea38c4 Refactor removeEmptyAttrs (#1594)
- migrated to visitor plugin api
- covered with tsdoc
2021-10-07 14:07:06 +03:00
65b6bf4c16 Refactor svg stringifier (#1593)
- rewrote prototype class with functions
- covered with tsdoc
- added a few TODOs for v3
2021-10-07 14:06:55 +03:00
5fb42ab47a Migrate to yarn 2 (#1602)
Yarn supports windows with custom shell, has better tools for
dependencies upgrade and more readable lockfile.

Migrated with preserving lockfile data.
2021-10-05 16:06:12 +03:00
7601b17ab5 Rename js2svg to stringifier 2021-10-01 14:44:17 +03:00
6235264cf3 Fix prefixIds plugin to properly handle url()s in style="..." (#1592)
`prefixIds` plugin currently breaks url()-links inside `style` attributes:

```javascript
optimize(
  `<g style="fill:url(#brush-id);stroke:url(#pen-id)"/>`,
  { plugins: ['prefixIds'] }
).data
```
will generate `<g style=""/>`. Seems like `prefixIds` assumes that attribute's whole value might be `url()`, but this is not the case for the `style` attribute.

This fix solves the issue by preserving all attribute's content other than #id inside url(). It also adds some more tests for the `prefixIds` plugin.
2021-09-30 14:40:40 +03:00
203db9aaec Replace strip-ansi with --no-color flag (#1588)
nanocolors checks for --color and --no-color flags to force or disable
output coloring. Which can be used instead of strip-ansi package which
btw introduced vulnerability recently.
2021-09-30 14:39:12 +03:00
acd91835f5 2.7.0 v2.7.0 2021-09-24 00:18:26 +03:00
543346ca97 Refactor moveElemsAttrsToGroup (#1574)
- migrated to visitor plugin api
- covered with tsdoc
- added more test cases
- restructured and simplified code
2021-09-23 21:52:46 +03:00
9ebff13725 Refactor mergeStyles (#1575)
- covered with tsdoc
- replace another closestByName usage with visitSkip symbol to skip
  subtree instead of skipping element by ancestor

Better review with hidden whitespaces as most code just got bigger indent.
2021-09-23 21:48:54 +03:00
8af10de8d4 fix(plugin): removeAttrs: warn without attrs (#1582) 2021-09-23 21:48:14 +03:00
6e23b9cf56 Cover svg parser with tsdoc (#1584)
Moved to lib/parser.js. The code will be slightly simpler
when JSAPI will be removed in v3.
2021-09-23 21:45:22 +03:00
7111c52f96 Support es modules (#1583)
Ref https://github.com/svg/svgo/issues/1579

In config of course. Projects with type:module can now use modules to
export config

```js
export default {
  plugins: []
}
```

Also added support for resolving svgo.config.mjs and svgo.config.cjs.

Moved loadConfig tests to svgo-node tests.

mjs test is skipped for now in node 10, just don't use modules there
2021-09-23 21:44:55 +03:00
4c6a091a90 Replace colorette with nanocolors (#1586)
Ref https://github.com/ai/nanocolors

Nanocolors is the new player in color libraries. And it's perfectly
packaged as all @ai packages. Colorette is already replaced even
in transitive dependencies.
2021-09-23 21:44:40 +03:00
08373acf22 Create SECURITY.md (#1580)
To verify that the repository authorises trysound@yandex.ru as its security contact.
2021-09-21 19:37:04 +03:00
79ceb09daf Avoid node.parentNode in style manager (#1576)
node.parentNode will be removed in v3 along with JSAPI class wrapper on
each node.

Style manager uses it to find inherited styles. To workaround this
I collected all parents along with all styles. This constraints style
manager to work only with initial ast which should not be a problem as
each plagin execution is isolated.
2021-09-21 19:11:53 +03:00
e3c6873243 Refactor collapseGroups (#1572)
- migrated to visitor plugin api
- covered with tsdoc

Part of the code is still complicated. Will come to it eventually.
2021-09-16 01:51:08 +03:00
4e7b903a23 2.6.1 v2.6.1 2021-09-15 23:07:41 +03:00
1b56e70cc0 Fix config type (#1573) 2021-09-15 22:55:19 +03:00
a0bf4f7ebf Add missing filter primitives to collections (#1571)
Ref https://github.com/svg/svgo/issues/1045#issuecomment-510208768

This should prevent feDropShadow from removing.
2021-09-14 18:03:50 +03:00
edbd433753 Refactor removeEmptyContainers (#1570)
- migrated to visitor plugin api
- covered with tsdoc
2021-09-14 18:03:29 +03:00
65b2a30954 Upgrade to npm 7 2021-09-13 20:50:58 +03:00
42f3f8c230 Update dependencies (#1569)
* colorette    ^1.3.0  →   ^1.4.0
* jest        ^27.1.1  →  ^27.2.0
* node-fetch   ^2.6.1  →   ^2.6.2
* prettier     ^2.3.2  →   ^2.4.0
* typescript   ^4.4.2  →   ^4.4.3
2021-09-13 17:40:33 +03:00
f602e10eb1 Pick from https://github.com/svg/svgo/pull/1567 2021-09-13 16:59:05 +03:00
721a1e591d 2.6.0 v2.6.0 2021-09-13 16:56:14 +03:00
1c551a87c0 Refactor sortAttrs plugin (#1564)
- covered with tsdoc
- migrated to visitor plugin api
- slightly simplified (hope so) logic by avoiding loop over order array
  in every compare function call
- rewrote tests
2021-09-13 16:16:56 +03:00
3d22a5b23d Refactor prefixIds (#1561)
Ref https://github.com/svg/svgo/issues/1499

- migrated to visitor plugin api
- covered with tsdoc
- made the plugin idempotent as requested a few times
  Now even manually running svgo a few times will not duplicate
  prefix in ids and classes
- run each plugin test twice to see which plugin need to run many times
  ideally idempotent plugins will allow to get rid of multipass option in v3
2021-09-13 16:16:38 +03:00
23c7f48130 Move platform specific eol to svgo-node entry point (#1565)
`os` package in js2svg module bothered me for a long time.
We had to hack rollup to mock it for browser.

Thanks to https://github.com/svg/svgo/pull/1546 we now can pass eol from
svgo-node entry point and simplify build.
2021-09-12 16:40:21 +03:00
1f5ea7e610 Remove node 16 version fix (#1566)
Looks like the bug with v8 internals was fixed.
2021-09-12 14:16:28 +03:00