summaryrefslogtreecommitdiffstats
path: root/src/Pattern.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-10-25 23:28:12 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-10-25 23:28:12 +0200
commitcfdfcc529dedff770dc54e78d2900d9a790f5766 (patch)
tree7b59c282a7823ded1d182aca95da5d55815456b2 /src/Pattern.js
parent464af8b747389b7fdb569a933591c863b9be0f6b (diff)
downloadsvg.js-cfdfcc529dedff770dc54e78d2900d9a790f5766.tar.gz
svg.js-cfdfcc529dedff770dc54e78d2900d9a790f5766.zip
convert everything to es6 classes and imports
Diffstat (limited to 'src/Pattern.js')
-rw-r--r--src/Pattern.js79
1 files changed, 38 insertions, 41 deletions
diff --git a/src/Pattern.js b/src/Pattern.js
index d4c4116..00f9de5 100644
--- a/src/Pattern.js
+++ b/src/Pattern.js
@@ -1,53 +1,51 @@
-SVG.Pattern = SVG.invent({
- // Initialize node
- create: 'pattern',
-
- // Inherit from
- inherit: SVG.Container,
-
- // Add class methods
- extend: {
- // Return the fill id
- url: function () {
- return 'url(#' + this.id() + ')'
- },
- // Update pattern by rebuilding
- update: function (block) {
- // remove content
- this.clear()
+import {Container, Defs} from './classes.js'
+import {nodeOrNew} from './tools.js'
- // invoke passed block
- if (typeof block === 'function') {
- block.call(this, this)
- }
+export default class Pattern extends Container {
+ // Initialize node
+ constructor (node) {
+ super(nodeOrNew('pattern', node))
+ }
- return this
- },
- // Alias string convertion to fill
- toString: function () {
- return this.url()
- },
- // custom attr to handle transform
- attr: function (a, b, c) {
- if (a === 'transform') a = 'patternTransform'
- return SVG.Container.prototype.attr.call(this, a, b, c)
+ // Return the fill id
+ url () {
+ return 'url(#' + this.id() + ')'
+ }
+ // Update pattern by rebuilding
+ update (block) {
+ // remove content
+ this.clear()
+
+ // invoke passed block
+ if (typeof block === 'function') {
+ block.call(this, this)
}
- },
+ return this
+ }
+ // Alias string convertion to fill
+ toString () {
+ return this.url()
+ }
+ // custom attr to handle transform
+ attr (a, b, c) {
+ if (a === 'transform') a = 'patternTransform'
+ return super.attr(a, b, c)
+ }
+}
// Add parent method
- construct: {
- // Create pattern element in defs
- pattern: function (width, height, block) {
- return this.defs().pattern(width, height, block)
- }
+addFactory(Container, {
+ // Create pattern element in defs
+ pattern (width, height, block) {
+ return this.defs().pattern(width, height, block)
}
})
-SVG.extend(SVG.Defs, {
+extend(Defs, {
// Define gradient
- pattern: function (width, height, block) {
- return this.put(new SVG.Pattern()).update(block).attr({
+ pattern (width, height, block) {
+ return this.put(new Pattern()).update(block).attr({
x: 0,
y: 0,
width: width,
@@ -55,5 +53,4 @@ SVG.extend(SVG.Defs, {
patternUnits: 'userSpaceOnUse'
})
}
-
})