sprite.less
2.61 KB
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
/*
LESS variables are information about icon's compiled state, stored under its original file name
.icon-home {
width: @icon-home-width;
}
The large array-like variables contain all information about a single icon
@icon-home: x y offset_x offset_y width height total_width total_height image_path name;
At the bottom of this section, we provide information about the spritesheet itself
@spritesheet: width height image @spritesheet-sprites;
*/
@icon-back-to-name: icon-back-to;
@icon-back-to-x: 0px;
@icon-back-to-y: 0px;
@icon-back-to-offset-x: 0px;
@icon-back-to-offset-y: 0px;
@icon-back-to-width: 22px;
@icon-back-to-height: 38px;
@icon-back-to-total-width: 50px;
@icon-back-to-total-height: 38px;
@icon-back-to-image: '../images/dist/sprite.png';
@icon-back-to: 0px 0px 0px 0px 22px 38px 50px 38px '../images/dist/sprite.png' icon-back-to;
@icon-back-name: icon-back;
@icon-back-x: 28px;
@icon-back-y: 0px;
@icon-back-offset-x: -28px;
@icon-back-offset-y: 0px;
@icon-back-width: 22px;
@icon-back-height: 38px;
@icon-back-total-width: 50px;
@icon-back-total-height: 38px;
@icon-back-image: '../images/dist/sprite.png';
@icon-back: 28px 0px -28px 0px 22px 38px 50px 38px '../images/dist/sprite.png' icon-back;
@spritesheet-width: 50px;
@spritesheet-height: 38px;
@spritesheet-image: '../images/dist/sprite.png';
@spritesheet-sprites: @icon-back-to @icon-back;
@spritesheet: 50px 38px '../images/dist/sprite.png' @spritesheet-sprites;
/*
The provided classes are intended to be used with the array-like variables
.icon-home {
.sprite-width(@icon-home);
}
.icon-email {
.sprite(@icon-email);
}
*/
.sprite-width(@sprite) {
width: extract(@sprite, 5);
}
.sprite-height(@sprite) {
height: extract(@sprite, 6);
}
.sprite-position(@sprite) {
@sprite-offset-x: extract(@sprite, 3);
@sprite-offset-y: extract(@sprite, 4);
background-position: @sprite-offset-x @sprite-offset-y;
}
.sprite-image(@sprite) {
@sprite-image: extract(@sprite, 9);
@sprite-image-bare: ~`"@{sprite-image}".slice(1, -1)`;
background-image: url(@sprite-image-bare);
}
.sprite(@sprite) {
.sprite-image(@sprite);
.sprite-position(@sprite);
.sprite-width(@sprite);
.sprite-height(@sprite);
}
/*
The `.sprites` mixin generates identical output to the CSS template
but can be overridden inside of LESS
This must be run when you have at least 2 sprites.
If run with a single sprite, then there will be reference errors.
.sprites(@spritesheet-sprites);
*/
.sprites(@sprites, @i: 1) when (@i <= length(@sprites)) {
@sprite: extract(@sprites, @i);
@sprite-name: extract(@sprite, 10);
.@{sprite-name} {
.sprite(@sprite);
}
.sprites(@sprites, @i + 1);
}