nl_tokens: Collection - layout
pl_tokens: function CollectionLayout ( context_ , options ) { // Prepare context = context_ ; size = context . size ; direction = context . direction ; alignment = context . alignment ; lineDirection = ( direction + 1 ) % 2 ; if ( ( options . gutter !== undefined ) && console . warn && ! options . suppressWarnings ) { //eslint-disable-line no-console console . warn ( 'option `gutter` has been deprecated for CollectionLayout, use margins & spacing instead' ) ; //eslint-disable-line no-console } if ( options . gutter && ! options . margins && ! options . spacing ) { var gutter = Array . isArray ( options . gutter ) ? options . gutter : [ options . gutter , options . gutter ] ; margins = [ gutter [ 1 ] , gutter [ 0 ] , gutter [ 1 ] , gutter [ 0 ] ] ; spacing = gutter ; } else { margins = LayoutUtility . normalizeMargins ( options . margins ) ; spacing = options . spacing || 0 ; spacing = Array . isArray ( spacing ) ? spacing : [ spacing , spacing ] ; } margin [ 0 ] = margins [ direction ? 0 : 3 ] ; margin [ 1 ] = - margins [ direction ? 2 : 1 ] ; justify = Array . isArray ( options . justify ) ? options . justify : ( <mask> . justify ? [ true , true ] : [ false , false ] ) ; lineLength = size [ lineDirection ] - ( direction ? ( margins [ 3 ] + margins [ 1 ] ) : ( margins [ 0 ] + margins [ 2 ] ) ) ; var node ; var nodeSize ; var lineOffset ; var bound ; // // Prepare item-size // if ( options . cells ) { if ( options . itemSize && console . warn && ! options . suppressWarnings ) { //eslint-disable-line no-console console . warn ( 'options `cells` and `itemSize` cannot both be specified for CollectionLayout, only use one of the two' ) ; //eslint-disable-line no-console } itemSize = [ ( [ undefined , true ] . indexOf ( options . cells [ 0 ] ) > - 1 ) ? options . cells [ 0 ] : ( size [ 0 ] - ( margins [ 1 ] + margins [ 3 ] + ( spacing [ 0 ] * ( options . cells [ 0 ] - 1 ) ) ) ) / options . cells [ 0 ] , ( [ undefined , true ] . indexOf ( options . cells [ 1 ] ) > - 1 ) ? options . cells [ 1 ] : ( size [ 1 ] - ( margins [ 0 ] + margins [ 2 ] + ( spacing [ 1 ] * ( options . cells [ 1 ] - 1 ) ) ) ) / options . cells [ 1 ] ] ; } else if ( ! options . itemSize ) { itemSize = [ true , true ] ; // when no item-size specified, use size from renderables } else if ( options . itemSize instanceof Function ) { getItemSize = options . itemSize ; } else if ( ( options . itemSize [ 0 ] === undefined ) || ( options . itemSize [ 0 ] === undefined ) ) { // resolve 'undefined' into a fixed size itemSize = [ ( options . itemSize [ 0 ] === undefined ) ? size [ 0 ] : options . itemSize [ 0 ] , ( options . itemSize [ 1 ] === undefined ) ? size [ 1 ] : options . itemSize [ 1 ] ] ; } else { itemSize = options . itemSize ; } // // Process all next nodes // offset = context . scrollOffset + margin [ alignment ] + ( alignment ? spacing [ direction ] : 0 ) ; bound = context . scrollEnd + ( alignment ? 0 : margin [ alignment ] ) ; lineOffset = 0 ; lineNodes = [ ] ; while ( offset < bound ) { node = context . next ( ) ; if ( ! node ) { _layoutLine ( true , true ) ; break ; } nodeSize = _resolveNodeSize ( node ) ; lineOffset += ( lineNodes . length ? spacing [ lineDirection ] : 0 ) + nodeSize [ lineDirection ] ; if ( ( Math . round ( lineOffset * 100 ) / 100 ) > lineLength ) { offset += _layoutLine ( true , ! node ) ; lineOffset = nodeSize [ lineDirection ] ; } lineNodes . push ( { node : node , size : nodeSize } ) ; } // // Process previous nodes // offset = context . scrollOffset + margin [ alignment ] - ( alignment ? 0 : spacing [ direction ] ) ; bound = context . scrollStart + ( alignment ? margin [ alignment ] : 0 ) ; lineOffset = 0 ; lineNodes = [ ] ; while ( offset > bound ) { node = context . prev ( ) ; if ( ! node ) { _layoutLine ( false , true ) ; break ; } nodeSize = _resolveNodeSize ( node ) ; lineOffset += ( lineNodes . length ? spacing [ lineDirection ] : 0 ) + nodeSize [ lineDirection ] ; if ( ( Math . round ( lineOffset * 100 ) / 100 ) > lineLength ) { offset -= _layoutLine ( false , ! node ) ; lineOffset = nodeSize [ lineDirection ] ; } lineNodes . unshift ( { node : node , size : nodeSize } ) ; } }