@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.
@@ -0,0 +1,174 @@
1
+ // Which of a prototype's controls a Client gets: its dials and its variants.
2
+ // Pure, so the server, the kit and the tests read one set of rules.
3
+ //
4
+ // A dial is internal until marked client-facing. It is marked in two places:
5
+ // in code, with `client(...)` around the dial where it is declared, which is
6
+ // where it starts; and in the hub, by Studio, which is stored per deployed
7
+ // site and overrules the code either way. A variant is marked only in the
8
+ // hub. The View tools are never asked about: they are always a Client's.
9
+ //
10
+ // The mark decides what a Client's panel draws and nothing else. A prototype's
11
+ // code is one file a Client's browser loads, so an internal dial's name, range
12
+ // and default are still in it; its value stays at the default.
13
+ export const CONTROL_KINDS = ['dial', 'variant'];
14
+ export const NO_MARKS = { dials: {}, variants: [] };
15
+ const MAX_ID = 200;
16
+ /** A dial's or a variant's name as the store keeps it: one line of text, trimmed, at most 200 characters. */
17
+ export const isControlId = (v) => typeof v === 'string' &&
18
+ v.length > 0 &&
19
+ v.length <= MAX_ID &&
20
+ v.trim() === v &&
21
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what is refused
22
+ !/[\u0000-\u001f\u007f]/.test(v);
23
+ /** A dial is named by its panel and its key, a folder's dial by the keys down to it: `Review/density`, `Card/shadow.blur`. */
24
+ export const dialId = (panel, path) => `${panel}/${path.join('.')}`;
25
+ /** The store's field for one control. */
26
+ export const controlField = (kind, id) => `${kind}:${id}`;
27
+ /** The marks in a prototype's stored fields. A field or a value that is not one of ours is left out, so it reads as unmarked. */
28
+ export function readMarks(fields) {
29
+ const dials = {};
30
+ const variants = [];
31
+ for (const [field, value] of Object.entries(fields)) {
32
+ const at = field.indexOf(':');
33
+ const [kind, id] = [field.slice(0, at), field.slice(at + 1)];
34
+ if (!isControlId(id))
35
+ continue;
36
+ if (kind === 'dial' && (value === 'client' || value === 'internal'))
37
+ dials[id] = value;
38
+ if (kind === 'variant' && value === 'client')
39
+ variants.push(id);
40
+ }
41
+ return { dials, variants: variants.sort() };
42
+ }
43
+ /** The marks after one control is switched. */
44
+ export function withMark(marks, kind, id, audience) {
45
+ if (kind === 'dial')
46
+ return { ...marks, dials: { ...marks.dials, [id]: audience } };
47
+ const rest = marks.variants.filter((v) => v !== id);
48
+ return { ...marks, variants: audience === 'client' ? [...rest, id].sort() : rest };
49
+ }
50
+ /** Who a dial is for: the hub's mark when Studio set one, else what the code says, else internal. */
51
+ export const dialAudience = (marks, id, inCode) => marks.dials[id] ?? inCode;
52
+ /**
53
+ * The variants a Client gets, in the order the prototype declares them. One
54
+ * is no picker. None marked is still one: the first, so a page is never empty.
55
+ */
56
+ export function clientVariants(names, marks) {
57
+ const kept = names.filter((n) => marks.variants.includes(n));
58
+ return kept.length ? kept : names.slice(0, 1);
59
+ }
60
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
61
+ const isMarked = (v) => isRecord(v) && '__client' in v;
62
+ const isFolder = (v) => isRecord(v) && !('type' in v);
63
+ /** DialKit's own key for a folder that starts closed: not a dial. */
64
+ const SETTING = '_collapsed';
65
+ /**
66
+ * Marks a dial client-facing where it is declared, or a folder and every dial
67
+ * in it. Typed as the dial itself, so the values a prototype reads keep their types.
68
+ */
69
+ export const client = (dial) => ({ __client: dial });
70
+ /** A config as DialKit takes it (every `client()` unwrapped) and the dials in it. */
71
+ export function readConfig(panel, config) {
72
+ const dials = [];
73
+ const walk = (node, path, inherited) => {
74
+ const out = {};
75
+ for (const [key, raw] of Object.entries(node)) {
76
+ if (key === SETTING) {
77
+ out[key] = raw;
78
+ continue;
79
+ }
80
+ const inCode = isMarked(raw) ? 'client' : inherited;
81
+ const value = isMarked(raw) ? raw.__client : raw;
82
+ const at = [...path, key];
83
+ if (isFolder(value))
84
+ out[key] = walk(value, at, inCode);
85
+ else {
86
+ out[key] = value;
87
+ dials.push({ id: dialId(panel, at), path: at, inCode });
88
+ }
89
+ }
90
+ return out;
91
+ };
92
+ return { config: walk(config, [], 'internal'), dials };
93
+ }
94
+ /** The part of an unwrapped config whose dials `shown` keeps. A folder with none left goes with them. */
95
+ export function keepDials(panel, config, shown) {
96
+ const walk = (node, path) => {
97
+ const out = {};
98
+ for (const [key, value] of Object.entries(node)) {
99
+ if (key === SETTING)
100
+ continue;
101
+ const at = [...path, key];
102
+ if (isFolder(value)) {
103
+ const inner = walk(value, at);
104
+ if (Object.keys(inner).length)
105
+ out[key] = SETTING in value ? { ...inner, [SETTING]: value[SETTING] } : inner;
106
+ }
107
+ else if (shown(dialId(panel, at)))
108
+ out[key] = value;
109
+ }
110
+ return out;
111
+ };
112
+ return walk(config, []);
113
+ }
114
+ const finite = (v) => typeof v === 'number' && Number.isFinite(v);
115
+ const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
116
+ /** A slider's starting value: its first number, kept inside a range that is given. */
117
+ function sliderDefault(value) {
118
+ const seed = finite(value[0]) ? value[0] : 0;
119
+ if (!finite(value[1]) || !finite(value[2]))
120
+ return seed;
121
+ const [min, max] = value[1] <= value[2] ? [value[1], value[2]] : [value[2], value[1]];
122
+ return clamp(seed, min, min === max ? min + 1 : max);
123
+ }
124
+ const firstOption = (options) => {
125
+ const first = Array.isArray(options) ? options[0] : undefined;
126
+ if (first === undefined)
127
+ return '';
128
+ return typeof first === 'string' ? first : first.value;
129
+ };
130
+ /** One axis of a pad: `[default, min, max, step?]`, the default snapped to the step as DialKit snaps it. */
131
+ function padAxis(axis) {
132
+ const [initial, min, max, given] = (Array.isArray(axis) ? axis : [0, -1, 1, 0.01]);
133
+ const step = given ?? (max - min) / 200;
134
+ const at = clamp(initial, min, max);
135
+ if (at === min || at === max)
136
+ return at;
137
+ return clamp(Number((min + Math.round((at - min) / step) * step).toPrecision(12)), min, max);
138
+ }
139
+ /** By `type`: what DialKit starts each kind of dial at when its config names no default. */
140
+ const TYPED = {
141
+ select: (v) => v.default ?? firstOption(v.options),
142
+ color: (v) => v.default ?? '#000000',
143
+ image: (v) => v.default ?? firstOption(v.options ?? []),
144
+ text: (v) => v.default ?? '',
145
+ pad: (v) => ({ x: padAxis(v.x), y: padAxis(v.y) }),
146
+ };
147
+ /**
148
+ * What a dial reads when nobody can move it: the value DialKit would start it
149
+ * at. A test holds this equal to DialKit's own for every kind of dial.
150
+ */
151
+ export function defaultOf(dial) {
152
+ if (Array.isArray(dial))
153
+ return sliderDefault(dial);
154
+ if (!isRecord(dial) || typeof dial.type !== 'string')
155
+ return dial;
156
+ const typed = TYPED[dial.type];
157
+ return typed ? typed(dial) : dial;
158
+ }
159
+ /**
160
+ * The values a prototype reads: DialKit's for the dials it drew, the default
161
+ * for every dial it did not, in the shape of the whole config.
162
+ */
163
+ export function withDefaults(config, values) {
164
+ const out = {};
165
+ for (const [key, dial] of Object.entries(config)) {
166
+ if (key === SETTING)
167
+ continue;
168
+ if (isFolder(dial))
169
+ out[key] = withDefaults(dial, isRecord(values[key]) ? values[key] : {});
170
+ else
171
+ out[key] = key in values ? values[key] : defaultOf(dial);
172
+ }
173
+ return out;
174
+ }
@@ -1,3 +1,4 @@
1
+ import { type ControlKind } from '../controls.ts';
1
2
  /** Which side a person is on: the studio that makes the work, or the client it is for. */
