Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(mobile): add theme and format utilities
Richie McIlroy0201c681f269
diff --git a/apps/mobile/src/theme.test.ts b/apps/mobile/src/theme.test.tsnew file mode 100644index 000000000..13a0898d4--- /dev/null+++ b/apps/mobile/src/theme.test.ts@@ -0,0 +1,63 @@+import { describe, expect, it, vi } from "vitest";+import { colors } from "./theme";++vi.mock("react-native", () => ({+ StyleSheet: {+ create: <T extends Record<string, unknown>>(styles: T) => styles,+ },+}));++const webRadixColors = {+ gray: {+ gray1: "#fcfcfc",+ gray2: "#f9f9f9",+ gray3: "#f0f0f0",+ gray4: "#e8e8e8",+ gray5: "#e0e0e0",+ gray6: "#d9d9d9",+ gray7: "#cecece",+ gray8: "#bbbbbb",+ gray9: "#8d8d8d",+ gray10: "#838383",+ gray11: "#646464",+ gray12: "#202020",+ },+ blue: {+ blue1: "#fbfdff",+ blue2: "#f4faff",+ blue3: "#e6f4fe",+ blue4: "#d5efff",+ blue5: "#c2e5ff",+ blue6: "#acd8fc",+ blue7: "#8ec8f6",+ blue8: "#5eb1ef",+ blue9: "#0090ff",+ blue10: "#0588f0",+ blue11: "#0d74ce",+ blue12: "#113264",+ },+ red: {+ red1: "#fffcfc",+ red2: "#fff7f7",+ red3: "#feebec",+ red4: "#ffdbdc",+ red5: "#ffcdce",+ red6: "#fdbdbe",+ red7: "#f4a9aa",+ red8: "#eb8e90",+ red9: "#e5484d",+ red10: "#dc3e42",+ red11: "#ce2c31",+ red12: "#641723",+ },+};++describe("mobile theme", () => {+ it("matches the Radix color scales imported by Cap web", () => {+ expect(colors).toMatchObject({+ ...webRadixColors.gray,+ ...webRadixColors.blue,+ ...webRadixColors.red,+ });+ });+});diff --git a/apps/mobile/src/theme.ts b/apps/mobile/src/theme.tsnew file mode 100644index 000000000..786269c6b--- /dev/null+++ b/apps/mobile/src/theme.ts@@ -0,0 +1,95 @@+import { StyleSheet } from "react-native";++export const colors = {+ white: "#ffffff",+ black: "#000000",+ gray1: "#fcfcfc",+ gray2: "#f9f9f9",+ gray3: "#f0f0f0",+ gray4: "#e8e8e8",+ gray5: "#e0e0e0",+ gray6: "#d9d9d9",+ gray7: "#cecece",+ gray8: "#bbbbbb",+ gray9: "#8d8d8d",+ gray10: "#838383",+ gray11: "#646464",+ gray12: "#202020",+ appBackground: "#f9f9f9",+ blue1: "#fbfdff",+ blue2: "#f4faff",+ blue3: "#e6f4fe",+ blue4: "#d5efff",+ blue5: "#c2e5ff",+ blue6: "#acd8fc",+ blue7: "#8ec8f6",+ blue8: "#5eb1ef",+ blue9: "#0090ff",+ blue10: "#0588f0",+ blue11: "#0d74ce",+ blue12: "#113264",+ red1: "#fffcfc",+ red2: "#fff7f7",+ red3: "#feebec",+ red4: "#ffdbdc",+ red5: "#ffcdce",+ red6: "#fdbdbe",+ red7: "#f4a9aa",+ red8: "#eb8e90",+ red9: "#e5484d",+ red10: "#dc3e42",+ red11: "#ce2c31",+ red12: "#641723",+ primary: "#005cb1",+ primary2: "#004c93",+ secondary: "#2eb4ff",+ tertiary: "#c5eaff",+ buttonBlue: "#2563eb",+ buttonBlueHover: "#1d4ed8",+ buttonBlueBorder: "#1e40af",+ glass: "rgba(252, 252, 252, 0.72)",+ blackAlpha5: "rgba(18, 22, 31, 0.05)",+ blackAlpha10: "rgba(18, 22, 31, 0.1)",+ blackAlpha40: "rgba(18, 22, 31, 0.4)",+ blackAlpha60: "rgba(18, 22, 31, 0.6)",+ green9: "#30a46c",+ yellow3: "#fffab8",+ yellow5: "#ffe770",+ yellow9: "#f5d90a",+};++export const fonts = {+ regular: "NeueMontreal-Regular",+ medium: "NeueMontreal-Medium",+ bold: "NeueMontreal-Bold",+};++export const radius = {+ xs: 6,+ sm: 8,+ md: 12,+ lg: 16,+ xl: 20,+ full: 999,+};++export const squircle = {+ borderCurve: "continuous" as const,+};++export const shadows = StyleSheet.create({+ card: {+ shadowColor: colors.black,+ shadowOffset: { width: 0, height: 1 },+ shadowOpacity: 0.04,+ shadowRadius: 2,+ elevation: 1,+ },+ popover: {+ shadowColor: colors.black,+ shadowOffset: { width: 0, height: 16 },+ shadowOpacity: 0.12,+ shadowRadius: 32,+ elevation: 10,+ },+});diff --git a/apps/mobile/src/utils/format.test.ts b/apps/mobile/src/utils/format.test.tsnew file mode 100644index 000000000..1ef398500--- /dev/null+++ b/apps/mobile/src/utils/format.test.ts@@ -0,0 +1,35 @@+import { describe, expect, it } from "vitest";+import { formatDuration, formatFileSize, formatRelativeDate } from "./format";++describe("mobile formatters", () => {+ it("formats card dates like Cap web", () => {+ const now = new Date("2026-05-18T11:00:00.000Z");++ expect(formatRelativeDate("2026-05-18T10:30:00.000Z", now)).toBe(+ "30 minutes ago",+ );+ expect(formatRelativeDate("2026-05-18T09:45:00.000Z", now)).toBe(+ "an hour ago",+ );+ expect(formatRelativeDate("2026-05-16T11:00:00.000Z", now)).toBe(+ "2 days ago",+ );+ });++ it("formats card durations like Cap web thumbnails", () => {+ expect(formatDuration(0)).toBe("< 1 sec");+ expect(formatDuration(8)).toBe("8 secs");+ expect(formatDuration(61)).toBe("1 min");+ expect(formatDuration(125)).toBe("2 mins");+ expect(formatDuration(7200)).toBe("2 hrs");+ });++ it("formats native upload file sizes", () => {+ expect(formatFileSize(null)).toBeNull();+ expect(formatFileSize(0)).toBeNull();+ expect(formatFileSize(640)).toBe("640 B");+ expect(formatFileSize(124_000)).toBe("124 KB");+ expect(formatFileSize(12_400_000)).toBe("12 MB");+ expect(formatFileSize(2_300_000_000)).toBe("2 GB");+ });+});diff --git a/apps/mobile/src/utils/format.ts b/apps/mobile/src/utils/format.tsnew file mode 100644index 000000000..a8b43469f--- /dev/null+++ b/apps/mobile/src/utils/format.ts@@ -0,0 +1,51 @@+export const formatRelativeDate = (input: string, now = new Date()) => {+ const date = new Date(input);+ const diffMs = now.getTime() - date.getTime();+ const diffSeconds = Math.max(0, Math.round(diffMs / 1000));+ if (diffSeconds < 45) return "a few seconds ago";+ if (diffSeconds < 90) return "a minute ago";++ const diffMinutes = Math.round(diffSeconds / 60);+ if (diffMinutes < 45) return `${diffMinutes} minutes ago`;+ if (diffMinutes < 90) return "an hour ago";++ const diffHours = Math.round(diffMinutes / 60);+ if (diffHours < 22) return `${diffHours} hours ago`;+ if (diffHours < 36) return "a day ago";++ const diffDays = Math.round(diffHours / 24);+ if (diffDays < 26) return `${diffDays} days ago`;+ if (diffDays < 45) return "a month ago";++ const diffMonths = Math.round(diffDays / 30);+ if (diffDays < 320) return `${diffMonths} months ago`;+ if (diffDays < 548) return "a year ago";++ const diffYears = Math.round(diffDays / 365);+ return `${diffYears} years ago`;+};++export const formatDuration = (seconds: number | null) => {+ if (seconds === null || !Number.isFinite(seconds)) return null;+ const safeSeconds = Math.max(0, Math.ceil(seconds));+ const hours = Math.floor(safeSeconds / 3600);+ const minutes = Math.floor(safeSeconds / 60);+ const remainingSeconds = safeSeconds % 60;+ if (hours > 0) return `${hours} hr${hours > 1 ? "s" : ""}`;+ if (minutes > 0) return `${minutes} min${minutes > 1 ? "s" : ""}`;+ if (remainingSeconds > 0) {+ return `${remainingSeconds} sec${remainingSeconds === 1 ? "" : "s"}`;+ }+ return "< 1 sec";+};++export const formatFileSize = (bytes: number | null | undefined) => {+ if (bytes === null || bytes === undefined || !Number.isFinite(bytes)) {+ return null;+ }+ if (bytes <= 0) return null;+ if (bytes >= 1_000_000_000) return `${Math.round(bytes / 1_000_000_000)} GB`;+ if (bytes >= 1_000_000) return `${Math.round(bytes / 1_000_000)} MB`;+ if (bytes >= 1_000) return `${Math.round(bytes / 1_000)} KB`;+ return `${Math.round(bytes)} B`;+};