API / Minn\Blocks / LayoutStyle

LayoutStyle final class

Minn\Blocks\LayoutStyle · public/minn/src/Minn/Blocks/LayoutStyle.php · 193 lines

The CSS rules a block's layout writes (wp_get_layout_style, probe block-supports), as selector => declarations pairs the style engine turns into a stylesheet:

- flow: only the gap between children (none, then the gap, on each); - constrained: the content width on the children that are not aligned left, right or full, the wide width on wide ones, no limit on full ones (justifyContent pushes the children to a side: both margins with a width, the one side alone without), negative margins on full ones for a block with side padding, then the children's gap; - flex: nowrap, the gap, then the direction and alignments the orientation reads from justifyContent and verticalAlignment; - grid: the column template (a count, a minimum width, or both folded together with the gap, or the fallback gap without one), then the gap.

Widths arrive checked (one dropped as unsafe is empty) and gaps with presets turned into custom properties.

Used by 1

Constants and properties

privateJUSTIFY = array ( 'left' => 'flex-start', 'right' => 'flex-end', 'center' => 'center', 'stretch' => 'stretch', 'space-between' => 'space-between', )
privateALIGN = array ( 'top' => 'flex-start', 'center' => 'center', 'bottom' => 'flex-end', 'stretch' => 'stretch', 'space-between' => 'space-between', )
privateCHILD_KEYS = array ( 0 => 'selfStretch', 1 => 'flexSize', 2 => 'columnSpan', 3 => 'rowSpan', 4 => 'columnStart', 5 => 'rowStart', )

Public

staticrules(string $selector, array $layout, array|string|null $gap, array $padding = array ( ), string $fallbackGap = '0.5em'): array#

The rules for a container.

$layoutarray<string, mixed>the layout, its widths checked
$gapstring|array<string, string>|nullthe block gap (a value, or top and left), null when it is not written
$paddingarray<string, string>the block's own padding (left, right), for full-width children
$fallbackGapstringthe gap a grid with a minimum column width counts when the block writes none
@return list<array{selector: string, declarations: array<string, string>}>
staticchildRules(string $selector, array $child, array $parent): array#

The rules a child writes from its own layout (wp_get_child_layout_style_rules): a fixed or filling flex size, a grid span, a grid position, released again (the full row for a span) in a container narrower than the columns it needs: the columns at the parent's minimum width (12rem by default) and the gaps between them (1.5rem, or 24px for a width in px).

$childarray<string, mixed>the child's layout (selfStretch, flexSize, columnSpan, rowSpan, columnStart, rowStart)
$parentarray<string, mixed>the parent's layout
@return list<array<string, mixed>>
staticcontainerValues(array $layout): array#

A layout's container values: everything but the child keys.

staticchildValues(array $layout): array#

A layout's child values: the child keys alone.

Internals 7

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

privateflowGap(string $selector, array|string|null $gap): array#
@return list<array{selector: string, declarations: array<string, string>}>
privateconstrained(string $selector, array $layout, array $padding): array#
@return list<array{selector: string, declarations: array<string, string>}>
privateflex(array $layout, array|string|null $gap): array#
@return array<string, string>
privategrid(array $layout, array|string|null $gap, string $fallbackGap): array#
@return array<string, string>
privategapValue(array|string|null $gap): ?string#

A flex or grid gap: one value, or the row and column gaps together.

privatefilled(array $declarations): array#
$declarationsarray<string, string>
@return array<string, string> the declarations that have a value
privatesingle(string $selector, array $declarations): array#
$declarationsarray<string, string>
@return list<array{selector: string, declarations: array<string, string>}>