ayongui
Version:
52 lines (51 loc) • 1.44 kB
JavaScript
import { useRef as m } from "react";
function g(e, t) {
const n = m();
return function(...r) {
n.current && clearTimeout(n.current), n.current = setTimeout(() => {
e(r);
}, t);
};
}
const f = async (e, ...t) => new Promise(async (n, o) => {
try {
const r = await e(...t);
n(r);
} catch (r) {
o(r);
}
}), h = (e) => (e / 1024).toFixed(1), b = (e, t, n) => new Promise((o) => {
const r = new FileReader();
r.onloadend = () => {
const c = new Image();
c.src = r.result, c.onload = () => {
let a = c.width, s = c.height;
if (a > t || s > n) {
const x = Math.min(t / a, n / s);
a *= x, s *= x;
}
const i = document.createElement("canvas");
i.width = a, i.height = s, i.getContext("2d").drawImage(c, 0, 0, a, s);
const u = i.toDataURL("image/jpeg");
o(u);
};
}, r.readAsDataURL(e);
}), y = (e) => Object.prototype.toString.call(e) === "[object Object]";
function w(e) {
const t = document.documentElement;
for (let [n, o] of Object.entries(e))
t.style.setProperty(`--${n}`, o);
}
const p = () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
var t = Math.random() * 16 | 0, n = e == "x" ? t : t & 3 | 8;
return n.toString(16);
});
export {
h as formatFileSize,
p as generateUUID,
y as isObject,
f as isPromise,
b as readAsDataURLImg,
w as setThemeVariables,
g as useDebounce
};