@astryxdesign/cli 0.7.18-canary.gfca8508 → 0.7.18

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 (341) hide show
  1. package/CHANGELOG.md +185 -19
  2. package/README.md +19 -19
  3. package/api/component/_adapter.d.mts +2 -1
  4. package/api/component/_adapter.mjs +2 -1
  5. package/api/docs/_adapter.d.mts +6 -5
  6. package/api/docs/_adapter.mjs +36 -5
  7. package/api/doctor/_adapter.d.mts +6 -3
  8. package/api/doctor/_adapter.mjs +13 -5
  9. package/api/doctor/doctor.mjs +2 -2
  10. package/api/doctor/font-packages.d.mts +36 -0
  11. package/api/doctor/font-packages.mjs +124 -0
  12. package/api/doctor/theme-checks.mjs +110 -49
  13. package/api/experimental.d.mts +0 -2
  14. package/api/experimental.mjs +0 -12
  15. package/api/icon/_adapter.d.mts +1 -1
  16. package/api/icon/_adapter.mjs +1 -0
  17. package/api/icon/_authoring.mjs +17 -8
  18. package/api/icon/_default-look.mjs +15 -15
  19. package/api/icon/add/add.mjs +9 -4
  20. package/api/icon/exportIconIndex.doc.mjs +1 -1
  21. package/api/icon/icon.doc.mjs +1 -1
  22. package/api/icon/icon.type.d.mts +33 -33
  23. package/api/icon/icon.type.mjs +45 -45
  24. package/api/icon/iconAdd.doc.mjs +1 -1
  25. package/api/icon/iconNewSet.doc.mjs +3 -3
  26. package/api/icon/iconUse.doc.mjs +5 -5
  27. package/api/icon/rankIconIndex.doc.mjs +1 -1
  28. package/api/icon/use/use.mjs +4 -4
  29. package/api/init/run/run.mjs +0 -1
  30. package/api/integration/add-helpers.mjs +1 -1
  31. package/api/render/_adapter.mjs +7 -1
  32. package/api/search/ORDERING.md +1 -1
  33. package/api/search/_candidate-score.mjs +20 -0
  34. package/api/search/_words.d.mts +8 -0
  35. package/api/search/_words.mjs +15 -0
  36. package/api/template/template.type.d.mts +2 -2
  37. package/api/template/template.type.mjs +2 -2
  38. package/api/theme/_adapter.mjs +19 -11
  39. package/api/theme/build/build.d.mts +19 -51
  40. package/api/theme/build/build.mjs +195 -189
  41. package/api/theme/build/font-warning.d.mts +19 -2
  42. package/api/theme/build/font-warning.mjs +46 -5
  43. package/api/theme/generateTonalPalette.doc.mjs +1 -1
  44. package/api/theme/palette/generate/derive-look.mjs +108 -37
  45. package/api/theme/palette/generate/mapping.mjs +2 -0
  46. package/api/theme/template/template.d.mts +0 -17
  47. package/api/theme/template/template.mjs +1 -42
  48. package/api/theme/theme.type.d.mts +5 -4
  49. package/api/theme/theme.type.mjs +5 -4
  50. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  51. package/api/theme/themeRemove.doc.mjs +1 -1
  52. package/assets/codemods/transforms/v0.7.0/preserve-bottom-sheet-content-padding.mjs +3 -1
  53. package/assets/component-list.generated.json +1 -1
  54. package/assets/discover/official-packages.json +26 -2
  55. package/assets/docs/author-a-theme.doc.mjs +6 -5
  56. package/assets/docs/browser-support.doc.mjs +1 -0
  57. package/assets/docs/icons.doc.mjs +8 -7
  58. package/assets/docs/motion.doc.mjs +46 -0
  59. package/assets/docs/theme.doc.dense.mjs +6 -17
  60. package/assets/docs/theme.doc.mjs +6 -16
  61. package/assets/docs/theme.doc.zh.mjs +6 -16
  62. package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
  63. package/assets/docs/tree/font-setup.doc.mjs +30 -0
  64. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  65. package/assets/docs/tree/template-icons.doc.mjs +3 -3
  66. package/assets/docs/tree/tokens-color.doc.mjs +5 -0
  67. package/assets/docs/tree/tokens.doc.mjs +4 -3
  68. package/assets/docs/tree/updates.doc.mjs +1 -1
  69. package/assets/docs-routes.generated.json +1 -1
  70. package/assets/docs.generated.json +2 -2
  71. package/assets/icons/definitions/drag.doc.mjs +1 -0
  72. package/assets/search-catalog.generated.json +2 -2
  73. package/assets/self-audit.generated.json +1 -1
  74. package/assets/templates/blocks/components/Card/SelectableCardElevated.doc.mjs +1 -1
  75. package/assets/templates/blocks/components/Card/SelectableCardElevated.tsx +20 -10
  76. package/assets/templates/blocks/components/Card/SelectableCardShowcase.doc.mjs +1 -1
  77. package/assets/templates/blocks/components/Card/SelectableCardShowcase.tsx +36 -16
  78. package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +6 -0
  79. package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +6 -0
  80. package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.doc.mjs +14 -0
  81. package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.tsx +63 -0
  82. package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.doc.mjs +29 -0
  83. package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.tsx +237 -0
  84. package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +10 -72
  85. package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.doc.mjs +1 -1
  86. package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.tsx +7 -7
  87. package/assets/templates/blocks/components/Table/TableCustomRowTable.doc.mjs +14 -0
  88. package/assets/templates/blocks/components/Table/TableCustomRowTable.tsx +96 -0
  89. package/assets/templates/components.generated.json +1 -1
  90. package/assets/templates/pages/ai-chat-landing/page.tsx +4 -0
  91. package/assets/templates/pages/dashboard-scorecard/page.tsx +26 -7
  92. package/assets/templates/pages/editor/page.tsx +13 -3
  93. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +2 -2
  94. package/assets/templates/themes/butter/butterTheme.ts +12 -10
  95. package/assets/templates/themes/butter/icons.tsx +2 -0
  96. package/assets/templates/themes/chocolate/chocolateTheme.ts +1 -0
  97. package/assets/templates/themes/chocolate/icons.tsx +2 -0
  98. package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +1 -1
  99. package/assets/templates/themes/gothic/gothicTheme.ts +1 -0
  100. package/assets/templates/themes/gothic/icons.tsx +2 -0
  101. package/assets/templates/themes/matcha/icons.tsx +2 -0
  102. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +2 -2
  103. package/assets/templates/themes/matcha/matchaTheme.ts +1 -0
  104. package/assets/templates/themes/neutral/icons.tsx +2 -0
  105. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
  106. package/assets/templates/themes/neutral/neutralTheme.ts +1 -0
  107. package/assets/templates/themes/stone/icons.tsx +2 -0
  108. package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
  109. package/assets/templates/themes/stone/stoneTheme.ts +1 -0
  110. package/assets/templates/themes/y2k/icons.tsx +2 -0
  111. package/assets/templates/themes/y2k/y2kTheme.ts +1 -0
  112. package/assets/theme.template.ts +9 -5
  113. package/authoring/config/parse.mjs +1 -1
  114. package/authoring/doctypes/base/type.ts +2 -3
  115. package/authoring/doctypes/component/component.doc.mjs +1 -1
  116. package/authoring/doctypes/icon-set/icon-names.mjs +1 -0
  117. package/authoring/integration/integration.doc.mjs +1 -1
  118. package/authoring/integration/type.ts +1 -1
  119. package/clients/cli/build-id.generated.json +1 -1
  120. package/clients/cli/commands/experimental/icon.mjs +7 -7
  121. package/clients/cli/commands/experimental/index.mjs +0 -5
  122. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  123. package/clients/cli/commands/experimental-icon-use.doc.mjs +4 -4
  124. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  125. package/clients/cli/commands/experimental.doc.mjs +2 -6
  126. package/clients/cli/commands/template.mjs +1 -1
  127. package/clients/cli/commands/theme-build.doc.mjs +8 -1
  128. package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -1
  129. package/clients/cli/commands/theme-remove.doc.mjs +1 -1
  130. package/clients/cli/commands/theme.doc.mjs +1 -11
  131. package/clients/cli/commands/theme.mjs +110 -475
  132. package/clients/cli/commands.generated.json +1 -1
  133. package/clients/cli/index.mjs +4 -34
  134. package/clients/cli/lib/base-gate.mjs +2 -3
  135. package/clients/cli/lib/cli-error.mjs +8 -72
  136. package/clients/cli/lib/define-command.mjs +0 -19
  137. package/clients/cli/lib/json-shim.mjs +11 -633
  138. package/clients/cli/lib/manifest.mjs +0 -4
  139. package/clients/cli/lib/stray-option.mjs +1 -2
  140. package/clients/cli/manifest.generated.json +1 -1
  141. package/foundation/agent-docs/agent-docs.mjs +1 -1
  142. package/foundation/color/css-color.mjs +2 -3
  143. package/foundation/discovery/app-layout.d.mts +13 -0
  144. package/foundation/discovery/app-layout.mjs +35 -0
  145. package/foundation/discovery/fixture-refs.d.mts +51 -0
  146. package/foundation/discovery/fixture-refs.mjs +351 -0
  147. package/foundation/discovery/icon-definition-discovery.mjs +1 -1
  148. package/foundation/discovery/icon-ranking.mjs +2 -2
  149. package/foundation/discovery/icon-set-checks.mjs +1 -1
  150. package/foundation/discovery/icon-set-discovery.mjs +1 -1
  151. package/foundation/discovery/icon-set-writer.d.mts +24 -7
  152. package/foundation/discovery/icon-set-writer.mjs +66 -22
  153. package/foundation/discovery/static-descriptor.d.mts +49 -0
  154. package/foundation/discovery/static-descriptor.mjs +548 -0
  155. package/foundation/discovery/template-adapter.d.mts +0 -47
  156. package/foundation/discovery/template-adapter.mjs +1 -333
  157. package/foundation/discovery/theme-discovery.d.mts +6 -47
  158. package/foundation/discovery/theme-discovery.mjs +15 -537
  159. package/foundation/doc-compiler/import.mjs +1 -1
  160. package/foundation/env/user-dirs.d.mts +5 -2
  161. package/foundation/env/user-dirs.mjs +12 -5
  162. package/foundation/fonts/next-font.d.mts +26 -0
  163. package/foundation/fonts/next-font.mjs +149 -0
  164. package/foundation/fs/empty-folder.mjs +2 -2
  165. package/foundation/fs/read-record.mjs +11 -4
  166. package/foundation/pictures/pictures.d.mts +1 -45
  167. package/foundation/pictures/pictures.mjs +8 -8
  168. package/foundation/release/folder-lock.mjs +3 -2
  169. package/foundation/render/cut-short.d.mts +2 -2
  170. package/foundation/render/cut-short.mjs +2 -2
  171. package/foundation/render/drawn-contrast.d.mts +2 -2
  172. package/foundation/render/drawn-contrast.mjs +2 -2
  173. package/foundation/render/font-probe.d.mts +2 -2
  174. package/foundation/render/font-probe.mjs +2 -2
  175. package/foundation/render/layers.mjs +1 -2
  176. package/foundation/render/package-resolve-hooks.d.mts +25 -5
  177. package/foundation/render/package-resolve-hooks.mjs +77 -14
  178. package/foundation/render/page-worker.mjs +24 -12
  179. package/foundation/render/part-boxes.d.mts +2 -3
  180. package/foundation/render/part-boxes.mjs +2 -3
  181. package/foundation/render/picture-chrome.mjs +5 -0
  182. package/foundation/render/render-page.d.mts +1 -1
  183. package/foundation/render/render-page.mjs +4 -5
  184. package/foundation/render/single-copy-hooks.d.mts +2 -0
  185. package/foundation/render/single-copy-hooks.mjs +2 -0
  186. package/foundation/response/error-codes.doc.mjs +14 -14
  187. package/foundation/response/error-codes.mjs +13 -13
  188. package/foundation/response/response-types.doc.mjs +7 -68
  189. package/foundation/runtime/css-tree.mjs +2 -2
  190. package/foundation/runtime/word-table.d.mts +1 -1
  191. package/foundation/runtime/word-table.mjs +1 -1
  192. package/foundation/suggest/other-command.d.mts +52 -15
  193. package/foundation/suggest/other-command.mjs +168 -45
  194. package/foundation/text/suggest-order.d.mts +7 -0
  195. package/foundation/text/suggest-order.mjs +1 -1
  196. package/package.json +7 -8
  197. package/api/theme-edit/_adapter.d.mts +0 -228
  198. package/api/theme-edit/_adapter.mjs +0 -2025
  199. package/api/theme-edit/_catalog.d.mts +0 -172
  200. package/api/theme-edit/_catalog.mjs +0 -806
  201. package/api/theme-edit/_check.d.mts +0 -391
  202. package/api/theme-edit/_check.mjs +0 -9370
  203. package/api/theme-edit/_color.d.mts +0 -135
  204. package/api/theme-edit/_color.mjs +0 -480
  205. package/api/theme-edit/_compiler.d.mts +0 -77
  206. package/api/theme-edit/_compiler.mjs +0 -1053
  207. package/api/theme-edit/_context.d.mts +0 -399
  208. package/api/theme-edit/_context.mjs +0 -1778
  209. package/api/theme-edit/_css.d.mts +0 -169
  210. package/api/theme-edit/_css.mjs +0 -1167
  211. package/api/theme-edit/_edit.d.mts +0 -167
  212. package/api/theme-edit/_edit.mjs +0 -11220
  213. package/api/theme-edit/_how-commands.d.mts +0 -315
  214. package/api/theme-edit/_how-commands.mjs +0 -1664
  215. package/api/theme-edit/_how-question.d.mts +0 -341
  216. package/api/theme-edit/_how-question.mjs +0 -33339
  217. package/api/theme-edit/_how-sides.d.mts +0 -22
  218. package/api/theme-edit/_how-sides.mjs +0 -173
  219. package/api/theme-edit/_how-steps.d.mts +0 -42
  220. package/api/theme-edit/_how-steps.mjs +0 -208
  221. package/api/theme-edit/_how-values.d.mts +0 -29
  222. package/api/theme-edit/_how-values.mjs +0 -111
  223. package/api/theme-edit/_how-words.d.mts +0 -15
  224. package/api/theme-edit/_how-words.mjs +0 -239
  225. package/api/theme-edit/_how.d.mts +0 -55
  226. package/api/theme-edit/_how.mjs +0 -2388
  227. package/api/theme-edit/_importers.d.mts +0 -38
  228. package/api/theme-edit/_importers.mjs +0 -188
  229. package/api/theme-edit/_marks.d.mts +0 -39
  230. package/api/theme-edit/_marks.mjs +0 -67
  231. package/api/theme-edit/_missed.d.mts +0 -56
  232. package/api/theme-edit/_missed.mjs +0 -1128
  233. package/api/theme-edit/_name-rule.d.mts +0 -11
  234. package/api/theme-edit/_name-rule.mjs +0 -12
  235. package/api/theme-edit/_normal.d.mts +0 -365
  236. package/api/theme-edit/_normal.mjs +0 -1978
  237. package/api/theme-edit/_overview.d.mts +0 -9
  238. package/api/theme-edit/_overview.mjs +0 -293
  239. package/api/theme-edit/_palette.d.mts +0 -616
  240. package/api/theme-edit/_palette.mjs +0 -2776
  241. package/api/theme-edit/_part-pieces.d.mts +0 -54
  242. package/api/theme-edit/_part-pieces.mjs +0 -179
  243. package/api/theme-edit/_part-words.d.mts +0 -39
  244. package/api/theme-edit/_part-words.mjs +0 -242
  245. package/api/theme-edit/_parts.d.mts +0 -402
  246. package/api/theme-edit/_parts.mjs +0 -2322
  247. package/api/theme-edit/_picture-traits.d.mts +0 -259
  248. package/api/theme-edit/_picture-traits.mjs +0 -1030
  249. package/api/theme-edit/_png.d.mts +0 -94
  250. package/api/theme-edit/_png.mjs +0 -479
  251. package/api/theme-edit/_preview-app.d.mts +0 -172
  252. package/api/theme-edit/_preview-app.mjs +0 -6430
  253. package/api/theme-edit/_preview.d.mts +0 -484
  254. package/api/theme-edit/_preview.mjs +0 -2775
  255. package/api/theme-edit/_project.d.mts +0 -207
  256. package/api/theme-edit/_project.mjs +0 -643
  257. package/api/theme-edit/_resolved.d.mts +0 -46
  258. package/api/theme-edit/_resolved.mjs +0 -800
  259. package/api/theme-edit/_set-line.d.mts +0 -29
  260. package/api/theme-edit/_set-line.mjs +0 -100
  261. package/api/theme-edit/_settings.d.mts +0 -2426
  262. package/api/theme-edit/_settings.mjs +0 -18449
  263. package/api/theme-edit/_tables.d.mts +0 -227
  264. package/api/theme-edit/_tables.mjs +0 -1128
  265. package/api/theme-edit/_text-looks.d.mts +0 -78
  266. package/api/theme-edit/_text-looks.mjs +0 -376
  267. package/api/theme-edit/_vet.d.mts +0 -50
  268. package/api/theme-edit/_vet.mjs +0 -166
  269. package/api/theme-edit/how/how.d.mts +0 -17
  270. package/api/theme-edit/how/how.mjs +0 -28
  271. package/api/theme-edit/new/new.d.mts +0 -11
  272. package/api/theme-edit/new/new.mjs +0 -22
  273. package/api/theme-edit/preview-add/preview-add.d.mts +0 -14
  274. package/api/theme-edit/preview-add/preview-add.mjs +0 -25
  275. package/api/theme-edit/preview-app/preview-app.d.mts +0 -13
  276. package/api/theme-edit/preview-app/preview-app.mjs +0 -24
  277. package/api/theme-edit/preview-list/preview-list.d.mts +0 -10
  278. package/api/theme-edit/preview-list/preview-list.mjs +0 -21
  279. package/api/theme-edit/preview-remove/preview-remove.d.mts +0 -12
  280. package/api/theme-edit/preview-remove/preview-remove.mjs +0 -23
  281. package/api/theme-edit/set/set.d.mts +0 -13
  282. package/api/theme-edit/set/set.mjs +0 -24
  283. package/api/theme-edit/show/show.d.mts +0 -13
  284. package/api/theme-edit/show/show.mjs +0 -24
  285. package/api/theme-edit/theme-edit.d.mts +0 -12
  286. package/api/theme-edit/theme-edit.mjs +0 -36
  287. package/api/theme-edit/theme-edit.type.d.mts +0 -730
  288. package/api/theme-edit/theme-edit.type.mjs +0 -342
  289. package/api/theme-edit/themeEditHow.doc.d.mts +0 -6
  290. package/api/theme-edit/themeEditHow.doc.mjs +0 -105
  291. package/api/theme-edit/themeEditNew.doc.d.mts +0 -5
  292. package/api/theme-edit/themeEditNew.doc.mjs +0 -112
  293. package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +0 -6
  294. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +0 -121
  295. package/api/theme-edit/themeEditPreviewApp.doc.d.mts +0 -6
  296. package/api/theme-edit/themeEditPreviewApp.doc.mjs +0 -87
  297. package/api/theme-edit/themeEditPreviewList.doc.d.mts +0 -6
  298. package/api/theme-edit/themeEditPreviewList.doc.mjs +0 -62
  299. package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +0 -6
  300. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +0 -96
  301. package/api/theme-edit/themeEditSet.doc.d.mts +0 -6
  302. package/api/theme-edit/themeEditSet.doc.mjs +0 -175
  303. package/api/theme-edit/themeEditShow.doc.d.mts +0 -6
  304. package/api/theme-edit/themeEditShow.doc.mjs +0 -118
  305. package/api/theme-edit/themeEditUndo.doc.d.mts +0 -6
  306. package/api/theme-edit/themeEditUndo.doc.mjs +0 -133
  307. package/api/theme-edit/undo/undo.d.mts +0 -13
  308. package/api/theme-edit/undo/undo.mjs +0 -24
  309. package/assets/preview-app/README.md +0 -6
  310. package/assets/preview-app/css.d.ts +0 -5
  311. package/assets/preview-app/gitignore +0 -4
  312. package/assets/preview-app/next.config.mjs +0 -12
  313. package/assets/preview-app/package.json +0 -24
  314. package/assets/preview-app/src/app/globals.css +0 -6
  315. package/assets/preview-app/src/app/layout.tsx +0 -21
  316. package/assets/preview-app/src/app/page.tsx +0 -94
  317. package/assets/preview-app/src/app/providers.tsx +0 -16
  318. package/assets/preview-app/tsconfig.json +0 -27
  319. package/clients/cli/commands/experimental/theme.mjs +0 -2990
  320. package/clients/cli/commands/experimental-theme-add.doc.mjs +0 -80
  321. package/clients/cli/commands/experimental-theme-compile.doc.mjs +0 -98
  322. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +0 -196
  323. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -174
  324. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +0 -139
  325. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +0 -77
  326. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +0 -105
  327. package/clients/cli/commands/experimental-theme-editor.doc.mjs +0 -49
  328. package/clients/cli/commands/experimental-theme-eject.doc.mjs +0 -72
  329. package/clients/cli/commands/experimental-theme-list.doc.mjs +0 -49
  330. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +0 -88
  331. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +0 -61
  332. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +0 -48
  333. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +0 -59
  334. package/clients/cli/commands/experimental-theme-preview.doc.mjs +0 -41
  335. package/clients/cli/commands/experimental-theme-remove.doc.mjs +0 -57
  336. package/clients/cli/commands/experimental-theme-targets.doc.mjs +0 -62
  337. package/clients/cli/commands/experimental-theme-template.doc.mjs +0 -63
  338. package/clients/cli/commands/experimental-theme-use.doc.mjs +0 -57
  339. package/clients/cli/commands/experimental-theme.doc.mjs +0 -60
  340. package/foundation/fonts/fontsource-families.generated.d.mts +0 -5
  341. package/foundation/fonts/fontsource-families.generated.mjs +0 -2110
