[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Media 5 * 6 * @package Less 7 * @subpackage tree 8 */ 9 class Less_Tree_Media extends Less_Tree{ 10 11 public $features; 12 public $rules; 13 public $index; 14 public $currentFileInfo; 15 public $isReferenced; 16 public $type = 'Media'; 17 18 public function __construct($value = array(), $features = array(), $index = null, $currentFileInfo = null ){ 19 20 $this->index = $index; 21 $this->currentFileInfo = $currentFileInfo; 22 23 $selectors = $this->emptySelectors(); 24 25 $this->features = new Less_Tree_Value($features); 26 27 $this->rules = array(new Less_Tree_Ruleset($selectors, $value)); 28 $this->rules[0]->allowImports = true; 29 } 30 31 public function accept( $visitor ){ 32 $this->features = $visitor->visitObj($this->features); 33 $this->rules = $visitor->visitArray($this->rules); 34 } 35 36 /** 37 * @see Less_Tree::genCSS 38 */ 39 public function genCSS( $output ){ 40 41 $output->add( '@media ', $this->currentFileInfo, $this->index ); 42 $this->features->genCSS( $output ); 43 Less_Tree::outputRuleset( $output, $this->rules); 44 45 } 46 47 public function compile($env) { 48 49 $media = new Less_Tree_Media(array(), array(), $this->index, $this->currentFileInfo ); 50 51 $strictMathBypass = false; 52 if( Less_Parser::$options['strictMath'] === false) { 53 $strictMathBypass = true; 54 Less_Parser::$options['strictMath'] = true; 55 } 56 57 $media->features = $this->features->compile($env); 58 59 if( $strictMathBypass ){ 60 Less_Parser::$options['strictMath'] = false; 61 } 62 63 $env->mediaPath[] = $media; 64 $env->mediaBlocks[] = $media; 65 66 array_unshift($env->frames, $this->rules[0]); 67 $media->rules = array($this->rules[0]->compile($env)); 68 array_shift($env->frames); 69 70 array_pop($env->mediaPath); 71 72 return !$env->mediaPath ? $media->compileTop($env) : $media->compileNested($env); 73 } 74 75 public function variable($name) { 76 return $this->rules[0]->variable($name); 77 } 78 79 public function find($selector) { 80 return $this->rules[0]->find($selector, $this); 81 } 82 83 public function emptySelectors(){ 84 $el = new Less_Tree_Element('','&', $this->index, $this->currentFileInfo ); 85 $sels = array( new Less_Tree_Selector(array($el), array(), null, $this->index, $this->currentFileInfo) ); 86 $sels[0]->mediaEmpty = true; 87 return $sels; 88 } 89 90 public function markReferenced(){ 91 $this->rules[0]->markReferenced(); 92 $this->isReferenced = true; 93 Less_Tree::ReferencedArray($this->rules[0]->rules); 94 } 95 96 // evaltop 97 public function compileTop($env) { 98 $result = $this; 99 100 if (count($env->mediaBlocks) > 1) { 101 $selectors = $this->emptySelectors(); 102 $result = new Less_Tree_Ruleset($selectors, $env->mediaBlocks); 103 $result->multiMedia = true; 104 } 105 106 $env->mediaBlocks = array(); 107 $env->mediaPath = array(); 108 109 return $result; 110 } 111 112 public function compileNested($env) { 113 $path = array_merge($env->mediaPath, array($this)); 114 115 // Extract the media-query conditions separated with `,` (OR). 116 foreach ($path as $key => $p) { 117 $value = $p->features instanceof Less_Tree_Value ? $p->features->value : $p->features; 118 $path[$key] = is_array($value) ? $value : array($value); 119 } 120 121 // Trace all permutations to generate the resulting media-query. 122 // 123 // (a, b and c) with nested (d, e) -> 124 // a and d 125 // a and e 126 // b and c and d 127 // b and c and e 128 129 $permuted = $this->permute($path); 130 $expressions = array(); 131 foreach($permuted as $path){ 132 133 for( $i=0, $len=count($path); $i < $len; $i++){ 134 $path[$i] = Less_Parser::is_method($path[$i], 'toCSS') ? $path[$i] : new Less_Tree_Anonymous($path[$i]); 135 } 136 137 for( $i = count($path) - 1; $i > 0; $i-- ){ 138 array_splice($path, $i, 0, array(new Less_Tree_Anonymous('and'))); 139 } 140 141 $expressions[] = new Less_Tree_Expression($path); 142 } 143 $this->features = new Less_Tree_Value($expressions); 144 145 146 147 // Fake a tree-node that doesn't output anything. 148 return new Less_Tree_Ruleset(array(), array()); 149 } 150 151 public function permute($arr) { 152 if (!$arr) 153 return array(); 154 155 if (count($arr) == 1) 156 return $arr[0]; 157 158 $result = array(); 159 $rest = $this->permute(array_slice($arr, 1)); 160 foreach ($rest as $r) { 161 foreach ($arr[0] as $a) { 162 $result[] = array_merge( 163 is_array($a) ? $a : array($a), 164 is_array($r) ? $r : array($r) 165 ); 166 } 167 } 168 169 return $result; 170 } 171 172 public function bubbleSelectors($selectors) { 173 174 if( !$selectors) return; 175 176 $this->rules = array(new Less_Tree_Ruleset( $selectors, array($this->rules[0]))); 177 } 178 179 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |