mirror of
https://github.com/meowarex/TidaLuna-Plugins.git
synced 2026-06-18 03:43:10 +10:00
Cleanup
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { ReactiveStore } from "@luna/core";
|
import { ReactiveStore } from "@luna/core";
|
||||||
import { LunaSettings, LunaNumberSetting, LunaSwitchSetting, LunaTextSetting } from "@luna/ui";
|
import { LunaSettings, LunaSwitchSetting } from "@luna/ui";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
export type ColoramaMode = "single" | "gradient-experimental" | "cover" | "cover-gradient";
|
export type ColoramaMode = "single" | "gradient-experimental" | "cover" | "cover-gradient";
|
||||||
@@ -38,8 +38,7 @@ export const Settings = () => {
|
|||||||
const [activeEndpoint, setActiveEndpoint] = React.useState<'single' | 'start' | 'end'>('single');
|
const [activeEndpoint, setActiveEndpoint] = React.useState<'single' | 'start' | 'end'>('single');
|
||||||
const AnySwitch = LunaSwitchSetting as unknown as React.ComponentType<any>;
|
const AnySwitch = LunaSwitchSetting as unknown as React.ComponentType<any>;
|
||||||
|
|
||||||
// Helpers for HEX parsing and alpha extraction
|
// Helper for HEX normalization
|
||||||
const clamp = (n: number, min: number, max: number) => Math.max(min, Math.min(max, n));
|
|
||||||
const normalizeToRGB = (hex: string, fallback: string = "#FFFFFF"): string => {
|
const normalizeToRGB = (hex: string, fallback: string = "#FFFFFF"): string => {
|
||||||
let v = hex.trim().toLowerCase();
|
let v = hex.trim().toLowerCase();
|
||||||
if (!v.startsWith('#')) v = `#${v}`;
|
if (!v.startsWith('#')) v = `#${v}`;
|
||||||
@@ -61,19 +60,6 @@ export const Settings = () => {
|
|||||||
if (/^#([0-9a-f]{6})$/.test(v)) return v.toUpperCase();
|
if (/^#([0-9a-f]{6})$/.test(v)) return v.toUpperCase();
|
||||||
return fallback;
|
return fallback;
|
||||||
};
|
};
|
||||||
const extractAlphaPercent = (hex: string, fallbackPercent: number = 100): number => {
|
|
||||||
let v = hex.trim().toLowerCase();
|
|
||||||
if (!v.startsWith('#')) v = `#${v}`;
|
|
||||||
if (/^#([0-9a-f]{4})$/.test(v)) {
|
|
||||||
const a = v[4];
|
|
||||||
return Math.round((parseInt(a + a, 16) / 255) * 100);
|
|
||||||
}
|
|
||||||
if (/^#([0-9a-f]{8})$/.test(v)) {
|
|
||||||
const a = v.slice(1, 3);
|
|
||||||
return Math.round((parseInt(a, 16) / 255) * 100);
|
|
||||||
}
|
|
||||||
return fallbackPercent;
|
|
||||||
};
|
|
||||||
|
|
||||||
const colorPresets = [
|
const colorPresets = [
|
||||||
"#FFFFFF", "#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF", "#00FFFF",
|
"#FFFFFF", "#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF", "#00FFFF",
|
||||||
@@ -220,8 +206,6 @@ export const Settings = () => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Rainbow mode removed */}
|
|
||||||
|
|
||||||
{/* Modal for picking and managing colors (reused) */}
|
{/* Modal for picking and managing colors (reused) */}
|
||||||
{shouldRender && (
|
{shouldRender && (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// NOTE: definition duplicated earlier accidentally; keep this single definition below
|
|
||||||
import { LunaUnload, Tracer } from "@luna/core";
|
import { LunaUnload, Tracer } from "@luna/core";
|
||||||
import { StyleTag, PlayState } from "@luna/lib";
|
import { StyleTag, PlayState } from "@luna/lib";
|
||||||
import { settings, Settings } from "./Settings";
|
import { settings, Settings } from "./Settings";
|
||||||
@@ -10,7 +9,7 @@ export { Settings };
|
|||||||
|
|
||||||
export const unloads = new Set<LunaUnload>();
|
export const unloads = new Set<LunaUnload>();
|
||||||
|
|
||||||
const styleTag = new StyleTag("ColoramaLyrics", unloads, styles);
|
new StyleTag("ColoramaLyrics", unloads, styles);
|
||||||
|
|
||||||
// Simple dominant color extraction from current cover art
|
// Simple dominant color extraction from current cover art
|
||||||
async function getCoverArtElement(): Promise<HTMLImageElement | null> {
|
async function getCoverArtElement(): Promise<HTMLImageElement | null> {
|
||||||
@@ -64,7 +63,7 @@ function getDominantColorsFromImage(img: HTMLImageElement, count: number = 2): s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utilities to build rgba() from hex + alpha percentage
|
// build rgba() from hex + alpha percentage
|
||||||
function hexToRgb(hex: string): { r: number; g: number; b: number } | null {
|
function hexToRgb(hex: string): { r: number; g: number; b: number } | null {
|
||||||
let v = hex.trim();
|
let v = hex.trim();
|
||||||
if (!v.startsWith('#')) v = `#${v}`;
|
if (!v.startsWith('#')) v = `#${v}`;
|
||||||
@@ -193,7 +192,7 @@ function observeTrackChanges(): void {
|
|||||||
setTimeout(() => applyColoramaLyrics(), 200);
|
setTimeout(() => applyColoramaLyrics(), 200);
|
||||||
observeTrackChanges();
|
observeTrackChanges();
|
||||||
|
|
||||||
// Ensure compatibility: re-apply after Radiant updates its styles/backgrounds
|
// for some reason, re-apply after Radiant updates its styles/backgrounds
|
||||||
function hookRadiantUpdates(): void {
|
function hookRadiantUpdates(): void {
|
||||||
const w = window as any;
|
const w = window as any;
|
||||||
const wrap = (name: string) => {
|
const wrap = (name: string) => {
|
||||||
@@ -217,6 +216,4 @@ function hookRadiantUpdates(): void {
|
|||||||
|
|
||||||
setTimeout(() => hookRadiantUpdates(), 0);
|
setTimeout(() => hookRadiantUpdates(), 0);
|
||||||
|
|
||||||
// Rainbow mode removed
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user