svg / svgo

⚙️ Node.js tool for optimizing SVG files
https://svgo.dev/
MIT License
20.77k stars 1.38k forks source link

Multiple issues with styles / css #2047

Open konstantinschuette opened 1 month ago

konstantinschuette commented 1 month ago

Describe the bug I have two issues:

  1. You can't override minifyStyles to be false
  2. minifyStyles just removes the styles in a specific case

To Reproduce I'm using this config. Even if i set minifyStyles: false it still applies changes to <style> tags

module.exports = {
  floatPrecision: "0",
  gzip: false,
  plugins: [
    {
      name: "preset-default",
      params: {
        overrides: {
          cleanupIds: false,
          removeViewBox: false,

          // aka. Collapse useless groups
          collapseGroups: false,

          // aka. Shapes to (smaller) paths
          convertShapeToPath: false,

          // aka. Remove unneeded group attrs
          removeNonInheritableGroupAttrs: false,

          minifyStyles: false
        },
      },
    },
  ],
};

For the second issue i'm using this SVG and the config from above:

<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" viewBox="0 0 1417.3 1417.3" xmlns="http://www.w3.org/2000/svg">
 <style>
    #svg-3007386279 {
      .cls-1 {
        fill: #8d3013;
        stroke: #8d3013;
      }
    }
 </style>
</svg>

Which results into:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1417 1417"/>

When I remove the wrapping element #svg-3007386279, it still keeps the styles.

Expected behavior With the config I provided, I would expect no css changes to be made. Also I expect wrapping elements to not cause any issues, like getting rid of all styles.

Desktop (please complete the following information):

KTibow commented 1 month ago

the second one doesn't appear to have valid css? edit: actually nesting became a thing within the past year. regardless, it doesn't change anything meaningful within the svg.

konstantinschuette commented 4 weeks ago

the second one doesn't appear to have valid css? edit: actually nesting became a thing within the past year. regardless, it doesn't change anything meaningful within the svg.

What do you mean with doesn't change anything meaningful within the svg.?

KTibow commented 4 weeks ago

there is no svg-3007386279 or cls-1 that it is styling