страница пакета→ /design/icons.html
pages/design/icons.html
230 строк, 14.9 КБ. Открыть как есть (в проекте рядом лежат другие файлы, здесь их может не быть).
Файл как есть в пакете: код и комментарии в нём не переводятся.
- <!--
- ---
- type: Lens
- title: "Icons"
- icon: "🏷️"
- description: "Every icon set of the project by group: each icon at the chosen size on the page, on light and dark tiles or in every installed style side by side; search by name, alias and meaning; a click shows its record in the right panel and copies the name."
- template: custom
- lensType: specimen
- sources: ["/design/<set>/registry.json", "/design/<set>/flat/*.svg", "IconStyle pages under /design/"]
- generator: "shtuk run icons lens"
- ---
- The icon lens of `icons`, read from `lib/design/icons.data.js` (`shtuk run icons lens`). The settings and the chosen
- icon's record are in the right panel; `?icon=<name>` opens that icon.
- -->
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Icons</title>
- <link rel="stylesheet" href="../lib/kit.css">
- <link rel="stylesheet" href="../lib/explore.css">
- <script src="../lib/data.js"></script>
- <script src="../lib/design/icons.data.js"></script>
- <script src="../lib/design/icon-render.js"></script>
- <script src="../lib/explore.js"></script>
- <script src="../lib/kit.js"></script>
- <style>
- /* The icons on the lens shell: a white page of groups, each icon on the page's own surface (or on a light or dark tile
- when asked), its name under it; no cards. The chosen icon's record and the settings are in the right panel. */
- .ic { --ic-fg: var(--foreground, var(--ink, #191919)); --ic-mute: var(--muted-foreground, var(--lx-muted, #6f6e69)); --ic-line: var(--border, var(--line, #e9e9e7));
- --ic-row: var(--sidebar-accent, color-mix(in srgb, var(--ic-fg) 6%, transparent));
- box-sizing: border-box; width: 100%; max-width: 1120px; margin: 0 auto; padding: 40px 48px 96px; color: var(--ic-fg); display: flex; flex-direction: column; gap: 40px; }
- .ic *, .ic *::before, .ic *::after { box-sizing: border-box; }
- .ic code { font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; }
- .ic-group h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; text-transform: capitalize; }
- .ic-group h2 small { font-weight: 400; color: var(--ic-mute); font-size: 12px; text-transform: none; }
- .ic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--cell), 1fr)); gap: 8px; }
- .ic-cell { border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px 8px; outline: none; min-width: 0; }
- .ic-cell:hover, .ic-cell.on { background: var(--ic-row); }
- .ic-cell:focus-visible { box-shadow: 0 0 0 2px var(--ring, #e04a72); }
- .ic-faces { display: flex; gap: 6px; }
- .ic-face { display: flex; gap: 6px; justify-content: center; align-items: center; }
- .ic-face.light, .ic-face.dark { padding: 8px; border-radius: 8px; }
- .ic-face.light { background: #ffffff; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .06); }
- .ic-face.dark { background: #1f1f1f; }
- .ic-face img { width: var(--px); height: var(--px); display: block; }
- .ic-one { display: flex; flex-direction: column; align-items: center; gap: 3px; }
- .ic-one i { font-style: normal; font-size: 10px; color: var(--ic-mute); font-family: var(--font-mono, ui-monospace, monospace); }
- .ic-face.dark .ic-one i { color: #a3a29e; }
- .ic-name { font-size: 12px; max-width: 100%; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ic-fg); }
- .ic-copied .ic-name::after { content: " · copied"; color: var(--ic-mute); }
- .ic-empty, .ic-warn { color: var(--muted-foreground, var(--lx-muted, #6f6e69)); font-size: 13px; }
- .ic-warn { color: var(--destructive, #e85339); }
- /* the record of the chosen icon, in the right panel */
- .ic-det { display: flex; flex-direction: column; gap: 12px; font-size: 13px; line-height: 1.4; }
- .ic-det .ic-face { flex-wrap: wrap; justify-content: flex-start; gap: 10px; }
- .ic-det .ic-face img { width: 48px; height: 48px; }
- .ic-det .ic-faces { flex-direction: column; }
- .ic-det h3 { margin: 0; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
- .ic-det dl { margin: 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; }
- .ic-det dt { color: var(--muted-foreground, var(--lx-muted, #6f6e69)); }
- .ic-det dd { margin: 0; overflow-wrap: anywhere; }
- .ic-btns { display: flex; gap: 4px 12px; flex-wrap: wrap; }
- .ic-btn { all: unset; cursor: pointer; font-size: 12.5px; text-decoration: underline; text-decoration-color: var(--border, var(--line, #e9e9e7)); text-underline-offset: 3px; }
- .ic-btn:hover { text-decoration-color: currentColor; }
- .ic-btn.ic-copied::after { content: " · copied"; color: var(--muted-foreground, #6f6e69); }
- .ic-styles { display: flex; gap: 4px 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted-foreground, var(--lx-muted, #6f6e69)); }
- .ic-styles b { color: var(--foreground, var(--ink, #191919)); font-weight: 500; }
- /* the stand-in controls when the explore kit is not there */
- .ic-standin label { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; margin: 4px 0; }
- </style>
- <script>
- (function () {
- const { h } = Lens;
- const D = window.SB_ICONS, R = window.SBIconRender;
- const SIZES = ["16", "24", "32", "48", "56", "96"];
- const cache = new Map();
- function url(styleId, icon, set) {
- const key = styleId + "|" + set + "|" + icon.name;
- if (cache.has(key)) return cache.get(key);
- let svg = icon.svg;
- const st = D.styles.find((s) => s.id === styleId);
- if (st && st.render && R) { try { svg = R.render(icon.svg, st.render, st.palette, { idPrefix: "i" }); } catch (e) { svg = icon.svg; } }
- const u = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
- cache.set(key, u);
- return u;
- }
- function copy(text, el) {
- const done = () => { if (el) { el.classList.add("ic-copied"); setTimeout(() => el.classList.remove("ic-copied"), 900); } };
- if (navigator.clipboard) navigator.clipboard.writeText(text).then(done, done); else done();
- }
- const words = (r) => [r.name, ...(r.aliases || []), r.description || "", r.use || "", r.group || ""].join(" ").toLowerCase();
- Lens.templates.custom = function (cfg) {
- const ui = Lens.page(cfg);
- if (!D || !R) {
- ui.main.append(h("div", { class: "ic" }, h("p", { class: "ic-warn" }, "There is no icon data. Build it from the project root: shtuk run icons lens")));
- return;
- }
- const sets = D.sets || [];
- const styles = D.styles || [];
- const groups = [...new Set(sets.flatMap((s) => s.icons.map((i) => i.group || "other")))].sort();
- let v = { style: D.style || (styles[0] && styles[0].id) || "flat", size: "48", surface: "page", group: "all", set: "all", q: "" };
- let headerQ = "";
- let selected = null;
- const root = h("div", { class: "ic" });
- const body = h("div", { style: "display:flex;flex-direction:column;gap:40px" });
- root.append(body);
- ui.main.append(root);
- // the right panel: the chosen icon's record first, then the overview, the settings
- const detail = ui.section("Icon");
- const detSec = () => detail.card || detail.closest("[data-slot=panel-section], .lx-sec");
- const showSec = (on) => { const sc = detSec(); if (sc) sc.hidden = !on; };
- showSec(false);
- function faces(icon, set, px, styleIds) {
- const surf = v.surface === "both" ? ["light", "dark"] : [v.surface || "page"];
- return h("div", { class: "ic-faces" }, surf.map((s) => h("div", { class: "ic-face " + s },
- styleIds.map((id) => styleIds.length > 1
- ? h("div", { class: "ic-one" }, h("img", { src: url(id, icon, set), alt: icon.name, width: px, height: px, loading: "lazy" }), h("i", {}, id))
- : h("img", { src: url(id, icon, set), alt: icon.name, width: px, height: px, loading: "lazy" })))));
- }
- const shownStyles = () => v.style === "all" ? (styles.length ? styles.map((s) => s.id) : ["flat"]) : [v.style];
- function showDetail(icon, set) {
- selected = { icon, set };
- const p = set.prefix || set.id;
- const rows = [["What it draws", icon.description], ["Use", icon.use], ["Avoid", icon.avoid], ["Aliases", (icon.aliases || []).join(", ")],
- ["Group", icon.group], ["File", icon.file], ["Added", icon.added ? [icon.added.date, icon.added.by, icon.added.from, icon.added.why].filter(Boolean).join(" · ") : ""]]
- .filter(([, x]) => x);
- const ids = styles.length ? styles.map((s) => s.id) : ["flat"];
- detail.replaceChildren(h("div", { class: "ic-det" },
- h("h3", {}, icon.name),
- faces(icon, set.id, 48, ids),
- h("dl", {}, rows.flatMap(([k, x]) => [h("dt", {}, k), h("dd", {}, x)])),
- h("div", { class: "ic-btns" },
- btn("Copy name", icon.name), btn("Copy " + p + ":" + icon.name, p + ":" + icon.name),
- btn("Copy path", "/assets/icons/set/" + icon.name + ".svg"),
- h("button", { class: "ic-btn", type: "button", onclick: () => { showSec(false); selected = null; draw(); } }, "Close"))));
- showSec(true);
- const sc = detSec(); if (sc && sc.tagName === "DETAILS") sc.open = true;
- function btn(label, text) { const b = h("button", { class: "ic-btn", type: "button" }, label); b.addEventListener("click", () => copy(text, b)); return b; }
- }
- function draw() {
- const px = Number(v.size) || 56;
- const ids = shownStyles();
- root.style.setProperty("--px", px + "px");
- root.style.setProperty("--cell", Math.max(104, (px + (v.surface === "page" ? 8 : 22)) * ids.length * (v.surface === "both" ? 2 : 1) + 20) + "px");
- const q = (v.q + " " + headerQ).trim().toLowerCase().split(/\s+/).filter(Boolean);
- // a link may name an icon (?icon=<name>): open its record once, at the start
- if (!draw.done) {
- draw.done = true;
- const want = new URLSearchParams(location.search).get("icon");
- for (const set of sets) { const icon = want && set.icons.find((i) => i.name === want); if (icon) { showDetail(icon, set); break; } }
- } else if (selected) showDetail(selected.icon, selected.set);
- body.replaceChildren();
- let shown = 0;
- for (const set of sets) {
- if (v.set !== "all" && set.id !== v.set) continue;
- for (const g of groups) {
- if (v.group !== "all" && g !== v.group) continue;
- const icons = set.icons.filter((i) => (i.group || "other") === g && q.every((w) => words(i).includes(w)));
- if (!icons.length) continue;
- shown += icons.length;
- body.append(h("section", { class: "ic-group", id: "g-" + set.id + "-" + g },
- h("h2", {}, g, h("small", {}, icons.length + (sets.length > 1 ? " · " + set.id : ""))),
- h("div", { class: "ic-grid" }, icons.map((icon) => {
- const cell = h("div", { class: "ic-cell" + (selected && selected.icon === icon ? " on" : ""), tabindex: "0", title: icon.description || icon.name },
- faces(icon, set.id, px, ids), h("div", { class: "ic-name" }, icon.name));
- const pick = () => { copy(icon.name, cell); showDetail(icon, set); document.querySelectorAll(".ic-cell.on").forEach((x) => x.classList.remove("on")); cell.classList.add("on"); };
- cell.addEventListener("click", pick);
- cell.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); pick(); } });
- return cell;
- }))));
- }
- }
- if (!shown) body.append(h("p", { class: "ic-empty" }, sets.length ? "No icon matches." : "Install an icon set, then run shtuk run icons lens."));
- counts.replaceChildren(...Lens.stats([["Icons", String(sets.reduce((n, s) => n + s.icons.length, 0))], ["Shown", String(shown)], ["Groups", String(groups.length)], ["Styles", String(styles.length)]]));
- }
- const counts = h("div", { class: "lx-stats" });
- ui.section("Overview", (D.errors || []).map((e) => h("p", { class: "ic-warn" }, e)),
- h("p", { class: "ic-empty", style: "margin:0 0 8px" }, sets.length ? sets.map((s) => s.icons.length + " icons in " + s.id).join("; ") + "." + (styles.length ? " The project's icon style: " + (D.style || "none") + "." : " No icon style is installed: the flat drawings are shown.")
- : "No icon set is installed: a set is /design/<set>/registry.json with its flat drawings."),
- counts);
- if (styles.length) ui.section("Installed styles", h("div", { class: "ic-styles" }, styles.map((s) => h("span", {}, h("b", {}, s.id), " " + s.role))));
- const styleOpts = [["all", "All side by side"], ...styles.map((s) => [s.id, s.id + " — " + s.title.replace(/^\S+\s/, "")])];
- if (!styles.length) styleOpts.splice(1, 0, ["flat", "flat"]);
- const controls = {
- style: { kind: "select", label: "Style", options: styleOpts, default: v.style },
- size: { kind: "select", label: "Size", options: SIZES.map((s) => [s, s + " px"]), default: "48" },
- surface: { kind: "segment", label: "Surface", options: [["page", "Page"], ["light", "Light"], ["dark", "Dark"], ["both", "Both"]], default: "page" },
- };
- const filter = {
- group: { kind: "select", label: "Group", options: [["all", "All groups"], ...groups.map((g) => [g, g])], default: "all" },
- q: { kind: "text", label: "Search", default: "" },
- };
- if (sets.length > 1) filter.set = { kind: "select", label: "Set", options: [["all", "All sets"], ...sets.map((s) => [s.id, s.id])], default: "all" };
- const onChange = (vals) => { v = Object.assign(v, vals); draw(); };
- const opts = {
- title: "Settings", storageKey: "icons-lens", target: h("div", { hidden: true }),
- sections: [{ title: "View", controls }, { title: "Filter", controls: filter }],
- presets: { main: {}, "small rows": { size: "16", surface: "page" }, "light and dark": { size: "48", surface: "both" }, "all styles": { style: "all", size: "48", surface: "page" } },
- onChange,
- };
- if (ui.settings) ui.settings(opts);
- else if (window.Explore && window.Explore.panel && !window.Explore.standIn) window.Explore.panel(Object.assign({}, opts, { container: ui.section() }));
- else {
- // a stand-in when the explore kit is not installed: the same controls as plain fields in the side panel
- const box = h("div", { class: "ic-standin" });
- for (const [k, c] of Object.entries(Object.assign({}, controls, filter))) {
- const opts = (c.options || []).map((o) => Array.isArray(o) ? o : [o, o]);
- const input = c.kind === "text" ? h("input", { type: "search", value: v[k] || "" }) : h("select", {}, opts.map(([val, lab]) => h("option", String(v[k]) === String(val) ? { value: val, selected: true } : { value: val }, lab)));
- input.addEventListener("input", () => onChange({ [k]: input.value }));
- box.append(h("label", {}, c.label || k, input));
- }
- ui.section("Settings", box, h("p", { class: "lx-hint" }, "The explore kit (lib/explore.js) is not there: plain fields are used."));
- draw();
- }
- Lens.on("search", (q) => { headerQ = q || ""; draw(); });
- };
- })();
- </script>
- </head>
- <body><p class="lx-missing">The lens "Icons". There is no data yet: build it from the project root with <code>shtuk run lenses build</code> and <code>shtuk run icons lens</code>.</p></body>
- </html>