@@ -1,1053 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file The type checker behind `astryx experimental theme`: the type of
5
- * every token (from Core's own token groups), what each part reads (from the
6
- * part data), and the checks that refuse a change that cannot take effect.
7
- * Also `how` lookups, and contrast problems the theme caused versus its base.
8
- *
9
- * @position api/theme-edit — compile-time knowledge over the part data
10
- */
11
-
12
- import {ratioDown} from '../theme/palette/generate/color.mjs';
13
- import {DIRECT, GROUPS, HOW} from './_tables.mjs';
14
- import {splitTop} from './_css.mjs';
15
- import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
16
-
17
- /** Only these token types may differ between light and dark. */
18
- export const MODAL = new Set(['color', 'shadow']);
19
-
20
- /**
21
- * Whether a token is a color by its name, as Core's color groups and the
22
- * token table type it: `--color-*`, `--syntax-*` and `--focus-outline-color`.
23
- * Settings are checked by it where no installed Core is read.
24
- * @param {string} name
25
- */
26
- export const isColorToken = name =>
27
- /^--color-|^--syntax-|^--focus-outline-color$/.test(name);
28
-
29
- /** Tokens a component may read only in some states: never refused globally. */
30
- /**
31
- * Tokens no catalog part is recorded reading, though Core reads them: code
32
- * highlighting, the display text sizes and the colored icons read them only
33
- * under a variant or in a global stylesheet. Never refused as unread.
34
- */
35
- const SOFT =
36
- /^--(color-data|color-syntax|syntax|duration|ease|z-|layer|breakpoint|text-display-\d|color-icon-[a-z]+$)/;
37
-
38
- /** @typedef {{token: string, props: string[], when: string[]}} Read */
39
- /** @typedef {{message: string, run: string[], also: string[], soft?: boolean, held?: string[]}} CheckFailure */
40
- /** @typedef {import('./_parts.mjs').PartData} PartData */
41
- /** @typedef {import('./_parts.mjs').TextPair} TextPair */
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
-
50
- /**
51
- * @param {import('./_project.mjs').ThemeProject} project
52
- * @param {PartData} parts
53
- */
54
- export function makeCompiler(project, parts) {
55
- const {core} = project;
56
- const MAP = parts.map;
57
- const TARGET = project.target;
58
-
59
- /** @type {Record<string, string>} */
60
- const TYPE = {};
61
- /** @param {unknown} obj */
62
- const groupVars = obj =>
63
- Object.values(/** @type {Record<string, unknown>} */ (obj ?? {}))
64
- .map(v => /var\((--[a-zA-Z0-9-]+)/.exec(String(v))?.[1])
65
- .filter(/** @returns {v is string} */ v => Boolean(v));
66
- /** @param {string[]} list @param {string} type */
67
- const put = (list, type) => {
68
- for (const k of list) TYPE[k] ??= type;
69
- };
70
- put(groupVars(core.colorVars), 'color');
71
- put(groupVars(core.shadowVars), 'shadow');
72
- put(groupVars(core.radiusVars), 'size');
73
- put(groupVars(core.spacingVars), 'size');
74
- put(groupVars(core.sizeVars), 'size');
75
- put(groupVars(core.textSizeVars), 'size');
76
- put(groupVars(core.borderVars), 'size');
77
- put(groupVars(core.fontWeightVars), 'number');
78
- put(groupVars(core.durationVars), 'time');
79
- put(groupVars(core.easeVars), 'easing');
80
- for (const k of Object.keys(core.tokenDefaults ?? {})) {
81
- if (TYPE[k]) continue;
82
- if (isColorToken(k)) TYPE[k] = 'color';
83
- else if (/^--font-family/.test(k)) TYPE[k] = 'font';
84
- else if (/^--font-weight|^--text-.*-weight$/.test(k)) TYPE[k] = 'number';
85
- else if (/^--shadow/.test(k)) TYPE[k] = 'shadow';
86
- else if (
87
- /^--(radius|spacing|size|text-.*-size|border-width|focus-outline-(width|offset))/.test(
88
- k,
89
- )
90
- )
91
- TYPE[k] = 'size';
92
- else if (/leading|line-height/.test(k)) TYPE[k] = 'number';
93
- else TYPE[k] = 'other';
94
- }
95
- /** @param {string} tok */
96
- const typeOf = tok => TYPE[tok] ?? 'other';
97
- /** Whether Core defines the token. @param {string} tok */
98
- const isToken = tok => Object.hasOwn(TYPE, tok);
99
-
100
- /** @param {string} p */
101
- const groupOfProp = p => GROUP_OF_PROP.get(p) ?? null;
102
-
103
- /** @param {string} t @returns {string | null} */
104
- function groupOfToken(t) {
105
- if (/^--color-(text|on|icon)-/.test(t) || t === '--color-on-accent')
106
- return 'text';
107
- if (/^--color-border/.test(t)) return 'border';
108
- if (/^--color-shadow$|^--shadow-/.test(t)) return 'shadow';
109
- if (/^--color-/.test(t)) return 'background';
110
- if (/^--radius-/.test(t)) return 'corners';
111
- if (/^--spacing-/.test(t)) return 'spacing';
112
- if (/^--(font|text)-/.test(t)) return 'font';
113
- if (/^--size-/.test(t)) return 'size';
114
- if (/^--border-width/.test(t)) return 'border';
115
- return null;
116
- }
117
-
118
- /** @type {Map<string, boolean>} */
119
- const paintsMemo = new Map();
120
- /**
121
- * Whether a visual prop changes a color the part paints: two of its
122
- * rules that differ only in that prop's value give a color property
123
- * different values.
124
- * @param {string} target @param {string} prop
125
- */
126
- function paintsBy(target, prop) {
127
- const id = `${target}|${prop}`;
128
- const known = paintsMemo.get(id);
129
- if (known != null) return known;
130
- let found = false;
131
- for (const [p, rules] of Object.entries(MAP[target]?.at ?? {})) {
132
- if (!/(^|-)color$|^background(-color)?$|^fill$|^stroke$/.test(p))
133
- continue;
134
- /** @type {Map<string, Set<string>>} */
135
- const byRest = new Map();
136
- for (const [key, value] of Object.entries(rules)) {
137
- const [attrs, ...css] = key.split(' ');
138
- const list = attrs.includes('=') ? attrs.split(',') : [];
139
- if (!list.some(kv => kv.startsWith(`${prop}=`))) continue;
140
- const rest = [
141
- ...list.filter(kv => !kv.startsWith(`${prop}=`)),
142
- ...css,
143
- ].join(' ');
144
- const seen = byRest.get(rest) ?? new Set();
145
- seen.add(String(value));
146
- byRest.set(rest, seen);
147
- }
148
- if ([...byRest.values()].some(v => v.size > 1)) {
149
- found = true;
150
- break;
151
- }
152
- }
153
- paintsMemo.set(id, found);
154
- return found;
155
- }
156
-
157
- /** A condition, kept to what a person can act on. @param {string} target @param {string} cond */
158
- function shortCond(target, cond) {
159
- if (cond === 'always') return '';
160
- const attrs = MAP[target]?.attrs ?? {};
161
- const [attrPart, ...css] = cond.split(' ');
162
- const t = TARGET.get(target);
163
- const kept = (attrPart.includes('=') ? attrPart.split(',') : []).filter(
164
- kv => {
165
- const [k] = kv.split('=');
166
- // Only the part's own visual props are read down to what a person
167
- // acts on (a size or an elevation the render happened to use is not
168
- // a condition). Anything else stays: a runtime state of the part, a
169
- // prop of another target on the same element (a selectable card's
170
- // selection on its card), and the place another component puts the
171
- // part in (the part data's aria context conditions); none is the
172
- // part at rest.
173
- if (!t?.props.includes(k) || t.states.includes(k)) return true;
174
- // A look prop drawn in more than one value that changes a color
175
- // the part paints (a variant, a status, a toast's type) tells its
176
- // renders apart; one that changes only a size or a weight (a
177
- // heading's level) is read as the part, as a size the render used.
178
- return (attrs[k]?.length ?? 0) > 1 && paintsBy(target, k);
179
- },
180
- );
181
- const cssPart = (attrPart.includes('=') ? css : [attrPart, ...css])
182
- .join(' ')
183
- .replace(/\[data-astryx-press="[a-z]+"\]/g, ':active')
184
- .trim();
185
- return [...kept, cssPart].filter(Boolean).join(' ');
186
- }
187
-
188
- /**
189
- * The tokens a part reads for one aspect (or every aspect), each with the
190
- * properties and conditions it applies under; unconditional reads first.
191
- * @param {string} target
192
- * @param {string | null} group
193
- * @returns {Read[]}
194
- */
195
- function partReads(target, group) {
196
- // The part data never changes while the compiler lives, and the checks
197
- // ask for the same part many times in one command: each answer is made
198
- // once, and handed out frozen so no caller can change it for the next.
199
- const key = `${target}\0${group ?? ''}`;
200
- const known = readsOf.get(key);
201
- if (known) return known;
202
- const reads = freshReads(target, group);
203
- for (const r of reads) {
204
- Object.freeze(r.props);
205
- Object.freeze(r.when);
206
- Object.freeze(r);
207
- }
208
- Object.freeze(reads);
209
- readsOf.set(key, reads);
210
- return reads;
211
- }
212
- /** @type {Map<string, Read[]>} */
213
- const readsOf = new Map();
214
-
215
- /**
216
- * {@link partReads}, made anew.
217
- * @param {string} target
218
- * @param {string | null} group
219
- * @returns {Read[]}
220
- */
221
- function freshReads(target, group) {
222
- const own = MAP[target]?.own ?? {};
223
- /** @type {Map<string, {token: string, props: Set<string>, when: Set<string>}>} */
224
- const out = new Map();
225
- for (const [prop, v] of Object.entries(own)) {
226
- if (group && groupOfProp(prop) !== group) continue;
227
- for (const [tok, conds] of Object.entries(v.tokens)) {
228
- const e = out.get(tok) ?? {
229
- token: tok,
230
- props: new Set(),
231
- when: new Set(),
232
- };
233
- e.props.add(prop);
234
- for (const c of conds) e.when.add(shortCond(target, c));
235
- out.set(tok, e);
236
- }
237
- }
238
- return [...out.values()]
239
- .map(e => ({token: e.token, props: [...e.props], when: [...e.when]}))
240
- .sort(
241
- (a, b) => (b.when.includes('') ? 1 : 0) - (a.when.includes('') ? 1 : 0),
242
- );
243
- }
244
-
245
- const STATUS = /-(info|success|warning|error)(-|$)/;
246
- /** @param {string} target @param {string} tok */
247
- const statusNote = (target, tok) =>
248
- STATUS.test(tok) && (TARGET.get(target)?.props ?? []).includes('status')
249
- ? ` [status ${tok.match(STATUS)?.[1]}; other statuses: same name with success|warning|error]`
250
- : '';
251
- /** @param {string[]} w */
252
- const fmtWhen = w =>
253
- w.includes('') || !w.length
254
- ? ''
255
- : ` (when ${w.filter(Boolean).slice(0, 3).join(' | ')}${w.length > 3 ? ' | ...' : ''})`;
256
-
257
- /** Every token the part or anything inside it reads. @param {string} target */
258
- function allReads(target) {
259
- /** @type {Set<string>} */
260
- const s = new Set();
261
- /** @param {string} t */
262
- const add = t => {
263
- for (const v of Object.values(MAP[t]?.own ?? {}))
264
- for (const k of Object.keys(v.tokens)) s.add(k);
265
- for (const k of Object.keys(MAP[t]?.inside ?? {})) s.add(k);
266
- };
267
- add(target);
268
- for (const c of MAP[target]?.contains ?? []) add(c);
269
- return s;
270
- }
271
- /** @type {Map<string, string[]>} */
272
- const readersCache = new Map();
273
- /** The parts that read a token anywhere. @param {string} tok */
274
- const anyReader = tok => {
275
- let r = readersCache.get(tok);
276
- if (!r) {
277
- r = Object.keys(MAP).filter(
278
- t =>
279
- Object.values(MAP[t].own).some(v => tok in v.tokens) ||
280
- tok in (MAP[t].inside ?? {}),
281
- );
282
- readersCache.set(tok, r);
283
- }
284
- return r;
285
- };
286
-
287
- /**
288
- * Where a token feeds a part: each property of the part (or of an element
289
- * or part inside it) that reads it, with its condition.
290
- * @param {string} target
291
- * @param {string} token
292
- * @returns {Array<{part: string, prop: string, when: string}>}
293
- */
294
- function feeds(target, token) {
295
- /** @type {Array<{part: string, prop: string, when: string}>} */
296
- const out = [];
297
- for (const t of [target, ...(MAP[target]?.contains ?? [])]) {
298
- for (const [prop, v] of Object.entries(MAP[t]?.own ?? {})) {
299
- for (const c of v.tokens[token] ?? [])
300
- out.push({part: t, prop, when: shortCond(t, c)});
301
- }
302
- for (const prop of MAP[t]?.inside?.[token] ?? [])
303
- out.push({part: t, prop, when: ''});
304
- }
305
- return out;
306
- }
307
-
308
- /**
309
- * One line for where a token feeds. A part inside `target` (a button in a
310
- * toast) is named as inside it, so the line never reads as every button.
311
- * @param {ReturnType<typeof feeds>} list
312
- * @param {string} [target]
313
- */
314
- const fmtFeeds = (list, target) =>
315
- [
316
- ...new Set(
317
- list.map(
318
- f =>
319
- `${f.prop}${f.part ? ` on ${f.part}${target && f.part !== target ? ` inside ${target}` : ''}` : ''}${f.when ? ` (when ${f.when})` : ''}`,
320
- ),
321
- ),
322
- ]
323
- .slice(0, 4)
324
- .join(', ');
325
-
326
- /**
327
- * Whether a token set on a part can take effect there: the part, or a part
328
- * inside it, must read it. A part with no record is checked through the
329
- * parts that contain it, else reported unchecked (soft).
330
- * @param {string} theme
331
- * @param {string} target
332
- * @param {string} token
333
- * @param {string} value
334
- * @param {string} P
335
- * @param {string} [when] the --when the token is set under (`variant:strong`)
336
- * @param {string} [also] the rest of the flags the setting carries (` --state hover --mode dark`), kept on the lines offered
337
- * @returns {CheckFailure | null}
338
- */
339
- function checkTokenOn(theme, target, token, value, P, when, also = '') {
340
- if (!MAP[target]) {
341
- return {
342
- soft: true,
343
- message: `There is no compiled record of what ${target} reads (it did not render in the catalog), so this change could not be checked.`,
344
- run: [],
345
- also: [],
346
- };
347
- }
348
- const g = groupOfToken(token);
349
- // Under a variant: only what the part reads in that variant's rules (or
350
- // rules that name no variant) counts.
351
- // (Several conditions, `variant:ghost+size:sm`: a rule counts when it
352
- // names none of them otherwise; the message names the first.)
353
- const whens = String(when ?? '')
354
- .split('+')
355
- .map(w => w.split(':'))
356
- .filter(([p, v]) => p && v);
357
- const [wProp, wVal] = whens[0] ?? [];
358
- if (wProp && wVal && allReads(target).has(token)) {
359
- const conds = [
360
- ...Object.values(MAP[target]?.own ?? {}).flatMap(
361
- x => /** @type {string[]} */ (x.tokens?.[token] ?? []),
362
- ),
363
- ];
364
- const inVariant = (/** @type {string} */ c) => {
365
- const attrs = c.split(' ')[0].split(',');
366
- return whens.every(([p, v]) => {
367
- const own = attrs.find(a => a.startsWith(`${p}=`));
368
- return !own || own === `${p}=${v}`;
369
- });
370
- };
371
- // (What a line inside the part declares is recorded as the part's
372
- // own already; any other part inside it that reads the token takes
373
- // it.)
374
- const inside =
375
- !MAP[target]?.line?.length &&
376
- (MAP[target]?.inside?.[token] ?? []).length > 0;
377
- if (conds.length && !conds.some(inVariant) && !inside) {
378
- const there = [
379
- ...new Set(
380
- Object.values(MAP[target]?.own ?? {}).flatMap(x =>
381
- Object.entries(x.tokens ?? {})
382
- .filter(([, cs]) =>
383
- /** @type {string[]} */ (cs).some(inVariant),
384
- )
385
- .map(([t]) => t)
386
- .filter(
387
- t =>
388
- groupOfToken(t) === g &&
389
- /^--color-/.test(t) === /^--color-/.test(token),
390
- ),
391
- ),
392
- ),
393
- ];
394
- return {
395
- message: `${target} (${wProp} ${wVal}) never reads ${token}: only its other ${wProp}s do.${there.length ? ` There it reads ${there.slice(0, 4).join(', ')}.` : ''}`,
396
- run: there
397
- .slice(0, 3)
398
- .map(
399
- t =>
400
- `${P} set ${theme} ${t} ${quoteCommandArgument(value)} --on ${target} --when ${when}${also}`,
401
- ),
402
- also: [],
403
- };
404
- }
405
- }
406
- // Read only under conditions the part is not drawn in by default (a
407
- // link reads --color-text-primary only as color primary; drawn as it
408
- // is, it reads --color-text-accent): set on the part with no
409
- // condition, it changes nothing in its default look. Said, with the
410
- // token that look reads and the condition that reads this one.
411
- if (
412
- !wProp &&
413
- allReads(target).has(token) &&
414
- (g === 'text' || g === 'background')
415
- ) {
416
- const conds = [
417
- ...Object.values(MAP[target]?.own ?? {}).flatMap(
418
- x => /** @type {string[]} */ (x.tokens?.[token] ?? []),
419
- ),
420
- ];
421
- const attrsOf = (/** @type {string} */ c) => c.split(' ')[0];
422
- const drawn = [
423
- ...new Set(
424
- parts.pairs
425
- .filter(p =>
426
- g === 'text' ? p.fg.target === target : p.bg.target === target,
427
- )
428
- .map(p => (g === 'text' ? p.fg.tokens[0] : p.bg.tokens[0]))
429
- .filter(Boolean),
430
- ),
431
- ];
432
- const inside = (MAP[target]?.inside?.[token] ?? []).length > 0;
433
- if (
434
- conds.length &&
435
- conds.every(c => /=/.test(attrsOf(c))) &&
436
- drawn.length &&
437
- !drawn.includes(token) &&
438
- !inside
439
- ) {
440
- const named = [
441
- ...new Set(
442
- conds
443
- .flatMap(c => attrsOf(c).split(','))
444
- .map(a => a.replace('=', ':')),
445
- ),
446
- ];
447
- return {
448
- soft: true,
449
- message: `${target} reads ${token} only when ${named.join(' or ')}; as drawn by default it reads ${drawn.join(', ')}, so this changes nothing in its default look. For the default look: ${P} set ${theme} ${drawn[0]} ${quoteCommandArgument(value)} --on ${target}${also}; for ${named[0]} alone: ${P} set ${theme} ${token} ${quoteCommandArgument(value)} --on ${target} --when ${named[0]}${also}`,
450
- run: [
451
- `${P} set ${theme} ${drawn[0]} ${quoteCommandArgument(value)} --on ${target}${also}`,
452
- `${P} set ${theme} ${token} ${quoteCommandArgument(value)} --on ${target} --when ${named[0]}${also}`,
453
- ],
454
- also: [],
455
- };
456
- }
457
- }
458
- if (allReads(target).has(token)) {
459
- // Read, but maybe only for another property: an error color that feeds
460
- // only the focus outline does not paint the background.
461
- const fed = feeds(target, token);
462
- const wanted =
463
- g === 'text'
464
- ? ['color', 'fill']
465
- : g === 'background'
466
- ? ['background-color', 'background', 'background-image']
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
- };
492
- // The part reads the token the user named: it is set as asked, and
493
- // the result names what it feeds.
494
- return null;
495
- }
496
- // Only a token of the same kind takes the value: a weight never goes to
497
- // a line height, a line height never to a weight.
498
- // Font tokens share a type across kinds (a weight and a leading are
499
- // both numbers), so the kind is read from the name.
500
- const kindOf = (/** @type {string} */ t) =>
501
- /family/.test(t)
502
- ? 'family'
503
- : /weight/.test(t)
504
- ? 'weight'
505
- : /leading|line-height/.test(t)
506
- ? 'leading'
507
- : /tracking|letter-spacing/.test(t)
508
- ? 'tracking'
509
- : typeOf(t);
510
- const reads = g
511
- ? partReads(target, g).filter(r => kindOf(r.token) === kindOf(token))
512
- : [];
513
- const v = quoteCommandArgument(value);
514
- /** @type {string[]} */
515
- const run = [];
516
- if (reads.length)
517
- run.push(
518
- ...reads
519
- .slice(0, 3)
520
- .map(
521
- r =>
522
- `${P} set ${theme} ${r.token} ${v} --on ${target}${fmtWhen(r.when) ? ` #${fmtWhen(r.when)}` : ''}`,
523
- ),
524
- );
525
- // The property that takes this kind of value: a size goes to
526
- // font-size, never to font-weight.
527
- const direct =
528
- g === 'font'
529
- ? /-(size)$|font-size-/.test(token)
530
- ? 'font-size'
531
- : /-leading$/.test(token)
532
- ? 'line-height'
533
- : /-tracking$/.test(token)
534
- ? 'letter-spacing'
535
- : /family/.test(token)
536
- ? 'font-family'
537
- : 'font-weight'
538
- : g && DIRECT[g];
539
- const kids = g
540
- ? (MAP[target]?.contains ?? [])
541
- .filter(c => partReads(c, g).length)
542
- .slice(0, 4)
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
- );
568
- const what = g
569
- ? `${target}'s ${g} comes from ${
570
- reads.length
571
- ? reads
572
- .slice(0, 4)
573
- .map(
574
- r => r.token + fmtWhen(r.when) + statusNote(target, r.token),
575
- )
576
- .join(', ')
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'
580
- }`
581
- : `${target} reads: ${[...allReads(target)].slice(0, 8).join(', ')}`;
582
- return {
583
- message: `${target} never reads ${token}. ${what}.`,
584
- run,
585
- // (The tokens the parts it holds read for this, when it reads none.)
586
- held: kidTokens,
587
- also: kids.length
588
- ? [
589
- `parts inside ${target} with their own ${g}: ${kids.join(', ')} (${HOW} ${kids[0]})`,
590
- ]
591
- : [],
592
- };
593
- }
594
-
595
- /**
596
- * Whether a whole-theme token is read by any part.
597
- * @param {string} token
598
- * @param {string} _P the command prefix (unused: the result is a note)
599
- * @returns {CheckFailure | null}
600
- */
601
- function checkTokenGlobal(token, _P) {
602
- if (anyReader(token).length || SOFT.test(token)) return null;
603
- const g = groupOfToken(token);
604
- const near = g
605
- ? Object.keys(MAP)
606
- .flatMap(t => partReads(t, g).map(r => r.token))
607
- .filter((x, i, a) => a.indexOf(x) === i && groupOfToken(x) === g)
608
- .slice(0, 6)
609
- : [];
610
- return {
611
- message: `No component reads ${token}, so setting it changes nothing.${near.length ? ` Tokens components do read for ${g}: ${near.join(', ')}.` : ''}`,
612
- run: [`${HOW} ${quoteCommandArgument(token)}`],
613
- also: [],
614
- };
615
- }
616
-
617
- /**
618
- * Each visual prop of a part and its values: from the component doc, else
619
- * the values seen in the catalog.
620
- * @param {string} target
621
- * @returns {Record<string, string[]>}
622
- */
623
- function variantValues(target) {
624
- const comp = TARGET.get(target)?.component;
625
- const info = comp ? project.components[comp] : undefined;
626
- // The component named like the part (Heading for heading) owns its
627
- // values before any other component whose docs name the same class.
628
- const pascal = target.replace(/(^|-)([a-z0-9])/g, (_, __, ch) =>
629
- ch.toUpperCase(),
630
- );
631
- const own = project.components?.[pascal]?.targets?.find(
632
- (/** @type {any} */ x) => x.className === `astryx-${target}`,
633
- );
634
- const t =
635
- own ??
636
- info?.targets.find(x => x.className === `astryx-${target}`) ??
637
- info?.targets[0];
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];
650
- const seen = MAP[target]?.attrs ?? {};
651
- /** @type {Record<string, string[]>} */
652
- const out = {};
653
- for (const p of TARGET.get(target)?.props ?? [])
654
- out[p] = fromDocs[p]?.length
655
- ? fromDocs[p]
656
- : (elsewhere(p) ?? seen[p] ?? []);
657
- // A state Core marks with more than one value (a checkbox's checked and
658
- // indeterminate looks) is a condition --when names by value.
659
- for (const st of TARGET.get(target)?.states ?? [])
660
- if ((seen[st] ?? []).some(v => v !== st)) out[st] = seen[st];
661
- return out;
662
- }
663
-
664
- /**
665
- * The color stops of a background made of gradients, or null when any
666
- * layer is an image or any stop has no color the editor can name.
667
- * @param {string} v
668
- * @returns {string[] | null}
669
- */
670
- function gradientStops(v) {
671
- /** The parts between commas outside parentheses. @param {string} x */
672
- const top = x =>
673
- splitTop(x, ',')
674
- .map(part => part.trim())
675
- .filter(Boolean);
676
- /** @type {string[]} */
677
- const stops = [];
678
- for (const layer of top(v)) {
679
- const m =
680
- /^(?:repeating-)?(?:linear|radial|conic)-gradient\((.*)\)$/s.exec(
681
- layer,
682
- );
683
- if (!m) {
684
- // A layer that is one color (the shorthand's last) is a stop too.
685
- if (/url\(|gradient\(/.test(layer)) return null;
686
- stops.push(layer);
687
- continue;
688
- }
689
- for (const arg of top(m[1])) {
690
- // The direction, shape or position comes first, with no color.
691
- if (
692
- /^(to\b|at\b|from\b|-?[\d.]+(deg|turn|rad|grad)\b|circle\b|ellipse\b|closest|farthest)/.test(
693
- arg,
694
- )
695
- )
696
- continue;
697
- // A stop is its color and up to two positions after it.
698
- const color = arg.replace(/(\s+-?[\d.]+(%|px|rem|em)?)+$/, '').trim();
699
- if (!color || /^-?[\d.]+(%|px|rem|em)?$/.test(color)) continue;
700
- stops.push(color);
701
- }
702
- }
703
- return stops.length ? stops : null;
704
- }
705
-
706
- /**
707
- * Text that this theme made unreadable: every real text-on-background pair,
708
- * in each mode, below 4.5:1 now but not as low in the base theme. Also
709
- * the values this theme set that have no fixed color to check (a
710
- * `color-mix()`, a `var()`), so the result can say what it skipped.
711
- * @param {(pair: TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} value
712
- * @param {(pair: TextPair, side: 'fg' | 'bg', mode: string) => string | null | undefined} baseValue
713
- * @param {string[]} modes
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
715
- * `page` is the page color in a mode: a see-through background is drawn
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.
719
- * @param {TextPair[]} [extra] more pairs to measure (a part's variants)
720
- */
721
- function contrast(
722
- value,
723
- baseValue,
724
- modes,
725
- {
726
- parseColor,
727
- ratio,
728
- alphaOf,
729
- compositeOver,
730
- page,
731
- drawnByRule = () => false,
732
- },
733
- extra = [],
734
- ) {
735
- /**
736
- * The opaque colors the eye sees for a pair, or null with no fixed color:
737
- * a see-through background is drawn over what is beneath it (the region
738
- * the part sits in, else the page).
739
- * @param {unknown} fg @param {unknown} bg @param {string} m
740
- * @param {unknown} [beneath]
741
- * @param {boolean} [onPage] whether a see-through region sits on the page
742
- */
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);
752
- /** @type {[number, number, number]} */
753
- const ground = !region
754
- ? pageColor
755
- : onPage
756
- ? compositeOver(region, alphaOf(beneath), pageColor)
757
- : region;
758
- const bgAlpha = alphaOf(bg);
759
- const back = parseColor(bg);
760
- const under =
761
- bgAlpha === 0 ? ground : back && compositeOver(back, bgAlpha, ground);
762
- const top = parseColor(fg);
763
- if (!under || !top) return null;
764
- return [compositeOver(top, alphaOf(fg), under), under];
765
- };
766
- /**
767
- * The color a one-layer linear or radial gradient has where centered
768
- * text sits: the middle of a linear one, the center of a radial one,
769
- * between the stops around that place; null for any other (several
770
- * layers, a conic or repeating one, a stop with no fixed color).
771
- * @param {string} v
772
- * @returns {string | null}
773
- */
774
- const colorBehindText = v => {
775
- const m = /^(linear|radial)-gradient\((.*)\)$/s.exec(v.trim());
776
- if (!m || splitTop(v.trim(), ',').length !== 1) return null;
777
- const args = splitTop(m[2], ',').map(x => x.trim());
778
- if (
779
- args[0] &&
780
- /^(to\b|at\b|-?[\d.]+(deg|turn|rad|grad)\b|circle\b|ellipse\b|closest|farthest)/.test(
781
- args[0],
782
- )
783
- )
784
- args.shift();
785
- /** @type {Array<{c: [number, number, number], a: number, at: number | null}>} */
786
- const stops = [];
787
- for (const arg of args) {
788
- const pos = /\s(-?[\d.]+)%$/.exec(arg);
789
- const color = arg.replace(/(\s+-?[\d.]+(%|px|rem|em)?)+$/, '').trim();
790
- const c = parseColor(color);
791
- if (!c) return null;
792
- stops.push({
793
- c,
794
- a: alphaOf(color),
795
- at: pos ? Number(pos[1]) / 100 : null,
796
- });
797
- }
798
- if (stops.length < 2) return null;
799
- // Positions a stop leaves out are spread evenly, as CSS spreads them.
800
- stops.forEach((x, i) => {
801
- if (x.at == null) x.at = i / (stops.length - 1);
802
- });
803
- const at = m[1] === 'linear' ? 0.5 : 0;
804
- const i = stops.findIndex(x => /** @type {number} */ (x.at) >= at);
805
- if (i <= 0) {
806
- const x = stops[Math.max(0, i)];
807
- return `rgba(${x.c.join(', ')}, ${x.a})`;
808
- }
809
- const [lo, hi] = [stops[i - 1], stops[i]];
810
- const span =
811
- /** @type {number} */ (hi.at) - /** @type {number} */ (lo.at);
812
- const f = span > 0 ? (at - /** @type {number} */ (lo.at)) / span : 0;
813
- const mix = lo.c.map((v0, k) => Math.round(v0 + (hi.c[k] - v0) * f));
814
- return `rgba(${mix.join(', ')}, ${lo.a + (hi.a - lo.a) * f})`;
815
- };
816
- /** @type {Array<{part: string, mode: string, ratio: number, sample: string, fg: string, fgToken: string | null, textPart: string | null, when: string | null, bgPart: string | null, bg: string, ground: [number, number, number], over: string | null, pair: any}>} */
817
- const out = [];
818
- const seen = new Set();
819
- /** @type {Set<string>} */
820
- const unchecked = new Set();
821
- // A census pair the caller measures again per variant (`replaces`) is
822
- // measured only as those.
823
- const replaced = new Set(
824
- extra.map((/** @type {any} */ x) => x.replaces).filter(Boolean),
825
- );
826
- for (const p of [...parts.pairs, ...extra]) {
827
- if (replaced.has(p)) continue;
828
- // Text drawn in a disabled color marks an inactive control, which
829
- // needs no 4.5:1 (and must stay dimmer than the live text beside it).
830
- if (/^--color-(text|icon)-disabled$/.test(String(p.fg.tokens[0])))
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.)
834
- if (
835
- p.fg.target !== p.bg.target &&
836
- p.bg.target &&
837
- !(/** @type {any} */ (p).ownColor) &&
838
- partReads(p.bg.target, 'text').length
839
- )
840
- continue;
841
- for (const m of modes) {
842
- const fg = value(p, 'fg', m);
843
- const whole = value(p, 'bg', m);
844
- // The region a part sits in shows through its see-through background.
845
- const region = p.over ? {...p, bg: p.over} : null;
846
- const beneath = region ? value(region, 'bg', m) : page(m);
847
- const baseBeneath = region ? baseValue(region, 'bg', m) : page(m);
848
- // Over a region, only a see-through background shows it: an opaque
849
- // one is measured as the pair itself already is.
850
- if (
851
- region &&
852
- !(/** @type {any} */ (p).mediaOf) &&
853
- alphaOf(whole) >= 1 &&
854
- !/gradient|url\(/.test(String(whole))
855
- )
856
- continue;
857
- // A gradient is measured where the text sits on it: a linear or
858
- // radial one at the color it has under the text (its middle, or its
859
- // center), so a glossy highlight at an edge is not taken for the
860
- // ground; any other at each of its color stops, the worst one
861
- // counting. An image, or a stop with no fixed color, is not checked.
862
- const behind = /gradient/.test(String(whole))
863
- ? colorBehindText(String(whole))
864
- : null;
865
- const stops = behind
866
- ? [behind]
867
- : /gradient|url\(/.test(String(whole))
868
- ? gradientStops(String(whole))
869
- : [whole];
870
- if (!stops) {
871
- if (whole !== baseValue(p, 'bg', m)) unchecked.add(String(whole));
872
- continue;
873
- }
874
- const measured = stops.map(stop => ({
875
- stop,
876
- pair: drawn(fg, stop, m, beneath, !(/** @type {any} */ (p).mediaOf)),
877
- }));
878
- if (stops.length > 1 && measured.some(x => !x.pair)) {
879
- if (whole !== baseValue(p, 'bg', m)) unchecked.add(String(whole));
880
- continue;
881
- }
882
- const worst = measured.reduce((a, b) =>
883
- a.pair &&
884
- b.pair &&
885
- ratio(b.pair[0], b.pair[1]) < ratio(a.pair[0], a.pair[1])
886
- ? b
887
- : a,
888
- );
889
- const bg = worst.stop;
890
- const pair = worst.pair;
891
- if (!pair) {
892
- for (const [v, side] of /** @type {const} */ ([
893
- [fg, 'fg'],
894
- [bg, 'bg'],
895
- ]))
896
- if (
897
- v &&
898
- !parseColor(v) &&
899
- alphaOf(v) !== 0 &&
900
- v !== baseValue(p, side, m)
901
- )
902
- unchecked.add(String(v));
903
- continue;
904
- }
905
- const r = ratio(pair[0], pair[1]);
906
- if (r >= 4.5) continue;
907
- const was = drawn(
908
- baseValue(p, 'fg', m),
909
- baseValue(p, 'bg', m),
910
- m,
911
- baseBeneath,
912
- );
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);
922
- // Pairs alike in color are one problem only when they read the same
923
- // token on the same part: text on another token or on another part
924
- // is another fix, and shows as they part ways.
925
- const key = `${p.text}|${p.fg.tokens[0] ?? ''}|${p.bg.target ?? ''}|${fg}|${bg}|${beneath}|${m}`;
926
- if (seen.has(key)) continue;
927
- seen.add(key);
928
- out.push({
929
- part: p.text,
930
- mode: m,
931
- // (Cut down, never rounded up: just under a need never meets it.)
932
- ratio: ratioDown(r),
933
- sample: p.sample,
934
- // A side the theme changed is named by the value it set, not the
935
- // token the part reads without it.
936
- // (So is one the base theme's own rule draws, not its token.)
937
- fg:
938
- fg !== baseValue(p, 'fg', m) || drawnByRule(p, 'fg', m)
939
- ? String(fg)
940
- : (p.fg.tokens[0] ?? String(fg)),
941
- bgPart: p.bg.target,
942
- // What shows through a see-through background, when it is the
943
- // region the part sits in.
944
- over:
945
- region && alphaOf(bg) < 1
946
- ? `${p.over?.target}'s ${beneath !== baseBeneath ? String(beneath) : (p.over?.tokens[0] ?? String(beneath))}`
947
- : null,
948
- bg: behind
949
- ? `${bg}, its gradient where the text sits`
950
- : stops.length > 1
951
- ? `${bg}, a stop of its gradient`
952
- : bg !== baseValue(p, 'bg', m) || drawnByRule(p, 'bg', m)
953
- ? String(bg)
954
- : (p.bg.tokens[0] ?? String(bg)),
955
- // What a fix needs: the token the text reads, the part that draws
956
- // it, the variant it was measured in, and the opaque color the
957
- // text sits on.
958
- fgToken: p.fg.tokens[0] ?? null,
959
- textPart: p.fg.target ?? null,
960
- when: /** @type {any} */ (p).when ?? null,
961
- ground: pair[1],
962
- pair: p,
963
- ...(base ? {base: true} : {}),
964
- });
965
- }
966
- }
967
- return {
968
- problems: out,
969
- unchecked: [...unchecked],
970
- };
971
- }
972
-
973
- /**
974
- * Whether a part shows its corners: it sets a radius, a background, a
975
- * border or a shadow. A radius on anything else changes nothing you see.
976
- * @param {string} target
977
- */
978
- function showsCorners(target) {
979
- const own = MAP[target]?.own;
980
- if (!own) return true;
981
- for (const [p, v] of Object.entries(own)) {
982
- if (GROUPS.corners.includes(p) || p === 'box-shadow') return true;
983
- if (
984
- /^border(-(top|right|bottom|left|block|inline))?(-width)?$/.test(p) &&
985
- v.values.some(x => !/^(0|0px|none)$/.test(x))
986
- )
987
- return true;
988
- if (
989
- p === 'background-color' ||
990
- p === 'background' ||
991
- p === 'background-image'
992
- ) {
993
- // A background the same as the page behind it shows no edge.
994
- const always = Object.entries(v.tokens).some(
995
- ([tok, conds]) =>
996
- tok !== '--color-background-body' && conds.includes('always'),
997
- );
998
- const raw = v.values.some(
999
- x => !/var\(|transparent|inherit|none/.test(x),
1000
- );
1001
- if (always || raw) return true;
1002
- }
1003
- }
1004
- return false;
1005
- }
1006
-
1007
- /** @type {Map<string, string[]>} */
1008
- const propsCache = new Map();
1009
- /**
1010
- * The CSS properties anything in the catalog reads a token in.
1011
- * @param {string} tok
1012
- */
1013
- const propsReading = tok => {
1014
- let r = propsCache.get(tok);
1015
- if (!r) {
1016
- /** @type {Set<string>} */
1017
- const out = new Set();
1018
- for (const t of Object.values(MAP)) {
1019
- for (const [prop, v] of Object.entries(t.own ?? {}))
1020
- if (tok in v.tokens) out.add(prop);
1021
- for (const [k, v] of Object.entries(t.inside ?? {}))
1022
- if (k === tok)
1023
- for (const p of /** @type {string[]} */ (v)) out.add(p);
1024
- }
1025
- r = [...out];
1026
- propsCache.set(tok, r);
1027
- }
1028
- return r;
1029
- };
1030
-
1031
- return {
1032
- MAP,
1033
- typeOf,
1034
- isToken,
1035
- propsReading,
1036
- feeds,
1037
- fmtFeeds,
1038
- showsCorners,
1039
- groupOfToken,
1040
- groupOfProp,
1041
- partReads,
1042
- fmtWhen,
1043
- statusNote,
1044
- allReads,
1045
- anyReader,
1046
- checkTokenOn,
1047
- checkTokenGlobal,
1048
- variantValues,
1049
- contrast,
1050
- };
1051
- }
1052
-
1053
- /** @typedef {ReturnType<typeof makeCompiler>} Compiler */