()
| 2 | import Sortable from './Sortable.js'; |
| 3 | |
| 4 | export default function AnimationStateManager() { |
| 5 | let animationStates = [], |
| 6 | animationCallbackId; |
| 7 | |
| 8 | return { |
| 9 | captureAnimationState() { |
| 10 | animationStates = []; |
| 11 | if (!this.options.animation) return; |
| 12 | let children = [].slice.call(this.el.children); |
| 13 | |
| 14 | children.forEach(child => { |
| 15 | if (css(child, 'display') === 'none' || child === Sortable.ghost) return; |
| 16 | animationStates.push({ |
| 17 | target: child, |
| 18 | rect: getRect(child) |
| 19 | }); |
| 20 | let fromRect = { ...animationStates[animationStates.length - 1].rect }; |
| 21 | |
| 22 | // If animating: compensate for current animation |
| 23 | if (child.thisAnimationDuration) { |
| 24 | let childMatrix = matrix(child, true); |
| 25 | if (childMatrix) { |
| 26 | fromRect.top -= childMatrix.f; |
| 27 | fromRect.left -= childMatrix.e; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | child.fromRect = fromRect; |
| 32 | }); |
| 33 | }, |
| 34 | |
| 35 | addAnimationState(state) { |
| 36 | animationStates.push(state); |
| 37 | }, |
| 38 | |
| 39 | removeAnimationState(target) { |
| 40 | animationStates.splice(indexOfObject(animationStates, { target }), 1); |
| 41 | }, |
| 42 | |
| 43 | animateAll(callback) { |
| 44 | if (!this.options.animation) { |
| 45 | clearTimeout(animationCallbackId); |
| 46 | if (typeof(callback) === 'function') callback(); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | let animating = false, |
| 51 | animationTime = 0; |
| 52 | |
| 53 | animationStates.forEach((state) => { |
| 54 | let time = 0, |
| 55 | animatingThis = false, |
| 56 | target = state.target, |
| 57 | fromRect = target.fromRect, |
| 58 | toRect = getRect(target), |
| 59 | prevFromRect = target.prevFromRect, |
| 60 | prevToRect = target.prevToRect, |
| 61 | animatingRect = state.rect, |
no outgoing calls
no test coverage detected
searching dependent graphs…