-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtriangle.js
128 lines (114 loc) · 2.86 KB
/
triangle.js
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
/**
* Triangle
*/
module.exports = function (decl, args) {
var color = '#000';
var size = '20px';
if (args[1]) {
size = args[1];
}
if (args[2]) {
color = args[2];
}
var border;
if (args[3]) {
switch (args[3]) {
case 'down':
border = [true, 't', false, 't'];
break;
case 'up':
border = [false, 't', true, 't'];
break;
case 'left':
border = ['t', true, 't', false];
break;
case 'right':
border = ['t', false, 't', true];
break;
case 'up-right':
border = [true, false, false, 't'];
break;
case 'up-left':
border = [true, 't', false, false];
break;
case 'down-right':
border = [false, false, true, 't'];
break;
case 'down-left':
border = [false, 't', true, false];
break;
default:
throw decl.error('Circle orientation is not valid.');
}
} else {
border = [true, 't', false, 't']; // down as default
}
var aux = decl;
aux.append({
prop: 'height',
value: 0,
source: decl.source
}, {
prop: 'width',
value: 0,
source: decl.source
});
if (border[0] === true) { // top
aux.append({
prop: 'border-top',
value: size + ' solid ' + color,
source: decl.source
});
}
if (border[1] === true) { // right
aux.append({
prop: 'border-right',
value: size + ' solid ' + color,
source: decl.source
});
}
if (border[2] === true) { // bottom
aux.append({
prop: 'border-bottom',
value: size + ' solid ' + color,
source: decl.source
});
}
if (border[3] === true) { // left
aux.append({
prop: 'border-left',
value: size + ' solid ' + color,
source: decl.source
});
}
// transparent
if (border[0] === 't') { // top
aux.append({
prop: 'border-top',
value: size + ' solid transparent',
source: decl.source
});
}
if (border[1] === 't') { // right
aux.append({
prop: 'border-right',
value: size + ' solid transparent',
source: decl.source
});
}
if (border[2] === 't') { // bottom
aux.append({
prop: 'border-bottom',
value: size + ' solid transparent',
source: decl.source
});
}
if (border[3] === 't') { // left
aux.append({
prop: 'border-left',
value: size + ' solid transparent',
source: decl.source
});
}
decl.replaceWith(aux.nodes);
};