| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\Styles; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\DynamicTags\Dynamic_Prop_Types_Mapping; |
| 6 |
use Elementor\Modules\AtomicWidgets\PropTypes\Background_Image_Overlay_Prop_Type; |
| 7 |
use Elementor\Modules\AtomicWidgets\PropTypes\Background_Overlay_Prop_Type; |
| 8 |
use Elementor\Modules\AtomicWidgets\PropTypes\Background_Prop_Type; |
| 9 |
use Elementor\Modules\AtomicWidgets\PropTypes\Box_Shadow_Prop_Type; |
| 10 |
use Elementor\Modules\AtomicWidgets\PropTypes\Border_Radius_Prop_Type; |
| 11 |
use Elementor\Modules\AtomicWidgets\PropTypes\Border_Width_Prop_Type; |
| 12 |
use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type; |
| 13 |
use Elementor\Modules\AtomicWidgets\PropTypes\Dimensions_Prop_Type; |
| 14 |
use Elementor\Modules\AtomicWidgets\PropTypes\Filters\Backdrop_Filter_Prop_Type; |
| 15 |
use Elementor\Modules\AtomicWidgets\PropTypes\Filters\Filter_Prop_Type; |
| 16 |
use Elementor\Modules\AtomicWidgets\PropTypes\Layout_Direction_Prop_Type; |
| 17 |
use Elementor\Modules\AtomicWidgets\PropTypes\Position_Prop_Type; |
| 18 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Number_Prop_Type; |
| 19 |
use Elementor\Modules\AtomicWidgets\PropTypes\Size_Prop_Type; |
| 20 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\String_Prop_Type; |
| 21 |
use Elementor\Modules\AtomicWidgets\PropTypes\Stroke_Prop_Type; |
| 22 |
use Elementor\Modules\AtomicWidgets\PropTypes\Transform\Transform_Prop_Type; |
| 23 |
use Elementor\Modules\AtomicWidgets\PropTypes\Transition_Prop_Type; |
| 24 |
use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type; |
| 25 |
use Elementor\Modules\AtomicWidgets\PropTypes\Flex_Prop_Type; |
| 26 |
use Elementor\Modules\AtomicWidgets\PropDependencies\Manager as Dependency_Manager; |
| 27 |
|
| 28 |
if ( ! defined( 'ABSPATH' ) ) { |
| 29 |
exit; // Exit if accessed directly. |
| 30 |
} |
| 31 |
|
| 32 |
class Style_Schema { |
| 33 |
public static function get() { |
| 34 |
return apply_filters( 'elementor/atomic-widgets/styles/schema', static::get_style_schema() ); |
| 35 |
} |
| 36 |
|
| 37 |
public static function get_style_schema(): array { |
| 38 |
return array_merge( |
| 39 |
self::get_size_props(), |
| 40 |
self::get_position_props(), |
| 41 |
self::get_typography_props(), |
| 42 |
self::get_spacing_props(), |
| 43 |
self::get_border_props(), |
| 44 |
self::get_background_props(), |
| 45 |
self::get_effects_props(), |
| 46 |
self::get_layout_props(), |
| 47 |
self::get_alignment_props(), |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
private static function get_size_props() { |
| 52 |
return [ |
| 53 |
'width' => Size_Prop_Type::make()->description( 'The width of the element' ), |
| 54 |
'height' => Size_Prop_Type::make()->description( 'The height of the element' ), |
| 55 |
'min-width' => Size_Prop_Type::make()->description( 'The minimum width of the element' ), |
| 56 |
'min-height' => Size_Prop_Type::make()->description( 'The minimum height of the element' ), |
| 57 |
'max-width' => Size_Prop_Type::make()->description( 'The maximum width of the element' ), |
| 58 |
'max-height' => Size_Prop_Type::make()->description( 'The maximum height of the element' ), |
| 59 |
'overflow' => String_Prop_Type::make()->enum( [ |
| 60 |
'visible', |
| 61 |
'hidden', |
| 62 |
'auto', |
| 63 |
] )->description( 'The overflow CSS property. CSS values: visible, hidden, auto' ), |
| 64 |
'aspect-ratio' => String_Prop_Type::make()->description( 'Equivalent to CSS aspect-ration property' ), |
| 65 |
'object-fit' => String_Prop_Type::make()->enum( [ |
| 66 |
'fill', |
| 67 |
'cover', |
| 68 |
'contain', |
| 69 |
'none', |
| 70 |
'scale-down', |
| 71 |
] )->description( 'The object-fit CSS. CSS values: fill, cover, contain, none, scale-down' ), |
| 72 |
'object-position' => Union_Prop_Type::make() |
| 73 |
->add_prop_type( String_Prop_Type::make()->enum( Position_Prop_Type::get_position_enum_values() ) ) |
| 74 |
->add_prop_type( Position_Prop_Type::make() ) |
| 75 |
->set_dependencies( |
| 76 |
Dependency_Manager::make( Dependency_Manager::RELATION_AND ) |
| 77 |
->where( [ |
| 78 |
'operator' => 'ne', |
| 79 |
'path' => [ 'object-fit' ], |
| 80 |
'value' => 'fill', |
| 81 |
] ) |
| 82 |
->where( [ |
| 83 |
'operator' => 'exists', |
| 84 |
'path' => [ 'object-fit' ], |
| 85 |
] ) |
| 86 |
->get() |
| 87 |
), |
| 88 |
]; |
| 89 |
} |
| 90 |
|
| 91 |
private static function get_position_props() { |
| 92 |
return [ |
| 93 |
'position' => String_Prop_Type::make()->enum( [ |
| 94 |
'static', |
| 95 |
'relative', |
| 96 |
'absolute', |
| 97 |
'fixed', |
| 98 |
'sticky', |
| 99 |
] )->description( 'The CSS position property specifies the type of positioning method used for an element (static, relative, absolute, fixed, or sticky).' ), |
| 100 |
'inset-block-start' => Size_Prop_Type::make()->description( 'Size PropType for the inset-block-start CSS property' ), |
| 101 |
'inset-inline-end' => Size_Prop_Type::make()->description( 'Size PropType for the inset-inline-end CSS property' ), |
| 102 |
'inset-block-end' => Size_Prop_Type::make()->description( 'Size PropType for the inset-block-end CSS property' ), |
| 103 |
'inset-inline-start' => Size_Prop_Type::make()->description( 'Size PropType for the inset-inline-start CSS property' ), |
| 104 |
'z-index' => Number_Prop_Type::make() |
| 105 |
->description( 'The z-index CSS property sets the z-order of a positioned element and its descendants or flex items. It specifies the stack order of elements.' ), |
| 106 |
'scroll-margin-top' => Size_Prop_Type::make()->units( Size_Constants::anchor_offset() ), |
| 107 |
]; |
| 108 |
} |
| 109 |
|
| 110 |
private static function get_typography_props() { |
| 111 |
return [ |
| 112 |
'font-family' => String_Prop_Type::make()->description( 'The font family of the text content.' ), |
| 113 |
'font-weight' => String_Prop_Type::make()->enum( [ |
| 114 |
'100', |
| 115 |
'200', |
| 116 |
'300', |
| 117 |
'400', |
| 118 |
'500', |
| 119 |
'600', |
| 120 |
'700', |
| 121 |
'800', |
| 122 |
'900', |
| 123 |
'normal', |
| 124 |
'bold', |
| 125 |
'bolder', |
| 126 |
'lighter', |
| 127 |
] ) |
| 128 |
->description( 'The weight (or boldness) of the font. Values should match css font-weight specifications.' ), |
| 129 |
'font-size' => Size_Prop_Type::make()->units( Size_Constants::typography() )->description( 'The font size in Size PropType Format' ), |
| 130 |
'color' => Color_Prop_Type::make() |
| 131 |
->description( 'The text color, specified as a hex code, rgb(a), hsl(a), or a standard css color name.' ), |
| 132 |
'letter-spacing' => Size_Prop_Type::make()->units( Size_Constants::typography() )->description( 'The spacing between letters in Size PropType format' ), |
| 133 |
'word-spacing' => Size_Prop_Type::make()->units( Size_Constants::typography() )->description( 'The spacing between words in Size PropType format' ), |
| 134 |
'column-count' => Number_Prop_Type::make()->description( 'The number of columns the text content should be divided into.' ), |
| 135 |
'column-gap' => Size_Prop_Type::make() |
| 136 |
->set_dependencies( |
| 137 |
Dependency_Manager::make() |
| 138 |
->where( [ |
| 139 |
'operator' => 'gte', |
| 140 |
'path' => [ 'column-count' ], |
| 141 |
'value' => 1, |
| 142 |
] ) |
| 143 |
->get() |
| 144 |
), |
| 145 |
'line-height' => Size_Prop_Type::make()->units( Size_Constants::typography() )->description( 'The line height of the text content in Size PropType format' ), |
| 146 |
'text-align' => String_Prop_Type::make()->enum( [ |
| 147 |
'start', |
| 148 |
'center', |
| 149 |
'end', |
| 150 |
'justify', |
| 151 |
] ) |
| 152 |
->description( 'The horizontal alignment of the text content. Allowed values: start, center, end, justify.' ), |
| 153 |
'font-style' => String_Prop_Type::make()->enum( [ |
| 154 |
'normal', |
| 155 |
'italic', |
| 156 |
'oblique', |
| 157 |
] ) |
| 158 |
->description( 'The font style of the text content. CSS values: normal, italic, oblique' ), |
| 159 |
// TODO: validate text-decoration in more specific way [EDS-524] |
| 160 |
'text-decoration' => String_Prop_Type::make() |
| 161 |
->description( 'The text decoration style. CSS values like: none, underline, overline, line-through, blink, etc.' ), |
| 162 |
'text-transform' => String_Prop_Type::make()->enum( [ |
| 163 |
'none', |
| 164 |
'capitalize', |
| 165 |
'uppercase', |
| 166 |
'lowercase', |
| 167 |
] ) |
| 168 |
->description( 'Controls the capitalization of text. CSS values: none, capitalize, uppercase, lowercase' ), |
| 169 |
'direction' => String_Prop_Type::make()->enum( [ |
| 170 |
'ltr', |
| 171 |
'rtl', |
| 172 |
] )->description( 'The text direction. CSS values: ltr (left to right), rtl (right to left)' ), |
| 173 |
'stroke' => Stroke_Prop_Type::make(), |
| 174 |
'all' => String_Prop_Type::make()->enum( [ |
| 175 |
'initial', |
| 176 |
'inherit', |
| 177 |
'unset', |
| 178 |
'revert', |
| 179 |
'revert-layer', |
| 180 |
] )->description( 'The all CSS property. CSS values: initial, inherit, unset, revert, revert-layer' ), |
| 181 |
'cursor' => String_Prop_Type::make()->enum( [ |
| 182 |
'pointer', |
| 183 |
] ) |
| 184 |
->description( 'The type of cursor to be displayed when pointing over the element. E.g., pointer.' ), |
| 185 |
]; |
| 186 |
} |
| 187 |
|
| 188 |
private static function get_spacing_props() { |
| 189 |
return [ |
| 190 |
'padding' => Union_Prop_Type::make() |
| 191 |
->add_prop_type( Dimensions_Prop_Type::make_with_units( Size_Constants::spacing() ) ) |
| 192 |
->add_prop_type( |
| 193 |
Size_Prop_Type::make() |
| 194 |
->units( Size_Constants::spacing() ) |
| 195 |
->description( 'Padding css in Size PropType format' ) |
| 196 |
), |
| 197 |
'margin' => Union_Prop_Type::make() |
| 198 |
->add_prop_type( Dimensions_Prop_Type::make_with_units( Size_Constants::spacing_margin() ) ) |
| 199 |
->add_prop_type( |
| 200 |
Size_Prop_Type::make() |
| 201 |
->units( Size_Constants::spacing_margin() ) |
| 202 |
->description( 'Margin css in Size PropType format' ) |
| 203 |
), |
| 204 |
]; |
| 205 |
} |
| 206 |
|
| 207 |
private static function get_border_props() { |
| 208 |
return [ |
| 209 |
'border-radius' => Union_Prop_Type::make() |
| 210 |
->add_prop_type( Border_Radius_Prop_Type::make() ) |
| 211 |
->add_prop_type( Size_Prop_Type::make()->units( Size_Constants::border() ) ), |
| 212 |
'border-width' => Union_Prop_Type::make() |
| 213 |
->add_prop_type( Border_Width_Prop_Type::make() ) |
| 214 |
->add_prop_type( Size_Prop_Type::make()->units( Size_Constants::border() ) ), |
| 215 |
'border-color' => Color_Prop_Type::make()->description( 'The border color, specified as a hex code, rgb(a), hsl(a), or a standard css color name.' ), |
| 216 |
'border-style' => String_Prop_Type::make()->enum( [ |
| 217 |
'none', |
| 218 |
'hidden', |
| 219 |
'dotted', |
| 220 |
'dashed', |
| 221 |
'solid', |
| 222 |
'double', |
| 223 |
'groove', |
| 224 |
'ridge', |
| 225 |
'inset', |
| 226 |
'outset', |
| 227 |
] ) |
| 228 |
->description( 'The border style in CSS values' ), |
| 229 |
'outline-width' => Size_Prop_Type::make() |
| 230 |
->units( Size_Constants::border() ) |
| 231 |
->description( 'The width of the outline in Size PropType format' ), |
| 232 |
]; |
| 233 |
} |
| 234 |
|
| 235 |
private static function get_background_props() { |
| 236 |
// Background image overlay as an exception |
| 237 |
$background_prop_type = Background_Prop_Type::make(); |
| 238 |
$bg_overlay_prop_type = $background_prop_type->get_shape_field( Background_Overlay_Prop_Type::get_key() ); |
| 239 |
$bg_image_overlay_prop_type = $bg_overlay_prop_type->get_item_type()->get_prop_type( Background_Image_Overlay_Prop_Type::get_key() ); |
| 240 |
Dynamic_Prop_Types_Mapping::make()->get_extended_schema( $bg_image_overlay_prop_type->get_shape() ); |
| 241 |
return [ |
| 242 |
'background' => $background_prop_type, |
| 243 |
]; |
| 244 |
} |
| 245 |
|
| 246 |
private static function get_effects_props() { |
| 247 |
return [ |
| 248 |
'mix-blend-mode' => String_Prop_Type::make()->enum( [ |
| 249 |
'normal', |
| 250 |
'multiply', |
| 251 |
'screen', |
| 252 |
'overlay', |
| 253 |
'darken', |
| 254 |
'lighten', |
| 255 |
'color-dodge', |
| 256 |
'saturation', |
| 257 |
'color', |
| 258 |
'difference', |
| 259 |
'exclusion', |
| 260 |
'hue', |
| 261 |
'luminosity', |
| 262 |
'soft-light', |
| 263 |
'hard-light', |
| 264 |
'color-burn', |
| 265 |
] )->description( 'Applied as mix-blend mode css effect.' ), |
| 266 |
'box-shadow' => Box_Shadow_Prop_Type::make(), |
| 267 |
'opacity' => Size_Prop_Type::make() |
| 268 |
->description( 'The opacity of the element, specified as a percentage between 0 (fully transparent) and 100 (fully opaque).' ) |
| 269 |
->units( Size_Constants::opacity() ) |
| 270 |
->default_unit( Size_Constants::UNIT_PERCENT ), |
| 271 |
'filter' => Filter_Prop_Type::make(), |
| 272 |
'backdrop-filter' => Backdrop_Filter_Prop_Type::make(), |
| 273 |
'transform' => Transform_Prop_Type::make(), |
| 274 |
'transition' => Transition_Prop_Type::make(), |
| 275 |
]; |
| 276 |
} |
| 277 |
|
| 278 |
private static function get_layout_props() { |
| 279 |
return [ |
| 280 |
'display' => String_Prop_Type::make()->enum( [ |
| 281 |
'block', |
| 282 |
'inline', |
| 283 |
'inline-block', |
| 284 |
'flex', |
| 285 |
'inline-flex', |
| 286 |
'grid', |
| 287 |
'inline-grid', |
| 288 |
'flow-root', |
| 289 |
'none', |
| 290 |
'contents', |
| 291 |
] )->description( 'The CSS display property defines the display behavior (the type of rendering box) of an element.' ), |
| 292 |
'flex-direction' => String_Prop_Type::make() |
| 293 |
->description( 'The direction of the contained items.' ) |
| 294 |
->enum( [ |
| 295 |
'row', |
| 296 |
'row-reverse', |
| 297 |
'column', |
| 298 |
'column-reverse', |
| 299 |
] ), |
| 300 |
'gap' => Union_Prop_Type::make() |
| 301 |
->add_prop_type( Layout_Direction_Prop_Type::make() ) |
| 302 |
->add_prop_type( Size_Prop_Type::make()->units( Size_Constants::layout() ) ), |
| 303 |
'flex-wrap' => String_Prop_Type::make()->enum( [ |
| 304 |
'wrap', |
| 305 |
'nowrap', |
| 306 |
'wrap-reverse', |
| 307 |
] )->description( 'Specifies whether the flex items should wrap or not. CSS values: wrap, nowrap, wrap-reverse' ), |
| 308 |
'flex' => Flex_Prop_Type::make(), |
| 309 |
]; |
| 310 |
} |
| 311 |
|
| 312 |
private static function get_alignment_props() { |
| 313 |
return [ |
| 314 |
'justify-content' => String_Prop_Type::make()->enum( [ |
| 315 |
'center', |
| 316 |
'start', |
| 317 |
'end', |
| 318 |
'flex-start', |
| 319 |
'flex-end', |
| 320 |
'left', |
| 321 |
'right', |
| 322 |
'normal', |
| 323 |
'space-between', |
| 324 |
'space-around', |
| 325 |
'space-evenly', |
| 326 |
'stretch', |
| 327 |
] ) |
| 328 |
->description( 'Defines how the browser distributes space between and around content items along the main-axis of a flex container. CSS values: center, start, end, flex-start, flex-end, left, right, normal, space-between, space-around, space-evenly, stretch' ), |
| 329 |
'align-content' => String_Prop_Type::make()->enum( [ |
| 330 |
'center', |
| 331 |
'start', |
| 332 |
'end', |
| 333 |
'space-between', |
| 334 |
'space-around', |
| 335 |
'space-evenly', |
| 336 |
] ) |
| 337 |
->description( 'Aligns a flex container\'s lines within when there is extra space in the cross-axis. CSS values: center, start, end, space-between, space-around, space-evenly' ), |
| 338 |
'align-items' => String_Prop_Type::make()->enum( [ |
| 339 |
'normal', |
| 340 |
'stretch', |
| 341 |
'center', |
| 342 |
'start', |
| 343 |
'end', |
| 344 |
'flex-start', |
| 345 |
'flex-end', |
| 346 |
'self-start', |
| 347 |
'self-end', |
| 348 |
'anchor-center', |
| 349 |
] )->description( 'Defines the default behavior for how flex items are laid out along the cross axis on the current line. CSS values: normal, stretch, center, start, end, flex-start, flex-end, self-start, self-end, anchor-center' ), |
| 350 |
'align-self' => String_Prop_Type::make()->enum( [ |
| 351 |
'auto', |
| 352 |
'normal', |
| 353 |
'center', |
| 354 |
'start', |
| 355 |
'end', |
| 356 |
'self-start', |
| 357 |
'self-end', |
| 358 |
'flex-start', |
| 359 |
'flex-end', |
| 360 |
'anchor-center', |
| 361 |
'baseline', |
| 362 |
'first baseline', |
| 363 |
'last baseline', |
| 364 |
'stretch', |
| 365 |
] )->description( 'Allows the default alignment (or the one specified by align-items) to be overridden for individual flex items. CSS values: auto, normal, center, start, end, self-start, self-end, flex-start, flex-end, anchor-center, baseline, first baseline, last baseline, stretch' ), |
| 366 |
'order' => Number_Prop_Type::make()->description( 'Specifies the order of the flex items. Items with lower order values are displayed first.' ), |
| 367 |
]; |
| 368 |
} |
| 369 |
} |
| 370 |
|