<commit_before>/*!
 * ZRender, a high performance canvas library.
 *  
 * Copyright (c) 2013, Baidu Inc.
 * All rights reserved.
 * 
 * LICENSE
 * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
 */
define(function(require) {
    var util = require('./core/util');
    var log = require('./core/log');
    var guid = require('./core/guid');
    var env = require('./core/env');

    var Handler = require('./Handler');
    var Storage = require('./Storage');
    var Animation = require('./animation/Animation');

    var useVML = ! env.canvasSupported;
    if (useVML) {
        require('./vml/graphic');
    }
    var Painter = useVML ? require('./vml/Painter') : require('./Painter');

    var _instances = {};    // ZRender实例map索引

    var zrender = {};
    /**
     * @type {string}
     */
    zrender.version = '2.0.8';

    /**
     * 创建zrender实例
     *
     * @param {HTMLElement} dom 绘图容器
     * @return {module:zrender/ZRender} ZRender实例
     */
    // 不让外部直接new ZRender实例，为啥？
    // 不为啥，提供全局可控同时减少全局污染和降低命名冲突的风险！
    zrender.init = function(dom) {
        var zr = new ZRender(guid(), dom);
        _instances[zr.id] = zr;
        return zr;
    };

    /**
     * zrender实例销毁
     * @param {module:zrender/ZRender} zr ZRender对象，不传则销毁全部
     */
    // 在_instances里的索引也会删除了
    // 管生就得管死，可以通过zrender.dispose(zr)销毁指定ZRender实例
    // 当然也可以直接zr.dispose()自己销毁
    zrender.dispose = function (zr) {
        if (zr) {
            zr.dispose();
        }
        else {
            for (var key in _instances) {
                _instances[key].dispose();
            }
            _instances = {};
        }

        return zrender;
    };

    /**
     * 获取zrender实例
     * @param {string} id ZRender对象索引
     * @return {module:zrender/ZRender}
     */
    zrender.getInstance = function (id) {
        return _instances[id];
    };

    /**
     * 删除zrender实例，ZRender实例dispose时会调用，
     * 删除后getInstance则返回undefined
     * ps: 仅是删除，删除的实例不代表已经dispose了~~
     *     这是一个摆脱全局zrender.dispose()自动销毁的后门，
     *     take care of yourself~
     *
     * @param {string} id ZRender对象索引
     */
    zrender.delInstance = function (id) {
        delete _instances[id];
        return zrender;
    };

    function getFrameCallback(zrInstance) {
        return function () {
            if (zrInstance._needsRefreshNextFrame) {
                zrInstance.refresh();
            }
        };
    }

    /**
     * @module zrender/ZRender
     */
    /**
     * ZRender接口类，对外可用的所有接口都在这里
     * 非get接口统一返回支持链式调用
     *
     * @constructor
     * @alias module:zrender/ZRender
     * @param {string} id 唯一标识
     * @param {HTMLElement} dom dom对象，不帮你做document.getElementById
     * @return {ZRender} ZRender实例
     */
    var ZRender = function(id, dom) {
        /**
         * 实例 id
         * @type {string}
         */
        this.id = id;
        this.env = env;

        this.storage = new Storage();
        this.painter = new Painter(dom, this.storage);
        this.handler = new Handler(dom, this.storage, this.painter);

        /**
         * @type {module:zrender/animation/Animation}
         */
        this.animation = new Animation({
            stage: {
                update: getFrameCallback(this)
            }
        });
        this.animation.start();

        this._needsRefreshNextFrame = false;

        // 修改 storage.delFromMap, 每次删除元素之前删除动画<commit_msg>Handler root<commit_after>/*!
 * ZRender, a high performance canvas library.
 *  
 * Copyright (c) 2013, Baidu Inc.
 * All rights reserved.
 * 
 * LICENSE
 * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
 */
define(function(require) {
    var util = require('./core/util');
    var log = require('./core/log');
    var guid = require('./core/guid');
    var env = require('./core/env');

    var Handler = require('./Handler');
    var Storage = require('./Storage');
    var Animation = require('./animation/Animation');

    var useVML = ! env.canvasSupported;
    if (useVML) {
        require('./vml/graphic');
    }
    var Painter = useVML ? require('./vml/Painter') : require('./Painter');

    var _instances = {};    // ZRender实例map索引

    var zrender = {};
    /**
     * @type {string}
     */
    zrender.version = '2.0.8';

    /**
     * 创建zrender实例
     *
     * @param {HTMLElement} dom 绘图容器
     * @return {module:zrender/ZRender} ZRender实例
     */
    // 不让外部直接new ZRender实例，为啥？
    // 不为啥，提供全局可控同时减少全局污染和降低命名冲突的风险！
    zrender.init = function(dom) {
        var zr = new ZRender(guid(), dom);
        _instances[zr.id] = zr;
        return zr;
    };

    /**
     * zrender实例销毁
     * @param {module:zrender/ZRender} zr ZRender对象，不传则销毁全部
     */
    // 在_instances里的索引也会删除了
    // 管生就得管死，可以通过zrender.dispose(zr)销毁指定ZRender实例
    // 当然也可以直接zr.dispose()自己销毁
    zrender.dispose = function (zr) {
        if (zr) {
            zr.dispose();
        }
        else {
            for (var key in _instances) {
                _instances[key].dispose();
            }
            _instances = {};
        }

        return zrender;
    };

    /**
     * 获取zrender实例
     * @param {string} id ZRender对象索引
     * @return {module:zrender/ZRender}
     */
    zrender.getInstance = function (id) {
        return _instances[id];
    };

    /**
     * 删除zrender实例，ZRender实例dispose时会调用，
     * 删除后getInstance则返回undefined
     * ps: 仅是删除，删除的实例不代表已经dispose了~~
     *     这是一个摆脱全局zrender.dispose()自动销毁的后门，
     *     take care of yourself~
     *
     * @param {string} id ZRender对象索引
     */
    zrender.delInstance = function (id) {
        delete _instances[id];
        return zrender;
    };

    function getFrameCallback(zrInstance) {
        return function () {
            if (zrInstance._needsRefreshNextFrame) {
                zrInstance.refresh();
            }
        };
    }

    /**
     * @module zrender/ZRender
     */
    /**
     * ZRender接口类，对外可用的所有接口都在这里
     * 非get接口统一返回支持链式调用
     *
     * @constructor
     * @alias module:zrender/ZRender
     * @param {string} id 唯一标识
     * @param {HTMLElement} dom dom对象，不帮你做document.getElementById
     * @return {ZRender} ZRender实例
     */
    var ZRender = function(id, dom) {
        /**
         * 实例 id
         * @type {string}
         */
        this.id = id;
        this.env = env;

        var storage = new Storage();
        var painter = new Painter(dom, storage);
        this.storage = storage;
        this.painter = painter;
        // VML 下为了性能可能会直接操作 VMLRoot 的位置
        // 因此鼠标的相对位置应该是相对于 VMLRoot
        // PENDING
        this.handler = new Handler(useVML ? painter.getVMLRoot() : dom, storage, painter);

        /**
         * @type {module:zrender/animation/Animation}
         */
        this.animation = new Animation({
            stage: {
                update: getFrameCallback(this)
            }
        });
        this.animation.start();

        this._needsRefreshNextFrame = false;

        // 修改 storage.delFromMap, 每次删除元素之前删除动画
{'fraction_non_alphanumeric': 0.13321799307958476, 'fraction_numerical': 0.002018454440599769, 'mean_word_length': 1.8594394064303381, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2304359', 'n_tokens_mistral': 2559, 'n_tokens_neox': 2588, 'n_words': 415}