diff --git a/src/animation-turn.js b/src/animation-turn.js index c398d8e..e5bb0b3 100644 --- a/src/animation-turn.js +++ b/src/animation-turn.js @@ -17,7 +17,10 @@ export default class AnimationTurn extends BaseTurn { this.dispatch('before-exit', { detail }) window.requestAnimationFrame(() => { - exitAnimations.start(() => this.addClasses('exit')) + exitAnimations.start(() => { + this.addClasses(this.direction) + this.addClasses('exit') + }) this.removeClasses('before-exit') resolveExit() }) @@ -43,6 +46,7 @@ export default class AnimationTurn extends BaseTurn { async complete (detail) { this.removeClasses('enter') + this.removeClasses(this.direction) this.dispatch('enter', { detail: { ...detail, action: this.action } }) } @@ -50,6 +54,7 @@ export default class AnimationTurn extends BaseTurn { this.removeClasses('before-exit') this.removeClasses('exit') this.removeClasses('enter') + this.removeClasses(this.direction) } get finished () { diff --git a/src/base-turn.js b/src/base-turn.js index 850759a..0813a71 100644 --- a/src/base-turn.js +++ b/src/base-turn.js @@ -5,14 +5,18 @@ const DEFAULT_OPTIONS = { } export default class BaseTurn { - constructor (action, options = {}) { + constructor (action, direction = 'none', options = {}) { this.action = action + this.direction = direction this.options = { ...DEFAULT_OPTIONS, ...options } this.beforeExitClasses = new Set() this.exitClasses = new Set() this.enterClasses = new Set() this.beforeTransitionClasses = new Set() this.transitionClasses = new Set() + this.forwardClasses = new Set() + this.backClasses = new Set() + this.noneClasses = new Set() } addClasses (type) { diff --git a/src/controller.js b/src/controller.js index 8dee98b..336993d 100644 --- a/src/controller.js +++ b/src/controller.js @@ -39,8 +39,8 @@ export default class Controller { visit (event) { this.reset(event) - this.animationTurn = create(AnimationTurn, event.detail.action) - this.viewTransitionTurn = create(ViewTransitionTurn, event.detail.action) + this.animationTurn = create(AnimationTurn, event.detail.action, event.detail.direction) + this.viewTransitionTurn = create(ViewTransitionTurn, event.detail.action, event.detail.direction) this.animationTurn.exit({ ...event.detail, @@ -132,10 +132,10 @@ function removeActionClasses () { classList.remove.apply(classList, ACTIONS.map(a => `turn-${a}`)) } -function create (Klass, action) { +function create (Klass, action, direction) { if (!Klass.supported || document.body.dataset.turn === 'false') { Klass = NullTurn } const options = JSON.parse(document.body.dataset.turnOptions || '{}') - return new Klass(action, options) + return new Klass(action, direction, options) } diff --git a/src/null-turn.js b/src/null-turn.js index 25c470e..65b29f0 100644 --- a/src/null-turn.js +++ b/src/null-turn.js @@ -1,5 +1,6 @@ export default class NullTurn { static supported = true + direction = 'none' exit () {} async beforeEnter () {} async enter () {}