-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Summary
The convertTransform plugin currently applies transform="translate(...)" only to certain elements like <path>, but does not apply it to other valid SVG elements such as:
<text><circle><rect><tspan><g>(nested)
This results in inconsistent transform flattening and prevents full removal of transform from <g> containers in many real-world designs, particularly when working with Sketch or Illustrator-generated SVGs.
Example (Before)
<g transform="translate(200 188)">
<rect width="100" height="80"/>
<text><tspan x="30" y="40">Hello</tspan></text>
</g>Expected (After)
<rect x="200" y="188" width="100" height="80"/>
<text transform="translate(200 188)"><tspan x="30" y="40">Hello</tspan></text>Problem
In current output, convertTransform partially transforms the <rect> into absolute x, y, but leaves the <text> as-is or wrapped in residual transform. This breaks downstream animation or layout systems that expect flat coordinate-based SVGs without transform wrappers.
Suggestion
-
Extend
convertTransformto support applying translations to:x/yattributes (e.g.rect,circle,text)cx/cy(e.g.circle)- Wrap
textwith its owntransformif inline transform is not possible - Possibly recursively flatten nested
<g>elements
This would significantly improve usability of SVGO for SVG animation and simplify DOM manipulation for frontend developers.
Version
SVGO v4.0.0
My Config
export default {
multipass: true,
js2svg: { indent: 2, pretty: true },
plugins: [
{
name: 'removeViewBox',
active: false
},
{
name: 'removeXMLNS',
active: false
},
{
name: 'preset-default',
},
'collapseGroups',
'convertShapeToPath',
'convertPathData',
'mergePaths',
'convertTransform',
]
}relative:
https://github.com/stadline/svg-flatten
https://kurachiweb.github.io/svg-rect-to-path/
https://lean-svg.netlify.app/