@@ -102,6 +102,8 @@ interface EdgeRide {
102102 * on the content can show.
103103 */
104104 beyond : number ;
105+ /** How much shows as the close starts: its conceal's first keyframe. */
106+ concealStart : number ;
105107}
106108
107109/**
@@ -111,7 +113,8 @@ interface EdgeRide {
111113 * shown bottom edge stands against the content after it. Both sides are read
112114 * on the module's own clock: the clip from its animation's keyframes and the
113115 * content after it from its glide's keyframes, at their current time (WebKit
114- * evaluates a main-thread clip and a compositor translate a little apart).
116+ * evaluates a main-thread clip and a compositor translate a little apart). It
117+ * also reads where the close starts: its conceal's first keyframe.
115118 */
116119async function edgeRide (
117120 page : Page ,
@@ -175,8 +178,8 @@ async function edgeRide(
175178 [ ...String ( value ) . matchAll ( / ( - ? [ \d . e + - ] + ) p x / g) ] . map ( m =>
176179 Number ( m [ 1 ] ) ,
177180 ) [ 1 ] ?? 0 ;
178- const glideTop = ( element : HTMLElement ) => {
179- const rect = element . getBoundingClientRect ( ) ;
181+ // An element's glide offset from its keyframes at its current time.
182+ const glideY = ( element : HTMLElement ) => {
180183 const animation = element
181184 . getAnimations ( )
182185 . filter ( a =>
@@ -186,31 +189,43 @@ async function edgeRide(
186189 )
187190 . at ( - 1 ) ;
188191 if ( animation == null ) {
189- return rect . top ;
192+ return 0 ;
190193 }
191194 const frames = ( animation . effect as KeyframeEffect ) . getKeyframes ( ) ;
192195 const { i, f} = bracket ( frames , at ( animation ) ) ;
193196 const y0 = y ( frames [ i ] . translate ) ;
194197 const y1 = y ( frames [ i + 1 ] . translate ) ;
195- return (
196- rect . top - y ( getComputedStyle ( element ) . translate ) + y0 + ( y1 - y0 ) * f
197- ) ;
198+ return y0 + ( y1 - y0 ) * f ;
199+ } ;
200+ // A box's top on the module's clock: where layout puts it (offsets ignore
201+ // transforms), plus each glide that carries it. No evaluated transform is
202+ // read, because WebKit evaluates a running translate a little ahead.
203+ const clockTop = ( element : HTMLElement ) => {
204+ let top = 0 ;
205+ let node : HTMLElement | null = element ;
206+ while ( node != null ) {
207+ top += node . offsetTop + ( node === element ? 0 : node . clientTop ) ;
208+ node = node . offsetParent as HTMLElement | null ;
209+ }
210+ for ( let n : HTMLElement | null = element ; n != null ; ) {
211+ top += glideY ( n ) ;
212+ n = n . parentElement ;
213+ }
214+ return top ;
198215 } ;
199216 const frames : EdgeRideFrame [ ] = [ ] ;
200217 const read = ( phase : string ) => {
201218 const element = content ( ) ;
202219 if ( element == null ) {
203220 return ;
204221 }
205- const box = element . getBoundingClientRect ( ) ;
222+ const height = element . offsetHeight ;
206223 const hidden = insetBottom ( element ) ;
207224 frames . push ( {
208225 phase,
209- gap : glideTop ( next ) - ( box . bottom - hidden ) ,
226+ gap : clockTop ( next ) - ( clockTop ( element ) + height - hidden ) ,
210227 shown :
211- getComputedStyle ( element ) . display === 'none'
212- ? 0
213- : box . height - hidden ,
228+ getComputedStyle ( element ) . display === 'none' ? 0 : height - hidden ,
214229 } ) ;
215230 } ;
216231 const frame = async ( ) =>
@@ -262,6 +277,14 @@ async function edgeRide(
262277 setTimeout ( resolve , 0 ) ;
263278 } ) ;
264279 }
280+ const conceal = clipOf ( ) ;
281+ const [ start ] =
282+ ( conceal ?. effect as KeyframeEffect | undefined ) ?. getKeyframes ( ) ?? [ ] ;
283+ const startBox = ( content ( ) as HTMLElement ) . getBoundingClientRect ( ) ;
284+ const concealStart =
285+ start == null
286+ ? Number . NaN
287+ : startBox . height - bottomOf ( start . clipPath , startBox ) ;
265288 for ( const animation of document . getAnimations ( ) ) {
266289 if ( animation . playState === 'paused' ) {
267290 animation . play ( ) ;
@@ -271,7 +294,7 @@ async function edgeRide(
271294 await frame ( ) ;
272295 read ( 'closing' ) ;
273296 }
274- return { frames, restGap, height, beyond} ;
297+ return { frames, restGap, height, beyond, concealStart } ;
275298 } , selectors ) ;
276299}
277300
@@ -294,12 +317,14 @@ function expectEdgeRide(result: EdgeRide): void {
294317 expect ( f . gap , detail ) . toBeGreaterThan ( result . restGap - result . beyond - 1.5 ) ;
295318 }
296319 const reversed = result . frames . find ( f => f . phase === 'reversed' ) ;
297- const next = result . frames . find ( f => f . phase === 'closing' ) ;
298320 expect ( reversed ?. shown ) . toBeGreaterThan ( 2 ) ;
299321 expect ( reversed ?. shown ) . toBeLessThan ( result . height - 2 ) ;
300- expect ( Math . abs ( ( next ?. shown ?? 0 ) - ( reversed ?. shown ?? 0 ) ) ) . toBeLessThan (
301- result . height / 4 ,
302- ) ;
322+ // Read at its first keyframe, not on a later frame, where a quick curve
323+ // has already moved on. The clip may also show the container gap that the
324+ // content after it travels.
325+ const start = result . concealStart - ( reversed ?. shown ?? 0 ) ;
326+ expect ( start ) . toBeGreaterThan ( - 1 ) ;
327+ expect ( start ) . toBeLessThan ( result . beyond + 1 ) ;
303328}
304329
305330async function viewportScroll ( page : Page ) : Promise < number > {
@@ -452,6 +477,59 @@ test.describe('component:Collapsible FR10 and component:TreeList FR9 (spec:AST-1
452477 const b1 = bottomOf ( frames [ i + 1 ] . clipPath , height ) ;
453478 return b0 + ( b1 - b0 ) * f ;
454479 } ;
480+ // A box's top on the module's clock, as the clip is read. It is where
481+ // layout puts it, since offsets ignore transforms, plus each glide that
482+ // carries it at its current time. No evaluated transform is read:
483+ // WebKit evaluates a running translate a little ahead.
484+ const yOf = ( value : unknown ) =>
485+ [ ...String ( value ) . matchAll ( / ( - ? [ \d . e + - ] + ) p x / g) ] . map ( m =>
486+ Number ( m [ 1 ] ) ,
487+ ) [ 1 ] ?? 0 ;
488+ const glideY = ( node : HTMLElement ) => {
489+ const animation = node
490+ . getAnimations ( )
491+ . filter ( a =>
492+ ( a . effect as KeyframeEffect )
493+ . getKeyframes ( )
494+ . some ( k => k . translate != null ) ,
495+ )
496+ . at ( - 1 ) ;
497+ if ( animation == null ) {
498+ return 0 ;
499+ }
500+ const effect = animation . effect as KeyframeEffect ;
501+ const frames = effect . getKeyframes ( ) ;
502+ const at = Math . min (
503+ 1 ,
504+ Math . max (
505+ 0 ,
506+ Number ( animation . currentTime ) / Number ( effect . getTiming ( ) . duration ) ,
507+ ) ,
508+ ) ;
509+ let i = 0 ;
510+ while ( i < frames . length - 2 && frames [ i + 1 ] . computedOffset < at ) {
511+ i += 1 ;
512+ }
513+ const o0 = frames [ i ] . computedOffset ;
514+ const o1 = frames [ i + 1 ] . computedOffset ;
515+ const f = o1 > o0 ? ( at - o0 ) / ( o1 - o0 ) : 1 ;
516+ const y0 = yOf ( frames [ i ] . translate ) ;
517+ const y1 = yOf ( frames [ i + 1 ] . translate ) ;
518+ return y0 + ( y1 - y0 ) * f ;
519+ } ;
520+ const clockTop = ( element : HTMLElement ) => {
521+ let top = 0 ;
522+ let node : HTMLElement | null = element ;
523+ while ( node != null ) {
524+ top += node . offsetTop + ( node === element ? 0 : node . clientTop ) ;
525+ node = node . offsetParent as HTMLElement | null ;
526+ }
527+ for ( let n : HTMLElement | null = element ; n != null ; ) {
528+ top += glideY ( n ) ;
529+ n = n . parentElement ;
530+ }
531+ return top ;
532+ } ;
455533 const frame = async ( ) =>
456534 new Promise < void > ( resolve => {
457535 requestAnimationFrame ( ( ) => resolve ( ) ) ;
@@ -472,19 +550,19 @@ test.describe('component:Collapsible FR10 and component:TreeList FR9 (spec:AST-1
472550 if ( element == null || getComputedStyle ( element ) . display === 'none' ) {
473551 continue ;
474552 }
475- const box = element . getBoundingClientRect ( ) ;
476553 const hidden = hiddenBottom ( element ) ;
554+ const bottom = clockTop ( element ) + element . offsetHeight ;
477555 frames . push ( {
478- gap : nextItem ( ) . getBoundingClientRect ( ) . top - ( box . bottom - hidden ) ,
479- shown : box . height - hidden ,
556+ gap : clockTop ( nextItem ( ) ) - ( bottom - hidden ) ,
557+ shown : element . offsetHeight - hidden ,
480558 } ) ;
481559 }
482560 await settle ( ) ;
483- const box = ( content ( ) as HTMLElement ) . getBoundingClientRect ( ) ;
561+ const rest = content ( ) as HTMLElement ;
484562 return {
485563 frames,
486- restGap : nextItem ( ) . getBoundingClientRect ( ) . top - box . bottom ,
487- height : box . height ,
564+ restGap : clockTop ( nextItem ( ) ) - ( clockTop ( rest ) + rest . offsetHeight ) ,
565+ height : rest . offsetHeight ,
488566 } ;
489567 } ) ;
490568 const shown = result . frames . filter ( f => f . shown > 0.5 ) ;
0 commit comments