Skip to content

Add option to limit IRI renumeration to <defs> children only #1555

@tanem

Description

@tanem

Currently, when renumerateIRIElements: true (the default), all IRI-addressable elements are renumerated regardless of their position in the SVG tree. This can be problematic for interactive SVGs where elements outside (e.g. in a US map) need to retain their original IDs for event handling or DOM queries.

Proposed solution

Add a new option (e.g. renumerateScope: 'all' | 'defs') that restricts renumeration to elements inside when set to 'defs'.

Considerations

Elements like <clipPath>, <mask>, <filter> are often defined outside <defs> in real-world SVGs (valid per spec). A defs-only scope would skip those, which could break cross-references in some SVGs. The reference-updating logic would remain unchanged - only the initial element collection phase would be scoped.

Workaround

Set renumerateIRIElements: false to preserve all original IDs (disables renumeration entirely).

Related: #14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions