mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-16 10:33:00 +03:00
Merge branch 'dev' into feature/share-review-timestamp
This commit is contained in:
@@ -115,6 +115,51 @@ export type CameraAudioFeatures = {
|
||||
* @param requireSecureContext - If true, two-way audio requires secure context (default: true)
|
||||
* @returns CameraAudioFeatures object with detected capabilities
|
||||
*/
|
||||
/**
|
||||
* Calculates optimal detect dimensions from stream resolution.
|
||||
*
|
||||
* Scales dimensions to an efficient size for object detection while
|
||||
* preserving the stream's aspect ratio. Does not upscale.
|
||||
*
|
||||
* @param streamWidth - Native stream width in pixels
|
||||
* @param streamHeight - Native stream height in pixels
|
||||
* @returns Detect dimensions with even values, or null if inputs are invalid
|
||||
*/
|
||||
|
||||
// Target size for the smaller dimension (width or height) for detect streams
|
||||
export const DETECT_TARGET_PX = 720;
|
||||
|
||||
export function calculateDetectDimensions(
|
||||
streamWidth: number,
|
||||
streamHeight: number,
|
||||
): { width: number; height: number } | null {
|
||||
if (
|
||||
!Number.isFinite(streamWidth) ||
|
||||
!Number.isFinite(streamHeight) ||
|
||||
streamWidth <= 0 ||
|
||||
streamHeight <= 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const smallerDim = Math.min(streamWidth, streamHeight);
|
||||
const target = Math.min(DETECT_TARGET_PX, smallerDim);
|
||||
const scale = target / smallerDim;
|
||||
|
||||
let width = Math.round(streamWidth * scale);
|
||||
let height = Math.round(streamHeight * scale);
|
||||
|
||||
// Round down to even numbers (required for video processing)
|
||||
width = width - (width % 2);
|
||||
height = height - (height % 2);
|
||||
|
||||
if (width < 2 || height < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
export function detectCameraAudioFeatures(
|
||||
metadata: LiveStreamMetadata | null | undefined,
|
||||
requireSecureContext: boolean = true,
|
||||
|
||||
+148
-21
@@ -6,6 +6,7 @@
|
||||
|
||||
import get from "lodash/get";
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import merge from "lodash/merge";
|
||||
import unset from "lodash/unset";
|
||||
import isEqual from "lodash/isEqual";
|
||||
import mergeWith from "lodash/mergeWith";
|
||||
@@ -68,6 +69,63 @@ export const globalCameraDefaultSections = new Set([
|
||||
"ffmpeg",
|
||||
]);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Profile helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the base (pre-profile) value for a camera section.
|
||||
*
|
||||
* When a profile is active the API populates `base_config` with original
|
||||
* section values. This helper returns that value when available, falling
|
||||
* back to the top-level (effective) value otherwise.
|
||||
*/
|
||||
export function getBaseCameraSectionValue(
|
||||
config: FrigateConfig | undefined,
|
||||
cameraName: string | undefined,
|
||||
sectionPath: string,
|
||||
): unknown {
|
||||
if (!config || !cameraName) return undefined;
|
||||
const cam = config.cameras?.[cameraName];
|
||||
if (!cam) return undefined;
|
||||
const base = cam.base_config?.[sectionPath];
|
||||
return base !== undefined ? base : get(cam, sectionPath);
|
||||
}
|
||||
|
||||
/** Sections that can appear inside a camera profile definition. */
|
||||
export const PROFILE_ELIGIBLE_SECTIONS = new Set([
|
||||
"audio",
|
||||
"birdseye",
|
||||
"detect",
|
||||
"face_recognition",
|
||||
"lpr",
|
||||
"motion",
|
||||
"notifications",
|
||||
"objects",
|
||||
"record",
|
||||
"review",
|
||||
"snapshots",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Parse a section path that may encode a profile reference.
|
||||
*
|
||||
* Examples:
|
||||
* "detect" → { isProfile: false, actualSection: "detect" }
|
||||
* "profiles.armed.detect" → { isProfile: true, profileName: "armed", actualSection: "detect" }
|
||||
*/
|
||||
export function parseProfileFromSectionPath(sectionPath: string): {
|
||||
isProfile: boolean;
|
||||
profileName?: string;
|
||||
actualSection: string;
|
||||
} {
|
||||
const match = sectionPath.match(/^profiles\.([^.]+)\.(.+)$/);
|
||||
if (match) {
|
||||
return { isProfile: true, profileName: match[1], actualSection: match[2] };
|
||||
}
|
||||
return { isProfile: false, actualSection: sectionPath };
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// buildOverrides — pure recursive diff of current vs stored config & defaults
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -168,6 +226,26 @@ export function buildOverrides(
|
||||
// Normalize raw config data (strip internal fields) and remove any paths
|
||||
// listed in `hiddenFields` so they are not included in override computation.
|
||||
|
||||
// lodash `unset` treats `*` as a literal key. This helper expands wildcard
|
||||
// segments so that e.g. `"filters.*.mask"` unsets `filters.<each key>.mask`.
|
||||
function unsetWithWildcard(obj: Record<string, unknown>, path: string): void {
|
||||
if (!path.includes("*")) {
|
||||
unset(obj, path);
|
||||
return;
|
||||
}
|
||||
const segments = path.split(".");
|
||||
const starIndex = segments.indexOf("*");
|
||||
const prefix = segments.slice(0, starIndex).join(".");
|
||||
const suffix = segments.slice(starIndex + 1).join(".");
|
||||
const parent = prefix ? get(obj, prefix) : obj;
|
||||
if (parent && typeof parent === "object") {
|
||||
for (const key of Object.keys(parent as Record<string, unknown>)) {
|
||||
const fullPath = suffix ? `${key}.${suffix}` : key;
|
||||
unsetWithWildcard(parent as Record<string, unknown>, fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function sanitizeSectionData(
|
||||
data: ConfigSectionData,
|
||||
hiddenFields?: string[],
|
||||
@@ -179,7 +257,7 @@ export function sanitizeSectionData(
|
||||
const cleaned = cloneDeep(normalized) as ConfigSectionData;
|
||||
hiddenFields.forEach((path) => {
|
||||
if (!path) return;
|
||||
unset(cleaned, path);
|
||||
unsetWithWildcard(cleaned as Record<string, unknown>, path);
|
||||
});
|
||||
return cleaned;
|
||||
}
|
||||
@@ -315,7 +393,7 @@ export function requiresRestartForFieldPath(
|
||||
|
||||
export interface SectionSavePayload {
|
||||
basePath: string;
|
||||
sanitizedOverrides: Record<string, unknown>;
|
||||
sanitizedOverrides: JsonObject;
|
||||
updateTopic: string | undefined;
|
||||
needsRestart: boolean;
|
||||
pendingDataKey: string;
|
||||
@@ -421,23 +499,57 @@ export function prepareSectionSavePayload(opts: {
|
||||
level = "global";
|
||||
}
|
||||
|
||||
// Resolve section config
|
||||
const sectionConfig = getSectionConfig(sectionPath, level);
|
||||
// Detect profile-encoded section paths (e.g., "profiles.armed.detect")
|
||||
const profileInfo = parseProfileFromSectionPath(sectionPath);
|
||||
const schemaSection = profileInfo.actualSection;
|
||||
|
||||
// Resolve section schema
|
||||
const sectionSchema = extractSectionSchema(fullSchema, sectionPath, level);
|
||||
// Resolve section config using the actual section name (not the profile path)
|
||||
const sectionConfig = getSectionConfig(schemaSection, level);
|
||||
|
||||
// Resolve section schema using the actual section name
|
||||
const sectionSchema = extractSectionSchema(fullSchema, schemaSection, level);
|
||||
if (!sectionSchema) return null;
|
||||
|
||||
const modifiedSchema = modifySchemaForSection(
|
||||
sectionPath,
|
||||
schemaSection,
|
||||
level,
|
||||
sectionSchema,
|
||||
);
|
||||
|
||||
// Compute rawFormData (the current stored value for this section)
|
||||
// For profiles, merge base camera config with profile overrides (matching
|
||||
// what BaseSection displays in the form) so the diff only contains actual
|
||||
// user changes, not every field from the merged view.
|
||||
let rawSectionValue: unknown;
|
||||
if (level === "camera" && cameraName) {
|
||||
rawSectionValue = get(config.cameras?.[cameraName], sectionPath);
|
||||
if (profileInfo.isProfile) {
|
||||
const baseValue = getBaseCameraSectionValue(
|
||||
config,
|
||||
cameraName,
|
||||
profileInfo.actualSection,
|
||||
);
|
||||
const profileOverrides = get(config.cameras?.[cameraName], sectionPath);
|
||||
if (
|
||||
profileOverrides &&
|
||||
typeof profileOverrides === "object" &&
|
||||
baseValue &&
|
||||
typeof baseValue === "object"
|
||||
) {
|
||||
rawSectionValue = merge(
|
||||
cloneDeep(baseValue),
|
||||
cloneDeep(profileOverrides),
|
||||
);
|
||||
} else {
|
||||
rawSectionValue = baseValue;
|
||||
}
|
||||
} else {
|
||||
// Use base (pre-profile) value so the diff matches what the form shows
|
||||
rawSectionValue = getBaseCameraSectionValue(
|
||||
config,
|
||||
cameraName,
|
||||
sectionPath,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
rawSectionValue = get(config, sectionPath);
|
||||
}
|
||||
@@ -446,10 +558,21 @@ export function prepareSectionSavePayload(opts: {
|
||||
? {}
|
||||
: rawSectionValue;
|
||||
|
||||
// For profile sections, also hide restart-required fields to match
|
||||
// effectiveHiddenFields in BaseSection (prevents spurious deletion markers
|
||||
// for fields that are hidden from the form during profile editing).
|
||||
let hiddenFieldsForSanitize = sectionConfig.hiddenFields;
|
||||
if (profileInfo.isProfile && sectionConfig.restartRequired?.length) {
|
||||
const base = sectionConfig.hiddenFields ?? [];
|
||||
hiddenFieldsForSanitize = [
|
||||
...new Set([...base, ...sectionConfig.restartRequired]),
|
||||
];
|
||||
}
|
||||
|
||||
// Sanitize raw form data
|
||||
const rawData = sanitizeSectionData(
|
||||
rawFormData as ConfigSectionData,
|
||||
sectionConfig.hiddenFields,
|
||||
hiddenFieldsForSanitize,
|
||||
);
|
||||
|
||||
// Compute schema defaults
|
||||
@@ -457,7 +580,7 @@ export function prepareSectionSavePayload(opts: {
|
||||
? applySchemaDefaults(modifiedSchema, {})
|
||||
: {};
|
||||
const effectiveDefaults = getEffectiveDefaultsForSection(
|
||||
sectionPath,
|
||||
schemaSection,
|
||||
level,
|
||||
modifiedSchema ?? undefined,
|
||||
schemaDefaults,
|
||||
@@ -466,7 +589,7 @@ export function prepareSectionSavePayload(opts: {
|
||||
// Build overrides
|
||||
const overrides = buildOverrides(pendingData, rawData, effectiveDefaults);
|
||||
const sanitizedOverrides = sanitizeOverridesForSection(
|
||||
sectionPath,
|
||||
schemaSection,
|
||||
level,
|
||||
overrides,
|
||||
);
|
||||
@@ -474,7 +597,7 @@ export function prepareSectionSavePayload(opts: {
|
||||
if (
|
||||
!sanitizedOverrides ||
|
||||
typeof sanitizedOverrides !== "object" ||
|
||||
Object.keys(sanitizedOverrides as Record<string, unknown>).length === 0
|
||||
Object.keys(sanitizedOverrides as JsonObject).length === 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
@@ -485,9 +608,11 @@ export function prepareSectionSavePayload(opts: {
|
||||
? `cameras.${cameraName}.${sectionPath}`
|
||||
: sectionPath;
|
||||
|
||||
// Compute updateTopic
|
||||
// Compute updateTopic — profile definitions don't trigger hot-reload
|
||||
let updateTopic: string | undefined;
|
||||
if (level === "camera" && cameraName) {
|
||||
if (profileInfo.isProfile) {
|
||||
updateTopic = undefined;
|
||||
} else if (level === "camera" && cameraName) {
|
||||
const topic = cameraUpdateTopicMap[sectionPath];
|
||||
updateTopic = topic ? `config/cameras/${cameraName}/${topic}` : undefined;
|
||||
} else if (globalCameraDefaultSections.has(sectionPath)) {
|
||||
@@ -497,16 +622,18 @@ export function prepareSectionSavePayload(opts: {
|
||||
updateTopic = `config/${sectionPath}`;
|
||||
}
|
||||
|
||||
// Restart detection
|
||||
const needsRestart = requiresRestartForOverrides(
|
||||
sanitizedOverrides,
|
||||
sectionConfig.restartRequired,
|
||||
true,
|
||||
);
|
||||
// Restart detection — profile definitions never need restart
|
||||
const needsRestart = profileInfo.isProfile
|
||||
? false
|
||||
: requiresRestartForOverrides(
|
||||
sanitizedOverrides,
|
||||
sectionConfig.restartRequired,
|
||||
true,
|
||||
);
|
||||
|
||||
return {
|
||||
basePath,
|
||||
sanitizedOverrides: sanitizedOverrides as Record<string, unknown>,
|
||||
sanitizedOverrides: sanitizedOverrides as JsonObject,
|
||||
updateTopic,
|
||||
needsRestart,
|
||||
pendingDataKey,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
const MASKED_AUTH_PATTERN = /:\/\/\*:\*@/i;
|
||||
const MASKED_QUERY_PATTERN = /(?:[?&])user=\*&password=\*/i;
|
||||
|
||||
export const isMaskedPath = (value: string): boolean =>
|
||||
MASKED_AUTH_PATTERN.test(value) || MASKED_QUERY_PATTERN.test(value);
|
||||
|
||||
export const hasCredentials = (value: string): boolean => {
|
||||
if (!value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isMaskedPath(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = new URL(value);
|
||||
if (parsed.username || parsed.password) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
parsed.searchParams.has("user") && parsed.searchParams.has("password")
|
||||
);
|
||||
} catch {
|
||||
return /:\/\/[^:@/\s]+:[^@/\s]+@/.test(value);
|
||||
}
|
||||
};
|
||||
|
||||
export const maskCredentials = (value: string): string => {
|
||||
if (!value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
const maskedAuth = value.replace(/:\/\/[^:@/\s]+:[^@/\s]*@/g, "://*:*@");
|
||||
|
||||
return maskedAuth
|
||||
.replace(/([?&]user=)[^&]*/gi, "$1*")
|
||||
.replace(/([?&]password=)[^&]*/gi, "$1*");
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
export type FfmpegVideoOption = "copy" | "h264" | "h265" | "exclude";
|
||||
export type FfmpegAudioOption =
|
||||
| "copy"
|
||||
| "aac"
|
||||
| "opus"
|
||||
| "pcmu"
|
||||
| "pcma"
|
||||
| "pcm"
|
||||
| "mp3"
|
||||
| "exclude";
|
||||
export type FfmpegHardwareOption = "none" | "auto";
|
||||
|
||||
export type ParsedFfmpegUrl = {
|
||||
isFfmpeg: boolean;
|
||||
baseUrl: string;
|
||||
video: FfmpegVideoOption;
|
||||
audio: FfmpegAudioOption;
|
||||
hardware: FfmpegHardwareOption;
|
||||
extraFragments: string[];
|
||||
};
|
||||
|
||||
const VIDEO_VALUES = new Set(["copy", "h264", "h265"]);
|
||||
const AUDIO_VALUES = new Set([
|
||||
"copy",
|
||||
"aac",
|
||||
"opus",
|
||||
"pcmu",
|
||||
"pcma",
|
||||
"pcm",
|
||||
"mp3",
|
||||
]);
|
||||
const HARDWARE_SPECIFIC = new Set([
|
||||
"vaapi",
|
||||
"cuda",
|
||||
"v4l2m2m",
|
||||
"dxva2",
|
||||
"videotoolbox",
|
||||
]);
|
||||
|
||||
export function parseFfmpegUrl(url: string): ParsedFfmpegUrl {
|
||||
if (!url.startsWith("ffmpeg:")) {
|
||||
return {
|
||||
isFfmpeg: false,
|
||||
baseUrl: url,
|
||||
video: "copy",
|
||||
audio: "copy",
|
||||
hardware: "none",
|
||||
extraFragments: [],
|
||||
};
|
||||
}
|
||||
|
||||
const withoutPrefix = url.slice(7);
|
||||
const parts = withoutPrefix.split("#");
|
||||
const baseUrl = parts[0];
|
||||
const fragments = parts.slice(1);
|
||||
|
||||
let video: FfmpegVideoOption | null = null;
|
||||
let audio: FfmpegAudioOption | null = null;
|
||||
let hardware: FfmpegHardwareOption = "none";
|
||||
const extraFragments: string[] = [];
|
||||
|
||||
for (const frag of fragments) {
|
||||
if (frag.startsWith("video=")) {
|
||||
const val = frag.slice(6);
|
||||
if (VIDEO_VALUES.has(val)) {
|
||||
video = val as FfmpegVideoOption;
|
||||
} else {
|
||||
extraFragments.push(frag);
|
||||
}
|
||||
} else if (frag.startsWith("audio=")) {
|
||||
const val = frag.slice(6);
|
||||
if (AUDIO_VALUES.has(val)) {
|
||||
audio = val as FfmpegAudioOption;
|
||||
} else {
|
||||
extraFragments.push(frag);
|
||||
}
|
||||
} else if (frag === "hardware") {
|
||||
hardware = "auto";
|
||||
} else if (frag.startsWith("hardware=")) {
|
||||
const val = frag.slice(9);
|
||||
if (HARDWARE_SPECIFIC.has(val)) {
|
||||
hardware = "auto";
|
||||
} else {
|
||||
extraFragments.push(frag);
|
||||
}
|
||||
} else {
|
||||
extraFragments.push(frag);
|
||||
}
|
||||
}
|
||||
|
||||
const hasAnyKnownFragment = video !== null || audio !== null;
|
||||
|
||||
return {
|
||||
isFfmpeg: true,
|
||||
baseUrl,
|
||||
video: video ?? (hasAnyKnownFragment ? "exclude" : "copy"),
|
||||
audio: audio ?? (hasAnyKnownFragment ? "exclude" : "copy"),
|
||||
hardware,
|
||||
extraFragments,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildFfmpegUrl(parsed: ParsedFfmpegUrl): string {
|
||||
let url = `ffmpeg:${parsed.baseUrl}`;
|
||||
|
||||
if (parsed.video !== "exclude") {
|
||||
url += `#video=${parsed.video}`;
|
||||
}
|
||||
if (parsed.audio !== "exclude") {
|
||||
url += `#audio=${parsed.audio}`;
|
||||
}
|
||||
if (parsed.hardware === "auto") {
|
||||
url += "#hardware";
|
||||
}
|
||||
for (const frag of parsed.extraFragments) {
|
||||
url += `#${frag}`;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
export function toggleFfmpegMode(url: string, enable: boolean): string {
|
||||
if (enable) {
|
||||
if (url.startsWith("ffmpeg:")) {
|
||||
return url;
|
||||
}
|
||||
return `ffmpeg:${url}#video=copy#audio=copy`;
|
||||
}
|
||||
|
||||
if (!url.startsWith("ffmpeg:")) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const withoutPrefix = url.slice(7);
|
||||
const baseUrl = withoutPrefix.split("#")[0];
|
||||
return baseUrl;
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { TFunction } from "i18next";
|
||||
|
||||
export const calculatePasswordStrength = (password: string): number => {
|
||||
if (!password) return 0;
|
||||
|
||||
@@ -16,13 +18,18 @@ export const getPasswordRequirements = (password: string) => ({
|
||||
|
||||
export const getPasswordStrengthLabel = (
|
||||
password: string,
|
||||
t: (key: string) => string,
|
||||
t: TFunction,
|
||||
): string => {
|
||||
const strength = calculatePasswordStrength(password);
|
||||
|
||||
if (!password) return "";
|
||||
if (strength < 1) return t("users.dialog.form.password.strength.weak");
|
||||
return t("users.dialog.form.password.strength.veryStrong");
|
||||
if (strength < 1)
|
||||
return t("users.dialog.form.password.strength.weak", {
|
||||
ns: "views/settings",
|
||||
});
|
||||
return t("users.dialog.form.password.strength.veryStrong", {
|
||||
ns: "views/settings",
|
||||
});
|
||||
};
|
||||
|
||||
export const getPasswordStrengthColor = (password: string): string => {
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import type { ProfileColor } from "@/types/profile";
|
||||
|
||||
const PROFILE_COLORS: ProfileColor[] = [
|
||||
{
|
||||
bg: "bg-pink-400",
|
||||
text: "text-pink-400",
|
||||
dot: "bg-pink-400",
|
||||
border: "border-pink-400",
|
||||
bgMuted: "bg-pink-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-violet-500",
|
||||
text: "text-violet-500",
|
||||
dot: "bg-violet-500",
|
||||
border: "border-violet-500",
|
||||
bgMuted: "bg-violet-500/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-lime-500",
|
||||
text: "text-lime-500",
|
||||
dot: "bg-lime-500",
|
||||
border: "border-lime-500",
|
||||
bgMuted: "bg-lime-500/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-teal-400",
|
||||
text: "text-teal-400",
|
||||
dot: "bg-teal-400",
|
||||
border: "border-teal-400",
|
||||
bgMuted: "bg-teal-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-sky-400",
|
||||
text: "text-sky-400",
|
||||
dot: "bg-sky-400",
|
||||
border: "border-sky-400",
|
||||
bgMuted: "bg-sky-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-emerald-400",
|
||||
text: "text-emerald-400",
|
||||
dot: "bg-emerald-400",
|
||||
border: "border-emerald-400",
|
||||
bgMuted: "bg-emerald-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-indigo-400",
|
||||
text: "text-indigo-400",
|
||||
dot: "bg-indigo-400",
|
||||
border: "border-indigo-400",
|
||||
bgMuted: "bg-indigo-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-rose-400",
|
||||
text: "text-rose-400",
|
||||
dot: "bg-rose-400",
|
||||
border: "border-rose-400",
|
||||
bgMuted: "bg-rose-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-cyan-300",
|
||||
text: "text-cyan-300",
|
||||
dot: "bg-cyan-300",
|
||||
border: "border-cyan-300",
|
||||
bgMuted: "bg-cyan-300/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-purple-400",
|
||||
text: "text-purple-400",
|
||||
dot: "bg-purple-400",
|
||||
border: "border-purple-400",
|
||||
bgMuted: "bg-purple-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-green-400",
|
||||
text: "text-green-400",
|
||||
dot: "bg-green-400",
|
||||
border: "border-green-400",
|
||||
bgMuted: "bg-green-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-amber-400",
|
||||
text: "text-amber-400",
|
||||
dot: "bg-amber-400",
|
||||
border: "border-amber-400",
|
||||
bgMuted: "bg-amber-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-slate-400",
|
||||
text: "text-slate-400",
|
||||
dot: "bg-slate-400",
|
||||
border: "border-slate-400",
|
||||
bgMuted: "bg-slate-400/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-orange-300",
|
||||
text: "text-orange-300",
|
||||
dot: "bg-orange-300",
|
||||
border: "border-orange-300",
|
||||
bgMuted: "bg-orange-300/20",
|
||||
},
|
||||
{
|
||||
bg: "bg-blue-300",
|
||||
text: "text-blue-300",
|
||||
dot: "bg-blue-300",
|
||||
border: "border-blue-300",
|
||||
bgMuted: "bg-blue-300/20",
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Get a deterministic color for a profile name.
|
||||
*
|
||||
* Colors are assigned based on sorted position among all profile names,
|
||||
* so the same profile always gets the same color regardless of context.
|
||||
*/
|
||||
export function getProfileColor(
|
||||
profileName: string,
|
||||
allProfileNames: string[],
|
||||
): ProfileColor {
|
||||
const sorted = [...allProfileNames].sort();
|
||||
const index = sorted.indexOf(profileName);
|
||||
return PROFILE_COLORS[(index >= 0 ? index : 0) % PROFILE_COLORS.length];
|
||||
}
|
||||
Reference in New Issue
Block a user