feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes

This commit is contained in:
Yun Chan 2026-11-14 11:51:41 +09:00
parent 01ef3293cf
commit 66b6b45ba9
399 changed files with 17828 additions and 11330 deletions

View file

@ -6,10 +6,11 @@
import React, { useRef, useEffect } from 'react'
import { Box, type BoxProps } from '@mui/material'
import { d3roRadius } from '../../theme'
import { RAW } from '../../theme-raw'
/** SSR/무-문서 환경 폴백 — 테마 원시값에서 가져온다(하드코딩 hex 금지). */
const WAVE_FALLBACK = RAW.dark.gradient
import {
buildWaveLinearGradient,
readWaveGradientColors,
stepSmoothedAudioLevel,
} from './wave-math'
export interface AudioVisualizerBarProps extends Omit<BoxProps, 'children'> {
/** Real-time normalized audio RMS level (0.0 to 1.0) */
@ -26,19 +27,6 @@ export interface AudioVisualizerBarProps extends Omit<BoxProps, 'children'> {
active?: boolean
}
function readVisualizerColors(): [string, string, string, string] {
const fallback = [WAVE_FALLBACK.wave1, WAVE_FALLBACK.wave2, WAVE_FALLBACK.wave3, WAVE_FALLBACK.wave4]
if (typeof document === 'undefined') return [fallback[0], fallback[1], fallback[2], fallback[3]]
const style = getComputedStyle(document.documentElement)
const read = (name: string, fb: string): string => style.getPropertyValue(name).trim() || fb
return [
read('--d3-gradient-wave1', fallback[0]),
read('--d3-gradient-wave2', fallback[1]),
read('--d3-gradient-wave3', fallback[2]),
read('--d3-gradient-wave4', fallback[3]),
]
}
export function AudioVisualizerBar({
audioLevel = 0,
bars = 32,
@ -66,9 +54,14 @@ export function AudioVisualizerBar({
let raf = 0
let width = 0
let heightPx = height
let colors = readVisualizerColors()
let colors = readWaveGradientColors()
let gradient: CanvasGradient | null = null
let frame = 0
const rebuildGradient = (): void => {
gradient = width > 0 ? buildWaveLinearGradient(ctx, width, colors) : null
}
const resize = (): void => {
const dpr = window.devicePixelRatio || 1
width = canvas.clientWidth
@ -76,6 +69,7 @@ export function AudioVisualizerBar({
canvas.width = Math.max(1, Math.round(width * dpr))
canvas.height = Math.max(1, Math.round(heightPx * dpr))
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
rebuildGradient()
}
const observer = new ResizeObserver(resize)
@ -85,36 +79,37 @@ export function AudioVisualizerBar({
const render = (): void => {
frame += 1
if (frame % 60 === 0) {
colors = readVisualizerColors()
const next = readWaveGradientColors()
if (next.join() !== colors.join()) {
colors = next
rebuildGradient()
}
}
// Smooth audio RMS response
const target = Math.min(1, levelRef.current)
const k = target > smoothedRef.current ? 0.35 : 0.08
smoothedRef.current += (target - smoothedRef.current) * k
// Smooth audio RMS response (NaN/범위 밖 입력 시 상태 오염 방지)
smoothedRef.current = stepSmoothedAudioLevel(
smoothedRef.current,
levelRef.current,
0.35,
0.08,
)
ctx.clearRect(0, 0, width, heightPx)
if (width <= 0 || heightPx <= 0) {
const totalStep = barWidth + gap
const safeBars = Number.isFinite(bars) ? Math.max(0, Math.floor(bars)) : 0
const actualBars = totalStep > 0 ? Math.min(safeBars, Math.floor(width / totalStep)) : 0
if (!gradient || width <= 0 || heightPx <= 0 || totalStep <= 0 || barWidth <= 0 || actualBars <= 0) {
raf = requestAnimationFrame(render)
return
}
const totalStep = barWidth + gap
const actualBars = Math.min(bars, Math.floor(width / totalStep))
const totalWidth = actualBars * totalStep - gap
const startX = (width - totalWidth) / 2
const centerY = heightPx / 2
const t = performance.now() / 1000
// Create harmonious gradient for bars
const grad = ctx.createLinearGradient(0, 0, width, 0)
grad.addColorStop(0, colors[0])
grad.addColorStop(0.35, colors[1])
grad.addColorStop(0.7, colors[2])
grad.addColorStop(1, colors[3])
ctx.fillStyle = grad
ctx.fillStyle = gradient
for (let i = 0; i < actualBars; i++) {
const x = startX + i * totalStep

View file

@ -7,10 +7,11 @@
import { useRef, useEffect } from 'react'
import { Box } from '@mui/material'
import { RAW } from '../../theme-raw'
/** SSR/무-문서 환경 폴백 — 테마 원시값에서 가져온다(하드코딩 hex 금지). */
const WAVE_FALLBACK = RAW.dark.gradient
import {
buildWaveLinearGradient,
readWaveGradientColors,
stepSmoothedAudioLevel,
} from './wave-math'
interface GradientWaveProps {
/** 실시간 오디오 레벨 0~1 (없으면 유휴 애니메이션만) */
@ -29,21 +30,6 @@ interface GradientWaveProps {
height?: number | string
}
/** :root에 주입된 웨이브 그라디언트 스톱을 읽는다 */
function readWaveColors(): [string, string, string, string] {
const fallback = [WAVE_FALLBACK.wave1, WAVE_FALLBACK.wave2, WAVE_FALLBACK.wave3, WAVE_FALLBACK.wave4]
if (typeof document === 'undefined') return [fallback[0], fallback[1], fallback[2], fallback[3]]
const style = getComputedStyle(document.documentElement)
const read = (name: string, fb: string): string =>
style.getPropertyValue(name).trim() || fb
return [
read('--d3-gradient-wave1', fallback[0]),
read('--d3-gradient-wave2', fallback[1]),
read('--d3-gradient-wave3', fallback[2]),
read('--d3-gradient-wave4', fallback[3]),
]
}
/** 결정적 의사난수 (바 인덱스별 고정 시드) */
function seeded(i: number): number {
const x = Math.sin(i * 127.1 + 311.7) * 43758.5453
@ -76,17 +62,16 @@ export function GradientWave({
let raf = 0
let width = 0
let heightPx = 0
let colors = readWaveColors()
let colors = readWaveGradientColors()
let gradient: CanvasGradient | null = null
let frame = 0
const start = performance.now()
const safeIdleAmplitude = Number.isFinite(idleAmplitude) ? Math.max(0, Math.min(1, idleAmplitude)) : 0
const safeSpeed = Number.isFinite(speed) ? Math.max(0, speed) : 1
const safeGlow = Number.isFinite(glow) ? Math.max(0, glow) : 0
const rebuildGradient = (): void => {
gradient = ctx.createLinearGradient(0, 0, width, 0)
gradient.addColorStop(0, colors[0])
gradient.addColorStop(0.38, colors[1])
gradient.addColorStop(0.7, colors[2])
gradient.addColorStop(1, colors[3])
gradient = width > 0 ? buildWaveLinearGradient(ctx, width, colors) : null
}
const resize = (): void => {
@ -107,33 +92,36 @@ export function GradientWave({
frame += 1
// 테마 전환 대응: 1초마다 색 재판독
if (frame % 60 === 0) {
const next = readWaveColors()
const next = readWaveGradientColors()
if (next.join() !== colors.join()) {
colors = next
rebuildGradient()
}
}
// 레벨 스무딩 (상승 빠르게, 하강 느리게)
const target = Math.min(1, levelRef.current)
const k = target > smoothedRef.current ? 0.4 : 0.08
smoothedRef.current += (target - smoothedRef.current) * k
// 레벨 스무딩 (상승 빠르게, 하강 느리게; NaN/범위 밖 방어)
smoothedRef.current = stepSmoothedAudioLevel(
smoothedRef.current,
levelRef.current,
0.4,
0.08,
)
ctx.clearRect(0, 0, width, heightPx)
if (!gradient || width <= 0) {
const step = barWidth + barGap
if (!gradient || width <= 0 || heightPx <= 0 || step <= 0 || barWidth <= 0) {
raf = requestAnimationFrame(render)
return
}
const t = ((performance.now() - start) / 1000) * speed
const step = barWidth + barGap
const t = ((performance.now() - start) / 1000) * safeSpeed
const count = Math.max(1, Math.floor(width / step))
const centerY = heightPx / 2
const maxHalf = heightPx / 2 - 1
const maxHalf = Math.max(1.5, heightPx / 2 - 1)
ctx.fillStyle = gradient
if (glow > 0) {
ctx.shadowBlur = glow
if (safeGlow > 0) {
ctx.shadowBlur = safeGlow
ctx.shadowColor = colors[1]
}
@ -144,7 +132,7 @@ export function GradientWave({
const idle =
(Math.sin(t * 1.4 + i * 0.35) * 0.5 + 0.5) * 0.55 +
(Math.sin(t * 0.7 + i * 0.11 + s * 6.28) * 0.5 + 0.5) * 0.45
const envelope = idleAmplitude * (0.25 + idle * 0.75) + smoothedRef.current * (0.4 + s * 0.6)
const envelope = safeIdleAmplitude * (0.25 + idle * 0.75) + smoothedRef.current * (0.4 + s * 0.6)
const half = Math.max(1.5, Math.min(1, envelope) * maxHalf)
const radius = Math.min(barWidth / 2, half)
ctx.beginPath()

View file

@ -5,7 +5,7 @@
import React from 'react'
import { Box, Typography } from '@mui/material'
import { d3roPalette, d3roRadius, d3roShadow, typoSx } from '../../theme'
import { d3roFocusRing, d3roPalette, d3roRadius, d3roShadow, typoSx } from '../../theme'
export interface SegmentOption<T extends string = string> {
value: T
@ -20,6 +20,7 @@ export interface SegmentControlProps<T extends string = string> {
items?: SegmentOption<T>[]
value: T
onChange: (value: T) => void
ariaLabel?: string
size?: 'small' | 'medium'
sx?: object
}
@ -29,6 +30,7 @@ export function SegmentControl<T extends string = string>({
items,
value,
onChange,
ariaLabel,
size = 'medium',
sx,
}: SegmentControlProps<T>): React.ReactElement {
@ -37,6 +39,8 @@ export function SegmentControl<T extends string = string>({
return (
<Box
role="tablist"
aria-label={ariaLabel}
sx={{
display: 'inline-flex',
alignItems: 'center',
@ -53,7 +57,16 @@ export function SegmentControl<T extends string = string>({
return (
<Box
key={opt.value}
role="tab"
aria-selected={isSelected}
tabIndex={isSelected ? 0 : -1}
onClick={() => onChange(opt.value)}
onKeyDown={(e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault()
onChange(opt.value)
}
}}
sx={{
display: 'flex',
alignItems: 'center',
@ -72,6 +85,7 @@ export function SegmentControl<T extends string = string>({
color: d3roPalette.text.primary,
bgcolor: isSelected ? d3roPalette.glass.raised : d3roPalette.glass.surface,
},
'&:focus-visible': d3roFocusRing,
'&:active': {
transform: 'scale(0.97)',
},

View file

@ -0,0 +1,53 @@
import { RAW } from '../../theme-raw'
/** SSR/무-문서 환경 폴백 — 테마 원시값에서 가져온다(하드코딩 hex 금지). */
const WAVE_FALLBACK = RAW.dark.gradient
export type WaveGradientColors = readonly [string, string, string, string]
export function readWaveGradientColors(): WaveGradientColors {
const fallback: WaveGradientColors = [
WAVE_FALLBACK.wave1,
WAVE_FALLBACK.wave2,
WAVE_FALLBACK.wave3,
WAVE_FALLBACK.wave4,
]
if (typeof document === 'undefined') return fallback
const style = getComputedStyle(document.documentElement)
const read = (name: string, fb: string): string => style.getPropertyValue(name).trim() || fb
return [
read('--d3-gradient-wave1', fallback[0]),
read('--d3-gradient-wave2', fallback[1]),
read('--d3-gradient-wave3', fallback[2]),
read('--d3-gradient-wave4', fallback[3]),
]
}
export function clampAudioLevel(level: number): number {
return Number.isFinite(level) ? Math.max(0, Math.min(1, level)) : 0
}
export function stepSmoothedAudioLevel(
currentSmoothed: number,
rawLevel: number,
attack = 0.35,
release = 0.08,
): number {
const safeCurrent = Number.isFinite(currentSmoothed) ? Math.max(0, Math.min(1, currentSmoothed)) : 0
const target = clampAudioLevel(rawLevel)
const k = target > safeCurrent ? attack : release
return safeCurrent + (target - safeCurrent) * k
}
export function buildWaveLinearGradient(
ctx: CanvasRenderingContext2D,
width: number,
colors: WaveGradientColors,
): CanvasGradient {
const grad = ctx.createLinearGradient(0, 0, width, 0)
grad.addColorStop(0, colors[0])
grad.addColorStop(0.38, colors[1])
grad.addColorStop(0.7, colors[2])
grad.addColorStop(1, colors[3])
return grad
}