@astryxdesign/cli 0.7.16 → 0.7.17-canary.g335a172

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