3 final class CeleritySpriteGenerator
extends Phobject
{
5 public function buildTokenSheet() {
6 $icons = $this->getDirectoryList('tokens_1x');
11 $template = id(new PhutilSprite())
12 ->setSourceSize(18, 18);
16 foreach ($icons as $icon) {
17 $sprite = id(clone $template)
18 ->setName('tokens-'.$icon)
19 ->setTargetCSS('.tokens-'.$icon);
21 foreach ($scales as $scale_key => $scale) {
22 $path = $this->getPath($prefix.$scale_key.'/'.$icon.'.png');
23 $sprite->setSourceFile($path, $scale);
28 $sheet = $this->buildSheet('tokens', true);
29 $sheet->setScales($scales);
30 foreach ($sprites as $sprite) {
31 $sheet->addSprite($sprite);
37 public function buildLoginSheet() {
38 $icons = $this->getDirectoryList('login_1x');
43 $template = id(new PhutilSprite())
44 ->setSourceSize(28, 28);
48 foreach ($icons as $icon) {
49 $sprite = id(clone $template)
50 ->setName('login-'.$icon)
51 ->setTargetCSS('.login-'.$icon);
53 foreach ($scales as $scale_key => $scale) {
54 $path = $this->getPath($prefix.$scale_key.'/'.$icon.'.png');
55 $sprite->setSourceFile($path, $scale);
60 $sheet = $this->buildSheet('login', true);
61 $sheet->setScales($scales);
62 foreach ($sprites as $sprite) {
63 $sheet->addSprite($sprite);
69 private function getPath($to_path = null) {
70 $root = dirname(phutil_get_library_root('phabricator'));
71 return $root.'/resources/sprite/'.$to_path;
74 private function getDirectoryList($dir) {
75 $path = $this->getPath($dir);
79 $images = Filesystem
::listDirectory($path, $include_hidden = false);
80 foreach ($images as $image) {
81 if (!preg_match('/\.png$/', $image)) {
84 "Expected file '%s' in '%s' to be a sprite source ending in '%s'.",
89 $result[] = substr($image, 0, -4);
95 private function buildSheet(
101 $sheet = new PhutilSpriteSheet();
106 case PhutilSpriteSheet
::TYPE_STANDARD
:
108 $type = PhutilSpriteSheet
::TYPE_STANDARD
;
109 $repeat_rule = 'no-repeat';
111 case PhutilSpriteSheet
::TYPE_REPEAT_X
:
112 $repeat_rule = 'repeat-x';
114 case PhutilSpriteSheet
::TYPE_REPEAT_Y
:
115 $repeat_rule = 'repeat-y';
119 $retina_rules = null;
121 $retina_rules = <<<EOCSS
123 only screen and (min-device-pixel-ratio: 1.5),
124 only screen and (-webkit-min-device-pixel-ratio: 1.5),
125 only screen and (min-resolution: 1.5dppx) {
126 .sprite-{$name}{$extra_css} {
127 background-image: url(/rsrc/image/sprite-{$name}-X2.png);
128 background-size: {X}px {Y}px;
134 $sheet->setSheetType($type);
135 $sheet->setCSSHeader(<<<EOCSS
137 * @provides sprite-{$name}-css
141 .sprite-{$name}{$extra_css} {
142 background-image: url(/rsrc/image/sprite-{$name}.png);
143 background-repeat: {$repeat_rule};