@@ -25,7 +25,7 @@ export type TrackSize = number | CSSTrackSize;
2525export const isFractionUnit = ( trackSize : TrackSize ) =>
2626 typeof trackSize === "string" && trackSize . endsWith ( "fr" ) ;
2727
28- export const isPixelUnit = ( trackSize : TrackSize ) =>
28+ export const isPixelUnit = ( trackSize : TrackSize ) : trackSize is CSSTrackSize =>
2929 typeof trackSize === "string" && trackSize . endsWith ( "px" ) ;
3030
3131const NO_SPLITTERS : ISplitter [ ] = [ ] ;
@@ -59,13 +59,16 @@ export const isMapBasedLayout = (
5959 Record < string , GridLayoutChildItemDescriptor >
6060> => ! Array . isArray ( layout . gridLayoutItems ) ;
6161
62- export type GridLayoutDescriptor <
63- T extends GridLayoutChildItemDescriptors = GridLayoutChildItemDescriptors ,
64- > = {
62+ export interface GridColumnsAndRows {
6563 cols : TrackSize [ ] ;
6664 rows : TrackSize [ ] ;
65+ }
66+
67+ export interface GridLayoutDescriptor <
68+ T extends GridLayoutChildItemDescriptors = GridLayoutChildItemDescriptors ,
69+ > extends GridColumnsAndRows {
6770 gridLayoutItems : T ;
68- } ;
71+ }
6972
7073export interface GridLayoutModelCoordinates {
7174 column : GridLayoutModelPosition ;
@@ -484,6 +487,18 @@ export class GridTrack {
484487 return isFractionUnit ( this . #trackSize) ;
485488 }
486489
490+ get isPixelValue ( ) {
491+ return isPixelUnit ( this . #trackSize) ;
492+ }
493+
494+ get isNumber ( ) {
495+ return typeof this . #trackSize === "number" ;
496+ }
497+
498+ get isMeasured ( ) {
499+ return this . measuredValue !== - 1 ;
500+ }
501+
487502 get measuredValue ( ) {
488503 return this . #measuredValue ?? - 1 ;
489504 }
@@ -502,9 +517,13 @@ export class GridTrack {
502517 }
503518 }
504519
505- get numericValue ( ) {
506- if ( typeof this . #trackSize === "number" ) {
507- return this . #trackSize;
520+ get hasNumericValue ( ) {
521+ return this . isNumber || this . isPixelValue || this . isMeasured ;
522+ }
523+
524+ get numericValue ( ) : number {
525+ if ( this . isNumber ) {
526+ return this . #trackSize as number ;
508527 } else if ( isPixelUnit ( this . #trackSize) ) {
509528 return parseInt ( this . #trackSize) ;
510529 } else if ( this . #measuredValue !== - 1 ) {
@@ -611,6 +630,42 @@ export class GridTracks extends EventEmitter<GridTrackEvents> {
611630 }
612631 }
613632
633+ getBisectingTrack (
634+ trackType : TrackType ,
635+ startIndex : number ,
636+ endIndex : number ,
637+ ) {
638+ console . log (
639+ `[GridTracks] getBisectingTrack (${ trackType } ) [${ startIndex } : ${ endIndex } ] ` ,
640+ ) ;
641+
642+ const tracks = this . getTracks ( trackType ) ;
643+ const tracksInRange = tracks . slice ( startIndex - 1 , endIndex ) ;
644+ if ( ! tracksInRange . every ( ( track ) => track . hasNumericValue ) ) {
645+ this . measure ( trackType ) ;
646+ }
647+
648+ if ( endIndex - startIndex > 1 ) {
649+ // Total the sizes between start and end
650+ // find the half way point
651+ // see if an existing edge occurs at that point (or wiuthin .5 pixesl, if decimal)
652+ }
653+ let size = 0 ;
654+ for ( let i = startIndex - 1 ; i < endIndex - 1 ; i ++ ) {
655+ size += tracks [ i ] . numericValue ;
656+ }
657+ const halfSize = size / 2 ;
658+
659+ size = 0 ;
660+ for ( let i = startIndex - 1 ; i < endIndex - 1 ; i ++ ) {
661+ size += tracks [ i ] . numericValue ;
662+ if ( Math . abs ( halfSize - size ) < 1 ) {
663+ return i + 2 ;
664+ }
665+ }
666+ return - 1 ;
667+ }
668+
614669 splitTrack ( trackType : TrackType , trackIndex : number ) {
615670 console . log ( `[GridTracks] splitTrack (${ trackType } ) [${ trackIndex } ] ` ) ;
616671
0 commit comments