33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import { getAnimations , ViewTransitionPart } from "./animations.js" ;
6+
77
88/**
99 * Returns CSS needed to morph an element during a View Transition,
1010 * following the technique described in https://www.bram.us/2025/05/15/view-transitions-border-radius-revisited/
1111 *
1212 * @param vt The active ViewTransition
1313 * @param element The element to apply the morph to
14- * @param properties A list of CSS properties to transition
14+ * @param options Object containing duration (ms) and easing string
1515 * @returns A string containing the required CSS, or an empty string if it couldn't be generated
1616 */
1717export function morph (
1818 vt : ViewTransition ,
1919 element : HTMLElement ,
20- properties : string [ ]
20+ properties : string [ ] ,
21+ options : { duration : number ; easing : string }
2122) : string {
2223 // 1. Get view-transition-name
2324 const styles = window . getComputedStyle ( element ) ;
@@ -34,18 +35,8 @@ export function morph(
3435 console . warn ( "morph: Element already has a CSS transition applied. It will be overwritten by morph." ) ;
3536 }
3637
37- // 3. Get the duration and easing from the original ::view-transition-group
38- const groupAnimations = getAnimations ( vt , vtName , ViewTransitionPart . Group ) ;
39- if ( groupAnimations . length === 0 ) {
40- console . warn ( `morph: Could not find ::view-transition-group animation for ${ vtName } . Skipping.` ) ;
41- return "" ;
42- }
43-
44- const anim = groupAnimations [ 0 ] ;
45- const effect = anim . effect as KeyframeEffect ;
46- const timing = effect . getComputedTiming ( ) ;
47- const durationMs = timing . duration ;
48- const easing = effect . getTiming ( ) . easing ;
38+ const durationMs = options . duration ;
39+ const easing = options . easing ;
4940
5041 // 4. Generate the CSS string
5142 if ( ! element . id ) {
0 commit comments