diff options
Diffstat (limited to 'src/ClipPath.js')
-rw-r--r-- | src/ClipPath.js | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/ClipPath.js b/src/ClipPath.js index ef820e5..486b30c 100644 --- a/src/ClipPath.js +++ b/src/ClipPath.js @@ -1,11 +1,11 @@ -import Container from './Container.js' -import Element from './Element.js' +import Base from './Base.js' import {nodeOrNew, extend} from './tools.js' import find from './selector.js' +import {remove} from './Element.js' -export default class ClipPath extends Container { +export default class ClipPath extends Base { constructor (node) { - super(nodeOrNew('clipPath', node)) + super(nodeOrNew('clipPath', node), ClipPath) } // Unclip all clipped elements and remove itself @@ -16,7 +16,7 @@ export default class ClipPath extends Container { }) // remove clipPath from parent - return super.remove() + return remove.call(this) } targets () { @@ -24,31 +24,33 @@ export default class ClipPath extends Container { } } -addFactory(Container, { - // Create clipping element - clip: function() { - return this.defs().put(new ClipPath) - } -}) - -extend(Element, { - // Distribute clipPath to svg element - clipWith (element) { - // use given clip or create a new one - let clipper = element instanceof ClipPath - ? element - : this.parent().clip().add(element) - - // apply mask - return this.attr('clip-path', 'url("#' + clipper.id() + '")') - }, - // Unclip element - unclip () { - return this.attr('clip-path', null) +ClipPath.constructors = { + Container: { + // Create clipping element + clip: function() { + return this.defs().put(new ClipPath) + } }, - - clipper () { - return this.reference('clip-path') + Element: { + // Distribute clipPath to svg element + clipWith (element) { + // use given clip or create a new one + let clipper = element instanceof ClipPath + ? element + : this.parent().clip().add(element) + + // apply mask + return this.attr('clip-path', 'url("#' + clipper.id() + '")') + }, + + // Unclip element + unclip () { + return this.attr('clip-path', null) + }, + + clipper () { + return this.reference('clip-path') + } } -}) +} |