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
31 .normalize("NFKD")
32 .replace(/\p{M}/gu, "")
33 .toLowerCase()
34 .replace(/ς/g, "σ")
35 .replace(/\s+/g, " ")
36 .trim();
37}
38
39export function getLocalFileManagerName(platform: string, resolve: MessageResolver = m): string {
40 if (isMacPlatform(platform)) {
41 return "Finder";
42 }
43 if (isWindowsPlatform(platform)) {
44 return resolve(msg({ context: "the Windows file manager app" })`File Explorer`);
45 }
46 return resolve(msg({ context: "the Linux file manager app" })`Files`);
47}
48
49export function randomUUID(): string {
50 const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
51 bytes[6] = (bytes[6]! & 0x0f) | 0x40;
52 bytes[8] = (bytes[8]! & 0x3f) | 0x80;
53 const hex = Hex.encode(bytes);
54 return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
55}
56
57export const newProjectId = (): ProjectId => ProjectId.make(randomUUID());
58
59export const newThreadId = (): ThreadId => ThreadId.make(randomUUID());
60
61export const newDraftId = (): DraftId => DraftId.make(randomUUID());
62
63export const newMessageId = (): MessageId => MessageId.make(randomUUID());