Polish BIM share modal controls

This commit is contained in:
CODEX
2026-06-18 22:45:33 +03:00
parent e6bb3f1761
commit 5b5d8f1c3c
4 changed files with 90 additions and 4 deletions
+32
View File
@@ -66,6 +66,36 @@ const projectSettings = typeof window !== "undefined" && window.__BIMDC_THEME__
? { ...defaultSettings, ...window.__BIMDC_THEME__ }
: { ...defaultSettings };
const parseColor = (value) => {
if (typeof value !== "string") return null;
const color = value.trim();
const hex = color.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
if (hex) {
const raw = hex[1].length === 3
? hex[1].split("").map((c) => c + c).join("")
: hex[1];
return [
parseInt(raw.slice(0, 2), 16),
parseInt(raw.slice(2, 4), 16),
parseInt(raw.slice(4, 6), 16),
];
}
const rgb = color.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);
if (!rgb) return null;
return rgb.slice(1, 4).map((channel) => Math.max(0, Math.min(255, Number(channel))));
};
const readableTextColor = (value) => {
const rgb = parseColor(value);
if (!rgb || rgb.some((channel) => !Number.isFinite(channel))) return "#15170f";
const toLinear = (channel) => {
const value = channel / 255;
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
};
const lum = 0.2126 * toLinear(rgb[0]) + 0.7152 * toLinear(rgb[1]) + 0.0722 * toLinear(rgb[2]);
return (lum + 0.05) / 0.05 >= 1.05 / (lum + 0.05) ? "#15170f" : "#f5f5fa";
};
const applySettings = (s) => {
const root = document.documentElement;
root.style.setProperty("--bg-outer", s.bgOuter);
@@ -82,11 +112,13 @@ const applySettings = (s) => {
root.style.setProperty("--project-btn-border", s.projectBtnBorder);
root.style.setProperty("--project-btn-hover", s.projectBtnHover);
root.style.setProperty("--modal-btn-primary", s.modalBtnPrimary);
root.style.setProperty("--modal-btn-primary-contrast", readableTextColor(s.modalBtnPrimary));
root.style.setProperty("--modal-btn-secondary", s.modalBtnSecondary);
root.style.setProperty("--loader-color", s.loaderColor);
root.style.setProperty("--template-glow-strength", `${s.templateGlow}%`);
root.style.setProperty("--toolbar-bg", s.toolbarBg);
root.style.setProperty("--toolbar-bg-active", s.toolbarBgActive);
root.style.setProperty("--toolbar-bg-active-contrast", readableTextColor(s.toolbarBgActive));
root.style.setProperty("--toolbar-border", s.toolbarBorder);
root.style.setProperty("--toolbar-outline", s.toolbarOutline);
const bgAlphaPct = `${(s.modalBgAlpha ?? 1) * 100}%`;