postcss-font-variant
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,7 +1,11 @@ | ||
# 1.0.2 - 2015-01-27 | ||
- Fixed: Re–use existing font-feature-settings declarations to avoid creating multiples that override themselves ([#1](https://github.com/postcss/postcss-font-variant/pull/1)) | ||
# 1.0.1 - 2014-11-11 | ||
- fix wrong space char that breaks on some environnements | ||
- Fixed: wrong space char that breaks on some environnements | ||
# 1.0.0 - 2014-10-09 | ||
First release based on [rework-font-variant](https://github.com/ianstormtaylor/rework-font-variant) v1.0.1 | ||
✨ First release based on [rework-font-variant](https://github.com/ianstormtaylor/rework-font-variant) v1.0.1 |
63
index.js
@@ -57,2 +57,21 @@ /** | ||
// Find font-feature-settings declaration before given declaration, | ||
// create if does not exist | ||
function getFontFeatureSettingsPrevTo(decl) { | ||
var fontFeatureSettings = null; | ||
decl.parent.eachDecl(function(decl) { | ||
if (decl.prop === "font-feature-settings") { | ||
fontFeatureSettings = decl; | ||
} | ||
}) | ||
if (fontFeatureSettings === null) { | ||
fontFeatureSettings = decl.clone() | ||
fontFeatureSettings.prop = "font-feature-settings" | ||
fontFeatureSettings.value = "" | ||
decl.parent.insertBefore(decl, fontFeatureSettings) | ||
} | ||
return fontFeatureSettings | ||
} | ||
/** | ||
@@ -63,24 +82,32 @@ * Expose the font-variant plugin. | ||
return function(styles) { | ||
// read custom media queries | ||
styles.eachDecl(function(decl) { | ||
if (!fontVariantProperties[decl.prop]) { | ||
return null | ||
} | ||
styles.eachRule(function(rule) { | ||
var fontFeatureSettings = null | ||
// read custom media queries | ||
rule.eachDecl(function(decl) { | ||
if (!fontVariantProperties[decl.prop]) { | ||
return null | ||
} | ||
var newValue = decl.value | ||
if (decl.prop === "font-variant") { | ||
newValue = decl.value.split(/\s+/g).map(function(val) { | ||
return fontVariantProperties["font-variant"][val] | ||
}).join(", ") | ||
} | ||
else if (fontVariantProperties[decl.prop][decl.value]) { | ||
newValue = fontVariantProperties[decl.prop][decl.value] | ||
} | ||
var newValue = decl.value | ||
if (decl.prop === "font-variant") { | ||
newValue = decl.value.split(/\s+/g).map(function(val) { | ||
return fontVariantProperties["font-variant"][val] | ||
}).join(", ") | ||
} | ||
else if (fontVariantProperties[decl.prop][decl.value]) { | ||
newValue = fontVariantProperties[decl.prop][decl.value] | ||
} | ||
var newDecl = decl.clone() | ||
newDecl.prop = "font-feature-settings" | ||
newDecl.value = newValue | ||
decl.parent.insertBefore(decl, newDecl) | ||
if (fontFeatureSettings === null) { | ||
fontFeatureSettings = getFontFeatureSettingsPrevTo(decl); | ||
} | ||
if (fontFeatureSettings.value) { | ||
fontFeatureSettings.value += ", " + newValue; | ||
} | ||
else { | ||
fontFeatureSettings.value = newValue; | ||
} | ||
}) | ||
}) | ||
} | ||
} |
{ | ||
"name": "postcss-font-variant", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "PostCSS plugin to transform W3C font-variant properties to more compatible CSS (font-feature-settings)", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"jshint": "^2.5.6", | ||
"postcss": "^2.2.5", | ||
"postcss": "^3.0.0", | ||
"tape": "^3.0.0" | ||
@@ -31,0 +31,0 @@ }, |
6739
101