public override Node Evaluate(Env env) { if(Rules != null) Rules = new List<Node>(Rules.Select(r => r.Evaluate(env))); else Value = Value.Evaluate(env); return this; }
protected override Node Eval(Number number, Node[] args) { if (number.Unit == "%") return number; if (string.IsNullOrEmpty(number.Unit)) return new Number(number.Value * 100, "%"); throw new ParsingException(string.Format("Expected unitless number in function 'percentage', found {0}", number.ToCSS(null))); }
// In an operation between two Dimensions, // we default to the first Number's unit, // so `1px + 2em` will yield `3px`. // In the future, we could implement some unit // conversions such that `100cm + 10mm` would yield // `101cm`. public Node Operate(string op, Node other) { var dim = (Number) other; var unit = Unit; var otherUnit = dim.Unit; if (unit == otherUnit && op == "/") unit = ""; else if (string.IsNullOrEmpty(unit)) unit = otherUnit; else if(!string.IsNullOrEmpty(otherUnit)) { // convert units } return new Number(Operation.Operate(op, Value, dim.Value), unit); }
public override Node Evaluate(Env env) { if (Evaluated != null) return Evaluated; var args = Arguments.Select(a => a.Evaluate(env)); if (env != null) { var function = env.GetFunction(Name); if (function != null) { function.Name = Name; Evaluated = function.Call(args); return Evaluated; } } Evaluated = new TextNode(Name + "(" + Arguments.Select(a => a.Evaluate(env).ToCSS()).JoinStrings(", ") + ")"); return Evaluated; }
public Alpha(Node value) { Value = value; }
public override Node Evaluate(Env env) { Value = Value.Evaluate(env); return this; }
public Shorthand(Node first, Node second) { First = first; Second = second; }
public Operation(string op, Node first, Node second) { First = first; Second = second; Operator = op.Trim(); }
public Alpha Alpha(Node value) { return new Alpha(value); }
public Directive(string name, Node value) { Name = name; Value = value; }
public Url Url(Node value) { return new Url(value); }
protected abstract Node Eval(Number number, Node[] args);
public Node Operate(string op, Node other) { var otherColor = other as Color; if (otherColor == null) otherColor = ((IOperable)other).ToColor(); var result = new double[3]; for (var c = 0; c < 3; c++) { result[c] = Operation.Operate(op, RGB[c], otherColor.RGB[c]); } return new Color(result); }
public Rule(string name, Node value) { Name = name; Value = value; Variable = name != null ? name[0] == '@' : false; }
public Rule Rule(string name, Node value) { return new Rule(name, value); }
public Operation Operation(string operation, Node left, Node right) { return new Operation(operation, left, right); }
public Directive Directive(string name, Node value) { return new Directive(name, value); }
public Value Value(IEnumerable<Node> values, Node important) { return new Value(values, important); }
public Url(Node value) { Value = value; }
public Value(IEnumerable<Node> values, Node important) { Values = new NodeList(values); Important = important; }
public Shorthand Shorthand(Node first, Node second) { return new Shorthand(first, second); }
protected override Node Eval(Number number, Node[] args) { return new Number(Math.Floor(number.Value), number.Unit); }
public Value Value(NodeList values, Node important) { return new Value(values, important); }