2
3
  export declare const PERSON_KINDS: readonly ['studio', 'client'];
3
4
  export type PersonKind = (typeof PERSON_KINDS)[number];
@@ -142,6 +143,16 @@ export declare function checkPersonInput(input: unknown): Checked<PersonInput>;
142
143
  export declare function checkAudience(input: unknown): Checked<Audience | null>;
143
144
  /** A prototype's audience as Studio sets it: one of AUDIENCES, required. */
144
145
  export declare function checkPrototypeAudience(input: unknown): Checked<Audience>;
146
+ /** One control's mark as Studio sets it: which kind, its id, and who it is for. */
147
+ export declare function checkControl(input: {
148
+ kind: unknown;
149
+ id: unknown;
150
+ audience: unknown;
151
+ }): Checked<{
152
+ kind: ControlKind;
153
+ id: string;
154
+ audience: Audience;
155
+ }>;
145
156
  /** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
146
157
  export declare function checkViewAs(input: unknown): Checked<PersonKind | null>;
147
158
  export declare function checkBody(body: unknown): Checked<string>;
@@ -3,6 +3,7 @@
3
3
  // Pure: no I/O, no environment. Every limit and rule lives here once and is
4
4
  // enforced by the service, whichever adapter (Vercel, Vite dev, the CLI)
5
5
  // calls it.
6
+ import { CONTROL_KINDS, isControlId } from '../controls.js';
6
7
  import { SLUG } from '../feature.js';
7
8
  /** Which side a person is on: the studio that makes the work, or the client it is for. */
