Flip grid
ng-gsap + gsap/Flip
Flip (also free in core now) captures a layout's "before" state, lets Angular's @for reorder or resize the DOM however it wants, then animates every tile from where it was to where it landed — no manual position math. injectGSAP just needs to read the same signals the grid renders from, so it re-runs right after the DOM settles into its new shape.
Tween
Timeline
Ease
Stagger
Scrub
Pin
Morph
Flip
Context
protected items = signal<Tile[]>(TILES);
protected large = signal(false);
private flipState?: Flip.FlipState;
// viewChildren, not a '.tile' selector string — Angular already tracks every
// rendered tile, so Flip gets the real elements straight from the query
private tiles = viewChildren<ElementRef<HTMLElement>>('tile');
// items()/large() are the dependencies — injectGSAP re-runs after Angular's
// @for reorders the DOM, and Flip.from() animates from the captured "before" state
private anim = injectGSAP(() => {
this.items();
this.large();
if (this.flipState) {
Flip.from(this.flipState, { duration: 0.6, ease: 'power2.inOut', stagger: 0.03, scale: true });
this.flipState = undefined;
}
}, { scope: this.grid });
protected shuffle(): void {
this.flipState = Flip.getState(this.tiles().map((t) => t.nativeElement)); // capture "before"
this.items.update((list) => shuffle(list)); // Angular reorders the DOM
}