<commit_before>/* global interfaceConfig */

import UIUtil from '../util/UIUtil';

/**
 * Responsible for drawing audio levels.
 */
const AudioLevels = {
    /**
     * Fills the dot(s) with the specified "index", with as much opacity as
     * indicated by "opacity".
     *
     * @param {string} elementID the parent audio indicator span element
     * @param {number} index the index of the dots to fill, where 0 indicates
     * the middle dot and the following increments point toward the
     * corresponding pair of dots.
     * @param {number} opacity the opacity to set for the specified dot.
     */
    _setDotLevel(elementID, index, opacity) {
        let audioSpan
            = document.getElementById(elementID)
                .getElementsByClassName('audioindicator');

        // Make sure the audio span is still around.
        if (audioSpan && audioSpan.length > 0) {
            audioSpan = audioSpan[0];
        } else {
            return;
        }

        const audioTopDots
            = audioSpan.getElementsByClassName('audiodot-top');
        const audioDotMiddle
            = audioSpan.getElementsByClassName('audiodot-middle');
        const audioBottomDots
            = audioSpan.getElementsByClassName('audiodot-bottom');

        // First take care of the middle dot case.
        if (index === 0) {
            audioDotMiddle[0].style.opacity = opacity;

            return;
        }

        // Index > 0 : we are setting non-middle dots.
        index--;// eslint-disable-line no-param-reassign
        audioBottomDots[index].style.opacity = opacity;
        audioTopDots[this.sideDotsCount - index - 1].style.opacity = opacity;
    },

    /**
     * Updates the audio level of the large video.
     *
     * @param audioLevel the new audio level to set.
     */
    updateLargeVideoAudioLevel(elementId, audioLevel) {
        const element = document.getElementById(elementId);

        if (!UIUtil.isVisible(element)) {
            return;
        }

        let level = parseFloat(audioLevel);

        level = isNaN(level) ? 0 : level;

        let shadowElement = element.getElementsByClassName('dynamic-shadow');

        if (shadowElement && shadowElement.length > 0) {
            shadowElement = shadowElement[0];
        }

        shadowElement.style.boxShadow = this._updateLargeVideoShadow(level);
    },

    /**
     * Updates the large video shadow effect.
     */
    _updateLargeVideoShadow(level) {
        const scale = 2;

        // Internal circle audio level.
        const int = {
            level: level > 0.15 ? 20 : 0,
            color: interfaceConfig.AUDIO_LEVEL_PRIMARY_COLOR
        };

        // External circle audio level.
        const ext = {
            level: ((int.level * scale * level) + int.level).toFixed(0),
            color: interfaceConfig.AUDIO_LEVEL_SECONDARY_COLOR
        };

        // Internal blur.
        int.blur = int.level ? 2 : 0;

        // External blur.<commit_msg>fix(speaker-levels): convert calculation from string to float (#3870)<commit_after>/* global interfaceConfig */

import UIUtil from '../util/UIUtil';

/**
 * Responsible for drawing audio levels.
 */
const AudioLevels = {
    /**
     * Fills the dot(s) with the specified "index", with as much opacity as
     * indicated by "opacity".
     *
     * @param {string} elementID the parent audio indicator span element
     * @param {number} index the index of the dots to fill, where 0 indicates
     * the middle dot and the following increments point toward the
     * corresponding pair of dots.
     * @param {number} opacity the opacity to set for the specified dot.
     */
    _setDotLevel(elementID, index, opacity) {
        let audioSpan
            = document.getElementById(elementID)
                .getElementsByClassName('audioindicator');

        // Make sure the audio span is still around.
        if (audioSpan && audioSpan.length > 0) {
            audioSpan = audioSpan[0];
        } else {
            return;
        }

        const audioTopDots
            = audioSpan.getElementsByClassName('audiodot-top');
        const audioDotMiddle
            = audioSpan.getElementsByClassName('audiodot-middle');
        const audioBottomDots
            = audioSpan.getElementsByClassName('audiodot-bottom');

        // First take care of the middle dot case.
        if (index === 0) {
            audioDotMiddle[0].style.opacity = opacity;

            return;
        }

        // Index > 0 : we are setting non-middle dots.
        index--;// eslint-disable-line no-param-reassign
        audioBottomDots[index].style.opacity = opacity;
        audioTopDots[this.sideDotsCount - index - 1].style.opacity = opacity;
    },

    /**
     * Updates the audio level of the large video.
     *
     * @param audioLevel the new audio level to set.
     */
    updateLargeVideoAudioLevel(elementId, audioLevel) {
        const element = document.getElementById(elementId);

        if (!UIUtil.isVisible(element)) {
            return;
        }

        let level = parseFloat(audioLevel);

        level = isNaN(level) ? 0 : level;

        let shadowElement = element.getElementsByClassName('dynamic-shadow');

        if (shadowElement && shadowElement.length > 0) {
            shadowElement = shadowElement[0];
        }

        shadowElement.style.boxShadow = this._updateLargeVideoShadow(level);
    },

    /**
     * Updates the large video shadow effect.
     */
    _updateLargeVideoShadow(level) {
        const scale = 2;

        // Internal circle audio level.
        const int = {
            level: level > 0.15 ? 20 : 0,
            color: interfaceConfig.AUDIO_LEVEL_PRIMARY_COLOR
        };

        // External circle audio level.
        const ext = {
            level: parseFloat(
                ((int.level * scale * level) + int.level).toFixed(0)),
            color: interfaceConfig.AUDIO_LEVEL_SECONDARY_COLOR
        };

        // Internal blur.
        int.blur = int.level ? 2 : 0;

        // External blur.
{'fraction_non_alphanumeric': 0.09819506540818017, 'fraction_numerical': 0.007285974499089253, 'mean_word_length': 2.0443548387096775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1772316', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1575, 'n_words': 455}