@astryxdesign/cli 0.7.16 → 0.7.17-canary.g49a475f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +12 -0
  3. package/api/build/_adapter.mjs +51 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +4 -3
  7. package/api/build/build.type.d.mts +2 -2
  8. package/api/build/build.type.mjs +3 -3
  9. package/api/build/kit/kind.d.mts +2 -1
  10. package/api/build/kit/kind.mjs +199 -10
  11. package/api/build/kit/kit.mjs +6 -4
  12. package/api/build/kit/rank.d.mts +4 -2
  13. package/api/build/kit/rank.mjs +125 -24
  14. package/api/build/kit/start.d.mts +5 -4
  15. package/api/build/kit/start.mjs +12 -8
  16. package/api/build/kit/weights.d.mts +39 -3
  17. package/api/build/kit/weights.json +1 -1
  18. package/api/build/kit/weights.mjs +340 -43
  19. package/api/build/kit/word-model.d.mts +23 -0
  20. package/api/build/kit/word-model.mjs +46 -0
  21. package/api/build/kit/words.d.mts +48 -0
  22. package/api/build/kit/words.mjs +90 -1
  23. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  24. package/api/component/list/list.d.mts +1 -1
  25. package/api/component/list/list.mjs +48 -6
  26. package/api/discover/_adapter.d.mts +1 -1
  27. package/api/discover/search/search.mjs +3 -2
  28. package/api/docs/_adapter.d.mts +26 -2
  29. package/api/docs/_adapter.mjs +219 -6
  30. package/api/docs/docs.d.mts +3 -0
  31. package/api/docs/docs.doc.mjs +7 -1
  32. package/api/docs/docs.mjs +12 -0
  33. package/api/docs/docs.type.d.mts +5 -0
  34. package/api/docs/docs.type.mjs +2 -0
  35. package/api/docs/node/node.mjs +1 -1
  36. package/api/doctor/_adapter.d.mts +27 -5
  37. package/api/doctor/_adapter.mjs +83 -10
  38. package/api/doctor/built-checks.mjs +40 -14
  39. package/api/doctor/doctor.d.mts +4 -3
  40. package/api/doctor/doctor.mjs +14 -7
  41. package/api/doctor/theme-checks.mjs +121 -17
  42. package/api/icon/_records.mjs +2 -1
  43. package/api/index.d.mts +2 -0
  44. package/api/index.mjs +2 -0
  45. package/api/integration/_adapter.d.mts +44 -0
  46. package/api/integration/_adapter.mjs +77 -1
  47. package/api/integration/authoring-checks.mjs +6 -6
  48. package/api/integration/example-scope.d.mts +14 -0
  49. package/api/integration/example-scope.mjs +44 -0
  50. package/api/integration/example-scope.type.d.mts +29 -0
  51. package/api/integration/example-scope.type.mjs +25 -0
  52. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  53. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  54. package/api/integration/validate-integration.mjs +19 -1
  55. package/api/integration/validate-integration.type.d.mts +9 -0
  56. package/api/integration/validate-integration.type.mjs +1 -1
  57. package/api/integration/validateIntegration.doc.mjs +1 -1
  58. package/api/render/_adapter.mjs +591 -195
  59. package/api/render/render.doc.mjs +11 -3
  60. package/api/render/render.type.d.mts +52 -0
  61. package/api/render/render.type.mjs +31 -1
  62. package/api/search/ORDERING.md +1 -1
  63. package/api/search/_adapter.d.mts +9 -0
  64. package/api/search/_adapter.mjs +85 -0
  65. package/api/search/_candidate-score.mjs +51 -32
  66. package/api/search/_fit-order.mjs +3 -3
  67. package/api/search/_gather-components.d.mts +3 -2
  68. package/api/search/_gather-components.mjs +12 -3
  69. package/api/search/_lexical.d.mts +5 -0
  70. package/api/search/_lexical.mjs +8 -2
  71. package/api/search/_result.d.mts +11 -9
  72. package/api/search/_result.mjs +4 -4
  73. package/api/search/_score.d.mts +6 -1
  74. package/api/search/_score.mjs +15 -3
  75. package/api/search/search-index.mjs +7 -1
  76. package/api/search/search.d.mts +1 -1
  77. package/api/theme/_adapter.mjs +12 -1
  78. package/api/theme/build/build.d.mts +75 -0
  79. package/api/theme/build/build.mjs +243 -58
  80. package/api/theme/build/font-warning.d.mts +7 -0
  81. package/api/theme/build/font-warning.mjs +17 -0
  82. package/api/theme/theme.type.d.mts +10 -0
  83. package/api/theme/theme.type.mjs +7 -1
  84. package/api/theme-edit/_adapter.d.mts +63 -2
  85. package/api/theme-edit/_adapter.mjs +771 -57
  86. package/api/theme-edit/_check.d.mts +40 -22
  87. package/api/theme-edit/_check.mjs +2029 -336
  88. package/api/theme-edit/_color.d.mts +10 -0
  89. package/api/theme-edit/_color.mjs +49 -1
  90. package/api/theme-edit/_compiler.mjs +9 -0
  91. package/api/theme-edit/_context.d.mts +3 -3
  92. package/api/theme-edit/_context.mjs +111 -48
  93. package/api/theme-edit/_css.d.mts +14 -0
  94. package/api/theme-edit/_css.mjs +46 -1
  95. package/api/theme-edit/_edit.d.mts +18 -4
  96. package/api/theme-edit/_edit.mjs +1685 -155
  97. package/api/theme-edit/_how-commands.d.mts +65 -0
  98. package/api/theme-edit/_how-commands.mjs +633 -1
  99. package/api/theme-edit/_how-question.d.mts +84 -0
  100. package/api/theme-edit/_how-question.mjs +5124 -281
  101. package/api/theme-edit/_how.mjs +140 -29
  102. package/api/theme-edit/_marks.d.mts +31 -5
  103. package/api/theme-edit/_marks.mjs +57 -5
  104. package/api/theme-edit/_name-rule.d.mts +11 -0
  105. package/api/theme-edit/_name-rule.mjs +12 -0
  106. package/api/theme-edit/_normal.d.mts +257 -0
  107. package/api/theme-edit/_normal.mjs +1252 -0
  108. package/api/theme-edit/_palette.mjs +10 -4
  109. package/api/theme-edit/_parts.d.mts +10 -1
  110. package/api/theme-edit/_parts.mjs +179 -3
  111. package/api/theme-edit/_preview-app.d.mts +7 -1
  112. package/api/theme-edit/_preview-app.mjs +515 -148
  113. package/api/theme-edit/_preview.d.mts +100 -14
  114. package/api/theme-edit/_preview.mjs +549 -137
  115. package/api/theme-edit/_settings.d.mts +347 -30
  116. package/api/theme-edit/_settings.mjs +2971 -327
  117. package/api/theme-edit/_tables.d.mts +6 -0
  118. package/api/theme-edit/_tables.mjs +44 -1
  119. package/api/theme-edit/_vet.d.mts +18 -0
  120. package/api/theme-edit/_vet.mjs +32 -0
  121. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  122. package/api/theme-edit/theme-edit.type.mjs +4 -1
  123. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  124. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  125. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  126. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  128. package/api/upgrade/run/run.mjs +4 -3
  129. package/assets/codemods/integration-discovery.mjs +2 -1
  130. package/assets/codemods/run-codemod.mjs +87 -7
  131. package/assets/codemods/transforms/next/index.mjs +11 -1
  132. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  133. package/assets/component-list.generated.json +1 -0
  134. package/assets/docs/author-a-theme.doc.mjs +1 -0
  135. package/assets/docs/theme.doc.dense.mjs +2 -2
  136. package/assets/docs/theme.doc.mjs +1 -1
  137. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  138. package/assets/docs/tree/checks.doc.mjs +1 -1
  139. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  140. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  141. package/assets/docs/tree/single-component.doc.mjs +4 -0
  142. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  143. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  144. package/assets/docs/use-a-theme.doc.mjs +1 -1
  145. package/assets/docs.generated.json +2 -2
  146. package/assets/search-catalog.generated.json +2 -0
  147. package/assets/self-audit.generated.json +1 -1
  148. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  149. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  150. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  151. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  152. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  153. package/assets/templates/components.generated.json +1 -1
  154. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  155. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  156. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  157. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  158. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  159. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  160. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  161. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  162. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  163. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  164. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  165. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  166. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  167. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  168. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  169. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  170. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  171. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  172. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  173. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  174. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  175. package/assets/templates/pages/ide/page.tsx +24 -2
  176. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  177. package/assets/templates/pages/library/template.doc.mjs +4 -1
  178. package/assets/templates/pages/login/template.doc.mjs +2 -1
  179. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  180. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  181. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  182. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  183. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  184. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  185. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  186. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  187. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  188. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  189. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  190. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  191. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  192. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  193. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  194. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  195. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  196. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  197. package/assets/theme.template.ts +6 -0
  198. package/authoring/debug/parse.d.mts +3 -3
  199. package/authoring/doctypes/_schema.d.mts +3 -3
  200. package/authoring/doctypes/command/command.doc.mjs +1 -1
  201. package/authoring/doctypes/component/categories.d.mts +37 -0
  202. package/authoring/doctypes/component/categories.mjs +54 -0
  203. package/authoring/doctypes/template/template.doc.mjs +1 -1
  204. package/authoring/doctypes/template/type.ts +9 -0
  205. package/authoring/example/example.doc.d.mts +12 -0
  206. package/authoring/example/example.doc.mjs +69 -0
  207. package/authoring/example/preview.d.mts +92 -0
  208. package/authoring/example/preview.mjs +994 -0
  209. package/authoring/example/type.ts +102 -0
  210. package/authoring/index.d.mts +1 -0
  211. package/authoring/index.d.ts +12 -0
  212. package/authoring/index.mjs +3 -1
  213. package/clients/cli/bin/astryx.mjs +6 -9
  214. package/clients/cli/build-id.generated.json +1 -1
  215. package/clients/cli/commands/component.doc.mjs +1 -1
  216. package/clients/cli/commands/component.mjs +22 -3
  217. package/clients/cli/commands/docs.doc.mjs +7 -1
  218. package/clients/cli/commands/docs.mjs +3 -1
  219. package/clients/cli/commands/doctor.mjs +32 -14
  220. package/clients/cli/commands/experimental/render.mjs +42 -1
  221. package/clients/cli/commands/experimental/theme.mjs +163 -28
  222. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  223. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  224. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  225. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  226. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  227. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  228. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  229. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  230. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  231. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  232. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  233. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  234. package/clients/cli/commands/search.doc.mjs +2 -1
  235. package/clients/cli/commands/search.mjs +6 -1
  236. package/clients/cli/commands/template.mjs +4 -2
  237. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  238. package/clients/cli/commands/theme.doc.mjs +1 -1
  239. package/clients/cli/commands/theme.mjs +209 -8
  240. package/clients/cli/commands/upgrade.mjs +42 -7
  241. package/clients/cli/index.mjs +1 -1
  242. package/clients/cli/lib/cli-error.mjs +2 -1
  243. package/clients/cli/lib/component-format.mjs +205 -98
  244. package/clients/cli/lib/hook-format.mjs +9 -19
  245. package/clients/cli/lib/json-shim.mjs +77 -21
  246. package/clients/cli/lib/manifest.mjs +3 -2
  247. package/clients/cli/manifest.generated.json +1 -1
  248. package/foundation/agent-docs/agent-docs.mjs +1 -1
  249. package/foundation/config/theme-state.d.mts +13 -1
  250. package/foundation/config/theme-state.mjs +47 -7
  251. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  252. package/foundation/discovery/component-discovery.d.mts +11 -0
  253. package/foundation/discovery/component-discovery.mjs +56 -8
  254. package/foundation/discovery/component-replacement.mjs +130 -1
  255. package/foundation/discovery/copied-passages.mjs +2 -1
  256. package/foundation/discovery/doc-types.mjs +4 -3
  257. package/foundation/discovery/entry-name-files.d.mts +43 -0
  258. package/foundation/discovery/entry-name-files.mjs +264 -0
  259. package/foundation/discovery/hook-discovery.d.mts +8 -2
  260. package/foundation/discovery/hook-discovery.mjs +22 -8
  261. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  262. package/foundation/discovery/icon-set-checks.mjs +2 -1
  263. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  264. package/foundation/discovery/integration-doc-files.mjs +2 -1
  265. package/foundation/discovery/package-exports.d.mts +10 -0
  266. package/foundation/discovery/package-exports.mjs +56 -3
  267. package/foundation/discovery/prop-drift.mjs +9 -9
  268. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  269. package/foundation/discovery/runner-allowlist.mjs +2 -0
  270. package/foundation/discovery/stored-component-list.d.mts +43 -0
  271. package/foundation/discovery/stored-component-list.mjs +90 -0
  272. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  273. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  274. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  275. package/foundation/discovery/stored-self-audit.mjs +38 -18
  276. package/foundation/discovery/template-adapter.d.mts +52 -0
  277. package/foundation/discovery/template-adapter.mjs +176 -12
  278. package/foundation/discovery/template-icons.mjs +2 -1
  279. package/foundation/discovery/theme-discovery.mjs +3 -2
  280. package/foundation/discovery/theme-imports.d.mts +14 -0
  281. package/foundation/discovery/theme-imports.mjs +43 -1
  282. package/foundation/discovery/theming-targets.mjs +3 -2
  283. package/foundation/doc-compiler/import.mjs +7 -1
  284. package/foundation/doc-compiler/inputs.mjs +3 -2
  285. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  286. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  287. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  288. package/foundation/env/semver.mjs +3 -1
  289. package/foundation/fonts/font-stylesheet.d.mts +31 -0
  290. package/foundation/fonts/font-stylesheet.mjs +115 -0
  291. package/foundation/fs/cache-eviction.d.mts +21 -0
  292. package/foundation/fs/cache-eviction.mjs +73 -0
  293. package/foundation/fs/file-protection.mjs +4 -3
  294. package/foundation/fs/gather-cache.d.mts +25 -4
  295. package/foundation/fs/gather-cache.mjs +164 -55
  296. package/foundation/fs/jiti-cache.d.mts +19 -1
  297. package/foundation/fs/jiti-cache.mjs +130 -6
  298. package/foundation/fs/kept-tree.d.mts +60 -0
  299. package/foundation/fs/kept-tree.mjs +154 -0
  300. package/foundation/fs/listing-cache.d.mts +7 -0
  301. package/foundation/fs/listing-cache.mjs +10 -0
  302. package/foundation/fs/module-loader.d.mts +24 -2
  303. package/foundation/fs/module-loader.mjs +94 -21
  304. package/foundation/fs/paths.d.mts +18 -0
  305. package/foundation/fs/paths.mjs +15 -2
  306. package/foundation/identity/provider-identity.d.mts +6 -0
  307. package/foundation/identity/provider-identity.mjs +10 -1
  308. package/foundation/integrations/contribution-inventory.mjs +4 -3
  309. package/foundation/integrations/example-code.d.mts +63 -0
  310. package/foundation/integrations/example-code.mjs +416 -0
  311. package/foundation/integrations/public-imports.d.mts +9 -0
  312. package/foundation/integrations/public-imports.mjs +3 -2
  313. package/foundation/integrations/validate-contributions.mjs +17 -45
  314. package/foundation/render/embedded-files.d.mts +6 -0
  315. package/foundation/render/embedded-files.mjs +25 -5
  316. package/foundation/render/embedded-imports.d.mts +39 -7
  317. package/foundation/render/embedded-imports.mjs +66 -27
  318. package/foundation/render/file-header.d.mts +66 -0
  319. package/foundation/render/file-header.mjs +118 -0
  320. package/foundation/render/host-answer.d.mts +18 -0
  321. package/foundation/render/host-answer.mjs +46 -0
  322. package/foundation/render/host-exit.d.mts +1 -0
  323. package/foundation/render/host-exit.mjs +6 -1
  324. package/foundation/render/html-reader.d.mts +55 -2
  325. package/foundation/render/html-reader.mjs +145 -26
  326. package/foundation/render/markup-edits.d.mts +57 -0
  327. package/foundation/render/markup-edits.mjs +182 -0
  328. package/foundation/render/page-host.mjs +29 -12
  329. package/foundation/render/page-worker.mjs +121 -13
  330. package/foundation/render/picture-chrome.d.mts +4 -0
  331. package/foundation/render/picture-chrome.mjs +185 -0
  332. package/foundation/render/picture-playwright.d.mts +4 -0
  333. package/foundation/render/picture-playwright.mjs +34 -0
  334. package/foundation/render/rebuild.mjs +2 -1
  335. package/foundation/render/render-page.d.mts +35 -3
  336. package/foundation/render/render-page.mjs +316 -42
  337. package/foundation/render/source-block.d.mts +85 -6
  338. package/foundation/render/source-block.mjs +211 -20
  339. package/foundation/render/ts-paths.d.mts +69 -6
  340. package/foundation/render/ts-paths.mjs +326 -40
  341. package/foundation/response/error-codes.d.mts +3 -1
  342. package/foundation/response/error-codes.d.ts +1 -0
  343. package/foundation/response/error-codes.doc.mjs +12 -1
  344. package/foundation/response/error-codes.mjs +11 -1
  345. package/foundation/response/response-types.doc.mjs +2 -2
  346. package/foundation/text/compare-text.d.mts +14 -0
  347. package/foundation/text/compare-text.mjs +68 -0
  348. package/foundation/text/string-utils.d.mts +3 -2
  349. package/foundation/text/string-utils.mjs +18 -4
  350. package/foundation/text/suggest-order.d.mts +9 -0
  351. package/foundation/text/suggest-order.mjs +15 -1
  352. package/foundation/xle/expand.mjs +2 -1
  353. package/host/index.mjs +8 -6
  354. package/package.json +7 -6
@@ -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,
@@ -32,9 +31,11 @@ import {
32
31
  numbersIn,
33
32
  propertyGrammar,
34
33
  takesPercentage,
34
+ sameKindValues,
35
35
  } from './_css.mjs';
36
36
  import {calcVars, coreFallback, multipliedTokens} from './_parts.mjs';
