Deploy implemented Videoreg interface and persistent theme cycle

This commit is contained in:
huncode committed 2026-10-27 15:49:46 +03:00
1 parent 6405a8d101
commit a12eefa1de
98 files changed
+4094 -2319

No files matched your search

@@ -0,0 +1,3 @@
// Explicit source-pinned gate: this design-only candidate MUST NOT activate the
// separately prepared/rejected analytics release. No environment/runtime override.
export const analytics = Object.freeze({ enabled: false, counterId: 109268682, webvisor: false, accurateTrackBounce: true, trackHash: false });
@@ -0,0 +1,88 @@
{
"palette": {
"surface-paper": "#eef3f6",
"surface-sheet": "#f9fbfc",
"text-primary": "#152d40",
"text-secondary": "#435f73",
"link": "#185d82",
"focus": "#a34200",
"border-control": "#56758c",
"border-subtle": "#c4d0d9",
"surface-note": "#fff0df",
"surface-inverse": "#112c43",
"text-inverse": "#ffffff",
"text-inverse-muted": "#d1dee7",
"accent-inverse": "#f3933d",
"text-note": "#703700",
"surface-subtle": "#e3ebf0",
"accent-hover": "#ffb36c",
"text-action": "#112c43"
},
"themes": {
"light": {
"surface-paper": "#eef3f6",
"surface-sheet": "#f9fbfc",
"text-primary": "#152d40",
"text-secondary": "#435f73",
"link": "#185d82",
"focus": "#a34200",
"border-control": "#56758c",
"border-subtle": "#c4d0d9",
"surface-note": "#fff0df",
"surface-inverse": "#112c43",
"text-inverse": "#ffffff",
"text-inverse-muted": "#d1dee7",
"accent-inverse": "#f3933d",
"text-note": "#703700",
"surface-subtle": "#e3ebf0",
"accent-hover": "#ffb36c",
"text-action": "#112c43"
},
"dark": {
"surface-paper": "#07131c",
"surface-sheet": "#102636",
"text-primary": "#e0ebf3",
"text-secondary": "#b1c5d4",
"link": "#86ccef",
"focus": "#ffbb77",
"border-control": "#7896aa",
"border-subtle": "#58758a",
"surface-note": "#382b1c",
"surface-inverse": "#0b2030",
"text-inverse": "#ffffff",
"text-inverse-muted": "#d1dee7",
"accent-inverse": "#f3933d",
"text-note": "#ffd2a0",
"surface-subtle": "#1a3548",
"accent-hover": "#ffb36c",
"text-action": "#112c43"
}
},
"typography": {
"bodyDesktop": "18px / 1.75 system sans",
"bodyMobile": "17px / 1.75 system sans",
"proseMeasure": "40rem",
"heading": "Arial, Helvetica, system sans",
"code": "ui-monospace, SFMono-Regular, Consolas, monospace"
},
"spacing": [
4,
8,
12,
16,
24,
32,
48,
64
],
"grid": {
"container": "1440px",
"reading": "640px",
"rail": "220px",
"gap": "48px",
"breakpoints": [
600,
900
]
}
}
+2
View File
@@ -0,0 +1,2 @@
export { analytics } from "./analytics";
export { default as designTokens } from "./design-tokens.json";
+1
View File
@@ -0,0 +1 @@
export { getThemeChoice, setThemeChoice, subscribeThemeChoice, themeChangeEvent, type ThemeChoice } from './theme';
@@ -0,0 +1,85 @@
import { readFileSync } from 'node:fs';
import { runInNewContext } from 'node:vm';
import { describe, expect, it } from 'vitest';
import { getThemeChoice, setThemeChoice } from './theme';
const script = readFileSync('web-front/public/theme.js', 'utf8');
function boot({ saved = null, dark = false, blocked = false, mediaAvailable = true, legacy = false }: {
saved?: string | null; dark?: boolean; blocked?: boolean; mediaAvailable?: boolean; legacy?: boolean;
} = {}) {
const values = new Map<string, string>();
if (saved !== null) values.set('videoreg-theme', saved);
const listeners: Record<string, ((event: any) => void)[]> = {};
const osListeners: (() => void)[] = [];
const storage = { getItem(key: string) { if (blocked) throw Error('blocked'); return values.get(key) ?? null; },
setItem(key: string, value: string) { if (blocked) throw Error('blocked'); values.set(key, value); } };
const root = { dataset: {} as Record<string, string>, style: {} as Record<string, string> };
const media = { matches: dark,
...(legacy ? { addListener: (fn: () => void) => osListeners.push(fn) }
: { addEventListener: (_: string, fn: () => void) => osListeners.push(fn) }) };
const window: any = {
addEventListener: (name: string, fn: (event: any) => void) => (listeners[name] ??= []).push(fn),
dispatchEvent: (event: any) => (listeners[event.type] ?? []).forEach(fn => fn(event)),
...(mediaAvailable ? { matchMedia: () => media } : {}),
};
let notifications = 0;
window.addEventListener('videoreg:theme-change', () => notifications++);
const context = { window, document: { documentElement: root }, localStorage: storage,
CustomEvent: class { constructor(public type: string) {} } };
runInNewContext(script, context);
return { root, values, storage, window, choice: () => window.videoregTheme.get(),
set: (choice: string) => window.videoregTheme.set(choice), notifications: () => notifications,
os: (dark: boolean) => { media.matches = dark; osListeners.forEach(fn => fn()); },
storageEvent: (key: string | null = 'videoreg-theme', storageArea: unknown = storage) => window.dispatchEvent({ type: 'storage', key, storageArea }) };
}
describe('blocking theme bootstrap contract', () => {
it('sets all first-paint attributes synchronously from persisted explicit choice', () => {
const app = boot({ saved: 'light', dark: true });
expect(app.root).toEqual({ dataset: { theme: 'light', themeChoice: 'light' }, style: { colorScheme: 'light' } });
expect(app.notifications()).toBe(1);
app.os(false); app.os(true);
expect(app.root.dataset.theme).toBe('light');
expect(app.notifications()).toBe(1);
});
it('follows live OS changes only in system mode, including legacy media listeners', () => {
const app = boot({ dark: true, legacy: true });
expect(app.choice()).toBe('system'); expect(app.root.dataset.theme).toBe('dark');
app.os(false); expect(app.root.dataset.theme).toBe('light');
app.set('dark'); app.os(false); expect(app.root.dataset.theme).toBe('dark');
app.set('system'); expect(app.root.dataset.theme).toBe('light');
app.os(true); expect(app.root.dataset.theme).toBe('dark');
});
it('persists every valid mode across a fresh page bootstrap and rejects invalid input', () => {
const app = boot();
for (const choice of ['light', 'dark', 'system']) {
app.set(choice);
expect(boot({ saved: app.values.get('videoreg-theme') }).choice()).toBe(choice);
}
app.set('invalid'); expect(app.choice()).toBe('system');
expect(app.values.get('videoreg-theme')).toBe('system');
});
it('handles missing/invalid/blocked storage and missing matchMedia without throwing', () => {
for (const saved of [null, '', 'sepia']) expect(boot({ saved, dark: true }).root.dataset.theme).toBe('dark');
const blocked = boot({ blocked: true, dark: true });
blocked.set('light'); expect(blocked.root.dataset.theme).toBe('light');
expect(blocked.choice()).toBe('light');
expect(boot({ mediaAvailable: false }).root.dataset.theme).toBe('light');
});
it('updates other consumers via events and follows same-origin storage updates and removal', () => {
const app = boot(); const before = app.notifications();
app.set('dark'); expect(app.notifications()).toBe(before + 1);
app.values.set('videoreg-theme', 'light'); app.storageEvent();
expect(app.choice()).toBe('light'); expect(app.root.dataset.theme).toBe('light');
app.values.delete('videoreg-theme'); app.storageEvent(null);
expect(app.choice()).toBe('system');
app.values.set('videoreg-theme', 'dark'); app.storageEvent('unrelated');
expect(app.choice()).toBe('system');
app.storageEvent('videoreg-theme', {}); expect(app.choice()).toBe('system');
app.storageEvent(); expect(app.choice()).toBe('dark');
});
it('keeps client API safe during server rendering', () => {
expect(getThemeChoice()).toBe('system');
expect(() => setThemeChoice('dark')).not.toThrow();
});
});
+22
View File
@@ -0,0 +1,22 @@
export type ThemeChoice = 'system' | 'light' | 'dark';
export const themeChangeEvent = 'videoreg:theme-change';
declare global {
interface Window {
videoregTheme?: { get(): ThemeChoice; set(choice: ThemeChoice): void };
}
}
export function getThemeChoice(): ThemeChoice {
return typeof window === 'undefined' ? 'system' : window.videoregTheme?.get() ?? 'system';
}
export function setThemeChoice(choice: ThemeChoice): void {
if (typeof window === 'undefined') return;
window.videoregTheme?.set(choice);
}
export function subscribeThemeChoice(onChange: () => void): () => void {
window.addEventListener(themeChangeEvent, onChange);
return () => window.removeEventListener(themeChangeEvent, onChange);
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,81 @@
:root {
color-scheme: light;
--color-surface-paper: #eef3f6;
--color-surface-sheet: #f9fbfc;
--color-text-primary: #152d40;
--color-text-secondary: #435f73;
--color-link: #185d82;
--color-focus: #a34200;
--color-border-control: #56758c;
--color-border-subtle: #c4d0d9;
--color-surface-note: #fff0df;
--color-surface-inverse: #112c43;
--color-text-inverse: #ffffff;
--color-text-inverse-muted: #d1dee7;
--color-accent-inverse: #f3933d;
--color-text-note: #703700;
--color-surface-subtle: #e3ebf0;
--color-accent-hover: #ffb36c;
--color-text-action: #112c43;
--space-4: 4px;
--space-8: 8px;
--space-12: 12px;
--space-16: 16px;
--space-24: 24px;
--space-32: 32px;
--space-48: 48px;
--space-64: 64px;
--font-sans: Arial, Helvetica, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
--font-serif: var(--font-sans);
--font-mono: ui-monospace, SFMono-Regular, Consolas, monospace;
--type-body: 18px;
--leading-body: 1.75;
--type-meta: 12px;
--type-code: 14px;
--type-h1: clamp(32px, 4.5vw, 60px);
--type-h2: clamp(25px, 3vw, 36px);
--measure-reading: 40rem;
--paper: var(--color-surface-paper); --sheet: var(--color-surface-sheet);
--ink: var(--color-text-primary); --muted: var(--color-text-secondary);
--rule: var(--color-border-subtle); --accent: var(--color-link);
--mono: var(--font-mono); --serif: var(--font-sans);
}
html[data-theme="dark"] { color-scheme: dark;
--color-surface-paper: #07131c;
--color-surface-sheet: #102636;
--color-text-primary: #e0ebf3;
--color-text-secondary: #b1c5d4;
--color-link: #86ccef;
--color-focus: #ffbb77;
--color-border-control: #7896aa;
--color-border-subtle: #58758a;
--color-surface-note: #382b1c;
--color-surface-inverse: #0b2030;
--color-text-inverse: #ffffff;
--color-text-inverse-muted: #d1dee7;
--color-accent-inverse: #f3933d;
--color-text-note: #ffd2a0;
--color-surface-subtle: #1a3548;
--color-accent-hover: #ffb36c;
--color-text-action: #112c43;
}
@media (prefers-color-scheme: dark) { html:not([data-theme]) { color-scheme: dark;
--color-surface-paper: #07131c;
--color-surface-sheet: #102636;
--color-text-primary: #e0ebf3;
--color-text-secondary: #b1c5d4;
--color-link: #86ccef;
--color-focus: #ffbb77;
--color-border-control: #7896aa;
--color-border-subtle: #58758a;
--color-surface-note: #382b1c;
--color-surface-inverse: #0b2030;
--color-text-inverse: #ffffff;
--color-text-inverse-muted: #d1dee7;
--color-accent-inverse: #f3933d;
--color-text-note: #ffd2a0;
--color-surface-subtle: #1a3548;
--color-accent-hover: #ffb36c;
--color-text-action: #112c43;
}}
@media (max-width: 600px) { :root { --type-body: 17px; } }
+37
View File
@@ -0,0 +1,37 @@
import type { AnchorHTMLAttributes, ButtonHTMLAttributes, InputHTMLAttributes, SelectHTMLAttributes, ReactNode } from "react";
const cls = (...values: (string | undefined | false)[]) => values.filter(Boolean).join(" ");
export function Button({ className, ...props }: ButtonHTMLAttributes<HTMLButtonElement>) {
return <button type="button" {...props} className={cls("ui-button", className)} />;
}
export function Input({ className, ...props }: InputHTMLAttributes<HTMLInputElement>) { return <input {...props} className={cls("ui-input", className)} />; }
export function Select({ className, ...props }: SelectHTMLAttributes<HTMLSelectElement>) { return <select {...props} className={cls("ui-select", className)} />; }
export function ActionLink({ className, ...props }: AnchorHTMLAttributes<HTMLAnchorElement>) { return <a {...props} className={cls("button", className)} />; }
export function Brand() {
return <a className="brand" href="/" aria-label="На главную — videoreg, библиотека систем СВК"><img className="brand-mark" src="/brand/mark.svg" alt="" aria-hidden="true" width="48" height="48" /><span className="brand-words"><strong>videoreg</strong><span className="brand-subtitle">Библиотека систем СВК</span></span></a>;
}
export function Field({ id, label, hint, error, children }: { id: string; label: string; hint?: string; error?: string; children: ReactNode }) {
return <div className={cls("field", !!error && "field-invalid")}><label htmlFor={id}>{label}</label>{children}{hint && <p id={id+"-hint"} className="field-hint">{hint}</p>}{error && <p id={id+"-error"} className="field-error">{error}</p>}</div>;
}
export function Notice({ children, className }: { children: ReactNode; className?: string }) {
return <aside className={cls("reading-note", className)}>{children}</aside>;
}
export function CodeBlock({ children, label = "Код или формула" }: { children: string; label?: string }) {
return <div className="code-block"><p className="scroll-hint">Длинную строку можно прокрутить по горизонтали.</p><pre tabIndex={0} role="region" aria-label={label}><code>{children}</code></pre></div>;
}
export function DataTable({ caption, head, rows }: { caption: string; head: string[]; rows: string[][] }) {
return <div className="table-block"><p className="scroll-hint">Таблицу можно прокручивать по горизонтали.</p><div className="table-region" tabIndex={0} role="region" aria-label={caption}><table><caption>{caption}</caption><thead><tr>{head.map(h => <th scope="col" key={h}>{h}</th>)}</tr></thead><tbody>{rows.map((row,i) => <tr key={i}>{row.map((value,j) => j === 0 ? <th scope="row" key={j}>{value}</th> : <td key={j}>{value}</td>)}</tr>)}</tbody></table></div></div>;
}
export function ResourceLink({ href, label, className }: { href: string; label: string; className?: string }) {
return <a className={cls("resource-link",className)} href={href} rel={href.startsWith("https://")?"noreferrer":undefined}>{label} ↗</a>;
}
export function ContentCard({ href, title, summary, eyebrow, variant="result", headingLevel="h2" }: { href:string; title:string; summary?:string; eyebrow?:ReactNode; variant?:"index"|"result"; headingLevel?:"h2"|"h3" }) {
const Heading=headingLevel;
return <a className={variant==="index"?"index-card":"result-card"} href={href}>{eyebrow&&<span className="search-kind">{eyebrow}</span>}<Heading>{title}</Heading>{summary&&<p>{summary}</p>}<span aria-hidden="true">↗</span></a>;
}
export function ImageFigure({ src, alt, caption, width, height, small = false, diagram = false, loading = "lazy", openLabel, className }: { src: string; alt: string; caption: string; width?: number; height?: number; small?: boolean; diagram?: boolean; loading?: "eager" | "lazy"; openLabel?: string; className?: string }) {
return <figure className={cls("content-figure", small && "small-figure", diagram && "diagram", className)}><a href={src} aria-label={openLabel ?? "Открыть изображение: " + alt}><img src={src} alt={alt} width={width} height={height} loading={loading} /></a><figcaption>{caption}</figcaption></figure>;
}
export function StateMessage({ title, children, actions, headingLevel = "h2", className }: { title: ReactNode; children?: ReactNode; actions?: ReactNode; headingLevel?: "h1" | "h2"; className?: string }) {
const Heading = headingLevel;
return <div className={cls("state-message", className)}><Heading>{title}</Heading>{children}{actions && <div className="state-actions">{actions}</div>}</div>;
}