API / Minn\Theme / StylePresets

StylePresets final class

Minn\Theme\StylePresets · public/minn/src/Minn/Theme/StylePresets.php · 160 lines

The preset side of theme.json: the colour, gradient, font-size, font-family, spacing, and shadow lists a theme declares over core's own, as the custom properties on :root and the has-* utility classes the reference prints for them. Pure: settings in, CSS fragments out.

Constants and properties

constMETADATA = array ( 0 => array ( 'path' => array ( 0 => 'dimensions', 1 => 'aspectRatios', ), 'prevent_override' => array ( 0 => 'dimensions', 1 => 'defaultAspectRatios', ), 'use_default_names' => false, 'value_key' => 'ratio', 'css_vars' => '--wp--preset--aspect-ratio--$slug', 'classes' => array ( ), 'properties' => array ( 0 => 'aspect-ratio', ), ), 1 => array ( 'path' => array ( 0 => 'color', 1 => 'palette', ), 'prevent_override' => array ( 0 => 'color', 1 => 'defaultPalette', ), 'use_default_names' => false, 'value_key' => 'color', 'css_vars' => '--wp--preset--color--$slug', 'classes' => array ( '.has-$slug-color' => 'color', '.has-$slug-background-color' => 'background-color', '.has-$slug-border-color' => 'border-color', ), 'properties' => array ( 0 => 'color', 1 => 'background-color', 2 => 'border-color', ), ), 2 => array ( 'path' => array ( 0 => 'color', 1 => 'gradients', ), 'prevent_override' => array ( 0 => 'color', 1 => 'defaultGradients', ), 'use_default_names' => false, 'value_key' => 'gradient', 'css_vars' => '--wp--preset--gradient--$slug', 'classes' => array ( '.has-$slug-gradient-background' => 'background', ), 'properties' => array ( 0 => 'background', ), ), 3 => array ( 'path' => array ( 0 => 'color', 1 => 'duotone', ), 'prevent_override' => array ( 0 => 'color', 1 => 'defaultDuotone', ), 'use_default_names' => false, 'value_func' => NULL, 'css_vars' => NULL, 'classes' => array ( ), 'properties' => array ( 0 => 'filter', ), ), 4 => array ( 'path' => array ( 0 => 'typography', 1 => 'fontSizes', ), 'prevent_override' => array ( 0 => 'typography', 1 => 'defaultFontSizes', ), 'use_default_names' => true, 'value_func' => 'wp_get_typography_font_size_value', 'css_vars' => '--wp--preset--font-size--$slug', 'classes' => array ( '.has-$slug-font-size' => 'font-size', ), 'properties' => array ( 0 => 'font-size', ), ), 5 => array ( 'path' => array ( 0 => 'typography', 1 => 'fontFamilies', ), 'prevent_override' => false, 'use_default_names' => false, 'value_key' => 'fontFamily', 'css_vars' => '--wp--preset--font-family--$slug', 'classes' => array ( '.has-$slug-font-family' => 'font-family', ), 'properties' => array ( 0 => 'font-family', ), ), 6 => array ( 'path' => array ( 0 => 'spacing', 1 => 'spacingSizes', ), 'prevent_override' => array ( 0 => 'spacing', 1 => 'defaultSpacingSizes', ), 'use_default_names' => true, 'value_key' => 'size', 'css_vars' => '--wp--preset--spacing--$slug', 'classes' => array ( ), 'properties' => array ( 0 => 'padding', 1 => 'margin', ), ), 7 => array ( 'path' => array ( 0 => 'shadow', 1 => 'presets', ), 'prevent_override' => array ( 0 => 'shadow', 1 => 'defaultPresets', ), 'use_default_names' => false, 'value_key' => 'shadow', 'css_vars' => '--wp--preset--shadow--$slug', 'classes' => array ( ), 'properties' => array ( 0 => 'box-shadow', ), ), 8 => array ( 'path' => array ( 0 => 'border', 1 => 'radiusSizes', ), 'prevent_override' => false, 'use_default_names' => false, 'value_key' => 'size', 'css_vars' => '--wp--preset--border-radius--$slug', 'classes' => array ( ), 'properties' => array ( 0 => 'border-radius', ), ), 9 => array ( 'path' => array ( 0 => 'dimensions', 1 => 'dimensionSizes', ), 'prevent_override' => false, 'use_default_names' => false, 'value_key' => 'size', 'css_vars' => '--wp--preset--dimension--$slug', 'classes' => array ( ), 'properties' => array ( 0 => 'width', 1 => 'height', 2 => 'min-height', ), ), )

Each preset list theme.json may hold: where it sits, what overrides the defaults, its value, custom property, classes and CSS properties (WP_Theme_JSON::PRESETS_METADATA).

Public

staticpresets(array $settings, ?array $core = NULL): array#

Every preset list the theme declares, over core's own (as given, else data/presets.json), keyed by kind.

staticpresetList(mixed $presets): array#

A preset list as theme.json writes it is a plain list; as the site editor saves it, it is keyed by origin (default, theme, custom). The reference prints the origins in that order, so the two shapes flatten to one list here.

@return list<array>
staticfontFamilies(array $settings): array#

The font family presets in the settings.

@return list<array>
staticpresetProperties(array $presets): string#

The presets as custom properties for :root.

staticcustomProperties(array $custom, string $prefix = '--wp--custom--'): string#

A settings.custom tree as custom properties: --wp--custom-- and the path to each value, every key in kebab case, lists by index; empty values are left out.

$customarray<array-key, mixed>
staticpresetClasses(array $presets, string $prefix = ''): string#

The has-* utility classes the presets give every colour, gradient, font size, and font family; each under the prefix given (a block's :where(selector)).

staticfontSizes(array $defaults, array $own, array $settings): array#

Core's font sizes, always printed, then the theme's: a theme size with one of core's slugs takes its place when defaultFontSizes is false, and gives way to core's while core's are kept (probe default-presets).

$defaultslist<array{slug: string, value: string}>core's, as data/presets.json holds them
$ownlist<array>the theme's (and the site editor's) presets
$settingsarray<string, mixed>the theme's settings, which say whether core's are kept
@return list<array>
staticspacingPresets(array $defaults, array $own): array#

The default spacing scale (20 to 80) is always present, whatever defaultSpacingSizes says; a theme size with the same slug replaces the default in place, and the theme's other sizes follow the scale.

@return list<array{slug: string, value: string}>
staticfluidFontSize(array $preset, array $settings): string#

A font size preset as the global stylesheet writes it: fluid by the theme's settings (Typography::fontSize).