<commit_before>/*!
 * Facade.js v0.3.0beta
 * https://github.com/neogeek/facade.js
 *
 * Copyright (c) 2014 <NAME>
 * Dual-licensed under both MIT and BSD licenses.
 */

(function () {

    'use strict';

    var _requestAnimationFrame,
        _cancelAnimationFrame,
        _context = document.createElement('canvas').getContext('2d'),
        _contextProperties = [ 'fillStyle', 'font', 'globalAlpha', 'globalCompositeOperation', 'lineCap', 'lineJoin', 'lineWidth', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline' ],
        _contextMethods = [],
        _TO_RADIANS = Math.PI / 180;

    /*!
     * requestAnimationFrame Support
     */

    (['webkit', 'moz']).forEach(function (key) {
        _requestAnimationFrame = _requestAnimationFrame || window.requestAnimationFrame || window[key + 'RequestAnimationFrame'] || null;
        _cancelAnimationFrame = _cancelAnimationFrame || window.cancelAnimationFrame || window[key + 'CancelAnimationFrame'] || null;
    });

    /**
     * Checks an object to see if it is an array. Returns a boolean result.
     *
     *  console.log(isArray([1, 2, 3, 4, 5])); // true
     *  console.log(isArray({ x: 0, y: 0, width: 100, height: 100 })); // false
     *
     * @param {Object} obj The object to be checked.
     * @return {Boolean} Result of the test.
     * @api private
     */

    function isArray(obj) {

        return Object.prototype.toString.call(obj) === '[object Array]' ? true : false;

    }

    /**
     * Checks an object to see if it is a function. Returns a boolean result.
     *
     *  console.log(isisFunction(this._draw)); // true
     *
     * @param {Object} obj The object to be checked.
     * @return {Boolean} Result of the test.
     * @api private
     */

    function isFunction(obj) {

        return Object.prototype.toString.call(obj) === '[object Function]' ? true : false;

    }

    /**
     * Creates a new Facade.js object with either a preexisting canvas tag or a unique name, width, and height.
     *
     *  var stage = new Facade(document.getElementById('stage'));
     *  var stage = new Facade('stage', 500, 300);
     *
     * @property {Object} canvas Reference to the canvas element.
     * @property {Object} context Reference to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D" target="_blank">CanvasRenderingContext2D</a> object.
     * @property {Integer} dt Current time in milliseconds since last canvas draw.
     * @property {Integer} fps Current frames per second.
     * @property {Integer} ftime Time of last canvas draw.
     * @param {Object|String?} canvas Reference to an HTML canvas element or a unique name.
     * @param {Integer?} width Width of the canvas.
     * @param {Integer?} height Height of the canvas.
     * @return {Object} New Facade.js object.
     * @api public
     */

    function Facade(canvas, width, height) {

        if (!(this instanceof Facade)) {

            return new Facade(canvas, width, height);

        }

        if (canvas && typeof canvas === 'object' && canvas.nodeType === 1) {

            this.canvas = canvas;

        } else {

            this.canvas = document.createElement('canvas');

            if (typeof canvas === 'string') {

                this.canvas.setAttribute('id', canvas);

            }

        }

        if (width && height) {

            this.canvas.setAttribute('width', parseInt(width, 10));
            this.canvas.setAttribute('height', parseInt(height, 10));

        }

        try {

            this.context = this.canvas.getContext('2d');

        } catch (e) {

            throw new Error('Canvas passed to Facade.js was not a valid canvas element.');

        }

        this.dt = null;
        this.fps = null;
        this.ftime = null;

        this._callback = null;

        this._requestAnimation = null;

    }

    /**
     * Draws a Facade.js object to the stage.
     *
     *  stage.addToStage(circle);
     *
     * @param {Object} obj Facade.js entity object.
     * @return {Object} Facade.js object.
     * @api public
     */

    Facade.prototype.addToStage = function (obj) {

        if (!(obj instanceof Facade.Entity)) {

            throw new Error('Parameter passed to Facade.addToStage is not a valid Facade.js entity object');

        }

        obj.draw(this);

        return this;

    };

    /**
     * Clears the canvas.
     *
     *  stage.clear();
     *
     * @return {Object} Facade.js object.
     * @api public
     */

    Facade.prototype.clear = function () {

        this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);

        return this;

    };

    /**
     * Sets a callback function to run in a loop using <a href="https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame" target="_blank">requestAnimationFrame</a>.
     *
     *  stage.draw(function () {
     *
     *      this.clear();
     *
     *      this.addToStage(circle, { x: 100, y: 100 });
     *
     *  });
     *
     * @param {Function} callback Function callback.
     * @return {Object} Facade.js object.
     * @api public
     */

    Facade.prototype.draw = function (callback) {

        if (typeof callback === 'function') {

            this._callback = callback;

            this.start();

        } else {

            throw new Error('Parameter passed to Facade.draw is not a valid function');

        }

        return this;

    };

    /**
     * Exports a base64 encoded representation of the current rendered canvas.
     *
     *  console.log(stage.exportBase64('image/png', 100));
     *
     * @param {String?} type Image format: <code>image/png</code> (Default), <code>image/jpeg</code>, <code>image/webp</code> (Google Chrome Only)
     * @param {Integer?} quality Number between 0 and 100.
     * @return {String} Base64 encoded string.
     * @api public
     */

    Facade.prototype.exportBase64 = function (type, quality) {

        if (!type) {

            type = 'image/png';

        }

        if (typeof quality === 'number') {

            quality = quality / 100;

        } else {

            quality = 1;

        }

        return this.canvas.toDataURL(type, quality);

    };

    /**
     * Gets and sets the canvas height.
     *
     *  console.log(stage.height()); // 300
     *  console.log(stage.height(600)); // 600
     *
     * @param {Integer?} height Height in pixels.
     * @return {Integer} Height in pixels.
     * @api public
     */

    Facade.prototype.height = function (height) {

        if (height) {

            this.canvas.setAttribute('height', parseInt(height, 10));

        }

        return this.canvas.height;

    };

    Facade.prototype.renderWithContext = function (options, callback) {

        var key;

        this.context.save();

        for (key in options) {

            if (options.hasOwnProperty(key)) {

                if (isArray(options[key]) && isFunction(this.context[key])) {

                    this.context[key].apply(this.context, options[key]);

                } else if (_contextProperties.hasOwnProperty(key)) {

                    this.context[key] = options[key];

                }

            }

        }

        if (callback) {

            callback.call(null, this);

        }

        this.context.restore();

    };

    /**
     * Starts the callback supplied in <code>Facade.draw</code>.
     *
     *  stage.start();
     *
     * @return {Object} Facade.js object.
     * @api public
     */

    Facade.prototype.start = function () {

        this._requestAnimation = _requestAnimationFrame(this._animate.bind(this));<commit_msg>Updated context validation to check contents of array rather than properties.<commit_after>/*!
 * Facade.js v0.3.0beta
 * https://github.com/neogeek/facade.js
 *
 * Copyright (c) 2014 <NAME>
 * Dual-licensed under both MIT and BSD licenses.
 */

(function () {

    'use strict';

    var _requestAnimationFrame,
        _cancelAnimationFrame,
        _context = document.createElement('canvas').getContext('2d'),
        _contextProperties = [ 'fillStyle', 'font', 'globalAlpha', 'globalCompositeOperation', 'lineCap', 'lineJoin', 'lineWidth', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline' ],
        _contextMethods = [],
        _TO_RADIANS = Math.PI / 180;

    /*!
     * requestAnimationFrame Support
     */

    (['webkit', 'moz']).forEach(function (key) {
        _requestAnimationFrame = _requestAnimationFrame || window.requestAnimationFrame || window[key + 'RequestAnimationFrame'] || null;
        _cancelAnimationFrame = _cancelAnimationFrame || window.cancelAnimationFrame || window[key + 'CancelAnimationFrame'] || null;
    });

    /**
     * Checks an object to see if it is an array. Returns a boolean result.
     *
     *  console.log(isArray([1, 2, 3, 4, 5])); // true
     *  console.log(isArray({ x: 0, y: 0, width: 100, height: 100 })); // false
     *
     * @param {Object} obj The object to be checked.
     * @return {Boolean} Result of the test.
     * @api private
     */

    function isArray(obj) {

        return Object.prototype.toString.call(obj) === '[object Array]' ? true : false;

    }

    /**
     * Checks an object to see if it is a function. Returns a boolean result.
     *
     *  console.log(isisFunction(this._draw)); // true
     *
     * @param {Object} obj The object to be checked.
     * @return {Boolean} Result of the test.
     * @api private
     */

    function isFunction(obj) {

        return Object.prototype.toString.call(obj) === '[object Function]' ? true : false;

    }

    /**
     * Creates a new Facade.js object with either a preexisting canvas tag or a unique name, width, and height.
     *
     *  var stage = new Facade(document.getElementById('stage'));
     *  var stage = new Facade('stage', 500, 300);
     *
     * @property {Object} canvas Reference to the canvas element.
     * @property {Object} context Reference to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D" target="_blank">CanvasRenderingContext2D</a> object.
     * @property {Integer} dt Current time in milliseconds since last canvas draw.
     * @property {Integer} fps Current frames per second.
     * @property {Integer} ftime Time of last canvas draw.
     * @param {Object|String?} canvas Reference to an HTML canvas element or a unique name.
     * @param {Integer?} width Width of the canvas.
     * @param {Integer?} height Height of the canvas.
     * @return {Object} New Facade.js object.
     * @api public
     */

    function Facade(canvas, width, height) {

        if (!(this instanceof Facade)) {

            return new Facade(canvas, width, height);

        }

        if (canvas && typeof canvas === 'object' && canvas.nodeType === 1) {

            this.canvas = canvas;

        } else {

            this.canvas = document.createElement('canvas');

            if (typeof canvas === 'string') {

                this.canvas.setAttribute('id', canvas);

            }

        }

        if (width && height) {

            this.canvas.setAttribute('width', parseInt(width, 10));
            this.canvas.setAttribute('height', parseInt(height, 10));

        }

        try {

            this.context = this.canvas.getContext('2d');

        } catch (e) {

            throw new Error('Canvas passed to Facade.js was not a valid canvas element.');

        }

        this.dt = null;
        this.fps = null;
        this.ftime = null;

        this._callback = null;

        this._requestAnimation = null;

    }

    /**
     * Draws a Facade.js object to the stage.
     *
     *  stage.addToStage(circle);
     *
     * @param {Object} obj Facade.js entity object.
     * @return {Object} Facade.js object.
     * @api public
     */

    Facade.prototype.addToStage = function (obj) {

        if (!(obj instanceof Facade.Entity)) {

            throw new Error('Parameter passed to Facade.addToStage is not a valid Facade.js entity object');

        }

        obj.draw(this);

        return this;

    };

    /**
     * Clears the canvas.
     *
     *  stage.clear();
     *
     * @return {Object} Facade.js object.
     * @api public
     */

    Facade.prototype.clear = function () {

        this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);

        return this;

    };

    /**
     * Sets a callback function to run in a loop using <a href="https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame" target="_blank">requestAnimationFrame</a>.
     *
     *  stage.draw(function () {
     *
     *      this.clear();
     *
     *      this.addToStage(circle, { x: 100, y: 100 });
     *
     *  });
     *
     * @param {Function} callback Function callback.
     * @return {Object} Facade.js object.
     * @api public
     */

    Facade.prototype.draw = function (callback) {

        if (typeof callback === 'function') {

            this._callback = callback;

            this.start();

        } else {

            throw new Error('Parameter passed to Facade.draw is not a valid function');

        }

        return this;

    };

    /**
     * Exports a base64 encoded representation of the current rendered canvas.
     *
     *  console.log(stage.exportBase64('image/png', 100));
     *
     * @param {String?} type Image format: <code>image/png</code> (Default), <code>image/jpeg</code>, <code>image/webp</code> (Google Chrome Only)
     * @param {Integer?} quality Number between 0 and 100.
     * @return {String} Base64 encoded string.
     * @api public
     */

    Facade.prototype.exportBase64 = function (type, quality) {

        if (!type) {

            type = 'image/png';

        }

        if (typeof quality === 'number') {

            quality = quality / 100;

        } else {

            quality = 1;

        }

        return this.canvas.toDataURL(type, quality);

    };

    /**
     * Gets and sets the canvas height.
     *
     *  console.log(stage.height()); // 300
     *  console.log(stage.height(600)); // 600
     *
     * @param {Integer?} height Height in pixels.
     * @return {Integer} Height in pixels.
     * @api public
     */

    Facade.prototype.height = function (height) {

        if (height) {

            this.canvas.setAttribute('height', parseInt(height, 10));

        }

        return this.canvas.height;

    };

    Facade.prototype.renderWithContext = function (options, callback) {

        var key;

        this.context.save();

        for (key in options) {

            if (options.hasOwnProperty(key)) {

                if (isArray(options[key]) && isFunction(this.context[key])) {

                    this.context[key].apply(this.context, options[key]);

                } else if (_contextProperties.indexOf(key) !== -1) {

                    this.context[key] = options[key];

                }

            }

        }

        if (callback) {

            callback.call(null, this);

        }

        this.context.restore();

    };

    /**
     * Starts the callback supplied in <code>Facade.draw</code>.
     *
     *  stage.start();
     *
     * @return {Object} Facade.js object.
     * @api public
     */

    Facade.prototype.start = function () {

        this._requestAnimation = _requestAnimationFrame(this._animate.bind(this));
{'fraction_non_alphanumeric': 0.1318844318328389, 'fraction_numerical': 0.009867148200696504, 'mean_word_length': 2.1032619571743045, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 6, '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': '1236219', 'n_tokens_mistral': 4700, 'n_tokens_neox': 4356, 'n_words': 1172}