@astryxdesign/cli 0.7.14-canary.g179767d → 0.7.14-canary.g7deca33

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.
@@ -540,7 +540,7 @@ export function checkSetting(
540
540
  s.note = `no effect on ${hard.map(([t]) => t).join(', ')} (they never read ${thing})`;
541
541
  if (!s.note && recorded.length) {
542
542
  const fed = C.feeds(recorded[0][0], thing);
543
- if (fed.length) s.note = `feeds ${C.fmtFeeds(fed)}`;
543
+ if (fed.length) s.note = `feeds ${C.fmtFeeds(fed, recorded[0][0])}`;
544
544
  }
545
545
  const soft = results.filter(([, r]) => r?.soft);
546
546
  if (!s.note && soft.length && soft.length === results.length)
@@ -549,10 +549,22 @@ export function checkSetting(
549
549
  ).message;
550
550
  } else {
551
551
  const r = C.checkTokenGlobal(thing, P);
552
+ // Tokens whose default is built from this one: a part that reads
553
+ // them sees the change.
554
+ const fed = r
555
+ ? Object.entries(TOKENS)
556
+ .filter(
557
+ ([k, v]) =>
558
+ k !== thing && new RegExp(`var\\(${thing}[,)]`).test(String(v)),
559
+ )
560
+ .map(([k]) => k)
561
+ : [];
552
562
  // A token a dial writes is always accepted, so a dial's notes never
553
563
  // name a token `set` refuses.
554
- if (r && dialWrites(thing))
555
- s.note = `no part reads ${thing} directly in this Core; a dial writes it too, so it is set as asked`;
564
+ if (r && fed.length)
565
+ s.note = `no part reads ${thing} itself, but ${fed.slice(0, 4).join(', ')} ${fed.length > 1 ? 'are' : 'is'} built from it, so the change shows wherever ${fed.length > 1 ? 'those are' : 'that is'} used${fed.some(k => k.startsWith('--color-syntax-')) ? ' (such as diff rows in code blocks)' : ''}`;
566
+ else if (r && dialWrites(thing))
567
+ s.note = `no part of this Core reads ${thing}, and no token it feeds is read, so it changes nothing you see now; it is set as asked because a dial writes it too`;
556
568
  else if (r)
557
569
  refuse(E.ERR_THEME_NO_EFFECT, r.message, {run: r.run, also: r.also});
558
570
  }
@@ -682,6 +694,62 @@ const dialWrites = token =>
682
694
  token,
683
695
  );
684
696
 
