@supersuit/components 0.0.0-stage → 0.2.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 (60) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +21 -0
  3. package/README.md +250 -2
  4. package/bin/supersuit-theme.mjs +116 -0
  5. package/dist/check/depth/bar.d.ts +27 -0
  6. package/dist/check/depth/bar.js +40 -0
  7. package/dist/check/depth/check.d.ts +40 -0
  8. package/dist/check/depth/check.js +50 -0
  9. package/dist/check/depth/crop.d.ts +24 -0
  10. package/dist/check/depth/crop.js +126 -0
  11. package/dist/check/depth/index.d.ts +3 -0
  12. package/dist/check/depth/index.js +5 -0
  13. package/dist/check/depth/measure.d.ts +42 -0
  14. package/dist/check/depth/measure.js +141 -0
  15. package/dist/check/depth/parts-page.d.ts +6 -0
  16. package/dist/check/depth/parts-page.js +69 -0
  17. package/dist/check/depth/playwright.d.ts +4 -0
  18. package/dist/check/depth/playwright.js +10 -0
  19. package/dist/check/depth/png.d.ts +3 -0
  20. package/dist/check/depth/png.js +12 -0
  21. package/dist/check/depth/shoot.d.ts +37 -0
  22. package/dist/check/depth/shoot.js +30 -0
  23. package/dist/index.d.ts +4 -0
  24. package/dist/index.js +11 -0
  25. package/dist/sound/engine.d.ts +59 -0
  26. package/dist/sound/engine.js +325 -0
  27. package/dist/sound/index.d.ts +18 -0
  28. package/dist/sound/index.js +10 -0
  29. package/dist/sound/synth.d.ts +24 -0
  30. package/dist/sound/synth.js +139 -0
  31. package/dist/theme/color.d.ts +29 -0
  32. package/dist/theme/color.js +116 -0
  33. package/dist/theme/compile.d.ts +23 -0
  34. package/dist/theme/compile.js +138 -0
  35. package/dist/theme/index.d.ts +3 -0
  36. package/dist/theme/index.js +4 -0
  37. package/dist/theme/record.d.ts +90 -0
  38. package/dist/theme/record.js +222 -0
  39. package/dist/voice-field/box-trace.d.ts +18 -0
  40. package/dist/voice-field/box-trace.js +87 -0
  41. package/dist/voice-field/index.d.ts +8 -0
  42. package/dist/voice-field/index.js +10 -0
  43. package/dist/voice-field/recorder.d.ts +71 -0
  44. package/dist/voice-field/recorder.js +211 -0
  45. package/dist/voice-field/rules.d.ts +27 -0
  46. package/dist/voice-field/rules.js +62 -0
  47. package/dist/voice-field/saved-take.d.ts +7 -0
  48. package/dist/voice-field/saved-take.js +66 -0
  49. package/dist/voice-field/store.d.ts +27 -0
  50. package/dist/voice-field/store.js +40 -0
  51. package/dist/voice-field/styles.css +161 -0
  52. package/dist/voice-field/toast.d.ts +13 -0
  53. package/dist/voice-field/toast.js +26 -0
  54. package/dist/voice-field/voice-field.d.ts +80 -0
  55. package/dist/voice-field/voice-field.js +259 -0
  56. package/dist/voice-field/words.d.ts +37 -0
  57. package/dist/voice-field/words.js +33 -0
  58. package/package.json +106 -4
  59. package/specs/brand-theme/v1/SPEC.md +130 -0
  60. package/specs/brand-theme/v1/default-bar.json +1196 -0
