UNPKG

962 BJavaScriptView Raw
1var postcss = require('postcss');
2var autoprefixer = require('autoprefixer');
3
4/**
5 * 自动添加 CSS 前缀
6 *
7 * @param {string} content 文本内容
8 * @param {Object} attrs 属性
9 * @param {string} attrs.browsers 兼容的浏览器环境
10 * @param {Object} scope 作用域
11 * @param {Function} scope.execImport 导入数据
12 * @return {string} 返回处理后的内容
13 * @example
14 * <~jdists encoding="autoprefixer" browsers="iOS >= 7,Firefox >= 20" ~>
15 * @color blue;
16 * .rotate {
17 * animation: rotate 3s ease-in infinite;
18 * }
19 * @keyframes rotate {
20 * from {
21 * transform: rotate(0deg);
22 * }
23 * to {
24 * transform: rotate(360deg);
25 * }
26 * }
27 * <~/jdists~>
28 */
29module.exports = function processor(content, attrs, scope) {
30 var browsers;
31 if (attrs.browsers) {
32 browsers = scope.execImport(
33 attrs.browsers
34 ).split(/\s*,\s*/);
35 }
36 return postcss(autoprefixer({
37 browsers: browsers
38 })).process(content).toString();
39};
\No newline at end of file