Changeset 55719
- Timestamp:
- 05/03/2023 11:55:50 PM (19 months ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/style-engine.php
r54156 r55719 11 11 */ 12 12 13 14 13 /** 15 14 * Global public interface method to generate styles from a single style object, e.g., … … 20 19 * Example usage: 21 20 * 22 * $styles = wp_style_engine_get_styles( array( 'color' => array( 'text' => '#cccccc' ) ) ); 23 * // Returns `array( 'css' => 'color: #cccccc', 'declarations' => array( 'color' => '#cccccc' ), 'classnames' => 'has-color' )`. 21 * $styles = wp_style_engine_get_styles( array( 'color' => array( 'text' => '#cccccc' ) ) ); 22 * 23 * Returns: 24 * 25 * array( 'css' => 'color: #cccccc', 'declarations' => array( 'color' => '#cccccc' ), 'classnames' => 'has-color' ) 24 26 * 25 27 * @access public … … 32 34 * @type string|null $context An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is `null`. 33 35 * When set, the style engine will attempt to store the CSS rules, where a selector is also passed. 34 * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* )values. Default `false`.36 * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to `var( --wp--preset--* )` values. Default `false`. 35 37 * @type string $selector Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`, 36 38 * otherwise, the value will be a concatenated string of CSS declarations. 37 39 * } 38 *39 40 * @return array { 40 41 * @type string $css A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag. 41 * @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).42 * @type string[] $declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`. 42 43 * @type string $classnames Classnames separated by a space. 43 44 * } … … 75 76 /** 76 77 * Returns compiled CSS from a collection of selectors and declarations. 77 * Useful for returning a compiled stylesheet from any collection of 78 * Useful for returning a compiled stylesheet from any collection of CSS selector + declarations. 78 79 * 79 80 * Example usage: 80 * $css_rules = array( array( 'selector' => '.elephant-are-cool', 'declarations' => array( 'color' => 'gray', 'width' => '3em' ) ) ); 81 * $css = wp_style_engine_get_stylesheet_from_css_rules( $css_rules ); 82 * // Returns `.elephant-are-cool{color:gray;width:3em}`. 81 * 82 * $css_rules = array( array( 'selector' => '.elephant-are-cool', 'declarations' => array( 'color' => 'gray', 'width' => '3em' ) ) ); 83 * $css = wp_style_engine_get_stylesheet_from_css_rules( $css_rules ); 84 * 85 * Returns: 86 * 87 * .elephant-are-cool{color:gray;width:3em} 83 88 * 84 89 * @since 6.1.0 … … 89 94 * @type array ...$0 { 90 95 * @type string $selector A CSS selector. 91 * @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).96 * @type string[] $declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`. 92 97 * } 93 98 * } … … 100 105 * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined. 101 106 * } 102 *103 107 * @return string A string of compiled CSS declarations, or empty string. 104 108 */ … … 147 151 * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined. 148 152 * } 149 *150 153 * @return string A compiled CSS string. 151 154 */ -
trunk/src/wp-includes/style-engine/class-wp-style-engine-css-declarations.php
r54481 r55719 25 25 * @since 6.1.0 26 26 * 27 * @var array27 * @var string[] 28 28 */ 29 29 protected $declarations = array(); … … 37 37 * @since 6.1.0 38 38 * 39 * @param string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).39 * @param string[] $declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`. 40 40 */ 41 41 public function __construct( $declarations = array() ) { … … 50 50 * @param string $property The CSS property. 51 51 * @param string $value The CSS value. 52 *53 52 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods. 54 53 */ … … 79 78 * 80 79 * @param string $property The CSS property. 81 *82 80 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods. 83 81 */ … … 92 90 * @since 6.1.0 93 91 * 94 * @param array $declarations An array of declarations. 95 * 92 * @param string[] $declarations An array of declarations. 96 93 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods. 97 94 */ … … 108 105 * @since 6.1.0 109 106 * 110 * @param array $properties An array of properties. 111 * 107 * @param string[] $properties An array of properties. 112 108 * @return WP_Style_Engine_CSS_Declarations Returns the object to allow chaining methods. 113 109 */ … … 124 120 * @since 6.1.0 125 121 * 126 * @return array122 * @return string[] The declarations array. 127 123 */ 128 124 public function get_declarations() { … … 138 134 * @param string $value The value to be filtered. 139 135 * @param string $spacer The spacer between the colon and the value. Defaults to an empty string. 140 *141 136 * @return string The filtered declaration or an empty string. 142 137 */ … … 154 149 * @since 6.1.0 155 150 * 156 * @param bool $should_prettify Whether to add spacing, new lines and indents. 157 * @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`. 158 * 151 * @param bool $should_prettify Whether to add spacing, new lines and indents. 152 * @param int $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`. 159 153 * @return string The CSS declarations. 160 154 */ … … 182 176 * 183 177 * @param string $property The CSS property. 184 *185 178 * @return string The sanitized property name. 186 179 */ -
trunk/src/wp-includes/style-engine/class-wp-style-engine-css-rule.php
r54481 r55719 44 44 * 45 45 * @param string $selector The CSS selector. 46 * @param string[]|WP_Style_Engine_CSS_Declarations $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ),46 * @param string[]|WP_Style_Engine_CSS_Declarations $declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`, 47 47 * or a WP_Style_Engine_CSS_Declarations object. 48 48 */ … … 58 58 * 59 59 * @param string $selector The CSS selector. 60 *61 60 * @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods. 62 61 */ … … 73 72 * @param array|WP_Style_Engine_CSS_Declarations $declarations An array of declarations (property => value pairs), 74 73 * or a WP_Style_Engine_CSS_Declarations object. 75 *76 74 * @return WP_Style_Engine_CSS_Rule Returns the object to allow chaining of methods. 77 75 */ … … 119 117 * @since 6.1.0 120 118 * 121 * @param bool $should_prettify Whether to add spacing, new lines and indents. 122 * @param number $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`. 123 * 119 * @param bool $should_prettify Whether to add spacing, new lines and indents. 120 * @param int $indent_count The number of tab indents to apply to the rule. Applies if `prettify` is `true`. 124 121 * @return string 125 122 */ -
trunk/src/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php
r54481 r55719 52 52 * 53 53 * @param string $store_name The name of the store. 54 *55 54 * @return WP_Style_Engine_CSS_Rules_Store|void 56 55 */ … … 95 94 * 96 95 * @param string $name The store name. 97 *98 96 * @return void 99 97 */ … … 131 129 * 132 130 * @param string $selector The CSS selector. 133 * 134 * @return WP_Style_Engine_CSS_Rule|void Returns a WP_Style_Engine_CSS_Rule object, or null if the selector is empty. 131 * @return WP_Style_Engine_CSS_Rule|void Returns a WP_Style_Engine_CSS_Rule object, or void if the selector is empty. 135 132 */ 136 133 public function add_rule( $selector ) { … … 156 153 * 157 154 * @param string $selector The CSS selector. 158 *159 155 * @return void 160 156 */ -
trunk/src/wp-includes/style-engine/class-wp-style-engine-processor.php
r54481 r55719 42 42 * 43 43 * @param WP_Style_Engine_CSS_Rules_Store $store The store to add. 44 *45 44 * @return WP_Style_Engine_Processor Returns the object to allow chaining methods. 46 45 */ … … 66 65 * 67 66 * @param WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[] $css_rules A single, or an array of, WP_Style_Engine_CSS_Rule objects from a store or otherwise. 68 *69 67 * @return WP_Style_Engine_Processor Returns the object to allow chaining methods. 70 68 */ … … 97 95 * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined. 98 96 * } 99 *100 97 * @return string The computed CSS. 101 98 */ -
trunk/src/wp-includes/style-engine/class-wp-style-engine.php
r55175 r55719 17 17 * This class is final and should not be extended. 18 18 * This class is for internal Core usage and is not supposed to be used by extenders (plugins and/or themes). 19 * This is a low-level API that may need to do breaking changes. Please, use wp_style_engine_get_styles instead.19 * This is a low-level API that may need to do breaking changes. Please, use wp_style_engine_get_styles() instead. 20 20 * 21 21 * @access private … … 230 230 231 231 /** 232 * Util: Extracts the slug in kebab case from a preset string, e.g., "heavenly-blue" from 'var:preset|color|heavenlyBlue'.232 * Util: Extracts the slug in kebab case from a preset string, e.g., `heavenly-blue` from `var:preset|color|heavenlyBlue`. 233 233 * 234 234 * @since 6.1.0 … … 236 236 * @param string $style_value A single CSS preset value. 237 237 * @param string $property_key The CSS property that is the second element of the preset string. Used for matching. 238 *239 238 * @return string The slug, or empty string if not found. 240 239 */ … … 248 247 249 248 /** 250 * Util: Generates a CSS var string, e.g., var(--wp--preset--color--background) from a preset string such as `var:preset|space|50`. 251 * 252 * @since 6.1.0 253 * 254 * @param string $style_value A single css preset value. 255 * @param string[] $css_vars An associate array of css var patterns used to generate the var string. 256 * 257 * @return string The css var, or an empty string if no match for slug found. 249 * Util: Generates a CSS var string, e.g., `var(--wp--preset--color--background)` from a preset string such as `var:preset|space|50`. 250 * 251 * @since 6.1.0 252 * 253 * @param string $style_value A single CSS preset value. 254 * @param string[] $css_vars An associate array of CSS var patterns used to generate the var string. 255 * @return string The CSS var, or an empty string if no match for slug found. 258 256 */ 259 257 protected static function get_css_var_value( $style_value, $css_vars ) { 260 foreach ( $css_vars as 258 foreach ( $css_vars as $property_key => $css_var_pattern ) { 261 259 $slug = static::get_slug_from_preset_value( $style_value, $property_key ); 262 260 if ( static::is_valid_style_value( $slug ) ) { … … 277 275 * 278 276 * @param string $style_value A single CSS preset value. 279 *280 277 * @return bool 281 278 */ … … 291 288 * @param string $store_name A valid store key. 292 289 * @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values. 293 * @param string[] $css_declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ). 294 * 295 * @return void. 290 * @param string[] $css_declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`. 291 * @return void 296 292 */ 297 293 public static function store_css_rule( $store_name, $css_selector, $css_declarations ) { … … 308 304 * 309 305 * @param string $store_name A store key. 310 * 311 * @return WP_Style_Engine_CSS_Rules_Store 306 * @return WP_Style_Engine_CSS_Rules_Store|null 312 307 */ 313 308 public static function get_store( $store_name ) { … … 325 320 * Optional. An array of options. Default empty array. 326 321 * 327 * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.322 * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to `var( --wp--preset--* )` values. Default false. 328 323 * @type string $selector Optional. When a selector is passed, the value of `$css` in the return value will comprise a full CSS rule `$selector { ...$css_declarations }`, 329 324 * otherwise, the value will be a concatenated string of CSS declarations. 330 325 * } 331 *332 326 * @return array { 333 * @type string $classnames Classnames separated by a space.334 * @type string[] $declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).327 * @type string[] $classnames Array of class names. 328 * @type string[] $declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`. 335 329 * } 336 330 */ … … 365 359 366 360 /** 367 * Returns classnames, and generates classname(s) from a CSS preset property pattern, e.g., '`var:preset|<PRESET_TYPE>|<PRESET_SLUG>`'. 368 * 369 * @since 6.1.0 370 * 371 * @param array $style_value A single raw style value or css preset property from the $block_styles array. 372 * @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA. 373 * 374 * @return array|string[] An array of CSS classnames, or empty array. 361 * Returns classnames, and generates classname(s) from a CSS preset property pattern, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`. 362 * 363 * @since 6.1.0 364 * 365 * @param string $style_value A single raw style value or CSS preset property from the `$block_styles` array. 366 * @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA. 367 * @return string[] An array of CSS classnames, or empty array if there are none. 375 368 */ 376 369 protected static function get_classnames( $style_value, $style_definition ) { … … 408 401 * @since 6.1.0 409 402 * 410 * @param array$style_value A single raw style value from $block_styles array.403 * @param mixed $style_value A single raw style value from $block_styles array. 411 404 * @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA. 412 405 * @param array $options { 413 406 * Optional. An array of options. Default empty array. 414 407 * 415 * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`. 408 * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., 409 * `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to `var( --wp--preset--* )` values. 410 * Default false. 416 411 * } 417 * 418 * @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ). 412 * @return string[] An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`. 419 413 */ 420 414 protected static function get_css_declarations( $style_value, $style_definition, $options = array() ) { … … 474 468 * Style value parser that returns a CSS definition array comprising style properties 475 469 * that have keys representing individual style properties, otherwise known as longhand CSS properties. 476 * e.g., "$style_property-$individual_feature: $value;", which could represent the following: 477 * "border-{top|right|bottom|left}-{color|width|style}: {value};" or, 478 * "border-image-{outset|source|width|repeat|slice}: {value};" 479 * 480 * @since 6.1.0 481 * 482 * @param array $style_value A single raw style value from $block_styles array. 470 * 471 * Example: 472 * 473 * "$style_property-$individual_feature: $value;" 474 * 475 * Which could represent the following: 476 * 477 * "border-{top|right|bottom|left}-{color|width|style}: {value};" 478 * 479 * or: 480 * 481 * "border-image-{outset|source|width|repeat|slice}: {value};" 482 * 483 * @since 6.1.0 484 * 485 * @param array $style_value A single raw style value from `$block_styles` array. 483 486 * @param array $individual_property_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA representing an individual property of a CSS property, e.g., 'top' in 'border-top'. 484 487 * @param array $options { 485 488 * Optional. An array of options. Default empty array. 486 489 * 487 * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to var( --wp--preset--* ) values. Default `false`.490 * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, e.g., `var:preset|<PRESET_TYPE>|<PRESET_SLUG>`, to `var( --wp--preset--* )` values. Default false. 488 491 * } 489 * 490 * @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ). 492 * @return string[] An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`. 491 493 */ 492 494 protected static function get_individual_property_css_declarations( $style_value, $individual_property_definition, $options = array() ) { … … 527 529 528 530 /** 529 * Returns compiled CSS from css_declarations.530 * 531 * @since 6.1.0 532 * 533 * @param string[] $css_declarations An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).531 * Returns compiled CSS from CSS declarations. 532 * 533 * @since 6.1.0 534 * 535 * @param string[] $css_declarations An associative array of CSS definitions, e.g., `array( "$property" => "$value", "$property" => "$value" )`. 534 536 * @param string $css_selector When a selector is passed, the function will return a full CSS rule `$selector { ...rules }`, otherwise a concatenated string of properties and values. 535 *536 537 * @return string A compiled CSS string. 537 538 */ … … 560 561 * Optional. An array of options. Default empty array. 561 562 * 562 * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`. 563 * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined. 563 * @type string|null $context An identifier describing the origin of the style object, e.g., 'block-supports' or 'global-styles'. Default is 'block-supports'. 564 * When set, the style engine will attempt to store the CSS rules. 565 * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules. Default is `false`. 566 * @type bool $prettify Whether to add new lines and indents to output. Default is the test of whether the global constant `SCRIPT_DEBUG` is defined. 564 567 * } 565 *566 568 * @return string A compiled stylesheet from stored CSS rules. 567 569 */
Note: See TracChangeset
for help on using the changeset viewer.