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

49 Commits

Author SHA1 Message Date
Seth Falco
747cc722d9 chore: revamp how we export types (#2118) 2025-05-04 17:39:44 +01:00
Seth Falco
df87725b19 chore: improve jsdoc types and match most files (#2108) 2025-04-29 10:35:11 +01:00
Seth Falco
71a1254895 fix: improve jsdoc types and remove excludes (#2107) 2025-04-28 22:24:16 +01:00
XhmikosR
964c7b28ff chore!: drop Node.js < 16 support (#2002) 2024-06-07 18:21:00 +01:00
Jon Dufresne
2442f74239 chore: convert project to us ECMAScript modules (preserving CJS compatibility) (#1905) 2024-01-03 16:17:37 +00:00
Bogdan Chadkin
f5d1dd06cc Loosly cover with types convertPathData 2022-10-16 14:53:04 +03:00
Bogdan Chadkin
075ab164f6 Store builtin plugins as an array 2022-10-02 22:58:02 +03:00
Bogdan Chadkin
783583538f Drop legacy JSAPI style handler 2022-10-02 00:24:43 +03:00
Bogdan Chadkin
da1d761b53 Refactor removeDimensions and removeXMLNS (#1640)
Migrated both to visitor api and tsdoc
2022-01-22 00:12:52 +03:00
Bogdan Chadkin
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
Bogdan Chadkin
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
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
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
Bogdan Chadkin
4377ea38c4 Refactor removeEmptyAttrs (#1594)
- migrated to visitor plugin api
- covered with tsdoc
2021-10-07 14:07:06 +03:00
Bogdan Chadkin
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
Bogdan Chadkin
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
Bogdan Chadkin
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
Bogdan Chadkin
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
Bogdan Chadkin
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
Bogdan Chadkin
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
Bogdan Chadkin
edbd433753 Refactor removeEmptyContainers (#1570)
- migrated to visitor plugin api
- covered with tsdoc
2021-09-14 18:03:29 +03:00
Bogdan Chadkin
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
Bogdan Chadkin
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
Bogdan Chadkin
77102ed096 Add better parser errors (#1553)
Old SVGO errors were not very helpful. Packages like cssnano
(postcss-svgo) had to deal with a lot of issues which are hard to debug
with old errors.

```
Error: Error in parsing SVG: Unquoted attribute value
Line: 1
Column: 29
Char: 6
File: input.svg
```

New errors are more informative and may solve many struggles

```
Error: SvgoParserError: input.svg:2:29: Unquoted attribute value

  1 | <svg viewBox="0 0 120 120">
> 2 |   <circle fill="#ff0000" cx=60.444444" cy="60" r="50"/>
    |                             ^
  3 | </svg>
  4 |
```
2021-09-12 01:09:10 +03:00
Bogdan Chadkin
6eb4524aef Refactor removeUnusedNS plugin (#1559)
- covered with types
- migrated to visitor plugin api
- dropped traverse utility which is replaced by visitor
2021-09-10 20:30:34 +03:00
Bogdan Chadkin
f587aae1c2 Refactor removeEditorsNSData (#1557)
- covered with types
- migrated to visitor plugin api
- got rid from parseName utility in favour of simple string operations
2021-09-10 19:34:27 +03:00
Bogdan Chadkin
298820b8d9 Refactor cleanupIDs (#1556)
I still did get how id generation works but data flow is clear now at
least.

- covered with types
- migrated to visitor plugin api
- got rid of traverse api
2021-09-05 17:35:37 +03:00
Bogdan Chadkin
107922405a Refactor minifyStyles plugin (#1552)
- migrated to visitor plugin api
- covered with types
- get rid from "traverse" usage

Splitted the work to collecting and modifying when root exit.
2021-09-05 17:35:11 +03:00
Bogdan Chadkin
93143f32c1 Refactor removeUselessStrokeAndFill (#1549)
The logic is a little messy. Will be better when we drop node 12 support
and use optional chaining.

- migrated to visitor plugin api
- covered with types
- get rid from patching params as plugin state
- replaced many node.computedAttr() with style manager
- enabled and fixed removeNone param test (was merged as muted back in 2017)
- added ability to return null and not run visitor in plugins
2021-09-05 17:34:13 +03:00
Bogdan Chadkin
1e5236d813 Refactor reusePaths plugin (#1551)
- migrated to visitor plugin api; combination of enter and exit helped
  to fit into single traverse
- got rid from the only node.clone() usage in the project so no need to
  reimplement it
- the logic is a bit simplified
2021-09-01 15:47:04 +03:00
Bogdan Chadkin
bc95263885 Refactor removeUnknownsAndDefaults (#1548)
- got rid from two computeAttr usages
- got rid from node.parentNode usages
- avoided mutating global _collections objects
- refactored with visitor api
- covered with types
- skip whole foreignObject subtree not only its children
2021-08-27 23:02:28 +03:00
Bogdan Chadkin
5ad2d4a5f6 Refactor removeOffCanvasPaths plugin (#1545)
- refactored with visitor plugin api
- covered with types
- replaced parentNode traverse with visitSkip symbol
- replaced regex path parser with parsePathData
- get rid from global state which lead test case to invalid state
2021-08-27 17:15:18 +03:00
Bogdan Chadkin
6002f0bf65 Check types in path tests 2021-08-27 17:05:39 +03:00
Bogdan Chadkin
3ca57d1856 Add visitSkip symbol (#1547)
This should help to avoid node.parentNode and closestByName
in some cases by skiping visiting children of current node.

Works only in `enter` listener.
2021-08-27 17:01:29 +03:00
Bogdan Chadkin
1b02799e18 Cover convertTransform plugin with types (#1542)
In this diff covered convertTransform pluginn with types
and got rid from global state which made data flow more complex and
error prone.
2021-08-25 20:52:31 +03:00
Bogdan Chadkin
cce036f285 Refactor convertColors (#1543)
- refactored with visitor plugin api
- covered with types
2021-08-25 20:52:21 +03:00
Bogdan Chadkin
a228020329 Refactor defs plugins (#1544)
Refactored and covered with types following plugins

- removeUselessDefs
- sortDefsChildren
2021-08-25 20:52:07 +03:00
Bogdan Chadkin
0ead871eed Cover with types numeric values plugins (#1541)
- cleanupNumericValues
- cleanupListOfValues
2021-08-24 14:57:09 +03:00
Bogdan Chadkin
4082eca762 Refactor cleanupEnableBackground with visitor plugin api (#1540)
Slightly restructured plugin to do less work in case no filters used.
2021-08-24 14:20:23 +03:00
Bogdan Chadkin
a2331a5dee removeViewBox and convertShapeToPath types and visitor (#1537)
- added types to convertShapeToPath
- refactored removeViewBox with visitor plugin api and got rid from one
  closestByName usage
2021-08-24 13:41:26 +03:00
Bogdan Chadkin
74c383153e Cover mergePaths plugin with types (#1539)
- covered mergePaths plugin
- covered big path logic
2021-08-24 13:41:16 +03:00
Bogdan Chadkin
e4918ccdd1 Covert removeHiddenElems with types (#1532)
Covered removeHiddenElems plugin and big part of our code
- path parser and stringifier
- style manager
2021-08-21 14:55:05 +03:00
Bogdan Chadkin
9b8f13e911 Add plugin types (#1527)
Covered following plugins
- addAttributesToSVGElement.js 
- addClassesToSVGElement.js 
- cleanupAttrs.js 
- convertEllipseToCircle.js 
- removeAttributesBySelector.js 
- removeAttrs.js 
- removeComments.js 
- removeDesc.js 
- removeDoctype.js 
- removeElementsByAttr.js 
- removeEmptyText.js 
- removeMetadata.js 
- removeRasterImages.js 
- removeScriptElement.js 
- removeStyleElement.js 
- removeTitle.js 
- removeXMLProcInst.js
2021-08-15 13:52:41 +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
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
Bogdan Chadkin
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
Bogdan Chadkin
c925e4da0a Fix ts 2021-03-15 21:34:36 +03:00
Sebastian Kreft
76c7719604 chore: Improve TS config (#1405)
Changed the TS config file to include all relevant folders and explicitly exclude those files that fail the type checks. In this way new files will be automatically type checked and we can see the list of files that need types improvements.

In this pass I also fixed some js files.
2021-03-05 01:17:44 +03:00
Sebastian Kreft
6842b47cc7 Add TS support (#1370)
Added Typescript support via JSDoc comments for some files.

The code has really outdated type signatures, so in order to fully type the codebase the changes need to be incremental.

To check the types run:
npx tsc
2021-03-04 16:30:28 +03:00