postcss-merge-longhand
Advanced tools
Comparing version 4.0.4 to 4.0.5
@@ -80,3 +80,3 @@ 'use strict'; | ||
const wsc = ['width', 'style', 'color']; | ||
const defaults = ['medium', 'none', 'currentColor']; | ||
const defaults = ['medium', 'none', 'currentcolor']; | ||
@@ -151,4 +151,4 @@ function borderProperty(...parts) { | ||
const origLength = (decl.value + nextDecl.prop + nextDecl.value).length; | ||
const newLength1 = decl.value.length + prop1.length + nextValues[position].length; | ||
const origLength = ((0, _minifyWsc2.default)(decl.value) + nextDecl.prop + nextDecl.value).length; | ||
const newLength1 = decl.value.length + prop1.length + (0, _minifyWsc2.default)(nextValues[position]).length; | ||
const newLength2 = borderValue2.length + prop2.length + propValue2.length; | ||
@@ -341,11 +341,16 @@ | ||
const reduced = getDistinctShorthands(mapped); | ||
const none = 'none none currentColor'; | ||
const none = 'medium none currentcolor'; | ||
if (reduced.length === 2 && reduced[0] === none || reduced[1] === none) { | ||
if (reduced.length > 1 && reduced.length < 4 && reduced.includes(none)) { | ||
const filtered = mapped.filter(p => p !== none); | ||
const mostCommon = reduced.sort((a, b) => mapped.filter(v => v === b).length - mapped.filter(v => v === a).length)[0]; | ||
const borderValue = reduced.length === 2 ? filtered[0] : mostCommon; | ||
rule.insertBefore(lastNode, Object.assign(lastNode.clone(), { | ||
prop: 'border', | ||
value: mapped[1] === none ? 'none' : mapped.filter(value => value !== none)[0] | ||
value: borderValue | ||
})); | ||
directions.forEach((dir, i) => { | ||
if (mapped[1] === none && mapped[i] !== none) { | ||
if (mapped[i] !== borderValue) { | ||
rule.insertBefore(lastNode, Object.assign(lastNode.clone(), { | ||
@@ -356,9 +361,4 @@ prop: dir, | ||
} | ||
if (mapped[1] !== none && mapped[i] === none) { | ||
rule.insertBefore(lastNode, Object.assign(lastNode.clone(), { | ||
prop: dir, | ||
value: 'none' | ||
})); | ||
} | ||
}); | ||
rules.forEach(_remove2.default); | ||
@@ -467,2 +467,36 @@ return true; | ||
rule.walkDecls(/^border($|-(top|right|bottom|left)$)/, decl => { | ||
let values = (0, _parseWsc2.default)(decl.value); | ||
if (!(0, _validateWsc.isValidWsc)(values)) { | ||
return; | ||
} | ||
const position = directions.indexOf(decl.prop); | ||
let dirs = [...directions]; | ||
dirs.splice(position, 1); | ||
wsc.forEach((d, i) => { | ||
const props = dirs.map(dir => `${dir}-${d}`); | ||
(0, _mergeRules2.default)(rule, [decl.prop, ...props], rules => { | ||
if (!rules.includes(decl)) { | ||
return; | ||
} | ||
const longhands = rules.filter(p => p !== decl); | ||
if (longhands[0].value === longhands[1].value && longhands[1].value === longhands[2].value && longhands[0].value === values[i]) { | ||
longhands.forEach(_remove2.default); | ||
(0, _insertCloned2.default)(decl.parent, decl, { | ||
prop: borderProperty(d), | ||
value: values[i] | ||
}); | ||
values[i] = null; | ||
} | ||
}); | ||
const newValue = values.join(' '); | ||
if (newValue) { | ||
decl.value = newValue; | ||
} else { | ||
decl.remove(); | ||
} | ||
}); | ||
}); | ||
// clean-up values | ||
@@ -469,0 +503,0 @@ rule.walkDecls(/^border($|-(top|right|bottom|left)$)/, decl => { |
@@ -33,5 +33,5 @@ 'use strict'; | ||
}).trim(); | ||
return (0, _minifyTrbl2.default)(value || defaults[0]); | ||
return (0, _minifyTrbl2.default)(value || 'none'); | ||
}; | ||
module.exports = exports['default']; |
@@ -12,7 +12,7 @@ 'use strict'; | ||
const none = /^\s*none(\s+none(\s+(none|currentcolor))?)?\s*$/i; | ||
const none = /^\s*(none|medium)(\s+none(\s+(none|currentcolor))?)?\s*$/i; | ||
function parseWsc(value) { | ||
if (none.test(value)) { | ||
return ['none', 'none', 'currentColor']; | ||
return ['medium', 'none', 'currentcolor']; | ||
} | ||
@@ -25,3 +25,3 @@ | ||
values.unshift(); | ||
width = 'none'; | ||
width = '0'; | ||
} | ||
@@ -33,7 +33,7 @@ | ||
if ((0, _validateWsc.isStyle)(v)) { | ||
style = v; | ||
style = v.toLowerCase(); | ||
} else if ((0, _validateWsc.isWidth)(v)) { | ||
width = v; | ||
width = v.toLowerCase(); | ||
} else if ((0, _validateWsc.isColor)(v)) { | ||
color = v; | ||
color = v.toLowerCase(); | ||
} else { | ||
@@ -40,0 +40,0 @@ unknown.push(v); |
{ | ||
"name": "postcss-merge-longhand", | ||
"version": "4.0.4", | ||
"version": "4.0.5", | ||
"description": "Merge longhand properties into shorthand with PostCSS.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
46900
1045
0