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 { msg } from "gt-react";
6import { extendTailwindMerge } from "tailwind-merge";
7import { DraftId } from "../composerDraftStore";
8import { m, type MessageResolver } from "../i18n/messages";
9
10// Register extra font sizes and background images so tailwind-merge does not
11// treat text-2xs or bg-composer-seam-below as colors.
12const twMerge = extendTailwindMerge({
13 extend: {
14 theme: { text: ["2xs", "3xs", "4xs", "5xs"] },
15 classGroups: { "bg-image": [{ bg: ["composer-seam-below", "composer-seam-above"] }] },
16 },
17});
18
19export function cn(...inputs: CxOptions) {
20 return twMerge(cx(inputs));
21}
22
23export { isMacPlatform };
24
25export function isWindowsPlatform(platform: string): boolean {
26 return /^win(dows)?/i.test(platform);
27}
28
29export function normalizeSearchText(value: string): string {
30 return value.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
31}
32
33export function getLocalFileManagerName(platform: string, resolve: MessageResolver = m): string {
34 if (isMacPlatform(platform)) {
35 return "Finder";
36 }
37 if (isWindowsPlatform(platform)) {
38 return resolve(msg("File Explorer", { $context: "the Windows file manager app" }));
39 }
40 return resolve(msg("Files", { $context: "the Linux file manager app" }));
41}
42
43export function randomUUID(): string {
44 const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
45 bytes[6] = (bytes[6]! & 0x0f) | 0x40;
46 bytes[8] = (bytes[8]! & 0x3f) | 0x80;
47 const hex = Hex.encode(bytes);
48 return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
49}
50
51export const newProjectId = (): ProjectId => ProjectId.make(randomUUID());
52
53export const newThreadId = (): ThreadId => ThreadId.make(randomUUID());
54
55export const newDraftId = (): DraftId => DraftId.make(randomUUID());
56
57export const newMessageId = (): MessageId => MessageId.make(randomUUID());