<commit_before>(function(root, factory) {

  // Set up Backbone appropriately for the environment. Start with AMD.
  if (typeof define === 'function' && define.amd) {
    define(['underscore', 'jquery', 'modernizr'], factory);

  // Next for Node.js or CommonJS. jQuery may not be needed as a module.
  } else if (typeof exports !== 'undefined') {
    var _ = require('underscore');
    var $ = require('underscore');
    var Modernizr = require('Modernizr');

    factory(_, $, Modernizr);

  // Finally, as a browser global.
  } else {
    root.Trans = factory(root._, (root.$ || root.jQuery), root.Modernizr);
  }

}(this, function(_, $, Modernizr) {

    'use strict';

    var w = window;
    var doc = document;

    var hasCSSTransitions = Modernizr.csstransitions;

    var transitionProperty = Modernizr.prefixed('transition');

    var transitionEndEvent = {
        WebkitTransition: 'webkitTransitionEnd',
        MozTransition: 'transitionend',
        OTransition: 'otransitionend',
        transition: 'transitionend'
    }[transitionProperty];

    var splitCommasOutside = function(str) {
        return str.split(/(?:,+\s)(?=(?:[^\(\)]|[\(\)|\(\)][^\(\)]*[\(|\)])*$)/g);
    };

    var addStyleTag = function(css) {
        var tag = doc.createElement('style');
        tag.setAttribute('type', 'text/css');
        doc.getElementsByTagName('head')[0].appendChild(tag);
        if (tag.styleSheet) {
            tag.styleSheet.cssText = css;
        } else {
            tag.appendChild(doc.createTextNode(css));
        }
    };


    function Trans($el, opts) {
        var ins = $el.data('trans');
        var _this = ins || this;
        var optsIsFn = $.isFunction(opts);

        _this.$el = $el;
        _this.el = $el[0];
        _this.opts = {};

        !optsIsFn && (_this.opts = opts || {});
        optsIsFn && (_this.opts.endAll = opts);

        if (!ins) {
            _this.$el.data('trans', _this.init());
        } else {
            return ins;
        }
    }

    Trans.css = '.js-notransition {' +
                '  -webkit-transition: none !important;' +
                '  -moz-transition: none !important;' +
                '  -o-transition: none !important;' +
                '  -ms-transition: none !important;' +
                '  transition: none !important;' +
                '}';

    Trans.autoProps = {
        'height': true,
        'width': true,
        'opacity': true,
    };

    Trans.maps = {
        'dimension': {
            'from': {
                '0px': '*',
                '*': '*'
            },
            'to': {
                '0px': '',
                '*': ''
            }
        },
        'display': {
            'opacity': {
                'from': {
                    '0': 'block',
                    '1': 'block'
                },
                'to': {
                    '0': 'none',
                    '1': 'block'
                }
            },
            'dimension': {
                'from': {
                    '0px': 'block',
                    '*': 'block'
                },
                'to': {
                    '0px': '',
                    '*': 'block'
                }
            }
        }
    };

    Trans.methods = {
        'add': $.fn.addClass,
        'remove': $.fn.removeClass
    };

    _.extend(Trans.prototype, {
        init: function() {
            this.transClass = '';
            this.transProps = {};
            this.transPrefix = _.filter(Modernizr._cssomPrefixes, function(prfx) {
                return Modernizr.prefixed(prfx + 'Transition');
            })[0];
            return this;
        },

        repaint: function() {
            this.$el.width();
        },

        manageAutoProps: function(point, props) {
            props || (props = this.transProps);
            var i, css = {};

            if (!_.intersection(_.keys(Trans.autoProps), _.keys(props)).length) {
                return;
            }

            var _display = function(prop) {
                var i = props[prop][point];
                i === '0px' || (i = '*');
                var val = Trans.maps.display.dimension[point][i];
                css['display'] = val;
            };

            var _dimension = function(prop) {
                var fromVal, toVal, i, val, size, z;
                fromVal = props[prop]['from'];
                toVal = props[prop]['to'];

                if ((fromVal == 'auto' || toVal == 'auto') ||
                    (fromVal == '0px' || toVal == '0px')) {
                    i = props[prop][point];
                    size = i !== '0px' ? fromVal : toVal;
                    z = i === '0px' ? '0px' : '*';
                    val = Trans.maps.dimension[point][z];
                    if (val === '*') { val = size; }
                    css[prop] = val;
                }
            };

            if (props['opacity']) {
                i = props['opacity'][point];
                css['display'] = Trans.maps.display.opacity[point][i];
            }

            _.each(['width', 'height'], function(prop) {
                if (props[prop]) {
                    _display(prop);
                    _dimension(prop);
                }
            });

            if (_.size(css)) {
                this.$el.css(css);
                this.repaint();
            }
        },

        getTransitionValue: function() {
            var style = w.getComputedStyle(this.el, null);
            this.transitionValue = style.getPropertyValue(transitionProperty);

            if (!hasCSSTransitions) {
                this.transitionValue = splitCommasOutside(this.$el.css('transition'));
                return;
            }

            // firefox doesn't return data in shorthand CSS props
            if (!this.transitionValue || !this.transitionValue.length) {
                // TODO: move this to a test method fired after init
                var prefix = this.transPrefix;
                var properties = this.$el.css(prefix + 'TransitionProperty').split(', ');

                var transitions = [];
                for (var i = properties.length - 1; i >= 0; i--) {
                    transitions.push(properties[i]);
                }<commit_msg>chore: improve manageAutoProps method<commit_after>(function(root, factory) {

  // Set up Backbone appropriately for the environment. Start with AMD.
  if (typeof define === 'function' && define.amd) {
    define(['underscore', 'jquery', 'modernizr'], factory);

  // Next for Node.js or CommonJS. jQuery may not be needed as a module.
  } else if (typeof exports !== 'undefined') {
    var _ = require('underscore');
    var $ = require('jquery');
    var Modernizr = require('Modernizr');

    factory(_, $, Modernizr);

  // Finally, as a browser global.
  } else {
    root.Trans = factory(root._, (root.$ || root.jQuery), root.Modernizr);
  }

}(this, function(_, $, Modernizr) {

    'use strict';

    var w = window;
    var doc = document;

    var hasCSSTransitions = Modernizr.csstransitions;

    var transitionProperty = Modernizr.prefixed('transition');

    var transitionEndEvent = {
        WebkitTransition: 'webkitTransitionEnd',
        MozTransition: 'transitionend',
        OTransition: 'otransitionend',
        transition: 'transitionend'
    }[transitionProperty];

    var splitCommasOutside = function(str) {
        return str.split(/(?:,+\s)(?=(?:[^\(\)]|[\(\)|\(\)][^\(\)]*[\(|\)])*$)/g);
    };

    var addStyleTag = function(css) {
        var tag = doc.createElement('style');
        tag.setAttribute('type', 'text/css');
        doc.getElementsByTagName('head')[0].appendChild(tag);
        if (tag.styleSheet) {
            tag.styleSheet.cssText = css;
        } else {
            tag.appendChild(doc.createTextNode(css));
        }
    };


    function Trans($el, opts) {
        var ins = $el.data('trans');
        var _this = ins || this;
        var optsIsFn = $.isFunction(opts);

        _this.$el = $el;
        _this.el = $el[0];
        _this.opts = {};

        !optsIsFn && (_this.opts = opts || {});
        optsIsFn && (_this.opts.endAll = opts);

        if (!ins) {
            _this.$el.data('trans', _this.init());
        } else {
            return ins;
        }
    }

    Trans.css = '.js-notransition {' +
                '  -webkit-transition: none !important;' +
                '  -moz-transition: none !important;' +
                '  -o-transition: none !important;' +
                '  -ms-transition: none !important;' +
                '  transition: none !important;' +
                '}';

    Trans.autoProps = {
        'height': true,
        'width': true,
        'opacity': true,
    };

    Trans.maps = {
        'dimension': {
            'from': {
                '0px': '*',
                '*': '*'
            },
            'to': {
                '0px': '',
                '*': ''
            }
        },
        'display': {
            'opacity': {
                'from': {
                    '0': 'block',
                    '1': 'block'
                },
                'to': {
                    '0': 'none',
                    '1': 'block'
                }
            },
            'dimension': {
                'from': {
                    '0px': 'block',
                    '*': 'block'
                },
                'to': {
                    '0px': '',
                    '*': 'block'
                }
            }
        }
    };

    Trans.methods = {
        'add': $.fn.addClass,
        'remove': $.fn.removeClass
    };

    _.extend(Trans.prototype, {
        init: function() {
            this.transClass = '';
            this.transProps = {};
            this.transPrefix = _.filter(Modernizr._cssomPrefixes, function(prfx) {
                return Modernizr.prefixed(prfx + 'Transition');
            })[0];
            return this;
        },

        repaint: function() {
            this.$el.width();
        },

        manageAutoProps: function(point, props) {
            props || (props = this.transProps);
            var css = {};

            if (!_.intersection(_.keys(Trans.autoProps), _.keys(props)).length) {
                return;
            }

            var _setProp = function(prop, subprop) {
                var fromVal, toVal, i, val, size, z;
                fromVal = props[(subprop || prop)]['from'];
                toVal = props[(subprop || prop)]['to'];
                i = props[(subprop || prop)][point];

                switch (prop) {
                    case "display":
                        if (fromVal !== '0px' && toVal !== '0px') { return; }
                        i === '0px' || (i = '*');
                        val = Trans.maps.display.dimension[point][i];
                        css['display'] = val;
                    break;

                    case "width":
                    case "height":
                        if ((fromVal == 'auto' || toVal == 'auto') ||
                            (fromVal == '0px' || toVal == '0px')) {
                            size = i !== '0px' ? fromVal : toVal;
                            z = i === '0px' ? '0px' : '*';
                            val = Trans.maps.dimension[point][z];
                            if (val === '*') { val = size; }
                            css[prop] = val;
                        }
                    break;
                }

            };

            if (props['opacity']) {
                var j = props['opacity'][point];
                // console.log(i, point, '---', Trans.maps.display.opacity[point][i]);
                css['display'] = Trans.maps.display.opacity[point][j];
            }


            _.each(['width', 'height'], function(prop) {
                if (props[prop]) {
                    _setProp('display', prop);
                    // _setProp(prop);
                }
            });

            if (_.size(css)) {
                this.$el.css(css);
                this.repaint();
            }
        },

        getTransitionValue: function() {
            var style = w.getComputedStyle(this.el, null);
            this.transitionValue = style.getPropertyValue(transitionProperty);

            if (!hasCSSTransitions) {
                this.transitionValue = splitCommasOutside(this.$el.css('transition'));
                return;
            }

            // firefox doesn't return data in shorthand CSS props
            if (!this.transitionValue || !this.transitionValue.length) {
                // TODO: move this to a test method fired after init
                var prefix = this.transPrefix;
                var properties = this.$el.css(prefix + 'TransitionProperty').split(', ');

                var transitions = [];
                for (var i = properties.length - 1; i >= 0; i--) {
                    transitions.push(properties[i]);
                }
{'fraction_non_alphanumeric': 0.15463837695524238, 'fraction_numerical': 0.003097413659594239, 'mean_word_length': 1.325769854132901, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4163004', 'n_tokens_mistral': 3705, 'n_tokens_neox': 3456, 'n_words': 716}