import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; /** cn merges conditional class names and resolves Tailwind conflicts. */ export function cn(...inputs: ClassValue[]): string { return twMerge(clsx(inputs)); } export function base64urlToBytes(str: string): ArrayBuffer { let base64 = str.replace(/-/g, "+").replace(/_/g, "/"); const pad = base64.length % 4; if (pad) { base64 += "=".repeat(4 - pad); } const binary = atob(base64); const bytes = new Uint8Array(binary.length); for (let i = 0; i < binary.length; i++) { bytes[i] = binary.charCodeAt(i); } return bytes.buffer; } export function bytesToBase64url(bytes: ArrayBuffer): string { let binary = ""; const uint8 = new Uint8Array(bytes); const len = uint8.byteLength; for (let i = 0; i < len; i++) { binary += String.fromCharCode(uint8[i]); } const base64 = btoa(binary); return base64 .replace(/\+/g, "-") .replace(/\//g, "_") .replace(/=+$/, ""); }