-
Notifications
You must be signed in to change notification settings - Fork 200
/
ColorSpinPlugin.cs
45 lines (37 loc) · 1.2 KB
/
ColorSpinPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace dotless.Core.Plugins
{
using System;
using Parser.Infrastructure.Nodes;
using Parser.Tree;
using Utils;
using System.ComponentModel;
[Description("Automatically spins all colors in a less file"), DisplayName("ColorSpin")]
public class ColorSpinPlugin : VisitorPlugin
{
public double Spin { get; set; }
public ColorSpinPlugin(double spin)
{
Spin = spin;
}
public override VisitorPluginType AppliesTo
{
get { return VisitorPluginType.AfterEvaluation; }
}
public override Node Execute(Node node, out bool visitDeeper)
{
visitDeeper = true;
if(node is Color)
{
var color = node as Color;
var hslColor = HslColor.FromRgbColor(color);
hslColor.Hue += Spin/360.0d;
var newColor = hslColor.ToRgbColor();
//node = new Color(newColor.R, newColor.G, newColor.B);
color.R = newColor.R;
color.G = newColor.G;
color.B = newColor.B;
}
return node;
}
}
}