| 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 object |
| 40 |
*/ |
| 41 |
public $borderRadius; |
| 42 |
|
| 43 |
/** |
| 44 |
* @var object |
| 45 |
*/ |
| 46 |
public $boxShadow; |
| 47 |
|
| 48 |
/** |
| 49 |
* @var object |
| 50 |
*/ |
| 51 |
public $margin; |
| 52 |
|
| 53 |
/** |
| 54 |
* @var object |
| 55 |
*/ |
| 56 |
public $border; |
| 57 |
|
| 58 |
/** |
| 59 |
* @var All |
| 60 |
*/ |
| 61 |
protected $allOptions; |
| 62 |
|
| 63 |
|
| 64 |
public function setAllOptions( $allOptions ){ |
| 65 |
$this->allOptions = $allOptions; |
| 66 |
} |
| 67 |
|
| 68 |
public function getAllOptions(){ |
| 69 |
return $this->allOptions; |
| 70 |
} |
| 71 |
|
| 72 |
public function getStylesList(){ |
| 73 |
$styles = [ |
| 74 |
'default' => [] |
| 75 |
]; |
| 76 |
|
| 77 |
$isFullscreen = $this->getAllOptions()->getLayout() === 'fullscreen'; |
| 78 |
|
| 79 |
if( $isFullscreen || $this->keepAspect ) { |
| 80 |
$styles = $this->getMinHeightStyles( $styles, true ); |
| 81 |
} |
| 82 |
|
| 83 |
if( ! empty( $this->maxHeight->value ) && $isFullscreen ){ |
| 84 |
$styles[ 'default' ]['max-height'] = $this->maxHeight; |
| 85 |
} |
| 86 |
|
| 87 |
if( $this->backgroundColor ){ |
| 88 |
$styles['default']['background-color'] = $this->backgroundColor; |
| 89 |
} |
| 90 |
|
| 91 |
return $styles; |
| 92 |
} |
| 93 |
|
| 94 |
public function getBoxShadowStyle( $boxShadow ) { |
| 95 |
$offsetX = $boxShadow->offsetX ?? 10; |
| 96 |
$offsetY = $boxShadow->offsetY ?? 10; |
| 97 |
$blur = $boxShadow->blur ?? 25; |
| 98 |
$spread = $boxShadow->spread ?? 0; |
| 99 |
$color = $boxShadow->color ?? '#000'; |
| 100 |
$inset = !empty($boxShadow->inset) ? 'inset ' : ''; |
| 101 |
|
| 102 |
return $inset . $offsetX . "px " . $offsetY . 'px ' . $blur . 'px ' . $spread . 'px ' . $color; |
| 103 |
} |
| 104 |
|
| 105 |
public function getMinHeightStyles( $styles = [], $keepAspect = null ){ |
| 106 |
if( empty( $styles ) ){ |
| 107 |
$styles = [ |
| 108 |
'default' => [] |
| 109 |
]; |
| 110 |
} |
| 111 |
|
| 112 |
$keepAspect = $keepAspect ?? $this->keepAspect; |
| 113 |
|
| 114 |
if( $keepAspect ) { |
| 115 |
$heightSizes = $this->getAllOptions()->getSizes('height', false ); |
| 116 |
foreach ( $heightSizes as $device => $height ){ |
| 117 |
if( ! empty( $this->minHeight->value ) && ( $device === 'default' || $height > $this->minHeight->value ) ){ |
| 118 |
$styles[ $device ]['min-height'] = $this->minHeight; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
return $styles; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Get carousel styles |
| 128 |
* |
| 129 |
* @param object $documentTypeOptions |
| 130 |
* @return array $styles |
| 131 |
*/ |
| 132 |
public function getCarouselSectionStyles( $documentTypeOptions ) { |
| 133 |
$styles = [ |
| 134 |
'default' => [] |
| 135 |
]; |
| 136 |
|
| 137 |
if ( ! isset( $documentTypeOptions->carousel->styles ) ) { |
| 138 |
return $styles; |
| 139 |
} |
| 140 |
|
| 141 |
$sectionStyles = $documentTypeOptions->carousel->styles->section; |
| 142 |
if ( ! empty( $sectionStyles->boxShadow->enable ) ) { |
| 143 |
$styles['default']['box-shadow'] = $this->getBoxShadowStyle( $sectionStyles->boxShadow ); |
| 144 |
} |
| 145 |
|
| 146 |
if ( ! empty( $sectionStyles->borderRadius ) ) { |
| 147 |
if ( isset( $sectionStyles->borderRadius->link ) && $sectionStyles->borderRadius->link ) { |
| 148 |
$styles[ 'default' ][ 'border-radius' ] = $sectionStyles->borderRadius->topRight->value . $sectionStyles->borderRadius->topRight->unit; |
| 149 |
} elseif( isset( $sectionStyles->borderRadius->topLeft ) ) { |
| 150 |
$styles[ 'default' ][ 'border-radius' ] = $sectionStyles->borderRadius->topLeft->value . $sectionStyles->borderRadius->topLeft->unit ." ". $sectionStyles->borderRadius->topRight->value . $sectionStyles->borderRadius->topRight->unit ." " . $sectionStyles->borderRadius->bottomRight->value . $sectionStyles->borderRadius->bottomRight->unit ." " .$sectionStyles->borderRadius->bottomLeft->value . $sectionStyles->borderRadius->bottomLeft->unit; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
if ( ! empty( $sectionStyles->border->enabled ) ) { |
| 155 |
$styles[ 'default' ][ 'border-style' ] = $sectionStyles->border->style ?? 'solid'; |
| 156 |
if ( isset( $sectionStyles->border->link ) && $sectionStyles->border->link ) { |
| 157 |
$styles[ 'default' ][ 'border-width' ] = $sectionStyles->border->top->value . $sectionStyles->border->top->unit; |
| 158 |
} else { |
| 159 |
$styles[ 'default' ][ 'border-width' ] = $sectionStyles->border->top->value . $sectionStyles->border->top->unit ." ". $sectionStyles->border->right->value . $sectionStyles->border->right->unit ." " . $sectionStyles->border->bottom->value . $sectionStyles->border->bottom->unit ." " .$sectionStyles->border->left->value . $sectionStyles->border->left->unit; |
| 160 |
} |
| 161 |
|
| 162 |
if ( isset( $sectionStyles->border->color ) ) { |
| 163 |
$styles[ 'default' ][ 'border-color' ] = $sectionStyles->border->color; |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
return $styles; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
/** |
| 172 |
* Get before init document styles |
| 173 |
* |
| 174 |
* @return array |
| 175 |
*/ |
| 176 |
public function getBeforeInitStyles(){ |
| 177 |
$styles = [ |
| 178 |
'default' => [] |
| 179 |
]; |
| 180 |
$layout = $this->getAllOptions()->getLayout(); |
| 181 |
|
| 182 |
if( $layout == 'fullscreen' ){ |
| 183 |
if( is_numeric( $this->fullscreenMargin ) ){ |
| 184 |
$styles['default']['height'] = "calc( 100vh - {$this->fullscreenMargin}px )"; |
| 185 |
} elseif ( $this->fullscreenMargin === 'auto' ) { |
| 186 |
$styles['default']['height'] = "100vh"; |
| 187 |
} |
| 188 |
} elseif( $layout == 'boxed' ){ |
| 189 |
$responsiveSizes = $this->getAllOptions()->getSizes('width', true); |
| 190 |
foreach ( $responsiveSizes as $device => $value ){ |
| 191 |
$styles[ $device ][ 'width' ] = $value; |
| 192 |
} |
| 193 |
|
| 194 |
$responsiveSizes = $this->getAllOptions()->getSizes('height', true); |
| 195 |
foreach ( $responsiveSizes as $device => $value ){ |
| 196 |
$styles[ $device ][ 'height' ] = $value; |
| 197 |
} |
| 198 |
} elseif( $layout == 'fullwidth' ){ |
| 199 |
$responsiveSizes = $this->getAllOptions()->getSizes('height', true); |
| 200 |
foreach ( $responsiveSizes as $device => $value ){ |
| 201 |
$styles[ $device ][ 'height' ] = $value; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
return $styles; |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
public function getPrimaryContainerStyles() { |
| 210 |
$styles = [ |
| 211 |
'default' => [] |
| 212 |
]; |
| 213 |
|
| 214 |
if ( ! empty( $this->margin ) ) { |
| 215 |
if ( $this->margin->link ) { |
| 216 |
$styles['default']['margin-top'] = $this->margin->top->value . $this->margin->top->unit; |
| 217 |
$styles['default']['margin-bottom'] = $this->margin->top->value . $this->margin->top->unit; |
| 218 |
} else { |
| 219 |
$styles['default']['margin-top'] = $this->margin->top->value . $this->margin->top->unit; |
| 220 |
$styles['default']['margin-bottom'] = $this->margin->bottom->value . $this->margin->bottom->unit; |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
if ( ! empty( $this->borderRadius ) ) { |
| 225 |
if ( isset( $this->borderRadius->link ) && $this->borderRadius->link ) { |
| 226 |
$styles[ 'default' ][ 'border-radius' ] = $this->borderRadius->topRight->value . $this->borderRadius->topRight->unit; |
| 227 |
} elseif( isset( $this->borderRadius->topLeft ) ) { |
| 228 |
$styles[ 'default' ][ 'border-radius' ] = $this->borderRadius->topLeft->value . $this->borderRadius->topLeft->unit ." ". $this->borderRadius->topRight->value . $this->borderRadius->topRight->unit ." " . $this->borderRadius->bottomRight->value . $this->borderRadius->bottomRight->unit ." " .$this->borderRadius->bottomLeft->value . $this->borderRadius->bottomLeft->unit; |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
if ( ! empty( $this->boxShadow ) && $this->boxShadow->enable ) { |
| 233 |
$styles['default']['box-shadow'] = $this->getBoxShadowStyle( $this->boxShadow ); |
| 234 |
} |
| 235 |
|
| 236 |
if ( ! empty( $this->border->enable ) ) { |
| 237 |
$styles[ 'default' ][ 'border-style' ] = $this->border->style ?? 'solid'; |
| 238 |
if ( isset( $this->border->link ) && ! $this->border->link ) { |
| 239 |
$styles[ 'default' ][ 'border-width' ] = ($this->border->top->value ?? 1) . ($this->border->top->unit ?? "px") ." ". |
| 240 |
($this->border->right->value ?? 1) . ($this->border->right->unit ?? "px") ." ". |
| 241 |
($this->border->bottom->value ?? 1) . ($this->border->bottom->unit ?? "px") ." ". |
| 242 |
($this->border->left->value ?? 1) . ($this->border->left->unit ?? "px"); |
| 243 |
} else { |
| 244 |
$styles[ 'default' ][ 'border-width' ] = ($this->border->top->value ?? 1) . ($this->border->top->unit ?? "px"); |
| 245 |
|
| 246 |
} |
| 247 |
|
| 248 |
if ( isset( $this->border->color ) ) { |
| 249 |
$styles[ 'default' ][ 'border-color' ] = $this->border->color; |
| 250 |
} |
| 251 |
|
| 252 |
} |
| 253 |
|
| 254 |
return $styles; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
} |
| 259 |
|