@astryxdesign/cli 0.7.16 → 0.7.17-canary.g49a475f

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 (354) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +12 -0
  3. package/api/build/_adapter.mjs +51 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +4 -3
  7. package/api/build/build.type.d.mts +2 -2
  8. package/api/build/build.type.mjs +3 -3
  9. package/api/build/kit/kind.d.mts +2 -1
  10. package/api/build/kit/kind.mjs +199 -10
  11. package/api/build/kit/kit.mjs +6 -4
  12. package/api/build/kit/rank.d.mts +4 -2
  13. package/api/build/kit/rank.mjs +125 -24
  14. package/api/build/kit/start.d.mts +5 -4
  15. package/api/build/kit/start.mjs +12 -8
  16. package/api/build/kit/weights.d.mts +39 -3
  17. package/api/build/kit/weights.json +1 -1
  18. package/api/build/kit/weights.mjs +340 -43
  19. package/api/build/kit/word-model.d.mts +23 -0
  20. package/api/build/kit/word-model.mjs +46 -0
  21. package/api/build/kit/words.d.mts +48 -0
  22. package/api/build/kit/words.mjs +90 -1
  23. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  24. package/api/component/list/list.d.mts +1 -1
  25. package/api/component/list/list.mjs +48 -6
  26. package/api/discover/_adapter.d.mts +1 -1
  27. package/api/discover/search/search.mjs +3 -2
  28. package/api/docs/_adapter.d.mts +26 -2
  29. package/api/docs/_adapter.mjs +219 -6
  30. package/api/docs/docs.d.mts +3 -0
  31. package/api/docs/docs.doc.mjs +7 -1
  32. package/api/docs/docs.mjs +12 -0
  33. package/api/docs/docs.type.d.mts +5 -0
  34. package/api/docs/docs.type.mjs +2 -0
  35. package/api/docs/node/node.mjs +1 -1
  36. package/api/doctor/_adapter.d.mts +27 -5
  37. package/api/doctor/_adapter.mjs +83 -10
  38. package/api/doctor/built-checks.mjs +40 -14
  39. package/api/doctor/doctor.d.mts +4 -3
  40. package/api/doctor/doctor.mjs +14 -7
  41. package/api/doctor/theme-checks.mjs +121 -17
  42. package/api/icon/_records.mjs +2 -1
  43. package/api/index.d.mts +2 -0
  44. package/api/index.mjs +2 -0
  45. package/api/integration/_adapter.d.mts +44 -0
  46. package/api/integration/_adapter.mjs +77 -1
  47. package/api/integration/authoring-checks.mjs +6 -6
  48. package/api/integration/example-scope.d.mts +14 -0
  49. package/api/integration/example-scope.mjs +44 -0
  50. package/api/integration/example-scope.type.d.mts +29 -0
  51. package/api/integration/example-scope.type.mjs +25 -0
  52. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  53. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  54. package/api/integration/validate-integration.mjs +19 -1
  55. package/api/integration/validate-integration.type.d.mts +9 -0
  56. package/api/integration/validate-integration.type.mjs +1 -1
  57. package/api/integration/validateIntegration.doc.mjs +1 -1
  58. package/api/render/_adapter.mjs +591 -195
  59. package/api/render/render.doc.mjs +11 -3
  60. package/api/render/render.type.d.mts +52 -0
  61. package/api/render/render.type.mjs +31 -1
  62. package/api/search/ORDERING.md +1 -1
  63. package/api/search/_adapter.d.mts +9 -0
  64. package/api/search/_adapter.mjs +85 -0
  65. package/api/search/_candidate-score.mjs +51 -32
  66. package/api/search/_fit-order.mjs +3 -3
  67. package/api/search/_gather-components.d.mts +3 -2
  68. package/api/search/_gather-components.mjs +12 -3
  69. package/api/search/_lexical.d.mts +5 -0
  70. package/api/search/_lexical.mjs +8 -2
  71. package/api/search/_result.d.mts +11 -9
  72. package/api/search/_result.mjs +4 -4
  73. package/api/search/_score.d.mts +6 -1
  74. package/api/search/_score.mjs +15 -3
  75. package/api/search/search-index.mjs +7 -1
  76. package/api/search/search.d.mts +1 -1
  77. package/api/theme/_adapter.mjs +12 -1
  78. package/api/theme/build/build.d.mts +75 -0
  79. package/api/theme/build/build.mjs +243 -58
  80. package/api/theme/build/font-warning.d.mts +7 -0
  81. package/api/theme/build/font-warning.mjs +17 -0
  82. package/api/theme/theme.type.d.mts +10 -0
  83. package/api/theme/theme.type.mjs +7 -1
  84. package/api/theme-edit/_adapter.d.mts +63 -2
  85. package/api/theme-edit/_adapter.mjs +771 -57
  86. package/api/theme-edit/_check.d.mts +40 -22
  87. package/api/theme-edit/_check.mjs +2029 -336
  88. package/api/theme-edit/_color.d.mts +10 -0
  89. package/api/theme-edit/_color.mjs +49 -1
  90. package/api/theme-edit/_compiler.mjs +9 -0
  91. package/api/theme-edit/_context.d.mts +3 -3
  92. package/api/theme-edit/_context.mjs +111 -48
  93. package/api/theme-edit/_css.d.mts +14 -0
  94. package/api/theme-edit/_css.mjs +46 -1
  95. package/api/theme-edit/_edit.d.mts +18 -4
  96. package/api/theme-edit/_edit.mjs +1685 -155
  97. package/api/theme-edit/_how-commands.d.mts +65 -0
  98. package/api/theme-edit/_how-commands.mjs +633 -1
  99. package/api/theme-edit/_how-question.d.mts +84 -0
  100. package/api/theme-edit/_how-question.mjs +5124 -281
  101. package/api/theme-edit/_how.mjs +140 -29
  102. package/api/theme-edit/_marks.d.mts +31 -5
  103. package/api/theme-edit/_marks.mjs +57 -5
  104. package/api/theme-edit/_name-rule.d.mts +11 -0
  105. package/api/theme-edit/_name-rule.mjs +12 -0
  106. package/api/theme-edit/_normal.d.mts +257 -0
  107. package/api/theme-edit/_normal.mjs +1252 -0
  108. package/api/theme-edit/_palette.mjs +10 -4
  109. package/api/theme-edit/_parts.d.mts +10 -1
  110. package/api/theme-edit/_parts.mjs +179 -3
  111. package/api/theme-edit/_preview-app.d.mts +7 -1
  112. package/api/theme-edit/_preview-app.mjs +515 -148
  113. package/api/theme-edit/_preview.d.mts +100 -14
  114. package/api/theme-edit/_preview.mjs +549 -137
  115. package/api/theme-edit/_settings.d.mts +347 -30
  116. package/api/theme-edit/_settings.mjs +2971 -327
  117. package/api/theme-edit/_tables.d.mts +6 -0
  118. package/api/theme-edit/_tables.mjs +44 -1
  119. package/api/theme-edit/_vet.d.mts +18 -0
  120. package/api/theme-edit/_vet.mjs +32 -0
  121. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  122. package/api/theme-edit/theme-edit.type.mjs +4 -1
  123. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  124. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  125. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  126. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  128. package/api/upgrade/run/run.mjs +4 -3
  129. package/assets/codemods/integration-discovery.mjs +2 -1
  130. package/assets/codemods/run-codemod.mjs +87 -7
  131. package/assets/codemods/transforms/next/index.mjs +11 -1
  132. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  133. package/assets/component-list.generated.json +1 -0
  134. package/assets/docs/author-a-theme.doc.mjs +1 -0
  135. package/assets/docs/theme.doc.dense.mjs +2 -2
  136. package/assets/docs/theme.doc.mjs +1 -1
  137. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  138. package/assets/docs/tree/checks.doc.mjs +1 -1
  139. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  140. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  141. package/assets/docs/tree/single-component.doc.mjs +4 -0
  142. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  143. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  144. package/assets/docs/use-a-theme.doc.mjs +1 -1
  145. package/assets/docs.generated.json +2 -2
  146. package/assets/search-catalog.generated.json +2 -0
  147. package/assets/self-audit.generated.json +1 -1
  148. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  149. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  150. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  151. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  152. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  153. package/assets/templates/components.generated.json +1 -1
  154. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  155. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  156. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  157. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  158. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  159. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  160. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  161. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  162. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  163. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  164. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  165. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  166. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  167. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  168. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  169. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  170. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  171. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  172. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  173. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  174. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  175. package/assets/templates/pages/ide/page.tsx +24 -2
  176. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  177. package/assets/templates/pages/library/template.doc.mjs +4 -1
  178. package/assets/templates/pages/login/template.doc.mjs +2 -1
  179. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  180. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  181. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  182. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  183. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  184. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  185. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  186. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  187. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  188. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  189. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  190. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  191. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  192. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  193. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  194. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  195. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  196. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  197. package/assets/theme.template.ts +6 -0
  198. package/authoring/debug/parse.d.mts +3 -3
  199. package/authoring/doctypes/_schema.d.mts +3 -3
  200. package/authoring/doctypes/command/command.doc.mjs +1 -1
  201. package/authoring/doctypes/component/categories.d.mts +37 -0
  202. package/authoring/doctypes/component/categories.mjs +54 -0
  203. package/authoring/doctypes/template/template.doc.mjs +1 -1
  204. package/authoring/doctypes/template/type.ts +9 -0
  205. package/authoring/example/example.doc.d.mts +12 -0
  206. package/authoring/example/example.doc.mjs +69 -0
  207. package/authoring/example/preview.d.mts +92 -0
  208. package/authoring/example/preview.mjs +994 -0
  209. package/authoring/example/type.ts +102 -0
  210. package/authoring/index.d.mts +1 -0
  211. package/authoring/index.d.ts +12 -0
  212. package/authoring/index.mjs +3 -1
  213. package/clients/cli/bin/astryx.mjs +6 -9
  214. package/clients/cli/build-id.generated.json +1 -1
  215. package/clients/cli/commands/component.doc.mjs +1 -1
  216. package/clients/cli/commands/component.mjs +22 -3
  217. package/clients/cli/commands/docs.doc.mjs +7 -1
  218. package/clients/cli/commands/docs.mjs +3 -1
  219. package/clients/cli/commands/doctor.mjs +32 -14
  220. package/clients/cli/commands/experimental/render.mjs +42 -1
  221. package/clients/cli/commands/experimental/theme.mjs +163 -28
  222. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  223. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  224. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  225. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  226. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  227. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  228. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  229. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  230. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  231. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  232. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  233. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  234. package/clients/cli/commands/search.doc.mjs +2 -1
  235. package/clients/cli/commands/search.mjs +6 -1
  236. package/clients/cli/commands/template.mjs +4 -2
  237. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  238. package/clients/cli/commands/theme.doc.mjs +1 -1
  239. package/clients/cli/commands/theme.mjs +209 -8
  240. package/clients/cli/commands/upgrade.mjs +42 -7
  241. package/clients/cli/index.mjs +1 -1
  242. package/clients/cli/lib/cli-error.mjs +2 -1
  243. package/clients/cli/lib/component-format.mjs +205 -98
  244. package/clients/cli/lib/hook-format.mjs +9 -19
  245. package/clients/cli/lib/json-shim.mjs +77 -21
  246. package/clients/cli/lib/manifest.mjs +3 -2
  247. package/clients/cli/manifest.generated.json +1 -1
  248. package/foundation/agent-docs/agent-docs.mjs +1 -1
  249. package/foundation/config/theme-state.d.mts +13 -1
  250. package/foundation/config/theme-state.mjs +47 -7
  251. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  252. package/foundation/discovery/component-discovery.d.mts +11 -0
  253. package/foundation/discovery/component-discovery.mjs +56 -8
  254. package/foundation/discovery/component-replacement.mjs +130 -1
  255. package/foundation/discovery/copied-passages.mjs +2 -1
  256. package/foundation/discovery/doc-types.mjs +4 -3
  257. package/foundation/discovery/entry-name-files.d.mts +43 -0
  258. package/foundation/discovery/entry-name-files.mjs +264 -0
  259. package/foundation/discovery/hook-discovery.d.mts +8 -2
  260. package/foundation/discovery/hook-discovery.mjs +22 -8
  261. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  262. package/foundation/discovery/icon-set-checks.mjs +2 -1
  263. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  264. package/foundation/discovery/integration-doc-files.mjs +2 -1
  265. package/foundation/discovery/package-exports.d.mts +10 -0
  266. package/foundation/discovery/package-exports.mjs +56 -3
  267. package/foundation/discovery/prop-drift.mjs +9 -9
  268. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  269. package/foundation/discovery/runner-allowlist.mjs +2 -0
  270. package/foundation/discovery/stored-component-list.d.mts +43 -0
  271. package/foundation/discovery/stored-component-list.mjs +90 -0
  272. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  273. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  274. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  275. package/foundation/discovery/stored-self-audit.mjs +38 -18
  276. package/foundation/discovery/template-adapter.d.mts +52 -0
  277. package/foundation/discovery/template-adapter.mjs +176 -12
  278. package/foundation/discovery/template-icons.mjs +2 -1
  279. package/foundation/discovery/theme-discovery.mjs +3 -2
  280. package/foundation/discovery/theme-imports.d.mts +14 -0
  281. package/foundation/discovery/theme-imports.mjs +43 -1
  282. package/foundation/discovery/theming-targets.mjs +3 -2
  283. package/foundation/doc-compiler/import.mjs +7 -1
  284. package/foundation/doc-compiler/inputs.mjs +3 -2
  285. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  286. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  287. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  288. package/foundation/env/semver.mjs +3 -1
  289. package/foundation/fonts/font-stylesheet.d.mts +31 -0
  290. package/foundation/fonts/font-stylesheet.mjs +115 -0
  291. package/foundation/fs/cache-eviction.d.mts +21 -0
  292. package/foundation/fs/cache-eviction.mjs +73 -0
  293. package/foundation/fs/file-protection.mjs +4 -3
  294. package/foundation/fs/gather-cache.d.mts +25 -4
  295. package/foundation/fs/gather-cache.mjs +164 -55
  296. package/foundation/fs/jiti-cache.d.mts +19 -1
  297. package/foundation/fs/jiti-cache.mjs +130 -6
  298. package/foundation/fs/kept-tree.d.mts +60 -0
  299. package/foundation/fs/kept-tree.mjs +154 -0
  300. package/foundation/fs/listing-cache.d.mts +7 -0
  301. package/foundation/fs/listing-cache.mjs +10 -0
  302. package/foundation/fs/module-loader.d.mts +24 -2
  303. package/foundation/fs/module-loader.mjs +94 -21
  304. package/foundation/fs/paths.d.mts +18 -0
  305. package/foundation/fs/paths.mjs +15 -2
  306. package/foundation/identity/provider-identity.d.mts +6 -0
  307. package/foundation/identity/provider-identity.mjs +10 -1
  308. package/foundation/integrations/contribution-inventory.mjs +4 -3
  309. package/foundation/integrations/example-code.d.mts +63 -0
  310. package/foundation/integrations/example-code.mjs +416 -0
  311. package/foundation/integrations/public-imports.d.mts +9 -0
  312. package/foundation/integrations/public-imports.mjs +3 -2
  313. package/foundation/integrations/validate-contributions.mjs +17 -45
  314. package/foundation/render/embedded-files.d.mts +6 -0
  315. package/foundation/render/embedded-files.mjs +25 -5
  316. package/foundation/render/embedded-imports.d.mts +39 -7
  317. package/foundation/render/embedded-imports.mjs +66 -27
  318. package/foundation/render/file-header.d.mts +66 -0
  319. package/foundation/render/file-header.mjs +118 -0
  320. package/foundation/render/host-answer.d.mts +18 -0
  321. package/foundation/render/host-answer.mjs +46 -0
  322. package/foundation/render/host-exit.d.mts +1 -0
  323. package/foundation/render/host-exit.mjs +6 -1
  324. package/foundation/render/html-reader.d.mts +55 -2
  325. package/foundation/render/html-reader.mjs +145 -26
  326. package/foundation/render/markup-edits.d.mts +57 -0
  327. package/foundation/render/markup-edits.mjs +182 -0
  328. package/foundation/render/page-host.mjs +29 -12
  329. package/foundation/render/page-worker.mjs +121 -13
  330. package/foundation/render/picture-chrome.d.mts +4 -0
  331. package/foundation/render/picture-chrome.mjs +185 -0
  332. package/foundation/render/picture-playwright.d.mts +4 -0
  333. package/foundation/render/picture-playwright.mjs +34 -0
  334. package/foundation/render/rebuild.mjs +2 -1
  335. package/foundation/render/render-page.d.mts +35 -3
  336. package/foundation/render/render-page.mjs +316 -42
  337. package/foundation/render/source-block.d.mts +85 -6
  338. package/foundation/render/source-block.mjs +211 -20
  339. package/foundation/render/ts-paths.d.mts +69 -6
  340. package/foundation/render/ts-paths.mjs +326 -40
  341. package/foundation/response/error-codes.d.mts +3 -1
  342. package/foundation/response/error-codes.d.ts +1 -0
  343. package/foundation/response/error-codes.doc.mjs +12 -1
  344. package/foundation/response/error-codes.mjs +11 -1
  345. package/foundation/response/response-types.doc.mjs +2 -2
  346. package/foundation/text/compare-text.d.mts +14 -0
  347. package/foundation/text/compare-text.mjs +68 -0
  348. package/foundation/text/string-utils.d.mts +3 -2
  349. package/foundation/text/string-utils.mjs +18 -4
  350. package/foundation/text/suggest-order.d.mts +9 -0
  351. package/foundation/text/suggest-order.mjs +15 -1
  352. package/foundation/xle/expand.mjs +2 -1
  353. package/host/index.mjs +8 -6
  354. package/package.json +7 -6
