Debian Codegraph @

vendor/wikimedia/less.php/lib/Less/Tree/Element.php

raw
1 <?php
2 /**
3 * @private
4 */
5 class Less_Tree_Element extends Less_Tree implements Less_Tree_HasValueProperty {
6
7 /** @var string */
8 public $combinator;
9 /** @var bool Whether combinator is null (represented by empty string) or child (single space) */
10 public $combinatorIsEmptyOrWhitespace;
11 /** @var string|Less_Tree */
12 public $value;
13 /** @var int|null */
14 public $index;
15 /** @var array|null */
16 public $currentFileInfo;
17
18 /**
19 * @param null|string $combinator
20 * @param string|Less_Tree $value
21 * @param int|null $index
22 * @param array|null $currentFileInfo
23 */
24 public function __construct( $combinator, $value, $index = null, $currentFileInfo = null ) {
25 $this->value = $value;
26
27 // see less-2.5.3.js#Combinator
28 $this->combinator = $combinator ?? '';
29 $this->combinatorIsEmptyOrWhitespace = ( $combinator === null || trim( $combinator ) === '' );
30
31 $this->index = $index;
32 $this->currentFileInfo = $currentFileInfo;
33 }
34
35 public function accept( $visitor ) {
36 if ( $this->value instanceof Less_Tree ) {
37 $this->value = $visitor->visitObj( $this->value );
38 }
39 }
40
41 public function compile( $env ) {
42 return new self(
43 $this->combinator,
44 ( $this->value instanceof Less_Tree ? $this->value->compile( $env ) : $this->value ),
45 $this->index,
46 $this->currentFileInfo
47 );
48 }
49
50 /**
51 * @see Less_Tree::genCSS
52 */
53 public function genCSS( $output ) {
54 $output->add( $this->toCSS(), $this->currentFileInfo, $this->index );
55 }
56
57 public function toCSS() {
58 if ( $this->value instanceof Less_Tree ) {
59 $value = $this->value->toCSS();
60 } else {
61 $value = $this->value;
62 }
63
64 $spaceOrEmpty = ' ';
65 if ( Less_Parser::$options['compress'] ||
66 ( isset( Less_Environment::$_noSpaceCombinators[$this->combinator] ) && Less_Environment::$_noSpaceCombinators[$this->combinator] )
67 ) {
68 $spaceOrEmpty = '';
69 }
70
71 return $spaceOrEmpty . $this->combinator . $spaceOrEmpty . $value;
72 }
73
74 }