<commit_before>var paramCase = require('param-case');

var generatedStyles.counter;

//tools
var Prefixer = require('./tools/Prefixer');
var Validator = require('./tools/Validator');
var DebugHelper = require('./tools/DebugHelper');
var unitlessProperties = require('./tools/Unitless');

var Stylesheet = {
	output: undefined,
	debugMode: false,
	/*
     Main function to create a new stylesheet
     This returns a totally generated style object with prefixes, media queries and browser state
     Check the README for detailed information on the options
  */

	//userAgent, vendorPrefix, unit, debugMode, selectorPrefix, autoApply, counter
	create: function(styles, options) {
		options = (options ? options : {});

		this.debugMode = (options.debugMode ? options.debugMode : false);
		this.debugMode && DebugHelper.start();


		options.unit = (options.unit ? options.unit : 'px');
		options.vendorPrefix = (options.vendorPrefix ? options.vendorPrefix : Prefixer.getVendorPrefix(options.userAgent));
		options.autoApply = (options.autoApply ? options.autoApply : true);

		counter = (options.counter ? options.counter : 0);

		generatedStyles = {};

		this.generateSelectors(styles, options);


		this.output = '';
		var selector;
		for (selector in generatedStyles) {
			this.output += selector + '{' + generatedStyles[selector] + '}';
		}

		if (this.debugMode) {
			DebugHelper.selectorInformation(generatedStyles);
			DebugHelper.outputStored(this.output);
			!options.autoApply && this.stop();
		}
		options.autoApply && this.apply();

		return styles;
	},


	apply: function(CSS)  {
		CSS = (CSS ? CSS : this.output);

		if (!CSS) {
			this.debugMode && DebugHelper.noStylesheetWarning();
		} else {
			var style = document.createElement('style');
			style.type = "text/css";
			style.innerHTML = CSS;

			document.head.appendChild(style);
			this.debugMode && DebugHelper.stylesheetApplied();
		}
		this.debugMode && DebugHelper.stop()
		return CSS;
	},

	/*
		Generates an object with selectors as key and a CSS string as value for a given styles object
	*/
	generateSelectors: function(styles, options, parent) {
		options.selectorPrefix = (options.selectorPrefix ? options.selectorPrefix.trim() + ' ' : '');
		parent = (parent ? parent : '');

		var selector;
		for (selector in styles) {
			if (styles[selector] instanceof Object) {
				if (Validator.isClass(selector)) {
					this.handleClass(selector, parent, styles, options);
				} else {
					//check for extends
					if (Validator.isExtend(selector)) {
						//TODO: handle extend
					}
					//check for media queries
					if (Validator.isMediaQuery(selector)) {
						//TODO: handle media queries
					}
					//check for pseudo classes
					if (Validator.isPseudoClass(selector)) {
						//TODO: handle pseudo classes
					}
				}
			} else {
				this.handleProperty(selector, parent, styles[selector], options);
			}
		}
	},

	/*
		Generates a new class selector and calls for its properties
	*/
	handleClass: function(selector, className, styles, options) {
		className = this.generateClassName(selector);
		generatedStyles[className] = '';
		this.generateSelectors(styles[selector], options, className);
		styles[selector] = className;
		className = '';
	},

	/*
		Validates properties for vendor prefixes and assigns to a given selector
	*/
	handleProperty: function(property, selector, style, options) {
		var value = this.addUnits(selector, style, options.unit);
		//adds additional vendor prefxied properties
		if (Prefixer.isPrefixProperty(property, options.vendorPrefix)) {
			this.addCSSProperty(selector, paramCase(Prefixer.getPrefixedProperty(selector, options.vendorPrefix)), value);
		}
		this.addCSSProperty(selector, paramCase(selector), value)
	},

	/*
		Adds a property to a given selector
	*/
	addCSSProperty: function(selector, property, value) {
		generatedStyles[selector] && (generatedStyles[selector] += ';')
		generatedStyles[selector] += property + ':' + value;
	},

	/*
	  checks if a value needs a unit
	*/
	addUnits: function(selector, value, unit) {
		if (!isNaN(value) && unitlessProperties.indexOf(selector) == -1) {
			value += unit;
		}
		return value;
	},

	/* 
	   Checks the selectors type and generates CSS valid selectors
	*/
	generateClassName: function(selector) {
		if (!this.debugMode) {
			selector = 'c' + counter.toString(36);
			++counter;
		}
		selector = '.' + selector;
		return selector;
	}
};


module.exports = Stylesheet;<commit_msg>added merge helper for multiple style assignments<commit_after>var paramCase = require('param-case');

var generatedStyles.counter;

//tools
var Prefixer = require('./tools/Prefixer');
var Validator = require('./tools/Validator');
var DebugHelper = require('./tools/DebugHelper');
var unitlessProperties = require('./tools/Unitless');

