@@ -667,46 +667,28 @@ function getGroupTsDeltas(
667667 } = { } ;
668668
669669 for ( const leaderSlot of groupLeaderSlots ) {
670- // get first defined slot
671- // ignore missing slots at the start when positioning group
672- let firstDefinedSlot = undefined ;
673- for (
674- let slotNumber = leaderSlot ;
675- slotNumber < leaderSlot + slotsPerLeader ;
676- slotNumber ++
677- ) {
678- if ( slotNumber in slotTsDeltas ) {
679- firstDefinedSlot = slotNumber ;
680- break ;
681- }
682- }
670+ const slotNumbers = Array . from (
671+ { length : slotsPerLeader } ,
672+ ( _ , i ) => i + leaderSlot ,
673+ ) ;
674+ const definedSlotTsDeltas = slotNumbers
675+ . map ( ( slotNumber ) => slotTsDeltas [ slotNumber ] )
676+ . filter ( ( v ) => v !== undefined ) ;
683677
684- if ( firstDefinedSlot === undefined ) {
678+ if ( definedSlotTsDeltas . length === 0 ) {
685679 continue ;
686680 }
687681
688- let groupStart = Infinity ;
689- let groupEnd = - Infinity ;
690-
691- for (
692- let slotNumber = firstDefinedSlot ;
693- slotNumber < leaderSlot + slotsPerLeader ;
694- slotNumber ++
695- ) {
696- const slotTsDeltaRange = slotTsDeltas [ slotNumber ] ;
697- const slotStart = slotTsDeltaRange ?. [ 0 ] ;
698- const slotEnd = slotTsDeltaRange ?. [ 1 ] ;
682+ // ignore missing slots at the start when positioning group
683+ const minStart = Math . min ( ...definedSlotTsDeltas . map ( ( [ start ] ) => start ) ) ;
684+ const ends = definedSlotTsDeltas . map ( ( [ , end ] ) => end ) ;
685+ const definedEnds = ends . filter ( ( end ) => end !== undefined ) ;
699686
700- if ( slotStart != null ) {
701- groupStart = Math . min ( groupStart , slotStart ) ;
702- }
703- // undefined slot end will extend to max x
704- groupEnd = Math . max ( groupEnd , slotEnd ?? Infinity ) ;
705- }
687+ // undefined slot end will extend to max x
688+ const hasUndefinedEnd = ends . length > definedEnds . length ;
689+ const maxEnd = hasUndefinedEnd ? undefined : Math . max ( ...definedEnds ) ;
706690
707- // replace Infinity with undefined for end
708- const end = groupEnd === Infinity ? undefined : groupEnd ;
709- groupTsDeltas [ leaderSlot ] = [ groupStart , end ] ;
691+ groupTsDeltas [ leaderSlot ] = [ minStart , maxEnd ] ;
710692 }
711693 return groupTsDeltas ;
712694}
@@ -749,6 +731,7 @@ function moveLabelPosition(
749731
750732 const key = isGroup ? "groups" : "slots" ;
751733 const positionsToMutate = labelPositionsToMutate [ key ] ;
734+ const xPosProp = isGroup ? "--group-x" : "--slot-x" ;
752735
753736 const isVisible = ! ! position ;
754737 const prevPositions = prevLabelPositions ?. [ key ] ;
@@ -757,8 +740,7 @@ function moveLabelPosition(
757740 if ( ! isVisible ) {
758741 if ( forceUpdates || prevVisible ) {
759742 // hide
760- const prop = isGroup ? "--group-x" : "--slot-x" ;
761- el . style . setProperty ( prop , isVisible ? "0" : "-100000px" ) ;
743+ el . style . setProperty ( xPosProp , "-100000px" ) ;
762744 }
763745 return ;
764746 }
@@ -769,25 +751,26 @@ function moveLabelPosition(
769751 const prevXPos = prevPositions ?. [ slotNumber ] ?. [ 0 ] ;
770752
771753 if ( forceUpdates || xPos !== prevXPos ) {
772- const prop = isGroup ? "--group-x" : "--slot-x" ;
773- el . style . setProperty ( prop , `${ xPos } px` ) ;
754+ el . style . setProperty ( xPosProp , `${ xPos } px` ) ;
774755 }
775756
776757 // no width data -- extend to max width
777758 const width = position [ 1 ] ;
778759 const isExtended = position [ 1 ] == null ;
779- // extend past maxXPos to hide right border
780- const extendedWidth = width ?? maxXPos + 1 - xPos ;
781760 const prevWidth = prevPositions ?. [ slotNumber ] ?. [ 1 ] ;
761+ // extend past maxXPos to hide right border
762+ const newWidth = isExtended ? maxXPos - xPos + 1 : width ;
782763
783- if ( forceUpdates || extendedWidth !== prevWidth ) {
784- el . style . width = `${ extendedWidth } px` ;
764+ if ( forceUpdates || newWidth !== prevWidth ) {
765+ el . style . width = `${ newWidth } px` ;
785766 }
786767
787768 const wasPrevExtended =
788769 prevPositions ?. [ slotNumber ] && prevPositions [ slotNumber ] [ 1 ] == null ;
789770
790771 if ( isGroup && ( forceUpdates || isExtended !== wasPrevExtended ) ) {
772+ // Extended groups don't have a defined end, so we don't know where to center the name text.
773+ // Set to opacity 0, and transition to 1 when the group end becomes defined.
791774 el . style . setProperty ( "--group-name-opacity" , isExtended ? "0" : "1" ) ;
792775 }
793776}
0 commit comments