@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 57 lines 2.08 KB
Raw
1 import { MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
2 import { isMacPlatform } from "@t3tools/shared/keybindings";
3 import { type CxOptions, cx } from "class-variance-authority";
4 import * as Hex from "effect/encoding/Hex";
5 import { msg } from "gt-react";
6 import { extendTailwindMerge } from "tailwind-merge";
7 import { DraftId } from "../composerDraftStore";
8 import { 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.
12 const 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
19 export function cn(...inputs: CxOptions) {
20 return twMerge(cx(inputs));
21 }
22
23 export { isMacPlatform };
24
25 export function isWindowsPlatform(platform: string): boolean {
26 return /^win(dows)?/i.test(platform);
27 }
28
29 export function normalizeSearchText(value: string): string {
30 return value.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/\s+/g, " ").trim();
31 }
32
33 export 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
43 export 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
51 export const newProjectId = (): ProjectId => ProjectId.make(randomUUID());
52
53 export const newThreadId = (): ThreadId => ThreadId.make(randomUUID());
54
55 export const newDraftId = (): DraftId => DraftId.make(randomUUID());
56
57 export const newMessageId = (): MessageId => MessageId.make(randomUUID());