Skip to content

Commit

Permalink
Don't inline symbols that are <use>d with a width/height.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 committed Oct 18, 2024
1 parent e0ff0e4 commit 4cd447e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugins/inlineUse.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ export const fn = (root, params, info) => {
* @returns {boolean}
*/
function inlineUse(use, def) {
// Don't inline if <use> has children, or has a width or height attribute.
// Don't inline if <use> has children.
if (use.children.length > 0) {
return false;
}

// Don't inline symbols that are <use>d with a width/height.
if (
use.children.length > 0 ||
use.attributes.width ||
use.attributes.height
(use.attributes.width || use.attributes.height) &&
def.name === 'symbol'
) {
return false;
}
Expand Down
17 changes: 17 additions & 0 deletions test/plugins/inlineUse.08.svg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Ignore width and height when inlining a path.

===

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">
<defs>
<path id="a" d="M1 1L3 3" transform="scale(2)" style="stroke:black"/>
</defs>
<use x="2" y="2" href="#a" width="3" height="4"/>
</svg>

@@@

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10">
<defs/>
<path d="M1 1L3 3" transform="translate(2,2)scale(2)" style="stroke:black"/>
</svg>

0 comments on commit 4cd447e

Please sign in to comment.