diff --git a/assets/css/components.css b/assets/css/components.css index c393404..078d4c4 100644 --- a/assets/css/components.css +++ b/assets/css/components.css @@ -754,15 +754,12 @@ html[data-theme="light"] .chrnx-home-music p { } .chrnx-topic-hero { - display: grid; - min-height: 30rem; - grid-template-columns: minmax(0, 1fr) minmax(15rem, 0.65fr); - align-items: end; - overflow: hidden; + display: block; + min-height: 0; + overflow: visible; margin-bottom: 3rem; - border: 1px solid var(--chrnx-line); - border-radius: calc(var(--chrnx-radius) * 1.5); - background: linear-gradient(135deg, var(--chrnx-surface), var(--chrnx-accent-soft)); + border: 0; + background: none; } .chrnx-topic-hero__content { @@ -1087,3 +1084,347 @@ html[data-theme="light"] .chrnx-home-music p { scroll-behavior: auto; } } + +/* Shared character-led section frame. */ + +.chrnx-character-stage { + --chrnx-character-accent: var(--chrnx-accent); + --chrnx-character-halo: color-mix(in srgb, var(--chrnx-character-accent) 30%, transparent); + --chrnx-character-wash: color-mix(in srgb, var(--chrnx-character-accent) 12%, transparent); + --chrnx-character-shadow: drop-shadow(0 1.75rem 1.5rem rgb(0 0 0 / 32%)); + --chrnx-character-copy-surface: rgb(21 27 35 / 88%); + position: relative; + display: grid; + box-sizing: border-box; + min-height: clamp(30rem, 44vw, 38rem); + grid-template-columns: minmax(0, 55fr) minmax(0, 45fr); + isolation: isolate; + overflow: clip; + border: 1px solid color-mix(in srgb, var(--chrnx-character-accent) 32%, var(--chrnx-line)); + border-radius: calc(var(--chrnx-radius) * 1.5); + background-color: var(--chrnx-surface); + background-image: linear-gradient(125deg, var(--chrnx-surface) 0 45%, var(--chrnx-character-wash) 100%); + box-shadow: var(--chrnx-shadow); + color: var(--chrnx-text); +} + +.chrnx-character-stage__atmosphere { + position: absolute; + z-index: 0; + inset: 0; + overflow: hidden; + pointer-events: none; +} + +.chrnx-character-stage__atmosphere::before { + position: absolute; + top: 8%; + right: -4%; + width: min(48rem, 62%); + aspect-ratio: 1; + border-radius: 50%; + background: radial-gradient(circle, var(--chrnx-character-halo) 0 24%, transparent 68%); + content: ""; + filter: blur(0.2rem); +} + +.chrnx-character-stage__atmosphere::after { + position: absolute; + inset: 0; + background-image: + linear-gradient(112deg, transparent 0 49%, var(--chrnx-character-wash) 49.5% 50.5%, transparent 51%), + linear-gradient(28deg, transparent 0 72%, color-mix(in srgb, var(--chrnx-character-accent) 18%, transparent) 72.5% 74%, transparent 74.5%), + radial-gradient(ellipse at 78% 100%, rgb(0 0 0 / 20%) 0 12%, transparent 42%); + content: ""; +} + +.chrnx-character-stage__content { + position: relative; + z-index: 2; + display: grid; + box-sizing: border-box; + width: 100%; + min-width: 0; + align-content: center; + align-self: stretch; + grid-column: 1; + grid-row: 1; + margin: 0 !important; + padding: clamp(2rem, 5vw, 5rem); + color: var(--chrnx-text); +} + +.chrnx-character-stage__content::before { + position: absolute; + z-index: 1; + inset: 0; + background-color: var(--chrnx-character-copy-surface); + content: ""; + pointer-events: none; +} + +.chrnx-character-stage__content > :not(.chrnx-responsive-portrait) { + position: relative; + z-index: 2; +} + +.chrnx-character-stage__content > :first-child { + margin-block-start: 0; +} + +.chrnx-character-stage__content > :last-child { + margin-block-end: 0; +} + +.chrnx-character-stage__art { + position: relative; + z-index: 3; + display: flex; + box-sizing: border-box; + width: 100%; + min-width: 0; + height: 100%; + align-self: end; + align-items: end; + justify-content: center; + grid-column: 2; + grid-row: 1; + margin: 0; +} + +.chrnx-character-stage__art::before { + position: absolute; + z-index: 1; + right: 5%; + bottom: -1.25rem; + left: 5%; + height: 4.5rem; + border-radius: 50%; + background: radial-gradient(ellipse, rgb(0 0 0 / 38%), transparent 68%); + content: ""; + filter: blur(0.55rem); +} + +.chrnx-character-stage__art > .chrnx-responsive-portrait { + position: relative; + z-index: 2; + display: flex; + width: 100%; + height: 100%; + align-items: end; + justify-content: center; + margin: 0; +} + +.chrnx-character-stage__art img { + display: block; + width: 100%; + height: auto; + max-height: clamp(28rem, 44vw, 38rem); + object-fit: contain; + object-position: center bottom; + filter: var(--chrnx-character-shadow) saturate(0.96) contrast(1.04); +} + +.chrnx-character-stage__secondary-art { + position: absolute; + z-index: 1; + right: 27%; + bottom: 0; + width: min(29%, 18rem); + height: auto; + opacity: 0.34; + filter: saturate(0.55) contrast(1.08) drop-shadow(0 1rem 2rem rgb(0 0 0 / 24%)); +} + +.chrnx-character-stage__atmosphere > .chrnx-responsive-portrait { + position: absolute; + z-index: 1; + inset: 0; + width: 100%; + height: 100%; +} + +.chrnx-character-stage__atmosphere .chrnx-character-stage__collage { + width: 100%; + height: 100%; + object-fit: cover; + object-position: 68% center; + filter: saturate(0.68) contrast(1.08); + opacity: 0.46; +} + +.chrnx-music-landing .chrnx-character-stage__content > .chrnx-responsive-portrait:has(.chrnx-character-stage__collage) { + position: absolute; + z-index: 0; + inset: 0 auto 0 0; + width: calc(100% / 0.55); + height: 100%; + overflow: hidden; + margin: 0 !important; + opacity: 0.28; +} + +.chrnx-music-landing .chrnx-character-stage__content > h2, +.chrnx-music-landing .chrnx-character-stage__content > p { + position: relative; + z-index: 2; +} + +.chrnx-music-landing .chrnx-character-stage__collage { + width: 100%; + height: 100%; + object-fit: cover; + filter: saturate(0.72) contrast(1.08); +} + +.chrnx-home-projects .chrnx-character-stage, +.is-topic-code .chrnx-character-stage { + --chrnx-character-accent: #59c3c3; +} + +.is-topic-research .chrnx-character-stage { + --chrnx-character-accent: #a5d66a; +} + +.is-topic-literature .chrnx-character-stage { + --chrnx-character-accent: #b88ad9; +} + +.chrnx-home-music .chrnx-character-stage, +.chrnx-music-landing .chrnx-character-stage, +.is-topic-music .chrnx-character-stage { + --chrnx-character-accent: #d36b3f; +} + +.chrnx-home-music .chrnx-character-stage, +.chrnx-music-landing .chrnx-character-stage { + --chrnx-character-copy-surface: rgb(13 17 23 / 86%); + background-color: #0d1117; + background-image: linear-gradient(125deg, #0d1117 0 45%, rgb(84 38 15 / 72%) 100%); + color: #e6edf3; +} + +html[data-theme="light"] .chrnx-character-stage { + --chrnx-character-copy-surface: rgb(255 253 247 / 90%); +} + +html[data-theme="light"] .chrnx-home-music .chrnx-character-stage, +html[data-theme="light"] .chrnx-music-landing .chrnx-character-stage { + --chrnx-character-copy-surface: rgb(13 17 23 / 86%); +} + +.chrnx-home-music .chrnx-character-stage__content, +.chrnx-home-music .chrnx-character-stage__content h2, +.chrnx-home-music .chrnx-character-stage__content p, +.chrnx-music-landing .chrnx-character-stage__content, +.chrnx-music-landing .chrnx-character-stage__content h2, +.chrnx-music-landing .chrnx-character-stage__content p, +.chrnx-music-landing .chrnx-character-stage__content a { + color: #e6edf3; +} + +.chrnx-podcast-landing .chrnx-character-stage, +.is-topic-podcasts .chrnx-character-stage, +.is-topic-silicon-ranch .chrnx-character-stage { + --chrnx-character-accent: #58a7d8; +} + +.chrnx-about .chrnx-character-stage, +.is-topic-life .chrnx-character-stage { + --chrnx-character-accent: #e0b75b; +} + +.is-topic-gaming .chrnx-character-stage { + --chrnx-character-accent: #da7b45; +} + +.chrnx-topic-hero__fallback { + position: absolute; + right: 9%; + bottom: 0; + width: min(36%, 24rem); + aspect-ratio: 0.78; + border: 1px solid color-mix(in srgb, var(--chrnx-character-accent) 46%, transparent); + border-bottom: 0; + border-radius: 48% 48% 0 0; + background: + radial-gradient(circle at 50% 26%, var(--chrnx-character-halo) 0 14%, transparent 15%), + linear-gradient(145deg, var(--chrnx-character-wash), transparent 62%); + box-shadow: 0 1.5rem 3rem rgb(0 0 0 / 18%); +} + +.chrnx-character-facets { + position: relative; + z-index: 0; + opacity: 0.84; +} + +.chrnx-character-facets .chrnx-section-portrait { + filter: saturate(0.72) contrast(1.02) drop-shadow(0 1rem 1.25rem rgb(0 0 0 / 20%)); +} + +@media (max-width: 780px) { + + .chrnx-topic-hero { + min-height: 0; + } + + .chrnx-character-stage { + min-height: 0; + grid-template-columns: 1fr; + grid-template-rows: auto auto; + } + + .chrnx-character-stage__content { + align-self: start; + grid-column: 1; + grid-row: 1; + padding: clamp(1.5rem, 7vw, 3rem); + } + + .chrnx-character-stage__art { + width: 76%; + height: clamp(20rem, 100vw, 34rem); + justify-self: end; + grid-column: 1; + grid-row: 2; + margin: 0; + } + + .chrnx-character-stage__art img { + max-height: 100%; + } + + .chrnx-character-stage__secondary-art { + display: none; + } + + .chrnx-character-stage__atmosphere::before { + top: auto; + right: -18%; + bottom: 0; + width: 100%; + } + + .chrnx-character-stage__atmosphere .chrnx-character-stage__collage { + object-position: 62% center; + opacity: 0.34; + } + + .chrnx-music-landing .chrnx-character-stage__content > .chrnx-responsive-portrait:has(.chrnx-character-stage__collage) { + width: 100%; + height: calc(100% + clamp(20rem, 100vw, 34rem)); + } +} + +@media (prefers-reduced-motion: reduce) { + + .chrnx-character-stage, + .chrnx-character-stage *, + .chrnx-character-stage::before, + .chrnx-character-stage::after { + animation: none !important; + transition: none !important; + } +} diff --git a/assets/images/alter-ego-gaming-half-body.png b/assets/images/alter-ego-gaming-half-body.png new file mode 100644 index 0000000..c2d96d7 Binary files /dev/null and b/assets/images/alter-ego-gaming-half-body.png differ diff --git a/assets/images/generated/alter-ego-gaming-half-body-384.avif b/assets/images/generated/alter-ego-gaming-half-body-384.avif new file mode 100644 index 0000000..92c7491 Binary files /dev/null and b/assets/images/generated/alter-ego-gaming-half-body-384.avif differ diff --git a/assets/images/generated/alter-ego-gaming-half-body-384.webp b/assets/images/generated/alter-ego-gaming-half-body-384.webp new file mode 100644 index 0000000..e3ce8d2 Binary files /dev/null and b/assets/images/generated/alter-ego-gaming-half-body-384.webp differ diff --git a/assets/images/generated/alter-ego-gaming-half-body-768.avif b/assets/images/generated/alter-ego-gaming-half-body-768.avif new file mode 100644 index 0000000..ad18887 Binary files /dev/null and b/assets/images/generated/alter-ego-gaming-half-body-768.avif differ diff --git a/assets/images/generated/alter-ego-gaming-half-body-768.webp b/assets/images/generated/alter-ego-gaming-half-body-768.webp new file mode 100644 index 0000000..01b3e95 Binary files /dev/null and b/assets/images/generated/alter-ego-gaming-half-body-768.webp differ diff --git a/assets/images/generated/alter-ego-gaming-half-body.json b/assets/images/generated/alter-ego-gaming-half-body.json new file mode 100644 index 0000000..4e8a1ef --- /dev/null +++ b/assets/images/generated/alter-ego-gaming-half-body.json @@ -0,0 +1,5 @@ +{ + "source": "alter-ego-gaming-half-body.png", + "formats": [ "avif", "webp" ], + "widths": [ 384, 768 ] +} diff --git a/blocks/topic-hero/render.php b/blocks/topic-hero/render.php index 7f93da8..c152bb1 100644 --- a/blocks/topic-hero/render.php +++ b/blocks/topic-hero/render.php @@ -6,28 +6,43 @@ */ $chrnx_topic = isset( $attributes['topic'] ) && is_string( $attributes['topic'] ) ? $attributes['topic'] : ''; -if ( '' === $chrnx_topic && is_tax( 'chrnx_topic' ) ) { - $chrnx_queried = get_queried_object(); - $chrnx_topic = $chrnx_queried instanceof WP_Term ? $chrnx_queried->slug : ''; -} -$chrnx_asset = chrnx_get_topic_art_asset( $chrnx_topic ); -$chrnx_size = chrnx_get_topic_art_dimensions( $chrnx_topic ); -if ( '' === $chrnx_asset || 2 !== count( $chrnx_size ) ) { +if ( '' !== $chrnx_topic && ! preg_match( '/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $chrnx_topic ) ) { return; } -$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 ); -$chrnx_term = get_term_by( 'slug', $chrnx_topic, 'chrnx_topic' ); -$chrnx_label = $chrnx_term instanceof WP_Term ? $chrnx_term->name : ucfirst( $chrnx_topic ); +$chrnx_queried = get_queried_object(); +$chrnx_taxonomy = ''; +if ( '' === $chrnx_topic && $chrnx_queried instanceof WP_Term && in_array( $chrnx_queried->taxonomy, array( 'chrnx_topic', 'chrnx_show' ), true ) ) { + $chrnx_topic = $chrnx_queried->slug; + $chrnx_taxonomy = $chrnx_queried->taxonomy; +} +if ( '' === $chrnx_topic ) { + return; +} +$chrnx_art_topic = 'chrnx_show' === $chrnx_taxonomy ? 'podcasts' : $chrnx_topic; +$chrnx_asset = chrnx_get_topic_art_asset( $chrnx_art_topic ); +$chrnx_size = chrnx_get_topic_art_dimensions( $chrnx_art_topic ); +$chrnx_has_art = '' !== $chrnx_asset && 2 === count( $chrnx_size ); +$chrnx_has_image = $chrnx_has_art && is_readable( get_theme_file_path( $chrnx_asset ) ); +$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 ); +$chrnx_term = $chrnx_queried instanceof WP_Term && $chrnx_queried->slug === $chrnx_topic ? $chrnx_queried : get_term_by( 'slug', $chrnx_topic, 'chrnx_topic' ); +$chrnx_label = $chrnx_term instanceof WP_Term ? $chrnx_term->name : ucwords( str_replace( '-', ' ', $chrnx_topic ) ); +$chrnx_classes = 'chrnx-topic-hero is-topic-' . sanitize_html_class( $chrnx_topic ); +$chrnx_wrapper = isset( $block ) && $block instanceof WP_Block ? get_block_wrapper_attributes( array( 'class' => $chrnx_classes ) ) : 'class="' . esc_attr( $chrnx_classes ) . '"'; ?> -
'chrnx-topic-hero is-topic-' . sanitize_html_class( $chrnx_topic ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> -
- class="chrnx-topic-hero__title">> -
-
- - - - - +
> +
+ +
+ class="chrnx-topic-hero__title">> +
+
+ + + +
diff --git a/inc/queries.php b/inc/queries.php index ef0f3c9..25a1804 100644 --- a/inc/queries.php +++ b/inc/queries.php @@ -631,7 +631,7 @@ function chrnx_get_topic_art_asset( string $topic_slug ): string { 'music-collage' => 'the-no-names-collage.jpeg', 'podcasts' => 'alter-ego-podcasts.png', 'life' => 'alter-ego-life.png', - 'gaming' => 'alter-ego-gaming.png', + 'gaming' => 'alter-ego-gaming-half-body.png', ); return isset( $mapping[ $topic_slug ] ) ? 'assets/images/' . $mapping[ $topic_slug ] : ''; } diff --git a/patterns/about.php b/patterns/about.php index 70d39b2..b5e43cf 100644 --- a/patterns/about.php +++ b/patterns/about.php @@ -12,18 +12,27 @@ $chrnx_research_url = esc_url( 'https://arxiv.org/abs/2603.05352' ); ?>
- -
- + +
+ + +
+

+

+

.

+

+

+

+
+ +
+
+ + +
-

-

-

.

-

-

-

diff --git a/patterns/home-music.php b/patterns/home-music.php index 5d9faa9..95df04f 100644 --- a/patterns/home-music.php +++ b/patterns/home-music.php @@ -11,18 +11,18 @@ ?>
- -
-
- + +
+ + +

-
-
- -
+
+ +
- +
diff --git a/patterns/home-projects.php b/patterns/home-projects.php index 7c9c276..964a36b 100644 --- a/patterns/home-projects.php +++ b/patterns/home-projects.php @@ -11,15 +11,23 @@ ?>
- -

- -
-

-

-

+ +
+ + +
+

+ +
+

+

+

+
+ +
+ +
- - +
diff --git a/patterns/music-landing.php b/patterns/music-landing.php index 4201155..29041ca 100644 --- a/patterns/music-landing.php +++ b/patterns/music-landing.php @@ -8,18 +8,22 @@ * * @package CHRNX */ -$chrnx_music_collage = get_theme_file_uri( 'assets/images/the-no-names-collage.jpeg' ); ?>
-

-

-

-

- -
- <?php echo esc_attr__( 'The No Names collage', 'chrnx' ); ?> - + +
+ + +
+

+

+

+

+ +
+ +

diff --git a/patterns/podcast-landing.php b/patterns/podcast-landing.php index 071a608..1ba0fd5 100644 --- a/patterns/podcast-landing.php +++ b/patterns/podcast-landing.php @@ -11,8 +11,17 @@ ?>
-

- + +
+ + +
+

+
+ +
+
+
diff --git a/scripts/build-responsive-images.sh b/scripts/build-responsive-images.sh index 64f3b0d..0580b92 100755 --- a/scripts/build-responsive-images.sh +++ b/scripts/build-responsive-images.sh @@ -78,6 +78,9 @@ for chrnx_image_topic in code gaming life literature podcasts research; do printf '{\n\t"source": "alter-ego-%s.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' "$chrnx_image_topic" > "$chrnx_image_output/alter-ego-$chrnx_image_topic.json" done +chrnx_build_responsive_image "alter-ego-gaming-half-body" "alter-ego-gaming-half-body.png" +printf '{\n\t"source": "alter-ego-gaming-half-body.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' > "$chrnx_image_output/alter-ego-gaming-half-body.json" + chrnx_build_responsive_image "the-no-names-musician-cutout" "the-no-names-musician-cutout.png" printf '{\n\t"source": "the-no-names-musician-cutout.png",\n\t"formats": [ "avif", "webp" ],\n\t"widths": [ 384, 768 ]\n}\n' > "$chrnx_image_output/the-no-names-musician-cutout.json" diff --git a/tests/assets/test_alter_ego_assets.py b/tests/assets/test_alter_ego_assets.py index 2c926ff..6bd6514 100644 --- a/tests/assets/test_alter_ego_assets.py +++ b/tests/assets/test_alter_ego_assets.py @@ -16,6 +16,7 @@ ALTER_EGO_ASSETS = ( "alter-ego-life.png", "alter-ego-gaming.png", ) +ALTER_EGO_SOURCE_ASSETS = (*ALTER_EGO_ASSETS, "alter-ego-gaming-half-body.png") CONTACT_SHEET_SCRIPT = PROJECT_ROOT / "scripts" / "build-alter-ego-contact-sheet.py" @@ -33,9 +34,9 @@ def test_opaque_coverage_counts_near_opaque_alpha() -> None: def test_alter_ego_asset_inventory_and_image_contract() -> None: - expected = set(ALTER_EGO_ASSETS) + expected = set(ALTER_EGO_SOURCE_ASSETS) actual = {path.name for path in ASSET_DIRECTORY.glob("alter-ego-*.png")} - missing = [name for name in ALTER_EGO_ASSETS if name not in actual] + missing = [name for name in ALTER_EGO_SOURCE_ASSETS if name not in actual] unexpected = sorted(actual - expected) inventory_violations = [ *(f"missing assets/images/{name}" for name in missing), @@ -46,7 +47,7 @@ def test_alter_ego_asset_inventory_and_image_contract() -> None: ) violations: list[str] = [] - for name in ALTER_EGO_ASSETS: + for name in ALTER_EGO_SOURCE_ASSETS: path = ASSET_DIRECTORY / name with Image.open(path) as image: if image.format != "PNG": @@ -92,6 +93,24 @@ def test_alter_ego_asset_inventory_and_image_contract() -> None: ) +def test_gaming_half_body_preserves_original_and_has_prominent_visible_alpha() -> None: + original = ASSET_DIRECTORY / "alter-ego-gaming.png" + half_body = ASSET_DIRECTORY / "alter-ego-gaming-half-body.png" + assert original.read_bytes() != half_body.read_bytes() + + with Image.open(original) as original_image, Image.open(half_body) as half_body_image: + assert original_image.size == half_body_image.size == (1024, 1536) + original_box = original_image.getchannel("A").point( + lambda value: 255 if value >= 16 else 0 + ).getbbox() + half_body_box = half_body_image.getchannel("A").point( + lambda value: 255 if value >= 16 else 0 + ).getbbox() + assert original_box == (170, 54, 882, 1475) + assert half_body_box == (15, 79, 948, 1536) + assert (half_body_box[2] - half_body_box[0]) / 1024 >= 0.90 + + def _install_contact_sheet_script(project_root: Path) -> Path: assert CONTACT_SHEET_SCRIPT.is_file(), ( f"Missing contact-sheet script: {CONTACT_SHEET_SCRIPT}" diff --git a/tests/e2e/visual-states.spec.mjs b/tests/e2e/visual-states.spec.mjs index ee72680..ddffc6f 100644 --- a/tests/e2e/visual-states.spec.mjs +++ b/tests/e2e/visual-states.spec.mjs @@ -8,6 +8,143 @@ const viewports = [ { width: 2560, height: 1440 }, ]; +const characterSurfaces = [ + { name: 'home-projects', path: '/', selector: '.chrnx-home-projects .chrnx-character-stage' }, + { name: 'home-music', path: '/', selector: '.chrnx-home-music .chrnx-character-stage' }, + { name: 'projects', path: '/projects/', selector: '.chrnx-home-projects .chrnx-character-stage' }, + { name: 'music', path: '/music/', selector: '.chrnx-music-landing .chrnx-character-stage' }, + { + name: 'podcasts', + path: '/podcasts/', + selector: '.chrnx-podcast-landing .chrnx-character-stage', + }, + { name: 'about', path: '/about/', selector: '.chrnx-about .chrnx-character-stage' }, + { + name: 'show-silicon-ranch', + path: '/show/silicon-ranch/', + selector: '.chrnx-topic-hero .chrnx-character-stage', + }, + ...[ 'research', 'code', 'literature', 'music', 'podcasts', 'life', 'gaming' ].map( + ( topic ) => ( { + name: `topic-${ topic }`, + path: `/topic/${ topic }/`, + selector: '.chrnx-topic-hero .chrnx-character-stage', + } ), + ), +]; + +const characterVisibleAlphaBounds = { + 'alter-ego-code': [ 1122, 1402, 87, 204, 1022, 1172 ], + 'alter-ego-gaming-half-body': [ 1024, 1536, 15, 79, 948, 1536 ], + 'alter-ego-life': [ 1122, 1402, 25, 81, 1078, 1402 ], + 'alter-ego-literature': [ 1122, 1402, 51, 48, 1072, 1359 ], + 'alter-ego-podcasts': [ 1122, 1402, 62, 110, 1101, 1338 ], + 'alter-ego-research': [ 1122, 1402, 106, 52, 1074, 1402 ], + 'the-no-names-musician-cutout': [ 1122, 1402, 0, 46, 1102, 1402 ], +}; + +async function positionStageBelowStickyHeader( page, stage ) { + await stage.scrollIntoViewIfNeeded(); + await page.evaluate( + ( element ) => { + const header = document.querySelector( 'header.wp-block-template-part' ); + const overlap = header.getBoundingClientRect().bottom - element.getBoundingClientRect().top; + if ( overlap > 0 ) { + window.scrollBy( 0, -( overlap + 16 ) ); + } + }, + await stage.elementHandle(), + ); + await page.evaluate( + () => + new Promise( ( resolve ) => + window.requestAnimationFrame( () => window.requestAnimationFrame( resolve ) ), + ), + ); +} + +async function setExplicitTheme( page, theme ) { + await page.addInitScript( ( value ) => { + window.localStorage.setItem( 'chrnx-theme', value ); + }, theme ); +} + +async function readCharacterGeometry( stage ) { + return stage.evaluate( ( element ) => { + const content = element.querySelector( ':scope > .chrnx-character-stage__content' ); + const art = element.querySelector( ':scope > .chrnx-character-stage__art' ); + const atmosphere = element.querySelector( ':scope > .chrnx-character-stage__atmosphere' ); + const picture = art.querySelector( ':scope > picture' ); + const image = picture?.querySelector( 'img' ); + const secondary = atmosphere.querySelector( 'picture' ); + const collage = element + .querySelector( '.chrnx-character-stage__collage' ) + ?.closest( 'picture' ); + const facets = element.parentElement.querySelector( ':scope > .chrnx-character-facets' ); + const stageRect = element.getBoundingClientRect(); + const contentRect = content.getBoundingClientRect(); + const artRect = art.getBoundingClientRect(); + const pictureRect = picture?.getBoundingClientRect(); + const imageStyle = image ? window.getComputedStyle( image ) : null; + const pictureStyle = picture ? window.getComputedStyle( picture ) : null; + const atmosphereStyle = window.getComputedStyle( atmosphere ); + const secondaryStyle = secondary ? window.getComputedStyle( secondary ) : null; + const collageStyle = collage ? window.getComputedStyle( collage ) : null; + const facetsStyle = facets ? window.getComputedStyle( facets ) : null; + const intersects = ( first, second ) => + first.left < second.right - 1 && + first.right > second.left + 1 && + first.top < second.bottom - 1 && + first.bottom > second.top + 1; + const following = []; + let branch = element; + while ( branch && branch.tagName !== 'MAIN' ) { + let sibling = branch.nextElementSibling; + while ( sibling ) { + following.push( sibling ); + sibling = sibling.nextElementSibling; + } + branch = branch.parentElement; + } + + return { + stageWidth: stageRect.width, + artWidth: artRect.width, + artBottomGap: Math.abs( stageRect.bottom - artRect.bottom ), + contentTop: contentRect.top, + contentBottom: contentRect.bottom, + artTop: artRect.top, + contentArtIntersect: intersects( contentRect, artRect ), + followingIntersections: following.filter( ( candidate ) => + intersects( stageRect, candidate.getBoundingClientRect() ), + ).length, + followingCount: following.length, + stageOverflow: element.scrollWidth - element.clientWidth, + pictureVisible: Boolean( + pictureRect && pictureRect.width > 0 && pictureRect.height > 0 && image?.complete, + ), + pictureContained: Boolean( + pictureRect && + pictureRect.left >= artRect.left - 1 && + pictureRect.right <= artRect.right + 1 && + pictureRect.top >= artRect.top - 1 && + pictureRect.bottom <= artRect.bottom + 1, + ), + pictureZ: Number.parseInt( pictureStyle?.zIndex || '0', 10 ) || 0, + atmosphereZ: Number.parseInt( atmosphereStyle.zIndex, 10 ) || 0, + secondaryZ: Number.parseInt( secondaryStyle?.zIndex || '0', 10 ) || 0, + collageZ: Number.parseInt( collageStyle?.zIndex || '0', 10 ) || 0, + collageLoading: collage?.querySelector( 'img' )?.loading, + facetsOpacity: facetsStyle ? Number.parseFloat( facetsStyle.opacity ) : null, + facetsZ: Number.parseInt( facetsStyle?.zIndex || '0', 10 ) || 0, + effect: imageStyle + ? `${ imageStyle.filter }|${ imageStyle.boxShadow }|${ imageStyle.maskImage }|${ imageStyle.webkitMaskImage }` + : '', + loading: image?.loading, + }; + } ); +} + async function expectNoHorizontalOverflow( page ) { const overflow = await page.evaluate( () => ( { document: document.documentElement.scrollWidth - window.innerWidth, @@ -34,6 +171,20 @@ function contrastRatio( foreground, background ) { return ( lighter + 0.05 ) / ( darker + 0.05 ); } +function conservativeOverlayContrast( foreground, overlay ) { + const channels = overlay.match( /[\d.]+/g ).map( Number ); + const alpha = channels[ 3 ] ?? 1; + const composite = ( underlay ) => + `rgb(${ channels + .slice( 0, 3 ) + .map( ( channel ) => Math.round( channel * alpha + underlay * ( 1 - alpha ) ) ) + .join( ', ' ) })`; + return Math.min( + contrastRatio( foreground, composite( 0 ) ), + contrastRatio( foreground, composite( 255 ) ), + ); +} + test( 'home remains coherent at all approved review viewports', async ( { page } ) => { for ( const viewport of viewports ) { await page.setViewportSize( viewport ); @@ -672,3 +823,381 @@ test( 'key public surfaces pass automated WCAG 2.2 AA checks', async ( { page }, } } } ); + +test( 'character stage geometry, layering, effects, loading, and inspection captures', async ( { + page, +}, testInfo ) => { + test.setTimeout( 180_000 ); + test.skip( testInfo.project.name !== 'chromium', 'Character geometry is reviewed in Chromium.' ); + + for ( const theme of [ 'dark', 'light' ] ) { + await setExplicitTheme( page, theme ); + for ( const viewport of viewports ) { + await page.setViewportSize( viewport ); + for ( const surface of characterSurfaces ) { + await page.goto( surface.path ); + await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', theme ); + const stage = page.locator( surface.selector ).first(); + await expect( stage, `${ surface.name } stage` ).toBeVisible(); + const initial = await stage.evaluate( ( element ) => ( { + top: element.getBoundingClientRect().top, + loading: element.querySelector( ':scope > .chrnx-character-stage__art picture img' ) + ?.loading, + priority: element.querySelector( ':scope > .chrnx-character-stage__art picture img' ) + ?.fetchPriority, + } ) ); + await positionStageBelowStickyHeader( page, stage ); + await stage + .locator( ':scope > .chrnx-character-stage__art picture img' ) + .evaluate( ( image ) => image.decode() ); + const geometry = await readCharacterGeometry( stage ); + const mobile = viewport.width <= 768; + const ratio = geometry.artWidth / geometry.stageWidth; + + expect( + ratio, + `${ surface.name } art ratio at ${ viewport.width }px ${ theme }`, + ).toBeGreaterThanOrEqual( mobile ? 0.62 : 0.35 ); + if ( ! mobile ) { + expect( ratio ).toBeLessThanOrEqual( 0.48 ); + } + expect( geometry.artBottomGap ).toBeLessThanOrEqual( 2 ); + if ( mobile ) { + expect( geometry.contentTop ).toBeLessThan( geometry.artTop ); + expect( geometry.contentBottom ).toBeLessThanOrEqual( geometry.artTop + 1 ); + } + expect( geometry.contentArtIntersect ).toBeFalsy(); + expect( geometry.followingIntersections ).toBe( 0 ); + if ( + [ 'home-projects', 'home-music', 'projects', 'music', 'podcasts', 'about' ].includes( + surface.name, + ) + ) { + expect( geometry.followingCount, `${ surface.name } following surfaces` ).toBeGreaterThan( + 0, + ); + } + expect( geometry.stageOverflow ).toBeLessThanOrEqual( 1 ); + expect( geometry.pictureVisible ).toBeTruthy(); + expect( geometry.pictureContained ).toBeTruthy(); + expect( geometry.pictureZ ).toBeGreaterThan( geometry.atmosphereZ ); + expect( geometry.pictureZ ).toBeGreaterThan( geometry.secondaryZ ); + expect( geometry.pictureZ ).toBeGreaterThan( geometry.collageZ ); + expect( geometry.effect ).not.toBe( 'none|none|none|none' ); + const painted = await stage.evaluate( ( element, boundsByAsset ) => { + const image = element.querySelector( ':scope > .chrnx-character-stage__art picture img' ); + const sourceName = new URL( image.src ).pathname + .split( '/' ) + .pop() + .replace( /\.png$/, '' ); + const [ naturalWidth, naturalHeight, x0, y0, x1, y1 ] = boundsByAsset[ sourceName ]; + const imageRect = image.getBoundingClientRect(); + const stageRect = element.getBoundingClientRect(); + const scale = Math.min( + imageRect.width / naturalWidth, + imageRect.height / naturalHeight, + ); + const objectWidth = naturalWidth * scale; + const objectHeight = naturalHeight * scale; + const objectLeft = imageRect.left + ( imageRect.width - objectWidth ) / 2; + const objectTop = imageRect.bottom - objectHeight; + const visible = { + left: objectLeft + x0 * scale, + top: objectTop + y0 * scale, + right: objectLeft + x1 * scale, + bottom: objectTop + y1 * scale, + }; + return { + sourceName, + widthRatio: ( visible.right - visible.left ) / stageRect.width, + heightRatio: ( visible.bottom - visible.top ) / stageRect.height, + contained: + visible.left >= stageRect.left - 1 && + visible.right <= stageRect.right + 1 && + visible.top >= stageRect.top - 1 && + visible.bottom <= stageRect.bottom + 1, + }; + }, characterVisibleAlphaBounds ); + expect( painted.widthRatio, `${ surface.name } painted width` ).toBeGreaterThanOrEqual( + mobile ? 0.45 : 0.36, + ); + expect( painted.heightRatio ).toBeGreaterThanOrEqual( 0.28 ); + expect( painted.contained ).toBeTruthy(); + if ( surface.name === 'topic-gaming' ) { + expect( painted.sourceName ).toBe( 'alter-ego-gaming-half-body' ); + } + if ( surface.name === 'home-music' || surface.name === 'music' ) { + expect( geometry.collageLoading ).toBe( 'lazy' ); + } + if ( surface.name === 'music' ) { + const collage = stage.locator( + '.chrnx-character-stage__content > .chrnx-responsive-portrait:has(.chrnx-character-stage__collage)', + ); + const collageContract = await collage.evaluate( + ( picture, stageElement ) => { + const pictureRect = picture.getBoundingClientRect(); + const stageRect = stageElement.getBoundingClientRect(); + return { + left: Math.abs( pictureRect.left - stageRect.left ), + right: Math.abs( pictureRect.right - stageRect.right ), + top: Math.abs( pictureRect.top - stageRect.top ), + bottom: Math.abs( pictureRect.bottom - stageRect.bottom ), + hiddenAncestor: Boolean( picture.closest( '[aria-hidden="true"]' ) ), + alt: picture.querySelector( 'img' )?.alt, + }; + }, + await stage.elementHandle(), + ); + expect( collageContract.left ).toBeLessThanOrEqual( 2 ); + expect( collageContract.right ).toBeLessThanOrEqual( 2 ); + expect( collageContract.top ).toBeLessThanOrEqual( 2 ); + expect( collageContract.bottom ).toBeLessThanOrEqual( 2 ); + expect( collageContract.hiddenAncestor ).toBeFalsy(); + expect( collageContract.alt ).toBe( 'The No Names collage' ); + } + if ( surface.name === 'about' ) { + expect( geometry.facetsOpacity ).toBeLessThan( 1 ); + expect( geometry.facetsZ ).toBeLessThan( geometry.pictureZ ); + } + await expectNoHorizontalOverflow( page ); + + if ( initial.top >= viewport.height ) { + expect( initial.loading ).not.toBe( 'eager' ); + expect( initial.priority ).not.toBe( 'high' ); + } + const captureContract = await stage.evaluate( ( element ) => { + const header = document.querySelector( 'header.wp-block-template-part' ); + const heading = element.querySelector( 'h1, h2, h3, h4, h5, h6' ); + const headerRect = header.getBoundingClientRect(); + const stageRect = element.getBoundingClientRect(); + const headingRect = heading.getBoundingClientRect(); + return { + headerIntersects: + headerRect.bottom > stageRect.top && headerRect.top < stageRect.bottom, + headingContained: + headingRect.top >= stageRect.top && headingRect.bottom <= stageRect.bottom, + }; + } ); + expect( captureContract.headerIntersects ).toBeFalsy(); + expect( captureContract.headingContained ).toBeTruthy(); + const header = page.locator( 'header.wp-block-template-part' ); + await header.evaluate( ( element ) => { + element.dataset.characterCaptureVisibility = element.style.visibility; + element.style.visibility = 'hidden'; + } ); + try { + await testInfo.attach( + `character-stage-${ surface.name }-${ viewport.width }-${ theme }.png`, + { body: await stage.screenshot(), contentType: 'image/png' }, + ); + } finally { + await header.evaluate( ( element ) => { + element.style.visibility = element.dataset.characterCaptureVisibility; + delete element.dataset.characterCaptureVisibility; + } ); + } + } + } + } +} ); + +test( 'character stage long copy grows safely with AA contrast in both themes', async ( { + page, +}, testInfo ) => { + test.setTimeout( 120_000 ); + test.skip( testInfo.project.name !== 'chromium', 'Character geometry is reviewed in Chromium.' ); + + for ( const theme of [ 'dark', 'light' ] ) { + await setExplicitTheme( page, theme ); + for ( const width of [ 375, 1440 ] ) { + await page.setViewportSize( { width, height: width === 375 ? 812 : 900 } ); + for ( const surface of characterSurfaces ) { + await page.goto( surface.path ); + const stage = page.locator( surface.selector ).first(); + await stage.locator( ':scope > .chrnx-character-stage__content' ).evaluate( ( content ) => { + const walker = document.createTreeWalker( content, window.NodeFilter.SHOW_TEXT ); + const nodes = []; + while ( walker.nextNode() ) { + if ( walker.currentNode.textContent.trim() ) { + nodes.push( walker.currentNode ); + } + } + for ( const node of nodes ) { + node.textContent = `${ node.textContent.trim() } `.repeat( 4 ).trim(); + } + } ); + + const result = await stage.evaluate( ( element ) => { + const content = element.querySelector( ':scope > .chrnx-character-stage__content' ); + const art = element.querySelector( ':scope > .chrnx-character-stage__art' ); + const stageRect = element.getBoundingClientRect(); + const contentRect = content.getBoundingClientRect(); + const artRect = art.getBoundingClientRect(); + const following = [ + ...element.parentElement.querySelectorAll( + '.chrnx-release-card, .chrnx-podcast-card, .chrnx-character-facets', + ), + ].filter( ( candidate ) => { + const rect = candidate.getBoundingClientRect(); + return ! element.contains( candidate ) && rect.height > 0 && rect.top >= stageRect.top; + } ); + const foregrounds = [ ...content.querySelectorAll( 'h1, h2, h3, h4, h5, h6, p, li, a' ) ] + .filter( ( candidate ) => candidate.getClientRects().length > 0 ) + .map( ( candidate ) => window.getComputedStyle( candidate ).color ); + const copySurfaceStyle = window.getComputedStyle( content, '::before' ); + return { + stageBottom: stageRect.bottom, + contentBottom: contentRect.bottom, + artTop: artRect.top, + artBottom: artRect.bottom, + nextTop: following.length + ? Math.min( + ...following.map( ( candidate ) => candidate.getBoundingClientRect().top ), + ) + : Number.POSITIVE_INFINITY, + foregrounds, + background: copySurfaceStyle.backgroundColor, + backgroundImage: copySurfaceStyle.backgroundImage, + copySurfaceContent: copySurfaceStyle.content, + }; + } ); + + expect( result.stageBottom ).toBeGreaterThanOrEqual( result.contentBottom - 1 ); + expect( result.stageBottom ).toBeGreaterThanOrEqual( result.artBottom - 1 ); + expect( result.nextTop ).toBeGreaterThanOrEqual( result.stageBottom - 1 ); + if ( width === 375 ) { + expect( result.artTop ).toBeGreaterThanOrEqual( result.contentBottom - 1 ); + } + expect( result.foregrounds.length ).toBeGreaterThan( 0 ); + expect( result.copySurfaceContent ).not.toBe( 'none' ); + const backgroundChannels = result.background.match( /[\d.]+/g ).map( Number ); + expect( backgroundChannels[ 3 ] ?? 1 ).toBeGreaterThanOrEqual( 0.85 ); + expect( result.backgroundImage ).toBe( 'none' ); + for ( const foreground of result.foregrounds ) { + expect( + conservativeOverlayContrast( foreground, result.background ), + `${ surface.name } ${ width }px ${ theme } contrast`, + ).toBeGreaterThanOrEqual( 4.5 ); + } + await expectNoHorizontalOverflow( page ); + } + } + } +} ); + +test( 'character stage is static under reduced motion and visible without JavaScript', async ( { + browser, +}, testInfo ) => { + test.setTimeout( 60_000 ); + test.skip( testInfo.project.name !== 'chromium', 'Character geometry is reviewed in Chromium.' ); + const cases = characterSurfaces.filter( ( surface ) => + [ 'home-music', 'about', 'topic-code' ].includes( surface.name ), + ); + + for ( const surface of cases ) { + const regularContext = await browser.newContext( { + baseURL: testInfo.project.use.baseURL, + viewport: { width: 375, height: 812 }, + } ); + const reducedContext = await browser.newContext( { + baseURL: testInfo.project.use.baseURL, + viewport: { width: 375, height: 812 }, + reducedMotion: 'reduce', + } ); + const noJavaScriptContext = await browser.newContext( { + baseURL: testInfo.project.use.baseURL, + viewport: { width: 375, height: 812 }, + javaScriptEnabled: false, + } ); + const [ regular, reduced, noJavaScript ] = await Promise.all( [ + regularContext.newPage(), + reducedContext.newPage(), + noJavaScriptContext.newPage(), + ] ); + try { + for ( const page of [ regular, reduced, noJavaScript ] ) { + await page.goto( surface.path ); + } + const regularStage = regular.locator( surface.selector ).first(); + const reducedStage = reduced.locator( surface.selector ).first(); + const noJsStage = noJavaScript.locator( surface.selector ).first(); + const [ regularBox, reducedBox ] = await Promise.all( [ + regularStage.boundingBox(), + reducedStage.boundingBox(), + ] ); + expect( Math.abs( regularBox.width - reducedBox.width ) ).toBeLessThanOrEqual( 1 ); + expect( Math.abs( regularBox.height - reducedBox.height ) ).toBeLessThanOrEqual( 1 ); + await expect( noJsStage ).toBeVisible(); + const noJsGeometry = await readCharacterGeometry( noJsStage ); + expect( noJsGeometry.pictureVisible ).toBeTruthy(); + expect( noJsGeometry.stageOverflow ).toBeLessThanOrEqual( 1 ); + await expectNoHorizontalOverflow( noJavaScript ); + } finally { + await Promise.all( [ + regularContext.close(), + reducedContext.close(), + noJavaScriptContext.close(), + ] ); + } + } +} ); + +test( 'character stage below-fold derivatives wait for approach and then load responsively', async ( { + page, +}, testInfo ) => { + test.setTimeout( 60_000 ); + test.skip( testInfo.project.name !== 'chromium', 'Character loading is reviewed in Chromium.' ); + await page.setViewportSize( { width: 375, height: 812 } ); + const requested = []; + page.on( 'request', ( request ) => { + if ( /\/assets\/images\/(?:generated\/)?/.test( request.url() ) ) { + requested.push( request.url() ); + } + } ); + await page.goto( '/' ); + await page.waitForTimeout( 300 ); + + const stages = page.locator( + '.chrnx-home-projects .chrnx-character-stage, .chrnx-home-music .chrnx-character-stage', + ); + await expect( stages ).toHaveCount( 2 ); + const expected = []; + for ( let stageIndex = 0; stageIndex < 2; stageIndex += 1 ) { + const stage = stages.nth( stageIndex ); + const stageTop = await stage.evaluate( ( element ) => element.getBoundingClientRect().top ); + expect( stageTop ).toBeGreaterThanOrEqual( 812 ); + const portraits = await stage.locator( 'picture' ).evaluateAll( ( pictures ) => + pictures + .filter( + ( picture ) => + window.getComputedStyle( picture.querySelector( 'img' ) ).display !== 'none', + ) + .map( ( picture ) => { + const source = picture.querySelector( 'source[type="image/avif"]' ); + return { + candidates: source.srcset + .split( ',' ) + .map( ( candidate ) => new URL( candidate.trim().split( /\s+/ )[ 0 ] ).pathname ), + }; + } ), + ); + expected.push( ...portraits ); + } + for ( const portrait of expected ) { + expect( + requested.some( ( url ) => portrait.candidates.includes( new URL( url ).pathname ) ), + ).toBeFalsy(); + } + + for ( let stageIndex = 0; stageIndex < 2; stageIndex += 1 ) { + await stages.nth( stageIndex ).scrollIntoViewIfNeeded(); + } + for ( const portrait of expected ) { + await expect + .poll( + () => requested.find( ( url ) => portrait.candidates.includes( new URL( url ).pathname ) ), + { timeout: 10_000 }, + ) + .toMatch( /-384\.avif$/ ); + } +} ); diff --git a/tests/php/BlockRenderingTest.php b/tests/php/BlockRenderingTest.php index 06d1d75..f56b7d7 100644 --- a/tests/php/BlockRenderingTest.php +++ b/tests/php/BlockRenderingTest.php @@ -367,7 +367,7 @@ class BlockRenderingTest extends WP_UnitTestCase { 'music' => 'the-no-names-musician-cutout.png', 'podcasts' => 'alter-ego-podcasts.png', 'life' => 'alter-ego-life.png', - 'gaming' => 'alter-ego-gaming.png', + 'gaming' => 'alter-ego-gaming-half-body.png', ); foreach ( $expected as $slug => $filename ) { $this->assertSame( 'assets/images/' . $filename, chrnx_get_topic_art_asset( $slug ) ); @@ -628,6 +628,9 @@ class BlockRenderingTest extends WP_UnitTestCase { $this->assertStringContainsString( 'loading="eager"', $output ); $this->assertStringContainsString( 'fetchpriority="high"', $output ); $this->assertStringContainsString( 'decoding="async"', $output ); + $this->assertStringContainsString( 'type="image/avif"', $output ); + $this->assertStringContainsString( 'type="image/webp"', $output ); + $this->assertStringContainsString( 'srcset="', $output ); $unsafe = render_block( array( @@ -651,6 +654,59 @@ class BlockRenderingTest extends WP_UnitTestCase { ); $this->assertStringContainsString( 'width="1024"', $gaming ); $this->assertStringContainsString( 'height="1536"', $gaming ); + $this->assertStringContainsString( 'alter-ego-gaming-half-body', $gaming ); + } + + /** Topic heroes share the three-layer stage and unknown topics retain a safe labeled fallback. */ + public function test_topic_hero_uses_shared_stage_and_labels_unknown_fallbacks() { + $attributes = array( + 'topic' => 'future-topic', + 'headingLevel' => 2, + ); + ob_start(); + include get_theme_file_path( 'blocks/topic-hero/render.php' ); + $output = (string) ob_get_clean(); + + $this->assertStringContainsString( 'chrnx-topic-hero', $output ); + $this->assertStringContainsString( 'chrnx-character-stage', $output ); + $this->assertStringContainsString( '>Future Topic', $output ); + $this->assertMatchesRegularExpression( '/class="chrnx-topic-hero__fallback" aria-hidden="true"/', $output ); + $this->assertStringNotContainsString( 'loadHTML( '' . $output, LIBXML_NOERROR | LIBXML_NOWARNING ); + $xpath = new DOMXPath( $dom ); + $stage = $xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' )->item( 0 ); + $children = array(); + foreach ( $stage->childNodes as $child ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property. + if ( XML_ELEMENT_NODE === $child->nodeType ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property. + $children[] = $child; + } + } + $this->assertCount( 3, $children ); + $this->assertStringContainsString( 'chrnx-character-stage__atmosphere', $children[0]->getAttribute( 'class' ) ); + $this->assertSame( 'true', $children[0]->getAttribute( 'aria-hidden' ) ); + $this->assertStringContainsString( 'chrnx-character-stage__content', $children[1]->getAttribute( 'class' ) ); + $this->assertStringContainsString( 'chrnx-character-stage__art', $children[2]->getAttribute( 'class' ) ); + } + + /** Show archives use podcast art without replacing the visible show name. */ + public function test_show_archive_uses_podcasts_art_and_keeps_silicon_ranch_title() { + $show = get_term_by( 'slug', 'silicon-ranch', 'chrnx_show' ); + $this->assertInstanceOf( WP_Term::class, $show ); + $this->go_to( get_term_link( $show ) ); + + $output = render_block( + array( + 'blockName' => 'chrnx/topic-hero', + 'attrs' => array(), + ) + ); + + $this->assertStringContainsString( '>Silicon Ranch', $output ); + $this->assertStringContainsString( 'alter-ego-podcasts.png', $output ); + $this->assertStringNotContainsString( '>Podcasts', $output ); + $this->assertSame( 1, substr_count( $output, 'class="chrnx-character-stage"' ) ); } /** Subscribe CTA is exactly empty until a published Page is configured. */ diff --git a/tests/php/PatternsTest.php b/tests/php/PatternsTest.php index b0e4dfc..297bccd 100644 --- a/tests/php/PatternsTest.php +++ b/tests/php/PatternsTest.php @@ -84,11 +84,11 @@ class PatternsTest extends WP_UnitTestCase { $content = $this->render_pattern( get_theme_file_path( 'patterns/home-music.php' ) ); $this->assertStringContainsString( "chrnx_get_topic_portrait_markup( 'music-collage'", $source ); - $this->assertStringContainsString( 'chrnx-home-music__collage-layer', $content ); + $this->assertStringContainsString( 'chrnx-character-stage__atmosphere', $content ); $this->assertStringContainsString( 'the-no-names-collage-384.avif 384w', $content ); $this->assertStringContainsString( 'the-no-names-collage-768.webp 768w', $content ); $this->assertStringContainsString( 'sizes="(max-width: 599px) 100vw, 720px"', $content ); - $this->assertMatchesRegularExpression( '/class="chrnx-home-music__collage"[^>]*loading="lazy"[^>]*alt=""/', $content ); + $this->assertMatchesRegularExpression( '/class="chrnx-character-stage__collage"[^>]*loading="lazy"[^>]*alt=""/', $content ); $this->assertStringContainsString( 'the-no-names-musician-cutout.png', $content ); $this->assertLessThan( strpos( $content, 'the-no-names-musician-cutout.png' ), @@ -197,6 +197,176 @@ class PatternsTest extends WP_UnitTestCase { } } + /** Section openings expose one block-valid three-layer character stage. */ + public function test_character_led_patterns_use_the_exact_shared_stage_api() { + $contracts = array( + 'home-projects' => array( + 'heading' => 'Selected work', + 'order' => array( 'Selected work', 'Expressive Tea', 'Ailed', 'Published research' ), + 'art' => 'alter-ego-code.png', + 'art_alt' => '', + 'atmosphere' => 'chrnx-character-stage__secondary-art', + ), + 'home-music' => array( + 'heading' => 'The No Names', + 'order' => array( 'The No Names', 'Grunge mexicano para cerebros que no se callan.', 'Un proyecto de banda activo hecho en Sinaloa: estudio crudo, cero live.' ), + 'art' => 'the-no-names-musician-cutout.png', + 'art_alt' => 'The No Names musician portrait', + 'atmosphere' => 'chrnx-character-stage__collage', + ), + 'music-landing' => array( + 'heading' => 'The No Names', + 'order' => array( 'The No Names', 'Grunge mexicano para cerebros que no se callan.', 'The No Names es una banda activa', 'El proceso usa generative AI' ), + 'art' => 'the-no-names-musician-cutout.png', + 'art_alt' => 'The No Names musician portrait', + ), + 'podcast-landing' => array( + 'heading' => 'Podcasts', + 'order' => array( 'Podcasts' ), + 'art' => 'alter-ego-podcasts.png', + 'art_alt' => '', + ), + 'about' => array( + 'heading' => 'About', + 'order' => array( 'About', 'I work as Lead Developer @Expressive Tea', 'I am a published researcher.', 'I am an autistic Level 1 software developer and researcher.', 'Beyond the work', 'I am the father of three wonderful children' ), + 'art' => 'alter-ego-life.png', + 'art_alt' => '', + 'facets' => array( 'alter-ego-literature.png', 'alter-ego-gaming-half-body.png' ), + ), + ); + + foreach ( $contracts as $name => $contract ) { + $content = $this->render_pattern( get_theme_file_path( 'patterns/' . $name . '.php' ) ); + $dom = $this->load_html_fragment( $content ); + $xpath = new DOMXPath( $dom ); + $stages = $xpath->query( '//*[contains(concat(" ", normalize-space(@class), " "), " chrnx-character-stage ")]' ); + + $this->assertCount( 1, $stages, $name ); + $stage = $stages->item( 0 ); + $children = array(); + foreach ( $stage->childNodes as $child ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property. + if ( XML_ELEMENT_NODE === $child->nodeType ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOM API property. + $children[] = $child; + } + } + $this->assertCount( 3, $children, $name ); + $this->assert_element_has_class( $children[0], 'chrnx-character-stage__atmosphere', $name ); + $this->assertSame( 'true', $children[0]->getAttribute( 'aria-hidden' ), $name ); + $this->assert_element_has_class( $children[1], 'chrnx-character-stage__content', $name ); + $this->assert_element_has_class( $children[2], 'chrnx-character-stage__art', $name ); + $this->assertCount( 1, $xpath->query( './/picture', $children[2] ), $name ); + $art_markup = $dom->saveHTML( $children[2] ); + $this->assertStringContainsString( $contract['art'], $art_markup, $name ); + $this->assertStringContainsString( 'type="image/avif"', $art_markup, $name ); + $this->assertStringContainsString( 'type="image/webp"', $art_markup, $name ); + $this->assertStringContainsString( 'srcset="', $art_markup, $name ); + $this->assertStringContainsString( 'loading="lazy"', $art_markup, $name ); + $this->assertStringContainsString( 'alt="' . $contract['art_alt'] . '"', $art_markup, $name ); + if ( '' === $contract['art_alt'] ) { + $this->assertStringContainsString( '