[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp-duotone.php (summary)

WP_Duotone class Parts of this source were derived and modified from colord, released under the MIT license.

File Size: 1342 lines (41 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Duotone:: (38 methods):
  colord_clamp()
  colord_clamp_hue()
  colord_parse_hue()
  colord_parse_hex()
  colord_clamp_rgba()
  colord_parse_rgba_string()
  colord_clamp_hsla()
  colord_hsva_to_rgba()
  colord_hsla_to_hsva()
  colord_hsla_to_rgba()
  colord_parse_hsla_string()
  colord_parse()
  get_slug_from_attribute()
  is_preset()
  get_css_custom_property_name()
  get_filter_id()
  get_css_var()
  get_filter_url()
  get_filter_svg()
  get_filter_id_from_preset()
  get_filter_svg_from_preset()
  get_svg_definitions()
  get_global_styles_presets()
  enqueue_block_css()
  enqueue_custom_filter()
  enqueue_global_styles_preset()
  register_duotone_support()
  get_selector()
  get_all_global_styles_presets()
  get_all_global_style_block_names()
  render_duotone_support()
  restore_image_outer_container()
  output_block_styles()
  output_global_styles()
  output_footer_assets()
  add_editor_settings()
  migrate_experimental_duotone_support_flag()
  get_filter_css_property_value_from_preset()


Class: WP_Duotone  - X-Ref

Manages duotone block supports and global styles.

colord_clamp( $number, $min = 0, $max = 1 )   X-Ref
Clamps a value between an upper and lower bound.

Direct port of colord's clamp function.

param: float $number The number to clamp.
param: float $min    The minimum value.
param: float $max    The maximum value.
return: float The clamped value.

colord_clamp_hue( $degrees )   X-Ref
Processes and clamps a degree (angle) value properly.

Direct port of colord's clampHue function.

param: float $degrees The hue to clamp.
return: float The clamped hue.

colord_parse_hue( $value, $unit = 'deg' )   X-Ref
Converts a hue value to degrees from 0 to 360 inclusive.

Direct port of colord's parseHue function.

param: float  $value The hue value to parse.
param: string $unit  The unit of the hue value.
return: float The parsed hue value.

colord_parse_hex( $hex )   X-Ref
Parses any valid Hex3, Hex4, Hex6 or Hex8 string and converts it to an RGBA object.

Direct port of colord's parseHex function.

param: string $hex The hex string to parse.
return: array|null An array of RGBA values or null if the hex string is invalid.

colord_clamp_rgba( $rgba )   X-Ref
Clamps an array of RGBA values.

Direct port of colord's clampRgba function.

param: array $rgba The RGBA array to clamp.
return: array The clamped RGBA array.

colord_parse_rgba_string( $input )   X-Ref
Parses a valid RGB[A] CSS color function/string.

Direct port of colord's parseRgbaString function.

param: string $input The RGBA string to parse.
return: array|null An array of RGBA values or null if the RGB string is invalid.

colord_clamp_hsla( $hsla )   X-Ref
Clamps an array of HSLA values.

Direct port of colord's clampHsla function.

param: array $hsla The HSLA array to clamp.
return: array The clamped HSLA array.

colord_hsva_to_rgba( $hsva )   X-Ref
Converts an HSVA array to RGBA.

Direct port of colord's hsvaToRgba function.

param: array $hsva The HSVA array to convert.
return: array The RGBA array.

colord_hsla_to_hsva( $hsla )   X-Ref
Converts an HSLA array to HSVA.

Direct port of colord's hslaToHsva function.

param: array $hsla The HSLA array to convert.
return: array The HSVA array.

colord_hsla_to_rgba( $hsla )   X-Ref
Converts an HSLA array to RGBA.

Direct port of colord's hslaToRgba function.

param: array $hsla The HSLA array to convert.
return: array The RGBA array.

colord_parse_hsla_string( $input )   X-Ref
Parses a valid HSL[A] CSS color function/string.

Direct port of colord's parseHslaString function.

param: string $input The HSLA string to parse.
return: array|null An array of RGBA values or null if the RGB string is invalid.

colord_parse( $input )   X-Ref
Tries to convert an incoming string into RGBA values.

Direct port of colord's parse function simplified for our use case. This
version only supports string parsing and only returns RGBA values.

param: string $input The string to parse.
return: array|null An array of RGBA values or null if the string is invalid.

get_slug_from_attribute( $duotone_attr )   X-Ref
Takes the inline CSS duotone variable from a block and return the slug.

Handles styles slugs like:
var:preset|duotone|blue-orange
var(--wp--preset--duotone--blue-orange)

param: string $duotone_attr The duotone attribute from a block.
return: string The slug of the duotone preset or an empty string if no slug is found.

is_preset( $duotone_attr )   X-Ref
Checks if we have a valid duotone preset.

Valid presets are defined in the $global_styles_presets array.

param: string $duotone_attr The duotone attribute from a block.
return: bool True if the duotone preset present and valid.

get_css_custom_property_name( $slug )   X-Ref
Gets the CSS variable name for a duotone preset.

Example output:
--wp--preset--duotone--blue-orange

param: string $slug The slug of the duotone preset.
return: string The CSS variable name.

get_filter_id( $slug )   X-Ref
Get the ID of the duotone filter.

Example output:
wp-duotone-blue-orange

param: string $slug The slug of the duotone preset.
return: string The ID of the duotone filter.

get_css_var( $slug )   X-Ref
Get the CSS variable for a duotone preset.

Example output:
var(--wp--preset--duotone--blue-orange)

param: string $slug The slug of the duotone preset.
return: string The CSS variable.

get_filter_url( $filter_id )   X-Ref
Get the URL for a duotone filter.

Example output:
url(#wp-duotone-blue-orange)

param: string $filter_id The ID of the filter.
return: string The URL for the duotone filter.

get_filter_svg( $filter_id, $colors )   X-Ref
Gets the SVG for the duotone filter definition.

Whitespace is removed when SCRIPT_DEBUG is not enabled.

param: string $filter_id The ID of the filter.
param: array  $colors    An array of color strings.
return: string An SVG with a duotone filter definition.

get_filter_id_from_preset( $preset )   X-Ref
Returns the prefixed id for the duotone filter for use as a CSS id.

Exported for the deprecated function wp_get_duotone_filter_id().

param: array $preset Duotone preset value as seen in theme.json.
return: string        Duotone filter CSS id.

get_filter_svg_from_preset( $preset )   X-Ref
Gets the SVG for the duotone filter definition from a preset.

Exported for the deprecated function wp_get_duotone_filter_property().

param: array $preset The duotone preset.
return: string The SVG for the filter definition.

get_svg_definitions( $sources )   X-Ref
Get the SVGs for the duotone filters.

Example output:
<svg><defs><filter id="wp-duotone-blue-orange">…</filter></defs></svg><svg>…</svg>

param: array $sources The duotone presets.
return: string The SVGs for the duotone filters.

get_global_styles_presets( $sources )   X-Ref
Get the CSS for global styles.

Example output:
body{--wp--preset--duotone--blue-orange:url('#wp-duotone-blue-orange');}

param: array $sources The duotone presets.
return: string The CSS for global styles.

enqueue_block_css( $filter_id, $duotone_selector, $filter_value )   X-Ref
Enqueue a block CSS declaration for the page.

This does not include any SVGs.

param: string $filter_id        The filter ID. e.g. 'wp-duotone-000000-ffffff-2'.
param: string $duotone_selector The block's duotone selector. e.g. '.wp-block-image img'.
param: string $filter_value     The filter CSS value. e.g. 'url(#wp-duotone-000000-ffffff-2)' or 'unset'.

enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, $filter_data )   X-Ref
Enqueue custom filter assets for the page.

Includes an SVG filter and block CSS declaration.

param: string $filter_id        The filter ID. e.g. 'wp-duotone-000000-ffffff-2'.
param: string $duotone_selector The block's duotone selector. e.g. '.wp-block-image img'.
param: string $filter_value     The filter CSS value. e.g. 'url(#wp-duotone-000000-ffffff-2)' or 'unset'.
param: array  $filter_data      Duotone filter data with 'slug' and 'colors' keys.

enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value )   X-Ref
Enqueue preset assets for the page.

Includes a CSS custom property, SVG filter, and block CSS declaration.

param: string $filter_id        The filter ID. e.g. 'wp-duotone-blue-orange'.
param: string $duotone_selector The block's duotone selector. e.g. '.wp-block-image img'.
param: string $filter_value     The filter CSS value. e.g. 'url(#wp-duotone-blue-orange)' or 'unset'.

register_duotone_support( $block_type )   X-Ref
Registers the style and colors block attributes for block types that support it.

Block support is added with `supports.filter.duotone` in block.json.

param: WP_Block_Type $block_type Block Type.

get_selector( $block_type )   X-Ref
Get the CSS selector for a block type.

This handles selectors defined in `color.__experimentalDuotone` support
if `filter.duotone` support is not defined.

param: WP_Block_Type $block_type Block type to check for support.
return: string|null The CSS selector or null if there is no support.

get_all_global_styles_presets()   X-Ref
Scrape all possible duotone presets from global and theme styles and
store them in self::$global_styles_presets.

Used in conjunction with self::render_duotone_support for blocks that
use duotone preset filters.

return: array An array of global styles presets, keyed on the filter ID.

get_all_global_style_block_names()   X-Ref
Scrape all block names from global styles and store in self::$global_styles_block_names.

Used in conjunction with self::render_duotone_support to output the
duotone filters defined in the theme.json global styles.

return: string[] An array of global style block slugs, keyed on the block name.

render_duotone_support( $block_content, $block, $wp_block )   X-Ref
Render out the duotone CSS styles and SVG.

The hooks self::set_global_style_block_names and self::set_global_styles_presets
must be called before this function.

param: string   $block_content Rendered block content.
param: array    $block         Block object.
param: WP_Block $wp_block      The block instance.
return: string Filtered block content.

restore_image_outer_container( $block_content )   X-Ref
Fixes the issue with our generated class name not being added to the block's outer container
in classic themes due to gutenberg_restore_image_outer_container from layout block supports.

param: string $block_content Rendered block content.
return: string Filtered block content.

output_block_styles()   X-Ref
Appends the used block duotone filter declarations to the inline block supports CSS.

Uses the declarations saved in earlier calls to self::enqueue_block_css.


output_global_styles()   X-Ref
Appends the used global style duotone filter presets (CSS custom
properties) to the inline global styles CSS.

Uses the declarations saved in earlier calls to self::enqueue_global_styles_preset.


output_footer_assets()   X-Ref
Outputs all necessary SVG for duotone filters, CSS for classic themes.

Uses the declarations saved in earlier calls to self::enqueue_global_styles_preset
and self::enqueue_custom_filter.


add_editor_settings( $settings )   X-Ref
Adds the duotone SVGs and CSS custom properties to the editor settings.

This allows the properties to be pulled in by the EditorStyles component
in JS and rendered in the post editor.

param: array $settings The block editor settings from the `block_editor_settings_all` filter.
return: array The editor settings with duotone SVGs and CSS custom properties.

migrate_experimental_duotone_support_flag( $settings, $metadata )   X-Ref
Migrates the experimental duotone support flag to the stabilized location.

This moves `supports.color.__experimentalDuotone` to `supports.filter.duotone`.

param: array $settings Current block type settings.
param: array $metadata Block metadata as read in via block.json.
return: array Filtered block type settings.

get_filter_css_property_value_from_preset( $preset )   X-Ref
Gets the CSS filter property value from a preset.

Exported for the deprecated function wp_get_duotone_filter_id().

param: array $preset The duotone preset.
return: string The CSS filter property value.



Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref