From 73fb624a1750f77f244599bd0c705fad2ff78a75 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Sat, 25 Nov 2017 04:05:01 +0900 Subject: [PATCH] Add support for @supports see: https://github.com/buildingblocks/grunt-combine-media-queries/issues/27 --- tasks/combine-media-queries.js | 19 +++++++++- test/test8.css | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 test/test8.css diff --git a/tasks/combine-media-queries.js b/tasks/combine-media-queries.js index 09c892a..e7dfc04 100644 --- a/tasks/combine-media-queries.js +++ b/tasks/combine-media-queries.js @@ -83,6 +83,8 @@ module.exports = function(grunt) { strCss += processMedia(rule); } else if (rule.type === 'keyframes') { strCss += processKeyframes(rule); + } else if (rule.type === 'supports') { + strCss += processSupports(rule); } return strCss; }; @@ -134,6 +136,21 @@ module.exports = function(grunt) { return strCss; }; + // Process supports + var processSupports = function (supports) { + var strCss = ''; + + strCss += '@supports ' + supports.supports + ' {\n\n'; + supports.rules.forEach(function (rule) { + strCss += commentOrRule(rule); + }); + strCss += '}\n\n'; + + log('@supports ' + supports.supports); + + return strCss; + }; + // Process document var processDocument = function(doc) { var strCss = ''; @@ -238,7 +255,7 @@ module.exports = function(grunt) { } else if (rule.type === 'charset') { processedCSS.charset.push(rule); - } else if (rule.type === 'rule' || 'comment') { + } else if (rule.type === 'rule' || 'comment' || 'supports') { processedCSS.base.push(rule); } diff --git a/test/test8.css b/test/test8.css new file mode 100644 index 0000000..a0e8b4b --- /dev/null +++ b/test/test8.css @@ -0,0 +1,65 @@ +@charset "UTF-8"; + +body { + font-family: "Georgia Pro", Georgia, Times, serif; + font-weight: 400; + color: #000; +} + +body:before, body:after { + display: table; + content: ""; +} + +body:after { + clear: both; +} + +@-moz-document url-prefix(http://www.example.com) { + + p { + height: 5px; + } + + @media (min-width: 500px) { + + p { + height: 5px; + } + + @supports (display: flex) { + + p { + height: 10px; + } + + } + + } + +} + +@supports ( not ((text-align-last:justify) or (-moz-text-align-last:justify) ) { + + p { + color: #ABCDEF; + } + +} + +@media (min-width: 900px) { + + p { + height: 15px; + } + + @supports not (display: flex) { + + p { + height: 20px; + } + + } + +} +