@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
@@ -1,6 +1,72 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * A box color shorthand's colors as typed, one per side (`#ddd #ddd
6
+ * transparent`), each with the sides it colors; null for a property that
7
+ * takes one color, or for one value. `tooMany` is set when the value has
8
+ * more than the property takes.
9
+ * @param {string} prop the property, as CSS names it
10
+ * @param {string} value
11
+ * @returns {{colors: Array<{color: string, sides: string[]}>, max: number, tooMany: boolean} | null}
12
+ */
13
+ export function colorSides(prop: string, value: string): {
14
+ colors: Array<{
15
+ color: string;
16
+ sides: string[];
17
+ }>;
18
+ max: number;
19
+ tooMany: boolean;
20
+ } | null;
21
+ /**
22
+ * The opacity a slash after a color gives it, as Tailwind writes it
23
+ * (`black/5` is black at 5%; `white/[.08]` and `white/[8%]` at 8%), read at
24
+ * `at` (the slash), with how many characters it takes; null when no
25
+ * opacity is written there. Only the share of the color is read: 0 to 100,
26
+ * or 0 to 1 in brackets.
27
+ * @param {string} text
28
+ * @param {number} at
29
+ * @returns {{alpha: number, length: number} | null}
30
+ */
31
+ export function opacitySuffixAt(text: string, at: number): {
32
+ alpha: number;
33
+ length: number;
34
+ } | null;
35
+ /**
36
+ * A color at a share of its opacity, as CSS writes it: `rgb(r g b / a)`,
37
+ * its own alpha included (a half-clear color at 50% is a quarter); null
38
+ * for what is not a fixed color.
39
+ * @param {string} color
40
+ * @param {number} alpha 0 to 1
41
+ * @returns {string | null}
42
+ */
43
+ export function colorAtOpacity(color: string, alpha: number): string | null;
44
+ /**
45
+ * Tailwind's color/opacity shorthand written in a value (`0 0 0 1px
46
+ * black/5`, `#000/10`, `white/[.08]`): each color written out (a hex or a
47
+ * CSS color name) with an opacity after its slash. `color` is what CSS
48
+ * writes for it; null for a color word this reader cannot read as one
49
+ * (Tailwind's own stops, `blue-500/20`), which the caller names.
50
+ * @param {string} value
51
+ * @returns {Array<{index: number, typed: string, color: string | null}>}
52
+ */
53
+ export function colorOpacitiesIn(value: string): Array<{
54
+ index: number;
55
+ typed: string;
56
+ color: string | null;
57
+ }>;
58
+ /**
59
+ * A value with each color/opacity shorthand in it written as CSS writes it
60
+ * (`0 0 0 1px black/5` is `0 0 0 1px rgb(0 0 0 / 0.05)`), and the ones this
61
+ * reader cannot read (Tailwind's own stops); null when the value has none.
62
+ * @param {string} value
63
+ * @returns {{css: string, found: ReturnType<typeof colorOpacitiesIn>, unread: ReturnType<typeof colorOpacitiesIn>} | null}
64
+ */
65
+ export function colorOpacitiesAsCss(value: string): {
66
+ css: string;
67
+ found: ReturnType<typeof colorOpacitiesIn>;
68
+ unread: ReturnType<typeof colorOpacitiesIn>;
69
+ } | null;
4
70
  /** @typedef {[number, number, number]} Rgb */
5
71
  /**
6
72
  * A comma (legacy) rgb() or hsl() that CSS does not take as written, in the
@@ -21,6 +87,14 @@ export function colorProblem(value: unknown): {
21
87
  message: string;
22
88
  opaque?: string;
23
89
  } | null;
90
+ /**
91
+ * A contrast ratio as a result says it: cut down to two decimals, never
92
+ * rounded up, so a ratio just under what a check needs (4.497) never reads
93
+ * as meeting it ("4.5:1, needs 4.5:1").
94
+ * @param {number} r
95
+ * @returns {string}
96
+ */
97
+ export function ratioWords(r: number): string;
24
98
  /**
25
99
  * The WCAG contrast ratio of two colors.
26
100
  * @param {number[]} a
@@ -24,12 +24,15 @@ import {
24
24
  MIX_SPACES,
25
25
  NAMED,
26
26
  SYSTEM,
27
+ alphaOf,
27
28
  hex,
28
29
  mixColor,
29
30
  mixSide,
31
+ namedColorHex,
32
+ parseColor,
30
33
  readColor,
31
34
  } from '../../foundation/color/css-color.mjs';
32
- import {luminance} from '../theme/palette/generate/color.mjs';
35
+ import {contrastRatio, ratioDown} from '../theme/palette/generate/color.mjs';
33
36
 
34
37
  export {splitTop};
35
38
  export {
@@ -47,6 +50,158 @@ export {
47
50
  parseColor,
48
51
  } from '../../foundation/color/css-color.mjs';
49
52
 
53
+ /**
54
+ * The box color shorthands, which take one color per side, and how many
55
+ * sides each names (`border-color: top right bottom left`).
56
+ * @type {Record<string, number>}
57
+ */
58
+ const COLOR_SIDE_COUNT = {
59
+ 'border-color': 4,
60
+ 'border-block-color': 2,
61
+ 'border-inline-color': 2,
62
+ };
63
+
64
+ /**
65
+ * The sides each count of colors names, as CSS gives them out.
66
+ * @type {Record<number, string[][]>}
67
+ */
68
+ const SIDE_NAMES = {
69
+ 4: [['top'], ['right'], ['bottom'], ['left']],
70
+ 3: [['top'], ['right', 'left'], ['bottom']],
71
+ 2: [
72
+ ['top', 'bottom'],
73
+ ['right', 'left'],
74
+ ],
75
+ };
76
+
77
+ /**
78
+ * A box color shorthand's colors as typed, one per side (`#ddd #ddd
79
+ * transparent`), each with the sides it colors; null for a property that
80
+ * takes one color, or for one value. `tooMany` is set when the value has
81
+ * more than the property takes.
82
+ * @param {string} prop the property, as CSS names it
83
+ * @param {string} value
84
+ * @returns {{colors: Array<{color: string, sides: string[]}>, max: number, tooMany: boolean} | null}
85
+ */
86
+ export function colorSides(prop, value) {
87
+ const max = COLOR_SIDE_COUNT[prop];
88
+ if (!max) return null;
89
+ const parts = splitTop(String(value).trim(), ' ')
90
+ .map(x => x.trim())
91
+ .filter(Boolean);
92
+ if (parts.length < 2) return null;
93
+ const logical = max === 2 && prop !== 'border-color';
94
+ /** @type {string[][]} */
95
+ const names = logical
96
+ ? [['start'], ['end']]
97
+ : (SIDE_NAMES[parts.length] ?? []);
98
+ return {
99
+ colors: parts.map((color, i) => ({color, sides: names[i] ?? []})),
100
+ max,
101
+ tooMany: parts.length > max,
102
+ };
103
+ }
104
+
105
+ /**
106
+ * The opacity a slash after a color gives it, as Tailwind writes it
107
+ * (`black/5` is black at 5%; `white/[.08]` and `white/[8%]` at 8%), read at
108
+ * `at` (the slash), with how many characters it takes; null when no
109
+ * opacity is written there. Only the share of the color is read: 0 to 100,
110
+ * or 0 to 1 in brackets.
111
+ * @param {string} text
112
+ * @param {number} at
113
+ * @returns {{alpha: number, length: number} | null}
114
+ */
115
+ export function opacitySuffixAt(text, at) {
116
+ const m =
117
+ /^\/(?:(\d{1,3}(?:\.\d+)?)|\[\s*(\d*\.?\d+)\s*(%?)\s*\])(?![\w.%\]])/.exec(
118
+ text.slice(at),
119
+ );
120
+ if (!m) return null;
121
+ const n = m[1] != null ? Number(m[1]) / 100 : Number(m[2]) / (m[3] ? 100 : 1);
122
+ if (!Number.isFinite(n) || n < 0 || n > 1) return null;
123
+ return {alpha: n, length: m[0].length};
124
+ }
125
+
126
+ /**
127
+ * A color at a share of its opacity, as CSS writes it: `rgb(r g b / a)`,
128
+ * its own alpha included (a half-clear color at 50% is a quarter); null
129
+ * for what is not a fixed color.
130
+ * @param {string} color
131
+ * @param {number} alpha 0 to 1
132
+ * @returns {string | null}
133
+ */
134
+ export function colorAtOpacity(color, alpha) {
135
+ const rgb = parseColor(color);
136
+ if (!rgb) return null;
137
+ const a = Math.round(alphaOf(color) * alpha * 1000) / 1000;
138
+ return `rgb(${rgb.map(c => Math.round(c)).join(' ')} / ${a})`;
139
+ }
140
+
141
+ /**
142
+ * Tailwind's color/opacity shorthand written in a value (`0 0 0 1px
143
+ * black/5`, `#000/10`, `white/[.08]`): each color written out (a hex or a
144
+ * CSS color name) with an opacity after its slash. `color` is what CSS
145
+ * writes for it; null for a color word this reader cannot read as one
146
+ * (Tailwind's own stops, `blue-500/20`), which the caller names.
147
+ * @param {string} value
148
+ * @returns {Array<{index: number, typed: string, color: string | null}>}
149
+ */
150
+ export function colorOpacitiesIn(value) {
151
+ const text = String(value ?? '');
152
+ /** @type {Array<{index: number, typed: string, color: string | null}>} */
153
+ const out = [];
154
+ // (A url() holds a path, `url(/img/white/24.png)`, never a color; so
155
+ // does a quoted string, an image-set() path or a bare quoted path,
156
+ // `"/img/red/50/a.png"`.)
157
+ const urls = [
158
+ ...text.matchAll(/\burl\(\s*(?:"[^"]*"|'[^']*'|[^)]*)\)|"[^"]*"|'[^']*'/gi),
159
+ ].map(u => [u.index ?? 0, (u.index ?? 0) + u[0].length]);
160
+ for (const m of text.matchAll(
161
+ /(?<![\w#.])(#[0-9a-f]{3,8}|[a-z]+(?:-\d{2,3})?)(?=\/)/gi,
162
+ )) {
163
+ if (urls.some(([a, b]) => (m.index ?? 0) >= a && (m.index ?? 0) < b))
164
+ continue;
165
+ const at = (m.index ?? 0) + m[0].length;
166
+ const op = opacitySuffixAt(text, at);
167
+ if (!op) continue;
168
+ const word = m[1].toLowerCase();
169
+ const stop = /-\d{2,3}$/.test(word);
170
+ const base = word.startsWith('#')
171
+ ? parseColor(word)
172
+ ? m[1]
173
+ : null
174
+ : namedColorHex(word);
175
+ if (!base && !stop) continue;
176
+ out.push({
177
+ index: m.index ?? 0,
178
+ typed: text.slice(m.index ?? 0, at + op.length),
179
+ color: base ? colorAtOpacity(base, op.alpha) : null,
180
+ });
181
+ }
182
+ return out;
183
+ }
184
+
185
+ /**
186
+ * A value with each color/opacity shorthand in it written as CSS writes it
187
+ * (`0 0 0 1px black/5` is `0 0 0 1px rgb(0 0 0 / 0.05)`), and the ones this
188
+ * reader cannot read (Tailwind's own stops); null when the value has none.
189
+ * @param {string} value
190
+ * @returns {{css: string, found: ReturnType<typeof colorOpacitiesIn>, unread: ReturnType<typeof colorOpacitiesIn>} | null}
191
+ */
192
+ export function colorOpacitiesAsCss(value) {
193
+ const found = colorOpacitiesIn(value);
194
+ if (!found.length) return null;
195
+ const css = found.reduceRight(
196
+ (v, x) =>
197
+ x.color == null
198
+ ? v
199
+ : v.slice(0, x.index) + x.color + v.slice(x.index + x.typed.length),
200
+ String(value),
201
+ );
202
+ return {css, found, unread: found.filter(x => x.color == null)};
203
+ }
204
+
50
205
  /** @typedef {[number, number, number]} Rgb */
51
206
 
52
207
  /**
@@ -160,14 +315,24 @@ export function colorProblem(value) {
160
315
  return {kind: 'unknown', message: 'is not a CSS color'};
161
316
  }
162
317
 
318
+ /**
319
+ * A contrast ratio as a result says it: cut down to two decimals, never
320
+ * rounded up, so a ratio just under what a check needs (4.497) never reads
321
+ * as meeting it ("4.5:1, needs 4.5:1").
322
+ * @param {number} r
323
+ * @returns {string}
324
+ */
325
+ export function ratioWords(r) {
326
+ return ratioDown(r).toFixed(2);
327
+ }
328
+
163
329
  /**
164
330
  * The WCAG contrast ratio of two colors.
165
331
  * @param {number[]} a
166
332
  * @param {number[]} b
167
333
  */
168
334
  export function ratio(a, b) {
169
- const [x, y] = [luminance(hex(a)), luminance(hex(b))].sort((p, q) => q - p);
170
- return (x + 0.05) / (y + 0.05);
335
+ return contrastRatio(hex(a), hex(b));
171
336
  }
172
337
 
173
338
  /**
@@ -1,10 +1,6 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
- /** @typedef {{token: string, props: string[], when: string[]}} Read */
5
- /** @typedef {{message: string, run: string[], also: string[], soft?: boolean}} CheckFailure */
6
- /** @typedef {import('./_parts.mjs').PartData} PartData */
7
- /** @typedef {import('./_parts.mjs').TextPair} TextPair */
8
4
  /**
9
5
  * @param {import('./_project.mjs').ThemeProject} project
10
6
  * @param {PartData} parts
@@ -35,12 +31,13 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
35
31
  checkTokenOn: (theme: string, target: string, token: string, value: string, P: string, when?: string, also?: string) => CheckFailure | null;
36
32
  checkTokenGlobal: (token: string, _P: string) => CheckFailure | null;
37
33
  variantValues: (target: string) => Record<string, string[]>;
38
- contrast: (value: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio, alphaOf, compositeOver, page }: {
34
+ contrast: (value: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio, alphaOf, compositeOver, page, drawnByRule, }: {
39
35
  parseColor: (v: unknown) => [number, number, number] | null;
40
36
  ratio: (a: number[], b: number[]) => number;
41
37
  alphaOf: (v: unknown) => number;
42
38
  compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number];
43
39
  page: (mode: string) => string | null | undefined;
40
+ drawnByRule?: (pair: TextPair, side: "fg" | "bg", mode: string) => boolean;
44
41
  }, extra?: TextPair[]) => {
45
42
  problems: {
46
43
  part: string;
@@ -73,6 +70,7 @@ export type CheckFailure = {
73
70
  run: string[];
74
71
  also: string[];
75
72
  soft?: boolean;
73
+ held?: string[];
76
74
  };
77
75
  export type PartData = import("./_parts.mjs").PartData;
78
76
  export type TextPair = import("./_parts.mjs").TextPair;
@@ -9,6 +9,7 @@
9
9
  * @position api/theme-edit — compile-time knowledge over the part data
10
10
  */
11
11
 
12
+ import {ratioDown} from '../theme/palette/generate/color.mjs';
12
13
  import {DIRECT, GROUPS, HOW} from './_tables.mjs';
13
14
  import {splitTop} from './_css.mjs';
14
15
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
@@ -35,10 +36,17 @@ const SOFT =
35
36
  /^--(color-data|color-syntax|syntax|duration|ease|z-|layer|breakpoint|text-display-\d|color-icon-[a-z]+$)/;
36
37
 
37
38
  /** @typedef {{token: string, props: string[], when: string[]}} Read */
38
- /** @typedef {{message: string, run: string[], also: string[], soft?: boolean}} CheckFailure */
39
+ /** @typedef {{message: string, run: string[], also: string[], soft?: boolean, held?: string[]}} CheckFailure */
39
40
  /** @typedef {import('./_parts.mjs').PartData} PartData */
40
41
  /** @typedef {import('./_parts.mjs').TextPair} TextPair */
41
42
 
43
+ /** The aspect group each property belongs to, the first group that lists it. */
44
+ const GROUP_OF_PROP = new Map(
45
+ Object.entries(GROUPS)
46
+ .flatMap(([g, ps]) => ps.map(p => /** @type {[string, string]} */ ([p, g])))
47
+ .reverse(),
48
+ );
49
+
42
50
  /**
43
51
  * @param {import('./_project.mjs').ThemeProject} project
44
52
  * @param {PartData} parts
@@ -90,8 +98,7 @@ export function makeCompiler(project, parts) {
90
98
  const isToken = tok => Object.hasOwn(TYPE, tok);
91
99
 
92
100
  /** @param {string} p */
93
- const groupOfProp = p =>
94
- Object.entries(GROUPS).find(([, ps]) => ps.includes(p))?.[0] ?? null;
101
+ const groupOfProp = p => GROUP_OF_PROP.get(p) ?? null;
95
102
 
96
103
  /** @param {string} t @returns {string | null} */
97
104
  function groupOfToken(t) {
@@ -458,10 +465,32 @@ export function makeCompiler(project, parts) {
458
465
  : g === 'background'
459
466
  ? ['background-color', 'background', 'background-image']
460
467
  : null;
468
+ // A fill token on a part Core also draws with no fill of its own
469
+ // where it sits in another part (main content inside an app shell is
470
+ // transparent there, and the shell's own fill shows; the census sees
471
+ // that clear fill in no condition of the part's own): the token still
472
+ // reaches what inside reads it, but not that part's look there. Said,
473
+ // with the property that paints the part itself everywhere.
474
+ const clear = ['background-color', 'background'].some(
475
+ prop =>
476
+ (MAP[target]?.own?.[prop]?.values ?? []).includes('transparent') &&
477
+ !Object.values(MAP[target]?.at?.[prop] ?? {}).includes('transparent'),
478
+ );
479
+ if (
480
+ g === 'background' &&
481
+ clear &&
482
+ fed.some(f => f.part === target && (wanted ?? []).includes(f.prop))
483
+ )
484
+ return {
485
+ soft: true,
486
+ message: `${target} is also drawn with no fill of its own inside another part (main content in an app shell is transparent, and the shell's fill shows), so there ${token} colors only what inside ${target} reads it, not ${target} itself. To paint ${target} itself everywhere: ${P} set ${theme} background-color ${quoteCommandArgument(value)} --on ${target}${when ? ` --when ${when}` : ''}${also}`,
487
+ run: [
488
+ `${P} set ${theme} background-color ${quoteCommandArgument(value)} --on ${target}${when ? ` --when ${when}` : ''}${also}`,
489
+ ],
490
+ also: [],
491
+ };
461
492
  // The part reads the token the user named: it is set as asked, and
462
493
  // the result names what it feeds.
463
- void wanted;
464
- void fed;
465
494
  return null;
466
495
  }
467
496
  // Only a token of the same kind takes the value: a weight never goes to
@@ -507,15 +536,35 @@ export function makeCompiler(project, parts) {
507
536
  ? 'font-family'
508
537
  : 'font-weight'
509
538
  : g && DIRECT[g];
510
- if (direct)
511
- run.push(
512
- `${P} set ${theme} ${direct} ${v} --on ${target} # sets it directly, whatever token it uses`,
513
- );
514
539
  const kids = g
515
540
  ? (MAP[target]?.contains ?? [])
516
541
  .filter(c => partReads(c, g).length)
517
542
  .slice(0, 4)
518
543
  : [];
544
+ // A part that reads no font token of this kind, holding parts that do
545
+ // (a tab list's tabs size their text from --text-label-size): those
546
+ // tokens,
547
+ // set on it, reach each of them; the property set on it directly does
548
+ // not, since they set it themselves.
549
+ const kidTokens =
550
+ reads.length || g !== 'font'
551
+ ? []
552
+ : [
553
+ ...new Set(
554
+ kids.flatMap(c =>
555
+ partReads(c, /** @type {string} */ (g))
556
+ .filter(r => kindOf(r.token) === kindOf(token))
557
+ .map(r => r.token),
558
+ ),
559
+ ),
560
+ ].slice(0, 3);
561
+ run.push(
562
+ ...kidTokens.map(t => `${P} set ${theme} ${t} ${v} --on ${target}`),
563
+ );
564
+ if (direct && !kidTokens.length)
565
+ run.push(
566
+ `${P} set ${theme} ${direct} ${v} --on ${target} # sets it directly, whatever token it uses`,
567
+ );
519
568
  const what = g
520
569
  ? `${target}'s ${g} comes from ${
521
570
  reads.length
@@ -525,12 +574,16 @@ export function makeCompiler(project, parts) {
525
574
  r => r.token + fmtWhen(r.when) + statusNote(target, r.token),
526
575
  )
527
576
  .join(', ')
528
- : 'no token, so set the property directly'
577
+ : kidTokens.length
578
+ ? `no token; the parts inside it read ${kidTokens.join(', ')} for theirs, so set ${kidTokens.length > 1 ? 'those' : 'that'} on ${target}`
579
+ : 'no token, so set the property directly'
529
580
  }`
530
581
  : `${target} reads: ${[...allReads(target)].slice(0, 8).join(', ')}`;
531
582
  return {
532
583
  message: `${target} never reads ${token}. ${what}.`,
533
584
  run,
585
+ // (The tokens the parts it holds read for this, when it reads none.)
586
+ held: kidTokens,
534
587
  also: kids.length
535
588
  ? [
536
589
  `parts inside ${target} with their own ${g}: ${kids.join(', ')} (${HOW} ${kids[0]})`,
@@ -583,11 +636,24 @@ export function makeCompiler(project, parts) {
583
636
  info?.targets.find(x => x.className === `astryx-${target}`) ??
584
637
  info?.targets[0];
585
638
  const fromDocs = t?.values ?? {};
639
+ // (A doc that lists the part with no values for a prop, a shared
640
+ // indicator's doc, leaves them to another doc that lists the same part
641
+ // with them: CheckboxInput names its box's sizes.)
642
+ /** @param {string} p */
643
+ const elsewhere = p =>
644
+ Object.values(project.components ?? {})
645
+ .flatMap((/** @type {any} */ c) => c.targets ?? [])
646
+ .find(
647
+ (/** @type {any} */ x) =>
648
+ x.className === `astryx-${target}` && x.values?.[p]?.length,
649
+ )?.values[p];
586
650
  const seen = MAP[target]?.attrs ?? {};
587
651
  /** @type {Record<string, string[]>} */
588
652
  const out = {};
589
653
  for (const p of TARGET.get(target)?.props ?? [])
590
- out[p] = fromDocs[p]?.length ? fromDocs[p] : (seen[p] ?? []);
654
+ out[p] = fromDocs[p]?.length
655
+ ? fromDocs[p]
656
+ : (elsewhere(p) ?? seen[p] ?? []);
591
657
  // A state Core marks with more than one value (a checkbox's checked and
592
658
  // indeterminate looks) is a condition --when names by value.
593
659
  for (const st of TARGET.get(target)?.states ?? [])
@@ -645,16 +711,25 @@ export function makeCompiler(project, parts) {
645
711
  * @param {(pair: TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} value
646
712
  * @param {(pair: TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} baseValue
647
713
  * @param {string[]} modes
648
- * @param {{parseColor: (v: unknown) => [number, number, number] | null, ratio: (a: number[], b: number[]) => number, alphaOf: (v: unknown) => number, compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number], page: (mode: string) => string | null | undefined}} helpers
714
+ * @param {{parseColor: (v: unknown) => [number, number, number] | null, ratio: (a: number[], b: number[]) => number, alphaOf: (v: unknown) => number, compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number], page: (mode: string) => string | null | undefined, drawnByRule?: (pair: TextPair, side: 'fg' | 'bg', mode: string) => boolean}} helpers
649
715
  * `page` is the page color in a mode: a see-through background is drawn
650
716
  * over it, and see-through text over that background, before measuring.
717
+ * `drawnByRule`: whether the base theme's own rule for a part draws a
718
+ * side (not its token), so the side is named by its color.
651
719
  * @param {TextPair[]} [extra] more pairs to measure (a part's variants)
652
720
  */
653
721
  function contrast(
654
722
  value,
655
723
  baseValue,
656
724
  modes,
657
- {parseColor, ratio, alphaOf, compositeOver, page},
725
+ {
726
+ parseColor,
727
+ ratio,
728
+ alphaOf,
729
+ compositeOver,
730
+ page,
731
+ drawnByRule = () => false,
732
+ },
658
733
  extra = [],
659
734
  ) {
660
735
  /**
@@ -663,13 +738,23 @@ export function makeCompiler(project, parts) {
663
738
  * the part sits in, else the page).
664
739
  * @param {unknown} fg @param {unknown} bg @param {string} m
665
740
  * @param {unknown} [beneath]
741
+ * @param {boolean} [onPage] whether a see-through region sits on the page
666
742
  */
667
- const drawn = (fg, bg, m, beneath = page(m)) => {
743
+ const drawn = (fg, bg, m, beneath = page(m), onPage = true) => {
744
+ /** @type {[number, number, number]} */
745
+ const pageColor =
746
+ parseColor(page(m)) ?? (m === 'dark' ? [0, 0, 0] : [255, 255, 255]);
747
+ // (A see-through region, a translucent top bar, is drawn over the
748
+ // page itself. A surface Core draws in its own scheme, a lightbox,
749
+ // sits over its media and a blurred page, not a bare one: its color
750
+ // is the ground as it is.)
751
+ const region = parseColor(beneath);
668
752
  /** @type {[number, number, number]} */
669
- const ground =
670
- parseColor(beneath) ??
671
- parseColor(page(m)) ??
672
- (m === 'dark' ? [0, 0, 0] : [255, 255, 255]);
753
+ const ground = !region
754
+ ? pageColor
755
+ : onPage
756
+ ? compositeOver(region, alphaOf(beneath), pageColor)
757
+ : region;
673
758
  const bgAlpha = alphaOf(bg);
674
759
  const back = parseColor(bg);
675
760
  const under =
@@ -744,9 +829,12 @@ export function makeCompiler(project, parts) {
744
829
  // needs no 4.5:1 (and must stay dimmer than the live text beside it).
745
830
  if (/^--color-(text|icon)-disabled$/.test(String(p.fg.tokens[0])))
746
831
  continue;
832
+ // (Text on another part that sets text of its own takes that part's
833
+ // text; a part's own color set on it, `ownColor`, is its text there.)
747
834
  if (
748
835
  p.fg.target !== p.bg.target &&
749
836
  p.bg.target &&
837
+ !(/** @type {any} */ (p).ownColor) &&
750
838
  partReads(p.bg.target, 'text').length
751
839
  )
752
840
  continue;
@@ -785,7 +873,7 @@ export function makeCompiler(project, parts) {
785
873
  }
786
874
  const measured = stops.map(stop => ({
787
875
  stop,
788
- pair: drawn(fg, stop, m, beneath),
876
+ pair: drawn(fg, stop, m, beneath, !(/** @type {any} */ (p).mediaOf)),
789
877
  }));
790
878
  if (stops.length > 1 && measured.some(x => !x.pair)) {
791
879
  if (whole !== baseValue(p, 'bg', m)) unchecked.add(String(whole));
@@ -822,7 +910,15 @@ export function makeCompiler(project, parts) {
822
910
  m,
823
911
  baseBeneath,
824
912
  );
825
- if (was && ratio(was[0], was[1]) <= r + 0.05) continue;
913
+ // No worse than the base theme draws it: none of the theme's own,
914
+ // and where the theme draws neither side, the base theme's own
915
+ // failure (`base`), a note with its line.
916
+ const baseDrawn =
917
+ fg === baseValue(p, 'fg', m) &&
918
+ bg === baseValue(p, 'bg', m) &&
919
+ beneath === baseBeneath;
920
+ if (was && ratio(was[0], was[1]) <= r + 0.05 && !baseDrawn) continue;
921
+ const base = Boolean(was && ratio(was[0], was[1]) <= r + 0.05);
826
922
  // Pairs alike in color are one problem only when they read the same
827
923
  // token on the same part: text on another token or on another part
828
924
  // is another fix, and shows as they part ways.
@@ -832,12 +928,14 @@ export function makeCompiler(project, parts) {
832
928
  out.push({
833
929
  part: p.text,
834
930
  mode: m,
835
- ratio: Number(r.toFixed(2)),
931
+ // (Cut down, never rounded up: just under a need never meets it.)
932
+ ratio: ratioDown(r),
836
933
  sample: p.sample,
837
934
  // A side the theme changed is named by the value it set, not the
838
935
  // token the part reads without it.
936
+ // (So is one the base theme's own rule draws, not its token.)
839
937
  fg:
840
- fg !== baseValue(p, 'fg', m)
938
+ fg !== baseValue(p, 'fg', m) || drawnByRule(p, 'fg', m)
841
939
  ? String(fg)
842
940
  : (p.fg.tokens[0] ?? String(fg)),
843
941
  bgPart: p.bg.target,
@@ -851,7 +949,7 @@ export function makeCompiler(project, parts) {
851
949
  ? `${bg}, its gradient where the text sits`
852
950
  : stops.length > 1
853
951
  ? `${bg}, a stop of its gradient`
854
- : bg !== baseValue(p, 'bg', m)
952
+ : bg !== baseValue(p, 'bg', m) || drawnByRule(p, 'bg', m)
855
953
  ? String(bg)
856
954
  : (p.bg.tokens[0] ?? String(bg)),
857
955
  // What a fix needs: the token the text reads, the part that draws
@@ -862,6 +960,7 @@ export function makeCompiler(project, parts) {
862
960
  when: /** @type {any} */ (p).when ?? null,
863
961
  ground: pair[1],
864
962
  pair: p,
963
+ ...(base ? {base: true} : {}),
865
964
  });
866
965
  }
867
966
  }