API / Minn\Theme / TreeStyles

TreeStyles final readonly class

Minn\Theme\TreeStyles · public/minn/src/Minn/Theme/TreeStyles.php · 259 lines

The CSS one theme.json tree writes, as WP_Theme_JSON keeps the tree (presets keyed by origin): its custom properties, its preset classes, its styles (the root layout, the root, elements, blocks) and its own CSS, by type, origin and option (probe theme-json-css). The rules are GlobalStyles'; what the page's writer takes for granted is read from the tree instead: block gaps only when the tree turns them on, the root padding only on the sides it gives, and none of the engine's own defaults.

Constants and properties

privateORIGINS = array ( 0 => 'default', 1 => 'blocks', 2 => 'theme', 3 => 'custom', )
privateKINDS = array ( 'aspect-ratio' => array ( 0 => array ( 0 => 'dimensions', 1 => 'aspectRatios', ), 1 => 'ratio', ), 'color' => array ( 0 => array ( 0 => 'color', 1 => 'palette', ), 1 => 'color', ), 'gradient' => array ( 0 => array ( 0 => 'color', 1 => 'gradients', ), 1 => 'gradient', ), 'font-size' => array ( 0 => array ( 0 => 'typography', 1 => 'fontSizes', ), 1 => 'size', ), 'font-family' => array ( 0 => array ( 0 => 'typography', 1 => 'fontFamilies', ), 1 => 'fontFamily', ), 'spacing' => array ( 0 => array ( 0 => 'spacing', 1 => 'spacingSizes', ), 1 => 'size', ), 'shadow' => array ( 0 => array ( 0 => 'shadow', 1 => 'presets', ), 1 => 'shadow', ), 'border-radius' => array ( 0 => array ( 0 => 'border', 1 => 'radiusSizes', ), 1 => 'size', ), 'dimension' => array ( 0 => array ( 0 => 'dimensions', 1 => 'dimensionSizes', ), 1 => 'size', ), )

Preset kinds in the order they print: where each sits under settings, and the key holding its value.

privatereadonly array $tree

Promoted from the constructor.

Public

new__construct(array $tree)#
$treearray<string, mixed>
methodstylesheet(array $types, array $origins, array $options): string#

The stylesheet for the types asked for, in the order variables, styles, presets, the tree's own CSS; origins narrow the presets.

$typeslist<string>
$originslist<string>
$optionsarray<string, mixed>root_selector, scope, skip_root_layout_styles
methodvariables(array $origins, string $scope): string#

The presets and settings.custom as custom properties: on :root, then on each block's settings selector that has its own.

$originslist<string>
methodvariablesOf(array $settings, array $origins, string $selector): string#

One settings node's custom properties under its selector; nothing when it has none.

$settingsarray<string, mixed>
$originslist<string>
methodpresetClasses(array $origins, string $scope): string#

The has-* classes: the root's bare, each block's under :where(its settings selector).

$originslist<string>
methodclassesOf(array $settings, array $origins, string $selector): string#

One settings node's has-* classes, under :where(selector) unless it is the bare :root.

$settingsarray<string, mixed>
$originslist<string>
methodstyles(array $options): string#

The styles: the root layout (unless skip_root_layout_styles), the root's own rule, its CSS when the root is not body, the elements, then each block; under the root_selector and scope options.

$optionsarray<string, mixed>
methodrootLayoutRules(string $selector): string#

The root layout: the content and wide sizes, the body's margin, the global padding rules, the alignments; for body, the block gap (or the fallback gap of flex and grid) and the layouts' own rules.

methodlayoutStyles(): string#

The block gap and the layouts' own rules; flex and grid fall back to a 0.5em gap when the tree has no block gap.

methodrootStyles(string $selector): string#

The root's own rule: body as it is, any other root under :root :where().

methodblockStyles(string $name, string $scope = ''): string#

One block's rules; its own block gap only when the tree turns block gaps on.

methodblockOwnStyles(string $name): string#

One block's own rules, its elements left out: each element is a style node of its own.

methodblockElements(string $name): array#

The elements a block styles, in the order they print.

@return list<string>
methodelementStyles(string $element, string $block = ''): string#

One element's rules, under a block's selector when it belongs to one.

methodcustomCss(): string#

The tree's own top-level CSS, as written.

staticsettingsSelector(string $name): string#

A block's settings selector: its experimental selector when it has one, else .wp-block-{slug}.

Internals 2

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateblockGap(): ?string#

The block gap: the styles' value when the tree's settings turn block gaps on, else null.

privatepresets(array $settings, array $origins): array#

A settings node's presets by kind, the origins asked for in order, one per slug; a font size is written fluid by the root's typography settings.

$settingsarray<string, mixed>
$originslist<string>
@return array<string, list<array{slug: string, value: string}>>