Skip to content

Add core/media-text support to the php-transformer - #814

Merged
borkweb merged 11 commits into
trunkfrom
add/php-transformer-core-media-text
Aug 6, 2026
Merged

Add core/media-text support to the php-transformer#814
borkweb merged 11 commits into
trunkfrom
add/php-transformer-core-media-text

Conversation

@borkweb

@borkweb borkweb commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

Adds native core/media-text recognition to the php-transformer: strict two-pane image/video + text containers with an authored horizontal mechanism (display:flex/grid, a usable grid template, or round-trip wp-block-media-text markup) now emit core/media-text with core's canonical save shape, instead of falling through to columns/group handling.

What's included

  • Pattern recognizer (MediaTextPattern): exactly two element children, one pure img/video side (figure/div/a/picture wrappers allowed; figcaption declines), text-bearing other side. Emits mediaPosition, mediaWidth (percentage, fr-ratio, or auto-beside-percentage complement, clamped 15–85), verticalAlignment, and safe link attributes.
  • Fail-closed gates: mechanism-less containers, floated panes, unresolvable var() layout values, inherited RTL (ancestor dir, inherited CSS direction, dir="auto"), reversed/vertical flex, authored child order, linked video, unsafe URLs (scheme allowlist; data:image minus SVG for media), and grid templates that cannot express a mediaWidth all decline into the existing columns/group/author-layout paths.
  • Serialization (BlockFactory): core save shape with supported style groups only (border/color/elements/spacing/typography); defaults omitted; grid-template-columns emitted core-style.
  • Dispatch: runs before author-owned layout preservation — media-text candidates are by definition authored flex/grid containers.
  • Corpus diagnostics: per-gate decline counters, adoption metric, nested-candidate dedup, and a separate diagnostic-error counter so crashes are never counted as declines.
  • Validation: save-shape validator accepts media-text state classes only when the corresponding attributes justify them.

Review

Built through a gated architect/builder loop (35 frozen gates), then hardened by three adversarial review passes whose findings (silent pane swaps under design-token var() layouts, ancestor RTL, floats, px-track grids; rejected-href metadata retention; validator allowlist gaps; diagnostics accuracy/perf) are all fixed here. Corpus diagnostics report an unchanged baseline: blocks=57765 native_rate=99.7%, media-text counters identical before/after.

Testing

  • composer test:unit, composer test:parity, composer test:canonical — all pass
  • php tools/visual-parity/tests/transform-media-text.php — desktop/mobile visual-parity target renders
  • composer corpus-diagnostics — media-text counters unchanged from baseline

borkweb added 11 commits August 5, 2026 17:20
Honor resolved CSS cascade semantics for media-text layout gates, preserve carrier-owned geometry dependencies, and clamp representable widths.

Add regressions for inline display modes, order and reversal rules, geometry carriers, data URLs, memoization, CSS importance, specificity, and invalid declarations.
…view

## Summary
Close the fail-open gaps two adversarial review passes found in media-text conversion, and integrate the pattern with trunk's author-owned layout preservation after the rebase.

## Why
The strict gates read absent style values as defaults, so design-token var() layouts, ancestor RTL, floated panes, and inexpressible grid templates silently converted with the wrong pane order or width. After the rebase, trunk's author-owned-layout interception also consumed every candidate before the media-text dispatch was reached, and containers with no authored horizontal CSS converted into side-by-side layouts their sources never render.

## How
- Dispatch media-text before author-owned layout preservation and remove the now-unreachable later dispatch site
- Require an authored horizontal mechanism (display:flex/grid, a usable grid template, or round-trip wp-block-media-text markup) before converting
- Resolve text direction through inheritance (ancestor dir attributes and inherited CSS direction; dir="auto" fails closed)
- Decline floated panes, unresolvable var() gate values, and grid templates that cannot express a mediaWidth; derive complement widths for an auto media track beside a percentage text track
- Run width gates before text-side conversion so declines stop double-converting the subtree and leaking block-binding occurrence counts
- Hoist text-side wrapper groups only when their sole classes are transformer-generated css-owned markers absent from source markup
- Drop linkTarget/rel/linkClass when the href is rejected as unsafe
- Accept media-text state classes in the save-shape validator only when the corresponding attributes justify them
- Diagnostics: single-scan at-rule skip, nested-candidate dedup, memoized inherited-direction walk, and PCRE or transform failures counted as diagnostic errors instead of declines

## Testing
- [ ] composer test:unit && composer test:parity && composer test:canonical
- [ ] php tools/visual-parity/tests/transform-media-text.php
- [ ] composer corpus-diagnostics reports media-text counters unchanged from baseline
@borkweb
borkweb merged commit 7f722d9 into trunk Aug 6, 2026
4 checks passed
@borkweb
borkweb deleted the add/php-transformer-core-media-text branch August 6, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant