@astryxdesign/cli 0.7.16 → 0.7.17-canary.g335a172

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +12 -0
  3. package/api/build/_adapter.mjs +51 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +4 -3
  7. package/api/build/build.type.d.mts +2 -2
  8. package/api/build/build.type.mjs +3 -3
  9. package/api/build/kit/kind.d.mts +2 -1
  10. package/api/build/kit/kind.mjs +199 -10
  11. package/api/build/kit/kit.mjs +6 -4
  12. package/api/build/kit/rank.mjs +69 -16
  13. package/api/build/kit/start.d.mts +5 -4
  14. package/api/build/kit/start.mjs +12 -8
  15. package/api/build/kit/weights.d.mts +16 -3
  16. package/api/build/kit/weights.json +1 -1
  17. package/api/build/kit/weights.mjs +251 -35
  18. package/api/build/kit/word-model.d.mts +23 -0
  19. package/api/build/kit/word-model.mjs +46 -0
  20. package/api/build/kit/words.d.mts +48 -0
  21. package/api/build/kit/words.mjs +90 -1
  22. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  23. package/api/component/list/list.d.mts +1 -1
  24. package/api/component/list/list.mjs +48 -6
  25. package/api/discover/_adapter.d.mts +1 -1
  26. package/api/discover/search/search.mjs +3 -2
  27. package/api/docs/_adapter.d.mts +26 -2
  28. package/api/docs/_adapter.mjs +219 -6
  29. package/api/docs/docs.d.mts +3 -0
  30. package/api/docs/docs.doc.mjs +7 -1
  31. package/api/docs/docs.mjs +12 -0
  32. package/api/docs/docs.type.d.mts +5 -0
  33. package/api/docs/docs.type.mjs +2 -0
  34. package/api/docs/node/node.mjs +1 -1
  35. package/api/doctor/_adapter.d.mts +27 -5
  36. package/api/doctor/_adapter.mjs +83 -10
  37. package/api/doctor/built-checks.mjs +40 -14
  38. package/api/doctor/doctor.d.mts +4 -3
  39. package/api/doctor/doctor.mjs +14 -7
  40. package/api/doctor/theme-checks.mjs +121 -17
  41. package/api/icon/_records.mjs +2 -1
  42. package/api/index.d.mts +2 -0
  43. package/api/index.mjs +2 -0
  44. package/api/integration/_adapter.d.mts +44 -0
  45. package/api/integration/_adapter.mjs +77 -1
  46. package/api/integration/authoring-checks.mjs +6 -6
  47. package/api/integration/example-scope.d.mts +14 -0
  48. package/api/integration/example-scope.mjs +44 -0
  49. package/api/integration/example-scope.type.d.mts +29 -0
  50. package/api/integration/example-scope.type.mjs +25 -0
  51. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  52. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  53. package/api/integration/validate-integration.mjs +19 -1
  54. package/api/integration/validate-integration.type.d.mts +9 -0
  55. package/api/integration/validate-integration.type.mjs +1 -1
  56. package/api/integration/validateIntegration.doc.mjs +1 -1
  57. package/api/render/_adapter.mjs +591 -195
  58. package/api/render/render.doc.mjs +11 -3
  59. package/api/render/render.type.d.mts +52 -0
  60. package/api/render/render.type.mjs +31 -1
  61. package/api/search/ORDERING.md +1 -1
  62. package/api/search/_candidate-score.mjs +51 -32
  63. package/api/search/_fit-order.mjs +3 -3
  64. package/api/search/_gather-components.d.mts +3 -2
  65. package/api/search/_gather-components.mjs +12 -3
  66. package/api/search/_lexical.d.mts +5 -0
  67. package/api/search/_lexical.mjs +8 -2
  68. package/api/search/_result.d.mts +11 -9
  69. package/api/search/_result.mjs +4 -4
  70. package/api/search/_score.d.mts +6 -1
  71. package/api/search/_score.mjs +15 -3
  72. package/api/search/search-index.mjs +7 -1
  73. package/api/search/search.d.mts +1 -1
  74. package/api/theme/_adapter.mjs +12 -1
  75. package/api/theme/build/build.d.mts +60 -0
  76. package/api/theme/build/build.mjs +210 -54
  77. package/api/theme/build/font-warning.d.mts +8 -0
  78. package/api/theme/build/font-warning.mjs +19 -0
  79. package/api/theme/theme.type.d.mts +10 -0
  80. package/api/theme/theme.type.mjs +7 -1
  81. package/api/theme-edit/_adapter.d.mts +55 -0
  82. package/api/theme-edit/_adapter.mjs +673 -42
  83. package/api/theme-edit/_check.d.mts +28 -22
  84. package/api/theme-edit/_check.mjs +1858 -312
  85. package/api/theme-edit/_color.d.mts +10 -0
  86. package/api/theme-edit/_color.mjs +49 -1
  87. package/api/theme-edit/_compiler.mjs +9 -0
  88. package/api/theme-edit/_context.mjs +60 -3
  89. package/api/theme-edit/_css.mjs +21 -1
  90. package/api/theme-edit/_edit.d.mts +22 -0
  91. package/api/theme-edit/_edit.mjs +1533 -92
  92. package/api/theme-edit/_how-commands.d.mts +57 -0
  93. package/api/theme-edit/_how-commands.mjs +587 -1
  94. package/api/theme-edit/_how-question.d.mts +78 -0
  95. package/api/theme-edit/_how-question.mjs +4716 -235
  96. package/api/theme-edit/_how.mjs +134 -8
  97. package/api/theme-edit/_marks.d.mts +31 -5
  98. package/api/theme-edit/_marks.mjs +57 -5
  99. package/api/theme-edit/_normal.d.mts +219 -0
  100. package/api/theme-edit/_normal.mjs +1041 -0
  101. package/api/theme-edit/_palette.mjs +10 -4
  102. package/api/theme-edit/_parts.d.mts +8 -0
  103. package/api/theme-edit/_parts.mjs +103 -2
  104. package/api/theme-edit/_playwright-picture.d.mts +4 -0
  105. package/api/theme-edit/_playwright-picture.mjs +34 -0
  106. package/api/theme-edit/_preview-app.d.mts +7 -1
  107. package/api/theme-edit/_preview-app.mjs +394 -74
  108. package/api/theme-edit/_preview.d.mts +69 -8
  109. package/api/theme-edit/_preview.mjs +531 -108
  110. package/api/theme-edit/_settings.d.mts +243 -6
  111. package/api/theme-edit/_settings.mjs +2415 -147
  112. package/api/theme-edit/_tables.d.mts +6 -0
  113. package/api/theme-edit/_tables.mjs +44 -1
  114. package/api/theme-edit/_vet.d.mts +18 -0
  115. package/api/theme-edit/_vet.mjs +32 -0
  116. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  117. package/api/theme-edit/theme-edit.type.mjs +4 -1
  118. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  119. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  120. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  121. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  122. package/api/upgrade/run/run.mjs +4 -3
  123. package/assets/codemods/integration-discovery.mjs +2 -1
  124. package/assets/codemods/run-codemod.mjs +87 -7
  125. package/assets/codemods/transforms/next/index.mjs +11 -1
  126. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  127. package/assets/component-list.generated.json +1 -0
  128. package/assets/docs/author-a-theme.doc.mjs +1 -0
  129. package/assets/docs/theme.doc.dense.mjs +2 -2
  130. package/assets/docs/theme.doc.mjs +1 -1
  131. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  132. package/assets/docs/tree/checks.doc.mjs +1 -1
  133. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  134. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  135. package/assets/docs/tree/single-component.doc.mjs +4 -0
  136. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  137. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  138. package/assets/docs/use-a-theme.doc.mjs +1 -1
  139. package/assets/docs.generated.json +2 -2
  140. package/assets/self-audit.generated.json +1 -1
  141. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  142. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  143. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  144. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  145. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  146. package/assets/templates/components.generated.json +1 -1
  147. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  148. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  149. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  150. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  151. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  152. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  153. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  154. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  155. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  156. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  157. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  158. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  159. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  160. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  161. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  162. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  163. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  164. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  165. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  166. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  167. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  168. package/assets/templates/pages/ide/page.tsx +24 -2
  169. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  170. package/assets/templates/pages/library/template.doc.mjs +4 -1
  171. package/assets/templates/pages/login/template.doc.mjs +2 -1
  172. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  173. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  174. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  175. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  176. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  177. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  178. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  179. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  180. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  181. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  182. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  183. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  184. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  185. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  186. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  187. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  188. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  189. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  190. package/assets/theme.template.ts +6 -0
  191. package/authoring/debug/parse.d.mts +3 -3
  192. package/authoring/doctypes/_schema.d.mts +3 -3
  193. package/authoring/doctypes/command/command.doc.mjs +1 -1
  194. package/authoring/doctypes/component/categories.d.mts +37 -0
  195. package/authoring/doctypes/component/categories.mjs +54 -0
  196. package/authoring/doctypes/template/template.doc.mjs +1 -1
  197. package/authoring/doctypes/template/type.ts +9 -0
  198. package/authoring/example/example.doc.d.mts +12 -0
  199. package/authoring/example/example.doc.mjs +69 -0
  200. package/authoring/example/preview.d.mts +92 -0
  201. package/authoring/example/preview.mjs +994 -0
  202. package/authoring/example/type.ts +102 -0
  203. package/authoring/index.d.mts +1 -0
  204. package/authoring/index.d.ts +12 -0
  205. package/authoring/index.mjs +3 -1
  206. package/clients/cli/bin/astryx.mjs +6 -9
  207. package/clients/cli/build-id.generated.json +1 -1
  208. package/clients/cli/commands/component.doc.mjs +1 -1
  209. package/clients/cli/commands/component.mjs +22 -3
  210. package/clients/cli/commands/docs.doc.mjs +7 -1
  211. package/clients/cli/commands/docs.mjs +3 -1
  212. package/clients/cli/commands/doctor.mjs +32 -14
  213. package/clients/cli/commands/experimental/render.mjs +42 -1
  214. package/clients/cli/commands/experimental/theme.mjs +145 -16
  215. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  216. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  217. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  218. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  219. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  220. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  221. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  222. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  223. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  224. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  225. package/clients/cli/commands/search.doc.mjs +2 -1
  226. package/clients/cli/commands/search.mjs +6 -1
  227. package/clients/cli/commands/template.mjs +4 -2
  228. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  229. package/clients/cli/commands/theme.doc.mjs +1 -1
  230. package/clients/cli/commands/theme.mjs +183 -6
  231. package/clients/cli/commands/upgrade.mjs +42 -7
  232. package/clients/cli/index.mjs +1 -1
  233. package/clients/cli/lib/cli-error.mjs +2 -1
  234. package/clients/cli/lib/component-format.mjs +205 -98
  235. package/clients/cli/lib/hook-format.mjs +9 -19
  236. package/clients/cli/lib/json-shim.mjs +77 -21
  237. package/clients/cli/lib/manifest.mjs +3 -2
  238. package/clients/cli/manifest.generated.json +1 -1
  239. package/foundation/agent-docs/agent-docs.mjs +1 -1
  240. package/foundation/config/theme-state.d.mts +13 -1
  241. package/foundation/config/theme-state.mjs +47 -7
  242. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  243. package/foundation/discovery/component-discovery.d.mts +11 -0
  244. package/foundation/discovery/component-discovery.mjs +56 -8
  245. package/foundation/discovery/component-replacement.mjs +130 -1
  246. package/foundation/discovery/copied-passages.mjs +2 -1
  247. package/foundation/discovery/doc-types.mjs +4 -3
  248. package/foundation/discovery/entry-name-files.d.mts +43 -0
  249. package/foundation/discovery/entry-name-files.mjs +264 -0
  250. package/foundation/discovery/hook-discovery.d.mts +8 -2
  251. package/foundation/discovery/hook-discovery.mjs +22 -8
  252. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  253. package/foundation/discovery/icon-set-checks.mjs +2 -1
  254. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  255. package/foundation/discovery/integration-doc-files.mjs +2 -1
  256. package/foundation/discovery/package-exports.d.mts +10 -0
  257. package/foundation/discovery/package-exports.mjs +56 -3
  258. package/foundation/discovery/prop-drift.mjs +9 -9
  259. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  260. package/foundation/discovery/runner-allowlist.mjs +2 -0
  261. package/foundation/discovery/stored-component-list.d.mts +43 -0
  262. package/foundation/discovery/stored-component-list.mjs +90 -0
  263. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  264. package/foundation/discovery/stored-self-audit.mjs +38 -18
  265. package/foundation/discovery/template-adapter.d.mts +52 -0
  266. package/foundation/discovery/template-adapter.mjs +176 -12
  267. package/foundation/discovery/template-icons.mjs +2 -1
  268. package/foundation/discovery/theme-discovery.mjs +3 -2
  269. package/foundation/discovery/theme-imports.d.mts +14 -0
  270. package/foundation/discovery/theme-imports.mjs +43 -1
  271. package/foundation/discovery/theming-targets.mjs +3 -2
  272. package/foundation/doc-compiler/import.mjs +7 -1
  273. package/foundation/doc-compiler/inputs.mjs +3 -2
  274. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  275. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  276. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  277. package/foundation/env/semver.mjs +3 -1
  278. package/foundation/fonts/font-stylesheet.d.mts +31 -0
  279. package/foundation/fonts/font-stylesheet.mjs +115 -0
  280. package/foundation/fs/cache-eviction.d.mts +21 -0
  281. package/foundation/fs/cache-eviction.mjs +73 -0
  282. package/foundation/fs/file-protection.mjs +4 -3
  283. package/foundation/fs/gather-cache.d.mts +25 -4
  284. package/foundation/fs/gather-cache.mjs +164 -55
  285. package/foundation/fs/jiti-cache.d.mts +19 -1
  286. package/foundation/fs/jiti-cache.mjs +130 -6
  287. package/foundation/fs/kept-tree.d.mts +60 -0
  288. package/foundation/fs/kept-tree.mjs +154 -0
  289. package/foundation/fs/listing-cache.d.mts +7 -0
  290. package/foundation/fs/listing-cache.mjs +10 -0
  291. package/foundation/fs/module-loader.d.mts +24 -2
  292. package/foundation/fs/module-loader.mjs +94 -21
  293. package/foundation/fs/paths.d.mts +18 -0
  294. package/foundation/fs/paths.mjs +15 -2
  295. package/foundation/identity/provider-identity.d.mts +6 -0
  296. package/foundation/identity/provider-identity.mjs +10 -1
  297. package/foundation/integrations/contribution-inventory.mjs +4 -3
  298. package/foundation/integrations/example-code.d.mts +63 -0
  299. package/foundation/integrations/example-code.mjs +416 -0
  300. package/foundation/integrations/public-imports.d.mts +9 -0
  301. package/foundation/integrations/public-imports.mjs +3 -2
  302. package/foundation/integrations/validate-contributions.mjs +17 -45
  303. package/foundation/render/embedded-files.d.mts +6 -0
  304. package/foundation/render/embedded-files.mjs +25 -5
  305. package/foundation/render/embedded-imports.d.mts +39 -7
  306. package/foundation/render/embedded-imports.mjs +66 -27
  307. package/foundation/render/file-header.d.mts +66 -0
  308. package/foundation/render/file-header.mjs +118 -0
  309. package/foundation/render/host-answer.d.mts +18 -0
  310. package/foundation/render/host-answer.mjs +46 -0
  311. package/foundation/render/host-exit.d.mts +1 -0
  312. package/foundation/render/host-exit.mjs +6 -1
  313. package/foundation/render/html-reader.d.mts +55 -2
  314. package/foundation/render/html-reader.mjs +145 -26
  315. package/foundation/render/markup-edits.d.mts +57 -0
  316. package/foundation/render/markup-edits.mjs +182 -0
  317. package/foundation/render/page-host.mjs +29 -12
  318. package/foundation/render/page-worker.mjs +121 -13
  319. package/foundation/render/rebuild.mjs +2 -1
  320. package/foundation/render/render-page.d.mts +35 -3
  321. package/foundation/render/render-page.mjs +316 -42
  322. package/foundation/render/source-block.d.mts +85 -6
  323. package/foundation/render/source-block.mjs +211 -20
  324. package/foundation/render/ts-paths.d.mts +69 -6
  325. package/foundation/render/ts-paths.mjs +326 -40
  326. package/foundation/response/error-codes.d.mts +3 -1
  327. package/foundation/response/error-codes.d.ts +1 -0
  328. package/foundation/response/error-codes.doc.mjs +12 -1
  329. package/foundation/response/error-codes.mjs +11 -1
  330. package/foundation/response/response-types.doc.mjs +2 -2
  331. package/foundation/text/compare-text.d.mts +14 -0
  332. package/foundation/text/compare-text.mjs +68 -0
  333. package/foundation/text/string-utils.d.mts +3 -2
  334. package/foundation/text/string-utils.mjs +18 -4
  335. package/foundation/text/suggest-order.d.mts +9 -0
  336. package/foundation/text/suggest-order.mjs +15 -1
  337. package/foundation/xle/expand.mjs +2 -1
  338. package/host/index.mjs +8 -6
  339. package/package.json +7 -6
