mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-23 04:39:59 +00:00
ui, plan: badge site design system and wizard shell
This commit is contained in:
1 parent
85a753f42f
commit
e9c8578b65
20 files changed
+1493
-33
No files matched your search
@@ -0,0 +1,10 @@
|
||||
<svg width="34" height="35" viewBox="0 0 34 35" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.02958 8.60922L8.622 14.2013L14.3705 8.45375L17.1669 11.2498L11.4183 16.9972L17.0114 22.5895L14.1373 25.4633L8.54422 19.871L2.79636 25.6187L0 22.8227L5.74794 17.075L0.155484 11.483L3.02958 8.60922Z" fill="white"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.0923 25.5156L16.944 22.6642L16.9429 22.6634L22.6467 16.9612L17.0513 11.3675L17.0523 11.367L14.2548 8.56979L8.65972 2.97535L11.5114 0.123963L17.1061 5.71849L22.8099 0.015625L25.6074 2.81285L19.9035 8.51562L25.4984 14.1099L31.2025 8.40729L34 11.2045L28.2958 16.907L33.8917 22.5017L31.0399 25.3531L25.4442 19.7584L19.7409 25.4611L25.3365 31.0559L22.4848 33.9073L16.8892 28.3124L11.1864 34.0156L8.38885 31.2184L14.0923 25.5156Z" fill="url(#paint0_linear_656_10815)"/>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_656_10815" x1="12.8381" y1="-0.678252" x2="9.54355" y2="31.4493" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#01F1FF"/>
|
||||
<stop offset="1" stop-color="#0197FF"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,15 @@
|
||||
<svg width="34" height="34" viewBox="0 0 34 34" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_14_10)">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.02972 8.59396L8.62219 14.186L14.3703 8.43848L17.1668 11.2346L11.4182 16.982L17.0112 22.5742L14.1371 25.448L8.5441 19.8557L2.79651 25.6035L0 22.8074L5.74813 17.0597L0.155656 11.4678L3.02972 8.59396Z" fill="#023789"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.0922 25.5L16.9434 22.6486L16.9423 22.6478L22.6464 16.9456L17.0512 11.3519L17.0518 11.3514L14.2542 8.55418L8.65961 2.95973L11.5114 0.108337L17.106 5.70288L22.8095 0L25.607 2.79722L19.903 8.5L25.4981 14.0943L31.2022 8.39169L33.9997 11.1889L28.2957 16.8914L33.8914 22.4861L31.0396 25.3375L25.4439 19.7428L19.7404 25.4454L25.3361 31.0403L22.4843 33.8917L16.8887 28.2968L11.1862 34L8.38867 31.2028L14.0922 25.5Z" fill="url(#paint0_linear_14_10)"/>
|
||||
</g>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_14_10" x1="12.8379" y1="-0.693875" x2="9.54344" y2="31.4337" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#01F1FF"/>
|
||||
<stop offset="1" stop-color="#0197FF"/>
|
||||
</linearGradient>
|
||||
<clipPath id="clip0_14_10">
|
||||
<rect width="34" height="34" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
+11
-2
@@ -23,8 +23,17 @@
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main id="app"></main>
|
||||
<footer><a href="https://example.invalid/dev-support-contact">Contact support</a></footer>
|
||||
<div class="column">
|
||||
<!-- The site's only image. styles.css shows one and hides the other by
|
||||
colour scheme; both cannot be referenced from CSS, because CSS is
|
||||
served verbatim and a token in it would not be substituted. -->
|
||||
<header class="masthead">
|
||||
<img class="logo logo--light" src="./logo-symbol-light.svg" alt="SimpleX" width="34" height="34" />
|
||||
<img class="logo logo--dark" src="./logo-symbol-dark.svg" alt="SimpleX" width="34" height="35" />
|
||||
</header>
|
||||
<main id="app"></main>
|
||||
<footer class="footer"><a href="https://example.invalid/dev-support-contact">Contact support</a></footer>
|
||||
</div>
|
||||
<script type="module" src="./main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,10 @@
|
||||
<svg width="34" height="35" viewBox="0 0 34 35" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.02958 8.60922L8.622 14.2013L14.3705 8.45375L17.1669 11.2498L11.4183 16.9972L17.0114 22.5895L14.1373 25.4633L8.54422 19.871L2.79636 25.6187L0 22.8227L5.74794 17.075L0.155484 11.483L3.02958 8.60922Z" fill="white"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.0923 25.5156L16.944 22.6642L16.9429 22.6634L22.6467 16.9612L17.0513 11.3675L17.0523 11.367L14.2548 8.56979L8.65972 2.97535L11.5114 0.123963L17.1061 5.71849L22.8099 0.015625L25.6074 2.81285L19.9035 8.51562L25.4984 14.1099L31.2025 8.40729L34 11.2045L28.2958 16.907L33.8917 22.5017L31.0399 25.3531L25.4442 19.7584L19.7409 25.4611L25.3365 31.0559L22.4848 33.9073L16.8892 28.3124L11.1864 34.0156L8.38885 31.2184L14.0923 25.5156Z" fill="url(#paint0_linear_656_10815)"/>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_656_10815" x1="12.8381" y1="-0.678252" x2="9.54355" y2="31.4493" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#01F1FF"/>
|
||||
<stop offset="1" stop-color="#0197FF"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,15 @@
|
||||
<svg width="34" height="34" viewBox="0 0 34 34" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_14_10)">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.02972 8.59396L8.62219 14.186L14.3703 8.43848L17.1668 11.2346L11.4182 16.982L17.0112 22.5742L14.1371 25.448L8.5441 19.8557L2.79651 25.6035L0 22.8074L5.74813 17.0597L0.155656 11.4678L3.02972 8.59396Z" fill="#023789"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M14.0922 25.5L16.9434 22.6486L16.9423 22.6478L22.6464 16.9456L17.0512 11.3519L17.0518 11.3514L14.2542 8.55418L8.65961 2.95973L11.5114 0.108337L17.106 5.70288L22.8095 0L25.607 2.79722L19.903 8.5L25.4981 14.0943L31.2022 8.39169L33.9997 11.1889L28.2957 16.8914L33.8914 22.4861L31.0396 25.3375L25.4439 19.7428L19.7404 25.4454L25.3361 31.0403L22.4843 33.8917L16.8887 28.2968L11.1862 34L8.38867 31.2028L14.0922 25.5Z" fill="url(#paint0_linear_14_10)"/>
|
||||
</g>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_14_10" x1="12.8379" y1="-0.693875" x2="9.54344" y2="31.4337" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#01F1FF"/>
|
||||
<stop offset="1" stop-color="#0197FF"/>
|
||||
</linearGradient>
|
||||
<clipPath id="clip0_14_10">
|
||||
<rect width="34" height="34" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
+20
-6
@@ -1,7 +1,21 @@
|
||||
// Placeholder entry point; the wizard shell replaces it.
|
||||
// The relative specifier keeps its ".js" extension into the emitted module:
|
||||
// tsc does not rewrite specifiers and the browser resolves them itself.
|
||||
import { renderPlaceholder } from "./ui.js";
|
||||
// Entry point. index.html loads this as a module and the browser resolves the
|
||||
// relative specifiers below itself: tsc does not rewrite them, which is why
|
||||
// they keep their ".js" extension and why the whole graph is served under one
|
||||
// prefix (decision 7, D4).
|
||||
import { startShell } from "./ui.js";
|
||||
const app = document.getElementById("app");
|
||||
if (app)
|
||||
renderPlaceholder(app);
|
||||
if (app) {
|
||||
try {
|
||||
startShell(app);
|
||||
}
|
||||
catch (err) {
|
||||
// A shell that fails to start must still say so: the alternative is an
|
||||
// empty page with the reason only in the console (D2).
|
||||
const banner = document.createElement("p");
|
||||
banner.className = "banner";
|
||||
banner.setAttribute("role", "alert");
|
||||
banner.textContent = "This page failed to load. Please reload, or contact support using the link below.";
|
||||
app.replaceChildren(banner);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// Hash routing for the site wizard: one question per screen, no page reloads.
|
||||
//
|
||||
// Everything here is pure — no DOM, no history, no location — so that the
|
||||
// mapping a browser depends on can be tested with `node --test` (see
|
||||
// ../test/router.test.mjs). ui.ts owns pushState, popstate and rendering.
|
||||
/** Every screen the site can show, in wizard order. */
|
||||
export const SCREEN_IDS = ["tier", "months", "pay", "checkout", "order", "code"];
|
||||
/** Where a visit with no usable hash starts. */
|
||||
export const FIRST_SCREEN = "tier";
|
||||
const SCREENS = new Set(SCREEN_IDS);
|
||||
/**
|
||||
* The screen a location hash names, or null when it names none.
|
||||
*
|
||||
* Accepts `#/tier`, `#tier`, and either with a trailing slash, because a hash
|
||||
* is hand-editable and a URL may be pasted with the slash dropped. Returns
|
||||
* FIRST_SCREEN for an absent or empty hash. Null is a real answer, not an
|
||||
* error: the caller decides what an unknown hash does, and ui.ts sends it to
|
||||
* FIRST_SCREEN rather than leaving a blank page.
|
||||
*/
|
||||
export function screenIdForHash(hash) {
|
||||
const name = hash.replace(/^#/, "").replace(/^\//, "").replace(/\/$/, "");
|
||||
if (name === "")
|
||||
return FIRST_SCREEN;
|
||||
return SCREENS.has(name) ? name : null;
|
||||
}
|
||||
/** The canonical hash for a screen. The inverse of screenIdForHash. */
|
||||
export function hashForScreen(id) {
|
||||
return `#/${id}`;
|
||||
}
|
||||
/**
|
||||
* The screen after this one, or null at the end of the wizard.
|
||||
*
|
||||
* `checkout` ends the answered part: `order` and `code` are reached from a
|
||||
* checkout response (D7, E5, E6), never by advancing.
|
||||
*/
|
||||
export function nextScreen(id) {
|
||||
const wizard = ["tier", "months", "pay", "checkout"];
|
||||
const i = wizard.indexOf(id);
|
||||
return i >= 0 && i + 1 < wizard.length ? wizard[i + 1] : null;
|
||||
}
|
||||
+107
-5
@@ -1,6 +1,108 @@
|
||||
// Placeholder view layer; the wizard shell replaces it.
|
||||
export function renderPlaceholder(root) {
|
||||
const heading = document.createElement("h1");
|
||||
heading.textContent = "SimpleX supporter badges";
|
||||
root.replaceChildren(heading);
|
||||
// The wizard shell: the only module that touches the DOM.
|
||||
//
|
||||
// One question per screen, hash-routed with no page reload. Forward navigation
|
||||
// is history.pushState, which does not fire popstate, so the shell renders
|
||||
// directly; back and forward are history traversals, which do fire it, so the
|
||||
// listener re-renders from the hash. There is no hashchange listener: every
|
||||
// hash change originates here.
|
||||
//
|
||||
// Everything decidable without a browser lives in router.ts and view.ts.
|
||||
import { FIRST_SCREEN, hashForScreen, nextScreen, screenIdForHash } from "./router.js";
|
||||
import { questionOfScreen, screenView } from "./view.js";
|
||||
const CHOOSE_AN_OPTION = "Choose an option to continue.";
|
||||
// D7 replaces this branch with the POST to /api/checkout.
|
||||
const PAYMENT_UNAVAILABLE = "Payment is not available yet.";
|
||||
/** Build elements from a view tree. No innerHTML: text is always a text node. */
|
||||
export function toDom(el) {
|
||||
const node = document.createElement(el.tag);
|
||||
for (const name of Object.keys(el.attrs))
|
||||
node.setAttribute(name, el.attrs[name]);
|
||||
for (const child of el.children)
|
||||
node.append(childNode(child));
|
||||
return node;
|
||||
}
|
||||
function childNode(child) {
|
||||
return typeof child === "string" ? child : toDom(child);
|
||||
}
|
||||
/** Render the screen the current hash names into `root`, and keep it in step with history. */
|
||||
export function startShell(root) {
|
||||
const banner = errorBanner();
|
||||
const answers = {};
|
||||
let current = FIRST_SCREEN;
|
||||
const shell = {
|
||||
showError(message) {
|
||||
banner.textContent = message;
|
||||
banner.hidden = false;
|
||||
},
|
||||
go(id) {
|
||||
history.pushState(null, "", hashForScreen(id));
|
||||
render(id, true);
|
||||
},
|
||||
answers() {
|
||||
return { ...answers };
|
||||
},
|
||||
};
|
||||
function clearError() {
|
||||
banner.hidden = true;
|
||||
banner.textContent = "";
|
||||
}
|
||||
function render(id, moveFocus) {
|
||||
current = id;
|
||||
clearError();
|
||||
const screen = toDom(screenView(id, answers));
|
||||
root.replaceChildren(banner, screen);
|
||||
// The heading is the start of the new screen for a keyboard or screen
|
||||
// reader user, who would otherwise stay on a button that no longer exists.
|
||||
const heading = screen.querySelector("h1");
|
||||
if (heading) {
|
||||
heading.setAttribute("tabindex", "-1");
|
||||
if (moveFocus)
|
||||
heading.focus();
|
||||
}
|
||||
}
|
||||
// An unknown hash renders the first screen rather than nothing, and the
|
||||
// address bar is corrected in place so that back does not return to it.
|
||||
function screenFromLocation() {
|
||||
const id = screenIdForHash(location.hash);
|
||||
if (id !== null && location.hash === hashForScreen(id))
|
||||
return id;
|
||||
const target = id ?? FIRST_SCREEN;
|
||||
history.replaceState(null, "", hashForScreen(target));
|
||||
return target;
|
||||
}
|
||||
function onSubmit(event) {
|
||||
event.preventDefault();
|
||||
const question = questionOfScreen(current);
|
||||
if (!question) {
|
||||
// The only other screen with a form is #/checkout, whose Pay button D7 wires.
|
||||
shell.showError(PAYMENT_UNAVAILABLE);
|
||||
return;
|
||||
}
|
||||
const form = event.target;
|
||||
if (!(form instanceof HTMLFormElement))
|
||||
return;
|
||||
const chosen = form.querySelector("input[type=radio]:checked");
|
||||
if (!chosen) {
|
||||
shell.showError(CHOOSE_AN_OPTION);
|
||||
return;
|
||||
}
|
||||
answers[question] = chosen.value;
|
||||
const next = nextScreen(current);
|
||||
if (next)
|
||||
shell.go(next);
|
||||
}
|
||||
root.addEventListener("submit", onSubmit);
|
||||
// Choosing an option answers the complaint the banner is showing.
|
||||
root.addEventListener("change", clearError);
|
||||
window.addEventListener("popstate", () => render(screenFromLocation(), true));
|
||||
render(screenFromLocation(), false);
|
||||
return shell;
|
||||
}
|
||||
function errorBanner() {
|
||||
const banner = document.createElement("p");
|
||||
banner.className = "banner";
|
||||
// role=alert so the message is announced when it appears, not only seen.
|
||||
banner.setAttribute("role", "alert");
|
||||
banner.hidden = true;
|
||||
return banner;
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
// The screens, as pure data.
|
||||
//
|
||||
// A screen is described as an element tree and never touches the DOM, so the
|
||||
// structure a browser will render can be asserted with `node --test` (see
|
||||
// ../test/static.test.mjs, which counts the <h1> of every screen and checks
|
||||
// that every radio group is a real fieldset/legend/label). ui.ts turns a tree
|
||||
// into elements with document.createElement and textContent — there is no
|
||||
// innerHTML anywhere, so a label that later comes from the catalog (D3) or from
|
||||
// a query parameter (D5) cannot become markup.
|
||||
//
|
||||
// The options here are placeholders. D3 builds the first three screens from the
|
||||
// catalog payload and replaces them.
|
||||
/** An element node. An attribute present with an empty value is a boolean attribute. */
|
||||
export function h(tag, attrs = {}, children = []) {
|
||||
return { tag, attrs, children };
|
||||
}
|
||||
const QUESTIONS = {
|
||||
tier: {
|
||||
heading: "Choose your level",
|
||||
legend: "Badge level",
|
||||
options: [
|
||||
{ value: "supporter", label: "Supporter", detail: "2 GB files" },
|
||||
{ value: "legend", label: "Legend", detail: "5 GB files" },
|
||||
],
|
||||
},
|
||||
months: {
|
||||
heading: "How long?",
|
||||
legend: "Subscription length",
|
||||
options: [
|
||||
{ value: "1", label: "1 month", detail: "Billed once" },
|
||||
{ value: "3", label: "3 months", detail: "Billed once" },
|
||||
{ value: "12", label: "12 months", detail: "Billed once" },
|
||||
],
|
||||
},
|
||||
pay: {
|
||||
heading: "How would you like to pay?",
|
||||
legend: "Payment method",
|
||||
options: [
|
||||
{ value: "card", label: "Card", detail: "Visa, Mastercard and others" },
|
||||
{ value: "btc", label: "Bitcoin", detail: "On-chain or Lightning" },
|
||||
{ value: "xmr", label: "Monero", detail: "On-chain" },
|
||||
],
|
||||
},
|
||||
};
|
||||
const QUESTION_IDS = new Set(Object.keys(QUESTIONS));
|
||||
/** The question a screen asks, or null for a screen that asks none. */
|
||||
export function questionOfScreen(id) {
|
||||
return QUESTION_IDS.has(id) ? id : null;
|
||||
}
|
||||
/** The placeholder options of a question screen. D3 replaces this with the catalog. */
|
||||
export function optionsOfQuestion(q) {
|
||||
return QUESTIONS[q].options;
|
||||
}
|
||||
/**
|
||||
* The whole screen, ready to be turned into elements. Exactly one <h1>.
|
||||
*
|
||||
* The switch is exhaustive over ScreenId with no default, so adding a screen
|
||||
* to router.ts fails to compile until this renders it — there is no route the
|
||||
* shell can reach that renders nothing.
|
||||
*/
|
||||
export function screenView(id, answers) {
|
||||
switch (id) {
|
||||
case "tier":
|
||||
case "months":
|
||||
case "pay":
|
||||
return questionScreen(id, answers[id]);
|
||||
case "checkout":
|
||||
return checkoutScreen(answers);
|
||||
case "order":
|
||||
return orderScreen();
|
||||
case "code":
|
||||
return codeScreen();
|
||||
}
|
||||
}
|
||||
function questionScreen(q, answer) {
|
||||
const { heading, legend, options } = QUESTIONS[q];
|
||||
return section(heading, [
|
||||
h("form", { class: "form" }, [
|
||||
h("fieldset", { class: "options" }, [h("legend", { class: "options__legend" }, [legend]), ...options.map((o) => optionCard(q, o, answer))]),
|
||||
submitButton("Continue"),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
function optionCard(group, option, answer) {
|
||||
const input = { class: "option__input", type: "radio", name: group, value: option.value };
|
||||
if (option.value === answer)
|
||||
input.checked = "";
|
||||
if (option.disabled)
|
||||
input.disabled = "";
|
||||
return h("label", { class: "option" }, [
|
||||
h("input", input),
|
||||
h("span", { class: "option__body" }, [
|
||||
h("span", { class: "option__label" }, [option.label]),
|
||||
h("span", { class: "option__detail" }, [option.detail]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
const NOT_CHOSEN = "Not chosen yet";
|
||||
function checkoutScreen(answers) {
|
||||
return section("Review your order", [
|
||||
h("form", { class: "form" }, [
|
||||
h("dl", { class: "summary" }, [
|
||||
...summaryRow("Level", labelOf("tier", answers.tier)),
|
||||
...summaryRow("Length", labelOf("months", answers.months)),
|
||||
...summaryRow("Payment", labelOf("pay", answers.pay)),
|
||||
]),
|
||||
submitButton("Pay"),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
function summaryRow(term, value) {
|
||||
return [h("dt", { class: "summary__term" }, [term]), h("dd", { class: "summary__value" }, [value])];
|
||||
}
|
||||
function labelOf(q, value) {
|
||||
if (value === undefined)
|
||||
return NOT_CHOSEN;
|
||||
return QUESTIONS[q].options.find((o) => o.value === value)?.label ?? value;
|
||||
}
|
||||
// E5 replaces this with the crypto payment screen, E6 with the result screen.
|
||||
// They exist now so that no path can route to a hash that renders nothing.
|
||||
function orderScreen() {
|
||||
return section("Complete your payment", [h("p", { class: "prose" }, ["Payment details will appear here once an order has been created."])]);
|
||||
}
|
||||
function codeScreen() {
|
||||
return section("Your redemption code", [h("p", { class: "prose" }, ["Your code will appear here once a payment has been confirmed."])]);
|
||||
}
|
||||
function section(heading, body) {
|
||||
return h("section", { class: "screen" }, [h("h1", { class: "screen__heading" }, [heading]), ...body]);
|
||||
}
|
||||
function submitButton(label) {
|
||||
return h("button", { class: "button", type: "submit" }, [label]);
|
||||
}
|
||||
@@ -22,8 +22,17 @@
|
||||
<link rel="stylesheet" href="@@styles.css@@" />
|
||||
</head>
|
||||
<body>
|
||||
<main id="app"></main>
|
||||
<footer><a href="@@support_contact@@">Contact support</a></footer>
|
||||
<div class="column">
|
||||
<!-- The site's only image. styles.css shows one and hides the other by
|
||||
colour scheme; both cannot be referenced from CSS, because CSS is
|
||||
served verbatim and a token in it would not be substituted. -->
|
||||
<header class="masthead">
|
||||
<img class="logo logo--light" src="@@logo-symbol-light.svg@@" alt="SimpleX" width="34" height="34" />
|
||||
<img class="logo logo--dark" src="@@logo-symbol-dark.svg@@" alt="SimpleX" width="34" height="35" />
|
||||
</header>
|
||||
<main id="app"></main>
|
||||
<footer class="footer"><a href="@@support_contact@@">Contact support</a></footer>
|
||||
</div>
|
||||
<script type="module" src="@@main.js@@"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -4,7 +4,8 @@
|
||||
"private": true,
|
||||
"description": "Checkout site for SimpleX supporter badges, served by simplex-badge-service",
|
||||
"scripts": {
|
||||
"build": "node build.mjs"
|
||||
"build": "node build.mjs",
|
||||
"test": "node --test test/*.test.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "5.9.3"
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
// Placeholder entry point; the wizard shell replaces it.
|
||||
// The relative specifier keeps its ".js" extension into the emitted module:
|
||||
// tsc does not rewrite specifiers and the browser resolves them itself.
|
||||
// Entry point. index.html loads this as a module and the browser resolves the
|
||||
// relative specifiers below itself: tsc does not rewrite them, which is why
|
||||
// they keep their ".js" extension and why the whole graph is served under one
|
||||
// prefix (decision 7, D4).
|
||||
|
||||
import {renderPlaceholder} from "./ui.js"
|
||||
import {startShell} from "./ui.js"
|
||||
|
||||
const app = document.getElementById("app")
|
||||
if (app) renderPlaceholder(app)
|
||||
if (app) {
|
||||
try {
|
||||
startShell(app)
|
||||
} catch (err) {
|
||||
// A shell that fails to start must still say so: the alternative is an
|
||||
// empty page with the reason only in the console (D2).
|
||||
const banner = document.createElement("p")
|
||||
banner.className = "banner"
|
||||
banner.setAttribute("role", "alert")
|
||||
banner.textContent = "This page failed to load. Please reload, or contact support using the link below."
|
||||
app.replaceChildren(banner)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// Hash routing for the site wizard: one question per screen, no page reloads.
|
||||
//
|
||||
// Everything here is pure — no DOM, no history, no location — so that the
|
||||
// mapping a browser depends on can be tested with `node --test` (see
|
||||
// ../test/router.test.mjs). ui.ts owns pushState, popstate and rendering.
|
||||
|
||||
/** Every screen the site can show, in wizard order. */
|
||||
export const SCREEN_IDS = ["tier", "months", "pay", "checkout", "order", "code"] as const
|
||||
|
||||
export type ScreenId = (typeof SCREEN_IDS)[number]
|
||||
|
||||
/** Where a visit with no usable hash starts. */
|
||||
export const FIRST_SCREEN: ScreenId = "tier"
|
||||
|
||||
const SCREENS: ReadonlySet<string> = new Set(SCREEN_IDS)
|
||||
|
||||
/**
|
||||
* The screen a location hash names, or null when it names none.
|
||||
*
|
||||
* Accepts `#/tier`, `#tier`, and either with a trailing slash, because a hash
|
||||
* is hand-editable and a URL may be pasted with the slash dropped. Returns
|
||||
* FIRST_SCREEN for an absent or empty hash. Null is a real answer, not an
|
||||
* error: the caller decides what an unknown hash does, and ui.ts sends it to
|
||||
* FIRST_SCREEN rather than leaving a blank page.
|
||||
*/
|
||||
export function screenIdForHash(hash: string): ScreenId | null {
|
||||
const name = hash.replace(/^#/, "").replace(/^\//, "").replace(/\/$/, "")
|
||||
if (name === "") return FIRST_SCREEN
|
||||
return SCREENS.has(name) ? (name as ScreenId) : null
|
||||
}
|
||||
|
||||
/** The canonical hash for a screen. The inverse of screenIdForHash. */
|
||||
export function hashForScreen(id: ScreenId): string {
|
||||
return `#/${id}`
|
||||
}
|
||||
|
||||
/**
|
||||
* The screen after this one, or null at the end of the wizard.
|
||||
*
|
||||
* `checkout` ends the answered part: `order` and `code` are reached from a
|
||||
* checkout response (D7, E5, E6), never by advancing.
|
||||
*/
|
||||
export function nextScreen(id: ScreenId): ScreenId | null {
|
||||
const wizard: readonly ScreenId[] = ["tier", "months", "pay", "checkout"]
|
||||
const i = wizard.indexOf(id)
|
||||
return i >= 0 && i + 1 < wizard.length ? wizard[i + 1] : null
|
||||
}
|
||||
@@ -1,7 +1,124 @@
|
||||
// Placeholder view layer; the wizard shell replaces it.
|
||||
// The wizard shell: the only module that touches the DOM.
|
||||
//
|
||||
// One question per screen, hash-routed with no page reload. Forward navigation
|
||||
// is history.pushState, which does not fire popstate, so the shell renders
|
||||
// directly; back and forward are history traversals, which do fire it, so the
|
||||
// listener re-renders from the hash. There is no hashchange listener: every
|
||||
// hash change originates here.
|
||||
//
|
||||
// Everything decidable without a browser lives in router.ts and view.ts.
|
||||
|
||||
export function renderPlaceholder(root: HTMLElement): void {
|
||||
const heading = document.createElement("h1")
|
||||
heading.textContent = "SimpleX supporter badges"
|
||||
root.replaceChildren(heading)
|
||||
import {FIRST_SCREEN, hashForScreen, nextScreen, screenIdForHash, type ScreenId} from "./router.js"
|
||||
import {questionOfScreen, screenView, type Answers, type Child, type El} from "./view.js"
|
||||
|
||||
/** The running shell. D3 fetches the catalog through it; D7 the checkout. */
|
||||
export interface Shell {
|
||||
/** Show the error banner. Nothing on this site fails to a blank screen. */
|
||||
showError(message: string): void
|
||||
/** Navigate to a screen, pushing a history entry. */
|
||||
go(id: ScreenId): void
|
||||
/** The answers gathered so far. */
|
||||
answers(): Answers
|
||||
}
|
||||
|
||||
const CHOOSE_AN_OPTION = "Choose an option to continue."
|
||||
// D7 replaces this branch with the POST to /api/checkout.
|
||||
const PAYMENT_UNAVAILABLE = "Payment is not available yet."
|
||||
|
||||
/** Build elements from a view tree. No innerHTML: text is always a text node. */
|
||||
export function toDom(el: El): HTMLElement {
|
||||
const node = document.createElement(el.tag)
|
||||
for (const name of Object.keys(el.attrs)) node.setAttribute(name, el.attrs[name])
|
||||
for (const child of el.children) node.append(childNode(child))
|
||||
return node
|
||||
}
|
||||
|
||||
function childNode(child: Child): HTMLElement | string {
|
||||
return typeof child === "string" ? child : toDom(child)
|
||||
}
|
||||
|
||||
/** Render the screen the current hash names into `root`, and keep it in step with history. */
|
||||
export function startShell(root: HTMLElement): Shell {
|
||||
const banner = errorBanner()
|
||||
const answers: {tier?: string; months?: string; pay?: string} = {}
|
||||
let current = FIRST_SCREEN
|
||||
|
||||
const shell: Shell = {
|
||||
showError(message: string): void {
|
||||
banner.textContent = message
|
||||
banner.hidden = false
|
||||
},
|
||||
go(id: ScreenId): void {
|
||||
history.pushState(null, "", hashForScreen(id))
|
||||
render(id, true)
|
||||
},
|
||||
answers(): Answers {
|
||||
return {...answers}
|
||||
},
|
||||
}
|
||||
|
||||
function clearError(): void {
|
||||
banner.hidden = true
|
||||
banner.textContent = ""
|
||||
}
|
||||
|
||||
function render(id: ScreenId, moveFocus: boolean): void {
|
||||
current = id
|
||||
clearError()
|
||||
const screen = toDom(screenView(id, answers))
|
||||
root.replaceChildren(banner, screen)
|
||||
// The heading is the start of the new screen for a keyboard or screen
|
||||
// reader user, who would otherwise stay on a button that no longer exists.
|
||||
const heading = screen.querySelector("h1")
|
||||
if (heading) {
|
||||
heading.setAttribute("tabindex", "-1")
|
||||
if (moveFocus) heading.focus()
|
||||
}
|
||||
}
|
||||
|
||||
// An unknown hash renders the first screen rather than nothing, and the
|
||||
// address bar is corrected in place so that back does not return to it.
|
||||
function screenFromLocation(): ScreenId {
|
||||
const id = screenIdForHash(location.hash)
|
||||
if (id !== null && location.hash === hashForScreen(id)) return id
|
||||
const target = id ?? FIRST_SCREEN
|
||||
history.replaceState(null, "", hashForScreen(target))
|
||||
return target
|
||||
}
|
||||
|
||||
function onSubmit(event: Event): void {
|
||||
event.preventDefault()
|
||||
const question = questionOfScreen(current)
|
||||
if (!question) {
|
||||
// The only other screen with a form is #/checkout, whose Pay button D7 wires.
|
||||
shell.showError(PAYMENT_UNAVAILABLE)
|
||||
return
|
||||
}
|
||||
const form = event.target
|
||||
if (!(form instanceof HTMLFormElement)) return
|
||||
const chosen = form.querySelector<HTMLInputElement>("input[type=radio]:checked")
|
||||
if (!chosen) {
|
||||
shell.showError(CHOOSE_AN_OPTION)
|
||||
return
|
||||
}
|
||||
answers[question] = chosen.value
|
||||
const next = nextScreen(current)
|
||||
if (next) shell.go(next)
|
||||
}
|
||||
|
||||
root.addEventListener("submit", onSubmit)
|
||||
// Choosing an option answers the complaint the banner is showing.
|
||||
root.addEventListener("change", clearError)
|
||||
window.addEventListener("popstate", () => render(screenFromLocation(), true))
|
||||
render(screenFromLocation(), false)
|
||||
return shell
|
||||
}
|
||||
|
||||
function errorBanner(): HTMLElement {
|
||||
const banner = document.createElement("p")
|
||||
banner.className = "banner"
|
||||
// role=alert so the message is announced when it appears, not only seen.
|
||||
banner.setAttribute("role", "alert")
|
||||
banner.hidden = true
|
||||
return banner
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// The screens, as pure data.
|
||||
//
|
||||
// A screen is described as an element tree and never touches the DOM, so the
|
||||
// structure a browser will render can be asserted with `node --test` (see
|
||||
// ../test/static.test.mjs, which counts the <h1> of every screen and checks
|
||||
// that every radio group is a real fieldset/legend/label). ui.ts turns a tree
|
||||
// into elements with document.createElement and textContent — there is no
|
||||
// innerHTML anywhere, so a label that later comes from the catalog (D3) or from
|
||||
// a query parameter (D5) cannot become markup.
|
||||
//
|
||||
// The options here are placeholders. D3 builds the first three screens from the
|
||||
// catalog payload and replaces them.
|
||||
|
||||
import type {ScreenId} from "./router.js"
|
||||
|
||||
export type Child = El | string
|
||||
|
||||
export interface El {
|
||||
readonly tag: string
|
||||
readonly attrs: Readonly<Record<string, string>>
|
||||
readonly children: readonly Child[]
|
||||
}
|
||||
|
||||
/** An element node. An attribute present with an empty value is a boolean attribute. */
|
||||
export function h(tag: string, attrs: Record<string, string> = {}, children: readonly Child[] = []): El {
|
||||
return {tag, attrs, children}
|
||||
}
|
||||
|
||||
/** One radio card. `detail` is the secondary line, as on the app's PeriodCard. */
|
||||
export interface Option {
|
||||
readonly value: string
|
||||
readonly label: string
|
||||
readonly detail: string
|
||||
readonly disabled?: boolean
|
||||
}
|
||||
|
||||
/** The answers gathered so far. D3 replaces the values with catalog identifiers. */
|
||||
export interface Answers {
|
||||
readonly tier?: string
|
||||
readonly months?: string
|
||||
readonly pay?: string
|
||||
}
|
||||
|
||||
/** The radio group name of a question screen, which is also its answer key. */
|
||||
export type Question = "tier" | "months" | "pay"
|
||||
|
||||
interface QuestionScreen {
|
||||
readonly heading: string
|
||||
readonly legend: string
|
||||
readonly options: readonly Option[]
|
||||
}
|
||||
|
||||
const QUESTIONS: Readonly<Record<Question, QuestionScreen>> = {
|
||||
tier: {
|
||||
heading: "Choose your level",
|
||||
legend: "Badge level",
|
||||
options: [
|
||||
{value: "supporter", label: "Supporter", detail: "2 GB files"},
|
||||
{value: "legend", label: "Legend", detail: "5 GB files"},
|
||||
],
|
||||
},
|
||||
months: {
|
||||
heading: "How long?",
|
||||
legend: "Subscription length",
|
||||
options: [
|
||||
{value: "1", label: "1 month", detail: "Billed once"},
|
||||
{value: "3", label: "3 months", detail: "Billed once"},
|
||||
{value: "12", label: "12 months", detail: "Billed once"},
|
||||
],
|
||||
},
|
||||
pay: {
|
||||
heading: "How would you like to pay?",
|
||||
legend: "Payment method",
|
||||
options: [
|
||||
{value: "card", label: "Card", detail: "Visa, Mastercard and others"},
|
||||
{value: "btc", label: "Bitcoin", detail: "On-chain or Lightning"},
|
||||
{value: "xmr", label: "Monero", detail: "On-chain"},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const QUESTION_IDS: ReadonlySet<string> = new Set(Object.keys(QUESTIONS))
|
||||
|
||||
/** The question a screen asks, or null for a screen that asks none. */
|
||||
export function questionOfScreen(id: ScreenId): Question | null {
|
||||
return QUESTION_IDS.has(id) ? (id as Question) : null
|
||||
}
|
||||
|
||||
/** The placeholder options of a question screen. D3 replaces this with the catalog. */
|
||||
export function optionsOfQuestion(q: Question): readonly Option[] {
|
||||
return QUESTIONS[q].options
|
||||
}
|
||||
|
||||
/**
|
||||
* The whole screen, ready to be turned into elements. Exactly one <h1>.
|
||||
*
|
||||
* The switch is exhaustive over ScreenId with no default, so adding a screen
|
||||
* to router.ts fails to compile until this renders it — there is no route the
|
||||
* shell can reach that renders nothing.
|
||||
*/
|
||||
export function screenView(id: ScreenId, answers: Answers): El {
|
||||
switch (id) {
|
||||
case "tier":
|
||||
case "months":
|
||||
case "pay":
|
||||
return questionScreen(id, answers[id])
|
||||
case "checkout":
|
||||
return checkoutScreen(answers)
|
||||
case "order":
|
||||
return orderScreen()
|
||||
case "code":
|
||||
return codeScreen()
|
||||
}
|
||||
}
|
||||
|
||||
function questionScreen(q: Question, answer: string | undefined): El {
|
||||
const {heading, legend, options} = QUESTIONS[q]
|
||||
return section(heading, [
|
||||
h("form", {class: "form"}, [
|
||||
h("fieldset", {class: "options"}, [h("legend", {class: "options__legend"}, [legend]), ...options.map((o) => optionCard(q, o, answer))]),
|
||||
submitButton("Continue"),
|
||||
]),
|
||||
])
|
||||
}
|
||||
|
||||
function optionCard(group: string, option: Option, answer: string | undefined): El {
|
||||
const input: Record<string, string> = {class: "option__input", type: "radio", name: group, value: option.value}
|
||||
if (option.value === answer) input.checked = ""
|
||||
if (option.disabled) input.disabled = ""
|
||||
return h("label", {class: "option"}, [
|
||||
h("input", input),
|
||||
h("span", {class: "option__body"}, [
|
||||
h("span", {class: "option__label"}, [option.label]),
|
||||
h("span", {class: "option__detail"}, [option.detail]),
|
||||
]),
|
||||
])
|
||||
}
|
||||
|
||||
const NOT_CHOSEN = "Not chosen yet"
|
||||
|
||||
function checkoutScreen(answers: Answers): El {
|
||||
return section("Review your order", [
|
||||
h("form", {class: "form"}, [
|
||||
h("dl", {class: "summary"}, [
|
||||
...summaryRow("Level", labelOf("tier", answers.tier)),
|
||||
...summaryRow("Length", labelOf("months", answers.months)),
|
||||
...summaryRow("Payment", labelOf("pay", answers.pay)),
|
||||
]),
|
||||
submitButton("Pay"),
|
||||
]),
|
||||
])
|
||||
}
|
||||
|
||||
function summaryRow(term: string, value: string): readonly El[] {
|
||||
return [h("dt", {class: "summary__term"}, [term]), h("dd", {class: "summary__value"}, [value])]
|
||||
}
|
||||
|
||||
function labelOf(q: Question, value: string | undefined): string {
|
||||
if (value === undefined) return NOT_CHOSEN
|
||||
return QUESTIONS[q].options.find((o) => o.value === value)?.label ?? value
|
||||
}
|
||||
|
||||
// E5 replaces this with the crypto payment screen, E6 with the result screen.
|
||||
// They exist now so that no path can route to a hash that renders nothing.
|
||||
function orderScreen(): El {
|
||||
return section("Complete your payment", [h("p", {class: "prose"}, ["Payment details will appear here once an order has been created."])])
|
||||
}
|
||||
|
||||
function codeScreen(): El {
|
||||
return section("Your redemption code", [h("p", {class: "prose"}, ["Your code will appear here once a payment has been confirmed."])])
|
||||
}
|
||||
|
||||
function section(heading: string, body: readonly Child[]): El {
|
||||
return h("section", {class: "screen"}, [h("h1", {class: "screen__heading"}, [heading]), ...body])
|
||||
}
|
||||
|
||||
function submitButton(label: string): El {
|
||||
return h("button", {class: "button", type: "submit"}, [label])
|
||||
}
|
||||
@@ -1,12 +1,306 @@
|
||||
/* Placeholder stylesheet; the design system replaces it.
|
||||
/* Design system for the supporter-badge checkout site.
|
||||
|
||||
Served from web/ rather than from dist/, so that an edit is picked up
|
||||
without a rebuild when the service runs with [web] web_dir set. */
|
||||
without a rebuild when the service runs with [web] web_dir set.
|
||||
|
||||
Two rules bind every edit to this file:
|
||||
|
||||
1. No double-at token belongs here — the syntax index.html names its assets
|
||||
with. Only index.html is substituted, so such a token in a CSS rule would
|
||||
reach the browser as literal text. The two logos are <img> elements in
|
||||
index.html; this file only chooses which of them is shown.
|
||||
2. No cross-origin URL belongs here either. The service sends
|
||||
Content-Security-Policy: default-src 'self' (D4), so a webfont or a
|
||||
remote image would be blocked at runtime with nothing to see. The font
|
||||
stack below is the system one for that reason.
|
||||
|
||||
Every colour is defined on bare :root. The dark block only *redefines*
|
||||
tokens that already exist: a colour introduced there alone would be
|
||||
undefined in light mode, which is where most of this site is read, and the
|
||||
browser would fall back to nothing rather than to an error. */
|
||||
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
|
||||
/* Accent: primary-light and primary-dark from website/tailwind.config.js. */
|
||||
--accent: #0053D0;
|
||||
--accent-hover: #1661D1;
|
||||
--on-accent: #FFFFFF;
|
||||
|
||||
--bg: #FFFFFF;
|
||||
--card-bg: #FFFFFF;
|
||||
--text: #0D0E12;
|
||||
--text-secondary: #3F484B;
|
||||
--border: #DFE4EA;
|
||||
--focus-ring: #0053D0;
|
||||
|
||||
--error-bg: #FDECEC;
|
||||
--error-text: #8C1C13;
|
||||
--error-border: #E0A5A0;
|
||||
|
||||
--gutter: 20px;
|
||||
--radius: 16px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--accent: #70F0F9;
|
||||
--accent-hover: #66D9E2;
|
||||
--on-accent: #000832;
|
||||
|
||||
--bg: #000832;
|
||||
/* The app's PeriodCard tints its card in dark mode and leaves it flush
|
||||
with the page in light mode; these two match that. */
|
||||
--card-bg: #071C46;
|
||||
--text: #FFFFFF;
|
||||
--text-secondary: #A9BAD4;
|
||||
--border: #0B2A59;
|
||||
--focus-ring: #70F0F9;
|
||||
|
||||
--error-bg: #3A1113;
|
||||
--error-text: #FFB3AD;
|
||||
--error-border: #7A2B2B;
|
||||
}
|
||||
|
||||
.logo--light {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.logo--dark {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: 17px;
|
||||
line-height: 1.5;
|
||||
/* A long code or address must wrap rather than widen the page: the narrow
|
||||
layout this site is read on has no horizontal room to give. */
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
/* One centred column, the whole site. */
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32px;
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
min-height: 100vh;
|
||||
margin: 0 auto;
|
||||
padding: 40px var(--gutter) 56px;
|
||||
}
|
||||
|
||||
.masthead {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: block;
|
||||
width: auto;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
.logo--dark {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#app {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.screen {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
animation: screen-fade-in 150ms ease-out;
|
||||
}
|
||||
|
||||
@keyframes screen-fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.screen {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
|
||||
.screen__heading {
|
||||
margin: 0;
|
||||
font-size: 1.625rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.prose {
|
||||
margin: 0;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* A plain block fieldset: a flex or grid fieldset moves its rendered legend
|
||||
out of normal flow in some engines, and the legend is a real one here. */
|
||||
.options {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.options__legend {
|
||||
margin: 0 0 12px;
|
||||
padding: 0;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
/* The radio card, following PeriodCard in BadgesPayView.kt: a 2px border that
|
||||
turns accent when selected. The input stays in the accessibility tree and
|
||||
in the tab order; only its own rendering is hidden. */
|
||||
.option {
|
||||
display: block;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.option + .option {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.option__input {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
clip-path: inset(50%);
|
||||
}
|
||||
|
||||
.option__body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 16px 18px;
|
||||
border: 2px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
.option__input:checked + .option__body {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.option__input:focus-visible + .option__body {
|
||||
outline: 2px solid var(--focus-ring);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.option__input:disabled + .option__body {
|
||||
cursor: default;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.option__label {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.option__detail {
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.9375rem;
|
||||
}
|
||||
|
||||
.option__input:checked + .option__body .option__detail {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.summary {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 8px 16px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.summary__term {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.summary__value {
|
||||
margin: 0;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.button {
|
||||
width: 100%;
|
||||
padding: 14px 24px;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
background: var(--accent);
|
||||
color: var(--on-accent);
|
||||
font: inherit;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background: var(--accent-hover);
|
||||
}
|
||||
|
||||
/* Nothing here fails to a blank screen: a failed fetch or an unanswered
|
||||
question says so in this banner. */
|
||||
.banner {
|
||||
margin: 0;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid var(--error-border);
|
||||
border-radius: 12px;
|
||||
background: var(--error-bg);
|
||||
color: var(--error-text);
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: auto;
|
||||
font-size: 0.9375rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
/* The only focus styling in this file, and nothing suppresses it: there is no
|
||||
`outline: none` anywhere here. */
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--focus-ring);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// A very small CSS reader for the assertions in static.test.mjs.
|
||||
//
|
||||
// It understands exactly what this stylesheet uses — nested at-rules, rule
|
||||
// blocks and custom properties — because the alternative is a parser
|
||||
// dependency and this project is capped at one (decision 7). Anything it
|
||||
// cannot answer, it answers by throwing rather than by returning nothing: a
|
||||
// check that silently finds no rules is a check that cannot fail.
|
||||
|
||||
/** The body of the block whose opening brace is at or after `from`. */
|
||||
function blockAt(css, from) {
|
||||
const open = css.indexOf("{", from)
|
||||
if (open < 0) throw new Error(`no block after offset ${from}`)
|
||||
let depth = 0
|
||||
for (let i = open; i < css.length; i++) {
|
||||
if (css[i] === "{") depth++
|
||||
else if (css[i] === "}" && --depth === 0) return {body: css.slice(open + 1, i), end: i + 1}
|
||||
}
|
||||
throw new Error(`unclosed block opened at offset ${open}`)
|
||||
}
|
||||
|
||||
/** Comments removed, so that prose in them is never mistaken for a declaration. */
|
||||
export function stripComments(css) {
|
||||
return css.replace(/\/\*[\s\S]*?\*\//g, "")
|
||||
}
|
||||
|
||||
/**
|
||||
* The body of the at-rule whose prelude contains `prelude`, e.g.
|
||||
* "prefers-color-scheme: dark". Throws when there is not exactly one.
|
||||
*/
|
||||
export function atRule(css, prelude) {
|
||||
const found = []
|
||||
const re = /@media[^{]*/g
|
||||
for (const m of css.matchAll(re)) {
|
||||
if (m[0].includes(prelude)) found.push(blockAt(css, m.index).body)
|
||||
}
|
||||
if (found.length !== 1) throw new Error(`expected exactly one @media containing "${prelude}", found ${found.length}`)
|
||||
return found[0]
|
||||
}
|
||||
|
||||
/** Every at-rule block removed, leaving only top-level rules. */
|
||||
export function withoutAtRules(css) {
|
||||
let out = ""
|
||||
let i = 0
|
||||
while (i < css.length) {
|
||||
const at = css.indexOf("@", i)
|
||||
if (at < 0) return out + css.slice(i)
|
||||
out += css.slice(i, at)
|
||||
const semi = css.indexOf(";", at)
|
||||
const brace = css.indexOf("{", at)
|
||||
// An at-rule with no block (@import, @charset) ends at its semicolon.
|
||||
if (semi >= 0 && (brace < 0 || semi < brace)) i = semi + 1
|
||||
else i = blockAt(css, at).end
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** The declarations of every rule whose selector list matches `selector` exactly. */
|
||||
export function rules(css, selector) {
|
||||
const found = []
|
||||
let i = 0
|
||||
while (i < css.length) {
|
||||
const open = css.indexOf("{", i)
|
||||
if (open < 0) break
|
||||
const sel = css.slice(i, open).trim()
|
||||
const {body, end} = blockAt(css, open)
|
||||
if (sel === selector) found.push(body)
|
||||
i = end
|
||||
}
|
||||
return found
|
||||
}
|
||||
|
||||
/** The custom properties declared by a block, as a Map from name to value. */
|
||||
export function customProperties(body) {
|
||||
const props = new Map()
|
||||
for (const m of body.matchAll(/(--[\w-]+)\s*:\s*([^;}]+)/g)) props.set(m[1], m[2].trim())
|
||||
return props
|
||||
}
|
||||
|
||||
/** Every custom property referenced through var(), anywhere in the sheet. */
|
||||
export function referencedProperties(css) {
|
||||
return new Set([...css.matchAll(/var\(\s*(--[\w-]+)/g)].map((m) => m[1]))
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// Unit tests for the pure routing functions, run against the built modules
|
||||
// with `npm test` (node's built-in runner — no dependency, decision 7).
|
||||
//
|
||||
// These run against dist/, not src/, so they test what a browser is served.
|
||||
// Run `npm run build` first; `npm test` does not compile.
|
||||
|
||||
import test from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
|
||||
import {FIRST_SCREEN, SCREEN_IDS, hashForScreen, nextScreen, screenIdForHash} from "../dist/router.js"
|
||||
|
||||
test("every screen in the plan has a route", () => {
|
||||
assert.deepEqual([...SCREEN_IDS], ["tier", "months", "pay", "checkout", "order", "code"])
|
||||
})
|
||||
|
||||
test("screenIdForHash resolves the canonical hash of every screen", () => {
|
||||
for (const id of SCREEN_IDS) {
|
||||
assert.equal(screenIdForHash(hashForScreen(id)), id, `#/${id} must route to ${id}`)
|
||||
}
|
||||
})
|
||||
|
||||
test("hashForScreen is the inverse of screenIdForHash", () => {
|
||||
for (const id of SCREEN_IDS) assert.equal(hashForScreen(id), `#/${id}`)
|
||||
})
|
||||
|
||||
test("a hand-edited hash is tolerated: no slash, or a trailing one", () => {
|
||||
assert.equal(screenIdForHash("#tier"), "tier")
|
||||
assert.equal(screenIdForHash("#/tier/"), "tier")
|
||||
assert.equal(screenIdForHash("#checkout/"), "checkout")
|
||||
})
|
||||
|
||||
test("an absent or empty hash starts the wizard", () => {
|
||||
assert.equal(screenIdForHash(""), FIRST_SCREEN)
|
||||
assert.equal(screenIdForHash("#"), FIRST_SCREEN)
|
||||
assert.equal(screenIdForHash("#/"), FIRST_SCREEN)
|
||||
assert.equal(FIRST_SCREEN, "tier")
|
||||
})
|
||||
|
||||
test("an unknown hash is null, not a screen and not a throw", () => {
|
||||
for (const hash of ["#/nonsense", "#/TIER", "#/tier/extra", "#//tier", "#/order?id=1"]) {
|
||||
assert.equal(screenIdForHash(hash), null, `${hash} must not resolve to a screen`)
|
||||
}
|
||||
})
|
||||
|
||||
test("nextScreen walks the wizard and stops at checkout", () => {
|
||||
assert.equal(nextScreen("tier"), "months")
|
||||
assert.equal(nextScreen("months"), "pay")
|
||||
assert.equal(nextScreen("pay"), "checkout")
|
||||
assert.equal(nextScreen("checkout"), null)
|
||||
})
|
||||
|
||||
test("the two screens reached from a checkout response are not advanced into", () => {
|
||||
assert.equal(nextScreen("order"), null)
|
||||
assert.equal(nextScreen("code"), null)
|
||||
})
|
||||
@@ -0,0 +1,306 @@
|
||||
// The static half of D2's verification.
|
||||
//
|
||||
// There is no browser and no display in this environment, so nothing here
|
||||
// claims that anything *renders*. What it does assert is every property of the
|
||||
// built output that a browser would otherwise be the only witness to, and each
|
||||
// assertion was checked to fail when the thing it names is broken (see the
|
||||
// D2 report). Run with `npm test` after `npm run build`.
|
||||
//
|
||||
// Assertions are against dist/ and against the two files served from web/,
|
||||
// never against src/: the served bytes are what a browser gets.
|
||||
|
||||
import test from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import {readFileSync, readdirSync} from "node:fs"
|
||||
import {fileURLToPath} from "node:url"
|
||||
|
||||
import {SCREEN_IDS} from "../dist/router.js"
|
||||
import {optionsOfQuestion, questionOfScreen, screenView} from "../dist/view.js"
|
||||
import {atRule, customProperties, referencedProperties, rules, stripComments, withoutAtRules} from "./css.mjs"
|
||||
|
||||
const read = (rel) => readFileSync(fileURLToPath(new URL(rel, import.meta.url)), "utf8")
|
||||
|
||||
const cssSource = read("../styles.css")
|
||||
const css = stripComments(cssSource)
|
||||
const topLevel = withoutAtRules(css)
|
||||
const darkBlock = atRule(css, "prefers-color-scheme: dark")
|
||||
const indexHtml = read("../index.html")
|
||||
const devHtml = read("../dist/dev.html")
|
||||
const uiJs = read("../dist/ui.js")
|
||||
|
||||
// Derived, not listed: a screen that view.ts starts calling a question is
|
||||
// covered by the fieldset and label checks below without editing this file.
|
||||
const QUESTIONS = SCREEN_IDS.filter((id) => questionOfScreen(id) !== null)
|
||||
const LOGOS = ["logo-symbol-light.svg", "logo-symbol-dark.svg"]
|
||||
|
||||
// -- colour tokens ----------------------------------------------------------
|
||||
|
||||
test("every custom property the sheet uses is defined on bare :root", () => {
|
||||
const rootBlocks = rules(topLevel, ":root")
|
||||
assert.equal(rootBlocks.length, 1, "expected exactly one top-level :root rule")
|
||||
const defined = customProperties(rootBlocks[0])
|
||||
assert.ok(defined.size > 0, "the :root rule declares no custom properties")
|
||||
for (const name of referencedProperties(css)) {
|
||||
assert.ok(defined.has(name), `${name} is used but has no definition on bare :root, so it is undefined in light mode`)
|
||||
}
|
||||
})
|
||||
|
||||
test("the dark block only redefines tokens, and introduces none", () => {
|
||||
const light = customProperties(rules(topLevel, ":root")[0])
|
||||
const darkRoot = rules(darkBlock, ":root")
|
||||
assert.equal(darkRoot.length, 1, "expected exactly one :root rule inside the dark media query")
|
||||
const dark = customProperties(darkRoot[0])
|
||||
assert.ok(dark.size > 0, "the dark :root rule declares no custom properties")
|
||||
for (const name of dark.keys()) {
|
||||
assert.ok(light.has(name), `${name} is defined only in dark mode, so it is undefined in light mode`)
|
||||
}
|
||||
})
|
||||
|
||||
test("no custom property is declared outside a :root rule", () => {
|
||||
// A token declared on a selector would be scoped to it, and its light and
|
||||
// dark definitions could then disagree about which elements they reach.
|
||||
for (const block of [topLevel, darkBlock]) {
|
||||
let i = 0
|
||||
while (i < block.length) {
|
||||
const open = block.indexOf("{", i)
|
||||
if (open < 0) break
|
||||
const selector = block.slice(i, open).trim()
|
||||
const close = matchingClose(block, open)
|
||||
if (selector !== ":root") {
|
||||
const stray = [...customProperties(block.slice(open + 1, close)).keys()]
|
||||
assert.deepEqual(stray, [], `${selector} declares custom properties: ${stray.join(", ")}`)
|
||||
}
|
||||
i = close + 1
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function matchingClose(s, open) {
|
||||
let depth = 0
|
||||
for (let i = open; i < s.length; i++) {
|
||||
if (s[i] === "{") depth++
|
||||
else if (s[i] === "}" && --depth === 0) return i
|
||||
}
|
||||
throw new Error("unclosed block")
|
||||
}
|
||||
|
||||
test("the accent is the website's primary colour in both schemes", () => {
|
||||
const light = customProperties(rules(topLevel, ":root")[0])
|
||||
const dark = customProperties(rules(darkBlock, ":root")[0])
|
||||
assert.equal(light.get("--accent"), "#0053D0", "light accent must be primary-light from website/tailwind.config.js")
|
||||
assert.equal(dark.get("--accent"), "#70F0F9", "dark accent must be primary-dark from website/tailwind.config.js")
|
||||
})
|
||||
|
||||
// -- what the stylesheet may not contain ------------------------------------
|
||||
|
||||
test("styles.css carries no @@token@@: it is served verbatim and never substituted", () => {
|
||||
assert.equal(cssSource.match(/@@[\w.-]+@@/g), null)
|
||||
})
|
||||
|
||||
test("styles.css references no external origin: default-src 'self' would block it", () => {
|
||||
assert.equal(css.match(/[a-z][a-z0-9+.-]*:\/\//gi), null, "an absolute URL in the stylesheet")
|
||||
assert.equal(css.match(/\burl\(/g), null, "url() would have to resolve to a same-origin asset; none is used")
|
||||
assert.equal(css.match(/@import/g), null)
|
||||
})
|
||||
|
||||
test("the font stack is the system one", () => {
|
||||
const body = rules(topLevel, "body")
|
||||
assert.equal(body.length, 1)
|
||||
assert.match(body[0], /font-family:\s*system-ui/)
|
||||
})
|
||||
|
||||
// -- layout, motion, focus --------------------------------------------------
|
||||
|
||||
test("the column is capped at 560px", () => {
|
||||
const column = rules(topLevel, ".column")
|
||||
assert.equal(column.length, 1, "expected exactly one .column rule")
|
||||
assert.match(column[0], /max-width:\s*560px/)
|
||||
})
|
||||
|
||||
test("the screen transition is 150ms and prefers-reduced-motion turns it off", () => {
|
||||
const screen = rules(topLevel, ".screen")
|
||||
assert.equal(screen.length, 1, "expected exactly one .screen rule")
|
||||
assert.match(screen[0], /animation:[^;]*\b150ms\b/, ".screen must carry the 150 ms fade")
|
||||
const reduced = atRule(css, "prefers-reduced-motion: reduce")
|
||||
const reducedScreen = rules(reduced, ".screen")
|
||||
assert.equal(reducedScreen.length, 1, "the reduced-motion block must address .screen")
|
||||
assert.match(reducedScreen[0], /animation:\s*none/)
|
||||
})
|
||||
|
||||
test("a :focus-visible ring exists and nothing suppresses it", () => {
|
||||
const ring = rules(topLevel, ":focus-visible")
|
||||
assert.equal(ring.length, 1, "expected a global :focus-visible rule")
|
||||
assert.match(ring[0], /outline:\s*\d+px\s+solid/)
|
||||
// Not "no blanket outline:none" but "no outline:none at all" — the weaker
|
||||
// rule needs a judgement about which selectors count as blanket.
|
||||
assert.equal(css.match(/outline\s*:\s*none/g), null, "outline: none anywhere would put this ring in doubt")
|
||||
})
|
||||
|
||||
test("the selected card gets a 2px accent border, as PeriodCard does", () => {
|
||||
const body = rules(topLevel, ".option__body")
|
||||
assert.equal(body.length, 1)
|
||||
assert.match(body[0], /border:\s*2px\s+solid\s+var\(--border\)/)
|
||||
const checked = rules(topLevel, ".option__input:checked + .option__body")
|
||||
assert.equal(checked.length, 1, "expected a rule for the checked card")
|
||||
assert.match(checked[0], /border-color:\s*var\(--accent\)/)
|
||||
})
|
||||
|
||||
test("the focus ring reaches the card, since the radio itself is visually hidden", () => {
|
||||
const hidden = rules(topLevel, ".option__input")
|
||||
assert.equal(hidden.length, 1)
|
||||
assert.doesNotMatch(hidden[0], /display:\s*none/, "display: none would drop the radio out of the tab order")
|
||||
const focused = rules(topLevel, ".option__input:focus-visible + .option__body")
|
||||
assert.equal(focused.length, 1, "a hidden radio must show its focus on the card")
|
||||
assert.match(focused[0], /outline:\s*\d+px\s+solid/)
|
||||
})
|
||||
|
||||
// -- the screens ------------------------------------------------------------
|
||||
|
||||
function walk(node, visit, parents = []) {
|
||||
visit(node, parents)
|
||||
const chain = [...parents, node]
|
||||
for (const child of node.children) if (typeof child !== "string") walk(child, visit, chain)
|
||||
}
|
||||
|
||||
function findAll(root, tag) {
|
||||
const found = []
|
||||
walk(root, (node, parents) => {
|
||||
if (node.tag === tag) found.push({node, parents})
|
||||
})
|
||||
return found
|
||||
}
|
||||
|
||||
function text(node) {
|
||||
let out = ""
|
||||
walk(node, (n) => {
|
||||
for (const child of n.children) if (typeof child === "string") out += child
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
test("every screen has exactly one <h1>, and it says something", () => {
|
||||
for (const id of SCREEN_IDS) {
|
||||
const headings = findAll(screenView(id, {}), "h1")
|
||||
assert.equal(headings.length, 1, `screen ${id} must have exactly one <h1>, found ${headings.length}`)
|
||||
assert.notEqual(text(headings[0].node).trim(), "", `the <h1> of screen ${id} is empty`)
|
||||
}
|
||||
})
|
||||
|
||||
test("every screen renders something under its heading", () => {
|
||||
for (const id of SCREEN_IDS) {
|
||||
const view = screenView(id, {})
|
||||
assert.ok(view.children.length > 1, `screen ${id} is a bare heading`)
|
||||
}
|
||||
})
|
||||
|
||||
test("the three question screens are the ones the plan names", () => {
|
||||
// Without this the loops below would pass vacuously if QUESTIONS were empty.
|
||||
assert.deepEqual(QUESTIONS, ["tier", "months", "pay"])
|
||||
})
|
||||
|
||||
test("each question is a real fieldset with a real legend", () => {
|
||||
for (const id of QUESTIONS) {
|
||||
const view = screenView(id, {})
|
||||
const fieldsets = findAll(view, "fieldset")
|
||||
assert.equal(fieldsets.length, 1, `screen ${id} must group its radios in one <fieldset>`)
|
||||
const legends = findAll(fieldsets[0].node, "legend")
|
||||
assert.equal(legends.length, 1, `the <fieldset> of screen ${id} must have exactly one <legend>`)
|
||||
assert.notEqual(text(legends[0].node).trim(), "", `the <legend> of screen ${id} is empty`)
|
||||
}
|
||||
})
|
||||
|
||||
test("every option is a radio inside a label, and every option is offered", () => {
|
||||
for (const id of QUESTIONS) {
|
||||
const view = screenView(id, {})
|
||||
const radios = findAll(view, "input").filter(({node}) => node.attrs.type === "radio")
|
||||
const options = optionsOfQuestion(questionOfScreen(id))
|
||||
assert.equal(radios.length, options.length, `screen ${id} offers ${options.length} options but renders ${radios.length} radios`)
|
||||
for (const {node, parents} of radios) {
|
||||
assert.ok(
|
||||
parents.some((p) => p.tag === "label"),
|
||||
`a radio on screen ${id} is not inside a <label>, so its card is not clickable and it has no accessible name`
|
||||
)
|
||||
assert.equal(node.attrs.name, id, `a radio on screen ${id} is in the wrong group`)
|
||||
}
|
||||
assert.deepEqual(
|
||||
radios.map(({node}) => node.attrs.value),
|
||||
options.map((o) => o.value)
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
test("the chosen option is the checked one, and only that one", () => {
|
||||
for (const id of QUESTIONS) {
|
||||
const options = optionsOfQuestion(questionOfScreen(id))
|
||||
const chosen = options[options.length - 1].value
|
||||
const radios = findAll(screenView(id, {[id]: chosen}), "input")
|
||||
const checked = radios.filter(({node}) => "checked" in node.attrs).map(({node}) => node.attrs.value)
|
||||
assert.deepEqual(checked, [chosen], `screen ${id} must check exactly the chosen option`)
|
||||
}
|
||||
})
|
||||
|
||||
test("the checkout summary shows every answer, and says so when one is missing", () => {
|
||||
const answered = screenView("checkout", {tier: "legend", months: "12", pay: "xmr"})
|
||||
const summary = text(answered)
|
||||
assert.match(summary, /Legend/)
|
||||
assert.match(summary, /12 months/)
|
||||
assert.match(summary, /Monero/)
|
||||
assert.doesNotMatch(summary, /Not chosen/)
|
||||
assert.match(text(screenView("checkout", {})), /Not chosen/, "an unanswered question must not render as blank")
|
||||
})
|
||||
|
||||
// -- routing and the shell --------------------------------------------------
|
||||
|
||||
test("the shell registers a popstate listener, so back and forward work", () => {
|
||||
assert.match(uiJs, /addEventListener\(\s*["']popstate["']/, "no popstate listener in the built shell")
|
||||
})
|
||||
|
||||
test("the shell navigates with pushState and never reloads the page", () => {
|
||||
assert.match(uiJs, /history\.pushState\(/)
|
||||
assert.equal(uiJs.match(/location\.(assign|reload|replace)\(/g), null, "a page reload would lose the wizard's answers")
|
||||
})
|
||||
|
||||
test("no module builds markup from a string", () => {
|
||||
// Everything an option's label may later carry — catalog copy (D3), a query
|
||||
// parameter (D5), a provider's address (E5) — reaches the page as a text
|
||||
// node, so none of it can become markup.
|
||||
const dist = fileURLToPath(new URL("../dist", import.meta.url))
|
||||
for (const name of readdirSync(dist).filter((n) => n.endsWith(".js"))) {
|
||||
assert.equal(read(`../dist/${name}`).match(/\.innerHTML|\.outerHTML|insertAdjacentHTML\(|document\.write\(/g), null, `in dist/${name}`)
|
||||
}
|
||||
})
|
||||
|
||||
// -- the served page --------------------------------------------------------
|
||||
|
||||
test("index.html carries a token for each logo, and dev.html resolves both", () => {
|
||||
for (const logo of LOGOS) {
|
||||
assert.ok(indexHtml.includes(`@@${logo}@@`), `index.html must reference ${logo} by token`)
|
||||
assert.ok(devHtml.includes(`./${logo}`), `dev.html must resolve ${logo} into dist/`)
|
||||
}
|
||||
assert.equal(devHtml.match(/@@[\w.-]+@@/g), null, "dev.html has an unresolved token")
|
||||
})
|
||||
|
||||
test("the built assets are the two logos and nothing else", () => {
|
||||
const assets = readdirSync(fileURLToPath(new URL("../assets", import.meta.url))).filter((n) => !n.startsWith("."))
|
||||
assert.deepEqual(assets.sort(), [...LOGOS].sort())
|
||||
})
|
||||
|
||||
test("the support contact renders on every screen, from index.html's footer", () => {
|
||||
assert.match(indexHtml, /<footer[^>]*>[\s\S]*@@support_contact@@[\s\S]*<\/footer>/)
|
||||
// Outside <main id="app">, which the shell replaces on every navigation.
|
||||
assert.ok(indexHtml.indexOf("</main>") < indexHtml.indexOf("<footer"))
|
||||
})
|
||||
|
||||
test("no token is written anywhere but index.html", () => {
|
||||
const tokenRe = /@@[\w.-]+@@/g
|
||||
const src = fileURLToPath(new URL("../src", import.meta.url))
|
||||
for (const name of readdirSync(src)) {
|
||||
assert.equal(read(`../src/${name}`).match(tokenRe), null, `src/${name} carries a token, which nothing substitutes`)
|
||||
}
|
||||
assert.equal(cssSource.match(tokenRe), null)
|
||||
})
|
||||
|
||||
test("exactly one <h1> exists in the page shell too, counting the screens' own", () => {
|
||||
// The screens supply the <h1>; index.html must not add a second one.
|
||||
assert.equal(indexHtml.match(/<h1[\s>]/g), null)
|
||||
})
|
||||
@@ -151,7 +151,7 @@ The two `-m` filters are needed because the badge tests live under two hspec pat
|
||||
| C5 | Client and service integration tests | B10, C4 | ☑ |
|
||||
| D0 | Store layer: orders, invoices, provider events | A3, A5, B1 | ☑ |
|
||||
| D1 | Web project skeleton and tsc build | — | ☑ |
|
||||
| D2 | Design system and site wizard shell | D1 | ☐ |
|
||||
| D2 | Design system and site wizard shell | D1 | ☑ |
|
||||
| D3 | Catalog fetch and the four site screens | D2, D4 | ☐ |
|
||||
| D4 | Warp listener, asset embedding, routing | A2, A4, A6, B1, D1 | ☐ |
|
||||
| D5 | URL prefill | D3 | ☐ |
|
||||
@@ -782,7 +782,7 @@ Phase D ends with a browsable, priced site wizard whose Pay button reaches a rea
|
||||
|
||||
#### D2 — Design system and site wizard shell
|
||||
|
||||
**Files:** `apps/simplex-badge-service/web/{styles.css,index.html}`, `apps/simplex-badge-service/web/src/{ui.ts,main.ts}`, `apps/simplex-badge-service/web/assets/logo-symbol-{light,dark}.svg` (copied from `website/src/img/new/`)
|
||||
**Files:** `apps/simplex-badge-service/web/{styles.css,index.html,package.json}`, `apps/simplex-badge-service/web/src/{router.ts,view.ts,ui.ts,main.ts}`, `apps/simplex-badge-service/web/test/{router.test.mjs,static.test.mjs,css.mjs}`, `apps/simplex-badge-service/web/assets/logo-symbol-{light,dark}.svg` (copied from `website/src/img/new/`)
|
||||
|
||||
**Do:** Match `https://snrc-testing.pages.dev/`: a single centred column, `max-width: 560px`, generous whitespace, a system font stack, and the SimpleX logo as the only image: `website/src/img/new/logo-symbol-light.svg` and `logo-symbol-dark.svg`, copied into `web/assets/` and from there into `dist/` by `npm run build` (D1), referenced as two `<img>` elements in `index.html` carrying the tokens `@@logo-symbol-light.svg@@` and `@@logo-symbol-dark.svg@@`. The tokens go in `index.html` and nowhere else, because D4 substitutes only there; `styles.css` is served verbatim, so a token written into a CSS rule would reach the browser as literal text. The `prefers-color-scheme` media query that redefines the colour tokens also toggles which of the two images is displayed. The reference site is the visual target, but the specifications in this step are sufficient on their own if it is unreachable.
|
||||
|
||||
@@ -792,12 +792,14 @@ Phase D ends with a browsable, priced site wizard whose Pay button reaches a rea
|
||||
- Transitions: a 150 ms opacity fade, disabled under `prefers-reduced-motion`.
|
||||
- Accessibility: real `<fieldset>`, `<legend>` and `<label>` radios, keyboard navigable, `:focus-visible` rings, exactly one `<h1>` per screen.
|
||||
- `main.ts`, written as a placeholder in D1, imports the shell and starts it, so `dev.html` renders something. D3 and D5 extend the same module.
|
||||
- The shell is four modules, so that everything decidable without a browser can be asserted without one (§9): `router.ts` is the pure hash-to-screen mapping, `view.ts` describes each screen as a pure element tree, `ui.ts` is the only module that touches the DOM, and `main.ts` starts it. `npm test` runs the assertions on `node:test`, a built-in, so decision 7's one-devDependency cap is untouched. D3's money formatter belongs in the same pure half.
|
||||
- A question screen does not advance when a radio's `change` fires: the arrow keys move the selection inside a radio group, so auto-advance puts every option after the first out of keyboard reach. Each question ends in a Continue button, and submitting one unanswered shows the error banner (§9).
|
||||
- A visible error banner for failed fetches. Never a silent blank screen.
|
||||
- A support contact renders in the footer on every screen, from the `@@support_contact@@` token D4 substitutes (D1). It is the site's only contact channel, and D7, E5, E6 and F3 all direct users to it.
|
||||
|
||||
**Verify:** Manual: serve `apps/simplex-badge-service/web` with `python3 -m http.server` and open `/dist/dev.html`, whose screens carry hardcoded placeholder options at this step, and step through every screen with the keyboard only, reaching and activating every option. In both light and dark themes at 320 px width, confirm that no screen scrolls horizontally, that the selected option card's 2px accent border is visible, and that the `:focus-visible` ring is visible against both backgrounds.
|
||||
**Verify:** In `apps/simplex-badge-service/web`: `npx tsc --noEmit` clean, `npm run build`, then `npm test` (`test/router.test.mjs` and `test/static.test.mjs`), then a second `npm run build` leaving `git status --porcelain -- apps/simplex-badge-service/web/dist` empty (D8). The assertions run against the **built** output and against the two files served from `web/`, never against `src/`: every custom property used anywhere has a definition on bare `:root` and the dark block introduces none of its own; the accent is exactly `#0053D0` and `#70F0F9`; `styles.css` carries no `@@…@@` token, no `url()` and no absolute URL; every screen renders exactly one `<h1>`; every radio group is a real `<fieldset>` with a real `<legend>` and every radio sits inside a `<label>`; a `:focus-visible` rule exists and no `outline: none` appears anywhere; the reduced-motion block turns off the 150 ms fade; the column is capped at `max-width: 560px`; all six hashes resolve and the built shell registers a `popstate` listener and never assigns markup from a string. Each of these was run against a deliberately broken input and observed to fail there (§9).
|
||||
|
||||
**This pass is also D1's first browser run, and confirms three things about its plumbing that no environment without a browser could check (§9).** Confirm each explicitly, because a blank or unstyled page here is as likely to be D1's mechanism as this step's markup: that `dev.html` loads at all rather than rendering an empty shell; that `../styles.css` is *applied* and not merely served with a `text/css` header — the colour tokens are the visible proof; and that the browser executes the module graph across files, `main.js` importing `ui.js` by the relative specifier `tsc` does not rewrite. The third is what decision 7 and D4's single-prefix asset hash both rest on, and this is the first time anything runs it.
|
||||
**Rendering is asserted nowhere, by anything, until the phase's browser pass.** That pass is one §9 entry covering D1's three deferred assertions and D2's own; it is not handed from step to step. Do not read a green `npm test` as evidence that the page draws.
|
||||
|
||||
#### D3 — Catalog fetch and the four site screens
|
||||
|
||||
@@ -1492,6 +1494,13 @@ Append here when a step contradicts this plan: the step id, what was wrong, and
|
||||
- **D8 — the step text's `git diff --exit-code` was implemented as `git status --porcelain`, per the D1/D8 entry above.** The blind spot was already recorded but the step text still named the blind command; it now names the porcelain one. This is not theoretical: in the clean clone used to verify the job, building a new asset into `dist/` without `git add`ing it leaves `git diff --exit-code -- dist` **exiting 0** while the porcelain check exits 1 — the gate as the plan first wrote it would have gone green on precisely the failure it exists to catch, and that failure surfaces at D4 as a *startup* error in the service. The untracked case includes a nested asset, whose whole directory `git status` collapses to one `?? …/dist/img/` line — still non-empty, so still a failure.
|
||||
- **D8 — "a job gated on `apps/simplex-badge-service/web/**`" is not expressible; the job runs on every trigger of `build.yml` instead.** GitHub Actions `paths:` filters are a *workflow* trigger, not a per-job condition, so the only ways to gate a single job are a separate workflow file with its own `paths:` or a third-party changed-files action. Neither was taken. `build.yml` is this repository's one PR gate and its `pull_request` paths already list `apps/simplex-badge-service/**` (`:19`), so a PR touching `web/` already runs this workflow and the gating would buy nothing there; `web.yml`, the only `paths:`-triggered workflow here, is a gh-pages *deploy* pipeline, not a check, so following its shape would be copying a different kind of thing. On pushes to `master`/`stable` and on tags, where `build.yml` has no `paths` filter, running unconditionally is what is wanted — a merge can leave `dist/` inconsistent with `src/` while touching neither, and a path-filtered workflow would skip exactly that commit. The cost is `npm ci` of one package plus `tsc`, seconds, in parallel with builds that take tens of minutes. A separate workflow would also add a second path list to keep in step with the first and a second required-check name; a `paths`-filtered check that is marked required leaves PRs that do not touch those paths pending forever.
|
||||
- **D8 — the step's Verify was manual and unrunnable before merge; it is now the same command sequence run locally.** "Edit a `.ts` and confirm the job fails" cannot be executed before the workflow is on the default branch. The line now specifies a clean clone of HEAD, the job's own commands in it, and both failure modes with the exact output each produces — which is what was run. What remains unverified is only what no local run can cover: that GitHub resolves `actions/checkout@v6` and `actions/setup-node@v6` and provisions node 24 on `ubuntu-latest`. The first CI run on this branch confirms that.
|
||||
- **Phase D — ONE outstanding browser pass, held here. Do not defer it step to step.** D1 deferred three assertions to D2, D2 has no browser either, and a chain of hand-offs evaporates: each step ticks, each points at the next, and nothing is ever run. So there is one list, in this entry, and a later step that cannot run a browser **appends to it** rather than writing "D3 will cover it". Everything on it needs a human at a browser, opening `/dist/dev.html` over `python3 -m http.server` rooted at `apps/simplex-badge-service/web`, or the served site once D4 exists. Nothing in the plan may claim any of it is verified until someone reports having seen it.
|
||||
- From D1: that `dev.html` **loads at all** rather than rendering an empty shell; that `../styles.css` is **applied** and not merely served with a `text/css` header, for which the colour tokens are the visible proof; and that the browser **executes the module graph across files** — `main.js` importing `./ui.js`, and `ui.js` importing `./router.js` and `./view.js`, by the relative specifiers `tsc` does not rewrite. The third is what decision 7 and D4's single-prefix asset hash both rest on. A blank or unstyled page at this pass is as likely to be D1's mechanism as D2's markup, so confirm each separately. (D1's fourth deferral, that a `file://` open fails where HTTP succeeds, is still carried untested and nothing depends on it.)
|
||||
- From D2: a keyboard-only pass through every screen, reaching and activating **every** option and the Continue button, with browser back and forward landing on the right screen — the hash-to-screen mapping is unit-tested but `pushState`/`popstate` wiring is not; at 320 px in both colour schemes, that no screen scrolls horizontally; that the selected card's 2 px accent border is visible in both schemes; that the `:focus-visible` ring is visible against both backgrounds, **including the ring the visually hidden radio projects onto its card** — the one place where hiding an input could silently cost the focus indicator; that each scheme shows its own logo and hides the other; that the 150 ms fade runs, and does not under `prefers-reduced-motion: reduce`; and that submitting a question unanswered shows the error banner rather than a native validation bubble.
|
||||
- **D2 — the shell is four modules, not the two the Files list named, and there is now a `web/test/` directory.** The step named `src/{ui.ts,main.ts}`. Splitting out `router.ts` (the pure hash-to-screen mapping) and `view.ts` (each screen as a pure element tree, with no DOM call in it) is what makes the entry above a short list instead of the whole step: with the pure half separated, "every screen has exactly one `<h1>`", "every radio is inside a `<label>`" and "all six hashes resolve" are assertions a machine can run, and only *rendering* needs a human. `ui.ts` is the only module that touches the DOM and stays unasserted. The tests are `node:test` and `node:assert`, **built-in modules**, run by a new `npm test` script: nothing was added to `package.json`'s dependencies or to the lockfile, so decision 7's one-devDependency cap is intact. They import from `dist/`, not `src/`, so they assert on the bytes a browser is served. `test/css.mjs` is a 60-line reader for the stylesheet — a CSS parser is a dependency this project may not have, and grepping raw text cannot tell a declaration inside the dark media query from one outside it, which is the exact distinction the light-mode trap turns on. **Files** corrected; `package.json` added to it.
|
||||
- **D2 — the Verify line was a browser pass, which no CI and no agent environment can run; it is now a static suite that was proved able to fail.** Rule 4 requires the Verify line to be run before the step is ticked, so a line that cannot be run anywhere but on a human's screen makes the step unfalsifiable. The line now names the assertions listed in the step, and the browser half moved into the phase entry above. Being able to *fail* is the point: fourteen mutations were applied one at a time and the suite caught each — a colour token moved into the dark block only, the accent off by one digit, a screen's `<h1>` removed, a second `<h1>` added, `<fieldset>` replaced by `<div>`, the `<label>` wrapper removed, the `popstate` listener deleted, a hash dropped from the route set, a blanket `*:focus { outline: none }` added, the reduced-motion block removed, `max-width` moved off 560px, a token written into a CSS rule, a Google Fonts `@import` added, and a logo token dropped from `index.html`. A check nobody has watched fail is not a check.
|
||||
- **D2 — a radio's `change` may not navigate; each question needs a Continue button.** "One question per screen" reads like an invitation to advance as soon as an option is chosen, and that is inaccessible: arrow keys move the selection *within* a radio group, so a keyboard user pressing Down to hear the second option would be navigated away before reaching it, and every option after the first becomes unreachable — which is precisely what the step's own Verify line asks someone to confirm they can do. Each question therefore ends in a Continue button. Submitting one unanswered renders the error banner the step already requires for failed fetches, rather than a native `required` validation bubble, so there is one visible error surface on the site instead of two. D5's prefill skips a screen without any of this, since it never renders the question at all.
|
||||
- **D2 — the two logos differ in intrinsic height (34 and 35), and light/dark names the scheme, not the ink.** `logo-symbol-light.svg` is the one shown in *light* mode (dark blue ink, `#023789`) and `logo-symbol-dark.svg` in dark mode (white ink); `website/src/_includes/navbar.html:200-201` shows the same pairing, and getting it backwards yields an invisible logo rather than an error. Their `viewBox`es are `0 0 34 34` and `0 0 34 35`, so the CSS sets `height` and leaves `width: auto` rather than fixing both, and each `<img>` carries its own intrinsic `width`/`height` attributes to reserve the right box before the file loads.
|
||||
|
||||
## 10. End-to-end verification
|
||||
|
||||
|
||||
Reference in new issue
Block a user