diff --git a/dist/css-layout.h b/dist/css-layout.h index 47ae3f3f..c0293f75 100644 --- a/dist/css-layout.h +++ b/dist/css-layout.h @@ -1,7 +1,7 @@ -/* - * #define CSS_LAYOUT_IMPLEMENTATION - * before you include this file in *one* C or C++ file to create the implementation. - */ +/* + * #define CSS_LAYOUT_IMPLEMENTATION + * before you include this file in *one* C or C++ file to create the implementation. + */ /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. @@ -133,18 +133,22 @@ typedef struct { float maxDimensions[2]; } css_style_t; -typedef struct css_node { +typedef struct css_node css_node_t; +struct css_node { css_style_t style; css_layout_t layout; int children_count; int line_index; + css_node_t* next_absolute_child; + css_node_t* next_flex_child; + css_dim_t (*measure)(void *context, float width); void (*print)(void *context); struct css_node* (*get_child)(void *context, int i); bool (*is_dirty)(void *context); void *context; -} css_node_t; +}; // Lifecycle of nodes and children @@ -165,7 +169,7 @@ void layoutNode(css_node_t *node, float maxWidth, css_direction_t parentDirectio bool isUndefined(float value); #endif - + #ifdef CSS_LAYOUT_IMPLEMENTATION /** * Copyright (c) 2014, Facebook, Inc. @@ -545,18 +549,6 @@ static float getPaddingAndBorderAxis(css_node_t *node, css_flex_direction_t axis return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis); } -static css_position_type_t getPositionType(css_node_t *node) { - return node->style.position_type; -} - -static css_justify_t getJustifyContent(css_node_t *node) { - return node->style.justify_content; -} - -static css_align_t getAlignContent(css_node_t *node) { - return node->style.align_content; -} - static css_align_t getAlignItem(css_node_t *node, css_node_t *child) { if (child->style.align_self != CSS_ALIGN_AUTO) { return child->style.align_self; @@ -604,7 +596,7 @@ static float getFlex(css_node_t *node) { static bool isFlex(css_node_t *node) { return ( - getPositionType(node) == CSS_POSITION_RELATIVE && + node->style.position_type == CSS_POSITION_RELATIVE && getFlex(node) > 0 ); } @@ -722,23 +714,29 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction node->layout.position[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) + getRelativePosition(node, crossAxis); + // Inline immutable values from the target node to avoid excessive method + // invocations during the layout calculation. + int childCount = node->children_count; + float paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis); + if (isMeasureDefined(node)) { + bool isResolvedRowDimDefined = !isUndefined(node->layout.dimensions[dim[resolvedRowAxis]]); + float width = CSS_UNDEFINED; if (isDimDefined(node, resolvedRowAxis)) { width = node->style.dimensions[CSS_WIDTH]; - } else if (!isUndefined(node->layout.dimensions[dim[resolvedRowAxis]])) { + } else if (isResolvedRowDimDefined) { width = node->layout.dimensions[dim[resolvedRowAxis]]; } else { width = parentMaxWidth - getMarginAxis(node, resolvedRowAxis); } - width -= getPaddingAndBorderAxis(node, resolvedRowAxis); + width -= paddingAndBorderAxisResolvedRow; // We only need to give a dimension for the text if we haven't got any // for it computed yet. It can either be from the style attribute or because // the element is flexible. - bool isRowUndefined = !isDimDefined(node, resolvedRowAxis) && - isUndefined(node->layout.dimensions[dim[resolvedRowAxis]]); + bool isRowUndefined = !isDimDefined(node, resolvedRowAxis) && !isResolvedRowDimDefined; bool isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) && isUndefined(node->layout.dimensions[dim[CSS_FLEX_DIRECTION_COLUMN]]); @@ -751,66 +749,42 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction ); if (isRowUndefined) { node->layout.dimensions[CSS_WIDTH] = measureDim.dimensions[CSS_WIDTH] + - getPaddingAndBorderAxis(node, resolvedRowAxis); + paddingAndBorderAxisResolvedRow; } if (isColumnUndefined) { node->layout.dimensions[CSS_HEIGHT] = measureDim.dimensions[CSS_HEIGHT] + getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN); } } - if (node->children_count == 0) { + if (childCount == 0) { return; } } + bool isNodeFlexWrap = isFlexWrap(node); + + css_justify_t justifyContent = node->style.justify_content; + + float leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis); + float leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis); + float paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis); + float paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis); + + bool isMainDimDefined = !isUndefined(node->layout.dimensions[dim[mainAxis]]); + bool isCrossDimDefined = !isUndefined(node->layout.dimensions[dim[crossAxis]]); + bool isMainRowDirection = isRowDirection(mainAxis); + int i; int ii; css_node_t* child; css_flex_direction_t axis; - // Pre-fill some dimensions straight from the parent - for (i = 0; i < node->children_count; ++i) { - child = node->get_child(node->context, i); - // Pre-fill cross axis dimensions when the child is using stretch before - // we call the recursive layout pass - if (getAlignItem(node, child) == CSS_ALIGN_STRETCH && - getPositionType(child) == CSS_POSITION_RELATIVE && - !isUndefined(node->layout.dimensions[dim[crossAxis]]) && - !isDimDefined(child, crossAxis)) { - child->layout.dimensions[dim[crossAxis]] = fmaxf( - boundAxis(child, crossAxis, node->layout.dimensions[dim[crossAxis]] - - getPaddingAndBorderAxis(node, crossAxis) - - getMarginAxis(child, crossAxis)), - // You never want to go smaller than padding - getPaddingAndBorderAxis(child, crossAxis) - ); - } else if (getPositionType(child) == CSS_POSITION_ABSOLUTE) { - // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both - // left and right or top and bottom). - for (ii = 0; ii < 2; ii++) { - axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; - if (!isUndefined(node->layout.dimensions[dim[axis]]) && - !isDimDefined(child, axis) && - isPosDefined(child, leading[axis]) && - isPosDefined(child, trailing[axis])) { - child->layout.dimensions[dim[axis]] = fmaxf( - boundAxis(child, axis, node->layout.dimensions[dim[axis]] - - getPaddingAndBorderAxis(node, axis) - - getMarginAxis(child, axis) - - getPosition(child, leading[axis]) - - getPosition(child, trailing[axis])), - // You never want to go smaller than padding - getPaddingAndBorderAxis(child, axis) - ); - } - } - } - } + css_node_t* firstAbsoluteChild = NULL; + css_node_t* currentAbsoluteChild = NULL; float definedMainDim = CSS_UNDEFINED; - if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { - definedMainDim = node->layout.dimensions[dim[mainAxis]] - - getPaddingAndBorderAxis(node, mainAxis); + if (isMainDimDefined) { + definedMainDim = node->layout.dimensions[dim[mainAxis]] - paddingAndBorderAxisMain; } // We want to execute the next two loops one per line with flex-wrap @@ -822,7 +796,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction float linesCrossDim = 0; float linesMainDim = 0; int linesCount = 0; - while (endLine < node->children_count) { + while (endLine < childCount) { // Layout non flexible children and count children by type // mainContentDim is accumulation of the dimensions and margin of all the @@ -837,16 +811,99 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction float totalFlexible = 0; int nonFlexibleChildrenCount = 0; + // Use the line loop to position children in the main axis for as long + // as they are using a simple stacking behaviour. Children that are + // immediately stacked in the initial loop will not be touched again + // in . + bool isSimpleStackMain = + (isMainDimDefined && justifyContent == CSS_JUSTIFY_FLEX_START) || + (!isMainDimDefined && justifyContent != CSS_JUSTIFY_CENTER); + int firstComplexMain = (isSimpleStackMain ? childCount : startLine); + + // Use the initial line loop to position children in the cross axis for + // as long as they are relatively positioned with alignment STRETCH or + // FLEX_START. Children that are immediately stacked in the initial loop + // will not be touched again in . + bool isSimpleStackCross = true; + int firstComplexCross = childCount; + + css_node_t* firstFlexChild = NULL; + css_node_t* currentFlexChild = NULL; + + float mainDim = leadingPaddingAndBorderMain; + float crossDim = 0; + float maxWidth; - for (i = startLine; i < node->children_count; ++i) { + for (i = startLine; i < childCount; ++i) { child = node->get_child(node->context, i); + child->line_index = linesCount; + + child->next_absolute_child = NULL; + child->next_flex_child = NULL; + + css_align_t alignItem = getAlignItem(node, child); + + // Pre-fill cross axis dimensions when the child is using stretch before + // we call the recursive layout pass + if (alignItem == CSS_ALIGN_STRETCH && + child->style.position_type == CSS_POSITION_RELATIVE && + isCrossDimDefined && + !isDimDefined(child, crossAxis)) { + child->layout.dimensions[dim[crossAxis]] = fmaxf( + boundAxis(child, crossAxis, node->layout.dimensions[dim[crossAxis]] - + paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, crossAxis) + ); + } else if (child->style.position_type == CSS_POSITION_ABSOLUTE) { + // Store a private linked list of absolutely positioned children + // so that we can efficiently traverse them later. + if (firstAbsoluteChild == NULL) { + firstAbsoluteChild = child; + } + if (currentAbsoluteChild != NULL) { + currentAbsoluteChild->next_absolute_child = child; + } + currentAbsoluteChild = child; + + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (!isUndefined(node->layout.dimensions[dim[axis]]) && + !isDimDefined(child, axis) && + isPosDefined(child, leading[axis]) && + isPosDefined(child, trailing[axis])) { + child->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(child, axis, node->layout.dimensions[dim[axis]] - + getPaddingAndBorderAxis(node, axis) - + getMarginAxis(child, axis) - + getPosition(child, leading[axis]) - + getPosition(child, trailing[axis])), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, axis) + ); + } + } + } + float nextContentDim = 0; // It only makes sense to consider a child flexible if we have a computed // dimension for the node-> - if (!isUndefined(node->layout.dimensions[dim[mainAxis]]) && isFlex(child)) { + if (isMainDimDefined && isFlex(child)) { flexibleChildrenCount++; - totalFlexible += getFlex(child); + totalFlexible += child->style.flex; + + // Store a private linked list of flexible children so that we can + // efficiently traverse them later. + if (firstFlexChild == NULL) { + firstFlexChild = child; + } + if (currentFlexChild != NULL) { + currentFlexChild->next_flex_child = child; + } + currentFlexChild = child; // Even if we don't know its exact size yet, we already know the padding, // border and margin. We'll use this partial information, which represents @@ -857,14 +914,14 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction } else { maxWidth = CSS_UNDEFINED; - if (!isRowDirection(mainAxis)) { - maxWidth = parentMaxWidth - - getMarginAxis(node, resolvedRowAxis) - - getPaddingAndBorderAxis(node, resolvedRowAxis); - + if (!isMainRowDirection) { if (isDimDefined(node, resolvedRowAxis)) { maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - - getPaddingAndBorderAxis(node, resolvedRowAxis); + paddingAndBorderAxisResolvedRow; + } else { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + paddingAndBorderAxisResolvedRow; } } @@ -875,7 +932,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction // Absolute positioned elements do not take part of the layout, so we // don't use them to compute mainContentDim - if (getPositionType(child) == CSS_POSITION_RELATIVE) { + if (child->style.position_type == CSS_POSITION_RELATIVE) { nonFlexibleChildrenCount++; // At this point we know the final size and margin of the element. nextContentDim = getDimWithMargin(child, mainAxis); @@ -883,8 +940,8 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction } // The element we are about to add would make us go to the next line - if (isFlexWrap(node) && - !isUndefined(node->layout.dimensions[dim[mainAxis]]) && + if (isNodeFlexWrap && + isMainDimDefined && mainContentDim + nextContentDim > definedMainDim && // If there's only one element, then it's bigger than the content // and needs its own line @@ -893,6 +950,44 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction alreadyComputedNextLayout = 1; break; } + + // Disable simple stacking in the main axis for the current line as + // we found a non-trivial child-> The remaining children will be laid out + // in . + if (isSimpleStackMain && + (child->style.position_type != CSS_POSITION_RELATIVE || isFlex(child))) { + isSimpleStackMain = false; + firstComplexMain = i; + } + + // Disable simple stacking in the cross axis for the current line as + // we found a non-trivial child-> The remaining children will be laid out + // in . + if (isSimpleStackCross && + (child->style.position_type != CSS_POSITION_RELATIVE || + (alignItem != CSS_ALIGN_STRETCH && alignItem != CSS_ALIGN_FLEX_START) || + isUndefined(child->layout.dimensions[dim[crossAxis]]))) { + isSimpleStackCross = false; + firstComplexCross = i; + } + + if (isSimpleStackMain) { + child->layout.position[pos[mainAxis]] += mainDim; + if (isMainDimDefined) { + setTrailingPosition(node, child, mainAxis); + } + + mainDim += getDimWithMargin(child, mainAxis); + crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + } + + if (isSimpleStackCross) { + child->layout.position[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross; + if (isCrossDimDefined) { + setTrailingPosition(node, child, crossAxis); + } + } + alreadyComputedNextLayout = 0; mainContentDim += nextContentDim; endLine = i + 1; @@ -908,7 +1003,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction // The remaining available space that needs to be allocated float remainingMainDim = 0; - if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + if (isMainDimDefined) { remainingMainDim = definedMainDim - mainContentDim; } else { remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim; @@ -921,21 +1016,20 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction float baseMainDim; float boundMainDim; - // Iterate over every child in the axis. If the flex share of remaining - // space doesn't meet min/max bounds, remove this child from flex - // calculations. - for (i = startLine; i < endLine; ++i) { - child = node->get_child(node->context, i); - if (isFlex(child)) { - baseMainDim = flexibleMainDim * getFlex(child) + - getPaddingAndBorderAxis(child, mainAxis); - boundMainDim = boundAxis(child, mainAxis, baseMainDim); + // If the flex share of remaining space doesn't meet min/max bounds, + // remove this child from flex calculations. + currentFlexChild = firstFlexChild; + while (currentFlexChild != NULL) { + baseMainDim = flexibleMainDim * currentFlexChild->style.flex + + getPaddingAndBorderAxis(currentFlexChild, mainAxis); + boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim); - if (baseMainDim != boundMainDim) { - remainingMainDim -= boundMainDim; - totalFlexible -= getFlex(child); - } + if (baseMainDim != boundMainDim) { + remainingMainDim -= boundMainDim; + totalFlexible -= currentFlexChild->style.flex; } + + currentFlexChild = currentFlexChild->next_flex_child; } flexibleMainDim = remainingMainDim / totalFlexible; @@ -944,37 +1038,37 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction if (flexibleMainDim < 0) { flexibleMainDim = 0; } - // We iterate over the full array and only apply the action on flexible - // children. This is faster than actually allocating a new array that - // contains only flexible children. - for (i = startLine; i < endLine; ++i) { - child = node->get_child(node->context, i); - if (isFlex(child)) { - // At this point we know the final size of the element in the main - // dimension - child->layout.dimensions[dim[mainAxis]] = boundAxis(child, mainAxis, - flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis) - ); - maxWidth = CSS_UNDEFINED; - if (isDimDefined(node, resolvedRowAxis)) { - maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - - getPaddingAndBorderAxis(node, resolvedRowAxis); - } else if (!isRowDirection(mainAxis)) { - maxWidth = parentMaxWidth - - getMarginAxis(node, resolvedRowAxis) - - getPaddingAndBorderAxis(node, resolvedRowAxis); - } + currentFlexChild = firstFlexChild; + while (currentFlexChild != NULL) { + // At this point we know the final size of the element in the main + // dimension + currentFlexChild->layout.dimensions[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis, + flexibleMainDim * currentFlexChild->style.flex + + getPaddingAndBorderAxis(currentFlexChild, mainAxis) + ); - // And we recursively call the layout algorithm for this child - layoutNode(child, maxWidth, direction); + maxWidth = CSS_UNDEFINED; + if (isDimDefined(node, resolvedRowAxis)) { + maxWidth = node->layout.dimensions[dim[resolvedRowAxis]] - + paddingAndBorderAxisResolvedRow; + } else if (!isMainRowDirection) { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + paddingAndBorderAxisResolvedRow; } + + // And we recursively call the layout algorithm for this child + layoutNode(currentFlexChild, maxWidth, direction); + + child = currentFlexChild; + currentFlexChild = currentFlexChild->next_flex_child; + child->next_flex_child = NULL; } // We use justifyContent to figure out how to allocate the remaining // space available - } else { - css_justify_t justifyContent = getJustifyContent(node); + } else if (justifyContent != CSS_JUSTIFY_FLEX_START) { if (justifyContent == CSS_JUSTIFY_CENTER) { leadingMainDim = remainingMainDim / 2; } else if (justifyContent == CSS_JUSTIFY_FLEX_END) { @@ -1001,15 +1095,12 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction // find their position. In order to do that, we accumulate data in // variables that are also useful to compute the total dimensions of the // container! - float crossDim = 0; - float mainDim = leadingMainDim + - getLeadingPaddingAndBorder(node, mainAxis); + mainDim += leadingMainDim; - for (i = startLine; i < endLine; ++i) { + for (i = firstComplexMain; i < endLine; ++i) { child = node->get_child(node->context, i); - child->line_index = linesCount; - if (getPositionType(child) == CSS_POSITION_ABSOLUTE && + if (child->style.position_type == CSS_POSITION_ABSOLUTE && isPosDefined(child, leading[mainAxis])) { // In case the child is position absolute and has left/top being // defined, we override the position to whatever the user said @@ -1023,40 +1114,40 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction child->layout.position[pos[mainAxis]] += mainDim; // Define the trailing position accordingly. - if (!isUndefined(node->layout.dimensions[dim[mainAxis]])) { + if (isMainDimDefined) { setTrailingPosition(node, child, mainAxis); } - } - // Now that we placed the element, we need to update the variables - // We only need to do that for relative elements. Absolute elements - // do not take part in that phase. - if (getPositionType(child) == CSS_POSITION_RELATIVE) { - // The main dimension is the sum of all the elements dimension plus - // the spacing. - mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); - // The cross dimension is the max of the elements dimension since there - // can only be one element in that cross dimension. - crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + // Now that we placed the element, we need to update the variables + // We only need to do that for relative elements. Absolute elements + // do not take part in that phase. + if (child->style.position_type == CSS_POSITION_RELATIVE) { + // The main dimension is the sum of all the elements dimension plus + // the spacing. + mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); + // The cross dimension is the max of the elements dimension since there + // can only be one element in that cross dimension. + crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + } } } float containerCrossAxis = node->layout.dimensions[dim[crossAxis]]; - if (isUndefined(node->layout.dimensions[dim[crossAxis]])) { + if (!isCrossDimDefined) { containerCrossAxis = fmaxf( // For the cross dim, we add both sides at the end because the value // is aggregate via a max function. Intermediate negative values // can mess this computation otherwise - boundAxis(node, crossAxis, crossDim + getPaddingAndBorderAxis(node, crossAxis)), - getPaddingAndBorderAxis(node, crossAxis) + boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross), + paddingAndBorderAxisCross ); } // Position elements in the cross axis - for (i = startLine; i < endLine; ++i) { + for (i = firstComplexCross; i < endLine; ++i) { child = node->get_child(node->context, i); - if (getPositionType(child) == CSS_POSITION_ABSOLUTE && + if (child->style.position_type == CSS_POSITION_ABSOLUTE && isPosDefined(child, leading[crossAxis])) { // In case the child is absolutely positionned and has a // top/left/bottom/right being set, we override all the previously @@ -1066,20 +1157,19 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction getLeadingMargin(child, crossAxis); } else { - float leadingCrossDim = getLeadingPaddingAndBorder(node, crossAxis); + float leadingCrossDim = leadingPaddingAndBorderCross; // For a relative children, we're either using alignItems (parent) or // alignSelf (child) in order to determine the position in the cross axis - if (getPositionType(child) == CSS_POSITION_RELATIVE) { + if (child->style.position_type == CSS_POSITION_RELATIVE) { css_align_t alignItem = getAlignItem(node, child); if (alignItem == CSS_ALIGN_STRETCH) { // You can only stretch if the dimension has not already been set // previously. - if (!isDimDefined(child, crossAxis)) { + if (isUndefined(child->layout.dimensions[dim[crossAxis]])) { child->layout.dimensions[dim[crossAxis]] = fmaxf( boundAxis(child, crossAxis, containerCrossAxis - - getPaddingAndBorderAxis(node, crossAxis) - - getMarginAxis(child, crossAxis)), + paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)), // You never want to go smaller than padding getPaddingAndBorderAxis(child, crossAxis) ); @@ -1088,8 +1178,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction // The remaining space between the parent dimensions+padding and child // dimensions+margin. float remainingCrossDim = containerCrossAxis - - getPaddingAndBorderAxis(node, crossAxis) - - getDimWithMargin(child, crossAxis); + paddingAndBorderAxisCross - getDimWithMargin(child, crossAxis); if (alignItem == CSS_ALIGN_CENTER) { leadingCrossDim += remainingCrossDim / 2; @@ -1103,7 +1192,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction child->layout.position[pos[crossAxis]] += linesCrossDim + leadingCrossDim; // Define the trailing position accordingly. - if (!isUndefined(node->layout.dimensions[dim[crossAxis]])) { + if (isCrossDimDefined) { setTrailingPosition(node, child, crossAxis); } } @@ -1128,16 +1217,15 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm // section 9.4 // - if (linesCount > 1 && - !isUndefined(node->layout.dimensions[dim[crossAxis]])) { + if (linesCount > 1 && isCrossDimDefined) { float nodeCrossAxisInnerSize = node->layout.dimensions[dim[crossAxis]] - - getPaddingAndBorderAxis(node, crossAxis); + paddingAndBorderAxisCross; float remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim; float crossDimLead = 0; - float currentLead = getLeadingPaddingAndBorder(node, crossAxis); + float currentLead = leadingPaddingAndBorderCross; - css_align_t alignContent = getAlignContent(node); + css_align_t alignContent = node->style.align_content; if (alignContent == CSS_ALIGN_FLEX_END) { currentLead += remainingAlignContentDim; } else if (alignContent == CSS_ALIGN_CENTER) { @@ -1154,9 +1242,9 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction // compute the line's height and find the endIndex float lineHeight = 0; - for (ii = startIndex; ii < node->children_count; ++ii) { + for (ii = startIndex; ii < childCount; ++ii) { child = node->get_child(node->context, ii); - if (getPositionType(child) != CSS_POSITION_RELATIVE) { + if (child->style.position_type != CSS_POSITION_RELATIVE) { continue; } if (child->line_index != i) { @@ -1174,7 +1262,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction for (ii = startIndex; ii < endIndex; ++ii) { child = node->get_child(node->context, ii); - if (getPositionType(child) != CSS_POSITION_RELATIVE) { + if (child->style.position_type != CSS_POSITION_RELATIVE) { continue; } @@ -1202,33 +1290,39 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction // If the user didn't specify a width or height, and it has not been set // by the container, then we set it via the children. - if (isUndefined(node->layout.dimensions[dim[mainAxis]])) { + if (!isMainDimDefined) { node->layout.dimensions[dim[mainAxis]] = fmaxf( // We're missing the last padding at this point to get the final // dimension boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)), // We can never assign a width smaller than the padding and borders - getPaddingAndBorderAxis(node, mainAxis) + paddingAndBorderAxisMain ); - needsMainTrailingPos = true; + if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || + mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + needsMainTrailingPos = true; + } } - if (isUndefined(node->layout.dimensions[dim[crossAxis]])) { + if (!isCrossDimDefined) { node->layout.dimensions[dim[crossAxis]] = fmaxf( // For the cross dim, we add both sides at the end because the value // is aggregate via a max function. Intermediate negative values // can mess this computation otherwise - boundAxis(node, crossAxis, linesCrossDim + getPaddingAndBorderAxis(node, crossAxis)), - getPaddingAndBorderAxis(node, crossAxis) + boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross), + paddingAndBorderAxisCross ); - needsCrossTrailingPos = true; + if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || + crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + needsCrossTrailingPos = true; + } } // Set trailing position if necessary if (needsMainTrailingPos || needsCrossTrailingPos) { - for (i = 0; i < node->children_count; ++i) { + for (i = 0; i < childCount; ++i) { child = node->get_child(node->context, i); if (needsMainTrailingPos) { @@ -1242,40 +1336,41 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction } // Calculate dimensions for absolutely positioned elements - for (i = 0; i < node->children_count; ++i) { - child = node->get_child(node->context, i); - if (getPositionType(child) == CSS_POSITION_ABSOLUTE) { - // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both - // left and right or top and bottom). - for (ii = 0; ii < 2; ii++) { - axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; - if (!isUndefined(node->layout.dimensions[dim[axis]]) && - !isDimDefined(child, axis) && - isPosDefined(child, leading[axis]) && - isPosDefined(child, trailing[axis])) { - child->layout.dimensions[dim[axis]] = fmaxf( - boundAxis(child, axis, node->layout.dimensions[dim[axis]] - - getBorderAxis(node, axis) - - getMarginAxis(child, axis) - - getPosition(child, leading[axis]) - - getPosition(child, trailing[axis]) - ), - // You never want to go smaller than padding - getPaddingAndBorderAxis(child, axis) - ); - } + currentAbsoluteChild = firstAbsoluteChild; + while (currentAbsoluteChild != NULL) { + // Pre-fill dimensions when using absolute position and both offsets for + // the axis are defined (either both left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + + if (!isUndefined(node->layout.dimensions[dim[axis]]) && + !isDimDefined(currentAbsoluteChild, axis) && + isPosDefined(currentAbsoluteChild, leading[axis]) && + isPosDefined(currentAbsoluteChild, trailing[axis])) { + currentAbsoluteChild->layout.dimensions[dim[axis]] = fmaxf( + boundAxis(currentAbsoluteChild, axis, node->layout.dimensions[dim[axis]] - + getBorderAxis(node, axis) - + getMarginAxis(currentAbsoluteChild, axis) - + getPosition(currentAbsoluteChild, leading[axis]) - + getPosition(currentAbsoluteChild, trailing[axis]) + ), + // You never want to go smaller than padding + getPaddingAndBorderAxis(currentAbsoluteChild, axis) + ); } - for (ii = 0; ii < 2; ii++) { - axis = (ii != 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; - if (isPosDefined(child, trailing[axis]) && - !isPosDefined(child, leading[axis])) { - child->layout.position[leading[axis]] = - node->layout.dimensions[dim[axis]] - - child->layout.dimensions[dim[axis]] - - getPosition(child, trailing[axis]); - } + + if (isPosDefined(currentAbsoluteChild, trailing[axis]) && + !isPosDefined(currentAbsoluteChild, leading[axis])) { + currentAbsoluteChild->layout.position[leading[axis]] = + node->layout.dimensions[dim[axis]] - + currentAbsoluteChild->layout.dimensions[dim[axis]] - + getPosition(currentAbsoluteChild, trailing[axis]); } } + + child = currentAbsoluteChild; + currentAbsoluteChild = currentAbsoluteChild->next_absolute_child; + child->next_absolute_child = NULL; } /** END_GENERATED **/ } diff --git a/dist/css-layout.jar b/dist/css-layout.jar index a6e88d0b..79c83dd6 100644 Binary files a/dist/css-layout.jar and b/dist/css-layout.jar differ diff --git a/dist/css-layout.js b/dist/css-layout.js index 3db6a3ac..97de476b 100644 --- a/dist/css-layout.js +++ b/dist/css-layout.js @@ -39,7 +39,7 @@ var computeLayout = (function() { var CSS_FLEX_DIRECTION_COLUMN = 'column'; var CSS_FLEX_DIRECTION_COLUMN_REVERSE = 'column-reverse'; - // var CSS_JUSTIFY_FLEX_START = 'flex-start'; + var CSS_JUSTIFY_FLEX_START = 'flex-start'; var CSS_JUSTIFY_CENTER = 'center'; var CSS_JUSTIFY_FLEX_END = 'flex-end'; var CSS_JUSTIFY_SPACE_BETWEEN = 'space-between'; @@ -306,14 +306,10 @@ var computeLayout = (function() { return 'relative'; } - function getFlex(node) { - return node.style.flex; - } - function isFlex(node) { return ( getPositionType(node) === CSS_POSITION_RELATIVE && - getFlex(node) > 0 + node.style.flex > 0 ); } @@ -410,9 +406,9 @@ var computeLayout = (function() { function layoutNode(node, parentMaxWidth, /*css_direction_t*/parentDirection) { var/*css_direction_t*/ direction = resolveDirection(node, parentDirection); - var/*css_flex_direction_t*/ mainAxis = resolveAxis(getFlexDirection(node), direction); - var/*css_flex_direction_t*/ crossAxis = getCrossFlexDirection(mainAxis, direction); - var/*css_flex_direction_t*/ resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); + var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction); + var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction); + var/*(c)!css_flex_direction_t*//*(java)!int*/ resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); // Handle width and height style attributes setDimensionFromStyle(node, mainAxis); @@ -432,23 +428,29 @@ var computeLayout = (function() { node.layout[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) + getRelativePosition(node, crossAxis); + // Inline immutable values from the target node to avoid excessive method + // invocations during the layout calculation. + var/*int*/ childCount = node.children.length; + var/*float*/ paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis); + if (isMeasureDefined(node)) { + var/*bool*/ isResolvedRowDimDefined = !isUndefined(node.layout[dim[resolvedRowAxis]]); + var/*float*/ width = CSS_UNDEFINED; if (isDimDefined(node, resolvedRowAxis)) { width = node.style.width; - } else if (!isUndefined(node.layout[dim[resolvedRowAxis]])) { + } else if (isResolvedRowDimDefined) { width = node.layout[dim[resolvedRowAxis]]; } else { width = parentMaxWidth - getMarginAxis(node, resolvedRowAxis); } - width -= getPaddingAndBorderAxis(node, resolvedRowAxis); + width -= paddingAndBorderAxisResolvedRow; // We only need to give a dimension for the text if we haven't got any // for it computed yet. It can either be from the style attribute or because // the element is flexible. - var/*bool*/ isRowUndefined = !isDimDefined(node, resolvedRowAxis) && - isUndefined(node.layout[dim[resolvedRowAxis]]); + var/*bool*/ isRowUndefined = !isDimDefined(node, resolvedRowAxis) && !isResolvedRowDimDefined; var/*bool*/ isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) && isUndefined(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]]); @@ -461,66 +463,42 @@ var computeLayout = (function() { ); if (isRowUndefined) { node.layout.width = measureDim.width + - getPaddingAndBorderAxis(node, resolvedRowAxis); + paddingAndBorderAxisResolvedRow; } if (isColumnUndefined) { node.layout.height = measureDim.height + getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN); } } - if (node.children.length === 0) { + if (childCount === 0) { return; } } + var/*bool*/ isNodeFlexWrap = isFlexWrap(node); + + var/*css_justify_t*/ justifyContent = getJustifyContent(node); + + var/*float*/ leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis); + var/*float*/ leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis); + var/*float*/ paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis); + var/*float*/ paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis); + + var/*bool*/ isMainDimDefined = !isUndefined(node.layout[dim[mainAxis]]); + var/*bool*/ isCrossDimDefined = !isUndefined(node.layout[dim[crossAxis]]); + var/*bool*/ isMainRowDirection = isRowDirection(mainAxis); + var/*int*/ i; var/*int*/ ii; var/*css_node_t**/ child; - var/*css_flex_direction_t*/ axis; + var/*(c)!css_flex_direction_t*//*(java)!int*/ axis; - // Pre-fill some dimensions straight from the parent - for (i = 0; i < node.children.length; ++i) { - child = node.children[i]; - // Pre-fill cross axis dimensions when the child is using stretch before - // we call the recursive layout pass - if (getAlignItem(node, child) === CSS_ALIGN_STRETCH && - getPositionType(child) === CSS_POSITION_RELATIVE && - !isUndefined(node.layout[dim[crossAxis]]) && - !isDimDefined(child, crossAxis)) { - child.layout[dim[crossAxis]] = fmaxf( - boundAxis(child, crossAxis, node.layout[dim[crossAxis]] - - getPaddingAndBorderAxis(node, crossAxis) - - getMarginAxis(child, crossAxis)), - // You never want to go smaller than padding - getPaddingAndBorderAxis(child, crossAxis) - ); - } else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) { - // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both - // left and right or top and bottom). - for (ii = 0; ii < 2; ii++) { - axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; - if (!isUndefined(node.layout[dim[axis]]) && - !isDimDefined(child, axis) && - isPosDefined(child, leading[axis]) && - isPosDefined(child, trailing[axis])) { - child.layout[dim[axis]] = fmaxf( - boundAxis(child, axis, node.layout[dim[axis]] - - getPaddingAndBorderAxis(node, axis) - - getMarginAxis(child, axis) - - getPosition(child, leading[axis]) - - getPosition(child, trailing[axis])), - // You never want to go smaller than padding - getPaddingAndBorderAxis(child, axis) - ); - } - } - } - } + var/*css_node_t**/ firstAbsoluteChild = null; + var/*css_node_t**/ currentAbsoluteChild = null; var/*float*/ definedMainDim = CSS_UNDEFINED; - if (!isUndefined(node.layout[dim[mainAxis]])) { - definedMainDim = node.layout[dim[mainAxis]] - - getPaddingAndBorderAxis(node, mainAxis); + if (isMainDimDefined) { + definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain; } // We want to execute the next two loops one per line with flex-wrap @@ -532,7 +510,7 @@ var computeLayout = (function() { var/*float*/ linesCrossDim = 0; var/*float*/ linesMainDim = 0; var/*int*/ linesCount = 0; - while (endLine < node.children.length) { + while (endLine < childCount) { // Layout non flexible children and count children by type // mainContentDim is accumulation of the dimensions and margin of all the @@ -547,16 +525,99 @@ var computeLayout = (function() { var/*float*/ totalFlexible = 0; var/*int*/ nonFlexibleChildrenCount = 0; + // Use the line loop to position children in the main axis for as long + // as they are using a simple stacking behaviour. Children that are + // immediately stacked in the initial loop will not be touched again + // in . + var/*bool*/ isSimpleStackMain = + (isMainDimDefined && justifyContent == CSS_JUSTIFY_FLEX_START) || + (!isMainDimDefined && justifyContent != CSS_JUSTIFY_CENTER); + var/*int*/ firstComplexMain = (isSimpleStackMain ? childCount : startLine); + + // Use the initial line loop to position children in the cross axis for + // as long as they are relatively positioned with alignment STRETCH or + // FLEX_START. Children that are immediately stacked in the initial loop + // will not be touched again in . + var/*bool*/ isSimpleStackCross = true; + var/*int*/ firstComplexCross = childCount; + + var/*css_node_t**/ firstFlexChild = null; + var/*css_node_t**/ currentFlexChild = null; + + var/*float*/ mainDim = leadingPaddingAndBorderMain; + var/*float*/ crossDim = 0; + var/*float*/ maxWidth; - for (i = startLine; i < node.children.length; ++i) { + for (i = startLine; i < childCount; ++i) { child = node.children[i]; + child.lineIndex = linesCount; + + child.nextAbsoluteChild = null; + child.nextFlexChild = null; + + var/*css_align_t*/ alignItem = getAlignItem(node, child); + + // Pre-fill cross axis dimensions when the child is using stretch before + // we call the recursive layout pass + if (alignItem === CSS_ALIGN_STRETCH && + getPositionType(child) === CSS_POSITION_RELATIVE && + isCrossDimDefined && + !isDimDefined(child, crossAxis)) { + child.layout[dim[crossAxis]] = fmaxf( + boundAxis(child, crossAxis, node.layout[dim[crossAxis]] - + paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, crossAxis) + ); + } else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) { + // Store a private linked list of absolutely positioned children + // so that we can efficiently traverse them later. + if (firstAbsoluteChild === null) { + firstAbsoluteChild = child; + } + if (currentAbsoluteChild !== null) { + currentAbsoluteChild.nextAbsoluteChild = child; + } + currentAbsoluteChild = child; + + // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both + // left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + if (!isUndefined(node.layout[dim[axis]]) && + !isDimDefined(child, axis) && + isPosDefined(child, leading[axis]) && + isPosDefined(child, trailing[axis])) { + child.layout[dim[axis]] = fmaxf( + boundAxis(child, axis, node.layout[dim[axis]] - + getPaddingAndBorderAxis(node, axis) - + getMarginAxis(child, axis) - + getPosition(child, leading[axis]) - + getPosition(child, trailing[axis])), + // You never want to go smaller than padding + getPaddingAndBorderAxis(child, axis) + ); + } + } + } + var/*float*/ nextContentDim = 0; // It only makes sense to consider a child flexible if we have a computed // dimension for the node. - if (!isUndefined(node.layout[dim[mainAxis]]) && isFlex(child)) { + if (isMainDimDefined && isFlex(child)) { flexibleChildrenCount++; - totalFlexible += getFlex(child); + totalFlexible += child.style.flex; + + // Store a private linked list of flexible children so that we can + // efficiently traverse them later. + if (firstFlexChild === null) { + firstFlexChild = child; + } + if (currentFlexChild !== null) { + currentFlexChild.nextFlexChild = child; + } + currentFlexChild = child; // Even if we don't know its exact size yet, we already know the padding, // border and margin. We'll use this partial information, which represents @@ -567,14 +628,14 @@ var computeLayout = (function() { } else { maxWidth = CSS_UNDEFINED; - if (!isRowDirection(mainAxis)) { - maxWidth = parentMaxWidth - - getMarginAxis(node, resolvedRowAxis) - - getPaddingAndBorderAxis(node, resolvedRowAxis); - + if (!isMainRowDirection) { if (isDimDefined(node, resolvedRowAxis)) { maxWidth = node.layout[dim[resolvedRowAxis]] - - getPaddingAndBorderAxis(node, resolvedRowAxis); + paddingAndBorderAxisResolvedRow; + } else { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + paddingAndBorderAxisResolvedRow; } } @@ -593,8 +654,8 @@ var computeLayout = (function() { } // The element we are about to add would make us go to the next line - if (isFlexWrap(node) && - !isUndefined(node.layout[dim[mainAxis]]) && + if (isNodeFlexWrap && + isMainDimDefined && mainContentDim + nextContentDim > definedMainDim && // If there's only one element, then it's bigger than the content // and needs its own line @@ -603,6 +664,44 @@ var computeLayout = (function() { alreadyComputedNextLayout = 1; break; } + + // Disable simple stacking in the main axis for the current line as + // we found a non-trivial child. The remaining children will be laid out + // in . + if (isSimpleStackMain && + (getPositionType(child) != CSS_POSITION_RELATIVE || isFlex(child))) { + isSimpleStackMain = false; + firstComplexMain = i; + } + + // Disable simple stacking in the cross axis for the current line as + // we found a non-trivial child. The remaining children will be laid out + // in . + if (isSimpleStackCross && + (getPositionType(child) != CSS_POSITION_RELATIVE || + (alignItem !== CSS_ALIGN_STRETCH && alignItem != CSS_ALIGN_FLEX_START) || + isUndefined(child.layout[dim[crossAxis]]))) { + isSimpleStackCross = false; + firstComplexCross = i; + } + + if (isSimpleStackMain) { + child.layout[pos[mainAxis]] += mainDim; + if (isMainDimDefined) { + setTrailingPosition(node, child, mainAxis); + } + + mainDim += getDimWithMargin(child, mainAxis); + crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + } + + if (isSimpleStackCross) { + child.layout[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross; + if (isCrossDimDefined) { + setTrailingPosition(node, child, crossAxis); + } + } + alreadyComputedNextLayout = 0; mainContentDim += nextContentDim; endLine = i + 1; @@ -618,7 +717,7 @@ var computeLayout = (function() { // The remaining available space that needs to be allocated var/*float*/ remainingMainDim = 0; - if (!isUndefined(node.layout[dim[mainAxis]])) { + if (isMainDimDefined) { remainingMainDim = definedMainDim - mainContentDim; } else { remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim; @@ -631,21 +730,20 @@ var computeLayout = (function() { var/*float*/ baseMainDim; var/*float*/ boundMainDim; - // Iterate over every child in the axis. If the flex share of remaining - // space doesn't meet min/max bounds, remove this child from flex - // calculations. - for (i = startLine; i < endLine; ++i) { - child = node.children[i]; - if (isFlex(child)) { - baseMainDim = flexibleMainDim * getFlex(child) + - getPaddingAndBorderAxis(child, mainAxis); - boundMainDim = boundAxis(child, mainAxis, baseMainDim); + // If the flex share of remaining space doesn't meet min/max bounds, + // remove this child from flex calculations. + currentFlexChild = firstFlexChild; + while (currentFlexChild !== null) { + baseMainDim = flexibleMainDim * currentFlexChild.style.flex + + getPaddingAndBorderAxis(currentFlexChild, mainAxis); + boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim); - if (baseMainDim !== boundMainDim) { - remainingMainDim -= boundMainDim; - totalFlexible -= getFlex(child); - } + if (baseMainDim !== boundMainDim) { + remainingMainDim -= boundMainDim; + totalFlexible -= currentFlexChild.style.flex; } + + currentFlexChild = currentFlexChild.nextFlexChild; } flexibleMainDim = remainingMainDim / totalFlexible; @@ -654,37 +752,37 @@ var computeLayout = (function() { if (flexibleMainDim < 0) { flexibleMainDim = 0; } - // We iterate over the full array and only apply the action on flexible - // children. This is faster than actually allocating a new array that - // contains only flexible children. - for (i = startLine; i < endLine; ++i) { - child = node.children[i]; - if (isFlex(child)) { - // At this point we know the final size of the element in the main - // dimension - child.layout[dim[mainAxis]] = boundAxis(child, mainAxis, - flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis) - ); - maxWidth = CSS_UNDEFINED; - if (isDimDefined(node, resolvedRowAxis)) { - maxWidth = node.layout[dim[resolvedRowAxis]] - - getPaddingAndBorderAxis(node, resolvedRowAxis); - } else if (!isRowDirection(mainAxis)) { - maxWidth = parentMaxWidth - - getMarginAxis(node, resolvedRowAxis) - - getPaddingAndBorderAxis(node, resolvedRowAxis); - } + currentFlexChild = firstFlexChild; + while (currentFlexChild !== null) { + // At this point we know the final size of the element in the main + // dimension + currentFlexChild.layout[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis, + flexibleMainDim * currentFlexChild.style.flex + + getPaddingAndBorderAxis(currentFlexChild, mainAxis) + ); - // And we recursively call the layout algorithm for this child - layoutNode(/*(java)!layoutContext, */child, maxWidth, direction); + maxWidth = CSS_UNDEFINED; + if (isDimDefined(node, resolvedRowAxis)) { + maxWidth = node.layout[dim[resolvedRowAxis]] - + paddingAndBorderAxisResolvedRow; + } else if (!isMainRowDirection) { + maxWidth = parentMaxWidth - + getMarginAxis(node, resolvedRowAxis) - + paddingAndBorderAxisResolvedRow; } + + // And we recursively call the layout algorithm for this child + layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, direction); + + child = currentFlexChild; + currentFlexChild = currentFlexChild.nextFlexChild; + child.nextFlexChild = null; } // We use justifyContent to figure out how to allocate the remaining // space available - } else { - var/*css_justify_t*/ justifyContent = getJustifyContent(node); + } else if (justifyContent !== CSS_JUSTIFY_FLEX_START) { if (justifyContent === CSS_JUSTIFY_CENTER) { leadingMainDim = remainingMainDim / 2; } else if (justifyContent === CSS_JUSTIFY_FLEX_END) { @@ -711,13 +809,10 @@ var computeLayout = (function() { // find their position. In order to do that, we accumulate data in // variables that are also useful to compute the total dimensions of the // container! - var/*float*/ crossDim = 0; - var/*float*/ mainDim = leadingMainDim + - getLeadingPaddingAndBorder(node, mainAxis); + mainDim += leadingMainDim; - for (i = startLine; i < endLine; ++i) { + for (i = firstComplexMain; i < endLine; ++i) { child = node.children[i]; - child.lineIndex = linesCount; if (getPositionType(child) === CSS_POSITION_ABSOLUTE && isPosDefined(child, leading[mainAxis])) { @@ -733,37 +828,37 @@ var computeLayout = (function() { child.layout[pos[mainAxis]] += mainDim; // Define the trailing position accordingly. - if (!isUndefined(node.layout[dim[mainAxis]])) { + if (isMainDimDefined) { setTrailingPosition(node, child, mainAxis); } - } - // Now that we placed the element, we need to update the variables - // We only need to do that for relative elements. Absolute elements - // do not take part in that phase. - if (getPositionType(child) === CSS_POSITION_RELATIVE) { - // The main dimension is the sum of all the elements dimension plus - // the spacing. - mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); - // The cross dimension is the max of the elements dimension since there - // can only be one element in that cross dimension. - crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + // Now that we placed the element, we need to update the variables + // We only need to do that for relative elements. Absolute elements + // do not take part in that phase. + if (getPositionType(child) === CSS_POSITION_RELATIVE) { + // The main dimension is the sum of all the elements dimension plus + // the spacing. + mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); + // The cross dimension is the max of the elements dimension since there + // can only be one element in that cross dimension. + crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis))); + } } } var/*float*/ containerCrossAxis = node.layout[dim[crossAxis]]; - if (isUndefined(node.layout[dim[crossAxis]])) { + if (!isCrossDimDefined) { containerCrossAxis = fmaxf( // For the cross dim, we add both sides at the end because the value // is aggregate via a max function. Intermediate negative values // can mess this computation otherwise - boundAxis(node, crossAxis, crossDim + getPaddingAndBorderAxis(node, crossAxis)), - getPaddingAndBorderAxis(node, crossAxis) + boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross), + paddingAndBorderAxisCross ); } // Position elements in the cross axis - for (i = startLine; i < endLine; ++i) { + for (i = firstComplexCross; i < endLine; ++i) { child = node.children[i]; if (getPositionType(child) === CSS_POSITION_ABSOLUTE && @@ -776,7 +871,7 @@ var computeLayout = (function() { getLeadingMargin(child, crossAxis); } else { - var/*float*/ leadingCrossDim = getLeadingPaddingAndBorder(node, crossAxis); + var/*float*/ leadingCrossDim = leadingPaddingAndBorderCross; // For a relative children, we're either using alignItems (parent) or // alignSelf (child) in order to determine the position in the cross axis @@ -785,11 +880,10 @@ var computeLayout = (function() { if (alignItem === CSS_ALIGN_STRETCH) { // You can only stretch if the dimension has not already been set // previously. - if (!isDimDefined(child, crossAxis)) { + if (isUndefined(child.layout[dim[crossAxis]])) { child.layout[dim[crossAxis]] = fmaxf( boundAxis(child, crossAxis, containerCrossAxis - - getPaddingAndBorderAxis(node, crossAxis) - - getMarginAxis(child, crossAxis)), + paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)), // You never want to go smaller than padding getPaddingAndBorderAxis(child, crossAxis) ); @@ -798,8 +892,7 @@ var computeLayout = (function() { // The remaining space between the parent dimensions+padding and child // dimensions+margin. var/*float*/ remainingCrossDim = containerCrossAxis - - getPaddingAndBorderAxis(node, crossAxis) - - getDimWithMargin(child, crossAxis); + paddingAndBorderAxisCross - getDimWithMargin(child, crossAxis); if (alignItem === CSS_ALIGN_CENTER) { leadingCrossDim += remainingCrossDim / 2; @@ -813,7 +906,7 @@ var computeLayout = (function() { child.layout[pos[crossAxis]] += linesCrossDim + leadingCrossDim; // Define the trailing position accordingly. - if (!isUndefined(node.layout[dim[crossAxis]])) { + if (isCrossDimDefined) { setTrailingPosition(node, child, crossAxis); } } @@ -838,14 +931,13 @@ var computeLayout = (function() { // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm // section 9.4 // - if (linesCount > 1 && - !isUndefined(node.layout[dim[crossAxis]])) { + if (linesCount > 1 && isCrossDimDefined) { var/*float*/ nodeCrossAxisInnerSize = node.layout[dim[crossAxis]] - - getPaddingAndBorderAxis(node, crossAxis); + paddingAndBorderAxisCross; var/*float*/ remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim; var/*float*/ crossDimLead = 0; - var/*float*/ currentLead = getLeadingPaddingAndBorder(node, crossAxis); + var/*float*/ currentLead = leadingPaddingAndBorderCross; var/*css_align_t*/ alignContent = getAlignContent(node); if (alignContent === CSS_ALIGN_FLEX_END) { @@ -864,7 +956,7 @@ var computeLayout = (function() { // compute the line's height and find the endIndex var/*float*/ lineHeight = 0; - for (ii = startIndex; ii < node.children.length; ++ii) { + for (ii = startIndex; ii < childCount; ++ii) { child = node.children[ii]; if (getPositionType(child) !== CSS_POSITION_RELATIVE) { continue; @@ -912,33 +1004,39 @@ var computeLayout = (function() { // If the user didn't specify a width or height, and it has not been set // by the container, then we set it via the children. - if (isUndefined(node.layout[dim[mainAxis]])) { + if (!isMainDimDefined) { node.layout[dim[mainAxis]] = fmaxf( // We're missing the last padding at this point to get the final // dimension boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)), // We can never assign a width smaller than the padding and borders - getPaddingAndBorderAxis(node, mainAxis) + paddingAndBorderAxisMain ); - needsMainTrailingPos = true; + if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || + mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + needsMainTrailingPos = true; + } } - if (isUndefined(node.layout[dim[crossAxis]])) { + if (!isCrossDimDefined) { node.layout[dim[crossAxis]] = fmaxf( // For the cross dim, we add both sides at the end because the value // is aggregate via a max function. Intermediate negative values // can mess this computation otherwise - boundAxis(node, crossAxis, linesCrossDim + getPaddingAndBorderAxis(node, crossAxis)), - getPaddingAndBorderAxis(node, crossAxis) + boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross), + paddingAndBorderAxisCross ); - needsCrossTrailingPos = true; + if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE || + crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) { + needsCrossTrailingPos = true; + } } // Set trailing position if necessary if (needsMainTrailingPos || needsCrossTrailingPos) { - for (i = 0; i < node.children.length; ++i) { + for (i = 0; i < childCount; ++i) { child = node.children[i]; if (needsMainTrailingPos) { @@ -952,40 +1050,41 @@ var computeLayout = (function() { } // Calculate dimensions for absolutely positioned elements - for (i = 0; i < node.children.length; ++i) { - child = node.children[i]; - if (getPositionType(child) === CSS_POSITION_ABSOLUTE) { - // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both - // left and right or top and bottom). - for (ii = 0; ii < 2; ii++) { - axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; - if (!isUndefined(node.layout[dim[axis]]) && - !isDimDefined(child, axis) && - isPosDefined(child, leading[axis]) && - isPosDefined(child, trailing[axis])) { - child.layout[dim[axis]] = fmaxf( - boundAxis(child, axis, node.layout[dim[axis]] - - getBorderAxis(node, axis) - - getMarginAxis(child, axis) - - getPosition(child, leading[axis]) - - getPosition(child, trailing[axis]) - ), - // You never want to go smaller than padding - getPaddingAndBorderAxis(child, axis) - ); - } + currentAbsoluteChild = firstAbsoluteChild; + while (currentAbsoluteChild !== null) { + // Pre-fill dimensions when using absolute position and both offsets for + // the axis are defined (either both left and right or top and bottom). + for (ii = 0; ii < 2; ii++) { + axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; + + if (!isUndefined(node.layout[dim[axis]]) && + !isDimDefined(currentAbsoluteChild, axis) && + isPosDefined(currentAbsoluteChild, leading[axis]) && + isPosDefined(currentAbsoluteChild, trailing[axis])) { + currentAbsoluteChild.layout[dim[axis]] = fmaxf( + boundAxis(currentAbsoluteChild, axis, node.layout[dim[axis]] - + getBorderAxis(node, axis) - + getMarginAxis(currentAbsoluteChild, axis) - + getPosition(currentAbsoluteChild, leading[axis]) - + getPosition(currentAbsoluteChild, trailing[axis]) + ), + // You never want to go smaller than padding + getPaddingAndBorderAxis(currentAbsoluteChild, axis) + ); } - for (ii = 0; ii < 2; ii++) { - axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN; - if (isPosDefined(child, trailing[axis]) && - !isPosDefined(child, leading[axis])) { - child.layout[leading[axis]] = - node.layout[dim[axis]] - - child.layout[dim[axis]] - - getPosition(child, trailing[axis]); - } + + if (isPosDefined(currentAbsoluteChild, trailing[axis]) && + !isPosDefined(currentAbsoluteChild, leading[axis])) { + currentAbsoluteChild.layout[leading[axis]] = + node.layout[dim[axis]] - + currentAbsoluteChild.layout[dim[axis]] - + getPosition(currentAbsoluteChild, trailing[axis]); } } + + child = currentAbsoluteChild; + currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild; + child.nextAbsoluteChild = null; } } @@ -1002,6 +1101,7 @@ if (typeof exports === 'object') { module.exports = computeLayout; } + return function(node) { computeLayout.fillNodes(node); computeLayout.computeLayout(node); diff --git a/dist/css-layout.min.js b/dist/css-layout.min.js index d8907372..941672f8 100644 --- a/dist/css-layout.min.js +++ b/dist/css-layout.min.js @@ -1,2 +1,2 @@ -!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.computeLayout=b()}(this,function(){var a=function(){function a(a){return a.charAt(0).toUpperCase()+a.slice(1)}function b(b,c,d,e){for(var f=0;f=0)return b.style[h];if(h=c+d,h in b.style&&b.style[h]>=0)return b.style[h]}return 0}function e(a){return void 0===a}function f(a){return a===X||a===Y}function g(a){return a===Z||a===$}function h(a){var b=[ja[a]];return f(a)&&b.unshift("start"),b}function i(a){var b=[ka[a]];return f(a)&&b.unshift("end"),b}function j(a,c){return b(a,"margin","",c)}function k(a,b){return j(a,h(b))}function l(a,b){return j(a,i(b))}function m(a,b){return d(a,"padding","",b)}function n(a,b){return m(a,h(b))}function o(a,b){return m(a,i(b))}function p(a,b){return d(a,"border","Width",b)}function q(a,b){return p(a,h(b))}function r(a,b){return p(a,i(b))}function s(a,b){return n(a,b)+q(a,b)}function t(a,b){return o(a,b)+r(a,b)}function u(a,b){return q(a,b)+r(a,b)}function v(a,b){return k(a,b)+l(a,b)}function w(a,b){return s(a,b)+t(a,b)}function x(a){return"justifyContent"in a.style?a.style.justifyContent:"flex-start"}function y(a){return"alignContent"in a.style?a.style.alignContent:"flex-start"}function z(a,b){return"alignSelf"in b.style?b.style.alignSelf:"alignItems"in a.style?a.style.alignItems:"stretch"}function A(a,b){if(b===W){if(a===X)return Y;if(a===Y)return X}return a}function B(a,b){var c;return c="direction"in a.style?a.style.direction:U,c===U&&(c=void 0===b?V:b),c}function C(a){return"flexDirection"in a.style?a.style.flexDirection:Z}function D(a,b){return g(a)?A(X,b):Z}function E(a){return"position"in a.style?a.style.position:"relative"}function F(a){return a.style.flex}function G(a){return E(a)===ha&&F(a)>0}function H(a){return"wrap"===a.style.flexWrap}function I(a,b){return a.layout[ma[b]]+v(a,b)}function J(a,b){return!e(a.style[ma[b]])&&a.style[ma[b]]>=0}function K(a,b){return!e(a.style[b])}function L(a){return"measure"in a.style}function M(a,b){return b in a.style?a.style[b]:0}function N(a,b,c){var d={row:a.style.minWidth,"row-reverse":a.style.minWidth,column:a.style.minHeight,"column-reverse":a.style.minHeight}[b],f={row:a.style.maxWidth,"row-reverse":a.style.maxWidth,column:a.style.maxHeight,"column-reverse":a.style.maxHeight}[b],g=c;return!e(f)&&f>=0&&g>f&&(g=f),!e(d)&&d>=0&&d>g&&(g=d),g}function O(a,b){return a>b?a:b}function P(a,b){e(a.layout[ma[b]])&&J(a,b)&&(a.layout[ma[b]]=O(N(a,b,a.style[ma[b]]),w(a,b)))}function Q(a,b,c){b.layout[ka[c]]=a.layout[ma[c]]-b.layout[ma[c]]-b.layout[la[c]]}function R(a,b){return ja[b]in a.style?M(a,ja[b]):-M(a,ka[b])}function S(a,b,c){var d=B(a,c),g=A(C(a),d),h=D(g,d),i=A(X,d);if(P(a,g),P(a,h),a.layout.direction=d,a.layout[ja[g]]+=k(a,g)+R(a,g),a.layout[ka[g]]+=l(a,g)+R(a,g),a.layout[ja[h]]+=k(a,h)+R(a,h),a.layout[ka[h]]+=l(a,h)+R(a,h),L(a)){var j=T;j=J(a,i)?a.style.width:e(a.layout[ma[i]])?b-v(a,i):a.layout[ma[i]],j-=w(a,i);var m=!J(a,i)&&e(a.layout[ma[i]]),n=!J(a,Z)&&e(a.layout[ma[Z]]);if(m||n){var o=a.style.measure(j);m&&(a.layout.width=o.width+w(a,i)),n&&(a.layout.height=o.height+w(a,Z))}if(0===a.children.length)return}var p,r,U,V;for(p=0;pr;r++)V=0!==r?X:Z,!e(a.layout[ma[V]])&&!J(U,V)&&K(U,ja[V])&&K(U,ka[V])&&(U.layout[ma[V]]=O(N(U,V,a.layout[ma[V]]-w(a,V)-v(U,V)-M(U,ja[V])-M(U,ka[V])),w(U,V)))}else U.layout[ma[h]]=O(N(U,h,a.layout[ma[h]]-w(a,h)-v(U,h)),w(U,h));var W=T;e(a.layout[ma[g]])||(W=a.layout[ma[g]]-w(a,g));for(var Y=0,$=0,na=0,oa=0,pa=0,qa=0;$W&&p!==Y){va--,na=1;break}na=0,sa+=wa,$=p+1}var xa=0,ya=0,za=0;if(za=e(a.layout[ma[g]])?O(sa,0)-sa:W-sa,0!==ta){var Aa,Ba,Ca=za/ua;for(p=Y;$>p;++p)U=a.children[p],G(U)&&(Aa=Ca*F(U)+w(U,g),Ba=N(U,g,Aa),Aa!==Ba&&(za-=Ba,ua-=F(U)));for(Ca=za/ua,0>Ca&&(Ca=0),p=Y;$>p;++p)U=a.children[p],G(U)&&(U.layout[ma[g]]=N(U,g,Ca*F(U)+w(U,g)),ra=T,J(a,i)?ra=a.layout[ma[i]]-w(a,i):f(g)||(ra=b-v(a,i)-w(a,i)),S(U,ra,d))}else{var Da=x(a);Da===_?xa=za/2:Da===aa?xa=za:Da===ba?(za=O(za,0),ya=ta+va-1!==0?za/(ta+va-1):0):Da===ca&&(ya=za/(ta+va),xa=ya/2)}var Ea=0,Fa=xa+s(a,g);for(p=Y;$>p;++p)U=a.children[p],U.lineIndex=qa,E(U)===ia&&K(U,ja[g])?U.layout[la[g]]=M(U,ja[g])+q(a,g)+k(U,g):(U.layout[la[g]]+=Fa,e(a.layout[ma[g]])||Q(a,U,g)),E(U)===ha&&(Fa+=ya+I(U,g),Ea=O(Ea,N(U,h,I(U,h))));var Ga=a.layout[ma[h]];for(e(a.layout[ma[h]])&&(Ga=O(N(a,h,Ea+w(a,h)),w(a,h))),p=Y;$>p;++p)if(U=a.children[p],E(U)===ia&&K(U,ja[h]))U.layout[la[h]]=M(U,ja[h])+q(a,h)+k(U,h);else{var Ha=s(a,h);if(E(U)===ha){var Ia=z(a,U);if(Ia===ga)J(U,h)||(U.layout[ma[h]]=O(N(U,h,Ga-w(a,h)-v(U,h)),w(U,h)));else if(Ia!==da){var Ja=Ga-w(a,h)-I(U,h);Ha+=Ia===ea?Ja/2:Ja}}U.layout[la[h]]+=oa+Ha,e(a.layout[ma[h]])||Q(a,U,h)}oa+=Ea,pa=O(pa,Fa),qa+=1,Y=$}if(qa>1&&!e(a.layout[ma[h]])){var Ka=a.layout[ma[h]]-w(a,h),La=Ka-oa,Ma=0,Na=s(a,h),Oa=y(a);Oa===fa?Na+=La:Oa===ea?Na+=La/2:Oa===ga&&Ka>oa&&(Ma=La/qa);var Pa=0;for(p=0;qa>p;++p){var Qa=Pa,Ra=0;for(r=Qa;rr;++r)if(U=a.children[r],E(U)===ha){var Sa=z(a,U);if(Sa===da)U.layout[la[h]]=Na+k(U,h);else if(Sa===fa)U.layout[la[h]]=Na+Ra-l(U,h)-U.layout[ma[h]];else if(Sa===ea){var Ta=U.layout[ma[h]];U.layout[la[h]]=Na+(Ra-Ta)/2}else Sa===ga&&(U.layout[la[h]]=Na+k(U,h))}Na+=Ra}}var Ua=!1,Va=!1;if(e(a.layout[ma[g]])&&(a.layout[ma[g]]=O(N(a,g,pa+t(a,g)),w(a,g)),Ua=!0),e(a.layout[ma[h]])&&(a.layout[ma[h]]=O(N(a,h,oa+w(a,h)),w(a,h)),Va=!0),Ua||Va)for(p=0;pr;r++)V=0!==r?X:Z,!e(a.layout[ma[V]])&&!J(U,V)&&K(U,ja[V])&&K(U,ka[V])&&(U.layout[ma[V]]=O(N(U,V,a.layout[ma[V]]-u(a,V)-v(U,V)-M(U,ja[V])-M(U,ka[V])),w(U,V)));for(r=0;2>r;r++)V=0!==r?X:Z,K(U,ka[V])&&!K(U,ja[V])&&(U.layout[ja[V]]=a.layout[ma[V]]-U.layout[ma[V]]-M(U,ka[V]))}}var T,U="inherit",V="ltr",W="rtl",X="row",Y="row-reverse",Z="column",$="column-reverse",_="center",aa="flex-end",ba="space-between",ca="space-around",da="flex-start",ea="center",fa="flex-end",ga="stretch",ha="relative",ia="absolute",ja={row:"left","row-reverse":"right",column:"top","column-reverse":"bottom"},ka={row:"right","row-reverse":"left",column:"bottom","column-reverse":"top"},la={row:"left","row-reverse":"right",column:"top","column-reverse":"bottom"},ma={row:"width","row-reverse":"width",column:"height","column-reverse":"height"};return{computeLayout:S,fillNodes:c}}();return"object"==typeof exports&&(module.exports=a),function(b){a.fillNodes(b),a.computeLayout(b)}}); +!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.computeLayout=b()}(this,function(){var a=function(){function a(a){return a.charAt(0).toUpperCase()+a.slice(1)}function b(b,c,d,e){for(var f=0;f=0)return b.style[h];if(h=c+d,h in b.style&&b.style[h]>=0)return b.style[h]}return 0}function e(a){return void 0===a}function f(a){return a===W||a===X}function g(a){return a===Y||a===Z}function h(a){var b=[ja[a]];return f(a)&&b.unshift("start"),b}function i(a){var b=[ka[a]];return f(a)&&b.unshift("end"),b}function j(a,c){return b(a,"margin","",c)}function k(a,b){return j(a,h(b))}function l(a,b){return j(a,i(b))}function m(a,b){return d(a,"padding","",b)}function n(a,b){return m(a,h(b))}function o(a,b){return m(a,i(b))}function p(a,b){return d(a,"border","Width",b)}function q(a,b){return p(a,h(b))}function r(a,b){return p(a,i(b))}function s(a,b){return n(a,b)+q(a,b)}function t(a,b){return o(a,b)+r(a,b)}function u(a,b){return q(a,b)+r(a,b)}function v(a,b){return k(a,b)+l(a,b)}function w(a,b){return s(a,b)+t(a,b)}function x(a){return"justifyContent"in a.style?a.style.justifyContent:"flex-start"}function y(a){return"alignContent"in a.style?a.style.alignContent:"flex-start"}function z(a,b){return"alignSelf"in b.style?b.style.alignSelf:"alignItems"in a.style?a.style.alignItems:"stretch"}function A(a,b){if(b===V){if(a===W)return X;if(a===X)return W}return a}function B(a,b){var c;return c="direction"in a.style?a.style.direction:T,c===T&&(c=void 0===b?U:b),c}function C(a){return"flexDirection"in a.style?a.style.flexDirection:Y}function D(a,b){return g(a)?A(W,b):Y}function E(a){return"position"in a.style?a.style.position:"relative"}function F(a){return E(a)===ha&&a.style.flex>0}function G(a){return"wrap"===a.style.flexWrap}function H(a,b){return a.layout[ma[b]]+v(a,b)}function I(a,b){return!e(a.style[ma[b]])&&a.style[ma[b]]>=0}function J(a,b){return!e(a.style[b])}function K(a){return"measure"in a.style}function L(a,b){return b in a.style?a.style[b]:0}function M(a,b,c){var d={row:a.style.minWidth,"row-reverse":a.style.minWidth,column:a.style.minHeight,"column-reverse":a.style.minHeight}[b],f={row:a.style.maxWidth,"row-reverse":a.style.maxWidth,column:a.style.maxHeight,"column-reverse":a.style.maxHeight}[b],g=c;return!e(f)&&f>=0&&g>f&&(g=f),!e(d)&&d>=0&&d>g&&(g=d),g}function N(a,b){return a>b?a:b}function O(a,b){e(a.layout[ma[b]])&&I(a,b)&&(a.layout[ma[b]]=N(M(a,b,a.style[ma[b]]),w(a,b)))}function P(a,b,c){b.layout[ka[c]]=a.layout[ma[c]]-b.layout[ma[c]]-b.layout[la[c]]}function Q(a,b){return ja[b]in a.style?L(a,ja[b]):-L(a,ka[b])}function R(a,b,c){var d=B(a,c),g=A(C(a),d),h=D(g,d),i=A(W,d);O(a,g),O(a,h),a.layout.direction=d,a.layout[ja[g]]+=k(a,g)+Q(a,g),a.layout[ka[g]]+=l(a,g)+Q(a,g),a.layout[ja[h]]+=k(a,h)+Q(a,h),a.layout[ka[h]]+=l(a,h)+Q(a,h);var j=a.children.length,m=w(a,i);if(K(a)){var n=!e(a.layout[ma[i]]),o=S;o=I(a,i)?a.style.width:n?a.layout[ma[i]]:b-v(a,i),o-=m;var p=!I(a,i)&&!n,r=!I(a,Y)&&e(a.layout[ma[Y]]);if(p||r){var T=a.style.measure(o);p&&(a.layout.width=T.width+m),r&&(a.layout.height=T.height+w(a,Y))}if(0===j)return}var U,V,na,oa,pa=G(a),qa=x(a),ra=s(a,g),sa=s(a,h),ta=w(a,g),ua=w(a,h),va=!e(a.layout[ma[g]]),wa=!e(a.layout[ma[h]]),xa=f(g),ya=null,za=null,Aa=S;va&&(Aa=a.layout[ma[g]]-ta);for(var Ba=0,Ca=0,Da=0,Ea=0,Fa=0,Ga=0;j>Ca;){var Ha,Ia=0,Ja=0,Ka=0,La=0,Ma=va&&qa==$||!va&&qa!=_,Na=Ma?j:Ba,Oa=!0,Pa=j,Qa=null,Ra=null,Sa=ra,Ta=0;for(U=Ba;j>U;++U){na=a.children[U],na.lineIndex=Ga,na.nextAbsoluteChild=null,na.nextFlexChild=null;var Ua=z(a,na);if(Ua===ga&&E(na)===ha&&wa&&!I(na,h))na.layout[ma[h]]=N(M(na,h,a.layout[ma[h]]-ua-v(na,h)),w(na,h));else if(E(na)===ia)for(null===ya&&(ya=na),null!==za&&(za.nextAbsoluteChild=na),za=na,V=0;2>V;V++)oa=0!==V?W:Y,!e(a.layout[ma[oa]])&&!I(na,oa)&&J(na,ja[oa])&&J(na,ka[oa])&&(na.layout[ma[oa]]=N(M(na,oa,a.layout[ma[oa]]-w(a,oa)-v(na,oa)-L(na,ja[oa])-L(na,ka[oa])),w(na,oa)));var Va=0;if(va&&F(na)?(Ja++,Ka+=na.style.flex,null===Qa&&(Qa=na),null!==Ra&&(Ra.nextFlexChild=na),Ra=na,Va=w(na,g)+v(na,g)):(Ha=S,xa||(Ha=I(a,i)?a.layout[ma[i]]-m:b-v(a,i)-m),0===Da&&R(na,Ha,d),E(na)===ha&&(La++,Va=H(na,g))),pa&&va&&Ia+Va>Aa&&U!==Ba){La--,Da=1;break}Ma&&(E(na)!=ha||F(na))&&(Ma=!1,Na=U),Oa&&(E(na)!=ha||Ua!==ga&&Ua!=da||e(na.layout[ma[h]]))&&(Oa=!1,Pa=U),Ma&&(na.layout[la[g]]+=Sa,va&&P(a,na,g),Sa+=H(na,g),Ta=N(Ta,M(na,h,H(na,h)))),Oa&&(na.layout[la[h]]+=Ea+sa,wa&&P(a,na,h)),Da=0,Ia+=Va,Ca=U+1}var Wa=0,Xa=0,Ya=0;if(Ya=va?Aa-Ia:N(Ia,0)-Ia,0!==Ja){var Za,$a,_a=Ya/Ka;for(Ra=Qa;null!==Ra;)Za=_a*Ra.style.flex+w(Ra,g),$a=M(Ra,g,Za),Za!==$a&&(Ya-=$a,Ka-=Ra.style.flex),Ra=Ra.nextFlexChild;for(_a=Ya/Ka,0>_a&&(_a=0),Ra=Qa;null!==Ra;)Ra.layout[ma[g]]=M(Ra,g,_a*Ra.style.flex+w(Ra,g)),Ha=S,I(a,i)?Ha=a.layout[ma[i]]-m:xa||(Ha=b-v(a,i)-m),R(Ra,Ha,d),na=Ra,Ra=Ra.nextFlexChild,na.nextFlexChild=null}else qa!==$&&(qa===_?Wa=Ya/2:qa===aa?Wa=Ya:qa===ba?(Ya=N(Ya,0),Xa=Ja+La-1!==0?Ya/(Ja+La-1):0):qa===ca&&(Xa=Ya/(Ja+La),Wa=Xa/2));for(Sa+=Wa,U=Na;Ca>U;++U)na=a.children[U],E(na)===ia&&J(na,ja[g])?na.layout[la[g]]=L(na,ja[g])+q(a,g)+k(na,g):(na.layout[la[g]]+=Sa,va&&P(a,na,g),E(na)===ha&&(Sa+=Xa+H(na,g),Ta=N(Ta,M(na,h,H(na,h)))));var ab=a.layout[ma[h]];for(wa||(ab=N(M(a,h,Ta+ua),ua)),U=Pa;Ca>U;++U)if(na=a.children[U],E(na)===ia&&J(na,ja[h]))na.layout[la[h]]=L(na,ja[h])+q(a,h)+k(na,h);else{var bb=sa;if(E(na)===ha){var Ua=z(a,na);if(Ua===ga)e(na.layout[ma[h]])&&(na.layout[ma[h]]=N(M(na,h,ab-ua-v(na,h)),w(na,h)));else if(Ua!==da){var cb=ab-ua-H(na,h);bb+=Ua===ea?cb/2:cb}}na.layout[la[h]]+=Ea+bb,wa&&P(a,na,h)}Ea+=Ta,Fa=N(Fa,Sa),Ga+=1,Ba=Ca}if(Ga>1&&wa){var db=a.layout[ma[h]]-ua,eb=db-Ea,fb=0,gb=sa,hb=y(a);hb===fa?gb+=eb:hb===ea?gb+=eb/2:hb===ga&&db>Ea&&(fb=eb/Ga);var ib=0;for(U=0;Ga>U;++U){var jb=ib,kb=0;for(V=jb;j>V;++V)if(na=a.children[V],E(na)===ha){if(na.lineIndex!==U)break;e(na.layout[ma[h]])||(kb=N(kb,na.layout[ma[h]]+v(na,h)))}for(ib=V,kb+=fb,V=jb;ib>V;++V)if(na=a.children[V],E(na)===ha){var lb=z(a,na);if(lb===da)na.layout[la[h]]=gb+k(na,h);else if(lb===fa)na.layout[la[h]]=gb+kb-l(na,h)-na.layout[ma[h]];else if(lb===ea){var mb=na.layout[ma[h]];na.layout[la[h]]=gb+(kb-mb)/2}else lb===ga&&(na.layout[la[h]]=gb+k(na,h))}gb+=kb}}var nb=!1,ob=!1;if(va||(a.layout[ma[g]]=N(M(a,g,Fa+t(a,g)),ta),(g==X||g==Z)&&(nb=!0)),wa||(a.layout[ma[h]]=N(M(a,h,Ea+ua),ua),(h==X||h==Z)&&(ob=!0)),nb||ob)for(U=0;j>U;++U)na=a.children[U],nb&&P(a,na,g),ob&&P(a,na,h);for(za=ya;null!==za;){for(V=0;2>V;V++)oa=0!==V?W:Y,!e(a.layout[ma[oa]])&&!I(za,oa)&&J(za,ja[oa])&&J(za,ka[oa])&&(za.layout[ma[oa]]=N(M(za,oa,a.layout[ma[oa]]-u(a,oa)-v(za,oa)-L(za,ja[oa])-L(za,ka[oa])),w(za,oa))),J(za,ka[oa])&&!J(za,ja[oa])&&(za.layout[ja[oa]]=a.layout[ma[oa]]-za.layout[ma[oa]]-L(za,ka[oa]));na=za,za=za.nextAbsoluteChild,na.nextAbsoluteChild=null}}var S,T="inherit",U="ltr",V="rtl",W="row",X="row-reverse",Y="column",Z="column-reverse",$="flex-start",_="center",aa="flex-end",ba="space-between",ca="space-around",da="flex-start",ea="center",fa="flex-end",ga="stretch",ha="relative",ia="absolute",ja={row:"left","row-reverse":"right",column:"top","column-reverse":"bottom"},ka={row:"right","row-reverse":"left",column:"bottom","column-reverse":"top"},la={row:"left","row-reverse":"right",column:"top","column-reverse":"bottom"},ma={row:"width","row-reverse":"width",column:"height","column-reverse":"height"};return{computeLayout:R,fillNodes:c}}();return"object"==typeof exports&&(module.exports=a),function(b){a.fillNodes(b),a.computeLayout(b)}}); //# sourceMappingURL=css-layout.min.js.map \ No newline at end of file diff --git a/dist/css-layout.min.js.map b/dist/css-layout.min.js.map index 4eeaca1d..ee3334ea 100644 --- a/dist/css-layout.min.js.map +++ b/dist/css-layout.min.js.map @@ -1 +1 @@ -{"version":3,"file":"css-layout.min.js","sources":["css-layout.js"],"names":["root","factory","define","amd","exports","module","computeLayout","this","capitalizeFirst","str","charAt","toUpperCase","slice","getSpacing","node","type","suffix","locations","i","length","location","key","style","fillNodes","layout","width","undefined","height","top","left","right","bottom","children","forEach","getPositiveSpacing","isUndefined","value","isRowDirection","flexDirection","CSS_FLEX_DIRECTION_ROW","CSS_FLEX_DIRECTION_ROW_REVERSE","isColumnDirection","CSS_FLEX_DIRECTION_COLUMN","CSS_FLEX_DIRECTION_COLUMN_REVERSE","getLeadingLocations","axis","leading","unshift","getTrailingLocations","trailing","getMargin","getLeadingMargin","getTrailingMargin","getPadding","getLeadingPadding","getTrailingPadding","getBorder","getLeadingBorder","getTrailingBorder","getLeadingPaddingAndBorder","getTrailingPaddingAndBorder","getBorderAxis","getMarginAxis","getPaddingAndBorderAxis","getJustifyContent","justifyContent","getAlignContent","alignContent","getAlignItem","child","alignSelf","alignItems","resolveAxis","direction","CSS_DIRECTION_RTL","resolveDirection","parentDirection","CSS_DIRECTION_INHERIT","CSS_DIRECTION_LTR","getFlexDirection","getCrossFlexDirection","getPositionType","position","getFlex","flex","isFlex","CSS_POSITION_RELATIVE","isFlexWrap","flexWrap","getDimWithMargin","dim","isDimDefined","isPosDefined","pos","isMeasureDefined","getPosition","boundAxis","min","row","minWidth","row-reverse","column","minHeight","column-reverse","max","maxWidth","maxHeight","boundValue","fmaxf","a","b","setDimensionFromStyle","setTrailingPosition","getRelativePosition","layoutNode","parentMaxWidth","mainAxis","crossAxis","resolvedRowAxis","CSS_UNDEFINED","isRowUndefined","isColumnUndefined","measureDim","measure","ii","CSS_ALIGN_STRETCH","CSS_POSITION_ABSOLUTE","definedMainDim","startLine","endLine","alreadyComputedNextLayout","linesCrossDim","linesMainDim","linesCount","mainContentDim","flexibleChildrenCount","totalFlexible","nonFlexibleChildrenCount","nextContentDim","leadingMainDim","betweenMainDim","remainingMainDim","baseMainDim","boundMainDim","flexibleMainDim","CSS_JUSTIFY_CENTER","CSS_JUSTIFY_FLEX_END","CSS_JUSTIFY_SPACE_BETWEEN","CSS_JUSTIFY_SPACE_AROUND","crossDim","mainDim","lineIndex","containerCrossAxis","leadingCrossDim","alignItem","CSS_ALIGN_FLEX_START","remainingCrossDim","CSS_ALIGN_CENTER","nodeCrossAxisInnerSize","remainingAlignContentDim","crossDimLead","currentLead","CSS_ALIGN_FLEX_END","endIndex","startIndex","lineHeight","alignContentAlignItem","childHeight","needsMainTrailingPos","needsCrossTrailingPos"],"mappings":"CAKC,SAAUA,EAAMC,GACO,kBAAXC,SAAyBA,OAAOC,IAEzCD,UAAWD,GACiB,gBAAZG,SAIhBC,OAAOD,QAAUH,IAGjBD,EAAKM,cAAgBL,KAEvBM,KAAM,WAUR,GAAID,GAAgB,WAoDlB,QA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O,QACPE,cAAe,QACfC,OAAU,SACVE,iBAAkB,SAk5BpB,QACEjG,cAAe4G,EACf3F,UAAWA,KAWX,OAJmB,gBAAZnB,WACTC,OAAOD,QAAUE,GAGR,SAASQ,GACdR,EAAciB,UAAUT,GACxBR,EAAcA,cAAcQ","sourcesContent":["// UMD (Universal Module Definition)\n// See https://github.com/umdjs/umd for reference\n//\n// This file uses the following specific UMD implementation:\n// https://github.com/umdjs/umd/blob/master/returnExports.js\n(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define([], factory);\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like environments that support module.exports,\n // like Node.\n module.exports = factory();\n } else {\n // Browser globals (root is window)\n root.computeLayout = factory();\n }\n}(this, function () {\n /**\n * Copyright (c) 2014, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nvar computeLayout = (function() {\n\n var CSS_UNDEFINED;\n\n var CSS_DIRECTION_INHERIT = 'inherit';\n var CSS_DIRECTION_LTR = 'ltr';\n var CSS_DIRECTION_RTL = 'rtl';\n\n var CSS_FLEX_DIRECTION_ROW = 'row';\n var CSS_FLEX_DIRECTION_ROW_REVERSE = 'row-reverse';\n var CSS_FLEX_DIRECTION_COLUMN = 'column';\n var CSS_FLEX_DIRECTION_COLUMN_REVERSE = 'column-reverse';\n\n // var CSS_JUSTIFY_FLEX_START = 'flex-start';\n var CSS_JUSTIFY_CENTER = 'center';\n var CSS_JUSTIFY_FLEX_END = 'flex-end';\n var CSS_JUSTIFY_SPACE_BETWEEN = 'space-between';\n var CSS_JUSTIFY_SPACE_AROUND = 'space-around';\n\n var CSS_ALIGN_FLEX_START = 'flex-start';\n var CSS_ALIGN_CENTER = 'center';\n var CSS_ALIGN_FLEX_END = 'flex-end';\n var CSS_ALIGN_STRETCH = 'stretch';\n\n var CSS_POSITION_RELATIVE = 'relative';\n var CSS_POSITION_ABSOLUTE = 'absolute';\n\n var leading = {\n 'row': 'left',\n 'row-reverse': 'right',\n 'column': 'top',\n 'column-reverse': 'bottom'\n };\n var trailing = {\n 'row': 'right',\n 'row-reverse': 'left',\n 'column': 'bottom',\n 'column-reverse': 'top'\n };\n var pos = {\n 'row': 'left',\n 'row-reverse': 'right',\n 'column': 'top',\n 'column-reverse': 'bottom'\n };\n var dim = {\n 'row': 'width',\n 'row-reverse': 'width',\n 'column': 'height',\n 'column-reverse': 'height'\n };\n\n function capitalizeFirst(str) {\n return str.charAt(0).toUpperCase() + str.slice(1);\n }\n\n function getSpacing(node, type, suffix, locations) {\n for (var i = 0; i < locations.length; ++i) {\n var location = locations[i];\n\n var key = type + capitalizeFirst(location) + suffix;\n if (key in node.style) {\n return node.style[key];\n }\n\n key = type + suffix;\n if (key in node.style) {\n return node.style[key];\n }\n }\n\n return 0;\n }\n\n // When transpiled to Java / C the node type has layout, children and style\n // properties. For the JavaScript version this function adds these properties\n // if they don't already exist.\n function fillNodes(node) {\n if (!node.layout) {\n node.layout = {\n width: undefined,\n height: undefined,\n top: 0,\n left: 0,\n right: 0,\n bottom: 0\n };\n }\n\n if (!node.style) {\n node.style = {};\n }\n\n if (!node.children) {\n node.children = [];\n }\n node.children.forEach(fillNodes);\n return node;\n }\n\n function getPositiveSpacing(node, type, suffix, locations) {\n for (var i = 0; i < locations.length; ++i) {\n var location = locations[i];\n\n var key = type + capitalizeFirst(location) + suffix;\n if (key in node.style && node.style[key] >= 0) {\n return node.style[key];\n }\n\n key = type + suffix;\n if (key in node.style && node.style[key] >= 0) {\n return node.style[key];\n }\n }\n\n return 0;\n }\n\n function isUndefined(value) {\n return value === undefined;\n }\n\n function isRowDirection(flexDirection) {\n return flexDirection === CSS_FLEX_DIRECTION_ROW ||\n flexDirection === CSS_FLEX_DIRECTION_ROW_REVERSE;\n }\n\n function isColumnDirection(flexDirection) {\n return flexDirection === CSS_FLEX_DIRECTION_COLUMN ||\n flexDirection === CSS_FLEX_DIRECTION_COLUMN_REVERSE;\n }\n\n function getLeadingLocations(axis) {\n var locations = [leading[axis]];\n if (isRowDirection(axis)) {\n locations.unshift('start');\n }\n\n return locations;\n }\n\n function getTrailingLocations(axis) {\n var locations = [trailing[axis]];\n if (isRowDirection(axis)) {\n locations.unshift('end');\n }\n\n return locations;\n }\n\n function getMargin(node, locations) {\n return getSpacing(node, 'margin', '', locations);\n }\n\n function getLeadingMargin(node, axis) {\n return getMargin(node, getLeadingLocations(axis));\n }\n\n function getTrailingMargin(node, axis) {\n return getMargin(node, getTrailingLocations(axis));\n }\n\n function getPadding(node, locations) {\n return getPositiveSpacing(node, 'padding', '', locations);\n }\n\n function getLeadingPadding(node, axis) {\n return getPadding(node, getLeadingLocations(axis));\n }\n\n function getTrailingPadding(node, axis) {\n return getPadding(node, getTrailingLocations(axis));\n }\n\n function getBorder(node, locations) {\n return getPositiveSpacing(node, 'border', 'Width', locations);\n }\n\n function getLeadingBorder(node, axis) {\n return getBorder(node, getLeadingLocations(axis));\n }\n\n function getTrailingBorder(node, axis) {\n return getBorder(node, getTrailingLocations(axis));\n }\n\n function getLeadingPaddingAndBorder(node, axis) {\n return getLeadingPadding(node, axis) + getLeadingBorder(node, axis);\n }\n\n function getTrailingPaddingAndBorder(node, axis) {\n return getTrailingPadding(node, axis) + getTrailingBorder(node, axis);\n }\n\n function getBorderAxis(node, axis) {\n return getLeadingBorder(node, axis) + getTrailingBorder(node, axis);\n }\n\n function getMarginAxis(node, axis) {\n return getLeadingMargin(node, axis) + getTrailingMargin(node, axis);\n }\n\n function getPaddingAndBorderAxis(node, axis) {\n return getLeadingPaddingAndBorder(node, axis) +\n getTrailingPaddingAndBorder(node, axis);\n }\n\n function getJustifyContent(node) {\n if ('justifyContent' in node.style) {\n return node.style.justifyContent;\n }\n return 'flex-start';\n }\n\n function getAlignContent(node) {\n if ('alignContent' in node.style) {\n return node.style.alignContent;\n }\n return 'flex-start';\n }\n\n function getAlignItem(node, child) {\n if ('alignSelf' in child.style) {\n return child.style.alignSelf;\n }\n if ('alignItems' in node.style) {\n return node.style.alignItems;\n }\n return 'stretch';\n }\n\n function resolveAxis(axis, direction) {\n if (direction === CSS_DIRECTION_RTL) {\n if (axis === CSS_FLEX_DIRECTION_ROW) {\n return CSS_FLEX_DIRECTION_ROW_REVERSE;\n } else if (axis === CSS_FLEX_DIRECTION_ROW_REVERSE) {\n return CSS_FLEX_DIRECTION_ROW;\n }\n }\n\n return axis;\n }\n\n function resolveDirection(node, parentDirection) {\n var direction;\n if ('direction' in node.style) {\n direction = node.style.direction;\n } else {\n direction = CSS_DIRECTION_INHERIT;\n }\n\n if (direction === CSS_DIRECTION_INHERIT) {\n direction = (parentDirection === undefined ? CSS_DIRECTION_LTR : parentDirection);\n }\n\n return direction;\n }\n\n function getFlexDirection(node) {\n if ('flexDirection' in node.style) {\n return node.style.flexDirection;\n }\n return CSS_FLEX_DIRECTION_COLUMN;\n }\n\n function getCrossFlexDirection(flexDirection, direction) {\n if (isColumnDirection(flexDirection)) {\n return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);\n } else {\n return CSS_FLEX_DIRECTION_COLUMN;\n }\n }\n\n function getPositionType(node) {\n if ('position' in node.style) {\n return node.style.position;\n }\n return 'relative';\n }\n\n function getFlex(node) {\n return node.style.flex;\n }\n\n function isFlex(node) {\n return (\n getPositionType(node) === CSS_POSITION_RELATIVE &&\n getFlex(node) > 0\n );\n }\n\n function isFlexWrap(node) {\n return node.style.flexWrap === 'wrap';\n }\n\n function getDimWithMargin(node, axis) {\n return node.layout[dim[axis]] + getMarginAxis(node, axis);\n }\n\n function isDimDefined(node, axis) {\n return !isUndefined(node.style[dim[axis]]) && node.style[dim[axis]] >= 0;\n }\n\n function isPosDefined(node, pos) {\n return !isUndefined(node.style[pos]);\n }\n\n function isMeasureDefined(node) {\n return 'measure' in node.style;\n }\n\n function getPosition(node, pos) {\n if (pos in node.style) {\n return node.style[pos];\n }\n return 0;\n }\n\n function boundAxis(node, axis, value) {\n var min = {\n 'row': node.style.minWidth,\n 'row-reverse': node.style.minWidth,\n 'column': node.style.minHeight,\n 'column-reverse': node.style.minHeight\n }[axis];\n\n var max = {\n 'row': node.style.maxWidth,\n 'row-reverse': node.style.maxWidth,\n 'column': node.style.maxHeight,\n 'column-reverse': node.style.maxHeight\n }[axis];\n\n var boundValue = value;\n if (!isUndefined(max) && max >= 0 && boundValue > max) {\n boundValue = max;\n }\n if (!isUndefined(min) && min >= 0 && boundValue < min) {\n boundValue = min;\n }\n return boundValue;\n }\n\n function fmaxf(a, b) {\n if (a > b) {\n return a;\n }\n return b;\n }\n\n // When the user specifically sets a value for width or height\n function setDimensionFromStyle(node, axis) {\n // The parent already computed us a width or height. We just skip it\n if (!isUndefined(node.layout[dim[axis]])) {\n return;\n }\n // We only run if there's a width or height defined\n if (!isDimDefined(node, axis)) {\n return;\n }\n\n // The dimensions can never be smaller than the padding and border\n node.layout[dim[axis]] = fmaxf(\n boundAxis(node, axis, node.style[dim[axis]]),\n getPaddingAndBorderAxis(node, axis)\n );\n }\n\n function setTrailingPosition(node, child, axis) {\n child.layout[trailing[axis]] = node.layout[dim[axis]] -\n child.layout[dim[axis]] - child.layout[pos[axis]];\n }\n\n // If both left and right are defined, then use left. Otherwise return\n // +left or -right depending on which is defined.\n function getRelativePosition(node, axis) {\n if (leading[axis] in node.style) {\n return getPosition(node, leading[axis]);\n }\n return -getPosition(node, trailing[axis]);\n }\n\n function layoutNode(node, parentMaxWidth, /*css_direction_t*/parentDirection) {\n var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);\n var/*css_flex_direction_t*/ mainAxis = resolveAxis(getFlexDirection(node), direction);\n var/*css_flex_direction_t*/ crossAxis = getCrossFlexDirection(mainAxis, direction);\n var/*css_flex_direction_t*/ resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);\n\n // Handle width and height style attributes\n setDimensionFromStyle(node, mainAxis);\n setDimensionFromStyle(node, crossAxis);\n\n // Set the resolved resolution in the node's layout\n node.layout.direction = direction;\n\n // The position is set by the parent, but we need to complete it with a\n // delta composed of the margin and left/top/right/bottom\n node.layout[leading[mainAxis]] += getLeadingMargin(node, mainAxis) +\n getRelativePosition(node, mainAxis);\n node.layout[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) +\n getRelativePosition(node, mainAxis);\n node.layout[leading[crossAxis]] += getLeadingMargin(node, crossAxis) +\n getRelativePosition(node, crossAxis);\n node.layout[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) +\n getRelativePosition(node, crossAxis);\n\n if (isMeasureDefined(node)) {\n var/*float*/ width = CSS_UNDEFINED;\n if (isDimDefined(node, resolvedRowAxis)) {\n width = node.style.width;\n } else if (!isUndefined(node.layout[dim[resolvedRowAxis]])) {\n width = node.layout[dim[resolvedRowAxis]];\n } else {\n width = parentMaxWidth -\n getMarginAxis(node, resolvedRowAxis);\n }\n width -= getPaddingAndBorderAxis(node, resolvedRowAxis);\n\n // We only need to give a dimension for the text if we haven't got any\n // for it computed yet. It can either be from the style attribute or because\n // the element is flexible.\n var/*bool*/ isRowUndefined = !isDimDefined(node, resolvedRowAxis) &&\n isUndefined(node.layout[dim[resolvedRowAxis]]);\n var/*bool*/ isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) &&\n isUndefined(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]]);\n\n // Let's not measure the text if we already know both dimensions\n if (isRowUndefined || isColumnUndefined) {\n var/*css_dim_t*/ measureDim = node.style.measure(\n /*(c)!node->context,*/\n /*(java)!layoutContext.measureOutput,*/\n width\n );\n if (isRowUndefined) {\n node.layout.width = measureDim.width +\n getPaddingAndBorderAxis(node, resolvedRowAxis);\n }\n if (isColumnUndefined) {\n node.layout.height = measureDim.height +\n getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);\n }\n }\n if (node.children.length === 0) {\n return;\n }\n }\n\n var/*int*/ i;\n var/*int*/ ii;\n var/*css_node_t**/ child;\n var/*css_flex_direction_t*/ axis;\n\n // Pre-fill some dimensions straight from the parent\n for (i = 0; i < node.children.length; ++i) {\n child = node.children[i];\n // Pre-fill cross axis dimensions when the child is using stretch before\n // we call the recursive layout pass\n if (getAlignItem(node, child) === CSS_ALIGN_STRETCH &&\n getPositionType(child) === CSS_POSITION_RELATIVE &&\n !isUndefined(node.layout[dim[crossAxis]]) &&\n !isDimDefined(child, crossAxis)) {\n child.layout[dim[crossAxis]] = fmaxf(\n boundAxis(child, crossAxis, node.layout[dim[crossAxis]] -\n getPaddingAndBorderAxis(node, crossAxis) -\n getMarginAxis(child, crossAxis)),\n // You never want to go smaller than padding\n getPaddingAndBorderAxis(child, crossAxis)\n );\n } else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) {\n // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both\n // left and right or top and bottom).\n for (ii = 0; ii < 2; ii++) {\n axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;\n if (!isUndefined(node.layout[dim[axis]]) &&\n !isDimDefined(child, axis) &&\n isPosDefined(child, leading[axis]) &&\n isPosDefined(child, trailing[axis])) {\n child.layout[dim[axis]] = fmaxf(\n boundAxis(child, axis, node.layout[dim[axis]] -\n getPaddingAndBorderAxis(node, axis) -\n getMarginAxis(child, axis) -\n getPosition(child, leading[axis]) -\n getPosition(child, trailing[axis])),\n // You never want to go smaller than padding\n getPaddingAndBorderAxis(child, axis)\n );\n }\n }\n }\n }\n\n var/*float*/ definedMainDim = CSS_UNDEFINED;\n if (!isUndefined(node.layout[dim[mainAxis]])) {\n definedMainDim = node.layout[dim[mainAxis]] -\n getPaddingAndBorderAxis(node, mainAxis);\n }\n\n // We want to execute the next two loops one per line with flex-wrap\n var/*int*/ startLine = 0;\n var/*int*/ endLine = 0;\n // var/*int*/ nextOffset = 0;\n var/*int*/ alreadyComputedNextLayout = 0;\n // We aggregate the total dimensions of the container in those two variables\n var/*float*/ linesCrossDim = 0;\n var/*float*/ linesMainDim = 0;\n var/*int*/ linesCount = 0;\n while (endLine < node.children.length) {\n // Layout non flexible children and count children by type\n\n // mainContentDim is accumulation of the dimensions and margin of all the\n // non flexible children. This will be used in order to either set the\n // dimensions of the node if none already exist, or to compute the\n // remaining space left for the flexible children.\n var/*float*/ mainContentDim = 0;\n\n // There are three kind of children, non flexible, flexible and absolute.\n // We need to know how many there are in order to distribute the space.\n var/*int*/ flexibleChildrenCount = 0;\n var/*float*/ totalFlexible = 0;\n var/*int*/ nonFlexibleChildrenCount = 0;\n\n var/*float*/ maxWidth;\n for (i = startLine; i < node.children.length; ++i) {\n child = node.children[i];\n var/*float*/ nextContentDim = 0;\n\n // It only makes sense to consider a child flexible if we have a computed\n // dimension for the node.\n if (!isUndefined(node.layout[dim[mainAxis]]) && isFlex(child)) {\n flexibleChildrenCount++;\n totalFlexible += getFlex(child);\n\n // Even if we don't know its exact size yet, we already know the padding,\n // border and margin. We'll use this partial information, which represents\n // the smallest possible size for the child, to compute the remaining\n // available space.\n nextContentDim = getPaddingAndBorderAxis(child, mainAxis) +\n getMarginAxis(child, mainAxis);\n\n } else {\n maxWidth = CSS_UNDEFINED;\n if (!isRowDirection(mainAxis)) {\n maxWidth = parentMaxWidth -\n getMarginAxis(node, resolvedRowAxis) -\n getPaddingAndBorderAxis(node, resolvedRowAxis);\n\n if (isDimDefined(node, resolvedRowAxis)) {\n maxWidth = node.layout[dim[resolvedRowAxis]] -\n getPaddingAndBorderAxis(node, resolvedRowAxis);\n }\n }\n\n // This is the main recursive call. We layout non flexible children.\n if (alreadyComputedNextLayout === 0) {\n layoutNode(/*(java)!layoutContext, */child, maxWidth, direction);\n }\n\n // Absolute positioned elements do not take part of the layout, so we\n // don't use them to compute mainContentDim\n if (getPositionType(child) === CSS_POSITION_RELATIVE) {\n nonFlexibleChildrenCount++;\n // At this point we know the final size and margin of the element.\n nextContentDim = getDimWithMargin(child, mainAxis);\n }\n }\n\n // The element we are about to add would make us go to the next line\n if (isFlexWrap(node) &&\n !isUndefined(node.layout[dim[mainAxis]]) &&\n mainContentDim + nextContentDim > definedMainDim &&\n // If there's only one element, then it's bigger than the content\n // and needs its own line\n i !== startLine) {\n nonFlexibleChildrenCount--;\n alreadyComputedNextLayout = 1;\n break;\n }\n alreadyComputedNextLayout = 0;\n mainContentDim += nextContentDim;\n endLine = i + 1;\n }\n\n // Layout flexible children and allocate empty space\n\n // In order to position the elements in the main axis, we have two\n // controls. The space between the beginning and the first element\n // and the space between each two elements.\n var/*float*/ leadingMainDim = 0;\n var/*float*/ betweenMainDim = 0;\n\n // The remaining available space that needs to be allocated\n var/*float*/ remainingMainDim = 0;\n if (!isUndefined(node.layout[dim[mainAxis]])) {\n remainingMainDim = definedMainDim - mainContentDim;\n } else {\n remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim;\n }\n\n // If there are flexible children in the mix, they are going to fill the\n // remaining space\n if (flexibleChildrenCount !== 0) {\n var/*float*/ flexibleMainDim = remainingMainDim / totalFlexible;\n var/*float*/ baseMainDim;\n var/*float*/ boundMainDim;\n\n // Iterate over every child in the axis. If the flex share of remaining\n // space doesn't meet min/max bounds, remove this child from flex\n // calculations.\n for (i = startLine; i < endLine; ++i) {\n child = node.children[i];\n if (isFlex(child)) {\n baseMainDim = flexibleMainDim * getFlex(child) +\n getPaddingAndBorderAxis(child, mainAxis);\n boundMainDim = boundAxis(child, mainAxis, baseMainDim);\n\n if (baseMainDim !== boundMainDim) {\n remainingMainDim -= boundMainDim;\n totalFlexible -= getFlex(child);\n }\n }\n }\n flexibleMainDim = remainingMainDim / totalFlexible;\n\n // The non flexible children can overflow the container, in this case\n // we should just assume that there is no space available.\n if (flexibleMainDim < 0) {\n flexibleMainDim = 0;\n }\n // We iterate over the full array and only apply the action on flexible\n // children. This is faster than actually allocating a new array that\n // contains only flexible children.\n for (i = startLine; i < endLine; ++i) {\n child = node.children[i];\n if (isFlex(child)) {\n // At this point we know the final size of the element in the main\n // dimension\n child.layout[dim[mainAxis]] = boundAxis(child, mainAxis,\n flexibleMainDim * getFlex(child) + getPaddingAndBorderAxis(child, mainAxis)\n );\n\n maxWidth = CSS_UNDEFINED;\n if (isDimDefined(node, resolvedRowAxis)) {\n maxWidth = node.layout[dim[resolvedRowAxis]] -\n getPaddingAndBorderAxis(node, resolvedRowAxis);\n } else if (!isRowDirection(mainAxis)) {\n maxWidth = parentMaxWidth -\n getMarginAxis(node, resolvedRowAxis) -\n getPaddingAndBorderAxis(node, resolvedRowAxis);\n }\n\n // And we recursively call the layout algorithm for this child\n layoutNode(/*(java)!layoutContext, */child, maxWidth, direction);\n }\n }\n\n // We use justifyContent to figure out how to allocate the remaining\n // space available\n } else {\n var/*css_justify_t*/ justifyContent = getJustifyContent(node);\n if (justifyContent === CSS_JUSTIFY_CENTER) {\n leadingMainDim = remainingMainDim / 2;\n } else if (justifyContent === CSS_JUSTIFY_FLEX_END) {\n leadingMainDim = remainingMainDim;\n } else if (justifyContent === CSS_JUSTIFY_SPACE_BETWEEN) {\n remainingMainDim = fmaxf(remainingMainDim, 0);\n if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 !== 0) {\n betweenMainDim = remainingMainDim /\n (flexibleChildrenCount + nonFlexibleChildrenCount - 1);\n } else {\n betweenMainDim = 0;\n }\n } else if (justifyContent === CSS_JUSTIFY_SPACE_AROUND) {\n // Space on the edges is half of the space between elements\n betweenMainDim = remainingMainDim /\n (flexibleChildrenCount + nonFlexibleChildrenCount);\n leadingMainDim = betweenMainDim / 2;\n }\n }\n\n // Position elements in the main axis and compute dimensions\n\n // At this point, all the children have their dimensions set. We need to\n // find their position. In order to do that, we accumulate data in\n // variables that are also useful to compute the total dimensions of the\n // container!\n var/*float*/ crossDim = 0;\n var/*float*/ mainDim = leadingMainDim +\n getLeadingPaddingAndBorder(node, mainAxis);\n\n for (i = startLine; i < endLine; ++i) {\n child = node.children[i];\n child.lineIndex = linesCount;\n\n if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&\n isPosDefined(child, leading[mainAxis])) {\n // In case the child is position absolute and has left/top being\n // defined, we override the position to whatever the user said\n // (and margin/border).\n child.layout[pos[mainAxis]] = getPosition(child, leading[mainAxis]) +\n getLeadingBorder(node, mainAxis) +\n getLeadingMargin(child, mainAxis);\n } else {\n // If the child is position absolute (without top/left) or relative,\n // we put it at the current accumulated offset.\n child.layout[pos[mainAxis]] += mainDim;\n\n // Define the trailing position accordingly.\n if (!isUndefined(node.layout[dim[mainAxis]])) {\n setTrailingPosition(node, child, mainAxis);\n }\n }\n\n // Now that we placed the element, we need to update the variables\n // We only need to do that for relative elements. Absolute elements\n // do not take part in that phase.\n if (getPositionType(child) === CSS_POSITION_RELATIVE) {\n // The main dimension is the sum of all the elements dimension plus\n // the spacing.\n mainDim += betweenMainDim + getDimWithMargin(child, mainAxis);\n // The cross dimension is the max of the elements dimension since there\n // can only be one element in that cross dimension.\n crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));\n }\n }\n\n var/*float*/ containerCrossAxis = node.layout[dim[crossAxis]];\n if (isUndefined(node.layout[dim[crossAxis]])) {\n containerCrossAxis = fmaxf(\n // For the cross dim, we add both sides at the end because the value\n // is aggregate via a max function. Intermediate negative values\n // can mess this computation otherwise\n boundAxis(node, crossAxis, crossDim + getPaddingAndBorderAxis(node, crossAxis)),\n getPaddingAndBorderAxis(node, crossAxis)\n );\n }\n\n // Position elements in the cross axis\n for (i = startLine; i < endLine; ++i) {\n child = node.children[i];\n\n if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&\n isPosDefined(child, leading[crossAxis])) {\n // In case the child is absolutely positionned and has a\n // top/left/bottom/right being set, we override all the previously\n // computed positions to set it correctly.\n child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]) +\n getLeadingBorder(node, crossAxis) +\n getLeadingMargin(child, crossAxis);\n\n } else {\n var/*float*/ leadingCrossDim = getLeadingPaddingAndBorder(node, crossAxis);\n\n // For a relative children, we're either using alignItems (parent) or\n // alignSelf (child) in order to determine the position in the cross axis\n if (getPositionType(child) === CSS_POSITION_RELATIVE) {\n var/*css_align_t*/ alignItem = getAlignItem(node, child);\n if (alignItem === CSS_ALIGN_STRETCH) {\n // You can only stretch if the dimension has not already been set\n // previously.\n if (!isDimDefined(child, crossAxis)) {\n child.layout[dim[crossAxis]] = fmaxf(\n boundAxis(child, crossAxis, containerCrossAxis -\n getPaddingAndBorderAxis(node, crossAxis) -\n getMarginAxis(child, crossAxis)),\n // You never want to go smaller than padding\n getPaddingAndBorderAxis(child, crossAxis)\n );\n }\n } else if (alignItem !== CSS_ALIGN_FLEX_START) {\n // The remaining space between the parent dimensions+padding and child\n // dimensions+margin.\n var/*float*/ remainingCrossDim = containerCrossAxis -\n getPaddingAndBorderAxis(node, crossAxis) -\n getDimWithMargin(child, crossAxis);\n\n if (alignItem === CSS_ALIGN_CENTER) {\n leadingCrossDim += remainingCrossDim / 2;\n } else { // CSS_ALIGN_FLEX_END\n leadingCrossDim += remainingCrossDim;\n }\n }\n }\n\n // And we apply the position\n child.layout[pos[crossAxis]] += linesCrossDim + leadingCrossDim;\n\n // Define the trailing position accordingly.\n if (!isUndefined(node.layout[dim[crossAxis]])) {\n setTrailingPosition(node, child, crossAxis);\n }\n }\n }\n\n linesCrossDim += crossDim;\n linesMainDim = fmaxf(linesMainDim, mainDim);\n linesCount += 1;\n startLine = endLine;\n }\n\n // \n //\n // Note(prenaux): More than one line, we need to layout the crossAxis\n // according to alignContent.\n //\n // Note that we could probably remove and handle the one line case\n // here too, but for the moment this is safer since it won't interfere with\n // previously working code.\n //\n // See specs:\n // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm\n // section 9.4\n //\n if (linesCount > 1 &&\n !isUndefined(node.layout[dim[crossAxis]])) {\n var/*float*/ nodeCrossAxisInnerSize = node.layout[dim[crossAxis]] -\n getPaddingAndBorderAxis(node, crossAxis);\n var/*float*/ remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;\n\n var/*float*/ crossDimLead = 0;\n var/*float*/ currentLead = getLeadingPaddingAndBorder(node, crossAxis);\n\n var/*css_align_t*/ alignContent = getAlignContent(node);\n if (alignContent === CSS_ALIGN_FLEX_END) {\n currentLead += remainingAlignContentDim;\n } else if (alignContent === CSS_ALIGN_CENTER) {\n currentLead += remainingAlignContentDim / 2;\n } else if (alignContent === CSS_ALIGN_STRETCH) {\n if (nodeCrossAxisInnerSize > linesCrossDim) {\n crossDimLead = (remainingAlignContentDim / linesCount);\n }\n }\n\n var/*int*/ endIndex = 0;\n for (i = 0; i < linesCount; ++i) {\n var/*int*/ startIndex = endIndex;\n\n // compute the line's height and find the endIndex\n var/*float*/ lineHeight = 0;\n for (ii = startIndex; ii < node.children.length; ++ii) {\n child = node.children[ii];\n if (getPositionType(child) !== CSS_POSITION_RELATIVE) {\n continue;\n }\n if (child.lineIndex !== i) {\n break;\n }\n if (!isUndefined(child.layout[dim[crossAxis]])) {\n lineHeight = fmaxf(\n lineHeight,\n child.layout[dim[crossAxis]] + getMarginAxis(child, crossAxis)\n );\n }\n }\n endIndex = ii;\n lineHeight += crossDimLead;\n\n for (ii = startIndex; ii < endIndex; ++ii) {\n child = node.children[ii];\n if (getPositionType(child) !== CSS_POSITION_RELATIVE) {\n continue;\n }\n\n var/*css_align_t*/ alignContentAlignItem = getAlignItem(node, child);\n if (alignContentAlignItem === CSS_ALIGN_FLEX_START) {\n child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);\n } else if (alignContentAlignItem === CSS_ALIGN_FLEX_END) {\n child.layout[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child.layout[dim[crossAxis]];\n } else if (alignContentAlignItem === CSS_ALIGN_CENTER) {\n var/*float*/ childHeight = child.layout[dim[crossAxis]];\n child.layout[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2;\n } else if (alignContentAlignItem === CSS_ALIGN_STRETCH) {\n child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);\n // TODO(prenaux): Correctly set the height of items with undefined\n // (auto) crossAxis dimension.\n }\n }\n\n currentLead += lineHeight;\n }\n }\n\n var/*bool*/ needsMainTrailingPos = false;\n var/*bool*/ needsCrossTrailingPos = false;\n\n // If the user didn't specify a width or height, and it has not been set\n // by the container, then we set it via the children.\n if (isUndefined(node.layout[dim[mainAxis]])) {\n node.layout[dim[mainAxis]] = fmaxf(\n // We're missing the last padding at this point to get the final\n // dimension\n boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)),\n // We can never assign a width smaller than the padding and borders\n getPaddingAndBorderAxis(node, mainAxis)\n );\n\n needsMainTrailingPos = true;\n }\n\n if (isUndefined(node.layout[dim[crossAxis]])) {\n node.layout[dim[crossAxis]] = fmaxf(\n // For the cross dim, we add both sides at the end because the value\n // is aggregate via a max function. Intermediate negative values\n // can mess this computation otherwise\n boundAxis(node, crossAxis, linesCrossDim + getPaddingAndBorderAxis(node, crossAxis)),\n getPaddingAndBorderAxis(node, crossAxis)\n );\n\n needsCrossTrailingPos = true;\n }\n\n // Set trailing position if necessary\n if (needsMainTrailingPos || needsCrossTrailingPos) {\n for (i = 0; i < node.children.length; ++i) {\n child = node.children[i];\n\n if (needsMainTrailingPos) {\n setTrailingPosition(node, child, mainAxis);\n }\n\n if (needsCrossTrailingPos) {\n setTrailingPosition(node, child, crossAxis);\n }\n }\n }\n\n // Calculate dimensions for absolutely positioned elements\n for (i = 0; i < node.children.length; ++i) {\n child = node.children[i];\n if (getPositionType(child) === CSS_POSITION_ABSOLUTE) {\n // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both\n // left and right or top and bottom).\n for (ii = 0; ii < 2; ii++) {\n axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;\n if (!isUndefined(node.layout[dim[axis]]) &&\n !isDimDefined(child, axis) &&\n isPosDefined(child, leading[axis]) &&\n isPosDefined(child, trailing[axis])) {\n child.layout[dim[axis]] = fmaxf(\n boundAxis(child, axis, node.layout[dim[axis]] -\n getBorderAxis(node, axis) -\n getMarginAxis(child, axis) -\n getPosition(child, leading[axis]) -\n getPosition(child, trailing[axis])\n ),\n // You never want to go smaller than padding\n getPaddingAndBorderAxis(child, axis)\n );\n }\n }\n for (ii = 0; ii < 2; ii++) {\n axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;\n if (isPosDefined(child, trailing[axis]) &&\n !isPosDefined(child, leading[axis])) {\n child.layout[leading[axis]] =\n node.layout[dim[axis]] -\n child.layout[dim[axis]] -\n getPosition(child, trailing[axis]);\n }\n }\n }\n }\n }\n\n return {\n computeLayout: layoutNode,\n fillNodes: fillNodes\n };\n})();\n\n// This module export is only used for the purposes of unit testing this file. When\n// the library is packaged this file is included within css-layout.js which forms \n// the public API.\nif (typeof exports === 'object') {\n module.exports = computeLayout;\n}\n\n return function(node) {\n computeLayout.fillNodes(node);\n computeLayout.computeLayout(node);\n };\n}));\n"]} \ No newline at end of file +{"version":3,"file":"css-layout.min.js","sources":["css-layout.js"],"names":["root","factory","define","amd","exports","module","computeLayout","this","capitalizeFirst","str","charAt","toUpperCase","slice","getSpacing","node","type","suffix","locations","i","length","location","key","style","fillNodes","layout","width","undefined","height","top","left","right","bottom","children","forEach","getPositiveSpacing","isUndefined","value","isRowDirection","flexDirection","CSS_FLEX_DIRECTION_ROW","CSS_FLEX_DIRECTION_ROW_REVERSE","isColumnDirection","CSS_FLEX_DIRECTION_COLUMN","CSS_FLEX_DIRECTION_COLUMN_REVERSE","getLeadingLocations","axis","leading","unshift","getTrailingLocations","trailing","getMargin","getLeadingMargin","getTrailingMargin","getPadding","getLeadingPadding","getTrailingPadding","getBorder","getLeadingBorder","getTrailingBorder","getLeadingPaddingAndBorder","getTrailingPaddingAndBorder","getBorderAxis","getMarginAxis","getPaddingAndBorderAxis","getJustifyContent","justifyContent","getAlignContent","alignContent","getAlignItem","child","alignSelf","alignItems","resolveAxis","direction","CSS_DIRECTION_RTL","resolveDirection","parentDirection","CSS_DIRECTION_INHERIT","CSS_DIRECTION_LTR","getFlexDirection","getCrossFlexDirection","getPositionType","position","isFlex","CSS_POSITION_RELATIVE","flex","isFlexWrap","flexWrap","getDimWithMargin","dim","isDimDefined","isPosDefined","pos","isMeasureDefined","getPosition","boundAxis","min","row","minWidth","row-reverse","column","minHeight","column-reverse","max","maxWidth","maxHeight","boundValue","fmaxf","a","b","setDimensionFromStyle","setTrailingPosition","getRelativePosition","layoutNode","parentMaxWidth","mainAxis","crossAxis","resolvedRowAxis","childCount","paddingAndBorderAxisResolvedRow","isResolvedRowDimDefined","CSS_UNDEFINED","isRowUndefined","isColumnUndefined","measureDim","measure","ii","isNodeFlexWrap","leadingPaddingAndBorderMain","leadingPaddingAndBorderCross","paddingAndBorderAxisMain","paddingAndBorderAxisCross","isMainDimDefined","isCrossDimDefined","isMainRowDirection","firstAbsoluteChild","currentAbsoluteChild","definedMainDim","startLine","endLine","alreadyComputedNextLayout","linesCrossDim","linesMainDim","linesCount","mainContentDim","flexibleChildrenCount","totalFlexible","nonFlexibleChildrenCount","isSimpleStackMain","CSS_JUSTIFY_FLEX_START","CSS_JUSTIFY_CENTER","firstComplexMain","isSimpleStackCross","firstComplexCross","firstFlexChild","currentFlexChild","mainDim","crossDim","lineIndex","nextAbsoluteChild","nextFlexChild","alignItem","CSS_ALIGN_STRETCH","CSS_POSITION_ABSOLUTE","nextContentDim","CSS_ALIGN_FLEX_START","leadingMainDim","betweenMainDim","remainingMainDim","baseMainDim","boundMainDim","flexibleMainDim","CSS_JUSTIFY_FLEX_END","CSS_JUSTIFY_SPACE_BETWEEN","CSS_JUSTIFY_SPACE_AROUND","containerCrossAxis","leadingCrossDim","remainingCrossDim","CSS_ALIGN_CENTER","nodeCrossAxisInnerSize","remainingAlignContentDim","crossDimLead","currentLead","CSS_ALIGN_FLEX_END","endIndex","startIndex","lineHeight","alignContentA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,KAChB2F,GAAqBhH,OAAOiE,GAAI5C,KAChCiD,EAAY0C,GAAsBvF,GAASJ,KAIjDwB,IAAQmE,GACRA,GAAuBA,GAAqBuB,kBAC5C1F,GAAM0F,kBAAoB,MAhiC9B,GAAItC,GAEA5C,EAAwB,UACxBC,EAAoB,MACpBJ,EAAoB,MAEpBnC,EAAyB,MACzBC,EAAiC,cACjCE,EAA4B,SAC5BC,EAAoC,iBAEpC0G,EAAyB,aACzBC,EAAqB,SACrBsB,GAAuB,WACvBC,GAA4B,gBAC5BC,GAA2B,eAE3BT,GAAuB,aACvBa,GAAmB,SACnBK,GAAqB,WACrBrB,GAAoB,UAEpB9E,GAAwB,WACxB+E,GAAwB,WAExBrH,IACFmD,IAAO,OACPE,cAAe,QACfC,OAAU,MACVE,iBAAkB,UAEhBrD,IACFgD,IAAO,QACPE,cAAe,OACfC,OAAU,SACVE,iBAAkB,OAEhBV,IACFK,IAAO,OACPE,cAAe,QACfC,OAAU,MACVE,iBAAkB,UAEhBb,IACFQ,IAAO,QACPE,cAAe,QACfC,OAAU,SACVE,iBAAkB,SAq/BpB,QACEhG,cAAe2G,EACf1F,UAAWA,KAYX,OALmB,gBAAZnB,WACTC,OAAOD,QAAUE,GAIR,SAASQ,GACdR,EAAciB,UAAUT,GACxBR,EAAcA,cAAcQ","sourcesContent":["// UMD (Universal Module Definition)\n// See https://github.com/umdjs/umd for reference\n//\n// This file uses the following specific UMD implementation:\n// https://github.com/umdjs/umd/blob/master/returnExports.js\n(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define([], factory);\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like environments that support module.exports,\n // like Node.\n module.exports = factory();\n } else {\n // Browser globals (root is window)\n root.computeLayout = factory();\n }\n}(this, function () {\n /**\n * Copyright (c) 2014, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\nvar computeLayout = (function() {\n\n var CSS_UNDEFINED;\n\n var CSS_DIRECTION_INHERIT = 'inherit';\n var CSS_DIRECTION_LTR = 'ltr';\n var CSS_DIRECTION_RTL = 'rtl';\n\n var CSS_FLEX_DIRECTION_ROW = 'row';\n var CSS_FLEX_DIRECTION_ROW_REVERSE = 'row-reverse';\n var CSS_FLEX_DIRECTION_COLUMN = 'column';\n var CSS_FLEX_DIRECTION_COLUMN_REVERSE = 'column-reverse';\n\n var CSS_JUSTIFY_FLEX_START = 'flex-start';\n var CSS_JUSTIFY_CENTER = 'center';\n var CSS_JUSTIFY_FLEX_END = 'flex-end';\n var CSS_JUSTIFY_SPACE_BETWEEN = 'space-between';\n var CSS_JUSTIFY_SPACE_AROUND = 'space-around';\n\n var CSS_ALIGN_FLEX_START = 'flex-start';\n var CSS_ALIGN_CENTER = 'center';\n var CSS_ALIGN_FLEX_END = 'flex-end';\n var CSS_ALIGN_STRETCH = 'stretch';\n\n var CSS_POSITION_RELATIVE = 'relative';\n var CSS_POSITION_ABSOLUTE = 'absolute';\n\n var leading = {\n 'row': 'left',\n 'row-reverse': 'right',\n 'column': 'top',\n 'column-reverse': 'bottom'\n };\n var trailing = {\n 'row': 'right',\n 'row-reverse': 'left',\n 'column': 'bottom',\n 'column-reverse': 'top'\n };\n var pos = {\n 'row': 'left',\n 'row-reverse': 'right',\n 'column': 'top',\n 'column-reverse': 'bottom'\n };\n var dim = {\n 'row': 'width',\n 'row-reverse': 'width',\n 'column': 'height',\n 'column-reverse': 'height'\n };\n\n function capitalizeFirst(str) {\n return str.charAt(0).toUpperCase() + str.slice(1);\n }\n\n function getSpacing(node, type, suffix, locations) {\n for (var i = 0; i < locations.length; ++i) {\n var location = locations[i];\n\n var key = type + capitalizeFirst(location) + suffix;\n if (key in node.style) {\n return node.style[key];\n }\n\n key = type + suffix;\n if (key in node.style) {\n return node.style[key];\n }\n }\n\n return 0;\n }\n\n // When transpiled to Java / C the node type has layout, children and style\n // properties. For the JavaScript version this function adds these properties\n // if they don't already exist.\n function fillNodes(node) {\n if (!node.layout) {\n node.layout = {\n width: undefined,\n height: undefined,\n top: 0,\n left: 0,\n right: 0,\n bottom: 0\n };\n }\n\n if (!node.style) {\n node.style = {};\n }\n\n if (!node.children) {\n node.children = [];\n }\n node.children.forEach(fillNodes);\n return node;\n }\n\n function getPositiveSpacing(node, type, suffix, locations) {\n for (var i = 0; i < locations.length; ++i) {\n var location = locations[i];\n\n var key = type + capitalizeFirst(location) + suffix;\n if (key in node.style && node.style[key] >= 0) {\n return node.style[key];\n }\n\n key = type + suffix;\n if (key in node.style && node.style[key] >= 0) {\n return node.style[key];\n }\n }\n\n return 0;\n }\n\n function isUndefined(value) {\n return value === undefined;\n }\n\n function isRowDirection(flexDirection) {\n return flexDirection === CSS_FLEX_DIRECTION_ROW ||\n flexDirection === CSS_FLEX_DIRECTION_ROW_REVERSE;\n }\n\n function isColumnDirection(flexDirection) {\n return flexDirection === CSS_FLEX_DIRECTION_COLUMN ||\n flexDirection === CSS_FLEX_DIRECTION_COLUMN_REVERSE;\n }\n\n function getLeadingLocations(axis) {\n var locations = [leading[axis]];\n if (isRowDirection(axis)) {\n locations.unshift('start');\n }\n\n return locations;\n }\n\n function getTrailingLocations(axis) {\n var locations = [trailing[axis]];\n if (isRowDirection(axis)) {\n locations.unshift('end');\n }\n\n return locations;\n }\n\n function getMargin(node, locations) {\n return getSpacing(node, 'margin', '', locations);\n }\n\n function getLeadingMargin(node, axis) {\n return getMargin(node, getLeadingLocations(axis));\n }\n\n function getTrailingMargin(node, axis) {\n return getMargin(node, getTrailingLocations(axis));\n }\n\n function getPadding(node, locations) {\n return getPositiveSpacing(node, 'padding', '', locations);\n }\n\n function getLeadingPadding(node, axis) {\n return getPadding(node, getLeadingLocations(axis));\n }\n\n function getTrailingPadding(node, axis) {\n return getPadding(node, getTrailingLocations(axis));\n }\n\n function getBorder(node, locations) {\n return getPositiveSpacing(node, 'border', 'Width', locations);\n }\n\n function getLeadingBorder(node, axis) {\n return getBorder(node, getLeadingLocations(axis));\n }\n\n function getTrailingBorder(node, axis) {\n return getBorder(node, getTrailingLocations(axis));\n }\n\n function getLeadingPaddingAndBorder(node, axis) {\n return getLeadingPadding(node, axis) + getLeadingBorder(node, axis);\n }\n\n function getTrailingPaddingAndBorder(node, axis) {\n return getTrailingPadding(node, axis) + getTrailingBorder(node, axis);\n }\n\n function getBorderAxis(node, axis) {\n return getLeadingBorder(node, axis) + getTrailingBorder(node, axis);\n }\n\n function getMarginAxis(node, axis) {\n return getLeadingMargin(node, axis) + getTrailingMargin(node, axis);\n }\n\n function getPaddingAndBorderAxis(node, axis) {\n return getLeadingPaddingAndBorder(node, axis) +\n getTrailingPaddingAndBorder(node, axis);\n }\n\n function getJustifyContent(node) {\n if ('justifyContent' in node.style) {\n return node.style.justifyContent;\n }\n return 'flex-start';\n }\n\n function getAlignContent(node) {\n if ('alignContent' in node.style) {\n return node.style.alignContent;\n }\n return 'flex-start';\n }\n\n function getAlignItem(node, child) {\n if ('alignSelf' in child.style) {\n return child.style.alignSelf;\n }\n if ('alignItems' in node.style) {\n return node.style.alignItems;\n }\n return 'stretch';\n }\n\n function resolveAxis(axis, direction) {\n if (direction === CSS_DIRECTION_RTL) {\n if (axis === CSS_FLEX_DIRECTION_ROW) {\n return CSS_FLEX_DIRECTION_ROW_REVERSE;\n } else if (axis === CSS_FLEX_DIRECTION_ROW_REVERSE) {\n return CSS_FLEX_DIRECTION_ROW;\n }\n }\n\n return axis;\n }\n\n function resolveDirection(node, parentDirection) {\n var direction;\n if ('direction' in node.style) {\n direction = node.style.direction;\n } else {\n direction = CSS_DIRECTION_INHERIT;\n }\n\n if (direction === CSS_DIRECTION_INHERIT) {\n direction = (parentDirection === undefined ? CSS_DIRECTION_LTR : parentDirection);\n }\n\n return direction;\n }\n\n function getFlexDirection(node) {\n if ('flexDirection' in node.style) {\n return node.style.flexDirection;\n }\n return CSS_FLEX_DIRECTION_COLUMN;\n }\n\n function getCrossFlexDirection(flexDirection, direction) {\n if (isColumnDirection(flexDirection)) {\n return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);\n } else {\n return CSS_FLEX_DIRECTION_COLUMN;\n }\n }\n\n function getPositionType(node) {\n if ('position' in node.style) {\n return node.style.position;\n }\n return 'relative';\n }\n\n function isFlex(node) {\n return (\n getPositionType(node) === CSS_POSITION_RELATIVE &&\n node.style.flex > 0\n );\n }\n\n function isFlexWrap(node) {\n return node.style.flexWrap === 'wrap';\n }\n\n function getDimWithMargin(node, axis) {\n return node.layout[dim[axis]] + getMarginAxis(node, axis);\n }\n\n function isDimDefined(node, axis) {\n return !isUndefined(node.style[dim[axis]]) && node.style[dim[axis]] >= 0;\n }\n\n function isPosDefined(node, pos) {\n return !isUndefined(node.style[pos]);\n }\n\n function isMeasureDefined(node) {\n return 'measure' in node.style;\n }\n\n function getPosition(node, pos) {\n if (pos in node.style) {\n return node.style[pos];\n }\n return 0;\n }\n\n function boundAxis(node, axis, value) {\n var min = {\n 'row': node.style.minWidth,\n 'row-reverse': node.style.minWidth,\n 'column': node.style.minHeight,\n 'column-reverse': node.style.minHeight\n }[axis];\n\n var max = {\n 'row': node.style.maxWidth,\n 'row-reverse': node.style.maxWidth,\n 'column': node.style.maxHeight,\n 'column-reverse': node.style.maxHeight\n }[axis];\n\n var boundValue = value;\n if (!isUndefined(max) && max >= 0 && boundValue > max) {\n boundValue = max;\n }\n if (!isUndefined(min) && min >= 0 && boundValue < min) {\n boundValue = min;\n }\n return boundValue;\n }\n\n function fmaxf(a, b) {\n if (a > b) {\n return a;\n }\n return b;\n }\n\n // When the user specifically sets a value for width or height\n function setDimensionFromStyle(node, axis) {\n // The parent already computed us a width or height. We just skip it\n if (!isUndefined(node.layout[dim[axis]])) {\n return;\n }\n // We only run if there's a width or height defined\n if (!isDimDefined(node, axis)) {\n return;\n }\n\n // The dimensions can never be smaller than the padding and border\n node.layout[dim[axis]] = fmaxf(\n boundAxis(node, axis, node.style[dim[axis]]),\n getPaddingAndBorderAxis(node, axis)\n );\n }\n\n function setTrailingPosition(node, child, axis) {\n child.layout[trailing[axis]] = node.layout[dim[axis]] -\n child.layout[dim[axis]] - child.layout[pos[axis]];\n }\n\n // If both left and right are defined, then use left. Otherwise return\n // +left or -right depending on which is defined.\n function getRelativePosition(node, axis) {\n if (leading[axis] in node.style) {\n return getPosition(node, leading[axis]);\n }\n return -getPosition(node, trailing[axis]);\n }\n\n function layoutNode(node, parentMaxWidth, /*css_direction_t*/parentDirection) {\n var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);\n var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction);\n var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction);\n var/*(c)!css_flex_direction_t*//*(java)!int*/ resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);\n\n // Handle width and height style attributes\n setDimensionFromStyle(node, mainAxis);\n setDimensionFromStyle(node, crossAxis);\n\n // Set the resolved resolution in the node's layout\n node.layout.direction = direction;\n\n // The position is set by the parent, but we need to complete it with a\n // delta composed of the margin and left/top/right/bottom\n node.layout[leading[mainAxis]] += getLeadingMargin(node, mainAxis) +\n getRelativePosition(node, mainAxis);\n node.layout[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) +\n getRelativePosition(node, mainAxis);\n node.layout[leading[crossAxis]] += getLeadingMargin(node, crossAxis) +\n getRelativePosition(node, crossAxis);\n node.layout[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) +\n getRelativePosition(node, crossAxis);\n\n // Inline immutable values from the target node to avoid excessive method\n // invocations during the layout calculation.\n var/*int*/ childCount = node.children.length;\n var/*float*/ paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);\n\n if (isMeasureDefined(node)) {\n var/*bool*/ isResolvedRowDimDefined = !isUndefined(node.layout[dim[resolvedRowAxis]]);\n\n var/*float*/ width = CSS_UNDEFINED;\n if (isDimDefined(node, resolvedRowAxis)) {\n width = node.style.width;\n } else if (isResolvedRowDimDefined) {\n width = node.layout[dim[resolvedRowAxis]];\n } else {\n width = parentMaxWidth -\n getMarginAxis(node, resolvedRowAxis);\n }\n width -= paddingAndBorderAxisResolvedRow;\n\n // We only need to give a dimension for the text if we haven't got any\n // for it computed yet. It can either be from the style attribute or because\n // the element is flexible.\n var/*bool*/ isRowUndefined = !isDimDefined(node, resolvedRowAxis) && !isResolvedRowDimDefined;\n var/*bool*/ isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) &&\n isUndefined(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]]);\n\n // Let's not measure the text if we already know both dimensions\n if (isRowUndefined || isColumnUndefined) {\n var/*css_dim_t*/ measureDim = node.style.measure(\n /*(c)!node->context,*/\n /*(java)!layoutContext.measureOutput,*/\n width\n );\n if (isRowUndefined) {\n node.layout.width = measureDim.width +\n paddingAndBorderAxisResolvedRow;\n }\n if (isColumnUndefined) {\n node.layout.height = measureDim.height +\n getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);\n }\n }\n if (childCount === 0) {\n return;\n }\n }\n\n var/*bool*/ isNodeFlexWrap = isFlexWrap(node);\n\n var/*css_justify_t*/ justifyContent = getJustifyContent(node);\n\n var/*float*/ leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis);\n var/*float*/ leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis);\n var/*float*/ paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis);\n var/*float*/ paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis);\n\n var/*bool*/ isMainDimDefined = !isUndefined(node.layout[dim[mainAxis]]);\n var/*bool*/ isCrossDimDefined = !isUndefined(node.layout[dim[crossAxis]]);\n var/*bool*/ isMainRowDirection = isRowDirection(mainAxis);\n\n var/*int*/ i;\n var/*int*/ ii;\n var/*css_node_t**/ child;\n var/*(c)!css_flex_direction_t*//*(java)!int*/ axis;\n\n var/*css_node_t**/ firstAbsoluteChild = null;\n var/*css_node_t**/ currentAbsoluteChild = null;\n\n var/*float*/ definedMainDim = CSS_UNDEFINED;\n if (isMainDimDefined) {\n definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain;\n }\n\n // We want to execute the next two loops one per line with flex-wrap\n var/*int*/ startLine = 0;\n var/*int*/ endLine = 0;\n // var/*int*/ nextOffset = 0;\n var/*int*/ alreadyComputedNextLayout = 0;\n // We aggregate the total dimensions of the container in those two variables\n var/*float*/ linesCrossDim = 0;\n var/*float*/ linesMainDim = 0;\n var/*int*/ linesCount = 0;\n while (endLine < childCount) {\n // Layout non flexible children and count children by type\n\n // mainContentDim is accumulation of the dimensions and margin of all the\n // non flexible children. This will be used in order to either set the\n // dimensions of the node if none already exist, or to compute the\n // remaining space left for the flexible children.\n var/*float*/ mainContentDim = 0;\n\n // There are three kind of children, non flexible, flexible and absolute.\n // We need to know how many there are in order to distribute the space.\n var/*int*/ flexibleChildrenCount = 0;\n var/*float*/ totalFlexible = 0;\n var/*int*/ nonFlexibleChildrenCount = 0;\n\n // Use the line loop to position children in the main axis for as long\n // as they are using a simple stacking behaviour. Children that are\n // immediately stacked in the initial loop will not be touched again\n // in .\n var/*bool*/ isSimpleStackMain =\n (isMainDimDefined && justifyContent == CSS_JUSTIFY_FLEX_START) ||\n (!isMainDimDefined && justifyContent != CSS_JUSTIFY_CENTER);\n var/*int*/ firstComplexMain = (isSimpleStackMain ? childCount : startLine);\n\n // Use the initial line loop to position children in the cross axis for\n // as long as they are relatively positioned with alignment STRETCH or\n // FLEX_START. Children that are immediately stacked in the initial loop\n // will not be touched again in .\n var/*bool*/ isSimpleStackCross = true;\n var/*int*/ firstComplexCross = childCount;\n\n var/*css_node_t**/ firstFlexChild = null;\n var/*css_node_t**/ currentFlexChild = null;\n\n var/*float*/ mainDim = leadingPaddingAndBorderMain;\n var/*float*/ crossDim = 0;\n\n var/*float*/ maxWidth;\n for (i = startLine; i < childCount; ++i) {\n child = node.children[i];\n child.lineIndex = linesCount;\n\n child.nextAbsoluteChild = null;\n child.nextFlexChild = null;\n\n var/*css_align_t*/ alignItem = getAlignItem(node, child);\n\n // Pre-fill cross axis dimensions when the child is using stretch before\n // we call the recursive layout pass\n if (alignItem === CSS_ALIGN_STRETCH &&\n getPositionType(child) === CSS_POSITION_RELATIVE &&\n isCrossDimDefined &&\n !isDimDefined(child, crossAxis)) {\n child.layout[dim[crossAxis]] = fmaxf(\n boundAxis(child, crossAxis, node.layout[dim[crossAxis]] -\n paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),\n // You never want to go smaller than padding\n getPaddingAndBorderAxis(child, crossAxis)\n );\n } else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) {\n // Store a private linked list of absolutely positioned children\n // so that we can efficiently traverse them later.\n if (firstAbsoluteChild === null) {\n firstAbsoluteChild = child;\n }\n if (currentAbsoluteChild !== null) {\n currentAbsoluteChild.nextAbsoluteChild = child;\n }\n currentAbsoluteChild = child;\n\n // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both\n // left and right or top and bottom).\n for (ii = 0; ii < 2; ii++) {\n axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;\n if (!isUndefined(node.layout[dim[axis]]) &&\n !isDimDefined(child, axis) &&\n isPosDefined(child, leading[axis]) &&\n isPosDefined(child, trailing[axis])) {\n child.layout[dim[axis]] = fmaxf(\n boundAxis(child, axis, node.layout[dim[axis]] -\n getPaddingAndBorderAxis(node, axis) -\n getMarginAxis(child, axis) -\n getPosition(child, leading[axis]) -\n getPosition(child, trailing[axis])),\n // You never want to go smaller than padding\n getPaddingAndBorderAxis(child, axis)\n );\n }\n }\n }\n\n var/*float*/ nextContentDim = 0;\n\n // It only makes sense to consider a child flexible if we have a computed\n // dimension for the node.\n if (isMainDimDefined && isFlex(child)) {\n flexibleChildrenCount++;\n totalFlexible += child.style.flex;\n\n // Store a private linked list of flexible children so that we can\n // efficiently traverse them later.\n if (firstFlexChild === null) {\n firstFlexChild = child;\n }\n if (currentFlexChild !== null) {\n currentFlexChild.nextFlexChild = child;\n }\n currentFlexChild = child;\n\n // Even if we don't know its exact size yet, we already know the padding,\n // border and margin. We'll use this partial information, which represents\n // the smallest possible size for the child, to compute the remaining\n // available space.\n nextContentDim = getPaddingAndBorderAxis(child, mainAxis) +\n getMarginAxis(child, mainAxis);\n\n } else {\n maxWidth = CSS_UNDEFINED;\n if (!isMainRowDirection) {\n if (isDimDefined(node, resolvedRowAxis)) {\n maxWidth = node.layout[dim[resolvedRowAxis]] -\n paddingAndBorderAxisResolvedRow;\n } else {\n maxWidth = parentMaxWidth -\n getMarginAxis(node, resolvedRowAxis) -\n paddingAndBorderAxisResolvedRow;\n }\n }\n\n // This is the main recursive call. We layout non flexible children.\n if (alreadyComputedNextLayout === 0) {\n layoutNode(/*(java)!layoutContext, */child, maxWidth, direction);\n }\n\n // Absolute positioned elements do not take part of the layout, so we\n // don't use them to compute mainContentDim\n if (getPositionType(child) === CSS_POSITION_RELATIVE) {\n nonFlexibleChildrenCount++;\n // At this point we know the final size and margin of the element.\n nextContentDim = getDimWithMargin(child, mainAxis);\n }\n }\n\n // The element we are about to add would make us go to the next line\n if (isNodeFlexWrap &&\n isMainDimDefined &&\n mainContentDim + nextContentDim > definedMainDim &&\n // If there's only one element, then it's bigger than the content\n // and needs its own line\n i !== startLine) {\n nonFlexibleChildrenCount--;\n alreadyComputedNextLayout = 1;\n break;\n }\n\n // Disable simple stacking in the main axis for the current line as\n // we found a non-trivial child. The remaining children will be laid out\n // in .\n if (isSimpleStackMain &&\n (getPositionType(child) != CSS_POSITION_RELATIVE || isFlex(child))) {\n isSimpleStackMain = false;\n firstComplexMain = i;\n }\n\n // Disable simple stacking in the cross axis for the current line as\n // we found a non-trivial child. The remaining children will be laid out\n // in .\n if (isSimpleStackCross &&\n (getPositionType(child) != CSS_POSITION_RELATIVE ||\n (alignItem !== CSS_ALIGN_STRETCH && alignItem != CSS_ALIGN_FLEX_START) ||\n isUndefined(child.layout[dim[crossAxis]]))) {\n isSimpleStackCross = false;\n firstComplexCross = i;\n }\n\n if (isSimpleStackMain) {\n child.layout[pos[mainAxis]] += mainDim;\n if (isMainDimDefined) {\n setTrailingPosition(node, child, mainAxis);\n }\n\n mainDim += getDimWithMargin(child, mainAxis);\n crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));\n }\n\n if (isSimpleStackCross) {\n child.layout[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross;\n if (isCrossDimDefined) {\n setTrailingPosition(node, child, crossAxis);\n }\n }\n\n alreadyComputedNextLayout = 0;\n mainContentDim += nextContentDim;\n endLine = i + 1;\n }\n\n // Layout flexible children and allocate empty space\n\n // In order to position the elements in the main axis, we have two\n // controls. The space between the beginning and the first element\n // and the space between each two elements.\n var/*float*/ leadingMainDim = 0;\n var/*float*/ betweenMainDim = 0;\n\n // The remaining available space that needs to be allocated\n var/*float*/ remainingMainDim = 0;\n if (isMainDimDefined) {\n remainingMainDim = definedMainDim - mainContentDim;\n } else {\n remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim;\n }\n\n // If there are flexible children in the mix, they are going to fill the\n // remaining space\n if (flexibleChildrenCount !== 0) {\n var/*float*/ flexibleMainDim = remainingMainDim / totalFlexible;\n var/*float*/ baseMainDim;\n var/*float*/ boundMainDim;\n\n // If the flex share of remaining space doesn't meet min/max bounds,\n // remove this child from flex calculations.\n currentFlexChild = firstFlexChild;\n while (currentFlexChild !== null) {\n baseMainDim = flexibleMainDim * currentFlexChild.style.flex +\n getPaddingAndBorderAxis(currentFlexChild, mainAxis);\n boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim);\n\n if (baseMainDim !== boundMainDim) {\n remainingMainDim -= boundMainDim;\n totalFlexible -= currentFlexChild.style.flex;\n }\n\n currentFlexChild = currentFlexChild.nextFlexChild;\n }\n flexibleMainDim = remainingMainDim / totalFlexible;\n\n // The non flexible children can overflow the container, in this case\n // we should just assume that there is no space available.\n if (flexibleMainDim < 0) {\n flexibleMainDim = 0;\n }\n\n currentFlexChild = firstFlexChild;\n while (currentFlexChild !== null) {\n // At this point we know the final size of the element in the main\n // dimension\n currentFlexChild.layout[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis,\n flexibleMainDim * currentFlexChild.style.flex +\n getPaddingAndBorderAxis(currentFlexChild, mainAxis)\n );\n\n maxWidth = CSS_UNDEFINED;\n if (isDimDefined(node, resolvedRowAxis)) {\n maxWidth = node.layout[dim[resolvedRowAxis]] -\n paddingAndBorderAxisResolvedRow;\n } else if (!isMainRowDirection) {\n maxWidth = parentMaxWidth -\n getMarginAxis(node, resolvedRowAxis) -\n paddingAndBorderAxisResolvedRow;\n }\n\n // And we recursively call the layout algorithm for this child\n layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, direction);\n\n child = currentFlexChild;\n currentFlexChild = currentFlexChild.nextFlexChild;\n child.nextFlexChild = null;\n }\n\n // We use justifyContent to figure out how to allocate the remaining\n // space available\n } else if (justifyContent !== CSS_JUSTIFY_FLEX_START) {\n if (justifyContent === CSS_JUSTIFY_CENTER) {\n leadingMainDim = remainingMainDim / 2;\n } else if (justifyContent === CSS_JUSTIFY_FLEX_END) {\n leadingMainDim = remainingMainDim;\n } else if (justifyContent === CSS_JUSTIFY_SPACE_BETWEEN) {\n remainingMainDim = fmaxf(remainingMainDim, 0);\n if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 !== 0) {\n betweenMainDim = remainingMainDim /\n (flexibleChildrenCount + nonFlexibleChildrenCount - 1);\n } else {\n betweenMainDim = 0;\n }\n } else if (justifyContent === CSS_JUSTIFY_SPACE_AROUND) {\n // Space on the edges is half of the space between elements\n betweenMainDim = remainingMainDim /\n (flexibleChildrenCount + nonFlexibleChildrenCount);\n leadingMainDim = betweenMainDim / 2;\n }\n }\n\n // Position elements in the main axis and compute dimensions\n\n // At this point, all the children have their dimensions set. We need to\n // find their position. In order to do that, we accumulate data in\n // variables that are also useful to compute the total dimensions of the\n // container!\n mainDim += leadingMainDim;\n\n for (i = firstComplexMain; i < endLine; ++i) {\n child = node.children[i];\n\n if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&\n isPosDefined(child, leading[mainAxis])) {\n // In case the child is position absolute and has left/top being\n // defined, we override the position to whatever the user said\n // (and margin/border).\n child.layout[pos[mainAxis]] = getPosition(child, leading[mainAxis]) +\n getLeadingBorder(node, mainAxis) +\n getLeadingMargin(child, mainAxis);\n } else {\n // If the child is position absolute (without top/left) or relative,\n // we put it at the current accumulated offset.\n child.layout[pos[mainAxis]] += mainDim;\n\n // Define the trailing position accordingly.\n if (isMainDimDefined) {\n setTrailingPosition(node, child, mainAxis);\n }\n\n // Now that we placed the element, we need to update the variables\n // We only need to do that for relative elements. Absolute elements\n // do not take part in that phase.\n if (getPositionType(child) === CSS_POSITION_RELATIVE) {\n // The main dimension is the sum of all the elements dimension plus\n // the spacing.\n mainDim += betweenMainDim + getDimWithMargin(child, mainAxis);\n // The cross dimension is the max of the elements dimension since there\n // can only be one element in that cross dimension.\n crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));\n }\n }\n }\n\n var/*float*/ containerCrossAxis = node.layout[dim[crossAxis]];\n if (!isCrossDimDefined) {\n containerCrossAxis = fmaxf(\n // For the cross dim, we add both sides at the end because the value\n // is aggregate via a max function. Intermediate negative values\n // can mess this computation otherwise\n boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross),\n paddingAndBorderAxisCross\n );\n }\n\n // Position elements in the cross axis\n for (i = firstComplexCross; i < endLine; ++i) {\n child = node.children[i];\n\n if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&\n isPosDefined(child, leading[crossAxis])) {\n // In case the child is absolutely positionned and has a\n // top/left/bottom/right being set, we override all the previously\n // computed positions to set it correctly.\n child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]) +\n getLeadingBorder(node, crossAxis) +\n getLeadingMargin(child, crossAxis);\n\n } else {\n var/*float*/ leadingCrossDim = leadingPaddingAndBorderCross;\n\n // For a relative children, we're either using alignItems (parent) or\n // alignSelf (child) in order to determine the position in the cross axis\n if (getPositionType(child) === CSS_POSITION_RELATIVE) {\n var/*css_align_t*/ alignItem = getAlignItem(node, child);\n if (alignItem === CSS_ALIGN_STRETCH) {\n // You can only stretch if the dimension has not already been set\n // previously.\n if (isUndefined(child.layout[dim[crossAxis]])) {\n child.layout[dim[crossAxis]] = fmaxf(\n boundAxis(child, crossAxis, containerCrossAxis -\n paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),\n // You never want to go smaller than padding\n getPaddingAndBorderAxis(child, crossAxis)\n );\n }\n } else if (alignItem !== CSS_ALIGN_FLEX_START) {\n // The remaining space between the parent dimensions+padding and child\n // dimensions+margin.\n var/*float*/ remainingCrossDim = containerCrossAxis -\n paddingAndBorderAxisCross - getDimWithMargin(child, crossAxis);\n\n if (alignItem === CSS_ALIGN_CENTER) {\n leadingCrossDim += remainingCrossDim / 2;\n } else { // CSS_ALIGN_FLEX_END\n leadingCrossDim += remainingCrossDim;\n }\n }\n }\n\n // And we apply the position\n child.layout[pos[crossAxis]] += linesCrossDim + leadingCrossDim;\n\n // Define the trailing position accordingly.\n if (isCrossDimDefined) {\n setTrailingPosition(node, child, crossAxis);\n }\n }\n }\n\n linesCrossDim += crossDim;\n linesMainDim = fmaxf(linesMainDim, mainDim);\n linesCount += 1;\n startLine = endLine;\n }\n\n // \n //\n // Note(prenaux): More than one line, we need to layout the crossAxis\n // according to alignContent.\n //\n // Note that we could probably remove and handle the one line case\n // here too, but for the moment this is safer since it won't interfere with\n // previously working code.\n //\n // See specs:\n // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm\n // section 9.4\n //\n if (linesCount > 1 && isCrossDimDefined) {\n var/*float*/ nodeCrossAxisInnerSize = node.layout[dim[crossAxis]] -\n paddingAndBorderAxisCross;\n var/*float*/ remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;\n\n var/*float*/ crossDimLead = 0;\n var/*float*/ currentLead = leadingPaddingAndBorderCross;\n\n var/*css_align_t*/ alignContent = getAlignContent(node);\n if (alignContent === CSS_ALIGN_FLEX_END) {\n currentLead += remainingAlignContentDim;\n } else if (alignContent === CSS_ALIGN_CENTER) {\n currentLead += remainingAlignContentDim / 2;\n } else if (alignContent === CSS_ALIGN_STRETCH) {\n if (nodeCrossAxisInnerSize > linesCrossDim) {\n crossDimLead = (remainingAlignContentDim / linesCount);\n }\n }\n\n var/*int*/ endIndex = 0;\n for (i = 0; i < linesCount; ++i) {\n var/*int*/ startIndex = endIndex;\n\n // compute the line's height and find the endIndex\n var/*float*/ lineHeight = 0;\n for (ii = startIndex; ii < childCount; ++ii) {\n child = node.children[ii];\n if (getPositionType(child) !== CSS_POSITION_RELATIVE) {\n continue;\n }\n if (child.lineIndex !== i) {\n break;\n }\n if (!isUndefined(child.layout[dim[crossAxis]])) {\n lineHeight = fmaxf(\n lineHeight,\n child.layout[dim[crossAxis]] + getMarginAxis(child, crossAxis)\n );\n }\n }\n endIndex = ii;\n lineHeight += crossDimLead;\n\n for (ii = startIndex; ii < endIndex; ++ii) {\n child = node.children[ii];\n if (getPositionType(child) !== CSS_POSITION_RELATIVE) {\n continue;\n }\n\n var/*css_align_t*/ alignContentAlignItem = getAlignItem(node, child);\n if (alignContentAlignItem === CSS_ALIGN_FLEX_START) {\n child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);\n } else if (alignContentAlignItem === CSS_ALIGN_FLEX_END) {\n child.layout[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child.layout[dim[crossAxis]];\n } else if (alignContentAlignItem === CSS_ALIGN_CENTER) {\n var/*float*/ childHeight = child.layout[dim[crossAxis]];\n child.layout[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2;\n } else if (alignContentAlignItem === CSS_ALIGN_STRETCH) {\n child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);\n // TODO(prenaux): Correctly set the height of items with undefined\n // (auto) crossAxis dimension.\n }\n }\n\n currentLead += lineHeight;\n }\n }\n\n var/*bool*/ needsMainTrailingPos = false;\n var/*bool*/ needsCrossTrailingPos = false;\n\n // If the user didn't specify a width or height, and it has not been set\n // by the container, then we set it via the children.\n if (!isMainDimDefined) {\n node.layout[dim[mainAxis]] = fmaxf(\n // We're missing the last padding at this point to get the final\n // dimension\n boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)),\n // We can never assign a width smaller than the padding and borders\n paddingAndBorderAxisMain\n );\n\n if (mainAxis == CSS_FLEX_DIRECTION_ROW_REVERSE ||\n mainAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) {\n needsMainTrailingPos = true;\n }\n }\n\n if (!isCrossDimDefined) {\n node.layout[dim[crossAxis]] = fmaxf(\n // For the cross dim, we add both sides at the end because the value\n // is aggregate via a max function. Intermediate negative values\n // can mess this computation otherwise\n boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross),\n paddingAndBorderAxisCross\n );\n\n if (crossAxis == CSS_FLEX_DIRECTION_ROW_REVERSE ||\n crossAxis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) {\n needsCrossTrailingPos = true;\n }\n }\n\n // Set trailing position if necessary\n if (needsMainTrailingPos || needsCrossTrailingPos) {\n for (i = 0; i < childCount; ++i) {\n child = node.children[i];\n\n if (needsMainTrailingPos) {\n setTrailingPosition(node, child, mainAxis);\n }\n\n if (needsCrossTrailingPos) {\n setTrailingPosition(node, child, crossAxis);\n }\n }\n }\n\n // Calculate dimensions for absolutely positioned elements\n currentAbsoluteChild = firstAbsoluteChild;\n while (currentAbsoluteChild !== null) {\n // Pre-fill dimensions when using absolute position and both offsets for\n // the axis are defined (either both left and right or top and bottom).\n for (ii = 0; ii < 2; ii++) {\n axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;\n\n if (!isUndefined(node.layout[dim[axis]]) &&\n !isDimDefined(currentAbsoluteChild, axis) &&\n isPosDefined(currentAbsoluteChild, leading[axis]) &&\n isPosDefined(currentAbsoluteChild, trailing[axis])) {\n currentAbsoluteChild.layout[dim[axis]] = fmaxf(\n boundAxis(currentAbsoluteChild, axis, node.layout[dim[axis]] -\n getBorderAxis(node, axis) -\n getMarginAxis(currentAbsoluteChild, axis) -\n getPosition(currentAbsoluteChild, leading[axis]) -\n getPosition(currentAbsoluteChild, trailing[axis])\n ),\n // You never want to go smaller than padding\n getPaddingAndBorderAxis(currentAbsoluteChild, axis)\n );\n }\n\n if (isPosDefined(currentAbsoluteChild, trailing[axis]) &&\n !isPosDefined(currentAbsoluteChild, leading[axis])) {\n currentAbsoluteChild.layout[leading[axis]] =\n node.layout[dim[axis]] -\n currentAbsoluteChild.layout[dim[axis]] -\n getPosition(currentAbsoluteChild, trailing[axis]);\n }\n }\n\n child = currentAbsoluteChild;\n currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild;\n child.nextAbsoluteChild = null;\n }\n }\n\n return {\n computeLayout: layoutNode,\n fillNodes: fillNodes\n };\n})();\n\n// This module export is only used for the purposes of unit testing this file. When\n// the library is packaged this file is included within css-layout.js which forms \n// the public API.\nif (typeof exports === 'object') {\n module.exports = computeLayout;\n}\n\n\n return function(node) {\n computeLayout.fillNodes(node);\n computeLayout.computeLayout(node);\n };\n}));\n"]} \ No newline at end of file