@@ -20,7 +20,14 @@ import {
20
20
  readHistory,
21
21
  themeFiles,
22
22
  } from './_settings.mjs';
23
- import {LIKE, P} from './_tables.mjs';
23
+ import {FAMILIES, GROUPS, LIKE, P} from './_tables.mjs';
24
+ import {
25
+ COLOR_IN_VALUE,
26
+ alphaOf,
27
+ colorsIn,
28
+ parseColor,
29
+ splitTop,
30
+ } from './_color.mjs';
24
31
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
25
32
 
26
33
  /** The theme name commands use when the app has no theme yet. */
@@ -54,6 +61,7 @@ export const EXAMPLE_THEME = 'my-theme';
54
61
  * @property {{light: Record<string, string>, dark: Record<string, string>}} base
55
62
  * @property {{light: Record<string, string>, dark: Record<string, string>}} [own] - The theme's own values: the base's with its settings applied.
56
63
  * @property {(steps: Step[]) => {ok: true} | {ok: false, why: string}} check
64
+ * @property {(steps: Step[], intent: MeasureIntent) => string | null} measure the measured check: why the built result does not do what the question asks, or null
57
65
  */
58
66
 
59
67
  /**
@@ -120,6 +128,9 @@ export async function howTheme(ctx, cwd, name) {
120
128
  const compiled = (/** @type {import('./_settings.mjs').ThemeData} */ d) =>
