@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,1128 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file What a theme's own changes should have reached and did not: each
5
- * part, with why and the steps that reach it. `show` lists them under
6
- * missed, each step followed as set follows it; `how "<part> match the
7
- * theme"` answers with the same steps for that part.
8
- *
9
- * @position api/theme-edit — imported by _edit.mjs and _how.mjs
10
- */
11
-
12
- import {COMMON_STATES, P} from './_tables.mjs';
13
- import {
14
- autoMediaSide,
15
- baseComponent,
16
- kebab,
17
- modesOf,
18
- partsOf,
19
- roleReach,
20
- cornersPlain,
21
- pillShapes,
22
- controlHeightSplits,
23
- } from './_settings.mjs';
24
- import {borderlessSurfaces} from './_check.mjs';
25
- import {hex, parseColor, ratio, splitTop} from './_color.mjs';
26
- import {hexToOklch} from '../theme/palette/generate/color.mjs';
27
- import {blurScaled} from './_how-steps.mjs';
28
-
29
- /**
30
- * @typedef {{thing: string, value: string, on?: string, when?: string, state?: string, mode?: string, only?: boolean}} MissedStep
31
- * @typedef {{kind: number, part: string, state?: string, when?: string, why: string, steps: MissedStep[], aspect: string}} Missed
32
- */
33
-
34
- /**
35
- * The parts the theme's own changes should have reached and did not, one
36
- * of each kind first (an inverted surface, a disabled part, a selected
37
- * state, a status fill, pills, borderless surfaces), then the next of
38
- * each, with the steps that reach each (not yet checked). None for a theme
39
- * with no settings.
40
- * @param {any} ctx
41
- * @param {import('./_settings.mjs').ThemeData} data
42
- * @param {Record<string, Record<string, string>>} res
43
- * @param {Record<string, any>} base
44
- * @returns {Missed[]}
45
- */
46
- export function missedSteps(ctx, data, res, base) {
47
- if (!data.settings.length) return [];
48
- const C = ctx.C;
49
- // The modes the theme draws (a dark-only theme's dark), each one res
50
- // holds.
51
- const modes = modesOf(data).filter(m => res[m]);
52
- /**
53
- * What the accent tint a selected look takes draws in dark, said with
54
- * the line: a dark tint can be a strong block of the accent (a soft
55
- * coral's is a deep red). A strong one (OKLCH chroma 0.1 or more) the
56
- * theme does not set itself comes with the line for a softer one: the
57
- * tint halfway to the dark page.
58
- */
59
- const darkTintWords = () => {
60
- if (!modes.includes('dark')) return '';
61
- const tint = parseColor(String(res.dark?.['--color-accent-muted'] ?? ''));
62
- const page = parseColor(
63
- String(res.dark?.['--color-background-body'] ?? ''),
64
- );
65
- if (!tint || !page) return '';
66
- const set = data.settings.some(
67
- x =>
68
- x.source === 'token' &&
69
- x.thing === '--color-accent-muted' &&
70
- !x.on &&
71
- !x.state &&
72
- !x.when,
73
- );
74
- const strong = !set && hexToOklch(hex(tint)).C >= 0.1;
75
- const soft = hex(
76
- /** @type {[number, number, number]} */ (
77
- tint.map((v, i) => Math.round((v + page[i]) / 2))
78
- ),
79
- );
80
- return `; in dark the accent tint draws ${hex(tint)}${
81
- strong
82
- ? `, a strong block of the accent; for a softer one first: ${P} set ${data.name} --color-accent-muted '${soft}' --mode dark`
83
- : ''
84
- }`;
85
- };
86
- /** @param {string} token */
87
- const changed = token =>
88
- modes.some(m => String(res[m]?.[token]) !== String(base[m]?.[token]));
89
- const tokens = Object.keys(res[modes[0]] ?? {});
90
- const any = (/** @type {RegExp} */ re) =>
91
- tokens.some(t => re.test(t) && changed(t));
92
- const accent = any(/^--color-(accent|on-accent|text-accent)/);
93
- const surfaces = any(/^--color-background-(body|surface)$/);
94
- const corners = any(/^--radius-(?!full$)/);
95
- // (A border width the theme took to zero draws no border: a part with
96
- // none already shows what it asked for.)
97
- const borders =
98
- any(/^--border-width/) &&
99
- modes.some(
100
- m =>
101
- !/^0(?:px|rem|em)?$/.test(
102
- String(res[m]?.['--border-width'] ?? '').trim(),
103
- ),
104
- );
105
- const has = (/** @type {string} */ p) => ctx.project.target.has(p);
106
- /**
107
- * A setting on the part that covers an aspect: one of the properties or
108
- * tokens named, in the state named (at rest with none).
109
- * @param {string} p @param {RegExp} things @param {string} [state]
110
- */
111
- const covers = (p, things, state) =>
112
- data.settings.some(
113
- x =>
114
- x.on &&
115
- (x.state ?? '') === (state ?? '') &&
116
- partsOf(ctx, x).includes(p) &&
117
- things.test(x.thing),
118
- );
119
- const FILL = /^(background(-color|-image)?|--color-background-[\w-]+)$/;
120
- /** @typedef {{thing: string, value: string, on?: string, when?: string, state?: string, mode?: string}} Step */
121
- /** @type {Array<{kind: number, part: string, state?: string, why: string, steps: Step[], aspect: string}>} */
122
- const found = [];
123
- /** The fills of a part (never the shared hover and pressed tints). @param {string} p @param {(prop: string) => boolean} prop */
124
- const fills = (p, prop = x => /^background/.test(x)) =>
125
- (C.partReads(p, null) ?? []).filter(
126
- (/** @type {any} */ r) =>
127
- /^--color-/.test(r.token) &&
128
- !/^--color-overlay-/.test(r.token) &&
129
- r.props.some(prop),
130
- );
131
- /** The tokens a part's text reads at rest. @param {string} q */
132
- const textTokensOf = q => [
133
- ...new Set(
134
- fills(q, x => x === 'color')
135
- .filter((/** @type {any} */ r) =>
136
- r.when.some((/** @type {string} */ w) => !/:|selected/.test(w)),
137
- )
138
- .map((/** @type {any} */ r) => /** @type {string} */ (r.token)),
139
- ),
140
- ];
141
- // The status colors, by the word their tokens carry, and the dial that
142
- // generates each with the text that reads on it.
143
- // Whether the theme's vibrancy differs from the base's: only then does a
144
- // status dial build a color of its own.
145
- const vibrancyMoved = data.settings.some(
146
- x => x.source === 'dial' && x.thing === 'vibrancy',
147
- );
148
- const STATUS = /** @type {Record<string, [string, string]>} */ ({
149
- info: ['info', '--color-info'],
150
- success: ['success', '--color-success'],
151
- warning: ['warning', '--color-warning'],
152
- error: ['danger', '--color-error'],
153
- });
154
- for (const p of Object.keys(C.MAP).filter(has)) {
155
- const reads = fills(p);
156
- const rest = reads.filter((/** @type {any} */ r) => r.when.includes(''));
157
- const restKept =
158
- rest.length && !rest.some((/** @type {any} */ r) => changed(r.token));
159
- // A part on the base's inverted surface (a toast's, or a tooltip drawn
160
- // in the theme's text color) that no longer stands out from the
161
- // theme's page (under 3:1 against it in a mode): one that still stands
162
- // out is drawn so on purpose. Its line, in each mode it disappears in,
163
- // turns the surface to the theme's own light surface where the page is
164
- // dark (or the other way), with the text on it the theme's text color.
165
- const INVERTED = ['--color-background-inverted', '--color-text-primary'];
166
- const inverted = rest.find((/** @type {any} */ r) =>
167
- INVERTED.includes(r.token),
168
- )?.token;
169
- /** Whether a color stands out from the page in a mode. @param {unknown} v @param {string} m */
170
- const standsOut = (v, m) => {
171
- const a = parseColor(String(v));
172
- const b = parseColor(String(res[m]?.['--color-background-body']));
173
- return !a || !b || ratio(a, b) >= 3;
174
- };
175
- const lost = inverted
176
- ? modes.filter(m => !standsOut(res[m]?.[inverted], m))
177
- : [];
178
- // (Only a surface that holds text: a placeholder block is no surface
179
- // a reader looks for.)
180
- const textTokens = textTokensOf(p);
181
- const holdsText = Boolean(C.MAP[p]?.media) || textTokens.length > 0;
182
- /**
183
- * The text on the theme's surface in a mode: the theme's text color
184
- * where it reads there (4.5:1), else the plain black or white that
185
- * does (a theme whose surface stays light in dark mode).
186
- * @param {string} m @param {string} [ground] the token the text sits on
187
- */
188
- const readableOn = (m, ground) => {
189
- const text = String(res[m]?.['--color-text-primary']);
190
- const t = parseColor(text);
191
- const g = parseColor(String(ground));
192
- if (!t || !g || ratio(t, g) >= 4.5) return text;
193
- return ratio([0, 0, 0], g) >= ratio([255, 255, 255], g)
194
- ? '#000000'
195
- : '#ffffff';
196
- };
197
- /**
198
- * The line that gives the part the theme's own surface in the modes
199
- * named, with its text readable on it.
200
- * @param {string[]} ms
201
- */
202
- // Another variant with a fill of its own (an error toast's red) keeps
203
- // text readable on that fill: its own text step, scoped to it, after
204
- // the text step for the part.
205
- const otherFills = reads.flatMap((/** @type {any} */ r) =>
206
- r.token === inverted
207
- ? []
208
- : r.when
209
- .map((/** @type {string} */ w) =>
210
- /^([\w-]+)=([\w-]+)$/.exec(w)?.slice(1).join(':'),
211
- )
212
- .filter(Boolean)
213
- .map((/** @type {string} */ when) => ({when, token: r.token})),
214
- );
215
- /**
216
- * Whether a media part's text, which picks its own side from its fill
217
- * (Core's automatic media mode), already reads on a fill in a mode: its
218
- * text then needs no step of its own, and the fill is the one line.
219
- * @param {string} m @param {unknown} fillValue @param {boolean} [error]
220
- */
221
- const textFollows = (m, fillValue, error = false) => {
222
- if (!C.MAP[p]?.media) return false;
223
- const tokens = res[m] ?? {};
224
- const side = autoMediaSide(String(fillValue ?? ''), tokens, {
225
- mode: m,
226
- ...(error ? {error: true} : {}),
227
- });
228
- const text = parseColor(
229
- String(
230
- tokens[
231
- side === 'off'
232
- ? '--color-text-primary'
233
- : side === 'dark'
234
- ? '--color-on-dark'
235
- : '--color-on-light'
236
- ] ?? '',
237
- ),
238
- );
239
- const g = parseColor(String(fillValue ?? ''));
240
- return Boolean(text && g && ratio(text, g) >= 4.5);
241
- };
242
- /**
243
- * @param {string[]} ms
244
- * @param {boolean} [inverse] the theme's own inverted surface: in a
245
- * theme that draws both modes, the surface it draws in the other mode
246
- * (dark in light, light in dark), as Core's inverted surface is; in a
247
- * one-mode theme, its surface
248
- */
249
- const surfaceSteps = (ms, inverse = false) => {
250
- /** @param {string} m */
251
- const fill = m =>
252
- String(
253
- res[
254
- inverse && modes.length > 1
255
- ? /** @type {string} */ (modes.find(x => x !== m))
256
- : m
257
- ]?.['--color-background-surface'],
258
- );
259
- return inverted === '--color-background-inverted'
260
- ? // The inverted surface turns to the theme's surface on this part
261
- // alone (as the color it is: a part may read the surface token
262
- // for its text; the lightbox and the scrim keep theirs), with its
263
- // text readable on it: a toast's color (the two colors its media
264
- // surface gives its text), else each token its text reads.
265
- ms.flatMap(m => [
266
- {
267
- thing: '--color-background-inverted',
268
- value: fill(m),
269
- on: p,
270
- mode: m,
271
- },
272
- // (A media part whose text picks a side that reads on the new
273
- // fill takes no text step: the fill is the one line.)
274
- ...(textFollows(m, fill(m))
275
- ? []
276
- : (C.MAP[p]?.media || !textTokens.length
277
- ? ['color']
278
- : textTokens
279
- ).map(thing => ({
280
- thing,
281
- value: readableOn(m, fill(m)),
282
- on: p,
283
- mode: m,
284
- }))),
285
- ...(C.MAP[p]?.media || !textTokens.length
286
- ? otherFills
287
- .filter(
288
- (/** @type {any} */ o) =>
289
- !textFollows(m, res[m]?.[o.token], true),
290
- )
291
- .map((/** @type {any} */ o) => ({
292
- thing: 'color',
293
- value: readableOn(m, res[m]?.[o.token]),
294
- on: p,
295
- mode: m,
296
- when: o.when,
297
- }))
298
- : []),
299
- ])
300
- : // The surface and the text as the colors they are in that mode (a
301
- // tooltip's text reads the surface token itself, so a token
302
- // reference would turn the fill back): the fill, then each token
303
- // the part's text reads, or its text color when it reads none.
304
- ms.flatMap(m => [
305
- {
306
- thing: 'background-color',
307
- value: fill(m),
308
- on: p,
309
- mode: m,
310
- },
311
- ...(textTokens.length ? textTokens : ['color']).map(thing => ({
312
- thing,
313
- value: readableOn(m, fill(m)),
314
- on: p,
315
- mode: m,
316
- })),
317
- ]);
318
- };
319
- // The theme's own surfaces changed (its neutral, surface, card or page
320
- // color), while the part still paints the base's inverted surface: it
321
- // keeps the base's dark look beside the theme's (a Win98 theme's grey
322
- // tooltips). Its line gives it the theme's own inverted surface: the
323
- // surface the theme draws in the other mode (a cream theme's warm dark
324
- // in light), or its surface in a one-mode theme.
325
- const ownSurfaces = any(
326
- /^--color-(neutral|background-(body|surface|card))$/,
327
- );
328
- // (Its inverted surface is the base's, or one a dial made from the
329
- // neutral seed: no setting of the theme's chose it.)
330
- const chosen = data.settings.some(
331
- x => x.source === 'token' && x.thing === inverted && !x.on,
332
- );
333
- if (
334
- inverted &&
335
- holdsText &&
336
- !covers(p, FILL) &&
337
- (lost.length
338
- ? surfaces && restKept
339
- : ownSurfaces &&
340
- !chosen &&
341
- rest.every(
342
- (/** @type {any} */ r) => r.token === inverted || !changed(r.token),
343
- ))
344
- ) {
345
- const swap = lost.filter(m =>
346
- standsOut(res[m]?.['--color-background-surface'], m),
347
- );
348
- // (With the surfaces changed, only the modes where the theme's own
349
- // inverted surface looks different from the base's: the same side,
350
- // dark or light, at nearly the same lightness (under 1.5:1 apart) is
351
- // the same look, and a line there changes nothing you see.)
352
- const looksNew = modes.filter(m => {
353
- const now = parseColor(String(res[m]?.[inverted] ?? ''));
354
- const other = modes.length > 1 ? modes.find(x => x !== m) : m;
355
- const next = parseColor(
356
- String(
357
- res[/** @type {string} */ (other)]?.[
358
- '--color-background-surface'
359
- ] ?? '',
360
- ),
361
- );
362
- if (!now || !next) return true;
363
- const side = (/** @type {[number, number, number]} */ c) =>
364
- ratio([255, 255, 255], c) >= ratio([0, 0, 0], c);
365
- return side(now) !== side(next) || ratio(now, next) >= 1.5;
366
- });
367
- if (lost.length || looksNew.length)
368
- found.push({
369
- kind: 0,
370
- part: p,
371
- why: lost.length
372
- ? `still the base's inverted surface (${inverted}), which no longer stands out from the page in ${lost.join(' and ')}`
373
- : `still the base's dark inverted surface (${inverted}); the theme's surfaces changed`,
374
- aspect: 'background',
375
- steps: lost.length
376
- ? swap.length !== lost.length
377
- ? []
378
- : surfaceSteps(lost)
379
- : surfaceSteps(looksNew, true),
380
- });
381
- }
382
- // A fill made from a status token the theme's own status color does
383
- // not reach (an error toast's inverted red, after the danger color is
384
- // set): still the base's red beside the theme's. Its line gives it the
385
- // theme's status color in each mode, in the condition it is drawn in.
386
- for (const st of Object.keys(STATUS)) {
387
- if (
388
- !data.settings.some(
389
- x => x.source === 'dial' && x.thing === STATUS[st][0] && !x.on,
390
- )
391
- )
392
- continue;
393
- const own = new RegExp(`^--color-background-${st}-[\\w-]+$`);
394
- for (const r of reads.filter(
395
- (/** @type {any} */ r) => own.test(r.token) && !changed(r.token),
396
- )) {
397
- const cond = r.when
398
- .map((/** @type {string} */ w) => /^([\w-]+)=([\w-]+)$/.exec(w))
399
- .find(Boolean);
400
- const when = cond ? `${cond[1]}:${cond[2]}` : undefined;
401
- if (!r.when.includes('') && !when) continue;
402
- if (covers(p, FILL)) continue;
403
- const ms = modes.filter(
404
- m => String(res[m]?.[STATUS[st][1]]) !== String(res[m]?.[r.token]),
405
- );
406
- if (!ms.length) continue;
407
- found.push({
408
- kind: 3,
409
- part: p,
410
- ...(when ? {when} : {}),
411
- why: `${when ? `${when.replace(':', ' ')}, ` : ''}its fill is still the base's ${st} color (${r.token}), which the theme's ${STATUS[st][0]} color does not reach`,
412
- aspect: 'background',
413
- // (A media part's text picks its side from the new fill: where
414
- // that side does not read on it, the text that does, in the same
415
- // condition, so the line makes no problem of its own.)
416
- steps: ms.flatMap(m => {
417
- const value = String(res[m]?.[STATUS[st][1]]);
418
- return [
419
- {thing: r.token, value, on: p, ...(when ? {when} : {}), mode: m},
420
- ...(C.MAP[p]?.media && !textFollows(m, value, st === 'error')
421
- ? [
422
- {
423
- thing: 'color',
424
- value: readableOn(m, value),
425
- on: p,
426
- ...(when ? {when} : {}),
427
- mode: m,
428
- },
429
- ]
430
- : []),
431
- ];
432
- }),
433
- });
434
- }
435
- }
436
- /** A base literal in a mode: its half of light-dark(). @param {string} v @param {string} m */
437
- const literal = (v, m) => {
438
- const pair = /^light-dark\((.*)\)$/is.exec(String(v).trim());
439
- const halves = pair ? splitTop(pair[1], ',') : null;
440
- const x = (
441
- halves?.length === 2 ? halves[m === 'light' ? 0 : 1] : String(v)
442
- ).trim();
443
- return /^var\(/.test(x) ? null : parseColor(x);
444
- };
445
- // A role color (the accent, a status color) the base theme takes away
446
- // from the part on its own, so the theme's role color never reaches it:
447
- // the base points the role token at another one there (stone's and
448
- // gothic's info banner reads the categorical blue), or a variant named
449
- // for the role draws a color of the base's palette written out (stone's
450
- // accent progress fill in its blue). Listed once the theme moved
451
- // that role, in each mode where it looks different, with a line that
452
- // gives the part the theme's role color there.
453
- for (const [key, look] of Object.entries(
454
- /** @type {Record<string, Record<string, unknown>>} */ (
455
- base.components?.[p] ?? {}
456
- ),
457
- )) {
458
- if (key !== 'base' && !/^[\w-]+:[\w-]+$/.test(key)) continue;
459
- if (!look || typeof look !== 'object') continue;
460
- const when = key === 'base' ? undefined : key;
461
- /** @param {string} thing */
462
- const covered = thing =>
463
- data.settings.some(
464
- x =>
465
- x.on &&
466
- !x.state &&
467
- (x.when ?? undefined) === when &&
468
- partsOf(ctx, x).includes(p) &&
469
- x.thing === thing,
470
- );
471
- // The role tokens pointed at other tokens on the part, in one line
472
- // (a banner's fill and its text).
473
- /** @type {Step[]} */
474
- const pointed = [];
475
- /** @type {string[]} */
476
- const names = [];
477
- for (const [prop, v] of Object.entries(look)) {
478
- if (typeof v !== 'string') continue;
479
- const role =
480
- /^--color-(on-)?(accent|info|success|warning|error)(-[\w-]+)?$/.exec(
481
- prop,
482
- );
483
- const to = /^var\(\s*(--[\w-]+)\s*\)$/.exec(v.trim())?.[1];
484
- if (!role || !to || to === prop || !changed(prop) || covered(prop))
485
- continue;
486
- const ms = modes.filter(
487
- m => String(res[m]?.[to]) !== String(res[m]?.[prop]),
488
- );
489
- if (!ms.length) continue;
490
- names.push(`${prop} at ${to}`);
491
- pointed.push(
492
- ...ms.map(m => ({
493
- thing: prop,
494
- value: String(res[m]?.[prop]),
495
- on: p,
496
- ...(when ? {when} : {}),
497
- mode: m,
498
- })),
499
- );
500
- }
501
- if (pointed.length)
502
- found.push({
503
- kind: 8,
504
- part: p,
505
- ...(when ? {when} : {}),
506
- why: `${when ? `${when.replace(':', ' ')}, ` : ''}the base theme points ${names.join(' and ')} there, so the theme's own color does not reach it`,
507
- aspect: 'background',
508
- steps: pointed,
509
- });
510
- // A variant named for a role, drawn in a color written out.
511
- const named = /^variant:(accent|info|success|warning|error)$/.exec(
512
- String(when ?? ''),
513
- )?.[1];
514
- if (!named) continue;
515
- const moved = named === 'accent' ? accent : changed(`--color-${named}`);
516
- if (!moved) continue;
517
- for (const [prop, thing, side] of /** @type {const} */ ([
518
- ['backgroundColor', 'background-color', 'background'],
519
- ['color', 'color', 'text'],
520
- ])) {
521
- const v = look[prop];
522
- if (typeof v !== 'string' || /var\(/.test(v) || covered(thing))
523
- continue;
524
- if (!modes.every(m => literal(v, m) != null)) continue;
525
- // Core's own color for that variant, else the role's own token.
526
- const core = (ctx.C.partReads(p, side) ?? []).find(
527
- (/** @type {any} */ r) => r.when.includes(`variant=${named}`),
528
- )?.token;
529
- const token =
530
- core ??
531
- (side === 'text' ? `--color-text-${named}` : `--color-${named}`);
532
- if (
533
- found.some(
534
- x =>
535
- x.part === p &&
536
- x.steps.some(st => st.thing === thing && st.when === when),
537
- )
538
- )
539
- continue;
540
- found.push({
541
- kind: 8,
542
- part: p,
543
- ...(when ? {when} : {}),
544
- why: `${String(when).replace(':', ' ')}, its ${side === 'text' ? 'text' : 'fill'} is a color of the base theme's palette written out (${v}), which the theme's ${named} color does not reach`,
545
- aspect: side === 'text' ? 'text' : 'background',
546
- steps: [{thing, value: `var(${token})`, on: p, when}],
547
- });
548
- }
549
- }
550
- if (!accent) continue;
551
- // A color the base theme gives the part as its own accent, written as
552
- // the color itself rather than the accent token (butter's nav links
553
- // and outline buttons in its blue): the accent dial never reaches it.
554
- // Listed for each variant (or at rest) whose color, in every mode the
555
- // theme draws, is the base's accent there, with a line that points it
556
- // at the accent token, where that changes the color built.
557
- const baseParts = /** @type {Record<string, Record<string, any>>} */ (
558
- base.components?.[p] ?? {}
559
- );
560
- const ACCENTS = [
561
- '--color-accent',
562
- '--color-text-accent',
563
- '--color-icon-accent',
564
- ];
565
- for (const [key, look] of Object.entries(baseParts)) {
566
- if (key !== 'base' && !/^[\w-]+:[\w-]+$/.test(key)) continue;
567
- if (!look || typeof look !== 'object') continue;
568
- for (const [prop, thing, token] of /** @type {const} */ ([
569
- ['color', 'color', '--color-text-accent'],
570
- ['backgroundColor', 'background-color', '--color-accent'],
571
- ['borderColor', 'border-color', '--color-accent'],
572
- ])) {
573
- const v = look[prop];
574
- if (typeof v !== 'string') continue;
575
- const when = key === 'base' ? undefined : key;
576
- const isBaseAccent = modes.every(m => {
577
- const c = literal(v, m);
578
- return (
579
- c != null &&
580
- ACCENTS.some(a => {
581
- const b = parseColor(String(base[m]?.[a] ?? ''));
582
- return b != null && b.every((x, k) => x === c[k]);
583
- })
584
- );
585
- });
586
- const moves = modes.some(
587
- m => String(res[m]?.[token]) !== String(base[m]?.[token]),
588
- );
589
- if (
590
- !isBaseAccent ||
591
- !moves ||
592
- data.settings.some(
593
- x =>
594
- x.on &&
595
- !x.state &&
596
- (x.when ?? undefined) === when &&
597
- partsOf(ctx, x).includes(p) &&
598
- (x.thing === thing ||
599
- (thing === 'border-color' && /^border$/.test(x.thing))),
600
- )
601
- )
602
- continue;
603
- found.push({
604
- kind: 8,
605
- part: p,
606
- ...(when ? {when} : {}),
607
- why: `${when ? `${when.replace(':', ' ')}, ` : ''}its ${thing === 'color' ? 'text' : thing.replace('-color', '')} is the base theme's own accent (${String(v)}), written as a color, which the accent leaves as it is`,
608
- aspect:
609
- thing === 'color'
610
- ? 'text'
611
- : thing === 'border-color'
612
- ? 'border'
613
- : 'background',
614
- steps: [
615
- {
616
- thing,
617
- value: `var(${token})`,
618
- on: p,
619
- ...(when ? {when} : {}),
620
- },
621
- ],
622
- });
623
- }
624
- }
625
- // A status fill still the base's (a banner's, a badge's status
626
- // variants): the status color generated at the theme's vibrancy (its
627
- // dial), with the text that reads on it. Only where that changes the
628
- // color built: with the vibrancy at the base's, the dial gives the
629
- // base's own color back, and the part is drawn as the base draws it.
630
- const statusReads = reads.filter(
631
- (/** @type {any} */ r) =>
632
- /-(info|success|warning|error)(-|$)/.test(r.token) &&
633
- !changed(r.token) &&
634
- r.when.some(
635
- (/** @type {string} */ w) => w === '' || /^variant=[\w-]+$/.test(w),
636
- ),
637
- );
638
- const statuses = vibrancyMoved
639
- ? [
640
- ...new Set(
641
- statusReads.map(
642
- (/** @type {any} */ r) =>
643
- /** @type {string} */ (
644
- /-(info|success|warning|error)(-|$)/.exec(r.token)?.[1]
645
- ),
646
- ),
647
- ),
648
- ].filter(
649
- st =>
650
- !data.settings.some(
651
- x => x.source === 'dial' && x.thing === STATUS[st][0],
652
- ),
653
- )
654
- : [];
655
- // (The looks the status fill is drawn in, when none is at rest.)
656
- const statusLooks = statusReads.some((/** @type {any} */ r) =>
657
- r.when.includes(''),
658
- )
659
- ? []
660
- : [
661
- ...new Set(
662
- statusReads.flatMap((/** @type {any} */ r) =>
663
- r.when
664
- .filter((/** @type {string} */ w) => /^variant=[\w-]+$/.test(w))
665
- .map((/** @type {string} */ w) => w.replace('=', ':')),
666
- ),
667
- ),
668
- ];
669
- if (statuses.length && !covers(p, FILL))
670
- found.push({
671
- kind: 3,
672
- part: p,
673
- ...(statusLooks.length ? {when: statusLooks.join(', ')} : {}),
674
- why: `still the base's ${statuses.join(', ')} color${statuses.length > 1 ? 's' : ''} (${statusReads[0].token}): not generated at the theme's vibrancy`,
675
- aspect: 'background',
676
- steps: statuses.map(st => ({
677
- thing: STATUS[st][0],
678
- value: String(base.light?.[STATUS[st][1]] ?? '#1f2937'),
679
- })),
680
- });
681
- // A disabled part drawn as the accent at reduced opacity: with the
682
- // accent changed, a translucent block of the new accent. Only the
683
- // variants drawn as the accent, with the text on them.
684
- const name = ctx.project.target.get(p)?.component;
685
- const disables = Boolean(
686
- name && ctx.project.components[name]?.props?.isDisabled,
687
- );
688
- const dims = (C.MAP[p]?.own?.opacity?.values ?? []).some(
689
- (/** @type {unknown} */ v) => Number(v) > 0 && Number(v) < 1,
690
- );
691
- const accentVariants = [
692
- ...new Set(
693
- reads
694
- .filter((/** @type {any} */ r) => r.token === '--color-accent')
695
- .flatMap((/** @type {any} */ r) => r.when)
696
- .filter((/** @type {string} */ w) => !/:/.test(w))
697
- .map(
698
- (/** @type {string} */ w) => /(?:^|\s)variant=(\S+)/.exec(w)?.[1],
699
- )
700
- .filter(Boolean),
701
- ),
702
- ];
703
- // (A part drawn as the accent in every variant, a checked indicator,
704
- // keeps it: its fill says checked or not.)
705
- if (
706
- disables &&
707
- dims &&
708
- accentVariants.length &&
709
- !covers(p, FILL, 'disabled')
710
- ) {
711
- const whens = accentVariants.map(v => `variant:${v}`);
712
- found.push({
713
- kind: 1,
714
- part: p,
715
- state: 'disabled',
716
- why: `disabled, the ${accentVariants.join(', ')} variant is drawn as the accent at reduced opacity, a translucent block of the new accent`,
717
- aspect: 'background',
718
- steps: whens.flatMap(when => [
719
- {
720
- thing: 'background-color',
721
- value: 'var(--color-neutral)',
722
- on: p,
723
- when,
724
- state: 'disabled',
725
- },
726
- {
727
- thing: 'color',
728
- value: 'var(--color-text-primary)',
729
- on: p,
730
- when,
731
- state: 'disabled',
732
- },
733
- ]),
734
- });
735
- }
736
- // A state the part draws as a look of its own (a selected item): one
737
- // whose fill, by the part data, is not the fill the part draws without
738
- // that state (the same variant and status, the state left out), still
739
- // the base's. A state that keeps that fill (a readonly field on its
740
- // surface, a checked switch's thumb) is drawn so on purpose: no line
741
- // paints it.
742
- const states = (ctx.project.target.get(p)?.states ?? []).filter(
743
- (/** @type {string} */ st) => !COMMON_STATES.includes(st),
744
- );
745
- for (const st of states) {
746
- const term = new RegExp(`(^|[\\s,])${st}=\\S+`);
747
- /** The condition without the state. @param {string} w */
748
- const without = w => w.replace(term, ' ').replace(/\s+/g, ' ').trim();
749
- // A tint the state lays over any fill (an overlay token) follows
750
- // the fill; only a fill of its own is kept from the base.
751
- const inState = reads.filter(
752
- (/** @type {any} */ r) =>
753
- !/^--color-overlay-/.test(r.token) &&
754
- r.when.some(
755
- (/** @type {string} */ w) =>
756
- term.test(w) &&
757
- !/:/.test(w) &&
758
- // The same fill without the state: no look of its own.
759
- !r.when.includes(without(w)),
760
- ),
761
- );
762
- // The base theme's own rule for the state (butter draws its
763
- // selected nav item with no fill, on purpose) is the look there.
764
- const baseDraws = ['backgroundColor', 'background'].some(
765
- prop =>
766
- baseComponent(/** @type {any} */ (base), ctx, p, prop, {
767
- state: st,
768
- }) != null,
769
- );
770
- if (
771
- inState.length &&
772
- !baseDraws &&
773
- !inState.some((/** @type {any} */ r) => changed(r.token)) &&
774
- !covers(p, FILL, st)
775
- )
776
- found.push({
777
- kind: 2,
778
- part: p,
779
- state: st,
780
- why: `${st}, it keeps the base's fill (${inState[0].token})${darkTintWords()}`,
781
- aspect: 'background',
782
- steps: [
783
- {
784
- thing: 'background-color',
785
- value: 'var(--color-accent-muted)',
786
- on: p,
787
- state: st,
788
- },
789
- ],
790
- });
791
- }
792
- }
793
- // A pill part (a switch, an avatar) stays round under rounded corners by
794
- // design, as nearly every look wants: it is missed only when the theme's
795
- // corners go square (its element corners at 0), where a round pill keeps
796
- // the base's look beside the theme's square one. A badge is a small box:
797
- // it is missed when the element corners change, as a button's corners
798
- // follow them.
799
- const squareCorners = modes.every(
800
- m => Number.parseFloat(String(res[m]?.['--radius-element'] ?? '')) === 0,
801
- );
802
- // (The corners dial at square squares them itself.)
803
- const squaresPills = data.settings.some(
804
- x =>
805
- x.source === 'dial' &&
806
- x.thing === 'corners' &&
807
- !x.on &&
808
- /^(?:square|0px)$/.test(cornersPlain(String(x.value)) ?? ''),
809
- );
810
- // (Only a pill that is a styling choice: a circle keeps its shape.)
811
- // (The corners dial gives a badge the element corners itself below pill,
812
- // and leaves it a pill at pill; square element corners under it are the
813
- // square case above. A badge the base theme rounds itself keeps its
814
- // shape.)
815
- // (A pill badge is listed only when the element corners are less than a
816
- // pill in some mode: at pill corners it matches the buttons.)
817
- const elementCorners =
818
- changed('--radius-element') &&
819
- modes.some(m => {
820
- const v = Number.parseFloat(String(res[m]?.['--radius-element'] ?? ''));
821
- return Number.isFinite(v) && v < 1000;
822
- });
823
- const cornersBelowPill = data.settings.some(
824
- x =>
825
- x.source === 'dial' &&
826
- x.thing === 'corners' &&
827
- !x.on &&
828
- cornersPlain(String(x.value)) !== 'pill',
829
- );
830
- const baseRoundsBadge = Object.values(
831
- /** @type {any} */ (base)?.components?.badge ?? {},
832
- ).some(r => r && typeof r === 'object' && 'borderRadius' in r);
833
- if (corners)
834
- for (const p of pillShapes(C).pills.filter(
835
- x =>
836
- has(x) &&
837
- !covers(x, /^(border-radius|corners|--radius-[\w-]+)$/) &&
838
- (x === 'badge'
839
- ? // (A corners dial below pill already gives it the element
840
- // corners, square ones included.)
841
- (squareCorners && !squaresPills && !cornersBelowPill) ||
842
- (elementCorners && !cornersBelowPill && !baseRoundsBadge)
843
- : squareCorners && !squaresPills),
844
- ))
845
- found.push({
846
- kind: 4,
847
- part: p,
848
- why: 'still a full pill: it reads --radius-full, which the corners leave as they are',
849
- aspect: 'corners',
850
- steps: [
851
- {thing: 'border-radius', value: 'var(--radius-element)', on: p},
852
- ],
853
- });
854
- // The theme changed one of its corner sizes and left the other (its
855
- // element corners, not its container corners): the parts whose corners
856
- // read the one it left (a popover's, a dialog's, at the container size)
857
- // keep the base's shape beside the theme's. One line sets the size it
858
- // left to the size it changed (as the value it has), when that differs
859
- // from what they draw.
860
- const RADII = ['--radius-element', '--radius-container'];
861
- const changedRadius = RADII.find(t => changed(t));
862
- const keptRadius = RADII.find(t => !changed(t));
863
- if (
864
- changedRadius &&
865
- keptRadius &&
866
- !data.settings.some(x => x.thing === keptRadius) &&
867
- modes.some(
868
- m => String(res[m]?.[keptRadius]) !== String(res[m]?.[changedRadius]),
869
- )
870
- ) {
871
- const kept = Object.keys(C.MAP)
872
- .filter(has)
873
- .filter(
874
- p =>
875
- !covers(p, /^(border-radius|corners|--radius-[\w-]+)$/) &&
876
- (C.partReads(p, 'corners') ?? []).some(
877
- (/** @type {any} */ r) =>
878
- r.token === keptRadius &&
879
- r.when.some(
880
- (/** @type {string} */ w) =>
881
- w === '' || !/:|aria-|selected|\[/.test(w),
882
- ),
883
- ),
884
- );
885
- const lead = ['popover', 'dialog', 'hover-card'].find(p =>
886
- kept.includes(p),
887
- );
888
- if (kept.length) {
889
- const values = modes.map(m => String(res[m]?.[changedRadius]));
890
- found.push({
891
- kind: 4,
892
- part: lead ?? kept[0],
893
- why: `still the base's corners (${keptRadius}), beside the theme's ${changedRadius}: ${kept.length} parts read it (${kept.slice(0, 4).join(', ')}${kept.length > 4 ? ', …' : ''})`,
894
- aspect: 'corners',
895
- steps: values.every(v => v === values[0])
896
- ? [{thing: keptRadius, value: values[0]}]
897
- : modes.map((m, k) => ({
898
- thing: keptRadius,
899
- value: values[k],
900
- mode: m,
901
- })),
902
- });
903
- }
904
- }
905
- // A square or outlined look (square corners, or a border width the
906
- // theme set) beside a soft shadow the base draws (a popover's, a menu's,
907
- // a dialog's): the shadow with no blur matches it. Square corners count
908
- // when the theme's own change made them so: a base square by design
909
- // (y2k) draws its shadows beside them as it means to.
910
- const square =
911
- corners &&
912
- modes.every(m =>
913
- /^0(px|rem)?$/.test(String(res[m]?.['--radius-element']).trim()),
914
- );
915
- // The same look beside the base's focus ring, drawn outside the part with
916
- // a gap: a ring drawn inside the part's edge matches it.
917
- const offsets = modes.map(m =>
918
- String(res[m]?.['--focus-outline-offset'] ?? ''),
919
- );
920
- if (
921
- (square || borders) &&
922
- !changed('--focus-outline-offset') &&
923
- !data.settings.some(x => x.thing === '--focus-outline-offset') &&
924
- offsets.every(
925
- o => /^\d*\.?\d+(px|rem)?$/.test(o.trim()) && parseFloat(o) > 0,
926
- )
927
- )
928
- found.push({
929
- kind: 7,
930
- part: 'focus-ring',
931
- why: `the focus ring is still drawn ${offsets[0]} outside each part, beside the theme's ${square ? 'square corners' : 'border'}`,
932
- aspect: 'ring',
933
- steps: [{thing: '--focus-outline-offset', value: '-2px'}],
934
- });
935
- if (square || borders)
936
- for (const p of Object.keys(C.MAP).filter(has)) {
937
- if (covers(p, /^(box-shadow|--shadow-[\w-]+)$/)) continue;
938
- const read = (C.partReads(p, 'shadow') ?? []).find(
939
- (/** @type {any} */ r) =>
940
- /^--shadow-/.test(r.token) &&
941
- r.when.includes('') &&
942
- !changed(r.token),
943
- );
944
- if (!read) continue;
945
- const hard = modes.map(m => ({
946
- m,
947
- v: blurScaled(String(res[m]?.[read.token] ?? ''), 0),
948
- was: String(res[m]?.[read.token] ?? ''),
949
- }));
950
- // Only a shadow with a blur (a line that would change nothing is
951
- // never offered).
952
- if (hard.some(h => !h.v || h.v === h.was)) continue;
953
- const same = hard.every(h => h.v === hard[0].v);
954
- found.push({
955
- kind: 6,
956
- part: p,
957
- why: `still a soft shadow (${read.token}) beside the theme's ${square ? 'square corners' : 'border'}`,
958
- aspect: 'shadow',
959
- steps: same
960
- ? [{thing: 'box-shadow', value: String(hard[0].v), on: p}]
961
- : hard.map(h => ({
962
- thing: 'box-shadow',
963
- value: String(h.v),
964
- on: p,
965
- mode: h.m,
966
- })),
967
- });
968
- }
969
- if (borders)
970
- for (const x of borderFrames(
971
- ctx,
972
- data,
973
- 'var(--border-width) solid var(--color-border)',
974
- ))
975
- found.push({...x, kind: 5, aspect: 'border'});
976
-
977
- // A control that keeps a height of its own at a size while the other
978
- // controls take another: controls share one height at each size, and
979
- // the line that set it, set again, makes it every control's height.
980
- for (const split of controlHeightSplits(ctx, data, res[modes[0]] ?? {}))
981
- found.push({
982
- kind: 9,
983
- part: split.part,
984
- why: `${split.reaches.includes(split.part) ? `${split.part} is` : `${split.setting.thing} ${split.setting.value} on ${split.part} reaches ${split.reaches.join(', ')}, so ${split.reaches.length > 1 ? 'they are' : 'it is'}`} ${sizesText(split.at.map(a => [a.size, a.value]))}, while the other controls are ${sizesText(split.at.map(a => [a.size, a.others.join(' or ')]))}: buttons, inputs, selectors and input groups share one height at each size`,
985
- aspect: 'size',
986
- steps: [
987
- {
988
- thing: split.line.thing,
989
- value: String(split.line.value),
990
- on: String(split.line.on),
991
- ...(split.line.when ? {when: split.line.when} : {}),
992
- ...(split.line.only ? {only: true} : {}),
993
- ...(split.line.mode ? {mode: split.line.mode} : {}),
994
- },
995
- ],
996
- });
997
-
998
- // What the theme's role colors reach on their own (the compiler writes
999
- // them onto the parts where the base theme draws the role itself) is
1000
- // not missed.
1001
- const reached = roleReach(ctx, data, base);
1002
- for (let i = found.length - 1; i >= 0; i--) {
1003
- const x = found[i];
1004
- const steps = x.steps.filter(
1005
- st =>
1006
- !reached.some(
1007
- r =>
1008
- r.part === x.part &&
1009
- r.when === (st.when ?? undefined) &&
1010
- kebab(r.prop) === st.thing &&
1011
- (st.on ?? x.part) === x.part,
1012
- ),
1013
- );
1014
- if (!steps.length) found.splice(i, 1);
1015
- else if (steps.length < x.steps.length) found[i] = {...x, steps};
1016
- }
1017
-
1018
- // One of each kind first, in the order the kinds are missed most (an
1019
- // inverted surface, a disabled part, a selected state, a status fill,
1020
- // pills, borderless surfaces), then the next of each: six lines reach six
1021
- // kinds of miss, never six of one.
1022
- /** @type {Map<number, typeof found>} */
1023
- const byKind = new Map();
1024
- for (const x of found) byKind.set(x.kind, [...(byKind.get(x.kind) ?? []), x]);
1025
- const kinds = [...byKind.keys()].sort((a, b) => a - b);
1026
- /** @type {typeof found} */
1027
- const ordered = [];
1028
- for (let round = 0; ordered.length < found.length; round++)
1029
- for (const k of kinds) {
1030
- const x = byKind.get(k)?.[round];
1031
- if (x) ordered.push(x);
1032
- }
1033
- return ordered;
1034
- }
1035
-
1036
- /**
1037
- * Heights by size in words: one value at every size once, else each with
1038
- * its size (`31px at every size`, `28px at sm, 32px at md`).
1039
- * @param {Array<[string, string]>} bySize
1040
- */
1041
- function sizesText(bySize) {
1042
- const values = [...new Set(bySize.map(([, v]) => v))];
1043
- return values.length === 1 && bySize.length === 3
1044
- ? `${values[0]} at every size`
1045
- : bySize.map(([size, v]) => `${v} at ${size}`).join(', ');
1046
- }
1047
-
1048
- /**
1049
- * The surfaces a border width does not reach that draw a box of their own
1050
- * (a dialog, a banner, a filled button's variants), each with the steps
1051
- * that frame it with `value`: scoped to the variants that draw a filled
1052
- * box at rest, where some do not (a ghost button); none for a part that
1053
- * draws no box at rest (a ghost toggle button, a menu row), one whose
1054
- * filled variants set cannot name, or one a border setting covers. Show's
1055
- * missed list and set's note on a border width both take them.
1056
- * @param {any} ctx
1057
- * @param {import('./_settings.mjs').ThemeData} data
1058
- * @param {string} value the border each step sets
1059
- * @returns {Array<{part: string, why: string, steps: MissedStep[]}>}
1060
- */
1061
- export function borderFrames(ctx, data, value) {
1062
- const C = ctx.C;
1063
- /** @param {string} p */
1064
- const covered = p =>
1065
- data.settings.some(
1066
- x =>
1067
- x.on &&
1068
- !x.state &&
1069
- partsOf(ctx, x).includes(p) &&
1070
- /^(border(-width|-style|-color)?|--border-[\w-]+)$/.test(x.thing),
1071
- );
1072
- /** The fills a part draws (never the shared hover and pressed tints). @param {string} p */
1073
- const fills = p =>
1074
- (C.partReads(p, null) ?? []).filter(
1075
- (/** @type {any} */ r) =>
1076
- /^--color-/.test(r.token) &&
1077
- !/^--color-overlay-/.test(r.token) &&
1078
- r.props.some((/** @type {string} */ x) => /^background/.test(x)),
1079
- );
1080
- /** @type {Array<{part: string, why: string, steps: MissedStep[]}>} */
1081
- const out = [];
1082
- for (const p of borderlessSurfaces(C).filter(
1083
- x => ctx.project.target.has(x) && !covered(x),
1084
- )) {
1085
- // A part whose variants differ, some with a filled box and some with
1086
- // none (a button's ghost): only the variants that draw a filled box
1087
- // at rest get a frame; one with no fill is borderless on purpose.
1088
- const variants = [
1089
- ...new Set(
1090
- fills(p)
1091
- .flatMap((/** @type {any} */ r) => r.when)
1092
- .filter((/** @type {string} */ w) => !/:|aria-|selected|\[/.test(w))
1093
- .map(
1094
- (/** @type {string} */ w) => /(?:^|\s)variant=(\S+)/.exec(w)?.[1],
1095
- )
1096
- .filter(Boolean),
1097
- ),
1098
- ];
1099
- // A part that draws no filled box at rest in any variant (a ghost
1100
- // toggle button, a menu row: their fills are pressed, hover or
1101
- // selected ones) is borderless on purpose: no frame for it.
1102
- const boxAtRest = fills(p).some((/** @type {any} */ r) =>
1103
- r.when.some(
1104
- (/** @type {string} */ w) => w === '' || !/:|aria-|selected|\[/.test(w),
1105
- ),
1106
- );
1107
- if (!boxAtRest) continue;
1108
- const all = /** @type {string[]} */ ([...(C.MAP[p]?.attrs?.variant ?? [])]);
1109
- const scoped = variants.length && all.some(v => !variants.includes(v));
1110
- // Scoped to variants set can name (the part's own variant prop); a
1111
- // part whose filled variants set cannot name is left out: one frame
1112
- // for all of them would frame the ones that draw no box.
1113
- const settable = /** @type {string[]} */ (
1114
- C.variantValues(p)?.variant ?? []
1115
- );
1116
- if (scoped && !variants.every(v => settable.includes(v))) continue;
1117
- out.push({
1118
- part: p,
1119
- why: scoped
1120
- ? `still borderless: the border width reaches no border it does not draw (the ${variants.join(', ')} variant${variants.length > 1 ? 's' : ''}; the others draw no box)`
1121
- : 'still borderless: the border width reaches no border it does not draw',
1122
- steps: (scoped ? variants.map(v => `variant:${v}`) : [undefined]).map(
1123
- when => ({thing: 'border', value, on: p, ...(when ? {when} : {})}),
1124
- ),
1125
- });
1126
- }
1127
- return out;
1128
- }