summaryrefslogtreecommitdiffstats
path: root/src/flatten.js
blob: 1c32a7665d7502c9089f9f2a08a6f62d5af97e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SVG.extend(SVG.Parent, {
  flatten: function (parent) {
    if (this instanceof SVG.Defs) return this

    parent = parent || (this instanceof SVG.Doc ? this : this.parent(SVG.Parent))

    this.each(function () {
      if (this instanceof SVG.Defs) return this
      if (this instanceof SVG.Parent) return this.flatten(parent)
      return this.toParent(parent)
    })

    // we need this so that SVG.Doc does not get removed
    this.node.firstElementChild || this.remove()

    return this
  }
})