style: apply CHRNX character-led sections

This commit is contained in:
chrnx committed 2026-08-12 17:40:22 -05:00
1 parent 5518e3598a
commit 11ac0ac715
3 files changed
+643 -8

No files matched your search

+306
View File
@@ -8,6 +8,107 @@ 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',
} ),
),
];
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 = [
...element.parentElement.querySelectorAll(
'.chrnx-release-card, .chrnx-podcast-card, .chrnx-character-facets',
),
].filter( ( candidate ) => ! element.contains( candidate ) );
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,
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,
@@ -672,3 +773,208 @@ 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.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 stage.scrollIntoViewIfNeeded();
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 );
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' );
if ( surface.name === 'home-music' || surface.name === 'music' ) {
expect( geometry.collageLoading ).toBe( 'lazy' );
}
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' );
}
await testInfo.attach(
`character-stage-${ surface.name }-${ viewport.width }-${ theme }.png`,
{ body: await stage.screenshot(), contentType: 'image/png' },
);
}
}
}
} );
test( 'character stage long copy grows safely with AA contrast in both themes', async ( {
page,
}, testInfo ) => {
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 background = window.getComputedStyle( element ).backgroundColor;
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,
};
} );
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 );
for ( const foreground of result.foregrounds ) {
expect(
contrastRatio( 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.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(),
] );
}
}
} );
+19
View File
@@ -271,3 +271,22 @@ test( 'character-led openings share the exact stage class contract', () => {
assert.match( read( 'patterns/about.php' ), /chrnx-character-facets/ );
assert.match( read( 'blocks/topic-hero/render.php' ), /chrnx-topic-hero__fallback/ );
} );
test( 'character stages define the shared mockup effect and responsive geometry', () => {
const components = read( 'assets/css/components.css' );
for ( const token of [
'--chrnx-character-accent',
'--chrnx-character-halo',
'--chrnx-character-wash',
'--chrnx-character-shadow',
] ) {
assert.match( components, new RegExp( token ), `${ token } must be shared` );
}
assert.match( components, /\.chrnx-character-stage\s*\{[\s\S]*?grid-template-columns:\s*minmax\(0,\s*55fr\)\s+minmax\(0,\s*45fr\)/ );
assert.match( components, /\.chrnx-character-stage__atmosphere::before/ );
assert.match( components, /\.chrnx-character-stage__atmosphere::after/ );
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/ );
} );