@@ -0,0 +1,23 @@
1
+ import { type BrandTheme } from './record.ts';
2
+ export type SoundRecipe = BrandTheme['sounds'];
3
+ export type CompileOptions = {
4
+ /** Round 1: every shadow a 1px hairline ring in the shade colour; no lights, sheens, ledge or press move. */
5
+ flat?: boolean;
6
+ /** The selector the variables sit under. Default `.theme-<id>, [data-theme="<id>"]`. */
7
+ scope?: string;
8
+ /** `depth`: only the depth variables (and `--raised`), no colour roles, no utilities. */
9
+ only?: 'depth';
10
+ /** Extra variables written inside the scope, such as `{ primary: 'var(--color-primary)' }`. */
11
+ map?: Record<string, string>;
12
+ };
13
+ export type Compiled = {
14
+ css: string;
15
+ registryItem: Record<string, unknown>;
16
+ sounds: SoundRecipe;
17
+ };
18
+ export declare const UTILITY_NAMES: string[];
19
+ /** The utilities in a shadcn registry item's `css` shape: { '@utility elev-1': { '--tw-shadow': ... } }. */
20
+ export declare function utilityCss(): Record<string, Record<string, string>>;
21
+ /** The utilities as plain CSS rules (class selectors), for a page with no Tailwind build. */
22
+ export declare function utilityRules(prefix?: string): string;
23
+ export declare function compileTheme(r: BrandTheme, o?: CompileOptions): Compiled;
@@ -0,0 +1,138 @@
1
+ // compileTheme: a brand-theme/v1 record to CSS variables, the depth utilities, a shadcn registry:theme item
2
+ // and the sound recipe. The depth recipe is round 3 of the vibe check, approved by Gary on 2026-12-01
3
+ // (pass component-vibe-check-mx412zaf-s6o2ik), ported value for value from its themes.css; only the
4
+ // record's values change. `flat` is round 1: the same theme with every depth setting at zero.
5
+ import { resolveColor, rgbChannels, toCss } from "./color.js";
6
+ import { COLOR_ROLES, resolveTheme, validateTheme } from "./record.js";
7
+ const RING = '0 0 0 1px rgb(var(--shade-rgb) / calc(0.10 * var(--shade)))';
8
+ /** The derived depth values, exactly as round 3 wrote them. */
9
+ function derived(ground) {
10
+ return [
11
+ ['edge', '0 0 0 1px rgb(var(--shade-rgb) / calc(0.09 * var(--shade)))'],
12
+ ['top', 'inset 0 1px 0 var(--lift)'],
13
+ ['elev-1', 'var(--top), var(--edge), 0 2px 4px rgb(var(--shade-rgb) / calc(0.10 * var(--shade))), 0 14px 34px -10px rgb(var(--shade-rgb) / calc(0.34 * var(--shade)))'],
14
+ ['elev-3', `var(--top), ${RING}, 0 8px 16px -6px rgb(var(--shade-rgb) / calc(0.20 * var(--shade))), 0 30px 64px -12px rgb(var(--shade-rgb) / calc(0.42 * var(--shade)))`],
15
+ ['btn-primary', 'inset 0 1px 0 var(--btn-lift), inset 0 -2px 0 rgb(0 0 0 / 0.16), 0 2px 0 var(--primary-edge), 0 7px 16px -3px rgb(var(--primary-glow-rgb) / 0.38)'],
16
+ ['btn-quiet', `var(--top), ${RING}, 0 2px 0 var(--quiet-edge), 0 6px 14px -4px rgb(var(--shade-rgb) / calc(0.24 * var(--shade)))`],
17
+ ['press', `inset 0 2px 5px rgb(0 0 0 / 0.26), ${RING}`],
18
+ ['press-move', '2px'],
19
+ ['well', 'inset 0 2px 4px rgb(var(--shade-rgb) / calc(0.15 * var(--shade))), inset 0 1px 0 rgb(var(--shade-rgb) / calc(0.06 * var(--shade)))'],
20
+ ['sheen-surface', 'linear-gradient(180deg, color-mix(in oklab, var(--card), var(--sheen-color) var(--sheen)), var(--card) 75%)'],
21
+ ['sheen-popover', 'linear-gradient(180deg, color-mix(in oklab, var(--popover), var(--sheen-color) var(--sheen)), var(--popover) 60%)'],
22
+ ['sheen-primary', 'linear-gradient(180deg, color-mix(in oklab, var(--primary), #FFFFFF 18%), var(--primary) 55%, color-mix(in oklab, var(--primary), black 8%))'],
23
+ ['sheen-quiet', 'linear-gradient(180deg, color-mix(in oklab, var(--raised), var(--sheen-color) var(--sheen)), var(--raised) 50%, color-mix(in oklab, var(--raised), rgb(var(--shade-rgb)) 4%))'],
24
+ ['sheen-tint', `linear-gradient(180deg, rgb(255 255 255 / ${ground === 'dark' ? '0.07' : '0.28'}), rgb(255 255 255 / 0) 70%)`],
25
+ ];
26
+ }
27
+ /** Round 1: the same names, every depth setting at zero. */
28
+ function derivedFlat() {
29
+ return [
30
+ ['edge', '0 0 0 1px rgb(var(--shade-rgb) / calc(0.09 * var(--shade)))'],
31
+ ['top', '0 0 #0000'],
32
+ ['elev-1', 'var(--edge)'],
33
+ ['elev-3', RING],
34
+ ['btn-primary', RING],
35
+ ['btn-quiet', RING],
36
+ ['press', RING],
37
+ ['press-move', '0px'],
38
+ ['well', RING],
39
+ ['sheen-surface', 'none'],
40
+ ['sheen-popover', 'none'],
41
+ ['sheen-primary', 'none'],
42
+ ['sheen-quiet', 'none'],
43
+ ['sheen-tint', 'none'],
44
+ ];
45
+ }
46
+ /** The utilities, copied from round 3. They feed Tailwind's shadow slot so focus rings still compose. */
47
+ const UTILITIES = [
48
+ ['elev-1', [['--tw-shadow', 'var(--elev-1)'], ['box-shadow', 'var(--tw-inset-shadow, 0 0 #0000), var(--tw-inset-ring-shadow, 0 0 #0000), var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)']]],
49
+ ['elev-3', [['--tw-shadow', 'var(--elev-3)'], ['box-shadow', 'var(--tw-inset-shadow, 0 0 #0000), var(--tw-inset-ring-shadow, 0 0 #0000), var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)']]],
50
+ ['elev-primary', [['--tw-shadow', 'var(--btn-primary)'], ['box-shadow', 'var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)']]],
51
+ ['elev-btn', [['--tw-shadow', 'var(--btn-quiet)'], ['box-shadow', 'var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)']]],
52
+ ['well', [['--tw-shadow', 'var(--well)'], ['box-shadow', 'var(--tw-inset-shadow, 0 0 #0000), var(--tw-inset-ring-shadow, 0 0 #0000), var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)']]],
53
+ ['pressed', [['--tw-shadow', 'var(--press)'], ['box-shadow', 'var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)'], ['transform', 'translateY(var(--press-move))'], ['filter', 'brightness(0.95)']]],
54
+ ['sheen-surface', [['background-image', 'var(--sheen-surface)']]],
55
+ ['sheen-popover', [['background-image', 'var(--sheen-popover)']]],
56
+ ['sheen-primary', [['background-image', 'var(--sheen-primary)']]],
57
+ ['sheen-quiet', [['background-image', 'var(--sheen-quiet)']]],
58
+ ['sheen-tint', [['background-image', 'var(--sheen-tint)']]],
59
+ ];
60
+ export const UTILITY_NAMES = UTILITIES.map(([n]) => n);
61
+ /** The utilities in a shadcn registry item's `css` shape: { '@utility elev-1': { '--tw-shadow': ... } }. */
62
+ export function utilityCss() {
63
+ return Object.fromEntries(UTILITIES.map(([n, decls]) => [`@utility ${n}`, Object.fromEntries(decls)]));
64
+ }
65
+ /** The utilities as plain CSS rules (class selectors), for a page with no Tailwind build. */
66
+ export function utilityRules(prefix = '.') {
67
+ return UTILITIES.map(([n, decls]) => `${prefix}${n} { ${decls.map(([p, v]) => `${p}: ${v};`).join(' ')} }`).join('\n');
68
+ }
69
+ function liftCss(v, tokens) {
70
+ return typeof v === 'number' ? `rgb(255 255 255 / ${v})` : toCss(resolveColor(v, tokens));
71
+ }
72
+ /** The depth inputs: the record's five settings as variables. */
73
+ function depthInputs(r, flat) {
74
+ const d = r.depth;
75
+ const t = r.tokens;
76
+ return [
77
+ ['shade-rgb', rgbChannels(resolveColor(d.shade.color, t))],
78
+ ['shade', String(d.shade.strength)],
79
+ ['lift', flat ? 'transparent' : liftCss(d.lift.surface, t)],
80
+ ['btn-lift', flat ? 'transparent' : liftCss(d.lift.button, t)],
81
+ ['sheen-color', toCss(resolveColor(d.sheen.color, t))],
82
+ ['sheen', flat ? '0%' : `${d.sheen.amount}%`],
83
+ ['primary-glow-rgb', rgbChannels(resolveColor(d.glow, t))],
84
+ ['primary-edge', `color-mix(in oklab, var(--primary), black ${d.edge.primary}%)`],
85
+ ['quiet-edge', toCss(resolveColor(d.edge.quiet, t))],
86
+ ];
87
+ }
88
+ export function compileTheme(r, o = {}) {
89
+ const problems = validateTheme(r);
90
+ if (problems.length)
91
+ throw new Error(`brand-theme refused:\n${problems.map((p) => ` ${p.field}: ${p.words}`).join('\n')}`);
92
+ const flat = !!o.flat;
93
+ const scope = o.scope ?? `.theme-${r.id}, [data-theme="${r.id}"]`;
94
+ const colors = resolveTheme(r, { flat });
95
+ const roles = o.only === 'depth'
96
+ ? [['raised', toCss(colors.raised)]]
97
+ : COLOR_ROLES.map((role) => [role, toCss(colors[role])]);
98
+ const base = o.only === 'depth' ? [] : [
99
+ ['radius', r.radius],
100
+ ['font-display', r.type.display],
101
+ ['font-text', r.type.text],
102
+ ['display-weight', String(r.type.displayWeight)],
103
+ ['display-tracking', r.type.displayTracking],
104
+ ];
105
+ const mapped = Object.entries(o.map ?? {});
106
+ const depth = [...depthInputs(r, flat), ...(flat ? derivedFlat() : derived(r.ground))];
107
+ const block = (title, vars) => vars.length ? ` /* ${title} */\n${vars.map(([k, v]) => ` --${k}: ${v};`).join('\n')}\n` : '';
108
+ const head = `/* ${r.name} (${r.id}), brand-theme/v1, compiled by supersuit-theme${flat ? ' flat (round 1)' : ''}${o.only ? ' --only depth' : ''}. Do not edit: change the record and rebuild. */\n`;
109
+ let css = head + `${scope} {\n`
110
+ + block('roles', roles)
111
+ + block('type and corner', base)
112
+ + block('mapped', mapped)
113
+ + block(flat ? 'depth, flat' : 'depth', depth)
114
+ + (o.only === 'depth' ? '' : ` color-scheme: ${r.ground};\n`)
115
+ + '}\n';
116
+ if (o.only !== 'depth') {
117
+ css += '\n' + UTILITIES.map(([n, decls]) => `@utility ${n} { ${decls.map(([p, v]) => `${p}: ${v};`).join(' ')} }`).join('\n') + '\n';
118
+ }
119
+ const vars = Object.fromEntries([...roles, ['radius', r.radius], ...mapped, ...depth]);
120
+ const registryItem = {
121
+ $schema: 'https://ui.shadcn.com/schema/registry-item.json',
122
+ name: `theme-${r.id}`,
123
+ type: 'registry:theme',
124
+ title: r.name,
125
+ description: r.essence,
126
+ cssVars: {
127
+ theme: {
128
+ 'font-display': r.type.display,
129
+ 'font-text': r.type.text,
130
+ 'display-weight': String(r.type.displayWeight),
131
+ 'display-tracking': r.type.displayTracking,
132
+ },
133
+ [r.ground]: vars,
134
+ },
135
+ css: utilityCss(),
136
+ };
137
+ return { css, registryItem, sounds: { ...r.sounds } };
138
+ }
@@ -0,0 +1,3 @@
1
+ export * from './color.ts';
2
+ export * from './record.ts';
3
+ export * from './compile.ts';
@@ -0,0 +1,4 @@
1
+ // @supersuit/components/theme: the brand-theme/v1 validator and compiler.
2
+ export * from "./color.js";
3
+ export * from "./record.js";
4
+ export * from "./compile.js";
@@ -0,0 +1,90 @@
1
+ import { type RGBA } from './color.ts';
2
+ export declare const FORMAT = "brand-theme/v1";
3
+ /** The 19 shadcn roles. */
4
+ export declare const SHADCN_ROLES: readonly ["background", "foreground", "card", "card-foreground", "popover", "popover-foreground", "primary", "primary-foreground", "secondary", "secondary-foreground", "muted", "muted-foreground", "accent", "accent-foreground", "destructive", "border", "input", "ring", "destructive-foreground"];
5
+ /** Our 10 extra roles. */
6
+ export declare const EXTRA_ROLES: readonly ["field", "raised", "skeleton", "scrim", "placeholder", "accent-ink", "rec", "rec-text", "on-rec", "eyebrow"];
7
+ export declare const COLOR_ROLES: readonly ["background", "foreground", "card", "card-foreground", "popover", "popover-foreground", "primary", "primary-foreground", "secondary", "secondary-foreground", "muted", "muted-foreground", "accent", "accent-foreground", "destructive", "border", "input", "ring", "destructive-foreground", "field", "raised", "skeleton", "scrim", "placeholder", "accent-ink", "rec", "rec-text", "on-rec", "eyebrow"];
8
+ export type ColorRole = (typeof COLOR_ROLES)[number];
9
+ /** Text roles and the grounds they must read on, at 4.5 or more. */
10
+ export declare const TEXT_PAIRS: ReadonlyArray<[ColorRole, ColorRole]>;
11
+ export declare const SOUND_FAMILIES: readonly ["wood", "bubble"];
12
+ export declare const SUCCESS_VOICES: readonly ["marimba", "bell"];
13
+ export type BrandTheme = {
14
+ format: typeof FORMAT;
15
+ id: string;
16
+ name: string;
17
+ essence: string;
18
+ ground: 'light' | 'dark';
19
+ tokens: Record<string, string>;
20
+ colors: Record<ColorRole, string>;
21
+ type: {
22
+ display: string;
23
+ text: string;
24
+ displayWeight: number;
25
+ displayTracking: string;
26
+ };
27
+ radius: string;
28
+ depth: {
29
+ /** The ink of every shadow, and its strength (1 on light grounds). */
30
+ shade: {
31
+ color: string;
32
+ strength: number;
33
+ };
34
+ /** The 1px light on top of a raised surface and of a filled button: white at a number, or a colour expression. */
35
+ lift: {
36
+ surface: number | string;
37
+ button: number | string;
38
+ };
39
+ /** The light mixed into the top of a raised face: a token, and how much (percent). */
40
+ sheen: {
41
+ color: string;
42
+ amount: number;
43
+ };
44
+ /** The ledge under filled buttons (primary mixed toward black, percent) and under quiet buttons (a colour). */
45
+ edge: {
46
+ primary: number;
47
+ quiet: string;
48
+ };
49
+ /** Dark grounds: the raised surfaces' colours with depth on (role to colour). 0 when nothing is raised by colour. */
50
+ raise: 0 | Partial<Record<ColorRole, string>>;
51
+ /** The tint of the filled button's drop shadow (a token). */
52
+ glow: string;
53
+ };
54
+ sounds: {
55
+ family: (typeof SOUND_FAMILIES)[number];
56
+ pitch: number;
57
+ brightness: number;
58
+ success: (typeof SUCCESS_VOICES)[number];
59
+ level: number;
60
+ };
61
+ depthBar: 'default' | 'flat' | Record<string, unknown>;
62
+ approval: {
63
+ by: string;
64
+ at: string;
65
+ words: string;
66
+ pass?: string;
67
+ hash?: string;
68
+ };
69
+ /**
70
+ * A text pair the owner approved under 4.5, recorded with its contrast so it cannot get worse unseen.
71
+ * The validator refuses one whose measured contrast moved by more than 0.01.
72
+ */
73
+ contrastExceptions?: Array<{
74
+ pair: string;
75
+ contrast: number;
76
+ why: string;
77
+ }>;
78
+ };
79
+ export type Problem = {
80
+ field: string;
81
+ words: string;
82
+ };
83
+ /** Every role resolved to a colour. Depth on applies `depth.raise`; flat leaves it out. */
84
+ export declare function resolveTheme(r: BrandTheme, o?: {
85
+ flat?: boolean;
86
+ }): Record<ColorRole, RGBA>;
87
+ /** Check a record. An empty list means it is a valid brand-theme/v1 record. */
88
+ export declare function validateTheme(r: unknown): Problem[];
89
+ /** The contrast of each text pair, the lower of flat and depth on, keyed "text on ground". */
90
+ export declare function textContrasts(r: BrandTheme): Record<string, number>;
@@ -0,0 +1,222 @@
1
+ // brand-theme/v1: everything a screen needs to look and sound like one brand.
2
+ // The format is specs/brand-theme/v1/SPEC.md. This file is its validator.
3
+ import { contrast, isHex, resolveColor } from "./color.js";
4
+ export const FORMAT = 'brand-theme/v1';
5
+ /** The 19 shadcn roles. */
6
+ export const SHADCN_ROLES = [
7
+ 'background', 'foreground', 'card', 'card-foreground', 'popover', 'popover-foreground',
8
+ 'primary', 'primary-foreground', 'secondary', 'secondary-foreground', 'muted', 'muted-foreground',
9
+ 'accent', 'accent-foreground', 'destructive', 'border', 'input', 'ring', 'destructive-foreground',
10
+ ];
11
+ /** Our 10 extra roles. */
12
+ export const EXTRA_ROLES = [
13
+ 'field', 'raised', 'skeleton', 'scrim', 'placeholder', 'accent-ink', 'rec', 'rec-text', 'on-rec', 'eyebrow',
14
+ ];
15
+ export const COLOR_ROLES = [...SHADCN_ROLES, ...EXTRA_ROLES];
16
+ /** Text roles and the grounds they must read on, at 4.5 or more. */
17
+ export const TEXT_PAIRS = [
18
+ ['foreground', 'background'],
19
+ ['card-foreground', 'card'],
20
+ ['popover-foreground', 'popover'],
21
+ ['primary-foreground', 'primary'],
22
+ ['secondary-foreground', 'secondary'],
23
+ ['muted-foreground', 'muted'],
24
+ ['muted-foreground', 'background'],
25
+ ['muted-foreground', 'card'],
26
+ ['accent-foreground', 'accent'],
27
+ ['rec-text', 'background'],
28
+ ];
29
+ export const SOUND_FAMILIES = ['wood', 'bubble'];
30
+ export const SUCCESS_VOICES = ['marimba', 'bell'];
31
+ const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
32
+ const isStr = (v) => typeof v === 'string' && v.trim().length > 0;
33
+ const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
34
+ /** Every role resolved to a colour. Depth on applies `depth.raise`; flat leaves it out. */
35
+ export function resolveTheme(r, o = {}) {
36
+ const out = {};
37
+ for (const role of COLOR_ROLES)
38
+ out[role] = resolveColor(r.colors[role], r.tokens);
39
+ if (!o.flat && isObj(r.depth?.raise)) {
40
+ for (const [role, expr] of Object.entries(r.depth.raise))
41
+ out[role] = resolveColor(expr, r.tokens);
42
+ }
43
+ return out;
44
+ }
45
+ /** Check a record. An empty list means it is a valid brand-theme/v1 record. */
46
+ export function validateTheme(r) {
47
+ const p = [];
48
+ const add = (field, words) => p.push({ field, words });
49
+ if (!isObj(r))
50
+ return [{ field: '(record)', words: 'not a JSON object' }];
51
+ if (r.format !== FORMAT)
52
+ add('format', `unknown format "${r.format}": this validator reads ${FORMAT}`);
53
+ if (!isStr(r.id) || !/^[a-z][a-z0-9-]*$/.test(r.id))
54
+ add('id', 'missing or not kebab-case');
55
+ for (const f of ['name', 'essence', 'radius'])
56
+ if (!isStr(r[f]))
57
+ add(f, 'missing');
58
+ if (isStr(r.radius) && !/^\d+(\.\d+)?(px|rem)$/.test(r.radius))
59
+ add('radius', `not a length: ${r.radius}`);
60
+ if (r.ground !== 'light' && r.ground !== 'dark')
61
+ add('ground', 'must be "light" or "dark"');
62
+ const tokens = isObj(r.tokens) ? r.tokens : {};
63
+ if (!isObj(r.tokens))
64
+ add('tokens', 'missing');
65
+ for (const [k, v] of Object.entries(tokens)) {
66
+ if (!/^[a-z][a-z0-9-]*$/.test(k))
67
+ add(`tokens.${k}`, 'a token name is lower-case kebab');
68
+ if (typeof v !== 'string' || !isHex(v))
69
+ add(`tokens.${k}`, `not a hex colour: ${v}`);
70
+ }
71
+ const colour = (field, v) => {
72
+ if (!isStr(v))
73
+ return add(field, 'missing');
74
+ if (isHex(v))
75
+ return add(field, `bare hex ${v}: name it in tokens and use the token`);
76
+ try {
77
+ resolveColor(v, tokens);
78
+ }
79
+ catch (e) {
80
+ add(field, e.message);
81
+ }
82
+ };
83
+ const colors = isObj(r.colors) ? r.colors : {};
84
+ if (!isObj(r.colors))
85
+ add('colors', 'missing');
86
+ for (const role of COLOR_ROLES)
87
+ colour(`colors.${role}`, colors[role]);
88
+ for (const k of Object.keys(colors))
89
+ if (!COLOR_ROLES.includes(k))
90
+ add(`colors.${k}`, 'not a role of brand-theme/v1');
91
+ const t = r.type;
92
+ if (!isObj(t))
93
+ add('type', 'missing');
94
+ else {
95
+ if (!isStr(t.display))
96
+ add('type.display', 'missing');
97
+ if (!isStr(t.text))
98
+ add('type.text', 'missing');
99
+ if (!isNum(t.displayWeight))
100
+ add('type.displayWeight', 'missing or not a number');
101
+ if (!isStr(t.displayTracking))
102
+ add('type.displayTracking', 'missing');
103
+ }
104
+ const d = r.depth;
105
+ if (!isObj(d))
106
+ add('depth', 'missing');
107
+ else {
108
+ if (!isObj(d.shade))
109
+ add('depth.shade', 'missing');
110
+ else {
111
+ colour('depth.shade.color', d.shade.color);
112
+ if (!isNum(d.shade.strength) || d.shade.strength < 0)
113
+ add('depth.shade.strength', 'a number, 0 or more');
114
+ }
115
+ if (!isObj(d.lift))
116
+ add('depth.lift', 'missing');
117
+ else
118
+ for (const k of ['surface', 'button']) {
119
+ const v = d.lift[k];
120
+ if (isNum(v)) {
121
+ if (v < 0 || v > 1)
122
+ add(`depth.lift.${k}`, 'a number from 0 to 1, or a colour');
123
+ }
124
+ else
125
+ colour(`depth.lift.${k}`, v);
126
+ }
127
+ if (!isObj(d.sheen))
128
+ add('depth.sheen', 'missing');
129
+ else {
130
+ colour('depth.sheen.color', d.sheen.color);
131
+ if (!isNum(d.sheen.amount) || d.sheen.amount < 0 || d.sheen.amount > 100)
132
+ add('depth.sheen.amount', 'a percent, 0 to 100');
133
+ }
134
+ if (!isObj(d.edge))
135
+ add('depth.edge', 'missing');
136
+ else {
137
+ if (!isNum(d.edge.primary) || d.edge.primary < 0 || d.edge.primary > 100)
138
+ add('depth.edge.primary', 'a percent toward black, 0 to 100');
139
+ colour('depth.edge.quiet', d.edge.quiet);
140
+ }
141
+ if (d.raise !== 0) {
142
+ if (!isObj(d.raise))
143
+ add('depth.raise', '0, or roles to colours');
144
+ else
145
+ for (const [role, v] of Object.entries(d.raise)) {
146
+ if (!COLOR_ROLES.includes(role))
147
+ add(`depth.raise.${role}`, 'not a role of brand-theme/v1');
148
+ else
149
+ colour(`depth.raise.${role}`, v);
150
+ }
151
+ }
152
+ colour('depth.glow', d.glow);
153
+ }
154
+ const s = r.sounds;
155
+ if (!isObj(s))
156
+ add('sounds', 'missing');
157
+ else {
158
+ if (!SOUND_FAMILIES.includes(s.family))
159
+ add('sounds.family', `one of ${SOUND_FAMILIES.join(', ')}`);
160
+ if (!isNum(s.pitch) || s.pitch <= 0)
161
+ add('sounds.pitch', 'a frequency in Hz');
162
+ if (!isNum(s.brightness) || s.brightness <= 0)
163
+ add('sounds.brightness', 'a number above 0');
164
+ if (!SUCCESS_VOICES.includes(s.success))
165
+ add('sounds.success', `one of ${SUCCESS_VOICES.join(', ')}`);
166
+ if (!isNum(s.level) || s.level > 0)
167
+ add('sounds.level', 'a peak in dBFS, 0 or below');
168
+ }
169
+ if (!(r.depthBar === 'default' || r.depthBar === 'flat' || isObj(r.depthBar)))
170
+ add('depthBar', '"default", "flat", or thresholds');
171
+ const a = r.approval;
172
+ if (!isObj(a))
173
+ add('approval', 'missing');
174
+ else {
175
+ if (!isStr(a.by))
176
+ add('approval.by', 'missing');
177
+ if (!isStr(a.at) || !/^\d{4}-\d{2}-\d{2}/.test(a.at))
178
+ add('approval.at', 'missing or not a date');
179
+ if (!isStr(a.words))
180
+ add('approval.words', 'missing');
181
+ }
182
+ const ex = r.contrastExceptions === undefined ? [] : r.contrastExceptions;
183
+ if (!Array.isArray(ex))
184
+ add('contrastExceptions', 'a list');
185
+ else
186
+ ex.forEach((e, i) => {
187
+ if (!isObj(e) || !isStr(e.pair) || !isNum(e.contrast) || !isStr(e.why))
188
+ add(`contrastExceptions.${i}`, 'needs pair, contrast and why');
189
+ });
190
+ // Text roles on their grounds, as drawn flat and with depth on: the lower of the two counts.
191
+ if (p.length === 0) {
192
+ for (const [pair, k] of Object.entries(textContrasts(r))) {
193
+ if (k >= 4.5)
194
+ continue;
195
+ const [text] = pair.split(' on ');
196
+ const e = ex.find((x) => x.pair === pair);
197
+ const shown = k.toFixed(2);
198
+ if (!e)
199
+ add(`colors.${text}`, `${pair} is ${shown}, under 4.5`);
200
+ else if (Math.abs(e.contrast - k) > 0.01)
201
+ add(`colors.${text}`, `${pair} is ${shown}, under 4.5, and the exception was recorded at ${e.contrast}`);
202
+ }
203
+ for (const e of ex) {
204
+ if (isObj(e) && isStr(e.pair) && !(e.pair in textContrasts(r)))
205
+ add('contrastExceptions', `"${e.pair}" is not a text pair`);
206
+ }
207
+ }
208
+ return p;
209
+ }
210
+ /** The contrast of each text pair, the lower of flat and depth on, keyed "text on ground". */
211
+ export function textContrasts(r) {
212
+ const out = {};
213
+ for (const flat of [true, false]) {
214
+ const c = resolveTheme(r, { flat });
215
+ for (const [text, ground] of TEXT_PAIRS) {
216
+ const k = contrast(c[text], c[ground]);
217
+ const key = `${text} on ${ground}`;
218
+ out[key] = Math.min(out[key] ?? Infinity, k);
219
+ }
220
+ }
221
+ return out;
222
+ }
@@ -0,0 +1,18 @@
1
+ export type TraceTone = 'on' | 'rec';
2
+ /** The length of a rounded rectangle's edge. */
3
+ export declare function roundedRectPerimeter(w: number, h: number, r: number): number;
4
+ /** The comet: TAIL_STEPS thin layers that all end at the same head, each shorter than the last and a step nearer
5
+ * the head's colour; then a soft glow and a bright tip. `mix` is how far a layer has moved from the tail's shade
6
+ * to the head's (0..1). `len` is its dash length in px, never more than half the edge. */
7
+ export declare const TAIL_STEPS = 9;
8
+ export declare function cometLayers(perimeter: number): {
9
+ len: number;
10
+ opacity: number;
11
+ width: number;
12
+ mix: number;
13
+ }[];
14
+ /** One lap, in ms: the same speed on a short box and a long one, held between 1.4 s and 2.6 s. */
15
+ export declare function lapMs(perimeter: number): number;
16
+ export declare function BoxTrace({ tone }: {
17
+ tone: TraceTone;
18
+ }): import("react").JSX.Element;
@@ -0,0 +1,87 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ // THE BOX TRACE: while a mic drawn as a rounded square is opening, or the words are being written down, a
4
+ // short gradient comet runs around the mic's own edge (asked for 2026-11-29: "a beautiful, animated, maybe
5
+ // gradient, snaking around the rounded square", and then "around just the microphone"). It draws round
6
+ // whatever element holds it.
7
+ //
8
+ // Nothing here rotates: a turning square swings its corners outside the mic and across the box's edge. The
9
+ // comet is a dash on a rounded rectangle the size of its holder, moved along the edge by its dash offset, so
10
+ // it follows the corners at one speed on every side. Each layer of the tail is its own shade, fading from a
11
+ // quiet tail into the bright head. Lengths are measured in pixels from the box (a ResizeObserver), never with
12
+ // `pathLength`, so the dash is the same in Safari and Chrome. With reduced motion the whole edge is drawn still.
13
+ //
14
+ // Colours come from the theme: --vf-trace-tail and --vf-trace-head for the computer answering, and
15
+ // --vf-trace-rec-tail and --vf-trace-rec-head while the microphone is opening.
16
+ import { useEffect, useRef, useState } from 'react';
17
+ /** The length of a rounded rectangle's edge. */
18
+ export function roundedRectPerimeter(w, h, r) {
19
+ const rr = Math.max(0, Math.min(r, w / 2, h / 2));
20
+ return 2 * (w - 2 * rr) + 2 * (h - 2 * rr) + 2 * Math.PI * rr;
21
+ }
22
+ /** The comet: TAIL_STEPS thin layers that all end at the same head, each shorter than the last and a step nearer
23
+ * the head's colour; then a soft glow and a bright tip. `mix` is how far a layer has moved from the tail's shade
24
+ * to the head's (0..1). `len` is its dash length in px, never more than half the edge. */
25
+ export const TAIL_STEPS = 9;
26
+ export function cometLayers(perimeter) {
27
+ const comet = Math.min(Math.max(perimeter * 0.3, 60), 280, perimeter / 2);
28
+ const tail = Array.from({ length: TAIL_STEPS }, (_, i) => ({ len: comet * (1 - i / TAIL_STEPS), opacity: 0.15, width: 2.5, mix: i / (TAIL_STEPS - 1) }));
29
+ return [...tail, { len: comet * 0.22, opacity: 0.3, width: 5, mix: 1 }, { len: comet * 0.1, opacity: 1, width: 3, mix: 1 }]
30
+ .map((l) => ({ ...l, len: Math.min(l.len, perimeter / 2) }));
31
+ }
32
+ /** One lap, in ms: the same speed on a short box and a long one, held between 1.4 s and 2.6 s. */
33
+ export function lapMs(perimeter) {
34
+ return Math.round(Math.min(Math.max((perimeter / 520) * 1000, 1400), 2600));
35
+ }
36
+ const SHADES = {
37
+ on: { tail: 'var(--vf-trace-tail, #22324A)', head: 'var(--vf-trace-head, #58E1D1)' },
38
+ rec: { tail: 'var(--vf-trace-rec-tail, #2B3B50)', head: 'var(--vf-trace-rec-head, #DE6152)' },
39
+ };
40
+ const shade = (tone, mix) => {
41
+ const { tail, head } = SHADES[tone];
42
+ return mix <= 0 ? tail : mix >= 1 ? head : `color-mix(in srgb, ${head} ${Math.round(mix * 100)}%, ${tail})`;
43
+ };
44
+ const reducedMotion = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
45
+ export function BoxTrace({ tone }) {
46
+ const holder = useRef(null);
47
+ const [size, setSize] = useState(null);
48
+ useEffect(() => {
49
+ const box = holder.current?.parentElement;
50
+ if (!box)
51
+ return;
52
+ const read = () => {
53
+ const w = box.clientWidth, h = box.clientHeight;
54
+ const r = parseFloat(getComputedStyle(box).borderTopLeftRadius) || 0;
55
+ setSize((s) => (s && s.w === w && s.h === h && s.r === r ? s : { w, h, r }));
56
+ };
57
+ read();
58
+ if (typeof ResizeObserver !== 'function')
59
+ return;
60
+ const ro = new ResizeObserver(read);
61
+ ro.observe(box);
62
+ return () => ro.disconnect();
63
+ }, []);
64
+ // The widest layer (the glow, 5 px) sits wholly inside the box: its centre line is 2.5 px in from the edge.
65
+ const inset = 2.5;
66
+ const w = size ? Math.max(0, size.w - inset * 2) : 0;
67
+ const h = size ? Math.max(0, size.h - inset * 2) : 0;
68
+ const r = size ? Math.max(0, Math.min(size.r - inset, w / 2, h / 2)) : 0;
69
+ const perimeter = roundedRectPerimeter(w, h, r);
70
+ const still = reducedMotion();
71
+ const layers = still ? [{ len: perimeter, opacity: 0.9, width: 2.5, mix: 0.6 }] : cometLayers(perimeter);
72
+ useEffect(() => {
73
+ if (still || !perimeter)
74
+ return;
75
+ const svg = holder.current?.querySelector('svg');
76
+ if (!svg)
77
+ return;
78
+ const anims = [...svg.querySelectorAll('rect[data-layer]')].flatMap((el) => {
79
+ if (typeof el.animate !== 'function')
80
+ return [];
81
+ const len = Number(el.dataset.len);
82
+ return [el.animate([{ strokeDashoffset: `${len}px` }, { strokeDashoffset: `${len - perimeter}px` }], { duration: lapMs(perimeter), iterations: Infinity, easing: 'linear' })];
83
+ });
84
+ return () => anims.forEach((a) => a.cancel());
85
+ }, [perimeter, still, layers.length]);
86
+ return (_jsx("span", { ref: holder, "data-box-trace": "", "data-tone": tone, "aria-hidden": "true", style: { position: 'absolute', inset: 0, pointerEvents: 'none', borderRadius: 'inherit' }, children: size && perimeter > 0 ? (_jsx("svg", { width: size.w, height: size.h, viewBox: `0 0 ${size.w} ${size.h}`, style: { position: 'absolute', inset: 0, overflow: 'visible' }, children: layers.map((l, i) => (_jsx("rect", { "data-layer": "", "data-len": l.len, x: inset, y: inset, width: w, height: h, rx: r, ry: r, fill: "none", stroke: shade(tone, l.mix), strokeWidth: l.width, strokeLinecap: "round", opacity: l.opacity, style: { strokeDasharray: still ? 'none' : `${l.len}px ${perimeter - l.len}px`, strokeDashoffset: `${l.len}px` } }, i))) })) : null }));
87
+ }
@@ -0,0 +1,8 @@
1
+ export { VoiceField, DRAFT_MS, RETRY_MS, type VoiceFieldProps, type Transcribe, type Reach } from './voice-field.js';
2
+ export { Recorder, defaultStartTake, pressVoice, VOICE_KEY_EVENT, type RecorderProps, type Recorded, type LiveTake, type StartTake, type MicState, type MicSize, type MicLook, type MicClassNames, type MicReport, } from './recorder.js';
3
+ export { SavedTake } from './saved-take.js';
4
+ export { BoxTrace, cometLayers, lapMs, roundedRectPerimeter, TAIL_STEPS, type TraceTone } from './box-trace.js';
5
+ export { VoiceToasts, voiceToast, clearVoiceToasts, type ToastFn, type VoiceToast, type ToastTone } from './toast.js';
6
+ export { defaultWords, wordsWith, type VoiceFieldWords } from './words.js';
7
+ export { memoryStore, fieldDraftKey, fieldTakesKey, clearFieldDraft, keepFieldTake, forgetFieldTake, keptTakes, takeBlob, newTakeKey, type VoiceStore, type Shelf, type KeptTake, } from './store.js';
8
+ export { TAP_MS, MIN_MS, MAX_SEC, SILENCE, NO_SPEECH_MS, clock, releaseIsTap, silenceWatch, micError, barsFromSamples } from './rules.js';
@@ -0,0 +1,10 @@
1
+ // @supersuit/components/voice-field: one text box that can also be spoken. Import the styles once:
2
+ // import '@supersuit/components/voice-field/styles.css'
3
+ export { VoiceField, DRAFT_MS, RETRY_MS } from './voice-field.js';
4
+ export { Recorder, defaultStartTake, pressVoice, VOICE_KEY_EVENT, } from './recorder.js';
5
+ export { SavedTake } from './saved-take.js';
6
+ export { BoxTrace, cometLayers, lapMs, roundedRectPerimeter, TAIL_STEPS } from './box-trace.js';
7
+ export { VoiceToasts, voiceToast, clearVoiceToasts } from './toast.js';
8
+ export { defaultWords, wordsWith } from './words.js';
9
+ export { memoryStore, fieldDraftKey, fieldTakesKey, clearFieldDraft, keepFieldTake, forgetFieldTake, keptTakes, takeBlob, newTakeKey, } from './store.js';
10
+ export { TAP_MS, MIN_MS, MAX_SEC, SILENCE, NO_SPEECH_MS, clock, releaseIsTap, silenceWatch, micError, barsFromSamples } from './rules.js';