import { normalizeFontId } from "./theme-core.js"; /** Префикс путей к ассетам (корень "" или "../" на страницах cases/*). */ export function getAssetPrefix() { const link = document.querySelector('link[rel="stylesheet"][href*="css/main.css"]'); if (link) { const href = link.getAttribute("href") || ""; const marker = "css/main.css"; const idx = href.lastIndexOf(marker); if (idx !== -1) return href.slice(0, idx); } const p = window.location.pathname || ""; if (p.includes("/cases/")) return "../"; return ""; } export function themeFontStylesheetHref(fontId) { const id = normalizeFontId(fontId); return `${getAssetPrefix()}assets/fonts/${id}.css`; } export function ensureThemeFontLoaded(fontId) { const id = normalizeFontId(fontId); const href = themeFontStylesheetHref(id); if (!href) return; if (document.querySelector(`link[data-theme-font="${id}"]`)) return; const link = document.createElement("link"); link.rel = "stylesheet"; link.href = href; link.dataset.themeFont = id; document.head.appendChild(link); }