@astryxdesign/cli 0.7.16-canary.ge95b87c → 0.7.16

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 (120) hide show
  1. package/CHANGELOG.md +369 -0
  2. package/README.md +1 -1
  3. package/api/build/_adapter.d.mts +9 -0
  4. package/api/build/_adapter.mjs +24 -0
  5. package/api/build/kit/shell.weights.json +1 -0
  6. package/api/build/kit/shellcall.d.mts +26 -0
  7. package/api/build/kit/shellcall.mjs +87 -0
  8. package/api/build/kit/start.mjs +67 -4
  9. package/api/build/kit/weights.d.mts +15 -0
  10. package/api/build/kit/weights.mjs +27 -0
  11. package/api/component/__fixtures__/resolutions/modules.txt +1 -1
  12. package/api/doctor/_adapter.d.mts +3 -2
  13. package/api/doctor/_adapter.mjs +7 -1
  14. package/api/doctor/doctor.d.mts +8 -0
  15. package/api/doctor/doctor.mjs +53 -8
  16. package/api/doctor/theme-checks.mjs +157 -8
  17. package/api/icon/_adapter.d.mts +7 -3
  18. package/api/icon/_adapter.mjs +12 -3
  19. package/api/icon/icon.type.d.mts +15 -0
  20. package/api/icon/icon.type.mjs +10 -3
  21. package/api/icon/iconUse.doc.mjs +19 -5
  22. package/api/icon/list/list.mjs +7 -1
  23. package/api/icon/use/use.d.mts +8 -5
  24. package/api/icon/use/use.mjs +95 -13
  25. package/api/init/run/run.mjs +1 -0
  26. package/api/template/template.type.d.mts +6 -2
  27. package/api/template/template.type.mjs +2 -1
  28. package/api/theme/_adapter.mjs +16 -2
  29. package/api/theme/build/build.d.mts +10 -6
  30. package/api/theme/build/build.mjs +42 -29
  31. package/api/theme/generateTonalPalette.doc.mjs +2 -2
  32. package/api/theme/palette/generate/generator.mjs +141 -2
  33. package/api/theme/theme.type.d.mts +39 -0
  34. package/api/theme/theme.type.mjs +21 -0
  35. package/api/theme/themeBuild.doc.mjs +1 -1
  36. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  37. package/api/theme-edit/_adapter.d.mts +1 -0
  38. package/api/theme-edit/_adapter.mjs +79 -21
  39. package/api/theme-edit/_check.d.mts +25 -2
  40. package/api/theme-edit/_check.mjs +251 -61
  41. package/api/theme-edit/_context.d.mts +2 -1
  42. package/api/theme-edit/_context.mjs +19 -1
  43. package/api/theme-edit/_edit.d.mts +16 -0
  44. package/api/theme-edit/_edit.mjs +360 -59
  45. package/api/theme-edit/_how-question.d.mts +8 -0
  46. package/api/theme-edit/_how-question.mjs +169 -22
  47. package/api/theme-edit/_marks.d.mts +13 -0
  48. package/api/theme-edit/_marks.mjs +15 -0
  49. package/api/theme-edit/_palette.d.mts +27 -0
  50. package/api/theme-edit/_palette.mjs +112 -8
  51. package/api/theme-edit/_preview-app.d.mts +46 -1
  52. package/api/theme-edit/_preview-app.mjs +367 -36
  53. package/api/theme-edit/_preview.d.mts +55 -0
  54. package/api/theme-edit/_preview.mjs +231 -6
  55. package/api/theme-edit/_project.d.mts +4 -0
  56. package/api/theme-edit/_project.mjs +27 -6
  57. package/api/theme-edit/_settings.d.mts +61 -2
  58. package/api/theme-edit/_settings.mjs +317 -115
  59. package/api/theme-edit/_tables.mjs +1 -1
  60. package/api/theme-edit/theme-edit.type.d.mts +30 -2
  61. package/api/theme-edit/theme-edit.type.mjs +10 -2
  62. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  63. package/assets/docs/author-a-theme.doc.mjs +1 -1
  64. package/assets/docs/theme.doc.dense.mjs +1 -1
  65. package/assets/docs/theme.doc.mjs +1 -1
  66. package/assets/docs/theme.doc.zh.mjs +4 -3
  67. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  68. package/assets/docs/tree/icon-sets.doc.mjs +63 -8
  69. package/assets/docs.generated.json +2 -2
  70. package/assets/self-audit.generated.json +1 -1
  71. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
  72. package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
  73. package/assets/templates/components.generated.json +1 -1
  74. package/assets/templates/pages/ai-chat/page.tsx +20 -2
  75. package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
  76. package/authoring/config/config.doc.mjs +8 -0
  77. package/authoring/config/parse.d.mts +1 -0
  78. package/authoring/config/parse.mjs +12 -0
  79. package/authoring/config/type.ts +8 -0
  80. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
  81. package/clients/cli/build-id.generated.json +1 -1
  82. package/clients/cli/commands/experimental/icon.mjs +61 -6
  83. package/clients/cli/commands/experimental/theme.mjs +9 -2
  84. package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
  85. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  86. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  87. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  88. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  89. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  90. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  91. package/clients/cli/commands/theme.doc.mjs +7 -2
  92. package/clients/cli/commands/theme.mjs +41 -18
  93. package/clients/cli/commands.generated.json +1 -1
  94. package/clients/cli/index.mjs +25 -5
  95. package/clients/cli/manifest.generated.json +1 -1
  96. package/foundation/agent-docs/agent-docs.mjs +1 -1
  97. package/foundation/config/config-writer.d.mts +23 -0
  98. package/foundation/config/config-writer.mjs +150 -56
  99. package/foundation/config/project.mjs +43 -2
  100. package/foundation/discovery/component-discovery.mjs +6 -5
  101. package/foundation/discovery/icon-set-checks.mjs +164 -48
  102. package/foundation/discovery/icon-set-discovery.d.mts +38 -5
  103. package/foundation/discovery/icon-set-discovery.mjs +50 -6
  104. package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
  105. package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
  106. package/foundation/discovery/icon-set-writer.d.mts +2 -3
  107. package/foundation/discovery/icon-set-writer.mjs +57 -16
  108. package/foundation/discovery/template-icons.d.mts +27 -10
  109. package/foundation/discovery/template-icons.mjs +142 -26
  110. package/foundation/discovery/theme-discovery.d.mts +25 -0
  111. package/foundation/discovery/theme-discovery.mjs +48 -7
  112. package/foundation/fs/gather-cache.mjs +6 -2
  113. package/foundation/integrations/autolink.d.mts +4 -2
  114. package/foundation/integrations/autolink.mjs +4 -2
  115. package/foundation/integrations/cli-requirement.d.mts +16 -5
  116. package/foundation/integrations/cli-requirement.mjs +27 -6
  117. package/foundation/integrations/may-have-integrations.mjs +5 -2
  118. package/foundation/integrations/missing-dependency.d.mts +9 -0
  119. package/foundation/integrations/missing-dependency.mjs +100 -0
  120. package/package.json +6 -6
