<commit_before>export function init() {

    let DURATION = 150;

    let ringElem = null;
    let prevFocused = null;
    let keyDownTime = 0;

    let win = window;
    let doc = document;
    let docElem = doc.documentElement;
    let body = doc.body;


    docElem.addEventListener('keydown', function (event) {
        let code = event.which;
        // Show animation only upon Tab or Arrow keys press.
        if (code === 9 || (code > 36 && code < 41)) {
            keyDownTime = Date.now();
        }
    }, false);

    win.addEventListener('resize', function (event) {
        if($('flying-focus').hasClass('flying-focus_visible')) {
            placeFlyingFocus(doc.activeElement);
        }
    }, false);

    docElem.addEventListener('focus', function (event) {
        let target = event.target;
        placeFlyingFocus(target);
    }, true);


    docElem.addEventListener('blur', function () {
        onEnd();
    }, true);

    /**
     * In some cases it is needed to adjust the flying focus position,
     * because the focused element moves (swimpe module / scrolling within div)
     */
    $(document).on('flyingfocus:move', function() {
        placeFlyingFocus(doc.activeElement);
    });

    function placeFlyingFocus(target) {
        if (target.id === 'flying-focus') {
            return;
        }

        if (!ringElem) {
            initialize();
        }

        let offset = offsetOf(target);
        ringElem.style.left = offset.left + 'px';
        ringElem.style.top = offset.top + 'px';
        ringElem.style.width = target.offsetWidth + 'px';
        ringElem.style.height = target.offsetHeight + 'px';

        // Special handling for hidden input fields
        if ($(target).is('input') && $(target).hasClass('h-offscreen')) {
            ringElem.style.width = Math.round($(target).parent().outerWidth()) + 'px';
            ringElem.style.height = Math.round($(target).parent().outerHeight()) + 'px';
        }

        // Fallback with and height (best guess and better then zero...)
        if(target.offsetWidth === 0 && target.offsetHeight === 0) {
            ringElem.style.width = Math.round(target.getBoundingClientRect().width) + 'px';
            ringElem.style.height = Math.round(target.getBoundingClientRect().height) + 'px';
        }

        if (!isJustPressed()) {
            return;
        }

        target.classList.add('flying-focus_target');
        ringElem.classList.add('flying-focus_visible');
        prevFocused = target;
    }

    function initialize() {
        ringElem = doc.createElement('flying-focus');
        ringElem.id = 'flying-focus';
        ringElem.style.transitionDuration = ringElem.style.WebkitTransitionDuration = DURATION / 1000 + 's';
        body.appendChild(ringElem);
    }


    function onEnd() {
        if (ringElem) {
            ringElem.classList.remove('flying-focus_visible');
        }
        if (prevFocused) {
            prevFocused.classList.remove('flying-focus_target');
        }
        prevFocused = null;
    }


    function isJustPressed() {
        return Date.now() - keyDownTime < 100;
    }


    function offsetOf(elem) {
        let rect = elem.getBoundingClientRect();
        let clientLeft = docElem.clientLeft || body.clientLeft;
        let clientTop = docElem.clientTop || body.clientTop;
        let scrollLeft = win.pageXOffset || docElem.scrollLeft || body.scrollLeft;
        let scrollTop = win.pageYOffset || docElem.scrollTop || body.scrollTop;
        let left = rect.left + scrollLeft - clientLeft;
        let top = rect.top + scrollTop - clientTop;

        /*
        * Special handing for scrollable janrain modal
        * Flying focus is moved into janrain modal + top and left is calculated differently
        */
        if ( $('#janrainModal:visible').length > 0 ) {
            if ($(window).width() >= 1024) {

                // close button is in janrain modal, but not in the scrollable part
                if($(elem).hasClass('janrain_modal_closebutton')) {
                    $('#flying-focus').appendTo('body');
                } else {
                    $('#flying-focus').prependTo('#janrainModal > section');
                }

                // check if focus is in modal
                if($(elem).parents('#janrainModal > section').length > 0) {
                    top  = rect.top - ($('#janrainModal').offset().top - scrollTop) + $(elem).closest('#janrainModal > section').scrollTop();
                    left = rect.left - $('#janrainModal').offset().left;
                }
            }
        }

        return {
            top: top || 0,
            left: left || 0
        };
    }


    let style = doc.createElement('style');
    style.textContent = `#flying-focus {
        position: absolute;
        margin: 0;
        background: transparent;
        -webkit-transition-property: left, top, width, height;
        transition-property: left, top, width, height;
        -webkit-transition-timing-function: cubic-bezier(0,1,0,1);
        transition-timing-function: cubic-bezier(0,1,0,1);
        visibility: hidden;<commit_msg>comments, only comments...<commit_after>export function init() {

    let DURATION = 150;

    let ringElem = null;
    let prevFocused = null;
    let keyDownTime = 0;

    let win = window;
    let doc = document;
    let docElem = doc.documentElement;
    let body = doc.body;


    docElem.addEventListener('keydown', function (event) {
        let code = event.which;
        // Show animation only upon Tab or Arrow keys press.
        if (code === 9 || (code > 36 && code < 41)) {
            keyDownTime = Date.now();
        }
    }, false);

    win.addEventListener('resize', function (event) {
        if($('flying-focus').hasClass('flying-focus_visible')) {
            placeFlyingFocus(doc.activeElement);
        }
    }, false);

    docElem.addEventListener('focus', function (event) {
        let target = event.target;
        placeFlyingFocus(target);
    }, true);


    docElem.addEventListener('blur', function () {
        onEnd();
    }, true);

    /**
     * In some cases it is needed to adjust the flying focus position,
     * because the focused element moves (e.g. swimpe module)
     */
    $(document).on('flyingfocus:move', function() {
        placeFlyingFocus(doc.activeElement);
    });

    function placeFlyingFocus(target) {
        if (target.id === 'flying-focus') {
            return;
        }

        if (!ringElem) {
            initialize();
        }

        let offset = offsetOf(target);
        ringElem.style.left = offset.left + 'px';
        ringElem.style.top = offset.top + 'px';
        ringElem.style.width = target.offsetWidth + 'px';
        ringElem.style.height = target.offsetHeight + 'px';

        // Special handling for hidden input fields
        if ($(target).is('input') && $(target).hasClass('h-offscreen')) {
            ringElem.style.width = Math.round($(target).parent().outerWidth()) + 'px';
            ringElem.style.height = Math.round($(target).parent().outerHeight()) + 'px';
        }

        // Fallback with and height (best guess and better then zero...)
        if(target.offsetWidth === 0 && target.offsetHeight === 0) {
            ringElem.style.width = Math.round(target.getBoundingClientRect().width) + 'px';
            ringElem.style.height = Math.round(target.getBoundingClientRect().height) + 'px';
        }

        if (!isJustPressed()) {
            return;
        }

        target.classList.add('flying-focus_target');
        ringElem.classList.add('flying-focus_visible');
        prevFocused = target;
    }

    function initialize() {
        ringElem = doc.createElement('flying-focus');
        ringElem.id = 'flying-focus';
        ringElem.style.transitionDuration = ringElem.style.WebkitTransitionDuration = DURATION / 1000 + 's';
        body.appendChild(ringElem);
    }


    function onEnd() {
        if (ringElem) {
            ringElem.classList.remove('flying-focus_visible');
        }
        if (prevFocused) {
            prevFocused.classList.remove('flying-focus_target');
        }
        prevFocused = null;
    }


    function isJustPressed() {
        return Date.now() - keyDownTime < 100;
    }


    function offsetOf(elem) {
        let rect = elem.getBoundingClientRect();
        let clientLeft = docElem.clientLeft || body.clientLeft;
        let clientTop = docElem.clientTop || body.clientTop;
        let scrollLeft = win.pageXOffset || docElem.scrollLeft || body.scrollLeft;
        let scrollTop = win.pageYOffset || docElem.scrollTop || body.scrollTop;
        let left = rect.left + scrollLeft - clientLeft;
        let top = rect.top + scrollTop - clientTop;

        /*
        * Special handing for scrollable janrain modal:
        * On janrain modal open the flying focus element gets moved into the janrain modal
        * Additionally the position (top, left) has to be calculated differently
        */
        if ( $('#janrainModal:visible').length > 0 ) {
            if ($(window).width() >= 1024) {

                // close button is in janrain modal, but not in the scrollable part
                if($(elem).hasClass('janrain_modal_closebutton')) {
                    $('#flying-focus').appendTo('body');
                } else {
                    $('#flying-focus').prependTo('#janrainModal > section');
                }

                if($(elem).parents('#janrainModal > section').length > 0) {
                    top  = rect.top - ($('#janrainModal').offset().top - scrollTop) + $(elem).closest('#janrainModal > section').scrollTop();
                    left = rect.left - $('#janrainModal').offset().left;
                }
            }
        }

        return {
            top: top || 0,
            left: left || 0
        };
    }


    let style = doc.createElement('style');
    style.textContent = `#flying-focus {
        position: absolute;
        margin: 0;
        background: transparent;
        -webkit-transition-property: left, top, width, height;
        transition-property: left, top, width, height;
        -webkit-transition-timing-function: cubic-bezier(0,1,0,1);
        transition-timing-function: cubic-bezier(0,1,0,1);
        visibility: hidden;
{'fraction_non_alphanumeric': 0.13378089122397355, 'fraction_numerical': 0.006810663553220471, 'mean_word_length': 2.099819059107358, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '5612151', 'n_tokens_mistral': 2967, 'n_tokens_neox': 2801, 'n_words': 636}