import { useState, useEffect, useRef, useMemo } from "react"; import { toast } from "sonner"; import { useStrokeDrawAnimation } from "@/lib/useStrokeDrawAnimation"; import { buildPeqSvgCurveData, sampleCombinedPeqMagnitudeDb, } from "@/lib/peqAudio"; import type { PeqEqUi } from "../constants"; import { eqInterp } from "../utils"; import { PeqUndoButton } from "./PeqUndoButton"; /* ── Y 轴刻度范围(±dB)可选项与持久化 ── */ const Y_RANGE_OPTIONS = [6, 12, 15, 20] as const; type YRangeDb = (typeof Y_RANGE_OPTIONS)[number]; const DEFAULT_Y_RANGE_DB: YRangeDb = 12; const Y_RANGE_STORAGE_KEY = "x9-peq-chart-y-db-max"; /** 每档范围的网格整数步长(均可整除边界,确保标签为整数) */ const Y_RANGE_STEP: Record = { 6: 2, 12: 3, 15: 5, 20: 5 }; function loadYRangeDb(): YRangeDb { try { const raw = Number(localStorage.getItem(Y_RANGE_STORAGE_KEY)); if (Y_RANGE_OPTIONS.includes(raw as YRangeDb)) return raw as YRangeDb; } catch { /* localStorage 不可用时回退默认值 */ } return DEFAULT_Y_RANGE_DB; } /* ── Legend indicator ── */ function LegendCurveIndicator({ loading, color, }: { loading: boolean; color: string; }) { if (loading) { return (