@@ -2,9 +2,11 @@
2
2
 
3
3
  /**
4
4
  * @file `icon.use` leaf (AST-084 FR8): choose the project's main icon set,
5
- * and any backup sets in order, by writing `experimental.iconSet` in
6
- * astryx.config. With no backup it writes the set name as a string; with
7
- * backups it writes a list, the main set first.
5
+ * any backup sets in order, and the look its icons draw, by writing
6
+ * `experimental.iconSet` and `experimental.iconVariant` in astryx.config in
7
+ * one write. With no backup it writes the set name as a string; with backups
8
+ * it writes a list, the main set first. With no variant it removes
9
+ * `experimental.iconVariant`, so the sets draw their default looks.
8
10
  *
9
11
  * @output the `icon.use` envelope
10
12
  * @position api/icon/use — dispatched by the `experimental icon use` command
@@ -17,9 +19,12 @@ import {
17
19
  iconSetConfigCliWarning,
18
20
  iconSetKey,
19
21
  loadIconProject,
22
+ lookThemeMap,
20
23
  ICON_USE_ORDER_COMMAND,
21
24
  refuseOutsideProject,
22
- setConfigValue,
25
+ setConfigValues,
26
+ iconSetLook,
27
+ iconUseCommand,
23
28
  unlistedIconSets,
24
29
  } from '../_adapter.mjs';
25
30
  import {setsNamed, unusableSet} from '../_records.mjs';
@@ -46,21 +51,69 @@ function oneSet(sets, withdrawn, selector) {
46
51
  return named[0];
47
52
  }
48
53
 
54
+ /**
55
+ * Refuse a variant the main set does not declare: the look a project picks
56
+ * is one of its main set's looks.
57
+ * @param {import('../../../foundation/discovery/icon-set-discovery.mjs').DiscoveredIconSet} main
58
+ * @param {string} selector
59
+ * @param {string[]} backups
60
+ * @param {unknown} variant
61
+ */
62
+ function checkVariant(main, selector, backups, variant) {
63
+ if (typeof variant !== 'string' || variant.trim() === '') {
64
+ throw new AstryxError(
65
+ 'Name the variant every icon draws, or leave out --variant',
66
+ [
67
+ {
68
+ name: `astryx experimental icon --list`,
69
+ reason: "each installed set's variants",
70
+ },
71
+ ],
72
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
73
+ );
74
+ }
75
+ const declared = main.data.variants ?? [];
76
+ if (declared.includes(variant)) return;
77
+ const fallback = main.data.default?.variant;
78
+ throw new AstryxError(
79
+ declared.length === 0
80
+ ? `Icon set "${iconSetKey(main)}" declares no variants: it draws one look, so it takes no --variant.`
81
+ : `Icon set "${iconSetKey(main)}" declares no "${variant}" variant. Its variants: ${declared.join(', ')}.`,
82
+ declared.length === 0
83
+ ? [
84
+ {
85
+ name: iconUseCommand(selector, backups),
86
+ reason: 'use it in its one look',
87
+ },
88
+ ]
89
+ : declared.map(each => ({
90
+ name: iconUseCommand(selector, backups, each),
91
+ reason:
92
+ each === fallback
93
+ ? `its default look, ${each}`
94
+ : `its ${each} look`,
95
+ })),
96
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
97
+ );
98
+ }
99
+
49
100
  /**
50
101
  * Make an installed set the project's main icon set, with backup sets in
51
- * order. A copied template takes each icon from the first set in the list
52
- * that has its meaning.
102
+ * order, and choose the look its icons draw. A copied template takes each
103
+ * icon from the first set in the list that has its meaning, in the project's
104
+ * variant when that set's icon has it.
53
105
  * Experimental (spec:AST-017 FR27): may change or be removed in a patch
54
106
  * release.
55
107
  * @experimental
56
108
  * @param {string} selector a set name, or `<package>/<set>`
57
- * @param {{cwd?: string, backups?: string[]}} [options] `backups`: the
58
- * backup sets, in order
109
+ * @param {{cwd?: string, backups?: string[], variant?: string}} [options]
110
+ * `backups`: the backup sets, in order; `variant`: the look every icon
111
+ * draws, one of the main set's variants
59
112
  * @returns {Promise<import('../icon.type.mjs').IconUseResponse>}
60
113
  */
