<commit_before>var VideomailError = require('./../util/videomailError')

function getOuterWidth(element) {
    var rect = element.getBoundingClientRect()
    return rect.right - rect.left
}

function figureMinHeight(height, options) {
    if (options.hasDefinedHeight()) {
        if (!height)
            height = options.video.height
        else
            height = Math.min(options.video.height, height)
    }

    if (height < 1)
        throw VideomailError.create(
            'Got a video height less than 1 (' +
            height +
            ') while figuring out the minimum!')
    else
        return height
}

module.exports = {

    limitWidth: function(element, width) {
        var outerWidth   = getOuterWidth(element)
        var limitedWidth = outerWidth > 0 && outerWidth < width ? outerWidth : width

        if (limitedWidth < 1)
            throw VideomailError.create('Limited width cannot be less than 1!')
        else
            return limitedWidth
    },

    // this is difficult to compute and is not entirely correct.
    // but good enough for now to ensure some stability.
    limitHeight: function(height) {
        if (height < 1)
            throw VideomailError.create('Passed limit-height argument cannot be less than 1!')
        else {
            var body = document.body,
                elem = document.documentElement

            var limitedHeight = Math.min(
                height,
                body.scrollHeight, elem.scrollHeight,
                body.offsetHeight, elem.offsetHeight,
                body.clientHeight, elem.clientHeight
            )

            if (limitedHeight < 1)
                throw VideomailError.create('Limited height cannot be less than 1!')
            else
                return limitedHeight
        }
    },

    calculateWidth: function(options) {
        var height = options.videoHeight || null,<commit_msg>fix limitHeight computations<commit_after>var VideomailError = require('./../util/videomailError')

function getOuterWidth(element) {
    var rect = element.getBoundingClientRect()
    return rect.right - rect.left
}

function figureMinHeight(height, options) {
    if (options.hasDefinedHeight()) {
        if (!height)
            height = options.video.height
        else
            height = Math.min(options.video.height, height)
    }

    if (height < 1)
        throw VideomailError.create(
            'Got a video height less than 1 (' +
            height +
            ') while figuring out the minimum!')
    else
        return height
}

module.exports = {

    limitWidth: function(element, width) {
        var outerWidth   = getOuterWidth(element)
        var limitedWidth = outerWidth > 0 && outerWidth < width ? outerWidth : width

        if (limitedWidth < 1)
            throw VideomailError.create('Limited width cannot be less than 1!')
        else
            return limitedWidth
    },

    // this is difficult to compute and is not entirely correct.
    // but good enough for now to ensure some stability.
    limitHeight: function(height) {
        if (height < 1)
            throw VideomailError.create('Passed limit-height argument cannot be less than 1!')
        else {
            var limitedHeight = Math.min(
                height,
                document.body.scrollHeight,
                document.documentElement.clientHeight
            )

            if (limitedHeight < 1)
                throw VideomailError.create('Limited height cannot be less than 1!')
            else
                return limitedHeight
        }
    },

    calculateWidth: function(options) {
        var height = options.videoHeight || null,
{'fraction_non_alphanumeric': 0.08258381030253475, 'fraction_numerical': 0.004905968928863451, 'mean_word_length': 1.9477911646586346, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '4860964', 'n_tokens_mistral': 976, 'n_tokens_neox': 929, 'n_words': 284}