<commit_before>var colCount, colWidth, outerMargin, $items, windowWidth

var margin = 25
var blocks = []
var gutter = 60

export default function setupBlocks() {
	$items = $('.BoardPost')
	if (!$items.length) return // sometimes called before posts are rendered

	blocks = []
	windowWidth = $(window).width() - gutter
	colWidth = $items.outerWidth()
	colCount = Math.floor(windowWidth / (colWidth+margin) )
	outerMargin = windowWidth - colCount * (colWidth+margin) + gutter

	for (let i=0; i < colCount; i++) {
		blocks.push(margin)
	}

	positionBlocks()
}

function positionBlocks() {
	$items.each(function(){
		var min = Array.min(blocks)
		var index = $.inArray(min, blocks)
		var leftPos = outerMargin/2 + margin/2 + (index * (colWidth+margin))
		$(this).css({
			'top': min+'px',
			'left': leftPos+'px'
		})
		blocks[index] = min+$(this).outerHeight()+margin
	})	
}

// Function to get the Min value in Array
Array.min = function(array) {
    return Math.min.apply(Math, array)
}
<commit_msg>feat(Board): Make layout configurable and more performant<commit_after>

export default function createLayout(options) {
    var {
        margin = 25,
        gutterLeft = 60,
        gutterRight = 60,
        targetSelector,
        containerSelector,
    } = options;

    var colCount,
        colWidth,
        outerMargin,
        $items,
        containerWidth,
        blocks

    return (reuseElements=false) => {
        discoverItems(reuseElements)
        positionItems()
    }

    function discoverItems(reuseElements) {
        if (!reuseElements) {
            $items = $(targetSelector)
        }

        // sometimes called before items are rendered
        if (!$items || !$items.length)
            return

        blocks = []
        containerWidth = $(containerSelector).width() - gutterRight - gutterLeft
        colWidth = $items.outerWidth() + margin
        colCount = Math.floor(containerWidth / colWidth)
        outerMargin = containerWidth - colCount * colWidth

        for (let i=0; i < colCount; i++) {
            blocks.push(margin)
        }
    }

    function positionItems() {
        $items && $items.each(function(){
            var min = Array.min(blocks)
            var index = $.inArray(min, blocks)
            var leftPos = gutterLeft + outerMargin/2 + margin/2 + (index * colWidth)
            $(this).css({
                'top': min+'px',
                'left': leftPos+'px'
            })

            blocks[index] = min + $(this).outerHeight() + margin
        })
    }
}


// Function to get the Min value in Array
Array.min = function(array) {
    return Math.min.apply(Math, array)
}

{'fraction_non_alphanumeric': 0.12803030303030302, 'fraction_numerical': 0.006060606060606061, 'mean_word_length': 2.434330299089727, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3073445', 'n_tokens_mistral': 808, 'n_tokens_neox': 784, 'n_words': 197}