From 33e82b796e7870a9523b6e9653877a2613f8f7a2 Mon Sep 17 00:00:00 2001
From: Ulrich-Matthias Schäfer <ulima.ums@googlemail.com>
Date: Wed, 12 Dec 2018 23:21:10 +0100
Subject: Release 3.0.5

---
 src/animation/Animator.js     |  2 +-
 src/animation/Runner.js       |  4 +++
 src/animation/Timeline.js     |  9 +++---
 src/elements/Element.js       | 10 +++++++
 src/elements/G.js             | 66 +++++++++++++++++++++++++++++++++----------
 src/modules/core/parser.js    |  4 ++-
 src/modules/optional/sugar.js | 14 +--------
 src/utils/utils.js            |  4 +--
 8 files changed, 77 insertions(+), 36 deletions(-)

(limited to 'src')

diff --git a/src/animation/Animator.js b/src/animation/Animator.js
index 390b200..21c735c 100644
--- a/src/animation/Animator.js
+++ b/src/animation/Animator.js
@@ -83,7 +83,7 @@ const Animator = {
     var nextFrame = null
     var lastFrame = Animator.frames.last()
     while ((nextFrame !== lastFrame) && (nextFrame = Animator.frames.shift())) {
-      nextFrame.run()
+      nextFrame.run(now)
     }
 
     var nextImmediate = null
diff --git a/src/animation/Runner.js b/src/animation/Runner.js
index 8c26578..eebfb75 100644
--- a/src/animation/Runner.js
+++ b/src/animation/Runner.js
@@ -136,6 +136,10 @@ export default class Runner extends EventTarget {
     this._times = times || Infinity
     this._swing = swing || false
     this._wait = wait || 0
+
+    // Allow true to be passed
+    if (this._times === true) { this._times = Infinity }
+
     return this
   }
 
diff --git a/src/animation/Timeline.js b/src/animation/Timeline.js
index f5460b3..66ba61f 100644
--- a/src/animation/Timeline.js
+++ b/src/animation/Timeline.js
@@ -40,7 +40,8 @@ export default class Timeline extends EventTarget {
     this._lastStepTime = 0
 
     // Make sure that step is always called in class context
-    this._step = this._step.bind(this)
+    this._step = this._stepFn.bind(this, false)
+    this._stepImmediate = this._stepFn.bind(this, true)
   }
 
   // schedules a runner on the timeline
@@ -184,7 +185,7 @@ export default class Timeline extends EventTarget {
     return this
   }
 
-  _step (immediateStep = false) {
+  _stepFn (immediateStep = false) {
     // Get the time delta from the last time and update the time
     var time = this._timeSource()
     var dtSource = time - this._lastSourceTime
@@ -278,8 +279,8 @@ export default class Timeline extends EventTarget {
     if ((runnersLeft && !(this._speed < 0 && this._time === 0)) || (this._runnerIds.length && this._speed < 0 && this._time > 0)) {
       this._continue()
     } else {
-      this.fire('finished')
       this.pause()
+      this.fire('finished')
     }
 
     return this
@@ -290,7 +291,7 @@ export default class Timeline extends EventTarget {
     Animator.cancelFrame(this._nextFrame)
     this._nextFrame = null
 
-    if (immediateStep) return this._step(true)
+    if (immediateStep) return this._stepImmediate()
     if (this._paused) return this
 
     this._nextFrame = Animator.frame(this._step)
diff --git a/src/elements/Element.js b/src/elements/Element.js
index 594daa1..ba15f52 100644
--- a/src/elements/Element.js
+++ b/src/elements/Element.js
@@ -55,6 +55,16 @@ export default class Element extends Dom {
     return this.root().defs()
   }
 
+  // Relative move over x axis
+  dx (x) {
+    return this.x(new SVGNumber(x).plus(this.x()))
+  }
+
+  // Relative move over y axis
+  dy (y) {
+    return this.y(new SVGNumber(y).plus(this.y()))
+  }
+
   // Get parent document
   root () {
     let p = this.parent(Svg)
diff --git a/src/elements/G.js b/src/elements/G.js
index 0a11c1e..8171fed 100644
--- a/src/elements/G.js
+++ b/src/elements/G.js
@@ -1,44 +1,80 @@
 import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
+import { proportionalSize } from '../utils/utils.js'
 import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
+import SVGNumber from '../types/SVGNumber.js'
 
 export default class G extends Container {
   constructor (node) {
     super(nodeOrNew('g', node), node)
   }
 
-  x (x) {
-    if (x == null) return this.transform()['x']
-    return this.move(x, 0)
+  x (x, box = this.bbox()) {
+    if (x == null) return box.x
+
+    this.children().dx(x - box.x)
+    return this
   }
 
-  y (y) {
-    if (y == null) return this.transform()['y']
-    return this.move(0, y)
+  y (y, box = this.bbox()) {
+    if (y == null) return box.y
+
+    this.children().dy(y - box.y)
+    return this
   }
 
   move (x, y) {
-    return this.translate(x, y)
+    const box = this.bbox()
+    return this.x(x, box).y(y, box)
   }
 
   dx (dx) {
-    return this.transform({ dx }, true)
+    return this.children().dx(dx)
   }
 
   dy (dy) {
-    return this.transform({ dy }, true)
+    return this.children().dy(dy)
   }
 
-  dmove (dx, dy) {
-    return this.transform({ dx, dy }, true)
+  width (width, box = this.bbox()) {
+    if (width == null) return box.width
+
+    const scale = width / box.width
+
+    this.each(function () {
+      const _width = this.width()
+      const _x = this.x()
+
+      this.width(_width * scale)
+      this.x((_x - box.x) * scale + box.x)
+    })
+
+    return this
   }
 
-  width () {
-    return this.bbox().width
+  height (height, box = this.bbox()) {
+    if (height == null) return box.height
+
+    const scale = height / box.height
+
+    this.each(function () {
+      const _height = this.height()
+      const _y = this.y()
+
+      this.height(_height * scale)
+      this.y((_y - box.y) * scale + box.y)
+    })
+
+    return this
   }
 
-  height () {
-    return this.bbox().height
+  size (width, height) {
+    const box = this.bbox()
+    const p = proportionalSize(this, width, height, box)
+
+    return this
+      .width(new SVGNumber(p.width), box)
+      .height(new SVGNumber(p.height), box)
   }
 }
 
diff --git a/src/modules/core/parser.js b/src/modules/core/parser.js
index 1ff2380..dfa7b7b 100644
--- a/src/modules/core/parser.js
+++ b/src/modules/core/parser.js
@@ -5,7 +5,7 @@ export default function parser () {
   // Reuse cached element if possible
   if (!parser.nodes) {
     let svg = makeInstance().size(2, 0)
-    svg.node.cssText = [
+    svg.node.style.cssText = [
       'opacity: 0',
       'position: absolute',
       'left: -100%',
@@ -13,6 +13,8 @@ export default function parser () {
       'overflow: hidden'
     ].join(';')
 
+    svg.attr('focusable', 'false')
+
     let path = svg.path().node
 
     parser.nodes = { svg, path }
diff --git a/src/modules/optional/sugar.js b/src/modules/optional/sugar.js
index d4255c3..c05512d 100644
--- a/src/modules/optional/sugar.js
+++ b/src/modules/optional/sugar.js
@@ -38,7 +38,7 @@ var sugar = {
     return this
   }
 
-  registerMethods([ 'Shape', 'Runner' ], extension)
+  registerMethods([ 'Element', 'Runner' ], extension)
 })
 
 registerMethods([ 'Element', 'Runner' ], {
@@ -110,18 +110,6 @@ registerMethods([ 'Element', 'Runner' ], {
   }
 })
 
-registerMethods('Element', {
-  // Relative move over x axis
-  dx: function (x) {
-    return this.x(new SVGNumber(x).plus(this.x()))
-  },
-
-  // Relative move over y axis
-  dy: function (y) {
-    return this.y(new SVGNumber(y).plus(this.y()))
-  }
-})
-
 registerMethods('radius', {
   // Add x and y radius
   radius: function (x, y) {
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 3bac0de..c2046a9 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -56,9 +56,9 @@ export function capitalize (s) {
 }
 
 // Calculate proportional width and height values when necessary
-export function proportionalSize (element, width, height) {
+export function proportionalSize (element, width, height, box) {
   if (width == null || height == null) {
-    var box = element.bbox()
+    box = box || element.bbox()
 
     if (width == null) {
       width = box.width / box.height * height
-- 
cgit v1.2.3