Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
$('style[type="text/css"]').each(function() {
if ($(this).attr("data-skip-inline")) {
$(this).removeAttr("data-skip-inline");
return;
}
// If the style tag is inside a
this.files.forEach(function(f) {
var src = f.src.filter(function(filepath) {
// Warn on and remove invalid source files (if nonull was set).
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function(filepath) {
// Read file source.
return grunt.file.read(filepath);
}).join(grunt.util.normalizelf(grunt.util.linefeed));
// Parse the style
var style = css.parse(src);
// Do the magic!
style.stylesheet.rules = stripMediaQueries(style.stylesheet.rules, options.overridesOnly);
var output = css.stringify(style);
// Write the destination file.
grunt.file.write(f.dest, output);
// Print a success message.
grunt.log.writeln('File "' + chalk.cyan(f.dest) + '" created: ' +
maxmin(src, output, false));
});
});
browser.on('har', function(har, done) {
if (har && har.log && har.log.entries) {
for (var i = 0; i < har.log.entries.length; i++) {
var entry = har.log.entries[i];
if (entry.response.status === 200) {
var mediaType = utils.mediaTypeName(entry.response.content
.mimeType);
if (mediaType === "text/css") {
if (entry.response.content.text === undefined) {
// not sure why that happens
// but cssparser breaks on undefined
continue;
}
var url = entry.request.url;
var cssObj = cssParser.parse(entry.response.content
.text, {
silent: true
});
for (var j = 0; j < cssObj.stylesheet.rules.length; j++) {
var rule = cssObj.stylesheet.rules[j];
var prefixedProperties = {};
var unprefixedProperties = {};
if (rule.declarations) {
for (var k = 0; k < rule.declarations.length; k++) {
var decl = rule.declarations[k];
if (decl.property && hasprefix(decl.property)) {
var unprefixed = unprefix(decl.property);
if (!prefixedProperties[unprefixed]) {
prefixedProperties[unprefixed] = {};
}
prefixedProperties[unprefixed][decl
tagStr = tagStr.replace(attr, cliColor.redBright(attr));
});
}
tagStr = tagStr.replace(new RegExp('\\'+tagName, 'ig'), cliColor.blueBright(tagName));
str = str.replace(tag, tagStr);
}
});
str = str.replace(/\>/g, cliColor.blueBright('>'));
str = str.replace(/\<\!DOCTYPE html(.+)?\>(.+)?/i, cliColor.bold.blackBright(''));
}else if (str.match(/(^|\n)( +)?[\.\:\#\[\]][a-z0-9\-\_\=\(\)\, \[\]]([\s\S]+)?\{/i)) {
// is probably css
let css = require('css');
let obj = css.parse(str, {silent:true});
let cssResult = '';
if(!obj.parsingErrors){
let i = 1;
obj.stylesheet.rules.forEach(rule=>{
let sels = [];
rule.selectors.forEach(selector => {
let selStr = cliColor.blueBright(selector
.replace(/\[/g, cliColor.magenta('['))
.replace(/\:hover/g, cliColor.redBright(":hover"))
.replace(/\:active/g, cliColor.redBright(":active"))
.replace(/\:visited/g, cliColor.redBright(":visited"))
.replace(/\:link/g, cliColor.redBright(":link"))
.replace(/\:after/g, cliColor.redBright(":after"))
.replace(/\:before/g, cliColor.redBright(":before"))
function getPrettyStylesFromClassNames(
classNames: Array,
elements: Array
) {
let styles = getStylesFromClassNames(classNames, elements)
let prettyStyles
try {
prettyStyles = css.stringify(css.parse(styles))
} catch (e) {
console.error(e)
throw new Error(`There was an error parsing the following css: "${styles}"`)
}
return prettyStyles
}
StyleScope.createSelectorsFromCss = function (css, cssFileName, keyframes) {
try {
var pageCssSyntaxTree = css ? cssParser.parse(css, { source: cssFileName }) : null;
var pageCssSelectors = [];
if (pageCssSyntaxTree) {
pageCssSelectors = pageCssSelectors.concat(StyleScope.createSelectorsFromImports(pageCssSyntaxTree, keyframes));
pageCssSelectors = pageCssSelectors.concat(StyleScope.createSelectorsFromSyntaxTree(pageCssSyntaxTree, keyframes));
}
return pageCssSelectors;
}
catch (e) {
trace.write("Css styling failed: " + e, trace.categories.Error, trace.messageType.error);
}
};
StyleScope.createSelectorsFromImports = function (tree, keyframes) {
const parseStyleToObject = (style) => {
try {
const styleObj = {};
const wrappedStyle = `.whatever { ${style} } `;
const cssAst = css.parse(wrappedStyle);
const { declarations } = cssAst.stylesheet.rules[0];
declarations.forEach(({ property, value }) => {
const camelCaseProperty = camelCaseCss(property);
styleObj[camelCaseProperty] = value;
});
return styleObj;
} catch (_) {
return {};
}
};
function formatComputedStyles(nodeSelectors, computedStyles) {
const selector = nodeSelectors.join('');
const cssString = `${selector} {
${Object.keys(computedStyles)
.map(k => `${k}: ${computedStyles[k]};`)
.join('\n')}
}`;
return css.stringify(css.parse(cssString));
}
function flip(str, options) {
var ast = css.parse(str, options);
flipNode(ast.stylesheet);
return css.stringify(ast, options);
}
function processStyles (opts, source) {
var ast = css.parse(source);
var rules = ast.stylesheet.rules;
rules.
forEach(function (rule) {
var selectors = rule.selectors;
rule.selectors =
selectors.
map(function (sel) {
return sel.
replace(
CLASSNAME_OR_ID_SELECTOR_REGEX,
function (match, pre, post) {
var newname = pre + opts.prefix + post;
opts.cache[post] = newname;
return newname;