返回资讯中心
外部精选
软件工程
#开发者实时流

Neuron Persona Library

const anchor = r => `n-L${r.L}-${r.n}-${r.s > 0 ? "p" : "m"}`;

Hacker News 最新chasingbrains2026/10/28 · 2 天前15 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

; const ICON_BOT = ``; const anchor = r => n-L${r.L}-${r.n}-${r.s > 0 ? "p" : "m"}; const pa = p => L${p.L}-${p.n}-${p.s > 0 ? "p" : "m"}; const canchor = r => c-${r.ps.map(pa).join("-")}; const slug = t => t.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60); const DISPLAY = '"Newsreader", "Iowan Old Style", Georgia, serif'; function balance(ctx, words, k) { const n = words.length, W = (a, b) => ctx.measureText(words.slice(a, b).join(" ")).width, memo = new Map(); const go = (i, j) => { if (j === 1) return [W(i, n), [n]]; const kk = i * 64 + j; if (memo.has(kk)) return memo.get(kk); let best = [Infinity, null]; for (let c = i + 1; c { const line = words.slice(a, c).join(" "); a = c; return line; }); } /* a name of any length at the largest size its column allows (430 px wide, maxH tall), on as many balanced lines as it needs */ function nameLayout(name, maxH = 470) { const ctx = (nameLayout.ctx ||= document.createElement("canvas").getContext("2d")); const words = name.split(" ").filter(Boolean), CAP = [168, 140, 118, 100, 86, 74, 64, 56, 50, 44, 40, 36]; let lines = [name]; for (let size = 168; size >= 22; size -= 2) { ctx.font = 500 ${size}px ${DISPLAY}; lines = []; for (const w of words) { const t = lines.length ? ${lines[lines.length - 1]} ${w}: w; if (lines.length && ctx.measureText(t).width ctx.measureText(l).width r.ps.length > 2 ?L${p.L} N${p.n} ${sgn(p.s)}:Layer ${p.L} · Neuron ${p.n} ${sgn(p.s)}; return { top: r.ps.map(addr).join(" + "), kicker: r.ps.map(p => p.name).join(" + "), name: r.persona, text: r.text, who: ${M.name}, with these ${r.ps.length === 2 ? "two" : "three"} neurons pushed, cc: cssVar(--k-${r.kind}) || "#d4752b", anchor: canchor(r), file: ${slug(M.name)}-combo-${r.ps.map(pa).join("-")}-${slug(r.persona) || "combo"}.png}; } const name = r.persona && r.persona !== "None" ? r.persona : LABEL[S.cats[r.cat]] || "Neuron"; return { top:Layer ${r.L} · Neuron ${r.n} · sign ${sgn(r.s)}, kicker: null, name, text: r.text, who: ${M.name}, with this one neuron pushed, cc: cssVar(--c-${S.cats[r.cat]}) || "#d4752b", anchor: anchor(r), file: ${slug(M.name)}-L${r.L}-N${r.n}-${r.s > 0 ? "plus" : "minus"}-${slug(r.persona) || "neuron"}.png}; } /* a click opens the share card: the image, drawn for posting, with the whole reply one tap away (Full reply and details). While a card is open the address bar holds its link, and Back closes it. */ const COARSE = matchMedia("(pointer: coarse)").matches; const CAN_SHARE = (() => { try { return !!navigator.canShare?.({ files: [new File([new Blob()], "card.png", { type: "image/png" })] }); } catch { return false; } })(); const CAN_COPY = !!(navigator.clipboard?.write && window.ClipboardItem); (function setupCardButtons() { $("pshare").hidden = !CAN_SHARE; $("pcopyimg").hidden = !CAN_COPY; // phones post through the share sheet; desktops paste an image into X, Slack or a chat const order = COARSE ? ["pshare", "pcopyimg", "pdownload"] : ["pcopyimg", "pshare", "pdownload"]; P.primary = $(order.find(id => !$(id).hidden)); P.primary.classList.add("pri"); const box = P.primary.parentElement; box.prepend(P.primary); })(); /* the whole reply once its layer is loaded; a library card starts from its excerpt and is redrawn when the layer arrives */ function cardRow(r) { if (r.combo) return r; const f = fullRow(r.L, r.n, r.s); if (f) return f; if (!layerReady(r.L) && !LAYER_FAILED.has(r.L)) { const gen = GEN, orig = P.list[P.i]; getLayer(r.L).then(() => { if (gen === GEN && !$("overlay").hidden && P.list[P.i] === orig && fullRow(r.L, r.n, r.s)) renderPoster(); }, () => {}); } return r; } function shareText(r) { const t = posterModel(r).text.trim().replace(/\s+/g, " "), q = t.length > 140 ?${t.slice(0, 139).replace(/\s+\S*$/, "")}…: t; return r.combo ?${M.name} with ${r.ps.length === 2 ? "two" : "three"} neurons pushed at once: “${q}” :${M.name} with one neuron pushed (layer ${r.L}, neuron ${r.n}, ${r.s > 0 ? "up" : "down"}): “${q}”; } function openPoster(list, i, push = true) { if (!list[i]) return; const wasOpen = !$("overlay").hidden; if (!wasOpen) P.focus = document.activeElement; P.list = list; P.i = i; if (!$("sheet").hidden) hideSheet(); $("overlay").hidden = false; document.body.style.overflow = "hidden"; if (push && !wasOpen && !P.pushed) { history.pushState({ card: 1 }, ""); P.pushed = true; } renderPoster(); fitPoster(); if (!wasOpen) P.primary.focus(); } /* a neuron's card from any address; a neuron the sweep has not settled has no card, so its details open instead */ function openCard(L, n, s, push = true) { const gen = GEN, row = () => fullRow(L, n, s) || S.byId.get(key3(L, n, s)) || fallbackRow(L, n, s), r = row(); if (r) { openPoster([r], 0, push); return; } const t = setTimeout(() => toast("Loading…"), 200); const go = () => { clearTimeout(t); if (gen !== GEN) return; const r2 = row(); r2 ? openPoster([r2], 0, push) : openNeuron(L, n, s); }; getLayer(L).then(go, go); } /* leaving a card or its details: drop the history entry the card pushed, or (opened from a link) put the model's address back */ function leaveCard(fromRoute) { if (fromRoute) { P.pushed = false; return; } if (P.pushed) { P.pushed = false; P.backing = true; history.back(); } else history.replaceState(null, "", #${M.id}); } function hidePoster() { $("overlay").hidden = true; document.body.style.overflow = ""; } function closePoster(fromRoute = false) { if ($("overlay").hidden) return; hidePoster(); leaveCard(fromRoute); P.focus?.focus?.(); } function renderPoster() { const r = cardRow(P.list[P.i]), PM = posterModel(r), NL = nameLayout(PM.name, PM.kicker ? 340 : 470); const el = $("poster"); el.className = "poster" + (P.ink ? " ink" : ""); el.style.setProperty("--cc", PM.cc); el.setAttribute("aria-label", ${PM.name}. ${PM.who}: ${PM.text.trim()}); el.innerHTML = ${esc(M.name)} · ${esc(PM.top)}

${PM.kicker ? `${esc(PM.kicker)}

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →