@astryxdesign/cli 0.7.17 → 0.7.18-canary.g32556bb

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 (261) hide show
  1. package/README.md +1 -1
  2. package/api/discover/_adapter.d.mts +7 -5
  3. package/api/discover/_adapter.mjs +12 -11
  4. package/api/docs/_adapter.d.mts +19 -2
  5. package/api/docs/_adapter.mjs +66 -5
  6. package/api/doctor/_adapter.d.mts +11 -62
  7. package/api/doctor/_adapter.mjs +242 -472
  8. package/api/doctor/doctor.d.mts +1 -1
  9. package/api/doctor/doctor.mjs +3 -3
  10. package/api/doctor/theme-checks.mjs +37 -45
  11. package/api/error.d.mts +21 -0
  12. package/api/error.mjs +89 -0
  13. package/api/hook/list/list.d.mts +1 -1
  14. package/api/icon/_adapter.d.mts +8 -0
  15. package/api/icon/_adapter.mjs +17 -0
  16. package/api/icon/_authoring.mjs +6 -6
  17. package/api/icon/_default-look.mjs +16 -16
  18. package/api/icon/add/add.mjs +3 -3
  19. package/api/icon/exportIconIndex.doc.mjs +2 -2
  20. package/api/icon/icon.doc.mjs +2 -2
  21. package/api/icon/icon.type.d.mts +4 -0
  22. package/api/icon/icon.type.mjs +2 -1
  23. package/api/icon/search/icon-index.mjs +16 -3
  24. package/api/icon/search/search.d.mts +15 -5
  25. package/api/icon/search/search.mjs +74 -16
  26. package/api/icon/use/use.mjs +4 -4
  27. package/api/render/_adapter.mjs +233 -40
  28. package/api/render/render.type.d.mts +1 -1
  29. package/api/render/render.type.mjs +1 -1
  30. package/api/search/ORDERING.md +2 -2
  31. package/api/search/_adapter.mjs +4 -0
  32. package/api/search/_candidate-score.mjs +32 -8
  33. package/api/search/_cards.json +1 -1
  34. package/api/search/_compound.d.mts +0 -1
  35. package/api/search/_compound.mjs +93 -2
  36. package/api/search/_icons.d.mts +4 -2
  37. package/api/search/_icons.mjs +4 -2
  38. package/api/search/_lexical.mjs +177 -17
  39. package/api/search/_order.d.mts +3 -1
  40. package/api/search/_order.mjs +16 -5
  41. package/api/search/_result.d.mts +9 -0
  42. package/api/search/_result.mjs +10 -0
  43. package/api/search/_score.mjs +21 -3
  44. package/api/swizzle/_moduleGraph.d.mts +8 -0
  45. package/api/swizzle/_moduleGraph.mjs +61 -3
  46. package/api/template/copy/copy.mjs +5 -3
  47. package/api/template/template.type.d.mts +3 -3
  48. package/api/template/template.type.mjs +3 -3
  49. package/api/theme/_adapter.mjs +48 -12
  50. package/api/theme/build/build.d.mts +4 -0
  51. package/api/theme/build/build.mjs +69 -18
  52. package/api/theme/build/style-keys.mjs +4 -5
  53. package/api/theme/build/theme-object.mjs +5 -0
  54. package/api/theme/palette/generate/color.d.mts +47 -0
  55. package/api/theme/palette/generate/color.mjs +58 -1
  56. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  57. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  58. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  59. package/api/theme/palette/generate/editor-look.mjs +550 -0
  60. package/api/theme/palette/generate/mapping.d.mts +94 -9
  61. package/api/theme/palette/generate/mapping.mjs +94 -22
  62. package/api/theme-edit/_adapter.mjs +13 -2
  63. package/api/theme-edit/_catalog.d.mts +13 -13
  64. package/api/theme-edit/_catalog.mjs +66 -28
  65. package/api/theme-edit/_check.d.mts +82 -6
  66. package/api/theme-edit/_check.mjs +1270 -238
  67. package/api/theme-edit/_color.d.mts +74 -0
  68. package/api/theme-edit/_color.mjs +168 -3
  69. package/api/theme-edit/_compiler.d.mts +3 -5
  70. package/api/theme-edit/_compiler.mjs +122 -23
  71. package/api/theme-edit/_context.d.mts +55 -12
  72. package/api/theme-edit/_context.mjs +114 -60
  73. package/api/theme-edit/_css.d.mts +11 -0
  74. package/api/theme-edit/_css.mjs +40 -0
  75. package/api/theme-edit/_edit.d.mts +15 -2
  76. package/api/theme-edit/_edit.mjs +1469 -133
  77. package/api/theme-edit/_how-commands.d.mts +116 -0
  78. package/api/theme-edit/_how-commands.mjs +227 -115
  79. package/api/theme-edit/_how-question.d.mts +74 -29
  80. package/api/theme-edit/_how-question.mjs +8514 -1256
  81. package/api/theme-edit/_how-sides.d.mts +22 -0
  82. package/api/theme-edit/_how-sides.mjs +173 -0
  83. package/api/theme-edit/_how-steps.d.mts +42 -0
  84. package/api/theme-edit/_how-steps.mjs +208 -0
  85. package/api/theme-edit/_how-values.d.mts +29 -0
  86. package/api/theme-edit/_how-values.mjs +111 -0
  87. package/api/theme-edit/_how-words.d.mts +15 -0
  88. package/api/theme-edit/_how-words.mjs +239 -0
  89. package/api/theme-edit/_how.d.mts +1 -1
  90. package/api/theme-edit/_how.mjs +422 -37
  91. package/api/theme-edit/_missed.d.mts +2 -1
  92. package/api/theme-edit/_missed.mjs +125 -13
  93. package/api/theme-edit/_normal.d.mts +5 -3
  94. package/api/theme-edit/_normal.mjs +54 -14
  95. package/api/theme-edit/_palette.d.mts +204 -4
  96. package/api/theme-edit/_palette.mjs +901 -25
  97. package/api/theme-edit/_part-pieces.d.mts +54 -0
  98. package/api/theme-edit/_part-pieces.mjs +179 -0
  99. package/api/theme-edit/_part-words.mjs +33 -5
  100. package/api/theme-edit/_parts.d.mts +133 -0
  101. package/api/theme-edit/_parts.mjs +599 -10
  102. package/api/theme-edit/_picture-traits.d.mts +259 -0
  103. package/api/theme-edit/_picture-traits.mjs +1030 -0
  104. package/api/theme-edit/_preview.d.mts +95 -4
  105. package/api/theme-edit/_preview.mjs +284 -31
  106. package/api/theme-edit/_project.d.mts +14 -4
  107. package/api/theme-edit/_project.mjs +95 -26
  108. package/api/theme-edit/_resolved.d.mts +46 -0
  109. package/api/theme-edit/_resolved.mjs +800 -0
  110. package/api/theme-edit/_set-line.d.mts +29 -0
  111. package/api/theme-edit/_set-line.mjs +100 -0
  112. package/api/theme-edit/_settings.d.mts +625 -28
  113. package/api/theme-edit/_settings.mjs +4867 -888
  114. package/api/theme-edit/_tables.d.mts +25 -1
  115. package/api/theme-edit/_tables.mjs +115 -11
  116. package/api/theme-edit/_text-looks.d.mts +78 -0
  117. package/api/theme-edit/_text-looks.mjs +376 -0
  118. package/api/theme-edit/_vet.d.mts +3 -26
  119. package/api/theme-edit/_vet.mjs +5 -89
  120. package/api/theme-edit/how/how.d.mts +1 -1
  121. package/api/theme-edit/how/how.mjs +1 -1
  122. package/api/theme-edit/show/show.d.mts +4 -3
  123. package/api/theme-edit/show/show.mjs +3 -2
  124. package/api/theme-edit/theme-edit.type.d.mts +117 -1
  125. package/api/theme-edit/theme-edit.type.mjs +46 -3
  126. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  128. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  129. package/api/theme-edit/themeEditShow.doc.mjs +22 -3
  130. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  131. package/assets/component-list.generated.json +1 -1
  132. package/assets/docs/author-a-theme.doc.mjs +7 -4
  133. package/assets/docs/icons.doc.mjs +7 -6
  134. package/assets/docs/theme.doc.dense.mjs +10 -0
  135. package/assets/docs/theme.doc.mjs +10 -0
  136. package/assets/docs/theme.doc.zh.mjs +10 -0
  137. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  138. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  139. package/assets/docs/use-a-theme.doc.mjs +89 -17
  140. package/assets/docs-routes.generated.json +1 -1
  141. package/assets/docs.generated.json +2 -2
  142. package/assets/icons/definitions/article.doc.mjs +9 -0
  143. package/assets/icons/template-icons.json +5 -0
  144. package/assets/search-catalog.generated.json +2 -2
  145. package/assets/self-audit.generated.json +1 -1
  146. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  147. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  148. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  149. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  150. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  151. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  152. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  153. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  154. package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +9 -1
  155. package/assets/templates/blocks/components/SideNavCollapseButton/SideNavCollapseButtonShowcase.doc.mjs +9 -2
  156. package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.doc.mjs +3 -2
  157. package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.tsx +2 -1
  158. package/assets/templates/blocks/components/SideNavItem/SideNavItemShowcase.doc.mjs +3 -2
  159. package/assets/templates/blocks/components/SideNavSection/SideNavSectionShowcase.doc.mjs +2 -1
  160. package/assets/templates/components.generated.json +1 -1
  161. package/assets/templates/pages/ide/page.tsx +5 -10
  162. package/assets/templates/pages/payment-form/page.tsx +16 -60
  163. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  164. package/authoring/config/parse.mjs +1 -1
  165. package/authoring/debug/parse.d.mts +1 -1
  166. package/authoring/doctypes/_schema.d.mts +13 -13
  167. package/authoring/doctypes/icon-definition/parse.mjs +2 -2
  168. package/authoring/doctypes/icon-set/parse.mjs +1 -1
  169. package/authoring/doctypes/template/parse.mjs +1 -4
  170. package/authoring/gap-report/parse.d.mts +1 -1
  171. package/clients/cli/build-id.generated.json +1 -1
  172. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  173. package/clients/cli/commands/experimental/icon.mjs +7 -7
  174. package/clients/cli/commands/experimental/theme.mjs +175 -13
  175. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  176. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  177. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  178. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  179. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +15 -5
  180. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  181. package/clients/cli/commands/hook.mjs +7 -0
  182. package/clients/cli/commands/template.mjs +1 -1
  183. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  184. package/clients/cli/index.mjs +6 -2
  185. package/clients/cli/lib/hook-format.mjs +41 -1
  186. package/clients/cli/lib/json-shim.mjs +34 -14
  187. package/clients/cli/lib/other-cli-words.mjs +7 -0
  188. package/clients/cli/lib/unknown-command.mjs +345 -46
  189. package/clients/cli/manifest.generated.json +1 -1
  190. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  191. package/foundation/agent-docs/agent-docs.mjs +51 -8
  192. package/foundation/config/project.d.mts +11 -1
  193. package/foundation/config/project.mjs +11 -2
  194. package/foundation/discovery/component-replacement.d.mts +5 -8
  195. package/foundation/discovery/component-replacement.mjs +12 -14
  196. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  197. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  198. package/foundation/discovery/core-elements.d.mts +6 -0
  199. package/foundation/discovery/core-elements.mjs +10 -2
  200. package/foundation/discovery/core-prop-types.d.mts +5 -0
  201. package/foundation/discovery/core-prop-types.mjs +10 -3
  202. package/foundation/discovery/core-props.d.mts +8 -0
  203. package/foundation/discovery/core-props.mjs +29 -13
  204. package/foundation/discovery/icon-ranking.d.mts +5 -2
  205. package/foundation/discovery/icon-ranking.mjs +101 -18
  206. package/foundation/discovery/icon-set-checks.mjs +1 -1
  207. package/foundation/discovery/icon-set-writer.mjs +1 -1
  208. package/foundation/discovery/official-list.d.mts +17 -0
  209. package/foundation/discovery/official-list.mjs +77 -0
  210. package/foundation/discovery/template-icon-notes.mjs +3 -3
  211. package/foundation/discovery/template-icons.mjs +2 -2
  212. package/foundation/discovery/template-placeholders.mjs +1 -1
  213. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  214. package/foundation/discovery/unknown-core-props.mjs +601 -0
  215. package/foundation/discovery/written-prop-values.d.mts +35 -0
  216. package/foundation/discovery/written-prop-values.mjs +258 -0
  217. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  218. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  219. package/foundation/fs/package-name.d.mts +10 -0
  220. package/foundation/fs/package-name.mjs +37 -0
  221. package/foundation/fs/project-source-files.d.mts +27 -0
  222. package/foundation/fs/project-source-files.mjs +115 -0
  223. package/foundation/fs/project-sources.d.mts +25 -0
  224. package/foundation/fs/project-sources.mjs +83 -0
  225. package/foundation/fs/read-record.d.mts +18 -0
  226. package/foundation/fs/read-record.mjs +36 -2
  227. package/foundation/integrations/integration-warnings.d.mts +39 -7
  228. package/foundation/integrations/integration-warnings.mjs +141 -19
  229. package/foundation/integrations/missing-dependency.d.mts +11 -0
  230. package/foundation/integrations/missing-dependency.mjs +20 -5
  231. package/foundation/release/folder-lock.d.mts +5 -2
  232. package/foundation/release/folder-lock.mjs +9 -3
  233. package/foundation/release/notices.mjs +2 -8
  234. package/foundation/render/cut-short.d.mts +8 -2
  235. package/foundation/render/cut-short.mjs +50 -5
  236. package/foundation/render/drawn-contrast.d.mts +40 -0
  237. package/foundation/render/drawn-contrast.mjs +355 -0
  238. package/foundation/render/file-header.mjs +4 -0
  239. package/foundation/render/layers.d.mts +2 -1
  240. package/foundation/render/layers.mjs +22 -1
  241. package/foundation/render/package-resolve-hooks.d.mts +38 -9
  242. package/foundation/render/package-resolve-hooks.mjs +124 -32
  243. package/foundation/render/page-worker.mjs +95 -23
  244. package/foundation/render/part-boxes.d.mts +27 -0
  245. package/foundation/render/part-boxes.mjs +45 -0
  246. package/foundation/render/picture-chrome.mjs +36 -4
  247. package/foundation/render/picture-playwright.mjs +26 -2
  248. package/foundation/render/picture-window.d.mts +29 -2
  249. package/foundation/render/picture-window.mjs +99 -1
  250. package/foundation/render/render-page.d.mts +39 -6
  251. package/foundation/render/render-page.mjs +26 -10
  252. package/foundation/render/ts-paths.mjs +2 -1
  253. package/foundation/response/error-codes.doc.mjs +1 -1
  254. package/foundation/response/error-codes.mjs +1 -1
  255. package/foundation/response/response-types.doc.mjs +9 -5
  256. package/foundation/suggest/other-command.mjs +25 -1
  257. package/foundation/text/icon-set-next.d.mts +1 -1
  258. package/foundation/text/icon-set-next.mjs +2 -2
  259. package/foundation/text/written-string.d.mts +4 -1
  260. package/foundation/text/written-string.mjs +4 -1
  261. package/package.json +8 -7
