| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace Wpxero\Marqueex\Core; |
| 5 |
|
| 6 |
defined('ABSPATH') || exit; |
| 7 |
|
| 8 |
/** |
| 9 |
* Converts styles to CSS. |
| 10 |
* |
| 11 |
* Plain value object — instantiate one per property. It holds transient |
| 12 |
* device/hover state that parse() does not reset, so it must not be shared. |
| 13 |
*/ |
| 14 |
class Property { |
| 15 |
|
| 16 |
|
| 17 |
/** |
| 18 |
* Raw name of the property without device or psuedo-class. |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
public string $name; |
| 23 |
|
| 24 |
/** |
| 25 |
* Device type. |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
public string $device = 'desktop'; |
| 30 |
|
| 31 |
/** |
| 32 |
* Hover psuedo-class or not. |
| 33 |
* |
| 34 |
* @var bool |
| 35 |
*/ |
| 36 |
public bool $hover = false; |
| 37 |
|
| 38 |
/** |
| 39 |
* Constructor |
| 40 |
*/ |
| 41 |
public function __construct() { |
| 42 |
// No initialization required; fields default per declaration. |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Set property name and parse it |
| 47 |
* |
| 48 |
* @param string $property |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public function set_property(string $property): void { |
| 52 |
$this->name = $property; |
| 53 |
$this->parse(); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Parse the fullname. |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
private function parse(): void { |
| 62 |
if (str_starts_with($this->name, 'tablet')) { |
| 63 |
$this->name = lcfirst(substr($this->name, 6)); |
| 64 |
$this->device = 'tablet'; |
| 65 |
} elseif (str_starts_with($this->name, 'mobile')) { |
| 66 |
$this->name = lcfirst(substr($this->name, 6)); |
| 67 |
$this->device = 'mobile'; |
| 68 |
} |
| 69 |
|
| 70 |
if (str_ends_with($this->name, 'Hover')) { |
| 71 |
$this->name = substr($this->name, 0, strlen($this->name) - 5); |
| 72 |
$this->hover = true; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|