ShtukbaseStandard
包页面→ /base/packages.html

pages/base/packages.html

411 行, 24.8 KB. 直接打开 (在项目中它旁边还有其他文件,这里可能缺失).

文件按包中的原样显示:代码及其注释不做翻译。

  1. <!--
  2. ---
  3. type: Lens
  4. title: "Project packages"
  5. icon: "📦"
  6. description: "The package map: every installed package on a canvas, by group or by dependency layer; a click shows its version, source, dependencies, actions, checks and norms."
  7. template: custom
  8. layout: canvas
  9. lensType: map
  10. render: live
  11. sources: [".shtukbase/packages.lock", ".shtukbase/packages/*/package.md"]
  12. generator: "shtuk run lenses build"
  13. ---
  14. A service lens of `lenses`, read from `lib/base/packages.data.js` (`shtuk run lenses build`). A canvas: drag to pan,
  15. Ctrl or Cmd and the wheel to zoom, F to fit. The card presets and the arrangement are in the right panel.
  16. -->
  17. <!doctype html>
  18. <html lang="en">
  19. <head>
  20. <meta charset="utf-8">
  21. <meta name="viewport" content="width=device-width, initial-scale=1">
  22. <title>Project packages</title>
  23. <link rel="stylesheet" href="../lib/kit.css">
  24. <link rel="stylesheet" href="../lib/explore.css">
  25. <script src="../lib/data.js"></script>
  26. <script src="../lib/base/packages.data.js"></script>
  27. <script src="../lib/design/components.data.js"></script>
  28. <script src="../lib/explore.js"></script>
  29. <script src="../lib/kit.js"></script>
  30. <style>
  31. /* The map, modelled on the explore kit's "Core and packages": groups of cards on a canvas. Contract names only, each with a
  32. fallback; the settings land on .pm as data-<name> and --x-<name>. */
  33. .pm { --pm-fg: var(--foreground, var(--ink, #191919)); --pm-mute: var(--muted-foreground, var(--lx-muted, #6f6e69)); --pm-line: var(--border, var(--line, #e9e9e7));
  34. --pm-bg: var(--background, var(--bg, #fff)); --pm-r: var(--x-radius, 8px);
  35. display: flex; flex-wrap: wrap; align-items: flex-start; gap: 56px 64px; padding: 48px; width: max-content; max-width: 1320px; color: var(--pm-fg); box-sizing: border-box; }
  36. .pm *, .pm *::before, .pm *::after { box-sizing: border-box; }
  37. .pm[data-arrange="layers"] { flex-direction: column; flex-wrap: nowrap; gap: 56px; max-width: none; }
  38. /* the canvas under the map */
  39. .pm-scroll[data-canvas="dots"] { background: var(--background, var(--bg, #fff)) radial-gradient(circle, color-mix(in srgb, var(--foreground, var(--ink, #191919)) 16%, transparent) 1px, transparent 1.3px) 0 0 / 22px 22px; }
  40. .pm-scroll[data-canvas="grid"] { background: linear-gradient(color-mix(in srgb, var(--foreground, var(--ink, #191919)) 6%, transparent) 1px, transparent 1px) 0 0 / 24px 24px,
  41. linear-gradient(90deg, color-mix(in srgb, var(--foreground, var(--ink, #191919)) 6%, transparent) 1px, transparent 1px) 0 0 / 24px 24px, var(--background, var(--bg, #fff)); }
  42. /* a group: a quiet heading (name, count, one line) above its cards; groups are told apart by space only, no border, no fill */
  43. .pm-area { --ac: var(--chart-2, #2383e2); flex: none; }
  44. .pm-area > h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; display: flex; align-items: baseline; gap: 8px; }
  45. .pm-area > h2 span { font-size: 12px; font-weight: 400; color: var(--pm-mute); }
  46. .pm-area > p { margin: 0 0 14px; width: 0; min-width: 100%; color: var(--pm-mute); font-size: 12.5px; line-height: 1.4; }
  47. .pm-area > h2 + .pm-cards { margin-top: 12px; }
  48. .pm-cards { display: grid; grid-template-columns: repeat(var(--cols, 1), var(--card-w, 300px)); gap: 10px; }
  49. .pm[data-size="s"] { --card-w: 236px; }
  50. .pm[data-size="l"] { --card-w: 340px; }
  51. .pm[data-arrange="layers"] .pm-cards { display: flex; flex-wrap: nowrap; }
  52. .pm[data-arrange="layers"] .pm-card { width: var(--card-w, 300px); }
  53. /* a card */
  54. .pm-card { all: unset; box-sizing: border-box; position: relative; overflow: hidden; display: flex; gap: 12px; padding: 12px; min-width: 0;
  55. background: var(--pm-bg); border-radius: var(--pm-r); cursor: pointer; transition: box-shadow var(--sb-dur, .18s) var(--sb-ease, ease); }
  56. .pm[data-edge="shadow"] .pm-card { box-shadow: var(--sb-edge, 0 0 0 1px color-mix(in srgb, var(--pm-fg) 12%, transparent), 0 0 8px color-mix(in srgb, var(--pm-fg) 5%, transparent)); }
  57. .pm[data-edge="shadow"] .pm-card:hover { box-shadow: var(--sb-shadow-lift, 0 0 0 1px color-mix(in srgb, var(--pm-fg) 16%, transparent), 0 2px 12px color-mix(in srgb, var(--pm-fg) 9%, transparent)); }
  58. .pm[data-edge="border"] .pm-card { box-shadow: 0 0 0 1px var(--pm-line); }
  59. .pm[data-edge="border"] .pm-card:hover { box-shadow: 0 0 0 1px color-mix(in srgb, var(--pm-fg) 24%, transparent); }
  60. .pm[data-edge="none"] .pm-card:hover { background: color-mix(in srgb, var(--pm-fg) 4%, var(--pm-bg)); }
  61. .pm .pm-card.on { box-shadow: 0 0 0 2px var(--ring, #e04a72); }
  62. .pm .pm-card:focus-visible { box-shadow: 0 0 0 2px var(--ring, #e04a72); }
  63. .pm[data-form="top"] .pm-card { flex-direction: column; }
  64. .pm-ic { flex: none; width: 40px; height: 40px; display: grid; place-items: center; font-size: 26px; line-height: 1; }
  65. .pm-ic img { width: 100%; height: 100%; object-fit: contain; display: block; }
  66. .pm[data-size="s"] .pm-ic { width: 28px; height: 28px; font-size: 20px; }
  67. .pm[data-size="l"] .pm-ic { width: 52px; height: 52px; font-size: 34px; }
  68. .pm-t { min-width: 0; flex: 1; display: flex; flex-direction: column; }
  69. .pm-t b { font-size: 13.5px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  70. .pm-d { color: var(--pm-mute); font-size: 12px; line-height: 1.4; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
  71. .pm[data-size="s"] .pm-d { display: none; }
  72. .pm[data-size="l"] .pm-d { -webkit-line-clamp: 3; }
  73. [data-cover="hair"] .pm-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: var(--ac); }
  74. [data-cover="tint"] .pm-card { background: linear-gradient(180deg, color-mix(in srgb, var(--ac) 9%, var(--pm-bg)), var(--pm-bg) 60%); }
  75. [data-cover="stripe"] .pm-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--ac); }
  76. .pm-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
  77. .pm-chip { font: 11px/1 var(--font-mono, ui-monospace, monospace); padding: 4px 6px; border-radius: min(var(--pm-r), 99px); white-space: nowrap; }
  78. [data-chips="outline"] .pm-chip { box-shadow: inset 0 0 0 1px var(--pm-line); color: var(--pm-mute); }
  79. [data-chips="tone"] .pm-chip { background: color-mix(in srgb, var(--pm-fg) 6%, var(--pm-bg)); color: var(--pm-mute); }
  80. [data-chips="juicy"] .pm-chip { background: color-mix(in srgb, var(--ac) 16%, var(--pm-bg)); color: color-mix(in srgb, var(--ac) 60%, var(--pm-fg)); }
  81. .pm .pm-chip.miss { box-shadow: inset 0 0 0 1px var(--destructive, #e85339); color: var(--destructive, #e85339); background: none; }
  82. .pm[data-size="l"] .pm-t b { font-size: 15px; }
  83. .pm-area > .pm-layer-h { font-size: 12.5px; color: var(--pm-mute); margin: 0 0 12px; width: auto; min-width: 0; }
  84. /* Package details inside the shared peek. */
  85. .pm-det { display: flex; flex-direction: column; gap: 14px; font-size: 13px; line-height: 1.4; }
  86. .pm-det p { margin: 0; }
  87. .pm-det .k { font-size: 12px; color: var(--muted-foreground, #6f6e69); margin-bottom: 4px; }
  88. .pm-det .mono { font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; overflow-wrap: anywhere; color: var(--muted-foreground, #6f6e69); }
  89. .pm-det .links { display: flex; flex-wrap: wrap; gap: 4px 10px; }
  90. .pm-det .links a { text-decoration: underline; text-decoration-color: var(--border, #e9e9e7); text-underline-offset: 3px; }
  91. .pm-det .links .miss { color: var(--destructive, #e85339); }
  92. .pm-det ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
  93. .pm-det li { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 0 8px; }
  94. .pm-det li code { font-size: 12px; }
  95. .pm-det li .chk { color: var(--muted-foreground, #6f6e69); font-size: 12px; }
  96. .pm-det .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--muted-foreground, #6f6e69); }
  97. .pm-det .dot.enforce { background: var(--chart-3, #01a26f); }
  98. .pm-det .dot.observe { background: var(--chart-4, #ef7f16); }
  99. .pm-det a { color: inherit; cursor: pointer; }
  100. .pm-warn { color: var(--destructive, #e85339); font-size: 12.5px; margin: 0 0 6px; }
  101. </style>
  102. <script>
  103. (function () {
  104. const { h } = Lens;
  105. const keys = (o) => Object.keys(o || {});
  106. const HUES = ["var(--chart-1, #e04a72)", "var(--chart-2, #2383e2)", "var(--chart-3, #01a26f)", "var(--chart-4, #ef7f16)", "var(--chart-5, #975cdc)"];
  107. const href = (p) => Lens.rootHref + String(p).replace(/^\//, "");
  108. // A source is a folder, a git address or a registry name; only its last two parts are shown (no home paths on screen).
  109. const shortSource = (s) => { const parts = String(s || "").replace(/[\\/]+$/, "").split(/[\\/]/); return parts.length > 2 ? "…/" + parts.slice(-2).join("/") : String(s || ""); };
  110. const firstSentence = (s) => { const m = /^(.+?[.!?])(\s|$)/.exec(String(s || "")); return m ? m[1] : String(s || ""); };
  111. Lens.templates.custom = function (cfg) {
  112. const ui = Lens.page(Object.assign({ layout: "canvas" }, cfg));
  113. const D = window.SHTUK_PACKAGES;
  114. if (!D) { ui.main.append(h("p", { class: "pm-warn", style: "padding:24px" }, "There is no package data. Build it from the project root: shtuk run lenses build")); return; }
  115. const P = D.packages, byId = Object.setPrototypeOf(Object.fromEntries(P.map((p) => [p.id, p])), null);
  116. const isSet = (p) => keys(p.includes).length > 0 || p.kind === "set";
  117. const usedBy = (id) => P.filter((p) => keys(p.requires).includes(id)).map((p) => p.id);
  118. const inSets = (id) => P.filter((s) => isSet(s) && keys(s.includes).includes(id)).map((s) => s.id);
  119. // ---------- groups: a set and what it includes; then families by the first part of the id; then the rest ----------
  120. const groups = [], placed = new Set();
  121. for (const s of P.filter(isSet)) {
  122. const ids = [s.id, ...keys(s.includes).filter((i) => byId[i] && !placed.has(i))];
  123. ids.forEach((i) => placed.add(i));
  124. groups.push({ title: s.title, note: firstSentence(s.description), ids });
  125. }
  126. const fam = {};
  127. for (const p of P) if (!placed.has(p.id)) { const f = p.id.split("-")[0]; (fam[f] = fam[f] || []).push(p.id); }
  128. const rest = [];
  129. for (const [f, ids] of Object.entries(fam)) {
  130. if (ids.length < 2) { rest.push(...ids); continue; }
  131. groups.push({ title: f[0].toUpperCase() + f.slice(1), note: "", ids });
  132. }
  133. if (rest.length) groups.push({ title: groups.length ? "Other packages" : "Packages", note: "", ids: rest });
  134. groups.forEach((g, i) => { g.ac = HUES[i % HUES.length]; });
  135. const acOf = {};
  136. for (const g of groups) for (const id of g.ids) acOf[id] = g.ac;
  137. // ---------- layers: a package stands one row below the deepest package it requires ----------
  138. const depth = {};
  139. const deep = (id, seen) => {
  140. if (depth[id] !== undefined) return depth[id];
  141. if (seen.has(id)) return 0;
  142. seen.add(id);
  143. const up = keys(byId[id].requires).filter((r) => byId[r]).map((r) => deep(r, seen) + 1);
  144. return (depth[id] = up.length ? Math.max(...up) : 0);
  145. };
  146. P.forEach((p) => deep(p.id, new Set()));
  147. // ---------- what is wrong ----------
  148. const warns = [];
  149. for (const p of P) {
  150. for (const r of keys(p.requires)) if (!byId[r]) warns.push(p.title + " requires " + r + ", which is not installed.");
  151. if (!p.manifest) warns.push(p.title + " has no package.md in .shtukbase/packages/" + p.id + "/.");
  152. }
  153. // ---------- a card ----------
  154. const cards = Object.create(null);
  155. function card(p) {
  156. const missing = keys(p.requires).filter((r) => !byId[r]);
  157. const checks = p.actions.filter((a) => a.check).length;
  158. const el = h("button", { type: "button", class: "pm-card", "data-node": p.id, "data-id-pkg": p.id, title: p.title, style: "--ac:" + (acOf[p.id] || HUES[0]),
  159. "aria-haspopup": "dialog", "aria-expanded": p.id === sel ? "true" : "false",
  160. onclick: (e) => {
  161. e.stopPropagation();
  162. choose(p.id, e.detail ? { clientX: e.clientX, clientY: e.clientY } : el, el);
  163. } },
  164. h("span", { class: "pm-ic" }, p.icon ? h("img", { src: href(p.icon), alt: "" }) : "📦"),
  165. h("span", { class: "pm-t" }, h("b", {}, p.title), p.description ? h("span", { class: "pm-d" }, firstSentence(p.description)) : null,
  166. h("span", { class: "pm-chips" }, h("span", { class: "pm-chip" }, "v" + p.version),
  167. isSet(p) ? h("span", { class: "pm-chip" }, "set") : null,
  168. checks ? h("span", { class: "pm-chip" }, "checks " + checks) : null,
  169. p.norms.length ? h("span", { class: "pm-chip" }, "norms " + p.norms.length) : null,
  170. missing.length ? h("span", { class: "pm-chip miss", title: "Not installed: " + missing.join(", ") }, "missing " + missing.length) : null)));
  171. cards[p.id] = el;
  172. return el;
  173. }
  174. // ---------- the map ----------
  175. const map = h("div", { class: "pm" });
  176. const scroller = ui.main;
  177. scroller.classList.add("pm-scroll");
  178. let edgesApi = null;
  179. function arrange(how) {
  180. if (edgesApi && edgesApi.destroy) edgesApi.destroy();
  181. map.querySelectorAll(":scope > svg, .lx-edges").forEach((x) => x.remove());
  182. edgesApi = null;
  183. map.replaceChildren();
  184. if (how === "layers") {
  185. const rows = [];
  186. for (const p of P) (rows[depth[p.id]] = rows[depth[p.id]] || []).push(p);
  187. rows.forEach((r, i) => map.append(h("section", { class: "pm-area" },
  188. h("p", { class: "pm-layer-h" }, i === 0 ? "Layer 1: needs nothing" : "Layer " + (i + 1)),
  189. h("div", { class: "pm-cards" }, (r || []).map(card)))));
  190. const edges = P.flatMap((p) => keys(p.requires).filter((r) => byId[r]).map((r) => ({ from: p.id, to: r, kind: "requires" })));
  191. requestAnimationFrame(() => { edgesApi = Lens.edges(map, edges, { kinds: { requires: { label: "requires", color: "blue" } } }); });
  192. } else {
  193. for (const g of groups) {
  194. const cols = g.ids.length > 4 ? 2 : 1;
  195. map.append(h("section", { class: "pm-area", style: "--ac:" + g.ac },
  196. h("h2", {}, g.title, h("span", {}, String(g.ids.length))), g.note ? h("p", {}, g.note) : null,
  197. h("div", { class: "pm-cards", style: "--cols:" + cols }, g.ids.map((id) => card(byId[id])))));
  198. }
  199. }
  200. if (sel && cards[sel]) cards[sel].classList.add("on");
  201. }
  202. scroller.append(map);
  203. // ---------- the card host and the package details ----------
  204. const frame = ui.layout;
  205. const template = h("template", {});
  206. const bundledPeek = "/design/shtukbase-ui-html/components/block/peek/peek.html";
  207. const specimen = (window.SB_COMPONENTS?.components || []).find((c) => c.id === "peek")?.html;
  208. const loadPeek = specimen?.templates?.default
  209. ? Promise.resolve(specimen.templates.default)
  210. : fetch(href(specimen?.source || bundledPeek)).then(async (response) => {
  211. if (!response.ok) return null;
  212. const doc = new DOMParser().parseFromString(await response.text(), "text/html");
  213. return doc.querySelector('template[data-state="default"]')?.innerHTML;
  214. }).catch(() => null);
  215. const modes = ["side", "center", "card"];
  216. const prefKey = "lx-open-mode";
  217. const preferred = new URLSearchParams(location.search).get("peek-mode") || Lens.prefs.get(prefKey, "side");
  218. let sel = null, handle = null, peek = null, mode = modes.includes(preferred) ? preferred : "side", request = 0;
  219. let sourceCard = null;
  220. const panelMode = () => mode === "card" ? "peek" : mode;
  221. const part = (name) => peek.querySelector(`[data-slot="peek-${name}"]`);
  222. const packageLink = (p) => href(p.pages.find((page) => page.path.endsWith("/" + p.id + ".md"))?.path
  223. || "/.shtukbase/packages/" + encodeURIComponent(p.id) + "/package.md");
  224. const mapLink = (id) => {
  225. const url = new URL(location.href);
  226. if (mode !== "side") url.searchParams.set("peek-mode", mode);
  227. else url.searchParams.delete("peek-mode");
  228. if (id) url.searchParams.set("package", id);
  229. else url.searchParams.delete("package");
  230. return url;
  231. };
  232. function select(id) {
  233. sel = id;
  234. for (const [key, el] of Object.entries(cards)) {
  235. el.classList.toggle("on", key === sel);
  236. el.setAttribute("aria-expanded", String(key === sel));
  237. }
  238. history.replaceState(null, "", mapLink(id));
  239. }
  240. function showMode(anchor) {
  241. if (!peek || !sel) return;
  242. peek.dataset.mode = mode;
  243. for (const el of part("modes").children)
  244. el.setAttribute("aria-pressed", String(el.dataset.mode === mode));
  245. handle = frame.openCard(peek, { mode: panelMode(), anchor });
  246. }
  247. function setMode(value) {
  248. if (!modes.includes(value) || value === mode) return;
  249. mode = value;
  250. Lens.prefs.set(prefKey, mode);
  251. modePicker.value = mode;
  252. history.replaceState(null, "", mapLink(sel));
  253. showMode();
  254. }
  255. if (frame?.cardHost) new MutationObserver(() => {
  256. if (!handle || frame.cardHost.dataset.state !== "closed") return;
  257. handle = null;
  258. select(null);
  259. if (sourceCard) {
  260. const target = sourceCard.el.isConnected ? sourceCard.el : cards[sourceCard.id];
  261. target?.focus({ preventScroll: true });
  262. }
  263. sourceCard = null;
  264. }).observe(frame.cardHost, { attributes: true, attributeFilter: ["data-state"] });
  265. function makePeek(markup) {
  266. template.innerHTML = markup;
  267. const el = template.content.querySelector('[data-slot="peek"]');
  268. if (!el) return null;
  269. // The lens build joins CSS into lib/kit.css, so resolve registry assets from the project root.
  270. for (const icon of el.querySelectorAll("[data-icon]")) {
  271. const url = href("/design/shtukbase-icons/flat/" + icon.dataset.icon + ".svg");
  272. icon.style.setProperty("--peek-icon", `url("${url}")`);
  273. }
  274. el.addEventListener("click", (event) => {
  275. const control = event.target.closest('[data-slot="peek-mode"], [data-slot="peek-close"]');
  276. if (!control) return;
  277. if (control.dataset.slot === "peek-close") handle?.close();
  278. else setMode(control.dataset.mode);
  279. });
  280. return el;
  281. }
  282. function sec(title, ...nodes) { const n = nodes.flat().filter(Boolean); return n.length ? h("div", {}, h("div", { class: "k" }, title), n) : null; }
  283. const linkList = (ids) => h("div", { class: "links" }, ids.map((id) => byId[id]
  284. ? h("a", { href: mapLink(id).href, onclick: (event) => {
  285. if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
  286. event.preventDefault();
  287. choose(id);
  288. } }, byId[id].title)
  289. : h("span", { class: "miss" }, id)));
  290. function details(p) {
  291. const req = keys(p.requires);
  292. return h("div", { class: "pm-det" },
  293. h("p", { class: "mono" }, p.id + " · v" + p.version),
  294. p.description ? h("p", {}, p.description) : null,
  295. sec("Source", h("div", { class: "mono", title: p.source }, shortSource(p.source)), p.installed ? h("div", { class: "mono" }, "installed " + p.installed) : null),
  296. req.length ? sec("Requires", linkList(req)) : null,
  297. usedBy(p.id).length ? sec("Required by", linkList(usedBy(p.id))) : null,
  298. keys(p.includes).length ? sec("Includes", linkList(keys(p.includes))) : null,
  299. inSets(p.id).length ? sec("In sets", linkList(inSets(p.id))) : null,
  300. p.actions.length ? sec("Actions", h("ul", {}, p.actions.map((a) => h("li", {}, h("code", {}, a.name), h("span", {}, a.title || a.run, a.check ? h("span", { class: "chk" }, " · check") : null))))) : null,
  301. p.norms.length ? sec("Norms", h("ul", {}, p.norms.map((n) => h("li", {}, h("span", { class: "dot " + (n.enforcers && n.enforcers.length ? n.mode : "") , title: n.enforcers && n.enforcers.length ? n.mode : "no enforcer" }),
  302. h("a", { href: href(n.path) }, n.id + " — " + n.title))))) : null,
  303. p.pages.length ? sec("Pages", h("div", { class: "mono" }, p.pages.length + " pages" + (p.pages.some((x) => x.state !== "clean") ? ", " + p.pages.filter((x) => x.state !== "clean").length + " edited" : ""))) : null);
  304. }
  305. async function choose(id, anchor, source) {
  306. const p = byId[id];
  307. if (!p) return;
  308. const ticket = ++request;
  309. const markup = peek ? null : await loadPeek;
  310. if (ticket !== request) return;
  311. if (!peek && markup) peek = makePeek(markup);
  312. if (!peek || !frame?.openCard) {
  313. location.assign(packageLink(p));
  314. return;
  315. }
  316. if (source) sourceCard = { id, el: source };
  317. select(id);
  318. const title = part("title");
  319. title.textContent = p.title;
  320. part("page").href = packageLink(p);
  321. const body = part("body");
  322. body.replaceChildren(details(p));
  323. (body.closest('[data-slot="scroll-area-viewport"]') || body).scrollTop = 0;
  324. part("footer").replaceChildren();
  325. showMode(anchor);
  326. if (!source) title.focus({ preventScroll: true });
  327. }
  328. scroller.addEventListener("click", (event) => {
  329. if (!event.target.closest(".pm-card, .lx-zoomctl")) handle?.close();
  330. });
  331. const counts = [["Packages", String(P.filter((p) => !isSet(p)).length)], ["Sets", String(P.filter(isSet).length)],
  332. ["Checks", String(P.reduce((n, p) => n + p.actions.filter((a) => a.check).length, 0))], ["Norms", String(P.reduce((n, p) => n + p.norms.length, 0))]];
  333. ui.section("Overview", warns.map((w) => h("p", { class: "pm-warn" }, w)), h("div", { class: "lx-stats" }, Lens.stats(counts)));
  334. const modeLabel = "Open in";
  335. const modeControl = Lens.select([["side", "Side"], ["center", "Center"], ["card", "Card"]], mode, setMode,
  336. { id: "pm-peek-mode" });
  337. const modePicker = modeControl.querySelector("select");
  338. ui.section("Settings", h("div", { class: "panel-section-row", "data-slot": "panel-section-row" },
  339. h("label", { for: modePicker.id, class: "panel-section-label", "data-slot": "panel-section-label" }, modeLabel),
  340. h("div", { class: "panel-section-control", "data-slot": "panel-section-control" }, modeControl)));
  341. if (mode !== "side") history.replaceState(null, "", mapLink(new URLSearchParams(location.search).get("package")));
  342. const opts = {
  343. title: "Settings",
  344. target: map,
  345. storageKey: "packages-map",
  346. sections: [
  347. { title: "Layout", controls: {
  348. arrange: { kind: "segment", label: "Arrange", options: [["groups", "groups"], ["layers", "layers"]], default: "groups" },
  349. canvas: { kind: "segment", label: "Canvas", options: [["dots", "dots"], ["grid", "grid"], ["plain", "plain"]], default: "dots" } } },
  350. { title: "Cards", controls: {
  351. form: { kind: "segment", label: "Icon", options: [["left", "left"], ["top", "on top"]], default: "left" },
  352. size: { kind: "segment", options: [["s", "S"], ["m", "M"], ["l", "L"]], default: "m" },
  353. cover: { kind: "select", options: [["none", "none"], ["hair", "line on top"], ["tint", "tint from the top"], ["stripe", "stripe on the left"]], default: "none" },
  354. edge: { kind: "segment", options: ["shadow", "border", "none"], default: "shadow" },
  355. chips: { kind: "select", options: [["outline", "grey outline"], ["tone", "grey tone"], ["juicy", "group colour"]], default: "outline" },
  356. radius: { kind: "range", label: "Rounding", min: 0, max: 16, step: 1, unit: "px", default: 8 } } },
  357. ],
  358. presets: {
  359. main: {},
  360. editorial: { form: "top", size: "l", cover: "tint", chips: "tone", radius: 12, edge: "shadow", canvas: "plain" },
  361. quiet: { cover: "none", edge: "border", chips: "tone", canvas: "plain" },
  362. juicy: { cover: "stripe", chips: "juicy", radius: 14, canvas: "grid" },
  363. },
  364. onChange: (v) => {
  365. scroller.dataset.canvas = v.canvas || "dots";
  366. if (v.arrange !== map.dataset.arranged) { map.dataset.arranged = v.arrange; arrange(v.arrange); }
  367. else if (edgesApi && edgesApi.redraw) requestAnimationFrame(() => edgesApi.redraw());
  368. },
  369. };
  370. if (ui.settings) ui.settings(opts);
  371. else if (window.Explore && !window.Explore.standIn) window.Explore.panel(Object.assign({}, opts, { container: ui.section() }));
  372. else {
  373. const d = { arrange: "groups", canvas: "dots", form: "left", size: "m", cover: "none", edge: "shadow", chips: "outline" };
  374. for (const [k, v] of Object.entries(d)) map.dataset[k] = v;
  375. opts.onChange(d);
  376. }
  377. if (!map.dataset.arranged) { map.dataset.arranged = map.dataset.arrange || "groups"; arrange(map.dataset.arranged); }
  378. // ---------- the canvas: pan, zoom, fit ----------
  379. const zoom = ui.zoom || Lens.zoom(scroller, map, { pan: true });
  380. const want = new URLSearchParams(location.search).get("package");
  381. // Fit first so a linked package can anchor to its final position.
  382. requestAnimationFrame(() => {
  383. if (zoom && !zoom.restored && zoom.fit) zoom.fit();
  384. if (byId[want]) choose(want, cards[want], cards[want]);
  385. });
  386. Lens.on("search", (q) => {
  387. for (const [id, c] of Object.entries(cards)) {
  388. const p = byId[id], hit = !q || (p.title + " " + p.id + " " + p.description).toLowerCase().includes(q);
  389. c.style.opacity = hit ? "" : ".25";
  390. }
  391. });
  392. };
  393. })();
  394. </script>
  395. </head>
  396. <body><p class="lx-missing">The lens "Project packages". There is no data yet: build it from the project root with <code>shtuk run lenses build</code>.</p></body>
  397. </html>