121
129
  JSON.stringify([d.mode, compileTheme(ctx, d, base)]);
122
130
  const before = compiled(theme);
131
+ /** @type {any} */
132
+ let beforeCache = null;
133
+ const beforeCompiled = () => (beforeCache ??= compileTheme(ctx, theme, base));
123
134
  // Whether a body font setting also moves the heading font: Core gives
124
135
  // headings the body family when a theme names no heading family, so it is
125
136
  // read from Core, and stays right when that changes.
@@ -184,6 +195,35 @@ export async function howTheme(ctx, cwd, name) {
184
195
  ? readHistory(themeFiles(cwd, slug).history).steps.length
185
196
  : 0,
186
197
  bodyFontReachesHeadings,
198
+ /**
199
+ * The measured check: build the theme with the steps in memory (the
200
+ * same compile `set` builds from; nothing is written), resolve every
201
+ * value the touched parts show at rest and in the named state or
202
+ * variant, in light and dark, before and after, and hold them to what
203
+ * the question asks. Returns why it does not fit, or null.
204
+ * @param {Step[]} steps
205
+ * @param {MeasureIntent} intent
206
+ * @returns {string | null}
207
+ */
208
+ measure(steps, intent) {
209
+ const d = JSON.parse(JSON.stringify(theme));
210
+ const checkCtx = /** @type {any} */ ({...ctx, base});
211
+ try {
212
+ for (const st of steps) apply(checkCtx, slug, d, st);
213
+ } catch {
214
+ return null; // check() says why
215
+ }
216
+ const was = beforeCompiled();
217
+ const now = compileTheme(ctx, d, base);
218
+ // A one-mode theme shows only that mode: only it is measured.
219
+ const visible =
220
+ d.mode === 'light-only'
221
+ ? 'light'
222
+ : d.mode === 'dark-only'
223
+ ? 'dark'
224
+ : null;
225
+ return measureFit(ctx, base, was, now, intent, steps, visible);
226
+ },
187
227
  check(steps) {
188
228
  /** @type {import('./_settings.mjs').ThemeData} */
189
229
  const d = JSON.parse(JSON.stringify(theme));
@@ -209,6 +249,598 @@ export async function howTheme(ctx, cwd, name) {
209
249
  };
210
250
  }
211
251
 
252
+ /**
253
+ * What the measured check holds a command to.
254
+ * @typedef {object} MeasureIntent
255
+ * @property {string[]} families the kinds of change asked for (color, radius, space, border, weight, opacity, shadow, fontsize); empty: any
256
+ * @property {'more' | 'less' | null} dir the way a size moves
257
+ * @property {boolean | null} lighter the way a color moves
258
+ * @property {'more' | 'less' | null} opacityDir the way an opacity moves
259
+ * @property {boolean} zero a removal: the changed values reach none or 0
260
+ * @property {string[]} subjects the parts the question changes
261
+ * @property {string[]} keep the parts it excepts, compares against or forbids changing
262
+ * @property {string[]} typed values the question gives (taken as given)
263
+ * @property {'light' | 'dark' | null} [mode] the mode the question names
264
+ * @property {boolean} [bound] the question gives a bound ("smaller than 24px"): a space is checked against it too
265
+ * @property {boolean} [contrast] the words ask about contrast ("too light to read"): text in dark mode moves the other way
266
+ * @property {string[]} [than] parts the question compares against ("darker than the page"): a color moves past theirs
267
+ * @property {boolean} [literal] a mode is named with lighter or darker: borders and the shared text color move as written
268
+ * @property {'more' | 'less' | null} [shadowDir] the way a shadow's strength moves ("darker shadows": more)
269
+ */
270
+
271
+ /** A camelCase property as CSS writes it. @param {string} k */
272
+ const kebab = k => k.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
273
+
274
+ /**
275
+ * Every value of a compiled part, by `when|state|prop`.
276
+ * @param {any} comp the part's compiled styles
277
+ * @returns {Map<string, string>}
278
+ */
279
+ function partValues(comp) {
280
+ /** @type {Map<string, string>} */
281
+ const out = new Map();
282
+ for (const [when, rules] of Object.entries(comp ?? {}))
283
+ for (const [k, v] of Object.entries(/** @type {any} */ (rules) ?? {}))
284
+ if (v && typeof v === 'object')
285
+ for (const [k2, v2] of Object.entries(v))
286
+ out.set(`${when}|${k}|${kebab(k2)}`, String(v2));
287
+ else out.set(`${when}||${kebab(k)}`, String(v));
288
+ // A plain color written as `background` paints the background color.
289
+ for (const [k, v] of [...out])
290
+ if (/\|background$/.test(k) && !/gradient|url\(/.test(v)) {
291
+ const bc = k.replace(/background$/, 'background-color');
292
+ if (!out.has(bc)) out.set(bc, v);
293
+ }
294
+ return out;
295
+ }
296
+
297
+ /**
298
+ * A value with every var() written out from a mode's tokens, and
299
+ * light-dark() taken for that mode.
300
+ * @param {string} v
301
+ * @param {Record<string, string>} map
302
+ * @param {'light' | 'dark'} mode
303
+ */
304
+ function resolveIn(v, map, mode) {
305
+ let out = String(v ?? '');
306
+ for (let i = 0; i < 8; i++) {
307
+ const next = out
308
+ .replace(/var\(\s*(--[a-z0-9-]+)\s*(?:,\s*([^()]*))?\)/gi, (_, t, fb) =>
309
+ String(map[t] ?? fb ?? ''),
310
+ )
311
+ .replace(
312
+ /light-dark\(\s*([^,()]+(?:\([^()]*\))?)\s*,\s*([^()]+(?:\([^()]*\))?)\s*\)/gi,
313
+ (_, a, b) => (mode === 'light' ? a : b),
314
+ );
315
+ if (next === out) break;
316
+ out = next;
317
+ }
318
+ return out.trim().toLowerCase();
319
+ }
320
+
321
+ /** The family of a CSS property or token, as the step check names them. @param {string} prop */
322
+ function familyOf(prop) {
323
+ if (/radius/.test(prop)) return 'radius';
324
+ if (/^--shadow-|^box-shadow$/.test(prop)) return 'shadow';
325
+ if (/^opacity$/.test(prop)) return 'opacity';
326
+ if (/weight/.test(prop)) return 'weight';
327
+ if (/^(font-size|--font-size-[a-z0-9]+|--text-[a-z0-9-]+-size)$/.test(prop))
328
+ return 'fontsize';
329
+ if (
330
+ /^(border(-[a-z]+)?-width|border(-(top|bottom|left|right|block|inline))?$|--border-width|--focus-outline-width|outline-width)$/.test(
331
+ prop,
332
+ )
333
+ )
334
+ return 'border';
335
+ if (/colou?r|^background(-image)?$|^fill$|^stroke$|^filter$/.test(prop))
336
+ return 'color';
337
+ if (
338
+ /^(padding|gap|margin|min-height|height|width|max-width|min-width|--spacing-|--size-)/.test(
339
+ prop,
340
+ )
341
+ )
342
+ return 'space';
343
+ return null;
344
+ }
345
+
346
+ /** A length as px (rem/em at 16), or a plain number, or null. @param {string} v */
347
+ function measureNumber(v) {
348
+ const m = /^(-?\d*\.?\d+)(px|rem|em)?$/.exec(
349
+ String(v).trim().split(/\s+/)[0],
350
+ );
351
+ return m ? Number(m[1]) * (m[2] === 'rem' || m[2] === 'em' ? 16 : 1) : null;
352
+ }
353
+
354
+ /**
355
+ * Whether a color steps for contrast in dark mode (a border; text when the
356
+ * words ask about contrast): there "darker" asks for more contrast, so it
357
+ * moves lighter, and "lighter" darker; a fill moves the same way in both
358
+ * modes.
359
+ * @param {string} name a token or a property
360
+ * @param {boolean} [contrast] the words ask about contrast
361
+ * @param {boolean} [literal] a mode is named with lighter or darker
362
+ */
363
+ const isForeground = (name, contrast = false, literal = false) =>
364
+ !/background|surface|fill|accent|overlay/.test(name) &&
365
+ // Borders and the shared text tokens step by contrast with the page (how
366
+ // answers "lighter text" and "darker borders" that way), unless a mode is
367
+ // named; a part's own color steps as written.
368
+ ((!literal && /border|outline/.test(name)) ||
369
+ (!literal && /^--color-text-/.test(name)) ||
370
+ (contrast && /text|^color$|on-/.test(name)));
371
+
372
+ /**
373
+ * How strong a shadow reads: the sum of its colors' alphas; 0 for none.
374
+ * @param {string} v
375
+ */
376
+ function shadowStrength(v) {
377
+ if (!v || /^none$/.test(v.trim())) return 0;
378
+ // Each layer's color, read by the one color reader (hex with alpha,
379
+ // rgba(), hsla(), `/ alpha`). A layer has lengths: a bare color is no
380
+ // shadow.
381
+ return splitTop(v, ',')
382
+ .filter(layer => /(?:^|\s)-?\d*\.?\d+(?:px|rem|em)?(?=\s|$)/.test(layer))
383
+ .reduce(
384
+ (sum, layer) => sum + colorsIn(layer).reduce((n, c) => n + alphaOf(c), 0),
385
+ 0,
386
+ );
387
+ }
388
+
389
+ /**
390
+ * A shadow as it renders: each color written in one form (hex with its
391
+ * alpha), so two spellings of the same shadow compare equal.
392
+ * @param {string} v
393
+ */
394
+ function shadowLook(v) {
395
+ return String(v)
396
+ .replace(COLOR_IN_VALUE, c => {
397
+ const rgb = parseColor(c);
398
+ if (!rgb) return c;
399
+ const a = Math.round(alphaOf(c) * 255);
400
+ return `rgb(${rgb.slice(0, 3).join(' ')} / ${a})`;
401
+ })
402
+ .replace(/\s+/g, ' ')
403
+ .trim();
404
+ }
405
+
406
+ /**
407
+ * A color as it paints over the page in a mode: its alpha blended with the
408
+ * page color, so a see-through fill compares by what shows.
409
+ * @param {string} v
410
+ * @param {Record<string, string>} toks the mode's tokens
411
+ * @param {'light' | 'dark'} mode
412
+ * @returns {number[] | null}
413
+ */
414
+ function painted(v, toks, mode) {
415
+ const rgb = parseColor(v);
416
+ if (!rgb) return null;
417
+ const a = alphaOf(v);
418
+ const page =
419
+ parseColor(resolveIn('var(--color-background-body)', toks, mode)) ??
420
+ (mode === 'dark' ? [0, 0, 0] : [255, 255, 255]);
421
+ return rgb.slice(0, 3).map((x, i) => x * a + page[i] * (1 - a));
422
+ }
423
+
424
+ /** @param {number[]} c */
425
+ const luminance = c => c[0] * 0.299 + c[1] * 0.587 + c[2] * 0.114;
426
+
427
+ /**
428
+ * Hold the after build to the intent; why it does not fit, or null.
429
+ * @param {any} ctx
430
+ * @param {any} base
431
+ * @param {any} was
432
+ * @param {any} now
433
+ * @param {MeasureIntent} intent
434
+ * @param {Step[]} steps
435
+ * @param {'light' | 'dark' | null} [visible] the one mode a one-mode theme shows
436
+ */
437
+ function measureFit(ctx, base, was, now, intent, steps, visible = null) {
438
+ const tw = ownTokens(was, base);
439
+ const tn = ownTokens(now, base);
440
+ const C = ctx.C;
441
+ /** @param {string} part */
442
+ const members = part => FAMILIES[part] ?? [part];
443
+ // A kept part, or one state or variant of it (`part@when|state|`).
444
+ /** @type {Array<{part: string, prefix: string}>} */
445
+ const keeps = intent.keep.flatMap(k => {
446
+ const [part, prefix = ''] = k.split('@');
447
+ return members(part).map(m => ({part: m, prefix}));
448
+ });
449
+ const subjects = new Set(intent.subjects.flatMap(members));
450
+ /**
451
+ * The values a part shows, by `when|state|prop` and mode: its own
452
+ * compiled rules, then each token it reads for a property.
453
+ * @param {any} compiled
454
+ * @param {{light: Record<string, string>, dark: Record<string, string>}} toks
455
+ * @param {string} part
456
+ */
457
+ const shown = (compiled, toks, part) => {
458
+ // Each rule of the part: the base theme's own declarations with the
459
+ // theme's on top, condition by condition (a theme rule that sets one
460
+ // property keeps the base rule's others).
461
+ /** @type {Record<string, Record<string, any>>} */
462
+ const rules = {};
463
+ for (const src of [
464
+ base.components?.[part] ?? {},
465
+ compiled.components?.[part] ?? {},
466
+ ])
467
+ for (const [when, rule] of Object.entries(src))
468
+ rules[when] =
469
+ rule && typeof rule === 'object' && !Array.isArray(rule)
470
+ ? {...(rules[when] ?? {}), ...rule}
471
+ : rule;
472
+ const own = partValues(rules);
473
+ // A token the part's own rule sets (a part-scoped dial's --spacing-4)
474
+ // is the value inside the part.
475
+ // A token a variant's rule sets holds in that variant, over the part's.
476
+ const scoped = (
477
+ /** @type {'light' | 'dark'} */ m,
478
+ /** @type {string} */ when,
479
+ ) => {
480
+ /** @type {Record<string, string>} */
481
+ const t = {...toks[m]};
482
+ for (const w of when === 'base' ? ['base'] : ['base', when])
483
+ for (const [k, v] of Object.entries(rules[w] ?? {}))
484
+ if (k.startsWith('--') && typeof v === 'string') t[k] = v;
485
+ return t;
486
+ };
487
+ /** @type {Map<string, string>} */
488
+ const raw = new Map(own);
489
+ // The part at rest in its main variant is its `base` too (a set with no
490
+ // --when writes base).
491
+ const mainWhen = (/** @type {string[]} */ ws) =>
492
+ ws.some(
493
+ w =>
494
+ w === '' ||
495
+ /^variant=(default|primary|accent|neutral)$|^size=md$/.test(w),
496
+ );
497
+ for (const g of Object.keys(GROUPS))
498
+ for (const r of C.partReads(part, g) ?? [])
499
+ if (mainWhen(r.when?.length ? r.when : ['']))
500
+ for (const prop of r.props ?? []) {
501
+ const key = `base||${prop}`;
502
+ if (!raw.has(key)) raw.set(key, `var(${r.token})`);
503
+ }
504
+ for (const g of Object.keys(GROUPS))
505
+ for (const r of C.partReads(part, g) ?? [])
506
+ for (const prop of r.props ?? [])
507
+ for (const w of r.when?.length ? r.when : [''])
508
+ if (!/::|:active|:hover|:focus|:checked|:disabled/.test(w)) {
509
+ const key = `${w ? w.replace('=', ':') : 'base'}||${prop}`;
510
+ // A variant with no rule of its own takes the part's own base
511
+ // rule over the token it reads.
512
+ if (!raw.has(key))
513
+ raw.set(key, own.get(`base||${prop}`) ?? `var(${r.token})`);
514
+ }
515
+ /** @type {Map<string, {light: string, dark: string, raw: string}>} */
516
+ const out = new Map();
517
+ for (const [k, v] of raw)
518
+ out.set(k, {
519
+ light: resolveIn(v, scoped('light', k.split('|')[0]), 'light'),
520
+ dark: resolveIn(v, scoped('dark', k.split('|')[0]), 'dark'),
521
+ raw: v,
522
+ });
523
+ return out;
524
+ };
525
+ // Parts the question keeps: every value they show is the same after.
526
+ for (const {part, prefix} of keeps) {
527
+ const a = shown(was, tw, part);
528
+ const b = shown(now, tn, part);
529
+ for (const [k, v] of b) {
530
+ // A whole kept part: its plain look (base); a state or variant: that.
531
+ // A whole kept part: every rule it shows at rest (its plain rule and
532
+ // each variant's); a state or variant: that.
533
+ // (At rest: the plain rule, or one variant's alone; a variant in a
534
+ // selected or checked state is a state of it.)
535
+ if (
536
+ prefix
537
+ ? !k.startsWith(prefix)
538
+ : k.split('|')[1] || !/^(base|[a-z]+:[\w-]+)$/.test(k.split('|')[0])
539
+ )
540
+ continue;
541
+ // A plain color written as `background` is the background color the
542
+ // part painted before.
543
+ const prop0 = k.split('|')[2] ?? '';
544
+ const o =
545
+ a.get(k) ??
546
+ (/\|background$/.test(k) ? a.get(`${k}-color`) : undefined) ??
547
+ // A custom property set on the part: what that token was before.
548
+ (/^--/.test(prop0)
549
+ ? {
550
+ light: resolveIn(`var(${prop0})`, tw.light, 'light'),
551
+ dark: resolveIn(`var(${prop0})`, tw.dark, 'dark'),
552
+ raw: `var(${prop0})`,
553
+ }
554
+ : undefined);
555
+ // (A state rule the part did not list before is not measured: what
556
+ // it showed in that state is not known here.)
557
+ if (!o && k.split('|')[1]) continue;
558
+ // A value the part did not show before (a keep rule on a member that
559
+ // reads none of it) is not a change it shows; a kept variant is held
560
+ // exactly: a rule it did not have, other than none, is a change,
561
+ // unless it is what the part showed at rest; a corner longhand under
562
+ // a kept shorthand follows the shorthand.
563
+ if (!o && (!prefix || /^(none|transparent|initial|unset)$/.test(v.raw)))
564
+ continue;
565
+ const inherited = a.get(`base||${k.split('|')[2]}`);
566
+ if (
567
+ !o &&
568
+ inherited &&
569
+ inherited.light === v.light &&
570
+ inherited.dark === v.dark
571
+ )
572
+ continue;
573
+ if (!o)
574
+ return `it would change ${part} (${k.split('|').filter(Boolean).join(' ')}), which the question keeps as it is`;
575
+ if (
576
+ /radius$/.test(k) &&
577
+ /-(start|end)-(start|end)-radius$/.test(k) &&
578
+ b.has('base||border-radius')
579
+ )
580
+ continue;
581
+ // A padding side under a kept padding shorthand follows the shorthand
582
+ // (the part's own padding covers every side).
583
+ if (/\|padding-/.test(k)) {
584
+ const sh = b.get('base||padding');
585
+ const was = a.get('base||padding');
586
+ if (sh && was && sh.light === was.light && sh.dark === was.dark)
587
+ continue;
588
+ }
589
+ if (o.light !== v.light || o.dark !== v.dark)
590
+ return `it would change ${part} (${k.split('|').filter(Boolean).join(' ')}), which the question keeps as it is`;
591
+ }
592
+ }
593
+ const typed = new Set(intent.typed.map(x => x.toLowerCase()));
594
+ // A shadow ask is answered only by a shadow that looks different: an
595
+ // opaque color written with alpha ff, or clamped there, is no change.
596
+ let shadowMoved = !intent.shadowDir;
597
+ // A value the question types is the target: the way of what it writes
598
+ // is as written, but the kind of change and a removal are still held,
599
+ // and every other value is measured the way asked (a dial step beside a
600
+ // typed value included: "smaller, 16px" never gives spacing more). A dial
601
+ // is judged by what it does, never by its own word: "vibrancy less" is
602
+ // the way "more washed out" asks.
603
+ const typedFamilies = new Set(
604
+ steps
605
+ .filter(st => typed.has(String(st.value ?? '').toLowerCase()))
606
+ .map(st => familyOf(st.thing)),
607
+ );
608
+ // The subject's changed values: family, direction, removal.
609
+ const touched = new Set([
610
+ ...subjects,
611
+ ...steps
612
+ .map(st => st.on)
613
+ .filter(Boolean)
614
+ .flatMap(x => members(String(x))),
615
+ ]);
616
+ for (const part of touched) {
617
+ // A whole kept part is checked above, not as a subject.
618
+ if (keeps.some(k => k.part === part && !k.prefix)) continue;
619
+ const a = shown(was, tw, part);
620
+ const b = shown(now, tn, part);
621
+ for (const [k, v] of b) {
622
+ // A kept state or variant of the part is checked above.
623
+ if (
624
+ keeps.some(x => x.part === part && x.prefix && k.startsWith(x.prefix))
625
+ )
626
+ continue;
627
+ const prop = k.split('|')[2];
628
+ // A shorthand written where the part read longhands: its first side.
629
+ // (Whether the value before is the same rule's, not a stand-in.)
630
+ const exact = a.has(k);
631
+ const o =
632
+ a.get(k) ??
633
+ (prop === 'padding'
634
+ ? (a.get(`${k.split('|')[0]}||padding-top`) ??
635
+ a.get('base||padding-top'))
636
+ : prop === 'border'
637
+ ? a.get('base||border-width')
638
+ : a.get(`base||${prop}`));
639
+ if (o && o.light === v.light && o.dark === v.dark) continue;
640
+ const fam = familyOf(prop);
641
+ if (!fam) continue;
642
+ // A property a typed value writes is asked: the question wrote it.
643
+ const typedHere = steps.some(
644
+ st =>
645
+ typed.has(String(st.value ?? '').toLowerCase()) &&
646
+ familyOf(st.thing) === fam,
647
+ );
648
+ if (
649
+ intent.families.length &&
650
+ !intent.families.includes(fam) &&
651
+ !typedHere
652
+ )
653
+ return `it would also change ${part}'s ${prop}, which is not what the question asks to change`;
654
+ for (const mode of /** @type {const} */ (['light', 'dark'])) {
655
+ if (visible && mode !== visible) continue;
656
+ const after = v[mode];
657
+ const before = o?.[mode] ?? null;
658
+ if (
659
+ intent.zero &&
660
+ ['radius', 'space', 'border', 'shadow'].includes(fam)
661
+ ) {
662
+ const n = measureNumber(after);
663
+ if (!/^(none|transparent|0)$/.test(after) && n !== 0)
664
+ return `${part}'s ${prop} would be ${after} in ${mode} mode, not none`;
665
+ continue;
666
+ }
667
+ // A shadow written where the part showed none it can read is a
668
+ // change.
669
+ if (fam === 'shadow' && before == null && !/^none$/i.test(after))
670
+ shadowMoved = true;
671
+ if (before == null || typedFamilies.has(fam)) continue;
672
+ // A shadow's strength moves the way asked, in each mode.
673
+ if (fam === 'shadow' && intent.shadowDir) {
674
+ const x = shadowStrength(after);
675
+ const y = shadowStrength(before);
676
+ if (Math.abs(x - y) > 1e-6 && (intent.shadowDir === 'more') !== x > y)
677
+ return `${part}'s ${prop} would get ${intent.shadowDir === 'more' ? 'weaker' : 'stronger'} in ${mode} mode`;
678
+ if (shadowLook(after) !== shadowLook(before)) shadowMoved = true;
679
+ continue;
680
+ }
681
+ // "more transparent": the color's alpha goes down, "more opaque" up.
682
+ if (fam === 'color' && intent.opacityDir) {
683
+ const x = parseColor(after) ? alphaOf(after) : null;
684
+ const y = parseColor(before) ? alphaOf(before) : null;
685
+ if (
686
+ x != null &&
687
+ y != null &&
688
+ Math.abs(x - y) > 1e-3 &&
689
+ (intent.opacityDir === 'more') !== x > y
690
+ )
691
+ return `${part}'s ${prop} would get ${intent.opacityDir === 'more' ? 'more' : 'less'} see-through in ${mode} mode`;
692
+ }
693
+ if (fam === 'color' && intent.lighter != null) {
694
+ // A part's color, in every variant and state it shows (a step on
695
+ // the plain rule reaches the variants that take it), in each mode
696
+ // (or the one the question names), never an overlay layer over
697
+ // the fill; only the kind of color the steps write (a new fill
698
+ // may bring a text color that reads on it).
699
+ if (intent.mode && mode !== intent.mode) continue;
700
+ const [when] = k.split('|');
701
+ if (!exact) continue;
702
+ const kindOf = (/** @type {string} */ x) =>
703
+ /^background/.test(x)
704
+ ? 'fill'
705
+ : /border|outline/.test(x)
706
+ ? 'line'
707
+ : 'ink';
708
+ if (
709
+ !steps.some(
710
+ st => kindOf(st.thing.replace(/^--color-/, '')) === kindOf(prop),
711
+ )
712
+ )
713
+ continue;
714
+ if (
715
+ /overlay|tint/.test(String(o?.raw ?? '')) ||
716
+ /overlay|tint/.test(v.raw)
717
+ )
718
+ continue;
719
+ const x = painted(after, tn[mode], mode);
720
+ const y = painted(before, tw[mode], mode);
721
+ const want =
722
+ mode === 'dark' &&
723
+ isForeground(prop, intent.contrast, intent.literal)
724
+ ? !intent.lighter
725
+ : intent.lighter;
726
+ if (x && y && Math.abs(luminance(x) - luminance(y)) >= 0.5)
727
+ if (want !== luminance(x) > luminance(y))
728
+ return `${part}'s ${prop}${when !== 'base' ? ` (${when})` : ''} would get ${want ? 'darker' : 'lighter'} in ${mode} mode (${before} to ${after})`;
729
+ // "darker than the page": past the part compared against, in
730
+ // each mode it shows.
731
+ if (x && /^background/.test(prop))
732
+ for (const ref of intent.than ?? []) {
733
+ const refValue =
734
+ ref === 'page'
735
+ ? resolveIn('var(--color-background-body)', tn[mode], mode)
736
+ : shown(now, tn, ref).get('base||background-color')?.[mode];
737
+ const r = refValue ? painted(refValue, tn[mode], mode) : null;
738
+ if (r && want !== luminance(x) > luminance(r))
739
+ return `${part}'s ${prop}${when !== 'base' ? ` (${when})` : ''} would still be ${want ? 'darker' : 'lighter'} than the ${ref} in ${mode} mode (${after} on ${refValue})`;
740
+ }
741
+ continue;
742
+ }
743
+ const dir = fam === 'opacity' ? intent.opacityDir : intent.dir;
744
+ if (
745
+ !dir ||
746
+ !(
747
+ ['radius', 'border', 'weight', 'opacity', 'fontsize'].includes(
748
+ fam,
749
+ ) ||
750
+ // A space: one length written over one read (never a shorthand).
751
+ (fam === 'space' &&
752
+ (intent.bound ||
753
+ (exact &&
754
+ steps.some(st => st.thing === prop) &&
755
+ !/\s/.test(after) &&
756
+ !/\s/.test(String(before)))))
757
+ )
758
+ )
759
+ continue;
760
+ const x = measureNumber(after);
761
+ const y = measureNumber(before);
762
+ if (x != null && y != null && x !== y && (dir === 'more') !== x > y)
763
+ return `${part}'s ${prop} would move the other way in ${mode} mode (${before} to ${after})`;
764
+ }
765
+ }
766
+ }
767
+ // Tokens the steps name (a dial: its main token): the same checks.
768
+ const DIAL_TOKEN = /** @type {Record<string, string>} */ ({
769
+ accent: '--color-accent',
770
+ danger: '--color-error',
771
+ success: '--color-success',
772
+ warning: '--color-warning',
773
+ info: '--color-info',
774
+ neutral: '--color-neutral',
775
+ });
776
+ for (const st of steps) {
777
+ const tok = /^--/.test(st.thing) ? st.thing : DIAL_TOKEN[st.thing];
778
+ if (!tok || st.on) continue;
779
+ const fam = familyOf(tok);
780
+ if (!fam) continue;
781
+ if (intent.families.length && !intent.families.includes(fam))
782
+ return `${tok} is not what the question asks to change`;
783
+ for (const mode of /** @type {const} */ (['light', 'dark'])) {
784
+ if (visible && mode !== visible) continue;
785
+ const after = resolveIn(`var(${tok})`, tn[mode], mode);
786
+ const before = resolveIn(`var(${tok})`, tw[mode], mode);
787
+ if (after === before) continue;
788
+ if (
789
+ intent.zero &&
790
+ ['radius', 'space', 'border', 'shadow'].includes(fam)
791
+ ) {
792
+ const n = measureNumber(after);
793
+ if (!/^(none|transparent|0)$/.test(after) && n !== 0)
794
+ return `${tok} would be ${after} in ${mode} mode, not none`;
795
+ continue;
796
+ }
797
+ if (typedFamilies.has(fam)) continue;
798
+ if (fam === 'shadow' && intent.shadowDir) {
799
+ const x = shadowStrength(after);
800
+ const y = shadowStrength(before);
801
+ if (Math.abs(x - y) > 1e-6 && (intent.shadowDir === 'more') !== x > y)
802
+ return `${tok} would get ${intent.shadowDir === 'more' ? 'weaker' : 'stronger'} in ${mode} mode`;
803
+ if (shadowLook(after) !== shadowLook(before)) shadowMoved = true;
804
+ continue;
805
+ }
806
+ if (fam === 'color' && intent.opacityDir) {
807
+ const x = parseColor(after) ? alphaOf(after) : null;
808
+ const y = parseColor(before) ? alphaOf(before) : null;
809
+ if (
810
+ x != null &&
811
+ y != null &&
812
+ Math.abs(x - y) > 1e-3 &&
813
+ (intent.opacityDir === 'more') !== x > y
814
+ )
815
+ return `${tok} would get ${intent.opacityDir === 'more' ? 'more' : 'less'} see-through in ${mode} mode`;
816
+ continue;
817
+ }
818
+ if (fam === 'color' && intent.lighter != null) {
819
+ if (intent.mode && mode !== intent.mode) continue;
820
+ const x = painted(after, tn[mode], mode);
821
+ const y = painted(before, tw[mode], mode);
822
+ const want =
823
+ mode === 'dark' && isForeground(tok, intent.contrast, intent.literal)
824
+ ? !intent.lighter
825
+ : intent.lighter;
826
+ if (x && y && Math.abs(luminance(x) - luminance(y)) >= 0.5)
827
+ if (want !== luminance(x) > luminance(y))
828
+ return `${tok} would get ${want ? 'darker' : 'lighter'} in ${mode} mode (${before} to ${after})`;
829
+ continue;
830
+ }
831
+ const dir = fam === 'opacity' ? intent.opacityDir : intent.dir;
832
+ if (!dir) continue;
833
+ const x = measureNumber(after);
834
+ const y = measureNumber(before);
835
+ if (x != null && y != null && x !== y && (dir === 'more') !== x > y)
836
+ return `${tok} would move the other way in ${mode} mode (${before} to ${after})`;
837
+ }
838
+ }
839
+ if (!shadowMoved && steps.some(st => familyOf(st.thing) === 'shadow'))
840
+ return 'the shadows would look the same as they do now (a shadow color at full strength gets no stronger; a bigger or blurrier shadow can)';
841
+ return null;
842
+ }
843
+
212
844
  /**
213
845
  * Apply one step to theme data in memory, as `set` and `undo` do.
214
846
  * @param {import('./_settings.mjs').Ctx} ctx