697
+ /** Hues a question can name, each with or without light, dark or pale. */
698
+ const HUES = [
699
+ 'gray',
700
+ 'grey',
701
+ 'red',
702
+ 'blue',
703
+ 'green',
704
+ 'yellow',
705
+ 'orange',
706
+ 'purple',
707
+ 'pink',
708
+ 'navy',
709
+ ];
710
+ /** Color words that can name a part's fill, longest first. */
711
+ const COLOR_WORDS = [
712
+ ...HUES.flatMap(h => ['light', 'dark', 'pale'].map(s => `${s} ${h}`)),
713
+ ...HUES,
714
+ 'white',
715
+ 'black',
716
+ 'cream',
717
+ 'beige',
718
+ ];
719
+ /** Fills for the plain grays, so the command has a real value. */
720
+ const NAMED_FILLS = /** @type {Record<string, string>} */ ({
721
+ 'light gray': '#e5e7eb',
722
+ 'light grey': '#e5e7eb',
723
+ gray: '#9ca3af',
724
+ grey: '#9ca3af',
725
+ 'dark gray': '#374151',
726
+ 'dark grey': '#374151',
727
+ 'light blue': '#dbeafe',
728
+ 'pale blue': '#eff6ff',
729
+ white: '#ffffff',
730
+ black: '#000000',
731
+ });
732
+ /** Nouns for parts that have a fill. */
733
+ const PART_NOUNS = [
734
+ 'button',
735
+ 'card',
736
+ 'panel',
737
+ 'banner',
738
+ 'header',
739
+ 'input',
740
+ 'field',
741
+ 'badge',
742
+ 'tab',
743
+ 'chip',
744
+ 'pill',
745
+ 'toast',
746
+ 'tooltip',
747
+ 'dialog',
748
+ 'modal',
749
+ 'sidebar',
750
+ 'row',
751
+ ];
752
+
685
753
  /**
686
754
  * Answer a plain-words question with exact commands: the parts it names,
687
755
  * the aspects it asks about, and what each part really reads for them.
@@ -711,13 +779,40 @@ export function answerHow(ctx, question) {
711
779
  /\bwhite (text|labels?|writing|words)\b|\b(text|labels?|writing|words) (in |is |are )?white\b/.test(
712
780
  text,
713
781
  );
782
+ // A color word right before a part ("light gray button") is the part's
783
+ // fill, so it keeps the background aspect beside text.
784
+ const fillMatch =
785
+ new RegExp(
786
+ `\\b(${COLOR_WORDS.join('|')})\\s+(?:${PART_NOUNS.join('|')})s?\\b`,
787
+ ).exec(text) ??
788
+ new RegExp(
789
+ `\\b(?:${PART_NOUNS.join('|')})s?\\s+(?:with\\s+an?\\s+|in\\s+|is\\s+)?(${COLOR_WORDS.join('|')})\\b(?!\\s+(?:text|labels?|writing|words))`,
790
+ ).exec(text);
791
+ const fillWord = Boolean(fillMatch);
792
+ // A fill named outright ("a blue tint") keeps the background aspect.
793
+ const namedFill =
794
+ /background|fill|gradient|glossy|\btint(ed)?\b|\bbg\b/.test(text) ||
795
+ fillWord;
714
796
  if (
715
797
  intents.includes('text') &&
716
798
  intents.includes('background') &&
717
- !/background|fill|gradient|glossy/.test(text) &&
799
+ !namedFill &&
718
800
  !(/\bwhite\b/.test(text) && !whiteText)
719
801
  )
720
802
  intents = intents.filter(g => g !== 'background');
803
+ // "border color" or "a gray border" is the border's color, not a fill; a
804
+ // color word for anything else ("a dark card with a border", "the card
805
+ // color and its border", "colored buttons") is the fill's.
806
+ const looseColor = new RegExp(
807
+ `(?<!\\b(border|outline|stroke|edge)\\s)\\b(${[...COLOR_WORDS, 'dark', 'light', 'colou?r(ed)?'].join('|')})\\b(?!\\s+(border|outline|stroke|edge|text|labels?)s?\\b)`,
808
+ ).test(text);
809
+ if (
810
+ intents.includes('border') &&
811
+ intents.includes('background') &&
812
+ !namedFill &&
813
+ !looseColor
814
+ )
815
+ intents = intents.filter(g => g !== 'background');
721
816
  if (!intents.length && parts.length) intents = [null];
722
817
  const design = Object.keys(DESIGN).filter(w => text.includes(w));
723
818
  const tracking = /letter ?spacing|tracking|kerning/.test(text);
@@ -741,12 +836,36 @@ export function answerHow(ctx, question) {
741
836
  if (g === 'font' && /bold|heav/.test(text)) return '700';
742
837
  if (g === 'font' && /\b(light(er)?|thin)\b/.test(text)) return '300';
743
838
  if (g === 'text' && whiteText) return '"#ffffff"';
744
- if (g === 'text' && /\baccent (text|labels?)\b/.test(text))
839
+ if (g === 'text' && /\bdark (text|labels?|writing|words)\b/.test(text))
840
+ return '"#111827"';
841
+ if (g === 'background' && fillMatch) {
842
+ const named = NAMED_FILLS[fillMatch[1]];
843
+ if (named) return `"${named}"`;
844
+ }
845
+ if (g === 'border')
846
+ return `"${/\bthick\b/.test(text) ? '2px' : '1px'} solid <color>"`;
847
+ if (g === 'text' && /\baccent[- ]?(colou?red )?(text|labels?)\b/.test(text))
745
848
  return '"var(--color-text-accent)"';
746
849
  if (g === 'background' && /\bwhite\b/.test(text) && !whiteText)
747
850
  return '"#ffffff"';
748
851
  return '<value>';
749
852
  };
853
+ /**
854
+ * A value for one token, of its own type: a whole border value suits only
855
+ * the border property, so a color token takes a color and a width token a
856
+ * width.
857
+ * @param {string} token @param {string} group
858
+ */
859
+ const tokenValue = (token, group) => {
860
+ const v = V(group);
861
+ const whole = /\s(solid|dashed|dotted)\s/.test(v);
862
+ if (!whole) return v;
863
+ const type = C.typeOf(token);
864
+ if (type === 'color') return '"<color>"';
865
+ if (type === 'size' || /width/.test(token))
866
+ return /\b2px\b/.test(v) ? '2px' : '1px';
867
+ return '<value>';
868
+ };
750
869
  for (const raw of parts.slice(0, 3)) {
751
870
  let [part, wp, wv] = raw.split(':');
752
871
  const named = Boolean(wp);
@@ -902,11 +1021,14 @@ export function answerHow(ctx, question) {
902
1021
  : group === 'font'
903
1022
  ? 'font-family'
904
1023
  : DIRECT[group];
1024
+ const restingBorder =
1025
+ group === 'border' && list.every(r => r.when.some(w => /:/.test(w)));
905
1026
  const tokenRoute =
906
1027
  (group === 'text' || group === 'background' || group === 'border') &&
1028
+ !restingBorder &&
907
1029
  !/gradient|inset/.test(V(group));
908
1030
  results.push({
909
- text: `${part} ${aspect ? (tracking ? 'letter spacing' : 'weight') : group}${when ? ` (${wp} ${wv})` : ''}: ${list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : inherited ? `inherits the page's text color (${inherited} for the whole theme); set the property for this part alone` : 'no token of its own; set the property directly'}`,
1031
+ text: `${part} ${aspect ? (tracking ? 'letter spacing' : 'weight') : group}${when ? ` (${wp} ${wv})` : ''}: ${restingBorder ? `the resting border is the border property (no token sets it)${list.length ? `; in states it reads ${list.map(r => r.token + C.fmtWhen(r.when)).join(', ')}` : ''}` : list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : inherited ? `inherits the page's text color (${inherited} for the whole theme); set the property for this part alone` : 'no token of its own; set the property directly'}`,
910
1032
  commands: [
911
1033
  `${P} set <theme> ${direct} ${V(group)} --on ${part}${when} # direct: always works`,
912
1034
  ...(inherited
@@ -917,7 +1039,7 @@ export function answerHow(ctx, question) {
917
1039
  .slice(0, 2)
918
1040
  .map(
919
1041
  r =>
920
- `${P} set <theme> ${r.token} ${V(group)} --on ${part} # via the token${C.fmtWhen(r.when)}`,
1042
+ `${P} set <theme> ${r.token} ${tokenValue(r.token, group)} --on ${part} # via the token${C.fmtWhen(r.when)}`,
921
1043
  )
922
1044
  : []),
923
1045
  ],
@@ -973,14 +1095,14 @@ export function answerHow(ctx, question) {
973
1095
  text: DIALS[dial].help,
974
1096
  commands: DIALS[dial].examples.map(e => `${P} ${e}`),
975
1097
  });
976
- // Text color comes from the text tokens first; the brand color after.
977
- if (g === 'text') results.push(...wholeThemeTokens(ctx, g));
1098
+ // Text and background colors come from their tokens first; the brand
1099
+ // color after.
1100
+ results.push(...wholeThemeTokens(ctx, g));
978
1101
  if (g === 'background' || g === 'text')
979
1102
  results.push({
980
1103
  text: DIALS.accent.help,
981
1104
  commands: DIALS.accent.examples.map(e => `${P} ${e}`),
982
1105
  });
983
- if (g !== 'text') results.push(...wholeThemeTokens(ctx, g));
984
1106
  }
985
1107
  }
986
1108
  if (!results.length) {
@@ -19,7 +19,7 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
19
19
  part: string;
20
20
  prop: string;
21
21
  when: string;
22
- }>>) => string;
22
+ }>>, target?: string) => string;
23
23
  showsCorners: (target: string) => boolean;
