diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-12-03 22:59:58 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-12-03 22:59:58 +0100 |
commit | f089db0c1990d75bbd34713f97f547045ae92fca (patch) | |
tree | a0aa8346394aae92fff16ff4f1f452b30909cb5a /src/animation | |
parent | c336bd4a1c8e129efffed63424b724a148f053b3 (diff) | |
download | svg.js-f089db0c1990d75bbd34713f97f547045ae92fca.tar.gz svg.js-f089db0c1990d75bbd34713f97f547045ae92fca.zip |
Release 3.0.23.0.2
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/Morphable.js | 7 | ||||
-rw-r--r-- | src/animation/Runner.js | 43 | ||||
-rw-r--r-- | src/animation/Timeline.js | 5 |
3 files changed, 44 insertions, 11 deletions
diff --git a/src/animation/Morphable.js b/src/animation/Morphable.js index 56ffe95..0f191c9 100644 --- a/src/animation/Morphable.js +++ b/src/animation/Morphable.js @@ -90,7 +90,12 @@ export default class Morphable { this._morphObj = this._morphObj || new this._type() this._context = this._context - || Array.apply(null, Array(result.length)).map(Object) + || Array.apply(null, Array(result.length)) + .map(Object) + .map(function (o) { + o.done = true + return o + }) return result } diff --git a/src/animation/Runner.js b/src/animation/Runner.js index 3af5823..d211876 100644 --- a/src/animation/Runner.js +++ b/src/animation/Runner.js @@ -1,5 +1,5 @@ import { Controller, Ease, Stepper } from './Controller.js' -import { extend } from '../utils/adopter.js' +import { extend, register } from '../utils/adopter.js' import { from, to } from '../modules/core/gradiented.js' import { getOrigin } from '../utils/utils.js' import { noop, timeline } from '../modules/core/defaults.js' @@ -64,6 +64,9 @@ export default class Runner extends EventTarget { this._swing = false this._wait = 0 this._times = 1 + + // Stores how long a runner is stored after beeing done + this._persist = this._isDeclarative ? true : null } /* @@ -199,6 +202,12 @@ export default class Runner extends EventTarget { return this.time(time) } + persist (dtOrForever) { + if (dtOrForever == null) return this._persist + this._persist = dtOrForever + return this + } + position (p) { // Get all of the variables we need var x = this._time @@ -338,11 +347,22 @@ export default class Runner extends EventTarget { morpher: morpher, caller: this._queue[this._queue.length - 1] } + + // We have to resume the timeline in case a controller + // is already done without beeing ever run + // This can happen when e.g. this is done: + // anim = el.animate(new SVG.Spring) + // and later + // anim.move(...) + if (this._isDeclarative) { + var timeline = this.timeline() + timeline && timeline.play() + } } // Try to set the target for a morpher if the morpher exists, otherwise // do nothing and return false - _tryRetarget (method, target) { + _tryRetarget (method, target, extra) { if (this._history[method]) { // if the last method wasnt even initialised, throw it away if (!this._history[method].caller.initialised) { @@ -354,7 +374,7 @@ export default class Runner extends EventTarget { // for the case of transformations, we use the special retarget function // which has access to the outer scope if (this._history[method].caller.retarget) { - this._history[method].caller.retarget(target) + this._history[method].caller.retarget(target, extra) // for everything else a simple morpher change is sufficient } else { this._history[method].morpher.to(target) @@ -362,7 +382,7 @@ export default class Runner extends EventTarget { this._history[method].caller.finished = false var timeline = this.timeline() - timeline && timeline._continue() + timeline && timeline.play() return true } return false @@ -604,7 +624,7 @@ registerMethods({ .reduce(lmultiply, new Matrix()) }, - addRunner (runner) { + _addRunner (runner) { this._transformationRunners.add(runner) Animator.transform_frame( @@ -636,9 +656,10 @@ extend(Runner, { styleAttr (type, name, val) { // apply attributes individually if (typeof name === 'object') { - for (var key in val) { - this.styleAttr(type, key, val[key]) + for (var key in name) { + this.styleAttr(type, key, name[key]) } + return this } var morpher = new Morphable(this._stepper).to(val) @@ -654,6 +675,8 @@ extend(Runner, { }, zoom (level, point) { + if (this._tryRetarget('zoom', to, point)) return this + var morpher = new Morphable(this._stepper).to(new SVGNumber(level)) this.queue(function () { @@ -661,6 +684,9 @@ extend(Runner, { }, function (pos) { this.element().zoom(morpher.at(pos), point) return morpher.done() + }, function (newLevel, newPoint) { + point = newPoint + morpher.to(newLevel) }) return this @@ -714,7 +740,7 @@ extend(Runner, { startTransform = new Matrix(relative ? undefined : element) // add the runner to the element so it can merge transformations - element.addRunner(this) + element._addRunner(this) // Deactivate all transforms that have run so far if we are absolute if (!relative) { @@ -953,3 +979,4 @@ extend(Runner, { }) extend(Runner, { rx, ry, from, to }) +register(Runner) diff --git a/src/animation/Timeline.js b/src/animation/Timeline.js index c3ad07c..44b5261 100644 --- a/src/animation/Timeline.js +++ b/src/animation/Timeline.js @@ -80,11 +80,12 @@ export default class Timeline extends EventTarget { // Manage runner runner.unschedule() runner.timeline(this) - // runner.time(-delay) + + const persist = runner.persist() // Save runnerInfo this._runners[runner.id] = { - persist: this.persist(), + persist: persist === null ? this._persist : persist, runner: runner, start: absoluteStartTime + delay } |