Open History to see the last commit
1import { MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
2import { isMacPlatform } from "@t3tools/shared/keybindings";
3import { type CxOptions, cx } from "class-variance-authority";
4import * as Hex from "effect/encoding/Hex";
5import { extendTailwindMerge } from "tailwind-merge";
6import { DraftId } from "../composerDraftStore";
7
8// Register extra font sizes so tailwind-merge does not treat text-2xs as a color.
9const twMerge = extendTailwindMerge({ extend: { theme: { text: ["2xs", "3xs", "4xs", "5xs"] } } });
10
11export function cn(...inputs: CxOptions) {
12 return twMerge(cx(inputs));
13}
14
15export { isMacPlatform };
16
17export function isWindowsPlatform(platform: string): boolean {
18 return /^win(dows)?/i.test(platform);
19}
20
21export function normalizeSearchText(value: string): string {
22 return value.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
23}
24
25export function getLocalFileManagerName(platform: string): string {
26 if (isMacPlatform(platform)) {
27 return "Finder";
28 }
29 if (isWindowsPlatform(platform)) {
30 return "File Explorer";
31 }
32 return "Files";
33}
34
35export function randomUUID(): string {
36 const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
37 bytes[6] = (bytes[6]! & 0x0f) | 0x40;
38 bytes[8] = (bytes[8]! & 0x3f) | 0x80;
39 const hex = Hex.encode(bytes);
40 return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
41}
42
43export const newProjectId = (): ProjectId => ProjectId.make(randomUUID());
44
45export const newThreadId = (): ThreadId => ThreadId.make(randomUUID());
46
47export const newDraftId = (): DraftId => DraftId.make(randomUUID());
48
49export const newMessageId = (): MessageId => MessageId.make(randomUUID());