From 1275903bf3c3e818a663788491363fc70a978d4d Mon Sep 17 00:00:00 2001 From: bcotrim Date: Mon, 3 Aug 2026 11:11:24 +0100 Subject: [PATCH 1/4] Parameterize EmptyBackground size and containment --- .../session-view/empty-background/index.tsx | 50 +++++++++++++------ .../empty-background/style.module.css | 6 +++ 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/apps/ui/src/ui-classic/components/session-view/empty-background/index.tsx b/apps/ui/src/ui-classic/components/session-view/empty-background/index.tsx index 9d33a4ac53..073af3c303 100644 --- a/apps/ui/src/ui-classic/components/session-view/empty-background/index.tsx +++ b/apps/ui/src/ui-classic/components/session-view/empty-background/index.tsx @@ -2,9 +2,8 @@ import { useEffect, useRef } from 'react'; import styles from './style.module.css'; import logoSrc from './wordpress-logo.webp'; -const SIZE = 320; -const PAD = 130; -const CANVAS_SIZE = SIZE + PAD * 2; +const DEFAULT_LOGO_SIZE = 320; +const DEFAULT_PADDING = 130; const RES = 6; const RECT_SIZE = 4; const MAX_DPR = 2; @@ -93,7 +92,25 @@ type ActiveRipple = { maxRadiusSquared: number; }; -export function EmptyBackground() { +interface EmptyBackgroundProps { + /** Rendered logo size in CSS pixels. */ + logoSize?: number; + /** Room around the logo for displaced particles to roam. */ + padding?: number; + /** + * Default true: clip painting to the host box (`contain: paint`). Set + * false when the host box is smaller than the canvas so the effect can + * spread beyond it without getting cut off. + */ + contained?: boolean; +} + +export function EmptyBackground( { + logoSize = DEFAULT_LOGO_SIZE, + padding = DEFAULT_PADDING, + contained = true, +}: EmptyBackgroundProps = {} ) { + const canvasSize = logoSize + padding * 2; const canvasRef = useRef< HTMLCanvasElement >( null ); useEffect( () => { @@ -104,9 +121,9 @@ export function EmptyBackground() { const canvasElement = canvas; const dpr = Math.min( window.devicePixelRatio || 1, MAX_DPR ); - canvasElement.width = Math.round( CANVAS_SIZE * dpr ); - canvasElement.height = Math.round( CANVAS_SIZE * dpr ); - canvasElement.style.setProperty( '--empty-background-canvas-size', `${ CANVAS_SIZE }px` ); + canvasElement.width = Math.round( canvasSize * dpr ); + canvasElement.height = Math.round( canvasSize * dpr ); + canvasElement.style.setProperty( '--empty-background-canvas-size', `${ canvasSize }px` ); const ctx = canvasElement.getContext( '2d', { alpha: true } ); if ( ! ctx ) { @@ -168,7 +185,7 @@ export function EmptyBackground() { bounds.top = rect.top; bounds.right = rect.right; bounds.bottom = rect.bottom; - bounds.scale = rect.width > 0 ? CANVAS_SIZE / rect.width : 1; + bounds.scale = rect.width > 0 ? canvasSize / rect.width : 1; } function clearScheduledWave() { @@ -199,7 +216,7 @@ export function EmptyBackground() { } function drawStatic() { - context.clearRect( 0, 0, CANVAS_SIZE, CANVAS_SIZE ); + context.clearRect( 0, 0, canvasSize, canvasSize ); context.fillStyle = BASE_COLOR; for ( let i = 0; i < particles.length; i++ ) { @@ -289,7 +306,7 @@ export function EmptyBackground() { const pointerEase = scaleEasingForFrameFactor( POINTER_EASE, frameFactor ); const spring = SPRING * frameFactor; const damping = Math.pow( DAMPING, frameFactor ); - context.clearRect( 0, 0, CANVAS_SIZE, CANVAS_SIZE ); + context.clearRect( 0, 0, canvasSize, canvasSize ); const activeRipples: ActiveRipple[] = []; for ( let i = ripples.length - 1; i >= 0; i-- ) { @@ -492,11 +509,11 @@ export function EmptyBackground() { offCtx.drawImage( img, 0, 0 ); const { data } = offCtx.getImageData( 0, 0, img.width, img.height ); - const scale = Math.min( SIZE / img.width, SIZE / img.height ) * 0.92; + const scale = Math.min( logoSize / img.width, logoSize / img.height ) * 0.92; const drawW = img.width * scale; const drawH = img.height * scale; - const offsetX = ( CANVAS_SIZE - drawW ) / 2; - const offsetY = ( CANVAS_SIZE - drawH ) / 2; + const offsetX = ( canvasSize - drawW ) / 2; + const offsetY = ( canvasSize - drawH ) / 2; for ( let y = 0; y < drawH; y += RES ) { for ( let x = 0; x < drawW; x += RES ) { @@ -666,10 +683,13 @@ export function EmptyBackground() { resizeObserver?.disconnect(); intersectionObserver?.disconnect(); }; - }, [] ); + }, [ canvasSize, logoSize ] ); return ( -