Files
anidev-design-system/runtime/index.js
T

37 lines
1.3 KiB
JavaScript

export { iconSvg, iconNames } from "../icons/icons.js";
export { createNotifier } from "../components/toast.js";
export {
searchSelectMarkup,
mountSearchSelect,
} from "../components/search-select.js";
export { mountCopyField } from "../components/copy-field.js";
export { mountDock } from "../components/dock.js";
export {
mountNavigation,
validateNavigation,
} from "../components/navigation.js";
import { tokensFor, cssVars } from "../concepts/registry.js";
/** Apply one document-wide Dock theme. Persistence belongs to the consuming app. */
export function applyTheme({
theme = "light",
density = "normal",
accent,
} = {}) {
if (!["light", "dark"].includes(theme)) throw new TypeError("Unknown theme");
if (!["compact", "normal", "relaxed"].includes(density))
throw new TypeError("Unknown density");
if (accent !== undefined && !/^#[0-9a-f]{6}$/i.test(accent))
throw new TypeError("Accent must be #RRGGBB");
let style = document.querySelector("style[data-anidev-tokens]");
if (!style) {
style = document.createElement("style");
style.dataset.anidevTokens = "";
document.head.append(style);
}
style.textContent = `:root {${cssVars(tokensFor("dock", theme, accent, density))}}`;
document.body.dataset.concept = "dock";
document.body.dataset.theme = theme;
document.body.dataset.density = density;
}