@milesroxas/design-hub 0.9.0 → 0.10.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.
package/kit/dials.tsx CHANGED
@@ -10,9 +10,21 @@ import {
10
10
  } from 'dialkit';
11
11
  import 'dialkit/styles.css';
12
12
  import './dials.css';
13
- import { type RefObject, useLayoutEffect } from 'react';
13
+ import { type RefObject, useEffect, useLayoutEffect, useState } from 'react';
14
14
  import { createRoot } from 'react-dom/client';
15
+ import {
16
+ type ControlAudience,
17
+ dialAudience,
18
+ dialId,
19
+ keepDials,
20
+ readConfig,
21
+ withDefaults,
22
+ } from '../core/controls.ts';
23
+ import { isStudioPerson, markControl, useControls } from './audience';
15
24
  import { type IconName, iconMarkup } from './Icon';
25
+ import { isClientView, setClientView } from './prefs';
26
+
27
+ export { client } from '../core/controls.ts';
16
28
 
17
29
  // What the panel calls itself. DialKit hard-codes its own name as the root
18
30
  // title; the prototypes say what the thing is instead.
@@ -45,17 +57,21 @@ export function ensureDialRoot() {
45
57
  // DialKit hides its panel in production builds unless told otherwise; the
46
58
  // deployed prototypes are for tuning, so the dials ship with them.
47
59
  createRoot(host).render(
48
- <DialRoot
49
- position={parked ? 'top-left' : 'top-right'}
50
- theme="dark"
51
- defaultOpen={open}
52
- productionEnabled
53
- />,
60
+ <>
61
+ <DialRoot
62
+ position={parked ? 'top-left' : 'top-right'}
63
+ theme="dark"
64
+ defaultOpen={open}
65
+ productionEnabled
66
+ />
67
+ <DialEyes />
68
+ </>,
54
69
  );
55
70
  // DialKit portals the panel to <body>; it appears once the first panel registers.
56
71
  const settle = (root: HTMLElement) => {
57
72
  retitle(root);
58
73
  placeLinks(root);
74
+ tagEmpty(root);
59
75
  new MutationObserver((records) => {
60
76
  for (const { type, target } of records) {
61
77
  // DialKit keeps the panel's scroll offset when it collapses, which pushes the trigger icon off-centre.
@@ -65,6 +81,7 @@ export function ensureDialRoot() {
65
81
  }
66
82
  retitle(root);
67
83
  placeLinks(root);
84
+ tagEmpty(root);
68
85
  }).observe(root, { subtree: true, childList: true, attributeFilter: ['data-collapsed'] });
69
86
  };
70
87
  const found = document.body.querySelector<HTMLElement>('.dialkit-root');
@@ -92,30 +109,65 @@ function retitle(root: HTMLElement) {
92
109
  if (title && title.textContent !== DIALS_TITLE) title.textContent = DIALS_TITLE;
93
110
  }
94
111
 
95
- type PanelLink = { key: string; href: string; label: string; icon: IconName; newTab?: boolean };
112
+ type PanelLink = {
113
+ key: string;
114
+ label: string;
115
+ icon: IconName;
116
+ href?: string;
117
+ newTab?: boolean;
118
+ /** A row that does something here instead of going somewhere. */
119
+ act?: () => void;
120
+ };
121
+
122
+ // Studio's way into Client view and back: the page as a client gets it, beside
123
+ // the dials it changes. The page loads again, so the comments, the dials and
124
+ // the prototype itself all start as a client's would.
125
+ function clientViewRow(): PanelLink {
126
+ const on = isClientView();
127
+ return {
128
+ key: 'client-view',
129
+ label: on ? 'Leave Client view' : 'Client view',
130
+ icon: 'briefcase-01',
131
+ act: () => {
132
+ setClientView(!on);
133
+ location.reload();
134
+ },
135
+ };
136
+ }
96
137
 
97
- // The panel's last rows, under every group: the hub's list of every prototype,
98
- // then the feature's walkthrough when it has one, which stays the very last.
138
+ // The panel's last rows, under every group: Client view for Studio, the hub's
139
+ // list of every prototype, then the feature's walkthrough when it has one,
140
+ // which stays the very last.
99
141
  function panelLinks(): PanelLink[] {
100
- const home: PanelLink = { key: 'home', href: '/', label: 'All prototypes', icon: 'grid-01' };
101
- if (!guide) return [home];
102
- return [
103
- home,
104
- { key: 'guide', href: guide, label: 'Open the walkthrough', icon: 'arrow-up-right', newTab: true },
105
- ];
142
+ const rows: PanelLink[] = isStudioPerson() ? [clientViewRow()] : [];
143
+ rows.push({ key: 'home', href: '/', label: 'All prototypes', icon: 'grid-01' });
144
+ if (guide)
145
+ rows.push({
146
+ key: 'guide',
147
+ href: guide,
148
+ label: 'Open the walkthrough',
149
+ icon: 'arrow-up-right',
150
+ newTab: true,
151
+ });
152
+ return rows;
106
153
  }
107
154
 
108
- function makeLink({ key, href, label, icon, newTab }: PanelLink) {
109
- const link = document.createElement('a');
110
- link.className = 'dial-link';
111
- link.dataset.dialLink = key;
112
- link.href = href;
113
- if (newTab) {
114
- link.target = '_blank';
115
- link.rel = 'noopener';
155
+ function makeLink({ key, href, label, icon, newTab, act }: PanelLink) {
156
+ const row = document.createElement(act ? 'button' : 'a');
157
+ row.className = 'dial-link';
158
+ row.dataset.dialLink = key;
159
+ if (row instanceof HTMLButtonElement) {
160
+ row.type = 'button';
161
+ row.addEventListener('click', () => act?.());
162
+ } else {
163
+ row.href = href ?? '/';
164
+ if (newTab) {
165
+ row.target = '_blank';
166
+ row.rel = 'noopener';
167
+ }
116
168
  }
117
- link.innerHTML = `<span>${label}</span>${iconMarkup(icon, 16)}`;
118
- return link;
169
+ row.innerHTML = `<span>${label}</span>${iconMarkup(icon, 16)}`;
170
+ return row;
119
171
  }
120
172
 
121
173
  // DialKit remounts the content on open and adds groups as panels register, so
@@ -125,7 +177,7 @@ function placeLinks(root: HTMLElement) {
125
177
  const content = root.querySelector('.dialkit-folder-root > .dialkit-folder-content');
126
178
  if (!content) return;
127
179
  const rows = panelLinks().map(
128
- (l) => content.querySelector<HTMLAnchorElement>(`:scope > [data-dial-link="${l.key}"]`) ?? makeLink(l),
180
+ (l) => content.querySelector<HTMLElement>(`:scope > [data-dial-link="${l.key}"]`) ?? makeLink(l),
129
181
  );
130
182
  const tail = Array.from(content.children).slice(-rows.length);
131
183
  if (rows.every((row, i) => tail[i] === row)) return;
@@ -183,7 +235,7 @@ const rowLabel = (row: HTMLElement) =>
183
235
  row.getAttribute('aria-label') ??
184
236
  (
185
237
  row.querySelector('.dialkit-labeled-control-label')?.firstChild ??
186
- row.querySelector('.dialkit-select-label') ??
238
+ row.querySelector('.dialkit-select-label, .dialkit-text-label, .dialkit-color-label') ??
187
239
  row
188
240
  ).textContent?.trim() ??
189
241
  '';
@@ -263,19 +315,204 @@ function installHints() {
263
315
  document.addEventListener('scroll', hide, true);
264
316
  }
265
317
 
266
- export function useDials<T extends DialConfig>(name: string, config: T, options?: DialOptions<T>) {
318
+ // Who a dial is for (core/controls.ts). Every dial is internal until marked
319
+ // client-facing: with `client(...)` where it is declared, or by Studio's eye
320
+ // beside its row, which is stored per site and overrules the code. Studio's
321
+ // panel has every dial. A Client's has only the client-facing ones: the others
322
+ // are never handed to DialKit, and code reads their defaults.
323
+
324
+ type Panel = {
325
+ /** Each dial's id by the label path its row shows, as the hints key theirs. */
326
+ byLabel: Record<string, string>;
327
+ inCode: Record<string, ControlAudience>;
328
+ /** Nothing in it for the person looking, so its header leaves the panel. */
329
+ empty: boolean;
330
+ };
331
+ const panels = new Map<string, Panel>();
332
+
333
+ function labelIds(
334
+ panel: string,
335
+ cfg: DialConfig,
336
+ into: Record<string, string>,
337
+ labels = '',
338
+ path: string[] = [],
339
+ ) {
340
+ for (const [k, v] of Object.entries(cfg)) {
341
+ if (k === '_collapsed') continue;
342
+ const label = labels + (actionLabel(v) ?? labelOf(k));
343
+ if (v && typeof v === 'object' && !Array.isArray(v) && !('type' in v))
344
+ labelIds(panel, v as DialConfig, into, label + PATH_SEP, [...path, k]);
345
+ else into[label] = dialId(panel, [...path, k]);
346
+ }
347
+ }
348
+
349
+ /**
350
+ * A panel's config as DialKit takes it (`all`), the part of it the person
351
+ * looking gets (`shown`), and DialKit's own options. Registers the hints too.
352
+ */
353
+ function usePanel<T extends DialConfig>(name: string, config: T, options?: DialOptions<T>) {
267
354
  useLayoutEffect(ensureDialRoot, []);
355
+ const { studio, marks } = useControls();
268
356
  const { hints: h, ...rest } = options ?? {};
269
- registerHints(name, config, h as Record<string, unknown> | undefined);
270
- return useDialKit(name, config, rest);
357
+ const { config: all, dials } = readConfig(name, config);
358
+ const inCode = Object.fromEntries(dials.map((d) => [d.id, d.inCode]));
359
+ const shown = studio
360
+ ? all
361
+ : keepDials(name, all, (id) => dialAudience(marks, id, inCode[id] ?? 'internal') === 'client');
362
+ const byLabel: Record<string, string> = {};
363
+ labelIds(name, all as DialConfig, byLabel);
364
+ panels.set(name, { byLabel, inCode, empty: Object.keys(shown).length === 0 });
365
+ registerHints(name, all as DialConfig, h as Record<string, unknown> | undefined);
366
+ /** What the prototype reads: DialKit's values, with the default of every dial it was not given. */
367
+ const read = (values: unknown) => (studio ? values : withDefaults(all, values as Record<string, unknown>));
368
+ return { shown: shown as T, rest, read };
369
+ }
370
+
371
+ // DialKit draws a header for a panel with no dials in it.
372
+ function tagEmpty(root: HTMLElement) {
373
+ for (const section of root.querySelectorAll<HTMLElement>('.dialkit-folder-section')) {
374
+ const title = section
375
+ .querySelector(':scope > .dialkit-folder-header .dialkit-folder-title')
376
+ ?.textContent?.trim();
377
+ const empty = !!title && !!panels.get(title)?.empty;
378
+ if (empty !== 'dialEmpty' in section.dataset) section.toggleAttribute('data-dial-empty', empty);
379
+ }
380
+ }
381
+
382
+ export function useDials<T extends DialConfig>(name: string, config: T, options?: DialOptions<T>) {
383
+ const { shown, rest, read } = usePanel(name, config, options);
384
+ return read(useDialKit(name, shown, rest)) as ReturnType<typeof useDialKit<T>>;
271
385
  }
272
386
 
273
387
  // The same panel with its controller, for dials that code also sets (every toggle at once).
274
388
  export function useDialsController<T extends DialConfig>(name: string, config: T, options?: DialOptions<T>) {
275
- useLayoutEffect(ensureDialRoot, []);
276
- const { hints: h, ...rest } = options ?? {};
277
- registerHints(name, config, h as Record<string, unknown> | undefined);
278
- return useDialKitController(name, config, rest);
389
+ const { shown, rest, read } = usePanel(name, config, options);
390
+ const controller = useDialKitController(name, shown, rest);
391
+ return { ...controller, values: read(controller.values) } as ReturnType<typeof useDialKitController<T>>;
392
+ }
393
+
394
+ // Studio's eye beside each dial: one click marks it client-facing or internal.
395
+ // DialKit has no slot in a row, so the row gives up 32px at its right end
396
+ // (kit/dials.css) and the eye is drawn over that slot, from outside the row:
397
+ // a click on it never reaches a slider's drag.
398
+
399
+ const EYE_ROWS =
400
+ '.dialkit-slider, .dialkit-labeled-control, .dialkit-select-row, .dialkit-text-control, .dialkit-color-control';
401
+ /** The panel's own sticky header, which a row scrolls under. */
402
+ const PANEL_HEAD = 48;
403
+
404
+ type Spot = { id: string; label: string; top: number; left: number };
405
+
406
+ function spotOf(row: HTMLElement, clip: DOMRect): Spot | null {
407
+ if (row.parentElement?.closest(EYE_ROWS)) return null;
408
+ const { path, panel } = rowPlace(row);
409
+ const label = rowLabel(row);
410
+ const id = panel ? panels.get(panel)?.byLabel[[...path, label].join(PATH_SEP)] : undefined;
411
+ if (!id) return null;
412
+ if (!('dialEye' in row.dataset)) row.dataset.dialEye = '';
413
+ const r = row.getBoundingClientRect();
414
+ const mid = r.top + r.height / 2;
415
+ if (r.height === 0 || mid < clip.top + PANEL_HEAD || mid > clip.bottom - 8) return null;
416
+ return { id, label, top: Math.round(mid), left: Math.round(r.right) };
417
+ }
418
+
419
+ function eyeSpots(): Spot[] {
420
+ const clip = document.querySelector('.dialkit-root .dialkit-panel-inner')?.getBoundingClientRect();
421
+ if (!clip) return [];
422
+ const rows = document.querySelectorAll<HTMLElement>(`.dialkit-root :is(${EYE_ROWS})`);
423
+ return [...rows].flatMap((row) => spotOf(row, clip) ?? []);
424
+ }
425
+
426
+ /** Where each eye sits, followed every frame while Studio can mark: the panel scrolls, folds and is dragged. */
427
+ function useEyeSpots(on: boolean) {
428
+ const [spots, setSpots] = useState<Spot[]>([]);
429
+ useEffect(() => {
430
+ if (!on) return setSpots([]);
431
+ document.documentElement.dataset.dialMarking = '';
432
+ let frame = 0;
433
+ let last = '';
434
+ const tick = () => {
435
+ const next = eyeSpots();
436
+ const sig = JSON.stringify(next);
437
+ if (sig !== last) setSpots(next);
438
+ last = sig;
439
+ frame = requestAnimationFrame(tick);
440
+ };
441
+ tick();
442
+ return () => {
443
+ cancelAnimationFrame(frame);
444
+ delete document.documentElement.dataset.dialMarking;
445
+ };
446
+ }, [on]);
447
+ return spots;
448
+ }
449
+
450
+ const EYE =
451
+ 'M2.4 12.7a1.2 1.2 0 0 1 0-1.4C3.5 9.6 6.7 5 12 5s8.5 4.6 9.6 6.3a1.2 1.2 0 0 1 0 1.4C20.5 14.4 17.3 19 12 19s-8.5-4.6-9.6-6.3Z';
452
+
453
+ function EyeIcon({ off }: { off: boolean }) {
454
+ return (
455
+ <svg
456
+ width="16"
457
+ height="16"
458
+ viewBox="0 0 24 24"
459
+ fill="none"
460
+ stroke="currentColor"
461
+ strokeWidth="2"
462
+ strokeLinecap="round"
463
+ strokeLinejoin="round"
464
+ aria-hidden="true"
465
+ >
466
+ <path d={EYE} />
467
+ <circle cx="12" cy="12" r="3" />
468
+ {off ? <path d="M4 4l16 16" /> : null}
469
+ </svg>
470
+ );
471
+ }
472
+
473
+ function inCodeOf(id: string): ControlAudience {
474
+ for (const p of panels.values()) if (id in p.inCode) return p.inCode[id];
475
+ return 'internal';
476
+ }
477
+
478
+ function DialEyes() {
479
+ const { studio, canMark, marks, failed } = useControls();
480
+ const spots = useEyeSpots(canMark);
481
+ // DialKit's own tools (Copy parameters, Save version) are Studio's: the panel shows them only under this mark.
482
+ useEffect(() => {
483
+ document.documentElement.toggleAttribute('data-dial-studio', studio);
484
+ }, [studio]);
485
+ if (!canMark) return null;
486
+ return (
487
+ <div data-harness="dial-eyes">
488
+ {spots.map((s) => {
489
+ const on = dialAudience(marks, s.id, inCodeOf(s.id)) === 'client';
490
+ return (
491
+ <button
492
+ key={s.id}
493
+ type="button"
494
+ className="dial-eye"
495
+ style={{ top: s.top, left: s.left }}
496
+ aria-pressed={on}
497
+ aria-label={`Client-facing: ${s.label}`}
498
+ title={
499
+ on
500
+ ? 'Clients get this dial. Click to keep it internal.'
501
+ : 'Internal. Click to give it to clients.'
502
+ }
503
+ onClick={() => void markControl('dial', s.id, on ? 'internal' : 'client')}
504
+ >
505
+ <EyeIcon off={!on} />
506
+ </button>
507
+ );
508
+ })}
509
+ {failed ? (
510
+ <p className="dial-eye-failed" role="alert">
511
+ {failed}
512
+ </p>
513
+ ) : null}
514
+ </div>
515
+ );
279
516
  }
280
517
 
281
518
  // Dial values as CSS variables on an element: `--key`, a folder's as `--folder-key`,
package/kit/harness.css CHANGED
@@ -97,3 +97,37 @@
97
97
  bottom: auto;
98
98
  top: 24px;
99
99
  }
100
+
101
+ /* Who a variant is for (kit/Variants.tsx). In Studio's picker a dot says a
102
+ client gets this one; the eye turns clicks into marks, and the note says so. */
103
+ .proto-picker-item { gap: 6px; }
104
+ .proto-picker-dot {
105
+ width: 6px;
106
+ height: 6px;
107
+ border-radius: 50%;
108
+ box-shadow: inset 0 0 0 1px oklch(1 0 0 / 0.35);
109
+ transition: background-color 120ms cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 120ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
110
+ }
111
+ [data-theirs] > .proto-picker-dot { background: oklch(0.72 0.17 150); box-shadow: none; }
112
+ .proto-picker-item[aria-pressed="false"] { color: oklch(1 0 0 / 0.45); }
113
+ .proto-picker-item[aria-pressed="true"] { color: oklch(1 0 0); }
114
+ .proto-picker-choose { padding: 0 10px; border-radius: 999px; }
115
+ .proto-picker-choose[aria-pressed="true"] { background: oklch(1 0 0 / 0.12); }
116
+ .proto-picker-note {
117
+ position: fixed;
118
+ left: 50%;
119
+ bottom: 72px;
120
+ z-index: 2147483647;
121
+ transform: translateX(-50%);
122
+ margin: 0;
123
+ padding: 4px 12px;
124
+ border-radius: 999px;
125
+ background: oklch(0.145 0 0 / 0.82);
126
+ -webkit-backdrop-filter: blur(12px) saturate(1.4);
127
+ backdrop-filter: blur(12px) saturate(1.4);
128
+ color: oklch(1 0 0 / 0.85);
129
+ font: 500 13px/20px var(--sys-font);
130
+ white-space: nowrap;
131
+ -webkit-font-smoothing: antialiased;
132
+ }
133
+ .proto-picker-note[data-position="top"] { bottom: auto; top: 72px; }
package/kit/prefs.ts CHANGED
@@ -22,6 +22,7 @@ const COMMENTS_KEY = 'proto:comments';
22
22
  const CLIENT_VIEW_KEY = 'proto:client-view';
23
23
 
24
24
  let appearance: Appearance = readAppearance();
25
+ let pinned: 'light' | 'dark' | null = null;
25
26
  let commentsHidden = readStored(COMMENTS_KEY) === 'hidden';
26
27
  let clientView = readStored(CLIENT_VIEW_KEY) === 'on';
27
28
  let forceReduce = false;
@@ -61,7 +62,8 @@ function subscribe(fn: () => void) {
61
62
  }
62
63
 
63
64
  function applyTheme() {
64
- const dark = appearance === 'dark' || (appearance === 'system' && darkQuery.matches);
65
+ const shown = pinned ?? appearance;
66
+ const dark = shown === 'dark' || (shown === 'system' && darkQuery.matches);
65
67
  // The browser chrome and native controls follow the app's theme, not the OS: the class decides.
66
68
  root.style.colorScheme = dark ? 'dark' : 'light';
67
69
  document.querySelector('meta[name="theme-color"]')?.setAttribute('content', dark ? '#0c0e12' : '#ffffff');
@@ -76,6 +78,24 @@ function applyMotion() {
76
78
  else delete root.dataset.motion;
77
79
  }
78
80
 
81
+ /**
82
+ * Holds the page to one look whatever the person's own theme is, without
83
+ * changing or storing that choice; null lets it go. A `Board` pins the look
84
+ * its files export in, so what is on screen is what `pnpm export` writes.
85
+ */
86
+ export function pinAppearance(next: 'light' | 'dark' | null) {
87
+ if (next === pinned) return;
88
+ pinned = next;
89
+ applyTheme();
90
+ emit();
91
+ }
92
+
93
+ /** The look `?theme=` asks for, when it names one: what an export of this page is written in. */
94
+ export const urlAppearance = (): 'light' | 'dark' | null => {
95
+ const asked = params.get('theme');
96
+ return asked === 'light' || asked === 'dark' ? asked : null;
97
+ };
98
+
79
99
  export function setAppearance(next: Appearance) {
80
100
  if (next === appearance) return;
81
101
  appearance = next;
@@ -117,6 +137,8 @@ export function setClientView(on: boolean) {
117
137
  export const isDark = () => root.classList.contains('dark-mode');
118
138
  export const prefersReducedMotion = () => root.dataset.motion === 'reduce';
119
139
 
140
+ /** Client view, for the controls that step aside in it (kit/audience.ts). */
141
+ export const useClientView = () => useSyncExternalStore(subscribe, isClientView);
120
142
  export const useAppearance = () => useSyncExternalStore(subscribe, () => appearance);
121
143
  export const useDark = () => useSyncExternalStore(subscribe, isDark);
122
144
  export const useReducedMotion = () => useSyncExternalStore(subscribe, prefersReducedMotion);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milesroxas/design-hub",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the sign-in 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": {
@@ -67,7 +67,7 @@
67
67
  "@vercel/functions": "^3.10.4",
68
68
  "@vitejs/plugin-react": "^6.1.2",
69
69
  "axe-core": "^4.14.0",
70
- "dialkit": "^2.1.0",
70
+ "dialkit": "^2.2.1",
71
71
  "marked": "^18.1.2",
72
72
  "motion": "^14.6.0",
73
73
  "postcss": "^8.5.32",
@@ -1,4 +1,6 @@
1
+ import { useControls } from '@kit/audience';
1
2
  import { Icon } from '@kit/Icon';
3
+ import { setClientView, useClientView } from '@kit/prefs';
2
4
  import { Button } from '@kit/ui';
3
5
  import './shell.css';
4
6
 
@@ -7,12 +9,38 @@ import './shell.css';
7
9
  * its words and look, with the one way back. On the index and on a
8
10
  * prototype's page that Client view shows as missing.
9
11
  */
10
- export function ClientViewNote({ onLeave }: { onLeave: () => void }) {
12
+ export function ClientViewNote({
13
+ onLeave,
14
+ text = 'Client view: prototypes as a client sees them',
15
+ at,
16
+ }: {
17
+ onLeave: () => void;
18
+ text?: string;
19
+ /** On a prototype's page the note sits at the top: the picker and the comment bar hold the bottom. */
20
+ at?: 'top';
21
+ }) {
11
22
  return (
12
- <p className="index-viewing sys" role="status">
23
+ <p className="index-viewing sys" role="status" data-at={at}>
13
24
  <Icon name="briefcase-01" size={14} />
14
- <span>Client view: prototypes as a client sees them</span>
25
+ <span>{text}</span>
15
26
  <Button kind="tertiary" size={null} className="index-viewing-act" label="Leave" onClick={onLeave} />
16
27
  </p>
17
28
  );
18
29
  }
30
+
31
+ /**
32
+ * On a prototype's page, for a Studio person in Client view: what the page
33
+ * is showing, and the way back. Client view is entered from the Controls
34
+ * panel or the comment bar; it is left from here, from either of them, or
35
+ * from the index.
36
+ */
37
+ export function PrototypeClientView() {
38
+ const { person } = useControls();
39
+ const on = useClientView();
40
+ if (!person || !on) return null;
41
+ const leave = () => {
42
+ setClientView(false);
43
+ location.reload();
44
+ };
45
+ return <ClientViewNote onLeave={leave} at="top" text="Client view: this prototype as a client gets it" />;
46
+ }
@@ -0,0 +1,26 @@
1
+ // A prototype page's one read of its controls, handed to the kit before the
2
+ // prototype renders (kit/audience.ts): the view the server gives this person
3
+ // and what Studio marked on the dials and variants. The page is the person's
4
+ // own view; Client view narrows it in the kit, with no second read.
5
+ import { setControls } from '@kit/audience';
6
+ import { type ControlAudience, type ControlKind, type Marks, NO_MARKS } from '../core/controls';
7
+ import type { PersonKind } from '../core/review/model';
8
+ import { call, noApi } from './review/client';
9
+
10
+ /** `design-hub export` captures the prototype as Studio tuned it: every dial, nothing to mark. */
11
+ export const exportControls = () => setControls({ studio: true, marks: NO_MARKS, save: null });
12
+
13
+ export async function loadControls(prototype: string) {
14
+ const save = (kind: ControlKind, id: string, audience: ControlAudience) =>
15
+ call('control.audience', { prototype, kind, id, audience });
16
+ try {
17
+ const { view, dials, variants } = await call<{ view: PersonKind } & Marks>('controls', undefined, {
18
+ prototype,
19
+ });
20
+ setControls({ studio: view === 'studio', marks: { dials, variants }, save });
21
+ } catch (error) {
22
+ // No review API at all (a local preview of the build) is Studio's view, as on the index, with nowhere to keep a mark.
23
+ // Any other failure leaves the narrowest view: a Client's, with nothing marked.
24
+ setControls({ studio: noApi(error), marks: NO_MARKS, save: null });
25
+ }
26
+ }
package/shell/main.tsx CHANGED
@@ -7,7 +7,8 @@ import { lazy, type ReactNode, StrictMode, Suspense } from 'react';
7
7
  import { createRoot } from 'react-dom/client';
8
8
  import { guideHref } from '../core/feature';
9
9
  import { hiddenFor } from './audience';
10
- import { ClientViewNote } from './ClientViewNote';
10
+ import { ClientViewNote, PrototypeClientView } from './ClientViewNote';
11
+ import { exportControls, loadControls } from './controls';
11
12
  import { readHub } from './hub';
12
13
  import { Index } from './Index';
13
14
  import { Notice } from './Notice';
@@ -77,9 +78,20 @@ if (slug === 'guide') {
77
78
  </Suspense>
78
79
  );
79
80
  } else if (slug) {
80
- const { entry, hidden } = await pageEntry(slug);
81
+ // The controls' audience is read beside the entry, so the first render already has it.
82
+ const [{ entry, hidden }] = await Promise.all([
83
+ pageEntry(slug),
84
+ exporting ? exportControls() : loadControls(slug),
85
+ ]);
81
86
  if (entry?.feature && guides.has(entry.feature)) setGuide(guideHref(entry.feature));
82
- page = hidden ? <HiddenInClientView name={slug} /> : <Prototype slug={slug} entry={entry} />;
87
+ page = hidden ? (
88
+ <HiddenInClientView name={slug} />
89
+ ) : (
90
+ <>
91
+ <Prototype slug={slug} entry={entry} />
92
+ {exporting ? null : <PrototypeClientView />}
93
+ </>
94
+ );
83
95
  if (entry && !exporting) {
84
96
  const { mountReview } = await import('./review/mount');
85
97
  mountReview({ prototype: slug, feature: entry.feature, states: (entry.states ?? []).map((s) => s.name) });
package/shell/shell.css CHANGED
@@ -154,6 +154,10 @@
154
154
  transition: opacity 200ms var(--ease-out), translate 200ms var(--ease-out);
155
155
  }
156
156
  @starting-style { .index-viewing { opacity: 0; translate: -50% 4px; } }
157
+ /* On a prototype's page: at the top, over the page, clear of the picker and the comment bar. */
158
+ .index-viewing[data-at="top"] { z-index: 2147483646; top: max(16px, env(safe-area-inset-top)); bottom: auto; }
159
+ /* The comment bar says the same while it is open: one note at a time. */
160
+ body:has(.rv-viewing) .index-viewing[data-at="top"] { display: none; }
157
161
  .index-viewing .icon { flex: none; color: var(--harness-fg-muted); }
158
162
  .index-viewing .btn.index-viewing-act { height: 28px; padding: 0 8px; }
159
163
 
@@ -21,6 +21,16 @@ A piece of collateral here is a template, not a picture: one component that hold
21
21
  - **Safe areas.** A story keeps type, buttons and the logo out of its top and bottom 250px; the Board shades them (Controls → Board → Guides). Other formats keep a margin of at least 64px at 1080 wide.
22
22
  - **One template, many formats.** Draw the content once as a component and place it in one `<Artboard>` per format, adjusting per format with `[data-format="story"] .x { … }` in CSS. Never a second copy of the markup per format.
23
23
 
24
+ ## Still, and one look
25
+
26
+ Collateral is a file: a PNG or a PDF. Nothing in it moves and it has no dark mode, so a board has no View panel. Its viewing tools are the Board's own **Zoom** and **Guides**.
27
+
28
+ - **No motion.** No `transition`, `animation`, `@keyframes` or `motion/react` in a brand prototype, and no reduce-motion or speed control. Export turns motion off, so anything that moves on the board is not what ships. The guard warns on it.
29
+ - **No theme.** A board is held to the look it exports in: light, whatever theme the person looking has. Never style collateral with `.dark-mode`, `prefers-color-scheme`, `useDark` or `useAppearance`, and never mount `ViewTools`. A dark or inverse version is a `tone` dial on the piece, so it is a state a reviewer can see and an export can name.
30
+ - **A piece that moves is not collateral here.** An animated story, a logo sting or a transition between slides is a `Space` prototype (`pnpm new <slug> --feature <feature>`), where View has the motion tools and nothing is exported. Say so to the user instead of animating an artboard.
31
+ - **A slide deck is stills.** One artboard per slide, no builds or slide transitions.
32
+ - **Collateral beside a product or a site.** A mock of a screen inside a post is drawn still, as a picture of that screen. It does not make the board a product prototype.
33
+
24
34
  ## Dials are the template's slots
25
35
 
26
36
  Every slot an editor will change is a dial or a fixture, never a hard-coded string:
@@ -30,7 +40,7 @@ Every slot an editor will change is a dial or a fixture, never a hard-coded stri
30
40
  | Copy (kicker, headline, subhead, call to action) | `fixtures.json`, one item per post; `text` names headline and subhead so `longest` stresses them |
31
41
  | Which post | A `post` select over the set |
32
42
  | Layout (photo, type only, quote) | A `layout` select; each option a state in the README |
33
- | Tone (brand, light, inverse) | A `tone` select |
43
+ | Tone (brand, light, inverse, dark) | A `tone` select. This is the only way a piece has a dark version: the board ignores the theme. |
34
44
 
35
45
  The README's States table lists every combination a reviewer must see: each fixture set, each layout, each tone. `empty` and `missing` are real states here too: a post with no image is the one that runs on a busy day.
36
46
 
@@ -89,6 +89,8 @@ A signed-in device stays signed in until the person's access ends: 3 months, 6 m
89
89
 
90
90
  Every prototype is **Internal** until a Studio person marks it **Client-facing** with the switch beside it on the deployed site's **Prototypes** page; only then can a Client open it or see it listed. No command reads or sets it: to check one, open the site's index signed in as Studio and look at its switch, or turn on **Client view** there to see the index as a client gets it. A switch flipped under `pnpm dev` writes the local store only; the deployed site has its own. A new prototype is internal, and so is every prototype on a site upgraded to the release that brought this: after that upgrade, tell the user once that clients see nothing until they switch on the prototypes the client should see. Before sending a handover, ask the user to check that the prototype it names is switched on. Walkthroughs and feature names reach every signed-in person whatever the switches say, so a walkthrough that describes internal work must wait.
91
91
 
92
+ Dials and variants follow the same rule from the release after that one. Every dial is internal until marked: a client's **Controls** panel has only the View tools (theme, reduce motion, speed), and each internal dial stays at its default. A client gets the first variant and no picker. Studio marks a dial with the eye beside its row in Controls, and variants with the eye at the end of the picker; both are kept per site, so marks made under `pnpm dev` do not reach the deployed one. After that upgrade, tell the user once that clients lose every dial and the picker until Studio marks what they should have, and that the brand board's Zoom and Guides stay theirs. Copy parameters and Save version are Studio's only. To check what a client gets, a Studio person presses **Client view** at the bottom of a prototype's Controls panel, or on the Prototypes page.
93
+
92
94
  The same upgrade changes what a build accepts and writes. Tell the user once, and when a build fails fix the file it names; never work around the check:
93
95
 
94
96
  - A stylesheet that does not parse (an unclosed block) fails `pnpm build` and stops `pnpm dev` (the page answers 500), naming file and line, where both worked before: every stylesheet is now read for reaches into a prototype's folder.