37
37
  import {
38
+ MODE_WORDS,
38
39
  AUTO_SPREAD,
39
40
  COLOR_PROP_PARTS,
40
41
  COLOR_PROPS,
@@ -61,6 +62,7 @@ import {
61
62
  wordTable,
62
63
  WRAPPED_PARTS,
63
64
  CARD_LIKE,
65
+ isSystemFamily,
64
66
  } from './_tables.mjs';
65
67
  import {
66
68
  COLOR_NAMES,
@@ -85,27 +87,82 @@ import {
85
87
  camel,
86
88
  kebab,
87
89
  nearest,
90
+ negates,
88
91
  partDefault,
89
92
  partsOf,
90
93
  refuse,
91
94
  lengthPx,
92
95
  radiusAt,
93
96
  radiusTokenOf,
97
+ cornerParts,
94
98
  focusStateOf,
95
99
  valueProblem,
96
100
  partComponentDocs,
97
101
  themeFiles,
98
102
  ownSourceTokenValues,
99
103
  baseTopTokens,
104
+ baseComponent,
100
105
  baseComponentReads,
106
+ baseRuleHas,
101
107
  partRuleTokens,
102
108
  cssFamily,
103
109
  familySpaces,
110
+ baseTextPx,
111
+ fontsourcePackageOf,
104
112
  } from './_settings.mjs';
113
+ import {isColorToken} from './_compiler.mjs';
114
+ import {
115
+ trimInsideQuotes,
116
+ colorPair,
117
+ otherSettingLabel,
118
+ familiesOf,
119
+ familyPieces,
120
+ normalValueText,
121
+ normalizeEntry,
122
+ withoutDebris,
123
+ typoOf,
124
+ typoNear,
125
+ PROPERTY_WORDS,
126
+ WEIGHT_WORDS,
127
+ TAILWIND_RADIUS,
128
+ documentReadings,
129
+ documentNumericTable,
130
+ documentRange,
131
+ withoutCopyDebris,
132
+ commaNumbers,
133
+ } from './_normal.mjs';
134
+
135
+ export {
136
+ familiesOf,
137
+ familyPieces,
138
+ normalValueText,
139
+ normalizeEntry,
140
+ withoutDebris,
141
+ };
105
142
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
106
143
 
107
144
  export {lengthPx};
108
145
 
146
+ /**
147
+ * The radius the base theme's own rule gives a part, in px, or null when
148
+ * its rule gives none.
149
+ * @param {any} ctx
150
+ * @param {{light: Record<string, string>}} base
151
+ * @param {string} part
152
+ * @param {string | undefined} when
153
+ * @returns {number | null}
154
+ */
155
+ function basePartRadiusPx(ctx, base, part, when) {
156
+ const own = ctx.base
157
+ ? baseComponent(ctx.base, ctx, part, 'borderRadius', {when})
158
+ : null;
159
+ if (typeof own !== 'string') return null;
160
+ const tokenName = /var\(\s*(--radius-[\w-]+)/.exec(own)?.[1];
161
+ if (tokenName) return tokenPx(base, tokenName);
162
+ const px = lengthPx(own);
163
+ return px == null ? null : Math.min(px, 9999);
164
+ }
165
+
109
166
  /**
110
167
  * A token's value in px, following var() references through the tokens.
111
168
  * @param {{light: Record<string, string>}} base
@@ -122,6 +179,13 @@ function tokenPx(base, token) {
122
179
  return lengthPx(v);
123
180
  }
124
181
 
182
+ // A type scale ratio is a number above 1, up to 2.
183
+ documentNumericTable(
184
+ ['type'],
185
+ Object.entries(TYPE_STYLES).map(([name, style]) => [name, style.ratio]),
186
+ [1, 2],
187
+ );
188
+
125
189
  /**
126
190
  * The `type` preset nearest a scale ratio typed as a number (1.3 is
127
191
  * editorial), or null for a number that is no ratio (16).
@@ -154,6 +218,108 @@ const cornerPxOf = v =>
154
218
 
155
219
  const E = ERROR_CODES;
156
220
 
221
+ /**
222
+ * Why the math in a value's calc() cannot work, or null: each `+`/`-`
223
+ * needs two sides of one kind (a length with a length or a percentage, a
224
+ * number with a number), `*` needs a plain number on one side, `/` a plain
225
+ * number on the right. A var() counts as its fallback; one with none, or a
226
+ * nested min(), max() or clamp(), is not judged.
227
+ * @param {string} value
228
+ * @returns {string | null}
229
+ */
230
+ export function calcUnitProblem(value) {
231
+ const text = String(value);
232
+ const re = /\bcalc\(/gi;
233
+ let m;
234
+ while ((m = re.exec(text))) {
235
+ const open = m.index + m[0].length - 1;
236
+ const close = matchingParen(text, open);
237
+ if (close < 0) return null;
238
+ let expr = text.slice(open + 1, close);
239
+ // Each var() is its fallback, innermost first.
240
+ for (let i = 0; i < 20 && /\bvar\(/i.test(expr); i += 1) {
241
+ const at = expr.search(/\bvar\((?:[^()]|\([^()]*\))*\)/i);
242
+ const v = /\bvar\(((?:[^()]|\([^()]*\))*)\)/i.exec(expr.slice(at));
243
+ if (at < 0 || !v) return null;
244
+ const comma = v[1].indexOf(',');
245
+ if (comma < 0) return null;
246
+ expr = `${expr.slice(0, at)}(${v[1].slice(comma + 1).trim()})${expr.slice(at + v[0].length)}`;
247
+ }
248
+ if (/[a-z-]+\(/i.test(expr.replace(/\bcalc\(/gi, '('))) continue;
249
+ const found = expr.match(/\d*\.?\d+(?:e[+-]?\d+)?[a-z%]*|[-+*/()]/gi);
250
+ if (!found) continue;
251
+ const tokens = found;
252
+ let pos = 0;
253
+ /** @returns {string | null} */
254
+ const kindOf = (/** @type {string} */ t) => {
255
+ const u = /[a-z%]*$/i.exec(t)?.[0].toLowerCase() ?? '';
256
+ if (!u) return 'number';
257
+ if (u === '%') return 'percent';
258
+ if (/^(m?s)$/.test(u)) return 'time';
259
+ if (/^(deg|rad|grad|turn)$/.test(u)) return 'angle';
260
+ return 'length';
261
+ };
262
+ /** @type {string | null} */
263
+ let why = null;
264
+ const fail = (/** @type {string} */ w) => {
265
+ why ??= w;
266
+ return 'number';
267
+ };
268
+ const join = (
269
+ /** @type {string} */ a,
270
+ /** @type {string} */ b,
271
+ /** @type {string} */ op,
272
+ ) => {
273
+ if (op === '+' || op === '-') {
274
+ if (a === b) return a;
275
+ const lp = new Set([a, b]);
276
+ if (lp.has('length') && lp.has('percent') && lp.size === 2)
277
+ return 'length';
278
+ return fail(`${a} ${op} ${b} adds two kinds of value`);
279
+ }
280
+ if (op === '*') {
281
+ if (a === 'number') return b;
282
+ if (b === 'number') return a;
283
+ return fail(`${a} * ${b} multiplies two values with units`);
284
+ }
285
+ if (b === 'number') return a;
286
+ return fail(`${a} / ${b} divides by a value with a unit`);
287
+ };
288
+ /** @returns {string} */
289
+ const factor = () => {
290
+ const t = tokens[pos++];
291
+ if (t === '(') {
292
+ const k = sum();
293
+ pos++;
294
+ return k;
295
+ }
296
+ if (t === '-' || t === '+') return factor();
297
+ return t == null ? 'number' : (kindOf(t) ?? 'number');
298
+ };
299
+ /** @returns {string} */
300
+ const product = () => {
301
+ let k = factor();
302
+ while (tokens[pos] === '*' || tokens[pos] === '/') {
303
+ const op = tokens[pos++];
304
+ k = join(k, factor(), op);
305
+ }
306
+ return k;
307
+ };
308
+ /** @returns {string} */
309
+ function sum() {
310
+ let k = product();
311
+ while (tokens[pos] === '+' || tokens[pos] === '-') {
312
+ const op = tokens[pos++];
313
+ k = join(k, product(), op);
314
+ }
315
+ return k;
316
+ }
317
+ sum();
318
+ if (why) return why;
319
+ }
320
+ return null;
321
+ }
322
+
157
323
  /**
158
324
  * The fallbacks of the var() calls inside a value that is not one var()
159
325
  * alone (`calc(var(--x, 4px) * 2)`), in order. A var() with an empty
@@ -227,6 +393,25 @@ function matchingParen(text, open) {
227
393
  return -1;
228
394
  }
229
395
 
396
+ /** A yes or no word, which `rounded` reads as round or square. */
397
+ const YES_NO = /^(true|yes|on|none|false|off|no)$/i;
398
+
399
+ /**
400
+ * A value as the corners dial reads it: a rung in any case, or a size with
401
+ * its unit (`10PX`, `1rem`) in px; null for anything else, a bare number
402
+ * included.
403
+ * @param {string} v
404
+ * @returns {string | null}
405
+ */
406
+ function cornersRead(v) {
407
+ const lower = String(v).trim().toLowerCase();
408
+ if (CORNERS.some(([n]) => n === lower)) return lower;
409
+ if (/^(0|none|sharp|zero|flat)$/.test(lower)) return 'square';
410
+ if (/^[+-]?\d*\.?\d+$/.test(lower)) return null;
411
+ const px = lengthPx(lower);
412
+ return px != null && px >= 0 ? `${Math.round(px * 100) / 100}px` : null;
413
+ }
414
+
230
415
  /**
231
416
  * A text size written another way (20px, 2e1, +20, 1.25rem, 125%, `20 px`,
232
417
  * `1,25rem`) as the body size in pixels text-size takes, kept to its 10 to
@@ -235,13 +420,52 @@ function matchingParen(text, open) {
235
420
  * @returns {number | null}
236
421
  */
237
422
  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'),
423
+ // Paste debris around the size (quotes, `!important`, a trailing `;` or
424
+ // `,`) is not part of it.
425
+ const bare = withoutDebris(
426
+ String(v)
427
+ .replace(/^\s*(["'])(.*)\1\s*$/, '$2')
428
+ .replace(/\s*!\s*important\s*/i, '')
429
+ .replace(/[;,]+\s*$/, ''),
243
430
  );
431
+ const plain = typedPlain(bare)
432
+ .replace(/(\d)\.(?=[a-z%]*$)/i, '$1')
433
+ .replace(/\s+/g, '')
434
+ .replace(/^(\d+),(\d+)/, '$1.$2');
435
+ // A constant calc() of px and rem sizes (`calc(16px + 2px)`) is worked out.
436
+ const calc =
437
+ /^calc\((\d*\.?\d+)(px|rem|em)?([*/+-])(\d*\.?\d+)(px|rem|em)?\)$/i.exec(
438
+ plain,
439
+ );
440
+ if (calc) {
441
+ const px = (/** @type {string} */ n, /** @type {string | undefined} */ u) =>
442
+ Number(n) * (u && /r?em/i.test(u) ? 16 : 1);
443
+ const [a, b] = [px(calc[1], calc[2]), px(calc[4], calc[5])];
444
+ const op = calc[3];
445
+ // Sizes add and subtract; a size scales by a plain number.
446
+ const r =
447
+ op === '+' || op === '-'
448
+ ? calc[2] && calc[5]
449
+ ? op === '+'
450
+ ? a + b
451
+ : a - b
452
+ : null
453
+ : op === '*'
454
+ ? calc[2] && calc[5]
455
+ ? null
456
+ : a * b
457
+ : calc[5]
458
+ ? null
459
+ : a / b;
460
+ return r != null && Number.isFinite(r) && r >= 10 && r <= 32
461
+ ? Math.round(r * 100) / 100
462
+ : null;
463
+ }
464
+ const m = /^\+?(\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/i.exec(plain);
244
465
  if (!m) return null;
466
+ // A bare number under 4 (1.5, 1.125) reads as rem as much as px: no
467
+ // size is guessed for it.
468
+ if (!m[2] && Number(m[1]) < 4) return null;
245
469
  const unit = (m[2] ?? '').toLowerCase();
246
470
  const n =
247
471
  Number(m[1]) *
@@ -334,6 +558,8 @@ function valueMeant(type, value) {
334
558
  .replace(/\s*!\s*important\s*$/i, '')
335
559
  .replace(/;+\s*$/, '')
336
560
  .trim();
561
+ // Copy debris around it (a trailing comma, a stray quote or bracket).
562
+ p = withoutDebris(p).trim();
337
563
  const q = /^(["'])(.*)\1$/.exec(p);
338
564
  if (q && type !== 'font') p = q[2].trim();
339
565
  const out = [p];
@@ -344,13 +570,14 @@ function valueMeant(type, value) {
344
570
  if (type === 'font' || type === 'font-family') {
345
571
  // A comma left out between families (`"Open Sans" serif`), read with
346
572
  // css-tree.
573
+ // The stack read as families (a trailing comma, a stack wrapped in one
574
+ // more pair of quotes), each quoted as CSS needs it.
575
+ const fams = familiesOf(p);
576
+ // A number or size is no family: never quoted into one (`"700"`).
577
+ if (fams?.length && !fams.some(f => NUMBERISH.test(f)))
578
+ out.push(fams.map(f => cssFamily(f, true)).join(', '));
347
579
  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(', '));
580
+ if (listed && !fams?.length) out.push(listed);
354
581
  }
355
582
  return [...new Set(out)].filter(x => x && x !== value.trim());
356
583
  }
@@ -430,7 +657,7 @@ function mathSpaced(v) {
430
657
  function numberMeant(v, name, ok) {
431
658
  const t = v.trim();
432
659
  const plain = typedPlain(t).replace(/(\d)\.$/, '$1');
433
- const comma = plain.replace(/^([+-]?\d+),(\d+)/, '$1.$2');
660
+ const comma = commaNumbers(plain);
434
661
  const tries = [
435
662
  /^[\doO.]+$/.test(plain) && /\d/.test(plain)
436
663
  ? plain.replace(/[oO]/g, '0')
@@ -590,6 +817,22 @@ export function storedProblems(ctx, slug, data, skip = '') {
590
817
  return scope(`${s.thing} applies to the whole theme, not to ${s.on}`);
591
818
  if (s.mode && s.source === 'dial' && !PALETTE_DIALS.includes(s.thing))
592
819
  return scope(`${s.thing} is the same in light and dark`);
820
+ // A light and a dark pair saved for one mode (a hand edit): set
821
+ // refuses that, so the loader does too; the repair is the half saved
822
+ // for that mode.
823
+ if (s.mode && /^\s*light-dark\(/i.test(String(s.value ?? ''))) {
824
+ const pair = colorPair(
825
+ String(s.value)
826
+ .trim()
827
+ .replace(/^light-dark\(\s*([\s\S]*)\)\s*$/i, 'light: $1')
828
+ .replace(/,\s*/, '; dark: '),
829
+ );
830
+ return {
831
+ setting: s,
832
+ why: `${s.thing} gives both modes with light-dark(), and is saved for ${s.mode} only`,
833
+ ...(pair ? {fix: s.mode === 'dark' ? pair.dark : pair.light} : {}),
834
+ };
835
+ }
593
836
  if (t && s.state && ![...t.states, ...COMMON_STATES].includes(s.state))
594
837
  return scope(`"${s.state}" is not a state of ${s.on}`);
595
838
  if (t && s.when) {
@@ -648,13 +891,45 @@ export function storedProblems(ctx, slug, data, skip = '') {
648
891
  // it.
649
892
  for (const s of data.settings) {
650
893
  if (replaced(s) || typeof s.value !== 'string') continue;
651
- const clean = normalValueText(s.value);
652
- if (clean !== s.value)
894
+ // Read as typed input is (a font family's quotes trimmed too), so the
895
+ // line offered is the value set would save.
896
+ const clean = /font/i.test(s.thing)
897
+ ? trimInsideQuotes(normalValueText(s.value))
898
+ : normalValueText(s.value);
899
+ if (clean !== s.value) {
900
+ // Name what is wrong: invisible spaces, or quotes around the value
901
+ // CSS does not read (a curly quote inside a quoted string is fine,
902
+ // and is left as it is).
903
+ const spaces =
904
+ clean.replace(/["']/g, '') !==
905
+ s.value.replace(
906
+ /[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`"']/g,
907
+ '',
908
+ );
909
+ const quotes =
910
+ /[\u2018-\u201F\u00AB\u00BB\u2039\u203A\u300C-\u300F\uFF02\uFF07`]/.test(
911
+ s.value,
912
+ ) &&
913
+ clean.replace(
914
+ /[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
915
+ '',
916
+ ) !==
917
+ s.value.replace(
918
+ /[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000\u200B-\u200D\u2060\uFEFF]/g,
919
+ '',
920
+ );
921
+ const why = [
922
+ spaces &&
923
+ 'a no-break, thin or zero-width space, which the browser does not read as a space',
924
+ quotes &&
925
+ 'curly or other quotes around a value, where CSS reads only straight ones',
926
+ ].filter(Boolean);
653
927
  found.push({
654
928
  setting: s,
655
- why: `${s.thing} holds a no-break, thin or zero-width space, which the browser does not read as a space`,
929
+ why: `${s.thing} holds ${why.join(', and ') || 'characters the browser does not read as written'}`,
656
930
  fix: clean,
657
931
  });
932
+ }
658
933
  }
659
934
  for (const s of data.settings) {
660
935
  if (s.source !== 'token' || s.thing === skipThing || !(s.thing in TOKENS))
@@ -700,6 +975,128 @@ export function storedProblems(ctx, slug, data, skip = '') {
700
975
  return found;
701
976
  }
702
977
 
978
+ /** The generic families a font list ends with. */
979
+ const GENERIC_FAMILIES = [
980
+ 'serif',
981
+ 'sans-serif',
982
+ 'monospace',
983
+ 'system-ui',
984
+ 'cursive',
985
+ 'fantasy',
986
+ 'ui-serif',
987
+ 'ui-sans-serif',
988
+ 'ui-monospace',
989
+ 'ui-rounded',
990
+ ];
991
+
992
+ /** The theme-wide dial or token for a CSS property typed with no part. */
993
+ const WHOLE_THEME_EQUIVALENT = /** @type {Record<string, string>} */ ({
994
+ 'border-radius': 'corners',
995
+ 'font-size': 'text-size',
996
+ 'font-family': 'font',
997
+ color: '--color-text-primary',
998
+ background: '--color-background-body',
999
+ 'background-color': '--color-background-body',
1000
+ });
1001
+
1002
+ /** A number or a size, which is never a font family. */
1003
+ const NUMBERISH = /^[+-]?(\d+\.?\d*|\.\d+)(px|rem|em|pt|%)?$/i;
1004
+
1005
+ /**
1006
+ * The font list a value with a missing comma or a spaced generic means
1007
+ * (`Georgia serif` is `Georgia, serif`, `Inter, sans serif` is `Inter,
1008
+ * sans-serif`), with why; null when it has neither. A generic is read only
1009
+ * in lower case, so a family named `Source Serif` stays one name.
1010
+ * @param {string} value
1011
+ * @returns {{value: string, why: string} | null}
1012
+ */
1013
+ export function fontListMeant(value) {
1014
+ const v = String(value).trim();
1015
+ // A whole list in one pair of quotes or brackets (`"Inter, serif"`,
1016
+ // `「Inter, serif」`): the quotes go around one family, so the list is
1017
+ // what is inside.
1018
+ const wrapped =
1019
+ /^(?:"([^"]*,[^"]*)"|'([^']*,[^']*)'|「([^」]*,[^」]*)」|『([^』]*,[^』]*)』|“([^”]*,[^”]*)”|‘([^’]*,[^’]*)’|«([^»]*,[^»]*)»)$/.exec(
1020
+ v,
1021
+ );
1022
+ if (wrapped) {
1023
+ const inside = wrapped.slice(1).find(x => x != null) ?? '';
1024
+ return {
1025
+ value: (fontListMeant(inside)?.value ?? inside).trim(),
1026
+ why: 'quotes go around one family name, not the whole list',
1027
+ };
1028
+ }
1029
+ if (/["']/.test(v)) return null;
1030
+ // Families split by `|`, `;` or ` / ` instead of commas.
1031
+ if (
1032
+ // (A pasted declaration, `font-family: Georgia, serif;`, is read
1033
+ // elsewhere: a colon or a trailing `;` is no separator.)
1034
+ !/:|\.(woff2?|ttf|otf)\b/i.test(v) &&
1035
+ /\S\s*(?:\||;|\s\/\s)\s*\S/.test(v)
1036
+ ) {
1037
+ const list = v
1038
+ .split(/\s*(?:\||;|\s\/\s)\s*/)
1039
+ .map(x => x.trim())
1040
+ .filter(Boolean)
1041
+ .join(', ');
1042
+ if (list && list !== v)
1043
+ return {
1044
+ value: fontListMeant(list)?.value ?? list,
1045
+ why: 'families are separated by commas',
1046
+ };
1047
+ }
1048
+ if (/\bsans serif\b/.test(v) && !/\d/.test(v))
1049
+ return {
1050
+ value: v.replace(/\bsans serif\b/g, 'sans-serif'),
1051
+ why: 'the generic family is sans-serif, with a dash',
1052
+ };
1053
+ // A comma missing before the generic family of any family in the list
1054
+ // (`Inter, Georgia serif`), the names in any case (`georgia serif`).
1055
+ const SHORTHAND =
1056
+ /^(\d+(\.\d+)?(px|rem|em|pt|%)?|bold|bolder|lighter|normal|italic|oblique|small-caps)$/i;
1057
+ // A word of a family name: letters (a digit after the first word, as in
1058
+ // `Source Serif 4`), or a generic; never a shorthand's weight or size.
1059
+ const familyWord = (/** @type {string} */ w, /** @type {number} */ i) =>
1060
+ (/^[A-Za-z][A-Za-z0-9]*$/.test(w) && !SHORTHAND.test(w)) ||
1061
+ (i > 0 && /^\d+$/.test(w)) ||
1062
+ GENERIC_FAMILIES.includes(w);
1063
+ const pieces = v.split(/\s*,\s*/);
1064
+ let missing = false;
1065
+ const fixedPieces = pieces.map(piece => {
1066
+ const ws = piece.split(/\s+/);
1067
+ const end = ws[ws.length - 1];
1068
+ if (
1069
+ ws.length > 1 &&
1070
+ GENERIC_FAMILIES.includes(end) &&
1071
+ ws.slice(0, -1).every(familyWord)
1072
+ ) {
1073
+ missing = true;
1074
+ return `${ws.slice(0, -1).join(' ')}, ${end}`;
1075
+ }
1076
+ return piece;
1077
+ });
1078
+ if (missing && pieces.length > 1)
1079
+ return {
1080
+ value: fixedPieces.join(', '),
1081
+ why: 'a comma goes before each generic family',
1082
+ };
1083
+ if (v.includes(',')) return null;
1084
+ const words = v.split(/\s+/);
1085
+ const last = words[words.length - 1];
1086
+ // Only family names before it (capitalized words), never a font
1087
+ // shorthand's weight, style or size.
1088
+ if (
1089
+ words.length > 1 &&
1090
+ GENERIC_FAMILIES.includes(last) &&
1091
+ words.slice(0, -1).every(familyWord)
1092
+ )
1093
+ return {
1094
+ value: `${words.slice(0, -1).join(' ')}, ${last}`,
1095
+ why: `a comma goes before the generic family ${last}`,
1096
+ };
1097
+ return null;
1098
+ }
1099
+
703
1100
  /**
704
1101
  * A value of a type to put in a suggestion, so a suggested command runs.
705
1102
  * @param {string} type
@@ -739,6 +1136,8 @@ function groupOfPropType(prop) {
739
1136
  * @param {string} slug
740
1137
  * @param {string[]} [readers] the CSS properties that read the token
741
1138
  * @param {boolean} [multiplied] whether Core multiplies the token by a size
1139
+ * @param {boolean} [isSet] whether the theme sets the token now (an undo
1140
+ * of it works)
742
1141
  */
743
1142
  function checkTypedValue(
744
1143
  type,
@@ -749,6 +1148,7 @@ function checkTypedValue(
749
1148
  slug,
750
1149
  readers = [],
751
1150
  multiplied = false,
1151
+ isSet = true,
752
1152
  ) {
753
1153
  // The value meant, when what is wrong is how it was typed (a trailing
754
1154
  // `;`, a comment, quotes around it, full-width characters, a font name
@@ -772,17 +1172,37 @@ function checkTypedValue(
772
1172
  }
773
1173
  return null;
774
1174
  };
775
- /** @param {string} what @param {string} example */
1175
+ /** @param {string} what @param {string | null} example */
776
1176
  const bad = (what, example) =>
777
1177
  refuse(
778
1178
  E.ERR_THEME_BAD_VALUE,
779
1179
  `${name} is ${what}; "${value}" is not one.`,
780
1180
  {
1181
+ // Nothing read from the value (no example given): how, never a
1182
+ // stock value.
781
1183
  run: [
782
- `${P} set ${slug} ${name} ${quoteCommandArgument(meant() ?? example)}`,
1184
+ (meant() ?? example) == null
1185
+ ? `${HOW} ${name}`
1186
+ : `${P} set ${slug} ${name} ${quoteCommandArgument(String(meant() ?? example))}`,
783
1187
  ],
784
1188
  },
785
1189
  );
1190
+ // A font family list with a comma missing before a generic family
1191
+ // (`Georgia serif`), or a generic written with a space (`sans serif`): the
1192
+ // list meant.
1193
+ if (type === 'font') {
1194
+ const fixed = fontListMeant(value);
1195
+ if (fixed)
1196
+ refuse(
1197
+ E.ERR_THEME_BAD_VALUE,
1198
+ `"${value}" names a family that exists nowhere: ${fixed.why}.`,
1199
+ {
1200
+ run: [
1201
+ `${P} set ${slug} ${name} ${quoteCommandArgument(fixed.value)}`,
1202
+ ],
1203
+ },
1204
+ );
1205
+ }
786
1206
  // A font file or a link is no family name: never quoted into one.
787
1207
  if (type === 'font') {
788
1208
  const file = fontFileReason(pastedFont(value) || value);
@@ -792,6 +1212,18 @@ function checkTypedValue(
792
1212
  `${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
793
1213
  ],
794
1214
  });
1215
+ // An empty family (`""`, a trailing comma) or one quoted name holding
1216
+ // commas is a broken stack: the browser drops the fallback after it.
1217
+ const pieces = familyPieces(value);
1218
+ if (
1219
+ pieces &&
1220
+ (pieces.some(f => !f.name) ||
1221
+ pieces.some(f => f.quoted && f.name.includes(',')))
1222
+ )
1223
+ bad(
1224
+ 'a font family list with a name for each family',
1225
+ exampleOf(type, name),
1226
+ );
795
1227
  }
796
1228
  if (!isSafeValue(value))
797
1229
  refuse(
@@ -813,14 +1245,24 @@ function checkTypedValue(
813
1245
  if (keyword)
814
1246
  refuse(
815
1247
  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.`,
1248
+ `"${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
1249
  {
1250
+ // How for the token; the undo only when the theme sets it.
818
1251
  run: [
819
- `${P} set ${slug} ${name} ${quoteCommandArgument(exampleOf(type, name))}`,
820
- `${P} undo ${slug} ${name}`,
1252
+ `${HOW} ${name}`,
1253
+ ...(isSet ? [`${P} undo ${slug} ${name}`] : []),
821
1254
  ],
822
1255
  },
823
1256
  );
1257
+ // Math whose units cannot combine (`8 + 2px`, `0.5rem * 1px`, a var()
1258
+ // read as its fallback): the browser drops the whole value.
1259
+ const math = type === 'size' ? calcUnitProblem(value) : null;
1260
+ if (math)
1261
+ refuse(
1262
+ E.ERR_THEME_BAD_VALUE,
1263
+ `${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.`,
1264
+ {run: [`${HOW} ${name}`]},
1265
+ );
824
1266
  // A var() inside a larger value (calc, max, color-mix) has a fallback of
825
1267
  // the token's kind too, checked like a whole-value var().
826
1268
  if (type !== 'other')
@@ -834,6 +1276,16 @@ function checkTypedValue(
834
1276
  )
835
1277
  )
836
1278
  continue;
1279
+ // A factor in a size's math (`calc(0.75rem * var(--x, 1))`, as the
1280
+ // official themes write their type scale): a plain number there is
1281
+ // what multiplies the size.
1282
+ if (
1283
+ type === 'size' &&
1284
+ within.some(f => /^(calc|min|max|clamp)$/i.test(f)) &&
1285
+ /^[+-]?(\d+\.?\d*|\.\d+)$/.test(fallback.trim()) &&
1286
+ (/[*/]\s*var\(/i.test(value) || /var\([^()]*\)\s*[*/]/i.test(value))
1287
+ )
1288
+ continue;
837
1289
  if (fallback === '')
838
1290
  refuse(
839
1291
  E.ERR_THEME_BAD_VALUE,
@@ -896,26 +1348,22 @@ function checkTypedValue(
896
1348
  );
897
1349
  return;
898
1350
  }
899
- if (type === 'color' && !isFixedColor(value)) bad('a color', '#1f2937');
1351
+ if (type === 'color' && !isFixedColor(value)) bad('a color', null);
900
1352
  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';
1353
+ // The token's own default is never offered as a repair: only a size
1354
+ // read from the value typed.
1355
+ const sizeExample = null;
912
1356
  // The size meant, when one dot or sign is all that is wrong (1.px).
913
1357
  const meant = value.trim().replace(/(\d)\.(?=[a-z%]|$)/gi, '$1');
914
1358
  // A bare number is the size in px.
915
1359
  // A bare number is the size in px; a minus sign is dropped.
916
1360
  const plain = value.trim().replace(/^-(?=\d|\.\d)/, '');
1361
+ // A bare number below one (a pasted `--radius: 0.5rem` that lost its
1362
+ // unit) has no unit to read it by: no size is guessed, as corners does.
917
1363
  const px = /^[+]?\d*\.?\d+(e[+-]?\d+)?$/i.test(plain)
918
- ? `${Number(plain)}px`
1364
+ ? Number(plain) > 0 && Number(plain) < 1
1365
+ ? null
1366
+ : `${Number(plain)}px`
919
1367
  : /^\d*\.?\d+[a-z%]+$/i.test(plain) && plain !== value.trim()
920
1368
  ? plain
921
1369
  : null;
@@ -1231,6 +1679,18 @@ function nearestColorName(v) {
1231
1679
  return nearest(w, COLOR_NAMES)[0] ?? null;
1232
1680
  }
1233
1681
 
1682
+ /**
1683
+ * Old keywords a property's grammar lists that no current browser applies,
1684
+ * each with the keyword that does what it meant.
1685
+ * @type {Record<string, Record<string, string>>}
1686
+ */
1687
+ const OBSOLETE_KEYWORDS = {
1688
+ cursor: {hand: 'pointer'},
1689
+ };
1690
+ documentReadings(
1691
+ Object.values(OBSOLETE_KEYWORDS).flatMap(words => Object.entries(words)),
1692
+ );
1693
+
1234
1694
  /**
1235
1695
  * Why a value is not one the property takes, or null. Colors are checked
1236
1696
  * by the editor's own color check; a property css-tree has no grammar for
@@ -1251,6 +1711,14 @@ function propertyProblem(prop, value) {
1251
1711
  takes: `a value its CSS grammar takes in each var() fallback too (${grammarText(known)})`,
1252
1712
  near: initialOf(prop),
1253
1713
  };
1714
+ // An old keyword the grammar still lists but no current browser
1715
+ // applies (`cursor: hand`): the keyword that does what it meant.
1716
+ const obsolete = OBSOLETE_KEYWORDS[prop]?.[v.toLowerCase()];
1717
+ if (obsolete)
1718
+ return {
1719
+ takes: `a value current browsers apply ("${v}" is an old keyword none applies; ${obsolete} does what it meant)`,
1720
+ near: obsolete,
1721
+ };
1254
1722
  if (matchValue(prop, v))
1255
1723
  return belowRange(prop, v)
1256
1724
  ? {
@@ -1281,9 +1749,7 @@ function propertyProblem(prop, value) {
1281
1749
  null)
1282
1750
  : null;
1283
1751
  // 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);
1752
+ // or the value typed cleaned; each checked.
1287
1753
  // A bare number on a length property means px (`padding 4` → `4px`, each
1288
1754
  // number in a list too), when the property takes that.
1289
1755
  // Each bare number token gets px (a mixed list `4 8px`, `8 / 4`, an
@@ -1296,31 +1762,77 @@ function propertyProblem(prop, value) {
1296
1762
  Number(num) === 0 ? `${pre}${num}` : `${pre}${num}px`,
1297
1763
  )
1298
1764
  : null;
1299
- // A suggestion is offered only when the property takes it, in range too.
1765
+ // A suggestion is offered only when the property takes it, in range too,
1766
+ // and never a reset the input did not hold (0, none, 1, auto, normal):
1767
+ // following it would undo what was asked. A reset typed with a typo
1768
+ // (`nnone`, `normall`: a word within two edits of it) is that reset,
1769
+ // corrected.
1770
+ const RESETS =
1771
+ /^(0|0px|none|1|auto|normal|initial|unset|inherit|revert|transparent)$/i;
1772
+ const typedAs = (/** @type {string} */ x) => x === typed || typoOf(typed, x);
1300
1773
  const takes = (/** @type {string | null} */ x) =>
1301
- x != null && matchValue(prop, x) != null && !belowRange(prop, x);
1774
+ x != null &&
1775
+ matchValue(prop, x) != null &&
1776
+ !belowRange(prop, x) &&
1777
+ !(RESETS.test(x.trim()) && !typedAs(x.trim().toLowerCase()));
1778
+ // A lone length on a shorthand where it is only a position (background,
1779
+ // mask) wipes the rest: no px is guessed there.
1780
+ const pxFits = !/^(background|mask)$/i.test(prop);
1781
+ // Words with a documented reading on a property (the allowlist a repair
1782
+ // may map through).
1783
+ const WORDS = PROPERTY_WORDS;
1784
+ // A weight word is its number (the same table the headings dial reads);
1785
+ // text in content is that text, quoted.
1786
+ const weightWord = typed.replace(/[\s-]+/g, '');
1787
+ const weight = HEADING_WEIGHTS[weightWord] ?? WEIGHT_WORDS[weightWord];
1788
+ const mapped =
1789
+ WORDS[prop]?.[typed.replace(/\s+/g, '-')] ??
1790
+ (prop === 'font-weight' && weight ? weight : null) ??
1791
+ (prop === 'content' && !/^["']|["']$/.test(v) ? JSON.stringify(v) : null) ??
1792
+ null;
1302
1793
  return {
1303
1794
  takes: `a value its CSS grammar takes (${grammarText(known)})`,
1304
1795
  near:
1305
- (takes(withPx) ? withPx : null) ??
1796
+ (mapped && matchValue(prop, mapped) != null ? mapped : null) ??
1797
+ (pxFits && takes(withPx) ? withPx : null) ??
1306
1798
  // Below the property's range (a negative width): the same, 0 or more.
1307
- (withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
1799
+ (pxFits && withPx && takes(withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1'))
1308
1800
  ? withPx.replace(/(^|[\s/(,])-(?=\.?\d)/g, '$1')
1309
1801
  : null) ??
1310
1802
  (takes(joined) && joined !== v ? joined : null) ??
1311
- // Several values on a property that takes one (padding-top with four):
1312
- // the first of them, when it is one the property takes.
1803
+ // A comma between digits is a decimal point (1,5rem is 1.5rem), never
1804
+ // a split into layers.
1805
+ (takes(commaNumbers(v)) && commaNumbers(v) !== v
1806
+ ? commaNumbers(v)
1807
+ : null) ??
1808
+ // Several values of one kind on a property that takes one
1809
+ // (padding-top with four lengths): the first as typed, with px only
1810
+ // when the property takes no bare number. Never one value of a
1811
+ // shorthand of several kinds (`all 200` for transition).
1313
1812
  (() => {
1314
- const first = splitTop((withPx ?? joined).trim(), ' ')[0];
1315
- return first && first !== v && takes(first) ? first : null;
1813
+ const same = sameKindValues(v);
1814
+ if (!same) return null;
1815
+ const first = same.items[0];
1816
+ const px = same.kind === '' ? `${first}px` : null;
1817
+ return takes(first) ? first : pxFits && px && takes(px) ? px : null;
1316
1818
  })() ??
1317
1819
  (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))),
1820
+ // Layers typed with one too many or an empty one (`url(a.png), red,
1821
+ // blue`, `red,,blue`): the layers before the last, else one of them,
1822
+ // when the property takes it. Never the property's reset or a stock
1823
+ // example: a repair carries only what was typed.
1824
+ (() => {
1825
+ const layers = splitTop(v.trim(), ',')
1826
+ .map(x => x.trim())
1827
+ .filter(Boolean);
1828
+ if (layers.length < 2 && !/,\s*,/.test(v)) return null;
1829
+ const tries = [
1830
+ layers.join(', '),
1831
+ layers.slice(0, -1).join(', '),
1832
+ ...layers,
1833
+ ];
1834
+ return tries.find(x => x && x !== v && takes(x)) ?? null;
1835
+ })(),
1324
1836
  };
1325
1837
  }
1326
1838
 
@@ -1385,35 +1897,767 @@ function baseReads(ctx, like, token) {
1385
1897
  } catch {
1386
1898
  return false;
1387
1899
  }
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);
1900
+ }
1901
+
1902
+ /**
1903
+ * The headings rung nearest a weight number (800 is heavy).
1904
+ * @param {number} weight
1905
+ */
1906
+ const weightRung = weight =>
1907
+ Object.entries(HEADING_WEIGHTS).reduce((a, b) =>
1908
+ Math.abs(Number(b[1]) - weight) < Math.abs(Number(a[1]) - weight) ? b : a,
1909
+ )[0];
1910
+ documentNumericTable(
1911
+ ['headings', 'font-weight'],
1912
+ Object.entries(HEADING_WEIGHTS).map(([w, n]) => [w, Number(n)]),
1913
+ [1, 1000],
1914
+ );
1915
+ // A font weight runs from 1 to 1000.
1916
+ documentRange(['font-weight', '--font-weight-*'], 1, 1000);
1917
+ documentNumericTable(
1918
+ ['spacing'],
1919
+ SPACING.map(([name, factor]) => [name, factor]),
1920
+ );
1921
+ documentNumericTable(
1922
+ ['text-size'],
1923
+ TEXT_SIZE.map(([name, px]) => [name, px]),
1924
+ );
1925
+ // The text size number is the body size in pixels, 10 to 32; vibrancy
1926
+ // runs from 0 to 100.
1927
+ documentRange(['text-size'], 10, 32);
1928
+ documentRange(['vibrancy'], 0, 100);
1929
+ documentReadings(TEXT_SIZE.map(([name, px]) => [name, `${px}px`]));
1930
+ documentReadings(Object.entries(HEADING_TRACKING));
1931
+ // `bold` given a no (false, off) is the normal weight.
1932
+ documentReadings(['false', 'off', 'no', 'none'].map(w => [w, 'normal']));
1933
+ /**
1934
+ * The CSS absolute-size keywords that are no text-size rung, as the px
1935
+ * CSS gives each at a 16px root.
1936
+ */
1937
+ const CSS_SIZE_KEYWORDS = wordTable(
1938
+ /** @type {Record<string, number>} */ ({
1939
+ 'xx-small': 9,
1940
+ 'x-small': 10,
1941
+ 'x-large': 24,
1942
+ 'xx-large': 32,
1943
+ 'xxx-large': 48,
1944
+ }),
1945
+ );
1946
+ documentReadings(
1947
+ Object.entries(CSS_SIZE_KEYWORDS)
1948
+ .filter(([, px]) => px >= 10 && px <= 32)
1949
+ .map(([w, px]) => [w, String(px)]),
1950
+ );
1951
+ // A weight word read as the headings rung its number is nearest.
1952
+ documentReadings(
1953
+ Object.entries(WEIGHT_WORDS).map(([w, n]) => [w, weightRung(Number(n))]),
1954
+ );
1955
+ /** Words for no rounding: corners square. */
1956
+ const NO_ROUNDING = ['0', '0%', 'none', 'sharp', 'zero', 'no', 'flat'];
1957
+ /** Words for no space: spacing's tightest rung. */
1958
+ const NO_SPACE = ['0', 'none', 'zero', 'no', 'off'];
1959
+ documentReadings(NO_ROUNDING.map(w => [w, 'square']));
1960
+ documentReadings(NO_SPACE.map(w => [w, SPACING[0][0]]));
1961
+ documentReadings(
1962
+ Object.values(DIAL_WORDS).flatMap(words => Object.entries(words)),
1963
+ );
1964
+ /** State words a value may be labeled with. */
1965
+ const STATE_WORDS = [
1966
+ 'hover',
1967
+ 'active',
1968
+ 'focus',
1969
+ 'focus-visible',
1970
+ 'focus-within',
1971
+ 'disabled',
1972
+ 'pressed',
1973
+ 'selected',
1974
+ 'checked',
1975
+ 'open',
1976
+ 'expanded',
1977
+ 'visited',
1978
+ ];
1979
+ /** Words for a kind of screen a value may be labeled with. */
1980
+ const DEVICE_WORDS = [
1981
+ 'phone',
1982
+ 'phones',
1983
+ 'mobile',
1984
+ 'tablet',
1985
+ 'tablets',
1986
+ 'desktop',
1987
+ 'laptop',
1988
+ 'ipad',
1989
+ 'iphone',
1990
+ 'android',
1991
+ 'ios',
1992
+ 'touch',
1993
+ 'small-screen',
1994
+ 'small-screens',
1995
+ 'large-screen',
1996
+ 'large-screens',
1997
+ 'print',
1998
+ ];
1999
+
2000
+ /**
2001
+ * The word a value is labeled with and the value after it (`dark: #2563eb`,
2002
+ * `"corners": "pill"`, `{"dark": "#2563eb"}`, `dark=#2563eb`, `dark mode:
2003
+ * #2563eb`, `textSize: 18`), the word as a dashed name; null when the value
2004
+ * holds no label.
2005
+ * @param {string} value
2006
+ * @returns {{word: string, rest: string, when?: string} | null}
2007
+ */
2008
+ function valueLabel(value) {
2009
+ // A flag's label after the value (`red mode: dark`, `red state: hover`,
2010
+ // `red part: card`) reads as the same label before it (`dark: red`); a
2011
+ // variant or size after it (`red variant: primary`) keeps its prop.
2012
+ const trail =
2013
+ /^\s*(.+?)\s+(mode|theme|state|part|on|variant|size|when)\s*[:=]\s*([a-z][a-z0-9:-]*)\s*;?\s*$/i.exec(
2014
+ String(value),
2015
+ );
2016
+ if (trail && !/[:=]/.test(trail[1])) {
2017
+ const flag = trail[2].toLowerCase();
2018
+ const word = trail[3].toLowerCase();
2019
+ if (/^(variant|size|when)$/.test(flag))
2020
+ return {
2021
+ word: 'when',
2022
+ rest: trail[1].trim(),
2023
+ when: flag === 'when' ? word : `${flag}:${word}`,
2024
+ };
2025
+ return {word, rest: trail[1].trim()};
2026
+ }
2027
+ const m =
2028
+ /^\s*\{?\s*["']?([a-zA-Z][a-zA-Z0-9 _-]*?|--[a-z0-9-]+)["']?\s*[:=]\s*(.+?)\s*;?\s*\}?\s*$/.exec(
2029
+ String(value),
2030
+ );
2031
+ if (!m || /^https?$/i.test(m[1])) return null;
2032
+ const word = m[1]
2033
+ .trim()
2034
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
2035
+ .replace(/[\s_]+/g, '-')
2036
+ .toLowerCase();
2037
+ const rest = m[2].trim().replace(/^"(.*)"\s*,?$/, '$1');
2038
+ return {word, rest};
2039
+ }
2040
+
2041
+ /**
2042
+ * Whether a label is the setting's own name (`accent: red` for accent,
2043
+ * `font-family: Inter` for font).
2044
+ * @param {string} thing @param {string} word
2045
+ */
2046
+ const ownLabel = (thing, word) =>
2047
+ word === thing ||
2048
+ (thing === 'font' && word === 'font-family') ||
2049
+ (thing.startsWith('--font-family') &&
2050
+ (word === 'font-family' || word === 'font')) ||
2051
+ (thing === 'text-size' && word === 'font-size');
2052
+
2053
+ /**
2054
+ * Whether a family is one the editor knows: a system family on the theme
2055
+ * build's list, an open font in its table or a preset's family, or one
2056
+ * whose @fontsource package the project has installed.
2057
+ * @param {any} ctx
2058
+ * @param {string} family without quotes
2059
+ */
2060
+ function knownFamily(ctx, family) {
2061
+ const name = family.trim().toLowerCase();
2062
+ if (!name) return false;
2063
+ if (isSystemFamily(family)) return true;
2064
+ if (
2065
+ [
2066
+ ...Object.values(OPEN_FONTS).map(f => f.family),
2067
+ ...Object.values(FONTS).map(f => f[0]),
2068
+ ].some(f => f.toLowerCase() === name)
2069
+ )
2070
+ return true;
2071
+ try {
2072
+ ctx?.project?.req?.resolve(`${fontsourcePackageOf(family)}/package.json`);
2073
+ return Boolean(ctx?.project?.req);
2074
+ } catch {
2075
+ return false;
2076
+ }
2077
+ }
2078
+
2079
+ /**
2080
+ * The one mode a light-only or dark-only theme shows, or null.
2081
+ * @param {{mode?: string} | null | undefined} data
2082
+ * @returns {'light' | 'dark' | null}
2083
+ */
2084
+ function oneModeOfTheme(data) {
2085
+ return data?.mode === 'light-only'
2086
+ ? 'light'
2087
+ : data?.mode === 'dark-only'
2088
+ ? 'dark'
2089
+ : null;
2090
+ }
2091
+
2092
+ /**
2093
+ * The states `set` takes on a part: the ones its doc lists and the ones
2094
+ * every part takes, less any a change in it is refused for while the same
2095
+ * change without it passes (a state that never applies there). `how` lists
2096
+ * these, and a state that is not one names them.
2097
+ * @param {import('./_settings.mjs').Ctx} ctx
2098
+ * @param {string} slug
2099
+ * @param {any} data
2100
+ * @param {string} part
2101
+ * @returns {string[]}
2102
+ */
2103
+ export function settableStates(ctx, slug, data, part) {
2104
+ const t = ctx.project.target.get(part);
2105
+ if (!t) return [];
2106
+ const takes = (/** @type {string | undefined} */ state) => {
2107
+ try {
2108
+ checkSetting(ctx, slug, data, 'opacity', '1', {
2109
+ on: part,
2110
+ ...(state ? {state} : {}),
2111
+ });
2112
+ return true;
2113
+ } catch {
2114
+ return false;
2115
+ }
2116
+ };
2117
+ const plain = takes(undefined);
2118
+ return [...new Set([...t.states, ...COMMON_STATES])].filter(
2119
+ state => !plain || takes(state),
2120
+ );
2121
+ }
2122
+
2123
+ /**
2124
+ * Check one setting and give it back ready to store, or refuse. What it
2125
+ * accepts, the settings loader takes too: the loader's own check runs last,
2126
+ * so a saved setting never blocks the theme.
2127
+ * @param {import('./_settings.mjs').Ctx} ctx
2128
+ * @param {string} slug
2129
+ * @param {import('./_settings.mjs').ThemeData} data
2130
+ * @param {string} thing
2131
+ * @param {string | undefined} value
2132
+ * @param {SetFlags} flags
2133
+ * @param {boolean} [unset] an undo of one setting: only the identity of the setting is checked
2134
+ * @returns {import('./_settings.mjs').Setting}
2135
+ */
2136
+ export function checkSetting(
2137
+ ctx,
2138
+ slug,
2139
+ data,
2140
+ thing,
2141
+ value,
2142
+ flags,
2143
+ unset = false,
2144
+ ) {
2145
+ // Any other dial's value pasted with its property name (`font-size:
2146
+ // 18px;` for text-size, `color: #e11d48` for accent) is the value: one
2147
+ // path for every dial (the font dial reads its own below).
2148
+ // A light and a dark color typed as one value: a token takes both as
2149
+ // light-dark() or one --mode at a time; a color dial takes one color and
2150
+ // makes both modes from it. Never one of them for both.
2151
+ // A light-dark() written with another separator (`light-dark(red /
2152
+ // blue)`, `light-dark(red; blue)`): the pair meant, with a comma.
2153
+ // A dial's own words in any case (ROOMY, MORE, Both, NONE): the word.
2154
+ if (!unset && typeof value === 'string' && DIALS[thing]) {
2155
+ const words = new Set(
2156
+ String(DIALS[thing].values ?? '')
2157
+ .split('|')
2158
+ .filter(w => /^[a-z][a-z-]*$/.test(w)),
2159
+ );
2160
+ const lower = value.trim().toLowerCase();
2161
+ // (On the font dial several words are a family list, whose names keep
2162
+ // their letters; one word is the preset.)
2163
+ const read = thing === 'font' ? [lower] : lower.split(/\s+/);
2164
+ if (lower && read.every(w => words.has(w))) value = lower;
2165
+ }
2166
+ if (!unset && typeof value === 'string') {
2167
+ const near =
2168
+ /^\s*light-dark\(\s*([^,;/()]+?)\s*(?:\s\/\s|\/|;)\s*([^,;/()]+?)\s*\)\s*$/i.exec(
2169
+ value,
2170
+ );
2171
+ if (near)
2172
+ refuse(
2173
+ E.ERR_THEME_BAD_VALUE,
2174
+ `"${value}" separates its two colors with something other than a comma; light-dark() takes "light-dark(light, dark)".`,
2175
+ {
2176
+ run: [
2177
+ setLine(
2178
+ slug,
2179
+ thing,
2180
+ `light-dark(${near[1]}, ${near[2]})`,
2181
+ {...flags, mode: undefined},
2182
+ false,
2183
+ ),
2184
+ ],
2185
+ },
2186
+ );
2187
+ }
2188
+ // A weight (or a style) after a family (`Inter 600`, `Inter bold
2189
+ // italic`) is no family name: the family alone, and the weight where a
2190
+ // weight is set.
2191
+ const familyWeight =
2192
+ !unset &&
2193
+ typeof value === 'string' &&
2194
+ (thing === 'font' ||
2195
+ thing === 'font-family' ||
2196
+ thing.startsWith('--font-family'))
2197
+ ? /^\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(
2198
+ value,
2199
+ )
2200
+ : null;
2201
+ // A weight word after a family is part of the family's name (Arial
2202
+ // Black, Archivo Black, Segoe UI Semibold) unless the whole name is no
2203
+ // family the editor knows and the name without it is; a weight number
2204
+ // (`Inter 600`) is never part of a name.
2205
+ const weightIsName =
2206
+ familyWeight != null &&
2207
+ !/^\d+$/.test(familyWeight[2]) &&
2208
+ !(
2209
+ !knownFamily(ctx, `${familyWeight[1].trim()} ${familyWeight[2]}`) &&
2210
+ knownFamily(ctx, familyWeight[1].trim())
2211
+ );
2212
+ if (
2213
+ familyWeight &&
2214
+ !weightIsName &&
2215
+ typeof value === 'string' &&
2216
+ !value.includes(',') &&
2217
+ // `bold bold` is a weight twice and `italic bold` a style and a
2218
+ // weight, read below: no family is named.
2219
+ familyWeight[1]
2220
+ .trim()
2221
+ .toLowerCase()
2222
+ .split(/\s+/)
2223
+ .some(
2224
+ w =>
2225
+ HEADING_WEIGHTS[w] === undefined &&
2226
+ WEIGHT_WORDS[w] === undefined &&
2227
+ !/^(italic|oblique|normal|small-caps)$/.test(w),
2228
+ )
2229
+ ) {
2230
+ const family = familyWeight[1].trim();
2231
+ const w = familyWeight[2].toLowerCase().replace('-', '');
2232
+ // The headings rung nearest the weight, in any form the weight table
2233
+ // reads (ExtraBold is heavy, 900 is heavy).
2234
+ const number = /^\d+$/.test(w)
2235
+ ? Number(w)
2236
+ : HEADING_WEIGHTS[w] !== undefined
2237
+ ? Number(HEADING_WEIGHTS[w])
2238
+ : WEIGHT_WORDS[w] !== undefined
2239
+ ? Number(WEIGHT_WORDS[w])
2240
+ : null;
2241
+ const word = number != null ? weightRung(number) : null;
2242
+ refuse(
2243
+ E.ERR_THEME_BAD_VALUE,
2244
+ `"${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.`,
2245
+ {
2246
+ run: [
2247
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(family)}${flags.on ? ` --on ${flags.on}` : ''}`,
2248
+ ...(thing === 'font' && word
2249
+ ? [`${P} set ${slug} headings ${word}`]
2250
+ : []),
2251
+ ],
2252
+ },
2253
+ );
2254
+ }
2255
+ // A number or size given as a font family (`--font-family-body 700`,
2256
+ // `font-family 16px --on card`) is a weight or a size, never a family.
2257
+ if (
2258
+ !unset &&
2259
+ typeof value === 'string' &&
2260
+ (thing === 'font-family' || thing.startsWith('--font-family')) &&
2261
+ NUMBERISH.test(value.trim())
2262
+ )
2263
+ refuse(
2264
+ E.ERR_THEME_BAD_VALUE,
2265
+ `"${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.'}`,
2266
+ {run: [`${HOW} ${quoteCommandArgument(thing)}`]},
2267
+ );
2268
+ // A font list with a comma missing before its generic family, or a
2269
+ // generic written with a space, on the font dial: the list meant.
2270
+ if (!unset && typeof value === 'string' && thing === 'font') {
2271
+ const fixed = fontListMeant(value);
2272
+ if (fixed)
2273
+ refuse(
2274
+ E.ERR_THEME_BAD_VALUE,
2275
+ `"${value}" names a family that exists nowhere: ${fixed.why}.`,
2276
+ {run: [setLine(slug, 'font', fixed.value, flags, false)]},
2277
+ );
2278
+ }
2279
+ // A light and a dark color on a part's color property (`background`,
2280
+ // `color`, `border-color` …) is that property's light-dark() pair.
2281
+ if (
2282
+ !unset &&
2283
+ typeof value === 'string' &&
2284
+ flags.on &&
2285
+ !flags.mode &&
2286
+ /^(color|background|(background|border|outline|text-decoration|caret|accent|fill|stroke)(-[a-z]+)?-color)$/.test(
2287
+ String(thing).trim().toLowerCase(),
2288
+ )
2289
+ ) {
2290
+ const pair = colorPair(value);
2291
+ if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
2292
+ // A theme with one mode shows one half: that half is the line, as
2293
+ // for a color token.
2294
+ const only = oneModeOfTheme(data);
2295
+ if (only)
2296
+ refuse(
2297
+ E.ERR_THEME_BAD_VALUE,
2298
+ `"${value}" is a light and a dark color; this theme is ${only} only, so it shows the ${only} one.`,
2299
+ {
2300
+ run: [
2301
+ setLine(slug, thing, pair[only], {...flags, mode: undefined}),
2302
+ ],
2303
+ },
2304
+ );
2305
+ value = `light-dark(${pair.light}, ${pair.dark})`;
2306
+ }
2307
+ }
2308
+ if (
2309
+ !unset &&
2310
+ typeof value === 'string' &&
2311
+ (PALETTE_DIALS.includes(thing) || isColorToken(thing))
2312
+ ) {
2313
+ const pair = colorPair(value);
2314
+ if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark)) {
2315
+ const q = quoteCommandArgument;
2316
+ const on = flags.on ? ` --on ${flags.on}` : '';
2317
+ // A theme with one mode shows one half: that half is the line.
2318
+ const only = oneModeOfTheme(data);
2319
+ if (only)
2320
+ refuse(
2321
+ E.ERR_THEME_BAD_VALUE,
2322
+ `"${value}" is a light and a dark color; this theme is ${only} only, so it shows the ${only} one.`,
2323
+ {run: [`${P} set ${slug} ${thing} ${q(pair[only])}${on}`]},
2324
+ );
2325
+ refuse(
2326
+ E.ERR_THEME_BAD_VALUE,
2327
+ PALETTE_DIALS.includes(thing)
2328
+ ? `"${value}" is a light and a dark color; ${thing} takes one color and makes both modes from it.`
2329
+ : `"${value}" is a light and a dark color; ${thing} takes them as light-dark(), or one --mode at a time.`,
2330
+ {
2331
+ run: PALETTE_DIALS.includes(thing)
2332
+ ? [
2333
+ `${P} set ${slug} ${thing} ${q(pair.light)}${on}`,
2334
+ ...(thing === 'accent'
2335
+ ? [
2336
+ `${P} set ${slug} --color-accent ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
2337
+ ]
2338
+ : []),
2339
+ ]
2340
+ : [
2341
+ `${P} set ${slug} ${thing} ${q(`light-dark(${pair.light}, ${pair.dark})`)}${on}`,
2342
+ `${P} set ${slug} ${thing} ${q(pair.light)}${on} --mode light`,
2343
+ `${P} set ${slug} ${thing} ${q(pair.dark)}${on} --mode dark`,
2344
+ ],
2345
+ },
2346
+ );
2347
+ }
2348
+ }
2349
+ // A value labeled with a word that is not this setting's own name (a
2350
+ // mode, a state, a device, a part, or a word the editor does not read) is
2351
+ // refused with what that word means here, never set with the word dropped.
2352
+ // A property set on a part (`padding 'hover: 4px' --on button`) and the
2353
+ // type tokens (`--font-weight-bold 'dark: 700'`) are read the same way;
2354
+ // a content string is its own text.
2355
+ const partProperty =
2356
+ Boolean(flags.on) && !DIALS[thing] && !thing.startsWith('--');
2357
+ const familyToken = thing.startsWith('--font-family');
2358
+ if (
2359
+ !unset &&
2360
+ typeof value === 'string' &&
2361
+ !/content/.test(thing) &&
2362
+ (DIALS[thing] || partProperty || thing.startsWith('--'))
2363
+ ) {
2364
+ const label = valueLabel(value);
2365
+ // Another CSS property's name before a part property's value
2366
+ // (`padding 'margin: 8px'`) is that property's value, never this one's.
2367
+ if (
2368
+ label &&
2369
+ partProperty &&
2370
+ label.word !== thing &&
2371
+ !ownLabel(thing, label.word) &&
2372
+ cssProperties().has(label.word) &&
2373
+ label.rest.trim()
2374
+ )
2375
+ refuse(
2376
+ E.ERR_THEME_BAD_VALUE,
2377
+ `"${value}" is labeled ${label.word}, another property than ${thing}; nothing is set from it.`,
2378
+ {
2379
+ didYouMean: [label.word],
2380
+ run: [setLine(slug, label.word, label.rest.trim(), flags, false)],
2381
+ },
2382
+ );
2383
+ // A CSS property's name before the value (`border-radius: pill`,
2384
+ // `color: #e11d48`, `font: bold 16px Inter`) is read by the paths
2385
+ // below, as a declaration pasted from a stylesheet.
2386
+ if (
2387
+ label &&
2388
+ !ownLabel(thing, label.word) &&
2389
+ !cssProperties().has(label.word)
2390
+ ) {
2391
+ const q = quoteCommandArgument;
2392
+ const rest = label.rest;
2393
+ const scope = `${flags.on ? ` --on ${flags.on}` : ''}${flags.when ? ` --when ${flags.when}` : ''}`;
2394
+ // A variant named after the value: the value with --when.
2395
+ if ('when' in label && label.when)
2396
+ refuse(
2397
+ E.ERR_THEME_BAD_VALUE,
2398
+ `"${value}" names a variant after the value; a value for one variant is given with --on <part> --when ${label.when}.`,
2399
+ {
2400
+ didYouMean: ['--when'],
2401
+ run: [
2402
+ flags.on
2403
+ ? `${P} set ${slug} ${thing} ${q(rest)} --on ${flags.on} --when ${label.when}`
2404
+ : `${HOW} ${q(`${label.when.split(':').pop()} ${thing}`)}`,
2405
+ ],
2406
+ },
2407
+ );
2408
+ const mode = MODE_WORDS[label.word];
2409
+ const colorful =
2410
+ PALETTE_DIALS.includes(thing) ||
2411
+ (thing.startsWith('--') && isColorToken(thing)) ||
2412
+ (partProperty &&
2413
+ /color|^background$|^fill$|^stroke$|shadow/.test(thing));
2414
+ const parts = [...ctx.project.target.keys(), ...Object.keys(FAMILIES)];
2415
+ // A theme with one mode: its own mode's label is the value, as the
2416
+ // theme has no other; the other mode's label names a mode it lacks.
2417
+ const only = oneModeOfTheme(data);
2418
+ if (mode && only) {
2419
+ if (mode === only)
2420
+ return checkSetting(ctx, slug, data, thing, rest, flags, unset);
2421
+ refuse(
2422
+ E.ERR_THEME_BAD_VALUE,
2423
+ `"${label.word}" in "${value}" names the ${mode} mode, which this ${only}-only theme does not show.`,
2424
+ {
2425
+ run: [
2426
+ `${P} set ${slug} mode both`,
2427
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}`,
2428
+ ],
2429
+ },
2430
+ );
2431
+ }
2432
+ if (mode && DIALS[thing] && PALETTE_DIALS.includes(thing))
2433
+ refuse(
2434
+ E.ERR_THEME_BAD_VALUE,
2435
+ `"${label.word}" in "${value}" names the ${mode} mode; ${thing} makes both modes from one color.`,
2436
+ {
2437
+ run: [
2438
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}`,
2439
+ ...(thing === 'accent'
2440
+ ? [
2441
+ `${P} set ${slug} --color-accent ${q(rest)}${scope} --mode ${mode}`,
2442
+ ]
2443
+ : []),
2444
+ ],
2445
+ },
2446
+ );
2447
+ const level = /^h([1-6])$/.exec(label.word)?.[1];
2448
+ if (level && thing === 'headings') {
2449
+ const w = rest.trim().toLowerCase();
2450
+ refuse(
2451
+ E.ERR_THEME_BAD_VALUE,
2452
+ `"${label.word}" in "${value}" is one heading level; headings sets every level, and one level is set with --on heading --when level:${level}.`,
2453
+ {
2454
+ run:
2455
+ HEADING_WEIGHTS[w] !== undefined
2456
+ ? [
2457
+ `${P} set ${slug} font-weight ${HEADING_WEIGHTS[w]} --on heading --when level:${level}`,
2458
+ `${P} set ${slug} headings ${w}`,
2459
+ ]
2460
+ : HEADING_TRACKING[w] !== undefined
2461
+ ? [
2462
+ `${P} set ${slug} letter-spacing ${q(HEADING_TRACKING[w])} --on heading --when level:${level}`,
2463
+ `${P} set ${slug} headings ${w}`,
2464
+ ]
2465
+ : [`${HOW} headings`],
2466
+ },
2467
+ );
2468
+ }
2469
+ if (mode)
2470
+ refuse(
2471
+ E.ERR_THEME_BAD_VALUE,
2472
+ colorful
2473
+ ? `"${label.word}" in "${value}" names the ${mode} mode; a value for one mode is given with --mode ${mode}.`
2474
+ : `"${label.word}" in "${value}" names the ${mode} mode, and ${thing} is the same in light and dark.`,
2475
+ {
2476
+ run: [
2477
+ `${P} set ${slug} ${thing} ${q(rest)}${scope}${colorful ? ` --mode ${mode}` : ''}`,
2478
+ ],
2479
+ },
2480
+ );
2481
+ if (STATE_WORDS.includes(label.word))
2482
+ refuse(
2483
+ E.ERR_THEME_BAD_VALUE,
2484
+ flags.on
2485
+ ? `"${label.word}" in "${value}" is a state; a value for it is given with --state ${label.word}.`
2486
+ : `"${label.word}" in "${value}" is a state; a state is set on a part, with --on <part> --state ${label.word}.`,
2487
+ {
2488
+ run: [
2489
+ flags.on
2490
+ ? `${P} set ${slug} ${thing} ${q(rest)}${scope} --state ${label.word}`
2491
+ : `${HOW} ${q(`${label.word} ${thing}`)}`,
2492
+ ],
2493
+ },
2494
+ );
2495
+ if (DEVICE_WORDS.includes(label.word))
2496
+ refuse(
2497
+ E.ERR_THEME_BAD_VALUE,
2498
+ `"${label.word}" in "${value}" names a kind of screen; the editor sets ${thing} for every screen, not for one kind.`,
2499
+ {run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`]},
2500
+ );
2501
+ // `on button: pill`: the part named after `on`.
2502
+ const onPart = /^on-([a-z][a-z0-9-]*)$/.exec(label.word)?.[1];
2503
+ if (onPart && parts.includes(onPart))
2504
+ refuse(
2505
+ E.ERR_THEME_BAD_VALUE,
2506
+ `"${value}" names the part ${onPart}; a value for one part is given with --on ${onPart}.`,
2507
+ {run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${onPart}`]},
2508
+ );
2509
+ if (parts.includes(label.word))
2510
+ refuse(
2511
+ E.ERR_THEME_BAD_VALUE,
2512
+ `"${label.word}" in "${value}" is a part; a value for one part is given with --on ${label.word}.`,
2513
+ {run: [`${P} set ${slug} ${thing} ${q(rest)} --on ${label.word}`]},
2514
+ );
2515
+ // A flag's own name as the label (`state: hover`, `part: card`,
2516
+ // `variant: primary`, `mode: dark`): what that flag does here.
2517
+ const flagWord = {
2518
+ state: 'state',
2519
+ states: 'state',
2520
+ part: 'on',
2521
+ on: 'on',
2522
+ component: 'on',
2523
+ variant: 'when',
2524
+ size: 'when',
2525
+ when: 'when',
2526
+ prop: 'when',
2527
+ mode: 'mode',
2528
+ theme: 'mode',
2529
+ }[label.word];
2530
+ if (
2531
+ flagWord &&
2532
+ (flagWord === 'mode'
2533
+ ? Boolean(MODE_WORDS[rest.trim().toLowerCase()])
2534
+ : !otherSettingLabel(thing, value))
2535
+ ) {
2536
+ const r = rest.trim().toLowerCase();
2537
+ // The flag's value and the setting's value in one (`state=hover
2538
+ // 4px`): the first word is the flag's, the rest the value.
2539
+ const [fv, ...more] = rest.trim().split(/\s+/);
2540
+ if (flagWord !== 'mode' && more.length > 0) {
2541
+ const flagged =
2542
+ flagWord === 'on'
2543
+ ? ` --on ${fv}${flags.when ? ` --when ${flags.when}` : ''}`
2544
+ : flags.on
2545
+ ? `${scope} --${flagWord} ${flagWord === 'when' && label.word !== 'when' && label.word !== 'prop' ? `${label.word}:${fv}` : fv}`
2546
+ : null;
2547
+ refuse(
2548
+ E.ERR_THEME_BAD_VALUE,
2549
+ `"${value}" holds the ${flagWord} ${fv} and the value ${more.join(' ')}; the ${flagWord} is given with --${flagWord}.`,
2550
+ {
2551
+ didYouMean: [`--${flagWord}`],
2552
+ run: [
2553
+ flagged
2554
+ ? `${P} set ${slug} ${thing} ${q(more.join(' '))}${flagged}`
2555
+ : `${HOW} ${q(`${fv} ${thing}`)}`,
2556
+ ],
2557
+ },
2558
+ );
2559
+ }
2560
+ const m = flagWord === 'mode' ? MODE_WORDS[r] : null;
2561
+ const when =
2562
+ flagWord === 'when'
2563
+ ? label.word === 'when' || label.word === 'prop'
2564
+ ? r
2565
+ : `${label.word}:${r}`
2566
+ : null;
2567
+ refuse(
2568
+ E.ERR_THEME_BAD_VALUE,
2569
+ flagWord === 'mode'
2570
+ ? `"${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\``}.`
2571
+ : flagWord === 'state'
2572
+ ? `"${value}" names a state, not a value for ${thing}: a value for a state is given with --on <part> --state ${r}.`
2573
+ : flagWord === 'on'
2574
+ ? `"${value}" names a part, not a value for ${thing}: a value for one part is given with --on ${r}.`
2575
+ : `"${value}" names a variant, not a value for ${thing}: a value for one variant is given with --on <part> --when ${when}.`,
2576
+ {
2577
+ didYouMean: [`--${flagWord}`],
2578
+ run: [
2579
+ flagWord === 'mode' && !colorful
2580
+ ? `${P} set ${slug} mode ${m ?? 'dark'}-only`
2581
+ : `${HOW} ${q(`${r} ${thing}`)}`,
2582
+ ],
2583
+ },
2584
+ );
2585
+ }
2586
+ // A Google Fonts family spec (`Inter:wght@400;600`): the family
2587
+ // before the colon.
2588
+ if (
2589
+ (thing === 'font' || familyToken || thing === 'font-family') &&
2590
+ /^(ital,)?wght@|^ital@/i.test(rest)
2591
+ ) {
2592
+ const family = String(value).split(':')[0].replace(/\+/g, ' ').trim();
2593
+ refuse(
2594
+ E.ERR_THEME_BAD_VALUE,
2595
+ `"${value}" is a Google Fonts family spec; ${thing} takes the family (${family}). A weight is set with font-weight or a --font-weight-* token.`,
2596
+ {run: [`${P} set ${slug} ${thing} ${q(family)}${scope}`]},
2597
+ );
2598
+ }
2599
+ // A family's own words may hold a colon; only the words above are
2600
+ // read there.
2601
+ if (!familyToken && !otherSettingLabel(thing, value))
2602
+ refuse(
2603
+ E.ERR_THEME_BAD_VALUE,
2604
+ `"${label.word}" in "${value}" is not a name the editor reads for ${thing}; give the value alone.`,
2605
+ {
2606
+ // Only setting names: a part or a state is never a value.
2607
+ didYouMean: nearest(label.word, Object.keys(DIALS)),
2608
+ run: [`${P} set ${slug} ${thing} ${q(rest)}${scope}`],
2609
+ },
2610
+ );
2611
+ }
2612
+ // The setting's own name before its value (`font: Inter`, `Font:
2613
+ // Georgia`) is the value.
2614
+ // (A `font:` shorthand is read whole below, as its family.)
2615
+ if (
2616
+ label &&
2617
+ ownLabel(thing, label.word) &&
2618
+ // A `font:` with a size is the shorthand, read whole below; with
2619
+ // only families (`font: Inter, serif`) it is the label.
2620
+ (label.word !== 'font' || !/\d/.test(label.rest)) &&
2621
+ label.rest.replace(/;+\s*$/, '').trim()
2622
+ )
2623
+ value = label.rest;
2624
+ }
2625
+ if (
2626
+ !unset &&
2627
+ typeof value === 'string' &&
2628
+ (DIALS[thing] || partProperty || thing.startsWith('--')) &&
2629
+ !/content/.test(thing)
2630
+ ) {
2631
+ // A value labeled with another setting's name is that setting's, never
2632
+ // this one's (`accent 'neutral: #64748b'`, `--radius-element 'accent:
2633
+ // red'`). The value goes to this setting again only for a dial that
2634
+ // checks it as its own (any word is a font family, so never the font).
2635
+ const other = otherSettingLabel(thing, value);
2636
+ if (other)
2637
+ refuse(
2638
+ E.ERR_THEME_BAD_VALUE,
2639
+ `"${value}" is labeled ${other.thing}, another setting than ${thing}; nothing is set from it.`,
2640
+ {
2641
+ didYouMean: [other.thing],
2642
+ run: [
2643
+ `${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
2644
+ // Another setting is not this part's property: the whole theme.
2645
+ ...(flags.on && partProperty
2646
+ ? [
2647
+ `${P} set ${slug} ${other.thing} ${quoteCommandArgument(other.value)}`,
2648
+ ]
2649
+ : []),
2650
+ ...(DIALS[thing] && thing !== 'font'
2651
+ ? [
2652
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(other.value)}${flags.on ? ` --on ${flags.on}` : ''}`,
2653
+ ]
2654
+ : []),
2655
+ ],
2656
+ },
2657
+ );
2658
+ }
2659
+ if (!unset && typeof value === 'string' && DIALS[thing]) {
2660
+ const d = thing === 'font' ? null : pastedDeclaration(value);
1417
2661
  if (d?.value) value = d.value;
1418
2662
  }
1419
2663
  // The font dial's value as pasted from a stylesheet (`Georgia, serif;`,
@@ -1485,8 +2729,8 @@ export function checkSetting(
1485
2729
  function fallbackVarTypo(v, TOKENS) {
1486
2730
  for (const [, name] of v.matchAll(/var\(\s*(--[a-z0-9-]+)\s*,/gi)) {
1487
2731
  if (name in TOKENS || name.startsWith('--_')) continue;
1488
- const near = nearest(name, Object.keys(TOKENS)).filter(
1489
- n => levenshteinDistance(n, name) <= 2,
2732
+ const near = nearest(name, Object.keys(TOKENS)).filter(n =>
2733
+ typoNear(name, n),
1490
2734
  );
1491
2735
  if (near.length)
1492
2736
  return `${name} is not a design token, so its fallback always shows; did you mean ${near[0]}?`;
@@ -1628,23 +2872,97 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1628
2872
  .toLowerCase();
1629
2873
  if (flags.only) s.only = true;
1630
2874
  if (flags.mode) {
1631
- const mode = flags.mode.toLowerCase();
1632
- if (mode !== 'light' && mode !== 'dark')
2875
+ // Read as any value is: invisible or no-break spaces, quotes around
2876
+ // it, a trailing colon (`'dark '`, `“dark”`, `dark:`).
2877
+ const mode = withoutDebris(normalValueText(String(flags.mode)))
2878
+ .trim()
2879
+ .replace(/^(["'])(.*)\1$/, '$2')
2880
+ .replace(/:+$/, '')
2881
+ .trim()
2882
+ .toLowerCase();
2883
+ if (mode !== 'light' && mode !== 'dark') {
2884
+ // A word for one of the two (night, day) is that one; never the
2885
+ // nearest spelling, which can be the other (night → light).
2886
+ const meant = {
2887
+ night: 'dark',
2888
+ nighttime: 'dark',
2889
+ dim: 'dark',
2890
+ black: 'dark',
2891
+ day: 'light',
2892
+ daytime: 'light',
2893
+ bright: 'light',
2894
+ white: 'light',
2895
+ }[mode];
2896
+ const near = meant ? [meant] : nearest(mode, ['light', 'dark']);
2897
+ // The line for that one mode: for a dial, the one `--mode dark` itself
2898
+ // offers (the color token for that mode), never the both-modes dial.
2899
+ const modeLine = (/** @type {string} */ m) => {
2900
+ if (DIALS[thing] && !unset)
2901
+ try {
2902
+ checkSetting(ctx, slug, data, thing, v, {...flags, mode: m});
2903
+ } catch (e) {
2904
+ const first = /** @type {any} */ (e)?.suggestions?.find(
2905
+ (/** @type {any} */ x) => / --mode (light|dark)\b/.test(x.name),
2906
+ );
2907
+ if (first) return first.name;
2908
+ }
2909
+ return setLine(slug, thing, v, {...s, mode: m}, unset);
2910
+ };
1633
2911
  refuse(
1634
2912
  E.ERR_THEME_BAD_VALUE,
1635
2913
  `--mode takes light or dark, not "${flags.mode}".`,
1636
2914
  {
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)],
2915
+ didYouMean: near,
2916
+ // The mode it is nearest keeps --mode; only with none near is the
2917
+ // same setting for both modes offered.
2918
+ run: [
2919
+ ...(near.length === 1 ? [modeLine(near[0])] : []),
2920
+ // A word that means one mode (night) keeps it: the both-modes
2921
+ // line only for a word read by spelling.
2922
+ ...(meant
2923
+ ? []
2924
+ : [setLine(slug, thing, v, {...s, mode: undefined}, unset)]),
2925
+ ],
1641
2926
  },
1642
2927
  );
2928
+ }
1643
2929
  s.mode = mode;
1644
2930
  }
1645
2931
  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 ?? ''))
2932
+ // A CSS-wide keyword is no color for one mode: a mode's half takes a
2933
+ // color, and the keyword applies to the whole declaration, in both modes.
2934
+ if (
2935
+ s.mode &&
2936
+ !unset &&
2937
+ CSS_WIDE.includes(
2938
+ String(v ?? '')
2939
+ .trim()
2940
+ .toLowerCase(),
2941
+ )
2942
+ )
2943
+ // A token takes no keyword in any mode (it would be left empty), so for
2944
+ // a token only the color is offered.
2945
+ refuse(
2946
+ E.ERR_THEME_NO_MODE,
2947
+ String(thing).startsWith('--')
2948
+ ? `"${String(v).trim()}" is a CSS keyword, which applies in both modes, so it takes no --mode; and a token never takes one. Give the ${s.mode} color.`
2949
+ : `"${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.`,
2950
+ {
2951
+ run: [
2952
+ String(thing).startsWith('--')
2953
+ ? `${HOW} ${thing}`
2954
+ : `${P} set ${slug} ${thing} ${String(v).trim()}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
2955
+ ],
2956
+ },
2957
+ );
2958
+ // A value that already gives both modes takes no --mode (a gradient
2959
+ // holding a light-dark() stop included).
2960
+ if (
2961
+ s.mode &&
2962
+ !unset &&
2963
+ (/^\s*light-dark\(/i.test(v ?? '') ||
2964
+ (/gradient\(/i.test(v ?? '') && /light-dark\(/i.test(v ?? '')))
2965
+ )
1648
2966
  refuse(
1649
2967
  E.ERR_THEME_NO_MODE,
1650
2968
  `"${v}" already gives both modes, so it takes no --mode; drop --mode, or give the ${s.mode} color alone.`,
@@ -1655,17 +2973,52 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1655
2973
  },
1656
2974
  );
1657
2975
  // A setting saved for a mode the theme no longer has can still be removed.
1658
- if (s.mode && data.mode !== 'both' && !unset)
2976
+ // An entry saved for the one mode the theme has ("[dark only]" in a
2977
+ // dark-only theme) can be set again with that --mode, so a doubled one
2978
+ // can be kept: that set replaces both.
2979
+ const sameModeEntry =
2980
+ s.mode &&
2981
+ data.mode === `${s.mode}-only` &&
2982
+ (Array.isArray(data.settings) ? data.settings : []).some(
2983
+ (/** @type {any} */ x) =>
2984
+ x &&
2985
+ x.thing === thing &&
2986
+ x.mode === s.mode &&
2987
+ (x.on ?? null) === (s.on ?? null) &&
2988
+ (x.when ?? null) === (s.when ?? null) &&
2989
+ (x.state ?? null) === (s.state ?? null),
2990
+ );
2991
+ if (s.mode && data.mode !== 'both' && !unset && !sameModeEntry) {
2992
+ // What takes no --mode in any theme (a size, a font, a keyword) is
2993
+ // refused for that, with the command that drops --mode: a theme with
2994
+ // both modes would refuse it too, so its mode is no way out.
2995
+ try {
2996
+ checkSetting(ctx, slug, {...data, mode: 'both'}, thing, v, flags);
2997
+ } catch (e) {
2998
+ if (/** @type {any} */ (e)?.code === E.ERR_THEME_NO_MODE) throw e;
2999
+ }
1659
3000
  refuse(
1660
3001
  E.ERR_THEME_NO_MODE,
1661
3002
  `This theme is ${data.mode}; --mode is for themes with both modes.`,
1662
- {run: [`${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}`]},
3003
+ {
3004
+ run: [
3005
+ // For the mode the theme does not show, both modes first; the
3006
+ // same setting for the theme's own mode keeps where it applies.
3007
+ ...((data.mode === 'light-only' ? 'light' : 'dark') !== s.mode
3008
+ ? [`${P} set ${slug} mode both`]
3009
+ : []),
3010
+ `${P} set ${slug} ${thing} ${quoteCommandArgument(v)}${onFlag}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
3011
+ ],
3012
+ },
1663
3013
  );
3014
+ }
1664
3015
  if ((s.when || s.state) && !s.on)
1665
3016
  refuse(E.ERR_MISSING_ARGUMENT, '--when and --state need --on <part>.', {
1666
3017
  run: [`${HOW} --list parts`],
1667
3018
  });
1668
- if (s.only) {
3019
+ // --only is checked on a part this Core has; a part in other letters or
3020
+ // misspelt gets the part's own refusal first, with --only kept.
3021
+ if (s.only && (!s.on || TARGET.has(s.on) || FAMILIES[s.on])) {
1669
3022
  const fam = s.on ? familyOf(s.on) : null;
1670
3023
  if (!fam || FAMILIES[/** @type {string} */ (s.on)])
1671
3024
  refuse(
@@ -1693,29 +3046,91 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1693
3046
  // Another case of a part or group, its class name copied from the
1694
3047
  // page (`.astryx-card`), or its component (`<Card>`, `Card`): that
1695
3048
  // part, as a working command with every flag kept.
3049
+ // Stray punctuation from a copied list ("text-input,") and the dashes
3050
+ // autocorrect types ("text\u2013input") are not part of the name.
1696
3051
  const lower = s.on
3052
+ .replace(/[\u2010-\u2015\u2212]/g, '-')
3053
+ .replace(/^[\s,;:.'"`]+|[\s,;:.'"`]+$/g, '')
1697
3054
  .trim()
1698
3055
  .replace(/^<\/?\s*|\s*\/?>$/g, '')
1699
3056
  .replace(/^\./, '')
1700
3057
  .replace(/^astryx-/, '')
1701
3058
  .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
1702
3059
  .toLowerCase();
3060
+ // A part named in words (dialog header, text inputs) is the dashed
3061
+ // part, read before any group a single word of it names.
3062
+ const dashed = lower.trim().replace(/[\s_]+/g, '-');
1703
3063
  // A plain word how reads as a part or group (checkboxes: checks).
1704
3064
  const byWord = partForWord(lower);
1705
3065
  // 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]));
3066
+ const singular = [lower, dashed]
3067
+ .flatMap(w => [
3068
+ w.replace(/ies$/, 'y'),
3069
+ w.replace(/(ch|sh|x|s)es$/, '$1'),
3070
+ w.replace(/s$/, ''),
3071
+ ])
3072
+ .find(x => x !== lower && (TARGET.has(x) || FAMILIES[x]));
3073
+ // Several parts named in one --on (`button, text-input`, `button/
3074
+ // text-input`, `button and text-input`, or spaces): one command per
3075
+ // part named, each checked, never a group that one word of the list
3076
+ // happens to name.
3077
+ const listed = /,|\/|&|\band\b/.test(lower);
3078
+ // (Words with only spaces that name one part, `text inputs`, are
3079
+ // that part.)
3080
+ if (!(TARGET.has(dashed) || FAMILIES[dashed]) && (listed || !singular)) {
3081
+ const pieces = lower
3082
+ .split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
3083
+ .map(x => x.trim())
3084
+ .filter(Boolean);
3085
+ const partOf = (/** @type {string} */ w) =>
3086
+ TARGET.has(w) || FAMILIES[w]
3087
+ ? w
3088
+ : ([w.replace(/ies$/, 'y'), w.replace(/s$/, '')].find(
3089
+ x => x !== w && (TARGET.has(x) || FAMILIES[x]),
3090
+ ) ?? null);
3091
+ const found = pieces.map(partOf);
3092
+ const parts = [...new Set(found.filter(x => x != null))];
3093
+ const missing = pieces.filter((_, i) => found[i] == null);
3094
+ if (
3095
+ pieces.length > 1 &&
3096
+ parts.length > 0 &&
3097
+ (missing.length === 0 || (listed && parts.length > 1))
3098
+ )
3099
+ refuse(
3100
+ E.ERR_THEME_UNKNOWN_PART,
3101
+ `"${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)` : ''}.`,
3102
+ {
3103
+ didYouMean: parts,
3104
+ run: parts
3105
+ .slice(0, 6)
3106
+ .map(on => setLine(slug, thing, v, {...s, on}, unset)),
3107
+ },
3108
+ );
3109
+ }
1711
3110
  const named =
1712
3111
  TARGET.has(lower) || FAMILIES[lower]
1713
3112
  ? lower
1714
- : singular
1715
- ? singular
1716
- : byWord && (TARGET.has(byWord) || FAMILIES[byWord])
1717
- ? byWord
1718
- : null;
3113
+ : TARGET.has(dashed) || FAMILIES[dashed]
3114
+ ? dashed
3115
+ : singular
3116
+ ? singular
3117
+ : byWord && (TARGET.has(byWord) || FAMILIES[byWord])
3118
+ ? byWord
3119
+ : null;
3120
+ // The page (the body behind every part) is painted by the app shell.
3121
+ if (
3122
+ !named &&
3123
+ /^(page|body|app|background|page-background)$/i.test(s.on) &&
3124
+ TARGET.has('app-shell')
3125
+ )
3126
+ refuse(
3127
+ E.ERR_THEME_UNKNOWN_PART,
3128
+ `"${s.on}" is not a part name; the page behind your parts is app-shell (a background there shows in every AppShell variant).`,
3129
+ {
3130
+ didYouMean: ['app-shell'],
3131
+ run: [setLine(slug, thing, v, {...s, on: 'app-shell'}, unset)],
3132
+ },
3133
+ );
1719
3134
  if (named)
1720
3135
  refuse(
1721
3136
  E.ERR_THEME_UNKNOWN_PART,
@@ -1725,16 +3140,22 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1725
3140
  run: [setLine(slug, thing, v, {...s, on: named}, unset)],
1726
3141
  },
1727
3142
  );
3143
+ // A plural or another case names the part it means; a typo of one
3144
+ // part leads with the same command on that part.
3145
+ const near = nearest(s.on.toLowerCase().replace(/s$/, ''), [
3146
+ ...TARGET.keys(),
3147
+ ...Object.keys(FAMILIES),
3148
+ ]);
3149
+ const typo = near.filter(n => typoOf(lower, n));
1728
3150
  refuse(
1729
3151
  E.ERR_THEME_UNKNOWN_PART,
1730
3152
  `"${s.on}" is not a part you can style.`,
1731
3153
  {
1732
- // A plural or another case names the part it means.
1733
- didYouMean: nearest(s.on.toLowerCase().replace(/s$/, ''), [
1734
- ...TARGET.keys(),
1735
- ...Object.keys(FAMILIES),
1736
- ]),
3154
+ didYouMean: near,
1737
3155
  run: [
3156
+ ...(typo.length === 1
3157
+ ? [setLine(slug, thing, v, {...s, on: typo[0]}, unset)]
3158
+ : []),
1738
3159
  `${HOW} --list parts ${quoteCommandArgument(lower.replace(/s$/, '').split('-')[0] || 'button')}`,
1739
3160
  `${HOW} ${quoteCommandArgument(s.on)}`,
1740
3161
  ],
@@ -1742,6 +3163,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1742
3163
  );
1743
3164
  }
1744
3165
  if (s.when) {
3166
+ // A prop and value in other letters, with spaces or `=` between
3167
+ // (`Variant: Primary`, `variant=primary`): the working command.
3168
+ const m = /^\s*([^:=\s]+)\s*[:=]\s*([^:=]+?)\s*$/.exec(s.when);
3169
+ if (m) {
3170
+ const prop = t.props.find(x => x.toLowerCase() === m[1].toLowerCase());
3171
+ const vals = prop ? (C.variantValues(s.on)[prop] ?? []) : [];
3172
+ const val = vals.length
3173
+ ? vals.find(x => x.toLowerCase() === m[2].toLowerCase())
3174
+ : m[2];
3175
+ const when = prop && val ? `${prop}:${val}` : null;
3176
+ if (when && when !== s.when)
3177
+ refuse(
3178
+ E.ERR_THEME_UNKNOWN_VARIANT,
3179
+ `--when "${s.when}" is written ${when}.`,
3180
+ {
3181
+ didYouMean: [when],
3182
+ run: [setLine(slug, thing, v, {...s, when}, unset)],
3183
+ },
3184
+ );
3185
+ }
1745
3186
  const [p, wv, ...more] = s.when.split(':');
1746
3187
  if (!wv || more.length)
1747
3188
  refuse(
@@ -1764,12 +3205,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1764
3205
  );
1765
3206
  }
1766
3207
  const states = [...t.states, ...COMMON_STATES];
3208
+ // A state the part lists in camelCase (toggle-button's isPressed) typed
3209
+ // in any case or with dashes is that state.
3210
+ const flat = (/** @type {string} */ x) =>
3211
+ x.replace(/[-_\s]/g, '').toLowerCase();
3212
+ if (s.state && !states.includes(s.state)) {
3213
+ const same = states.find(x => flat(x) === flat(String(s.state)));
3214
+ if (same) s.state = same;
3215
+ }
1767
3216
  // Other words for a state, mapped to the one the part has; with none
1768
3217
  // near, the list of its states (never a guess such as hover).
1769
3218
  const SYNONYMS = wordTable(
1770
3219
  /** @type {Record<string, string[]>} */ ({
1771
- pressed: ['active'],
1772
- press: ['active'],
3220
+ pressed: ['isPressed', 'active'],
3221
+ press: ['isPressed', 'active'],
3222
+ on: ['isPressed', 'checked', 'selected'],
1773
3223
  down: ['active'],
1774
3224
  clicked: ['active'],
1775
3225
  hovered: ['hover'],
@@ -1781,6 +3231,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1781
3231
  inactive: ['disabled'],
1782
3232
  }),
1783
3233
  );
3234
+ // Several states in one --state (`hover,focus-visible`, `hover
3235
+ // focus-visible`): one line per state, the value quoted as typed.
3236
+ const typedStates = String(flags.state ?? '')
3237
+ .split(/\s*(?:,|\/|&|\band\b)\s*|\s+/)
3238
+ .map(x => x.trim().toLowerCase())
3239
+ .filter(Boolean);
3240
+ if (
3241
+ typedStates.length > 1 &&
3242
+ typedStates.every(x => states.includes(x)) &&
3243
+ !states.includes(String(s.state))
3244
+ )
3245
+ refuse(
3246
+ E.ERR_THEME_UNKNOWN_STATE,
3247
+ `"${flags.state}" names ${typedStates.length} states; --state takes one at a time.`,
3248
+ {
3249
+ didYouMean: typedStates,
3250
+ run: typedStates
3251
+ .slice(0, 6)
3252
+ .map(state => setLine(slug, thing, v, {...s, state}, unset)),
3253
+ },
3254
+ );
1784
3255
  const meant =
1785
3256
  (SYNONYMS[String(s.state ?? '').toLowerCase()] ?? []).find(x =>
1786
3257
  states.includes(x),
@@ -1788,7 +3259,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
1788
3259
  if (s.state && !states.includes(s.state))
1789
3260
  refuse(
1790
3261
  E.ERR_THEME_UNKNOWN_STATE,
1791
- `"${s.state}" is not a state of ${s.on}. States: ${states.join(', ')}.`,
3262
+ `"${s.state}" is not a state of ${s.on}. States: ${settableStates(ctx, slug, data, s.on).join(', ') || 'none'}.`,
1792
3263
  {
1793
3264
  ...(meant ? {didYouMean: [meant]} : {}),
1794
3265
  run: [
@@ -2131,6 +3602,38 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2131
3602
  })(),
2132
3603
  },
2133
3604
  );
3605
+ // A comparative weight word is the weight (lighter is light, never the
3606
+ // tracking tighter); two words (`bold tight`, `bold, tight`) are a
3607
+ // weight and a tracking, one line each.
3608
+ if (!unset) {
3609
+ const MORE = /** @type {Record<string, string>} */ ({
3610
+ lighter: 'light',
3611
+ thinner: 'light',
3612
+ bolder: 'bold',
3613
+ heavier: 'heavy',
3614
+ wider: 'wide',
3615
+ looser: 'wide',
3616
+ });
3617
+ const words = String(v ?? '')
3618
+ .trim()
3619
+ .toLowerCase()
3620
+ .split(/[\s,]+/)
3621
+ .filter(Boolean)
3622
+ .map(w => MORE[w] ?? w);
3623
+ const known = (/** @type {string} */ w) =>
3624
+ HEADING_WEIGHTS[w] !== undefined || HEADING_TRACKING[w] !== undefined;
3625
+ if (
3626
+ (words.length > 1 || MORE[String(v).trim().toLowerCase()]) &&
3627
+ words.every(known)
3628
+ )
3629
+ refuse(
3630
+ E.ERR_THEME_BAD_VALUE,
3631
+ words.length > 1
3632
+ ? `"${v}" is ${words.length} headings values; headings takes one at a time (a weight and a tracking are two settings).`
3633
+ : `"${v}" is the weight ${words[0]}.`,
3634
+ {run: words.map(w => `${P} set ${slug} headings ${w}`)},
3635
+ );
3636
+ }
2134
3637
  if (s.mode)
2135
3638
  refuse(
2136
3639
  E.ERR_THEME_NO_MODE,
@@ -2168,17 +3671,17 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2168
3671
  ...Object.keys(HEADING_WEIGHTS),
2169
3672
  ...Object.keys(HEADING_TRACKING),
2170
3673
  ];
2171
- const weight = /^\d+(\.\d+)?$/.test(lower) ? Number(lower) : null;
3674
+ // A weight word (extra bold, ultra-bold) is its number, read as
3675
+ // the rung nearest it (800 is heavy).
3676
+ const weightWord = WEIGHT_WORDS[lower.replace(/[\s-]+/g, '')];
3677
+ const weight = /^\d+(\.\d+)?$/.test(lower)
3678
+ ? Number(lower)
3679
+ : weightWord
3680
+ ? Number(weightWord)
3681
+ : null;
2172
3682
  const meant =
2173
3683
  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]);
3684
+ (weight != null ? weightRung(weight) : nearest(lower, words)[0]);
2182
3685
  refuse(
2183
3686
  E.ERR_THEME_BAD_VALUE,
2184
3687
  `headings takes ${DIALS.headings.values}, not "${v}".${weight != null && meant ? ` ${meant} sets weight ${HEADING_WEIGHTS[meant]}.` : ''}`,
@@ -2248,10 +3751,16 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2248
3751
  (s.on && typeof def !== 'number' ? own('') : undefined) ??
2249
3752
  def;
2250
3753
  const at = L.findIndex(([n]) => n === cur);
3754
+ const stepped = at + (v === 'more' ? 1 : -1);
3755
+ if (at >= 0 && stepped >= 0 && stepped < L.length) return L[stepped][0];
3756
+ // At the last rung that way, a step goes nowhere: refused as every
3757
+ // dial refuses it at its end, with the other way.
2251
3758
  if (at >= 0)
2252
- return L[
2253
- Math.max(0, Math.min(L.length - 1, at + (v === 'more' ? 1 : -1)))
2254
- ][0];
3759
+ refuse(
3760
+ E.ERR_THEME_NO_EFFECT,
3761
+ `${thing} is already at its ${v === 'more' ? 'largest' : 'smallest'} step, ${L[at][0]}${s.on ? ` on ${s.on}` : ''}, so "${v}" has nowhere to go.`,
3762
+ {run: [setLine(slug, thing, v === 'more' ? 'less' : 'more', s)]},
3763
+ );
2255
3764
  // A size between rungs steps to the next rung that way, never past it.
2256
3765
  const px =
2257
3766
  typeof cur === 'number'
@@ -2279,7 +3788,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2279
3788
  );
2280
3789
  refuse(
2281
3790
  E.ERR_THEME_BAD_VALUE,
2282
- `${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go.${atEnd ? ` It is also the ${v === 'more' ? 'largest' : 'smallest'} size ${thing} takes (${lo} to ${hi}); the base font size token takes any size.` : ' Give an exact size.'}`,
3791
+ `${thing} is ${typeof cur === 'number' ? `${cur}px` : cur}, already ${Math.abs(px - edge[1]) < 0.01 ? 'at' : v === 'more' ? 'above' : 'below'} its ${v === 'more' ? 'largest' : 'smallest'} step (${edge[0]}, ${edge[1]}px), so "${v}" has nowhere to go.${atEnd ? ` It is also the ${v === 'more' ? 'largest' : 'smallest'} size ${thing} takes (${lo} to ${hi}); the base font size token takes any size.` : ' Give an exact size.'}`,
2283
3792
  {
2284
3793
  run: atEnd
2285
3794
  ? [
@@ -2412,9 +3921,12 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2412
3921
  : cornerPxOf(onPart.value)
2413
3922
  : whole
2414
3923
  ? 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));
3924
+ : // The base theme's own radius on the part, when its rule
3925
+ // gives one; else the radius token's; one it does not give
3926
+ // in px (a var() chain) counts as medium's.
3927
+ (basePartRadiusPx(ctx, base, part, s.when) ??
3928
+ tokenPx(base, token) ??
3929
+ radiusAt(base, 'medium', token));
2418
3930
  const rungs = CORNERS.map(
2419
3931
  ([n]) => /** @type {const} */ ([n, radiusAt(base, n, token)]),
2420
3932
  );
@@ -2435,17 +3947,27 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2435
3947
  );
2436
3948
  s.value = next ? next[0] : 'medium';
2437
3949
  } else {
3950
+ // A value with copy debris (`8px;`): the value without it.
3951
+ if (withoutCopyDebris(v) !== v && withoutCopyDebris(v))
3952
+ refuse(
3953
+ E.ERR_THEME_BAD_VALUE,
3954
+ `"${v}" holds copy debris (a ;, a comment or !important); corners takes the value alone.`,
3955
+ {run: [setLine(slug, 'corners', withoutCopyDebris(v), s)]},
3956
+ );
2438
3957
  // A rung in any case, a size in px written any way: the plain form.
2439
3958
  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;
3959
+ // Any CSS number in px (2e1px, +4px), the shared length parse; a
3960
+ // rem is that many 16px, saved in px.
3961
+ const pxLen = /\d(px|rem)$/.test(lower) ? lengthPx(lower) : null;
2442
3962
  if (CORNERS.some(([n]) => n === lower)) s.value = lower;
2443
- else if (pxLen != null && pxLen >= 0)
3963
+ else if (pxLen != null && pxLen >= 0) {
2444
3964
  s.value =
2445
3965
  pxLen >= 1000 ? 'pill' : `${Math.round(pxLen * 10000) / 10000}px`;
3966
+ if (/rem$/.test(lower))
3967
+ s.note = `corners ${v.trim()} is saved as ${s.value}`;
3968
+ }
2446
3969
  // No rounding, said any way, is square.
2447
- else if (/^(0|0%|none|sharp|zero|no|flat)$/.test(lower))
2448
- s.value = 'square';
3970
+ else if (NO_ROUNDING.includes(lower)) s.value = 'square';
2449
3971
  else {
2450
3972
  // What it most likely means, as a value corners takes: a simple
2451
3973
  // calc() of px is worked out.
@@ -2461,14 +3983,31 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2461
3983
  '-': Number(calc[1]) - Number(calc[3]),
2462
3984
  }[/** @type {'*' | '/' | '+' | '-'} */ (calc[2])]
2463
3985
  : null;
3986
+ // A bare number (0.5, as a pasted --radius: 0.5rem loses its
3987
+ // unit) has no unit to read it by: no size is guessed.
3988
+ const bareNumber = /^[+-]?\d*\.?\d+$/.test(lower);
2464
3989
  const len =
2465
3990
  calcPx != null && Number.isFinite(calcPx)
2466
3991
  ? calcPx
2467
- : lengthPx(lower);
3992
+ : bareNumber
3993
+ ? null
3994
+ : lengthPx(lower);
2468
3995
  const pct = /^(\d+(?:\.\d+)?)%$/.exec(lower);
3996
+ // Tailwind's names, and rounding said with a negation: what they
3997
+ // mean (rounded-none and not round are square, rounded-full is
3998
+ // pill, rounded-[12px] is 12px).
3999
+ const tw = /^rounded-\[(.+)\]$/.exec(lower)?.[1];
4000
+ const opposite =
4001
+ TAILWIND_RADIUS[lower] ??
4002
+ (tw && lengthPx(tw) != null
4003
+ ? `${Math.round(Number(lengthPx(tw)) * 100) / 100}px`
4004
+ : negates(lower) && /round/.test(lower)
4005
+ ? 'square'
4006
+ : null);
2469
4007
  // A radius below zero means none: square.
2470
4008
  const meant =
2471
- len != null
4009
+ opposite ??
4010
+ (len != null
2472
4011
  ? len <= 0
2473
4012
  ? 'square'
2474
4013
  : `${Math.round(len * 100) / 100}px`
@@ -2476,17 +4015,34 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2476
4015
  ? Number(pct[1]) >= 50
2477
4016
  ? 'pill'
2478
4017
  : null
2479
- : (nearest(
2480
- lower,
2481
- CORNERS.map(([n]) => n),
2482
- )[0] ?? null);
4018
+ : bareNumber
4019
+ ? null
4020
+ : (nearest(
4021
+ lower,
4022
+ CORNERS.map(([n]) => n),
4023
+ )[0] ?? null));
2483
4024
  refuse(
2484
4025
  E.ERR_THEME_BAD_VALUE,
2485
- `corners takes ${DIALS.corners.values}, not "${v}".`,
4026
+ `corners takes ${DIALS.corners.values}, not "${v}"${bareNumber ? ' (a number needs its unit: px or rem)' : ''}.`,
2486
4027
  {
2487
4028
  ...(meant ? {didYouMean: [meant]} : {}),
2488
4029
  // The same scope, flags included.
2489
- run: [setLine(slug, 'corners', meant ?? 'medium', s)],
4030
+ // Nothing near: how corners, never a stock rung.
4031
+ // A whole bare number gets the line with px, the unit it
4032
+ // most likely meant, and how corners; one below one (a
4033
+ // pasted 0.5rem that lost its unit) has no unit to read it
4034
+ // by: how corners only.
4035
+ run:
4036
+ bareNumber && Number(lower) >= 1
4037
+ ? [
4038
+ setLine(slug, 'corners', `${Number(lower)}px`, s),
4039
+ `${HOW} corners`,
4040
+ ]
4041
+ : [
4042
+ meant
4043
+ ? setLine(slug, 'corners', meant, s)
4044
+ : `${HOW} corners`,
4045
+ ],
2490
4046
  },
2491
4047
  );
2492
4048
  }
@@ -2547,7 +4103,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2547
4103
  run: [setLine(slug, 'spacing', nearFactor, s)],
2548
4104
  },
2549
4105
  );
2550
- else if (/^(0|none|zero|no|off)$/i.test(v))
4106
+ else if (NO_SPACE.includes(v.toLowerCase()))
2551
4107
  // Spacing scales the theme's space; it never goes to nothing. The
2552
4108
  // tightest rung is the nearest that works.
2553
4109
  refuse(
@@ -2568,15 +4124,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2568
4124
  SPACING.map(([n]) => n),
2569
4125
  ),
2570
4126
  run: [
2571
- setLine(
2572
- slug,
2573
- 'spacing',
2574
- nearest(
4127
+ (() => {
4128
+ const near = nearest(
2575
4129
  v,
2576
4130
  SPACING.map(([n]) => n),
2577
- )[0] ?? 'roomy',
2578
- s,
2579
- ),
4131
+ )[0];
4132
+ return near
4133
+ ? setLine(slug, 'spacing', near, s)
4134
+ : `${HOW} spacing`;
4135
+ })(),
2580
4136
  ],
2581
4137
  },
2582
4138
  );
@@ -2601,7 +4157,10 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2601
4157
  })(),
2602
4158
  },
2603
4159
  );
2604
- if (step) s.value = ladder(TEXT_SIZE, 'medium');
4160
+ // With no text-size setting yet, a step starts from the size the base
4161
+ // theme's body text shows (past the last rung, it asks for a size).
4162
+ if (step)
4163
+ s.value = ladder(TEXT_SIZE, ctx.base ? baseTextPx(ctx.base) : 'medium');
2605
4164
  else if (
2606
4165
  /^\d+\.\d+$/.test(v.trim()) &&
2607
4166
  Number(v) >= 10 &&
@@ -2620,7 +4179,11 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2620
4179
  E.ERR_THEME_BAD_VALUE,
2621
4180
  `text-size takes ${DIALS['text-size'].values} (a number is the body size in pixels, 10 to 32), not "${v}".`,
2622
4181
  (() => {
2623
- // A rung in other letter case (Medium) or with px is that rung.
4182
+ // A rung in other letter case (Medium) or with px is that rung;
4183
+ // a CSS size keyword (x-large) is the size CSS gives it.
4184
+ const keyword = CSS_SIZE_KEYWORDS[v.trim().toLowerCase()];
4185
+ if (keyword != null && keyword >= 10 && keyword <= 32)
4186
+ return {run: [`${P} set ${slug} text-size ${keyword}`]};
2624
4187
  const near =
2625
4188
  TEXT_SIZE.find(([n]) => n === v.trim().toLowerCase())?.[0] ??
2626
4189
  nearest(
@@ -2632,19 +4195,26 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2632
4195
  didYouMean: [near],
2633
4196
  run: [`${P} set ${slug} text-size ${near}`],
2634
4197
  }
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
- };
4198
+ : (() => {
4199
+ // A size typed full-width or with a trailing dot
4200
+ // (18, 18.) is that size; one read any other way (a
4201
+ // unit, a constant calc()) is that size. Nothing read:
4202
+ // how text-size, never a stock size.
4203
+ const t = typedPlain(v).replace(/\.$/, '');
4204
+ const size =
4205
+ /^\d+(\.\d+)?$/.test(t) &&
4206
+ Number(t) >= 10 &&
4207
+ Number(t) <= 32
4208
+ ? String(Number(t))
4209
+ : textSizePx(v);
4210
+ return {
4211
+ run: [
4212
+ size != null
4213
+ ? `${P} set ${slug} text-size ${size}`
4214
+ : `${HOW} text-size`,
4215
+ ],
4216
+ };
4217
+ })();
2648
4218
  })(),
2649
4219
  );
2650
4220
  else if (!TEXT_SIZE.some(([n]) => n === v))
@@ -2665,13 +4235,51 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2665
4235
  .replace(/\s*!important\s*$/i, '')
2666
4236
  .replace(/;+\s*$/, '')
2667
4237
  .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');
4238
+ // A hex written 0x… (as in code) is that hex.
4239
+ .replace(/^0x([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i, '#$1')
4240
+ .replace(/^([0-9a-f]{3}|[0-9a-f]{6})$/i, '#$1');
4241
+ // A hex a digit short or over is refused as it is: the digit
4242
+ // missing could be anywhere, so none is made up.
4243
+ // A name of several words with a color among them (`navy blue`)
4244
+ // is that color.
4245
+ // Two names run together (`navyblue`) are the first, as the
4246
+ // spaced form is.
4247
+ const words = v
4248
+ .toLowerCase()
4249
+ .split(/[\s,-]+/)
4250
+ .filter(Boolean);
4251
+ // The words joined (dark red, light-blue, dark-slate-gray) are the
4252
+ // color they name. A word with a scale step (red-500, gray-900) is
4253
+ // no CSS color, and the bare word is another color: none is named.
4254
+ const joined = words.join('');
4255
+ const scaled = words.some(w => /\d/.test(w)) || /^[{]/.test(v.trim());
4256
+ const named =
4257
+ negates(v) || scaled
4258
+ ? []
4259
+ : words.length > 1 && COLOR_NAMES.includes(joined)
4260
+ ? [joined]
4261
+ : v
4262
+ .toLowerCase()
4263
+ .split(/[\s,-]+/)
4264
+ .flatMap(w =>
4265
+ COLOR_NAMES.includes(w)
4266
+ ? [w]
4267
+ : COLOR_NAMES.filter(
4268
+ n =>
4269
+ n.length >= 3 &&
4270
+ w.startsWith(n) &&
4271
+ COLOR_NAMES.includes(w.slice(n.length)),
4272
+ ).slice(0, 1),
4273
+ );
2672
4274
  const near =
2673
4275
  problem.kind === 'unknown'
2674
- ? nearest(v.toLowerCase(), COLOR_NAMES)
4276
+ ? /^#?[0-9a-f]{4,8}$/i.test(v.trim())
4277
+ ? []
4278
+ : named.length
4279
+ ? named.slice(0, 1)
4280
+ : scaled
4281
+ ? []
4282
+ : nearest(v.toLowerCase(), COLOR_NAMES)
2675
4283
  : [];
2676
4284
  // light-dark(a, b): the dial takes one color, from which it makes
2677
4285
  // both modes; the light one is offered.
@@ -2735,12 +4343,23 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2735
4343
  if (!step && canApply && (!/^\d{1,3}$/.test(v) || Number(v) > 100)) {
2736
4344
  // The value meant: a step in other letters (MORE), or the number
2737
4345
  // read as CSS reads it (70%, 7e1), kept in range.
2738
- const word = v.trim().toLowerCase();
2739
- const n = cssNumber(v);
4346
+ // Quotes around it (`"50"`) are not part of it.
4347
+ const bare = v
4348
+ .trim()
4349
+ .replace(/^(["'])(.*)\1$/, '$2')
4350
+ .trim();
4351
+ const word = bare.toLowerCase();
4352
+ const n = cssNumber(bare);
4353
+ // A fraction of one (0.5) is that share of the scale (50), as a
4354
+ // number with no unit from 0 to 1 is read.
4355
+ const scaled =
4356
+ n && n.unit === '' && n.value > 0 && n.value < 1
4357
+ ? n.value * 100
4358
+ : n?.value;
2740
4359
  const near = ['more', 'less'].includes(word)
2741
4360
  ? word
2742
- : n && (n.unit === '' || n.unit === '%')
2743
- ? String(Math.max(0, Math.min(100, Math.round(n.value))))
4361
+ : n && (n.unit === '' || n.unit === '%') && scaled != null
4362
+ ? String(Math.max(0, Math.min(100, Math.round(scaled))))
2744
4363
  : null;
2745
4364
  refuse(
2746
4365
  E.ERR_THEME_BAD_VALUE,
@@ -2758,8 +4377,24 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
2758
4377
  E.ERR_THEME_NO_EFFECT,
2759
4378
  colors.length
2760
4379
  ? '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')}`]},
4380
+ : (() => {
4381
+ // Colors set as tokens or on parts are values of their own:
4382
+ // vibrancy saturates only what the color dials make.
4383
+ const own = data.settings.find(
4384
+ (/** @type {any} */ x) =>
4385
+ x &&
4386
+ typeof x.value === 'string' &&
4387
+ (/^--color-/.test(String(x.thing)) ||
4388
+ /(^|-)colou?r$|^background(-color)?$|^fill$/.test(
4389
+ String(x.thing),
4390
+ )) &&
4391
+ parseColor(x.value) != null,
4392
+ );
4393
+ return own
4394
+ ? `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.`
4395
+ : 'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.';
4396
+ })(),
4397
+ {run: [`${HOW} accent`]},
2763
4398
  );
2764
4399
  } else if (thing === 'font') {
2765
4400
  if (s.when || s.state)
@@ -3053,16 +4688,46 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3053
4688
  ],
3054
4689
  },
3055
4690
  );
4691
+ // A dial typed as a flag (--corners round): the dial is meant.
4692
+ const dial = thing.replace(/^-+/, '');
4693
+ if (
4694
+ !(thing in TOKENS) &&
4695
+ (dial in DIALS || dial === 'base' || dial === 'mode')
4696
+ )
4697
+ refuse(
4698
+ E.ERR_THEME_UNKNOWN_TOKEN,
4699
+ `"${thing}" is not a design token; ${dial} is a dial, typed without dashes.`,
4700
+ {
4701
+ run: [setLine(slug, dial, v, {...s, mode: undefined}, unset)],
4702
+ },
4703
+ );
3056
4704
  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
- });
4705
+ // The editor's own color words: danger is the error role, brand and
4706
+ // primary are the accent (as the danger and accent dials say).
4707
+ const role = thing
4708
+ .replace(/\bdanger\b/, 'error')
4709
+ .replace(/\b(brand|primary)\b/, 'accent');
4710
+ const aliased = role !== thing && role in TOKENS ? role : null;
4711
+ // The filtered list only when it lists something.
4712
+ const word = thing
4713
+ .replace(/^-+(color-)?/, '')
4714
+ .split('-')[0]
4715
+ .trim();
4716
+ const listed =
4717
+ word && Object.keys(TOKENS).some(k => k.includes(word))
4718
+ ? `${HOW} --list tokens ${word}`
4719
+ : `${HOW} --list tokens`;
4720
+ refuse(
4721
+ E.ERR_THEME_UNKNOWN_TOKEN,
4722
+ `"${thing}" is not a design token.${aliased ? ` The token for that role is ${aliased}.` : ''}`,
4723
+ {
4724
+ didYouMean: aliased ? [aliased] : nearest(thing, Object.keys(TOKENS)),
4725
+ run: [
4726
+ ...(aliased ? [setLine(slug, aliased, v, s, unset)] : []),
4727
+ listed,
4728
+ ],
4729
+ },
4730
+ );
3066
4731
  }
3067
4732
  const type = C.typeOf(thing);
3068
4733
  // Only colors differ by mode: a shadow list cannot sit inside
@@ -3097,6 +4762,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3097
4762
  slug,
3098
4763
  C.propsReading(thing),
3099
4764
  multipliedTokens(ctx.project).has(thing),
4765
+ data.settings.some(x => x.thing === thing),
3100
4766
  );
3101
4767
  checkCycle(thing, v, TOKENS, data, ctx.project.cwd, s);
3102
4768
  // With no part data, what reads the token is unknown: save, unchecked.
@@ -3172,7 +4838,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3172
4838
  const instead = /reads: ([^.]+)\./.exec(
3173
4839
  String(/** @type {any} */ (hard[0][1])?.message ?? ''),
3174
4840
  )?.[1];
3175
- s.note = `${readers.length ? `${readers.join(', ')} read ${thing} and take this change; ` : ''}the editor's render of ${hard.map(([t]) => t).join(', ')} did not read it${instead ? ` (${hard[0][0]} reads ${instead})` : ''}, so those stay as they were; each part is rendered once, with its default props, so a variant that reads it may be missed`;
4841
+ s.note = `${readers.length ? `${readers.join(', ')} read ${thing} and take this change; ` : ''}the editor's render of ${hard.map(([t]) => t).join(', ')} did not read it${instead ? ` (${hard[0][0]} reads ${instead})` : ''}, so those stay as they were; each part is rendered with its default props, each variant value and each look flag, so a state or a combination that reads it may be missed`;
3176
4842
  }
3177
4843
  if (!s.note && recorded.length) {
3178
4844
  const fed = C.feeds(recorded[0][0], thing);
@@ -3201,6 +4867,8 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3201
4867
  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
4868
  else if (r && data.like && baseReads(ctx, data.like, thing))
3203
4869
  s.note = `the ${data.like} theme's own part styles read ${thing}, so the change shows where they use it`;
4870
+ else if (r && coreStylesRead(ctx, thing))
4871
+ 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
4872
  else if (r && dialWrites(thing))
3205
4873
  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
4874
  // The editor's record of what parts read comes from one render of
@@ -3208,7 +4876,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3208
4876
  // token is set as asked, and the result says nothing was seen
3209
4877
  // reading it.
3210
4878
  else if (r)
3211
- s.note = `no part the editor rendered reads ${thing} (each part is rendered once, with its default props, so a variant that reads it may be missed); it is set as asked, and reaches any part that reads it`;
4879
+ s.note = `no part the editor rendered reads ${thing} (each part is rendered with its default props, each variant value and each look flag, so a state or a combination that reads it may be missed); it is set as asked, and reaches any part that reads it`;
3212
4880
  }
3213
4881
  return s;
3214
4882
  }
@@ -3252,9 +4920,15 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3252
4920
  E.ERR_MISSING_ARGUMENT,
3253
4921
  `${prop} is a CSS property, so it needs --on <part|group>. For the whole theme use a dial or a token.`,
3254
4922
  {
4923
+ // The theme-wide dial or token for it, when there is one; never
4924
+ // a part that was not named.
3255
4925
  run: [
3256
- `${P} set ${slug} ${prop} ${quoteCommandArgument(v || exampleOf(groupOfPropType(prop), prop))} --on card`,
3257
- `${HOW} "${prop}"`,
4926
+ ...(v && WHOLE_THEME_EQUIVALENT[prop]
4927
+ ? [
4928
+ `${P} set ${slug} ${WHOLE_THEME_EQUIVALENT[prop]} ${quoteCommandArgument(v)}`,
4929
+ ]
4930
+ : []),
4931
+ `${HOW} ${quoteCommandArgument(prop)}`,
3258
4932
  ],
3259
4933
  },
3260
4934
  );
@@ -3374,9 +5048,40 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3374
5048
  },
3375
5049
  );
3376
5050
  }
5051
+ // A state Core paints at run time with an inline style (a selected table
5052
+ // row's wash) outranks any theme rule for that property while Core paints
5053
+ // it: the token the inline style reads is what changes it. A component
5054
+ // option can turn that paint off (a table without its row highlight), and
5055
+ // then a rule in the state applies; the refusal says both.
5056
+ if (s.state && !unset) {
5057
+ const family =
5058
+ prop === 'background' || prop === 'background-color'
5059
+ ? 'background-color'
5060
+ : prop;
5061
+ const inline = partsOf(ctx, s)
5062
+ .map(t => [t, ctx.C.MAP[t]?.inline?.[s.state ?? '']?.[family]])
5063
+ .find(([, tok]) => tok);
5064
+ if (inline)
5065
+ refuse(
5066
+ E.ERR_THEME_NO_EFFECT,
5067
+ `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.`,
5068
+ {
5069
+ run: [
5070
+ `${P} set ${slug} ${inline[1]} ${quoteCommandArgument(v)} --on ${inline[0]} --state ${s.state}${s.mode ? ` --mode ${s.mode}` : ''}`,
5071
+ ],
5072
+ },
5073
+ );
5074
+ }
3377
5075
  // Text, headings and links take their color from the color prop.
3378
5076
  const textParts = COLOR_PROP_PARTS;
5077
+ // A heading's color is written as the text color tokens its color prop
5078
+ // reads, on the heading alone (compileTheme), so it shows.
5079
+ const headingColor =
5080
+ prop === 'color' &&
5081
+ partsOf(ctx, s).length > 0 &&
5082
+ partsOf(ctx, s).every(t => t === 'heading');
3379
5083
  if (
5084
+ !headingColor &&
3380
5085
  (prop === 'color' || prop === '-webkit-text-fill-color') &&
3381
5086
  partsOf(ctx, s).some(t => textParts.includes(t))
3382
5087
  ) {
@@ -3405,67 +5110,21 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3405
5110
  }
3406
5111
  s.note = `text, heading and link inside ${s.on} keep the color their color prop gives; set --color-text-primary for those`;
3407
5112
  }
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
- }
5113
+ // One mode on a part whose variants each read their own color is
5114
+ // written to each variant's rule with that variant's own other half
5115
+ // (compileTheme), so it needs no variant named.
3464
5116
  if (!isSafeValue(v))
3465
5117
  refuse(
3466
5118
  E.ERR_THEME_BAD_VALUE,
3467
5119
  `"${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}`]},
5120
+ {
5121
+ // The value without its copy debris, when that is one.
5122
+ run: [
5123
+ withoutCopyDebris(v) !== v && isSafeValue(withoutCopyDebris(v))
5124
+ ? setLine(slug, prop, withoutCopyDebris(v), s)
5125
+ : `${HOW} ${prop}`,
5126
+ ],
5127
+ },
3469
5128
  );
3470
5129
  if (/radius$/.test(prop)) refuseInvisibleCorners(ctx, slug, s, data);
3471
5130
  if (step)
@@ -3536,18 +5195,53 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3536
5195
  if (
3537
5196
  s.mode &&
3538
5197
  !COLOR_PROPS.test(prop) &&
3539
- !(prop === 'background' && isColorValue(v))
5198
+ !(prop === 'background' && isColorValue(v)) &&
5199
+ // A gradient background (no image file) goes per mode: its colors
5200
+ // are each painted in that mode only (compileTheme).
5201
+ !(
5202
+ /^background(-image)?$/.test(prop) &&
5203
+ /gradient\(/i.test(v) &&
5204
+ !/url\(/i.test(v)
5205
+ )
3540
5206
  ) {
3541
5207
  // A color mixed into the value (a border's) can go per mode on its
3542
5208
  // own; a value with none (a radius) is just set for both modes.
3543
5209
  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;
5210
+ // A gradient's colors sit in its image, above any background-color:
5211
+ // no color step can make them differ per mode.
5212
+ const alt =
5213
+ !hasColor || /gradient\(/i.test(v)
5214
+ ? null
5215
+ : prop === 'border' || prop.startsWith('border-')
5216
+ ? 'border-color'
5217
+ : prop === 'background'
5218
+ ? 'background-color'
5219
+ : null;
5220
+ // On a part whose variants each have their own color, the color per
5221
+ // mode is set for one variant at a time (as that refusal says): the
5222
+ // step names the default one, or the first.
5223
+ let altWhen = '';
5224
+ if (alt && !s.when) {
5225
+ const g = C.groupOfProp(alt);
5226
+ const variants = [
5227
+ ...new Set(
5228
+ partsOf(ctx, s).flatMap(t =>
5229
+ (g ? C.partReads(t, g) : [])
5230
+ .filter(r => r.props.includes(alt))
5231
+ .flatMap(r => r.when)
5232
+ .map(w => /^variant=([\w-]+)$/.exec(w)?.[1])
5233
+ .filter(Boolean),
5234
+ ),
5235
+ ),
5236
+ ];
5237
+ const plain = partsOf(ctx, s).some(t =>
5238
+ (g ? C.partReads(t, g) : []).some(
5239
+ r => r.props.includes(alt) && r.when.includes(''),
5240
+ ),
5241
+ );
5242
+ if (variants.length && !plain)
5243
+ altWhen = ` --when variant:${variants.includes('default') ? 'default' : variants[0]}`;
5244
+ }
3551
5245
  refuse(
3552
5246
  E.ERR_THEME_NO_MODE,
3553
5247
  `--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 +5249,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3555
5249
  run: alt
3556
5250
  ? [
3557
5251
  `${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`,
5252
+ `${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
5253
  ]
3560
5254
  : [
3561
5255
  `${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${whenFlag} # both modes`,
@@ -3567,12 +5261,25 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3567
5261
  // value set for both modes); with none to keep, the setting would
3568
5262
  // change that mode too. Without a state, the other mode keeps the
3569
5263
  // part's plain color.
5264
+ /** Whether a part keeps a value of its own in the other mode. */
5265
+ const keepsOther = (/** @type {string} */ t) =>
5266
+ Boolean(partDefault(ctx, t, camel(prop), s.when, s.state)) ||
5267
+ // The base theme's own value there (in the state, else at rest) is
5268
+ // what the other mode keeps.
5269
+ [`:${s.state}`, null].some(st =>
5270
+ baseRuleHas(
5271
+ ctx.project.cwd,
5272
+ data.like,
5273
+ t,
5274
+ s.when ?? 'base',
5275
+ st,
5276
+ camel(prop),
5277
+ ),
5278
+ );
5279
+ const cannotKeep =
5280
+ s.mode && s.state ? partsOf(ctx, s).filter(t => !keepsOther(t)) : [];
3570
5281
  if (
3571
- s.mode &&
3572
- s.state &&
3573
- !partsOf(ctx, s).every(t =>
3574
- partDefault(ctx, t, camel(prop), s.when, s.state),
3575
- ) &&
5282
+ cannotKeep.length &&
3576
5283
  !data.settings.some(
3577
5284
  x =>
3578
5285
  x.thing === prop &&
@@ -3581,16 +5288,30 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3581
5288
  x.state === s.state &&
3582
5289
  x.mode !== s.mode,
3583
5290
  )
3584
- )
5291
+ ) {
5292
+ const flagsTail = `${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`;
5293
+ // The part named keeps its own when only other members of its group
5294
+ // cannot: --only writes it alone, its mode kept.
5295
+ const onlyThis =
5296
+ s.on &&
5297
+ !cannotKeep.includes(s.on) &&
5298
+ familyOf(s.on) &&
5299
+ AUTO_SPREAD.includes(/** @type {string} */ (familyOf(s.on)));
3585
5300
  refuse(
3586
5301
  E.ERR_THEME_NO_MODE,
3587
- `${s.on} has no ${prop}${s.state ? ` when ${s.state}` : ''}${s.when ? ` for ${s.when}` : ''} of its own for the ${s.mode === 'light' ? 'dark' : 'light'} mode to keep, so a ${s.mode}-only value would change it too. Set it for both modes.`,
5302
+ `${cannotKeep.slice(0, 3).join(', ')}${cannotKeep.length > 3 ? ` and ${cannotKeep.length - 3} more` : ''} ${cannotKeep.length > 1 ? 'have' : 'has'} no ${prop}${s.state ? ` when ${s.state}` : ''}${s.when ? ` for ${s.when}` : ''} of ${cannotKeep.length > 1 ? 'their' : 'its'} own for the ${s.mode === 'light' ? 'dark' : 'light'} mode to keep, so a ${s.mode}-only value would change it too.${onlyThis ? ` ${s.on} has one: set it alone with --only.` : ' Set it for both modes.'}`,
3588
5303
  {
3589
5304
  run: [
3590
- `${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${s.when ? ` --when ${s.when}` : ''}${s.state ? ` --state ${s.state}` : ''}`,
5305
+ ...(onlyThis
5306
+ ? [
5307
+ `${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on} --only${flagsTail} --mode ${s.mode}`,
5308
+ ]
5309
+ : []),
5310
+ `${P} set ${slug} ${prop} ${quoteCommandArgument(v)} --on ${s.on}${flagsTail}`,
3591
5311
  ],
3592
5312
  },
3593
5313
  );
5314
+ }
3594
5315
  return s;
3595
5316
  }
3596
5317
  // A property written with _ or spaces, a trailing colon, or in camel
@@ -3638,13 +5359,18 @@ function checkOne(ctx, slug, data, thing, value, flags, unset) {
3638
5359
  // A hint names this theme and the part (card when none is given),
3639
5360
  // and a corners value corners takes.
3640
5361
  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,
5362
+ ? (/corners/.test(String(hint('', ''))) &&
5363
+ v.trim() &&
5364
+ !YES_NO.test(v.trim()) &&
5365
+ cornersRead(v) == null
5366
+ ? // A value corners cannot read: how corners, never a stock rung.
5367
+ [`${HOW} corners`]
5368
+ : hint(
5369
+ /corners/.test(String(hint('', ''))) && !YES_NO.test(v.trim())
5370
+ ? (cornersRead(v) ?? '')
5371
+ : v,
5372
+ s.on,
5373
+ )
3648
5374
  ).map(x =>
3649
5375
  x
3650
5376
  .replace(/<theme>/g, slug)
@@ -3672,6 +5398,13 @@ function refuseInvisibleCorners(ctx, slug, s, data) {
3672
5398
  if (ctx.unchecked) return;
3673
5399
  const parts = partsOf(ctx, s);
3674
5400
  if (!parts.length || parts.some(t => ctx.C.showsCorners(t))) return;
5401
+ // The corners dial on a part whose corners are drawn by parts of its own
5402
+ // inside it (a date-time input's date and time boxes) rounds those.
5403
+ if (
5404
+ s.thing === 'corners' &&
5405
+ parts.some(t => cornerParts(ctx, t).some(x => x !== t))
5406
+ )
5407
+ return;
3675
5408
  // An edge the theme gives the part itself shows its corners too.
3676
5409
  const edged = data.settings.some(
3677
5410
  x =>
@@ -3797,8 +5530,8 @@ export function unknownVarRef(v, TOKENS, thing) {
3797
5530
  // A fallback always gives a value: never "reads nothing" (a likely
3798
5531
  // typo is noted when the setting is made).
3799
5532
  if (comma) continue;
3800
- const near = nearest(name, Object.keys(TOKENS)).filter(
3801
- n => levenshteinDistance(n, name) <= 2,
5533
+ const near = nearest(name, Object.keys(TOKENS)).filter(n =>
5534
+ typoNear(name, n),
3802
5535
  );
3803
5536
  if (near.length)
3804
5537
  return {
@@ -3849,78 +5582,38 @@ export function fontFileReason(value) {
3849
5582
  }
3850
5583
 
3851
5584
  /**
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
5585
+ * A word as a suggested command quotes it, without the quotes.
5586
+ * @param {string} word
3856
5587
  */
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('');
5588
+ function unquoteArg(word) {
5589
+ const m = /^'(.*)'$/s.exec(word.trim());
5590
+ return m ? m[1].replace(/'\\''/g, "'") : word.trim();
3874
5591
  }
3875
5592
 
5593
+ /** Core's stylesheet text, by project folder. @type {Map<string, string>} */
5594
+ const coreStyles = new Map();
5595
+
3876
5596
  /**
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}}
5597
+ * Whether Core's own stylesheet reads a token anywhere (a part the editor
5598
+ * does not render, such as the app shell behind the page, included).
5599
+ * @param {any} ctx
5600
+ * @param {string} token
3885
5601
  */
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;
5602
+ function coreStylesRead(ctx, token) {
5603
+ const cwd = String(ctx?.project?.cwd ?? '');
5604
+ let css = coreStyles.get(cwd);
5605
+ if (css == null) {
5606
+ try {
5607
+ css = fs.readFileSync(
5608
+ ctx.project.req.resolve('@astryxdesign/core/astryx.css'),
5609
+ 'utf8',
5610
+ );
5611
+ } catch {
5612
+ css = '';
3898
5613
  }
5614
+ coreStyles.set(cwd, css);
3899
5615
  }
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,
5616
+ return new RegExp(`var\\(\\s*${token.replace(/[-]/g, '\\-')}\\s*[,)]`).test(
5617
+ css,
3910
5618
  );
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
5619
  }