@@ -15,7 +15,6 @@ import * as path from 'node:path';
15
15
  import {partForWord} from './_how-question.mjs';
16
16
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
17
17
  import {baseInstalled, baseThemeFile, installLine} from './_project.mjs';
18
- import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
19
18
  import {
20
19
  withFallbacks,
21
20
  MATH_FUNCTION,
@@ -35,6 +34,7 @@ import {
35
34
  } from './_css.mjs';
36
35
  import {calcVars, coreFallback, multipliedTokens} from './_parts.mjs';
37
36
  import {
37
+ MODE_WORDS,
38
38
  AUTO_SPREAD,
39
39
  COLOR_PROP_PARTS,
40
40
  COLOR_PROPS,
@@ -61,6 +61,7 @@ import {
61
61
  wordTable,
62
62
  WRAPPED_PARTS,
63
63
  CARD_LIKE,
64
+ isSystemFamily,
64
65
  } from './_tables.mjs';
65
66
  import {
66
67
  COLOR_NAMES,
@@ -85,6 +86,7 @@ import {
85
86
  camel,
86
87
  kebab,
87
88
  nearest,
89
+ negates,
88
90
  partDefault,
89
91
  partsOf,
90
92
  refuse,
@@ -97,15 +99,66 @@ import {
97
99
  themeFiles,
98
100
  ownSourceTokenValues,
99
101
  baseTopTokens,
102
+ baseComponent,
100
103
  baseComponentReads,
104
+ baseRuleHas,
101
105
  partRuleTokens,
102
106
  cssFamily,
103
107
  familySpaces,
108
+ fontsourcePackageOf,
104
109
  } from './_settings.mjs';
110
+ import {isColorToken} from './_compiler.mjs';
111
+ import {
112
+ trimInsideQuotes,
113
+ colorPair,
114
+ otherSettingLabel,
115
+ familiesOf,
116
+ familyPieces,
117
+ normalValueText,
118
+ normalizeEntry,
119
+ withoutDebris,
120
+ typoOf,
121
+ typoNear,
122
+ PROPERTY_WORDS,
123
+ WEIGHT_WORDS,
124
+ TAILWIND_RADIUS,
125
+ documentReadings,
126
+ documentNumericTable,
127
+ documentRange,
128
+ withoutCopyDebris,
129
+ } from './_normal.mjs';
130
+
131
+ export {
132
+ familiesOf,
133
+ familyPieces,
134
+ normalValueText,
135
+ normalizeEntry,
136
+ withoutDebris,
137
+ };
105
138
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
106
139
 
107
140
  export {lengthPx};
108
141
 
142
+ /**
143
+ * The radius the base theme's own rule gives a part, in px, or null when
144
+ * its rule gives none.
145
+ * @param {any} ctx
146
+ * @param {{light: Record<string, string>}} base
147
+ * @param {string} part
148
+ * @param {string | undefined} when
149
+ * @returns {number | null}
150
+ */
151
+ function basePartRadiusPx(ctx, base, part, when) {
152
+ const own = ctx.base
153
+ ? baseComponent(ctx.base, ctx, part, 'borderRadius', {when})
154
+ : null;
155
+ if (typeof own !== 'string') return null;
156
+ const tokenName = /var\(\s*(--radius-[\w-]+)/.exec(own)?.[1];
157
+ if (tokenName) return tokenPx(base, tokenName);
158
+ const px = lengthPx(own);
159
+ return px == null ? null : Math.min(px, 9999);
160
+ }
161
+
109
162
  /**
110
163
  * A token's value in px, following var() references through the tokens.
111
164
  * @param {{light: Record<string, string>}} base
@@ -122,6 +175,13 @@ function tokenPx(base, token) {
122
175
  return lengthPx(v);
123
176
  }
124
177
 
178
+ // A type scale ratio is a number above 1, up to 2.
179
+ documentNumericTable(
180
+ ['type'],
181
+ Object.entries(TYPE_STYLES).map(([name, style]) => [name, style.ratio]),
182
+ [1, 2],
183
+ );
184
+
125
185
  /**
126
186
  * The `type` preset nearest a scale ratio typed as a number (1.3 is
127
187
  * editorial), or null for a number that is no ratio (16).
@@ -154,6 +214,108 @@ const cornerPxOf = v =>
154
214
 
155
215
  const E = ERROR_CODES;
156
216
 
217
+ /**
218
+ * Why the math in a value's calc() cannot work, or null: each `+`/`-`
219
+ * needs two sides of one kind (a length with a length or a percentage, a
220
+ * number with a number), `*` needs a plain number on one side, `/` a plain
221
+ * number on the right. A var() counts as its fallback; one with none, or a
222
+ * nested min(), max() or clamp(), is not judged.
223
+ * @param {string} value
224
+ * @returns {string | null}
225
+ */
226
+ export function calcUnitProblem(value) {
227
+ const text = String(value);
228
+ const re = /\bcalc\(/gi;
229
+ let m;
230
+ while ((m = re.exec(text))) {
231
+ const open = m.index + m[0].length - 1;
232
+ const close = matchingParen(text, open);
233
+ if (close < 0) return null;
234
+ let expr = text.slice(open + 1, close);
235
+ // Each var() is its fallback, innermost first.
236
+ for (let i = 0; i < 20 && /\bvar\(/i.test(expr); i += 1) {
237
+ const at = expr.search(/\bvar\((?:[^()]|\([^()]*\))*\)/i);
238
+ const v = /\bvar\(((?:[^()]|\([^()]*\))*)\)/i.exec(expr.slice(at));
239
+ if (at < 0 || !v) return null;
240
+ const comma = v[1].indexOf(',');
241
+ if (comma < 0) return null;
242
+ expr = `${expr.slice(0, at)}(${v[1].slice(comma + 1).trim()})${expr.slice(at + v[0].length)}`;
243
+ }
244
+ if (/[a-z-]+\(/i.test(expr.replace(/\bcalc\(/gi, '('))) continue;
245
+ const found = expr.match(/\d*\.?\d+(?:e[+-]?\d+)?[a-z%]*|[-+*/()]/gi);
246
+ if (!found) continue;
247
+ const tokens = found;
248
+ let pos = 0;
249
+ /** @returns {string | null} */
250
+ const kindOf = (/** @type {string} */ t) => {
251
+ const u = /[a-z%]*$/i.exec(t)?.[0].toLowerCase() ?? '';
252
+ if (!u) return 'number';
253
+ if (u === '%') return 'percent';
254
+ if (/^(m?s)$/.test(u)) return 'time';
255
+ if (/^(deg|rad|grad|turn)$/.test(u)) return 'angle';
256
+ return 'length';
257
+ };
258
+ /** @type {string | null} */
259
+ let why = null;
260
+ const fail = (/** @type {string} */ w) => {
261
+ why ??= w;
262
+ return 'number';
263
+ };
264
+ const join = (
265
+ /** @type {string} */ a,
266
+ /** @type {string} */ b,
267
+ /** @type {string} */ op,
268
+ ) => {
269
+ if (op === '+' || op === '-') {
270
+ if (a === b) return a;
271
+ const lp = new Set([a, b]);
272
+ if (lp.has('length') && lp.has('percent') && lp.size === 2)
273
+ return 'length';
274
+ return fail(`${a} ${op} ${b} adds two kinds of value`);
275
+ }
276
+ if (op === '*') {
277
+ if (a === 'number') return b;
278
+ if (b === 'number') return a;
279
+ return fail(`${a} * ${b} multiplies two values with units`);
280
+ }
281
+ if (b === 'number') return a;
282
+ return fail(`${a} / ${b} divides by a value with a unit`);
283
+ };
284
+ /** @returns {string} */
285
+ const factor = () => {
286
+ const t = tokens[pos++];
287
+ if (t === '(') {
288
+ const k = sum();
289
+ pos++;
290
+ return k;
291
+ }
292
+ if (t === '-' || t === '+') return factor();
293
+ return t == null ? 'number' : (kindOf(t) ?? 'number');
294
+ };
295
+ /** @returns {string} */
296
+ const product = () => {
297
+ let k = factor();
298
+ while (tokens[pos] === '*' || tokens[pos] === '/') {
299
+ const op = tokens[pos++];
300
+ k = join(k, factor(), op);
301
+ }
302
+ return k;
303
+ };
304
+ /** @returns {string} */
305
+ function sum() {
306
+ let k = product();
307
+ while (tokens[pos] === '+' || tokens[pos] === '-') {
308
+ const op = tokens[pos++];
309
+ k = join(k, product(), op);
310
+ }
311
+ return k;
312
+ }
313
+ sum();
314
+ if (why) return why;
315
+ }
316
+ return null;
317
+ }
318
+
157
319
  /**
158
320
  * The fallbacks of the var() calls inside a value that is not one var()
159
321
  * alone (`calc(var(--x, 4px) * 2)`), in order. A var() with an empty
@@ -227,6 +389,25 @@ function matchingParen(text, open) {
227
389
  return -1;
228
390
  }
229
391
 
392
+ /** A yes or no word, which `rounded` reads as round or square. */
393
+ const YES_NO = /^(true|yes|on|none|false|off|no)$/i;
394
+
395
+ /**
396
+ * A value as the corners dial reads it: a rung in any case, or a size with
397
+ * its unit (`10PX`, `1rem`) in px; null for anything else, a bare number
398
+ * included.
399
+ * @param {string} v
400
+ * @returns {string | null}
401
+ */
402
+ function cornersRead(v) {
403
+ const lower = String(v).trim().toLowerCase();
404
+ if (CORNERS.some(([n]) => n === lower)) return lower;
405
+ if (/^(0|none|sharp|zero|flat)$/.test(lower)) return 'square';
406
+ if (/^[+-]?\d*\.?\d+$/.test(lower)) return null;
407
+ const px = lengthPx(lower);
408
+ return px != null && px >= 0 ? `${Math.round(px * 100) / 100}px` : null;
409
+ }
410
+
230
411
  /**
231
412
  * A text size written another way (20px, 2e1, +20, 1.25rem, 125%, `20 px`,
232
413
  * `1,25rem`) as the body size in pixels text-size takes, kept to its 10 to
@@ -235,13 +416,52 @@ function matchingParen(text, open) {
235
416
  * @returns {number | null}
236
417
  */
237
418
  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'),
419
+ // Paste debris around the size (quotes, `!important`, a trailing `;` or
420
+ // `,`) is not part of it.
421
+ const bare = withoutDebris(
422
+ String(v)
423
+ .replace(/^\s*(["'])(.*)\1\s*$/, '$2')
424
+ .replace(/\s*!\s*important\s*/i, '')
425
+ .replace(/[;,]+\s*$/, ''),
243
426
  );
427
+ const plain = typedPlain(bare)
428
+ .replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
429
+ .replace(/\s+/g, '')
430
+ .replace(/^(\d+),(\d+)/, '$1.$2');
431
+ // A constant calc() of px and rem sizes (`calc(16px + 2px)`) is worked out.
432
+ const calc =
433
+ /^calc\((\d*\.?\d+)(px|rem|em)?([*/+-])(\d*\.?\d+)(px|rem|em)?\)$/i.exec(
434
+ plain,
435
+ );
436
+ if (calc) {
437
+ const px = (/** @type {string} */ n, /** @type {string | undefined} */ u) =>
438
+ Number(n) * (u && /r?em/i.test(u) ? 16 : 1);
439
+ const [a, b] = [px(calc[1], calc[2]), px(calc[4], calc[5])];
440
+ const op = calc[3];
441
+ // Sizes add and subtract; a size scales by a plain number.
442
+ const r =
443
+ op === '+' || op === '-'
444
+ ? calc[2] && calc[5]
445
+ ? op === '+'
446
+ ? a + b
447
+ : a - b
448
+ : null
449
+ : op === '*'
450
+ ? calc[2] && calc[5]
451
+ ? null
452
+ : a * b
453
+ : calc[5]
454
+ ? null
455
+ : a / b;
456
+ return r != null && Number.isFinite(r) && r >= 10 && r <= 32
457
+ ? Math.round(r * 100) / 100
458
+ : null;
459
+ }
460
+ const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/i.exec(plain);
244
461
  if (!m) return null;
462
+ // A bare number under 4 (1.5, 1.125) reads as rem as much as px: no
463
+ // size is guessed for it.
464
+ if (!m[2] && Number(m[1]) < 4) return null;
245
465
  const unit = (m[2] ?? '').toLowerCase();
246
466
  const n =
247
467
  Number(m[1]) *
@@ -334,6 +554,8 @@ function valueMeant(type, value) {
334
554
  .replace(/\s*!\s*important\s*$/i, '')
335
555
  .replace(/;+\s*$/, '')
336
556
  .trim();
557
+ // Copy debris around it (a trailing comma, a stray quote or bracket).
558
+ p = withoutDebris(p).trim();
337
559
  const q = /^(["'])(.*)\1$/.exec(p);
338
560
  if (q && type !== 'font') p = q[2].trim();
339
561
  const out = [p];
@@ -344,13 +566,14 @@ function valueMeant(type, value) {
344
566
  if (type === 'font' || type === 'font-family') {
345
567
  // A comma left out between families (`"Open Sans" serif`), read with
346
568
  // css-tree.
569
+ // The stack read as families (a trailing comma, a stack wrapped in one
570
+ // more pair of quotes), each quoted as CSS needs it.
571
+ const fams = familiesOf(p);
572
+ // A number or size is no family: never quoted into one (`"700"`).
573
+ if (fams?.length && !fams.some(f => NUMBERISH.test(f)))
574
+ out.push(fams.map(f => cssFamily(f, true)).join(', '));
347
575
  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(', '));
576
+ if (listed && !fams?.length) out.push(listed);
354
577
  }
355
578
  return [...new Set(out)].filter(x => x && x !== value.trim());
356
579
  }
@@ -590,6 +813,22 @@ export function storedProblems(ctx, slug, data, skip = '') {
590
813
  return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
591
814
  if (s.mode && s.source === 'dial' && !PALETTE_DIALS.includes(s.thing))
592
815
  return scope(`${s.thing} is the same in light and dark`);
816
+ // A light and a dark pair saved for one mode (a hand edit): set
817
+ // refuses that, so the loader does too; the repair is the half saved
818
+ // for that mode.
819
+ if (s.mode && /^\s*light-dark\(/i.test(String(s.value ?? ''))) {
820
+ const pair = colorPair(
821
+ String(s.value)
822
+ .trim()
823
+ .replace(/^light-dark\(\s*([\s\S]*)\)\s*$/i, 'light: $1')
824
+ .replace(/,\s*/, '; dark: '),
825
+ );
826
+ return {
827
+ setting: s,
828
+ why: `${s.thing} gives both modes with light-dark(), and is saved for ${s.mode} only`,
829
+ ...(pair ? {fix: s.mode === 'dark' ? pair.dark : pair.light} : {}),
830
+ };
831
+ }
593
832
  if (t && s.state && ![...t.states, ...COMMON_STATES].includes(s.state))
594
833
  return scope(`"${s.state}" is not a state of ${s.on}`);
595
834
  if (t && s.when) {
@@ -648,13 +887,45 @@ export function storedProblems(ctx, slug, data, skip = '') {
648
887
  // it.
649
888
  for (const s of data.settings) {
650
889
  if (replaced(s) || typeof s.value !== 'string') continue;
651
- const clean = normalValueText(s.value);
652
- if (clean !== s.value)
890
+ // Read as typed input is (a font family's quotes trimmed too), so the
891
+ // line offered is the value set would save.
892
+ const clean = /font/i.test(s.thing)
893
+ ? trimInsideQuotes(normalValueText(s.value))
894
+ : normalValueText(s.value);
895
+ if (clean !== s.value) {
896
+ // Name what is wrong: invisible spaces, or quotes around the value
897
+ // CSS does not read (a curly quote inside a quoted string is fine,
898
+ // and is left as it is).
899
+ const spaces =
900
+ clean.replace(/["']/g, '') !==
901
+ s.value.replace(
902
+ /[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`"']/g,
903
+ '',
904
+ );
905
+ const quotes =
906
+ /[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`]/.test(
907
+ s.value,
908
+ ) &&
909
+ clean.replace(
910
+ /[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
911
+ '',
912
+ ) !==
913
+ s.value.replace(
914
+ /[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
915
+ '',
916
+ );
917
+ const why = [
918
+ spaces &&
919
+ 'a no-break, thin or zero-width space, which the browser does not read as a space',
920
+ quotes &&
921
+ 'curly or other quotes around a value, where CSS reads only straight ones',
922
+ ].filter(Boolean);
653
923
  found.push({
654
924
  setting: s,
655
- why: `${s.thing} holds a no-break, thin or zero-width space, which the browser does not read as a space`,
925
+ why: `${s.thing} holds ${why.join(', and ') || 'characters the browser does not read as written'}`,
656
926
  fix: clean,
657
927
  });
928
+ }
658
929
  }
659
930
  for (const s of data.settings) {
660
931
  if (s.source !== 'token' || s.thing === skipThing || !(s.thing in TOKENS))
@@ -700,6 +971,128 @@ export function storedProblems(ctx, slug, data, skip = '') {
700
971
  return found;
701
972
  }
702
973
 
974
+ /** The generic families a font list ends with. */
975
+ const GENERIC_FAMILIES = [
976
+ 'serif',
977
+ 'sans-serif',
978
+ 'monospace',
979
+ 'system-ui',
980
+ 'cursive',
981
+ 'fantasy',
982
+ 'ui-serif',
983
+ 'ui-sans-serif',
984
+ 'ui-monospace',
985
+ 'ui-rounded',
986
+ ];
987
+
988
+ /** The theme-wide dial or token for a CSS property typed with no part. */
989
+ const WHOLE_THEME_EQUIVALENT = /** @type {Record<string, string>} */ ({
990
+ 'border-radius': 'corners',
991
+ 'font-size': 'text-size',
992
+ 'font-family': 'font',
993
+ color: '--color-text-primary',
994
+ background: '--color-background-body',
995
+ 'background-color': '--color-background-body',
996
+ });
997
+
998
+ /** A number or a size, which is never a font family. */
999
+ const NUMBERISH = /^[+-]?(\d+\.?\d*|\.\d+)(px|rem|em|pt|%)?$/i;
1000
+
1001
+ /**
1002
+ * The font list a value with a missing comma or a spaced generic means
1003
+ * (`Georgia serif` is `Georgia, serif`, `Inter, sans serif` is `Inter,
1004
+ * sans-serif`), with why; null when it has neither. A generic is read only
1005
+ * in lower case, so a family named `Source Serif` stays one name.
1006
+ * @param {string} value
1007
+ * @returns {{value: string, why: string} | null}
1008
+ */
1009
+ export function fontListMeant(value) {
1010
+ const v = String(value).trim();
1011
+ // A whole list in one pair of quotes or brackets (`"Inter, serif"`,
1012
+ // `「Inter, serif」`): the quotes go around one family, so the list is
1013
+ // what is inside.
1014
+ const wrapped =
1015
+ /^(?:"([^"]*,[^"]*)"|'([^']*,[^']*)'|「([^」]*,[^」]*)」|『([^』]*,[^』]*)』|“([^”]*,[^”]*)”|‘([^’]*,[^’]*)’|«([^»]*,[^»]*)»)$/.exec(
1016
+ v,
1017
+ );
1018
+ if (wrapped) {
1019
+ const inside = wrapped.slice(1).find(x => x != null) ?? '';
1020
+ return {
1021
+ value: (fontListMeant(inside)?.value ?? inside).trim(),
1022
+ why: 'quotes go around one family name, not the whole list',
1023
+ };
1024
+ }
1025
+ if (/["']/.test(v)) return null;
1026
+ // Families split by `|`, `;` or ` / ` instead of commas.
1027
+ if (
1028
+ // (A pasted declaration, `font-family: Georgia, serif;`, is read
1029
+ // elsewhere: a colon or a trailing `;` is no separator.)
1030
+ !/:|\.(woff2?|ttf|otf)\b/i.test(v) &&
1031
+ /\S\s*(?:\||;|\s\/\s)\s*\S/.test(v)
1032
+ ) {
1033
+ const list = v
1034
+ .split(/\s*(?:\||;|\s\/\s)\s*/)
1035
+ .map(x => x.trim())
1036
+ .filter(Boolean)
1037
+ .join(', ');
1038
+ if (list && list !== v)
1039
+ return {
1040
+ value: fontListMeant(list)?.value ?? list,
1041
+ why: 'families are separated by commas',
1042
+ };
1043
+ }
1044
+ if (/\bsans serif\b/.test(v) && !/\d/.test(v))
1045
+ return {
1046
+ value: v.replace(/\bsans serif\b/g, 'sans-serif'),
1047
+ why: 'the generic family is sans-serif, with a dash',
1048
+ };
1049
+ // A comma missing before the generic family of any family in the list
1050
+ // (`Inter, Georgia serif`), the names in any case (`georgia serif`).
1051
+ const SHORTHAND =
1052
+ /^(\d+(\.\d+)?(px|rem|em|pt|%)?|bold|bolder|lighter|normal|italic|oblique|small-caps)$/i;
1053
+ // A word of a family name: letters (a digit after the first word, as in
1054
+ // `Source Serif 4`), or a generic; never a shorthand's weight or size.
1055
+ const familyWord = (/** @type {string} */ w, /** @type {number} */ i) =>
1056
+ (/^[A-Za-z][A-Za-z0-9]*$/.test(w) && !SHORTHAND.test(w)) ||
1057
+ (i > 0 && /^\d+$/.test(w)) ||
1058
+ GENERIC_FAMILIES.includes(w);
1059
+ const pieces = v.split(/\s*,\s*/);
1060
+ let missing = false;
1061
+ const fixedPieces = pieces.map(piece => {
1062
+ const ws = piece.split(/\s+/);
1063
+ const end = ws[ws.length - 1];
1064
+ if (
1065
+ ws.length > 1 &&
1066
+ GENERIC_FAMILIES.includes(end) &&
1067
+ ws.slice(0, -1).every(familyWord)
1068
+ ) {
1069
+ missing = true;
1070
+ return `${ws.slice(0, -1).join(' ')}, ${end}`;
1071
+ }
1072
+ return piece;
1073
+ });
1074
+ if (missing && pieces.length > 1)
1075
+ return {
1076
+ value: fixedPieces.join(', '),
1077
+ why: 'a comma goes before each generic family',
1078
+ };
1079
+ if (v.includes(',')) return null;
1080
+ const words = v.split(/\s+/);
1081
+ const last = words[words.length - 1];
1082
+ // Only family names before it (capitalized words), never a font
1083
+ // shorthand's weight, style or size.
1084
+ if (
1085
+ words.length > 1 &&
1086
+ GENERIC_FAMILIES.includes(last) &&
1087
+ words.slice(0, -1).every(familyWord)
1088
+ )
1089
+ return {
1090
+ value: `${words.slice(0, -1).join(' ')}, ${last}`,
1091
+ why: `a comma goes before the generic family ${last}`,
1092
+ };
1093
+ return null;
1094
+ }
1095
+
703
1096
  /**
704
1097
  * A value of a type to put in a suggestion, so a suggested command runs.
705
1098
  * @param {string} type
@@ -739,6 +1132,8 @@ function groupOfPropType(prop) {
739
1132
  * @param {string} slug
740
1133
  * @param {string[]} [readers] the CSS properties that read the token
741
1134
  * @param {boolean} [multiplied] whether Core multiplies the token by a size
1135
+ * @param {boolean} [isSet] whether the theme sets the token now (an undo
1136
+ * of it works)
742
1137
  */
743
1138
  function checkTypedValue(
744
1139
  type,
@@ -749,6 +1144,7 @@ function checkTypedValue(
749
1144
  slug,
750
1145
  readers = [],
751
1146
  multiplied = false,
1147
+ isSet = true,
752
1148
  ) {
753
1149
  // The value meant, when what is wrong is how it was typed (a trailing
754
1150
  // `;`, a comment, quotes around it, full-width characters, a font name
@@ -772,17 +1168,37 @@ function checkTypedValue(
772
1168
  }
773
1169
  return null;
774
1170
  };
775
- /** @param {string} what @param {string} example */
1171
+ /** @param {string} what @param {string | null} example */
776
1172
  const bad = (what, example) =>
777
1173
  refuse(
778
1174
  E.ERR_THEME_BAD_VALUE,
779
1175
  `${name} is ${what}; "${value}" is not one.`,
780
1176
  {
1177
+ // Nothing read from the value (no example given): how, never a
1178
+ // stock value.
781
1179
  run: [
782
- `${P} set ${slug} ${name} ${quoteCommandArgument(meant() ?? example)}`,
1180
+ (meant() ?? example) == null
1181
+ ? `${HOW} ${name}`
1182
+ : `${P} set ${slug} ${name} ${quoteCommandArgument(String(meant() ?? example))}`,
783
1183
  ],
784
1184
  },
785
1185
  );
1186
+ // A font family list with a comma missing before a generic family
1187
+ // (`Georgia serif`), or a generic written with a space (`sans serif`): the
1188
+ // list meant.
1189
+ if (type === 'font') {
1190
+ const fixed = fontListMeant(value);
1191
+ if (fixed)
1192
+ refuse(
1193
+ E.ERR_THEME_BAD_VALUE,
1194
+ `"${value}" names a family that exists nowhere: ${fixed.why}.`,
1195
+ {
1196
+ run: [
1197
+ `${P} set ${slug} ${name} ${quoteCommandArgument(fixed.value)}`,
1198
+ ],
1199
+ },
1200
+ );
1201
+ }
786
1202
  // A font file or a link is no family name: never quoted into one.
787
1203
  if (type === 'font') {
788
1204
  const file = fontFileReason(pastedFont(value) || value);
@@ -792,6 +1208,18 @@ function checkTypedValue(
792
1208
  `${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
793
1209
  ],
794
1210
  });
1211
+ // An empty family (`""`, a trailing comma) or one quoted name holding
1212
+ // commas is a broken stack: the browser drops the fallback after it.
1213
+ const pieces = familyPieces(value);
1214
+ if (
1215
+ pieces &&
1216
+ (pieces.some(f => !f.name) ||
1217
+ pieces.some(f => f.quoted && f.name.includes(',')))
1218
+ )
1219
+ bad(
1220
+ 'a font family list with a name for each family',
1221
+ exampleOf(type, name),
1222
+ );
795
1223
  }
796
1224
  if (!isSafeValue(value))
797
1225
  refuse(
@@ -813,14 +1241,24 @@ function checkTypedValue(
813
1241
  if (keyword)
814
1242
  refuse(
815
1243
  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.`,
1244
+ `"${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
1245
  {
1246
+ // How for the token; the undo only when the theme sets it.
818
1247
  run: [
819
- `${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
820
- `${P} undo ${slug} ${name}`,
1248
+ `${HOW} ${name}`,
1249
+ ...(isSet ? [`${P} undo ${slug} ${name}`] : []),
821
1250
  ],
822
1251
  },
823
1252
  );
1253
+ // Math whose units cannot combine (`8 + 2px`, `0.5rem * 1px`, a var()
1254
+ // read as its fallback): the browser drops the whole value.
1255
+ const math = type === 'size' ? calcUnitProblem(value) : null;
1256
+ if (math)
1257
+ refuse(
1258
+ E.ERR_THEME_BAD_VALUE,
1259
+ `${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.`,
1260
+ {run: [`${HOW} ${name}`]},
1261
+ );
824
1262
  // A var() inside a larger value (calc, max, color-mix) has a fallback of
825
1263
  // the token's kind too, checked like a whole-value var().
826
1264
  if (type !== 'other')
@@ -834,6 +1272,16 @@ function checkTypedValue(
834
1272
  )
835
1273
  )
836
1274
  continue;
1275
+ // A factor in a size's math (`calc(0.75rem * var(--x, 1))`, as the
1276
+ // official themes write their type scale): a plain number there is
1277
+ // what multiplies the size.
1278
+ if (
1279
+ type === 'size' &&
1280
+ within.some(f => /^(calc|min|max|clamp)$/i.test(f)) &&
1281
+ /^[+-]?(\d+\.?\d*|\.\d+)$/.test(fallback.trim()) &&
1282
+ (/[*/]\s*var\(/i.test(value) || /var\([^()]*\)\s*[*/]/i.test(value))
1283
+ )
1284
+ continue;
837
1285
  if (fallback === '')
838
1286
  refuse(
839
1287
  E.ERR_THEME_BAD_VALUE,
@@ -896,26 +1344,22 @@ function checkTypedValue(
896
1344
  );
897
1345
  return;
898
1346
  }
899
- if (type === 'color' && !isFixedColor(value)) bad('a color', '#1f2937');
1347
+ if (type === 'color' && !isFixedColor(value)) bad('a color', null);
900
1348
  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';
1349
+ // The token's own default is never offered as a repair: only a size
1350
+ // read from the value typed.
1351
+ const sizeExample = null;
912
1352
  // The size meant, when one dot or sign is all that is wrong (1.px).
913
1353
  const meant = value.trim().replace(/(\d)\.(?=[a-z%]|$)/gi, '$1');
914
1354
  // A bare number is the size in px.
915
1355
  // A bare number is the size in px; a minus sign is dropped.
916
1356
  const plain = value.trim().replace(/^-(?=\d|\.\d)/, '');
1357
+ // A bare number below one (a pasted `--radius: 0.5rem` that lost its
1358
+ // unit) has no unit to read it by: no size is guessed, as corners does.
917
1359
  const px = /^[+]?\d*\.?\d+(e[+-]?\d+)?$/i.test(plain)
918
- ? `${Number(plain)}px`
1360
+ ? Number(plain) > 0 && Number(plain) < 1
1361
+ ? null
1362
+ : `${Number(plain)}px`
919
1363
  : /^\d*\.?\d+[a-z%]+$/i.test(plain) && plain !== value.trim()
920
1364
  ? plain
921
1365
  : null;
@@ -1231,6 +1675,18 @@ function nearestColorName(v) {
1231
1675
  return nearest(w, COLOR_NAMES)[0] ?? null;
1232
1676
  }
1233
1677
 
1678
+ /**
1679
+ * Old keywords a property's grammar lists that no current browser applies,
1680
+ * each with the keyword that does what it meant.
1681
+ * @type {Record<string, Record<string, string>>}
1682
+ */
1683
+ const OBSOLETE_KEYWORDS = {
1684
+ cursor: {hand: 'pointer'},
1685
+ };
1686
+ documentReadings(
1687
+ Object.values(OBSOLETE_KEYWORDS).flatMap(words => Object.entries(words)),
1688
+ );
1689
+
1234
1690
  /**
1235
1691
  * Why a value is not one the property takes, or null. Colors are checked
1236
1692
  * by the editor's own color check; a property css-tree has no grammar for
@@ -1251,6 +1707,14 @@ function propertyProblem(prop, value) {
1251
1707
  takes: `a value its CSS grammar takes in each var() fallback too (${grammarText(known)})`,
1252
1708
  near: initialOf(prop),
1253
1709
  };
1710
+ // An old keyword the grammar still lists but no current browser
1711
+ // applies (`cursor: hand`): the keyword that does what it meant.
1712
+ const obsolete = OBSOLETE_KEYWORDS[prop]?.[v.toLowerCase()];
1713
+ if (obsolete)
1714
+ return {
1715
+ takes: `a value current browsers apply ("${v}" is an old keyword none applies; ${obsolete} does what it meant)`,
1716
+ near: obsolete,
1717
+ };
1254
1718
  if (matchValue(prop, v))
1255
1719
  return belowRange(prop, v)
1256
1720
  ? {
@@ -1281,9 +1745,7 @@ function propertyProblem(prop, value) {
1281
1745
  null)
1282
1746
  : null;
1283
1747
  // 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);
1748
+ // or the value typed cleaned; each checked.
1287
1749
  // A bare number on a length property means px (`padding 4` → `4px`, each
1288
1750
  // number in a list too), when the property takes that.
1289
1751
  // Each bare number token gets px (a mixed list `4 8px`, `8 / 4`, an
@@ -1296,31 +1758,70 @@ function propertyProblem(prop, value) {
1296
1758
  Number(num) === 0 ? `${pre}${num}` : `${pre}${num}px`,
1297
1759
  )
1298
1760
  : null;
1299
- // A suggestion is offered only when the property takes it, in range too.
1761
+ // A suggestion is offered only when the property takes it, in range too,
1762
+ // and never a reset the input did not hold (0, none, 1, auto, normal):
1763
+ // following it would undo what was asked. A reset typed with a typo
1764
+ // (`nnone`, `normall`: a word within two edits of it) is that reset,
1765
+ // corrected.
1766
+ const RESETS =
1767
+ /^(0|0px|none|1|auto|normal|initial|unset|inherit|revert|transparent)$/i;
1768
+ const typedAs = (/** @type {string} */ x) => x === typed || typoOf(typed, x);
1300
1769
  const takes = (/** @type {string | null} */ x) =>
1301
- x != null && matchValue(prop, x) != null && !belowRange(prop, x);
1770
+ x != null &&
1771
+ matchValue(prop, x) != null &&
1772
+ !belowRange(prop, x) &&
1773
+ !(RESETS.test(x.trim()) && !typedAs(x.trim().toLowerCase()));
1774
+ // A lone length on a shorthand where it is only a position (background,
1775
+ // mask) wipes the rest: no px is guessed there.
1776
+ const pxFits = !/^(background|mask)$/i.test(prop);
1777
+ // Words with a documented reading on a property (the allowlist a repair
1778
+ // may map through).
1779
+ const WORDS = PROPERTY_WORDS;
1780
+ // A weight word is its number (the same table the headings dial reads);
1781
+ // text in content is that text, quoted.
1782
+ const weightWord = typed.replace(/[\s-]+/g, '');
1783
+ const weight = HEADING_WEIGHTS[weightWord] ?? WEIGHT_WORDS[weightWord];
1784
+ const mapped =
1785
+ WORDS[prop]?.[typed.replace(/\s+/g, '-')] ??
1786
+ (prop === 'font-weight' && weight ? weight : null) ??
1787
+ (prop === 'content' && !/^["']|["']$/.test(v) ? JSON.stringify(v) : null) ??
1788
+ null;
1302
1789
  return {
1303
1790
  takes: `a value its CSS grammar takes (${grammarText(known)})`,
1304
1791
  near:
1305
- (takes(withPx) ? withPx : null) ??
1792
+ (mapped && matchValue(prop, mapped) != null ? mapped : null) ??
1793
+ (pxFits && takes(withPx) ? withPx : null) ??
1306
1794
  // Below the property's range (a negative width): the same, 0 or more.
1307
- (withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
1795
+ (pxFits && withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
1308
1796
  ? withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1')
1309
1797
  : null) ??
1310
1798
  (takes(joined) && joined !== v ? joined : null) ??
1311
1799
  // Several values on a property that takes one (padding-top with four):
1312
- // the first of them, when it is one the property takes.
1800
+ // the first of them, when it is one the property takes. Not when the
1801
+ // rest are words (`2 spacing units` is no 2px).
1313
1802
  (() => {
1314
- const first = splitTop((withPx ?? joined).trim(), ' ')[0];
1315
- return first && first !== v && takes(first) ? first : null;
1803
+ const all = splitTop((withPx ?? joined).trim(), ' ');
1804
+ if (all.slice(1).some(x => /^[a-z]/i.test(x))) return null;
1805
+ const first = all[0];
1806
+ return pxFits && first && first !== v && takes(first) ? first : null;
1316
1807
  })() ??
1317
1808
  (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))),
1809
+ // Layers typed with one too many or an empty one (`url(a.png), red,
1810
+ // blue`, `red,,blue`): the layers before the last, else one of them,
1811
+ // when the property takes it. Never the property's reset or a stock
1812
+ // example: a repair carries only what was typed.
1813
+ (() => {
1814
+ const layers = splitTop(v.trim(), ',')
1815
+ .map(x => x.trim())
1816
+ .filter(Boolean);
1817
+ if (layers.length < 2 && !/,\s*,/.test(v)) return null;
1818
+ const tries = [
1819
+ layers.join(', '),
1820
+ layers.slice(0, -1).join(', '),
1821
+ ...layers,
1822
+ ];
1823
+ return tries.find(x => x && x !== v && takes(x)) ?? null;
1824
+ })(),
1324
1825
  };
1325
1826
  }
1326
1827
 
@@ -1385,35 +1886,695 @@ function baseReads(ctx, like, token) {
1385
1886
  } catch {
1386
1887
  return false;
1387
1888
  }
1388
- }
1389
-
1390
- /**
1391
- * Check one setting and give it back ready to store, or refuse. What it
1392
- * accepts, the settings loader takes too: the loader's own check runs last,
1393
- * so a saved setting never blocks the theme.
1394
- * @param {import('./_settings.mjs').Ctx} ctx
1395
- * @param {string} slug
1396
- * @param {import('./_settings.mjs').ThemeData} data
1397
- * @param {string} thing
1398
- * @param {string | undefined} value
1399
- * @param {SetFlags} flags
1400
- * @param {boolean} [unset] an undo of one setting: only the identity of the setting is checked
1401
- * @returns {import('./_settings.mjs').Setting}
1402
- */
1403
- export function checkSetting(
1404
- ctx,
1405
- slug,
1406
- data,
1407
- thing,
1408
- value,
1409
- flags,
1410
- unset = false,
1411
- ) {
1412
- // Any other dial's value pasted with its property name (`font-size:
1413
- // 18px;` for text-size, `color: #e11d48` for accent) is the value: one
1414
- // 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);
1889
+ }
1890
+
1891
+ /**
1892
+ * The headings rung nearest a weight number (800 is heavy).
1893
+ * @param {number} weight
1894
+ */
1895
+ const weightRung = weight =>
1896
+ Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
1897
+ Math.abs(Number(b[1]) - weight) < Math.abs(Number(a[1]) - weight) ? b : a,
1898
+ )[0];
1899
+ documentNumericTable(
1900
+ ['headings', 'font-weight'],
1901
+ Object.entries(HEADING_WEIGHTS).map(([w, n]) => [w, Number(n)]),
1902
+ [1, 1000],
1903
+ );
1904
+ // A font weight runs from 1 to 1000.
1905
+ documentRange(['font-weight', '--font-weight-*'], 1, 1000);
1906
+ documentNumericTable(
1907
+ ['spacing'],
1908
+ SPACING.map(([name, factor]) => [name, factor]),
1909
+ );
1910
+ documentNumericTable(
1911
+ ['text-size'],
1912
+ TEXT_SIZE.map(([name, px]) => [name, px]),
1913
+ );
1914
+ // The text size number is the body size in pixels, 10 to 32; vibrancy
1915
+ // runs from 0 to 100.
1916
+ documentRange(['text-size'], 10, 32);
1917
+ documentRange(['vibrancy'], 0, 100);
1918
+ documentReadings(TEXT_SIZE.map(([name, px]) => [name, `${px}px`]));
1919
+ documentReadings(Object.entries(HEADING_TRACKING));
1920
+ // `bold` given a no (false, off) is the normal weight.
1921
+ documentReadings(['false', 'off', 'no', 'none'].map(w => [w, 'normal']));
1922
+ /** Words for no rounding: corners square. */
1923
+ const NO_ROUNDING = ['0', '0%', 'none', 'sharp', 'zero', 'no', 'flat'];
1924
+ /** Words for no space: spacing's tightest rung. */
1925
+ const NO_SPACE = ['0', 'none', 'zero', 'no', 'off'];
1926
+ documentReadings(NO_ROUNDING.map(w => [w, 'square']));
1927
+ documentReadings(NO_SPACE.map(w => [w, SPACING[0][0]]));
1928
+ documentReadings(
1929
+ Object.values(DIAL_WORDS).flatMap(words => Object.entries(words)),
1930
+ );
1931
+ /** State words a value may be labeled with. */
1932
+ const STATE_WORDS = [
1933
+ 'hover',
1934
+ 'active',
1935
+ 'focus',
1936
+ 'focus-visible',
1937
+ 'focus-within',
1938
+ 'disabled',
1939
+ 'pressed',
1940
+ 'selected',
1941
+ 'checked',
1942
+ 'open',
1943
+ 'expanded',
1944
+ 'visited',
1945
+ ];
1946
+ /** Words for a kind of screen a value may be labeled with. */
1947
+ const DEVICE_WORDS = [
1948
+ 'phone',
1949
+ 'phones',
1950
+ 'mobile',
1951
+ 'tablet',
1952
+ 'tablets',
1953
+ 'desktop',
1954
+ 'laptop',
1955
+ 'ipad',
1956
+ 'iphone',
1957
+ 'android',
1958
+ 'ios',
1959
+ 'touch',
1960
+ 'small-screen',
1961
+ 'small-screens',
1962
+ 'large-screen',
1963
+ 'large-screens',
1964
+ 'print',
1965
+ ];
1966
+
1967
+ /**
1968
+ * The word a value is labeled with and the value after it (`dark: #2563eb`,
1969
+ * `"corners": "pill"`, `{"dark": "#2563eb"}`, `dark=#2563eb`, `dark mode:
1970
+ * #2563eb`, `textSize: 18`), the word as a dashed name; null when the value
1971
+ * holds no label.
1972
+ * @param {string} value
1973
+ * @returns {{word: string, rest: string, when?: string} | null}
1974
+ */
1975
+ function valueLabel(value) {
1976
+ // A flag's label after the value (`red mode: dark`, `red state: hover`,
1977
+ // `red part: card`) reads as the same label before it (`dark: red`); a
1978
+ // variant or size after it (`red variant: primary`) keeps its prop.
1979
+ const trail =
1980
+ /^\s*(.+?)\s+(mode|theme|state|part|on|variant|size|when)\s*[:=]\s*([a-z][a-z0-9:-]*)\s*;?\s*$/i.exec(
1981
+ String(value),
1982
+ );
1983
+ if (trail && !/[:=]/.test(trail[1])) {
1984
+ const flag = trail[2].toLowerCase();
1985
+ const word = trail[3].toLowerCase();
1986
+ if (/^(variant|size|when)$/.test(flag))
1987
+ return {
1988
+ word: 'when',
1989
+ rest: trail[1].trim(),
1990
+ when: flag === 'when' ? word : `${flag}:${word}`,
1991
+ };
1992
+ return {word, rest: trail[1].trim()};
1993
+ }
1994
+ const m =
1995
+ /^\s*\{?\s*["']?([a-zA-Z][a-zA-Z0-9 _-]*?|--[a-z0-9-]+)["']?\s*[:=]\s*(.+?)\s*;?\s*\}?\s*$/.exec(
1996
+ String(value),
1997
+ );
1998
+ if (!m || /^https?$/i.test(m[1])) return null;
1999
+ const word = m[1]
2000
+ .trim()
2001
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
2002
+ .replace(/[\s_]+/g, '-')
2003
+ .toLowerCase();
2004
+ const rest = m[2].trim().replace(/^"(.*)"\s*,?$/, '$1');
2005
+ return {word, rest};
2006
+ }
2007
+
2008
+ /**
2009
+ * Whether a label is the setting's own name (`accent: red` for accent,
2010
+ * `font-family: Inter` for font).
2011
+ * @param {string} thing @param {string} word
2012
+ */
2013
+ const ownLabel = (thing, word) =>
2014
+ word === thing ||
2015
+ (thing === 'font' && word === 'font-family') ||
2016
+ (thing.startsWith('--font-family') &&
2017
+ (word === 'font-family' || word === 'font')) ||
2018
+ (thing === 'text-size' && word === 'font-size');
2019
+
2020
+ /**
2021
+ * Whether a family is one the editor knows: a system family on the theme
2022
+ * build's list, an open font in its table or a preset's family, or one
2023
+ * whose @fontsource package the project has installed.
2024
+ * @param {any} ctx
2025
+ * @param {string} family without quotes
2026
+ */
2027
+ function knownFamily(ctx, family) {
2028
+ const name = family.trim().toLowerCase();
2029
+ if (!name) return false;
2030
+ if (isSystemFamily(family)) return true;
2031
+ if (
2032
+ [
2033
+ ...Object.values(OPEN_FONTS).map(f => f.family),
2034
+ ...Object.values(FONTS).map(f => f[0]),
2035
+ ].some(f => f.toLowerCase() === name)
2036
+ )
2037
+ return true;
2038
+ try {
2039
+ ctx?.project?.req?.resolve(`${fontsourcePackageOf(family)}/package.json`);
2040
+ return Boolean(ctx?.project?.req);
2041
+ } catch {
2042
+ return false;
2043
+ }
2044
+ }
2045
+
2046
+ /**
2047
+ * The one mode a light-only or dark-only theme shows, or null.
2048
+ * @param {{mode?: string} | null | undefined} data
2049
+ * @returns {'light' | 'dark' | null}
2050
+ */
2051
+ function oneModeOfTheme(data) {
2052
+ return data?.mode === 'light-only'
2053
+ ? 'light'
2054
+ : data?.mode === 'dark-only'
2055
+ ? 'dark'
2056
+ : null;
2057
+ }
2058
+
2059
+ /**
2060
+ * Check one setting and give it back ready to store, or refuse. What it
2061
+ * accepts, the settings loader takes too: the loader's own check runs last,
2062
+ * so a saved setting never blocks the theme.
2063
+ * @param {import('./_settings.mjs').Ctx} ctx
2064
+ * @param {string} slug
2065
+ * @param {import('./_settings.mjs').ThemeData} data
2066
+ * @param {string} thing
2067
+ * @param {string | undefined} value
2068
+ * @param {SetFlags} flags
2069
+ * @param {boolean} [unset] an undo of one setting: only the identity of the setting is checked
2070
+ * @returns {import('./_settings.mjs').Setting}
2071
+ */
2072
+ export function checkSetting(
2073
+ ctx,
2074
+ slug,
2075
+ data,
2076
+ thing,
2077
+ value,
2078
+ flags,
2079
+ unset = false,
2080
+ ) {
2081
+ // Any other dial's value pasted with its property name (`font-size:
2082
+ // 18px;` for text-size, `color: #e11d48` for accent) is the value: one
2083
+ // path for every dial (the font dial reads its own below).
2084
+ // A light and a dark color typed as one value: a token takes both as
2085
+ // light-dark() or one --mode at a time; a color dial takes one color and
2086
+ // makes both modes from it. Never one of them for both.
2087
+ // A light-dark() written with another separator (`light-dark(red /
2088
+ // blue)`, `light-dark(red; blue)`): the pair meant, with a comma.
2089
+ // A dial's own words in any case (ROOMY, MORE, Both, NONE): the word.
2090
+ if (!unset && typeof value === 'string' && DIALS[thing]) {
2091
+ const words = new Set(
2092
+ String(DIALS[thing].values ?? '')
2093
+ .split('|')
2094
+ .filter(w => /^[a-z][a-z-]*$/.test(w)),
2095
+ );
2096
+ const lower = value.trim().toLowerCase();
2097
+ // (On the font dial several words are a family list, whose names keep
2098
+ // their letters; one word is the preset.)
2099
+ const read = thing === 'font' ? [lower] : lower.split(/\s+/);
2100
+ if (lower && read.every(w => words.has(w))) value = lower;
2101
+ }
2102
+ if (!unset && typeof value === 'string') {
2103
+ const near =
2104
+ /^\s*light-dark\(\s*([^,;/()]+?)\s*(?:\s\/\s|\/|;)\s*([^,;/()]+?)\s*\)\s*$/i.exec(
2105
+ value,
2106
+ );
2107
+ if (near)
2108
+ refuse(
2109
+ E.ERR_THEME_BAD_VALUE,
2110
+ `"${value}" separates its two colors with something other than a comma; light-dark() takes "light-dark(light, dark)".`,
2111
+ {
2112
+ run: [
2113
+ setLine(
2114
+ slug,
2115
+ thing,
2116
+ `light-dark(${near[1]}, ${near[2]})`,
2117
+ {...flags, mode: undefined},
2118
+ false,
2119
+ ),
2120
+ ],
2121
+ },
2122
+ );
2123
+ }
2124
+ // A weight (or a style) after a family (`Inter 600`, `Inter bold
2125
+ // italic`) is no family name: the family alone, and the weight where a
2126
+ // weight is set.
2127
+ const familyWeight =
2128
+ !unset &&
2129
+ typeof value === 'string' &&
2130
+ (thing === 'font' ||
2131
+ thing === 'font-family' ||
2132
+ thing.startsWith('--font-family'))
2133
+ ? /^\s*([A-Za-z][A-Za-z ]*?)\s+(\d{3}|thin|light|regular|medium|semibold|semi-bold|bold|extrabold|heavy|black)(\s+italic)?\s*$/i.exec(
2134
+ value,
2135
+ )
2136
+ : null;
2137
+ // A weight word after a family is part of the family's name (Arial
2138
+ // Black, Archivo Black, Segoe UI Semibold) unless the whole name is no
2139
+ // family the editor knows and the name without it is; a weight number
2140
+ // (`Inter 600`) is never part of a name.
2141
+ const weightIsName =
2142
+ familyWeight != null &&
2143
+ !/^\d+$/.test(familyWeight[2]) &&
2144
+ !(
2145
+ !knownFamily(ctx, `${familyWeight[1].trim()} ${familyWeight[2]}`) &&
2146
+ knownFamily(ctx, familyWeight[1].trim())
2147
+ );
2148
+ if (
2149
+ familyWeight &&
2150
+ !weightIsName &&
2151
+ typeof value === 'string' &&
2152
+ !value.includes(',') &&
2153
+ // `bold bold` is a weight twice and `italic bold` a style and a
2154
+ // weight, read below: no family is named.
2155
+ familyWeight[1]
2156
+ .trim()
2157
+ .toLowerCase()
2158
+ .split(/\s+/)
2159
+ .some(
2160
+ w =>
2161
+ HEADING_WEIGHTS[w] === undefined &&
2162
+ WEIGHT_WORDS[w] === undefined &&
2163
+ !/^(italic|oblique|normal|small-caps)$/.test(w),
2164
+ )
2165
+ ) {
2166
+ const family = familyWeight[1].trim();
2167
+ const w = familyWeight[2].toLowerCase().replace('-', '');
2168
+ const word = /^\d+$/.test(w)
2169
+ ? Object.keys(HEADING_WEIGHTS).find(k => HEADING_WEIGHTS[k] === w)
2170
+ : HEADING_WEIGHTS[w] !== undefined
2171
+ ? w
2172
+ : null;
2173
+ refuse(
2174
+ E.ERR_THEME_BAD_VALUE,
2175
+ `"${value.trim()}" puts a weight after the family, so the browser reads one family named that and falls back. ${thing} takes the family (${family}); a weight is set with headings, font-weight or a --font-weight-* token.`,
2176
+ {
2177
+ run: [
2178
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(family)}${flags.on ? ` --on ${flags.on}` : ''}`,
2179
+ ...(thing === 'font' && word
2180
+ ? [`${P} set ${slug} headings ${word}`]
2181
+ : []),
2182
+ ],
2183
+ },
2184
+ );
2185
+ }
2186
+ // A number or size given as a font family (`--font-family-body 700`,
2187
+ // `font-family 16px --on card`) is a weight or a size, never a family.
2188
+ if (
2189
+ !unset &&
2190
+ typeof value === 'string' &&
2191
+ (thing === 'font-family' || thing.startsWith('--font-family')) &&
2192
+ NUMBERISH.test(value.trim())
2193
+ )
2194
+ refuse(
2195
+ E.ERR_THEME_BAD_VALUE,
2196
+ `"${value.trim()}" is a ${/[a-z%]$/i.test(value.trim()) ? 'size' : 'weight'}, not a font family: ${thing} names families (such as Inter, serif). ${/[a-z%]$/i.test(value.trim()) ? 'A text size is set with text-size or a --font-size-* token.' : 'A weight is set with font-weight or a --font-weight-* token.'}`,
2197
+ {run: [`${HOW} ${quoteCommandArgument(thing)}`]},
2198
+ );
2199
+ // A font list with a comma missing before its generic family, or a
2200
+ // generic written with a space, on the font dial: the list meant.
2201
+ if (!unset && typeof value === 'string' && thing === 'font') {
2202
+ const fixed = fontListMeant(value);
2203
+ if (fixed)
2204
+ refuse(
2205
+ E.ERR_THEME_BAD_VALUE,
2206
+ `"${value}" names a family that exists nowhere: ${fixed.why}.`,
2207
+ {run: [setLine(slug, 'font', fixed.value, flags, false)]},
2208
+ );
2209
+ }
2210
+ // A light and a dark color on a part's color property (`background`,
2211
+ // `color`, `border-color` …) is that property's light-dark() pair.
2212
+ if (
2213
+ !unset &&
2214
+ typeof value === 'string' &&
2215
+ flags.on &&
2216
+ !flags.mode &&
2217
+ /^(color|background|(background|border|outline|text-decoration|caret|accent|fill|stroke)(-[a-z]+)?-color)$/.test(
2218
+ String(thing).trim().toLowerCase(),
2219
+ )
2220
+ ) {
2221
+ const pair = colorPair(value);
2222
+ if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark))
2223
+ value = `light-dark(${pair.light}, ${pair.dark})`;
2224
+ }
2225
+ if (
2226
+ !unset &&
2227
+ typeof value === 'string' &&
2228
+ (PALETTE_DIALS.includes(thing) || isColorToken(thing))
2229
+ ) {
2230
+ const pair = colorPair(value);
2231
+ if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
2232
+ const q = quoteCommandArgument;
2233
+ const on = flags.on ? ` --on ${flags.on}` : '';
2234
+ // A theme with one mode shows one half: that half is the line.
2235
+ const only = oneModeOfTheme(data);
2236
+ if (only)
2237
+ refuse(
2238
+ E.ERR_THEME_BAD_VALUE,
2239
+ `"${value}" is a light and a dark color; this theme is ${only} only, so it shows the ${only} one.`,
2240
+ {run: [`${P} set ${slug} ${thing} ${q(pair[only])}${on}`]},
2241
+ );
2242
+ refuse(
2243
+ E.ERR_THEME_BAD_VALUE,
2244
+ PALETTE_DIALS.includes(thing)
2245
+ ? `"${value}" is a light and a dark color; ${thing} takes one color and makes both modes from it.`
2246
+ : `"${value}" is a light and a dark color; ${thing} takes them as light-dark(), or one --mode at a time.`,
2247
+ {
2248
+ run: PALETTE_DIALS.includes(thing)
2249
+ ? [
2250
+ `${P} set ${slug} ${thing} ${q(pair.light)}${on}`,
2251
+ ...(thing === 'accent'
2252
+ ? [
2253
+ `${P} set ${slug} --color-accent ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
2254
+ ]
2255
+ : []),
2256
+ ]
2257
+ : [
2258
+ `${P} set ${slug} ${thing} ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
2259
+ `${P} set ${slug} ${thing} ${q(pair.light)}${on} --mode light`,
2260
+ `${P} set ${slug} ${thing} ${q(pair.dark)}${on} --mode dark`,
2261
+ ],
2262
+ },
2263
+ );
2264
+ }
2265
+ }
2266
+ // A value labeled with a word that is not this setting's own name (a
2267
+ // mode, a state, a device, a part, or a word the editor does not read) is
2268
+ // refused with what that word means here, never set with the word dropped.
2269
+ // A property set on a part (`padding 'hover: 4px' --on button`) and the
2270
+ // type tokens (`--font-weight-bold 'dark: 700'`) are read the same way;
2271
+ // a content string is its own text.
2272
+ const partProperty =
2273
+ Boolean(flags.on) && !DIALS[thing] && !thing.startsWith('--');
2274
+ const familyToken = thing.startsWith('--font-family');
2275
+ if (
2276
+ !unset &&
2277
+ typeof value === 'string' &&
2278
+ !/content/.test(thing) &&
2279
+ (DIALS[thing] || partProperty || thing.startsWith('--'))
2280
+ ) {
2281
+ const label = valueLabel(value);
2282
+ // Another CSS property's name before a part property's value
2283
+ // (`padding 'margin: 8px'`) is that property's value, never this one's.
2284
+ if (
2285
+ label &&
2286
+ partProperty &&
2287
+ label.word !== thing &&
2288
+ !ownLabel(thing, label.word) &&
2289
+ cssProperties().has(label.word) &&
2290
+ label.rest.trim()
2291
+ )
2292
+ refuse(
2293
+ E.ERR_THEME_BAD_VALUE,
2294
+ `"${value}" is labeled ${label.word}, another property than ${thing}; nothing is set from it.`,
2295
+ {
2296
+ didYouMean: [label.word],
2297
+ run: [setLine(slug, label.word, label.rest.trim(), flags, false)],
2298
+ },
2299
+ );
2300
+ // A CSS property's name before the value (`border-radius: pill`,
2301
+ // `color: #e11d48`, `font: bold 16px Inter`) is read by the paths
2302
+ // below, as a declaration pasted from a stylesheet.
2303
+ if (
2304
+ label &&
2305
+ !ownLabel(thing, label.word) &&
2306
+ !cssProperties().has(label.word)
2307
+ ) {
2308
+ const q = quoteCommandArgument;
2309
+ const rest = label.rest;
2310
+ const scope = `${flags.on ? ` --on ${flags.on}` : ''}${flags.when ? ` --when ${flags.when}` : ''}`;
2311
+ // A variant named after the value: the value with --when.
2312
+ if ('when' in label && label.when)
2313
+ refuse(
2314
+ E.ERR_THEME_BAD_VALUE,
2315
+ `"${value}" names a variant after the value; a value for one variant is given with --on <part> --when ${label.when}.`,
2316
+ {
2317
+ didYouMean: ['--when'],
2318
+ run: [
2319
+ flags.on
2320
+ ? `${P} set ${slug} ${thing} ${q(rest)} --on ${flags.on} --when ${label.when}`
2321
+ : `${HOW} ${q(`${label.when.split(':').pop()} ${thing}`)}`,
2322
+ ],
2323
+ },
2324
+ );
2325
+ const mode = MODE_WORDS[label.word];
2326
+ const colorful =
2327
+ PALETTE_DIALS.includes(thing) ||
2328
+ (thing.startsWith('--') && isColorToken(thing)) ||
2329
+ (partProperty &&
2330
+ /color|^background$|^fill$|^stroke$|shadow/.test(thing));
2331
+ const parts = [...ctx.project.target.keys(), ...Object.keys(FAMILIES)];
2332
+ // A theme with one mode: its own mode's label is the value, as the
2333
+ // theme has no other; the other mode's label names a mode it lacks.
2334
+ const only = oneModeOfTheme(data);
2335
+ if (mode && only) {
2336
+ if (mode === only)
2337
+ return checkSetting(ctx, slug, data, thing, rest, flags, unset);
2338
+ refuse(
2339
+ E.ERR_THEME_BAD_VALUE,
2340
+ `"${label.word}" in "${value}" names the ${mode} mode, which this ${only}-only theme does not show.`,
2341
+ {
2342
+ run: [
2343
+ `${P} set ${slug} mode both`,
2344
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}`,
2345
+ ],
2346
+ },
2347
+ );
2348
+ }
2349
+ if (mode && DIALS[thing] && PALETTE_DIALS.includes(thing))
2350
+ refuse(
2351
+ E.ERR_THEME_BAD_VALUE,
2352
+ `"${label.word}" in "${value}" names the ${mode} mode; ${thing} makes both modes from one color.`,
2353
+ {
2354
+ run: [
2355
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}`,
2356
+ ...(thing === 'accent'
2357
+ ? [
2358
+ `${P} set ${slug} --color-accent ${q(rest)}${scope} --mode ${mode}`,
2359
+ ]
2360
+ : []),
2361
+ ],
2362
+ },
2363
+ );
2364
+ const level = /^h([1-6])$/.exec(label.word)?.[1];
2365
+ if (level && thing === 'headings') {
2366
+ const w = rest.trim().toLowerCase();
2367
+ refuse(
2368
+ E.ERR_THEME_BAD_VALUE,
2369
+ `"${label.word}" in "${value}" is one heading level; headings sets every level, and one level is set with --on heading --when level:${level}.`,
2370
+ {
2371
+ run:
2372
+ HEADING_WEIGHTS[w] !== undefined
2373
+ ? [
2374
+ `${P} set ${slug} font-weight ${HEADING_WEIGHTS[w]} --on heading --when level:${level}`,
2375
+ `${P} set ${slug} headings ${w}`,
2376
+ ]
2377
+ : HEADING_TRACKING[w] !== undefined
2378
+ ? [
2379
+ `${P} set ${slug} letter-spacing ${q(HEADING_TRACKING[w])} --on heading --when level:${level}`,
2380
+ `${P} set ${slug} headings ${w}`,
2381
+ ]
2382
+ : [`${HOW} headings`],
2383
+ },
2384
+ );
2385
+ }
2386
+ if (mode)
2387
+ refuse(
2388
+ E.ERR_THEME_BAD_VALUE,
2389
+ colorful
2390
+ ? `"${label.word}" in "${value}" names the ${mode} mode; a value for one mode is given with --mode ${mode}.`
2391
+ : `"${label.word}" in "${value}" names the ${mode} mode, and ${thing} is the same in light and dark.`,
2392
+ {
2393
+ run: [
2394
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}${colorful ? ` --mode ${mode}` : ''}`,
2395
+ ],
2396
+ },
2397
+ );
2398
+ if (STATE_WORDS.includes(label.word))
2399
+ refuse(
2400
+ E.ERR_THEME_BAD_VALUE,
2401
+ flags.on
2402
+ ? `"${label.word}" in "${value}" is a state; a value for it is given with --state ${label.word}.`
2403
+ : `"${label.word}" in "${value}" is a state; a state is set on a part, with --on <part> --state ${label.word}.`,
2404
+ {
2405
+ run: [
2406
+ flags.on
2407
+ ? `${P} set ${slug} ${thing} ${q(rest)}${scope} --state ${label.word}`
2408
+ : `${HOW} ${q(`${label.word} ${thing}`)}`,
2409
+ ],
2410
+ },
2411
+ );
2412
+ if (DEVICE_WORDS.includes(label.word))
2413
+ refuse(
2414
+ E.ERR_THEME_BAD_VALUE,
2415
+ `"${label.word}" in "${value}" names a kind of screen; the editor sets ${thing} for every screen, not for one kind.`,
2416
+ {run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`]},
2417
+ );
2418
+ // `on button: pill`: the part named after `on`.
2419
+ const onPart = /^on-([a-z][a-z0-9-]*)$/.exec(label.word)?.[1];
2420
+ if (onPart && parts.includes(onPart))
2421
+ refuse(
2422
+ E.ERR_THEME_BAD_VALUE,
2423
+ `"${value}" names the part ${onPart}; a value for one part is given with --on ${onPart}.`,
2424
+ {run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${onPart}`]},
2425
+ );
2426
+ if (parts.includes(label.word))
2427
+ refuse(
2428
+ E.ERR_THEME_BAD_VALUE,
2429
+ `"${label.word}" in "${value}" is a part; a value for one part is given with --on ${label.word}.`,
2430
+ {run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${label.word}`]},
2431
+ );
2432
+ // A flag's own name as the label (`state: hover`, `part: card`,
2433
+ // `variant: primary`, `mode: dark`): what that flag does here.
2434
+ const flagWord = {
2435
+ state: 'state',
2436
+ states: 'state',
2437
+ part: 'on',
2438
+ on: 'on',
2439
+ component: 'on',
2440
+ variant: 'when',
2441
+ size: 'when',
2442
+ when: 'when',
2443
+ prop: 'when',
2444
+ mode: 'mode',
2445
+ theme: 'mode',
2446
+ }[label.word];
2447
+ if (
2448
+ flagWord &&
2449
+ (flagWord === 'mode'
2450
+ ? Boolean(MODE_WORDS[rest.trim().toLowerCase()])
2451
+ : !otherSettingLabel(thing, value))
2452
+ ) {
2453
+ const r = rest.trim().toLowerCase();
2454
+ // The flag's value and the setting's value in one (`state=hover
2455
+ // 4px`): the first word is the flag's, the rest the value.
2456
+ const [fv, ...more] = rest.trim().split(/\s+/);
2457
+ if (flagWord !== 'mode' && more.length > 0) {
2458
+ const flagged =
2459
+ flagWord === 'on'
2460
+ ? ` --on ${fv}${flags.when ? ` --when ${flags.when}` : ''}`
2461
+ : flags.on
2462
+ ? `${scope} --${flagWord} ${flagWord === 'when' && label.word !== 'when' && label.word !== 'prop' ? `${label.word}:${fv}` : fv}`
2463
+ : null;
2464
+ refuse(
2465
+ E.ERR_THEME_BAD_VALUE,
2466
+ `"${value}" holds the ${flagWord} ${fv} and the value ${more.join(' ')}; the ${flagWord} is given with --${flagWord}.`,
2467
+ {
2468
+ didYouMean: [`--${flagWord}`],
2469
+ run: [
2470
+ flagged
2471
+ ? `${P} set ${slug} ${thing} ${q(more.join(' '))}${flagged}`
2472
+ : `${HOW} ${q(`${fv} ${thing}`)}`,
2473
+ ],
2474
+ },
2475
+ );
2476
+ }
2477
+ const m = flagWord === 'mode' ? MODE_WORDS[r] : null;
2478
+ const when =
2479
+ flagWord === 'when'
2480
+ ? label.word === 'when' || label.word === 'prop'
2481
+ ? r
2482
+ : `${label.word}:${r}`
2483
+ : null;
2484
+ refuse(
2485
+ E.ERR_THEME_BAD_VALUE,
2486
+ flagWord === 'mode'
2487
+ ? `"${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\``}.`
2488
+ : flagWord === 'state'
2489
+ ? `"${value}" names a state, not a value for ${thing}: a value for a state is given with --on <part> --state ${r}.`
2490
+ : flagWord === 'on'
2491
+ ? `"${value}" names a part, not a value for ${thing}: a value for one part is given with --on ${r}.`
2492
+ : `"${value}" names a variant, not a value for ${thing}: a value for one variant is given with --on <part> --when ${when}.`,
2493
+ {
2494
+ didYouMean: [`--${flagWord}`],
2495
+ run: [
2496
+ flagWord === 'mode' && !colorful
2497
+ ? `${P} set ${slug} mode ${m ?? 'dark'}-only`
2498
+ : `${HOW} ${q(`${r} ${thing}`)}`,
2499
+ ],
2500
+ },
2501
+ );
2502
+ }
2503
+ // A Google Fonts family spec (`Inter:wght@400;600`): the family
2504
+ // before the colon.
2505
+ if (
2506
+ (thing === 'font' || familyToken || thing === 'font-family') &&
2507
+ /^(ital,)?wght@|^ital@/i.test(rest)
2508
+ ) {
2509
+ const family = String(value).split(':')[0].replace(/\+/g, ' ').trim();
2510
+ refuse(
2511
+ E.ERR_THEME_BAD_VALUE,
2512
+ `"${value}" is a Google Fonts family spec; ${thing} takes the family (${family}). A weight is set with font-weight or a --font-weight-* token.`,
2513
+ {run: [`${P} set ${slug} ${thing} ${q(family)}${scope}`]},
2514
+ );
2515
+ }
2516
+ // A family's own words may hold a colon; only the words above are
2517
+ // read there.
2518
+ if (!familyToken && !otherSettingLabel(thing, value))
2519
+ refuse(
2520
+ E.ERR_THEME_BAD_VALUE,
2521
+ `"${label.word}" in "${value}" is not a name the editor reads for ${thing}; give the value alone.`,
2522
+ {
2523
+ // Only setting names: a part or a state is never a value.
2524
+ didYouMean: nearest(label.word, Object.keys(DIALS)),
2525
+ run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`],
2526
+ },
2527
+ );
2528
+ }
2529
+ // The setting's own name before its value (`font: Inter`, `Font:
2530
+ // Georgia`) is the value.
2531
+ // (A `font:` shorthand is read whole below, as its family.)
2532
+ if (
2533
+ label &&
2534
+ ownLabel(thing, label.word) &&
2535
+ // A `font:` with a size is the shorthand, read whole below; with
2536
+ // only families (`font: Inter, serif`) it is the label.
2537
+ (label.word !== 'font' || !/\d/.test(label.rest)) &&
2538
+ label.rest.replace(/;+\s*$/, '').trim()
2539
+ )
2540
+ value = label.rest;
2541
+ }
2542
+ if (
2543
+ !unset &&
2544
+ typeof value === 'string' &&
2545
+ (DIALS[thing] || partProperty || thing.startsWith('--')) &&
2546
+ !/content/.test(thing)
2547
+ ) {
2548
+ // A value labeled with another setting's name is that setting's, never
2549
+ // this one's (`accent 'neutral: #64748b'`, `--radius-element 'accent:
2550
+ // red'`). The value goes to this setting again only for a dial that
2551
+ // checks it as its own (any word is a font family, so never the font).
2552
+ const other = otherSettingLabel(thing, value);
2553
+ if (other)
2554
+ refuse(
2555
+ E.ERR_THEME_BAD_VALUE,
2556
+ `"${value}" is labeled ${other.thing}, another setting than ${thing}; nothing is set from it.`,
2557
+ {
2558
+ didYouMean: [other.thing],
2559
+ run: [
2560
+ `${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
2561
+ // Another setting is not this part's property: the whole theme.
2562
+ ...(flags.on && partProperty
2563
+ ? [
2564
+ `${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}`,
2565
+ ]
2566
+ : []),
2567
+ ...(DIALS[thing] && thing !== 'font'
2568
+ ? [
2569
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
2570
+ ]
2571
+ : []),
2572
+ ],
2573
+ },
2574
+ );
2575
+ }
2576
+ if (!unset && typeof value === 'string' && DIALS[thing]) {
2577
+ const d = thing === 'font' ? null : pastedDeclaration(value);
1417
2578
  if (d?.value) value = d.value;
1418
2579
  }
1419
2580
  // The font dial's value as pasted from a stylesheet (`Georgia, serif;`,
@@ -1485,8 +2646,8 @@ export function checkSetting(
1485
2646
  function fallbackVarTypo(v, TOKENS) {
1486
2647
  for (const [, name] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*,/gi)) {
1487
2648
  if (name in TOKENS || name.startsWith('--_')) continue;
1488
- const near = nearest(name, Object.keys(TOKENS)).filter(
1489
- n => levenshteinDistance(n, name) <= 2,
2649
+ const near = nearest(name, Object.keys(TOKENS)).filter(n =>
2650
+ typoNear(name, n),
1490
2651
  );
1491
2652
  if (near.length)
1492
2653
  return `${name} is not a design token, so its fallback always shows; did you mean ${near[0]}?`;
@@ -1628,23 +2789,91 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1628
2789
  .toLowerCase();
1629
2790
  if (flags.only) s.only = true;
1630
2791
  if (flags.mode) {
1631
- const mode = flags.mode.toLowerCase();
1632
- if (mode !== 'light' && mode !== 'dark')
2792
+ // Read as any value is: invisible or no-break spaces, quotes around
2793
+ // it, a trailing colon (`'dark '`, `“dark”`, `dark:`).
2794
+ const mode = withoutDebris(normalValueText(String(flags.mode)))
2795
+ .trim()
2796
+ .replace(/^(["'])(.*)\1$/, '$2')
2797
+ .replace(/:+$/, '')
2798
+ .trim()
2799
+ .toLowerCase();
2800
+ if (mode !== 'light' && mode !== 'dark') {
2801
+ // A word for one of the two (night, day) is that one; never the
2802
+ // nearest spelling, which can be the other (night → light).
2803
+ const meant = {
2804
+ night: 'dark',
2805
+ nighttime: 'dark',
2806
+ dim: 'dark',
2807
+ black: 'dark',
2808
+ day: 'light',
2809
+ daytime: 'light',
2810
+ bright: 'light',
2811
+ white: 'light',
2812
+ }[mode];
2813
+ const near = meant ? [meant] : nearest(mode, ['light', 'dark']);
2814
+ // The line for that one mode: for a dial, the one `--mode dark` itself
2815
+ // offers (the color token for that mode), never the both-modes dial.
2816
+ const modeLine = (/** @type {string} */ m) => {
2817
+ if (DIALS[thing] && !unset)
2818
+ try {
2819
+ checkSetting(ctx, slug, data, thing, v, {...flags, mode: m});
2820
+ } catch (e) {
2821
+ const first = /** @type {any} */ (e)?.suggestions?.find(
2822
+ (/** @type {any} */ x) => / --mode (light|dark)\b/.test(x.name),
2823
+ );
2824
+ if (first) return first.name;
2825
+ }
2826
+ return setLine(slug, thing, v, {...s, mode: m}, unset);
2827
+ };
1633
2828
  refuse(
1634
2829
  E.ERR_THEME_BAD_VALUE,
1635
2830
  `--mode takes light or dark, not "${flags.mode}".`,
1636
2831
  {
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)],
2832
+ didYouMean: near,
2833
+ // The mode it is nearest keeps --mode; only with none near is the
2834
+ // same setting for both modes offered.
2835
+ run: [
2836
+ ...(near.length === 1 ? [modeLine(near[0])] : []),
2837
+ // A word that means one mode (night) keeps it: the both-modes
2838
+ // line only for a word read by spelling.
2839
+ ...(meant
2840
+ ? []
2841
+ : [setLine(slug, thing, v, {...s, mode: undefined}, unset)]),
2842
+ ],
1641
2843
  },
1642
2844
  );
2845
+ }
1643
2846
  s.mode = mode;
1644
2847
  }
1645
2848
  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 ?? ''))
2849
+ // A CSS-wide keyword is no color for one mode: a mode's half takes a
2850
+ // color, and the keyword applies to the whole declaration, in both modes.
2851
+ if (
2852
+ s.mode &&
2853
+ !unset &&
2854
+ CSS_WIDE.includes(
2855
+ String(v ?? '')
2856
+ .trim()
2857
+ .toLowerCase(),
2858
+ )
2859
+ )
2860
+ refuse(
2861
+ E.ERR_THEME_NO_MODE,
2862
+ `"${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.`,
2863
+ {
2864
+ run: [
2865
+ `${P} set ${slug} ${thing} ${String(v).trim()}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
2866
+ ],
2867
+ },
2868
+ );
2869
+ // A value that already gives both modes takes no --mode (a gradient
2870
+ // holding a light-dark() stop included).
2871
+ if (
2872
+ s.mode &&
2873
+ !unset &&
2874
+ (/^\s*light-dark\(/i.test(v ?? '') ||
2875
+ (/gradient\(/i.test(v ?? '') && /light-dark\(/i.test(v ?? '')))
2876
+ )
1648
2877
  refuse(
1649
2878
  E.ERR_THEME_NO_MODE,
1650
2879
  `"${v}" already gives both modes, so it takes no --mode; drop --mode, or give the ${s.mode} color alone.`,
@@ -1655,11 +2884,35 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1655
2884
  },
1656
2885
  );
1657
2886
  // A setting saved for a mode the theme no longer has can still be removed.
1658
- if (s.mode && data.mode !== 'both' && !unset)
2887
+ // An entry saved for the one mode the theme has ("[dark only]" in a
2888
+ // dark-only theme) can be set again with that --mode, so a doubled one
2889
+ // can be kept: that set replaces both.
2890
+ const sameModeEntry =
2891
+ s.mode &&
2892
+ data.mode === `${s.mode}-only` &&
2893
+ (Array.isArray(data.settings) ? data.settings : []).some(
2894
+ (/** @type {any} */ x) =>
2895
+ x &&
2896
+ x.thing === thing &&
2897
+ x.mode === s.mode &&
2898
+ (x.on ?? null) === (s.on ?? null) &&
2899
+ (x.when ?? null) === (s.when ?? null) &&
2900
+ (x.state ?? null) === (s.state ?? null),
2901
+ );
2902
+ if (s.mode && data.mode !== 'both' && !unset && !sameModeEntry)
1659
2903
  refuse(
1660
2904
  E.ERR_THEME_NO_MODE,
1661
2905
  `This theme is ${data.mode}; --mode is for themes with both modes.`,
1662
- {run: [`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}`]},
2906
+ {
2907
+ run: [
2908
+ // For the mode the theme does not show, both modes first; the
2909
+ // same setting for the theme's own mode keeps where it applies.
2910
+ ...((data.mode === 'light-only' ? 'light' : 'dark') !== s.mode
2911
+ ? [`${P} set ${slug} mode both`]
2912
+ : []),
2913
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
2914
+ ],
2915
+ },
1663
2916
  );
1664
2917
  if ((s.when || s.state) && !s.on)
1665
2918
  refuse(E.ERR_MISSING_ARGUMENT, '--when and --state need --on <part>.', {
@@ -1693,29 +2946,91 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1693
2946
  // Another case of a part or group, its class name copied from the
1694
2947
  // page (`.astryx-card`), or its component (`<Card>`, `Card`): that
1695
2948
  // part, as a working command with every flag kept.
2949
+ // Stray punctuation from a copied list ("text-input,") and the dashes
2950
+ // autocorrect types ("text\u2013input") are not part of the name.
1696
2951
  const lower = s.on
2952
+ .replace(/[\u2010-\u2015\u2212]/g, '-')
2953
+ .replace(/^[\s,;:.'"`]+|[\s,;:.'"`]+$/g, '')
1697
2954
  .trim()
1698
2955
  .replace(/^<\/?\s*|\s*\/?>$/g, '')
1699
2956
  .replace(/^\./, '')
1700
2957
  .replace(/^astryx-/, '')
1701
2958
  .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
1702
2959
  .toLowerCase();
2960
+ // A part named in words (dialog header, text inputs) is the dashed
2961
+ // part, read before any group a single word of it names.
2962
+ const dashed = lower.trim().replace(/[\s_]+/g, '-');
1703
2963
  // A plain word how reads as a part or group (checkboxes: checks).
1704
2964
  const byWord = partForWord(lower);
1705
2965
  // 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]));
2966
+ const singular = [lower, dashed]
2967
+ .flatMap(w => [
2968
+ w.replace(/ies$/, 'y'),
2969
+ w.replace(/(ch|sh|x|s)es$/, '$1'),
2970
+ w.replace(/s$/, ''),
2971
+ ])
2972
+ .find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
2973
+ // Several parts named in one --on (`button, text-input`, `button/
2974
+ // text-input`, `button and text-input`, or spaces): one command per
2975
+ // part named, each checked, never a group that one word of the list
2976
+ // happens to name.
2977
+ const listed = /,|\/|&|\band\b/.test(lower);
2978
+ // (Words with only spaces that name one part, `text inputs`, are
2979
+ // that part.)
2980
+ if (!(TARGET.has(dashed) || FAMILIES[dashed]) && (listed || !singular)) {
2981
+ const pieces = lower
2982
+ .split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
2983
+ .map(x => x.trim())
2984
+ .filter(Boolean);
2985
+ const partOf = (/** @type {string} */ w) =>
2986
+ TARGET.has(w) || FAMILIES[w]
2987
+ ? w
2988
+ : ([w.replace(/ies$/, 'y'), w.replace(/s$/, '')].find(
2989
+ x => x !== w && (TARGET.has(x) || FAMILIES[x]),
2990
+ ) ?? null);
2991
+ const found = pieces.map(partOf);
2992
+ const parts = [...new Set(found.filter(x => x != null))];
2993
+ const missing = pieces.filter((_, i) => found[i] == null);
2994
+ if (
2995
+ pieces.length > 1 &&
2996
+ parts.length > 0 &&
2997
+ (missing.length === 0 || (listed && parts.length > 1))
2998
+ )
2999
+ refuse(
3000
+ E.ERR_THEME_UNKNOWN_PART,
3001
+ `"${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)` : ''}.`,
3002
+ {
3003
+ didYouMean: parts,
3004
+ run: parts
3005
+ .slice(0, 6)
3006
+ .map(on => setLine(slug, thing, v, {...s, on}, unset)),
3007
+ },
3008
+ );
3009
+ }
1711
3010
  const named =
1712
3011
  TARGET.has(lower) || FAMILIES[lower]
1713
3012
  ? lower
1714
- : singular
1715
- ? singular
1716
- : byWord && (TARGET.has(byWord) || FAMILIES[byWord])
1717
- ? byWord
1718
- : null;
3013
+ : TARGET.has(dashed) || FAMILIES[dashed]
3014
+ ? dashed
3015
+ : singular
3016
+ ? singular
3017
+ : byWord && (TARGET.has(byWord) || FAMILIES[byWord])
3018
+ ? byWord
3019
+ : null;
3020
+ // The page (the body behind every part) is painted by the app shell.
3021
+ if (
3022
+ !named &&
3023
+ /^(page|body|app|background|page-background)$/i.test(s.on) &&
3024
+ TARGET.has('app-shell')
3025
+ )
3026
+ refuse(
3027
+ E.ERR_THEME_UNKNOWN_PART,
3028
+ `"${s.on}" is not a part name; the page behind your parts is app-shell (a background there shows in every AppShell variant).`,
3029
+ {
3030
+ didYouMean: ['app-shell'],
3031
+ run: [setLine(slug, thing, v, {...s, on: 'app-shell'}, unset)],
3032
+ },
3033
+ );
1719
3034
  if (named)
1720
3035
  refuse(
1721
3036
  E.ERR_THEME_UNKNOWN_PART,
@@ -1742,6 +3057,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1742
3057
  );
1743
3058
  }
1744
3059
  if (s.when) {
3060
+ // A prop and value in other letters, with spaces or `=` between
3061
+ // (`Variant: Primary`, `variant=primary`): the working command.
3062
+ const m = /^\s*([^:=\s]+)\s*[:=]\s*([^:=]+?)\s*$/.exec(s.when);
3063
+ if (m) {
3064
+ const prop = t.props.find(x => x.toLowerCase() === m[1].toLowerCase());
3065
+ const vals = prop ? (C.variantValues(s.on)[prop] ?? []) : [];
3066
+ const val = vals.length
3067
+ ? vals.find(x => x.toLowerCase() === m[2].toLowerCase())
3068
+ : m[2];
3069
+ const when = prop && val ? `${prop}:${val}` : null;
3070
+ if (when && when !== s.when)
3071
+ refuse(
3072
+ E.ERR_THEME_UNKNOWN_VARIANT,
3073
+ `--when "${s.when}" is written ${when}.`,
3074
+ {
3075
+ didYouMean: [when],
3076
+ run: [setLine(slug, thing, v, {...s, when}, unset)],
3077
+ },
3078
+ );
3079
+ }
1745
3080
  const [p, wv, ...more] = s.when.split(':');
1746
3081
  if (!wv || more.length)
1747
3082
  refuse(
@@ -1764,12 +3099,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1764
3099
  );
1765
3100
  }
1766
3101
  const states = [...t.states, ...COMMON_STATES];
3102
+ // A state the part lists in camelCase (toggle-button's isPressed) typed
3103
+ // in any case or with dashes is that state.
3104
+ const flat = (/** @type {string} */ x) =>
3105
+ x.replace(/[-_\s]/g, '').toLowerCase();
3106
+ if (s.state && !states.includes(s.state)) {
3107
+ const same = states.find(x => flat(x) === flat(String(s.state)));
3108
+ if (same) s.state = same;
3109
+ }
1767
3110
  // Other words for a state, mapped to the one the part has; with none
1768
3111
  // near, the list of its states (never a guess such as hover).
1769
3112
  const SYNONYMS = wordTable(
1770
3113
  /** @type {Record<string, string[]>} */ ({
1771
- pressed: ['active'],
1772
- press: ['active'],
3114
+ pressed: ['isPressed', 'active'],
3115
+ press: ['isPressed', 'active'],
3116
+ on: ['isPressed', 'checked', 'selected'],
1773
3117
  down: ['active'],
1774
3118
  clicked: ['active'],
1775
3119
  hovered: ['hover'],
@@ -1781,6 +3125,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1781
3125
  inactive: ['disabled'],
1782
3126
  }),
1783
3127
  );
3128
+ // Several states in one --state (`hover,focus-visible`, `hover
3129
+ // focus-visible`): one line per state, the value quoted as typed.
3130
+ const typedStates = String(flags.state ?? '')
3131
+ .split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
3132
+ .map(x => x.trim().toLowerCase())
3133
+ .filter(Boolean);
3134
+ if (
3135
+ typedStates.length > 1 &&
3136
+ typedStates.every(x => states.includes(x)) &&
3137
+ !states.includes(String(s.state))
3138
+ )
3139
+ refuse(
3140
+ E.ERR_THEME_UNKNOWN_STATE,
3141
+ `"${flags.state}" names ${typedStates.length} states; --state takes one at a time.`,
3142
+ {
3143
+ didYouMean: typedStates,
3144
+ run: typedStates
3145
+ .slice(0, 6)
3146
+ .map(state => setLine(slug, thing, v, {...s, state}, unset)),
3147
+ },
3148
+ );
1784
3149
  const meant =
1785
3150
  (SYNONYMS[String(s.state ?? '').toLowerCase()] ?? []).find(x =>
1786
3151
  states.includes(x),
@@ -2131,6 +3496,38 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2131
3496
  })(),
2132
3497
  },
2133
3498
  );
3499
+ // A comparative weight word is the weight (lighter is light, never the
3500
+ // tracking tighter); two words (`bold tight`, `bold, tight`) are a
3501
+ // weight and a tracking, one line each.
3502
+ if (!unset) {
3503
+ const MORE = /** @type {Record<string, string>} */ ({
3504
+ lighter: 'light',
3505
+ thinner: 'light',
3506
+ bolder: 'bold',
3507
+ heavier: 'heavy',
3508
+ wider: 'wide',
3509
+ looser: 'wide',
3510
+ });
3511
+ const words = String(v ?? '')
3512
+ .trim()
3513
+ .toLowerCase()
3514
+ .split(/[\s,]+/)
3515
+ .filter(Boolean)
3516
+ .map(w => MORE[w] ?? w);
3517
+ const known = (/** @type {string} */ w) =>
3518
+ HEADING_WEIGHTS[w] !== undefined || HEADING_TRACKING[w] !== undefined;
3519
+ if (
3520
+ (words.length > 1 || MORE[String(v).trim().toLowerCase()]) &&
3521
+ words.every(known)
3522
+ )
3523
+ refuse(
3524
+ E.ERR_THEME_BAD_VALUE,
3525
+ words.length > 1
3526
+ ? `"${v}" is ${words.length} headings values; headings takes one at a time (a weight and a tracking are two settings).`
3527
+ : `"${v}" is the weight ${words[0]}.`,
3528
+ {run: words.map(w => `${P} set ${slug} headings ${w}`)},
3529
+ );
3530
+ }
2134
3531
  if (s.mode)
2135
3532
  refuse(
2136
3533
  E.ERR_THEME_NO_MODE,
@@ -2171,14 +3568,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2171
3568
  const weight = /^\d+(\.\d+)?$/.test(lower) ? Number(lower) : null;
2172
3569
  const meant =
2173
3570
  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]);
3571
+ (weight != null ? weightRung(weight) : nearest(lower, words)[0]);
2182
3572
  refuse(
2183
3573
  E.ERR_THEME_BAD_VALUE,
2184
3574
  `headings takes ${DIALS.headings.values}, not "${v}".${weight != null && meant ? ` ${meant} sets weight ${HEADING_WEIGHTS[meant]}.` : ''}`,
@@ -2412,9 +3802,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2412
3802
  : cornerPxOf(onPart.value)
2413
3803
  : whole
2414
3804
  ? 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));
3805
+ : // The base theme's own radius on the part, when its rule
3806
+ // gives one; else the radius token's; one it does not give
3807
+ // in px (a var() chain) counts as medium's.
3808
+ (basePartRadiusPx(ctx, base, part, s.when) ??
3809
+ tokenPx(base, token) ??
3810
+ radiusAt(base, 'medium', token));
2418
3811
  const rungs = CORNERS.map(
2419
3812
  ([n]) => /** @type {const} */ ([n, radiusAt(base, n, token)]),
2420
3813
  );
@@ -2435,17 +3828,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2435
3828
  );
2436
3829
  s.value = next ? next[0] : 'medium';
2437
3830
  } else {
3831
+ // A value with copy debris (`8px;`): the value without it.
3832
+ if (withoutCopyDebris(v) !== v && withoutCopyDebris(v))
3833
+ refuse(
3834
+ E.ERR_THEME_BAD_VALUE,
3835
+ `"${v}" holds copy debris (a ;, a comment or !important); corners takes the value alone.`,
3836
+ {run: [setLine(slug, 'corners', withoutCopyDebris(v), s)]},
3837
+ );
2438
3838
  // A rung in any case, a size in px written any way: the plain form.
2439
3839
  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;
3840
+ // Any CSS number in px (2e1px, +4px), the shared length parse; a
3841
+ // rem is that many 16px, saved in px.
3842
+ const pxLen = /\d(px|rem)$/.test(lower) ? lengthPx(lower) : null;
2442
3843
  if (CORNERS.some(([n]) => n === lower)) s.value = lower;
2443
- else if (pxLen != null && pxLen >= 0)
3844
+ else if (pxLen != null && pxLen >= 0) {
2444
3845
  s.value =
2445
3846
  pxLen >= 1000 ? 'pill' : `${Math.round(pxLen * 10000) / 10000}px`;
3847
+ if (/rem$/.test(lower))
3848
+ s.note = `corners ${v.trim()} is saved as ${s.value}`;
3849
+ }
2446
3850
  // No rounding, said any way, is square.
2447
- else if (/^(0|0%|none|sharp|zero|no|flat)$/.test(lower))
2448
- s.value = 'square';
3851
+ else if (NO_ROUNDING.includes(lower)) s.value = 'square';
2449
3852
  else {
2450
3853
  // What it most likely means, as a value corners takes: a simple
2451
3854
  // calc() of px is worked out.
@@ -2461,14 +3864,31 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2461
3864
  '-': Number(calc[1]) - Number(calc[3]),
2462
3865
  }[/** @type {'*' | '/' | '+' | '-'} */ (calc[2])]
2463
3866
  : null;
3867
+ // A bare number (0.5, as a pasted --radius: 0.5rem loses its
3868
+ // unit) has no unit to read it by: no size is guessed.
3869
+ const bareNumber = /^[+-]?\d*\.?\d+$/.test(lower);
2464
3870
  const len =
2465
3871
  calcPx != null && Number.isFinite(calcPx)
2466
3872
  ? calcPx
2467
- : lengthPx(lower);
3873
+ : bareNumber
3874
+ ? null
3875
+ : lengthPx(lower);
2468
3876
  const pct = /^(\d+(?:\.\d+)?)%$/.exec(lower);
3877
+ // Tailwind's names, and rounding said with a negation: what they
3878
+ // mean (rounded-none and not round are square, rounded-full is
3879
+ // pill, rounded-[12px] is 12px).
3880
+ const tw = /^rounded-\[(.+)\]$/.exec(lower)?.[1];
3881
+ const opposite =
3882
+ TAILWIND_RADIUS[lower] ??
3883
+ (tw && lengthPx(tw) != null
3884
+ ? `${Math.round(Number(lengthPx(tw)) * 100) / 100}px`
3885
+ : negates(lower) && /round/.test(lower)
3886
+ ? 'square'
3887
+ : null);
2469
3888
  // A radius below zero means none: square.
2470
3889
  const meant =
2471
- len != null
3890
+ opposite ??
3891
+ (len != null
2472
3892
  ? len <= 0
2473
3893
  ? 'square'
2474
3894
  : `${Math.round(len * 100) / 100}px`
@@ -2476,17 +3896,34 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2476
3896
  ? Number(pct[1]) >= 50
2477
3897
  ? 'pill'
2478
3898
  : null
2479
- : (nearest(
2480
- lower,
2481
- CORNERS.map(([n]) => n),
2482
- )[0] ?? null);
3899
+ : bareNumber
3900
+ ? null
3901
+ : (nearest(
3902
+ lower,
3903
+ CORNERS.map(([n]) => n),
3904
+ )[0] ?? null));
2483
3905
  refuse(
2484
3906
  E.ERR_THEME_BAD_VALUE,
2485
- `corners takes ${DIALS.corners.values}, not "${v}".`,
3907
+ `corners takes ${DIALS.corners.values}, not "${v}"${bareNumber ? ' (a number needs its unit: px or rem)' : ''}.`,
2486
3908
  {
2487
3909
  ...(meant ? {didYouMean: [meant]} : {}),
2488
3910
  // The same scope, flags included.
2489
- run: [setLine(slug, 'corners', meant ?? 'medium', s)],
3911
+ // Nothing near: how corners, never a stock rung.
3912
+ // A whole bare number gets the line with px, the unit it
3913
+ // most likely meant, and how corners; one below one (a
3914
+ // pasted 0.5rem that lost its unit) has no unit to read it
3915
+ // by: how corners only.
3916
+ run:
3917
+ bareNumber && Number(lower) >= 1
3918
+ ? [
3919
+ setLine(slug, 'corners', `${Number(lower)}px`, s),
3920
+ `${HOW} corners`,
3921
+ ]
3922
+ : [
3923
+ meant
3924
+ ? setLine(slug, 'corners', meant, s)
3925
+ : `${HOW} corners`,
3926
+ ],
2490
3927
  },
2491
3928
  );
2492
3929
  }
@@ -2547,7 +3984,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2547
3984
  run: [setLine(slug, 'spacing', nearFactor, s)],
2548
3985
  },
2549
3986
  );
2550
- else if (/^(0|none|zero|no|off)$/i.test(v))
3987
+ else if (NO_SPACE.includes(v.toLowerCase()))
2551
3988
  // Spacing scales the theme's space; it never goes to nothing. The
2552
3989
  // tightest rung is the nearest that works.
2553
3990
  refuse(
@@ -2568,15 +4005,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2568
4005
  SPACING.map(([n]) => n),
2569
4006
  ),
2570
4007
  run: [
2571
- setLine(
2572
- slug,
2573
- 'spacing',
2574
- nearest(
4008
+ (() => {
4009
+ const near = nearest(
2575
4010
  v,
2576
4011
  SPACING.map(([n]) => n),
2577
- )[0] ?? 'roomy',
2578
- s,
2579
- ),
4012
+ )[0];
4013
+ return near
4014
+ ? setLine(slug, 'spacing', near, s)
4015
+ : `${HOW} spacing`;
4016
+ })(),
2580
4017
  ],
2581
4018
  },
2582
4019
  );
@@ -2632,19 +4069,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2632
4069
  didYouMean: [near],
2633
4070
  run: [`${P} set ${slug} text-size ${near}`],
2634
4071
  }
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
- };
4072
+ : (() => {
4073
+ // A size typed full-width or with a trailing dot
4074
+ // (18, 18.) is that size; one read any other way (a
4075
+ // unit, a constant calc()) is that size. Nothing read:
4076
+ // how text-size, never a stock size.
4077
+ const t = typedPlain(v).replace(/\.$/, '');
4078
+ const size =
4079
+ /^\d+(\.\d+)?$/.test(t) &&
4080
+ Number(t) >= 10 &&
4081
+ Number(t) <= 32
4082
+ ? String(Number(t))
4083
+ : textSizePx(v);
4084
+ return {
4085
+ run: [
4086
+ size != null
4087
+ ? `${P} set ${slug} text-size ${size}`
4088
+ : `${HOW} text-size`,
4089
+ ],
4090
+ };
4091
+ })();
2648
4092
  })(),
2649
4093
  );
2650
4094
  else if (!TEXT_SIZE.some(([n]) => n === v))
@@ -2665,13 +4109,51 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2665
4109
  .replace(/\s*!important\s*$/i, '')
2666
4110
  .replace(/;+\s*$/, '')
2667
4111
  .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');
4112
+ // A hex written 0x… (as in code) is that hex.
4113
+ .replace(/^0x([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, '#$1')
4114
+ .replace(/^([0-9a-f]{3}|[0-9a-f]{6})$/i, '#$1');
4115
+ // A hex a digit short or over is refused as it is: the digit
4116
+ // missing could be anywhere, so none is made up.
4117
+ // A name of several words with a color among them (`navy blue`)
4118
+ // is that color.
4119
+ // Two names run together (`navyblue`) are the first, as the
4120
+ // spaced form is.
4121
+ const words = v
4122
+ .toLowerCase()
4123
+ .split(/[\s,-]+/)
4124
+ .filter(Boolean);
4125
+ // The words joined (dark red, light-blue, dark-slate-gray) are the
4126
+ // color they name. A word with a scale step (red-500, gray-900) is
4127
+ // no CSS color, and the bare word is another color: none is named.
4128
+ const joined = words.join('');
4129
+ const scaled = words.some(w => /\d/.test(w)) || /^[{]/.test(v.trim());
4130
+ const named =
4131
+ negates(v) || scaled
4132
+ ? []
4133
+ : words.length > 1 && COLOR_NAMES.includes(joined)
4134
+ ? [joined]
4135
+ : v
4136
+ .toLowerCase()
4137
+ .split(/[\s,-]+/)
4138
+ .flatMap(w =>
4139
+ COLOR_NAMES.includes(w)
4140
+ ? [w]
4141
+ : COLOR_NAMES.filter(
4142
+ n =>
4143
+ n.length >= 3 &&
4144
+ w.startsWith(n) &&
4145
+ COLOR_NAMES.includes(w.slice(n.length)),
4146
+ ).slice(0, 1),
4147
+ );
2672
4148
  const near =
2673
4149
  problem.kind === 'unknown'
2674
- ? nearest(v.toLowerCase(), COLOR_NAMES)
4150
+ ? /^#?[0-9a-f]{4,8}$/i.test(v.trim())
4151
+ ? []
4152
+ : named.length
4153
+ ? named.slice(0, 1)
4154
+ : scaled
4155
+ ? []
4156
+ : nearest(v.toLowerCase(), COLOR_NAMES)
2675
4157
  : [];
2676
4158
  // light-dark(a, b): the dial takes one color, from which it makes
2677
4159
  // both modes; the light one is offered.
@@ -2735,12 +4217,23 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2735
4217
  if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
2736
4218
  // The value meant: a step in other letters (MORE), or the number
2737
4219
  // read as CSS reads it (70%, 7e1), kept in range.
2738
- const word = v.trim().toLowerCase();
2739
- const n = cssNumber(v);
4220
+ // Quotes around it (`"50"`) are not part of it.
4221
+ const bare = v
4222
+ .trim()
4223
+ .replace(/^(["'])(.*)\1$/, '$2')
4224
+ .trim();
4225
+ const word = bare.toLowerCase();
4226
+ const n = cssNumber(bare);
4227
+ // A fraction of one (0.5) is that share of the scale (50), as a
4228
+ // number with no unit from 0 to 1 is read.
4229
+ const scaled =
4230
+ n && n.unit === '' && n.value > 0 && n.value < 1
4231
+ ? n.value * 100
4232
+ : n?.value;
2740
4233
  const near = ['more', 'less'].includes(word)
2741
4234
  ? word
2742
- : n && (n.unit === '' || n.unit === '%')
2743
- ? String(Math.max(0, Math.min(100, Math.round(n.value))))
4235
+ : n && (n.unit === '' || n.unit === '%') && scaled != null
4236
+ ? String(Math.max(0, Math.min(100, Math.round(scaled))))
2744
4237
  : null;
2745
4238
  refuse(
2746
4239
  E.ERR_THEME_BAD_VALUE,
@@ -2758,8 +4251,24 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2758
4251
  E.ERR_THEME_NO_EFFECT,
2759
4252
  colors.length
2760
4253
  ? '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')}`]},
4254
+ : (() => {
4255
+ // Colors set as tokens or on parts are values of their own:
4256
+ // vibrancy saturates only what the color dials make.
4257
+ const own = data.settings.find(
4258
+ (/** @type {any} */ x) =>
4259
+ x &&
4260
+ typeof x.value === 'string' &&
4261
+ (/^--color-/.test(String(x.thing)) ||
4262
+ /(^|-)colou?r$|^background(-color)?$|^fill$/.test(
4263
+ String(x.thing),
4264
+ )) &&
4265
+ parseColor(x.value) != null,
4266
+ );
4267
+ return own
4268
+ ? `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.`
4269
+ : 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.';
4270
+ })(),
4271
+ {run: [`${HOW} accent`]},
2763
4272
  );
2764
4273
  } else if (thing === 'font') {
2765
4274
  if (s.when || s.state)
@@ -3053,16 +4562,46 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3053
4562
  ],
3054
4563
  },
3055
4564
  );
4565
+ // A dial typed as a flag (--corners round): the dial is meant.
4566
+ const dial = thing.replace(/^-+/, '');
4567
+ if (
4568
+ !(thing in TOKENS) &&
4569
+ (dial in DIALS || dial === 'base' || dial === 'mode')
4570
+ )
4571
+ refuse(
4572
+ E.ERR_THEME_UNKNOWN_TOKEN,
4573
+ `"${thing}" is not a design token; ${dial} is a dial, typed without dashes.`,
4574
+ {
4575
+ run: [setLine(slug, dial, v, {...s, mode: undefined}, unset)],
4576
+ },
4577
+ );
3056
4578
  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
- });
4579
+ // The editor's own color words: danger is the error role, brand and
4580
+ // primary are the accent (as the danger and accent dials say).
4581
+ const role = thing
4582
+ .replace(/\bdanger\b/, 'error')
4583
+ .replace(/\b(brand|primary)\b/, 'accent');
4584
+ const aliased = role !== thing && role in TOKENS ? role : null;
4585
+ // The filtered list only when it lists something.
4586
+ const word = thing
4587
+ .replace(/^-+(color-)?/, '')
4588
+ .split('-')[0]
4589
+ .trim();
4590
+ const listed =
4591
+ word && Object.keys(TOKENS).some(k => k.includes(word))
4592
+ ? `${HOW} --list tokens ${word}`
4593
+ : `${HOW} --list tokens`;
4594
+ refuse(
4595
+ E.ERR_THEME_UNKNOWN_TOKEN,
4596
+ `"${thing}" is not a design token.${aliased ? ` The token for that role is ${aliased}.` : ''}`,
4597
+ {
4598
+ didYouMean: aliased ? [aliased] : nearest(thing, Object.keys(TOKENS)),
4599
+ run: [
4600
+ ...(aliased ? [setLine(slug, aliased, v, s, unset)] : []),
4601
+ listed,
4602
+ ],
4603
+ },
4604
+ );
3066
4605
  }
3067
4606
  const type = C.typeOf(thing);
3068
4607
  // Only colors differ by mode: a shadow list cannot sit inside
@@ -3097,6 +4636,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3097
4636
  slug,
3098
4637
  C.propsReading(thing),
3099
4638
  multipliedTokens(ctx.project).has(thing),
4639
+ data.settings.some(x => x.thing === thing),
3100
4640
  );
3101
4641
  checkCycle(thing, v, TOKENS, data, ctx.project.cwd, s);
3102
4642
  // With no part data, what reads the token is unknown: save, unchecked.
@@ -3201,6 +4741,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3201
4741
  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
4742
  else if (r && data.like && baseReads(ctx, data.like, thing))
3203
4743
  s.note = `the ${data.like} theme's own part styles read ${thing}, so the change shows where they use it`;
4744
+ else if (r && coreStylesRead(ctx, thing))
4745
+ 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
4746
  else if (r && dialWrites(thing))
3205
4747
  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
4748
  // The editor's record of what parts read comes from one render of
@@ -3252,9 +4794,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3252
4794
  E.ERR_MISSING_ARGUMENT,
3253
4795
  `${prop} is a CSS property, so it needs --on <part|group>. For the whole theme use a dial or a token.`,
3254
4796
  {
4797
+ // The theme-wide dial or token for it, when there is one; never
4798
+ // a part that was not named.
3255
4799
  run: [
3256
- `${P} set ${slug} ${prop} ${quoteCommandArgument(v || exampleOf(groupOfPropType(prop), prop))} --on card`,
3257
- `${HOW} "${prop}"`,
4800
+ ...(v && WHOLE_THEME_EQUIVALENT[prop]
4801
+ ? [
4802
+ `${P} set ${slug} ${WHOLE_THEME_EQUIVALENT[prop]} ${quoteCommandArgument(v)}`,
4803
+ ]
4804
+ : []),
4805
+ `${HOW} ${quoteCommandArgument(prop)}`,
3258
4806
  ],
3259
4807
  },
3260
4808
  );
@@ -3374,9 +4922,40 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3374
4922
  },
3375
4923
  );
3376
4924
  }
4925
+ // A state Core paints at run time with an inline style (a selected table
4926
+ // row's wash) outranks any theme rule for that property while Core paints
4927
+ // it: the token the inline style reads is what changes it. A component
4928
+ // option can turn that paint off (a table without its row highlight), and
4929
+ // then a rule in the state applies; the refusal says both.
4930
+ if (s.state && !unset) {
4931
+ const family =
4932
+ prop === 'background' || prop === 'background-color'
4933
+ ? 'background-color'
4934
+ : prop;
4935
+ const inline = partsOf(ctx, s)
4936
+ .map(t => [t, ctx.C.MAP[t]?.inline?.[s.state ?? '']?.[family]])
4937
+ .find(([, tok]) => tok);
4938
+ if (inline)
4939
+ refuse(
4940
+ E.ERR_THEME_NO_EFFECT,
4941
+ `By default Core paints ${inline[0]}'s ${family} when ${s.state} as an inline style from ${inline[1]}, which no theme rule can replace, so set ${inline[1]} on ${inline[0]} 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 ${inline[1]} paints nothing.`,
4942
+ {
4943
+ run: [
4944
+ `${P} set ${slug} ${inline[1]} ${quoteCommandArgument(v)} --on ${inline[0]} --state ${s.state}${s.mode ? ` --mode ${s.mode}` : ''}`,
4945
+ ],
4946
+ },
4947
+ );
4948
+ }
3377
4949
  // Text, headings and links take their color from the color prop.
3378
4950
  const textParts = COLOR_PROP_PARTS;
4951
+ // A heading's color is written as the text color tokens its color prop
4952
+ // reads, on the heading alone (compileTheme), so it shows.
4953
+ const headingColor =
4954
+ prop === 'color' &&
4955
+ partsOf(ctx, s).length > 0 &&
4956
+ partsOf(ctx, s).every(t => t === 'heading');
3379
4957
  if (
4958
+ !headingColor &&
3380
4959
  (prop === 'color' || prop === '-webkit-text-fill-color') &&
3381
4960
  partsOf(ctx, s).some(t => textParts.includes(t))
3382
4961
  ) {
@@ -3405,67 +4984,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3405
4984
  }
3406
4985
  s.note = `text, heading and link inside ${s.on} keep the color their color prop gives; set --color-text-primary for those`;
3407
4986
  }
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
- }
4987
+ // One mode on a part whose variants each read their own color is
4988
+ // written to each variant's rule with that variant's own other half
4989
+ // (compileTheme), so it needs no variant named.
3464
4990
  if (!isSafeValue(v))
3465
4991
  refuse(
3466
4992
  E.ERR_THEME_BAD_VALUE,
3467
4993
  `"${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}`]},
4994
+ {
4995
+ // The value without its copy debris, when that is one.
4996
+ run: [
4997
+ withoutCopyDebris(v) !== v && isSafeValue(withoutCopyDebris(v))
4998
+ ? setLine(slug, prop, withoutCopyDebris(v), s)
4999
+ : `${HOW} ${prop}`,
5000
+ ],
5001
+ },
3469
5002
  );
3470
5003
  if (/radius$/.test(prop)) refuseInvisibleCorners(ctx, slug, s, data);
3471
5004
  if (step)
@@ -3536,18 +5069,53 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3536
5069
  if (
3537
5070
  s.mode &&
3538
5071
  !COLOR_PROPS.test(prop) &&
3539
- !(prop === 'background' && isColorValue(v))
5072
+ !(prop === 'background' && isColorValue(v)) &&
5073
+ // A gradient background (no image file) goes per mode: its colors
5074
+ // are each painted in that mode only (compileTheme).
5075
+ !(
5076
+ /^background(-image)?$/.test(prop) &&
5077
+ /gradient\(/i.test(v) &&
5078
+ !/url\(/i.test(v)
5079
+ )
3540
5080
  ) {
3541
5081
  // A color mixed into the value (a border's) can go per mode on its
3542
5082
  // own; a value with none (a radius) is just set for both modes.
3543
5083
  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;
5084
+ // A gradient's colors sit in its image, above any background-color:
5085
+ // no color step can make them differ per mode.
5086
+ const alt =
5087
+ !hasColor || /gradient\(/i.test(v)
5088
+ ? null
5089
+ : prop === 'border' || prop.startsWith('border-')
5090
+ ? 'border-color'
5091
+ : prop === 'background'
5092
+ ? 'background-color'
5093
+ : null;
5094
+ // On a part whose variants each have their own color, the color per
5095
+ // mode is set for one variant at a time (as that refusal says): the
5096
+ // step names the default one, or the first.
5097
+ let altWhen = '';
5098
+ if (alt && !s.when) {
5099
+ const g = C.groupOfProp(alt);
5100
+ const variants = [
5101
+ ...new Set(
5102
+ partsOf(ctx, s).flatMap(t =>
5103
+ (g ? C.partReads(t, g) : [])
5104
+ .filter(r => r.props.includes(alt))
5105
+ .flatMap(r => r.when)
5106
+ .map(w => /^variant=([\w-]+)$/.exec(w)?.[1])
5107
+ .filter(Boolean),
5108
+ ),
5109
+ ),
5110
+ ];
5111
+ const plain = partsOf(ctx, s).some(t =>
5112
+ (g ? C.partReads(t, g) : []).some(
5113
+ r => r.props.includes(alt) && r.when.includes(''),
5114
+ ),
5115
+ );
5116
+ if (variants.length && !plain)
5117
+ altWhen = ` --when variant:${variants.includes('default') ? 'default' : variants[0]}`;
5118
+ }
3551
5119
  refuse(
3552
5120
  E.ERR_THEME_NO_MODE,
3553
5121
  `--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.`,
@@ -3555,7 +5123,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3555
5123
  run: alt
3556
5124
  ? [
3557
5125
  `${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`,
5126
+ `${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
5127
  ]
3560
5128
  : [
3561
5129
  `${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${whenFlag} # both modes`,
@@ -3570,8 +5138,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3570
5138
  if (
3571
5139
  s.mode &&
3572
5140
  s.state &&
3573
- !partsOf(ctx, s).every(t =>
3574
- partDefault(ctx, t, camel(prop), s.when, s.state),
5141
+ !partsOf(ctx, s).every(
5142
+ t =>
5143
+ partDefault(ctx, t, camel(prop), s.when, s.state) ||
5144
+ // The base theme's own value there (in the state, else at rest)
5145
+ // is what the other mode keeps.
5146
+ [`:${s.state}`, null].some(st =>
5147
+ baseRuleHas(
5148
+ ctx.project.cwd,
5149
+ data.like,
5150
+ t,
5151
+ s.when ?? 'base',
5152
+ st,
5153
+ camel(prop),
5154
+ ),
5155
+ ),
3575
5156
  ) &&
3576
5157
  !data.settings.some(
3577
5158
  x =>
@@ -3638,13 +5219,18 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3638
5219
  // A hint names this theme and the part (card when none is given),
3639
5220
  // and a corners value corners takes.
3640
5221
  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,
5222
+ ? (/corners/.test(String(hint('', ''))) &&
5223
+ v.trim() &&
5224
+ !YES_NO.test(v.trim()) &&
5225
+ cornersRead(v) == null
5226
+ ? // A value corners cannot read: how corners, never a stock rung.
5227
+ [`${HOW} corners`]
5228
+ : hint(
5229
+ /corners/.test(String(hint('', ''))) && !YES_NO.test(v.trim())
5230
+ ? (cornersRead(v) ?? '')
5231
+ : v,
5232
+ s.on,
5233
+ )
3648
5234
  ).map(x =>
3649
5235
  x
3650
5236
  .replace(/<theme>/g, slug)
@@ -3797,8 +5383,8 @@ export function unknownVarRef(v, TOKENS, thing) {
3797
5383
  // A fallback always gives a value: never "reads nothing" (a likely
3798
5384
  // typo is noted when the setting is made).
3799
5385
  if (comma) continue;
3800
- const near = nearest(name, Object.keys(TOKENS)).filter(
3801
- n => levenshteinDistance(n, name) <= 2,
5386
+ const near = nearest(name, Object.keys(TOKENS)).filter(n =>
5387
+ typoNear(name, n),
3802
5388
  );
3803
5389
  if (near.length)
3804
5390
  return {
@@ -3849,78 +5435,38 @@ export function fontFileReason(value) {
3849
5435
  }
3850
5436
 
3851
5437
  /**
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
5438
+ * A word as a suggested command quotes it, without the quotes.
5439
+ * @param {string} word
3856
5440
  */
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('');
5441
+ function unquoteArg(word) {
5442
+ const m = /^'(.*)'$/s.exec(word.trim());
5443
+ return m ? m[1].replace(/'\\''/g, "'") : word.trim();
3874
5444
  }
3875
5445
 
5446
+ /** Core's stylesheet text, by project folder. @type {Map<string, string>} */
5447
+ const coreStyles = new Map();
5448
+
3876
5449
  /**
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}}
5450
+ * Whether Core's own stylesheet reads a token anywhere (a part the editor
5451
+ * does not render, such as the app shell behind the page, included).
5452
+ * @param {any} ctx
5453
+ * @param {string} token
3885
5454
  */
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;
5455
+ function coreStylesRead(ctx, token) {
5456
+ const cwd = String(ctx?.project?.cwd ?? '');
5457
+ let css = coreStyles.get(cwd);
5458
+ if (css == null) {
5459
+ try {
5460
+ css = fs.readFileSync(
5461
+ ctx.project.req.resolve('@astryxdesign/core/astryx.css'),
5462
+ 'utf8',
5463
+ );
5464
+ } catch {
5465
+ css = '';
3898
5466
  }
5467
+ coreStyles.set(cwd, css);
3899
5468
  }
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,
5469
+ return new RegExp(`var\\(\\s*${token.replace(/[-]/g, '\\-')}\\s*[,)]`).test(
5470
+ css,
3910
5471
  );
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
5472
  }