如何.define()用手写笔的颜色

时间:2015-04-16 17:48:30

标签: node.js stylus

我尝试使用手写笔API定义颜色.define(name,value):

var stylus = require('stylus');
stylus('.foo { color: darken(mycolor, 50%) }')
.define('mycolor', '#123')
.render(function(err, css) {
    console.log(err);
    console.log(css);
});

错误:

TypeError: expected rgba or hsla, but got string:'#123'

documentation中,我看不到任何对颜色类型的引用。

1 个答案:

答案 0 :(得分:4)

.define('mycolor', '#123')总是定义一个字符串,你可能已经发现了。即使你说.define('mycolor', 'rgba(0,0,0,0)'),你也会得到同样的错误。

您需要做的是定义rgbahsla节点,您可以这样做:

stylus('.foo { color: darken(mycolor, 50%) }')
.define('mycolor', new stylus.nodes.RGBA(1, 0x11, 0x22, 0x33))

可悲的是,我一直无法找到一种直接从颜色字符串定义颜色节点的简单方法。

new stylus.Parser('#123').lexer.color().valnew stylus.Parser('#123').peek().val适用于十六进制字符串。