postcss-custom-media
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -0,1 +1,6 @@ | ||
# 4.1.0 - 2015-06-30 | ||
- Added: Allow custom media to reference each other | ||
([#10](https://github.com/postcss/postcss-custom-media/pull/10)) | ||
# 4.0.0 - 2015-05-17 | ||
@@ -2,0 +7,0 @@ |
61
index.js
@@ -6,2 +6,29 @@ var postcss = require("postcss") | ||
/* | ||
* Resolve custom media values. | ||
*/ | ||
function resolveValue(value, map, result) { | ||
if (!EXTENSION_RE.test(value)) { | ||
return value | ||
} | ||
return value.replace(EXTENSION_RE, function(orig, name) { | ||
if (!map[name]) { | ||
return orig | ||
} | ||
var mq = map[name] | ||
if (mq.resolved) { | ||
return mq.value | ||
} | ||
if (mq.deps.indexOf(name) !== -1) { | ||
mq.circular = true | ||
return orig | ||
} | ||
mq.deps.push(name) | ||
mq.value = resolveValue(mq.value, map, result) | ||
return mq.value | ||
}) | ||
} | ||
/* | ||
* read & replace custom media queries by standard media queries | ||
@@ -36,3 +63,8 @@ */ | ||
// map[<extension-name>] = <media-query-list> | ||
map[params.shift()] = params.join(" ") | ||
map[params.shift()] = { | ||
value: params.join(" "), | ||
deps: [], | ||
circular: false, | ||
resolved: false, | ||
} | ||
@@ -46,5 +78,15 @@ if (!preserve) { | ||
Object.keys(extensions).forEach(function(name) { | ||
map[name] = extensions[name] | ||
map[name] = { | ||
value: extensions[name], | ||
deps: [], | ||
circular: false, | ||
resolved: false, | ||
} | ||
}) | ||
Object.keys(map).forEach(function(name) { | ||
map[name].value = resolveValue(map[name].value, map, result) | ||
map[name].resolved = true | ||
}) | ||
// transform custom media query aliases | ||
@@ -58,3 +100,11 @@ styles.eachAtRule(function(rule) { | ||
if (map[name]) { | ||
return map[name] | ||
if (map[name].circular) { | ||
result.warn( | ||
"Circular @custom-media definition for '" + name + | ||
"'. The entire rule has been removed from the output.", | ||
{node: rule} | ||
) | ||
toRemove.push(rule) | ||
} | ||
return map[name].value | ||
} | ||
@@ -75,6 +125,9 @@ | ||
names.forEach(function(name) { | ||
if (map[name].circular) { | ||
return | ||
} | ||
var atRule = postcss.atRule({ | ||
name: "custom-media", | ||
afterName: " ", | ||
params: name + " " + map[name], | ||
params: name + " " + map[name].value, | ||
}) | ||
@@ -81,0 +134,0 @@ styles.append(atRule) |
{ | ||
"name": "postcss-custom-media", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": " PostCSS plugin to transform W3C CSS Custom Media Queries to more compatible CSS", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
8182
127