postcss-normalize-repeat-style
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -37,54 +37,84 @@ 'use strict'; | ||
function transform(decl) { | ||
const values = (0, _postcssValueParser2.default)(decl.value); | ||
if (values.nodes.length === 1) { | ||
return; | ||
} | ||
const args = (0, _cssnanoUtilGetArguments2.default)(values); | ||
const relevant = []; | ||
args.forEach(arg => { | ||
relevant.push({ | ||
start: null, | ||
end: null | ||
}); | ||
arg.forEach((part, index) => { | ||
const isRepeat = ~repeatKeywords.indexOf(part.value.toLowerCase()); | ||
const len = relevant.length - 1; | ||
if (relevant[len].start === null && isRepeat) { | ||
relevant[len].start = index; | ||
relevant[len].end = index; | ||
exports.default = _postcss2.default.plugin('postcss-normalize-repeat-style', () => { | ||
return css => { | ||
const cache = {}; | ||
css.walkDecls(/background(-repeat)?|(-webkit-)?mask-repeat/i, decl => { | ||
const value = decl.value; | ||
if (cache[value]) { | ||
decl.value = cache[value]; | ||
return; | ||
} | ||
if (relevant[len].start !== null) { | ||
if (part.type === 'space') { | ||
const parsed = (0, _postcssValueParser2.default)(value); | ||
if (parsed.nodes.length === 1) { | ||
cache[value] = value; | ||
return; | ||
} | ||
const args = (0, _cssnanoUtilGetArguments2.default)(parsed); | ||
const relevant = []; | ||
args.forEach(arg => { | ||
relevant.push({ | ||
start: null, | ||
end: null | ||
}); | ||
arg.forEach((part, index) => { | ||
const isRepeat = ~repeatKeywords.indexOf(part.value.toLowerCase()); | ||
const len = relevant.length - 1; | ||
if (relevant[len].start === null && isRepeat) { | ||
relevant[len].start = index; | ||
relevant[len].end = index; | ||
return; | ||
} | ||
if (relevant[len].start !== null) { | ||
if (part.type === 'space') { | ||
return; | ||
} else if (isRepeat) { | ||
relevant[len].end = index; | ||
return; | ||
} | ||
return; | ||
} | ||
}); | ||
}); | ||
relevant.forEach((range, index) => { | ||
if (range.start === null) { | ||
return; | ||
} else if (isRepeat) { | ||
relevant[len].end = index; | ||
} | ||
const val = args[index].slice(range.start, range.end + 1); | ||
if (val.length !== 3) { | ||
return; | ||
} | ||
return; | ||
} | ||
const match = getMatch(val.filter(evenValues).map(n => n.value.toLowerCase())); | ||
if (match) { | ||
args[index][range.start].value = match; | ||
args[index][range.start + 1].value = ''; | ||
args[index][range.end].value = ''; | ||
} | ||
}); | ||
const result = parsed.toString(); | ||
decl.value = result; | ||
cache[value] = result; | ||
}); | ||
}); | ||
relevant.forEach((range, index) => { | ||
if (range.start === null) { | ||
return; | ||
} | ||
const val = args[index].slice(range.start, range.end + 1); | ||
if (val.length !== 3) { | ||
return; | ||
} | ||
const match = getMatch(val.filter(evenValues).map(n => n.value.toLowerCase())); | ||
if (match) { | ||
args[index][range.start].value = match; | ||
args[index][range.start + 1].value = ''; | ||
args[index][range.end].value = ''; | ||
} | ||
}); | ||
decl.value = values.toString(); | ||
} | ||
exports.default = _postcss2.default.plugin('postcss-normalize-repeat-style', () => { | ||
return css => css.walkDecls(/background(-repeat)?|(-webkit-)?mask-repeat/i, transform); | ||
}; | ||
}); | ||
module.exports = exports['default']; |
{ | ||
"name": "postcss-normalize-repeat-style", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Convert two value syntax for repeat-style into one value.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
6503
86
0
5