Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(desktop): format measured export estimate ranges
Richie McIlroy2f2c961f6db5
diff --git a/apps/desktop/src/routes/editor/export-estimates.test.ts b/apps/desktop/src/routes/editor/export-estimates.test.tsnew file mode 100644index 000000000..cce9b0b38--- /dev/null+++ b/apps/desktop/src/routes/editor/export-estimates.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from "vitest";+import { formatEstimatedSize, formatEstimatedTime } from "./export-estimates";++describe("export estimate labels", () => {+ it("keeps measured variation visible", () => {+ expect(formatEstimatedSize([18.7, 31.5])).toBe("~19–32 MB");+ expect(formatEstimatedTime([17.6, 18.9])).toBe("~18–19 s");+ });++ it("uses useful precision across unit boundaries", () => {+ expect(formatEstimatedSize([900, 1200])).toBe("~0.9–1.2 GB");+ expect(formatEstimatedTime([59, 90])).toBe("~1–1.5 min");+ expect(formatEstimatedTime([3600, 5400])).toBe("~1–1.5 hr");+ });++ it("avoids false zero or duplicated ranges for tiny exports", () => {+ expect(formatEstimatedTime([0.1, 0.9])).toBe("< 1s");+ expect(formatEstimatedSize([0.1, 0.9])).toBe("< 1 MB");+ expect(formatEstimatedTime([2.1, 2.3])).toBe("~2 s");+ });+});diff --git a/apps/desktop/src/routes/editor/export-estimates.ts b/apps/desktop/src/routes/editor/export-estimates.tsnew file mode 100644index 000000000..af8028535--- /dev/null+++ b/apps/desktop/src/routes/editor/export-estimates.ts@@ -0,0 +1,26 @@+function formatRange(range: number[], scale: number, unit: string): string {+ const precision = scale === 1 ? 1 : 10;+ const lower = Math.max(+ 1 / precision,+ Math.round((range[0] / scale) * precision) / precision,+ );+ const upper = Math.max(+ lower,+ Math.round((range[1] / scale) * precision) / precision,+ );+ return lower === upper ? `~${lower} ${unit}` : `~${lower}–${upper} ${unit}`;+}++export function formatEstimatedSize(range: number[]): string {+ if (range[1] < 1) return "< 1 MB";+ return range[1] >= 1024+ ? formatRange(range, 1024, "GB")+ : formatRange(range, 1, "MB");+}++export function formatEstimatedTime(range: number[]): string {+ if (range[1] < 1) return "< 1s";+ if (range[1] >= 3600) return formatRange(range, 3600, "hr");+ if (range[1] >= 60) return formatRange(range, 60, "min");+ return formatRange(range, 1, "s");+}