diff --git a/apps/web/app/actions.ts b/apps/web/app/actions.ts index 0b5a9d5..cc8b7ce 100644 --- a/apps/web/app/actions.ts +++ b/apps/web/app/actions.ts @@ -1,5 +1,21 @@ -"use server"; -import { cookies } from "next/headers"; -export const handleToggleReadability = async (value: string) => { - await cookies().set("showReadability", value); -}; +'use server' + +import colorNameList from '@/lib/converted_colors.json' +import { ColorNames } from '@/types/app' +import { differenceEuclidean, nearest } from 'culori' + +interface ColorNameListWithIndex { + [key: string]: string +} + +const indexedColorNameList: ColorNameListWithIndex = colorNameList + +export const getColorNames = async (colors: ColorNames) => { + const colorKeys = Object.keys(indexedColorNameList) + const nearestNamedColors = nearest(colorKeys, differenceEuclidean(), (name) => indexedColorNameList[name]) + let names = colors.map((color) => { + const name = nearestNamedColors(color, 1) + return name?.[0] + }) + return names +}