Skip to content

Conversation

@mikefromgrr
Copy link

@mikefromgrr mikefromgrr commented Jul 30, 2025

Adds support for importing SVGs with cloned elements and properly manifesting them as objects (vs. dropping them).

  • Scans the SVG for any <use> element (a clone) and replaces it with its original source element. Adds the cloned element's "transform" attribute so that its replacement inherits all its position and scaling.
  • Adds application Setting to toggle Clone Replacement, defaulting to OFF.
  • Considers nested clone within clone within clone (20 deep) etc...
  • Gracefully avoids stack overflow if clone hierarchy is self referencing (likely due to human manipulations).
  • Gracefully ignores bogus intra-document linking or external links.
  • Meager support for SVG1.1 and SVG2 in how the element references via xlink:href or href.

Note:
The <use> element in SVG is a mechanism for reusing existing graphics without duplicating code. It works by referencing another SVG element—like a <circle>, <g>, <path> etc via its ID and xlink:href or href attribute and rendering a copy at a new location. See Mozilla Documentation on element

Sample SVG with Clones

clone

FeatureComparison

Settings Screen Update

image

- Scans the SVG for any <use> element (a clone) and replaces it with its original source element. Adds
the cloned element's "transform" attribute so that its replacement inherits all its position and scaling.
- Adds application Setting to toggle Clone Replacment, defaulting to OFF.

Note:
The <use> element in SVG is a powerful mechanism for reusing existing graphics without duplicating code.
It works by referencing another SVG element—like a <cirle>, <g>, <path> etc via its ID and
rendering a copy at a new location.
In the presumably ultra rare occasion, raise a log message when an infinite element loop (or clone nesting deeper than 20) is detected in the SVG. Then, mark the element as a dead end so it is not attempted to be traversed again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant