ShtukbaseStandard
страница пакета→ /design/icons.html

pages/design/icons.html

230 строк, 14.9 КБ. Открыть как есть (в проекте рядом лежат другие файлы, здесь их может не быть).

Файл как есть в пакете: код и комментарии в нём не переводятся.

  1. <!--
  2. ---
  3. type: Lens
  4. title: "Icons"
  5. icon: "🏷️"
  6. 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."
  7. template: custom
  8. lensType: specimen
  9. sources: ["/design/<set>/registry.json", "/design/<set>/flat/*.svg", "IconStyle pages under /design/"]
  10. generator: "shtuk run icons lens"
  11. ---
  12. The icon lens of `icons`, read from `lib/design/icons.data.js` (`shtuk run icons lens`). The settings and the chosen
  13. icon's record are in the right panel; `?icon=<name>` opens that icon.
  14. -->
  15. <!doctype html>
  16. <html lang="en">
  17. <head>
  18. <meta charset="utf-8">
  19. <meta name="viewport" content="width=device-width, initial-scale=1">
  20. <title>Icons</title>
  21. <link rel="stylesheet" href="../lib/kit.css">
  22. <link rel="stylesheet" href="../lib/explore.css">
  23. <script src="../lib/data.js"></script>
  24. <script src="../lib/design/icons.data.js"></script>
  25. <script src="../lib/design/icon-render.js"></script>
  26. <script src="../lib/explore.js"></script>
  27. <script src="../lib/kit.js"></script>
  28. <style>
  29. /* 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
  30. when asked), its name under it; no cards. The chosen icon's record and the settings are in the right panel. */
  31. .ic { --ic-fg: var(--foreground, var(--ink, #191919)); --ic-mute: var(--muted-foreground, var(--lx-muted, #6f6e69)); --ic-line: var(--border, var(--line, #e9e9e7));
  32. --ic-row: var(--sidebar-accent, color-mix(in srgb, var(--ic-fg) 6%, transparent));
  33. 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; }
  34. .ic *, .ic *::before, .ic *::after { box-sizing: border-box; }
  35. .ic code { font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; }
  36. .ic-group h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; text-transform: capitalize; }
  37. .ic-group h2 small { font-weight: 400; color: var(--ic-mute); font-size: 12px; text-transform: none; }
  38. .ic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--cell), 1fr)); gap: 8px; }
  39. .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; }
  40. .ic-cell:hover, .ic-cell.on { background: var(--ic-row); }
  41. .ic-cell:focus-visible { box-shadow: 0 0 0 2px var(--ring, #e04a72); }
  42. .ic-faces { display: flex; gap: 6px; }
  43. .ic-face { display: flex; gap: 6px; justify-content: center; align-items: center; }
  44. .ic-face.light, .ic-face.dark { padding: 8px; border-radius: 8px; }
  45. .ic-face.light { background: #ffffff; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .06); }
  46. .ic-face.dark { background: #1f1f1f; }
  47. .ic-face img { width: var(--px); height: var(--px); display: block; }
  48. .ic-one { display: flex; flex-direction: column; align-items: center; gap: 3px; }
  49. .ic-one i { font-style: normal; font-size: 10px; color: var(--ic-mute); font-family: var(--font-mono, ui-monospace, monospace); }
  50. .ic-face.dark .ic-one i { color: #a3a29e; }
  51. .ic-name { font-size: 12px; max-width: 100%; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ic-fg); }
  52. .ic-copied .ic-name::after { content: " · copied"; color: var(--ic-mute); }
  53. .ic-empty, .ic-warn { color: var(--muted-foreground, var(--lx-muted, #6f6e69)); font-size: 13px; }
  54. .ic-warn { color: var(--destructive, #e85339); }
  55. /* the record of the chosen icon, in the right panel */
  56. .ic-det { display: flex; flex-direction: column; gap: 12px; font-size: 13px; line-height: 1.4; }
  57. .ic-det .ic-face { flex-wrap: wrap; justify-content: flex-start; gap: 10px; }
  58. .ic-det .ic-face img { width: 48px; height: 48px; }
  59. .ic-det .ic-faces { flex-direction: column; }
  60. .ic-det h3 { margin: 0; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
  61. .ic-det dl { margin: 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; }
  62. .ic-det dt { color: var(--muted-foreground, var(--lx-muted, #6f6e69)); }
  63. .ic-det dd { margin: 0; overflow-wrap: anywhere; }
  64. .ic-btns { display: flex; gap: 4px 12px; flex-wrap: wrap; }
  65. .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; }
  66. .ic-btn:hover { text-decoration-color: currentColor; }
  67. .ic-btn.ic-copied::after { content: " · copied"; color: var(--muted-foreground, #6f6e69); }
  68. .ic-styles { display: flex; gap: 4px 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted-foreground, var(--lx-muted, #6f6e69)); }
  69. .ic-styles b { color: var(--foreground, var(--ink, #191919)); font-weight: 500; }
  70. /* the stand-in controls when the explore kit is not there */
  71. .ic-standin label { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; margin: 4px 0; }
  72. </style>
  73. <script>
  74. (function () {
  75. const { h } = Lens;
  76. const D = window.SB_ICONS, R = window.SBIconRender;
  77. const SIZES = ["16", "24", "32", "48", "56", "96"];
  78. const cache = new Map();
  79. function url(styleId, icon, set) {
  80. const key = styleId + "|" + set + "|" + icon.name;
  81. if (cache.has(key)) return cache.get(key);
  82. let svg = icon.svg;
  83. const st = D.styles.find((s) => s.id === styleId);
  84. if (st && st.render && R) { try { svg = R.render(icon.svg, st.render, st.palette, { idPrefix: "i" }); } catch (e) { svg = icon.svg; } }
  85. const u = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
  86. cache.set(key, u);
  87. return u;
  88. }
  89. function copy(text, el) {
  90. const done = () => { if (el) { el.classList.add("ic-copied"); setTimeout(() => el.classList.remove("ic-copied"), 900); } };
  91. if (navigator.clipboard) navigator.clipboard.writeText(text).then(done, done); else done();
  92. }
  93. const words = (r) => [r.name, ...(r.aliases || []), r.description || "", r.use || "", r.group || ""].join(" ").toLowerCase();
  94. Lens.templates.custom = function (cfg) {
  95. const ui = Lens.page(cfg);
  96. if (!D || !R) {
  97. 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")));
  98. return;
  99. }
  100. const sets = D.sets || [];
  101. const styles = D.styles || [];
  102. const groups = [...new Set(sets.flatMap((s) => s.icons.map((i) => i.group || "other")))].sort();
  103. let v = { style: D.style || (styles[0] && styles[0].id) || "flat", size: "48", surface: "page", group: "all", set: "all", q: "" };
  104. let headerQ = "";
  105. let selected = null;
  106. const root = h("div", { class: "ic" });
  107. const body = h("div", { style: "display:flex;flex-direction:column;gap:40px" });
  108. root.append(body);
  109. ui.main.append(root);
  110. // the right panel: the chosen icon's record first, then the overview, the settings
  111. const detail = ui.section("Icon");
  112. const detSec = () => detail.card || detail.closest("[data-slot=panel-section], .lx-sec");
  113. const showSec = (on) => { const sc = detSec(); if (sc) sc.hidden = !on; };
  114. showSec(false);
  115. function faces(icon, set, px, styleIds) {
  116. const surf = v.surface === "both" ? ["light", "dark"] : [v.surface || "page"];
  117. return h("div", { class: "ic-faces" }, surf.map((s) => h("div", { class: "ic-face " + s },
  118. styleIds.map((id) => styleIds.length > 1
  119. ? h("div", { class: "ic-one" }, h("img", { src: url(id, icon, set), alt: icon.name, width: px, height: px, loading: "lazy" }), h("i", {}, id))
  120. : h("img", { src: url(id, icon, set), alt: icon.name, width: px, height: px, loading: "lazy" })))));
  121. }
  122. const shownStyles = () => v.style === "all" ? (styles.length ? styles.map((s) => s.id) : ["flat"]) : [v.style];
  123. function showDetail(icon, set) {
  124. selected = { icon, set };
  125. const p = set.prefix || set.id;
  126. const rows = [["What it draws", icon.description], ["Use", icon.use], ["Avoid", icon.avoid], ["Aliases", (icon.aliases || []).join(", ")],
  127. ["Group", icon.group], ["File", icon.file], ["Added", icon.added ? [icon.added.date, icon.added.by, icon.added.from, icon.added.why].filter(Boolean).join(" · ") : ""]]
  128. .filter(([, x]) => x);
  129. const ids = styles.length ? styles.map((s) => s.id) : ["flat"];
  130. detail.replaceChildren(h("div", { class: "ic-det" },
  131. h("h3", {}, icon.name),
  132. faces(icon, set.id, 48, ids),
  133. h("dl", {}, rows.flatMap(([k, x]) => [h("dt", {}, k), h("dd", {}, x)])),
  134. h("div", { class: "ic-btns" },
  135. btn("Copy name", icon.name), btn("Copy " + p + ":" + icon.name, p + ":" + icon.name),
  136. btn("Copy path", "/assets/icons/set/" + icon.name + ".svg"),
  137. h("button", { class: "ic-btn", type: "button", onclick: () => { showSec(false); selected = null; draw(); } }, "Close"))));
  138. showSec(true);
  139. const sc = detSec(); if (sc && sc.tagName === "DETAILS") sc.open = true;
  140. function btn(label, text) { const b = h("button", { class: "ic-btn", type: "button" }, label); b.addEventListener("click", () => copy(text, b)); return b; }
  141. }
  142. function draw() {
  143. const px = Number(v.size) || 56;
  144. const ids = shownStyles();
  145. root.style.setProperty("--px", px + "px");
  146. root.style.setProperty("--cell", Math.max(104, (px + (v.surface === "page" ? 8 : 22)) * ids.length * (v.surface === "both" ? 2 : 1) + 20) + "px");
  147. const q = (v.q + " " + headerQ).trim().toLowerCase().split(/\s+/).filter(Boolean);
  148. // a link may name an icon (?icon=<name>): open its record once, at the start
  149. if (!draw.done) {
  150. draw.done = true;
  151. const want = new URLSearchParams(location.search).get("icon");
  152. for (const set of sets) { const icon = want && set.icons.find((i) => i.name === want); if (icon) { showDetail(icon, set); break; } }
  153. } else if (selected) showDetail(selected.icon, selected.set);
  154. body.replaceChildren();
  155. let shown = 0;
  156. for (const set of sets) {
  157. if (v.set !== "all" && set.id !== v.set) continue;
  158. for (const g of groups) {
  159. if (v.group !== "all" && g !== v.group) continue;
  160. const icons = set.icons.filter((i) => (i.group || "other") === g && q.every((w) => words(i).includes(w)));
  161. if (!icons.length) continue;
  162. shown += icons.length;
  163. body.append(h("section", { class: "ic-group", id: "g-" + set.id + "-" + g },
  164. h("h2", {}, g, h("small", {}, icons.length + (sets.length > 1 ? " · " + set.id : ""))),
  165. h("div", { class: "ic-grid" }, icons.map((icon) => {
  166. const cell = h("div", { class: "ic-cell" + (selected && selected.icon === icon ? " on" : ""), tabindex: "0", title: icon.description || icon.name },
  167. faces(icon, set.id, px, ids), h("div", { class: "ic-name" }, icon.name));
  168. const pick = () => { copy(icon.name, cell); showDetail(icon, set); document.querySelectorAll(".ic-cell.on").forEach((x) => x.classList.remove("on")); cell.classList.add("on"); };
  169. cell.addEventListener("click", pick);
  170. cell.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); pick(); } });
  171. return cell;
  172. }))));
  173. }
  174. }
  175. if (!shown) body.append(h("p", { class: "ic-empty" }, sets.length ? "No icon matches." : "Install an icon set, then run shtuk run icons lens."));
  176. 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)]]));
  177. }
  178. const counts = h("div", { class: "lx-stats" });
  179. ui.section("Overview", (D.errors || []).map((e) => h("p", { class: "ic-warn" }, e)),
  180. 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.")
  181. : "No icon set is installed: a set is /design/<set>/registry.json with its flat drawings."),
  182. counts);
  183. if (styles.length) ui.section("Installed styles", h("div", { class: "ic-styles" }, styles.map((s) => h("span", {}, h("b", {}, s.id), " " + s.role))));
  184. const styleOpts = [["all", "All side by side"], ...styles.map((s) => [s.id, s.id + " — " + s.title.replace(/^\S+\s/, "")])];
  185. if (!styles.length) styleOpts.splice(1, 0, ["flat", "flat"]);
  186. const controls = {
  187. style: { kind: "select", label: "Style", options: styleOpts, default: v.style },
  188. size: { kind: "select", label: "Size", options: SIZES.map((s) => [s, s + " px"]), default: "48" },
  189. surface: { kind: "segment", label: "Surface", options: [["page", "Page"], ["light", "Light"], ["dark", "Dark"], ["both", "Both"]], default: "page" },
  190. };
  191. const filter = {
  192. group: { kind: "select", label: "Group", options: [["all", "All groups"], ...groups.map((g) => [g, g])], default: "all" },
  193. q: { kind: "text", label: "Search", default: "" },
  194. };
  195. if (sets.length > 1) filter.set = { kind: "select", label: "Set", options: [["all", "All sets"], ...sets.map((s) => [s.id, s.id])], default: "all" };
  196. const onChange = (vals) => { v = Object.assign(v, vals); draw(); };
  197. const opts = {
  198. title: "Settings", storageKey: "icons-lens", target: h("div", { hidden: true }),
  199. sections: [{ title: "View", controls }, { title: "Filter", controls: filter }],
  200. presets: { main: {}, "small rows": { size: "16", surface: "page" }, "light and dark": { size: "48", surface: "both" }, "all styles": { style: "all", size: "48", surface: "page" } },
  201. onChange,
  202. };
  203. if (ui.settings) ui.settings(opts);
  204. else if (window.Explore && window.Explore.panel && !window.Explore.standIn) window.Explore.panel(Object.assign({}, opts, { container: ui.section() }));
  205. else {
  206. // a stand-in when the explore kit is not installed: the same controls as plain fields in the side panel
  207. const box = h("div", { class: "ic-standin" });
  208. for (const [k, c] of Object.entries(Object.assign({}, controls, filter))) {
  209. const opts = (c.options || []).map((o) => Array.isArray(o) ? o : [o, o]);
  210. 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)));
  211. input.addEventListener("input", () => onChange({ [k]: input.value }));
  212. box.append(h("label", {}, c.label || k, input));
  213. }
  214. ui.section("Settings", box, h("p", { class: "lx-hint" }, "The explore kit (lib/explore.js) is not there: plain fields are used."));
  215. draw();
  216. }
  217. Lens.on("search", (q) => { headerQ = q || ""; draw(); });
  218. };
  219. })();
  220. </script>
  221. </head>
  222. <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>
  223. </html>