laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
54 lines (53 loc) • 1.84 kB
JavaScript
"use client";
import { guessKind as l, getOfficeEmbedUrl as m } from "./file-preview.js";
import { clsx as d } from "../node_modules/clsx/dist/clsx.js";
import { twMerge as p } from "../node_modules/tailwind-merge/dist/bundle-mjs.js";
function u(...n) {
return p(d(n));
}
const b = (n) => {
if (!n) return "#777777";
let e = 0;
for (let s = 0; s < n.length; s += 1)
e = n.charCodeAt(s) + ((e << 5) - e), e &= e;
let t = e >> 16 & 255, o = e >> 8 & 255, r = e & 255;
const c = 60, a = 200;
t = Math.min(a, Math.max(c, t)), o = Math.min(a, Math.max(c, o)), r = Math.min(a, Math.max(c, r));
const i = (s) => s.toString(16).padStart(2, "0");
return `#${i(t)}${i(o)}${i(r)}`;
}, w = (n, e) => {
let t = n.replace("#", "");
t.length === 3 && (t = t.split("").map((i) => i + i).join(""));
const o = parseInt(t, 16), r = o >> 16 & 255, c = o >> 8 & 255, a = o & 255;
return `rgba(${r}, ${c}, ${a}, ${e})`;
}, x = (n) => {
const e = parseInt(n.replace("#", ""), 16), t = e >> 16 & 255, o = e >> 8 & 255, r = e & 255;
return (0.299 * t + 0.587 * o + 0.114 * r) / 255 > 0.5 ? "#000000" : "#FFFFFF";
}, y = (n, e) => {
if (!n) return;
const t = n.split("?")[1] || "";
let o = "";
try {
const c = new URLSearchParams(t);
o = c.get("response-content-type") || c.get("content-type") || "";
} catch {
}
if (l({ mimeType: o, filename: e, url: n }) === "office") {
const c = m(n);
window.open(c, "_blank");
return;
}
window.open(n, "_blank");
}, F = (n, e) => {
if (!n) return;
const t = document.createElement("a");
t.href = n, t.download = e || "document", t.style.display = "none", document.body.appendChild(t), t.click(), document.body.removeChild(t);
};
export {
u as cn,
F as downloadFile,
x as hexContrast,
w as hexToRgba,
y as previewFile,
b as stringToHexColor
};