diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-12-05 19:36:28 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-12-05 19:36:28 +0100 |
commit | 5161dfdb3a08490da0ae1c5c8b6515eb0ae0da30 (patch) | |
tree | 03217ab484a962ea4b183c1d9902ffe92d08a153 /src/animation | |
parent | f089db0c1990d75bbd34713f97f547045ae92fca (diff) | |
download | svg.js-5161dfdb3a08490da0ae1c5c8b6515eb0ae0da30.tar.gz svg.js-5161dfdb3a08490da0ae1c5c8b6515eb0ae0da30.zip |
Release 3.0.33.0.3
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/Animator.js | 8 | ||||
-rw-r--r-- | src/animation/Runner.js | 34 | ||||
-rw-r--r-- | src/animation/Timeline.js | 17 |
3 files changed, 35 insertions, 24 deletions
diff --git a/src/animation/Animator.js b/src/animation/Animator.js index 2786602..64570eb 100644 --- a/src/animation/Animator.js +++ b/src/animation/Animator.js @@ -21,10 +21,6 @@ const Animator = { return node }, - transform_frame (fn, id) { - Animator.transforms[id] = fn - }, - timeout (fn, delay) { delay = delay || 0 @@ -74,10 +70,6 @@ const Animator = { nextFrame.run() } - Animator.transforms.forEach(function (el) { - el() - }) - // If we have remaining timeouts or frames, draw until we don't anymore Animator.nextDraw = Animator.timeouts.first() || Animator.frames.first() ? globals.window.requestAnimationFrame(Animator._draw) diff --git a/src/animation/Runner.js b/src/animation/Runner.js index d211876..6a085b6 100644 --- a/src/animation/Runner.js +++ b/src/animation/Runner.js @@ -65,6 +65,8 @@ export default class Runner extends EventTarget { this._wait = 0 this._times = 1 + this._frameId = null + // Stores how long a runner is stored after beeing done this._persist = this._isDeclarative ? true : null } @@ -441,7 +443,7 @@ export default class Runner extends EventTarget { // TODO: Keep track of all transformations so that deletion is faster clearTransformsFromQueue () { - if (!this.done) { + if (!this.done || !this._timeline || !this._timeline._order.includes(this)) { this._queue = this._queue.filter((item) => { return !item.isTransform }) @@ -558,7 +560,14 @@ class RunnerArray { merge () { let lastRunner = null this.runners.forEach((runner, i) => { - if (lastRunner && runner.done && lastRunner.done) { + + const condition = lastRunner + && runner.done && lastRunner.done + // don't merge runner when persisted on timeline + && (!runner._timeline || !runner._timeline._order.includes(runner.id)) + && (!lastRunner._timeline || !lastRunner._timeline._order.includes(lastRunner.id)) + + if (condition) { this.remove(runner.id) this.edit(lastRunner.id, runner.mergeWith(lastRunner)) } @@ -589,7 +598,6 @@ class RunnerArray { } } -let frameId = 0 registerMethods({ Element: { animate (duration, delay, when) { @@ -627,17 +635,18 @@ registerMethods({ _addRunner (runner) { this._transformationRunners.add(runner) - Animator.transform_frame( - mergeTransforms.bind(this), this._frameId - ) + // Make sure that the runner merge is executed at the very end of + // all Animator functions. Thats why we use setTimeout here + setTimeout(() => { + Animator.cancelFrame(this._frameId) + this._frameId = Animator.frame(mergeTransforms.bind(this)) + }, 0) }, _prepareRunner () { if (this._frameId == null) { this._transformationRunners = new RunnerArray() .add(new FakeRunner(new Matrix(this))) - - this._frameId = frameId++ } } } @@ -689,6 +698,7 @@ extend(Runner, { morpher.to(newLevel) }) + this._rememberMorpher('zoom', morpher) return this }, @@ -794,6 +804,7 @@ extend(Runner, { currentAngle = affineParameters.rotate current = new Matrix(affineParameters) + element._addRunner(this) this.addTransform(current) return morpher.done() } @@ -940,14 +951,19 @@ extend(Runner, { return this.plot([ a, b, c, d ]) } - var morpher = this._element.MorphArray().to(a) + if (this._tryRetarget('plot', a)) return this + + var morpher = new Morphable(this._stepper) + .type(this._element.MorphArray).to(a) this.queue(function () { morpher.from(this._element.array()) }, function (pos) { this._element.plot(morpher.at(pos)) + return morpher.done() }) + this._rememberMorpher('plot', morpher) return this }, diff --git a/src/animation/Timeline.js b/src/animation/Timeline.js index 44b5261..56198e0 100644 --- a/src/animation/Timeline.js +++ b/src/animation/Timeline.js @@ -45,9 +45,7 @@ export default class Timeline extends EventTarget { // schedules a runner on the timeline schedule (runner, delay, when) { if (runner == null) { - return this._runners.map(makeSchedule).sort(function (a, b) { - return a.runner.id - b.runner.id - }) + return this._order.map((id) => makeSchedule(this._runners[id])) } // The start time for the next animation can either be given explicitly, @@ -218,7 +216,7 @@ export default class Timeline extends EventTarget { if (dtToStart <= 0) { runnersLeft = true - // This is for the case that teh timeline was seeked so that the time + // This is for the case that the timeline was seeked so that the time // is now before the startTime of the runner. Thats why we need to set // the runner to position 0 runner.reset() @@ -281,9 +279,14 @@ export default class Timeline extends EventTarget { registerMethods({ Element: { - timeline: function () { - this._timeline = (this._timeline || new Timeline()) - return this._timeline + timeline: function (timeline) { + if (timeline == null) { + this._timeline = (this._timeline || new Timeline()) + return this._timeline + } else { + this._timeline = timeline + return this + } } } }) |