-
Notifications
You must be signed in to change notification settings - Fork 11
/
functions.go
149 lines (122 loc) · 2.29 KB
/
functions.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package css
import (
"fmt"
color_go "image/color"
"time"
"qlova.org/seed/use/css/units"
)
type Duration time.Duration
func (Duration) durationValue() {}
func (d Duration) Rule() Rule {
return Rule(fmt.Sprintf("%fs", time.Duration(d).Seconds()))
}
type AnimationName string
func (AnimationName) animationNameValue() {}
func (a AnimationName) Rule() Rule {
return Rule(a)
}
type Number float64
func (Number) numberValue() {}
func (n Number) Rule() Rule {
return Rule(fmt.Sprintf("%f", n))
}
type Int int
func (Int) integerOrAutoValue() {}
func (Int) animationIterationCountValue() {}
func (i Int) Rule() Rule {
return Rule(fmt.Sprintf("%v", i))
}
//Colour is the CSS color type.
type RGB struct {
color_go.Color
}
func (RGB) colorValue() {}
func (c RGB) Rule() Rule {
var col = color_go.NRGBAModel.Convert(c).(color_go.NRGBA)
var r, g, b, a = col.R, col.G, col.B, col.A
if a != 255 {
return Rule(fmt.Sprint("rgba(", r, ",", g, ",", b, ",", float64(a)/255, ")"))
} else {
return Rule(fmt.Sprint("rgb(", r, ",", g, ",", b, ")"))
}
}
type Unit struct {
string
}
func Measure(u units.Unit) Unit {
if u == nil {
return Unit{"0"}
}
q, r := u.Measure()
if q == 0 {
return Unit{"0"}
}
switch r {
case "px":
return Px(q)
case "em":
return Em(q)
case "rem":
return Rem(q)
case "vmin":
return Vmin(q)
case "vh":
return Vh(q)
case "vw":
return Vw(q)
case "%":
return Percent(q)
default:
return Unit{"0"}
}
}
func (u Unit) String() string {
return u.string
}
func (Unit) unitValue() {}
func (Unit) unitOrAutoValue() {}
func (Unit) unitOrNoneValue() {}
func (Unit) fontSizeValue() {}
func (Unit) borderRadiusValue() {}
func (Unit) thicknessValue() {}
func (u Unit) Rule() Rule {
if u.string == "" {
return "0"
}
return Rule(u.string)
}
func Em(v float64) Unit {
return Unit{
fmt.Sprintf(`%fem`, v),
}
}
func Px(v float64) Unit {
return Unit{
fmt.Sprintf(`%fpx`, v),
}
}
func Rem(v float64) Unit {
return Unit{
fmt.Sprintf(`%frem`, v),
}
}
func Vmin(v float64) Unit {
return Unit{
fmt.Sprintf(`%fvmin`, v),
}
}
func Vh(v float64) Unit {
return Unit{
fmt.Sprintf(`%fvh`, v),
}
}
func Vw(v float64) Unit {
return Unit{
fmt.Sprintf(`%fvw`, v),
}
}
func Percent(v float64) Unit {
return Unit{
fmt.Sprintf(`%f%%`, v),
}
}