Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/design/v3/arrows/after-demo-1440x900.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/design/v3/arrows/after-keys-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/design/v3/arrows/after-months-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/design/v3/arrows/after-usage-1440x900.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/design/v3/arrows/before-keys-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/design/v3/arrows/before-months-3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/design/v3/arrows/before-usage-1440x900.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1 id="headline">Connecting to the office…</h1>
<div class="chart-head">
<h2 id="chart-title">The last 24 hours</h2>
<p id="chart-sub"></p>
<p class="keys" id="keys"><kbd>←</kbd> <kbd>→</kbd> scrub · <kbd>Shift</kbd> an hour · <kbd>[</kbd> <kbd>]</kbd> previous or next action · <kbd>Esc</kbd> now</p>
<p class="keys" id="keys"><kbd><svg class="arrow" viewBox="0 0 12 12" aria-hidden="true" focusable="false"><path d="M10.5 6H1.5M5.5 2L1.5 6l4 4"/></svg><span class="sr">Left arrow</span></kbd> <kbd><svg class="arrow" viewBox="0 0 12 12" aria-hidden="true" focusable="false"><path d="M1.5 6h9M6.5 2l4 4-4 4"/></svg><span class="sr">Right arrow</span></kbd> scrub · <kbd>Shift</kbd> an hour · <kbd>[</kbd> <kbd>]</kbd> previous or next action · <kbd>Esc</kbd> now</p>
</div>
<ul class="now" id="now" aria-label="Now" hidden></ul>
<div class="plot" id="plot"></div>
Expand Down
9 changes: 4 additions & 5 deletions public/lib/words.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ export function ciSummary(c) {
// can underline each name without building markup. Three forms, longest first; the page shows
// the first that fits in three lines (fitHeadline).

// Each state as a glyph too, so the colour of a ring is never the only way to tell.
export const GLYPH = { WORKING: "●", REVIEW: "◎", DISCUSS: "⋯", IDLE: "○", PAUSED: "‖", SILENT: "◌" };
export const STATE_WORDS = STATE_WORD;

// "Vega", "Vega and Rigel", "Vega, Rigel and Lyra", as parts.
Expand Down Expand Up @@ -277,12 +275,13 @@ function silentSentence(down, agents, nowS, timeZone) {
return [...out, "."];
}

// The words beside a star, and on its card: { glyph, state: "Working", words: "working on an
// issue", repo } where repo is a public repo's name or "".
// The words beside a star, and on its card: { state: "Working", words: "working on an issue",
// repo } where repo is a public repo's name or "". The state's shape is an SVG symbol (#s-WORKING
// and the rest in index.html), not a character: the fonts have none of those (setkernel-live#80).
export function stateWords(info) {
const st = STATE_WORD[info?.state] ? info.state : "IDLE";
const words = doing({ ...info, repo: undefined });
return { glyph: GLYPH[st], state: STATE_WORD[st], words, repo: isActive(info) && info.repo ? info.repo : "" };
return { state: STATE_WORD[st], words, repo: isActive(info) && info.repo ? info.repo : "" };
}

// Whose work a review was about, when the page can tell: an approval or change request in a
Expand Down
16 changes: 12 additions & 4 deletions public/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/* live.setkernel.com, v3 "Day" (setkernel-live#48; the design is docs/design/v3/day).
Manrope and IBM Plex Mono, self-hosted (SIL OFL, licences in /fonts). The mono is for clock
times only, so the axis digits share one width. */
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/manrope-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/manrope-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
times only, so the axis digits share one width. Each face's unicode-range is what its file has
(its cmap, read by test/glyphs.test.mjs), so a character none of them has, such as an arrow,
is an SVG and never falls back to a system font (setkernel-live#80). */
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/manrope-latin-400-normal.woff2") format("woff2");
unicode-range: U+0020-007E, U+00A0-00FF, U+0102, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2013-2014, U+2018-201A, U+201C-201E, U+2022, U+2026, U+2039-203A, U+2044, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 600; font-display: swap; src: url("/fonts/manrope-latin-600-normal.woff2") format("woff2");
unicode-range: U+0020-007E, U+00A0-00FF, U+0102, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2013-2014, U+2018-201A, U+201C-201E, U+2022, U+2026, U+2039-203A, U+2044, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
unicode-range: U+0020-007E, U+00A0-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+2013-2014, U+2018-201A, U+201C-201E, U+2022, U+2026, U+2032-2033, U+2039-203A, U+2044, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; }

/* One type scale, one spacing scale. Every font size and every gap below is a step of these two,
the SVG text classes too. The wall is not a second scale: it is the page drawn once on a fixed
Expand Down Expand Up @@ -62,6 +67,9 @@ a:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outlin
.legend .sw-3 { width: 80px; }
.keys { margin: 0 0 0 auto; font-size: var(--f1); line-height: var(--l1); color: var(--ink-3); white-space: nowrap; }
.keys kbd { font: var(--f1) var(--mono); border: 1px solid var(--rule-2); border-radius: 3px; padding: 0 var(--s1); color: var(--ink-2); }
/* an arrow drawn, not typed: the fonts' Latin subsets have no left or right arrow. Sized by the
text around it, in its colour; the words for it are beside it (#keys) or it is decoration (/usage). */
.arrow { width: 1em; height: 1em; vertical-align: -0.15em; fill: none; stroke: currentColor; stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; }
.mood-waiting .foot, .mood-waiting .keys { display: none; }
.table { margin-top: var(--s5); font-size: var(--f2); line-height: var(--l2); }
.table summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
Expand Down
15 changes: 13 additions & 2 deletions public/usage/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ export function failure(status) {
return `Usage didn't load (${status ? `HTTP ${status}` : "no answer"}). Reload the page to try again; if your login expired, that signs you in.`;
}

// An arrow drawn, not typed: the page's fonts have no left or right arrow (setkernel-live#80).
// The month's name beside it says where the link goes.
function arrow(d) {
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), path = document.createElementNS("http://www.w3.org/2000/svg", "path");
for (const [k, v] of Object.entries({ class: "arrow", viewBox: "0 0 12 12", "aria-hidden": "true", focusable: "false" })) svg.setAttribute(k, v);
path.setAttribute("d", d);
svg.append(path);
return svg;
}

