<commit_before>/*
 * Sozi - A presentation tool using the SVG standard
 *
 * Copyright (C) 2010-2011 <NAME>
 *
 * This program is dual licensed under the terms of the MIT license
 * or the GNU General Public License (GPL) version 3.
 * A copy of both licenses is provided in the doc/ folder of the
 * official release of Sozi.
 * 
 * See http://sozi.baierouge.fr/wiki/en:license for details.
 */

var sozi = sozi || {};

(function () {
    var exports = sozi.animation = sozi.animation || {},
        window = this;
    
    exports.Animator = function (timeStepMs, onStep, onDone) {
        this.timeStepMs = timeStepMs || 40;
        this.onStep = onStep;
        this.onDone = onDone;

        this.durationMs = 0;
        this.data = {};
        this.initialTime = 0;
        this.started = false;
        this.timer = 0;
    };

    exports.Animator.prototype.start = function (durationMs, data) {
        var that = this;
        
        this.durationMs = durationMs;
        this.data = data;

        this.initialTime = Date.now();
        this.onStep(0, this.data);

        if (!this.started) {
            this.started = true;
            this.timer = window.setInterval(function () {
                that.step();
            }, this.timeStepMs);
        }
    };

    exports.Animator.prototype.stop = function () {
        if (this.started) {
            window.clearInterval(this.timer);
            this.started = false;
        }
    };

    exports.Animator.prototype.step = function () {
        var elapsedTime = Date.now() - this.initialTime;
        if (elapsedTime >= this.durationMs) {
            this.stop();
            this.onStep(1, this.data);
            this.onDone();
        } else {
            this.onStep(elapsedTime / this.durationMs, this.data);
        }
    };

    exports.profiles = {
        "linear": function (x) {
            return x;
        },
<commit_msg>Improved animations: using brower 'animation frames' when available<commit_after>/*
 * Sozi - A presentation tool using the SVG standard
 *
 * Copyright (C) 2010-2011 <NAME>
 *
 * This program is dual licensed under the terms of the MIT license
 * or the GNU General Public License (GPL) version 3.
 * A copy of both licenses is provided in the doc/ folder of the
 * official release of Sozi.
 * 
 * See http://sozi.baierouge.fr/wiki/en:license for details.
 */

var sozi = sozi || {};

(function () {
    var exports = sozi.animation = sozi.animation || {},
        window = this,
        animationFrameImpl = ["moz", "webkit", "ms"],
        i, impl,

		getAnimationStartTime = function () {
			return Date.now();
		},
	
		requestFirstAnimationFrame = function (callback, timeStepMs) {
			return window.setInterval(function () {
				callback(Date.now());
			}, timeStepMs);
		},
	
		requestNextAnimationFrame = function (callback) {},
	
		clearAnimationFrame = function (af) {
			window.clearInterval(af);
		};
	
	function lookupAnimationHandlers(impl) {
		if (typeof window[impl + "AnimationStartTime"] === "number") {
			getAnimationStartTime = function () {
				return window[impl + "AnimationStartTime"];
			};
		}
		if (typeof window[impl + "RequestAnimationFrame"] === "function") {
			requestFirstAnimationFrame = requestNextAnimationFrame = window[impl + "RequestAnimationFrame"];
			clearAnimationFrame = function (af) {};
		}
	}
	
	for (i = 0; i < animationFrameImpl.length; i += 1) {
		lookupAnimationHandlers(animationFrameImpl[i]);
	}
	
    exports.Animator = function (timeStepMs, onStep, onDone) {
        var that = this;
        
        this.timeStepMs = timeStepMs || 40;
        this.onStep = onStep;
        this.onDone = onDone;

        this.durationMs = 0;
        this.data = {};
        this.initialTime = 0;
        this.started = false;
        this.browserAnimationFrame = 0;
        
        this.callback = function (timestamp) {
            that.step(timestamp);
        };
    };

    exports.Animator.prototype.start = function (durationMs, data) {
        this.durationMs = durationMs;
        this.data = data;

        this.initialTime = getAnimationStartTime();
        this.onStep(0, this.data);

        if (!this.started) {
            this.started = true;
            this.browserAnimationFrame = requestFirstAnimationFrame(this.callback, this.timeStepMs);
        }
    };

    exports.Animator.prototype.stop = function () {
        if (this.started) {
            clearAnimationFrame(this.browserAnimationFrame);
            this.started = false;
        }
    };

    exports.Animator.prototype.step = function (timestamp) {
        var elapsedTime = timestamp - this.initialTime;
        if (elapsedTime >= this.durationMs) {
            this.stop();
            this.onStep(1, this.data);
            this.onDone();
        } else {
            this.onStep(elapsedTime / this.durationMs, this.data);
            requestNextAnimationFrame(this.callback);
        }
    };

    exports.profiles = {
        "linear": function (x) {
            return x;
        },

{'fraction_non_alphanumeric': 0.12014345487148835, 'fraction_numerical': 0.006774257820282925, 'mean_word_length': 2.1913541004450097, 'pattern_counts': {'":': 2, '<': 6, '<?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': '7277703', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1424, 'n_words': 347}