@@ -0,0 +1,62 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The families the theme editor grows beside the theme's own colors, in
6
+ * order: the category and chart hues of the look (lookSeeds), then the
7
+ * status roles the theme leaves unset, from the base theme's color for
8
+ * each (statusSeeds). Empty without a color setting.
9
+ * @param {ReadonlyArray<PaletteDial>} dials
10
+ * @param {Pick<PaletteMappingContext, 'base' | 'reader'>} context
11
+ * @returns {{id: string; name: string; seed: string}[]}
12
+ */
13
+ export function grownFamilies(dials: ReadonlyArray<PaletteDial>, context: Pick<PaletteMappingContext, "base" | "reader">): {
14
+ id: string;
15
+ name: string;
16
+ seed: string;
17
+ }[];
18
+ /**
19
+ * The colors the theme editor grows beyond `themePalette()`'s mapping,
20
+ * written into `tokens` as shades of the palette.
21
+ * @param {EditorLookInput} input
22
+ * @returns {EditorLookResult}
23
+ */
24
+ export function growLook(input: EditorLookInput): EditorLookResult;
25
+ export type BasePair = import("./mapping.mjs").BasePair;
26
+ export type ColorTriple = import("./mapping.mjs").ColorTriple;
27
+ export type PaletteBase = import("./mapping.mjs").PaletteBase;
28
+ export type PaletteColorReader = import("./mapping.mjs").PaletteColorReader;
29
+ export type PaletteDial = import("./mapping.mjs").PaletteDial;
30
+ export type PaletteMapping = import("./mapping.mjs").PaletteMapping;
31
+ export type PaletteMappingContext = import("./mapping.mjs").PaletteMappingContext;
32
+ export type PaletteMode = import("./mapping.mjs").PaletteMode;
33
+ export type PaletteTools = import("./mapping.mjs").PaletteTools;
34
+ export type TonalPaletteCandidate = import("./types.mjs").TonalPaletteCandidate;
35
+ /**
36
+ * What `mapPalette` hands the editor's rules.
37
+ */
38
+ export type EditorLookInput = {
39
+ candidate: TonalPaletteCandidate;
40
+ dials: ReadonlyArray<PaletteDial>;
41
+ context: PaletteMappingContext;
42
+ tokens: PaletteMapping["tokens"];
43
+ modes: PaletteMode[];
44
+ setExactly: (token: string) => boolean;
45
+ t: PaletteTools;
46
+ };
47
+ /**
48
+ * The editor's rules as `mapPalette` reads them (`context.editor`): this module.
49
+ */
50
+ export type PaletteEditorRules = {
51
+ growLook: (input: EditorLookInput) => EditorLookResult;
52
+ };
53
+ /**
54
+ * What the editor's rules add to a mapping.
55
+ */
56
+ export type EditorLookResult = {
57
+ categories: PaletteMapping["categories"];
58
+ statuses: PaletteMapping["statuses"];
59
+ code: string[];
60
+ cvd: PaletteMapping["cvd"];
61
+ keptAtBase: PaletteMapping["kept"];
62
+ };
@@ -0,0 +1,550 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // Generated from packages/core/src/palette/editor-look.ts by
3
+ // scripts/generate-cli-palette-engine.mjs. Do not edit: change the Core
4
+ // source and run `pnpm generate:cli-palette-engine`.
5
+ /**
6
+ * @file editor-look.ts
7
+ * @input The token mapping `mapPalette` has made, and its palette
8
+ * @output The colors the theme editor grows beyond `themePalette()`'s
9
+ * mapping
10
+ * @position The theme editor's own rules, its `context.editor`. Its own
11
+ * module, so an app that imports only `themePalette()` ships none of it
12
+ */
13
+ import {compositeOver} from './color.mjs';
14
+ import {
15
+ CATEGORY_HUES,
16
+ cvdClashes,
17
+ deriveCodeColors,
18
+ deriveLookColors,
19
+ deriveStatusColors,
20
+ lookSeeds,
21
+ statusSeeds,
22
+ } from './derive-look.mjs';
23
+ import {
24
+ STATUS_TOKEN,
25
+ TEXT,
26
+ TEXT_PROPS,
27
+ hex,
28
+ isLookToken,
29
+ ratio,
30
+ round2,
31
+ splitTopComma,
32
+ } from './mapping.mjs';
33
+
34
+ /** @typedef {import('./mapping.mjs').BasePair} BasePair */
35
+
36
+ /** @typedef {import('./mapping.mjs').ColorTriple} ColorTriple */
37
+
38
+ /** @typedef {import('./mapping.mjs').PaletteBase} PaletteBase */
39
+
40
+ /** @typedef {import('./mapping.mjs').PaletteColorReader} PaletteColorReader */
41
+
42
+ /** @typedef {import('./mapping.mjs').PaletteDial} PaletteDial */
43
+
44
+ /** @typedef {import('./mapping.mjs').PaletteMapping} PaletteMapping */
45
+
46
+ /** @typedef {import('./mapping.mjs').PaletteMappingContext} PaletteMappingContext */
47
+
48
+ /** @typedef {import('./mapping.mjs').PaletteMode} PaletteMode */
49
+
50
+ /** @typedef {import('./mapping.mjs').PaletteTools} PaletteTools */
51
+
52
+ /** @typedef {import('./types.mjs').TonalPaletteCandidate} TonalPaletteCandidate */
53
+
54
+ /**
55
+ * What `mapPalette` hands the editor's rules.
56
+ * @typedef {object} EditorLookInput
57
+ * @property {TonalPaletteCandidate} candidate
58
+ * @property {ReadonlyArray<PaletteDial>} dials
59
+ * @property {PaletteMappingContext} context
60
+ * @property {PaletteMapping['tokens']} tokens
61
+ * @property {PaletteMode[]} modes
62
+ * @property {(token: string) => boolean} setExactly
63
+ * @property {PaletteTools} t
64
+ */
65
+
66
+ /**
67
+ * The editor's rules as `mapPalette` reads them (`context.editor`): this module.
68
+ * @typedef {object} PaletteEditorRules
69
+ * @property {(input: EditorLookInput) => EditorLookResult} growLook
70
+ */
71
+
72
+ /**
73
+ * What the editor's rules add to a mapping.
74
+ * @typedef {object} EditorLookResult
75
+ * @property {PaletteMapping['categories']} categories
76
+ * @property {PaletteMapping['statuses']} statuses
77
+ * @property {string[]} code
78
+ * @property {PaletteMapping['cvd']} cvd
79
+ * @property {PaletteMapping['kept']} keptAtBase
80
+ */
81
+
82
+ /**
83
+ * The text/fill pairs a base theme draws: Core's own (each category's text
84
+ * on its fill; each status's text on its fill and on its tint) and those of
85
+ * the base theme's rules (a coloured card's text on its fill, a part's text
86
+ * color on its background), as `[pair, text, fill]` values a mode resolves.
87
+ * @param {PaletteBase | undefined} base
88
+ * @returns {[BasePair, string, string][]}
89
+ */
90
+ function basePairs(base) {
91
+ /**
92
+ * @type {[BasePair, string, string][]}
93
+ */
94
+ const out = [];
95
+ for (const hue of CATEGORY_HUES) {
96
+ out.push([
97
+ {kind: 'category', hue},
98
+ `var(--color-text-${hue})`,
99
+ `var(--color-background-${hue})`,
100
+ ]);
101
+ }
102
+ for (const role of ['info', 'success', 'warning', 'error']) {
103
+ out.push([
104
+ {kind: 'status', role, tint: false},
105
+ `var(--color-on-${role})`,
106
+ `var(--color-${role})`,
107
+ ]);
108
+ out.push([
109
+ {kind: 'status', role, tint: true},
110
+ `var(--color-on-${role}-muted)`,
111
+ `var(--color-${role}-muted)`,
112
+ ]);
113
+ }
114
+ for (const [part, rules] of Object.entries(
115
+ /** @type {Record<string, Record<string, unknown>>} */ (
116
+ base?.components ?? {}
117
+ ),
118
+ )) {
119
+ for (const [key, raw] of Object.entries(rules ?? {})) {
120
+ if (!raw || typeof raw !== 'object') {
121
+ continue;
122
+ }
123
+ const block = /** @type {Record<string, unknown>} */ (raw);
124
+ const hue = /^(?:variant|color):([a-z]+)$/.exec(key)?.[1];
125
+ const fill =
126
+ block.backgroundColor ??
127
+ (hue &&
128
+ HUE_FILL_PARTS.includes(part) &&
129
+ /** @type {ReadonlyArray<string>} */ (CATEGORY_HUES).includes(hue)
130
+ ? `var(--color-background-${hue})`
131
+ : null);
132
+ if (typeof fill !== 'string') {
133
+ continue;
134
+ }
135
+ for (const prop of TEXT_PROPS) {
136
+ const text = block[prop];
137
+ if (typeof text === 'string') {
138
+ out.push([{kind: 'part', part, block: key, prop}, text, fill]);
139
+ }
140
+ }
141
+ }
142
+ }
143
+ return out;
144
+ }
145
+ /**
146
+ * Keeps the base theme's value, in a mode, for each look color (category
147
+ * or status) that would leave a text/fill pair the base theme draws below
148
+ * 4.5:1 where the base's own values read better. Pairs are checked again
149
+ * until none changes, so a fill kept at the base's sends its text back too.
150
+ * `tokens` is written in place.
151
+ * @param {PaletteMapping['tokens']} tokens
152
+ * @param {PaletteBase | undefined} base
153
+ * @param {ReadonlyArray<PaletteMode>} modes
154
+ * @param {(k: string) => boolean} isLook
155
+ * @param {PaletteColorReader} reader
156
+ * @returns {PaletteMapping['kept']}
157
+ */
158
+ function keepWhereBaseReads(tokens, base, modes, isLook, reader) {
159
+ /**
160
+ * @type {PaletteMapping['kept']}
161
+ */
162
+ const kept = [];
163
+ const pairs = basePairs(base);
164
+ /** A value's color in a mode, with the tokens it reads. */
165
+ const colorOf =
166
+ /**
167
+ * @param {string} v
168
+ * @param {PaletteMode} m
169
+ * @param {boolean} now
170
+ * @returns {ColorTriple | null}
171
+ */
172
+ (v, m, now, depth = 0) => {
173
+ if (depth > 6) {
174
+ return null;
175
+ }
176
+ let x = v.trim();
177
+ const pair = /^light-dark\((.*)\)$/is.exec(x);
178
+ if (pair) {
179
+ const halves = splitTopComma(pair[1]);
180
+ if (halves.length === 2) {
181
+ x = halves[m === 'light' ? 0 : 1].trim();
182
+ }
183
+ }
184
+ const ref = /^var\((--[\w-]+)\)$/.exec(x)?.[1];
185
+ if (ref) {
186
+ const own = now ? tokens[ref]?.[m]?.color : null;
187
+ return colorOf(own ?? base?.[m]?.[ref] ?? '', m, now, depth + 1);
188
+ }
189
+ const rgb = reader.rgb(x);
190
+ if (!rgb) {
191
+ return null;
192
+ }
193
+ const page = reader.rgb(
194
+ (now ? tokens['--color-background-body']?.[m]?.color : null) ??
195
+ base?.[m]?.['--color-background-body'] ??
196
+ (m === 'light' ? '#ffffff' : '#000000'),
197
+ );
198
+ const a = reader.alpha(x);
199
+ return a < 1 && page ? compositeOver(rgb, a, page) : rgb;
200
+ };
201
+ /** The look tokens a value reads. */
202
+ const reads =
203
+ /**
204
+ * @param {string} v
205
+ * @returns {string[]}
206
+ */
207
+ v =>
208
+ [...v.matchAll(/var\((--[\w-]+)\)/g)]
209
+ .map(x => x[1])
210
+ .filter(k => isLook(k) && k in tokens);
211
+ for (let round = 0; round < 6; round++) {
212
+ let changed = false;
213
+ for (const m of modes) {
214
+ for (const [pair, text, fill] of pairs) {
215
+ const involved = [...reads(text), ...reads(fill)].filter(
216
+ k => tokens[k]?.[m]?.family !== 'literal',
217
+ );
218
+ if (!involved.length) {
219
+ continue;
220
+ }
221
+ const [ft, bt] = [colorOf(text, m, true), colorOf(fill, m, true)];
222
+ const [fb, bb] = [colorOf(text, m, false), colorOf(fill, m, false)];
223
+ if (!ft || !bt) {
224
+ continue;
225
+ }
226
+ const now = ratio(ft, bt);
227
+ const was = fb && bb ? ratio(fb, bb) : 0;
228
+ if (now >= TEXT || now >= was - 0.01) {
229
+ continue;
230
+ }
231
+ for (const k of involved) {
232
+ const value = base?.[m]?.[k];
233
+ if (value == null) {
234
+ continue;
235
+ }
236
+ tokens[k] = {
237
+ ...tokens[k],
238
+ [m]: {stop: 0, color: value, family: 'literal'},
239
+ };
240
+ kept.push({token: k, mode: m, pair, ratio: round2(now)});
241
+ changed = true;
242
+ }
243
+ }
244
+ }
245
+ if (!changed) {
246
+ break;
247
+ }
248
+ }
249
+ return kept;
250
+ }
251
+ /** A category or status token: the colors the look derives. */
252
+ const isLookOrStatus =
253
+ /**
254
+ * @param {string} k
255
+ * @returns {boolean}
256
+ */
257
+ k =>
258
+ isLookToken(k) ||
259
+ /^--color-(?:(?:on|text|icon|border)-)?(?:info|success|warning|error)(?:-muted)?$/.test(
260
+ k,
261
+ );
262
+ /** The text a card tint carries, as the look gives it. */
263
+ const LOOK_TEXT = [
264
+ '--color-text-primary',
265
+ '--color-text-secondary',
266
+ '--color-text-accent',
267
+ ];
268
+ /** The grounds the look's colors are read on, as the look gives them. */
269
+ const LOOK_GROUNDS = [
270
+ '--color-background-body',
271
+ '--color-background-surface',
272
+ '--color-background-card',
273
+ ];
274
+ /** The parts whose `variant:<hue>` and `color:<hue>` rules paint a category fill. */
275
+ const HUE_FILL_PARTS = ['card', 'clickable-card', 'selectable-card', 'token'];
276
+ /**
277
+ * The families the theme editor grows beside the theme's own colors, in
278
+ * order: the category and chart hues of the look (lookSeeds), then the
279
+ * status roles the theme leaves unset, from the base theme's color for
280
+ * each (statusSeeds). Empty without a color setting.
281
+ * @param {ReadonlyArray<PaletteDial>} dials
282
+ * @param {Pick<PaletteMappingContext, 'base' | 'reader'>} context
283
+ * @returns {{id: string; name: string; seed: string}[]}
284
+ */
285
+ export function grownFamilies(dials, context) {
286
+ if (!dials.length) {
287
+ return [];
288
+ }
289
+ const named =
290
+ /**
291
+ * @param {string} id
292
+ * @param {string} seed
293
+ */
294
+ (id, seed) => ({
295
+ id,
296
+ name: id[0].toUpperCase() + id.slice(1),
297
+ seed,
298
+ });
299
+ const accent = dials.find(d => d.id === 'accent')?.seed;
300
+ const out = Object.entries(
301
+ lookSeeds(accent, dials.find(d => d.id === 'neutral')?.seed),
302
+ ).map(([id, seed]) => named(id, seed));
303
+ /**
304
+ * @type {Record<string, string>}
305
+ */
306
+ const baseColors = {};
307
+ for (const d of Object.keys(STATUS_TOKEN)) {
308
+ if (dials.some(f => f.id === d)) {
309
+ continue;
310
+ }
311
+ const v = context.base?.light?.[`--color-${STATUS_TOKEN[d]}`];
312
+ const rgb = v ? context.reader.rgb(v) : null;
313
+ if (rgb && context.reader.alpha(v) >= 1) {
314
+ baseColors[d] = hex(rgb);
315
+ }
316
+ }
317
+ for (const [id, seed] of Object.entries(statusSeeds(baseColors, accent))) {
318
+ if (!out.some(f => f.id === id)) {
319
+ out.push(named(id, seed));
320
+ }
321
+ }
322
+ return out;
323
+ }
324
+ /**
325
+ * The colors the theme editor grows beyond `themePalette()`'s mapping,
326
+ * written into `tokens` as shades of the palette.
327
+ * @param {EditorLookInput} input
328
+ * @returns {EditorLookResult}
329
+ */
330
+ export function growLook(input) {
331
+ const {candidate, dials, context, tokens, modes, setExactly, t} = input;
332
+ const {alphaOf, exactOf, parseColor, stops} = t;
333
+ const {base, has} = context;
334
+ /**
335
+ * The look's own colors for tokens in a mode: what the palette gives them,
336
+ * else the base theme's. A color set exactly (a page fill, a link color)
337
+ * is not the look's: the colors the look grows never follow it.
338
+ */
339
+ const lookColors =
340
+ /**
341
+ * @param {string[]} ks
342
+ * @param {PaletteMode} m
343
+ * @returns {string[]}
344
+ */
345
+ (ks, m) =>
346
+ ks
347
+ .map(k => tokens[k]?.[m]?.color ?? t.colorIn(base?.[m]?.[k] ?? '', m))
348
+ .filter(
349
+ /**
350
+ * @returns {v is string}
351
+ */
352
+ v => Boolean(v && parseColor(v) && alphaOf(v) >= 1),
353
+ );
354
+ /**
355
+ * @type {PaletteMapping['categories']}
356
+ */
357
+ const categories = mapCategories();
358
+ /**
359
+ * @type {PaletteMapping['statuses']}
360
+ */
361
+ const statuses = mapStatuses();
362
+ const code = mapCode();
363
+ /**
364
+ * @type {PaletteMapping['cvd']}
365
+ */
366
+ const cvd = statusClashes();
367
+ /**
368
+ * The status fills, as the theme shows them, that someone red-weak or
369
+ * green-weak may not tell apart, in each mode, where the theme changed at
370
+ * least one of the two (a base theme's own pair is the base's).
371
+ * @returns {PaletteMapping['cvd']}
372
+ */
373
+ function statusClashes() {
374
+ /**
375
+ * @type {PaletteMapping['cvd']}
376
+ */
377
+ const out = [];
378
+ const words = ['info', 'success', 'warning', 'error'];
379
+ // (Every mode's page: a status color set with no mode shows on each.)
380
+ const pages = modes.map(m => {
381
+ const c = parseColor(
382
+ tokens['--color-background-body']?.[m]?.color ??
383
+ t.colorIn(base?.[m]?.['--color-background-body'] ?? '', m) ??
384
+ (m === 'light' ? '#ffffff' : '#000000'),
385
+ );
386
+ return c ? hex(c) : m === 'light' ? '#ffffff' : '#000000';
387
+ });
388
+ for (const m of modes) {
389
+ /**
390
+ * @type {Record<string, string>}
391
+ */
392
+ const fills = {};
393
+ for (const w of words) {
394
+ const k = `--color-${w}`;
395
+ const v =
396
+ exactOf(k, m) ??
397
+ tokens[k]?.[m]?.color ??
398
+ t.colorIn(base?.[m]?.[k] ?? '', m);
399
+ const rgb = v ? parseColor(v) : null;
400
+ if (v && rgb && alphaOf(v) >= 1) {
401
+ fills[w] = hex(rgb);
402
+ }
403
+ }
404
+ const changed =
405
+ /**
406
+ * @param {string} w
407
+ * @returns {boolean}
408
+ */
409
+ w => `--color-${w}` in tokens || exactOf(`--color-${w}`, m) != null;
410
+ const pageOf = parseColor(
411
+ tokens['--color-background-body']?.[m]?.color ??
412
+ t.colorIn(base?.[m]?.['--color-background-body'] ?? '', m) ??
413
+ (m === 'light' ? '#ffffff' : '#000000'),
414
+ );
415
+ const page = pageOf ? hex(pageOf) : m === 'light' ? '#ffffff' : '#000000';
416
+ for (const c of cvdClashes(fills)) {
417
+ if (changed(c.a) || changed(c.b)) {
418
+ out.push({
419
+ ...c,
420
+ mode: m,
421
+ colors: [fills[c.a], fills[c.b]],
422
+ page,
423
+ pages,
424
+ });
425
+ }
426
+ }
427
+ }
428
+ return out;
429
+ }
430
+ /**
431
+ * The status roles the theme leaves unset, from the palette's families of
432
+ * them (deriveStatusColors), written as its shades; a token set by hand
433
+ * keeps its value, and every other one is written.
434
+ * @returns {PaletteMapping['statuses']}
435
+ */
436
+ function mapStatuses() {
437
+ const pal =
438
+ /** @type {Record< string, Record<PaletteMode, Record<string | number, string>> >} */ (
439
+ /** @type {unknown} */ (candidate.palette)
440
+ );
441
+ const roles = Object.keys(STATUS_TOKEN).filter(
442
+ d => !dials.some(f => f.id === d) && pal[d],
443
+ );
444
+ if (!roles.length) {
445
+ return {roles: {}, why: [], short: []};
446
+ }
447
+ const derived = deriveStatusColors({
448
+ palette: pal,
449
+ stops,
450
+ modes,
451
+ roles,
452
+ grounds: m => lookColors(LOOK_GROUNDS, m),
453
+ inks: (m, id) =>
454
+ t.onChoices(id, m).map(r => ({
455
+ stop: r.stop,
456
+ color: r.color,
457
+ family: r.family ?? 'neutral',
458
+ })),
459
+ accent: m => tokens['--color-accent']?.[m]?.color ?? null,
460
+ wanted: k => has(k) && !setExactly(k),
461
+ ...(context.shown ? {shown: context.shown} : {}),
462
+ });
463
+ for (const [k, v] of Object.entries(derived.tokens)) {
464
+ tokens[k] = {family: v.family, light: v.light, dark: v.dark};
465
+ }
466
+ return {roles: derived.roles, why: derived.why, short: derived.short};
467
+ }
468
+ /**
469
+ * The code colors and the overlay scrim, from the palette
470
+ * (deriveCodeColors); a token set by hand keeps its value. Returns the
471
+ * roles that keep the base theme's.
472
+ * @returns {string[]}
473
+ */
474
+ function mapCode() {
475
+ const derived = deriveCodeColors({
476
+ palette:
477
+ /** @type {Record< string, Record<PaletteMode, Record<string | number, string>> >} */ (
478
+ /** @type {unknown} */ (candidate.palette)
479
+ ),
480
+ stops,
481
+ modes,
482
+ grounds: m => lookColors(LOOK_GROUNDS, m),
483
+ codeGround: m => {
484
+ const v = exactOf('--color-syntax-background', m);
485
+ const rgb = v ? parseColor(v) : null;
486
+ return v && rgb && alphaOf(v) >= 1 ? hex(rgb) : null;
487
+ },
488
+ wanted: k => has(k) && !setExactly(k),
489
+ });
490
+ for (const [k, v] of Object.entries(derived.tokens)) {
491
+ tokens[k] = {family: v.family, light: v.light, dark: v.dark};
492
+ }
493
+ return derived.unreadable;
494
+ }
495
+ /** A status token of a role the theme leaves unset: the editor's to grow. */
496
+ const grownStatus =
497
+ /**
498
+ * @param {string} k
499
+ * @returns {boolean}
500
+ */
501
+ k =>
502
+ Object.keys(STATUS_TOKEN).some(
503
+ d =>
504
+ !dials.some(f => f.id === d) &&
505
+ new RegExp(
506
+ `^--color-(?:(?:on|text|icon|border)-)?${STATUS_TOKEN[d]}(?:-muted)?$`,
507
+ ).test(k),
508
+ );
509
+ const keptAtBase = keepWhereBaseReads(
510
+ tokens,
511
+ base,
512
+ modes,
513
+ k => isLookToken(k) || (isLookOrStatus(k) && grownStatus(k)),
514
+ context.reader,
515
+ );
516
+ /**
517
+ * The category colors (Badge, Token and Card tints) and the chart colors
518
+ * the palette derives (deriveLookColors), written as its shades. A token
519
+ * the theme sets by hand keeps its value; every other one is written.
520
+ * @returns {PaletteMapping['categories']}
521
+ */
522
+ function mapCategories() {
523
+ const derived = deriveLookColors({
524
+ palette:
525
+ /** @type {Record< string, Record<PaletteMode, Record<string | number, string>> >} */ (
526
+ /** @type {unknown} */ (candidate.palette)
527
+ ),
528
+ stops,
529
+ modes,
530
+ // Card text, secondary text and links all sit on a card tint.
531
+ text: m => lookColors(LOOK_TEXT, m),
532
+ grounds: m => lookColors(LOOK_GROUNDS, m),
533
+ wanted: k => has(k) && !setExactly(k),
534
+ ...(context.shown ? {shown: context.shown} : {}),
535
+ accent: dials.find(f => f.id === 'accent')?.seed ?? null,
536
+ });
537
+ for (const [k, v] of Object.entries(derived.tokens)) {
538
+ tokens[k] = {family: v.family, light: v.light, dark: v.dark};
539
+ }
540
+ return {
541
+ badges: derived.badges,
542
+ chart: derived.chart,
543
+ limits: derived.limits,
544
+ moved: derived.moved,
545
+ alike: derived.alike,
546
+ unread: derived.unread,
547
+ };
548
+ }
549
+ return {categories, statuses, code, cvd, keptAtBase};
550
+ }