diff --git a/package.json b/package.json index aa19962..e8f51ea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,13 @@ { + "keywords": [ + "postcss-plugin" + ], "scripts": { "test": "make test" }, + "dependencies": { + "postcss": "^5.0.2" + }, "devDependencies": { "browserstack-runner": "^0.3.7", "connect": "^3.4.0", diff --git a/postcss-plugin.js b/postcss-plugin.js new file mode 100644 index 0000000..a8c5ec2 --- /dev/null +++ b/postcss-plugin.js @@ -0,0 +1,19 @@ +/*eslint-env node */ +var postcss = require('postcss'); + +module.exports = postcss.plugin('cq-prolyfill', function () { + 'use strict'; + return function (css) { + css.walkRules(/:container\(/i, function (rule) { + rule.selectors = rule.selectors.map(function(selector) { + return selector.replace(/:container\([^)]*\)/gi, function(match) { + return '.' + match + .replace(/([a-z])\s+([a-z])/gi, '$1|$2') + .replace(/\s+/g, '') + .replace(/[[\]!"#$%&'()*+,./:;<=>?@^`{|}~]/g, '\\$&') + .toLowerCase(); + }); + }); + }); + }; +});