@@ -41,16 +41,16 @@ export type FlexBasisAlias = 'grow' | 'initial' | 'auto' | 'none' | 'nogrow' | '
41
41
interface FlexBuilderParent {
42
42
direction : string ;
43
43
hasWrap : boolean ;
44
- useColumnBasisZero : boolean | undefined ;
45
44
}
46
45
47
46
@Injectable ( { providedIn : 'root' } )
48
- export class FlexStyleBuilder implements StyleBuilder {
49
- buildStyles ( input : string , parent : FlexBuilderParent ) : StyleDefinition {
50
- let grow : string | number ;
51
- let shrink : string | number ;
52
- let basis : string | number ;
53
- [ grow , shrink , basis ] = input . split ( '_' ) ;
47
+ export class FlexStyleBuilder extends StyleBuilder {
48
+ constructor ( @Inject ( LAYOUT_CONFIG ) protected layoutConfig : LayoutConfigOptions ) {
49
+ super ( ) ;
50
+ }
51
+ buildStyles ( input : string , parent : FlexBuilderParent ) {
52
+ let [ grow , shrink , ...basisParts ] : ( string | number ) [ ] = input . split ( ' ' ) ;
53
+ let basis = basisParts . join ( ' ' ) ;
54
54
55
55
// The flex-direction of this element's flex container. Defaults to 'row'.
56
56
const direction = ( parent . direction . indexOf ( 'column' ) > - 1 ) ? 'column' : 'row' ;
@@ -97,7 +97,7 @@ export class FlexStyleBuilder implements StyleBuilder {
97
97
} ;
98
98
switch ( basis || '' ) {
99
99
case '' :
100
- const useColumnBasisZero = parent . useColumnBasisZero !== false ;
100
+ const useColumnBasisZero = this . layoutConfig . useColumnBasisZero !== false ;
101
101
basis = direction === 'row' ? '0%' : ( useColumnBasisZero ? '0.000000001px' : 'auto' ) ;
102
102
break ;
103
103
case 'initial' : // default
@@ -192,7 +192,7 @@ export class FlexStyleBuilder implements StyleBuilder {
192
192
}
193
193
}
194
194
195
- return extendObject ( css , { 'box-sizing' : 'border-box' } ) ;
195
+ return extendObject ( css , { 'box-sizing' : 'border-box' } ) as StyleDefinition ;
196
196
}
197
197
}
198
198
@@ -310,12 +310,25 @@ export class FlexDirective extends BaseDirective implements OnInit, OnChanges, O
310
310
flexBasis = this . _mqActivation . activatedInput ;
311
311
}
312
312
313
- let basis = String ( flexBasis ) . replace ( ';' , '' ) ;
314
- let parts = validateBasis ( basis , this . _queryInput ( 'grow' ) , this . _queryInput ( 'shrink' ) ) ;
313
+ const basis = String ( flexBasis ) . replace ( ';' , '' ) ;
314
+ const parts = validateBasis ( basis , this . _queryInput ( 'grow' ) , this . _queryInput ( 'shrink' ) ) ;
315
315
const addFlexToParent = this . layoutConfig . addFlexToParent !== false ;
316
316
const direction = this . _getFlexFlowDirection ( this . parentElement , addFlexToParent ) ;
317
317
const hasWrap = this . _layout && this . _layout . wrap ;
318
- const useColumnBasisZero = this . layoutConfig . useColumnBasisZero ;
319
- this . addStyles ( parts . join ( '_' ) , { direction, hasWrap, useColumnBasisZero} ) ;
318
+ if ( direction === 'row' && hasWrap ) {
319
+ this . _styleCache = flexRowWrapCache ;
320
+ } else if ( direction === 'row' && ! hasWrap ) {
321
+ this . _styleCache = flexRowCache ;
322
+ } else if ( direction === 'column' && hasWrap ) {
323
+ this . _styleCache = flexColumnWrapCache ;
324
+ } else if ( direction === 'column' && ! hasWrap ) {
325
+ this . _styleCache = flexColumnCache ;
326
+ }
327
+ this . addStyles ( parts . join ( ' ' ) , { direction, hasWrap} ) ;
320
328
}
321
329
}
330
+
331
+ const flexRowCache : Map < string , StyleDefinition > = new Map ( ) ;
332
+ const flexColumnCache : Map < string , StyleDefinition > = new Map ( ) ;
333
+ const flexRowWrapCache : Map < string , StyleDefinition > = new Map ( ) ;
334
+ const flexColumnWrapCache : Map < string , StyleDefinition > = new Map ( ) ;
0 commit comments