Implement CHUNK #2: server layer, core schemas/adapters, contract tests, seed
Complete the server-backed storage layer for PubScript so the app can run against a real Fastify + SQLite backend instead of only local IndexedDB. Server (@pubscript/server): - db.ts: better-sqlite3 schema + migrations (users, shares, projects, books, chapters, entities, boards, ai_sessions, audit); WAL mode; idempotent admin bootstrap via PUBSCRIPT_ADMIN_EMAIL/PASSWORD. - auth.ts: argon2 hashing, JWT-ish session tokens, guards, auth routes. - routes.ts: REST CRUD for projects/books/chapters/entities/boards/ai_sessions with multi-tenant isolation and optimistic concurrency (baseRev). - ws.ts: Fastify websocket hub for autosave + presence events. - mapping.ts: row <-> core type conversion. Core (@pubscript/core): - Zod domain schemas (projects, books, chapters, entities, boards, ai_sessions) exported from index. - storage-local.ts (IndexedDB/Dexie) and storage-server.ts (REST) adapters implementing the StorageAdapter contract. Tests & tooling: - storage.contract.test.ts: parameterized over both adapters; wired as `pnpm contract` and added to CI. - seed.ts (`pnpm --filter server seed`): creates demo project "The Glass Harbor" — 3 chapters of prose, 4 linked characters, 1 world location, 6-node board. - Dockerfile + compose wiring for the server runtime. Acceptance: seed project opens with 3 chapters, 4 linked characters, 1 board.
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Theme engine — CSS-variable token map. See PLAN.md §4.7 and CHUNK #1 step 3.
|
||||
*
|
||||
* Four themes ship as token objects; `applyTheme(id)` sets
|
||||
* `document.documentElement.dataset.theme`. Accent color and density are
|
||||
* runtime overrides layered on top.
|
||||
*/
|
||||
|
||||
export type ThemeId = "ink" | "parchment" | "nocturne" | "terminal";
|
||||
|
||||
export const THEME_IDS: ThemeId[] = ["ink", "parchment", "nocturne", "terminal"];
|
||||
|
||||
export const THEME_LABELS: Record<ThemeId, string> = {
|
||||
ink: "Ink",
|
||||
parchment: "Parchment",
|
||||
nocturne: "Nocturne",
|
||||
terminal: "Terminal",
|
||||
};
|
||||
|
||||
export interface ThemeTokens {
|
||||
label: string;
|
||||
/** CSS custom properties applied to :root when this theme is active. */
|
||||
css: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* The four themes. Ink is the default (dark). Parchment is warm light,
|
||||
* Nocturne is deep indigo, Terminal is monochrome monospace.
|
||||
*/
|
||||
export const THEME_TOKENS: Record<ThemeId, ThemeTokens> = {
|
||||
ink: {
|
||||
label: "Ink",
|
||||
css: {
|
||||
"--ps-bg": "#0e0f13",
|
||||
"--ps-surface": "#17181f",
|
||||
"--ps-surface-2": "#20222c",
|
||||
"--ps-border": "#2a2d3a",
|
||||
"--ps-text": "#e6e8ee",
|
||||
"--ps-text-muted": "#9aa0b0",
|
||||
"--ps-accent": "#7c8bf5",
|
||||
"--ps-accent-contrast": "#0e0f13",
|
||||
"--ps-danger": "#f16d7a",
|
||||
"--ps-success": "#5fd08a",
|
||||
"--ps-warning": "#f0b754",
|
||||
},
|
||||
},
|
||||
parchment: {
|
||||
label: "Parchment",
|
||||
css: {
|
||||
"--ps-bg": "#f6f1e7",
|
||||
"--ps-surface": "#fffdf7",
|
||||
"--ps-surface-2": "#f2ead8",
|
||||
"--ps-border": "#e2d6bd",
|
||||
"--ps-text": "#2c2720",
|
||||
"--ps-text-muted": "#6f6656",
|
||||
"--ps-accent": "#b5793a",
|
||||
"--ps-accent-contrast": "#fffdf7",
|
||||
"--ps-danger": "#c0392b",
|
||||
"--ps-success": "#2e7d4f",
|
||||
"--ps-warning": "#b8860b",
|
||||
},
|
||||
},
|
||||
nocturne: {
|
||||
label: "Nocturne",
|
||||
css: {
|
||||
"--ps-bg": "#0c0b1e",
|
||||
"--ps-surface": "#171533",
|
||||
"--ps-surface-2": "#221f4a",
|
||||
"--ps-border": "#2e2a5e",
|
||||
"--ps-text": "#e8e6ff",
|
||||
"--ps-text-muted": "#a49fcf",
|
||||
"--ps-accent": "#9d7bff",
|
||||
"--ps-accent-contrast": "#0c0b1e",
|
||||
"--ps-danger": "#ff7b9c",
|
||||
"--ps-success": "#6ee7a8",
|
||||
"--ps-warning": "#ffd27b",
|
||||
},
|
||||
},
|
||||
terminal: {
|
||||
label: "Terminal",
|
||||
css: {
|
||||
"--ps-bg": "#05070a",
|
||||
"--ps-surface": "#0a0f14",
|
||||
"--ps-surface-2": "#0f1720",
|
||||
"--ps-border": "#16232e",
|
||||
"--ps-text": "#33ff9b",
|
||||
"--ps-text-muted": "#2c8a63",
|
||||
"--ps-accent": "#33ff9b",
|
||||
"--ps-accent-contrast": "#05070a",
|
||||
"--ps-danger": "#ff6b6b",
|
||||
"--ps-success": "#33ff9b",
|
||||
"--ps-warning": "#ffd93d",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/** The active theme id, persisted by the settings store. */
|
||||
let activeTheme: ThemeId = "ink";
|
||||
|
||||
/** Return the token map for a theme id (throws on unknown). */
|
||||
export function getThemeTokens(id: ThemeId): ThemeTokens {
|
||||
const t = THEME_TOKENS[id];
|
||||
if (!t) {
|
||||
throw new Error(`Unknown theme: ${id}`);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a theme by setting the data attribute and writing its CSS variables to
|
||||
* :root. Returns the applied id. Safe to call before the DOM exists (no-op).
|
||||
*/
|
||||
export function applyTheme(id: ThemeId): ThemeId {
|
||||
if (!THEME_TOKENS[id]) {
|
||||
throw new Error(`Unknown theme: ${id}`);
|
||||
}
|
||||
activeTheme = id;
|
||||
const root = typeof document !== "undefined" ? document.documentElement : undefined;
|
||||
if (root) {
|
||||
root.dataset.theme = id;
|
||||
const { css } = THEME_TOKENS[id]!;
|
||||
for (const [k, v] of Object.entries(css)) {
|
||||
root.style.setProperty(k, v);
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/** The currently active theme id. */
|
||||
export function getActiveTheme(): ThemeId {
|
||||
return activeTheme;
|
||||
}
|
||||
Reference in New Issue
Block a user