61
114
  export async function iconUse(
62
115
  selector,
63
- {cwd = process.cwd(), backups = []} = {},
116
+ {cwd = process.cwd(), backups = [], variant} = {},
64
117
  ) {
65
118
  if (typeof selector !== 'string' || selector.trim() === '') {
66
119
  throw new AstryxError(
@@ -79,7 +132,12 @@ export async function iconUse(
79
132
  );
80
133
  }
81
134
  refuseOutsideProject(cwd, 'experimental icon use', 'the app project');
82
- const {projectDir, sets, withdrawn} = await loadIconProject(cwd);
135
+ const {
136
+ projectDir,
137
+ sets,
138
+ withdrawn,
139
+ variant: configured,
140
+ } = await loadIconProject(cwd);
83
141
  const main = oneSet(sets, withdrawn, selector);
84
142
  const backupSets = backups.map(each => oneSet(sets, withdrawn, each));
85
143
  const listed = [main, ...backupSets];
@@ -91,10 +149,16 @@ export async function iconUse(
91
149
  ERROR_CODES.ERR_INVALID_ARGUMENT,
92
150
  );
93
151
  }
152
+ if (variant !== undefined) checkVariant(main, selector, backups, variant);
94
153
  const value = backups.length > 0 ? [selector, ...backups] : selector;
154
+ // One write: the sets, and the look, which is removed when none is named.
155
+ /** @type {Array<[string, string | string[] | null]>} */
156
+ const fields = [['experimental.iconSet', value]];
157
+ if (variant !== undefined) fields.push(['experimental.iconVariant', variant]);
158
+ else if (configured != null) fields.push(['experimental.iconVariant', null]);
95
159
  let written;
96
160
  try {
97
- written = setConfigValue(projectDir, 'experimental.iconSet', value);
161
+ written = setConfigValues(projectDir, fields);
98
162
  } catch (error) {
99
163
  // A protected config, or an unreadable protection source, keeps the
100
164
  // stable code every consumer-file writer uses (spec:AST-040 FR4, FR6).
@@ -109,17 +173,21 @@ export async function iconUse(
109
173
  stable ?? ERROR_CODES.ERR_WRITE_FAILED,
110
174
  );
111
175
  }
176
+ const previousVariant = written.previous[1] ?? null;
112
177
  // An older CLI the project may still run refuses the value just written.
113
178
  const warning = iconSetConfigCliWarning(projectDir, {
114
179
  list: Array.isArray(value),
180
+ variant: variant !== undefined,
115
181
  });
116
182
  // Doctor fails a project that installs several sets and leaves one out.
117
183
  const unlistedSets = sets.filter(set => !listed.includes(set));
118
184
  const unlisted = unlistedSets.map(iconSetKey);
119
185
  const left =
120
186
  unlistedSets.length > 0
121
- ? unlistedIconSets(sets, main, backupSets, unlistedSets)
187
+ ? unlistedIconSets(sets, main, backupSets, unlistedSets, variant)
122
188
  : null;
189
+ const themeMap =
190
+ variant === undefined ? null : lookThemeMap(main.data, variant);
123
191
  return {
124
192
  type: 'icon.use',
125
193
  data: {
@@ -129,11 +197,25 @@ export async function iconUse(
129
197
  iconSet: each,
130
198
  set: iconSetKey(backupSets[index]),
131
199
  })),
200
+ variant: variant ?? null,
132
201
  config: path.relative(projectDir, written.file).split(path.sep).join('/'),
133
202
  created: written.created,
134
- previous: written.previous,
203
+ previous: written.previous[0] ?? null,
204
+ previousVariant:
205
+ typeof previousVariant === 'string' ? previousVariant : null,
135
206
  changed: written.changed,
136
207
  unlisted,
208
+ ...(variant !== undefined
209
+ ? {
210
+ looks: listed.map(set => ({
211
+ set: iconSetKey(set),
212
+ variant: iconSetLook(set, variant),
213
+ })),
214
+ }
215
+ : {}),
216
+ ...(themeMap
217
+ ? {themeMap: {module: main.data.module, export: themeMap}}
218
+ : {}),
137
219
  ...(left ? {next: `${left.problem}. ${left.fix}`} : {}),
138
220
  ...(warning ? {warning} : {}),
139
221
  },
