-
Notifications
You must be signed in to change notification settings - Fork 1
/
mixins.styl
367 lines (317 loc) · 8.19 KB
/
mixins.styl
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// handy tuple for checking whether a value is auto or null
auto-null-check = (auto null);
/* collapse the top margin of the first child and the bottom margin of the second */
collapseinnermargins() {
> :first-child {
margin-top: 0;
}
> :last-child {
margin-bottom: 0;
}
}
.collapse-inner-margins {
collapseinnermargins();
}
/* inline-block fix for older browsers, in function and declaration form */
inlineblock() {
zoom: 1;
display: inline;
display: -moz-inline-stack;
display: inline-block;
}
.inlineblock {
inlineblock();
}
/* universal clearfix, in function and declaration form */
clearfix() {
& {
zoom:1;
}
&:before, &:after {
content:"";
display:table;
}
&:after {
clear:both;
}
}
cf = clearfix;
.cf, .clearfix {
clearfix();
}
/* clearfix lite, for modern browsers */
clearfixlite() {
overflow: hidden;
}
cflite = clearfixlite;
.cflite, .clearfixlite {
clearfixlite();
}
/* shade the border as if there's a light shining on it */
shadeborder(basecolor, amount, direction = convex) {
if (direction == concave) {
border-color: darken(basecolor, amount) basecolor lighten(basecolor, amount);
} else {
border-color: lighten(basecolor, amount) basecolor darken(basecolor, amount);
}
}
/* create a pushbutton effect */
pushbutton(distanceY = .0625em, distanceX = 0) {
position: relative;
top: distanceY;
left: distanceX;
}
.pushbutton {
pushbutton();
}
/* replace the text in an element with an image */
imagereplace(image, width, height, positionX = false, positionY = false) {
inlineblock();
box-sizing: border-box;
width: width;
height: height;
padding: 0;
if (positionX == false) {
positionX = left;
}
if (positionY == false) {
positionY = top;
}
background: image no-repeat positionX positionY;
text-indent: 100%;
line-height: 0;
overflow: hidden;
}
/* IE7-friendly border-box sizing -- doesn't do checking of units or anything,
* so make sure all your amounts are either the same unit or auto or 0 */
border-box(box-size, box-padding = none, box-border = none) {
box-sizing: border-box;
border-box-width = box-size[0];
width: border-box-width;
if (box-size[1] is not null && box-size[1] != auto) {
border-box-height = box-size[1];
height: border-box-height;
}
if ((length(box-padding) == 1 && box-padding != 0 && box-padding != none) || (length(box-padding) > 1)) {
padding: box-padding;
box-padding = expand-sides(box-padding, 4);
needs-ie7 = true;
} else {
box-padding = expand-sides(0, 4);
}
if ((length(box-border) == 1 && box-border != 0 && box-border != none) || (length(box-border) > 1)) {
border: box-border;
box-border = expand-sides(box-border, 4);
needs-ie7 = true;
} else {
box-border = expand-sides(0, 4);
}
if (needs-ie7 is defined) {
.ie-lte7 & {
// adjust width for IE7
ie7-box-width = border-box-width - box-padding[1] - box-padding[3] - box-border[1] - box-border[3];
if (border-box-width != ie7-box-width) {
width: ie7-box-width;
}
// adjust height for IE7, if an explicit height is set
if (border-box-height is defined) {
ie7-box-height = border-box-height - box-padding[0] - box-padding[2] - box-border[0] - box-border[2];
if (border-box-height != ie7-box-height) {
height: ie7-box-height;
}
}
}
}
}
/* Alignment */
.alignleft {
float: left;
margin-right: baselinesize;
}
.alignright {
float: right;
margin-left: baselinesize;
}
.aligncenter {
clear: both;
display: block;
margin: 0 auto;
}
/* Text meant only for screen readers and crappy feature phones */
assistive-text() {
position: absolute;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
}
accessible-hidden(createVisible = true, originalPosition = static) {
assistive-text();
if (createVisible) {
&.visible {
accessible-hidden-visible(originalPosition);
}
}
}
/* text that's hidden temporarily from the UI but available to screen readers */
.accessible-hidden {
accessible-hidden();
}
accessible-hidden-visible(originalPosition = static) {
clip: inherit;
position: originalPosition;
}
/** Lists **/
/* list without formatting */
.list-nostyle {
list-style: none;
padding-left: 0;
margin-left: 0;
}
.list-float {
@extend .list-nostyle;
& > li {
float: left;
}
}
/* inline-block list */
list-inlineblock(fixspace = false) {
@extend .list-nostyle;
> li {
inlineblock();
vertical-align: top;
if (fixspace) {
margin-right: -.25em;
&:last-child {
margin-right: 0;
}
}
}
}
.list-inlineblock {
list-inlineblock(true);
}
/* inline list with comma separation */
.list-inline {
@extend .list-nostyle;
& > li {
display: inline;
&:after {
content: ', ';
}
&:last-child {
&:after {
content: none;
}
}
}
}
/* list with extra-beefy margins */
.list-extra-margins li {
margin-bottom: baselinesize;
}
/* island */
.island {
background-color: aside-color;
collapseinnermargins();
margin: baselinesize baseindentsize;
padding: baselinesize baselindentsize;
}
triangle(direction = right, color = black, base = 1em, rise = auto, position = auto, whitespace-color = transparent, pseudo = auto) {
position: relative;
pseudo = triangle-get-pseudo(direction, pseudo);
&:{pseudo} {
direction-opposite = opposite-position(direction);
display: block;
position: absolute;
box-sizing: content-box;
content: " ";
line-height: 0;
width: 0;
height: 0;
border-style: solid;
triangle-size-block: direction base rise;
triangle-color-block: direction color whitespace-color;
triangle-position-block: direction position;
}
}
triangle-color-block(direction, color, whitespace-color = auto) {
direction-opposite = opposite-position(direction);
if (whitespace-color != auto) {
border-color: whitespace-color;
}
border-{direction-opposite}-color: color;
}
triangle-color(direction, color, whitespace-color = auto, pseudo = auto) {
pseudo = triangle-get-pseudo(direction, pseudo);
&:{pseudo} {
triangle-color-block(direction, color, whitespace-color);
}
}
triangle-get-widths(direction, base = 1em, rise = auto) {
border-width = base / 2;
if (rise == auto) {
rise = border-width;
}
triangle-width = rise;
if (direction == left) {
(border-width) (triangle-width) (border-width) (0);
} else if (direction == right) {
(border-width) (0) (border-width) (triangle-width);
} else if (direction == top) {
(0) (border-width) (triangle-width) (border-width);
} else if (direction == bottom) {
(triangle-width) (border-width) (0) (border-width);
} else {
error("triangle-get-widths: direction is invalid");
}
}
triangle-size-block(direction, base = 1em, rise = auto) {
widths = triangle-get-widths(direction, base, rise);
border-width: widths;
}
triangle-size(direction, base = 1em, rise = auto, pseudo = auto) {
pseudo = triangle-get-pseudo(direction, pseudo);
&:{pseudo} {
triangle-size-block(direction, base, rise);
}
}
triangle-get-position(direction, position) {
position-all = (auto auto auto auto);
perpendicular = perpendicular-position(direction);
direction-opposite = opposite-position(direction);
if (position != auto) {
position-all[0] = position[0] unless position[0] == auto;
position-all[1] = position[1] unless position[1] == auto;
position-all[2] = position[2] unless position[2] == auto;
position-all[3] = position[3] unless position[3] == auto;
}
if (position-all[position-order(perpendicular)] == auto) {
position-all[position-order(perpendicular)] = 0;
}
if (position-all[position-order(direction-opposite)] == auto) {
position-all[position-order(direction-opposite)] = 100%;
}
position-all;
}
triangle-position-block(direction, position) {
position-all = triangle-get-position(direction, position);
top: position-all[0] unless position-all[0] in auto-null-check;
right: position-all[1] unless position-all[1] in auto-null-check;
bottom: position-all[2] unless position-all[2] in auto-null-check;
left: position-all[3] unless position-all[3] in auto-null-check;
}
triangle-position(direction, position, pseudo = auto) {
pseudo = triangle-get-pseudo(direction, pseudo);
&:{pseudo} {
triangle-position-block(direction, position);
}
}
triangle-get-pseudo(direction, pseudo) {
if (pseudo == auto) {
if (direction in (top left)) {
pseudo = before;
} else if (direction in (bottom right)) {
pseudo = after;
}
}
pseudo;
}