rs-style-factory
v0.1.0-beta.0
Published
将 style 文本内容转化为 function 函数,可附加 prefix、换算 rpx、:host 选择符的操作
Readme
rs-style-factory
将 style 文本内容转化为 function 函数,可附加 prefix、换算 rpx、:host 选择符的操作。
作为小程序样式转换使用
Usage
import { styleFactory } from 'rs-style-factory';
const code = styleFactory(css);Input
/* 注释 */
.foo {
color: red;
height: 100rpx;
}Output
function styleFactory(options) {
const prefix = options.prefix || '';
const rpx = options.rpx;
const host = options.host || 'host-placeholder';
return '/* 注释 */\n.' + prefix + 'foo{\n color: red;\n height: ' + rpx(100) + 'px' + ';\n}';
}调用该方法
styleFactory({
prefix: 'foo--',
rpx: function (size) {
return size * 0.5;
},
});输出以下内容
/* 注释 */
.foo--foo {
color: red;
height: 50px;
}