@@ -64,6 +64,7 @@ export function getNextSteps(invocation) {
64
64
  " import { themes, defaultThemeSlug } from './astryx-themes'",
65
65
  ' <Theme theme={themes[defaultThemeSlug]}>...</Theme>',
66
66
  ` Extend an imported theme to customize it. Run \`${invocation} theme eject <slug>\` only to fork source.`,
67
+ ` To make or change a theme: the experimental theme editor, \`${invocation} experimental theme editor new <name> --like neutral\` (then editor set / editor how).`,
67
68
  ` 5. ${invocation} --help for all commands`,
68
69
  '',
69
70
  ];
@@ -132,12 +132,16 @@ export type TemplateIconsReport = {
132
132
  * The main set and each backup set as `<package>/<set>`, in the order icons are looked up; present when the project lists backups.
133
133
  */
134
134
  order?: string[] | undefined;
135
+ /**
136
+ * The look the project's icons draw, as `experimental.iconVariant` names it; present when it is set.
137
+ */
138
+ variant?: string | undefined;
135
139
  /**
136
140
  * Why the project has that set, or none.
137
141
  */
138
142
  reason: string;
139
143
  /**
140
- * Icons rewritten to the first set in the project's list that has them, and the rule that chose each one: a reviewed `exact` or `strong` match, or the icon the set's `map` names for the icon definition the template declares. `target.set` names the set used. `dropped` names the library's sizing props (`size`, `strokeWidth`, `absoluteStrokeWidth`) removed from the icon's elements: an icon set's icons take their size from CSS. `variant` is present when the template's icon draws a look the set's icon does not have: the look asked for and the set's default look used instead.
144
+ * Icons rewritten to the first set in the project's list that has them, and the rule that chose each one: a reviewed `exact` or `strong` match, the icon the set's `map` names for the icon definition the template declares, or `variant`, an icon the template already imports from a set in the list, moved to its export for the project's variant. `target.set` names the set used. `dropped` names the library's sizing props (`size`, `strokeWidth`, `absoluteStrokeWidth`) removed from the icon's elements: an icon set's icons take their size from CSS. `variant` is present when the look asked for, the project's variant or else the look the template's icon draws, is one the set's icon does not have: that look and the set's default look used instead.
141
145
  */
142
146
  mapped: Array<{
143
147
  source: {
@@ -151,7 +155,7 @@ export type TemplateIconsReport = {
151
155
  module: string;
152
156
  export: string;
153
157
  };
154
- by: "match" | "definition";
158
+ by: "match" | "definition" | "variant";
155
159
  dropped?: string[];
156
160
  variant?: {
157
161
  asked: string;
@@ -98,8 +98,9 @@
98
98
  * @property {'selected' | 'none' | 'ambiguous' | 'missing' | 'withdrawn'} status The project's icon-set state.
99
99
  * @property {string | null} set The project's main icon set as `<package>/<set>`, when selected.
100
100
  * @property {string[]} [order] The main set and each backup set as `<package>/<set>`, in the order icons are looked up; present when the project lists backups.
101
+ * @property {string} [variant] The look the project's icons draw, as `experimental.iconVariant` names it; present when it is set.
101
102
  * @property {string} reason Why the project has that set, or none.
102
- * @property {Array<{source: {module: string, export: string}, target: {set: string, package: string, id: string, module: string, export: string}, by: 'match' | 'definition', dropped?: string[], variant?: {asked: string, used: string | null}}>} mapped Icons rewritten to the first set in the project's list that has them, and the rule that chose each one: a reviewed `exact` or `strong` match, or the icon the set's `map` names for the icon definition the template declares. `target.set` names the set used. `dropped` names the library's sizing props (`size`, `strokeWidth`, `absoluteStrokeWidth`) removed from the icon's elements: an icon set's icons take their size from CSS. `variant` is present when the template's icon draws a look the set's icon does not have: the look asked for and the set's default look used instead.
103
+ * @property {Array<{source: {module: string, export: string}, target: {set: string, package: string, id: string, module: string, export: string}, by: 'match' | 'definition' | 'variant', dropped?: string[], variant?: {asked: string, used: string | null}}>} mapped Icons rewritten to the first set in the project's list that has them, and the rule that chose each one: a reviewed `exact` or `strong` match, the icon the set's `map` names for the icon definition the template declares, or `variant`, an icon the template already imports from a set in the list, moved to its export for the project's variant. `target.set` names the set used. `dropped` names the library's sizing props (`size`, `strokeWidth`, `absoluteStrokeWidth`) removed from the icon's elements: an icon set's icons take their size from CSS. `variant` is present when the look asked for, the project's variant or else the look the template's icon draws, is one the set's icon does not have: that look and the set's default look used instead.
103
104
  * @property {Array<{source: {module: string, export: string}, target: {local: string}, definitions: string[], fixes: string[], dropped?: string[], suggestion?: {set: string, id: string, module: string, export: string, confidence: 'likely'}}>} placeholder Icons with a meaning that no set in the project's list has. The template's original import is removed. The written code declares a small placeholder component once (`target.local`, `MissingIcon` unless the file already uses that name), and each use of the icon renders it, with a comment that names the meaning. It needs no package. `fixes` are the commands that give it a real icon: map the definition in the main set, or add a backup set that has it.
104
105
  * @property {Array<{module: string | null, export: string, reason: string, suggestion?: {set: string, id: string, module: string, export: string, confidence: 'likely'}}>} kept Icons left as the template wrote them, with why, and a `likely` reviewed match as a suggestion when the project set has one. Every declared key is mapped, a placeholder, or kept; `module` is null for a key the template does not import, and `export` is `default` for a default import and `*` for a namespace import.
105
106
  * @property {Array<{set: string, license: string, icons: number}>} sets Each set the mapped icons come from, as `<package>/<set>`, with its license and how many icons it gave.
@@ -20,7 +20,7 @@ import {
20
20
  requireCoreDir,
21
21
  } from '../../foundation/fs/paths.mjs';
22
22
  import {tryLock, userCacheDir} from '../../foundation/release/cache.mjs';
23
- import {Project} from '../../foundation/config/project.mjs';
23
+ import {Project, providerLedgerOf} from '../../foundation/config/project.mjs';
24
24
  import {
25
25
  BUNDLED_THEME_PACKAGE,
26
26
  THEMES_DIR,
@@ -137,9 +137,23 @@ async function availableThemeState(cwd, {includeLocal = true} = {}) {
137
137
  // One broken local folder must not hide every other theme: it is
138
138
  // skipped with its reason, and only a lookup of that slug fails.
139
139
  const themes = await project.themes({includeLocal, skipBrokenLocal: true});
140
+ // An installed dependency whose manifest could not load for want of a
141
+ // package it requires has an issue too (INV14), but nothing of it was
142
+ // ever discovered: a lookup in it stays an unknown theme, as before.
143
+ const unloaded = new Set(
144
+ [...providerLedgerOf(project).values()].flatMap(entry =>
145
+ entry.outcome === 'load-failed' &&
146
+ entry.candidate.source === 'autolinked'
147
+ ? [entry.candidate.spec ?? entry.label]
148
+ : [],
149
+ ),
150
+ );
140
151
  return {
141
152
  themes,
142
- issues: await project.issues(),
153
+ issues: (await project.issues()).filter(
154
+ issue =>
155
+ !(issue.code === 'integration_error' && unloaded.has(issue.package)),
156
+ ),
143
157
  skipped: project.skippedLocalThemes(),
144
158
  };
145
159
  } catch (error) {
@@ -49,6 +49,14 @@ export function coreUnavailableMessage(cwd: string, importError: any): string;
49
49
  * @returns {string}
50
50
  */
51
51
  export function normalizeThemeBuildForCompare(content: string): string;
52
+ /**
53
+ * Whether `error` is a build's refusal of a theme that sets a private var
54
+ * (which `doctor` reports in its own check, not as a stale output).
55
+ * CLI-internal.
56
+ * @param {unknown} error
57
+ * @returns {boolean}
58
+ */
59
+ export function isPrivateVarRefusal(error: unknown): boolean;
52
60
  /**
53
61
  * The files a theme source is made of: the source and every local file it
54
62
  * imports, directly or through other local files, read from their import
@@ -75,12 +83,6 @@ export function themeSourceGuesses(file: string, cwd: string): string[];
75
83
  * @param {((warning: string) => void) | null} listener
76
84
  */
77
85
  export function setEditorFolderListener(listener: ((warning: string) => void) | null): void;
78
- /**
79
- * Tell `listener` when a build in this process finds private var errors.
80
- * CLI-internal.
81
- * @param {(() => void) | null} listener
82
- */
83
- export function setPrivateVarErrorListener(listener: (() => void) | null): void;
84
86
  /**
85
87
  * A build's mode flags: what it does (`--check` compares, never writes) and
86
88
  * where (`--out`), carried into every build command a refusal suggests.
@@ -267,6 +269,8 @@ export function themeBuildFamily(files: string[], options: {
267
269
  notices: string[];
268
270
  };
269
271
  }>;
272
+ /** The first words of every file a build writes. */
273
+ export const GENERATED_MARKER: "@generated by `astryx theme build`";
270
274
  /**
271
275
  * The bindings one Core provides: the namespaces interception spreads, the
272
276
  * functions the build calls, and why the import failed, if it did.
@@ -898,7 +898,23 @@ function outsideCheckRemedy(writes, sources, root, args) {
898
898
  }
899
899
 
900
900
  /** The first words of every file a build writes. */
901
- const GENERATED_MARKER = '@generated by `astryx theme build`';
901
+ export const GENERATED_MARKER = '@generated by `astryx theme build`';
902
+
903
+ /** Marks the refusal of a theme that sets a private var. */
904
+ const PRIVATE_VAR_REFUSAL = Symbol('astryx.theme.privateVarRefusal');
905
+
906
+ /**
907
+ * Whether `error` is a build's refusal of a theme that sets a private var
908
+ * (which `doctor` reports in its own check, not as a stale output).
909
+ * CLI-internal.
910
+ * @param {unknown} error
911
+ * @returns {boolean}
912
+ */
913
+ export function isPrivateVarRefusal(error) {
914
+ return Boolean(
915
+ error && /** @type {any} */ (error)[PRIVATE_VAR_REFUSAL] === true,
916
+ );
917
+ }
902
918
 
903
919
  /** @param {string} file @returns {boolean} */
904
920
  function isDirectorySync(file) {
@@ -1128,22 +1144,6 @@ export function setEditorFolderListener(listener) {
1128
1144
  editorFolderListener = listener;
1129
1145
  }
1130
1146
 
1131
- /**
1132
- * Who is told a build found private var errors (the CLI, to exit 1). Set
1133
- * only by the CLI, never by an option of themeBuild.
1134
- * @type {(() => void) | null}
1135
- */
1136
- let privateVarErrorListener = null;
1137
-
1138
- /**
1139
- * Tell `listener` when a build in this process finds private var errors.
1140
- * CLI-internal.
1141
- * @param {(() => void) | null} listener
1142
- */
1143
- export function setPrivateVarErrorListener(listener) {
1144
- privateVarErrorListener = listener;
1145
- }
1146
-
1147
1147
  /**
1148
1148
  * A build's mode flags: what it does (`--check` compares, never writes) and
1149
1149
  * where (`--out`), carried into every build command a refusal suggests.
@@ -4036,17 +4036,20 @@ async function themeBuildInternal(
4036
4036
  logger.warn(` [warn] ${source}${w}`);
4037
4037
  }
4038
4038
 
4039
- // Validate no private vars are set directly
4039
+ // A theme that sets a private var directly is refused before anything is
4040
+ // written (a --check too): it is not a theme the build accepts, so no
4041
+ // output, receipt or success may say otherwise.
4042
+ // The message names no file: a batch and a family name the one it is
4043
+ // about, and a single build is about the file it was given.
4040
4044
  const privateVarErrors = validatePrivateVars(themeDef);
4041
- for (const e of privateVarErrors) {
4042
- warningMessages.push(e);
4043
- logger.error(` [error] ${source}${e}`);
4044
- }
4045
4045
  if (privateVarErrors.length > 0) {
4046
- privateVarErrorListener?.();
4047
- logger.error(
4048
- `\n ${source}${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
4046
+ const refusal = new AstryxError(
4047
+ `${privateVarErrors.join('\n')}\n${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
4048
+ undefined,
4049
+ ERROR_CODES.ERR_THEME_INVALID,
4049
4050
  );
4051
+ Object.defineProperty(refusal, PRIVATE_VAR_REFUSAL, {value: true});
4052
+ throw refusal;
4050
4053
  }
4051
4054
 
4052
4055
  const customHeadingErrors = validateCustomHeadingTypes(themeDef);
@@ -5036,10 +5039,20 @@ export async function themeBuildFamily(
5036
5039
  continue;
5037
5040
  }
5038
5041
  const file = source.file;
5039
- // `check` rides along for the suggestions a member's refusal makes; a
5040
- // prepared member writes nothing either way.
5041
- // prettier-ignore
5042
- const member = await themeBuildInternal(file, {iconsSpecifier: options.iconsSpecifier, check: options.check}, {cwd}, {}, {prepareFamily: true, familyLoader, familyInterception});
5042
+ /** @type {any} */
5043
+ let member;
5044
+ try {
5045
+ // `check` rides along for the suggestions a member's refusal makes; a
5046
+ // prepared member writes nothing either way.
5047
+ // prettier-ignore
5048
+ member = await themeBuildInternal(file, {iconsSpecifier: options.iconsSpecifier, check: options.check}, {cwd}, {}, {prepareFamily: true, familyLoader, familyInterception});
5049
+ } catch (error) {
5050
+ // A member's refusal names the member.
5051
+ if (isPrivateVarRefusal(error))
5052
+ /** @type {Error} */ (error).message =
5053
+ `${file}: ${/** @type {Error} */ (error).message}`;
5054
+ throw error;
5055
+ }
5043
5056
  if (!member || member.type) {
5044
5057
  throw new AstryxError(
5045
5058
  `Theme family member "${file}" did not produce a complete build plan.`,
@@ -29,7 +29,7 @@ export const doc = {
29
29
  name: 'input',
30
30
  type: 'TonalPaletteGenerationInput',
31
31
  description:
32
- 'Families and seeds plus optional modes, shared stops, anchors, vibrancy from 0 to 100 (default 50), and neutral profile.',
32
+ 'Families and seeds plus optional modes, shared stops, anchors, vibrancy from 0 to 100 (default 50), neutral profile, and a dark chroma taper that mutes the dark edge of chromatic families.',
33
33
  required: true,
34
34
  },
35
35
  ],
@@ -43,7 +43,7 @@ export const doc = {
43
43
  throws: [
44
44
  {
45
45
  code: 'Error',
46
- when: 'the request, family, seed, stop layout, mode, or anchor is invalid',
46
+ when: 'the request, family, seed, stop layout, mode, anchor, or dark chroma taper is invalid',
47
47
  },
48
48
  ],
49
49
  examples: [
@@ -111,9 +111,16 @@ export const GENERATION_INPUT_KEYS = Object.freeze([
111
111
  'vibrancy',
112
112
  'neutralProfile',
113
113
  'modeStrategy',
114
+ 'darkChromaTaper',
114
115
  'stops',
115
116
  'families',
116
117
  ]);
118
+ const DARK_CHROMA_TAPER_KEYS = Object.freeze([
119
+ 'edgeMultiplier',
120
+ 'throughStop',
121
+ 'recoverAtStop',
122
+ 'familyMultipliers',
123
+ ]);
117
124
  export const FAMILY_INPUT_KEYS = Object.freeze([
118
125
  'id',
119
126
  'name',
@@ -235,6 +242,8 @@ function anchorPolarAtStop(seed, anchors, stop) {
235
242
  * @param {PaletteMode} mode
236
243
  * @param {number} vibrancy
237
244
  * @param {boolean} coordinateWithOtherFamilies
245
+ * @param {number} [chromaMultiplier] Share of its in-gamut chroma the stop
246
+ * keeps (see darkChromaMultiplier).
238
247
  */
239
248
  function generateCandidate(
240
249
  source,
@@ -242,6 +251,7 @@ function generateCandidate(
242
251
  mode,
243
252
  vibrancy,
244
253
  coordinateWithOtherFamilies,
254
+ chromaMultiplier = 1,
245
255
  ) {
246
256
  const adjustedTone = tone;
247
257
  const adjustedHue = toneAdjustedHue(source.hue, adjustedTone);
@@ -256,9 +266,16 @@ function generateCandidate(
256
266
  toneChromaEnvelope(adjustedTone) *
257
267
  (mode === 'dark' ? DARK_CHROMA_FACTOR : 1);
258
268
  const lightness = toneToOklabLightness(adjustedTone);
269
+ const maxChroma = maxOklchChroma(adjustedHue, lightness);
270
+ // A taper scales the chroma the stop shows after gamut mapping, so a stop
271
+ // the gamut already limits loses the same share as any other stop.
272
+ const shownChroma =
273
+ chromaMultiplier === 1
274
+ ? chroma
275
+ : Math.min(chroma, maxChroma) * chromaMultiplier;
259
276
  return {
260
- hex: oklchClampedHex(lightness, chroma, adjustedHue),
261
- gamutMapped: chroma > maxOklchChroma(adjustedHue, lightness) + 0.000001,
277
+ hex: oklchClampedHex(lightness, shownChroma, adjustedHue),
278
+ gamutMapped: chroma > maxChroma + 0.000001,
262
279
  };
263
280
  }
264
281
 
@@ -490,6 +507,31 @@ function buildDiagnostics(colors, stops, sourceHue, gamutMappedStops, anchors) {
490
507
  };
491
508
  }
492
509
 
510
+ /**
511
+ * The share of its chroma a stop keeps under the request's
512
+ * `darkChromaTaper`: the edge multiplier through `throughStop`, a smoothstep
513
+ * back to 1 at `recoverAtStop`, and 1 from there on. Light ramps, neutral
514
+ * families, and the black and white endpoints keep all of it.
515
+ * @param {NormalizedRequest['darkChromaTaper']} taper
516
+ * @param {NormalizedFamily} family
517
+ * @param {PaletteMode} mode
518
+ * @param {number} stop
519
+ */
520
+ function darkChromaMultiplier(taper, family, mode, stop) {
521
+ if (!taper || mode !== 'dark' || family.kind === 'neutral') return 1;
522
+ if (stop <= 0 || stop >= 100 || stop >= taper.recoverAtStop) return 1;
523
+ // Read own keys only. A family id such as `constructor` must not get a
524
+ // multiplier from the object prototype.
525
+ const edge = Object.hasOwn(taper.familyMultipliers, family.id)
526
+ ? taper.familyMultipliers[family.id]
527
+ : taper.edgeMultiplier;
528
+ if (stop <= taper.throughStop) return edge;
529
+ const recovery = smoothstep(
530
+ (stop - taper.throughStop) / (taper.recoverAtStop - taper.throughStop),
531
+ );
532
+ return edge + (1 - edge) * recovery;
533
+ }
534
+
493
535
  /** @param {NormalizedRequest} request @param {NormalizedFamily} family @param {PaletteMode} mode @returns {GeneratedRamp} */
494
536
  function generateRamp(request, family, mode) {
495
537
  const seedHex = normalizeColor(family.seed);
@@ -508,6 +550,7 @@ function generateRamp(request, family, mode) {
508
550
  mode,
509
551
  request.vibrancy,
510
552
  family.kind !== 'neutral',
553
+ darkChromaMultiplier(request.darkChromaTaper, family, mode, 50),
511
554
  ).hex;
512
555
  for (const stop of request.stops) {
513
556
  const source = anchorPolarAtStop(seed, anchors, stop);
@@ -517,6 +560,7 @@ function generateRamp(request, family, mode) {
517
560
  mode,
518
561
  request.vibrancy,
519
562
  family.kind !== 'neutral',
563
+ darkChromaMultiplier(request.darkChromaTaper, family, mode, stop),
520
564
  );
521
565
  colors[stop] = generated.hex;
522
566
  if (generated.gamutMapped) gamutMappedStops.push(stop);
@@ -602,6 +646,95 @@ function buildCoordinationDiagnostics(request, families) {
602
646
  });
603
647
  }
604
648
 
649
+ /** @param {unknown} value @param {string} label */
650
+ function assertMultiplier(value, label) {
651
+ if (
652
+ typeof value !== 'number' ||
653
+ !Number.isFinite(value) ||
654
+ value < 0 ||
655
+ value > 1
656
+ ) {
657
+ throw new Error(`${label} must be a number from 0 to 1.`);
658
+ }
659
+ return value;
660
+ }
661
+
662
+ /**
663
+ * The request's dark chroma taper, checked against its stops and families,
664
+ * or undefined when the request has none. The receipt records the taper, so
665
+ * a field the taper does not read fails instead of changing nothing.
666
+ * @param {unknown} taper
667
+ * @param {number[]} stops
668
+ * @param {NormalizedFamily[]} families
669
+ * @returns {NormalizedRequest['darkChromaTaper']}
670
+ */
671
+ function normalizeDarkChromaTaper(taper, stops, families) {
672
+ if (taper == null) return undefined;
673
+ if (typeof taper !== 'object' || Array.isArray(taper)) {
674
+ throw new Error('darkChromaTaper must be an object.');
675
+ }
676
+ const fields = /** @type {Record<string, unknown>} */ (taper);
677
+ const unread = Object.keys(fields).filter(
678
+ key => !DARK_CHROMA_TAPER_KEYS.includes(key),
679
+ );
680
+ if (unread.length > 0) {
681
+ throw new Error(
682
+ `darkChromaTaper does not read ${unread.join(', ')}; it reads ${DARK_CHROMA_TAPER_KEYS.join(', ')}.`,
683
+ );
684
+ }
685
+ const {edgeMultiplier, throughStop, recoverAtStop, familyMultipliers} =
686
+ fields;
687
+ const edge = assertMultiplier(
688
+ edgeMultiplier,
689
+ 'darkChromaTaper.edgeMultiplier',
690
+ );
691
+ if (typeof throughStop !== 'number' || !stops.includes(throughStop)) {
692
+ throw new Error(
693
+ 'darkChromaTaper.throughStop must be a stop in the requested stop layout.',
694
+ );
695
+ }
696
+ if (
697
+ typeof recoverAtStop !== 'number' ||
698
+ !stops.includes(recoverAtStop) ||
699
+ recoverAtStop <= throughStop
700
+ ) {
701
+ throw new Error(
702
+ 'darkChromaTaper.recoverAtStop must be a stop in the requested stop layout after throughStop.',
703
+ );
704
+ }
705
+ if (
706
+ familyMultipliers != null &&
707
+ (typeof familyMultipliers !== 'object' || Array.isArray(familyMultipliers))
708
+ ) {
709
+ throw new Error('darkChromaTaper.familyMultipliers must be an object.');
710
+ }
711
+ /** @type {Record<string, number>} */
712
+ const multipliers = {};
713
+ for (const [id, value] of Object.entries(familyMultipliers ?? {})) {
714
+ const family = families.find(candidate => candidate.id === id);
715
+ if (!family) {
716
+ throw new Error(
717
+ `darkChromaTaper.familyMultipliers names unknown family ${id}.`,
718
+ );
719
+ }
720
+ if (family.kind === 'neutral') {
721
+ throw new Error(
722
+ `darkChromaTaper.familyMultipliers names neutral family ${id}; the taper changes only chromatic families.`,
723
+ );
724
+ }
725
+ multipliers[id] = assertMultiplier(
726
+ value,
727
+ `darkChromaTaper.familyMultipliers.${id}`,
728
+ );
729
+ }
730
+ return {
731
+ edgeMultiplier: edge,
732
+ throughStop,
733
+ recoverAtStop,
734
+ familyMultipliers: multipliers,
735
+ };
736
+ }
737
+
605
738
  /** @param {TonalPaletteGenerationInput} input @returns {NormalizedRequest} */
606
739
  export function normalizeGenerationRequest(input) {
607
740
  if (!input || typeof input !== 'object' || Array.isArray(input)) {
@@ -708,12 +841,18 @@ export function normalizeGenerationRequest(input) {
708
841
  if (!NEUTRAL_PROFILES.includes(neutralProfile)) {
709
842
  throw new Error(`Unknown neutral profile: ${String(neutralProfile)}`);
710
843
  }
844
+ const darkChromaTaper = normalizeDarkChromaTaper(
845
+ input.darkChromaTaper,
846
+ stops,
847
+ normalizedFamilies,
848
+ );
711
849
  /** @type {NormalizedRequest} */
712
850
  const request = {
713
851
  recipe: PALETTE_RECIPE,
714
852
  vibrancy: input.vibrancy ?? 50,
715
853
  neutralProfile,
716
854
  modeStrategy,
855
+ ...(darkChromaTaper ? {darkChromaTaper} : {}),
717
856
  stops,
718
857
  families: normalizedFamilies,
719
858
  };