* Animates the visual change after the DOM order is updated using FLIP. * Uses WAAPI directly for reliable mid-animation compositing and to * properly respect the app's no-animation setting. * @param {HTMLElement} $parent * @param {Map } previousRects
($parent, previousRects)
| 343 | * @param {Map<HTMLElement, DOMRect>} previousRects |
| 344 | */ |
| 345 | function animateTabReorder($parent, previousRects) { |
| 346 | for (const $child of $parent.children) { |
| 347 | if ($child === $tab) continue; |
| 348 | |
| 349 | const oldAnim = reorderAnimations.get($child); |
| 350 | if (oldAnim) { |
| 351 | oldAnim.cancel(); |
| 352 | reorderAnimations.delete($child); |
| 353 | } |
| 354 | |
| 355 | const previousRect = previousRects.get($child); |
| 356 | if (!previousRect) continue; |
| 357 | |
| 358 | const currentRect = $child.getBoundingClientRect(); |
| 359 | const deltaX = previousRect.left - currentRect.left; |
| 360 | const deltaY = previousRect.top - currentRect.top; |
| 361 | |
| 362 | if (Math.abs(deltaX) < 0.5 && Math.abs(deltaY) < 0.5) continue; |
| 363 | |
| 364 | const anim = $child.animate( |
| 365 | [ |
| 366 | { transform: `translate3d(${deltaX}px, ${deltaY}px, 0)` }, |
| 367 | { transform: "translate3d(0, 0, 0)" }, |
| 368 | ], |
| 369 | { |
| 370 | duration: document.body.classList.contains("no-animation") |
| 371 | ? 0 |
| 372 | : REORDER_DURATION, |
| 373 | easing: SPRING_EASING, |
| 374 | fill: "none", |
| 375 | composite: "replace", |
| 376 | }, |
| 377 | ); |
| 378 | reorderAnimations.set($child, anim); |
| 379 | |
| 380 | anim.onfinish = () => { |
| 381 | if (reorderAnimations.get($child) === anim) { |
| 382 | reorderAnimations.delete($child); |
| 383 | } |
| 384 | }; |
| 385 | anim.oncancel = () => { |
| 386 | if (reorderAnimations.get($child) === anim) { |
| 387 | reorderAnimations.delete($child); |
| 388 | } |
| 389 | }; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Scrolls the container using animation frame |