<commit_before>module.exports = css;


var win = window;


/** Get clean style */
var fakeStyle = document.createElement('div').style;


/** Detect vendor prefix */
var prefix = css['prefix'] = (function() {
	var regex = /^(webkit|moz|ms|O|khtml)[A-Z]/, prop;
	for (prop in fakeStyle) {
		if (regex.test(prop)) {
			return prop.match(regex)[1];
		}
	}
	return '';
}());


/** Prevent you know what */
function pd(e){
	e.preventDefault();
}


/**
 * Disable or Enable any selection possibilities for an element
 *
 * @param    {Element}   $el   Target to make unselectable
 *
 * @return   {[type]}   [description]
 */

css['disableSelection'] = function($el){
	css($el, {
		'user-select': 'none',
		'user-drag': 'none',
		'touch-callout': 'none'
	});
	$el.setAttribute('unselectable', 'on');
	$el.addEventListener('selectstart', pd);
};
css['enableSelection'] = function($el){
	css($el, {
		'user-select': null,
		'user-drag': null,
		'touch-callout': null
	});
	$el.removeAttribute('unselectable');
	$el.removeEventListener('selectstart', pd);
};


/**
 * Return paddings of an element
 *
 * @param    {Element}   $el   An element to calc paddings
 *
 * @return   {Object}   Paddings object {top:n, bottom:n, left:n, right:n}
 */

css['paddings'] = function($el){
	var style = getComputedStyle($el);

	return {
		top: parseValue(style.paddingTop),
		left: parseValue(style.paddingLeft),
		bottom: parseValue(style.paddingBottom),
		right: parseValue(style.paddingRight)
	};
};


/**
 * Return paddings of an element
 *
 * @param    {Element}   $el   An element to calc paddings
 *
 * @return   {Object}   Paddings object {top:n, bottom:n, left:n, right:n}
 */

css['margins'] = function($el){
	var style = getComputedStyle($el);

	return {
		top: parseValue(style.marginTop),
		left: parseValue(style.marginLeft),
		bottom: parseValue(style.marginBottom),
		right: parseValue(style.marginRight)
	};
};


/** Returns parsed css value */
function parseValue(str){
	str += '';
	return ~~str.slice(0,-2);
}
css['parseValue'] = parseValue;


/**
 * Return absolute offsets
 *
 * @param    {Element}   el   A target
 *
 * @return   {Object}   Offsets object with trbl, fromRight, fromLeft
 */

css['offsets'] = function(el){
	if (!el) return;

	var cRect;

	try {
		cRect = el.getBoundingClientRect();
	} catch (e) {
		cRect = {
			top: el.clientTop,
			left: el.clientLeft
		};
	}

	//whether element is or is in fixed
	var isNotFixed = 0, parentEl = el;
	while (parentEl && isNotFixed) {
		isNotFixed = getComputedStyle(parentEl).position === 'fixed' ? 0 : 1;
		parentEl = el.parentNode;
	}

	return {
		top: cRect.top + (isNotFixed && win.pageYOffset),
		left: cRect.left + (isNotFixed && win.pageXOffset),
		width: el.offsetWidth,
		height: el.offsetHeight,
		bottom: cRect.top + (isNotFixed && win.pageYOffset) + el.offsetHeight,
		right: cRect.left + (isNotFixed && win.pageXOffset) + el.offsetWidth,
		fromRight: win.innerWidth - cRect.left - el.offsetWidth,
		fromBottom: (win.innerHeight + (isNotFixed && win.pageYOffset) - cRect.top - el.offsetHeight)
	};
};


/**
 * Apply styles to an element.
 * Main function returned from the module.
 *
 * @param    {Element}   el   An element to apply styles
 * @param    {Object}   obj   Set of style rules
 *
 */

