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
| private | ORIGINS = array ( 0 => 'default', 1 => 'blocks', 2 => 'theme', 3 => 'custom', ) | |
| private | KINDS = 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. |
| private | readonly array $tree | Promoted from the constructor. |
Public
| new | __construct(array $tree)# |
| |||||||||
| method | stylesheet(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.
| |||||||||
| method | variables(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.
| |||||||||
| method | variablesOf(array $settings, array $origins, string $selector): string# | One settings node's custom properties under its selector; nothing when it has none.
| |||||||||
| method | presetClasses(array $origins, string $scope): string# | The has-* classes: the root's bare, each block's under :where(its settings selector).
| |||||||||
| method | classesOf(array $settings, array $origins, string $selector): string# | One settings node's has-* classes, under :where(selector) unless it is the bare :root.
| |||||||||
| method | styles(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.
| |||||||||
| method | rootLayoutRules(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. | |||||||||
| method | layoutStyles(): 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. | |||||||||
| method | rootStyles(string $selector): string# | The root's own rule: body as it is, any other root under :root :where(). | |||||||||
| method | blockStyles(string $name, string $scope = ''): string# | One block's rules; its own block gap only when the tree turns block gaps on. | |||||||||
| method | blockOwnStyles(string $name): string# | One block's own rules, its elements left out: each element is a style node of its own. | |||||||||
| method | blockElements(string $name): array# | The elements a block styles, in the order they print. @return list<string> | |||||||||
| method | elementStyles(string $element, string $block = ''): string# | One element's rules, under a block's selector when it belongs to one. | |||||||||
| method | customCss(): string# | The tree's own top-level CSS, as written. | |||||||||
| static | settingsSelector(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.
| private | blockGap(): ?string# | The block gap: the styles' value when the tree's settings turn block gaps on, else null. | ||||||
| private | presets(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.
@return array<string, list<array{slug: string, value: string}>> |
Nothing matches.