36 lines
1017 B
TypeScript
36 lines
1017 B
TypeScript
import type { AgentPsdTextColorConfig } from "@/types/agent";
|
|
import { normalizeHexColor } from "@/lib/agents/psd-text-layout";
|
|
|
|
export const AGENT_PSD_TEXT_COLOR_CONFIG_KEY = "agent_psd_text_color_config";
|
|
|
|
export const defaultAgentPsdTextColorConfig: AgentPsdTextColorConfig = {
|
|
enabled: false,
|
|
colors: ["#ffffff", "#111111"],
|
|
};
|
|
|
|
export function normalizeAgentPsdTextColorConfig(
|
|
value: unknown
|
|
): AgentPsdTextColorConfig {
|
|
const raw =
|
|
value && typeof value === "object" && !Array.isArray(value)
|
|
? (value as Record<string, unknown>)
|
|
: {};
|
|
|
|
const colors = Array.isArray(raw.colors)
|
|
? raw.colors
|
|
.map((item) => normalizeHexColor(String(item || ""), ""))
|
|
.filter(Boolean)
|
|
.slice(0, 2)
|
|
: [];
|
|
|
|
const [firstColor, secondColor] = [
|
|
colors[0] || defaultAgentPsdTextColorConfig.colors[0],
|
|
colors[1] || colors[0] || defaultAgentPsdTextColorConfig.colors[1],
|
|
];
|
|
|
|
return {
|
|
enabled: raw.enabled === true,
|
|
colors: [firstColor, secondColor],
|
|
};
|
|
}
|