@astryxdesign/cli 0.7.16 → 0.7.17-canary.g16fe6a8

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