* refactor to @base-ui/react

* fix all

* fixes to accordion

* more updates

* switch to chat/completions api from openai

* update version to v5.0.12
This commit is contained in:
Amruth Pillai
2026-03-17 23:38:06 +01:00
committed by GitHub
parent 89beb43ea2
commit 5cd16a62d9
192 changed files with 7333 additions and 9548 deletions
+4 -136
View File
@@ -1,126 +1,11 @@
export interface ColorValue {
r: number;
g: number;
b: number;
a: number;
}
import type { ColorResult } from "@uiw/color-convert";
export interface HSVColorValue {
h: number;
s: number;
v: number;
a: number;
}
export function rgbToHsv(color: ColorValue): HSVColorValue {
const r = color.r / 255;
const g = color.g / 255;
const b = color.b / 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
const diff = max - min;
let h = 0;
if (diff !== 0) {
switch (max) {
case r:
h = ((g - b) / diff) % 6;
break;
case g:
h = (b - r) / diff + 2;
break;
case b:
h = (r - g) / diff + 4;
break;
}
}
h = Math.round(h * 60);
if (h < 0) h += 360;
const s = max === 0 ? 0 : diff / max;
const v = max;
return {
h,
s: Math.round(s * 100),
v: Math.round(v * 100),
a: color.a,
};
}
export function hsvToRgb(hsv: HSVColorValue): ColorValue {
const h = hsv.h / 360;
const s = hsv.s / 100;
const v = hsv.v / 100;
const i = Math.floor(h * 6);
const f = h * 6 - i;
const p = v * (1 - s);
const q = v * (1 - f * s);
const t = v * (1 - (1 - f) * s);
let r: number;
let g: number;
let b: number;
switch (i % 6) {
case 0: {
r = v;
g = t;
b = p;
break;
}
case 1: {
r = q;
g = v;
b = p;
break;
}
case 2: {
r = p;
g = v;
b = t;
break;
}
case 3: {
r = p;
g = q;
b = v;
break;
}
case 4: {
r = t;
g = p;
b = v;
break;
}
case 5: {
r = v;
g = p;
b = q;
break;
}
default: {
r = 0;
g = 0;
b = 0;
}
}
return {
r: Math.round(r * 255),
g: Math.round(g * 255),
b: Math.round(b * 255),
a: hsv.a,
};
}
export function parseRgbString(value: string): ColorValue | null {
export function parseColorString(value: string): ColorResult["rgba"] | null {
const trimmed = value.trim();
// Parse rgb/rgba colors
const rgbMatch = trimmed.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)$/);
if (rgbMatch) {
return {
r: Number.parseInt(rgbMatch[1] ?? "0", 10),
@@ -141,6 +26,7 @@ export function parseRgbString(value: string): ColorValue | null {
a: 1,
};
}
// Support 3-digit hex
const hexMatch3 = trimmed.match(/^#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])$/i);
if (hexMatch3) {
@@ -155,21 +41,3 @@ export function parseRgbString(value: string): ColorValue | null {
return null;
}
export function rgbToString(color: ColorValue): string {
return color.a < 1
? `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`
: `rgb(${color.r}, ${color.g}, ${color.b})`;
}
export function hexToRgb(hex: string, alpha = 1): ColorValue {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result
? {
r: Number.parseInt(result[1] ?? "0", 16),
g: Number.parseInt(result[2] ?? "0", 16),
b: Number.parseInt(result[3] ?? "0", 16),
a: alpha,
}
: { r: 0, g: 0, b: 0, a: alpha };
}
-63
View File
@@ -1,63 +0,0 @@
import { useCallback } from "react";
type PossibleRef<T> = React.Ref<T> | undefined;
/**
* Set a given ref to a given value
* This utility takes care of different types of refs: callback refs and RefObject(s)
*/
function setRef<T>(ref: PossibleRef<T>, value: T) {
if (typeof ref === "function") {
return ref(value);
}
if (ref !== null && ref !== undefined) {
ref.current = value;
}
}
/**
* A utility to compose multiple refs together
* Accepts callback refs and RefObject(s)
*/
function composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {
return (node) => {
let hasCleanup = false;
const cleanups = refs.map((ref) => {
const cleanup = setRef(ref, node);
if (!hasCleanup && typeof cleanup === "function") {
hasCleanup = true;
}
return cleanup;
});
// React <19 will log an error to the console if a callback ref returns a
// value. We don't use ref cleanups internally so this will only happen if a
// user's ref callback returns a value, which we only expect if they are
// using the cleanup functionality added in React 19.
if (hasCleanup) {
return () => {
for (let i = 0; i < cleanups.length; i++) {
const cleanup = cleanups[i];
if (typeof cleanup === "function") {
cleanup();
} else {
setRef(refs[i], null);
}
}
};
}
};
}
/**
* A custom hook that composes multiple refs
* Accepts callback refs and RefObject(s)
*/
function useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {
return useCallback(composeRefs(...refs), refs);
}
export { useComposedRefs };
+2
View File
@@ -18,6 +18,7 @@ const localeSchema = z.union([
z.literal("de-DE"),
z.literal("el-GR"),
z.literal("en-US"),
z.literal("en-GB"),
z.literal("es-ES"),
z.literal("fa-IR"),
z.literal("fi-FI"),
@@ -79,6 +80,7 @@ export const localeMap = {
"de-DE": msg`German`,
"el-GR": msg`Greek`,
"en-US": msg`English`,
"en-GB": msg`English (United Kingdom)`,
"es-ES": msg`Spanish`,
"fa-IR": msg`Persian`,
"fi-FI": msg`Finnish`,