function nav(month, current) {
const link = (m, text) => (m > current ? el("span", "off", text) : Object.assign(el("a", null, text), { href: `?month=${m}` }));
$("months").replaceChildren(link(shiftMonth(month, -1), `← ${monthName(shiftMonth(month, -1))}`), el("b", null, `${monthName(month)} ${month.slice(0, 4)}`), link(shiftMonth(month, 1), `${monthName(shiftMonth(month, 1))} →`));
const link = (m, ...kids) => { const e = m > current ? el("span", "off") : Object.assign(el("a"), { href: `?month=${m}` }); e.append(...kids); return e; };
const prev = shiftMonth(month, -1), next = shiftMonth(month, 1);
$("months").replaceChildren(link(prev, arrow("M10.5 6H1.5M5.5 2L1.5 6l4 4"), el("span", null, monthName(prev))), el("b", null, `${monthName(month)} ${month.slice(0, 4)}`), link(next, el("span", null, monthName(next)), arrow("M1.5 6h9M6.5 2l4 4-4 4")));
}

// A number: its data-* attributes are the exact values its box shows.
Expand Down
2 changes: 2 additions & 0 deletions public/usage/usage.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
.lead { padding-bottom: var(--s3); }
.months { display: flex; gap: var(--s4); align-items: baseline; font-size: var(--f2); line-height: var(--l2); color: var(--ink-2); padding-bottom: var(--s3); }
.months .off { color: var(--ink-3); }
.months .arrow:first-child { margin-right: var(--s1); }
.months .arrow:last-child { margin-left: var(--s1); }
a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.status { margin: 0 0 var(--s4); color: var(--ink-2); }
.sum { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s5); margin: 0 0 var(--s4); padding: 0; list-style: none; }
Expand Down
178 changes: 178 additions & 0 deletions test/glyphs.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// Every character the page draws is one its fonts have (setkernel-live#80). The fonts are Latin
// subsets: a character outside them (an arrow, a status shape) would be drawn in whatever system
// font the visitor has. So each @font-face in style.css declares the unicode-range its file has,
// read here from the file's own cmap, and every non-ASCII character in the pages' HTML text or in
// a string in their scripts must be in that range. A string doesn't say which face draws it, so
// each is held to every face. Something the fonts lack is an SVG (.arrow in style.css).
// Run: npm test
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync, readdirSync } from "node:fs";
import { brotliDecompressSync } from "node:zlib";

const pub = new URL("../public/", import.meta.url);
const read = (name) => readFileSync(new URL(name, pub), "utf8");
const files = readdirSync(pub, { recursive: true }).map(String).sort();
const hex = (cp) => `U+${cp.toString(16).toUpperCase().padStart(4, "0")}`;

