feat: give every Ekklesia screen one set of design tokens and elements

Modules have owned their own UI since ADR 0021, but the platform has never
said what that UI should look like. Every screen here — the Dashboard shell,
the display host, the module template — invented its own hex colours, font
stack, spacing, and radii, and they already disagreed. A module author had no
vocabulary for "the ordinary panel background", so the only available answer
was to invent one, and two modules would invent two.

Add `@ekklesia/design-tokens`: one validated, enumerable registry of semantic
tokens. A token declares a name, label, description, and default value; its
category and `--ekklesia-*` identifier are derived from the name, so it can
never claim one category while being named for another. Construction rejects
duplicates, malformed names, unknown categories, empty or overlong text, and
any value that is not a bounded literal — no declaration terminator, rule
block, comment, at-rule, `url(`, `!important`, escape, control character, or
markup. A registry that constructs can therefore be emitted as CSS without
escaping, because nothing needing escaping can be in it. That validation is
also what makes a future theme editor implementable rather than aspirational.

Add `@ekklesia/ui`: button, icon button, text input, select, checkbox, field
wrapper, panel, dialog, tabs, table and list primitives, badge, toast, and
empty/error/loading states — every value a token reference, with real
`:focus-visible` treatment and status that never depends on colour alone.
Deliberately small: an element earns its place when two consumers need it.

The stylesheet is a string rather than a `.css` file so the identical bytes
install into a document or an isolated artifact root, and so hover, disabled,
and focus-visible are real CSS rather than JavaScript approximations of them.

`pnpm boundaries` opens exactly two shared roles to modules, by name — every
other role stays rejected — and pins both design packages to the bottom of the
presentation stack. Both are browser-safe by construction, proven by a real
compile of module-shaped source in which `process.env` must fail to typecheck.

The shell installs the defaults at its document root for the Dashboard and the
display; custom properties inherit into module artifacts, so a module reads
`var(--ekklesia-…)` with nothing to import at run time and nothing for a host
to forget to pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
ekklesia
2026-08-27 06:59:44 -05:00
co-authored by Claude Opus 5
parent b14613decd
commit e03d38fcab
64 changed files with 3697 additions and 105 deletions
+72
View File
@@ -0,0 +1,72 @@
import { ekklesiaDesignTokenStylesheet } from "./registry.js";
/**
* The attribute that marks a token stylesheet this package installed. Used to make installation
* idempotent, and to let a host remove exactly what it added.
*/
export const DESIGN_TOKEN_STYLE_ATTRIBUTE = "data-ekklesia-design-tokens";
/**
* A root that can own a `<style>` element: a whole document, or one artifact's shadow root.
*
* Structural rather than nominal (`Document | ShadowRoot`) on purpose. This package must not
* reference DOM interfaces it does not need, and the two things a caller actually passes differ in
* everything except these three members.
*/
export interface DesignTokenStyleRoot {
querySelector(selectors: string): Element | null;
appendChild<Node_ extends Node>(node: Node_): Node_;
readonly ownerDocument?: Document | null;
}
function documentFor(root: DesignTokenStyleRoot): Document | undefined {
if (typeof (root as Partial<Document>).createElement === "function") {
return root as Document;
}
return root.ownerDocument ?? undefined;
}
/**
* Installs Ekklesia's default token values at a host root, once.
*
* Idempotent by construction: a second call finds the element it inserted the first time and
* updates nothing, so a re-render, a re-mount, or two independent callers can never leave two
* competing copies of the theme in one root.
*
* CSS custom properties **inherit through shadow boundaries**, so installing this at the document
* root is what makes the same tokens available inside every isolated module artifact without the
* artifact importing anything or the host reaching into it. A caller that genuinely owns an isolated
* root with no inheriting ancestor — a standalone display, a test — installs with `scope: "host"`
* into that root instead.
*
* Returns a function that removes exactly the element this call inserted, and nothing else; calling
* it twice is safe. Returns a no-op when the tokens were already present, so a caller can never
* uninstall a theme it did not install.
*/
export function installEkklesiaDesignTokens(
root: DesignTokenStyleRoot,
options: { readonly scope?: "root" | "host" } = {},
): () => void {
if (root.querySelector(`style[${DESIGN_TOKEN_STYLE_ATTRIBUTE}]`)) {
return () => undefined;
}
const ownerDocument = documentFor(root);
if (!ownerDocument) {
return () => undefined;
}
const style = ownerDocument.createElement("style");
style.setAttribute(DESIGN_TOKEN_STYLE_ATTRIBUTE, "");
style.textContent = ekklesiaDesignTokenStylesheet(options.scope ?? "root");
const target =
(ownerDocument === (root as unknown as Document) ? ownerDocument.head : undefined) ?? root;
target.appendChild(style);
let removed = false;
return () => {
if (removed) {
return;
}
removed = true;
style.remove();
};
}