@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,10 +12,10 @@
12
12
  import {AstryxError} from '../error.mjs';
13
13
  import * as fs from 'node:fs';
14
14
  import * as path from 'node:path';
15
- import {partForWord} from './_how-question.mjs';
15
+ import {partForWord} from './_part-words.mjs';
16
16
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
17
+ import {cssUnescape} from '../../foundation/text/css-escape.mjs';
17
18
  import {baseInstalled, baseThemeFile, installLine} from './_project.mjs';
18
- import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
19
19
  import {
20
20
  withFallbacks,
21
21
  MATH_FUNCTION,
@@ -32,6 +32,7 @@ import {
32
32
  numbersIn,
33
33
  propertyGrammar,
34
34
  takesPercentage,
35
+ sameKindValues,
35
36
  } from './_css.mjs';
36
37
  import {calcVars, coreFallback, multipliedTokens} from './_parts.mjs';
37
38
  import {
@@ -61,6 +62,8 @@ import {
61
62
  wordTable,
62
63
  WRAPPED_PARTS,
63
64
  CARD_LIKE,
65
+ isSystemFamily,
66
+ fontStack,
64
67
  } from './_tables.mjs';
65
68
  import {
66
69
  COLOR_NAMES,
@@ -77,7 +80,7 @@ import {
77
80
  PALETTE_DIALS,
78
81
  PALETTE_TOKENS,
79
82
  VIBRANCY_DEFAULT,
80
- isGraySeed,
83
+ vibrancyMoves,
81
84
  paletteToken,
82
85
  seedOf,
83
86
  } from './_palette.mjs';
@@ -85,27 +88,88 @@ import {
85
88
  camel,
86
89
  kebab,
87
90
  nearest,
88
- partDefault,
91
+ negates,
89
92
  partsOf,
90
93
  refuse,
91
94
  lengthPx,
95
+ cornersPlain,
92
96
  radiusAt,
93
97
  radiusTokenOf,
98
+ cornerParts,
94
99
  focusStateOf,
95
100
  valueProblem,
96
101
  partComponentDocs,
97
102
  themeFiles,
98
103
  ownSourceTokenValues,
99
104
  baseTopTokens,
105
+ baseComponent,
100
106
  baseComponentReads,
101
107
  partRuleTokens,
102
108
  cssFamily,
103
109
  familySpaces,
110
+ baseTextPx,
111
+ fontsourcePackageOf,
112
+ dialWordOf,
113
+ paddedParts,
114
+ onBuiltInSteps,
104
115
  } from './_settings.mjs';
116
+ import {isColorToken} from './_compiler.mjs';
117
+ import {
118
+ trimInsideQuotes,
119
+ colorPair,
120
+ otherSettingLabel,
121
+ familiesOf,
122
+ familyPieces,
123
+ normalValueText,
124
+ normalizeEntry,
125
+ withoutDebris,
126
+ typoOf,
127
+ typoNear,
128
+ modeWord,
129
+ documentTypoWords,
130
+ PROPERTY_WORDS,
131
+ WEIGHT_WORDS,
132
+ TAILWIND_RADIUS,
133
+ documentReadings,
134
+ documentNumericTable,
135
+ documentRange,
136
+ withoutCopyDebris,
137
+ commaNumbers,
138
+ weightSetting,
139
+ baseWord,
140
+ } from './_normal.mjs';
141
+
142
+ export {
143
+ familiesOf,
144
+ familyPieces,
145
+ normalValueText,
146
+ normalizeEntry,
147
+ withoutDebris,
148
+ };
105
149
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
106
150
 
107
151
  export {lengthPx};
108
152
 
153
+ /**
154
+ * The radius the base theme's own rule gives a part, in px, or null when
155
+ * its rule gives none.
156
+ * @param {any} ctx
157
+ * @param {{light: Record<string, string>}} base
158
+ * @param {string} part
159
+ * @param {string | undefined} when
160
+ * @returns {number | null}
161
+ */
162
+ function basePartRadiusPx(ctx, base, part, when) {
163
+ const own = ctx.base
164
+ ? baseComponent(ctx.base, ctx, part, 'borderRadius', {when})
165
+ : null;
166
+ if (typeof own !== 'string') return null;
167
+ const tokenName = /var\(\s*(--radius-[\w-]+)/.exec(own)?.[1];
168
+ if (tokenName) return tokenPx(base, tokenName);
169
+ const px = lengthPx(own);
170
+ return px == null ? null : Math.min(px, 9999);
171
+ }
172
+
109
173
  /**
110
174
  * A token's value in px, following var() references through the tokens.
111
175
  * @param {{light: Record<string, string>}} base
@@ -122,6 +186,13 @@ function tokenPx(base, token) {
122
186
  return lengthPx(v);
123
187
  }
124
188
 
189
+ // A type scale ratio is a number above 1, up to 2.
190
+ documentNumericTable(
191
+ ['type'],
192
+ Object.entries(TYPE_STYLES).map(([name, style]) => [name, style.ratio]),
193
+ [1, 2],
194
+ );
195
+
125
196
  /**
126
197
  * The `type` preset nearest a scale ratio typed as a number (1.3 is
127
198
  * editorial), or null for a number that is no ratio (16).
@@ -154,6 +225,108 @@ const cornerPxOf = v =>
154
225
 
155
226
  const E = ERROR_CODES;
156
227
 
228
+ /**
229
+ * Why the math in a value's calc() cannot work, or null: each `+`/`-`
230
+ * needs two sides of one kind (a length with a length or a percentage, a
231
+ * number with a number), `*` needs a plain number on one side, `/` a plain
232
+ * number on the right. A var() counts as its fallback; one with none, or a
233
+ * nested min(), max() or clamp(), is not judged.
234
+ * @param {string} value
235
+ * @returns {string | null}
236
+ */
237
+ export function calcUnitProblem(value) {
238
+ const text = String(value);
239
+ const re = /\bcalc\(/gi;
240
+ let m;
241
+ while ((m = re.exec(text))) {
242
+ const open = m.index + m[0].length - 1;
243
+ const close = matchingParen(text, open);
244
+ if (close < 0) return null;
245
+ let expr = text.slice(open + 1, close);
246
+ // Each var() is its fallback, innermost first.
247
+ for (let i = 0; i < 20 && /\bvar\(/i.test(expr); i += 1) {
248
+ const at = expr.search(/\bvar\((?:[^()]|\([^()]*\))*\)/i);
249
+ const v = /\bvar\(((?:[^()]|\([^()]*\))*)\)/i.exec(expr.slice(at));
250
+ if (at < 0 || !v) return null;
251
+ const comma = v[1].indexOf(',');
252
+ if (comma < 0) return null;
253
+ expr = `${expr.slice(0, at)}(${v[1].slice(comma + 1).trim()})${expr.slice(at + v[0].length)}`;
254
+ }
255
+ if (/[a-z-]+\(/i.test(expr.replace(/\bcalc\(/gi, '('))) continue;
256
+ const found = expr.match(/\d*\.?\d+(?:e[+-]?\d+)?[a-z%]*|[-+*/()]/gi);
257
+ if (!found) continue;
258
+ const tokens = found;
259
+ let pos = 0;
260
+ /** @returns {string | null} */
261
+ const kindOf = (/** @type {string} */ t) => {
262
+ const u = /[a-z%]*$/i.exec(t)?.[0].toLowerCase() ?? '';
263
+ if (!u) return 'number';
264
+ if (u === '%') return 'percent';
265
+ if (/^(m?s)$/.test(u)) return 'time';
266
+ if (/^(deg|rad|grad|turn)$/.test(u)) return 'angle';
267
+ return 'length';
268
+ };
269
+ /** @type {string | null} */
270
+ let why = null;
271
+ const fail = (/** @type {string} */ w) => {
272
+ why ??= w;
273
+ return 'number';
274
+ };
275
+ const join = (
276
+ /** @type {string} */ a,
277
+ /** @type {string} */ b,
278
+ /** @type {string} */ op,
279
+ ) => {
280
+ if (op === '+' || op === '-') {
281
+ if (a === b) return a;
282
+ const lp = new Set([a, b]);
283
+ if (lp.has('length') && lp.has('percent') && lp.size === 2)
284
+ return 'length';
285
+ return fail(`${a} ${op} ${b} adds two kinds of value`);
286
+ }
287
+ if (op === '*') {
288
+ if (a === 'number') return b;
289
+ if (b === 'number') return a;
290
+ return fail(`${a} * ${b} multiplies two values with units`);
291
+ }
292
+ if (b === 'number') return a;
293
+ return fail(`${a} / ${b} divides by a value with a unit`);
294
+ };
295
+ /** @returns {string} */
296
+ const factor = () => {
297
+ const t = tokens[pos++];
298
+ if (t === '(') {
299
+ const k = sum();
300
+ pos++;
301
+ return k;
302
+ }
303
+ if (t === '-' || t === '+') return factor();
304
+ return t == null ? 'number' : (kindOf(t) ?? 'number');
305
+ };
306
+ /** @returns {string} */
307
+ const product = () => {
308
+ let k = factor();
309
+ while (tokens[pos] === '*' || tokens[pos] === '/') {
310
+ const op = tokens[pos++];
311
+ k = join(k, factor(), op);
312
+ }
313
+ return k;
314
+ };
315
+ /** @returns {string} */
316
+ function sum() {
317
+ let k = product();
318
+ while (tokens[pos] === '+' || tokens[pos] === '-') {
319
+ const op = tokens[pos++];
320
+ k = join(k, product(), op);
321
+ }
322
+ return k;
323
+ }
324
+ sum();
325
+ if (why) return why;
326
+ }
327
+ return null;
328
+ }
329
+
157
330
  /**
158
331
  * The fallbacks of the var() calls inside a value that is not one var()
159
332
  * alone (`calc(var(--x, 4px) * 2)`), in order. A var() with an empty
@@ -227,6 +400,25 @@ function matchingParen(text, open) {
227
400
  return -1;
228
401
  }
229
402
 
403
+ /** A yes or no word, which `rounded` reads as round or square. */
404
+ const YES_NO = /^(true|yes|on|none|false|off|no)$/i;
405
+
406
+ /**
407
+ * A value as the corners dial reads it: a rung in any case, or a size with
408
+ * its unit (`10PX`, `1rem`) in px; null for anything else, a bare number
409
+ * included.
410
+ * @param {string} v
411
+ * @returns {string | null}
412
+ */
413
+ function cornersRead(v) {
414
+ const lower = String(v).trim().toLowerCase();
415
+ if (CORNERS.some(([n]) => n === lower)) return lower;
416
+ if (/^(0|none|sharp|zero|flat)$/.test(lower)) return 'square';
417
+ if (/^[+-]?\d*\.?\d+$/.test(lower)) return null;
418
+ const px = lengthPx(lower);
419
+ return px != null && px >= 0 ? `${Math.round(px * 100) / 100}px` : null;
420
+ }
421
+
230
422
  /**
231
423
  * A text size written another way (20px, 2e1, +20, 1.25rem, 125%, `20 px`,
232
424
  * `1,25rem`) as the body size in pixels text-size takes, kept to its 10 to
@@ -235,13 +427,55 @@ function matchingParen(text, open) {
235
427
  * @returns {number | null}
236
428
  */
237
429
  function textSizePx(v) {
238
- const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/i.exec(
239
- typedPlain(v)
240
- .replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
241
- .replace(/\s+/g, '')
242
- .replace(/^(\d+),(\d+)/, '$1.$2'),
430
+ // Paste debris around the size (quotes, `!important`, a trailing `;` or
431
+ // `,`) is not part of it.
432
+ const bare = withoutDebris(
433
+ String(v)
434
+ .replace(/^\s*(["'])(.*)\1\s*$/, '$2')
435
+ .replace(/\s*!\s*important\s*/i, '')
436
+ .replace(/[;,]+\s*$/, ''),
243
437
  );
438
+ const plain = typedPlain(bare)
439
+ .replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
440
+ // A unit split off by a space (`16 px`), and the spaces of a math
441
+ // function (`calc(1rem + 2px)`); two numbers stay two.
442
+ .replace(/(\d)\s+(?=[a-z%])/gi, '$1')
443
+ .replace(/\s*([*/+()-])\s*/g, '$1')
444
+ .replace(/^(\d+),(\d+)/, '$1.$2');
445
+ // A constant calc() of px and rem sizes (`calc(16px + 2px)`) is worked out.
446
+ const calc =
447
+ /^calc\((\d*\.?\d+)(px|rem|em)?([*/+-])(\d*\.?\d+)(px|rem|em)?\)$/i.exec(
448
+ plain,
449
+ );
450
+ if (calc) {
451
+ const px = (/** @type {string} */ n, /** @type {string | undefined} */ u) =>
452
+ Number(n) * (u && /r?em/i.test(u) ? 16 : 1);
453
+ const [a, b] = [px(calc[1], calc[2]), px(calc[4], calc[5])];
454
+ const op = calc[3];
455
+ // Sizes add and subtract; a size scales by a plain number.
456
+ const r =
457
+ op === '+' || op === '-'
458
+ ? calc[2] && calc[5]
459
+ ? op === '+'
460
+ ? a + b
461
+ : a - b
462
+ : null
463
+ : op === '*'
464
+ ? calc[2] && calc[5]
465
+ ? null
466
+ : a * b
467
+ : calc[5]
468
+ ? null
469
+ : a / b;
470
+ return r != null && Number.isFinite(r) && r >= 10 && r <= 32
471
+ ? Math.round(r * 100) / 100
472
+ : null;
473
+ }
474
+ const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/i.exec(plain);
244
475
  if (!m) return null;
476
+ // A bare number under 4 (1.5, 1.125) reads as rem as much as px: no
477
+ // size is guessed for it.
478
+ if (!m[2] && Number(m[1]) < 4) return null;
245
479
  const unit = (m[2] ?? '').toLowerCase();
246
480
  const n =
247
481
  Number(m[1]) *
@@ -334,6 +568,8 @@ function valueMeant(type, value) {
334
568
  .replace(/\s*!\s*important\s*$/i, '')
335
569
  .replace(/;+\s*$/, '')
336
570
  .trim();
571
+ // Copy debris around it (a trailing comma, a stray quote or bracket).
572
+ p = withoutDebris(p).trim();
337
573
  const q = /^(["'])(.*)\1$/.exec(p);
338
574
  if (q && type !== 'font') p = q[2].trim();
339
575
  const out = [p];
@@ -344,13 +580,14 @@ function valueMeant(type, value) {
344
580
  if (type === 'font' || type === 'font-family') {
345
581
  // A comma left out between families (`"Open Sans" serif`), read with
346
582
  // css-tree.
583
+ // The stack read as families (a trailing comma, a stack wrapped in one
584
+ // more pair of quotes), each quoted as CSS needs it.
585
+ const fams = familiesOf(p);
586
+ // A number or size is no family: never quoted into one (`"700"`).
587
+ if (fams?.length && !fams.some(f => NUMBERISH.test(f)))
588
+ out.push(fams.map(f => cssFamily(f, true)).join(', '));
347
589
  const listed = familyListMeant(p);
348
- if (listed) out.push(listed);
349
- // Each family quoted as CSS needs it, only when no family holds a
350
- // quote inside (the pieces are whole names).
351
- const pieces = p.split(',').map(f => f.trim().replace(/^["']|["']$/g, ''));
352
- if (!listed && pieces.every(f => !/["'\\]/.test(f)))
353
- out.push(pieces.map(f => cssFamily(f, true)).join(', '));
590
+ if (listed && !fams?.length) out.push(listed);
354
591
  }
355
592
  return [...new Set(out)].filter(x => x && x !== value.trim());
356
593
  }
@@ -391,8 +628,12 @@ function sizeMeant(v, ok) {
391
628
  n,
392
629
  n.replace(/(\d)\.(?=[a-z%]|$)/gi, '$1'),
393
630
  t.replace(/(\d)\.(?=[a-z%]|$)/gi, '$1'),
394
- t.replace(/\s+/g, ''),
395
- t.replace(/^([+-]?\d+),(\d+)/, '$1.$2').replace(/\s+/g, ''),
631
+ // A unit split off by a space (`16 px`); two numbers (`12 16px`) are
632
+ // never joined into one.
633
+ t.replace(/(\d)\s+(?=[a-z%])/gi, '$1'),
634
+ t
635
+ .replace(/^([+-]?\d+),(\d+)/, '$1.$2')
636
+ .replace(/(\d)\s+(?=[a-z%])/gi, '$1'),
396
637
  mathSpaced(t),
397
638
  ];
398
639
  const m = /^([+-]?\d*\.?\d+)\s*([a-z%]+)$/i.exec(
@@ -430,7 +671,7 @@ function mathSpaced(v) {
430
671
  function numberMeant(v, name, ok) {
431
672
  const t = v.trim();
432
673
  const plain = typedPlain(t).replace(/(\d)\.$/, '$1');
433
- const comma = plain.replace(/^([+-]?\d+),(\d+)/, '$1.$2');
674
+ const comma = commaNumbers(plain, weightSetting(name));
434
675
  const tries = [
435
676
  /^[\doO.]+$/.test(plain) && /\d/.test(plain)
436
677
  ? plain.replace(/[oO]/g, '0')
@@ -590,6 +831,22 @@ export function storedProblems(ctx, slug, data, skip = '') {
590
831
  return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
591
832
  if (s.mode && s.source === 'dial' && !PALETTE_DIALS.includes(s.thing))
592
833
  return scope(`${s.thing} is the same in light and dark`);
834
+ // A light and a dark pair saved for one mode (a hand edit): set
835
+ // refuses that, so the loader does too; the repair is the half saved
836
+ // for that mode.
837
+ if (s.mode && /^\s*light-dark\(/i.test(String(s.value ?? ''))) {
838
+ const pair = colorPair(
839
+ String(s.value)
840
+ .trim()
841
+ .replace(/^light-dark\(\s*([\s\S]*)\)\s*$/i, 'light: $1')
842
+ .replace(/,\s*/, '; dark: '),
843
+ );
844
+ return {
845
+ setting: s,
846
+ why: `${s.thing} gives both modes with light-dark(), and is saved for ${s.mode} only`,
847
+ ...(pair ? {fix: s.mode === 'dark' ? pair.dark : pair.light} : {}),
848
+ };
849
+ }
593
850
  if (t && s.state && ![...t.states, ...COMMON_STATES].includes(s.state))
594
851
  return scope(`"${s.state}" is not a state of ${s.on}`);
595
852
  if (t && s.when) {
@@ -648,13 +905,45 @@ export function storedProblems(ctx, slug, data, skip = '') {
648
905
  // it.
649
906
  for (const s of data.settings) {
650
907
  if (replaced(s) || typeof s.value !== 'string') continue;
651
- const clean = normalValueText(s.value);
652
- if (clean !== s.value)
908
+ // Read as typed input is (a font family's quotes trimmed too), so the
909
+ // line offered is the value set would save.
910
+ const clean = /font/i.test(s.thing)
911
+ ? trimInsideQuotes(normalValueText(s.value))
912
+ : normalValueText(s.value);
913
+ if (clean !== s.value) {
914
+ // Name what is wrong: invisible spaces, or quotes around the value
915
+ // CSS does not read (a curly quote inside a quoted string is fine,
916
+ // and is left as it is).
917
+ const spaces =
918
+ clean.replace(/["']/g, '') !==
919
+ s.value.replace(
920
+ /[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`"']/g,
921
+ '',
922
+ );
923
+ const quotes =
924
+ /[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`]/.test(
925
+ s.value,
926
+ ) &&
927
+ clean.replace(
928
+ /[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
929
+ '',
930
+ ) !==
931
+ s.value.replace(
932
+ /[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
933
+ '',
934
+ );
935
+ const why = [
936
+ spaces &&
937
+ 'a no-break, thin or zero-width space, which the browser does not read as a space',
938
+ quotes &&
939
+ 'curly or other quotes around a value, where CSS reads only straight ones',
940
+ ].filter(Boolean);
653
941
  found.push({
654
942
  setting: s,
655
- why: `${s.thing} holds a no-break, thin or zero-width space, which the browser does not read as a space`,
943
+ why: `${s.thing} holds ${why.join(', and ') || 'characters the browser does not read as written'}`,
656
944
  fix: clean,
657
945
  });
946
+ }
658
947
  }
659
948
  for (const s of data.settings) {
660
949
  if (s.source !== 'token' || s.thing === skipThing || !(s.thing in TOKENS))
@@ -700,6 +989,379 @@ export function storedProblems(ctx, slug, data, skip = '') {
700
989
  return found;
701
990
  }
702
991
 
992
+ /** The generic families a font list ends with. */
993
+ const GENERIC_FAMILIES = [
994
+ 'serif',
995
+ 'sans-serif',
996
+ 'monospace',
997
+ 'system-ui',
998
+ 'cursive',
999
+ 'fantasy',
1000
+ 'ui-serif',
1001
+ 'ui-sans-serif',
1002
+ 'ui-monospace',
1003
+ 'ui-rounded',
1004
+ ];
1005
+ documentTypoWords(GENERIC_FAMILIES);
1006
+ documentTypoWords([...Object.keys(FONTS), ...Object.keys(OPEN_FONTS)]);
1007
+
1008
+ /** The theme-wide dial or token for a CSS property typed with no part. */
1009
+ const WHOLE_THEME_EQUIVALENT = /** @type {Record<string, string>} */ ({
1010
+ 'border-radius': 'corners',
1011
+ 'font-size': 'text-size',
1012
+ 'font-family': 'font',
1013
+ color: '--color-text-primary',
1014
+ background: '--color-background-body',
1015
+ 'background-color': '--color-background-body',
1016
+ });
1017
+
1018
+ /** A number or a size, which is never a font family. */
1019
+ const NUMBERISH = /^[+-]?(\d+\.?\d*|\.\d+)(px|rem|em|pt|%)?$/i;
1020
+
1021
+ /**
1022
+ * What is wrong with a typed family list, or null. Each family of the list
1023
+ * is read on its own, from its end:
1024
+ * - a size (`18px`, `Inter 16px`) is no family; a number is a weight only
1025
+ * as a whole hundred (100 to 1000), and any other bare number
1026
+ * (`Lato, 16`) is neither a weight nor a family;
1027
+ * - a weight (`600`, `ExtraBold`, `extra bold`, any form the weight table
1028
+ * reads) or a style (`Italic`, `Oblique`) after a family's name is that
1029
+ * family and the weight or style; a weight or style WORD is part of the
1030
+ * name unless the whole name is no family the editor knows and the name
1031
+ * without it is (knownFamily: `Arial Black` and `Segoe UI Semibold` are
1032
+ * families; `Inter ExtraBold` and `Inter Italic` are Inter and a word);
1033
+ * - a generic in quotes (`'sans-serif'`) is a family named so, and a
1034
+ * family the editor does not know that is a typo of a generic
1035
+ * (`sansserif`, `serf`, `system ui`) is that generic;
1036
+ * - with `presets` (the font dial), a lone family that is a typo of a
1037
+ * preset (`sytem`, `robto`) is that preset.
1038
+ * Only weight, style and size words (`16px bold`, `italic bold`) are a font
1039
+ * shorthand, read where the font dial reads one: null. `families` is the
1040
+ * list meant (empty when no family is left), `rung` the headings weight
1041
+ * nearest a weight given, `textSize` the text-size a size reads as, and
1042
+ * `style` a style given.
1043
+ * @param {string} value
1044
+ * @param {any} ctx
1045
+ * @param {boolean} [presets] whether a preset name is read (the font dial)
1046
+ * @returns {{why: string, families: string, asTyped: string | null, rung: string | null, size: boolean, textSize: number | null, style: string | null} | null}
1047
+ */
1048
+ function fontListProblem(value, ctx, presets = false) {
1049
+ // Copy debris (a trailing `;`, `!important`, a comment) is read away
1050
+ // first, as it is for any value.
1051
+ const pieces = familyPieces(withoutCopyDebris(pastedFont(value) ?? value));
1052
+ if (!pieces) return null;
1053
+ const weightOf = (/** @type {string} */ w) => {
1054
+ const k = w.toLowerCase().replace(/[\s_-]+/g, '');
1055
+ // A weight number is a whole hundred (Source Serif 4 is a family).
1056
+ return /^\d{3,4}$/.test(k) && Number(k) % 100 === 0 && Number(k) <= 1000
1057
+ ? Number(k)
1058
+ : HEADING_WEIGHTS[k] !== undefined
1059
+ ? Number(HEADING_WEIGHTS[k])
1060
+ : WEIGHT_WORDS[k] !== undefined
1061
+ ? Number(WEIGHT_WORDS[k])
1062
+ : null;
1063
+ };
1064
+ const STYLE = /^(italic|oblique)$/i;
1065
+ const bare = (/** @type {string} */ w) =>
1066
+ w.toLowerCase().replace(/[\s_-]+/g, '');
1067
+ /** The generic a family the editor does not know is a typo of. */
1068
+ const genericOf = (/** @type {string} */ name) => {
1069
+ // Written with no dash or a space (sansserif, system ui): that generic.
1070
+ const exact = GENERIC_FAMILIES.find(g => bare(g) === bare(name));
1071
+ if (exact) return exact;
1072
+ const hits = GENERIC_FAMILIES.filter(g => typoNear(name.toLowerCase(), g));
1073
+ return hits.length === 1 ? hits[0] : null;
1074
+ };
1075
+
1076
+ /** @type {string[]} */
1077
+ const kept = [];
1078
+ /**
1079
+ * Each family read as a misspelling, as typed in quotes: quotes keep a
1080
+ * family the editor does not know as written (Inder, Monaspace).
1081
+ * @type {Map<number, string>}
1082
+ */
1083
+ const asTyped = new Map();
1084
+ /** @type {number | null} */
1085
+ let weight = null;
1086
+ let number = false;
1087
+ let size = false;
1088
+ /** @type {string | null} */
1089
+ let sizeTyped = null;
1090
+ /** @type {string | null} */
1091
+ let style = null;
1092
+ let quotedGeneric = false;
1093
+ let misspelled = false;
1094
+ for (const p of pieces) {
1095
+ const name = p.name.trim();
1096
+ if (!name) continue;
1097
+ if (p.quoted) {
1098
+ if (GENERIC_FAMILIES.includes(name.toLowerCase())) {
1099
+ quotedGeneric = true;
1100
+ kept.push(name.toLowerCase());
1101
+ } else kept.push(/[^a-z0-9-]/i.test(name) ? JSON.stringify(name) : name);
1102
+ continue;
1103
+ }
1104
+ // A number or size alone is read where the setting reads one (a
1105
+ // size for text-size, a weight for headings); in a list of several it
1106
+ // is a family that is not one.
1107
+ if (NUMBERISH.test(name)) {
1108
+ if (pieces.length < 2) return null;
1109
+ if (/[a-z%]$/i.test(name)) {
1110
+ size = true;
1111
+ sizeTyped ??= name;
1112
+ } else if (weightOf(name) != null) weight ??= weightOf(name);
1113
+ else number = true;
1114
+ continue;
1115
+ }
1116
+ // A preset named by its key on the font dial (dm-sans, mono) is that
1117
+ // preset.
1118
+ const PRESETS = [...Object.keys(FONTS), ...Object.keys(OPEN_FONTS)];
1119
+ if (presets && PRESETS.includes(name.toLowerCase())) {
1120
+ kept.push(name);
1121
+ continue;
1122
+ }
1123
+ // A family the editor knows is that family, whatever its last word
1124
+ // (Arial Black, Source Serif 4).
1125
+ if (knownFamily(ctx, name)) {
1126
+ kept.push(name);
1127
+ continue;
1128
+ }
1129
+ // Weight, style, size and number words after the name, read from the
1130
+ // end; a weight of two words (extra bold) first.
1131
+ const words = name.split(/\s+/);
1132
+ let end = words.length;
1133
+ /** @type {Array<{kind: string, text: string, value?: number}>} */
1134
+ const tail = [];
1135
+ while (end > 0) {
1136
+ // A known family before the words read so far keeps its own last
1137
+ // word (Arial Black 900 is Arial Black and 900).
1138
+ if (end < words.length && knownFamily(ctx, words.slice(0, end).join(' ')))
1139
+ break;
1140
+ const two =
1141
+ end >= 2 ? weightOf(words.slice(end - 2, end).join('')) : null;
1142
+ const w = words[end - 1];
1143
+ if (two != null && end >= 3) {
1144
+ tail.unshift({
1145
+ kind: 'weight',
1146
+ text: words.slice(end - 2, end).join(' '),
1147
+ value: two,
1148
+ });
1149
+ end -= 2;
1150
+ } else if (STYLE.test(w)) {
1151
+ tail.unshift({kind: 'style', text: w.toLowerCase()});
1152
+ end -= 1;
1153
+ } else if (weightOf(w) != null) {
1154
+ tail.unshift({
1155
+ kind: 'weight',
1156
+ text: w,
1157
+ value: /** @type {number} */ (weightOf(w)),
1158
+ });
1159
+ end -= 1;
1160
+ } else if (NUMBERISH.test(w) && /[a-z%]$/i.test(w)) {
1161
+ tail.unshift({kind: 'size', text: w});
1162
+ end -= 1;
1163
+ // A bare number that is no weight is part of the name (Source Sans
1164
+ // 3); only a separate list item is a number that is no family.
1165
+ } else break;
1166
+ }
1167
+ const base = words.slice(0, end).join(' ');
1168
+ // Only those words: alone, a font shorthand (read where the font dial
1169
+ // reads one); in a list of several, an item that is no family.
1170
+ if (!base) {
1171
+ if (pieces.length < 2) return null;
1172
+ for (const t of tail) {
1173
+ if (t.kind === 'weight') weight ??= t.value ?? null;
1174
+ else if (t.kind === 'style') style ??= t.text;
1175
+ else if (t.kind === 'size') {
1176
+ size = true;
1177
+ sizeTyped ??= t.text;
1178
+ }
1179
+ }
1180
+ continue;
1181
+ }
1182
+ if (!tail.length) {
1183
+ // A family the editor does not know that is a typo of a generic, or
1184
+ // (on the font dial, alone) of a preset: that name.
1185
+ const generic = genericOf(name);
1186
+ const preset =
1187
+ presets && pieces.length === 1 && !generic
1188
+ ? (() => {
1189
+ const hits = PRESETS.filter(k => typoNear(bare(name), bare(k)));
1190
+ return hits.length === 1 ? hits[0] : null;
1191
+ })()
1192
+ : null;
1193
+ if (generic || preset) {
1194
+ misspelled = true;
1195
+ kept.push(/** @type {string} */ (generic ?? preset));
1196
+ asTyped.set(kept.length - 1, JSON.stringify(name));
1197
+ } else kept.push(name);
1198
+ continue;
1199
+ }
1200
+ // Words only (no number or size): part of the name unless the whole
1201
+ // name is unknown and the name without them is known.
1202
+ if (
1203
+ tail.every(
1204
+ t =>
1205
+ t.kind === 'style' || (t.kind === 'weight' && !/^\d+$/.test(t.text)),
1206
+ ) &&
1207
+ !(!knownFamily(ctx, name) && knownFamily(ctx, base))
1208
+ ) {
1209
+ kept.push(name);
1210
+ continue;
1211
+ }
1212
+ for (const t of tail) {
1213
+ if (t.kind === 'weight') weight ??= t.value ?? null;
1214
+ else if (t.kind === 'style') style ??= t.text;
1215
+ else if (t.kind === 'size') {
1216
+ size = true;
1217
+ sizeTyped ??= t.text;
1218
+ } else number = true;
1219
+ }
1220
+ kept.push(base);
1221
+ }
1222
+ if (
1223
+ weight == null &&
1224
+ !size &&
1225
+ !style &&
1226
+ !number &&
1227
+ !quotedGeneric &&
1228
+ !misspelled
1229
+ )
1230
+ return null;
1231
+ const rung =
1232
+ weight != null
1233
+ ? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
1234
+ Math.abs(Number(b[1]) - weight) < Math.abs(Number(a[1]) - weight)
1235
+ ? b
1236
+ : a,
1237
+ )[0]
1238
+ : null;
1239
+ return {
1240
+ why:
1241
+ weight != null
1242
+ ? 'holds a weight where a family goes, so the browser reads it as a family named that and falls back'
1243
+ : size
1244
+ ? 'holds a size where a family goes, so the browser reads it as a family named that and falls back'
1245
+ : style
1246
+ ? 'holds a style where a family goes, so the browser reads it as a family named that and falls back'
1247
+ : number
1248
+ ? 'holds a number where a family goes (a weight is a whole hundred, a size has a unit), so the browser reads it as a family named that and falls back'
1249
+ : quotedGeneric
1250
+ ? 'quotes a generic family, which makes it a family named that, so there is no generic to fall back to'
1251
+ : 'is near a generic family or font the editor knows; a family the editor does not know is kept as written when it is quoted',
1252
+ families: kept.join(', '),
1253
+ asTyped: misspelled
1254
+ ? kept.map((k, i) => asTyped.get(i) ?? k).join(', ')
1255
+ : null,
1256
+ rung,
1257
+ size,
1258
+ textSize: sizeTyped ? textSizePx(sizeTyped) : null,
1259
+ style,
1260
+ };
1261
+ }
1262
+
1263
+ /**
1264
+ * A mode's label before a value, in any spelling: `dark mode:`, `darkmode:`,
1265
+ * `dark-mode:`, `mode dark:` (group 1 or 2 the mode, group 3 the value).
1266
+ */
1267
+ const MODE_LABEL =
1268
+ /^\s*\{?\s*["']?(?:(light|dark)[\s_-]*mode|mode[\s_-]*(light|dark))["']?\s*[:=]\s*(.+?)\s*;?\s*\}?\s*$/i;
1269
+
1270
+ /**
1271
+ * The font list a value with a missing comma or a spaced generic means
1272
+ * (`Georgia serif` is `Georgia, serif`, `Inter, sans serif` is `Inter,
1273
+ * sans-serif`), with why; null when it has neither. A generic is read only
1274
+ * in lower case, so a family named `Source Serif` stays one name.
1275
+ * @param {string} value
1276
+ * @returns {{value: string, why: string} | null}
1277
+ */
1278
+ export function fontListMeant(value) {
1279
+ const v = String(value).trim();
1280
+ // A whole list in one pair of quotes or brackets (`"Inter, serif"`,
1281
+ // `「Inter, serif」`): the quotes go around one family, so the list is
1282
+ // what is inside.
1283
+ const wrapped =
1284
+ /^(?:"([^"]*,[^"]*)"|'([^']*,[^']*)'|「([^」]*,[^」]*)」|『([^』]*,[^』]*)』|“([^”]*,[^”]*)”|‘([^’]*,[^’]*)’|«([^»]*,[^»]*)»)$/.exec(
1285
+ v,
1286
+ );
1287
+ if (wrapped) {
1288
+ const inside = wrapped.slice(1).find(x => x != null) ?? '';
1289
+ return {
1290
+ value: (fontListMeant(inside)?.value ?? inside).trim(),
1291
+ why: 'quotes go around one family name, not the whole list',
1292
+ };
1293
+ }
1294
+ if (/["']/.test(v)) return null;
1295
+ // Families split by `|`, `;` or ` / ` instead of commas.
1296
+ if (
1297
+ // (A pasted declaration, `font-family: Georgia, serif;`, is read
1298
+ // elsewhere: a colon or a trailing `;` is no separator.)
1299
+ !/:|\.(woff2?|ttf|otf)\b/i.test(v) &&
1300
+ /\S\s*(?:\||;|\s\/\s)\s*\S/.test(v)
1301
+ ) {
1302
+ const list = v
1303
+ .split(/\s*(?:\||;|\s\/\s)\s*/)
1304
+ .map(x => x.trim())
1305
+ .filter(Boolean)
1306
+ .join(', ');
1307
+ if (list && list !== v)
1308
+ return {
1309
+ value: fontListMeant(list)?.value ?? list,
1310
+ why: 'families are separated by commas',
1311
+ };
1312
+ }
1313
+ if (/\bsans serif\b/.test(v) && !/\d/.test(v))
1314
+ return {
1315
+ value: v.replace(/\bsans serif\b/g, 'sans-serif'),
1316
+ why: 'the generic family is sans-serif, with a dash',
1317
+ };
1318
+ // A comma missing before the generic family of any family in the list
1319
+ // (`Inter, Georgia serif`), the names in any case (`georgia serif`).
1320
+ const SHORTHAND =
1321
+ /^(\d+(\.\d+)?(px|rem|em|pt|%)?|bold|bolder|lighter|normal|italic|oblique|small-caps)$/i;
1322
+ // A word of a family name: letters (a digit after the first word, as in
1323
+ // `Source Serif 4`), or a generic; never a shorthand's weight or size.
1324
+ const familyWord = (/** @type {string} */ w, /** @type {number} */ i) =>
1325
+ (/^[A-Za-z][A-Za-z0-9]*$/.test(w) && !SHORTHAND.test(w)) ||
1326
+ (i > 0 && /^\d+$/.test(w)) ||
1327
+ GENERIC_FAMILIES.includes(w);
1328
+ const pieces = v.split(/\s*,\s*/);
1329
+ let missing = false;
1330
+ const fixedPieces = pieces.map(piece => {
1331
+ const ws = piece.split(/\s+/);
1332
+ const end = ws[ws.length - 1];
1333
+ if (
1334
+ ws.length > 1 &&
1335
+ GENERIC_FAMILIES.includes(end) &&
1336
+ ws.slice(0, -1).every(familyWord)
1337
+ ) {
1338
+ missing = true;
1339
+ return `${ws.slice(0, -1).join(' ')}, ${end}`;
1340
+ }
1341
+ return piece;
1342
+ });
1343
+ if (missing && pieces.length > 1)
1344
+ return {
1345
+ value: fixedPieces.join(', '),
1346
+ why: 'a comma goes before each generic family',
1347
+ };
1348
+ if (v.includes(',')) return null;
1349
+ const words = v.split(/\s+/);
1350
+ const last = words[words.length - 1];
1351
+ // Only family names before it (capitalized words), never a font
1352
+ // shorthand's weight, style or size.
1353
+ if (
1354
+ words.length > 1 &&
1355
+ GENERIC_FAMILIES.includes(last) &&
1356
+ words.slice(0, -1).every(familyWord)
1357
+ )
1358
+ return {
1359
+ value: `${words.slice(0, -1).join(' ')}, ${last}`,
1360
+ why: `a comma goes before the generic family ${last}`,
1361
+ };
1362
+ return null;
1363
+ }
1364
+
703
1365
  /**
704
1366
  * A value of a type to put in a suggestion, so a suggested command runs.
705
1367
  * @param {string} type
@@ -739,6 +1401,8 @@ function groupOfPropType(prop) {
739
1401
  * @param {string} slug
740
1402
  * @param {string[]} [readers] the CSS properties that read the token
741
1403
  * @param {boolean} [multiplied] whether Core multiplies the token by a size
1404
+ * @param {boolean} [isSet] whether the theme sets the token now (an undo
1405
+ * of it works)
742
1406
  */
743
1407
  function checkTypedValue(
744
1408
  type,
@@ -749,6 +1413,7 @@ function checkTypedValue(
749
1413
  slug,
750
1414
  readers = [],
751
1415
  multiplied = false,
1416
+ isSet = true,
752
1417
  ) {
753
1418
  // The value meant, when what is wrong is how it was typed (a trailing
754
1419
  // `;`, a comment, quotes around it, full-width characters, a font name
@@ -772,17 +1437,37 @@ function checkTypedValue(
772
1437
  }
773
1438
  return null;
774
1439
  };
775
- /** @param {string} what @param {string} example */
1440
+ /** @param {string} what @param {string | null} example */
776
1441
  const bad = (what, example) =>
777
1442
  refuse(
778
1443
  E.ERR_THEME_BAD_VALUE,
779
1444
  `${name} is ${what}; "${value}" is not one.`,
780
1445
  {
1446
+ // Nothing read from the value (no example given): how, never a
1447
+ // stock value.
781
1448
  run: [
782
- `${P} set ${slug} ${name} ${quoteCommandArgument(meant() ?? example)}`,
1449
+ (meant() ?? example) == null
1450
+ ? `${HOW} ${name}`
1451
+ : `${P} set ${slug} ${name} ${quoteCommandArgument(String(meant() ?? example))}`,
783
1452
  ],
784
1453
  },
785
1454
  );
1455
+ // A font family list with a comma missing before a generic family
1456
+ // (`Georgia serif`), or a generic written with a space (`sans serif`): the
1457
+ // list meant.
1458
+ if (type === 'font') {
1459
+ const fixed = fontListMeant(value);
1460
+ if (fixed)
1461
+ refuse(
1462
+ E.ERR_THEME_BAD_VALUE,
1463
+ `"${value}" names a family that exists nowhere: ${fixed.why}.`,
1464
+ {
1465
+ run: [
1466
+ `${P} set ${slug} ${name} ${quoteCommandArgument(fixed.value)}`,
1467
+ ],
1468
+ },
1469
+ );
1470
+ }
786
1471
  // A font file or a link is no family name: never quoted into one.
787
1472
  if (type === 'font') {
788
1473
  const file = fontFileReason(pastedFont(value) || value);
@@ -792,6 +1477,18 @@ function checkTypedValue(
792
1477
  `${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
793
1478
  ],
794
1479
  });
1480
+ // An empty family (`""`, a trailing comma) or one quoted name holding
1481
+ // commas is a broken stack: the browser drops the fallback after it.
1482
+ const pieces = familyPieces(value);
1483
+ if (
1484
+ pieces &&
1485
+ (pieces.some(f => !f.name) ||
1486
+ pieces.some(f => f.quoted && f.name.includes(',')))
1487
+ )
1488
+ bad(
1489
+ 'a font family list with a name for each family',
1490
+ exampleOf(type, name),
1491
+ );
795
1492
  }
796
1493
  if (!isSafeValue(value))
797
1494
  refuse(
@@ -813,14 +1510,24 @@ function checkTypedValue(
813
1510
  if (keyword)
814
1511
  refuse(
815
1512
  E.ERR_THEME_BAD_VALUE,
816
- `"${keyword}" is a CSS keyword, not a value: on ${name} it leaves the token empty, so what reads it drops its style. Give a value such as ${exampleOf(type, name)}, or undo ${name} to go back to the base theme's.`,
1513
+ `"${keyword}" is a CSS keyword, not a value: on ${name} it leaves the token empty, so what reads it drops its style. Give a ${type} value${isSet ? `, or undo ${name} to go back to the base theme's` : ''}.`,
817
1514
  {
1515
+ // How for the token; the undo only when the theme sets it.
818
1516
  run: [
819
- `${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
820
- `${P} undo ${slug} ${name}`,
1517
+ `${HOW} ${name}`,
1518
+ ...(isSet ? [`${P} undo ${slug} ${name}`] : []),
821
1519
  ],
822
1520
  },
823
1521
  );
1522
+ // Math whose units cannot combine (`8 + 2px`, `0.5rem * 1px`, a var()
1523
+ // read as its fallback): the browser drops the whole value.
1524
+ const math = type === 'size' ? calcUnitProblem(value) : null;
1525
+ if (math)
1526
+ refuse(
1527
+ E.ERR_THEME_BAD_VALUE,
1528
+ `${name} is a ${type}; the calc() in "${value}" cannot be worked out: ${math} (with each var() at its fallback, as when the variable is unset), so the browser drops the value.`,
1529
+ {run: [`${HOW} ${name}`]},
1530
+ );
824
1531
  // A var() inside a larger value (calc, max, color-mix) has a fallback of
825
1532
  // the token's kind too, checked like a whole-value var().
826
1533
  if (type !== 'other')
@@ -834,6 +1541,16 @@ function checkTypedValue(
834
1541
  )
835
1542
  )
836
1543
  continue;
1544
+ // A factor in a size's math (`calc(0.75rem * var(--x, 1))`, as the
1545
+ // official themes write their type scale): a plain number there is
1546
+ // what multiplies the size.
1547
+ if (
1548
+ type === 'size' &&
1549
+ within.some(f => /^(calc|min|max|clamp)$/i.test(f)) &&
1550
+ /^[+-]?(\d+\.?\d*|\.\d+)$/.test(fallback.trim()) &&
1551
+ (/[*/]\s*var\(/i.test(value) || /var\([^()]*\)\s*[*/]/i.test(value))
1552
+ )
1553
+ continue;
837
1554
  if (fallback === '')
838
1555
  refuse(
839
1556
  E.ERR_THEME_BAD_VALUE,
@@ -896,26 +1613,22 @@ function checkTypedValue(
896
1613
  );
897
1614
  return;
898
1615
  }
899
- if (type === 'color' && !isFixedColor(value)) bad('a color', '#1f2937');
1616
+ if (type === 'color' && !isFixedColor(value)) bad('a color', null);
900
1617
  if (type === 'size' && !isSize(value, name)) {
901
- // With nothing to read from the value, the token's own default (a text
902
- // size stays readable), never one size for every token.
903
- // Followed through the tokens it reads (var(--font-size-base)).
904
- let own = String(TOKENS[name] ?? '').trim();
905
- for (let hop = 0; hop < 4; hop += 1) {
906
- const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(own)?.[1];
907
- if (!ref) break;
908
- own = String(TOKENS[ref] ?? '').trim();
909
- }
910
- const sizeExample =
911
- own && isSize(own, name) && !/var\(/.test(own) ? own : '6px';
1618
+ // The token's own default is never offered as a repair: only a size
1619
+ // read from the value typed.
1620
+ const sizeExample = null;
912
1621
  // The size meant, when one dot or sign is all that is wrong (1.px).
913
1622
  const meant = value.trim().replace(/(\d)\.(?=[a-z%]|$)/gi, '$1');
914
- // A bare number is the size in px.
915
- // A bare number is the size in px; a minus sign is dropped.
916
- const plain = value.trim().replace(/^-(?=\d|\.\d)/, '');
1623
+ // A bare number is the size in px; a minus sign is kept (a negative
1624
+ // size is refused, never offered as its positive).
1625
+ const plain = value.trim();
1626
+ // A bare number below one (a pasted `--radius: 0.5rem` that lost its
1627
+ // unit) has no unit to read it by: no size is guessed, as corners does.
917
1628
  const px = /^[+]?\d*\.?\d+(e[+-]?\d+)?$/i.test(plain)
918
- ? `${Number(plain)}px`
1629
+ ? Number(plain) > 0 && Number(plain) < 1
1630
+ ? null
1631
+ : `${Number(plain)}px`
919
1632
  : /^\d*\.?\d+[a-z%]+$/i.test(plain) && plain !== value.trim()
920
1633
  ? plain
921
1634
  : null;
@@ -1231,6 +1944,18 @@ function nearestColorName(v) {
1231
1944
  return nearest(w, COLOR_NAMES)[0] ?? null;
1232
1945
  }
1233
1946
 
1947
+ /**
1948
+ * Old keywords a property's grammar lists that no current browser applies,
1949
+ * each with the keyword that does what it meant.
1950
+ * @type {Record<string, Record<string, string>>}
1951
+ */
1952
+ const OBSOLETE_KEYWORDS = {
1953
+ cursor: {hand: 'pointer'},
1954
+ };
1955
+ documentReadings(
1956
+ Object.values(OBSOLETE_KEYWORDS).flatMap(words => Object.entries(words)),
1957
+ );
1958
+
1234
1959
  /**
1235
1960
  * Why a value is not one the property takes, or null. Colors are checked
1236
1961
  * by the editor's own color check; a property css-tree has no grammar for
@@ -1251,12 +1976,18 @@ function propertyProblem(prop, value) {
1251
1976
  takes: `a value its CSS grammar takes in each var() fallback too (${grammarText(known)})`,
1252
1977
  near: initialOf(prop),
1253
1978
  };
1979
+ // An old keyword the grammar still lists but no current browser
1980
+ // applies (`cursor: hand`): the keyword that does what it meant.
1981
+ const obsolete = OBSOLETE_KEYWORDS[prop]?.[v.toLowerCase()];
1982
+ if (obsolete)
1983
+ return {
1984
+ takes: `a value current browsers apply ("${v}" is an old keyword none applies; ${obsolete} does what it meant)`,
1985
+ near: obsolete,
1986
+ };
1254
1987
  if (matchValue(prop, v))
1255
1988
  return belowRange(prop, v)
1256
- ? {
1257
- takes: 'a value of 0 or more',
1258
- near: v.replace(/(^|[\s(,/])-(?=\.?\d)/g, '$1'),
1259
- }
1989
+ ? // A negative value is no size of the other sign: no line mirrors it.
1990
+ {takes: 'a value of 0 or more', near: null}
1260
1991
  : null;
1261
1992
  // The same value as it was meant to be typed (a font name quoted, a
1262
1993
  // trailing `;` gone), when the property takes that.
@@ -1281,9 +2012,7 @@ function propertyProblem(prop, value) {
1281
2012
  null)
1282
2013
  : null;
1283
2014
  // A value that works, for the suggestion: a keyword near the one typed,
1284
- // the property's initial value, or an example of its kind; each checked.
1285
- const example = exampleOf(groupOfPropType(prop), prop);
1286
- const initial = initialOf(prop);
2015
+ // or the value typed cleaned; each checked.
1287
2016
  // A bare number on a length property means px (`padding 4` → `4px`, each
1288
2017
  // number in a list too), when the property takes that.
1289
2018
  // Each bare number token gets px (a mixed list `4 8px`, `8 / 4`, an
@@ -1296,31 +2025,91 @@ function propertyProblem(prop, value) {
1296
2025
  Number(num) === 0 ? `${pre}${num}` : `${pre}${num}px`,
1297
2026
  )
1298
2027
  : null;
1299
- // A suggestion is offered only when the property takes it, in range too.
2028
+ // A suggestion is offered only when the property takes it, in range too,
2029
+ // and never a reset the input did not hold (0, none, 1, auto, normal):
2030
+ // following it would undo what was asked. A reset typed with a typo
2031
+ // (`nnone`, `normall`: a word within two edits of it) is that reset,
2032
+ // corrected.
2033
+ const RESETS =
2034
+ /^(0|0px|none|1|auto|normal|initial|unset|inherit|revert|transparent)$/i;
2035
+ const typedAs = (/** @type {string} */ x) => x === typed || typoOf(typed, x);
1300
2036
  const takes = (/** @type {string | null} */ x) =>
1301
- x != null && matchValue(prop, x) != null && !belowRange(prop, x);
2037
+ x != null &&
2038
+ matchValue(prop, x) != null &&
2039
+ !belowRange(prop, x) &&
2040
+ !(RESETS.test(x.trim()) && !typedAs(x.trim().toLowerCase()));
2041
+ // A lone length on a shorthand where it is only a position (background,
2042
+ // mask) wipes the rest: no px is guessed there.
2043
+ const pxFits = !/^(background|mask)$/i.test(prop);
2044
+ // Words with a documented reading on a property (the allowlist a repair
2045
+ // may map through).
2046
+ const WORDS = PROPERTY_WORDS;
2047
+ // A weight word is its number (the same table the headings dial reads);
2048
+ // text in content is that text, quoted.
2049
+ const weightWord = typed.replace(/[\s-]+/g, '');
2050
+ const weight = HEADING_WEIGHTS[weightWord] ?? WEIGHT_WORDS[weightWord];
2051
+ const mapped =
2052
+ WORDS[prop]?.[typed.replace(/\s+/g, '-')] ??
2053
+ (prop === 'font-weight' && weight ? weight : null) ??
2054
+ (prop === 'content' && !/^["']|["']$/.test(v) ? JSON.stringify(v) : null) ??
2055
+ null;
1302
2056
  return {
1303
2057
  takes: `a value its CSS grammar takes (${grammarText(known)})`,
1304
2058
  near:
1305
- (takes(withPx) ? withPx : null) ??
1306
- // Below the property's range (a negative width): the same, 0 or more.
1307
- (withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
1308
- ? withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1')
1309
- : null) ??
2059
+ (mapped && matchValue(prop, mapped) != null ? mapped : null) ??
2060
+ (pxFits && takes(withPx) ? withPx : null) ??
2061
+ // Below the property's range (a negative width) is no size of the
2062
+ // other sign: the mirrored value is never offered.
1310
2063
  (takes(joined) && joined !== v ? joined : null) ??
1311
- // Several values on a property that takes one (padding-top with four):
1312
- // the first of them, when it is one the property takes.
2064
+ // A comma between two bare numbers that the grammar pairs with a
2065
+ // slash (`aspect-ratio 16,9`, `grid-row 2,4`) separates them: the
2066
+ // pair, never a decimal (16.9).
2067
+ (() => {
2068
+ const pair = /^\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*$/.exec(v);
2069
+ return pair && takes(`${pair[1]} / ${pair[2]}`)
2070
+ ? `${pair[1]} / ${pair[2]}`
2071
+ : null;
2072
+ })() ??
2073
+ // A comma between digits is a decimal point (1,5rem is 1.5rem), never
2074
+ // a split into layers.
2075
+ (takes(commaNumbers(v, weightSetting(prop))) &&
2076
+ commaNumbers(v, weightSetting(prop)) !== v
2077
+ ? commaNumbers(v, weightSetting(prop))
2078
+ : null) ??
2079
+ // Several values of one kind on a property that takes one
2080
+ // (padding-top with four lengths): the first as typed, with px only
2081
+ // when the property takes no bare number. Never one value of a
2082
+ // shorthand of several kinds (`all 200` for transition). A property
2083
+ // whose grammar pairs them with a slash (`aspect-ratio 16 9`,
2084
+ // `grid-row 2 4`) takes the pair, never its first half.
1313
2085
  (() => {
1314
- const first = splitTop((withPx ?? joined).trim(), ' ')[0];
1315
- return first && first !== v && takes(first) ? first : null;
2086
+ const all = splitTop(v.trim(), ' ');
2087
+ const slashed = all.join(' / ');
2088
+ if (all.length === 2 && takes(slashed)) return slashed;
2089
+ if (all.length > 1 && takes(all.slice(0, 2).join(' / '))) return null;
2090
+ const same = sameKindValues(v);
2091
+ if (!same) return null;
2092
+ const first = same.items[0];
2093
+ const px = same.kind === '' ? `${first}px` : null;
2094
+ return takes(first) ? first : pxFits && px && takes(px) ? px : null;
1316
2095
  })() ??
1317
2096
  (near && takes(near) ? near : null) ??
1318
- // A value with numbers never falls back to the property's reset
1319
- // (padding 0 would remove what was asked for).
1320
- (/\d/.test(v)
1321
- ? null
1322
- : ((takes(initial) ? initial : null) ??
1323
- (takes(example) ? example : null))),
2097
+ // Layers typed with one too many or an empty one (`url(a.png), red,
2098
+ // blue`, `red,,blue`): the layers before the last, else one of them,
2099
+ // when the property takes it. Never the property's reset or a stock
2100
+ // example: a repair carries only what was typed.
2101
+ (() => {
2102
+ const layers = splitTop(v.trim(), ',')
2103
+ .map(x => x.trim())
2104
+ .filter(Boolean);
2105
+ if (layers.length < 2 && !/,\s*,/.test(v)) return null;
2106
+ const tries = [
2107
+ layers.join(', '),
2108
+ layers.slice(0, -1).join(', '),
2109
+ ...layers,
2110
+ ];
2111
+ return tries.find(x => x && x !== v && takes(x)) ?? null;
2112
+ })(),
1324
2113
  };
1325
2114
  }
1326
2115
 
@@ -1387,6 +2176,331 @@ function baseReads(ctx, like, token) {
1387
2176
  }
1388
2177
  }
1389
2178
 
2179
+ /**
2180
+ * The headings rung nearest a weight number (800 is heavy).
2181
+ * @param {number} weight
2182
+ */
2183
+ const weightRung = weight =>
2184
+ Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
2185
+ Math.abs(Number(b[1]) - weight) < Math.abs(Number(a[1]) - weight) ? b : a,
2186
+ )[0];
2187
+ documentNumericTable(
2188
+ ['headings', 'font-weight'],
2189
+ Object.entries(HEADING_WEIGHTS).map(([w, n]) => [w, Number(n)]),
2190
+ [1, 1000],
2191
+ );
2192
+ // A font weight runs from 1 to 1000.
2193
+ documentRange(['font-weight', '--font-weight-*'], 1, 1000);
2194
+ documentNumericTable(
2195
+ ['spacing'],
2196
+ SPACING.map(([name, factor]) => [name, factor]),
2197
+ );
2198
+ documentNumericTable(
2199
+ ['text-size'],
2200
+ TEXT_SIZE.map(([name, px]) => [name, px]),
2201
+ );
2202
+ // The text size number is the body size in pixels, 10 to 32; vibrancy
2203
+ // runs from 0 to 100.
2204
+ documentRange(['text-size'], 10, 32);
2205
+ documentRange(['vibrancy'], 0, 100);
2206
+ documentReadings(TEXT_SIZE.map(([name, px]) => [name, `${px}px`]));
2207
+ documentReadings(Object.entries(HEADING_TRACKING));
2208
+ // `bold` given a no (false, off) is the normal weight.
2209
+ documentReadings(['false', 'off', 'no', 'none'].map(w => [w, 'normal']));
2210
+ /**
2211
+ * The CSS absolute-size keywords that are no text-size rung, as the px
2212
+ * CSS gives each at a 16px root.
2213
+ */
2214
+ const CSS_SIZE_KEYWORDS = wordTable(
2215
+ /** @type {Record<string, number>} */ ({
2216
+ 'xx-small': 9,
2217
+ 'x-small': 10,
2218
+ 'x-large': 24,
2219
+ 'xx-large': 32,
2220
+ 'xxx-large': 48,
2221
+ }),
2222
+ );
2223
+ documentReadings(
2224
+ Object.entries(CSS_SIZE_KEYWORDS)
2225
+ .filter(([, px]) => px >= 10 && px <= 32)
2226
+ .map(([w, px]) => [w, String(px)]),
2227
+ );
2228
+ // A weight word read as the headings rung its number is nearest.
2229
+ documentReadings(
2230
+ Object.entries(WEIGHT_WORDS).map(([w, n]) => [w, weightRung(Number(n))]),
2231
+ );
2232
+ /** Words for no rounding: corners square. */
2233
+ const NO_ROUNDING = ['0', '0%', 'none', 'sharp', 'zero', 'no', 'flat'];
2234
+ /** Words for no space: spacing's tightest rung. */
2235
+ const NO_SPACE = ['0', 'none', 'zero', 'no', 'off'];
2236
+ documentReadings(NO_ROUNDING.map(w => [w, 'square']));
2237
+ documentReadings(NO_SPACE.map(w => [w, SPACING[0][0]]));
2238
+ documentReadings(
2239
+ Object.values(DIAL_WORDS).flatMap(words => Object.entries(words)),
2240
+ );
2241
+ /** State words a value may be labeled with. */
2242
+ const STATE_WORDS = [
2243
+ 'hover',
2244
+ 'active',
2245
+ 'focus',
2246
+ 'focus-visible',
2247
+ 'focus-within',
2248
+ 'disabled',
2249
+ 'pressed',
2250
+ 'selected',
2251
+ 'checked',
2252
+ 'open',
2253
+ 'expanded',
2254
+ 'visited',
2255
+ ];
2256
+ /** Words for a kind of screen a value may be labeled with. */
2257
+ const DEVICE_WORDS = [
2258
+ 'phone',
2259
+ 'phones',
2260
+ 'mobile',
2261
+ 'tablet',
2262
+ 'tablets',
2263
+ 'desktop',
2264
+ 'laptop',
2265
+ 'ipad',
2266
+ 'iphone',
2267
+ 'android',
2268
+ 'ios',
2269
+ 'touch',
2270
+ 'small-screen',
2271
+ 'small-screens',
2272
+ 'large-screen',
2273
+ 'large-screens',
2274
+ 'print',
2275
+ ];
2276
+
2277
+ /**
2278
+ * The word a value is labeled with and the value after it (`dark: #2563eb`,
2279
+ * `"corners": "pill"`, `{"dark": "#2563eb"}`, `dark=#2563eb`, `dark mode:
2280
+ * #2563eb`, `textSize: 18`), the word as a dashed name; null when the value
2281
+ * holds no label.
2282
+ * @param {string} value
2283
+ * @returns {{word: string, rest: string, when?: string} | null}
2284
+ */
2285
+ function valueLabel(value) {
2286
+ // A mode label in any spelling (`dark mode: red`, `darkmode: red`,
2287
+ // `mode dark: red`) is that mode's label: one reading, read first so the
2288
+ // value is never taken for the label.
2289
+ const modeLabel = MODE_LABEL.exec(String(value));
2290
+ if (modeLabel)
2291
+ return {
2292
+ word: (modeLabel[1] ?? modeLabel[2]).toLowerCase(),
2293
+ rest: modeLabel[3].trim(),
2294
+ };
2295
+ // A flag's label after the value (`red mode: dark`, `red state: hover`,
2296
+ // `red part: card`) reads as the same label before it (`dark: red`); a
2297
+ // variant or size after it (`red variant: primary`) keeps its prop.
2298
+ const trail =
2299
+ /^\s*(.+?)\s+(mode|theme|state|part|on|variant|size|when)\s*[:=]\s*([a-z][a-z0-9:-]*)\s*;?\s*$/i.exec(
2300
+ String(value),
2301
+ );
2302
+ if (trail && !/[:=]/.test(trail[1])) {
2303
+ const flag = trail[2].toLowerCase();
2304
+ const word = trail[3].toLowerCase();
2305
+ if (/^(variant|size|when)$/.test(flag))
2306
+ return {
2307
+ word: 'when',
2308
+ rest: trail[1].trim(),
2309
+ when: flag === 'when' ? word : `${flag}:${word}`,
2310
+ };
2311
+ return {word, rest: trail[1].trim()};
2312
+ }
2313
+ const m =
2314
+ /^\s*\{?\s*["']?([a-zA-Z][a-zA-Z0-9 _-]*?|--[a-z0-9-]+)["']?\s*[:=]\s*(.+?)\s*;?\s*\}?\s*$/.exec(
2315
+ String(value),
2316
+ );
2317
+ if (!m || /^https?$/i.test(m[1])) return null;
2318
+ const word = m[1]
2319
+ .trim()
2320
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
2321
+ .replace(/[\s_]+/g, '-')
2322
+ .toLowerCase();
2323
+ const rest = m[2].trim().replace(/^"(.*)"\s*,?$/, '$1');
2324
+ return {word, rest};
2325
+ }
2326
+
2327
+ /**
2328
+ * Whether a label is the setting's own name (`accent: red` for accent,
2329
+ * `font-family: Inter` for font).
2330
+ * @param {string} thing @param {string} word
2331
+ */
2332
+ const ownLabel = (thing, word) =>
2333
+ word === thing ||
2334
+ (thing === 'font' && word === 'font-family') ||
2335
+ (thing.startsWith('--font-family') &&
2336
+ (word === 'font-family' || word === 'font')) ||
2337
+ (thing === 'text-size' && word === 'font-size');
2338
+
2339
+ /**
2340
+ * Whether a family is one the editor knows: a system family on the theme
2341
+ * build's list, an open font in its table or a preset's family, or one
2342
+ * whose @fontsource package the project has installed.
2343
+ * @param {any} ctx
2344
+ * @param {string} family without quotes
2345
+ */
2346
+ function knownFamily(ctx, family) {
2347
+ const name = family.trim().toLowerCase();
2348
+ if (!name) return false;
2349
+ if (isSystemFamily(family)) return true;
2350
+ if (
2351
+ [
2352
+ ...Object.values(OPEN_FONTS).map(f => f.family),
2353
+ ...Object.values(FONTS).map(f => f[0]),
2354
+ ].some(f => f.toLowerCase() === name)
2355
+ )
2356
+ return true;
2357
+ try {
2358
+ ctx?.project?.req?.resolve(`${fontsourcePackageOf(family)}/package.json`);
2359
+ return Boolean(ctx?.project?.req);
2360
+ } catch {
2361
+ return false;
2362
+ }
2363
+ }
2364
+
2365
+ /**
2366
+ * The CSS properties a dial sets, whose pasted declaration is the dial's
2367
+ * own value (`border-radius: 8px` for corners, `color: #e11d48` for a
2368
+ * color dial). A dial with none takes no pasted property.
2369
+ * @type {Record<string, (word: string) => boolean>}
2370
+ */
2371
+ const DIAL_PROPERTIES = {
2372
+ corners: w => /^border(-[a-z]+)*-radius$/.test(w),
2373
+ spacing: w => /^(padding|margin|gap|row-gap|column-gap)(-[a-z]+)*$/.test(w),
2374
+ 'text-size': w => w === 'font-size',
2375
+ font: w => w === 'font' || w === 'font-family',
2376
+ headings: w => w === 'font-weight' || w === 'letter-spacing',
2377
+ ...Object.fromEntries(
2378
+ PALETTE_DIALS.map(d => [
2379
+ d,
2380
+ (/** @type {string} */ w) => w === 'background' || COLOR_PROPS.test(w),
2381
+ ]),
2382
+ ),
2383
+ };
2384
+
2385
+ /**
2386
+ * Whether a CSS property pasted before a value (`margin: 8px`) is one the
2387
+ * setting sets: its own label, a property a dial sets, a property that
2388
+ * reads the token, or, for a color token, a color property.
2389
+ * @param {any} ctx
2390
+ * @param {string} thing
2391
+ * @param {string} word
2392
+ * @param {boolean} partProperty
2393
+ */
2394
+ function labelOwned(ctx, thing, word, partProperty) {
2395
+ if (word === thing || ownLabel(thing, word)) return true;
2396
+ if (partProperty) return false;
2397
+ if (DIALS[thing]) return DIAL_PROPERTIES[thing]?.(word) ?? false;
2398
+ if (thing.startsWith('--')) {
2399
+ const kebab = (/** @type {string} */ p) =>
2400
+ p.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
2401
+ return (
2402
+ (ctx?.C?.propsReading?.(thing) ?? []).some(
2403
+ (/** @type {string} */ p) => kebab(p) === word,
2404
+ ) ||
2405
+ (isColorToken(thing) && (word === 'background' || COLOR_PROPS.test(word)))
2406
+ );
2407
+ }
2408
+ return false;
2409
+ }
2410
+
2411
+ /**
2412
+ * The one mode a light-only or dark-only theme shows, or null.
2413
+ * @param {{mode?: string} | null | undefined} data
2414
+ * @returns {'light' | 'dark' | null}
2415
+ */
2416
+ function oneModeOfTheme(data) {
2417
+ return data?.mode === 'light-only'
2418
+ ? 'light'
2419
+ : data?.mode === 'dark-only'
2420
+ ? 'dark'
2421
+ : null;
2422
+ }
2423
+
2424
+ /**
2425
+ * What a text property CSS inherits, set on a part, also reaches: the parts
2426
+ * inside it that set no such property of their own, said in one line; null
2427
+ * for any other property or when none does.
2428
+ * @param {import('./_settings.mjs').Ctx} ctx
2429
+ * @param {{on?: string, only?: boolean, thing?: string}} s
2430
+ * @param {string} prop kebab-case
2431
+ * @returns {string | null}
2432
+ */
2433
+ export function inheritedReach(ctx, s, prop) {
2434
+ if (
2435
+ !/^(font-(size|weight|style|family|variant)|text-(transform|align)|letter-spacing|line-height|white-space|word-spacing)$/.test(
2436
+ prop,
2437
+ )
2438
+ )
2439
+ return null;
2440
+ const reached = [
2441
+ ...new Set(
2442
+ partsOf(ctx, /** @type {any} */ (s)).flatMap(t =>
2443
+ /** @type {string[]} */ (ctx.C.MAP[t]?.contains ?? []).filter(
2444
+ inner =>
2445
+ ctx.project.target.has(inner) && !ctx.C.MAP[inner]?.own?.[prop],
2446
+ ),
2447
+ ),
2448
+ ),
2449
+ ];
2450
+ return reached.length
2451
+ ? `${prop} is inherited, so it also reaches ${reached.slice(0, 4).join(', ')}${reached.length > 4 ? ' and more' : ''} inside ${s.on}, which set no ${prop} of their own`
2452
+ : null;
2453
+ }
2454
+
2455
+ /**
2456
+ * The states `set` takes on a part: the ones its doc lists and the ones
2457
+ * every part takes, less any a change in it is refused for while the same
2458
+ * change without it passes (a state that never applies there). `how` lists
2459
+ * these, and a state that is not one names them.
2460
+ * @param {import('./_settings.mjs').Ctx} ctx
2461
+ * @param {string} slug
2462
+ * @param {any} data
2463
+ * @param {string} part
2464
+ * @returns {string[]}
2465
+ */
2466
+ export function settableStates(ctx, slug, data, part) {
2467
+ const t = ctx.project.target.get(part);
2468
+ if (!t) return [];
2469
+ const takes = (/** @type {string | undefined} */ state) => {
2470
+ try {
2471
+ checkSetting(ctx, slug, data, 'opacity', '1', {
2472
+ on: part,
2473
+ ...(state ? {state} : {}),
2474
+ });
2475
+ return true;
2476
+ } catch {
2477
+ return false;
2478
+ }
2479
+ };
2480
+ const plain = takes(undefined);
2481
+ return [...new Set([...t.states, ...COMMON_STATES])].filter(
2482
+ state => !plain || takes(state),
2483
+ );
2484
+ }
2485
+
2486
+ /**
2487
+ * The colors a part's color prop may show when none is given: its default
2488
+ * as its doc gives it; with none (Text's depends on its type), each value
2489
+ * of the prop whose text token the part's own color reads, in the order
2490
+ * the prop lists them. Empty with no color prop.
2491
+ * @param {{type?: string, default?: string | null} | undefined} prop
2492
+ * @param {Record<string, unknown> | undefined} reads the tokens the part's color reads (its part data)
2493
+ * @returns {string[]}
2494
+ */
2495
+ function colorPropDefaults(prop, reads) {
2496
+ if (!prop) return [];
2497
+ const own = /^'([\w-]+)'$/.exec(String(prop.default ?? '').trim())?.[1];
2498
+ if (own) return [own];
2499
+ return [...String(prop.type ?? '').matchAll(/'([\w-]+)'/g)]
2500
+ .map(m => m[1])
2501
+ .filter(v => Object.hasOwn(reads ?? {}, `--color-text-${v}`));
2502
+ }
2503
+
1390
2504
  /**
1391
2505
  * Check one setting and give it back ready to store, or refuse. What it
1392
2506
  * accepts, the settings loader takes too: the loader's own check runs last,
@@ -1398,6 +2512,9 @@ function baseReads(ctx, like, token) {
1398
2512
  * @param {string | undefined} value
1399
2513
  * @param {SetFlags} flags
1400
2514
  * @param {boolean} [unset] an undo of one setting: only the identity of the setting is checked
2515
+ * @param {{reads?: ReadonlySet<string>}} [scope] `reads`: the custom
2516
+ * properties the theme itself sets where the value is read, which a var()
2517
+ * in it reads as it reads a design token
1401
2518
  * @returns {import('./_settings.mjs').Setting}
1402
2519
  */
1403
2520
  export function checkSetting(
@@ -1408,12 +2525,500 @@ export function checkSetting(
1408
2525
  value,
1409
2526
  flags,
1410
2527
  unset = false,
2528
+ {reads} = {},
1411
2529
  ) {
1412
2530
  // Any other dial's value pasted with its property name (`font-size:
1413
2531
  // 18px;` for text-size, `color: #e11d48` for accent) is the value: one
1414
2532
  // path for every dial (the font dial reads its own below).
1415
- if (!unset && typeof value === 'string' && DIALS[thing] && thing !== 'font') {
1416
- const d = pastedDeclaration(value);
2533
+ // A light and a dark color typed as one value: a token takes both as
2534
+ // light-dark() or one --mode at a time; a color dial takes one color and
2535
+ // makes both modes from it. Never one of them for both.
2536
+ // A light-dark() written with another separator (`light-dark(red /
2537
+ // blue)`, `light-dark(red; blue)`): the pair meant, with a comma.
2538
+ // A dial's own words in any case (ROOMY, MORE, Both, NONE): the word.
2539
+ if (!unset && typeof value === 'string')
2540
+ value = dialWordOf(thing, value) ?? value;
2541
+ if (!unset && typeof value === 'string') {
2542
+ const near =
2543
+ /^\s*light-dark\(\s*([^,;/()]+?)\s*(?:\s\/\s|\/|;)\s*([^,;/()]+?)\s*\)\s*$/i.exec(
2544
+ value,
2545
+ );
2546
+ if (near)
2547
+ refuse(
2548
+ E.ERR_THEME_BAD_VALUE,
2549
+ `"${value}" separates its two colors with something other than a comma; light-dark() takes "light-dark(light, dark)".`,
2550
+ {
2551
+ run: [
2552
+ setLine(
2553
+ slug,
2554
+ thing,
2555
+ `light-dark(${near[1]}, ${near[2]})`,
2556
+ {...flags, mode: undefined},
2557
+ false,
2558
+ ),
2559
+ ],
2560
+ },
2561
+ );
2562
+ }
2563
+ // One reader for a family list, on the font dial, a family token and a
2564
+ // part's font-family: a weight or a size in it, alone or after a
2565
+ // family, is no family, and a quoted generic is a family named that.
2566
+ const fontish =
2567
+ thing === 'font' ||
2568
+ thing === 'font-family' ||
2569
+ thing.startsWith('--font-family');
2570
+ const listProblem =
2571
+ !unset && typeof value === 'string' && fontish
2572
+ ? fontListProblem(value, ctx, thing === 'font')
2573
+ : null;
2574
+ if (listProblem) {
2575
+ const on = flags.on ? ` --on ${flags.on}` : '';
2576
+ refuse(
2577
+ E.ERR_THEME_BAD_VALUE,
2578
+ `"${String(value).trim()}" ${listProblem.why}. ${thing} takes the families${listProblem.families ? ` (${listProblem.families})` : ''}${listProblem.size ? '; a size is set with text-size or a --font-size-* token' : listProblem.rung ? '; a weight is set with headings, font-weight or a --font-weight-* token' : listProblem.style ? '; a style is set with font-style on a part' : ''}.`,
2579
+ {
2580
+ run: [
2581
+ ...(listProblem.families
2582
+ ? [
2583
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(listProblem.families)}${on}`,
2584
+ ]
2585
+ : []),
2586
+ // The family as typed, kept as written by its quotes.
2587
+ ...(listProblem.asTyped
2588
+ ? [
2589
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(listProblem.asTyped)}${on}`,
2590
+ ]
2591
+ : []),
2592
+ ...(thing === 'font' && listProblem.rung
2593
+ ? [`${P} set ${slug} headings ${listProblem.rung}`]
2594
+ : []),
2595
+ ...(thing === 'font' && listProblem.textSize != null
2596
+ ? [`${P} set ${slug} text-size ${listProblem.textSize}`]
2597
+ : []),
2598
+ ...(thing === 'font-family' && flags.on && listProblem.style
2599
+ ? [`${P} set ${slug} font-style ${listProblem.style}${on}`]
2600
+ : []),
2601
+ ...(listProblem.families
2602
+ ? []
2603
+ : [`${HOW} ${quoteCommandArgument(thing)}`]),
2604
+ ],
2605
+ },
2606
+ );
2607
+ }
2608
+ // A font list with a comma missing before its generic family, or a
2609
+ // generic written with a space, on the font dial or a part's
2610
+ // font-family: the list meant (a family token reads it with its type).
2611
+ if (
2612
+ !unset &&
2613
+ typeof value === 'string' &&
2614
+ (thing === 'font' || thing === 'font-family')
2615
+ ) {
2616
+ const fixed = fontListMeant(value);
2617
+ if (fixed)
2618
+ refuse(
2619
+ E.ERR_THEME_BAD_VALUE,
2620
+ `"${value}" names a family that exists nowhere: ${fixed.why}.`,
2621
+ {run: [setLine(slug, thing, fixed.value, flags, false)]},
2622
+ );
2623
+ // A font dial word that names no family (mono, system, rounded): a
2624
+ // part's font-family takes the stack it stands for, never the word.
2625
+ const word = value.trim().toLowerCase();
2626
+ const stack = thing === 'font-family' ? fontStack(word) : null;
2627
+ if (
2628
+ stack &&
2629
+ FONTS[word] &&
2630
+ FONTS[word][0].toLowerCase() !== word &&
2631
+ !isSystemFamily(word)
2632
+ )
2633
+ refuse(
2634
+ E.ERR_THEME_BAD_VALUE,
2635
+ `"${value.trim()}" is a font dial word, not a family: no font is named that. font-family takes the families it stands for (${stack}).`,
2636
+ {run: [setLine(slug, thing, stack, flags, false)]},
2637
+ );
2638
+ }
2639
+ // A light and a dark color on a part's color property (`background`,
2640
+ // `color`, `border-color` …) is that property's light-dark() pair.
2641
+ if (
2642
+ !unset &&
2643
+ typeof value === 'string' &&
2644
+ flags.on &&
2645
+ !flags.mode &&
2646
+ /^(color|background|(background|border|outline|text-decoration|caret|accent|fill|stroke)(-[a-z]+)?-color)$/.test(
2647
+ String(thing).trim().toLowerCase(),
2648
+ )
2649
+ ) {
2650
+ const pair = colorPair(value);
2651
+ if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
2652
+ // A theme with one mode shows one half: that half is the line, as
2653
+ // for a color token.
2654
+ const only = oneModeOfTheme(data);
2655
+ if (only)
2656
+ refuse(
2657
+ E.ERR_THEME_BAD_VALUE,
2658
+ `"${value}" is a light and a dark color; this theme is ${only} only, so it shows the ${only} one.`,
2659
+ {
2660
+ run: [
2661
+ setLine(slug, thing, pair[only], {...flags, mode: undefined}),
2662
+ ],
2663
+ },
2664
+ );
2665
+ value = `light-dark(${pair.light}, ${pair.dark})`;
2666
+ }
2667
+ }
2668
+ if (
2669
+ !unset &&
2670
+ typeof value === 'string' &&
2671
+ (PALETTE_DIALS.includes(thing) || isColorToken(thing))
2672
+ ) {
2673
+ const pair = colorPair(value);
2674
+ if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
2675
+ const q = quoteCommandArgument;
2676
+ const on = flags.on ? ` --on ${flags.on}` : '';
2677
+ // A theme with one mode shows one half: that half is the line.
2678
+ const only = oneModeOfTheme(data);
2679
+ if (only)
2680
+ refuse(
2681
+ E.ERR_THEME_BAD_VALUE,
2682
+ `"${value}" is a light and a dark color; this theme is ${only} only, so it shows the ${only} one.`,
2683
+ {run: [`${P} set ${slug} ${thing} ${q(pair[only])}${on}`]},
2684
+ );
2685
+ refuse(
2686
+ E.ERR_THEME_BAD_VALUE,
2687
+ PALETTE_DIALS.includes(thing)
2688
+ ? `"${value}" is a light and a dark color; ${thing} takes one color and makes both modes from it.`
2689
+ : `"${value}" is a light and a dark color; ${thing} takes them as light-dark(), or one --mode at a time.`,
2690
+ {
2691
+ run: PALETTE_DIALS.includes(thing)
2692
+ ? [
2693
+ `${P} set ${slug} ${thing} ${q(pair.light)}${on}`,
2694
+ ...(thing === 'accent'
2695
+ ? [
2696
+ `${P} set ${slug} --color-accent ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
2697
+ ]
2698
+ : []),
2699
+ ]
2700
+ : [
2701
+ `${P} set ${slug} ${thing} ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
2702
+ `${P} set ${slug} ${thing} ${q(pair.light)}${on} --mode light`,
2703
+ `${P} set ${slug} ${thing} ${q(pair.dark)}${on} --mode dark`,
2704
+ ],
2705
+ },
2706
+ );
2707
+ }
2708
+ }
2709
+ // A value labeled with a word that is not this setting's own name (a
2710
+ // mode, a state, a device, a part, or a word the editor does not read) is
2711
+ // refused with what that word means here, never set with the word dropped.
2712
+ // A property set on a part (`padding 'hover: 4px' --on button`) and the
2713
+ // type tokens (`--font-weight-bold 'dark: 700'`) are read the same way;
2714
+ // a content string is its own text.
2715
+ const partProperty =
2716
+ Boolean(flags.on) && !DIALS[thing] && !thing.startsWith('--');
2717
+ const familyToken = thing.startsWith('--font-family');
2718
+ if (
2719
+ !unset &&
2720
+ typeof value === 'string' &&
2721
+ !/content/.test(thing) &&
2722
+ (DIALS[thing] || partProperty || thing.startsWith('--'))
2723
+ ) {
2724
+ const label = valueLabel(value);
2725
+ // Another CSS property's name before the value (`padding 'margin:
2726
+ // 8px'`, `corners 'margin: 24px'`, `--spacing-2 'border-radius: 8px'`)
2727
+ // is that property's value, never this setting's: for every setting, a
2728
+ // pasted property is read only when the setting is what it sets.
2729
+ if (
2730
+ label &&
2731
+ label.word !== thing &&
2732
+ !labelOwned(ctx, thing, label.word, Boolean(partProperty)) &&
2733
+ cssProperties().has(label.word) &&
2734
+ label.rest.trim()
2735
+ )
2736
+ refuse(
2737
+ E.ERR_THEME_BAD_VALUE,
2738
+ `"${value}" is labeled ${label.word}, another property than ${thing}; nothing is set from it.`,
2739
+ {
2740
+ didYouMean: [label.word],
2741
+ run: [setLine(slug, label.word, label.rest.trim(), flags, false)],
2742
+ },
2743
+ );
2744
+ // A CSS property's name before the value (`border-radius: pill`,
2745
+ // `color: #e11d48`, `font: bold 16px Inter`) is read by the paths
2746
+ // below, as a declaration pasted from a stylesheet.
2747
+ if (
2748
+ label &&
2749
+ !ownLabel(thing, label.word) &&
2750
+ !cssProperties().has(label.word)
2751
+ ) {
2752
+ const q = quoteCommandArgument;
2753
+ const rest = label.rest;
2754
+ const scope = `${flags.on ? ` --on ${flags.on}` : ''}${flags.when ? ` --when ${flags.when}` : ''}`;
2755
+ // A variant named after the value: the value with --when.
2756
+ if ('when' in label && label.when)
2757
+ refuse(
2758
+ E.ERR_THEME_BAD_VALUE,
2759
+ `"${value}" names a variant after the value; a value for one variant is given with --on <part> --when ${label.when}.`,
2760
+ {
2761
+ didYouMean: ['--when'],
2762
+ run: [
2763
+ flags.on
2764
+ ? `${P} set ${slug} ${thing} ${q(rest)} --on ${flags.on} --when ${label.when}`
2765
+ : `${HOW} ${q(`${label.when.split(':').pop()} ${thing}`)}`,
2766
+ ],
2767
+ },
2768
+ );
2769
+ const mode = modeWord(label.word);
2770
+ const colorful =
2771
+ PALETTE_DIALS.includes(thing) ||
2772
+ (thing.startsWith('--') && isColorToken(thing)) ||
2773
+ (partProperty &&
2774
+ /color|^background$|^fill$|^stroke$|shadow/.test(thing));
2775
+ const parts = [...ctx.project.target.keys(), ...Object.keys(FAMILIES)];
2776
+ // A theme with one mode: its own mode's label is the value, as the
2777
+ // theme has no other; the other mode's label names a mode it lacks.
2778
+ const only = oneModeOfTheme(data);
2779
+ if (mode && only) {
2780
+ if (mode === only)
2781
+ return checkSetting(ctx, slug, data, thing, rest, flags, unset);
2782
+ refuse(
2783
+ E.ERR_THEME_BAD_VALUE,
2784
+ `"${label.word}" in "${value}" names the ${mode} mode, which this ${only}-only theme does not show.`,
2785
+ {
2786
+ run: [
2787
+ `${P} set ${slug} mode both`,
2788
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}`,
2789
+ ],
2790
+ },
2791
+ );
2792
+ }
2793
+ if (mode && DIALS[thing] && PALETTE_DIALS.includes(thing))
2794
+ refuse(
2795
+ E.ERR_THEME_BAD_VALUE,
2796
+ `"${label.word}" in "${value}" names the ${mode} mode; ${thing} makes both modes from one color.`,
2797
+ {
2798
+ run: [
2799
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}`,
2800
+ ...(thing === 'accent'
2801
+ ? [
2802
+ `${P} set ${slug} --color-accent ${q(rest)}${scope} --mode ${mode}`,
2803
+ ]
2804
+ : []),
2805
+ ],
2806
+ },
2807
+ );
2808
+ const level = /^h([1-6])$/.exec(label.word)?.[1];
2809
+ if (level && thing === 'headings') {
2810
+ const w = rest.trim().toLowerCase();
2811
+ refuse(
2812
+ E.ERR_THEME_BAD_VALUE,
2813
+ `"${label.word}" in "${value}" is one heading level; headings sets every level, and one level is set with --on heading --when level:${level}.`,
2814
+ {
2815
+ run:
2816
+ HEADING_WEIGHTS[w] !== undefined
2817
+ ? [
2818
+ `${P} set ${slug} font-weight ${HEADING_WEIGHTS[w]} --on heading --when level:${level}`,
2819
+ `${P} set ${slug} headings ${w}`,
2820
+ ]
2821
+ : HEADING_TRACKING[w] !== undefined
2822
+ ? [
2823
+ `${P} set ${slug} letter-spacing ${q(HEADING_TRACKING[w])} --on heading --when level:${level}`,
2824
+ `${P} set ${slug} headings ${w}`,
2825
+ ]
2826
+ : [`${HOW} headings`],
2827
+ },
2828
+ );
2829
+ }
2830
+ if (mode)
2831
+ refuse(
2832
+ E.ERR_THEME_BAD_VALUE,
2833
+ colorful
2834
+ ? `"${label.word}" in "${value}" names the ${mode} mode; a value for one mode is given with --mode ${mode}.`
2835
+ : `"${label.word}" in "${value}" names the ${mode} mode, and ${thing} is the same in light and dark.`,
2836
+ {
2837
+ run: [
2838
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}${colorful ? ` --mode ${mode}` : ''}`,
2839
+ ],
2840
+ },
2841
+ );
2842
+ if (STATE_WORDS.includes(label.word))
2843
+ refuse(
2844
+ E.ERR_THEME_BAD_VALUE,
2845
+ flags.on
2846
+ ? `"${label.word}" in "${value}" is a state; a value for it is given with --state ${label.word}.`
2847
+ : `"${label.word}" in "${value}" is a state; a state is set on a part, with --on <part> --state ${label.word}.`,
2848
+ {
2849
+ run: [
2850
+ flags.on
2851
+ ? `${P} set ${slug} ${thing} ${q(rest)}${scope} --state ${label.word}`
2852
+ : `${HOW} ${q(`${label.word} ${thing}`)}`,
2853
+ ],
2854
+ },
2855
+ );
2856
+ if (DEVICE_WORDS.includes(label.word))
2857
+ refuse(
2858
+ E.ERR_THEME_BAD_VALUE,
2859
+ `"${label.word}" in "${value}" names a kind of screen; the editor sets ${thing} for every screen, not for one kind.`,
2860
+ {run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`]},
2861
+ );
2862
+ // `on button: pill`: the part named after `on`.
2863
+ const onPart = /^on-([a-z][a-z0-9-]*)$/.exec(label.word)?.[1];
2864
+ if (onPart && parts.includes(onPart))
2865
+ refuse(
2866
+ E.ERR_THEME_BAD_VALUE,
2867
+ `"${value}" names the part ${onPart}; a value for one part is given with --on ${onPart}.`,
2868
+ {run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${onPart}`]},
2869
+ );
2870
+ if (parts.includes(label.word))
2871
+ refuse(
2872
+ E.ERR_THEME_BAD_VALUE,
2873
+ `"${label.word}" in "${value}" is a part; a value for one part is given with --on ${label.word}.`,
2874
+ {run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${label.word}`]},
2875
+ );
2876
+ // A flag's own name as the label (`state: hover`, `part: card`,
2877
+ // `variant: primary`, `mode: dark`): what that flag does here.
2878
+ const flagWord = {
2879
+ state: 'state',
2880
+ states: 'state',
2881
+ part: 'on',
2882
+ on: 'on',
2883
+ component: 'on',
2884
+ variant: 'when',
2885
+ size: 'when',
2886
+ when: 'when',
2887
+ prop: 'when',
2888
+ mode: 'mode',
2889
+ theme: 'mode',
2890
+ }[label.word];
2891
+ if (
2892
+ flagWord &&
2893
+ (flagWord === 'mode'
2894
+ ? Boolean(modeWord(rest))
2895
+ : !otherSettingLabel(thing, value))
2896
+ ) {
2897
+ const r = rest.trim().toLowerCase();
2898
+ // The flag's value and the setting's value in one (`state=hover
2899
+ // 4px`): the first word is the flag's, the rest the value.
2900
+ const [fv, ...more] = rest.trim().split(/\s+/);
2901
+ if (flagWord !== 'mode' && more.length > 0) {
2902
+ const flagged =
2903
+ flagWord === 'on'
2904
+ ? ` --on ${fv}${flags.when ? ` --when ${flags.when}` : ''}`
2905
+ : flags.on
2906
+ ? `${scope} --${flagWord} ${flagWord === 'when' && label.word !== 'when' && label.word !== 'prop' ? `${label.word}:${fv}` : fv}`
2907
+ : null;
2908
+ refuse(
2909
+ E.ERR_THEME_BAD_VALUE,
2910
+ `"${value}" holds the ${flagWord} ${fv} and the value ${more.join(' ')}; the ${flagWord} is given with --${flagWord}.`,
2911
+ {
2912
+ didYouMean: [`--${flagWord}`],
2913
+ run: [
2914
+ flagged
2915
+ ? `${P} set ${slug} ${thing} ${q(more.join(' '))}${flagged}`
2916
+ : `${HOW} ${q(`${fv} ${thing}`)}`,
2917
+ ],
2918
+ },
2919
+ );
2920
+ }
2921
+ const m = flagWord === 'mode' ? modeWord(r) : null;
2922
+ const when =
2923
+ flagWord === 'when'
2924
+ ? label.word === 'when' || label.word === 'prop'
2925
+ ? r
2926
+ : `${label.word}:${r}`
2927
+ : null;
2928
+ refuse(
2929
+ E.ERR_THEME_BAD_VALUE,
2930
+ flagWord === 'mode'
2931
+ ? `"${value}" names ${m ? `the ${m} mode` : 'a mode'}, not a value for ${thing}: ${colorful ? `a value for one mode is given with --mode ${m ?? 'dark'}` : `a theme for one mode is set with \`set ${slug} mode ${m ?? 'dark'}-only\``}.`
2932
+ : flagWord === 'state'
2933
+ ? `"${value}" names a state, not a value for ${thing}: a value for a state is given with --on <part> --state ${r}.`
2934
+ : flagWord === 'on'
2935
+ ? `"${value}" names a part, not a value for ${thing}: a value for one part is given with --on ${r}.`
2936
+ : `"${value}" names a variant, not a value for ${thing}: a value for one variant is given with --on <part> --when ${when}.`,
2937
+ {
2938
+ didYouMean: [`--${flagWord}`],
2939
+ run: [
2940
+ flagWord === 'mode' && !colorful
2941
+ ? `${P} set ${slug} mode ${m ?? 'dark'}-only`
2942
+ : `${HOW} ${q(`${r} ${thing}`)}`,
2943
+ ],
2944
+ },
2945
+ );
2946
+ }
2947
+ // A Google Fonts family spec (`Inter:wght@400;600`): the family
2948
+ // before the colon.
2949
+ if (
2950
+ (thing === 'font' || familyToken || thing === 'font-family') &&
2951
+ /^(ital,)?wght@|^ital@/i.test(rest)
2952
+ ) {
2953
+ const family = String(value).split(':')[0].replace(/\+/g, ' ').trim();
2954
+ refuse(
2955
+ E.ERR_THEME_BAD_VALUE,
2956
+ `"${value}" is a Google Fonts family spec; ${thing} takes the family (${family}). A weight is set with font-weight or a --font-weight-* token.`,
2957
+ {run: [`${P} set ${slug} ${thing} ${q(family)}${scope}`]},
2958
+ );
2959
+ }
2960
+ // A family's own words may hold a colon; only the words above are
2961
+ // read there.
2962
+ if (!familyToken && !otherSettingLabel(thing, value))
2963
+ refuse(
2964
+ E.ERR_THEME_BAD_VALUE,
2965
+ `"${label.word}" in "${value}" is not a name the editor reads for ${thing}; give the value alone.`,
2966
+ {
2967
+ // Only setting names: a part or a state is never a value.
2968
+ didYouMean: nearest(label.word, Object.keys(DIALS)),
2969
+ run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`],
2970
+ },
2971
+ );
2972
+ }
2973
+ // The setting's own name before its value (`font: Inter`, `Font:
2974
+ // Georgia`) is the value.
2975
+ // (A `font:` shorthand is read whole below, as its family.)
2976
+ if (
2977
+ label &&
2978
+ ownLabel(thing, label.word) &&
2979
+ // A `font:` with a size is the shorthand, read whole below; with
2980
+ // only families (`font: Inter, serif`) it is the label.
2981
+ (label.word !== 'font' || !/\d/.test(label.rest)) &&
2982
+ label.rest.replace(/;+\s*$/, '').trim()
2983
+ )
2984
+ value = label.rest;
2985
+ }
2986
+ if (
2987
+ !unset &&
2988
+ typeof value === 'string' &&
2989
+ (DIALS[thing] || partProperty || thing.startsWith('--')) &&
2990
+ !/content/.test(thing)
2991
+ ) {
2992
+ // A value labeled with another setting's name is that setting's, never
2993
+ // this one's (`accent 'neutral: #64748b'`, `--radius-element 'accent:
2994
+ // red'`). The value goes to this setting again only for a dial that
2995
+ // checks it as its own (any word is a font family, so never the font).
2996
+ const other = otherSettingLabel(thing, value);
2997
+ if (other)
2998
+ refuse(
2999
+ E.ERR_THEME_BAD_VALUE,
3000
+ `"${value}" is labeled ${other.thing}, another setting than ${thing}; nothing is set from it.`,
3001
+ {
3002
+ didYouMean: [other.thing],
3003
+ run: [
3004
+ `${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
3005
+ // Another setting is not this part's property: the whole theme.
3006
+ ...(flags.on && partProperty
3007
+ ? [
3008
+ `${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}`,
3009
+ ]
3010
+ : []),
3011
+ ...(DIALS[thing] && thing !== 'font'
3012
+ ? [
3013
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
3014
+ ]
3015
+ : []),
3016
+ ],
3017
+ },
3018
+ );
3019
+ }
3020
+ if (!unset && typeof value === 'string' && DIALS[thing]) {
3021
+ const d = thing === 'font' ? null : pastedDeclaration(value);
1417
3022
  if (d?.value) value = d.value;
1418
3023
  }
1419
3024
  // The font dial's value as pasted from a stylesheet (`Georgia, serif;`,
@@ -1465,7 +3070,16 @@ export function checkSetting(
1465
3070
  throw e;
1466
3071
  }
1467
3072
  }
1468
- const s = checkSettingAsTyped(ctx, slug, data, thing, value, flags, unset);
3073
+ const s = checkSettingAsTyped(
3074
+ ctx,
3075
+ slug,
3076
+ data,
3077
+ thing,
3078
+ value,
3079
+ flags,
3080
+ unset,
3081
+ reads,
3082
+ );
1469
3083
  // A var() with a fallback always gives a value; a name one slip from a
1470
3084
  // design token is noted as a likely typo, and the setting stands.
1471
3085
  if (!unset && typeof value === 'string' && !s.note) {
@@ -1485,8 +3099,8 @@ export function checkSetting(
1485
3099
  function fallbackVarTypo(v, TOKENS) {
1486
3100
  for (const [, name] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*,/gi)) {
1487
3101
  if (name in TOKENS || name.startsWith('--_')) continue;
1488
- const near = nearest(name, Object.keys(TOKENS)).filter(
1489
- n => levenshteinDistance(n, name) <= 2,
3102
+ const near = nearest(name, Object.keys(TOKENS)).filter(n =>
3103
+ typoNear(name, n),
1490
3104
  );
1491
3105
  if (near.length)
1492
3106
  return `${name} is not a design token, so its fallback always shows; did you mean ${near[0]}?`;
@@ -1503,6 +3117,7 @@ function fallbackVarTypo(v, TOKENS) {
1503
3117
  * @param {string | undefined} value
1504
3118
  * @param {SetFlags} flags
1505
3119
  * @param {boolean} [unset]
3120
+ * @param {ReadonlySet<string>} [reads] custom properties the theme sets where the value is read
1506
3121
  * @returns {import('./_settings.mjs').Setting}
1507
3122
  */
1508
3123
  function checkSettingAsTyped(
@@ -1513,8 +3128,9 @@ function checkSettingAsTyped(
1513
3128
  value,
1514
3129
  flags,
1515
3130
  unset = false,
3131
+ reads = undefined,
1516
3132
  ) {
1517
- const s = checkOne(ctx, slug, data, thing, value, flags, unset);
3133
+ const s = checkOne(ctx, slug, data, thing, value, flags, unset, reads);
1518
3134
  const why = unset ? null : valueProblem(s);
1519
3135
  if (why)
1520
3136
  refuse(
@@ -1542,9 +3158,10 @@ function checkSettingAsTyped(
1542
3158
  * @param {string | undefined} value
1543
3159
  * @param {SetFlags} flags
1544
3160
  * @param {boolean} unset
3161
+ * @param {ReadonlySet<string>} [reads] custom properties the theme sets where the value is read
1545
3162
  * @returns {import('./_settings.mjs').Setting}
1546
3163
  */
1547
- function checkOne(ctx, slug, data, thing, value, flags, unset) {
3164
+ function checkOne(ctx, slug, data, thing, value, flags, unset, reads) {
1548
3165
  const {C} = ctx;
1549
3166
  const TARGET = ctx.project.target;
1550
3167
  const TOKENS = ctx.project.core.tokenDefaults;
@@ -1580,7 +3197,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1580
3197
  const v = normalValue(thing, value ?? '');
1581
3198
  // A var() that misspells a design token would read nothing.
1582
3199
  if (!unset) {
1583
- const bad = unknownVarRef(v, TOKENS, thing);
3200
+ const bad = unknownVarRef(v, TOKENS, thing, reads);
1584
3201
  if (bad)
1585
3202
  refuse(E.ERR_THEME_UNKNOWN_TOKEN, bad.message, {
1586
3203
  didYouMean: bad.near,
@@ -1628,23 +3245,89 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1628
3245
  .toLowerCase();
1629
3246
  if (flags.only) s.only = true;
1630
3247
  if (flags.mode) {
1631
- const mode = flags.mode.toLowerCase();
1632
- if (mode !== 'light' && mode !== 'dark')
3248
+ // Read as any value is: invisible or no-break spaces, quotes around
3249
+ // it, a trailing colon (`'dark '`, `“dark”`, `dark:`).
3250
+ const mode = withoutDebris(normalValueText(String(flags.mode)))
3251
+ .trim()
3252
+ .replace(/^(["'])(.*)\1$/, '$2')
3253
+ .replace(/:+$/, '')
3254
+ .trim()
3255
+ .toLowerCase();
3256
+ if (mode !== 'light' && mode !== 'dark') {
3257
+ // A word that names one of the two (dark-only, darkmode, night) is
3258
+ // that one, by the one mode reader; never the nearest spelling, which
3259
+ // can be the other (night → light).
3260
+ const meant = modeWord(mode);
3261
+ const near = meant ? [meant] : nearest(mode, ['light', 'dark']);
3262
+ // The line for that one mode: for a dial, the one `--mode dark` itself
3263
+ // offers (the color token for that mode), never the both-modes dial.
3264
+ const modeLine = (/** @type {string} */ m) => {
3265
+ if (DIALS[thing] && !unset)
3266
+ try {
3267
+ checkSetting(ctx, slug, data, thing, v, {...flags, mode: m});
3268
+ } catch (e) {
3269
+ const first = /** @type {any} */ (e)?.suggestions?.find(
3270
+ (/** @type {any} */ x) => / --mode (light|dark)\b/.test(x.name),
3271
+ );
3272
+ if (first) return first.name;
3273
+ }
3274
+ return setLine(slug, thing, v, {...s, mode: m}, unset);
3275
+ };
1633
3276
  refuse(
1634
3277
  E.ERR_THEME_BAD_VALUE,
1635
3278
  `--mode takes light or dark, not "${flags.mode}".`,
1636
3279
  {
1637
- didYouMean: nearest(mode, ['light', 'dark']),
1638
- // The same setting for both modes runs as printed; the mode it
1639
- // probably meant is the did-you-mean.
1640
- run: [setLine(slug, thing, v, {...s, mode: undefined}, unset)],
3280
+ didYouMean: near,
3281
+ // The mode it is nearest keeps --mode; only with none near is the
3282
+ // same setting for both modes offered.
3283
+ run: [
3284
+ ...(near.length === 1 ? [modeLine(near[0])] : []),
3285
+ // A word that means one mode (night) keeps it: the both-modes
3286
+ // line only for a word read by spelling.
3287
+ ...(meant
3288
+ ? []
3289
+ : [setLine(slug, thing, v, {...s, mode: undefined}, unset)]),
3290
+ ],
1641
3291
  },
1642
3292
  );
3293
+ }
1643
3294
  s.mode = mode;
1644
3295
  }
1645
3296
  const onFlag = s.on ? ` --on ${s.on}` : '';
1646
- // A value that already gives both modes takes no --mode.
1647
- if (s.mode && !unset && /^\s*light-dark\(/i.test(v ?? ''))
3297
+ // A CSS-wide keyword is no color for one mode: a mode's half takes a
3298
+ // color, and the keyword applies to the whole declaration, in both modes.
3299
+ if (
3300
+ s.mode &&
3301
+ !unset &&
3302
+ CSS_WIDE.includes(
3303
+ String(v ?? '')
3304
+ .trim()
3305
+ .toLowerCase(),
3306
+ )
3307
+ )
3308
+ // A token takes no keyword in any mode (it would be left empty), so for
3309
+ // a token only the color is offered.
3310
+ refuse(
3311
+ E.ERR_THEME_NO_MODE,
3312
+ String(thing).startsWith('--')
3313
+ ? `"${String(v).trim()}" is a CSS keyword, which applies in both modes, so it takes no --mode; and a token never takes one. Give the ${s.mode} color.`
3314
+ : `"${String(v).trim()}" is a CSS keyword, which applies in both modes, so it takes no --mode. Give the ${s.mode} color, or set ${thing} ${String(v).trim()} for both modes.`,
3315
+ {
3316
+ run: [
3317
+ String(thing).startsWith('--')
3318
+ ? `${HOW} ${thing}`
3319
+ : `${P} set ${slug} ${thing} ${String(v).trim()}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
3320
+ ],
3321
+ },
3322
+ );
3323
+ // A value that already gives both modes takes no --mode (a gradient
3324
+ // holding a light-dark() stop included).
3325
+ if (
3326
+ s.mode &&
3327
+ !unset &&
3328
+ (/^\s*light-dark\(/i.test(v ?? '') ||
3329
+ (/gradient\(/i.test(v ?? '') && /light-dark\(/i.test(v ?? '')))
3330
+ )
1648
3331
  refuse(
1649
3332
  E.ERR_THEME_NO_MODE,
1650
3333
  `"${v}" already gives both modes, so it takes no --mode; drop --mode, or give the ${s.mode} color alone.`,
@@ -1655,17 +3338,59 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1655
3338
  },
1656
3339
  );
1657
3340
  // A setting saved for a mode the theme no longer has can still be removed.
1658
- if (s.mode && data.mode !== 'both' && !unset)
3341
+ // An entry saved for the one mode the theme has ("[dark only]" in a
3342
+ // dark-only theme) can be set again with that --mode, so a doubled one
3343
+ // can be kept: that set replaces both.
3344
+ const sameModeEntry =
3345
+ s.mode &&
3346
+ data.mode === `${s.mode}-only` &&
3347
+ (Array.isArray(data.settings) ? data.settings : []).some(
3348
+ (/** @type {any} */ x) =>
3349
+ x &&
3350
+ x.thing === thing &&
3351
+ x.mode === s.mode &&
3352
+ (x.on ?? null) === (s.on ?? null) &&
3353
+ (x.when ?? null) === (s.when ?? null) &&
3354
+ (x.state ?? null) === (s.state ?? null),
3355
+ );
3356
+ // A one-mode theme still has the other mode where Core draws it (a toast,
3357
+ // a lightbox): a value for that mode is written for those regions.
3358
+ const otherModeOfOneMode =
3359
+ s.mode != null &&
3360
+ oneModeOfTheme(data) != null &&
3361
+ oneModeOfTheme(data) !== s.mode;
3362
+ if (
3363
+ s.mode &&
3364
+ data.mode !== 'both' &&
3365
+ !unset &&
3366
+ !sameModeEntry &&
3367
+ !otherModeOfOneMode
3368
+ ) {
3369
+ // What takes no --mode in any theme (a size, a font, a keyword) is
3370
+ // refused for that, with the command that drops --mode: a theme with
3371
+ // both modes would refuse it too, so its mode is no way out.
3372
+ try {
3373
+ checkSetting(ctx, slug, {...data, mode: 'both'}, thing, v, flags);
3374
+ } catch (e) {
3375
+ if (/** @type {any} */ (e)?.code === E.ERR_THEME_NO_MODE) throw e;
3376
+ }
1659
3377
  refuse(
1660
3378
  E.ERR_THEME_NO_MODE,
1661
- `This theme is ${data.mode}; --mode is for themes with both modes.`,
1662
- {run: [`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}`]},
3379
+ `This theme is ${data.mode}, so its own mode needs no --mode.`,
3380
+ {
3381
+ run: [
3382
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
3383
+ ],
3384
+ },
1663
3385
  );
3386
+ }
1664
3387
  if ((s.when || s.state) && !s.on)
1665
3388
  refuse(E.ERR_MISSING_ARGUMENT, '--when and --state need --on <part>.', {
1666
3389
  run: [`${HOW} --list parts`],
1667
3390
  });
1668
- if (s.only) {
3391
+ // --only is checked on a part this Core has; a part in other letters or
3392
+ // misspelt gets the part's own refusal first, with --only kept.
3393
+ if (s.only && (!s.on || TARGET.has(s.on) || FAMILIES[s.on])) {
1669
3394
  const fam = s.on ? familyOf(s.on) : null;
1670
3395
  if (!fam || FAMILIES[/** @type {string} */ (s.on)])
1671
3396
  refuse(
@@ -1693,29 +3418,99 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1693
3418
  // Another case of a part or group, its class name copied from the
1694
3419
  // page (`.astryx-card`), or its component (`<Card>`, `Card`): that
1695
3420
  // part, as a working command with every flag kept.
3421
+ // Stray punctuation from a copied list ("text-input,") and the dashes
3422
+ // autocorrect types ("text\u2013input") are not part of the name.
1696
3423
  const lower = s.on
3424
+ .replace(/[\u2010-\u2015\u2212]/g, '-')
3425
+ .replace(/^[\s,;:.'"`]+|[\s,;:.'"`]+$/g, '')
1697
3426
  .trim()
1698
3427
  .replace(/^<\/?\s*|\s*\/?>$/g, '')
1699
3428
  .replace(/^\./, '')
1700
3429
  .replace(/^astryx-/, '')
1701
3430
  .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
1702
3431
  .toLowerCase();
1703
- // A plain word how reads as a part or group (checkboxes: checks).
1704
- const byWord = partForWord(lower);
3432
+ // A part named in words (dialog header, text inputs) is the dashed
3433
+ // part, read before any group a single word of it names.
3434
+ const dashed = lower.trim().replace(/[\s_]+/g, '-');
3435
+ // A plain word how reads as a part or group (checkboxes: checks):
3436
+ // only the whole value as one word, never one word inside a longer
3437
+ // name (nmber-input is no word for inputs).
3438
+ const byWord = /^[a-z]+$/.test(lower) ? partForWord(lower) : null;
3439
+ // A typo of one whole part or group name is that name.
3440
+ const typoParts = [...TARGET.keys(), ...Object.keys(FAMILIES)].filter(
3441
+ n => n !== lower && n !== dashed && typoNear(dashed, n),
3442
+ );
1705
3443
  // A plain plural of a part (cards, dialogs, tabs) is that part.
1706
- const singular = [
1707
- lower.replace(/ies$/, 'y'),
1708
- lower.replace(/(ch|sh|x|s)es$/, '$1'),
1709
- lower.replace(/s$/, ''),
1710
- ].find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
3444
+ const singular = [lower, dashed]
3445
+ .flatMap(w => [
3446
+ w.replace(/ies$/, 'y'),
3447
+ w.replace(/(ch|sh|x|s)es$/, '$1'),
3448
+ w.replace(/s$/, ''),
3449
+ ])
3450
+ .find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
3451
+ // Several parts named in one --on (`button, text-input`, `button/
3452
+ // text-input`, `button and text-input`, or spaces): one command per
3453
+ // part named, each checked, never a group that one word of the list
3454
+ // happens to name.
3455
+ const listed = /,|\/|&|\band\b/.test(lower);
3456
+ // (Words with only spaces that name one part, `text inputs`, are
3457
+ // that part.)
3458
+ if (!(TARGET.has(dashed) || FAMILIES[dashed]) && (listed || !singular)) {
3459
+ const pieces = lower
3460
+ .split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
3461
+ .map(x => x.trim())
3462
+ .filter(Boolean);
3463
+ const partOf = (/** @type {string} */ w) =>
3464
+ TARGET.has(w) || FAMILIES[w]
3465
+ ? w
3466
+ : ([w.replace(/ies$/, 'y'), w.replace(/s$/, '')].find(
3467
+ x => x !== w && (TARGET.has(x) || FAMILIES[x]),
3468
+ ) ?? null);
3469
+ const found = pieces.map(partOf);
3470
+ const parts = [...new Set(found.filter(x => x != null))];
3471
+ const missing = pieces.filter((_, i) => found[i] == null);
3472
+ if (
3473
+ pieces.length > 1 &&
3474
+ parts.length > 0 &&
3475
+ (missing.length === 0 || (listed && parts.length > 1))
3476
+ )
3477
+ refuse(
3478
+ E.ERR_THEME_UNKNOWN_PART,
3479
+ `"${s.on}" names ${pieces.length} parts; --on takes one part at a time${missing.length ? ` (${missing.map(x => `"${x}"`).join(', ')} is not a part you can style)` : ''}.`,
3480
+ {
3481
+ didYouMean: parts,
3482
+ run: parts
3483
+ .slice(0, 6)
3484
+ .map(on => setLine(slug, thing, v, {...s, on}, unset)),
3485
+ },
3486
+ );
3487
+ }
1711
3488
  const named =
1712
3489
  TARGET.has(lower) || FAMILIES[lower]
1713
3490
  ? lower
1714
- : singular
1715
- ? singular
1716
- : byWord && (TARGET.has(byWord) || FAMILIES[byWord])
1717
- ? byWord
1718
- : null;
3491
+ : TARGET.has(dashed) || FAMILIES[dashed]
3492
+ ? dashed
3493
+ : singular
3494
+ ? singular
3495
+ : typoParts.length === 1
3496
+ ? typoParts[0]
3497
+ : byWord && (TARGET.has(byWord) || FAMILIES[byWord])
3498
+ ? byWord
3499
+ : null;
3500
+ // The page (the body behind every part) is painted by the app shell.
3501
+ if (
3502
+ !named &&
3503
+ /^(page|body|app|background|page-background)$/i.test(s.on) &&
3504
+ TARGET.has('app-shell')
3505
+ )
3506
+ refuse(
3507
+ E.ERR_THEME_UNKNOWN_PART,
3508
+ `"${s.on}" is not a part name; the page behind your parts is app-shell (a background there shows in every AppShell variant).`,
3509
+ {
3510
+ didYouMean: ['app-shell'],
3511
+ run: [setLine(slug, thing, v, {...s, on: 'app-shell'}, unset)],
3512
+ },
3513
+ );
1719
3514
  if (named)
1720
3515
  refuse(
1721
3516
  E.ERR_THEME_UNKNOWN_PART,
@@ -1725,16 +3520,22 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1725
3520
  run: [setLine(slug, thing, v, {...s, on: named}, unset)],
1726
3521
  },
1727
3522
  );
3523
+ // A plural or another case names the part it means; a typo of one
3524
+ // part leads with the same command on that part.
3525
+ const near = nearest(s.on.toLowerCase().replace(/s$/, ''), [
3526
+ ...TARGET.keys(),
3527
+ ...Object.keys(FAMILIES),
3528
+ ]);
3529
+ const typo = near.filter(n => typoOf(lower, n));
1728
3530
  refuse(
1729
3531
  E.ERR_THEME_UNKNOWN_PART,
1730
3532
  `"${s.on}" is not a part you can style.`,
1731
3533
  {
1732
- // A plural or another case names the part it means.
1733
- didYouMean: nearest(s.on.toLowerCase().replace(/s$/, ''), [
1734
- ...TARGET.keys(),
1735
- ...Object.keys(FAMILIES),
1736
- ]),
3534
+ didYouMean: near,
1737
3535
  run: [
3536
+ ...(typo.length === 1
3537
+ ? [setLine(slug, thing, v, {...s, on: typo[0]}, unset)]
3538
+ : []),
1738
3539
  `${HOW} --list parts ${quoteCommandArgument(lower.replace(/s$/, '').split('-')[0] || 'button')}`,
1739
3540
  `${HOW} ${quoteCommandArgument(s.on)}`,
1740
3541
  ],
@@ -1742,6 +3543,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1742
3543
  );
1743
3544
  }
1744
3545
  if (s.when) {
3546
+ // A prop and value in other letters, with spaces or `=` between
3547
+ // (`Variant: Primary`, `variant=primary`): the working command.
3548
+ const m = /^\s*([^:=\s]+)\s*[:=]\s*([^:=]+?)\s*$/.exec(s.when);
3549
+ if (m) {
3550
+ const prop = t.props.find(x => x.toLowerCase() === m[1].toLowerCase());
3551
+ const vals = prop ? (C.variantValues(s.on)[prop] ?? []) : [];
3552
+ const val = vals.length
3553
+ ? vals.find(x => x.toLowerCase() === m[2].toLowerCase())
3554
+ : m[2];
3555
+ const when = prop && val ? `${prop}:${val}` : null;
3556
+ if (when && when !== s.when)
3557
+ refuse(
3558
+ E.ERR_THEME_UNKNOWN_VARIANT,
3559
+ `--when "${s.when}" is written ${when}.`,
3560
+ {
3561
+ didYouMean: [when],
3562
+ run: [setLine(slug, thing, v, {...s, when}, unset)],
3563
+ },
3564
+ );
3565
+ }
1745
3566
  const [p, wv, ...more] = s.when.split(':');
1746
3567
  if (!wv || more.length)
1747
3568
  refuse(
@@ -1749,7 +3570,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1749
3570
  '--when takes <prop>:<value>, such as variant:primary.',
1750
3571
  {run: [`${HOW} ${s.on}`]},
1751
3572
  );
1752
- if (!t.props.includes(p))
3573
+ const conditions = Object.keys(C.variantValues(s.on));
3574
+ if (!t.props.includes(p) && !conditions.includes(p))
1753
3575
  refuse(
1754
3576
  E.ERR_THEME_UNKNOWN_VARIANT,
1755
3577
  `${s.on} has no prop "${p}". It has: ${t.props.join(', ') || 'none'}.`,
@@ -1764,12 +3586,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1764
3586
  );
1765
3587
  }
1766
3588
  const states = [...t.states, ...COMMON_STATES];
3589
+ // A state the part lists in camelCase (toggle-button's isPressed) typed
3590
+ // in any case or with dashes is that state.
3591
+ const flat = (/** @type {string} */ x) =>
3592
+ x.replace(/[-_\s]/g, '').toLowerCase();
3593
+ if (s.state && !states.includes(s.state)) {
3594
+ const same = states.find(x => flat(x) === flat(String(s.state)));
3595
+ if (same) s.state = same;
3596
+ }
1767
3597
  // Other words for a state, mapped to the one the part has; with none
1768
3598
  // near, the list of its states (never a guess such as hover).
1769
3599
  const SYNONYMS = wordTable(
1770
3600
  /** @type {Record<string, string[]>} */ ({
1771
- pressed: ['active'],
1772
- press: ['active'],
3601
+ pressed: ['isPressed', 'active'],
3602
+ press: ['isPressed', 'active'],
3603
+ on: ['isPressed', 'checked', 'selected'],
1773
3604
  down: ['active'],
1774
3605
  clicked: ['active'],
1775
3606
  hovered: ['hover'],
@@ -1781,6 +3612,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1781
3612
  inactive: ['disabled'],
1782
3613
  }),
1783
3614
  );
3615
+ // Several states in one --state (`hover,focus-visible`, `hover
3616
+ // focus-visible`): one line per state, the value quoted as typed.
3617
+ const typedStates = String(flags.state ?? '')
3618
+ .split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
3619
+ .map(x => x.trim().toLowerCase())
3620
+ .filter(Boolean);
3621
+ if (
3622
+ typedStates.length > 1 &&
3623
+ typedStates.every(x => states.includes(x)) &&
3624
+ !states.includes(String(s.state))
3625
+ )
3626
+ refuse(
3627
+ E.ERR_THEME_UNKNOWN_STATE,
3628
+ `"${flags.state}" names ${typedStates.length} states; --state takes one at a time.`,
3629
+ {
3630
+ didYouMean: typedStates,
3631
+ run: typedStates
3632
+ .slice(0, 6)
3633
+ .map(state => setLine(slug, thing, v, {...s, state}, unset)),
3634
+ },
3635
+ );
1784
3636
  const meant =
1785
3637
  (SYNONYMS[String(s.state ?? '').toLowerCase()] ?? []).find(x =>
1786
3638
  states.includes(x),
@@ -1788,7 +3640,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1788
3640
  if (s.state && !states.includes(s.state))
1789
3641
  refuse(
1790
3642
  E.ERR_THEME_UNKNOWN_STATE,
1791
- `"${s.state}" is not a state of ${s.on}. States: ${states.join(', ')}.`,
3643
+ `"${s.state}" is not a state of ${s.on}. States: ${settableStates(ctx, slug, data, s.on).join(', ') || 'none'}.`,
1792
3644
  {
1793
3645
  ...(meant ? {didYouMean: [meant]} : {}),
1794
3646
  run: [
@@ -1901,6 +3753,13 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1901
3753
  if (parts.length && dead.length === parts.length) {
1902
3754
  const bare = Object.keys(own(dead[0])).length === 0;
1903
3755
  const within = keys(dead[0], 'focus-within');
3756
+ // A ring Core draws inline on the part at focus time (an indicator's)
3757
+ // is changed by its token, with no state.
3758
+ const inlineAlways = ctx.C.MAP[dead[0]]?.inline?.[''] ?? {};
3759
+ const ringToken = /^focus/.test(s.state)
3760
+ ? (inlineAlways[kebab(thing)] ??
3761
+ (Object.values(inlineAlways).includes(thing) ? thing : null))
3762
+ : null;
1904
3763
  refuse(
1905
3764
  E.ERR_THEME_NO_EFFECT,
1906
3765
  bare
@@ -1916,12 +3775,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1916
3775
  ...(within && !bare && /^focus/.test(s.state)
1917
3776
  ? {didYouMean: ['focus-within']}
1918
3777
  : {}),
3778
+ ...(ringToken
3779
+ ? {
3780
+ also: [
3781
+ `Core draws ${dead[0]}'s focus ring at focus time from ${ringToken}, set on the part with no state`,
3782
+ ],
3783
+ }
3784
+ : {}),
1919
3785
  run: [
1920
- within && !bare && /^focus/.test(s.state)
1921
- ? setLine(slug, thing, v, {...s, state: 'focus-within'}, unset)
1922
- : bare
1923
- ? `${HOW} --list parts ${s.on.split('-')[0]}`
1924
- : `${HOW} ${quoteCommandArgument(s.on)}`,
3786
+ ringToken
3787
+ ? `${P} set ${slug} ${ringToken} ${quoteCommandArgument(v)} --on ${s.on}${s.mode ? ` --mode ${s.mode}` : ''}`
3788
+ : within && !bare && /^focus/.test(s.state)
3789
+ ? setLine(slug, thing, v, {...s, state: 'focus-within'}, unset)
3790
+ : bare
3791
+ ? `${HOW} --list parts ${s.on.split('-')[0]}`
3792
+ : `${HOW} ${quoteCommandArgument(s.on)}`,
1925
3793
  ],
1926
3794
  },
1927
3795
  );
@@ -1973,7 +3841,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1973
3841
  if (s.when) {
1974
3842
  const [p, wv, ...more] = s.when.split(':');
1975
3843
  const fits = members.some(([m, t]) => {
1976
- if (!wv || more.length || !t.props.includes(p)) return false;
3844
+ if (
3845
+ !wv ||
3846
+ more.length ||
3847
+ !(t.props.includes(p) || p in C.variantValues(m))
3848
+ )
3849
+ return false;
1977
3850
  const vals = C.variantValues(m)[p] ?? [];
1978
3851
  return !vals.length || vals.includes(wv);
1979
3852
  });
@@ -2131,6 +4004,38 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2131
4004
  })(),
2132
4005
  },
2133
4006
  );
4007
+ // A comparative weight word is the weight (lighter is light, never the
4008
+ // tracking tighter); two words (`bold tight`, `bold, tight`) are a
4009
+ // weight and a tracking, one line each.
4010
+ if (!unset) {
4011
+ const MORE = /** @type {Record<string, string>} */ ({
4012
+ lighter: 'light',
4013
+ thinner: 'light',
4014
+ bolder: 'bold',
4015
+ heavier: 'heavy',
4016
+ wider: 'wide',
4017
+ looser: 'wide',
4018
+ });
4019
+ const words = String(v ?? '')
4020
+ .trim()
4021
+ .toLowerCase()
4022
+ .split(/[\s,]+/)
4023
+ .filter(Boolean)
4024
+ .map(w => MORE[w] ?? w);
4025
+ const known = (/** @type {string} */ w) =>
4026
+ HEADING_WEIGHTS[w] !== undefined || HEADING_TRACKING[w] !== undefined;
4027
+ if (
4028
+ (words.length > 1 || MORE[String(v).trim().toLowerCase()]) &&
4029
+ words.every(known)
4030
+ )
4031
+ refuse(
4032
+ E.ERR_THEME_BAD_VALUE,
4033
+ words.length > 1
4034
+ ? `"${v}" is ${words.length} headings values; headings takes one at a time (a weight and a tracking are two settings).`
4035
+ : `"${v}" is the weight ${words[0]}.`,
4036
+ {run: words.map(w => `${P} set ${slug} headings ${w}`)},
4037
+ );
4038
+ }
2134
4039
  if (s.mode)
2135
4040
  refuse(
2136
4041
  E.ERR_THEME_NO_MODE,
@@ -2168,17 +4073,17 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2168
4073
  ...Object.keys(HEADING_WEIGHTS),
2169
4074
  ...Object.keys(HEADING_TRACKING),
2170
4075
  ];
2171
- const weight = /^\d+(\.\d+)?$/.test(lower) ? Number(lower) : null;
4076
+ // A weight word (extra bold, ultra-bold) is its number, read as
4077
+ // the rung nearest it (800 is heavy).
4078
+ const weightWord = WEIGHT_WORDS[lower.replace(/[\s-]+/g, '')];
4079
+ const weight = /^\d+(\.\d+)?$/.test(lower)
4080
+ ? Number(lower)
4081
+ : weightWord
4082
+ ? Number(weightWord)
4083
+ : null;
2172
4084
  const meant =
2173
4085
  words.find(w => w === lower) ??
2174
- (weight != null
2175
- ? Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
2176
- Math.abs(Number(b[1]) - weight) <
2177
- Math.abs(Number(a[1]) - weight)
2178
- ? b
2179
- : a,
2180
- )[0]
2181
- : nearest(lower, words)[0]);
4086
+ (weight != null ? weightRung(weight) : nearest(lower, words)[0]);
2182
4087
  refuse(
2183
4088
  E.ERR_THEME_BAD_VALUE,
2184
4089
  `headings takes ${DIALS.headings.values}, not "${v}".${weight != null && meant ? ` ${meant} sets weight ${HEADING_WEIGHTS[meant]}.` : ''}`,
@@ -2248,10 +4153,16 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2248
4153
  (s.on && typeof def !== 'number' ? own('') : undefined) ??
2249
4154
  def;
2250
4155
  const at = L.findIndex(([n]) => n === cur);
4156
+ const stepped = at + (v === 'more' ? 1 : -1);
4157
+ if (at >= 0 && stepped >= 0 && stepped < L.length) return L[stepped][0];
4158
+ // At the last rung that way, a step goes nowhere: refused as every
4159
+ // dial refuses it at its end, with the other way.
2251
4160
  if (at >= 0)
2252
- return L[
2253
- Math.max(0, Math.min(L.length - 1, at + (v === 'more' ? 1 : -1)))
2254
- ][0];
4161
+ refuse(
4162
+ E.ERR_THEME_NO_EFFECT,
4163
+ `${thing} is already at its ${v === 'more' ? 'largest' : 'smallest'} step, ${L[at][0]}${s.on ? ` on ${s.on}` : ''}, so "${v}" has nowhere to go.`,
4164
+ {run: [setLine(slug, thing, v === 'more' ? 'less' : 'more', s)]},
4165
+ );
2255
4166
  // A size between rungs steps to the next rung that way, never past it.
2256
4167
  const px =
2257
4168
  typeof cur === 'number'
@@ -2279,7 +4190,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2279
4190
  );
2280
4191
  refuse(
2281
4192
  E.ERR_THEME_BAD_VALUE,
2282
- `${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go.${atEnd ? ` It is also the ${v === 'more' ? 'largest' : 'smallest'} size ${thing} takes (${lo} to ${hi}); the base font size token takes any size.` : ' Give an exact size.'}`,
4193
+ `${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${Math.abs(px - edge[1]) < 0.01 ? 'at' : v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go.${atEnd ? ` It is also the ${v === 'more' ? 'largest' : 'smallest'} size ${thing} takes (${lo} to ${hi}); the base font size token takes any size.` : ' Give an exact size.'}`,
2283
4194
  {
2284
4195
  run: atEnd
2285
4196
  ? [
@@ -2412,9 +4323,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2412
4323
  : cornerPxOf(onPart.value)
2413
4324
  : whole
2414
4325
  ? radiusAt(base, whole.value, token)
2415
- : // The base theme's radius; one it does not give in px (a var()
2416
- // chain) counts as medium's.
2417
- (tokenPx(base, token) ?? radiusAt(base, 'medium', token));
4326
+ : // The base theme's own radius on the part, when its rule
4327
+ // gives one; else the radius token's; one it does not give
4328
+ // in px (a var() chain) counts as medium's.
4329
+ (basePartRadiusPx(ctx, base, part, s.when) ??
4330
+ tokenPx(base, token) ??
4331
+ radiusAt(base, 'medium', token));
2418
4332
  const rungs = CORNERS.map(
2419
4333
  ([n]) => /** @type {const} */ ([n, radiusAt(base, n, token)]),
2420
4334
  );
@@ -2435,17 +4349,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2435
4349
  );
2436
4350
  s.value = next ? next[0] : 'medium';
2437
4351
  } else {
4352
+ // A value with copy debris (`8px;`): the value without it.
4353
+ if (withoutCopyDebris(v) !== v && withoutCopyDebris(v))
4354
+ refuse(
4355
+ E.ERR_THEME_BAD_VALUE,
4356
+ `"${v}" holds copy debris (a ;, a comment or !important); corners takes the value alone.`,
4357
+ {run: [setLine(slug, 'corners', withoutCopyDebris(v), s)]},
4358
+ );
2438
4359
  // A rung in any case, a size in px written any way: the plain form.
2439
4360
  const lower = v.toLowerCase();
2440
- // Any CSS number in px (2e1px, +4px), the shared length parse.
2441
- const pxLen = /px$/.test(lower) ? lengthPx(lower) : null;
2442
- if (CORNERS.some(([n]) => n === lower)) s.value = lower;
2443
- else if (pxLen != null && pxLen >= 0)
2444
- s.value =
2445
- pxLen >= 1000 ? 'pill' : `${Math.round(pxLen * 10000) / 10000}px`;
4361
+ // Any CSS number in px (2e1px, +4px), the shared length parse; a
4362
+ // rem is that many 16px, saved in px (the one reading, cornersPlain,
4363
+ // which the settings reader gives a saved value too).
4364
+ const plain = cornersPlain(v);
4365
+ if (plain) {
4366
+ s.value = plain;
4367
+ if (/rem$/.test(lower))
4368
+ s.note = `corners ${v.trim()} is saved as ${s.value}`;
4369
+ }
2446
4370
  // No rounding, said any way, is square.
2447
- else if (/^(0|0%|none|sharp|zero|no|flat)$/.test(lower))
2448
- s.value = 'square';
4371
+ else if (NO_ROUNDING.includes(lower)) s.value = 'square';
2449
4372
  else {
2450
4373
  // What it most likely means, as a value corners takes: a simple
2451
4374
  // calc() of px is worked out.
@@ -2461,14 +4384,31 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2461
4384
  '-': Number(calc[1]) - Number(calc[3]),
2462
4385
  }[/** @type {'*' | '/' | '+' | '-'} */ (calc[2])]
2463
4386
  : null;
4387
+ // A bare number (0.5, as a pasted --radius: 0.5rem loses its
4388
+ // unit) has no unit to read it by: no size is guessed.
4389
+ const bareNumber = /^[+-]?\d*\.?\d+$/.test(lower);
2464
4390
  const len =
2465
4391
  calcPx != null && Number.isFinite(calcPx)
2466
4392
  ? calcPx
2467
- : lengthPx(lower);
4393
+ : bareNumber
4394
+ ? null
4395
+ : lengthPx(lower);
2468
4396
  const pct = /^(\d+(?:\.\d+)?)%$/.exec(lower);
4397
+ // Tailwind's names, and rounding said with a negation: what they
4398
+ // mean (rounded-none and not round are square, rounded-full is
4399
+ // pill, rounded-[12px] is 12px).
4400
+ const tw = /^rounded-\[(.+)\]$/.exec(lower)?.[1];
4401
+ const opposite =
4402
+ TAILWIND_RADIUS[lower] ??
4403
+ (tw && lengthPx(tw) != null
4404
+ ? `${Math.round(Number(lengthPx(tw)) * 100) / 100}px`
4405
+ : negates(lower) && /round/.test(lower)
4406
+ ? 'square'
4407
+ : null);
2469
4408
  // A radius below zero means none: square.
2470
4409
  const meant =
2471
- len != null
4410
+ opposite ??
4411
+ (len != null
2472
4412
  ? len <= 0
2473
4413
  ? 'square'
2474
4414
  : `${Math.round(len * 100) / 100}px`
@@ -2476,17 +4416,34 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2476
4416
  ? Number(pct[1]) >= 50
2477
4417
  ? 'pill'
2478
4418
  : null
2479
- : (nearest(
2480
- lower,
2481
- CORNERS.map(([n]) => n),
2482
- )[0] ?? null);
4419
+ : bareNumber
4420
+ ? null
4421
+ : (nearest(
4422
+ lower,
4423
+ CORNERS.map(([n]) => n),
4424
+ )[0] ?? null));
2483
4425
  refuse(
2484
4426
  E.ERR_THEME_BAD_VALUE,
2485
- `corners takes ${DIALS.corners.values}, not "${v}".`,
4427
+ `corners takes ${DIALS.corners.values}, not "${v}"${bareNumber ? ' (a number needs its unit: px or rem)' : ''}.`,
2486
4428
  {
2487
4429
  ...(meant ? {didYouMean: [meant]} : {}),
2488
4430
  // The same scope, flags included.
2489
- run: [setLine(slug, 'corners', meant ?? 'medium', s)],
4431
+ // Nothing near: how corners, never a stock rung.
4432
+ // A whole bare number gets the line with px, the unit it
4433
+ // most likely meant, and how corners; one below one (a
4434
+ // pasted 0.5rem that lost its unit) has no unit to read it
4435
+ // by: how corners only.
4436
+ run:
4437
+ bareNumber && Number(lower) >= 1
4438
+ ? [
4439
+ setLine(slug, 'corners', `${Number(lower)}px`, s),
4440
+ `${HOW} corners`,
4441
+ ]
4442
+ : [
4443
+ meant
4444
+ ? setLine(slug, 'corners', meant, s)
4445
+ : `${HOW} corners`,
4446
+ ],
2490
4447
  },
2491
4448
  );
2492
4449
  }
@@ -2547,7 +4504,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2547
4504
  run: [setLine(slug, 'spacing', nearFactor, s)],
2548
4505
  },
2549
4506
  );
2550
- else if (/^(0|none|zero|no|off)$/i.test(v))
4507
+ else if (NO_SPACE.includes(v.toLowerCase()))
2551
4508
  // Spacing scales the theme's space; it never goes to nothing. The
2552
4509
  // tightest rung is the nearest that works.
2553
4510
  refuse(
@@ -2568,15 +4525,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2568
4525
  SPACING.map(([n]) => n),
2569
4526
  ),
2570
4527
  run: [
2571
- setLine(
2572
- slug,
2573
- 'spacing',
2574
- nearest(
4528
+ (() => {
4529
+ const near = nearest(
2575
4530
  v,
2576
4531
  SPACING.map(([n]) => n),
2577
- )[0] ?? 'roomy',
2578
- s,
2579
- ),
4532
+ )[0];
4533
+ return near
4534
+ ? setLine(slug, 'spacing', near, s)
4535
+ : `${HOW} spacing`;
4536
+ })(),
2580
4537
  ],
2581
4538
  },
2582
4539
  );
@@ -2601,7 +4558,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2601
4558
  })(),
2602
4559
  },
2603
4560
  );
2604
- if (step) s.value = ladder(TEXT_SIZE, 'medium');
4561
+ // With no text-size setting yet, a step starts from the size the base
4562
+ // theme's body text shows (past the last rung, it asks for a size).
4563
+ if (step)
4564
+ s.value = ladder(TEXT_SIZE, ctx.base ? baseTextPx(ctx.base) : 'medium');
2605
4565
  else if (
2606
4566
  /^\d+\.\d+$/.test(v.trim()) &&
2607
4567
  Number(v) >= 10 &&
@@ -2620,7 +4580,11 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2620
4580
  E.ERR_THEME_BAD_VALUE,
2621
4581
  `text-size takes ${DIALS['text-size'].values} (a number is the body size in pixels, 10 to 32), not "${v}".`,
2622
4582
  (() => {
2623
- // A rung in other letter case (Medium) or with px is that rung.
4583
+ // A rung in other letter case (Medium) or with px is that rung;
4584
+ // a CSS size keyword (x-large) is the size CSS gives it.
4585
+ const keyword = CSS_SIZE_KEYWORDS[v.trim().toLowerCase()];
4586
+ if (keyword != null && keyword >= 10 && keyword <= 32)
4587
+ return {run: [`${P} set ${slug} text-size ${keyword}`]};
2624
4588
  const near =
2625
4589
  TEXT_SIZE.find(([n]) => n === v.trim().toLowerCase())?.[0] ??
2626
4590
  nearest(
@@ -2632,19 +4596,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2632
4596
  didYouMean: [near],
2633
4597
  run: [`${P} set ${slug} text-size ${near}`],
2634
4598
  }
2635
- : {
2636
- run: [
2637
- `${P} set ${slug} text-size ${
2638
- // A size typed full-width or with a trailing dot
2639
- // (18, 18.) is that size.
2640
- /^\d+(\.\d+)?\.?$/.test(typedPlain(v)) &&
2641
- Number(typedPlain(v).replace(/\.$/, '')) >= 10 &&
2642
- Number(typedPlain(v).replace(/\.$/, '')) <= 32
2643
- ? String(Number(typedPlain(v).replace(/\.$/, '')))
2644
- : (textSizePx(v) ?? 16)
2645
- }`,
2646
- ],
2647
- };
4599
+ : (() => {
4600
+ // A size typed full-width or with a trailing dot
4601
+ // (18, 18.) is that size; one read any other way (a
4602
+ // unit, a constant calc()) is that size. Nothing read:
4603
+ // how text-size, never a stock size.
4604
+ const t = typedPlain(v).replace(/\.$/, '');
4605
+ const size =
4606
+ /^\d+(\.\d+)?$/.test(t) &&
4607
+ Number(t) >= 10 &&
4608
+ Number(t) <= 32
4609
+ ? String(Number(t))
4610
+ : textSizePx(v);
4611
+ return {
4612
+ run: [
4613
+ size != null
4614
+ ? `${P} set ${slug} text-size ${size}`
4615
+ : `${HOW} text-size`,
4616
+ ],
4617
+ };
4618
+ })();
2648
4619
  })(),
2649
4620
  );
2650
4621
  else if (!TEXT_SIZE.some(([n]) => n === v))
@@ -2665,13 +4636,51 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2665
4636
  .replace(/\s*!important\s*$/i, '')
2666
4637
  .replace(/;+\s*$/, '')
2667
4638
  .trim()
2668
- .replace(/^([0-9a-f]{3}|[0-9a-f]{6})$/i, '#$1')
2669
- // One hex digit short or over: repeat or drop the last one.
2670
- .replace(/^#([0-9a-f]{4})([0-9a-f])$/i, '#$1$2$2')
2671
- .replace(/^#([0-9a-f]{6})[0-9a-f]$/i, '#$1');
4639
+ // A hex written 0x… (as in code) is that hex.
4640
+ .replace(/^0x([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, '#$1')
4641
+ .replace(/^([0-9a-f]{3}|[0-9a-f]{6})$/i, '#$1');
4642
+ // A hex a digit short or over is refused as it is: the digit
4643
+ // missing could be anywhere, so none is made up.
4644
+ // A name of several words with a color among them (`navy blue`)
4645
+ // is that color.
4646
+ // Two names run together (`navyblue`) are the first, as the
4647
+ // spaced form is.
4648
+ const words = v
4649
+ .toLowerCase()
4650
+ .split(/[\s,-]+/)
4651
+ .filter(Boolean);
4652
+ // The words joined (dark red, light-blue, dark-slate-gray) are the
4653
+ // color they name. A word with a scale step (red-500, gray-900) is
4654
+ // no CSS color, and the bare word is another color: none is named.
4655
+ const joined = words.join('');
4656
+ const scaled = words.some(w => /\d/.test(w)) || /^[{]/.test(v.trim());
4657
+ const named =
4658
+ negates(v) || scaled
4659
+ ? []
4660
+ : words.length > 1 && COLOR_NAMES.includes(joined)
4661
+ ? [joined]
4662
+ : v
4663
+ .toLowerCase()
4664
+ .split(/[\s,-]+/)
4665
+ .flatMap(w =>
4666
+ COLOR_NAMES.includes(w)
4667
+ ? [w]
4668
+ : COLOR_NAMES.filter(
4669
+ n =>
4670
+ n.length >= 3 &&
4671
+ w.startsWith(n) &&
4672
+ COLOR_NAMES.includes(w.slice(n.length)),
4673
+ ).slice(0, 1),
4674
+ );
2672
4675
  const near =
2673
4676
  problem.kind === 'unknown'
2674
- ? nearest(v.toLowerCase(), COLOR_NAMES)
4677
+ ? /^#?[0-9a-f]{4,8}$/i.test(v.trim())
4678
+ ? []
4679
+ : named.length
4680
+ ? named.slice(0, 1)
4681
+ : scaled
4682
+ ? []
4683
+ : nearest(v.toLowerCase(), COLOR_NAMES)
2675
4684
  : [];
2676
4685
  // light-dark(a, b): the dial takes one color, from which it makes
2677
4686
  // both modes; the light one is offered.
@@ -2730,17 +4739,32 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2730
4739
  const colors = data.settings.filter(
2731
4740
  x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing),
2732
4741
  );
2733
- // With no color to saturate, no vibrancy value is suggested.
2734
- const canApply = colors.some(x => !isGraySeed(seedOf(x.value)));
4742
+ // With no color to saturate, no vibrancy value is suggested. A color
4743
+ // counts when vibrancy changes the shades made from it at all (a warm
4744
+ // gray has a little hue to take out or add; a pure gray has none).
4745
+ const canApply = colors.some(x =>
4746
+ vibrancyMoves(x.thing, seedOf(x.value), 0, 100),
4747
+ );
2735
4748
  if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
2736
4749
  // The value meant: a step in other letters (MORE), or the number
2737
4750
  // read as CSS reads it (70%, 7e1), kept in range.
2738
- const word = v.trim().toLowerCase();
2739
- const n = cssNumber(v);
4751
+ // Quotes around it (`"50"`) are not part of it.
4752
+ const bare = v
4753
+ .trim()
4754
+ .replace(/^(["'])(.*)\1$/, '$2')
4755
+ .trim();
4756
+ const word = bare.toLowerCase();
4757
+ const n = cssNumber(bare);
4758
+ // A fraction of one (0.5) is that share of the scale (50), as a
4759
+ // number with no unit from 0 to 1 is read.
4760
+ const scaled =
4761
+ n && n.unit === '' && n.value > 0 && n.value < 1
4762
+ ? n.value * 100
4763
+ : n?.value;
2740
4764
  const near = ['more', 'less'].includes(word)
2741
4765
  ? word
2742
- : n && (n.unit === '' || n.unit === '%')
2743
- ? String(Math.max(0, Math.min(100, Math.round(n.value))))
4766
+ : n && (n.unit === '' || n.unit === '%') && scaled != null
4767
+ ? String(Math.max(0, Math.min(100, Math.round(scaled))))
2744
4768
  : null;
2745
4769
  refuse(
2746
4770
  E.ERR_THEME_BAD_VALUE,
@@ -2757,9 +4781,25 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2757
4781
  refuse(
2758
4782
  E.ERR_THEME_NO_EFFECT,
2759
4783
  colors.length
2760
- ? 'vibrancy sets how saturated the generated colors are, and every color this theme sets is a gray, so it would change nothing. Set a color first.'
2761
- : 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.',
2762
- {run: [`${P} set ${slug} accent ${quoteCommandArgument('#7c3aed')}`]},
4784
+ ? `vibrancy sets how saturated the generated colors are, and every color this theme sets (${colors.map(x => `${x.thing} ${x.value}`).join(', ')}) comes out the same at every vibrancy: a gray with no hue to change, so it would change nothing. Set a color first.`
4785
+ : (() => {
4786
+ // Colors set as tokens or on parts are values of their own:
4787
+ // vibrancy saturates only what the color dials make.
4788
+ const own = data.settings.find(
4789
+ (/** @type {any} */ x) =>
4790
+ x &&
4791
+ typeof x.value === 'string' &&
4792
+ (/^--color-/.test(String(x.thing)) ||
4793
+ /(^|-)colou?r$|^background(-color)?$|^fill$/.test(
4794
+ String(x.thing),
4795
+ )) &&
4796
+ parseColor(x.value) != null,
4797
+ );
4798
+ return own
4799
+ ? `vibrancy sets how saturated the colors made from the color dials (accent, neutral, …) are; this theme's colors are values of their own (${own.thing} ${own.value}), which vibrancy does not change. Set a color dial such as accent first.`
4800
+ : 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.';
4801
+ })(),
4802
+ {run: [`${HOW} accent`]},
2763
4803
  );
2764
4804
  } else if (thing === 'font') {
2765
4805
  if (s.when || s.state)
@@ -2789,7 +4829,9 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2789
4829
  )
2790
4830
  : family
2791
4831
  ? [
2792
- `${P} set ${slug} font-family ${quoteCommandArgument(v)} --on ${s.on}`,
4832
+ // A font dial word (mono, system, inter) names no family:
4833
+ // the part takes the stack it stands for.
4834
+ `${P} set ${slug} font-family ${quoteCommandArgument(fontStack(v) ?? v)} --on ${s.on}`,
2793
4835
  ]
2794
4836
  : [example];
2795
4837
  refuse(
@@ -2955,6 +4997,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2955
4997
  {run: [`${P} set ${slug} font inter`]},
2956
4998
  );
2957
4999
  } else if (thing === 'base') {
5000
+ // A built-in base this project has not installed: install it, then
5001
+ // the same set.
5002
+ // A theme that builds on a base keeps it by changing nothing: no
5003
+ // base is offered only to a theme on none.
5004
+ if (LIKE.includes(v) && !unset && !baseInstalled(ctx.project, v))
5005
+ throw new AstryxError(
5006
+ `The ${v} theme is not installed, so ${slug} cannot build on it. Install @astryxdesign/theme-${v}, then set the base again${data.like ? `; ${slug} stays on ${data.like} until then` : ', or build on no theme'}. Nothing was changed.`,
5007
+ [
5008
+ ...onBuiltInSteps(ctx.project.cwd, v, `${P} set ${slug} base ${v}`),
5009
+ ...(data.like
5010
+ ? []
5011
+ : [
5012
+ {
5013
+ name: `${P} set ${slug} base none`,
5014
+ reason: 'build on no theme',
5015
+ },
5016
+ ]),
5017
+ ],
5018
+ E.ERR_UNKNOWN_THEME,
5019
+ );
2958
5020
  if (s.on)
2959
5021
  refuse(
2960
5022
  E.ERR_THEME_BAD_VALUE,
@@ -2963,12 +5025,13 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2963
5025
  );
2964
5026
  if (![...LIKE, 'none'].includes(v)) {
2965
5027
  // `NEUTRAL`, `base=neutral`, `None`: the base meant.
2966
- const meant = v
2967
- .toLowerCase()
2968
- .replace(/^base\s*[=:]\s*/, '')
2969
- .trim()
2970
- .replace(/^@astryxdesign\/theme-/, '')
2971
- .replace(/^theme-/, '');
5028
+ // Read from the value as typed: its letters' case marks an export
5029
+ // name (neutralTheme).
5030
+ const meant = baseWord(
5031
+ String(value ?? v)
5032
+ .trim()
5033
+ .replace(/^base\s*[=:]\s*/i, ''),
5034
+ );
2972
5035
  // Only a base this project has installed is suggested; a theme
2973
5036
  // made here is never a base.
2974
5037
  const bases = [
@@ -3053,16 +5116,46 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3053
5116
  ],
3054
5117
  },
3055
5118
  );
5119
+ // A dial typed as a flag (--corners round): the dial is meant.
5120
+ const dial = thing.replace(/^-+/, '');
5121
+ if (
5122
+ !(thing in TOKENS) &&
5123
+ (dial in DIALS || dial === 'base' || dial === 'mode')
5124
+ )
5125
+ refuse(
5126
+ E.ERR_THEME_UNKNOWN_TOKEN,
5127
+ `"${thing}" is not a design token; ${dial} is a dial, typed without dashes.`,
5128
+ {
5129
+ run: [setLine(slug, dial, v, {...s, mode: undefined}, unset)],
5130
+ },
5131
+ );
3056
5132
  if (!(thing in TOKENS)) {
3057
- refuse(E.ERR_THEME_UNKNOWN_TOKEN, `"${thing}" is not a design token.`, {
3058
- didYouMean: nearest(thing, Object.keys(TOKENS)),
3059
- run: [
3060
- `${HOW} --list tokens ${thing
3061
- .replace(/^-+(color-)?/, '')
3062
- .split('-')[0]
3063
- .trim()}`.trim(),
3064
- ],
3065
- });
5133
+ // The editor's own color words: danger is the error role, brand and
5134
+ // primary are the accent (as the danger and accent dials say).
5135
+ const role = thing
5136
+ .replace(/\bdanger\b/, 'error')
5137
+ .replace(/\b(brand|primary)\b/, 'accent');
5138
+ const aliased = role !== thing && role in TOKENS ? role : null;
5139
+ // The filtered list only when it lists something.
5140
+ const word = thing
5141
+ .replace(/^-+(color-)?/, '')
5142
+ .split('-')[0]
5143
+ .trim();
5144
+ const listed =
5145
+ word && Object.keys(TOKENS).some(k => k.includes(word))
5146
+ ? `${HOW} --list tokens ${word}`
5147
+ : `${HOW} --list tokens`;
5148
+ refuse(
5149
+ E.ERR_THEME_UNKNOWN_TOKEN,
5150
+ `"${thing}" is not a design token.${aliased ? ` The token for that role is ${aliased}.` : ''}`,
5151
+ {
5152
+ didYouMean: aliased ? [aliased] : nearest(thing, Object.keys(TOKENS)),
5153
+ run: [
5154
+ ...(aliased ? [setLine(slug, aliased, v, s, unset)] : []),
5155
+ listed,
5156
+ ],
5157
+ },
5158
+ );
3066
5159
  }
3067
5160
  const type = C.typeOf(thing);
3068
5161
  // Only colors differ by mode: a shadow list cannot sit inside
@@ -3097,6 +5190,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3097
5190
  slug,
3098
5191
  C.propsReading(thing),
3099
5192
  multipliedTokens(ctx.project).has(thing),
5193
+ data.settings.some(x => x.thing === thing),
3100
5194
  );
3101
5195
  checkCycle(thing, v, TOKENS, data, ctx.project.cwd, s);
3102
5196
  // With no part data, what reads the token is unknown: save, unchecked.
@@ -3172,7 +5266,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3172
5266
  const instead = /reads: ([^.]+)\./.exec(
3173
5267
  String(/** @type {any} */ (hard[0][1])?.message ?? ''),
3174
5268
  )?.[1];
3175
- s.note = `${readers.length ? `${readers.join(', ')} read ${thing} and take this change; ` : ''}the editor's render of ${hard.map(([t]) => t).join(', ')} did not read it${instead ? ` (${hard[0][0]} reads ${instead})` : ''}, so those stay as they were; each part is rendered once, with its default props, so a variant that reads it may be missed`;
5269
+ s.note = `${readers.length ? `${readers.join(', ')} read ${thing} and take this change; ` : ''}the editor's render of ${hard.map(([t]) => t).join(', ')} did not read it${instead ? ` (${hard[0][0]} reads ${instead})` : ''}, so those stay as they were; each part is rendered with its default props, each variant value and each look flag, so a state or a combination that reads it may be missed`;
3176
5270
  }
3177
5271
  if (!s.note && recorded.length) {
3178
5272
  const fed = C.feeds(recorded[0][0], thing);
@@ -3201,6 +5295,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3201
5295
  s.note = `no part reads ${thing} itself, but ${fed.slice(0, 4).join(', ')} ${fed.length > 1 ? 'are' : 'is'} built from it, so the change shows wherever ${fed.length > 1 ? 'those are' : 'that is'} used${fed.some(k => k.startsWith('--color-syntax-')) ? ' (such as diff rows in code blocks)' : ''}`;
3202
5296
  else if (r && data.like && baseReads(ctx, data.like, thing))
3203
5297
  s.note = `the ${data.like} theme's own part styles read ${thing}, so the change shows where they use it`;
5298
+ else if (r && coreStylesRead(ctx, thing))
5299
+ s.note = `Core's stylesheet reads ${thing} outside the parts the editor renders (such as the page behind them, the app shell), so the change shows where it is used`;
3204
5300
  else if (r && dialWrites(thing))
3205
5301
  s.note = `no part of this Core reads ${thing}, and no token it feeds is read, so it changes nothing you see now; it is set as asked because a dial writes it too`;
3206
5302
  // The editor's record of what parts read comes from one render of
@@ -3208,11 +5304,17 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3208
5304
  // token is set as asked, and the result says nothing was seen
3209
5305
  // reading it.
3210
5306
  else if (r)
3211
- s.note = `no part the editor rendered reads ${thing} (each part is rendered once, with its default props, so a variant that reads it may be missed); it is set as asked, and reaches any part that reads it`;
5307
+ s.note = `no part the editor rendered reads ${thing} (each part is rendered with its default props, each variant value and each look flag, so a state or a combination that reads it may be missed); it is set as asked, and reaches any part that reads it`;
3212
5308
  }
3213
5309
  return s;
3214
5310
  }
3215
- const prop = kebab(thing);
5311
+ // A property in camel case, or with `_` or spaces for its dashes
5312
+ // (backgroundColor, font_size, "border radius"), is that property: one
5313
+ // reading, so each form gets the same answer.
5314
+ const spelled = kebab(thing.trim())
5315
+ .replace(/[_\s]+/g, '-')
5316
+ .replace(/-+/g, '-');
5317
+ const prop = cssProperties().has(spelled) ? spelled : kebab(thing);
3216
5318
  // A token typed without its leading dashes (color-accent,
3217
5319
  // text-body-size): the token, when no CSS property has that name.
3218
5320
  if (
@@ -3252,39 +5354,43 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3252
5354
  E.ERR_MISSING_ARGUMENT,
3253
5355
  `${prop} is a CSS property, so it needs --on <part|group>. For the whole theme use a dial or a token.`,
3254
5356
  {
5357
+ // The theme-wide dial or token for it, when there is one; never
5358
+ // a part that was not named.
3255
5359
  run: [
3256
- `${P} set ${slug} ${prop} ${quoteCommandArgument(v || exampleOf(groupOfPropType(prop), prop))} --on card`,
3257
- `${HOW} "${prop}"`,
5360
+ ...(v && WHOLE_THEME_EQUIVALENT[prop]
5361
+ ? [
5362
+ `${P} set ${slug} ${WHOLE_THEME_EQUIVALENT[prop]} ${quoteCommandArgument(v)}`,
5363
+ ]
5364
+ : []),
5365
+ `${HOW} ${quoteCommandArgument(prop)}`,
3258
5366
  ],
3259
5367
  },
3260
5368
  );
3261
5369
  s.source = 'property';
3262
5370
  s.thing = prop;
3263
5371
  if (unset) return s;
3264
- // A length property (padding, a corner radius, a gap) that reads a
3265
- // design token of another kind (a color, a font, a duration) gets
5372
+ // A property that reads a design token of a kind it does not take (a
5373
+ // color property reading a size, a length reading a color) gets
3266
5374
  // nothing the browser keeps: refused like the token form.
3267
- if (matchValue(prop, '1px') && !matchValue(prop, 'red'))
3268
- for (const m of v.matchAll(/var\(\s*(--[a-z0-9-]+)/gi)) {
3269
- const kind = ctx.C.isToken(m[1]) ? ctx.C.typeOf(m[1]) : null;
3270
- if (kind && !['size', 'number', 'other'].includes(kind)) {
3271
- const like = /radius/.test(prop)
3272
- ? 'var(--radius-container)'
3273
- : /^(padding|margin|gap|row-gap|column-gap|inset)/.test(prop)
3274
- ? 'var(--spacing-4)'
3275
- : exampleOf('size', prop);
3276
- refuse(
3277
- E.ERR_THEME_BAD_VALUE,
3278
- `${prop} takes a length; ${m[1]} is a ${kind}, so the browser would drop it.`,
3279
- {
3280
- run: [
3281
- `${P} set ${slug} ${prop} ${quoteCommandArgument(v.replace(new RegExp(`var\\(\\s*${m[1]}\\s*(,[^)]*)?\\)`, 'i'), like))} --on ${quoteCommandArgument(String(s.on))}${s.state ? ` --state ${s.state}` : ''}${s.when ? ` --when ${quoteCommandArgument(s.when)}` : ''}${s.mode ? ` --mode ${s.mode}` : ''}`,
3282
- `${HOW} --list tokens ${/radius/.test(prop) ? 'radius' : 'spacing'}`,
3283
- ],
3284
- },
3285
- );
3286
- }
3287
- }
5375
+ const mismatch = tokenKindMismatch(ctx, prop, v);
5376
+ if (mismatch) {
5377
+ const length = mismatch.takes === 'a length';
5378
+ const like = /radius/.test(prop)
5379
+ ? 'var(--radius-container)'
5380
+ : /^(padding|margin|gap|row-gap|column-gap|inset)/.test(prop)
5381
+ ? 'var(--spacing-4)'
5382
+ : null;
5383
+ refuse(E.ERR_THEME_BAD_VALUE, `${mismatch.message}.`, {
5384
+ run: [
5385
+ ...(length && like
5386
+ ? [
5387
+ `${P} set ${slug} ${prop} ${quoteCommandArgument(v.replace(new RegExp(`var\\(\\s*${mismatch.token}\\s*(,[^)]*)?\\)`, 'i'), like))} --on ${quoteCommandArgument(String(s.on))}${s.state ? ` --state ${s.state}` : ''}${s.when ? ` --when ${quoteCommandArgument(s.when)}` : ''}${s.mode ? ` --mode ${s.mode}` : ''}`,
5388
+ ]
5389
+ : []),
5390
+ `${HOW} --list tokens ${length ? (/radius/.test(prop) ? 'radius' : 'spacing') : mismatch.takes === 'a color' ? 'color' : ''}`.trimEnd(),
5391
+ ],
5392
+ });
5393
+ }
3288
5394
  // initial and unset leave a part's padding variables without a value:
3289
5395
  // the part takes Core's own default, which the result names.
3290
5396
  if (
@@ -3374,9 +5480,141 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3374
5480
  },
3375
5481
  );
3376
5482
  }
5483
+ // A property Core paints with an inline style from a token outranks any
5484
+ // theme rule for it: the token the inline style reads is what changes it.
5485
+ // A paint Core always makes (an indicator's focus ring) is changed by the
5486
+ // token on the part with no state. A paint in a state (a selected table
5487
+ // row's wash) is changed by the token in that state; a component option
5488
+ // can turn that paint off (a table without its row highlight), and then
5489
+ // a rule in the state applies, so the refusal says both.
5490
+ if (!unset) {
5491
+ const family =
5492
+ prop === 'background' || prop === 'background-color'
5493
+ ? 'background-color'
5494
+ : prop;
5495
+ const inline = partsOf(ctx, s)
5496
+ .map(t => {
5497
+ const at = ctx.C.MAP[t]?.inline ?? {};
5498
+ const tok =
5499
+ (s.state ? at[s.state]?.[family] : undefined) ?? at['']?.[family];
5500
+ return /** @type {const} */ ([t, tok]);
5501
+ })
5502
+ .find(([, tok]) => tok);
5503
+ if (inline) {
5504
+ const [part, token] = inline;
5505
+ const alwaysInline = Boolean(ctx.C.MAP[part]?.inline?.['']?.[family]);
5506
+ refuse(
5507
+ E.ERR_THEME_NO_EFFECT,
5508
+ alwaysInline
5509
+ ? `Core paints ${part}'s ${family} as an inline style from ${token}, which no theme rule can replace; set ${token} on ${part} instead.`
5510
+ : `By default Core paints ${part}'s ${family} when ${s.state} as an inline style from ${token}, which no theme rule can replace, so set ${token} on ${part} when ${s.state} instead; only where the component is set not to paint it (such as a table with its row highlight off) does a ${s.state} ${family} apply, and there ${token} paints nothing.`,
5511
+ {
5512
+ run: [
5513
+ `${P} set ${slug} ${token} ${quoteCommandArgument(v)} --on ${part}${alwaysInline || !s.state ? '' : ` --state ${s.state}`}${s.mode ? ` --mode ${s.mode}` : ''}`,
5514
+ ],
5515
+ },
5516
+ );
5517
+ }
5518
+ }
5519
+ // A border on a part that draws none itself, whose edges are drawn by
5520
+ // parts of its own inside it (a date-time input's date and time boxes):
5521
+ // those parts take it.
5522
+ if (
5523
+ !unset &&
5524
+ /^border(?!.*radius)(-|$)/.test(prop) &&
5525
+ partsOf(ctx, s).length === 1
5526
+ ) {
5527
+ const part = partsOf(ctx, s)[0];
5528
+ const own = ctx.C.MAP[part]?.own ?? {};
5529
+ const inner = cornerParts(ctx, part).filter(t => t !== part);
5530
+ if (
5531
+ inner.length &&
5532
+ !Object.keys(own).some(k => /^border(?!.*radius)/.test(k))
5533
+ )
5534
+ refuse(
5535
+ E.ERR_THEME_NO_EFFECT,
5536
+ `${part} draws no border of its own; its edges are the borders of ${inner.join(' and ')}, so set ${prop} on ${inner.length > 1 ? 'those parts' : 'that part'}.`,
5537
+ {
5538
+ run: inner.map(t =>
5539
+ setLine(slug, prop, v, {...s, on: t, only: undefined}),
5540
+ ),
5541
+ },
5542
+ );
5543
+ }
5544
+ // Padding on a part Core renders as a box CSS draws no padding on (a
5545
+ // table row): the parts inside it with padding of their own take it.
5546
+ if (
5547
+ !unset &&
5548
+ /^padding(-|$)/.test(prop) &&
5549
+ !s.state &&
5550
+ partsOf(ctx, s).length === 1
5551
+ ) {
5552
+ const part = partsOf(ctx, s)[0];
5553
+ const inner = paddedParts(ctx, part).filter(t => t !== part);
5554
+ if (inner.length)
5555
+ refuse(
5556
+ E.ERR_THEME_NO_EFFECT,
5557
+ `${part} is drawn as a table row, row group or column, which CSS draws no padding on; its space is the padding of ${inner.join(' and ')}, so set ${prop} on ${inner.length > 1 ? 'those parts' : 'that part'}.`,
5558
+ {
5559
+ run: inner.map(t =>
5560
+ setLine(slug, prop, v, {...s, on: t, only: undefined}),
5561
+ ),
5562
+ },
5563
+ );
5564
+ }
5565
+ // A text property on a part whose text is drawn by elements inside it
5566
+ // that set that property themselves from a token (a top nav heading's
5567
+ // title span) never reaches that text: the token, on the part, does.
5568
+ if (
5569
+ !unset &&
5570
+ !s.state &&
5571
+ ['font-size', 'font-weight', 'line-height', 'letter-spacing'].includes(
5572
+ prop,
5573
+ )
5574
+ ) {
5575
+ const inner = partsOf(ctx, s)
5576
+ .map(t => {
5577
+ const rec = ctx.C.MAP[t];
5578
+ const toks = Object.entries(rec?.inside ?? {})
5579
+ .filter(([, props]) => props.includes(prop))
5580
+ .map(([tok]) => tok);
5581
+ return /** @type {const} */ ([
5582
+ t,
5583
+ rec && !rec.own?.[prop] ? toks : [],
5584
+ ]);
5585
+ })
5586
+ .filter(([, toks]) => toks.length);
5587
+ if (inner.length && inner.length === partsOf(ctx, s).length) {
5588
+ const [part, toks] = inner[0];
5589
+ refuse(
5590
+ E.ERR_THEME_NO_EFFECT,
5591
+ `${part}'s text is drawn by elements inside it that set their own ${prop} from ${toks.join(', ')}, so a ${prop} on ${part} never reaches it; set ${toks.length > 1 ? 'one of those tokens' : 'that token'} on ${part} instead.`,
5592
+ {
5593
+ run: toks.map(
5594
+ tok =>
5595
+ `${P} set ${slug} ${tok} ${quoteCommandArgument(v)} --on ${part}`,
5596
+ ),
5597
+ },
5598
+ );
5599
+ }
5600
+ }
5601
+ // A text property CSS inherits reaches the parts inside the part that
5602
+ // do not set it themselves (a side nav section's items): the result
5603
+ // says which.
5604
+ if (!unset) {
5605
+ const reach = inheritedReach(ctx, s, prop);
5606
+ if (reach) s.note = reach;
5607
+ }
3377
5608
  // Text, headings and links take their color from the color prop.
3378
5609
  const textParts = COLOR_PROP_PARTS;
5610
+ // A heading's color is written as the text color tokens its color prop
5611
+ // reads, on the heading alone (compileTheme), so it shows.
5612
+ const headingColor =
5613
+ prop === 'color' &&
5614
+ partsOf(ctx, s).length > 0 &&
5615
+ partsOf(ctx, s).every(t => t === 'heading');
3379
5616
  if (
5617
+ !headingColor &&
3380
5618
  (prop === 'color' || prop === '-webkit-text-fill-color') &&
3381
5619
  partsOf(ctx, s).some(t => textParts.includes(t))
3382
5620
  ) {
@@ -3388,84 +5626,47 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3388
5626
  v && isColorValue(v) && isFixedColor(v) && !/\bvar\(/i.test(v)
3389
5627
  ? v
3390
5628
  : (nearestColorName(v) ?? '#1f2937');
5629
+ // The tokens the part's color prop reads: the one named, else the
5630
+ // prop's default as its doc gives it (a link's accent), else each
5631
+ // color whose token the part reads (Text's depends on its type),
5632
+ // set on the part alone.
5633
+ const colors = named
5634
+ ? [named]
5635
+ : colorPropDefaults(
5636
+ partComponentDocs(ctx, /** @type {string} */ (s.on))
5637
+ .map(d => d.doc.props?.color)
5638
+ .find(Boolean),
5639
+ ctx.C.MAP[/** @type {string} */ (s.on)]?.own?.color?.tokens,
5640
+ );
5641
+ const tail = `${s.on ? ` --on ${s.on}` : ''}${s.mode ? ` --mode ${s.mode}` : ''}`;
3391
5642
  refuse(
3392
5643
  E.ERR_THEME_NO_EFFECT,
3393
- `${s.on} takes its color from the color prop, which Core sets after part styles, so a color set on ${s.on} never shows. Set the text color token instead.`,
5644
+ `${s.on} takes its color from the color prop, which Core sets after part styles, so a color set on ${s.on} never shows. Set the token its color prop reads (${colors.map(c => `${c}: --color-text-${c}`).join('; ')}) on ${s.on} instead.`,
3394
5645
  {
3395
- run: [
3396
- `${P} set ${slug} --color-text-${named ?? 'primary'} ${quoteCommandArgument(color)}${s.mode ? ` --mode ${s.mode}` : ''}`,
3397
- ...(named
3398
- ? []
3399
- : [
3400
- `${P} set ${slug} --color-text-secondary ${quoteCommandArgument(color)}${s.mode ? ` --mode ${s.mode}` : ''}`,
3401
- ]),
3402
- ],
5646
+ run: colors.map(
5647
+ c =>
5648
+ `${P} set ${slug} --color-text-${c} ${quoteCommandArgument(color)}${tail}`,
5649
+ ),
3403
5650
  },
3404
5651
  );
3405
5652
  }
3406
5653
  s.note = `text, heading and link inside ${s.on} keep the color their color prop gives; set --color-text-primary for those`;
3407
5654
  }
3408
- // One mode on a part whose variants each read their own value: the
3409
- // other mode cannot keep each variant's value in one rule.
3410
- // With a state, the other mode would take one variant's value for
3411
- // every variant, so any part whose variants read their own value needs
3412
- // the variant named.
3413
- // Per-variant colors only: a value that is not a color is refused for
3414
- // --mode below, with the reason that holds.
3415
- if (
3416
- s.mode &&
3417
- !s.when &&
3418
- (COLOR_PROPS.test(prop) || (prop === 'background' && isColorValue(v)))
3419
- ) {
3420
- const g = C.groupOfProp(
3421
- prop === 'background' ? 'background-color' : prop,
3422
- );
3423
- for (const t of partsOf(ctx, s)) {
3424
- const reads = g
3425
- ? C.partReads(t, g).filter(r => r.props.includes(prop))
3426
- : [];
3427
- const variantsOf = (
3428
- /** @type {(w: string) => string | undefined} */ pick,
3429
- ) => [
3430
- ...new Set(
3431
- reads
3432
- .flatMap(r => r.when)
3433
- .map(pick)
3434
- .filter(Boolean),
3435
- ),
3436
- ];
3437
- // Resting reads keyed by the variant alone, and reads in the state.
3438
- const rest = variantsOf(w => /^variant=([\w-]+)$/.exec(w)?.[1]);
3439
- const inState = s.state
3440
- ? variantsOf(w =>
3441
- w.includes(`:${s.state}`)
3442
- ? /(?:^|,)variant=([\w-]+)/.exec(w)?.[1]
3443
- : undefined,
3444
- )
3445
- : [];
3446
- // A state that does not change this property shows each variant's
3447
- // resting value, so that is what the other mode must keep.
3448
- const variants = inState.length ? inState : rest;
3449
- const perVariant = inState.length
3450
- ? true
3451
- : rest.length > 0 && !reads.some(r => r.when.includes(''));
3452
- if (reads.length && variants.length && perVariant)
3453
- refuse(
3454
- E.ERR_THEME_NO_MODE,
3455
- `Each variant of ${t} has its own ${prop}${s.state ? ` when ${s.state}` : ''}, so one mode cannot be set for all of them at once: the other mode would take one variant's color for every variant. Name the variant.`,
3456
- {
3457
- run: [
3458
- `${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on} --when variant:${variants[0]}${s.state ? ` --state ${s.state}` : ''} --mode ${s.mode}`,
3459
- ],
3460
- },
3461
- );
3462
- }
3463
- }
5655
+ // One mode on a part whose variants each read their own color is
5656
+ // written to each variant's rule with that variant's own other half
5657
+ // (compileTheme), so it needs no variant named.
3464
5658
  if (!isSafeValue(v))
3465
5659
  refuse(
3466
5660
  E.ERR_THEME_BAD_VALUE,
3467
5661
  `"${v}" cannot be a CSS value: it has a ; { } < > or a newline, a comment, !important, or an unclosed bracket or quote.`,
3468
- {run: [`${HOW} ${prop}`]},
5662
+ {
5663
+ // The value without its copy debris, when that is one.
5664
+ run: [
5665
+ withoutCopyDebris(v) !== v && isSafeValue(withoutCopyDebris(v))
5666
+ ? setLine(slug, prop, withoutCopyDebris(v), s)
5667
+ : `${HOW} ${prop}`,
5668
+ ],
5669
+ },
3469
5670
  );
3470
5671
  if (/radius$/.test(prop)) refuseInvisibleCorners(ctx, slug, s, data);
3471
5672
  if (step)
@@ -3536,26 +5737,63 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3536
5737
  if (
3537
5738
  s.mode &&
3538
5739
  !COLOR_PROPS.test(prop) &&
3539
- !(prop === 'background' && isColorValue(v))
5740
+ !(prop === 'background' && isColorValue(v)) &&
5741
+ // A gradient background (no image file) goes per mode: its colors
5742
+ // are each painted in that mode only (compileTheme).
5743
+ !(
5744
+ /^background(-image)?$/.test(prop) &&
5745
+ /gradient\(/i.test(v) &&
5746
+ !/url\(/i.test(v)
5747
+ )
3540
5748
  ) {
3541
5749
  // A color mixed into the value (a border's) can go per mode on its
3542
5750
  // own; a value with none (a radius) is just set for both modes.
3543
5751
  const hasColor = /#[0-9a-f]{3,8}\b|rgba?\(|hsla?\(/i.test(v);
3544
- const alt = !hasColor
3545
- ? null
3546
- : prop === 'border' || prop.startsWith('border-')
3547
- ? 'border-color'
3548
- : prop === 'background'
3549
- ? 'background-color'
3550
- : null;
5752
+ // A gradient's colors sit in its image, above any background-color:
5753
+ // no color step can make them differ per mode.
5754
+ const alt =
5755
+ !hasColor || /gradient\(/i.test(v)
5756
+ ? null
5757
+ : prop === 'border' || prop.startsWith('border-')
5758
+ ? 'border-color'
5759
+ : prop === 'background'
5760
+ ? 'background-color'
5761
+ : null;
5762
+ // On a part whose variants each have their own color, the color per
5763
+ // mode is set for one variant at a time (as that refusal says): the
5764
+ // step names the default one, or the first.
5765
+ let altWhen = '';
5766
+ if (alt && !s.when) {
5767
+ const g = C.groupOfProp(alt);
5768
+ const variants = [
5769
+ ...new Set(
5770
+ partsOf(ctx, s).flatMap(t =>
5771
+ (g ? C.partReads(t, g) : [])
5772
+ .filter(r => r.props.includes(alt))
5773
+ .flatMap(r => r.when)
5774
+ .map(w => /^variant=([\w-]+)$/.exec(w)?.[1])
5775
+ .filter(Boolean),
5776
+ ),
5777
+ ),
5778
+ ];
5779
+ const plain = partsOf(ctx, s).some(t =>
5780
+ (g ? C.partReads(t, g) : []).some(
5781
+ r => r.props.includes(alt) && r.when.includes(''),
5782
+ ),
5783
+ );
5784
+ if (variants.length && !plain)
5785
+ altWhen = ` --when variant:${variants.includes('default') ? 'default' : variants[0]}`;
5786
+ }
3551
5787
  refuse(
3552
5788
  E.ERR_THEME_NO_MODE,
3553
- `--mode works on plain colors; ${prop} ${prop === 'box-shadow' || prop === 'border' ? 'mixes a color with sizes' : 'is not a color'}, so it cannot differ between light and dark.`,
5789
+ prop === 'box-shadow' || prop === 'border'
5790
+ ? `--mode takes a plain color; ${prop} mixes a color with sizes, so --mode cannot hold it. Its color can still differ between light and dark: write it in the value as light-dark(<light>, <dark>).`
5791
+ : `--mode works on plain colors; ${prop} is not a color, so it cannot differ between light and dark.`,
3554
5792
  {
3555
5793
  run: alt
3556
5794
  ? [
3557
5795
  `${P} set ${slug} ${prop} ${quoteCommandArgument(v.replace(/#[0-9a-f]{3,8}|rgba?\([^)]*\)/i, 'currentcolor'))} --on ${s.on}${whenFlag} # the shape, both modes`,
3558
- `${P} set ${slug} ${alt} ${quoteCommandArgument(/#[0-9a-f]{3,8}\b|rgba?\([^)]*\)|hsla?\([^)]*\)/i.exec(v)?.[0] ?? '#1f2937')} --on ${s.on}${whenFlag} --mode ${s.mode} # then the color per mode`,
5796
+ `${P} set ${slug} ${alt} ${quoteCommandArgument(/#[0-9a-f]{3,8}\b|rgba?\([^)]*\)|hsla?\([^)]*\)/i.exec(v)?.[0] ?? '#1f2937')} --on ${s.on}${altWhen}${whenFlag} --mode ${s.mode} # then the color per mode${altWhen ? ', for each variant' : ''}`,
3559
5797
  ]
3560
5798
  : [
3561
5799
  `${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${whenFlag} # both modes`,
@@ -3563,34 +5801,6 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3563
5801
  },
3564
5802
  );
3565
5803
  }
3566
- // In a state, the other mode keeps the state's own value there (or a
3567
- // value set for both modes); with none to keep, the setting would
3568
- // change that mode too. Without a state, the other mode keeps the
3569
- // part's plain color.
3570
- if (
3571
- s.mode &&
3572
- s.state &&
3573
- !partsOf(ctx, s).every(t =>
3574
- partDefault(ctx, t, camel(prop), s.when, s.state),
3575
- ) &&
3576
- !data.settings.some(
3577
- x =>
3578
- x.thing === prop &&
3579
- x.on === s.on &&
3580
- x.when === s.when &&
3581
- x.state === s.state &&
3582
- x.mode !== s.mode,
3583
- )
3584
- )
3585
- refuse(
3586
- E.ERR_THEME_NO_MODE,
3587
- `${s.on} has no ${prop}${s.state ? ` when ${s.state}` : ''}${s.when ? ` for ${s.when}` : ''} of its own for the ${s.mode === 'light' ? 'dark' : 'light'} mode to keep, so a ${s.mode}-only value would change it too. Set it for both modes.`,
3588
- {
3589
- run: [
3590
- `${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
3591
- ],
3592
- },
3593
- );
3594
5804
  return s;
3595
5805
  }
3596
5806
  // A property written with _ or spaces, a trailing colon, or in camel
@@ -3607,7 +5817,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3607
5817
  run: [
3608
5818
  unset
3609
5819
  ? `${P} undo ${slug} ${meant}${onFlag}`
3610
- : `${P} set ${slug} ${meant} ${quoteCommandArgument(v || exampleOf(groupOfPropType(meant), meant))}${onFlag || ' --on card'}`,
5820
+ : // The scope typed, never a part nobody named: with no --on,
5821
+ // set's own answer for the property (its whole-theme dial or
5822
+ // token) is folded in when the line is vetted.
5823
+ `${P} set ${slug} ${meant} ${quoteCommandArgument(v || exampleOf(groupOfPropType(meant), meant))}${onFlag}`,
3611
5824
  ],
3612
5825
  },
3613
5826
  );
@@ -3638,13 +5851,18 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3638
5851
  // A hint names this theme and the part (card when none is given),
3639
5852
  // and a corners value corners takes.
3640
5853
  run: hint
3641
- ? hint(
3642
- /corners/.test(String(hint('', '')))
3643
- ? CORNERS.some(([n]) => n === v) || /^\d+(\.\d+)?px$/.test(v)
3644
- ? v
3645
- : ''
3646
- : v,
3647
- s.on,
5854
+ ? (/corners/.test(String(hint('', ''))) &&
5855
+ v.trim() &&
5856
+ !YES_NO.test(v.trim()) &&
5857
+ cornersRead(v) == null
5858
+ ? // A value corners cannot read: how corners, never a stock rung.
5859
+ [`${HOW} corners`]
5860
+ : hint(
5861
+ /corners/.test(String(hint('', ''))) && !YES_NO.test(v.trim())
5862
+ ? (cornersRead(v) ?? '')
5863
+ : v,
5864
+ s.on,
5865
+ )
3648
5866
  ).map(x =>
3649
5867
  x
3650
5868
  .replace(/<theme>/g, slug)
@@ -3672,6 +5890,13 @@ function refuseInvisibleCorners(ctx, slug, s, data) {
3672
5890
  if (ctx.unchecked) return;
3673
5891
  const parts = partsOf(ctx, s);
3674
5892
  if (!parts.length || parts.some(t => ctx.C.showsCorners(t))) return;
5893
+ // The corners dial on a part whose corners are drawn by parts of its own
5894
+ // inside it (a date-time input's date and time boxes) rounds those.
5895
+ if (
5896
+ s.thing === 'corners' &&
5897
+ parts.some(t => cornerParts(ctx, t).some(x => x !== t))
5898
+ )
5899
+ return;
3675
5900
  // An edge the theme gives the part itself shows its corners too.
3676
5901
  const edged = data.settings.some(
3677
5902
  x =>
@@ -3765,6 +5990,68 @@ export function normalValue(thing, value) {
3765
5990
  /** @see familySpaces in _settings.mjs, re-exported for the checks. */
3766
5991
  export {familySpaces};
3767
5992
 
5993
+ /**
5994
+ * The first design token a property's value reads through var() whose kind
5995
+ * the property does not take, or null: the value with the var() replaced by
5996
+ * a value of the token's kind (the example each kind's refusals give) is
5997
+ * one the property's grammar does not take, so the browser drops it.
5998
+ * @param {import('./_settings.mjs').Ctx} ctx
5999
+ * @param {string} prop the property, as CSS names it
6000
+ * @param {string} v
6001
+ * @returns {{token: string, kind: string, takes: string, message: string} | null}
6002
+ */
6003
+ function tokenKindMismatch(ctx, prop, v) {
6004
+ for (const m of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*(?:,[^()]*)?\)/gi)) {
6005
+ const token = m[1];
6006
+ if (!ctx.C.isToken(token)) continue;
6007
+ const kind = ctx.C.typeOf(token);
6008
+ if (kind === 'other') continue;
6009
+ const sample = v.replace(m[0], exampleOf(kind, token));
6010
+ if (matchValue(prop, sample)) continue;
6011
+ const takes =
6012
+ matchValue(prop, '1px') && !matchValue(prop, 'red')
6013
+ ? 'a length'
6014
+ : matchValue(prop, 'red') && !matchValue(prop, '1px')
6015
+ ? 'a color'
6016
+ : null;
6017
+ return {
6018
+ token,
6019
+ kind,
6020
+ takes: takes ?? `no ${kind}`,
6021
+ message: takes
6022
+ ? `${prop} takes ${takes}; ${token} is a ${kind}, so the browser would drop it`
6023
+ : `${prop} takes no ${kind}; ${token} is a ${kind}, so the browser would drop it`,
6024
+ };
6025
+ }
6026
+ return null;
6027
+ }
6028
+
6029
+ /**
6030
+ * Why a part's CSS property value is refused, as `set` refuses it, or
6031
+ * null: a var() that reads nothing, a color property's value that is no
6032
+ * color, or a value the property's grammar does not take.
6033
+ * @param {import('./_settings.mjs').Ctx} ctx
6034
+ * @param {string} prop the property, as CSS names it
6035
+ * @param {string} value
6036
+ * @param {Record<string, unknown>} TOKENS
6037
+ * @param {ReadonlySet<string>} [reads] custom properties the theme sets where the value is read
6038
+ * @returns {string | null}
6039
+ */
6040
+ export function propertyValueProblem(ctx, prop, value, TOKENS, reads) {
6041
+ const v = value.trim();
6042
+ const ref = unknownVarRef(v, TOKENS, prop, reads);
6043
+ if (ref) return ref.message;
6044
+ const mismatch = tokenKindMismatch(ctx, prop, v);
6045
+ if (mismatch) return mismatch.message;
6046
+ if (CSS_WIDE.includes(v.toLowerCase())) return null;
6047
+ if (COLOR_PROPS.test(prop))
6048
+ return /\bvar\(/i.test(v) || isColorValue(v)
6049
+ ? null
6050
+ : `${prop} takes a color; "${v}" is not one.`;
6051
+ const grammar = propertyProblem(prop, v);
6052
+ return grammar ? `${prop} takes ${grammar.takes}; "${v}" is not one.` : null;
6053
+ }
6054
+
3768
6055
  /**
3769
6056
  * The first var() in a value that names no design token and would read
3770
6057
  * nothing (no fallback), or one a letter or two off a token, else null.
@@ -3772,9 +6059,11 @@ export {familySpaces};
3772
6059
  * @param {string} v
3773
6060
  * @param {Record<string, unknown>} TOKENS
3774
6061
  * @param {string} thing
6062
+ * @param {ReadonlySet<string>} [reads] custom properties the theme itself
6063
+ * sets where the value is read: a var() naming one reads it
3775
6064
  * @returns {{message: string, near: string[], close: boolean, fixed?: string} | null}
3776
6065
  */
3777
- export function unknownVarRef(v, TOKENS, thing) {
6066
+ export function unknownVarRef(v, TOKENS, thing, reads) {
3778
6067
  // A var() whose name is not a custom property (`var(color-x)`, `var(-x)`,
3779
6068
  // `var()`, `var(--)`) makes the whole value invalid: the browser drops
3780
6069
  // it. Named with the repaired form when there is one.
@@ -3793,12 +6082,12 @@ export function unknownVarRef(v, TOKENS, thing) {
3793
6082
  };
3794
6083
  }
3795
6084
  for (const [, name, comma] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*(,)?/gi)) {
3796
- if (name in TOKENS || name.startsWith('--_')) continue;
6085
+ if (name in TOKENS || name.startsWith('--_') || reads?.has(name)) continue;
3797
6086
  // A fallback always gives a value: never "reads nothing" (a likely
3798
6087
  // typo is noted when the setting is made).
3799
6088
  if (comma) continue;
3800
- const near = nearest(name, Object.keys(TOKENS)).filter(
3801
- n => levenshteinDistance(n, name) <= 2,
6089
+ const near = nearest(name, Object.keys(TOKENS)).filter(n =>
6090
+ typoNear(name, n),
3802
6091
  );
3803
6092
  if (near.length)
3804
6093
  return {
@@ -3827,20 +6116,21 @@ export function unknownVarRef(v, TOKENS, thing) {
3827
6116
  * @returns {string | null}
3828
6117
  */
3829
6118
  export function fontFileReason(value) {
3830
- const hit = String(value)
3831
- .split(',')
3832
- .map(f => f.trim().replace(/^["']|["']$/g, ''))
3833
- .find(
3834
- f =>
3835
- /^url\(/i.test(f) ||
3836
- /:\/\//.test(f) ||
3837
- /[\\/]/.test(f) ||
3838
- /\.(woff2?|ttf|otf|eot)$/i.test(f),
3839
- );
3840
- const colon = String(value)
3841
- .split(',')
3842
- .map(f => f.trim().replace(/^["']|["']$/g, ''))
3843
- .find(f => f.includes(':'));
6119
+ // Each family as CSS reads it: an escape (`Gill\ Sans`, `\5FAE`) is part
6120
+ // of the name, never a path separator.
6121
+ // The families as the one family-list reader splits them (a quoted name
6122
+ // with a comma is one family).
6123
+ const families = (familiesOf(value) ?? String(value).split(',')).map(f =>
6124
+ cssUnescape(f.trim().replace(/^["']|["']$/g, '')),
6125
+ );
6126
+ const hit = families.find(
6127
+ f =>
6128
+ /^url\(/i.test(f) ||
6129
+ /:\/\//.test(f) ||
6130
+ /[\\/]/.test(f) ||
6131
+ /\.(woff2?|ttf|otf|eot)$/i.test(f),
6132
+ );
6133
+ const colon = families.find(f => f.includes(':'));
3844
6134
  if (!hit && colon)
3845
6135
  return `"${colon}" holds a colon, so it is a pasted declaration or a link, not a font family name. Give the family alone, such as Inter, sans-serif.`;
3846
6136
  return hit
@@ -3849,78 +6139,38 @@ export function fontFileReason(value) {
3849
6139
  }
3850
6140
 
3851
6141
  /**
3852
- * A value with every Unicode space (no-break, thin, ideographic…) as a plain
3853
- * space and zero-width and format characters dropped, for every value type:
3854
- * the browser reads only a plain space as one.
3855
- * @param {string} v
6142
+ * A word as a suggested command quotes it, without the quotes.
6143
+ * @param {string} word
3856
6144
  */
3857
- export function normalValueText(v) {
3858
- // Curly quotes (a word processor's, a phone's) are the straight ones CSS
3859
- // reads.
3860
- const straight = v
3861
- .replace(/[\u2018\u2019\u201A\u201B]/g, "'")
3862
- .replace(/[\u201C\u201D\u201E\u201F]/g, '"');
3863
- // A quoted CSS string (`content: "a\u00A0b"`) keeps what is inside it.
3864
- return straight
3865
- .split(/("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')/)
3866
- .map((part, i) =>
3867
- i % 2
3868
- ? part
3869
- : part
3870
- .replace(/[\u200B-\u200D\u2060\uFEFF]/g, '')
3871
- .replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' '),
3872
- )
3873
- .join('');
6145
+ function unquoteArg(word) {
6146
+ const m = /^'(.*)'$/s.exec(word.trim());
6147
+ return m ? m[1].replace(/'\\''/g, "'") : word.trim();
3874
6148
  }
3875
6149
 
6150
+ /** Core's stylesheet text, by project folder. @type {Map<string, string>} */
6151
+ const coreStyles = new Map();
6152
+
3876
6153
  /**
3877
- * The thing and value a setting was typed as, put right before any check: a
3878
- * declaration pasted whole or split (`accent: #e11d48`, `--color-accent=red`,
3879
- * `font:inter`, `accent:` with the value next), a token typed with an em or
3880
- * en dash (`—color-accent`) or as `var(--color-accent)`, and the value's
3881
- * Unicode spaces. A thing it cannot read is left as typed.
3882
- * @param {string} thing
3883
- * @param {string | undefined} value
3884
- * @returns {{thing: string, value: string | undefined}}
6154
+ * Whether Core's own stylesheet reads a token anywhere (a part the editor
6155
+ * does not render, such as the app shell behind the page, included).
6156
+ * @param {any} ctx
6157
+ * @param {string} token
3885
6158
  */
3886
- export function normalizeEntry(thing, value) {
3887
- let t = normalValueText(String(thing ?? '')).trim();
3888
- let v = value == null ? value : normalValueText(String(value));
3889
- // A pasted declaration (the whole of it in the thing, or the thing with
3890
- // its colon and the value next): its `;` and `!important` go with it.
3891
- let pasted = false;
3892
- if (v == null || v.trim() === '') {
3893
- const m = /^(\S+?)\s*[:=]\s*(.+?)\s*;?\s*$/.exec(t);
3894
- if (m && !/^https?$/i.test(m[1])) {
3895
- t = m[1];
3896
- v = m[2];
3897
- pasted = true;
6159
+ function coreStylesRead(ctx, token) {
6160
+ const cwd = String(ctx?.project?.cwd ?? '');
6161
+ let css = coreStyles.get(cwd);
6162
+ if (css == null) {
6163
+ try {
6164
+ css = fs.readFileSync(
6165
+ ctx.project.req.resolve('@astryxdesign/core/astryx.css'),
6166
+ 'utf8',
6167
+ );
6168
+ } catch {
6169
+ css = '';
3898
6170
  }
6171
+ coreStyles.set(cwd, css);
3899
6172
  }
3900
- // A thing ending in its colon or equals sign, the value given next.
3901
- if (/\s*[:=]+$/.test(t)) {
3902
- t = t.replace(/\s*[:=]+$/, '');
3903
- pasted = true;
3904
- }
3905
- // Dash-like characters where a token's two dashes go (an em or en dash,
3906
- // a non-breaking hyphen, a minus sign, a full-width hyphen, alone or
3907
- // mixed with hyphens): `--`.
3908
- t = t.replace(/^[-\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]+/, run =>
3909
- /[^-]/.test(run) ? '--' : run,
6173
+ return new RegExp(`var\\(\\s*${token.replace(/[-]/g, '\\-')}\\s*[,)]`).test(
6174
+ css,
3910
6175
  );
3911
- // A token typed as a var() reference.
3912
- const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(t);
3913
- if (ref) t = ref[1];
3914
- if (pasted && typeof v === 'string')
3915
- v = v.replace(/\s*!\s*important\s*;?\s*$/i, '').replace(/;+\s*$/, '');
3916
- return {thing: t, value: v};
3917
- }
3918
-
3919
- /**
3920
- * A word as a suggested command quotes it, without the quotes.
3921
- * @param {string} word
3922
- */
3923
- function unquoteArg(word) {
3924
- const m = /^'(.*)'$/s.exec(word.trim());
3925
- return m ? m[1].replace(/'\\''/g, "'") : word.trim();
3926
6176
  }