fix(player): captcha canvas colors follow theme CSS variables (theme-3)
This commit is contained in:
@@ -15,6 +15,23 @@ const CHARS = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
|||||||
const CANVAS_W = 96;
|
const CANVAS_W = 96;
|
||||||
const CANVAS_H = 36;
|
const CANVAS_H = 36;
|
||||||
|
|
||||||
|
function cssVar(name: string, fallback: string): string {
|
||||||
|
const value = getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
||||||
|
return value || fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withAlpha(color: string, alpha: number): string {
|
||||||
|
const c = color.trim();
|
||||||
|
const rgb = c.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/);
|
||||||
|
if (rgb) return `rgba(${rgb[1]}, ${rgb[2]}, ${rgb[3]}, ${alpha})`;
|
||||||
|
const hex = c.match(/^#([0-9a-f]{6})$/i);
|
||||||
|
if (hex) {
|
||||||
|
const n = parseInt(hex[1], 16);
|
||||||
|
return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
function generateCode() {
|
function generateCode() {
|
||||||
let result = '';
|
let result = '';
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
@@ -31,18 +48,22 @@ function drawCaptcha() {
|
|||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
if (!ctx) return;
|
if (!ctx) return;
|
||||||
|
|
||||||
ctx.fillStyle = '#0d0d0d';
|
const bg = cssVar('--captcha-canvas-bg', '#0d0d0d');
|
||||||
|
const charBase = cssVar('--captcha-char', '#f0d875');
|
||||||
|
const noiseRgb = cssVar('--captcha-noise-rgb', '255, 255, 255');
|
||||||
|
|
||||||
|
ctx.fillStyle = bg;
|
||||||
ctx.fillRect(0, 0, CANVAS_W, CANVAS_H);
|
ctx.fillRect(0, 0, CANVAS_W, CANVAS_H);
|
||||||
|
|
||||||
for (let i = 0; i < 20; i++) {
|
for (let i = 0; i < 20; i++) {
|
||||||
ctx.fillStyle = `rgba(255, 255, 255, ${0.03 + Math.random() * 0.06})`;
|
ctx.fillStyle = `rgba(${noiseRgb}, ${0.03 + Math.random() * 0.06})`;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.arc(Math.random() * CANVAS_W, Math.random() * CANVAS_H, Math.random() * 1.8, 0, Math.PI * 2);
|
ctx.arc(Math.random() * CANVAS_W, Math.random() * CANVAS_H, Math.random() * 1.8, 0, Math.PI * 2);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
ctx.strokeStyle = `rgba(255, 255, 255, ${0.06 + Math.random() * 0.08})`;
|
ctx.strokeStyle = `rgba(${noiseRgb}, ${0.06 + Math.random() * 0.08})`;
|
||||||
ctx.lineWidth = 1;
|
ctx.lineWidth = 1;
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(Math.random() * CANVAS_W, Math.random() * CANVAS_H);
|
ctx.moveTo(Math.random() * CANVAS_W, Math.random() * CANVAS_H);
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
--bg-hover: #345E70;
|
--bg-hover: #345E70;
|
||||||
--bg-elevated: #2C5364;
|
--bg-elevated: #2C5364;
|
||||||
--bg-input: #162D36;
|
--bg-input: #162D36;
|
||||||
|
--captcha-canvas-bg: #162D36;
|
||||||
|
--captcha-char: #F4A261;
|
||||||
|
--captcha-noise-rgb: 255, 255, 255;
|
||||||
--bg-glass: rgba(15, 32, 39, 0.85);
|
--bg-glass: rgba(15, 32, 39, 0.85);
|
||||||
|
|
||||||
--text: #FFFFFF;
|
--text: #FFFFFF;
|
||||||
|
|||||||
Reference in New Issue
Block a user