// ---- a woff2 file's cmap: the code points it has a glyph for
function base128(b, at) {
let v = 0;
for (let n = 0; n < 5; n++) {
const x = b[at.i++];
v = v * 128 + (x & 127);
if (!(x & 128)) return v;
}
throw new Error("bad UIntBase128");
}
function cmap(woff2) {
assert.equal(woff2.toString("latin1", 0, 4), "wOF2");
const at = { i: 48 };
let off = 0, table;
for (let n = woff2.readUInt16BE(12); n > 0; n--) {
const flags = woff2[at.i++], known = flags & 63, version = flags >> 6;
const tag = known === 63 ? woff2.toString("latin1", at.i, (at.i += 4)) : known;
const length = base128(woff2, at);
// glyf (10) and loca (11) are transformed unless version 3; every other table only if not 0
const stored = (known === 10 || known === 11 ? version !== 3 : version !== 0) ? base128(woff2, at) : length;
if (tag === 0 || tag === "cmap") table = { off, stored };
off += stored;
}
const c = brotliDecompressSync(woff2.subarray(at.i, at.i + woff2.readUInt32BE(20))).subarray(table.off, table.off + table.stored);
const subtables = Array.from({ length: c.readUInt16BE(2) }, (_, n) => c.subarray(c.readUInt32BE(8 + 8 * n)));
const s = subtables.find((t) => t.readUInt16BE(0) === 12) ?? subtables.find((t) => t.readUInt16BE(0) === 4);
const cps = new Set();
if (s.readUInt16BE(0) === 12) {
for (let g = 0; g < s.readUInt32BE(12); g++) {
const [first, last, glyph] = [16, 20, 24].map((o) => s.readUInt32BE(o + 12 * g));
for (let cp = first; cp <= last; cp++) if (glyph + cp - first) cps.add(cp);
}
return cps;
}
const segs = s.readUInt16BE(6) / 2, ends = 14, starts = 16 + 2 * segs, deltas = starts + 2 * segs, offsets = deltas + 2 * segs;
for (let g = 0; g < segs; g++) {
const [first, last, delta, ro] = [starts, ends, deltas, offsets].map((o) => s.readUInt16BE(o + 2 * g));
for (let cp = first; cp <= last && cp !== 0xffff; cp++) {
let glyph = ro ? s.readUInt16BE(offsets + 2 * g + ro + 2 * (cp - first)) : cp;
if (glyph) glyph = (glyph + delta) & 0xffff;
if (glyph) cps.add(cp);
}
}
return cps;
}

// ---- the faces in style.css, each with what it declares and what its file has
function range(text) {
const cps = new Set();
for (const part of text.split(",")) {
const m = part.trim().match(/^U\+([0-9A-F?]{1,6})(?:-([0-9A-F]{1,6}))?$/i);
assert.ok(m, `unicode-range part "${part.trim()}"`);
const first = parseInt(m[1].replace(/\?/g, "0"), 16), last = parseInt(m[2] ?? m[1].replace(/\?/g, "F"), 16);
for (let cp = first; cp <= last; cp++) cps.add(cp);
}
return cps;
}
const faces = [...read("style.css").matchAll(/@font-face\s*{([^}]*)}/g)].map(([, f]) => {
const url = f.match(/url\("?\/([^")]+)"?\)/)[1];
const declared = f.match(/unicode-range:\s*([^;]+)/)?.[1];
return { name: `${f.match(/font-family:\s*"([^"]+)"/)[1]} ${f.match(/font-weight:\s*(\d+)/)[1]}`, url, declared: declared && range(declared), has: cmap(readFileSync(new URL(url, pub))) };
});

test("each @font-face declares the unicode-range its file has", () => {
assert.equal(faces.length, 3, "Manrope 400 and 600, IBM Plex Mono 400");
for (const { name, url, declared, has } of faces) {
assert.ok(declared, `${name} (${url}) declares no unicode-range, so it claims every character`);
const printable = (set) => [...set].filter((cp) => cp >= 0x20).sort((a, b) => a - b).map(hex);
assert.deepEqual(printable(declared), printable(has), `${name}: the range is what ${url} has`);
}
});

