/*
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;
*/
@author-name: 'author';
@author-x: 0px;
@author-y: 0px;
@author-offset-x: 0px;
@author-offset-y: 0px;
@author-width: 128px;
@author-height: 128px;
@author-total-width: 258px;
@author-total-height: 258px;
@author-image: '~icons.png';
@author: 0px 0px 0px 0px 128px 128px 258px 258px '~icons.png' 'author';
@docs-name: 'docs';
@docs-x: 130px;
@docs-y: 0px;
@docs-offset-x: -130px;
@docs-offset-y: 0px;
@docs-width: 128px;
@docs-height: 128px;
@docs-total-width: 258px;
@docs-total-height: 258px;
@docs-image: '~icons.png';
@docs: 130px 0px -130px 0px 128px 128px 258px 258px '~icons.png' 'docs';
@github-name: 'github';
@github-x: 0px;
@github-y: 130px;
@github-offset-x: 0px;
@github-offset-y: -130px;
@github-width: 128px;
@github-height: 128px;
@github-total-width: 258px;
@github-total-height: 258px;
@github-image: '~icons.png';
@github: 0px 130px 0px -130px 128px 128px 258px 258px '~icons.png' 'github';
@spritesheet-width: 258px;
@spritesheet-height: 258px;
@spritesheet-image: '~icons.png';
@spritesheet-sprites: @author @docs @github;
@spritesheet: 258px 258px '~icons.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);
}

Example usage in HTML:

`display: block` sprite:
<div class="icon-home"></div>

To change `display` (e.g. `display: inline-block;`), we suggest using a common CSS class:

// CSS
.icon {
  display: inline-block;
}

// HTML
<i class="icon icon-home"></i>
*/
.sprite-width(@sprite) {
  width: extract(@sprite, 5) / 2;
}

.sprite-height(@sprite) {
  height: extract(@sprite, 6) / 2;
}

//  nth是指#block "sprites"第几个参数，可以输出$sprite来查看,
.sprite-position(@sprite) {
  @sprite-offset-x: extract(@sprite, 3);
  @sprite-offset-y: extract(@sprite, 4);
  background-position: @sprite-offset-x / 2 @sprite-offset-y / 2;
  background-size: extract(@sprite, 7) / 2 auto;
}

.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: e(extract(@sprite, 10));
  .@{sprite-name} {
    .sprite(@sprite);
  }
  .sprites(@sprites, @i + 1);
}
