diff --git a/assets/css/components.css b/assets/css/components.css index bd974b8..078d4c4 100644 --- a/assets/css/components.css +++ b/assets/css/components.css @@ -1092,6 +1092,7 @@ html[data-theme="light"] .chrnx-home-music p { --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; @@ -1153,6 +1154,20 @@ html[data-theme="light"] .chrnx-home-music p { 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; } @@ -1242,17 +1257,18 @@ html[data-theme="light"] .chrnx-home-music p { .chrnx-music-landing .chrnx-character-stage__content > .chrnx-responsive-portrait:has(.chrnx-character-stage__collage) { position: absolute; z-index: 0; - inset: 0; - width: 100%; + 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: 1; + z-index: 2; } .chrnx-music-landing .chrnx-character-stage__collage { @@ -1283,11 +1299,21 @@ html[data-theme="light"] .chrnx-home-music p { .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, @@ -1385,6 +1411,11 @@ html[data-theme="light"] .chrnx-home-music p { 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) { diff --git a/tests/e2e/visual-states.spec.mjs b/tests/e2e/visual-states.spec.mjs index 77afa7e..ae77e31 100644 --- a/tests/e2e/visual-states.spec.mjs +++ b/tests/e2e/visual-states.spec.mjs @@ -66,11 +66,16 @@ async function readCharacterGeometry( stage ) { first.right > second.left + 1 && first.top < second.bottom - 1 && first.bottom > second.top + 1; - const following = [ - ...element.parentElement.querySelectorAll( - '.chrnx-release-card, .chrnx-podcast-card, .chrnx-character-facets', - ), - ].filter( ( candidate ) => ! element.contains( candidate ) ); + 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, @@ -83,6 +88,7 @@ async function readCharacterGeometry( stage ) { 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, @@ -135,6 +141,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 ); @@ -777,6 +797,7 @@ 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' ] ) { @@ -817,6 +838,15 @@ test( 'character stage geometry, layering, effects, loading, and inspection capt } 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(); @@ -827,6 +857,32 @@ test( 'character stage geometry, layering, effects, loading, and inspection capt 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 ); @@ -849,6 +905,7 @@ test( 'character stage geometry, layering, effects, loading, and inspection capt 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' ] ) { @@ -888,7 +945,7 @@ test( 'character stage long copy grows safely with AA contrast in both themes', 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 background = window.getComputedStyle( element ).backgroundColor; + const copySurfaceStyle = window.getComputedStyle( content, '::before' ); return { stageBottom: stageRect.bottom, contentBottom: contentRect.bottom, @@ -900,7 +957,9 @@ test( 'character stage long copy grows safely with AA contrast in both themes', ) : Number.POSITIVE_INFINITY, foregrounds, - background, + background: copySurfaceStyle.backgroundColor, + backgroundImage: copySurfaceStyle.backgroundImage, + copySurfaceContent: copySurfaceStyle.content, }; } ); @@ -911,9 +970,13 @@ test( 'character stage long copy grows safely with AA contrast in both themes', 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( - contrastRatio( foreground, result.background ), + conservativeOverlayContrast( foreground, result.background ), `${ surface.name } ${ width }px ${ theme } contrast`, ).toBeGreaterThanOrEqual( 4.5 ); } @@ -926,6 +989,7 @@ test( 'character stage long copy grows safely with AA contrast in both themes', 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 ), @@ -978,3 +1042,63 @@ test( 'character stage is static under reduced motion and visible without JavaSc } } } ); + +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/smoke/visual-integration.test.mjs b/tests/smoke/visual-integration.test.mjs index 1040357..be7f013 100644 --- a/tests/smoke/visual-integration.test.mjs +++ b/tests/smoke/visual-integration.test.mjs @@ -274,6 +274,7 @@ test( 'character-led openings share the exact stage class contract', () => { test( 'character stages define the shared mockup effect and responsive geometry', () => { const components = read( 'assets/css/components.css' ); + const visualStates = read( 'tests/e2e/visual-states.spec.mjs' ); for ( const token of [ '--chrnx-character-accent', @@ -289,4 +290,10 @@ test( 'character stages define the shared mockup effect and responsive geometry' assert.match( components, /\.chrnx-character-stage__art\s*>\s*\.chrnx-responsive-portrait/ ); assert.match( components, /@media \(max-width:\s*780px\)[\s\S]*?\.chrnx-character-stage\s*\{[\s\S]*?grid-template-columns:\s*1fr/ ); assert.match( components, /@media \(prefers-reduced-motion:\s*reduce\)[\s\S]*?\.chrnx-character-stage/ ); + assert.match( components, /--chrnx-character-copy-surface/ ); + assert.match( components, /\.chrnx-music-landing \.chrnx-character-stage__content\s*>\s*\.chrnx-responsive-portrait:has\(\.chrnx-character-stage__collage\)[\s\S]*?inset:\s*0/ ); + for ( const timeout of [ '180_000', '120_000', '60_000' ] ) { + assert.match( visualStates, new RegExp( `test\\.setTimeout\\( ${ timeout } \\)` ) ); + } + assert.match( visualStates, /character stage below-fold derivatives wait for approach/ ); } );