// ---- what the pages draw: the text of each HTML page's body, and every string in its scripts
// HTML: comments, scripts, styles and tags blanked (attributes aren't drawn), lines kept
function htmlText(html) {
const blank = (m) => m.replace(/[^\n]/g, " ");
const body = html.search(/<body\b/i);
return (blank(html.slice(0, body)) + html.slice(body))
.replace(/<!--[\s\S]*?-->|<(script|style)\b[\s\S]*?<\/\1>|<[^>]*>/gi, blank)
.replace(/&#x([0-9a-f]+);/gi, (_, h) => String.fromCodePoint(parseInt(h, 16)))
.replace(/&#(\d+);/g, (_, d) => String.fromCodePoint(Number(d)))
.split("\n");
}

// JS: each string and template literal's text, escapes decoded, with the line it starts on.
// Comments and regular expressions are skipped; a template's ${...} is code, so strings inside it count.
const KEYWORDS = new Set(["return", "typeof", "case", "of", "in", "do", "else", "void", "yield", "await", "delete", "new", "instanceof", "throw"]);
const unescape = (raw) => raw.replace(/\\(u\{[0-9a-f]+\}|u[0-9a-f]{4}|x[0-9a-f]{2}|[\s\S])/gi, (_, e) =>
/^[ux]/i.test(e) && e.length > 1 ? String.fromCodePoint(parseInt(e.replace(/^u\{?|^x|\}$/gi, ""), 16)) : e);
function strings(src) {
const out = [], open = []; // open: the brace depth at each unfinished ${
let i = 0, depth = 0, prev = "";
const lineAt = (n) => src.slice(0, n).split("\n").length;
const scan = (j, stop) => { while (j < src.length && !stop(j)) j += src[j] === "\\" ? 2 : 1; return j; };
const template = (from) => {
const j = scan(from, (k) => src[k] === "`" || (src[k] === "$" && src[k + 1] === "{"));
out.push([unescape(src.slice(from, j)), lineAt(from)]);
if (src[j] === "`") { i = j + 1; prev = "x"; } else { open.push(depth); i = j + 2; prev = "{"; }
};
while (i < src.length) {
const c = src[i], d = src[i + 1];
if (c === "/" && d === "/") i = src.includes("\n", i) ? src.indexOf("\n", i) : src.length;
else if (c === "/" && d === "*") i = src.includes("*/", i + 2) ? src.indexOf("*/", i + 2) + 2 : src.length;
else if (c === '"' || c === "'") {
const j = scan(i + 1, (k) => src[k] === c);
out.push([unescape(src.slice(i + 1, j)), lineAt(i)]);
i = j + 1; prev = "x";
} else if (c === "`") template(i + 1);
else if (c === "}" && open.length && open.at(-1) === depth) { open.pop(); template(i + 1); }
else if (c === "/" && (prev === "" || /^[(,=:[!&|?{};+\-*%<>~^]$/.test(prev) || KEYWORDS.has(prev))) {
let cls = false, j = i + 1; // a regular expression
for (; j < src.length && (cls || src[j] !== "/"); j++) {
if (src[j] === "\\") j++;
else if (src[j] === "[") cls = true;
else if (src[j] === "]") cls = false;
}
i = j + 1; prev = "x";
while (/[a-z]/.test(src[i] ?? "")) i++;
} else if (/[\w$]/.test(c)) {
const word = src.slice(i).match(/^[\w$]+/)[0];
i += word.length; prev = word;
} else {
if (c === "{") depth++;
if (c === "}") depth--;
if (!/\s/.test(c)) prev = c;
i++;
}
}
assert.deepEqual([open.length, depth], [0, 0], "every string, template and brace closes");
return out;
}

function drawn() {
const out = [];
for (const f of files) {
if (f.endsWith(".html")) htmlText(read(f)).forEach((text, n) => out.push([text, `public/${f}:${n + 1}`]));
if (f.endsWith(".js")) for (const [text, line] of strings(read(f))) out.push([text, `public/${f}:${line}`]);
}
return out;
}

test("every character the pages draw is in each face's unicode-range, or it is an SVG", () => {
const ok = (cp) => faces.every(({ declared, has }) => has.has(cp) && (!declared || declared.has(cp)));
const bad = [];
let seen = 0;
for (const [text, where] of drawn()) {
for (const ch of text) {
const cp = ch.codePointAt(0);
if (cp < 0x80) continue;
seen++;
if (!ok(cp)) bad.push(`${where}: "${ch}" (${hex(cp)})`);
}
}
assert.deepEqual(bad, [], "not in the fonts, so a system font would draw it: draw it as an SVG (.arrow in style.css)");
assert.ok(seen > 20, `${seen} non-ASCII characters checked, the · and … the pages use among them`);
});

test("the string reader keeps strings and skips comments and regular expressions", () => {
const src = "const a = \"·\" + '\\u2190'; // ●\n/* ○ */ x = /[\"/]●/g.test(b) ? `→ ${c ? \"✕\" : `‖${d}`} ◎` : a / 2 / 3;";
assert.deepEqual(strings(src), [["·", 1], ["←", 1], ["→ ", 2], ["✕", 2], ["‖", 2], ["", 2], [" ◎", 2]]);
});
Loading
Loading