feat: 1.统一右侧抽屉关闭按钮布局 2.统一 UI 组件为 Ant Design 移除 radix-ui、floating-ui 组件 3. 修复 ESLint 文件格式错误的问题
This commit is contained in:
@@ -50,7 +50,11 @@ import React, { useEffect, useRef } from 'react';
|
||||
const hexToRgb = (hex) => {
|
||||
if (!hex) return { r: 99, g: 102, b: 241 }; // brand-primary 兜底
|
||||
let h = hex.replace('#', '').trim();
|
||||
if (h.length === 3) h = h.split('').map((c) => c + c).join('');
|
||||
if (h.length === 3)
|
||||
h = h
|
||||
.split('')
|
||||
.map((c) => c + c)
|
||||
.join('');
|
||||
if (h.length === 8) h = h.slice(0, 6); // 忽略 alpha
|
||||
if (!/^[0-9a-fA-F]{6}$/.test(h)) return { r: 99, g: 102, b: 241 };
|
||||
const num = parseInt(h, 16);
|
||||
@@ -62,7 +66,12 @@ const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
|
||||
// 三阶 Bezier 求 t 处坐标(给触手沿曲线放置吸盘用)
|
||||
const bezierPoint = (p0, p1, p2, p3, t) => {
|
||||
const mt = 1 - t;
|
||||
return mt * mt * mt * p0 + 3 * mt * mt * t * p1 + 3 * mt * t * t * p2 + t * t * t * p3;
|
||||
return (
|
||||
mt * mt * mt * p0 +
|
||||
3 * mt * mt * t * p1 +
|
||||
3 * mt * t * t * p2 +
|
||||
t * t * t * p3
|
||||
);
|
||||
};
|
||||
|
||||
// ─── 粒子类 ──────────────────────────────────────────────────
|
||||
@@ -74,7 +83,11 @@ class Plankton {
|
||||
}
|
||||
reset(randomY = false) {
|
||||
this.x = Math.random() * this.w;
|
||||
this.y = randomY ? Math.random() * this.h : Math.random() < 0.5 ? -10 : this.h + 10;
|
||||
this.y = randomY
|
||||
? Math.random() * this.h
|
||||
: Math.random() < 0.5
|
||||
? -10
|
||||
: this.h + 10;
|
||||
this.size = Math.random() * 1.5 + 0.5;
|
||||
this.vx = (Math.random() - 0.5) * 0.2;
|
||||
this.vy = (Math.random() - 0.5) * 0.15;
|
||||
@@ -85,7 +98,13 @@ class Plankton {
|
||||
this.x += this.vx;
|
||||
this.y += this.vy + Math.sin(this.phase) * 0.15;
|
||||
this.phase += 0.015;
|
||||
if (this.x < -20 || this.x > this.w + 20 || this.y < -20 || this.y > this.h + 20) this.reset();
|
||||
if (
|
||||
this.x < -20 ||
|
||||
this.x > this.w + 20 ||
|
||||
this.y < -20 ||
|
||||
this.y > this.h + 20
|
||||
)
|
||||
this.reset();
|
||||
}
|
||||
resize(w, h) {
|
||||
this.w = w;
|
||||
@@ -153,7 +172,13 @@ class Bubble {
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${this.alpha * 0.5})`;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x - this.size * 0.3, y - this.size * 0.3, this.size * 0.28, 0, Math.PI * 2);
|
||||
ctx.arc(
|
||||
x - this.size * 0.3,
|
||||
y - this.size * 0.3,
|
||||
this.size * 0.28,
|
||||
0,
|
||||
Math.PI * 2,
|
||||
);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
@@ -287,10 +312,19 @@ class LifePulse {
|
||||
// 从屏幕外随机一侧触发
|
||||
const side = Math.floor(Math.random() * 4);
|
||||
const m = 100;
|
||||
if (side === 0) { this.ox = Math.random() * this.w; this.oy = -m; }
|
||||
else if (side === 1) { this.ox = this.w + m; this.oy = Math.random() * this.h; }
|
||||
else if (side === 2) { this.ox = Math.random() * this.w; this.oy = this.h + m; }
|
||||
else { this.ox = -m; this.oy = Math.random() * this.h; }
|
||||
if (side === 0) {
|
||||
this.ox = Math.random() * this.w;
|
||||
this.oy = -m;
|
||||
} else if (side === 1) {
|
||||
this.ox = this.w + m;
|
||||
this.oy = Math.random() * this.h;
|
||||
} else if (side === 2) {
|
||||
this.ox = Math.random() * this.w;
|
||||
this.oy = this.h + m;
|
||||
} else {
|
||||
this.ox = -m;
|
||||
this.oy = Math.random() * this.h;
|
||||
}
|
||||
this.active = true;
|
||||
this.startT = now;
|
||||
this.maxR = Math.hypot(this.w, this.h) * 0.7;
|
||||
@@ -307,7 +341,14 @@ class LifePulse {
|
||||
const alpha = p < 0.5 ? p * 2 * 0.35 : (1 - p) * 2 * 0.35;
|
||||
const inner = Math.max(0, radius - 50);
|
||||
const outer = radius + 50;
|
||||
const grad = ctx.createRadialGradient(this.ox, this.oy, inner, this.ox, this.oy, outer);
|
||||
const grad = ctx.createRadialGradient(
|
||||
this.ox,
|
||||
this.oy,
|
||||
inner,
|
||||
this.ox,
|
||||
this.oy,
|
||||
outer,
|
||||
);
|
||||
grad.addColorStop(0, rgba(color, 0));
|
||||
grad.addColorStop(0.5, rgba(color, alpha));
|
||||
grad.addColorStop(1, rgba(color, 0));
|
||||
@@ -330,7 +371,8 @@ const readTheme = () => {
|
||||
};
|
||||
const detectDark = () => {
|
||||
if (document.documentElement.classList.contains('dark')) return true;
|
||||
if (document.body && document.body.getAttribute('theme-mode') === 'dark') return true;
|
||||
if (document.body && document.body.getAttribute('theme-mode') === 'dark')
|
||||
return true;
|
||||
// ThemeContext 在浅色模式会移除上面两个标记,此时必须先看用户显式选择,
|
||||
// 否则"强制浅色 + 系统深色"会被 prefers-color-scheme 兜底误判成暗色
|
||||
try {
|
||||
@@ -340,7 +382,10 @@ const detectDark = () => {
|
||||
} catch {
|
||||
// localStorage 不可用(隐私模式等)时继续走系统偏好
|
||||
}
|
||||
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
return (
|
||||
window.matchMedia &&
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
);
|
||||
};
|
||||
|
||||
// ─── 组件 ─────────────────────────────────────────────────
|
||||
@@ -359,9 +404,10 @@ const OceanBackground = () => {
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, 1.5); // 上限避免移动端开销
|
||||
|
||||
// 设备 / 偏好检测
|
||||
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent,
|
||||
);
|
||||
const isMobile =
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent,
|
||||
);
|
||||
const reducedMotion =
|
||||
window.matchMedia &&
|
||||
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
@@ -393,9 +439,18 @@ const OceanBackground = () => {
|
||||
};
|
||||
|
||||
// 实例化
|
||||
const plankton = Array.from({ length: COUNT.plankton }, () => new Plankton(width, height));
|
||||
const sparkles = Array.from({ length: COUNT.sparkle }, () => new Sparkle(width, height));
|
||||
const bubbles = Array.from({ length: COUNT.bubble }, () => new Bubble(width, height));
|
||||
const plankton = Array.from(
|
||||
{ length: COUNT.plankton },
|
||||
() => new Plankton(width, height),
|
||||
);
|
||||
const sparkles = Array.from(
|
||||
{ length: COUNT.sparkle },
|
||||
() => new Sparkle(width, height),
|
||||
);
|
||||
const bubbles = Array.from(
|
||||
{ length: COUNT.bubble },
|
||||
() => new Bubble(width, height),
|
||||
);
|
||||
const pillars = Array.from(
|
||||
{ length: COUNT.pillar },
|
||||
(_, i) => new LightPillar(width, i, COUNT.pillar || 1),
|
||||
@@ -445,7 +500,10 @@ const OceanBackground = () => {
|
||||
const r1 = Math.max(width, height) * 0.75;
|
||||
const vig = ctx.createRadialGradient(cx, cy, r0, cx, cy, r1);
|
||||
vig.addColorStop(0, 'rgba(0, 0, 0, 0)');
|
||||
vig.addColorStop(1, isDark ? 'rgba(0, 0, 0, 0.55)' : 'rgba(0, 10, 25, 0.35)');
|
||||
vig.addColorStop(
|
||||
1,
|
||||
isDark ? 'rgba(0, 0, 0, 0.55)' : 'rgba(0, 10, 25, 0.35)',
|
||||
);
|
||||
ctx.fillStyle = vig;
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user