import cssLayout from 'css-layout';

const _getChildNodes = (childNodes, childStyles) => {
  const styleNodes = [];
  for (let ii = 0, nn = childNodes.length; ii < nn; ii++) {
    let childStyle = childStyles[ii];
    if (!childStyle || !childStyle.style) {
      childStyle = {style: {}};
    }
    const childNode = childNodes[ii];
    if (childNode) {
      const box = childNode.getBBox();
      styleNodes.push({
        node: childNode,
        style: Object.assign({
          height: Math.ceil(box.height),
          width: Math.ceil(box.width),
        }, childStyle.style),
      });
    }
  }
  return styleNodes;
};

export default {
  getLayout(node, parentStyle, childStyles) {
    return cssLayout({
      style: parentStyle,
      children: _getChildNodes(
        node.childNodes,
        childStyles ? childStyles : [],
      ),
    });
  },
};

import cssLayout from 'css-layout';

export default {

  getLayout(node, parentStyle, childStyles) {
    const _getChildNodes = (childNodes, childStyles) => {
      const styleNodes = [];
      for (let ii = 0, nn = childNodes.length; ii < nn; ii++) {
        let childStyle = childStyles[ii];
        if (!childStyle || !childStyle.style) {
          childStyle = {style: {}};
        }
        const childNode = childNodes[ii];
        if (childNode) {
          const box = childNode.getBBox();
          styleNodes.push({
            node: childNode,
            style: Object.assign({
              height: Math.ceil(box.height),
              width: Math.ceil(box.width),
            }, childStyle.style),
          });
        }
      }
      return styleNodes;
    };

    return cssLayout({
      style: parentStyle,
      children: _getChildNodes(
        node.childNodes, childStyles ? childStyles : [],
      ),
    });
  },

};

improve syntax of Flexbox