function css(el, obj){
	if (!el || !obj) return;
	var propName;

	//return value, if string passed
	if (typeof obj === 'string') {<commit_msg>Enhance fixed detection<commit_after>module.exports = css;


var win = window;


/** Get clean style */
var fakeStyle = document.createElement('div').style;


/** Detect vendor prefix */
var prefix = css['prefix'] = (function() {
	var regex = /^(webkit|moz|ms|O|khtml)[A-Z]/, prop;
	for (prop in fakeStyle) {
		if (regex.test(prop)) {
			return prop.match(regex)[1];
		}
	}
	return '';
}());


/** Prevent you know what */
function pd(e){
	e.preventDefault();
}


/**
 * Disable or Enable any selection possibilities for an element
 *
 * @param    {Element}   $el   Target to make unselectable
 *
 * @return   {[type]}   [description]
 */

css['disableSelection'] = function($el){
	css($el, {
		'user-select': 'none',
		'user-drag': 'none',
		'touch-callout': 'none'
	});
	$el.setAttribute('unselectable', 'on');
	$el.addEventListener('selectstart', pd);
};
css['enableSelection'] = function($el){
	css($el, {
		'user-select': null,
		'user-drag': null,
		'touch-callout': null
	});
	$el.removeAttribute('unselectable');
	$el.removeEventListener('selectstart', pd);
};


/**
 * Return paddings of an element
 *
 * @param    {Element}   $el   An element to calc paddings
 *
 * @return   {Object}   Paddings object {top:n, bottom:n, left:n, right:n}
 */

css['paddings'] = function($el){
	var style = getComputedStyle($el);

	return {
		top: parseValue(style.paddingTop),
		left: parseValue(style.paddingLeft),
		bottom: parseValue(style.paddingBottom),
		right: parseValue(style.paddingRight)
	};
};


/**
 * Return paddings of an element
 *
 * @param    {Element}   $el   An element to calc paddings
 *
 * @return   {Object}   Paddings object {top:n, bottom:n, left:n, right:n}
 */

css['margins'] = function($el){
	var style = getComputedStyle($el);

	return {
		top: parseValue(style.marginTop),
		left: parseValue(style.marginLeft),
		bottom: parseValue(style.marginBottom),
		right: parseValue(style.marginRight)
	};
};


/** Returns parsed css value */
function parseValue(str){
	str += '';
	return ~~str.slice(0,-2);
}
css['parseValue'] = parseValue;


/**
 * Return absolute offsets
 *
 * @param    {Element}   el   A target
 *
 * @return   {Object}   Offsets object with trbl, fromRight, fromLeft
 */

css['offsets'] = function(el){
	if (!el) return;

	var cRect;

	try {
		cRect = el.getBoundingClientRect();
	} catch (e) {
		cRect = {
			top: el.clientTop,
			left: el.clientLeft
		};
	}

	//whether element is or is in fixed
	var isNotFixed = 1, parentEl = el;
	while (parentEl.nodeType === 1 && isNotFixed) {
		isNotFixed = getComputedStyle(parentEl).position === 'fixed' ? 0 : 1;
		parentEl = parentEl.parentNode;
	}

	return {
		top: cRect.top + (isNotFixed && win.pageYOffset),
		left: cRect.left + (isNotFixed && win.pageXOffset),
		width: el.offsetWidth,
		height: el.offsetHeight,
		bottom: cRect.top + (isNotFixed && win.pageYOffset) + el.offsetHeight,
		right: cRect.left + (isNotFixed && win.pageXOffset) + el.offsetWidth,
		fromRight: win.innerWidth - cRect.left - el.offsetWidth,
		fromBottom: (win.innerHeight + (isNotFixed && win.pageYOffset) - cRect.top - el.offsetHeight)
	};
};


/**
 * Apply styles to an element.
 * Main function returned from the module.
 *
 * @param    {Element}   el   An element to apply styles
 * @param    {Object}   obj   Set of style rules
 *
 */

function css(el, obj){
	if (!el || !obj) return;
	var propName;

	//return value, if string passed
	if (typeof obj === 'string') {
{'fraction_non_alphanumeric': 0.16474030724213606, 'fraction_numerical': 0.0019019751280175566, 'mean_word_length': 3.727524204702628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1927902', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2364, 'n_words': 593}