postcss-merge-rules
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,3 +1,8 @@ | ||
# 1.1.0 | ||
* Less eager moving of properties, to avoid cases where moving a longhand | ||
property would allow a shorthand property to override it. | ||
# 1.0.0 | ||
* Initial release. |
43
index.js
@@ -14,2 +14,8 @@ 'use strict'; | ||
function different (a, b) { | ||
return a.filter(function (c) { | ||
return !~b.indexOf(c); | ||
}); | ||
} | ||
function filterPrefixes (selector) { | ||
@@ -89,18 +95,29 @@ return intersect(prefixes, selector); | ||
if (shouldMerge) { | ||
var difference = different(ruleDecls, cacheDecls); | ||
difference = difference.map(function (d) { | ||
return d.split(':')[0].split('-')[0]; | ||
}); | ||
var recievingBlock = cache.cloneAfter({ | ||
selector: joinSelectors(cache, rule), | ||
nodes: [] | ||
nodes: [], | ||
before: '' | ||
}); | ||
cache.eachInside(function (decl) { | ||
if (~intersection.indexOf('' + decl)) { | ||
decl.moveTo(recievingBlock); | ||
} | ||
}); | ||
rule.eachInside(function (decl) { | ||
if (~intersection.indexOf('' + decl)) { | ||
decl.removeSelf(); | ||
} | ||
}); | ||
// Clean up the original declarations if we removed their rules | ||
[rule, cache].forEach(function (r) { | ||
var moveDecl = function (callback) { | ||
return function (decl) { | ||
var intersects = ~intersection.indexOf('' + decl); | ||
var baseProperty = decl.prop.split('-')[0]; | ||
var canMove = !~difference.indexOf(baseProperty); | ||
if (intersects && (canMove || baseProperty === 'text')) { | ||
callback.call(this, decl); | ||
} | ||
}; | ||
}; | ||
cache.eachInside(moveDecl(function (decl) { | ||
decl.moveTo(recievingBlock); | ||
})); | ||
rule.eachInside(moveDecl(function (decl) { | ||
decl.removeSelf(); | ||
})); | ||
// Clean up any rules that have no declarations left | ||
[rule, recievingBlock, cache].forEach(function (r) { | ||
if (!r.nodes.length) { | ||
@@ -107,0 +124,0 @@ r.removeSelf(); |
{ | ||
"name": "postcss-merge-rules", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Merge CSS rules with PostCSS.", | ||
@@ -5,0 +5,0 @@ "main": "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
8296
121