var Stylesheet = {
	output: undefined,
	debugMode: false,
	/*
     Main function to create a new stylesheet
     This returns a totally generated style object with prefixes, media queries and browser state
     Check the README for detailed information on the options
  */

	//userAgent, vendorPrefix, unit, debugMode, selectorPrefix, autoApply, counter
	create: function(styles, options) {
		options = (options ? options : {});

		this.debugMode = (options.debugMode ? options.debugMode : false);
		this.debugMode && DebugHelper.start();


		options.unit = (options.unit ? options.unit : 'px');
		options.vendorPrefix = (options.vendorPrefix ? options.vendorPrefix : Prefixer.getVendorPrefix(options.userAgent));
		options.autoApply = (options.autoApply ? options.autoApply : true);

		counter = (options.counter ? options.counter : 0);

		generatedStyles = {};

		this.generateSelectors(styles, options);


		this.output = '';
		var selector;
		for (selector in generatedStyles) {
			this.output += selector + '{' + generatedStyles[selector] + '}';
		}

		if (this.debugMode) {
			DebugHelper.selectorInformation(generatedStyles);
			DebugHelper.outputStored(this.output);
			!options.autoApply && this.stop();
		}
		options.autoApply && this.apply();

		return styles;
	},


	apply: function(CSS)  {
		CSS = (CSS ? CSS : this.output);

		if (!CSS) {
			this.debugMode && DebugHelper.noStylesheetWarning();
		} else {
			var style = document.createElement('style');
			style.type = "text/css";
			style.innerHTML = CSS;

			document.head.appendChild(style);
			this.debugMode && DebugHelper.stylesheetApplied();
		}
		this.debugMode && DebugHelper.stop()
		return CSS;
	},

	/*
		Generates an object with selectors as key and a CSS string as value for a given styles object
	*/
	generateSelectors: function(styles, options, parent) {
		options.selectorPrefix = (options.selectorPrefix ? options.selectorPrefix.trim() + ' ' : '');
		parent = (parent ? parent : '');

		var selector;
		for (selector in styles) {
			if (styles[selector] instanceof Object) {
				if (Validator.isClass(selector)) {
					this.handleClass(selector, parent, styles, options);
				} else {
					//check for extends
					if (Validator.isExtend(selector)) {
						//TODO: handle extend
					}
					//check for media queries
					if (Validator.isMediaQuery(selector)) {
						//TODO: handle media queries
					}
					//check for pseudo classes
					if (Validator.isPseudoClass(selector)) {
						//TODO: handle pseudo classes
					}
				}
			} else {
				this.handleProperty(selector, parent, styles[selector], options);
			}
		}
	},

	/*
		Generates a new class selector and calls for its properties
	*/
	handleClass: function(selector, className, styles, options) {
		className = this.generateClassName(selector);
		generatedStyles[className] = '';
		this.generateSelectors(styles[selector], options, className);
		styles[selector] = className;
		className = '';
	},

	/*
		Validates properties for vendor prefixes and assigns to a given selector
	*/
	handleProperty: function(property, selector, style, options) {
		var value = this.addUnits(selector, style, options.unit);
		//adds additional vendor prefxied properties
		if (Prefixer.isPrefixProperty(property, options.vendorPrefix)) {
			this.addCSSProperty(selector, paramCase(Prefixer.getPrefixedProperty(selector, options.vendorPrefix)), value);
		}
		this.addCSSProperty(selector, paramCase(selector), value)
	},

	/*
		Adds a property to a given selector
	*/
	addCSSProperty: function(selector, property, value) {
		generatedStyles[selector] && (generatedStyles[selector] += ';')
		generatedStyles[selector] += property + ':' + value;
	},

	/*
	  checks if a value needs a unit
	*/
	addUnits: function(selector, value, unit) {
		if (!isNaN(value) && unitlessProperties.indexOf(selector) == -1) {
			value += unit;
		}
		return value;
	},

	/* 
	   Checks the selectors type and generates CSS valid selectors
	*/
	generateClassName: function(selector) {
		if (!this.debugMode) {
			selector = 'c' + counter.toString(36);
			++counter;
		}
		selector = '.' + selector;
		return selector;
	},

	/* 
	Generates a html attribute valid className string for direct use
*/
	mergeClassNames: function(classNames) {
		if (classNames instanceof Array) {
			classNames = classNames.join(' ');
		}
		return classNames;
	}
};


module.exports = Stylesheet;
{'fraction_non_alphanumeric': 0.1275621456607065, 'fraction_numerical': 0.0008722197993894462, 'mean_word_length': 3.8922666666666665, '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': '2177795', 'n_tokens_mistral': 3008, 'n_tokens_neox': 2663, 'n_words': 691}