Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ module.exports = postcss.plugin('postcss-px-to-viewport', function (options) {

if (blacklistedSelector(opts.selectorBlackList, rule.selector)) return;

if (blacklistedPath(opts.blacklistPath, file)) return;

if (opts.landscape && !rule.parent.params) {
var landscapeRule = rule.clone().removeAll();

rule.walkDecls(function(decl) {
rule.walkDecls(function (decl) {
if (decl.value.indexOf(opts.unitToConvert) === -1) return;
if (!satisfyPropList(decl.prop)) return;

Expand All @@ -86,7 +88,7 @@ module.exports = postcss.plugin('postcss-px-to-viewport', function (options) {

if (!validateParams(rule.parent.params, opts.mediaQuery)) return;

rule.walkDecls(function(decl, i) {
rule.walkDecls(function (decl, i) {
if (decl.value.indexOf(opts.unitToConvert) === -1) return;
if (!satisfyPropList(decl.prop)) return;

Expand Down Expand Up @@ -136,7 +138,7 @@ module.exports = postcss.plugin('postcss-px-to-viewport', function (options) {
if (landscapeRules.length > 0) {
var landscapeRoot = new postcss.atRule({ params: '(orientation: landscape)', name: 'media' });

landscapeRules.forEach(function(rule) {
landscapeRules.forEach(function (rule) {
landscapeRoot.append(rule);
});
css.append(landscapeRoot);
Expand Down Expand Up @@ -185,6 +187,14 @@ function toFixed(number, precision) {
return Math.round(wholeNumber / 10) * 10 / multiplier;
}

function blacklistedPath(blacklist, path) {
if (typeof path !== 'string') return;
return blacklist.some((regex) => {
if (typeof regex === 'string') return path.indexOf(regex) !== -1;
return path.match(regex);
});
}

function blacklistedSelector(blacklist, selector) {
if (typeof selector !== 'string') return;
return blacklist.some(function (regex) {
Expand All @@ -195,7 +205,7 @@ function blacklistedSelector(blacklist, selector) {

function declarationExists(decls, prop, value) {
return decls.some(function (decl) {
return (decl.prop === prop && decl.value === value);
return (decl.prop === prop && decl.value === value);
});
}

Expand Down