<commit_before>/**
 * Created by micku7zu on 1/27/2017.
 * MIT License.
 */
"use strict";
(function (undefined) {
    class VanillaTilt {

        constructor(element, settings = {}) {
            if (!(element instanceof Node)) {
                throw("Can't initialize VanillaTilt because " + element + " is not a Node.");
            }

            this.width = null;
            this.height = null;
            this.left = null;
            this.top = null;
            this.transitionTimeout = null;
            this.updateCall = null;

            this.updateBind = this.update.bind(this);

            this.element = element;
            this.settings = this.extendSettings(settings);

            this.addEventListeners();
        }

        addEventListeners() {
            this.onMouseEnterBind = this.onMouseEnter.bind(this);
            this.onMouseMoveBind = this.onMouseMove.bind(this);
            this.onMouseLeaveBind = this.onMouseLeave.bind(this);

            this.element.addEventListener("mouseenter", this.onMouseEnterBind);
            this.element.addEventListener("mousemove", this.onMouseMoveBind);
            this.element.addEventListener("mouseleave", this.onMouseLeaveBind);
        }

        removeEventListeners() {
            this.element.removeEventListener("mouseenter", this.onMouseEnterBind);
            this.element.removeEventListener("mousemove", this.onMouseMoveBind);
            this.element.removeEventListener("mouseleave", this.onMouseLeaveBind);
        }

        destroy() {
            this.removeEventListeners();
            this.element.vanillaTilt = null;
            this.element = null;
        }

        onMouseEnter(event) {
            this.width = this.element.offsetWidth;
            this.height = this.element.offsetHeight;
            this.left = this.element.offsetLeft;
            this.top = this.element.offsetTop;

            this.element.style.willChange = "transform";
            this.setTransition();
        }

        onMouseMove(event) {
            if (this.updateCall !== null) {
                cancelAnimationFrame(this.updateCall);
            }

            this.event = event;
            this.updateCall = requestAnimationFrame(this.updateBind);
        }

        onMouseLeave(event) {
            this.setTransition();

            if (this.settings.reset) {
                requestAnimationFrame(() => {
                    this.element.style.transform = "perspective(" + this.settings.perspective + "px) " +
                        "rotateX(0deg) " +
                        "rotateY(0deg) " +
                        "scale3d(1, 1, 1)";
                });
            }
        }

        update() {
            let x = (this.event.clientX - this.left) / this.width;
            let y = (this.event.clientY - this.top) / this.height;

            x = Math.min(Math.max(x, 0), 1);
            y = Math.min(Math.max(y, 0), 1);

            let tiltX = (this.settings.max / 2 - x * this.settings.max).toFixed(2);
            let tiltY = (y * this.settings.max - this.settings.max / 2).toFixed(2);

            this.element.style.transform = "perspective(" + this.settings.perspective + "px) " +
                "rotateX(" + (this.settings.axis === "x" ? 0 : tiltY) + "deg) " +
                "rotateY(" + (this.settings.axis === "y" ? 0 : tiltX) + "deg) " +
                "scale3d(" + this.settings.scale + ", " + this.settings.scale + ", " + this.settings.scale + ")";

            this.updateCall = null;
        }

        setTransition() {
            clearTimeout(this.transitionTimeout);
            this.element.style.transition = this.settings.speed + "ms " + this.settings.easing;
            this.transitionTimeout = setTimeout(() => this.element.style.transition = "", this.settings.speed);
        }

        extendSettings(settings) {
            let defaultSettings = {
                max: 20,
                perspective: 1000,
                easing: "cubic-bezier(.03,.98,.52,.99)",
                scale: "1",
                speed: "300",
                transition: true,
                axis: null,
                reset: true
            };

            let newSettings = {};

            for (var property in defaultSettings) {
                newSettings[property] = settings[property] || this.element.getAttribute("data-tilt-" + property) || defaultSettings[property];
            }

            return newSettings;
        }

        static init(elements, settings) {
            if (elements instanceof Node) {
                elements = [elements];
            }
<commit_msg>Fix settings extend. Fix mouse coordinates. Expose reset method.<commit_after>/**
 * Created by micku7zu on 1/27/2017.
 * MIT License.
 */
"use strict";
(function (undefined) {
    class VanillaTilt {

        constructor(element, settings = {}) {
            if (!(element instanceof Node)) {
                throw("Can't initialize VanillaTilt because " + element + " is not a Node.");
            }

            this.width = null;
            this.height = null;
            this.left = null;
            this.top = null;
            this.transitionTimeout = null;
            this.updateCall = null;

            this.updateBind = this.update.bind(this);

            this.element = element;
            this.settings = this.extendSettings(settings);

            this.addEventListeners();
        }

        addEventListeners() {
            this.onMouseEnterBind = this.onMouseEnter.bind(this);
            this.onMouseMoveBind = this.onMouseMove.bind(this);
            this.onMouseLeaveBind = this.onMouseLeave.bind(this);

            this.element.addEventListener("mouseenter", this.onMouseEnterBind);
            this.element.addEventListener("mousemove", this.onMouseMoveBind);
            this.element.addEventListener("mouseleave", this.onMouseLeaveBind);
        }

        removeEventListeners() {
            this.element.removeEventListener("mouseenter", this.onMouseEnterBind);
            this.element.removeEventListener("mousemove", this.onMouseMoveBind);
            this.element.removeEventListener("mouseleave", this.onMouseLeaveBind);
        }

        destroy() {
            this.removeEventListeners();
            this.element.vanillaTilt = null;
            this.element = null;
        }

        onMouseEnter(event) {
            this.width = this.element.offsetWidth;
            this.height = this.element.offsetHeight;
            this.left = this.element.offsetLeft;
            this.top = this.element.offsetTop;

            this.element.style.willChange = "transform";
            this.setTransition();
        }

        onMouseMove(event) {
            if (this.updateCall !== null) {
                cancelAnimationFrame(this.updateCall);
            }

            this.event = event;
            this.updateCall = requestAnimationFrame(this.updateBind);
        }

        onMouseLeave(event) {
            this.setTransition();

            if (this.settings.reset) {
                this.reset();
            }
        }

        reset() {
            requestAnimationFrame(() => {
                this.element.style.transform = "perspective(" + this.settings.perspective + "px) " +
                    "rotateX(0deg) " +
                    "rotateY(0deg) " +
                    "scale3d(1, 1, 1)";
            });
        }

        update() {
            let x = (this.event.pageX - this.left) / this.width;
            let y = (this.event.pageY - this.top) / this.height;

            x = Math.min(Math.max(x, 0), 1);
            y = Math.min(Math.max(y, 0), 1);

            let tiltX = (this.settings.max / 2 - x * this.settings.max).toFixed(2);
            let tiltY = (y * this.settings.max - this.settings.max / 2).toFixed(2);

            this.element.style.transform = "perspective(" + this.settings.perspective + "px) " +
                "rotateX(" + (this.settings.axis === "x" ? 0 : tiltY) + "deg) " +
                "rotateY(" + (this.settings.axis === "y" ? 0 : tiltX) + "deg) " +
                "scale3d(" + this.settings.scale + ", " + this.settings.scale + ", " + this.settings.scale + ")";

            this.updateCall = null;
        }

        setTransition() {
            clearTimeout(this.transitionTimeout);
            this.element.style.transition = this.settings.speed + "ms " + this.settings.easing;
            this.transitionTimeout = setTimeout(() => this.element.style.transition = "", this.settings.speed);
        }

        extendSettings(settings) {
            let defaultSettings = {
                max: 20,
                perspective: 1000,
                easing: "cubic-bezier(.03,.98,.52,.99)",
                scale: "1",
                speed: "300",
                transition: true,
                axis: null,
                reset: true
            };

            let newSettings = {};

            for (var property in defaultSettings) {
                if (property in settings) {
                    newSettings[property] = settings[property];
                } else if (this.element.hasAttribute("data-tilt-" + property)) {
                    newSettings[property] = this.element.getAttribute("data-tilt-" + property);
                } else {
                    newSettings[property] = defaultSettings[property];
                }
            }

            return newSettings;
        }

        static init(elements, settings) {
            if (elements instanceof Node) {
                elements = [elements];
            }

{'fraction_non_alphanumeric': 0.12389937106918239, 'fraction_numerical': 0.009014675052410902, 'mean_word_length': 1.6225948323254535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5781863', 'n_tokens_mistral': 2620, 'n_tokens_neox': 2474, 'n_words': 449}