24
24
  groupOfToken: (t: string) => string | null;
25
25
  groupOfProp: (p: string) => string | null;
@@ -219,13 +219,18 @@ export function makeCompiler(project, parts) {
219
219
  return out;
220
220
  }
221
221
 
222
- /** One line for where a token feeds. @param {ReturnType<typeof feeds>} list */
223
- const fmtFeeds = list =>
222
+ /**
223
+ * One line for where a token feeds. A part inside `target` (a button in a
224
+ * toast) is named as inside it, so the line never reads as every button.
225
+ * @param {ReturnType<typeof feeds>} list
226
+ * @param {string} [target]
227
+ */
228
+ const fmtFeeds = (list, target) =>
224
229
  [
225
230
  ...new Set(
226
231
  list.map(
227
232
  f =>
228
- `${f.prop}${f.part ? ` on ${f.part}` : ''}${f.when ? ` (when ${f.when})` : ''}`,
233
+ `${f.prop}${f.part ? ` on ${f.part}${target && f.part !== target ? ` inside ${target}` : ''}` : ''}${f.when ? ` (when ${f.when})` : ''}`,
229
234
  ),
230
235
  ),
231
236
  ]
@@ -270,7 +275,7 @@ export function makeCompiler(project, parts) {
270
275
  return null;
271
276
  const direct = g === 'text' ? 'color' : 'background-color';
272
277
  return {
273
- message: `${target} reads ${token} only for ${fmtFeeds(fed)}, not for its ${g}, so this would not change what you expect.`,
278
+ message: `${target} reads ${token} only for ${fmtFeeds(fed, target)}, not for its ${g}, so this would not change what you expect.`,
274
279
  run: [
275
280
  `${P} set ${theme} ${direct} ${quote(value)} --on ${target} # sets its ${g} directly`,
276
281
  `${HOW} ${target}`,
@@ -27,7 +27,7 @@ export function context(cwd: string): Promise<{
27
27
  part: string;
28
28
  prop: string;
29
29
  when: string;
30
- }>>) => string;
30
+ }>>, target?: string) => string;
31
31
  showsCorners: (target: string) => boolean;
