summaryrefslogtreecommitdiffstats
path: root/src/flatten.js
blob: 3ba6e22a516d15e76c5b727526f6bfc261fc8bb3 (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.isRoot() ? 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
  }
})