Spaces:
Running
Running
File size: 1,439 Bytes
fb12607 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export { clsx };
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatTime(seconds: number): string {
const s = Math.max(0, Math.floor(seconds));
const h = Math.floor(s / 3600);
const m = Math.floor((s % 3600) / 60);
const sec = s % 60;
const mm = String(m).padStart(2, "0");
const ss = String(sec).padStart(2, "0");
return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;
}
export function copyToClipboard(text: string): Promise<boolean> {
if (navigator.clipboard && window.isSecureContext) {
return navigator.clipboard.writeText(text).then(() => true).catch(() => false);
} else {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.left = "-999999px";
textArea.style.top = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
return new Promise((resolve) => {
const successful = document.execCommand('copy');
textArea.remove();
resolve(successful);
});
}
}
export function scrollToTop(behavior: ScrollBehavior = 'instant') {
if (typeof window === 'undefined') return;
window.scrollTo({ top: 0, left: 0, behavior });
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
}
|