32
32
  groupOfToken: (t: string) => string | null;
33
33
  groupOfProp: (p: string) => string | null;
@@ -162,7 +162,7 @@ export function fontNotes(ctx, data) {
162
162
  : 'system';
163
163
  notes.push(
164
164
  installed
165
- ? `the app loads this font with one import: import '${pkg}';`
165
+ ? `${family} is installed (${pkg}), so the previews load it; the app loads it with one import: import '${pkg}';`
166
166
  : `${family} is not installed, so it does not load: the previews and the app show the next font in the stack. Install it: ${installLine(ctx.project.cwd, [pkg])}. Then the preview imports it on the next set or show, and the app imports it once: import '${pkg}'; Until then, the closest font that needs no install is ${near}: ${P} set ${data.name} font ${near}`,
167
167
  );
168
168
  }
@@ -18,12 +18,14 @@ import {
18
18
  KEY_TOKENS,
19
19
  LIKE,
20
20
  P,
21
+ SPACING,
21
22
  TYPE_STYLES,
22
23
  familyOf,
23
24
  } from './_tables.mjs';
24
25
  import {
25
26
  commitTheme,
26
27
  compileTheme,
28
+ cornerPx,
27
29
  contrastProblems,
28
30
  describe,
29
31
  keyOf,
@@ -40,6 +42,7 @@ import {
40
42
  buildTheme,
41
43
  } from './_settings.mjs';
42
44
  import {checkSetting} from './_check.mjs';
45
+ import {MODAL} from './_compiler.mjs';
43
46
  import {
44
47
  PALETTE_DIALS,
45
48
  VIBRANCY_DEFAULT,
@@ -122,7 +125,11 @@ export async function themeEditNew(name, options = {}) {
122
125
  css: shown(cwd, f.css),
123
126
  module: shown(cwd, f.js),
124
127
  },
125
- settings: data.settings.map(describe),
128
+ // Every setting it applied: mode is the theme's, not a setting entry.
129
+ settings: [
130
+ ...(settings.mode != null ? [`mode = ${data.mode} (whole theme)`] : []),
131
+ ...data.settings.map(describe),
132
+ ],
126
133
  notes,
127
134
  problems: r.problems,
128
135
  ...p,
@@ -306,23 +313,41 @@ async function change(sub, slug, thing, value, options) {
306
313
  paletteMapping(cwd, slug, data, base, ctx.project.core.tokenDefaults),
307
314
  s.thing,
308
315
  slug,
316
+ modesOf(data),
309
317
  ),
310
318
  );
311
319
  if (PALETTE_DIALS.includes(s.thing) && sub === 'undo')
312
320
  notes.push(
313
321
  `the ${s.thing} color is no longer generated, and the tokens it fed go back to the base theme's values`,
314
322
  );
315
- if (s.thing === 'vibrancy')
323
+ if (s.thing === 'neutral' && sub === 'set') {
324
+ // Only the theme's own modes; a dark theme gets no white-page offer.
325
+ const modes = modesOf(data);
326
+ const pages = modes
327
+ .map(m => [m, base[m]['--color-background-body']])
328
+ .filter(([, v]) => v)
329
+ .map(([m, v]) => `${v} in ${m}`);
330
+ notes.push(
331
+ `the page background stays the base theme's${pages.length ? ` (${pages.join(', ')})` : ''}${
332
+ modes.includes('light')
333
+ ? `; for a white or off-white page: ${P} set ${slug} --color-background-body "#ffffff"${modes.length > 1 ? ' --mode light' : ''}`
334
+ : `; for another page color: ${P} set ${slug} --color-background-body "<color>"`
335
+ }`,
336
+ );
337
+ }
338
+ if (s.thing === 'vibrancy') {
316
339
  notes.push(
317
340
  sub === 'set'
318
- ? `every generated color is made again at vibrancy ${s.value} (0 is gray, 100 the most vivid, ${VIBRANCY_DEFAULT} the default)`
319
- : `every generated color is made again at the default vibrancy, ${VIBRANCY_DEFAULT}`,
341
+ ? `every color this theme sets is made again at vibrancy ${s.value} (0 is gray, 100 the most vivid, ${VIBRANCY_DEFAULT} the default)`
342
+ : `every color this theme sets is made again at the default vibrancy, ${VIBRANCY_DEFAULT}`,
320
343
  );
344
+ notes.push(...unsetColorNotes(data, base, slug));
345
+ }
321
346
  if (s.thing === 'font' && sub === 'set')
322
347
  notes.unshift(...fontNotes(ctx, {...data, settings: [s]}));
323
348
  if (s.thing === 'type' || s.thing === 'headings')
324
349
  for (const [m, why] of maskedSettings(data))
325
- notes.push(`${describe(m)} is partly hidden: ${why}`);
350
+ notes.push(`${describe(m)}: ${why}`);
326
351
  if (s.thing === 'type' && sub === 'set' && TYPE_STYLES[s.value].ratio > 1.2)
327
352
  notes.push(
328
353
  'text below the base size keeps its standard sizes, so small text stays readable',
@@ -337,6 +362,8 @@ async function change(sub, slug, thing, value, options) {
337
362
  sub === 'set'
338
363
  ? s
339
364
  : /** @type {import('./_settings.mjs').Setting} */ (prev),
365
+ // On undo, the setting above is the one removed, named as such.
366
+ ...(sub === 'undo' && prev ? {removed: prev} : {}),
340
367
  replaced: sub === 'set' ? prev : null,
341
368
  was: null,
342
369
  notes,
@@ -359,6 +386,34 @@ async function change(sub, slug, thing, value, options) {
359
386
  };
360
387
  }
361
388
 
389
+ /**
390
+ * Which status colors the theme does not set, so they keep the base theme's
391
+ * values whatever the vibrancy, with the commands that bring them in: each
392
+ * seeded with the base theme's own color, so it is then generated at the
393
+ * theme's vibrancy. Colored cards and other info-tinted surfaces follow info.
394
+ * @param {import('./_settings.mjs').ThemeData} data
395
+ * @param {{light: Record<string, string>, dark: Record<string, string>}} base
396
+ * @param {string} slug
397
+ * @returns {string[]}
398
+ */
399
+ function unsetColorNotes(data, base, slug) {
400
+ const word = /** @type {Record<string, string>} */ ({
401
+ info: '--color-info',
402
+ success: '--color-success',
403
+ warning: '--color-warning',
404
+ danger: '--color-error',
405
+ });
406
+ const unset = Object.keys(word).filter(
407
+ d => !data.settings.some(x => x.source === 'dial' && x.thing === d),
408
+ );
409
+ if (!unset.length) return [];
410
+ return [
411
+ `${unset.join(', ')} ${unset.length > 1 ? 'are' : 'is'} not set by this theme, so ${unset.length > 1 ? 'they keep' : 'it keeps'} the base theme's colors at any vibrancy${unset.includes('info') ? ', and so do surfaces tinted with info, such as colored cards' : ''}. To include ${unset.length > 1 ? 'them' : 'it'}: ${unset
412
+ .map(d => `${P} set ${slug} ${d} "${base.light[word[d]] ?? '<color>'}"`)
413
+ .join('; ')}`,
414
+ ];
415
+ }
416
+
362
417
  /**
363
418
  * Every setting of a theme, key resolved values, problems it caused, the
364
419
  * sample page and the theme-building page with every component.
@@ -409,12 +464,16 @@ export async function themeEditShow(theme, options = {}) {
409
464
  return {...s, parts: partsOf(ctx, s), ...(masked ? {masked} : {})};
410
465
  }),
411
466
  notes: fontNotes(ctx, data),
467
+ // A size, number or font is the same in both modes: one value.
412
468
  resolved: Object.fromEntries(
413
469
  KEY_TOKENS.map(k => [
414
470
  k,
415
- Object.fromEntries(modes.map(m => [m, res[m][k] ?? null])),
471
+ MODAL.has(ctx.C.typeOf(k))
472
+ ? Object.fromEntries(modes.map(m => [m, res[m][k] ?? null]))
473
+ : (res[modes[0]][k] ?? null),
416
474
  ]),
417
475
  ),
476
+ partValues: partValues(ctx, data, res, modes[0]),
418
477
  ...colorsReport(pal, data),
419
478
  problems,
420
479
  preview,
@@ -428,6 +487,58 @@ export async function themeEditShow(theme, options = {}) {
428
487
  };
429
488
  }
430
489
 
490
+ /**
491
+ * Each corners or spacing dial set on a part or group, with what its parts
492
+ * get, beside the whole-theme value: `corners large on containers ->
493
+ * border-radius 12px on card, dialog, ... (whole theme: --radius-container
494
+ * 10px)`.
495
+ * @param {import('./_settings.mjs').Ctx} ctx
496
+ * @param {import('./_settings.mjs').ThemeData} data
497
+ * @param {{light: Record<string, string>, dark: Record<string, string>}} res
498
+ * @param {'light' | 'dark'} mode
499
+ * @returns {string[]}
500
+ */
501
+ function partValues(ctx, data, res, mode) {
502
+ return data.settings
503
+ .filter(
504
+ s =>
505
+ s.source === 'dial' && s.on && ['corners', 'spacing'].includes(s.thing),
506
+ )
507
+ .map(s => {
508
+ const parts = partsOf(ctx, s);
509
+ const listed = `${parts.slice(0, 4).join(', ')}${parts.length > 4 ? `, and ${parts.length - 4} more` : ''}`;
510
+ if (s.thing === 'corners') {
511
+ const px = cornerPx(s.value);
512
+ // The radius token each part's resting corners read, as the whole-
513
+ // theme value they would have without this setting.
514
+ // A part the census saw closed (a menu, a popover) has no recorded
515
+ // radius: like every Core surface, it reads the container radius.
516
+ /** @type {Map<string, string[]>} */
517
+ const byToken = new Map();
518
+ for (const t of parts) {
519
+ const reads = ctx.C.partReads(t, 'corners').filter(x =>
520
+ x.props.includes('border-radius'),
521
+ );
522
+ const token =
523
+ (reads.find(x => x.when.includes('')) ?? reads[0])?.token ??
524
+ (['containers', 'menus'].includes(familyOf(t) ?? '')
525
+ ? '--radius-container'
526
+ : '--radius-element');
527
+ byToken.set(token, [...(byToken.get(token) ?? []), t]);
528
+ }
529
+ const whole = [...byToken]
530
+ .map(
531
+ ([token, ts]) =>
532
+ `${token} ${res[mode][token] ?? 'unset'}${byToken.size > 1 ? ` for ${ts.join(', ')}` : ''}`,
533
+ )
534
+ .join('; ');
535
+ return `${describe(s)} -> border-radius ${px >= 9999 ? 'fully round' : `${px}px`} on ${listed} (whole theme: ${whole})`;
536
+ }
537
+ const f = SPACING.find(([n]) => n === s.value)?.[1] ?? 1;
538
+ return `${describe(s)} -> spacing x${f} inside ${listed} (whole theme: --spacing-4 ${res[mode]['--spacing-4'] ?? 'unset'})`;
539
+ });
540
+ }
541
+
431
542
  /**
432
543
  * The colors part of `show`: the vibrancy, each color with its seed and the
433
544
  * shade each token uses in light and dark (an exact token setting wins and
@@ -443,7 +554,19 @@ function colorsReport(pal, data) {
443
554
  );
444
555
  /** @param {import('./_palette.mjs').StopRef} r */
445
556
  const shade = r =>
446
- `${r.stop}${r.alpha ? ` at opacity ${r.alpha}` : ''} ${r.color}`;
557
+ `${r.stop}${r.alpha ? ` at opacity ${r.alpha}` : ''} ${r.color}${r.from ? ' (your exact color)' : ''}`;
558
+ /** What the user set for each token exactly, by mode when it differs. */
559
+ const exactValue = /** @type {Record<string, string>} */ ({});
560
+ for (const s of data.settings)
561
+ if (s.source === 'token' && !s.on)
562
+ exactValue[s.thing] = [
563
+ ...(exactValue[s.thing] ? [exactValue[s.thing]] : []),
564
+ s.mode ? `${s.mode} ${s.value}` : s.value,
565
+ ].join(', ');
566
+ // A theme with one mode lists only that mode's shades.
567
+ const modes = modesOf(data);
568
+ /** @param {{light: import('./_palette.mjs').StopRef, dark: import('./_palette.mjs').StopRef}} v */
569
+ const shades = v => modes.map(m => `${m} ${shade(v[m])}`).join(', ');
447
570
  return {
448
571
  vibrancy: pal.vibrancy,
449
572
  colors: pal.families.map(fam => ({
@@ -454,16 +577,21 @@ function colorsReport(pal, data) {
454
577
  .filter(([, v]) => v.family === fam.id)
455
578
  .map(([k, v]) => [
456
579
  k,
457
- `light ${shade(v.light)}, dark ${shade(v.dark)}${exact.has(k) ? ' (your exact setting wins)' : ''}`,
580
+ exact.has(k)
581
+ ? `${exactValue[k]} (your exact setting wins over the generated ${shades(v)})`
582
+ : shades(v),
458
583
  ]),
459
584
  ),
460
585
  })),
461
586
  colorNotes: pal.contrast
587
+ .filter(c => modes.includes(c.mode))
462
588
  .filter(c => !c.pass || c.stop !== c.preferred)
463
589
  .map(c =>
464
- c.pass
465
- ? `${c.token} ${c.mode}: shade ${c.stop}, not ${c.preferred}, so it reads at ${c.ratio}:1 on ${c.against}`
466
- : `${c.token} ${c.mode}: only ${c.ratio}:1 on ${c.against} at shade ${c.stop} (needs ${c.needs}:1)`,
590
+ c.against.startsWith('the text on it')
591
+ ? `${c.token} ${c.mode}: shade ${c.stop}, not your exact color: ${c.against.slice('the text on it: '.length)}`
592
+ : c.pass
593
+ ? `${c.token} ${c.mode}: shade ${c.stop}, not ${c.preferred}, so it reads at ${c.ratio}:1 on ${c.against}`
594
+ : `${c.token} ${c.mode}: only ${c.ratio}:1 on ${c.against} at shade ${c.stop} (needs ${c.needs}:1)`,
467
595
  ),
468
596
  };
469
597
  }
@@ -408,8 +408,18 @@ const COLOR_QUESTIONS = [
408
408
  export function colorQuestion(question) {
409
409
  const q = question.toLowerCase();
410
410
  // A question about another aspect ("make the text red", "override the
411
- // corner radius") is answered for that aspect, not as a color question.
412
- if (INTENTS.some(([aspect, re]) => aspect !== 'background' && re.test(q)))
411
+ // corner radius", "a yellow background") is answered for that aspect, not
412
+ // as a color question. Color words alone raise the background aspect, so
413
+ // only a background named outright counts, and not for a status: "the
414
+ // error background" is the danger color.
415
+ const status =
416
+ /\b(errors?|danger|destructive|success|warnings?|caution|info|notices?)\b/.test(
417
+ q,
418
+ );
419
+ if (
420
+ INTENTS.some(([aspect, re]) => aspect !== 'background' && re.test(q)) ||
421
+ (/\b(background|bg|backdrop|fill)\b/.test(q) && !status)
422
+ )
413
423
  return null;
414
424
  const hit = COLOR_QUESTIONS.find(([re]) => re.test(q));
415
425
  return hit ? [hit[1](q)] : null;
@@ -57,6 +57,49 @@ const ROWS = [
57
57
 
58
58
  /** @type {Array<{title: string, tree: Tree}>} */
59
59
  export const OVERVIEW_SECTIONS = [
60
+ {
61
+ title: 'Open layers',
62
+ // First on the page, so the layers open below their anchors on load,
63
+ // into space kept free for them: each anchor's cell keeps room for its
64
+ // layer, so nothing sits under one, side by side or stacked.
65
+ tree: h(
66
+ 'Card',
67
+ {variant: 'transparent'},
68
+ h(
69
+ 'Grid',
70
+ {columns: {minWidth: 280, repeat: 'fit'}, gap: 4},
71
+ h(
72
+ 'Card',
73
+ {variant: 'transparent', minHeight: 150},
74
+ h(
75
+ 'Popover',
76
+ {
77
+ isOpen: true,
78
+ label: 'Menu',
79
+ placement: 'below',
80
+ content: h(
81
+ 'VStack',
82
+ {gap: 1},
83
+ h('Text', {type: 'label'}, 'A popover shown open'),
84
+ h('Button', {label: 'Rename', variant: 'ghost', size: 'sm'}),
85
+ h('Button', {label: 'Delete', variant: 'ghost', size: 'sm'}),
86
+ ),
87
+ },
88
+ h('Button', {label: 'Anchor', variant: 'secondary'}),
89
+ ),
90
+ ),
91
+ h(
92
+ 'Card',
93
+ {variant: 'transparent', minHeight: 150},
94
+ h(
95
+ 'Tooltip',
96
+ {isOpen: true, placement: 'below', content: 'A tooltip shown open'},
97
+ h('Button', {label: 'Tooltip anchor', variant: 'secondary'}),
98
+ ),
99
+ ),
100
+ ),
101
+ ),
102
+ },
60
103
  {
61
104
  title: 'Type',
62
105
  tree: h(
@@ -250,32 +293,4 @@ export const OVERVIEW_SECTIONS = [
250
293
  ],
251
294
  }),
252
295
  },
253
- {
254
- title: 'Open layers',
255
- tree: h(
256
- 'HStack',
257
- {gap: 10, align: 'start', wrap: 'wrap'},
258
- h(
259
- 'Popover',
260
- {
261
- isOpen: true,
262
- label: 'Menu',
263
- placement: 'end',
264
- content: h(
265
- 'VStack',
266
- {gap: 1},
267
- h('Text', {type: 'label'}, 'A popover shown open'),
268
- h('Button', {label: 'Rename', variant: 'ghost', size: 'sm'}),
269
- h('Button', {label: 'Delete', variant: 'ghost', size: 'sm'}),
270
- ),
271
- },
272
- h('Button', {label: 'Anchor', variant: 'secondary'}),
273
- ),
274
- h(
275
- 'Tooltip',
276
- {isOpen: true, placement: 'end', content: 'A tooltip shown open'},
277
- h('Button', {label: 'Tooltip anchor', variant: 'secondary'}),
278
- ),
279
- ),
280
- },
281
296
  ];
@@ -62,15 +62,17 @@ export function mappingRows(dial: string): string[];
62
62
  * @param {PaletteMapping | null} pal
63
63
  * @param {string} dial
64
64
  * @param {string} slug
65
+ * @param {Mode[]} [modes] the modes the theme has
65
66
  * @returns {string[]}
66
67
  */
67
- export function paletteNotes(pal: PaletteMapping | null, dial: string, slug: string): string[];
68
+ export function paletteNotes(pal: PaletteMapping | null, dial: string, slug: string, modes?: Mode[]): string[];
68
69
  /** @typedef {'light' | 'dark'} Mode */
69
70
  /** @typedef {import('../theme/theme.type.mjs').TonalPaletteCandidate} Candidate */
70
71
  /**
71
72
  * One token pointed at a palette stop in each mode.
72
73
  * @typedef {object} StopRef
73
74
  * @property {number} stop
75
+ * @property {Mode} [from] - The ramp the stop is from when it is not the token's own mode: a dark fill that keeps the exact color takes the light ramp's stop.
74
76
  * @property {string} color - The stop's color, with `alpha` appended when set.
75
77
  * @property {string} [alpha] - Two hex digits of opacity.
76
78
  */
@@ -109,6 +111,10 @@ export type Candidate = import("../theme/theme.type.mjs").TonalPaletteCandidate;
109
111
  */
110
112
  export type StopRef = {
111
113
  stop: number;
114
+ /**
115
+ * - The ramp the stop is from when it is not the token's own mode: a dark fill that keeps the exact color takes the light ramp's stop.
116
+ */
117
+ from?: Mode | undefined;
112
118
  /**
113
119
  * - The stop's color, with `alpha` appended when set.
114
120
  */