@@ -2,7 +2,11 @@ import type { RawSnapshotNode, Rect } from '@agent-device/kernel/snapshot';
22import { centerOfRect } from '@agent-device/kernel/snapshot' ;
33import { areRectsApproximatelyEqual , normalizeRect } from '@agent-device/kernel/rect-center' ;
44import { containsPoint , rectContains } from '@agent-device/kernel/rect' ;
5- import { normalizeType , isViewportRootNode } from '@agent-device/contracts/snapshot' ;
5+ import {
6+ isScrollableNodeLike ,
7+ normalizeType ,
8+ isViewportRootNode ,
9+ } from '@agent-device/contracts/snapshot' ;
610
711const COVERED_PRESENTATION_HINT = 'covered' ;
812const OVERLAY_KIND_FRAGMENTS = [
@@ -19,7 +23,7 @@ const OVERLAY_KIND_FRAGMENTS = [
1923] ;
2024const VIEWPORT_CHROME_KIND_FRAGMENTS = [ 'tabbar' , 'toolbar' , 'navigationbar' ] ;
2125const TOOLBAR_HOST_KIND_FRAGMENTS = [ 'toolbar' ] ;
22- const SCROLL_CONTAINER_TYPES = new Set ( [ 'collectionview ', 'table' , 'scrollview' ] ) ;
26+ const SCROLL_INDICATOR_KIND_FRAGMENTS = [ 'scrollbar ', 'scrollindicator' ] ;
2327const SEMANTIC_TOUCH_KIND_FRAGMENTS = [
2428 'button' ,
2529 'link' ,
@@ -321,7 +325,9 @@ function isSiblingSizedChromeContainer(
321325 if ( typeof node . parentIndex !== 'number' ) return false ;
322326 const rect = positiveRect ( node . rect ) ;
323327 if ( ! rect ) return false ;
324- const { siblings, position } = listedSiblings ( node , neighbourhood ) ;
328+ const listed = listedSiblings ( node , neighbourhood ) ;
329+ if ( ! listed ) return false ;
330+ const { siblings, position } = listed ;
325331 return siblings . some (
326332 ( sibling , siblingPosition ) =>
327333 siblingPosition !== position && areRectsApproximatelyEqual ( rect , sibling . rect ) ,
@@ -345,7 +351,9 @@ function isOwnPresentationToolbarHost(
345351 if ( ! nodeKindIncludesAny ( node , TOOLBAR_HOST_KIND_FRAGMENTS ) ) return false ;
346352 const rect = positiveRect ( node . rect ) ;
347353 if ( ! rect ) return false ;
348- const { siblings, position } = listedSiblings ( node , neighbourhood ) ;
354+ const listed = listedSiblings ( node , neighbourhood ) ;
355+ if ( ! listed ) return false ;
356+ const { siblings, position } = listed ;
349357 const ownStart = ownPresentationStart ( siblings , position ) ;
350358 const enclosed = siblings . flatMap ( ( sibling , siblingPosition ) =>
351359 siblingPosition !== position && isEnclosedHostedRegion ( rect , sibling ) ? [ siblingPosition ] : [ ] ,
@@ -366,25 +374,24 @@ function ownPresentationStart(siblings: readonly RawSnapshotNode[], position: nu
366374 return start ;
367375}
368376
369- /** A bar or a scroll container (by type, so a scroll indicator does not count) inside `rect` . */
377+ /** A bar or a scroll container inside `rect`; a scroll indicator is not a container . */
370378function isEnclosedHostedRegion ( rect : Rect , node : RawSnapshotNode ) : boolean {
371379 const isHostedRegion =
372380 nodeKindIncludesAny ( node , VIEWPORT_CHROME_KIND_FRAGMENTS ) ||
373- SCROLL_CONTAINER_TYPES . has ( normalizeType ( node . type ?? '' ) ) ;
381+ ( isScrollableNodeLike ( node ) && ! nodeKindIncludesAny ( node , SCROLL_INDICATOR_KIND_FRAGMENTS ) ) ;
374382 const nodeRect = positiveRect ( node . rect ) ;
375383 return Boolean ( isHostedRegion && nodeRect && rectContains ( rect , nodeRect ) ) ;
376384}
377385
378- /** The siblings listed under the node's parent in document order, and the node's position among them . */
386+ /** The siblings listed under the node's parent in document order and the node's position, if listed . */
379387function listedSiblings (
380388 node : RawSnapshotNode ,
381389 neighbourhood : NeighbourhoodIndex ,
382- ) : { siblings : readonly RawSnapshotNode [ ] ; position : number } {
383- const siblings =
384- typeof node . parentIndex === 'number'
385- ? ( neighbourhood . childrenByParent . get ( node . parentIndex ) ?? [ ] )
386- : [ ] ;
387- return { siblings, position : siblings . findIndex ( ( sibling ) => sibling . index === node . index ) } ;
390+ ) : { siblings : readonly RawSnapshotNode [ ] ; position : number } | undefined {
391+ if ( typeof node . parentIndex !== 'number' ) return undefined ;
392+ const siblings = neighbourhood . childrenByParent . get ( node . parentIndex ) ?? [ ] ;
393+ const position = siblings . findIndex ( ( sibling ) => sibling . index === node . index ) ;
394+ return position < 0 ? undefined : { siblings, position } ;
388395}
389396
390397function isFullViewportChromeContainer (
0 commit comments