| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Options; |
| 3 |
|
| 4 |
use Depicter\Document\CSS\Breakpoints; |
| 5 |
|
| 6 |
class General |
| 7 |
{ |
| 8 |
/** |
| 9 |
* @var string |
| 10 |
*/ |
| 11 |
public $fullscreenMargin; |
| 12 |
|
| 13 |
/** |
| 14 |
* @var bool |
| 15 |
*/ |
| 16 |
public $keepAspect; |
| 17 |
|
| 18 |
/** |
| 19 |
* @var Unit |
| 20 |
*/ |
| 21 |
public $minHeight; |
| 22 |
|
| 23 |
/** |
| 24 |
* @var Unit |
| 25 |
*/ |
| 26 |
public $maxHeight; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var States |
| 30 |
*/ |
| 31 |
public $visible; |
| 32 |
|
| 33 |
/** |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
public $backgroundColor = ''; |
| 37 |
|
| 38 |
/** |
| 39 |
* @var All |
| 40 |
*/ |
| 41 |
protected $allOptions; |
| 42 |
|
| 43 |
|
| 44 |
public function setAllOptions( $allOptions ){ |
| 45 |
$this->allOptions = $allOptions; |
| 46 |
} |
| 47 |
|
| 48 |
public function getAllOptions(){ |
| 49 |
return $this->allOptions; |
| 50 |
} |
| 51 |
|
| 52 |
public function getStylesList(){ |
| 53 |
$styles = [ |
| 54 |
'default' => [] |
| 55 |
]; |
| 56 |
|
| 57 |
$isFullscreen = $this->getAllOptions()->getLayout() === 'fullscreen'; |
| 58 |
|
| 59 |
if( $isFullscreen || $this->keepAspect ) { |
| 60 |
$styles = $this->getMinHeightStyles( $styles, true ); |
| 61 |
} |
| 62 |
|
| 63 |
if( ! empty( $this->maxHeight->value ) && $isFullscreen ){ |
| 64 |
$styles[ 'default' ]['max-height'] = $this->maxHeight; |
| 65 |
} |
| 66 |
|
| 67 |
if( $this->backgroundColor ){ |
| 68 |
$styles['default']['background-color'] = $this->backgroundColor; |
| 69 |
} |
| 70 |
|
| 71 |
return $styles; |
| 72 |
} |
| 73 |
|
| 74 |
public function getMinHeightStyles( $styles = [], $keepAspect = null ){ |
| 75 |
if( empty( $styles ) ){ |
| 76 |
$styles = [ |
| 77 |
'default' => [] |
| 78 |
]; |
| 79 |
} |
| 80 |
|
| 81 |
$keepAspect = $keepAspect ?? $this->keepAspect; |
| 82 |
|
| 83 |
if( $keepAspect ) { |
| 84 |
$heightSizes = $this->getAllOptions()->getSizes('height', false ); |
| 85 |
foreach ( $heightSizes as $device => $height ){ |
| 86 |
if( ! empty( $this->minHeight->value ) && ( $device === 'default' || $height > $this->minHeight->value ) ){ |
| 87 |
$styles[ $device ]['min-height'] = $this->minHeight; |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
return $styles; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Get before init document styles |
| 98 |
* |
| 99 |
* @return array |
| 100 |
*/ |
| 101 |
public function getBeforeInitStyles(){ |
| 102 |
$styles = [ |
| 103 |
'default' => [] |
| 104 |
]; |
| 105 |
$layout = $this->getAllOptions()->getLayout(); |
| 106 |
|
| 107 |
if( $layout == 'fullscreen' ){ |
| 108 |
if( is_numeric( $this->fullscreenMargin ) ){ |
| 109 |
$styles['default']['height'] = "calc( 100vh - {$this->fullscreenMargin}px )"; |
| 110 |
} elseif ( $this->fullscreenMargin === 'auto' ) { |
| 111 |
$styles['default']['height'] = "100vh"; |
| 112 |
} |
| 113 |
} elseif( $layout == 'boxed' ){ |
| 114 |
$responsiveSizes = $this->getAllOptions()->getSizes('width', true); |
| 115 |
foreach ( $responsiveSizes as $device => $value ){ |
| 116 |
$styles[ $device ][ 'width' ] = $value; |
| 117 |
} |
| 118 |
|
| 119 |
$responsiveSizes = $this->getAllOptions()->getSizes('height', true); |
| 120 |
foreach ( $responsiveSizes as $device => $value ){ |
| 121 |
$styles[ $device ][ 'height' ] = $value; |
| 122 |
} |
| 123 |
} elseif( $layout == 'fullwidth' ){ |
| 124 |
$responsiveSizes = $this->getAllOptions()->getSizes('height', true); |
| 125 |
foreach ( $responsiveSizes as $device => $value ){ |
| 126 |
$styles[ $device ][ 'height' ] = $value; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
return $styles; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
} |
| 135 |
|