Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function transformStyleSheetObjectIntoSpecification(content) {
assertPlainObject(content);
let styles = {};
foreach(content, (value, key) => {
if (isMediaQueryDeclaration.test(key)) {
processMediaQuery(styles, key.substring(1), value);
} else if (isStandaloneSelector.test(key)) {
assert(false, 'stand-alone selectors are not allowed at the top-level');
} else if (hasAttachedSelector.test(key)) {
var [styleName, selectorName] = splitSelector(key);
processStyleAndSelector(styles, styleName, selectorName, value);
} else {
processStyle(styles, key, value);
}
});
return styles;
}
function processStyleAndMediaQuery(styles, styleName, mediaQueryName, content) {
assertPlainObject(content);
let style = initStyleSpec(styles, styleName);
let mediaQuery = initMediaQuerySpec(style.mediaQueries, mediaQueryName);
foreach(content, (value, key) => {
if (isMediaQueryDeclaration.test(key)) {
assert(false, 'media queries cannot be nested into each other');
} else if (isStandaloneSelector.test(key)) {
processStyleAndMediaQueryAndSelector(styles, styleName, mediaQueryName, key, value);
} else if (hasAttachedSelector.test(key)) {
assert(false, 'styles cannot be nested into each other');
} else {
processRule(mediaQuery.rules, key, value);
}
});
}
function processStyle(styles, styleName, content, parent) {
assertPlainObject(content);
const style = initStyleSpec(styles, styleName, parent);
foreach(content, (value, key) => {
if (isMediaQueryDeclaration.test(key)) {
processStyleAndMediaQuery(styles, styleName, key.substring(1), value, parent);
} else if (isStandaloneSelector.test(key)) {
processStyleAndSelector(styles, styleName, key, value, parent);
} else if (hasAttachedSelector.test(key)) {
assert(false, 'styles cannot be nested into each other');
} else {
processRule(style.rules, key, value);
}
});
}
test('Should be an object with functions as properties', () => {
assert.isObject(model);
each(model, (prop) => assert.isFunction(prop));
});
function processSelectors(css, name, selectors, level, parent, options) {
if (isEmpty(selectors)) { return; }
foreach(selectors, (value, key) => {
processRules(css, name + key, value.rules, level, parent, options);
});
}
this.file.metadata.css = css;
if (css && css.length) {
context[KEY].cache[this.cssInJS.filename] = css;
} else {
delete context[KEY].cache[this.cssInJS.filename];
}
if (this.cssInJS.options.bundleFile && Object.keys(context[KEY].cache).length) {
const bundleFile = join(process.cwd(), this.cssInJS.options.bundleFile);
const output = [];
mkDirPSync(dirname(bundleFile));
foreach(context[KEY].cache, (fileCSS) => {
output.push(fileCSS);
});
writeFileSync(bundleFile, output.join(''), { encoding: 'utf8' });
}
context[KEY].visiting[filename] = false;
},
},
export default function(stylesheets, options) {
let css = '';
foreach(stylesheets, (stylesheet, name) => {
let cssOptions = extend({}, options);
cssOptions.prefixes = [options.filename, name];
css += transformSpecificationIntoCSS(stylesheet, cssOptions);
if (css.length) {
css += '\n';
}
});
if (css.length === 0) {
return null;
}
const vp = options.vendorPrefixes;
function processParents(css, name, parents, level, options) {
if (isEmpty(parents)) { return; }
foreach(parents, (spec, key) => {
processStyle(css, name, spec, level, key, options);
});
}
function processRules(css, name, rules, level, options) {
if (isEmpty(rules)) { return; }
css.push(indent(level) + '.' + generateClassName(name, options) + ' {');
foreach(rules, (value, key) => {
css.push(indent(level + 1) + buildCSSRule(key, value, options));
});
css.push(indent(level) + '}');
}