arborist-viz/arborist_viz/static/viz/hash.js
russell@unturf.com 0cd96ab1d7
Initial commit: arborist VIZ — Merkle command center
Pyramid web app for inspecting arborist Merkle trees over sharded SQLite:
document roots, inclusion proofs, an interactive 3D Merkle lattice
(six.js / WebGL with graceful fallback), audit-chain linkage, and a live
SSE event stream.

Generated artifacts (env/, vendored static/six/ bundles, demo databases)
are gitignored and rebuilt via the Makefile (venv, six, init-db, serve).
2026-05-28 09:22:59 -04:00

32 lines
1.3 KiB
JavaScript

// Hash display helpers — see docs/style-guide.md §4.4.
//
// Atomic identifiers (SHA-256, IPFS CIDs, signatures, JWTs, UUIDs…) must
// never wrap mid-token. Visual diff degrades to a character-by-character
// scan when two hashes wrap at different columns. These helpers render
// hashes in the two non-truncated styles defined by the guide:
//
// chunkHex(h) → Mode B: "38f82216 97ee54dd …" — fixed 8x8 groups,
// wraps only at chunk boundaries. Use in .root-hash-block.
//
// shortHex(h) → Mode C: "38f82216…b1042270" — first 8 + last 8 hex.
// Always pair with title= and a click-to-copy affordance.
//
// Mode A (inline one-line scroll) needs no helper — just render the hash
// verbatim inside a `white-space: pre; overflow-x: auto` container.
export function chunkHex(value, groupSize = 8, sep = " ") {
if (!value) return value || "";
const s = String(value);
const out = [];
for (let i = 0; i < s.length; i += groupSize) {
out.push(s.slice(i, i + groupSize));
}
return out.join(sep);
}
export function shortHex(value, head = 8, tail = 8) {
if (!value) return value || "";
const s = String(value);
if (s.length <= head + tail + 1) return s;
return `${s.slice(0, head)}…${s.slice(-tail)}`;
}