手写笔空文本变量

Stylus empty text variable

如何创建手写笔 EMPTY 文本变量?

$cross(prop)
  prop = shift(arguments)
  -webkit-{prop} arguments
  -moz-{prop} arguments
  -ms-{prop} arguments
  -o-{prop} arguments
  {prop} arguments

$transition()
  attrs = shift(arguments)
  if length(arguments)
    str = ????WTF???
    for arg in arguments
      if length(str)
        str += \,
      str += arg attrs
    $cross (transition) (str)

我想创建过渡混合:

$transition((.4s ease out), opacity, visibility)

不幸的是,length bif 只能用于 lists/hashes。对于其他节点,它总是 returns 1。你可以这样写:

$transition()
  attrs = shift(arguments)
  if length(arguments)
    str = ''
    for arg in arguments
      if str != ''
        str += ', '
      str += arg, attrs
    $cross (transition) unquote(str) // unquote to remove quotes

或者您可以编写自定义函数来获取字符串长度:

str-length.js

module.exports = function() {
  return function(stylus) {
    stylus.define('str-length', function(str) {
      return str.val.length;
    });
  };
};

test.styl

use('str-length.js')

$cross(prop)
  prop = shift(arguments)
  -webkit-{prop} arguments
  -moz-{prop} arguments
  -ms-{prop} arguments
  -o-{prop} arguments
  {prop} arguments

$transition()
  attrs = shift(arguments)
  if length(arguments)
    str = ''
    for arg in arguments
      if str-length(str)
        str += ', '
      str += arg attrs
    $cross (transition) unquote(str) // unquote to remove quotes

body
  $transition((.4s ease out), opacity, visibility)