🌈 style: 优化部分样式

This commit is contained in:
imsyy
2025-10-29 18:29:58 +08:00
parent 829dc3b591
commit 9145eb034b
15 changed files with 384 additions and 89 deletions

View File

@@ -393,3 +393,38 @@ export const shuffleArray = <T>(arr: T[]): T[] => {
}
return copy;
};
/**
* 在浏览器空闲时执行任务
* @param task 要执行的任务
*/
export const runIdle = (task: () => void) => {
try {
const ric = window?.requestIdleCallback as ((cb: () => void) => number) | undefined;
if (typeof ric === "function") {
ric(() => {
try {
task();
} catch {
/* empty */
}
});
} else {
setTimeout(() => {
try {
task();
} catch {
/* empty */
}
}, 0);
}
} catch {
setTimeout(() => {
try {
task();
} catch {
/* empty */
}
}, 0);
}
};