| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Common; |
| 3 |
|
| 4 |
use Averta\Core\Utility\Data; |
| 5 |
use Averta\WordPress\Utility\JSON; |
| 6 |
use Depicter\Document\CSS\Breakpoints; |
| 7 |
use Depicter\Document\Helper\Helper; |
| 8 |
|
| 9 |
class KenBurns extends States { |
| 10 |
|
| 11 |
/** |
| 12 |
* Get all kenburn attributes |
| 13 |
* |
| 14 |
* @return array |
| 15 |
*/ |
| 16 |
public function getKenBurnsAttrs(): array{ |
| 17 |
$attrs = []; |
| 18 |
// Collect animation attributes |
| 19 |
foreach ( Breakpoints::names() as $breakpoint ){ |
| 20 |
$breakpoint_prefix = $breakpoint ? $breakpoint . '-' : $breakpoint; |
| 21 |
$breakpoint_prefix = $breakpoint == 'default' ? '' : $breakpoint_prefix; |
| 22 |
|
| 23 |
if( Helper::isStyleEnabled( $this, $breakpoint ) ){ |
| 24 |
$attrs[ 'data-'. $breakpoint_prefix .'ken-burns' ] = $this->getKenBurnsOption( $breakpoint ); |
| 25 |
} else if ( isset( $this->default->enable ) ) { |
| 26 |
$attrs[ 'data-'. $breakpoint_prefix .'ken-burns' ] = "false"; |
| 27 |
} |
| 28 |
|
| 29 |
} |
| 30 |
return $attrs; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get kenburns option |
| 35 |
* |
| 36 |
* @param string $breakpoint |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
public function getKenBurnsOption( $breakpoint ): string{ |
| 40 |
$options = []; |
| 41 |
|
| 42 |
$options['scale'] = $this->{$breakpoint}->params->scale ?? $this->getParentValue( 'scale', $breakpoint, ''); |
| 43 |
$options['duration'] = $this->{$breakpoint}->params->duration ?? $this->getParentValue( 'duration', $breakpoint, '5000'); |
| 44 |
$options['focalPoint']['x'] = $this->{$breakpoint}->params->focalPoint->x ?? $this->getParentValue( 'focalX', $breakpoint, ''); |
| 45 |
$options['focalPoint']['y'] = $this->{$breakpoint}->params->focalPoint->y ?? $this->getParentValue( 'focalY', $breakpoint, ''); |
| 46 |
$options['easing'] = $this->{$breakpoint}->params->easing ?? $this->getParentValue( 'easing', $breakpoint, 'linear'); |
| 47 |
|
| 48 |
return JSON::encode( $options ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Get parent device value for a css variable |
| 53 |
* |
| 54 |
* @param $variable |
| 55 |
* @param $device |
| 56 |
* @param $default |
| 57 |
* |
| 58 |
* @return mixed |
| 59 |
*/ |
| 60 |
public function getParentValue( $variable, $device, $default ) { |
| 61 |
$parentDevice = Breakpoints::getParentDevice( $device ); |
| 62 |
if ( !empty( $parentDevice ) ) { |
| 63 |
if ( strpos( $variable, 'focal' ) === false ) { |
| 64 |
return $this->{$parentDevice}->params->{$variable} ?? $this->getParentValue( $variable, $parentDevice, $default ); |
| 65 |
} else { |
| 66 |
$focalAxis = str_replace( 'focal', '', strtolower( $variable ) ); |
| 67 |
return $this->{$parentDevice}->params->focalPoint->{$focalAxis} ?? $this->getParentValue( $variable, $parentDevice, $default ); |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
return $default; |
| 73 |
} |
| 74 |
} |
| 75 |
|