inner markup of a 24x24 stroke icon.
*
* Deliberately geometry only: no fill, no colour, no width, no height. The
* wrapper in svg() owns every one of those, so a path can never carry
* styling of its own.
*/
const ICONS = array(
'trend-up' => '',
'check' => '',
'star' => '',
'lightbulb' => '',
'quote' => '',
'info' => '',
'target' => '',
'clock' => '',
'arrow-right'=> '',
'download' => '',
'calendar' => '',
'sparkle' => '',
);
/** Default icon per content type, used when none is specified. */
const DEFAULTS = array(
'metric' => 'trend-up',
'takeaway' => 'lightbulb',
'checklist' => 'check',
'quote' => 'quote',
'cta' => 'arrow-right',
);
/**
* Decorative background shapes.
*
* These are what stop a block reading as a bootstrap panel: a soft arc
* behind a number, a dot field behind a quote. They carry no meaning, sit
* behind the content at low opacity, and are clipped by the block's own
* overflow, so they can never push text around or overflow on a phone.
*
* Drawn on a 100x100 grid and stretched with preserveAspectRatio="none",
* because a decorative wash should fill whatever box it is given rather
* than keeping its proportions.
*
* Same rule as the icons: the AI selects one by name and can never supply
* geometry.
*/
const SHAPES = array(
'arc' => '',
'blob' => '',
'dots' => '',
'rings' => '',
'grid' => '',
'wedge' => '',
);
/**
* Render a decorative shape.
*
* Always aria-hidden. It is wallpaper, and a screen reader announcing it
* would be announcing nothing.
*
* @param string $name Shape name. Unknown names render nothing.
* @return string
*/
public static function shape( $name ) {
if ( ! is_string( $name ) || ! isset( self::SHAPES[ $name ] ) ) {
return '';
}
return '';
}
/**
* Every shape name, for the editor picker and for validating AI output.
*
* @return string[]
*/
public static function shape_names() {
return array_keys( self::SHAPES );
}
/**
* Whether an icon name is one we can draw.
*
* @param string $name Icon name.
* @return bool
*/
public static function exists( $name ) {
return is_string( $name ) && isset( self::ICONS[ $name ] );
}
/**
* Every icon name, for the editor's picker and for validating AI output.
*
* @return string[]
*/
public static function names() {
return array_keys( self::ICONS );
}
/**
* Resolve a requested icon to something drawable.
*
* @param string $name Requested name; may be empty or unknown.
* @param string $content_type Content type, used to pick a sensible default.
* @return string A valid icon name, or '' when there is no sensible default.
*/
public static function resolve( $name, $content_type = '' ) {
if ( self::exists( $name ) ) {
return $name;
}
$fallback = self::DEFAULTS[ $content_type ] ?? '';
return self::exists( $fallback ) ? $fallback : '';
}
/**
* Render an icon as inline SVG.
*
* Always decorative: the surrounding block carries the real text, so the
* icon is hidden from assistive technology rather than given a label
* screen-reader users would hear twice.
*
* @param string $name Icon name. Unknown names render nothing.
* @return string SVG markup, or '' when the name is unknown.
*/
public static function svg( $name ) {
if ( ! self::exists( $name ) ) {
return '';
}
return '';
}
}