76 lines
2.7 KiB
JavaScript
76 lines
2.7 KiB
JavaScript
import { icons, iconNames, iconSvg } from "./icons.js";
|
|
import { tokensFor, cssVars } from "../concepts/registry.js";
|
|
const $ = (s) => document.querySelector(s);
|
|
const categories = {
|
|
navigation: "Навигация",
|
|
account: "Аккаунт",
|
|
security: "Безопасность",
|
|
actions: "Действия",
|
|
files: "Файлы",
|
|
system: "Система",
|
|
status: "Состояния",
|
|
direction: "Направления",
|
|
};
|
|
for (const [id, label] of Object.entries(categories))
|
|
$("#category").add(new Option(label, id));
|
|
let theme = "light",
|
|
timer;
|
|
try {
|
|
theme =
|
|
JSON.parse(localStorage.getItem("anidev.preferences") || "{}").theme ===
|
|
"dark"
|
|
? "dark"
|
|
: "light";
|
|
} catch {}
|
|
function applyTheme() {
|
|
document.documentElement.style.cssText = cssVars(tokensFor("dock", theme));
|
|
document.body.dataset.theme = theme;
|
|
$("#theme").textContent = theme === "dark" ? "Светлая тема" : "Тёмная тема";
|
|
$("#theme").setAttribute("aria-pressed", String(theme === "dark"));
|
|
}
|
|
function render() {
|
|
const query = $("#search").value.toLowerCase().trim(),
|
|
category = $("#category").value,
|
|
size = Number($("#size").value);
|
|
const names = iconNames.filter(
|
|
(id) =>
|
|
(!category || icons[id].category === category) &&
|
|
`${id} ${icons[id].label}`.toLowerCase().includes(query),
|
|
);
|
|
$("#icon-grid").innerHTML = names
|
|
.map(
|
|
(id) =>
|
|
`<button class="icon-tile" type="button" data-icon="${id}" title="${icons[id].label} — копировать SVG" aria-label="${icons[id].label}: копировать SVG ${id}">${iconSvg(id, { size })}<code>${id}</code></button>`,
|
|
)
|
|
.join("");
|
|
$("#count").textContent = `${names.length} / ${iconNames.length}`;
|
|
$("#empty").hidden = names.length > 0;
|
|
}
|
|
$("#search").addEventListener("input", render);
|
|
$("#category").addEventListener("change", render);
|
|
$("#size").addEventListener("change", render);
|
|
$(".library-controls").addEventListener("submit", (e) => e.preventDefault());
|
|
$("#theme").addEventListener("click", () => {
|
|
theme = theme === "dark" ? "light" : "dark";
|
|
applyTheme();
|
|
});
|
|
$("#icon-grid").addEventListener("click", async (e) => {
|
|
const tile = e.target.closest("[data-icon]");
|
|
if (!tile) return;
|
|
const toast = $("#toast");
|
|
toast.popover = "manual";
|
|
try {
|
|
await navigator.clipboard.writeText(
|
|
iconSvg(tile.dataset.icon, { size: Number($("#size").value) }),
|
|
);
|
|
toast.textContent = `SVG скопирован: ${tile.dataset.icon}`;
|
|
} catch {
|
|
toast.textContent = "Не удалось скопировать. Скачайте SVG-пак.";
|
|
}
|
|
toast.showPopover();
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => toast.hidePopover(), 2800);
|
|
});
|
|
applyTheme();
|
|
render();
|