API / Minn\Theme / GlobalStyles

GlobalStyles final readonly class

Minn\Theme\GlobalStyles · public/minn/src/Minn/Theme/GlobalStyles.php · 547 lines

theme.json to CSS. Presets become custom properties on :root and their has-* utility classes; settings.layout sizes, root styles, elements, and per-block styles become rules; the containers, galleries, and style variations the page actually rendered get their own stylesheets. The layout rules themselves (flow, constrained, flex, grid, alignments) are the engine's own, written to the same class hooks.

Constants and properties

constELEMENT_SELECTORS = array ( 'link' => 'a:where(:not(.wp-element-button))', 'heading' => 'h1, h2, h3, h4, h5, h6', 'h1' => 'h1', 'h2' => 'h2', 'h3' => 'h3', 'h4' => 'h4', 'h5' => 'h5', 'h6' => 'h6', 'button' => '.wp-element-button, .wp-block-button__link', 'caption' => '.wp-element-caption, .wp-block-audio figcaption, .wp-block-embed figcaption, .wp-block-gallery figcaption, .wp-block-image figcaption, .wp-block-table figcaption, .wp-block-video figcaption', 'cite' => 'cite', )

Element selectors in the order the reference prints them, whatever order theme.json or the saved styles list them in: the heading group lands before the individual levels, so an h1 line-height beats the group's. Themes list h1..h6 before heading and would otherwise win.

privateBLOCK_SELECTORS = array ( 'core/paragraph' => 'p', 'core/list-item' => '.wp-block-list > li', 'core/button' => '.wp-block-button .wp-block-button__link', 'core/table' => '.wp-block-table > table', 'core/icon' => '.wp-block-icon svg', )

Blocks whose metadata names a root selector other than .wp-block-{slug}.

privateSTYLESHEET_LESS = array ( 0 => 'core/block', 1 => 'core/column', 2 => 'core/comments-pagination-next', 3 => 'core/comments-pagination-numbers', 4 => 'core/comments-pagination-previous', 5 => 'core/comments-title', 6 => 'core/freeform', 7 => 'core/home-link', 8 => 'core/html', 9 => 'core/legacy-widget', 10 => 'core/list-item', 11 => 'core/missing', 12 => 'core/more', 13 => 'core/navigation-submenu', 14 => 'core/nextpage', 15 => 'core/page-list-item', 16 => 'core/pattern', 17 => 'core/query-no-results', 18 => 'core/query-pagination-next', 19 => 'core/query-pagination-numbers', 20 => 'core/query-pagination-previous', 21 => 'core/query', 22 => 'core/shortcode', 23 => 'core/social-link', 24 => 'core/tab-panels', 25 => 'core/template-part', 26 => 'core/terms-query', 27 => 'core/widget-group', )

The reference prints a core block's theme.json styles only when the page rendered the block with output (a generated excerpt counts), and attaches them to the block's own stylesheet; these core blocks have none, so their styles never reach a page. A block from outside core has no such stylesheet to wait for, so its styles always print.

privatereadonly Minn\Theme\Theme $theme

Promoted from the constructor.

privatereadonly ?array $user

Promoted from the constructor.

Public

new__construct(Minn\Theme\Theme $theme, ?array $user = NULL)#
$userarray|nullthe site editor's saved global styles, layered over the theme
methodstyles(): array#

The theme.json (plus site-editor) styles node, under the engine's own defaults.

methodresolvedStyles(): array#

The same node with every `var:preset|…` token resolved to the custom property it names, which is the shape a caller reading the styles as data expects (the CSS writer resolves them on the way out instead).

methodcss(): string#

The global stylesheet from theme.json and the user's styles, as a page prints it: only the core blocks it rendered.

methodstylesheet(array $types): string#

The stylesheet wp_get_global_stylesheet answers (probe editor-styles), by type: the custom properties, the styles (every block's, rendered or not), the preset classes; in that order.

$typeslist<string>
methodfontFaces(): string#

The @font-face rules for every family that declares font files (Theme\FontFaces), with file:./ resolved against the theme that carries the file. The page prints them through wp_print_font_faces on wp_head; the editor's styles read them here.

staticrootRules(bool $aware): string#

The body's margin, the global padding rules under root-padding-aware alignments, and the site's alignments.

staticblockGapRules(string $gap): string#

The block gap between the site's blocks and inside every layout.

staticlayoutRules(): string#

The layouts' own rules: alignments inside flow and constrained layouts, the content and wide sizes, flex and grid.

staticgapRules(string $prefix, string $gap): string#

The block-gap rules for a layout scope: "" for the root, or a block's -is-layout- prefix.

staticelementStyles(array $elements, string $scope): string#

The element rules (links, headings, buttons, captions, citations), each state after it; under a block's selector when one is given.

staticblockStyles(string $name, array $blockStyles, string $scope = ''): string#

A block's rules: its root rule, its layout gap rules, then a rule for each feature its metadata gives a selector of its own (the avatar's border on its image), its own CSS and its elements (probe editor-styles).

staticscoped(string $selector, string $scope): string#

Each selector in a list under the scope ("" for none).

staticrootSelector(string $name): string#

A block's root selector: its metadata's, the reference's own for a few core blocks, else .wp-block-{slug}.

staticselectorsOf(string $name): array#

A core block's selectors from its metadata. @return array<string, mixed>

@return array<string, mixed>
staticbyFeature(array $styles, array $selectors): array#

A block's styles split between its root selector and the features (or a feature's single properties) its metadata selects elsewhere.

$stylesarray<string, mixed>
$selectorsarray<string, mixed>
@return array{0: array<string, mixed>, 1: array<string, array<string, mixed>>}
staticvariationCss(string $name, string $style, int $instance, array $variation): string#

A numbered style variation's CSS (probe block-supports): its element rules scoped by the numbered class alone, then the variation on the block's root selector (the class riding on the block's own class: .wp-block-button.is-style-outline--3 .wp-block-button__link), its own CSS, and the blocks styled inside it.

staticdeclarations(array $styles, array $skip): array#

theme.json style properties to declarations: color, typography, spacing, border, shadow, dimensions, outline.

@return list<string>

Internals 8

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

privatejson(): array#

The theme's theme.json with the site editor's styles over it, those as wp_theme_json_data_user leaves them (a plugin may add a layer where the site editor saved none).

@return array<string, mixed>
privateparts(): array#
@return array{variables: string, base: string, presets: string, blocks: array<string, mixed>}
privatefontUrl(string $src): ?string#
privaterootStyles(array $styles): string#

Root styles land on body. With root-padding-aware alignments the root padding is NOT applied to body; it becomes the custom properties the has-global-padding rules read.

privateblockCustomProperties(array $blocks): string#

Each block's own settings.custom as custom properties on the block's root selector. @param array<string, mixed> $blocks

$blocksarray<string, mixed>
privatewithoutEmpty(array $styles): array#
privatecontainerStyles(): string#

The page's block-support rules (layouts, element styles, and the rest), which the facade keeps in the style engine's block-supports store.

privateordered(array $declarations): array#

The reference prints declarations in its own fixed property order: alphabetical, except that the sides of a margin or padding run top, right, bottom, left.

$declarationslist<string>
@return list<string>