@@ -672,46 +672,28 @@ function getGroupTsDeltas(
672672 } = { } ;
673673
674674 for ( const leaderSlot of groupLeaderSlots ) {
675- // get first defined slot
676- // ignore missing slots at the start when positioning group
677- let firstDefinedSlot = undefined ;
678- for (
679- let slotNumber = leaderSlot ;
680- slotNumber < leaderSlot + slotsPerLeader ;
681- slotNumber ++
682- ) {
683- if ( slotNumber in slotTsDeltas ) {
684- firstDefinedSlot = slotNumber ;
685- break ;
686- }
687- }
675+ const slotNumbers = Array . from (
676+ { length : slotsPerLeader } ,
677+ ( _ , i ) => i + leaderSlot ,
678+ ) ;
679+ const definedSlotTsDeltas = slotNumbers
680+ . map ( ( slotNumber ) => slotTsDeltas [ slotNumber ] )
681+ . filter ( ( v ) => v !== undefined ) ;
688682
689- if ( firstDefinedSlot === undefined ) {
683+ if ( definedSlotTsDeltas . length === 0 ) {
690684 continue ;
691685 }
692686
693- let groupStart = Infinity ;
694- let groupEnd = - Infinity ;
695-
696- for (
697- let slotNumber = firstDefinedSlot ;
698- slotNumber < leaderSlot + slotsPerLeader ;
699- slotNumber ++
700- ) {
701- const slotTsDeltaRange = slotTsDeltas [ slotNumber ] ;
702- const slotStart = slotTsDeltaRange ?. [ 0 ] ;
703- const slotEnd = slotTsDeltaRange ?. [ 1 ] ;
687+ // ignore missing slots at the start when positioning group
688+ const minStart = Math . min ( ...definedSlotTsDeltas . map ( ( [ start ] ) => start ) ) ;
689+ const ends = definedSlotTsDeltas . map ( ( [ , end ] ) => end ) ;
690+ const definedEnds = ends . filter ( ( end ) => end !== undefined ) ;
704691
705- if ( slotStart != null ) {
706- groupStart = Math . min ( groupStart , slotStart ) ;
707- }
708- // undefined slot end will extend to max x
709- groupEnd = Math . max ( groupEnd , slotEnd ?? Infinity ) ;
710- }
692+ // undefined slot end will extend to max x
693+ const hasUndefinedEnd = ends . length > definedEnds . length ;
694+ const maxEnd = hasUndefinedEnd ? undefined : Math . max ( ...definedEnds ) ;
711695
712- // replace Infinity with undefined for end
713- const end = groupEnd === Infinity ? undefined : groupEnd ;
714- groupTsDeltas [ leaderSlot ] = [ groupStart , end ] ;
696+ groupTsDeltas [ leaderSlot ] = [ minStart , maxEnd ] ;
715697 }
716698 return groupTsDeltas ;
717699}
@@ -754,6 +736,7 @@ function moveLabelPosition(
754736
755737 const key = isGroup ? "groups" : "slots" ;
756738 const positionsToMutate = labelPositionsToMutate [ key ] ;
739+ const xPosProp = isGroup ? "--group-x" : "--slot-x" ;
757740
758741 const isVisible = ! ! position ;
759742 const prevPositions = prevLabelPositions ?. [ key ] ;
@@ -762,8 +745,7 @@ function moveLabelPosition(
762745 if ( ! isVisible ) {
763746 if ( forceUpdates || prevVisible ) {
764747 // hide
765- const prop = isGroup ? "--group-x" : "--slot-x" ;
766- el . style . setProperty ( prop , isVisible ? "0" : "-100000px" ) ;
748+ el . style . setProperty ( xPosProp , "-100000px" ) ;
767749 }
768750 return ;
769751 }
@@ -774,25 +756,26 @@ function moveLabelPosition(
774756 const prevXPos = prevPositions ?. [ slotNumber ] ?. [ 0 ] ;
775757
776758 if ( forceUpdates || xPos !== prevXPos ) {
777- const prop = isGroup ? "--group-x" : "--slot-x" ;
778- el . style . setProperty ( prop , `${ xPos } px` ) ;
759+ el . style . setProperty ( xPosProp , `${ xPos } px` ) ;
779760 }
780761
781762 // no width data -- extend to max width
782763 const width = position [ 1 ] ;
783764 const isExtended = position [ 1 ] == null ;
784- // extend past maxXPos to hide right border
785- const extendedWidth = width ?? maxXPos + 1 - xPos ;
786765 const prevWidth = prevPositions ?. [ slotNumber ] ?. [ 1 ] ;
766+ // extend past maxXPos to hide right border
767+ const newWidth = isExtended ? maxXPos - xPos + 1 : width ;
787768
788- if ( forceUpdates || extendedWidth !== prevWidth ) {
789- el . style . width = `${ extendedWidth } px` ;
769+ if ( forceUpdates || newWidth !== prevWidth ) {
770+ el . style . width = `${ newWidth } px` ;
790771 }
791772
792773 const wasPrevExtended =
793774 prevPositions ?. [ slotNumber ] && prevPositions [ slotNumber ] [ 1 ] == null ;
794775
795776 if ( isGroup && ( forceUpdates || isExtended !== wasPrevExtended ) ) {
777+ // Extended groups don't have a defined end, so we don't know where to center the name text.
778+ // Set to opacity 0, and transition to 1 when the group end becomes defined.
796779 el . style . setProperty ( "--group-name-opacity" , isExtended ? "0" : "1" ) ;
797780 }
798781}
0 commit comments