8
9
  export const PERSON_KINDS = ['studio', 'client'];
@@ -146,6 +147,26 @@ export function checkPrototypeAudience(input) {
146
147
  ? { ok: true, value: input }
147
148
  : { ok: false, problems: [`audience: one of ${AUDIENCES.join(', ')}`] };
148
149
  }
150
+ /** One control's mark as Studio sets it: which kind, its id, and who it is for. */
151
+ export function checkControl(input) {
152
+ const problems = [];
153
+ if (!CONTROL_KINDS.includes(input.kind))
154
+ problems.push(`kind: one of ${CONTROL_KINDS.join(', ')}`);
155
+ if (!isControlId(input.id))
156
+ problems.push('id: the control’s name, one line of at most 200 characters');
157
+ if (!AUDIENCES.includes(input.audience))
158
+ problems.push(`audience: one of ${AUDIENCES.join(', ')}`);
159
+ return problems.length
160
+ ? { ok: false, problems }
161
+ : {
162
+ ok: true,
163
+ value: {
164
+ kind: input.kind,
165
+ id: input.id,
166
+ audience: input.audience,
167
+ },
168
+ };
169
+ }
149
170
  /** Whose view of the comments is asked for: a person kind, or null for the caller's own. */
150
171
  export function checkViewAs(input) {
151
172
  if (input === undefined || input === null)
@@ -1,3 +1,4 @@
1
+ import { type ControlKind, type Marks } from '../controls.ts';
1
2
  import { type Access, type Audience, type Comment, type Person, type PersonKind, type Triage } from './model.ts';
2
3
  import { type KV } from './store.ts';
3
4
  export type ErrorCode = 'unauthorized' | 'forbidden' | 'not_found' | 'invalid';
@@ -104,6 +105,32 @@ export declare function createReview(kv: KV, overrides?: Partial<Deps>): {
104
105
  * internal. Studio only.
105
106
  */
106
107
  setAudience(actor: Person | null, prototype: unknown, audience: unknown): Promise<Audience>;
108
+ /**
109
+ * What Studio marked on a prototype's dials and variants, with the view
110
+ * the actor gets. A Client reads the marks too: their page needs a dial
111
+ * Studio switched back to internal as much as one it shared, and the
112
+ * names are in the prototype's own code already. An internal prototype
113
+ * has none for a Client, as it has no comments.
114
+ */
115
+ controlsOf(actor: Person | null, prototype: unknown): Promise<{
116
+ view: PersonKind;
117
+ } & Marks>;
118
+ /**
119
+ * Marks one dial or one variant client-facing or internal. A dial's mark
120
+ * is stored either way, because it overrules what the code says; a
121
+ * variant's internal is the field's absence. Studio only. The server
122
+ * keeps no list of a prototype's controls, so any well-formed id is taken.
123
+ */
124
+ setControl(actor: Person | null, input: {
125
+ prototype: unknown;
126
+ kind: unknown;
127
+ id: unknown;
128
+ audience: unknown;
129
+ }): Promise<{
130
+ kind: ControlKind;
131
+ id: string;
132
+ audience: Audience;
133
+ }>;
107
134
  /**
108
135
  * Who a prototype is for, asked by the gate with no actor. Absent, or any
109
136
  * value but `client`, is internal; a name that cannot be a prototype is
@@ -5,8 +5,9 @@
5
5
  // person, per comment), so two people commenting at once never collide;
6
6
  // two edits of the same comment at once keep the last.
7
7
  import { base64url, hex, sha256 } from '../bytes.js';
8
+ import { controlField, readMarks } from '../controls.js';
8
9
  import { isPrototypeSlug } from '../prototype.js';
9
- import { accessEnd, authorOf, checkAccess, checkAnchor, checkAudience, checkBody, checkPersonInput, checkPrototypeAudience, checkStates, checkTriage, checkViewAs, DEFAULT_ACCESS, hasAccess, isProfile, isRoot, LINK_DAYS, readComment, } from './model.js';
10
+ import { accessEnd, authorOf, checkAccess, checkAnchor, checkAudience, checkBody, checkControl, checkPersonInput, checkPrototypeAudience, checkStates, checkTriage, checkViewAs, DEFAULT_ACCESS, hasAccess, isProfile, isRoot, LINK_DAYS, readComment, } from './model.js';
10
11
  import { audienceFor, can, viewOf, visibleTo } from './policy.js';
11
12
  import { KEY } from './store.js';
12
13
  export class ReviewError extends Error {
@@ -442,6 +443,40 @@ export function createReview(kv, overrides = {}) {
442
443
  await kv.hdel(KEY.audiences, slug);
443
444
  return value;
444
445
  },
446
+ /**
447
+ * What Studio marked on a prototype's dials and variants, with the view
448
+ * the actor gets. A Client reads the marks too: their page needs a dial
449
+ * Studio switched back to internal as much as one it shared, and the
450
+ * names are in the prototype's own code already. An internal prototype
451
+ * has none for a Client, as it has no comments.
452
+ */
453
+ async controlsOf(actor, prototype) {
454
+ allow(actor, 'read');
455
+ if (!isPrototypeSlug(prototype))
456
+ throw new ReviewError('invalid', 'Some fields are not valid.', ['prototype: a prototype slug']);
457
+ const view = viewOf(actor);
458
+ if (!(await reachable(view, prototype)))
459
+ throw new ReviewError('not_found', 'No such prototype.');
460
+ return { view, ...readMarks(await kv.hgetall(KEY.controls(prototype))) };
461
+ },
462
+ /**
463
+ * Marks one dial or one variant client-facing or internal. A dial's mark
464
+ * is stored either way, because it overrules what the code says; a
465
+ * variant's internal is the field's absence. Studio only. The server
466
+ * keeps no list of a prototype's controls, so any well-formed id is taken.
467
+ */
468
+ async setControl(actor, input) {
469
+ allow(actor, 'audience');
470
+ const [slug, mark] = validAll(isPrototypeSlug(input.prototype)
471
+ ? { ok: true, value: input.prototype }
472
+ : { ok: false, problems: ['prototype: a prototype slug'] }, checkControl(input));
473
+ const field = controlField(mark.kind, mark.id);
474
+ if (mark.kind === 'variant' && mark.audience === 'internal')
475
+ await kv.hdel(KEY.controls(slug), field);
476
+ else
477
+ await kv.hset(KEY.controls(slug), field, mark.audience);
478
+ return mark;
479
+ },
445
480
  /**
446
481
  * Who a prototype is for, asked by the gate with no actor. Absent, or any
447
482
  * value but `client`, is internal; a name that cannot be a prototype is
@@ -33,6 +33,13 @@ export declare const KEY: {
33
33
  */
34
34
  readonly counters: "hub3:counters";
35
35
  readonly comments: (prototype: string) => string;
36
+ /**
37
+ * What Studio marked on one prototype's controls (core/controls.ts): field
38
+ * `dial:<id>` is `client` or `internal`, overruling the code either way;
39
+ * field `variant:<name>` is `client`, and internal is its absence. One
40
+ * field per control, so two people marking at once never undo each other.
41
+ */
42
+ readonly controls: (prototype: string) => string;
36
43
  };
37
44
  export type Snapshot = {
38
45
  hashes: Record<string, Record<string, string>>;
@@ -32,6 +32,13 @@ export const KEY = {
32
32
  */
33
33
  counters: `${PREFIX}counters`,
34
34
  comments: (prototype) => `${PREFIX}comments:${prototype}`,
35
+ /**
36
+ * What Studio marked on one prototype's controls (core/controls.ts): field
37
+ * `dial:<id>` is `client` or `internal`, overruling the code either way;
38
+ * field `variant:<name>` is `client`, and internal is its absence. One
39
+ * field per control, so two people marking at once never undo each other.
40
+ */
41
+ controls: (prototype) => `${PREFIX}controls:${prototype}`,
35
42
  };
36
43
  export function memoryKV(initial = { hashes: {}, sets: {} }, onChange) {
37
44
  const hashes = new Map(Object.entries(initial.hashes).map(([k, v]) => [k, new Map(Object.entries(v))]));
@@ -30,6 +30,17 @@ export type Finding = {
30
30
  };
31
31
  /** The feature folder a file belongs to, or null for anything outside prototypes/<slug>/. */
32
32
  export declare function featureOf(file: string): string | null;
33
+ /**
34
+ * Whether a prototype stands on a Board: brand collateral, written to still
35
+ * files. Read from the change itself, else from the feature's own index.tsx,
36
+ * so its stylesheet is judged by what its markup stands on.
37
+ */
38
+ export declare function standsOnBoard(change: Change, feature: string): boolean;
39
+ /**
40
+ * The View tools are set by what a prototype stands on, never by hand: the
41
+ * shells and Space mount them, and a Board has none.
42
+ */
43
+ export declare function viewFindings(change: Change, board: boolean): Finding[];
33
44
  export declare function codeFindings(change: Change): Finding[];
34
45
  export declare function readmeStates(feature: string): string[];
35
46
  export declare function jevFindings(change: Change, feature: string, ask?: typeof judge): Promise<Finding[]>;
@@ -43,6 +43,49 @@ export function featureOf(file) {
43
43
  return null;
44
44
  return top;
45
45
  }
46
+ /**
47
+ * Whether a prototype stands on a Board: brand collateral, written to still
48
+ * files. Read from the change itself, else from the feature's own index.tsx,
49
+ * so its stylesheet is judged by what its markup stands on.
50
+ */
51
+ export function standsOnBoard(change, feature) {
52
+ if (change.added.includes('@kit/Artboard'))
53
+ return true;
54
+ const index = join(PROTOTYPES, feature, 'index.tsx');
55
+ return existsSync(index) && readFileSync(index, 'utf8').includes('@kit/Artboard');
56
+ }
57
+ /** What a board must not hold, each with what to do instead. `none` values turn motion off, so they pass. */
58
+ const ON_BOARD = [
59
+ {
60
+ test: /@keyframes|\b(?:animation|transition)(?:-[a-z-]+)?\s*:\s*(?!\s|none\b|0s\b)|from\s+['"]motion\/react['"]/,
61
+ note: 'adds motion to collateral, which exports as a still file; a piece that moves is a Space prototype, where View has the motion tools',
62
+ },
63
+ {
64
+ test: /\.dark-mode\b|prefers-color-scheme|\buseDark\b|\buseAppearance\b/,
65
+ note: 'styles collateral by theme, but a board is held to the look it exports in; a light or dark version is a Tone dial on the piece',
66
+ },
67
+ ];
68
+ /**
69
+ * The View tools are set by what a prototype stands on, never by hand: the
70
+ * shells and Space mount them, and a Board has none.
71
+ */
72
+ export function viewFindings(change, board) {
73
+ const file = relative(ROOT, change.file);
74
+ const out = [];
75
+ if (/from\s+['"]@kit\/ViewTools['"]/.test(change.added))
76
+ out.push({
77
+ file,
78
+ rule: RULE.view,
79
+ level: 'block',
80
+ note: 'mounts ViewTools; the shell or Space mounts it. Narrow it with <Space tools={[...]}>; a Board has none',
81
+ });
82
+ if (!board)
83
+ return out;
84
+ for (const { test, note } of ON_BOARD)
85
+ if (test.test(change.added))
86
+ out.push({ file, rule: RULE.view, level: 'warn', note });
87
+ return out;
88
+ }
46
89
  const DEPENDENCY_LINE = /^\s*"[^"]+":\s*"[\^~>=<\d]/gm;
47
90
  export function codeFindings(change) {
48
91
  const file = relative(ROOT, change.file);
@@ -90,6 +133,7 @@ export function codeFindings(change) {
90
133
  level: 'block',
91
134
  note: `imports ${crossing.join(', ')}; a prototype imports only @kit/* and its own folder`,
92
135
  });
136
+ out.push(...viewFindings(change, standsOnBoard(change, feature)));
93
137
  return out;
94
138
  }
95
139
  const clip = (text) => text.length > MAX_CHANGE_CHARS ? `${text.slice(0, MAX_CHANGE_CHARS)}\n…[clipped]` : text;
@@ -6,6 +6,7 @@ export declare const RULE: {
6
6
  readonly abstraction: 'No abstraction for later';
7
7
  readonly handling: 'No handling a fixture cannot reach';
8
8
  readonly state: 'Every state is in the README';
9
+ readonly view: 'View tools fit what the prototype is';
9
10
  };
10
11
  export type SemanticRule = 'fetching' | 'abstraction' | 'handling' | 'state';
11
12
  /** Each question reads `change`, `readmeStates` and `fixtureSets` from the state by path. */
@@ -10,6 +10,7 @@ export const RULE = {
10
10
  abstraction: 'No abstraction for later',
11
11
  handling: 'No handling a fixture cannot reach',
12
12
  state: 'Every state is in the README',
13
+ view: 'View tools fit what the prototype is',
13
14
  };
14
15
  /** Each question reads `change`, `readmeStates` and `fixtureSets` from the state by path. */
15
16
  export const NOULS = {
@@ -37,6 +37,9 @@ async function query(op, params, { review, actor }) {
37
37
  case 'prototypes':
38
38
  // The index's read: the view the caller gets and the client-facing slugs. viewAs is checked as comments checks it.
39
39
  return await review.visiblePrototypes(actor, params.get('viewAs') ?? undefined);
40
+ case 'controls':
41
+ // A prototype page's read: the caller's view, and what Studio marked on its dials and variants.
42
+ return await review.controlsOf(actor, params.get('prototype'));
40
43
  case 'people':
41
44
  return { people: (await review.listPeople(actor)).map(visible) };
42
45
  case 'access':
@@ -102,6 +105,16 @@ async function command(op, b, ctx) {
102
105
  prototype: b.prototype,
103
106
  audience: await review.setAudience(actor, b.prototype, b.audience),
104
107
  };
108
+ case 'control.audience':
109
+ return {
110
+ prototype: b.prototype,
111
+ ...(await review.setControl(actor, {
112
+ prototype: b.prototype,
113
+ kind: b.kind,
114
+ id: b.id,
115
+ audience: b.audience,
116
+ })),
117
+ };
105
118
  default:
106
119
  return peopleCommand(op, b, ctx);
107
120
  }
package/kit/Artboard.tsx CHANGED
@@ -8,8 +8,9 @@ import {
8
8
  useState,
9
9
  } from 'react';
10
10
  import { FORMATS, type Format, type FormatName, sizeLabel, zoomFor } from '../core/formats.ts';
11
- import { restoreDials, useDials } from './dials';
12
- import { ViewTools } from './ViewTools';
11
+ import { client, restoreDials, useDials } from './dials';
12
+ import { pinAppearance, urlAppearance } from './prefs';
13
+ import { ViewScope } from './ViewTools';
13
14
  import './artboard.css';
14
15
 
15
16
  export { FORMAT_NAMES, FORMATS, type FormatName } from '../core/formats.ts';
@@ -54,6 +55,8 @@ function useRoom() {
54
55
  return { ref, room };
55
56
  }
56
57
 
58
+ const NO_VIEW: readonly never[] = [];
59
+
57
60
  type BoardProps = { title: string; lede?: ReactNode; children: ReactNode };
58
61
 
59
62
  /**
@@ -65,8 +68,9 @@ export function Board({ title, lede, children }: BoardProps) {
65
68
  const view = useDials(
66
69
  'Board',
67
70
  {
68
- zoom: { type: 'select', options: ZOOMS, default: 'fit' },
69
- guides: true,
71
+ // How a person looks at the boards, not the design: a Client's from the start. They are a board's only viewing tools.
72
+ zoom: client({ type: 'select', options: ZOOMS, default: 'fit' }),
73
+ guides: client(true),
70
74
  },
71
75
  {
72
76
  hints: {
@@ -81,6 +85,13 @@ export function Board({ title, lede, children }: BoardProps) {
81
85
  if (exporting) void settleForExport();
82
86
  }, []);
83
87
 
88
+ // Collateral has one look: light, or the one ?theme= names, which is what export writes.
89
+ // A person's own dark theme never recolours a piece that ships light.
90
+ useEffect(() => {
91
+ pinAppearance(urlAppearance() ?? 'light');
92
+ return () => pinAppearance(null);
93
+ }, []);
94
+
84
95
  if (exporting)
85
96
  return (
86
97
  <BoardView.Provider value={{ zoom: '100%', guides: false, room }}>
@@ -95,10 +106,12 @@ export function Board({ title, lede, children }: BoardProps) {
95
106
  <h1 className="board-title">{title}</h1>
96
107
  {lede ? <p className="board-lede">{lede}</p> : null}
97
108
  </header>
98
- <div className="board-grid" ref={ref}>
99
- {children}
100
- </div>
101
- <ViewTools />
109
+ {/* No View panel on a board: a still file has no motion to slow and no theme to flip. */}
110
+ <ViewScope.Provider value={NO_VIEW}>
111
+ <div className="board-grid" ref={ref}>
112
+ {children}
113
+ </div>
114
+ </ViewScope.Provider>
102
115
  </main>
103
116
  </BoardView.Provider>
104
117
  );
package/kit/Space.tsx CHANGED
@@ -1,12 +1,13 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import './space.css';
3
- import { ViewTools } from './ViewTools';
3
+ import { type ViewTool, ViewTools } from './ViewTools';
4
4
 
5
5
  type Props = {
6
6
  title: string;
7
7
  lede?: ReactNode;
8
8
  width?: 'narrow' | 'wide' | 'full';
9
- tools?: boolean;
9
+ /** The View tools: all of them, none (`false`), or only the ones that change something here. */
10
+ tools?: boolean | readonly ViewTool[];
10
11
  children: ReactNode;
11
12
  };
12
13
 
@@ -19,7 +20,7 @@ export function Space({ title, lede, width = 'wide', tools = true, children }: P
19
20
  {lede ? <p className="space-lede">{lede}</p> : null}
20
21
  </header>
21
22
  {children}
22
- {tools ? <ViewTools /> : null}
23
+ {tools ? <ViewTools tools={tools === true ? undefined : tools} /> : null}
23
24
  </main>
24
25
  );
25
26
  }