@milesroxas/design-hub 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +1 -1
  2. package/core/catalog.test.ts +10 -1
  3. package/core/catalog.ts +11 -0
  4. package/core/cms.test.ts +103 -0
  5. package/core/cms.ts +178 -0
  6. package/core/export.test.ts +127 -0
  7. package/core/export.ts +120 -0
  8. package/core/formats.ts +60 -0
  9. package/core/project.test.ts +71 -0
  10. package/core/project.ts +147 -0
  11. package/dist/core/catalog.d.ts +5 -0
  12. package/dist/core/catalog.js +10 -0
  13. package/dist/core/cms.d.ts +40 -0
  14. package/dist/core/cms.js +141 -0
  15. package/dist/core/export.d.ts +52 -0
  16. package/dist/core/export.js +84 -0
  17. package/dist/core/formats.d.ts +90 -0
  18. package/dist/core/formats.js +39 -0
  19. package/dist/core/project.d.ts +56 -0
  20. package/dist/core/project.js +121 -0
  21. package/dist/scripts/bootstrap.d.ts +1 -1
  22. package/dist/scripts/bootstrap.js +38 -6
  23. package/dist/scripts/cli.js +8 -0
  24. package/dist/scripts/commands.js +8 -0
  25. package/dist/scripts/export.d.ts +42 -0
  26. package/dist/scripts/export.js +192 -0
  27. package/dist/scripts/fixtures-pull.d.ts +31 -19
  28. package/dist/scripts/fixtures-pull.js +102 -62
  29. package/dist/scripts/lib/cdp.d.ts +11 -0
  30. package/dist/scripts/lib/cdp.js +110 -0
  31. package/dist/scripts/lib/deploy.d.ts +76 -0
  32. package/dist/scripts/lib/deploy.js +94 -0
  33. package/dist/scripts/lib/vercel.d.ts +5 -0
  34. package/dist/scripts/lib/vercel.js +24 -0
  35. package/dist/scripts/new.d.ts +13 -1
  36. package/dist/scripts/new.js +43 -4
  37. package/dist/scripts/share.d.ts +63 -0
  38. package/dist/scripts/share.js +181 -0
  39. package/dist/scripts/signin.d.ts +31 -0
  40. package/dist/scripts/signin.js +119 -0
  41. package/dist/scripts/tracks.d.ts +40 -0
  42. package/dist/scripts/tracks.js +93 -0
  43. package/dist/server/paths.d.ts +2 -0
  44. package/dist/server/paths.js +2 -0
  45. package/dist/server/project.d.ts +7 -0
  46. package/dist/server/project.js +29 -0
  47. package/kit/Artboard.tsx +160 -0
  48. package/kit/artboard.css +47 -0
  49. package/kit/dials.tsx +2 -1
  50. package/package.json +1 -1
  51. package/shell/Index.tsx +49 -4
  52. package/shell/main.tsx +6 -2
  53. package/shell/shell.css +7 -3
  54. package/skills/miles-brand/SKILL.md +52 -0
  55. package/skills/miles-deploy/SKILL.md +26 -19
  56. package/skills/miles-design-hub/SKILL.md +77 -25
  57. package/skills/miles-get-hostile/SKILL.md +7 -5
  58. package/skills/miles-new-feature/SKILL.md +8 -7
  59. package/skills/miles-port/SKILL.md +14 -2
  60. package/skills/miles-port/references/emdash.md +43 -0
  61. package/skills/miles-port/references/payload.md +31 -0
  62. package/skills/miles-port/references/wordpress.md +31 -0
  63. package/skills/miles-prototype/SKILL.md +2 -2
  64. package/templates/app/README.md +1 -0
  65. package/templates/brand/README.md +48 -0
  66. package/templates/brand/index.tsx +16 -0
  67. package/templates/brand/styles.css +5 -0
  68. package/templates/site/README.md +42 -0
  69. package/templates/site/index.tsx +22 -0
  70. package/templates/site/styles.css +6 -0
  71. package/templates/space/README.md +1 -0
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+ /// <reference types="node" />
3
+ // Signing in to Vercel without a terminal. `vercel login` is a device sign-in:
4
+ // it prints a link, then waits until someone approves it in a browser. This
5
+ // starts it in the background and returns the link at once, so the agent sends
6
+ // it to the user as one click; `--wait` then blocks until the CLI is signed in.
7
+ import { spawn } from 'node:child_process';
8
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, writeFileSync } from 'node:fs';
9
+ import { homedir } from 'node:os';
10
+ import { dirname, join } from 'node:path';
11
+ import { ROOT } from '../server/paths.js';
12
+ import { CliError } from './lib/cli.js';
13
+ import { deviceLink } from './lib/deploy.js';
14
+ import { whoami } from './lib/vercel.js';
15
+ export const spec = {
16
+ name: 'signin',
17
+ summary: 'Sign the Vercel CLI in from a link the user clicks. Returns the link at once; --wait blocks until signed in.',
18
+ flags: {
19
+ wait: {
20
+ type: 'number',
21
+ description: 'Seconds to wait for the user to approve the link. Absent, return the link without waiting.',
22
+ },
23
+ },
24
+ output: '{ ok, signedIn, user? } or { ok, signedIn: false, url, code, next }',
25
+ };
26
+ // A device code lasts about fifteen minutes; reuse a pending one for less than that.
27
+ const PENDING_MS = 10 * 60_000;
28
+ const LINK_TIMEOUT_MS = 20_000;
29
+ function stateDir() {
30
+ const config = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
31
+ return join(config, 'design-hub');
32
+ }
33
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
34
+ function alive(pid) {
35
+ try {
36
+ process.kill(pid, 0);
37
+ return true;
38
+ }
39
+ catch {
40
+ return false;
41
+ }
42
+ }
43
+ function readPending(file) {
44
+ if (!existsSync(file))
45
+ return null;
46
+ try {
47
+ const p = JSON.parse(readFileSync(file, 'utf8'));
48
+ return Date.now() - p.at < PENDING_MS && alive(p.pid) ? p : null;
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ /** Starts `vercel login` detached, its output in a log, and reads the link back from the log. */
55
+ async function start() {
56
+ const dir = stateDir();
57
+ mkdirSync(dir, { recursive: true });
58
+ const log = join(dir, 'vercel-login.log');
59
+ const fd = openSync(log, 'w');
60
+ const child = spawn('vercel', ['login'], { cwd: ROOT, detached: true, stdio: ['ignore', fd, fd] });
61
+ closeSync(fd);
62
+ const failed = new Promise((resolve) => child.once('error', resolve));
63
+ child.unref();
64
+ const deadline = Date.now() + LINK_TIMEOUT_MS;
65
+ while (Date.now() < deadline) {
66
+ const error = await Promise.race([failed, sleep(250).then(() => null)]);
67
+ if (error)
68
+ throw new CliError('The Vercel CLI is not installed.', {
69
+ fix: 'npm i -g vercel, then run this again.',
70
+ });
71
+ const link = deviceLink(readFileSync(log, 'utf8'));
72
+ if (link)
73
+ return { pid: child.pid ?? 0, ...link, at: Date.now() };
74
+ if (child.exitCode !== null)
75
+ break;
76
+ }
77
+ throw new CliError('vercel login printed no sign-in link.', {
78
+ log: readFileSync(log, 'utf8').slice(-600),
79
+ fix: 'Ask the user to run `vercel login` in their terminal.',
80
+ });
81
+ }
82
+ async function waitFor(seconds) {
83
+ const deadline = Date.now() + seconds * 1000;
84
+ for (;;) {
85
+ const user = whoami(ROOT);
86
+ if (user || Date.now() >= deadline)
87
+ return user;
88
+ await sleep(2000);
89
+ }
90
+ }
91
+ export async function main({ flags }) {
92
+ const user = whoami(ROOT);
93
+ if (user)
94
+ return { signedIn: true, user };
95
+ const file = join(stateDir(), 'vercel-login.json');
96
+ let pending = readPending(file);
97
+ if (!pending) {
98
+ pending = await start();
99
+ mkdirSync(dirname(file), { recursive: true });
100
+ writeFileSync(file, `${JSON.stringify(pending)}\n`);
101
+ }
102
+ const link = { url: pending.url, code: pending.code };
103
+ if (flags.wait === undefined)
104
+ return {
105
+ signedIn: false,
106
+ ...link,
107
+ next: 'Send the user the url to approve in their browser, then run design-hub signin --wait 300.',
108
+ };
109
+ const after = await waitFor(flags.wait);
110
+ if (after)
111
+ return { signedIn: true, user: after };
112
+ return {
113
+ ok: false,
114
+ signedIn: false,
115
+ ...link,
116
+ error: `Not approved within ${flags.wait}s.`,
117
+ fix: 'Check the user opened the url and chose Allow; run design-hub signin --wait again.',
118
+ };
119
+ }
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ import { type Track } from '../core/project.ts';
3
+ import { type Args } from './lib/cli.ts';
4
+ export declare const spec: {
5
+ readonly name: 'tracks';
6
+ readonly summary: "Show or set the project's tracks (product, website, brand) and its website platform.";
7
+ readonly positionals: [{
8
+ readonly name: 'action';
9
+ readonly description: 'show (default): what project.json says. set: write it.';
10
+ }];
11
+ readonly flags: {
12
+ readonly track: {
13
+ readonly type: 'list';
14
+ readonly description: `For set: a track, repeated for several. One of: ${string}.`;
15
+ };
16
+ readonly platform: {
17
+ readonly type: 'string';
18
+ readonly choices: readonly ["webflow", "payload", "wordpress", "emdash"];
19
+ readonly description: 'For set, with the website track: where the site is built.';
20
+ };
21
+ readonly frontend: {
22
+ readonly type: 'string';
23
+ readonly choices: readonly ["astro", "next"];
24
+ readonly description: 'For set: the front end, for Payload or WordPress. Webflow takes none; EmDash is always Astro.';
25
+ };
26
+ readonly 'remove-samples': {
27
+ readonly type: 'boolean';
28
+ readonly description: 'For set: delete the sample prototype and walkthrough of every track not set. Setup only.';
29
+ };
30
+ };
31
+ readonly output: '{ ok, tracks, website?, file, removed?, warnings }';
32
+ };
33
+ /** Deletes the samples of the tracks a project does not keep; returns what went, relative to the project. */
34
+ export declare function removeSamples(keep: readonly Track[], prototypes?: string, docs?: string, root?: string): string[];
35
+ export declare function main(args: Args<typeof spec>): {
36
+ tracks: Track[];
37
+ website?: import("../core/project.ts").Website;
38
+ file: string;
39
+ warnings: string[];
40
+ };
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+ /// <reference types="node" />
3
+ // `design-hub tracks`: what kind of engagement the project is. `set` writes
4
+ // .design-hub/project.json (the tracks, and for a website its platform and
5
+ // front end); with --remove-samples it also drops the sample prototype and
6
+ // walkthrough of every track the project does not have, which is what setup
7
+ // wants and nothing later should do unasked.
8
+ import { existsSync, rmSync } from 'node:fs';
9
+ import { join, relative } from 'node:path';
10
+ import { FRONTENDS, makeProject, needsPlatform, PLATFORMS, samplesOutside, TRACKS, } from '../core/project.js';
11
+ import { DOCS, PROJECT_JSON, PROTOTYPES, ROOT } from '../server/paths.js';
12
+ import { readProject, writeProject } from '../server/project.js';
13
+ import { CliError } from './lib/cli.js';
14
+ export const spec = {
15
+ name: 'tracks',
16
+ summary: "Show or set the project's tracks (product, website, brand) and its website platform.",
17
+ positionals: [{ name: 'action', description: 'show (default): what project.json says. set: write it.' }],
18
+ flags: {
19
+ track: {
20
+ type: 'list',
21
+ description: `For set: a track, repeated for several. One of: ${TRACKS.join(', ')}.`,
22
+ },
23
+ platform: {
24
+ type: 'string',
25
+ choices: PLATFORMS,
26
+ description: 'For set, with the website track: where the site is built.',
27
+ },
28
+ frontend: {
29
+ type: 'string',
30
+ choices: FRONTENDS,
31
+ description: 'For set: the front end, for Payload or WordPress. Webflow takes none; EmDash is always Astro.',
32
+ },
33
+ 'remove-samples': {
34
+ type: 'boolean',
35
+ description: 'For set: delete the sample prototype and walkthrough of every track not set. Setup only.',
36
+ },
37
+ },
38
+ output: '{ ok, tracks, website?, file, removed?, warnings }',
39
+ };
40
+ /** Deletes the samples of the tracks a project does not keep; returns what went, relative to the project. */
41
+ export function removeSamples(keep, prototypes = PROTOTYPES, docs = DOCS, root = ROOT) {
42
+ const removed = [];
43
+ for (const { slug, feature } of samplesOutside(keep)) {
44
+ for (const dir of [join(prototypes, slug), join(docs, 'sprints', feature)]) {
45
+ if (!existsSync(dir))
46
+ continue;
47
+ rmSync(dir, { recursive: true, force: true });
48
+ removed.push(`${relative(root, dir)}/`);
49
+ }
50
+ }
51
+ return removed;
52
+ }
53
+ const warningsFor = (project) => needsPlatform(project)
54
+ ? ['The website track has no platform yet. Set it with --platform before porting: miles-port needs it.']
55
+ : [];
56
+ function show() {
57
+ const { project, problems } = readProject();
58
+ if (problems.length)
59
+ throw new CliError('project.json is invalid.', {
60
+ problems,
61
+ fix: 'Rewrite it with design-hub tracks set.',
62
+ });
63
+ if (!project)
64
+ return {
65
+ tracks: [],
66
+ file: relative(ROOT, PROJECT_JSON),
67
+ warnings: [
68
+ 'No tracks recorded: every track is allowed. Record them with design-hub tracks set --track <track>.',
69
+ ],
70
+ };
71
+ return { ...project, file: relative(ROOT, PROJECT_JSON), warnings: warningsFor(project) };
72
+ }
73
+ function set({ flags }) {
74
+ const made = makeProject(flags.track, { platform: flags.platform, frontend: flags.frontend });
75
+ if ('problems' in made)
76
+ throw new CliError(made.problems.join(' '), { fix: 'design-hub tracks --help lists the choices.' });
77
+ writeProject(made.project);
78
+ const removed = flags['remove-samples'] ? removeSamples(made.project.tracks) : undefined;
79
+ return {
80
+ ...made.project,
81
+ file: relative(ROOT, PROJECT_JSON),
82
+ ...(removed ? { removed } : {}),
83
+ warnings: warningsFor(made.project),
84
+ };
85
+ }
86
+ export function main(args) {
87
+ const [action = 'show'] = args.positionals;
88
+ if (action === 'show')
89
+ return show();
90
+ if (action === 'set')
91
+ return set(args);
92
+ throw new CliError(`Unknown action ${action}.`, { fix: 'Use show or set.' });
93
+ }
@@ -12,6 +12,8 @@ export declare const SKILLS: string;
12
12
  /** Local state, gitignored but for checks.json: the Jev log and its labels, the dev review store. */
13
13
  export declare const STATE_DIR: string;
14
14
  export declare const CHECKS_FILE: string;
15
+ /** The project's tracks and website platform (core/project.ts); committed, like checks.json. */
16
+ export declare const PROJECT_JSON: string;
15
17
  /** The nearest ancestor of `from` whose package.json names this package, so source and dist agree. */
16
18
  export declare function packageRoot(from: string): string;
17
19
  /** This package on disk, wherever it is installed: the shell, the kit, the templates, the skills. */
@@ -53,6 +53,8 @@ export const SKILLS = join(ROOT, '.claude', 'skills');
53
53
  /** Local state, gitignored but for checks.json: the Jev log and its labels, the dev review store. */
54
54
  export const STATE_DIR = join(ROOT, '.design-hub');
55
55
  export const CHECKS_FILE = join(STATE_DIR, 'checks.json');
56
+ /** The project's tracks and website platform (core/project.ts); committed, like checks.json. */
57
+ export const PROJECT_JSON = join(STATE_DIR, 'project.json');
56
58
  /** The nearest ancestor of `from` whose package.json names this package, so source and dist agree. */
57
59
  export function packageRoot(from) {
58
60
  let dir = dirname(from);
@@ -0,0 +1,7 @@
1
+ import { type Project } from '../core/project.ts';
2
+ export type LoadedProject = {
3
+ project: Project | null;
4
+ problems: string[];
5
+ };
6
+ export declare function readProject(file?: string): LoadedProject;
7
+ export declare function writeProject(project: Project, file?: string): void;
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ // .design-hub/project.json on disk: the project's tracks and website
3
+ // platform (core/project.ts has the rules). A project made before tracks
4
+ // existed has no file; every reader treats that as "any track", so nothing
5
+ // an older project does stops working.
6
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
7
+ import { dirname } from 'node:path';
8
+ import { parseProject } from '../core/project.js';
9
+ import { PROJECT_JSON } from './paths.js';
10
+ export function readProject(file = PROJECT_JSON) {
11
+ if (!existsSync(file))
12
+ return { project: null, problems: [] };
13
+ try {
14
+ const parsed = parseProject(JSON.parse(readFileSync(file, 'utf8')));
15
+ return 'project' in parsed
16
+ ? { project: parsed.project, problems: [] }
17
+ : { project: null, problems: parsed.problems };
18
+ }
19
+ catch (error) {
20
+ return {
21
+ project: null,
22
+ problems: [`${file}: ${error instanceof Error ? error.message : String(error)}`],
23
+ };
24
+ }
25
+ }
26
+ export function writeProject(project, file = PROJECT_JSON) {
27
+ mkdirSync(dirname(file), { recursive: true });
28
+ writeFileSync(file, `${JSON.stringify(project, null, 2)}\n`);
29
+ }
@@ -0,0 +1,160 @@
1
+ import {
2
+ createContext,
3
+ type ReactNode,
4
+ useContext,
5
+ useEffect,
6
+ useLayoutEffect,
7
+ useRef,
8
+ useState,
9
+ } from 'react';
10
+ import { FORMATS, type Format, type FormatName, sizeLabel, zoomFor } from '../core/formats.ts';
11
+ import { restoreDials, useDials } from './dials';
12
+ import { ViewTools } from './ViewTools';
13
+ import './artboard.css';
14
+
15
+ export { FORMAT_NAMES, FORMATS, type FormatName } from '../core/formats.ts';
16
+
17
+ const params = new URLSearchParams(location.search);
18
+ /** True when `design-hub export` opened the page: artboards only, at their real size, no tools. */
19
+ export const exporting = params.has('export');
20
+
21
+ type View = { zoom: string; guides: boolean; room: { width: number; height: number } };
22
+ const BoardView = createContext<View>({ zoom: '100%', guides: false, room: { width: 1e5, height: 1e5 } });
23
+
24
+ const ZOOMS = ['fit', '25%', '50%', '100%'];
25
+ const frames = (n: number) =>
26
+ new Promise<void>((resolve) => {
27
+ const step = (left: number) => (left ? requestAnimationFrame(() => step(left - 1)) : resolve());
28
+ step(n);
29
+ });
30
+
31
+ /** Applies the export's dial state, waits for fonts and images, then tells the exporter the page is ready. */
32
+ async function settleForExport() {
33
+ const dials = params.get('dials');
34
+ if (dials) restoreDials(JSON.parse(dials));
35
+ await document.fonts.ready;
36
+ await Promise.all([...document.images].map((img) => img.decode().catch(() => undefined)));
37
+ await frames(2);
38
+ document.documentElement.dataset.exportReady = '1';
39
+ }
40
+
41
+ /** The width the board has to draw in, and a height that keeps one artboard on screen. */
42
+ function useRoom() {
43
+ const ref = useRef<HTMLDivElement>(null);
44
+ const [room, setRoom] = useState({ width: 1e5, height: 1e5 });
45
+ useLayoutEffect(() => {
46
+ const el = ref.current;
47
+ if (!el || exporting) return;
48
+ const measure = () => setRoom({ width: el.clientWidth, height: Math.min(innerHeight * 0.6, 640) });
49
+ measure();
50
+ const observer = new ResizeObserver(measure);
51
+ observer.observe(el);
52
+ return () => observer.disconnect();
53
+ }, []);
54
+ return { ref, room };
55
+ }
56
+
57
+ type BoardProps = { title: string; lede?: ReactNode; children: ReactNode };
58
+
59
+ /**
60
+ * The canvas brand collateral sits on: every artboard side by side, scaled to
61
+ * fit, with its format and size under it. Under `design-hub export` it is
62
+ * the artboards alone, at their real size.
63
+ */
64
+ export function Board({ title, lede, children }: BoardProps) {
65
+ const view = useDials(
66
+ 'Board',
67
+ {
68
+ zoom: { type: 'select', options: ZOOMS, default: 'fit' },
69
+ guides: true,
70
+ },
71
+ {
72
+ hints: {
73
+ zoom: 'How large the artboards draw on screen. Export always writes them at their real size.',
74
+ guides: "Shade the bands a platform's own interface covers, where type and logos never go.",
75
+ },
76
+ },
77
+ );
78
+ const { ref, room } = useRoom();
79
+
80
+ useEffect(() => {
81
+ if (exporting) void settleForExport();
82
+ }, []);
83
+
84
+ if (exporting)
85
+ return (
86
+ <BoardView.Provider value={{ zoom: '100%', guides: false, room }}>
87
+ <div className="board-export">{children}</div>
88
+ </BoardView.Provider>
89
+ );
90
+
91
+ return (
92
+ <BoardView.Provider value={{ zoom: view.zoom as string, guides: view.guides as boolean, room }}>
93
+ <main className="board">
94
+ <header className="board-head">
95
+ <h1 className="board-title">{title}</h1>
96
+ {lede ? <p className="board-lede">{lede}</p> : null}
97
+ </header>
98
+ <div className="board-grid" ref={ref}>
99
+ {children}
100
+ </div>
101
+ <ViewTools />
102
+ </main>
103
+ </BoardView.Provider>
104
+ );
105
+ }
106
+
107
+ type ArtboardProps = {
108
+ format: FormatName;
109
+ /** Names the file on export (`<slug>-<name>.png`) and labels it on screen. */
110
+ name?: string;
111
+ children: ReactNode;
112
+ };
113
+
114
+ /**
115
+ * One piece of collateral at its real pixel size: type, spacing and images
116
+ * are drawn at the values that ship. On screen it scales with the Board's
117
+ * zoom; the content never knows.
118
+ */
119
+ /** The bands a platform's own interface covers, shaded on screen, never exported. */
120
+ function SafeBands({ format }: { format: FormatName }) {
121
+ const f: Format = FORMATS[format];
122
+ if (!f.safe) return null;
123
+ return (
124
+ <>
125
+ <div className="artboard-safe" style={{ top: 0, height: f.safe.top }} aria-hidden="true" />
126
+ <div className="artboard-safe" style={{ bottom: 0, height: f.safe.bottom }} aria-hidden="true" />
127
+ </>
128
+ );
129
+ }
130
+
131
+ export function Artboard({ format, name, children }: ArtboardProps) {
132
+ const { zoom, guides, room } = useContext(BoardView);
133
+ const f = FORMATS[format];
134
+ const scale = exporting ? 1 : zoomFor(zoom, format, room);
135
+ const frame = (
136
+ <div
137
+ className="artboard"
138
+ data-artboard=""
139
+ data-format={format}
140
+ data-name={name ?? ''}
141
+ data-output={f.output}
142
+ style={{ width: f.width, height: f.height, zoom: scale }}
143
+ >
144
+ {children}
145
+ {guides ? <SafeBands format={format} /> : null}
146
+ </div>
147
+ );
148
+ if (exporting) return frame;
149
+ return (
150
+ <figure className="artboard-slot">
151
+ {frame}
152
+ <figcaption className="artboard-label">
153
+ <span>{name ?? f.label}</span>
154
+ <span className="tabular">
155
+ {f.label} · {sizeLabel(format)}
156
+ </span>
157
+ </figcaption>
158
+ </figure>
159
+ );
160
+ }
@@ -0,0 +1,47 @@
1
+ /* The board: artboards side by side on a quiet canvas, each scaled with CSS
2
+ zoom so its content keeps its real pixel values. Under export, only the
3
+ artboards, stacked at 1:1, with motion off and one page per artboard. */
4
+ .board { min-height: 100vh; display: flex; flex-direction: column; gap: 32px; padding: 64px 32px 128px; background: var(--bg-secondary); }
5
+ .board-head { display: flex; flex-direction: column; gap: 4px; max-width: 65ch; }
6
+ .board-title { font-size: 18px; line-height: 28px; font-weight: 600; color: var(--text-primary); text-wrap: balance; }
7
+ .board-lede { color: var(--text-tertiary); text-wrap: pretty; }
8
+ .board-grid { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 40px; min-width: 0; }
9
+ .artboard-slot { display: flex; flex-direction: column; gap: 10px; margin: 0; min-width: 0; }
10
+ .artboard { position: relative; flex: none; overflow: hidden; background: var(--bg-primary); box-shadow: 0 0 0 1px rgb(16 24 40 / 0.08), 0 12px 32px -12px rgb(16 24 40 / 0.18); }
11
+ .artboard-label { display: flex; justify-content: space-between; gap: 16px; font-size: 12px; line-height: 18px; color: var(--text-tertiary); }
12
+ .artboard-label > span:first-child { color: var(--text-secondary); font-weight: 500; }
13
+ .artboard-safe { position: absolute; inset-inline: 0; pointer-events: none; background: repeating-linear-gradient(-45deg, rgb(240 68 56 / 0.14) 0 12px, rgb(240 68 56 / 0.06) 12px 24px); outline: 1px dashed rgb(240 68 56 / 0.5); outline-offset: -1px; }
14
+
15
+ @media (max-width: 720px) {
16
+ .board { padding: 32px 16px 128px; }
17
+ }
18
+
19
+ /* Export: the page is the artboards and nothing else. */
20
+ html[data-export] body { margin: 0; background: transparent; }
21
+ .board-export { display: flex; flex-direction: column; align-items: flex-start; width: max-content; }
22
+ .board-export .artboard { box-shadow: none; }
23
+ html[data-export] *, html[data-export] *::before, html[data-export] *::after { animation: none !important; transition: none !important; }
24
+
25
+ /* PDF: one page per artboard at the format's own size. The exporter prints
26
+ one format at a time, hiding the rest, because Chrome lays out one PDF at
27
+ a single width. */
28
+ @media print {
29
+ .board-export .artboard { break-after: page; }
30
+ .artboard[data-format="post-square"] { page: post-square; }
31
+ .artboard[data-format="post-portrait"] { page: post-portrait; }
32
+ .artboard[data-format="story"] { page: story; }
33
+ .artboard[data-format="link-preview"] { page: link-preview; }
34
+ .artboard[data-format="banner"] { page: banner; }
35
+ .artboard[data-format="slide"] { page: slide; }
36
+ .artboard[data-format="a4"] { page: a4; }
37
+ .artboard[data-format="letter"] { page: letter; }
38
+ }
39
+ @page { margin: 0; }
40
+ @page post-square { size: 1080px 1080px; margin: 0; }
41
+ @page post-portrait { size: 1080px 1350px; margin: 0; }
42
+ @page story { size: 1080px 1920px; margin: 0; }
43
+ @page link-preview { size: 1200px 630px; margin: 0; }
44
+ @page banner { size: 1584px 396px; margin: 0; }
45
+ @page slide { size: 1920px 1080px; margin: 0; }
46
+ @page a4 { size: 210mm 297mm; margin: 0; }
47
+ @page letter { size: 8.5in 11in; margin: 0; }
package/kit/dials.tsx CHANGED
@@ -35,7 +35,8 @@ export const setGuide = (href: string) => {
35
35
 
36
36
  // One DialRoot per page, in its own React root, however many panels register.
37
37
  export function ensureDialRoot() {
38
- if (mounted) return;
38
+ // `design-hub export` captures the prototype alone; the panel never mounts.
39
+ if (mounted || document.documentElement.dataset.export !== undefined) return;
39
40
  mounted = true;
40
41
  const host = document.createElement('div');
41
42
  host.dataset.harness = 'dials';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milesroxas/design-hub",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the password gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/shell/Index.tsx CHANGED
@@ -10,7 +10,9 @@ import {
10
10
  useRef,
11
11
  useState,
12
12
  } from 'react';
13
+ import { placeLabel } from '../core/catalog';
13
14
  import { featureTitle, guideHref } from '../core/feature';
15
+ import { TRACK_LABEL, TRACKS, type Track } from '../core/project';
14
16
  import { type Entry, entries, guides } from './registry';
15
17
  import './shell.css';
16
18
 
@@ -60,17 +62,34 @@ const groupsOf = (list: Entry[]): Group[] => {
60
62
  ].filter((g) => g.items.length || g.alternates.length || g.explorations.length);
61
63
  };
62
64
 
65
+ /** The track the index shows, remembered per browser. Only the tracks the prototypes use are offered; a stale choice shows all. */
66
+ function useTrackFilter() {
67
+ const [track, setTrack] = useStoredState<Track | 'all'>('index-track', 'all');
68
+ const tracks = TRACKS.filter((t) => entries.some((e) => e.track === t));
69
+ const inTrack = (e: Entry) => track === 'all' || !tracks.includes(track) || e.track === track;
70
+ return { filter: { tracks, value: track, onChange: setTrack }, inTrack };
71
+ }
72
+
73
+ const byQuery = (q: string) => (e: Entry) =>
74
+ !q || `${e.title} ${e.summary} ${e.slug}`.toLowerCase().includes(q);
75
+
76
+ /** The filter text and the track, and the entries they leave: the chosen track's, matching the text. */
77
+ function useIndexFilter() {
78
+ const [query, setQuery] = useState('');
79
+ const q = useDeferredValue(query.trim().toLowerCase());
80
+ const { filter, inTrack } = useTrackFilter();
81
+ return { query, setQuery, q, shown: entries.filter(inTrack).filter(byQuery(q)), trackFilter: filter };
82
+ }
83
+
63
84
  const RISE_CAP = 8;
64
85
  const rise = (i: number) => ({ '--i': Math.min(i, RISE_CAP) }) as CSSProperties;
65
86
 
66
87
  export function Index() {
67
- const [query, setQuery] = useState('');
88
+ const { query, setQuery, q, shown, trackFilter } = useIndexFilter();
68
89
  const [leaving, setLeaving] = useState<string | null>(null);
69
90
  const [opened, setOpened] = useStoredState<Record<string, boolean>>('index-explorations-open', {});
70
91
  const [instant, setInstant] = useState(false);
71
- const q = useDeferredValue(query.trim().toLowerCase());
72
92
  const main = useRef<HTMLElement>(null);
73
- const shown = entries.filter((e) => !q || `${e.title} ${e.summary} ${e.slug}`.toLowerCase().includes(q));
74
93
  const groups = groupsOf(shown);
75
94
  const archivedTotal = entries.filter((e) => e.status === 'archived').length;
76
95
 
@@ -136,6 +155,7 @@ export function Index() {
136
155
  High-fidelity sketches in code, made as we sprint on features and improve the product.
137
156
  </p>
138
157
  </header>
158
+ <TrackFilter {...trackFilter} />
139
159
  {entries.length > 6 ? (
140
160
  <label className="index-filter">
141
161
  <span className="sr-only">Filter prototypes</span>
@@ -286,10 +306,35 @@ function Explorations({
286
306
  );
287
307
  }
288
308
 
309
+ /** One button per track the project's prototypes use, plus All; shown only when there are two or more. */
310
+ function TrackFilter({
311
+ tracks,
312
+ value,
313
+ onChange,
314
+ }: {
315
+ tracks: Track[];
316
+ value: Track | 'all';
317
+ onChange: (t: Track | 'all') => void;
318
+ }) {
319
+ if (tracks.length < 2) return null;
320
+ const options: (Track | 'all')[] = ['all', ...tracks];
321
+ return (
322
+ <fieldset className="index-tracks">
323
+ <legend className="sr-only">Track</legend>
324
+ {options.map((t) => (
325
+ <button key={t} type="button" aria-pressed={value === t} onClick={() => onChange(t)}>
326
+ {t === 'all' ? 'All' : TRACK_LABEL[t]}
327
+ </button>
328
+ ))}
329
+ </fieldset>
330
+ );
331
+ }
332
+
289
333
  function EntryMeta({ entry, className }: { entry: Entry; className: string }) {
290
334
  return (
291
335
  <span className={className}>
292
- <span>{entry.context === 'app' ? 'App shell' : 'Space'}</span>
336
+ {entry.track ? <span>{TRACK_LABEL[entry.track]}</span> : null}
337
+ <span>{placeLabel(entry)}</span>
293
338
  <span className="index-status" data-status={entry.status}>
294
339
  {entry.status}
295
340
  </span>
package/shell/main.tsx CHANGED
@@ -11,6 +11,10 @@ import { Prototype } from './Prototype';
11
11
  import { findEntry, guides } from './registry';
12
12
 
13
13
  const params = new URLSearchParams(location.search);
14
+ // `design-hub export` opens a prototype with ?export: its artboards alone, no
15
+ // review panel, no dials, no accessibility overlay (kit/Artboard.tsx).
16
+ const exporting = params.has('export');
17
+ if (exporting) document.documentElement.dataset.export = '';
14
18
 
15
19
  // Lapse patches the clocks, so it lands before any prototype (and Motion) loads.
16
20
  // The module is empty unless the project installed @aiforui/lapse (vite/lapse.ts).
@@ -20,7 +24,7 @@ if (import.meta.env.DEV && params.has('lapse')) {
20
24
  else console.warn('[design-hub] ?lapse needs Lapse in the project: pnpm add -D @aiforui/lapse');
21
25
  }
22
26
 
23
- if (import.meta.env.DEV && params.get('a11y') !== '0') {
27
+ if (import.meta.env.DEV && !exporting && params.get('a11y') !== '0') {
24
28
  import('./a11y').then((m) => m.watchA11y());
25
29
  }
26
30
 
@@ -42,7 +46,7 @@ if (slug === 'guide') {
42
46
  const entry = findEntry(slug);
43
47
  if (entry?.feature && guides.has(entry.feature)) setGuide(guideHref(entry.feature));
44
48
  page = <Prototype slug={slug} entry={entry} />;
45
- if (entry) {
49
+ if (entry && !exporting) {
46
50
  const { mountReview } = await import('./review/mount');
47
51
  mountReview({ prototype: slug, feature: entry.feature, states: (entry.states ?? []).map((s) => s.name) });
48
52
  }