@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0404a74

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 (529) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +17 -0
  3. package/api/build/_adapter.mjs +53 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/blocks/blocks.weights.json +1 -1
  7. package/api/build/build.doc.mjs +4 -3
  8. package/api/build/build.type.d.mts +2 -2
  9. package/api/build/build.type.mjs +3 -3
  10. package/api/build/kit/kind.d.mts +2 -1
  11. package/api/build/kit/kind.mjs +199 -10
  12. package/api/build/kit/kit.mjs +6 -4
  13. package/api/build/kit/rank.d.mts +6 -4
  14. package/api/build/kit/rank.mjs +132 -28
  15. package/api/build/kit/signals.d.mts +7 -1
  16. package/api/build/kit/signals.mjs +21 -10
  17. package/api/build/kit/start.d.mts +5 -4
  18. package/api/build/kit/start.mjs +14 -9
  19. package/api/build/kit/weights.d.mts +39 -3
  20. package/api/build/kit/weights.json +1 -1
  21. package/api/build/kit/weights.mjs +351 -46
  22. package/api/build/kit/word-model.d.mts +23 -0
  23. package/api/build/kit/word-model.mjs +46 -0
  24. package/api/build/kit/words.d.mts +86 -0
  25. package/api/build/kit/words.mjs +241 -1
  26. package/api/build/tree.mjs +1 -1
  27. package/api/component/__fixtures__/resolutions/modules.txt +5 -6
  28. package/api/component/_adapter.d.mts +26 -2
  29. package/api/component/_adapter.mjs +135 -8
  30. package/api/component/component.mjs +14 -1
  31. package/api/component/list/list.d.mts +1 -1
  32. package/api/component/list/list.mjs +48 -6
  33. package/api/discover/_adapter.d.mts +11 -1
  34. package/api/discover/_adapter.mjs +95 -1
  35. package/api/discover/detail/item/item.mjs +5 -0
  36. package/api/discover/discover.mjs +12 -3
  37. package/api/discover/discover.type.d.mts +16 -3
  38. package/api/discover/discover.type.mjs +13 -3
  39. package/api/discover/search/search.mjs +3 -2
  40. package/api/docs/_adapter.d.mts +57 -2
  41. package/api/docs/_adapter.mjs +266 -33
  42. package/api/docs/_entry-names-lazily.d.mts +22 -0
  43. package/api/docs/_entry-names-lazily.mjs +25 -0
  44. package/api/docs/_entry-names.d.mts +23 -0
  45. package/api/docs/_entry-names.mjs +105 -0
  46. package/api/docs/docs.d.mts +3 -0
  47. package/api/docs/docs.doc.mjs +7 -1
  48. package/api/docs/docs.mjs +12 -0
  49. package/api/docs/docs.type.d.mts +5 -0
  50. package/api/docs/docs.type.mjs +2 -0
  51. package/api/docs/node/node.mjs +1 -1
  52. package/api/doctor/_adapter.d.mts +54 -5
  53. package/api/doctor/_adapter.mjs +162 -11
  54. package/api/doctor/built-checks.mjs +40 -14
  55. package/api/doctor/doctor.d.mts +15 -3
  56. package/api/doctor/doctor.doc.mjs +1 -1
  57. package/api/doctor/doctor.mjs +31 -7
  58. package/api/doctor/theme-checks.d.mts +35 -3
  59. package/api/doctor/theme-checks.mjs +377 -29
  60. package/api/hook/_adapter.d.mts +10 -4
  61. package/api/hook/_adapter.mjs +41 -5
  62. package/api/hook/detail/detail.mjs +5 -2
  63. package/api/hook/detail/params/params.mjs +10 -3
  64. package/api/icon/_records.mjs +2 -1
  65. package/api/index.d.mts +2 -0
  66. package/api/index.mjs +2 -0
  67. package/api/integration/_adapter.d.mts +44 -0
  68. package/api/integration/_adapter.mjs +77 -1
  69. package/api/integration/add-helpers.mjs +10 -0
  70. package/api/integration/authoring-checks.mjs +11 -8
  71. package/api/integration/example-scope.d.mts +14 -0
  72. package/api/integration/example-scope.mjs +44 -0
  73. package/api/integration/example-scope.type.d.mts +29 -0
  74. package/api/integration/example-scope.type.mjs +25 -0
  75. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  76. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  77. package/api/integration/pack-check.mjs +16 -1
  78. package/api/integration/validate-integration.d.mts +18 -6
  79. package/api/integration/validate-integration.mjs +129 -15
  80. package/api/integration/validate-integration.type.d.mts +22 -0
  81. package/api/integration/validate-integration.type.mjs +2 -1
  82. package/api/integration/validateIntegration.doc.mjs +1 -1
  83. package/api/render/_adapter.mjs +591 -195
  84. package/api/render/render.doc.mjs +11 -3
  85. package/api/render/render.type.d.mts +53 -1
  86. package/api/render/render.type.mjs +32 -2
  87. package/api/search/ORDERING.md +2 -2
  88. package/api/search/_adapter.d.mts +9 -0
  89. package/api/search/_adapter.mjs +85 -0
  90. package/api/search/_candidate-score.d.mts +9 -4
  91. package/api/search/_candidate-score.mjs +133 -46
  92. package/api/search/_fit-order.mjs +3 -3
  93. package/api/search/_gather-components.d.mts +3 -2
  94. package/api/search/_gather-components.mjs +12 -3
  95. package/api/search/_lexical.d.mts +14 -0
  96. package/api/search/_lexical.mjs +93 -11
  97. package/api/search/_result.d.mts +11 -9
  98. package/api/search/_result.mjs +4 -4
  99. package/api/search/_score.d.mts +6 -1
  100. package/api/search/_score.mjs +15 -3
  101. package/api/search/search-index.mjs +7 -1
  102. package/api/search/search.d.mts +1 -1
  103. package/api/template/_adapter.d.mts +16 -0
  104. package/api/template/_adapter.mjs +39 -2
  105. package/api/template/cdn/cdn.mjs +37 -8
  106. package/api/template/copy/copy.d.mts +6 -3
  107. package/api/template/copy/copy.mjs +40 -8
  108. package/api/template/template.doc.mjs +3 -3
  109. package/api/template/template.mjs +63 -11
  110. package/api/template/template.type.d.mts +1 -0
  111. package/api/template/template.type.mjs +1 -0
  112. package/api/theme/_adapter.d.mts +12 -1
  113. package/api/theme/_adapter.mjs +132 -13
  114. package/api/theme/_app-provider.d.mts +31 -0
  115. package/api/theme/_app-provider.mjs +135 -0
  116. package/api/theme/add/add.mjs +3 -1
  117. package/api/theme/build/build.d.mts +142 -1
  118. package/api/theme/build/build.mjs +692 -284
  119. package/api/theme/build/core-interception.d.mts +10 -0
  120. package/api/theme/build/core-interception.mjs +10 -0
  121. package/api/theme/build/font-warning.d.mts +80 -5
  122. package/api/theme/build/font-warning.mjs +323 -55
  123. package/api/theme/build/icon-imports.mjs +51 -9
  124. package/api/theme/build/null-values.d.mts +28 -0
  125. package/api/theme/build/null-values.mjs +191 -0
  126. package/api/theme/list/list.mjs +17 -1
  127. package/api/theme/remove/remove.d.mts +2 -1
  128. package/api/theme/remove/remove.mjs +7 -3
  129. package/api/theme/theme.type.d.mts +78 -1
  130. package/api/theme/theme.type.mjs +38 -2
  131. package/api/theme/themeAdd.doc.mjs +1 -1
  132. package/api/theme/themeListAvailable.doc.mjs +1 -1
  133. package/api/theme/themeRemove.doc.mjs +8 -5
  134. package/api/theme-edit/_adapter.d.mts +116 -4
  135. package/api/theme-edit/_adapter.mjs +1058 -93
  136. package/api/theme-edit/_catalog.d.mts +46 -2
  137. package/api/theme-edit/_catalog.mjs +115 -14
  138. package/api/theme-edit/_check.d.mts +133 -24
  139. package/api/theme-edit/_check.mjs +3392 -531
  140. package/api/theme-edit/_color.d.mts +26 -0
  141. package/api/theme-edit/_color.mjs +92 -2
  142. package/api/theme-edit/_compiler.d.mts +5 -1
  143. package/api/theme-edit/_compiler.mjs +141 -17
  144. package/api/theme-edit/_context.d.mts +74 -6
  145. package/api/theme-edit/_context.mjs +468 -76
  146. package/api/theme-edit/_css.d.mts +21 -0
  147. package/api/theme-edit/_css.mjs +87 -14
  148. package/api/theme-edit/_edit.d.mts +74 -7
  149. package/api/theme-edit/_edit.mjs +4426 -319
  150. package/api/theme-edit/_how-commands.d.mts +76 -1
  151. package/api/theme-edit/_how-commands.mjs +793 -9
  152. package/api/theme-edit/_how-question.d.mts +97 -6
  153. package/api/theme-edit/_how-question.mjs +9184 -747
  154. package/api/theme-edit/_how.d.mts +5 -2
  155. package/api/theme-edit/_how.mjs +255 -46
  156. package/api/theme-edit/_importers.d.mts +38 -0
  157. package/api/theme-edit/_importers.mjs +188 -0
  158. package/api/theme-edit/_marks.d.mts +31 -5
  159. package/api/theme-edit/_marks.mjs +57 -5
  160. package/api/theme-edit/_name-rule.d.mts +11 -0
  161. package/api/theme-edit/_name-rule.mjs +12 -0
  162. package/api/theme-edit/_normal.d.mts +322 -0
  163. package/api/theme-edit/_normal.mjs +1630 -0
  164. package/api/theme-edit/_palette.d.mts +49 -0
  165. package/api/theme-edit/_palette.mjs +180 -38
  166. package/api/theme-edit/_part-words.d.mts +39 -0
  167. package/api/theme-edit/_part-words.mjs +152 -0
  168. package/api/theme-edit/_parts.d.mts +55 -3
  169. package/api/theme-edit/_parts.mjs +421 -36
  170. package/api/theme-edit/_preview-app.d.mts +7 -13
  171. package/api/theme-edit/_preview-app.mjs +1108 -599
  172. package/api/theme-edit/_preview.d.mts +156 -19
  173. package/api/theme-edit/_preview.mjs +809 -180
  174. package/api/theme-edit/_project.d.mts +61 -1
  175. package/api/theme-edit/_project.mjs +177 -6
  176. package/api/theme-edit/_settings.d.mts +619 -48
  177. package/api/theme-edit/_settings.mjs +4910 -617
  178. package/api/theme-edit/_tables.d.mts +41 -0
  179. package/api/theme-edit/_tables.mjs +261 -41
  180. package/api/theme-edit/_vet.d.mts +31 -0
  181. package/api/theme-edit/_vet.mjs +114 -8
  182. package/api/theme-edit/theme-edit.type.d.mts +34 -2
  183. package/api/theme-edit/theme-edit.type.mjs +18 -3
  184. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  185. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  186. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  187. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  188. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  189. package/api/upgrade/run/run.mjs +4 -3
  190. package/api/upgrade/upgrade.mjs +16 -1
  191. package/assets/codemods/integration-discovery.mjs +2 -1
  192. package/assets/codemods/integration-runner.mjs +1 -1
  193. package/assets/codemods/jscodeshift.d.ts +1 -1
  194. package/assets/codemods/run-codemod.mjs +151 -18
  195. package/assets/codemods/runner.mjs +1 -4
  196. package/assets/codemods/transforms/next/index.mjs +11 -1
  197. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  198. package/assets/component-list.generated.json +1 -0
  199. package/assets/docs/author-a-theme.doc.mjs +2 -0
  200. package/assets/docs/theme.doc.dense.mjs +76 -7
  201. package/assets/docs/theme.doc.mjs +66 -2
  202. package/assets/docs/theme.doc.zh.mjs +51 -1
  203. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  204. package/assets/docs/tree/checks.doc.mjs +2 -2
  205. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  206. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  207. package/assets/docs/tree/font-setup.doc.mjs +1 -1
  208. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  209. package/assets/docs/tree/render-pages.doc.mjs +46 -5
  210. package/assets/docs/tree/share-a-page.doc.mjs +157 -0
  211. package/assets/docs/tree/single-component.doc.mjs +4 -0
  212. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  213. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  214. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  215. package/assets/docs/use-a-theme.doc.mjs +2 -2
  216. package/assets/docs-routes.generated.json +1 -0
  217. package/assets/docs.generated.json +2 -2
  218. package/assets/search-catalog.generated.json +2 -0
  219. package/assets/self-audit.generated.json +1 -1
  220. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  221. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  222. package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.doc.mjs +14 -0
  223. package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.tsx +43 -0
  224. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  225. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  226. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  227. package/assets/templates/components.generated.json +1 -1
  228. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  229. package/assets/templates/pages/ai-chat-landing/page.tsx +31 -4
  230. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
  231. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  232. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  233. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  234. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  235. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  236. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  237. package/assets/templates/pages/dashboard-alert-rail/page.tsx +1 -1
  238. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  239. package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +1 -1
  240. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  241. package/assets/templates/pages/dashboard-comparison/page.tsx +2 -2
  242. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  243. package/assets/templates/pages/dashboard-progress/page.tsx +1 -1
  244. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  245. package/assets/templates/pages/detail-page/page.tsx +60 -7
  246. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  247. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  248. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  249. package/assets/templates/pages/documentation-technical/page.tsx +13 -13
  250. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  251. package/assets/templates/pages/editor/page.tsx +14 -2
  252. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  253. package/assets/templates/pages/file-explorer/page.tsx +9 -0
  254. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  255. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  256. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  257. package/assets/templates/pages/form-wizard-vertical/page.tsx +23 -3
  258. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  259. package/assets/templates/pages/ide/page.tsx +33 -2
  260. package/assets/templates/pages/kanban-board/page.tsx +12 -2
  261. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  262. package/assets/templates/pages/library/template.doc.mjs +4 -1
  263. package/assets/templates/pages/login/template.doc.mjs +2 -1
  264. package/assets/templates/pages/login-card/page.tsx +16 -0
  265. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  266. package/assets/templates/pages/login-split/page.tsx +19 -6
  267. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  268. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  269. package/assets/templates/pages/messaging-shell/template.doc.mjs +6 -0
  270. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  271. package/assets/templates/pages/payment-form/page.tsx +30 -4
  272. package/assets/templates/pages/product-detail/page.tsx +26 -2
  273. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  274. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  275. package/assets/templates/pages/settings-dialog/page.tsx +162 -12
  276. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  277. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  278. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  279. package/assets/templates/pages/shell-side-nav/page.tsx +11 -3
  280. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  281. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  282. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  283. package/assets/templates/pages/table-filter/page.tsx +9 -0
  284. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  285. package/assets/templates/pages/table-grouped/page.tsx +161 -133
  286. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  287. package/assets/templates/pages/table-page/page.tsx +14 -1
  288. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  289. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  290. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  291. package/assets/templates/pages/work-item-detail/page.tsx +47 -7
  292. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  293. package/assets/theme.template.ts +9 -2
  294. package/authoring/debug/parse.d.mts +3 -3
  295. package/authoring/doctypes/_schema.d.mts +9 -9
  296. package/authoring/doctypes/command/command.doc.mjs +1 -1
  297. package/authoring/doctypes/component/categories.d.mts +37 -0
  298. package/authoring/doctypes/component/categories.mjs +54 -0
  299. package/authoring/doctypes/template/template.doc.mjs +1 -1
  300. package/authoring/doctypes/template/type.ts +9 -0
  301. package/authoring/example/example.doc.d.mts +12 -0
  302. package/authoring/example/example.doc.mjs +69 -0
  303. package/authoring/example/preview.d.mts +92 -0
  304. package/authoring/example/preview.mjs +994 -0
  305. package/authoring/example/type.ts +102 -0
  306. package/authoring/index.d.mts +1 -0
  307. package/authoring/index.d.ts +12 -0
  308. package/authoring/index.mjs +3 -1
  309. package/authoring/integration/integration.doc.mjs +8 -0
  310. package/authoring/integration/schema.d.mts +24 -1
  311. package/authoring/integration/schema.mjs +126 -4
  312. package/authoring/integration/type.ts +14 -0
  313. package/clients/cli/bin/astryx.mjs +6 -9
  314. package/clients/cli/build-id.generated.json +1 -1
  315. package/clients/cli/commands/component.doc.mjs +1 -1
  316. package/clients/cli/commands/component.mjs +22 -3
  317. package/clients/cli/commands/discover.mjs +70 -3
  318. package/clients/cli/commands/docs.doc.mjs +7 -1
  319. package/clients/cli/commands/docs.mjs +44 -6
  320. package/clients/cli/commands/doctor.mjs +84 -16
  321. package/clients/cli/commands/experimental/render.mjs +42 -1
  322. package/clients/cli/commands/experimental/theme.mjs +1032 -134
  323. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  324. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  325. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  326. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  327. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  328. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  329. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  330. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  331. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -2
  332. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  333. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  334. package/clients/cli/commands/experimental-theme-remove.doc.mjs +4 -4
  335. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  336. package/clients/cli/commands/search.doc.mjs +2 -1
  337. package/clients/cli/commands/search.mjs +6 -1
  338. package/clients/cli/commands/template.doc.mjs +1 -1
  339. package/clients/cli/commands/template.mjs +15 -2
  340. package/clients/cli/commands/theme-add.doc.mjs +1 -1
  341. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  342. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  343. package/clients/cli/commands/theme-remove.doc.mjs +13 -5
  344. package/clients/cli/commands/theme.doc.mjs +1 -1
  345. package/clients/cli/commands/theme.mjs +849 -441
  346. package/clients/cli/commands/upgrade.mjs +46 -8
  347. package/clients/cli/index.mjs +9 -19
  348. package/clients/cli/lib/cli-error.mjs +2 -1
  349. package/clients/cli/lib/component-format.mjs +205 -98
  350. package/clients/cli/lib/hook-format.mjs +9 -19
  351. package/clients/cli/lib/json-shim.mjs +265 -29
  352. package/clients/cli/lib/manifest.mjs +3 -2
  353. package/clients/cli/lib/stray-option.mjs +478 -0
  354. package/clients/cli/lib/unknown-command.mjs +353 -0
  355. package/clients/cli/manifest.generated.json +1 -1
  356. package/foundation/agent-docs/agent-docs.mjs +1 -1
  357. package/foundation/config/project.d.mts +8 -0
  358. package/foundation/config/project.mjs +26 -29
  359. package/foundation/config/theme-state.d.mts +31 -2
  360. package/foundation/config/theme-state.mjs +140 -8
  361. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  362. package/foundation/discovery/cli-self-doc-names.d.mts +13 -0
  363. package/foundation/discovery/cli-self-doc-names.mjs +51 -0
  364. package/foundation/discovery/cli-self-docs.d.mts +0 -2
  365. package/foundation/discovery/cli-self-docs.mjs +2 -15
  366. package/foundation/discovery/component-discovery.d.mts +11 -0
  367. package/foundation/discovery/component-discovery.mjs +59 -10
  368. package/foundation/discovery/component-replacement.mjs +130 -1
  369. package/foundation/discovery/copied-passages.mjs +2 -1
  370. package/foundation/discovery/core-component-docs.d.mts +29 -0
  371. package/foundation/discovery/core-component-docs.mjs +83 -0
  372. package/foundation/discovery/core-theme-facts.d.mts +70 -0
  373. package/foundation/discovery/core-theme-facts.mjs +384 -0
  374. package/foundation/discovery/doc-types.mjs +4 -3
  375. package/foundation/discovery/docs-discovery.d.mts +66 -9
  376. package/foundation/discovery/docs-discovery.mjs +126 -60
  377. package/foundation/discovery/entry-name-files.d.mts +106 -0
  378. package/foundation/discovery/entry-name-files.mjs +354 -0
  379. package/foundation/discovery/hook-discovery.d.mts +18 -2
  380. package/foundation/discovery/hook-discovery.mjs +93 -42
  381. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  382. package/foundation/discovery/icon-set-checks.mjs +2 -1
  383. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  384. package/foundation/discovery/integration-component-views.d.mts +15 -0
  385. package/foundation/discovery/integration-component-views.mjs +91 -0
  386. package/foundation/discovery/integration-doc-files.mjs +2 -1
  387. package/foundation/discovery/module-exports.d.mts +26 -1
  388. package/foundation/discovery/module-exports.mjs +114 -40
  389. package/foundation/discovery/name-roots.d.mts +38 -0
  390. package/foundation/discovery/name-roots.mjs +108 -0
  391. package/foundation/discovery/next-routes.d.mts +48 -0
  392. package/foundation/discovery/next-routes.mjs +181 -0
  393. package/foundation/discovery/package-exports.d.mts +10 -0
  394. package/foundation/discovery/package-exports.mjs +56 -3
  395. package/foundation/discovery/prop-drift.mjs +9 -9
  396. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  397. package/foundation/discovery/runner-allowlist.mjs +2 -0
  398. package/foundation/discovery/stored-component-list.d.mts +43 -0
  399. package/foundation/discovery/stored-component-list.mjs +90 -0
  400. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  401. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  402. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  403. package/foundation/discovery/stored-self-audit.mjs +40 -18
  404. package/foundation/discovery/template-adapter.d.mts +49 -29
  405. package/foundation/discovery/template-adapter.mjs +89 -99
  406. package/foundation/discovery/template-destination.d.mts +28 -0
  407. package/foundation/discovery/template-destination.mjs +104 -0
  408. package/foundation/discovery/template-icons.mjs +2 -1
  409. package/foundation/discovery/template-ids.d.mts +69 -0
  410. package/foundation/discovery/template-ids.mjs +199 -0
  411. package/foundation/discovery/theme-discovery.d.mts +12 -0
  412. package/foundation/discovery/theme-discovery.mjs +34 -4
  413. package/foundation/discovery/theme-imports.d.mts +24 -0
  414. package/foundation/discovery/theme-imports.mjs +61 -4
  415. package/foundation/discovery/theming-targets.d.mts +13 -5
  416. package/foundation/discovery/theming-targets.mjs +41 -47
  417. package/foundation/doc-compiler/generated-levels.d.mts +43 -0
  418. package/foundation/doc-compiler/generated-levels.mjs +72 -0
  419. package/foundation/doc-compiler/import.mjs +7 -1
  420. package/foundation/doc-compiler/inputs.mjs +3 -2
  421. package/foundation/doc-compiler/literal-doc.d.mts +12 -0
  422. package/foundation/doc-compiler/literal-doc.mjs +322 -0
  423. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  424. package/foundation/doc-compiler/stored-docs.d.mts +29 -0
  425. package/foundation/doc-compiler/stored-docs.mjs +63 -1
  426. package/foundation/doc-compiler/tree.d.mts +4 -84
  427. package/foundation/doc-compiler/tree.mjs +4 -62
  428. package/foundation/env/semver.mjs +3 -1
  429. package/foundation/fonts/font-stylesheet.d.mts +46 -0
  430. package/foundation/fonts/font-stylesheet.mjs +173 -0
  431. package/foundation/fs/cache-eviction.d.mts +21 -0
  432. package/foundation/fs/cache-eviction.mjs +73 -0
  433. package/foundation/fs/exact-codec.d.mts +12 -2
  434. package/foundation/fs/exact-codec.mjs +23 -6
  435. package/foundation/fs/file-protection.mjs +16 -5
  436. package/foundation/fs/gather-cache.d.mts +94 -4
  437. package/foundation/fs/gather-cache.mjs +671 -106
  438. package/foundation/fs/glob.d.mts +16 -0
  439. package/foundation/fs/glob.mjs +105 -0
  440. package/foundation/fs/jiti-cache.d.mts +19 -1
  441. package/foundation/fs/jiti-cache.mjs +130 -6
  442. package/foundation/fs/kept-tree.d.mts +80 -0
  443. package/foundation/fs/kept-tree.mjs +240 -0
  444. package/foundation/fs/listing-cache.d.mts +7 -0
  445. package/foundation/fs/listing-cache.mjs +10 -0
  446. package/foundation/fs/module-loader.d.mts +24 -2
  447. package/foundation/fs/module-loader.mjs +94 -21
  448. package/foundation/fs/path-safety.d.mts +11 -2
  449. package/foundation/fs/path-safety.mjs +108 -18
  450. package/foundation/fs/paths.d.mts +18 -0
  451. package/foundation/fs/paths.mjs +15 -2
  452. package/foundation/fs/read-record.d.mts +56 -7
  453. package/foundation/fs/read-record.mjs +280 -56
  454. package/foundation/fs/regular-file.d.mts +29 -0
  455. package/foundation/fs/regular-file.mjs +77 -0
  456. package/foundation/fs/stop-cleanup.d.mts +12 -0
  457. package/foundation/fs/stop-cleanup.mjs +66 -0
  458. package/foundation/identity/provider-identity.d.mts +6 -0
  459. package/foundation/identity/provider-identity.mjs +10 -1
  460. package/foundation/integrations/contribution-inventory.mjs +4 -3
  461. package/foundation/integrations/example-code.d.mts +63 -0
  462. package/foundation/integrations/example-code.mjs +416 -0
  463. package/foundation/integrations/integrations.d.mts +23 -1
  464. package/foundation/integrations/integrations.mjs +18 -1
  465. package/foundation/integrations/pack-state.d.mts +75 -0
  466. package/foundation/integrations/pack-state.mjs +314 -0
  467. package/foundation/integrations/public-imports.d.mts +9 -0
  468. package/foundation/integrations/public-imports.mjs +3 -2
  469. package/foundation/integrations/shipped-imports.d.mts +122 -0
  470. package/foundation/integrations/shipped-imports.mjs +497 -0
  471. package/foundation/integrations/validate-contributions.d.mts +0 -17
  472. package/foundation/integrations/validate-contributions.mjs +59 -333
  473. package/foundation/render/assets.mjs +52 -7
  474. package/foundation/render/charts.d.mts +78 -27
  475. package/foundation/render/charts.mjs +266 -90
  476. package/foundation/render/embedded-files.d.mts +6 -0
  477. package/foundation/render/embedded-files.mjs +25 -5
  478. package/foundation/render/embedded-imports.d.mts +70 -7
  479. package/foundation/render/embedded-imports.mjs +132 -41
  480. package/foundation/render/file-header.d.mts +66 -0
  481. package/foundation/render/file-header.mjs +118 -0
  482. package/foundation/render/host-answer.d.mts +18 -0
  483. package/foundation/render/host-answer.mjs +46 -0
  484. package/foundation/render/host-exit.d.mts +1 -0
  485. package/foundation/render/host-exit.mjs +6 -1
  486. package/foundation/render/html-reader.d.mts +55 -2
  487. package/foundation/render/html-reader.mjs +145 -26
  488. package/foundation/render/layers.d.mts +30 -0
  489. package/foundation/render/layers.mjs +158 -0
  490. package/foundation/render/markup-edits.d.mts +57 -0
  491. package/foundation/render/markup-edits.mjs +182 -0
  492. package/foundation/render/offline.d.mts +32 -0
  493. package/foundation/render/offline.mjs +56 -0
  494. package/foundation/render/page-host.mjs +29 -12
  495. package/foundation/render/page-worker.mjs +354 -21
  496. package/foundation/render/picture-chrome.d.mts +4 -0
  497. package/foundation/render/picture-chrome.mjs +192 -0
  498. package/foundation/render/picture-playwright.d.mts +4 -0
  499. package/foundation/render/picture-playwright.mjs +46 -0
  500. package/foundation/render/rebuild.mjs +2 -1
  501. package/foundation/render/render-page.d.mts +79 -5
  502. package/foundation/render/render-page.mjs +735 -109
  503. package/foundation/render/source-block.d.mts +85 -6
  504. package/foundation/render/source-block.mjs +211 -20
  505. package/foundation/render/ts-paths.d.mts +69 -6
  506. package/foundation/render/ts-paths.mjs +326 -40
  507. package/foundation/response/error-codes.d.mts +3 -1
  508. package/foundation/response/error-codes.d.ts +1 -0
  509. package/foundation/response/error-codes.doc.mjs +12 -1
  510. package/foundation/response/error-codes.mjs +11 -1
  511. package/foundation/response/response-types.doc.mjs +6 -6
  512. package/foundation/suggest/name-index.d.mts +148 -0
  513. package/foundation/suggest/name-index.mjs +317 -0
  514. package/foundation/suggest/other-command.d.mts +140 -0
  515. package/foundation/suggest/other-command.mjs +756 -0
  516. package/foundation/text/compare-text.d.mts +14 -0
  517. package/foundation/text/compare-text.mjs +68 -0
  518. package/foundation/text/css-escape.d.mts +18 -0
  519. package/foundation/text/css-escape.mjs +35 -0
  520. package/foundation/text/entry-names.d.mts +14 -0
  521. package/foundation/text/entry-names.mjs +14 -0
  522. package/foundation/text/string-utils.d.mts +46 -6
  523. package/foundation/text/string-utils.mjs +118 -20
  524. package/foundation/text/suggest-order.d.mts +47 -4
  525. package/foundation/text/suggest-order.mjs +174 -5
  526. package/foundation/xle/browser.d.mts +2 -2
  527. package/foundation/xle/expand.mjs +2 -1
  528. package/host/index.mjs +8 -6
  529. package/package.json +7 -6
@@ -0,0 +1,1630 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The theme editor's input normaliser: how a typed or saved thing and
5
+ * value are read before any check (Unicode spaces, delimiting quotes, a
6
+ * pasted declaration, JSON and copy debris, a font stack's families). Typed
7
+ * input (`set`, `undo`) and saved settings (`loadTheme`, the stored checks)
8
+ * both read through it.
9
+ * @position packages/cli/api/theme-edit — pure helpers, no environment access
10
+ */
11
+
12
+ import {
13
+ DIALS,
14
+ FONTS,
15
+ MODE_WORDS,
16
+ OPEN_FONTS,
17
+ fontStack,
18
+ wordTable,
19
+ } from './_tables.mjs';
20
+ import {colorProblem, hex, parseColor} from './_color.mjs';
21
+ import {sameKindValues, takesWholeNumbersOnly} from './_css.mjs';
22
+ import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
23
+
24
+ /**
25
+ * A value as CSS reads it, for every value type: every Unicode space
26
+ * (no-break, thin, ideographic…) a plain space and zero-width and format
27
+ * characters dropped, and quotes that delimit a value (curly ones, «», ‹›,
28
+ * full-width, backticks) straight. A straight-quoted CSS string keeps what
29
+ * it holds as written (`content: "it’s"`). Curly quotes pair by kind
30
+ * (double with double, single with single, in any of their shapes: „Inter“,
31
+ * ‚Inter‘); one left unpaired is read as the straight quote it stands for.
32
+ * @param {string} v
33
+ * @returns {string}
34
+ */
35
+ export function normalValueText(v) {
36
+ let out = '';
37
+ let plain = '';
38
+ const flush = () => {
39
+ out += plain
40
+ .replace(/[\u200B-\u200D\u2060\uFEFF]/g, '')
41
+ .replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' ');
42
+ plain = '';
43
+ };
44
+ for (let i = 0; i < v.length;) {
45
+ const c = v[i];
46
+ // A straight-quoted CSS string keeps everything inside it.
47
+ if (c === '"' || c === "'") {
48
+ let j = i + 1;
49
+ while (j < v.length && v[j] !== c) j += v[j] === '\\' ? 2 : 1;
50
+ if (j < v.length) {
51
+ flush();
52
+ out += v.slice(i, j + 1);
53
+ i = j + 1;
54
+ continue;
55
+ }
56
+ }
57
+ const kind = CURLY_DOUBLE.has(c)
58
+ ? CURLY_DOUBLE
59
+ : CURLY_SINGLE.has(c)
60
+ ? CURLY_SINGLE
61
+ : null;
62
+ /** @type {number} */
63
+ let j = -1;
64
+ if (kind) {
65
+ for (let k = i + 1; k < v.length; k++)
66
+ if (kind.has(v[k])) {
67
+ j = k;
68
+ break;
69
+ }
70
+ } else if (QUOTE_PAIRS[c]) j = v.indexOf(QUOTE_PAIRS[c], i + 1);
71
+ if (j > i) {
72
+ flush();
73
+ // What the quotes hold, as typed (`“ / ”` is a slash between
74
+ // spaces); a font family trims it (normalizeEntry).
75
+ const inner = v.slice(i + 1, j);
76
+ const single = kind === CURLY_SINGLE || c === '\uFF07';
77
+ const mark = single
78
+ ? inner.includes("'")
79
+ ? '"'
80
+ : "'"
81
+ : inner.includes('"')
82
+ ? "'"
83
+ : '"';
84
+ out += `${mark}${inner}${mark}`;
85
+ i = j + 1;
86
+ continue;
87
+ }
88
+ // An unpaired curly quote is the straight one it stands for.
89
+ plain += kind === CURLY_DOUBLE ? '"' : kind === CURLY_SINGLE ? "'" : c;
90
+ i += 1;
91
+ }
92
+ flush();
93
+ return out;
94
+ }
95
+
96
+ /** Curly double quotes, in every shape; any one closes any other. */
97
+ const CURLY_DOUBLE = new Set(['\u201C', '\u201D', '\u201E', '\u201F']);
98
+ /** Curly single quotes, in every shape. */
99
+ const CURLY_SINGLE = new Set(['\u2018', '\u2019', '\u201A', '\u201B']);
100
+ /** The other delimiting quotes and the one that closes each. */
101
+ /** @type {Record<string, string>} */
102
+ const QUOTE_PAIRS = {
103
+ '\u300C': '\u300D',
104
+ '\u300E': '\u300F',
105
+ '\u00AB': '\u00BB',
106
+ '\u00BB': '\u00AB',
107
+ '\u2039': '\u203A',
108
+ '\u203A': '\u2039',
109
+ '\uFF02': '\uFF02',
110
+ '\uFF07': '\uFF07',
111
+ '`': '`',
112
+ };
113
+
114
+ /** CSS functions whose names a value may write in any case. */
115
+ const CSS_FUNCTIONS =
116
+ /\b(light-dark|rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix|calc|min|max|clamp|var)\(/gi;
117
+
118
+ /**
119
+ * A value as meant when typed with escapes or in another notation: CSS
120
+ * function names in lower case (`LIGHT-DARK(` is `light-dark(`, as CSS reads
121
+ * it); a shell or JSON backslash before `#`, a quote or a space taken off;
122
+ * a JavaScript escape in a `content` string written as CSS writes it
123
+ * (`\u2022` is `\2022 `, `\n` a line break, `\t` a tab); and the JSON
124
+ * shapes a design-tokens file or an array writes (`{"$value": "#e11d48"}`,
125
+ * `{"value": 18, "unit": "px"}`, `["#e11d48"]`, `["Inter", "sans-serif"]`).
126
+ * @param {string} thing
127
+ * @param {string} value
128
+ * @returns {string}
129
+ */
130
+ export function escapesMeant(thing, value) {
131
+ let v = value;
132
+ const content = /^content$/i.test(thing);
133
+ if (content)
134
+ return (
135
+ v
136
+ .replace(
137
+ /\\u\{?([0-9a-f]{2,6})\}?/gi,
138
+ (_, h) => `\\${h.toUpperCase()} `,
139
+ )
140
+ // `\x` with four hex digits is written for the code point (as
141
+ // `\u`), with two for that character.
142
+ .replace(
143
+ /\\x([0-9a-f]{4}|[0-9a-f]{2})/gi,
144
+ (_, h) => `\\${h.toUpperCase()} `,
145
+ )
146
+ .replace(/\\n/g, '\\A ')
147
+ .replace(/\\t/g, '\\9 ')
148
+ .replace(/\\r/g, '\\D ')
149
+ );
150
+ v = v.replace(CSS_FUNCTIONS, f => f.toLowerCase());
151
+ // A JS escape of a printable character in a font family (`Inter\u0020
152
+ // Tight`) is that character, as CSS would read its own escape.
153
+ if (/font/i.test(thing))
154
+ v = v.replace(
155
+ /\\(?:u\{?([0-9a-f]{4,6})\}?|x([0-9a-f]{2}))/gi,
156
+ (m, u, x) => {
157
+ const c = String.fromCodePoint(parseInt(u ?? x, 16));
158
+ return /^[\p{L}\p{N} _-]$/u.test(c) ? c : m;
159
+ },
160
+ );
161
+ // (A JSON string holding escaped quotes is unwrapped whole later.)
162
+ if (!/^\s*"(?:[^"\\]|\\.)*"\s*$/.test(v)) v = v.replace(/\\([#"' ])/g, '$1');
163
+ else v = v.replace(/\\([# ])/g, '$1');
164
+ const t = v.trim();
165
+ if (/^[[{]/.test(t)) {
166
+ /** @type {any} */
167
+ let j;
168
+ try {
169
+ j = JSON.parse(t);
170
+ } catch {
171
+ // A list in single quotes, as a JS config writes it (`['Inter',
172
+ // 'serif']`): read like the JSON one.
173
+ const items =
174
+ /^\[\s*('(?:[^'\\]|\\.)*'\s*(?:,\s*'(?:[^'\\]|\\.)*'\s*)*),?\s*\]$/.exec(
175
+ t,
176
+ );
177
+ if (!items) return v;
178
+ j = [...items[1].matchAll(/'((?:[^'\\]|\\.)*)'/g)].map(x =>
179
+ x[1].replace(/\\(.)/g, '$1'),
180
+ );
181
+ }
182
+ /** @param {any} x */
183
+ const text = x =>
184
+ typeof x === 'string' || typeof x === 'number' ? String(x) : null;
185
+ if (Array.isArray(j) && j.length && j.every(x => text(x) != null)) {
186
+ if (j.length === 1) return String(j[0]);
187
+ if (/font/i.test(thing))
188
+ return j
189
+ .map(x =>
190
+ /\s/.test(String(x)) && !/^["']/.test(String(x))
191
+ ? `"${x}"`
192
+ : String(x),
193
+ )
194
+ .join(', ');
195
+ return v;
196
+ }
197
+ if (j && typeof j === 'object' && !Array.isArray(j)) {
198
+ const inner =
199
+ '$value' in j ? j.$value : 'value' in j ? j.value : undefined;
200
+ if (text(inner) != null)
201
+ return `${inner}${typeof j.unit === 'string' ? j.unit : ''}`;
202
+ // One labeled entry (`{"color": "#e11d48"}`) is read as the same
203
+ // label in its CSS form (`color: #e11d48`): one reader for both.
204
+ const keys = Object.keys(j);
205
+ if (
206
+ keys.length === 1 &&
207
+ /^(--)?[a-z][a-z0-9-]*$/i.test(keys[0]) &&
208
+ text(j[keys[0]]) != null
209
+ )
210
+ return `${keys[0]}: ${j[keys[0]]}`;
211
+ }
212
+ }
213
+ return v;
214
+ }
215
+
216
+ /**
217
+ * The thing and value a setting was typed as, put right before any check: a
218
+ * declaration pasted whole or split (`accent: #e11d48`, `--color-accent=red`,
219
+ * `font:inter`, `accent:` with the value next), a token typed with an em or
220
+ * en dash (`—color-accent`) or as `var(--color-accent)`, and the value's
221
+ * Unicode spaces. A thing it cannot read is left as typed.
222
+ * @param {string} thing
223
+ * @param {string | undefined} value
224
+ * @returns {{thing: string, value: string | undefined, dropped?: string, scope?: EntryScope}} `dropped`: a second declaration pasted after the first, which is not set; `scope`: the scope the editor's own printed line names
225
+ */
226
+ export function normalizeEntry(thing, value) {
227
+ let t = normalValueText(String(thing ?? '')).trim();
228
+ let v = value == null ? value : normalValueText(String(value));
229
+ // A pasted declaration (the whole of it in the thing, or the thing with
230
+ // its colon and the value next): its `;` and `!important` go with it.
231
+ let pasted = false;
232
+ // A JSON object around one entry (`{"accent": "#e11d48"}`), whole or
233
+ // split at its colon.
234
+ if ((v == null || v.trim() === '') && /^\{[\s\S]*\}$/.test(t))
235
+ t = t.slice(1, -1).trim().replace(/,\s*$/, '');
236
+ else if (t.startsWith('{') && typeof v === 'string' && /\}\s*$/.test(v)) {
237
+ t = t.slice(1).trim();
238
+ v = v.replace(/\s*\}\s*$/, '');
239
+ }
240
+ /** The scope the editor's own printed line names after its value. @type {EntryScope | undefined} */
241
+ let scope;
242
+ if (v == null || v.trim() === '') {
243
+ const m = /^(\S+?)\s*([:=])\s*(.+?)\s*;?\s*$/.exec(t);
244
+ if (m && !/^https?$/i.test(m[1])) {
245
+ t = m[1];
246
+ v = m[3];
247
+ pasted = true;
248
+ // The editor's own printed line (`corners = pill (whole theme)`,
249
+ // `opacity = 0.5 on card [dark only]`) pasted back: its scope goes
250
+ // with the setting, not into the value.
251
+ if (m[2] === '=') {
252
+ const printed = printedScope(v);
253
+ if (printed) {
254
+ v = printed.value;
255
+ scope = printed.scope;
256
+ }
257
+ }
258
+ }
259
+ }
260
+ // A thing ending in its colon or equals sign, the value given next.
261
+ if (/\s*[:=]+$/.test(t)) {
262
+ t = t.replace(/\s*[:=]+$/, '');
263
+ pasted = true;
264
+ }
265
+ // A thing in quotes, as a JSON or design-tokens file writes it
266
+ // (`"accent": "#e11d48"`).
267
+ const quotedThing = /^(["'])(.+)\1$/.exec(t);
268
+ if (quotedThing) {
269
+ t = quotedThing[2].trim();
270
+ pasted = true;
271
+ // Its value in JSON's double quotes is the string they hold
272
+ // (`"#e11d48"`, `"Inter, serif"`): the quotes are JSON's, for a font
273
+ // too; a family that needs its own quotes is written inside the string
274
+ // (`"\"Open Sans\", serif"`).
275
+ if (typeof v === 'string') {
276
+ const jv = /^\s*("(?:[^"\\]|\\.)*")\s*,?\s*$/.exec(v);
277
+ if (jv)
278
+ try {
279
+ v = String(JSON.parse(jv[1]));
280
+ } catch {
281
+ // Not a JSON string: read as typed.
282
+ }
283
+ }
284
+ }
285
+ // Dash-like characters where a token's two dashes go (an em or en dash,
286
+ // a non-breaking hyphen, a minus sign, a full-width hyphen, alone or
287
+ // mixed with hyphens): `--`.
288
+ t = t.replace(/^[-\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]+/, run =>
289
+ /[^-]/.test(run) ? '--' : run,
290
+ );
291
+ // A dash-like character inside a token's name is its hyphen.
292
+ if (t.startsWith('--'))
293
+ t = `--${t.slice(2).replace(/[\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]/g, '-')}`;
294
+ // A token typed as a var() reference.
295
+ const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(t);
296
+ if (ref) t = ref[1];
297
+ // A dial name written in another style (textSize, text_size, "text
298
+ // size", a dash-like character for its hyphen) is the dial.
299
+ if (
300
+ !t.startsWith('-') &&
301
+ /[_\s\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]|[a-z][A-Z]/.test(t)
302
+ ) {
303
+ const dial = t
304
+ .replace(/[_\s\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]+/g, '-')
305
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
306
+ .toLowerCase();
307
+ if (DIALS[dial]) t = dial;
308
+ }
309
+ if (typeof v === 'string') v = escapesMeant(t, v);
310
+ // A second declaration pasted after the first (`accent: red; text-size:
311
+ // 18`): the first is this setting.
312
+ /** A second declaration pasted after the first, which this does not set. @type {string | null} */
313
+ let dropped = null;
314
+ if (typeof v === 'string') {
315
+ const cut = withoutSecondDeclaration(v);
316
+ if (cut !== v)
317
+ dropped = v
318
+ .slice(cut.length)
319
+ .replace(/^\s*;\s*/, '')
320
+ .trim();
321
+ v = cut;
322
+ }
323
+ if (pasted && typeof v === 'string') {
324
+ v = v.replace(/\s*!\s*important\s*;?\s*$/i, '').replace(/;+\s*$/, '');
325
+ }
326
+ if (typeof v === 'string') v = withoutDebris(v);
327
+ // A font stack written as a JSON string (`"\\"Open Sans\\", serif"`): the
328
+ // stack it holds.
329
+ if (
330
+ typeof v === 'string' &&
331
+ /font/i.test(t) &&
332
+ /^"(?:[^"\\]|\\.)*"$/.test(v.trim()) &&
333
+ v.includes('\\"')
334
+ ) {
335
+ try {
336
+ const inner = JSON.parse(v.trim());
337
+ if (typeof inner === 'string') v = inner;
338
+ } catch {
339
+ // Not a JSON string.
340
+ }
341
+ }
342
+ // A font stack with its quotes escaped, as it sits inside a JSON or JS
343
+ // string (`\"Inter\", sans-serif`): the stack.
344
+ if (typeof v === 'string' && /font/i.test(t) && /\\["']/.test(v))
345
+ v = v.replace(/\\(["'])/g, '$1');
346
+ // A font family's name never starts or ends with a space: French quotes
347
+ // (« Inter », with a no-break or narrow no-break space) hold the name.
348
+ if (typeof v === 'string' && /font/i.test(t)) v = trimInsideQuotes(v);
349
+ return {
350
+ thing: t,
351
+ value: v,
352
+ ...(dropped ? {dropped} : {}),
353
+ ...(scope ? {scope} : {}),
354
+ };
355
+ }
356
+
357
+ /**
358
+ * @typedef {{on?: string, only?: boolean, when?: string, state?: string, mode?: 'light' | 'dark'}} EntryScope
359
+ */
360
+
361
+ /**
362
+ * The value and scope of the editor's own printed setting line after its
363
+ * `=` (`pill (whole theme)`, `0.5 on card only when sm :hover [dark only]`),
364
+ * as `describe` writes them; null when the text does not end in that form.
365
+ * @param {string} text
366
+ * @returns {{value: string, scope: EntryScope} | null}
367
+ */
368
+ function printedScope(text) {
369
+ const m =
370
+ /^(.+?)\s+(?:\(whole theme\)|on ([a-z][a-z0-9-]*)( only)?(?: when (\S+))?(?: :([a-z-]+))?)(?:\s+\[(light|dark) only\])?\s*$/.exec(
371
+ text,
372
+ );
373
+ if (!m) return null;
374
+ /** @type {EntryScope} */
375
+ const scope = {};
376
+ if (m[2]) scope.on = m[2];
377
+ if (m[3]) scope.only = true;
378
+ if (m[4]) scope.when = m[4];
379
+ if (m[5]) scope.state = m[5];
380
+ if (m[6] === 'light' || m[6] === 'dark') scope.mode = m[6];
381
+ return {value: m[1], scope};
382
+ }
383
+
384
+ /**
385
+ * A font stack's pieces, split on the commas outside quotes, with each
386
+ * piece's name and whether it was quoted; null when a quote is left open.
387
+ * @param {string} v
388
+ * @returns {Array<{name: string, quoted: boolean}> | null}
389
+ */
390
+ export function familyPieces(v) {
391
+ /** @type {Array<{name: string, quoted: boolean}>} */
392
+ const out = [];
393
+ let cur = '';
394
+ let quoted = false;
395
+ /** @type {string | null} */
396
+ let q = null;
397
+ let closed = false;
398
+ for (const c of String(v)) {
399
+ if (q) {
400
+ if (c === q) {
401
+ q = null;
402
+ closed = true;
403
+ } else cur += c;
404
+ continue;
405
+ }
406
+ if (c === '"' || c === "'") {
407
+ // A quote opening after text, or a second quoted name before a
408
+ // comma: not a stack of whole pieces.
409
+ if (cur.trim() || closed) return null;
410
+ q = c;
411
+ quoted = true;
412
+ continue;
413
+ }
414
+ // Text after a quoted name before its comma (`"Open Sans" serif`).
415
+ if (closed && c !== ',' && c.trim()) return null;
416
+ if (c === ',') {
417
+ out.push({name: cur.trim(), quoted});
418
+ cur = '';
419
+ quoted = false;
420
+ closed = false;
421
+ continue;
422
+ }
423
+ cur += c;
424
+ }
425
+ if (q) return null;
426
+ out.push({name: cur.trim(), quoted});
427
+ return out;
428
+ }
429
+
430
+ /**
431
+ * The families a typed font stack names: a trailing comma and empty pieces
432
+ * dropped, and a stack wrapped in one more pair of the quotes it uses
433
+ * inside (`""SF Mono", Monaco, monospace"`, as a JSON string) unwrapped.
434
+ * Null when the stack does not read.
435
+ * @param {string} v
436
+ * @returns {string[] | null}
437
+ */
438
+ export function familiesOf(v) {
439
+ let s = String(v)
440
+ .trim()
441
+ .replace(/,+\s*$/, '');
442
+ const w = /^(["'])([\s\S]*)\1$/.exec(s);
443
+ if (w && w[2].includes(w[1])) s = w[2].trim().replace(/,+\s*$/, '');
444
+ const pieces = familyPieces(s);
445
+ if (!pieces) return null;
446
+ return pieces.map(f => f.name).filter(Boolean);
447
+ }
448
+
449
+ /**
450
+ * A value with the debris of a bad copy taken off: a leading `=` or `:`, a
451
+ * trailing comma (a JSON or CSS list), and a quote or a closing bracket left
452
+ * over at either end. A value without any is returned as it was.
453
+ * @param {string} v
454
+ * @returns {string}
455
+ */
456
+ export function withoutDebris(v) {
457
+ let s = v.replace(/^\s*[=:]\s*/, '').replace(/\s*,+\s*$/, '');
458
+ // Quotes and brackets counted as CSS reads them: an escaped quote (\")
459
+ // is no quote, and a bracket inside a string is the string's.
460
+ const scan = (/** @type {string} */ t) => {
461
+ /** @type {Record<string, number>} */
462
+ const quotes = {'"': 0, "'": 0};
463
+ let open = 0;
464
+ let close = 0;
465
+ /** @type {string | null} */
466
+ let q = null;
467
+ for (let i = 0; i < t.length; i++) {
468
+ const c = t[i];
469
+ if (c === '\\') {
470
+ i++;
471
+ continue;
472
+ }
473
+ if (q) {
474
+ if (c === q) {
475
+ q = null;
476
+ quotes[c]++;
477
+ }
478
+ continue;
479
+ }
480
+ if (c === '"' || c === "'") {
481
+ q = c;
482
+ quotes[c]++;
483
+ } else if (c === '(') open++;
484
+ else if (c === ')') close++;
485
+ }
486
+ return {quotes, open, close};
487
+ };
488
+ for (const mark of /** @type {const} */ (['"', "'"])) {
489
+ if (scan(s).quotes[mark] % 2 === 1) {
490
+ if (s.endsWith(mark) && !s.endsWith(`\\${mark}`)) s = s.slice(0, -1);
491
+ else if (s.startsWith(mark)) s = s.slice(1);
492
+ }
493
+ }
494
+ const {open, close} = scan(s);
495
+ if (close > open && s.endsWith(')')) s = s.slice(0, -1);
496
+ return s === v.trim() ? v : s.trim();
497
+ }
498
+
499
+ /**
500
+ * A value without a second declaration pasted after it (`#e11d48;
501
+ * text-size: 18`): cut at the first `;` outside quotes that a `name:`
502
+ * follows. A `;` inside a quoted string (`"Tip; note: x"`) is the string's.
503
+ * @param {string} v
504
+ * @returns {string}
505
+ */
506
+ export function withoutSecondDeclaration(v) {
507
+ /** @type {string | null} */
508
+ let q = null;
509
+ for (let i = 0; i < v.length; i++) {
510
+ const c = v[i];
511
+ if (q) {
512
+ if (c === '\\') i++;
513
+ else if (c === q) q = null;
514
+ continue;
515
+ }
516
+ if (c === '"' || c === "'") q = c;
517
+ else if (
518
+ c === ';' &&
519
+ /^\s*[a-z-]+\s*:/i.test(v.slice(i + 1)) &&
520
+ // `light: red; dark: blue` is one value for two modes.
521
+ !/^\s*(?:light|dark)\s*:/i.test(v.slice(i + 1))
522
+ )
523
+ return v.slice(0, i);
524
+ }
525
+ return v;
526
+ }
527
+
528
+ /**
529
+ * A saved dial value read as typed input is (invisible or stray spaces,
530
+ * quotes around it, a pasted `corners: pill`, a trailing `;`, other
531
+ * letters): the value the dial may have meant.
532
+ * @param {string} dial
533
+ * @param {string} value
534
+ * @returns {string}
535
+ */
536
+ export function cleanDialValue(dial, value) {
537
+ const read = normalizeEntry(dial, value).value ?? '';
538
+ return read
539
+ .trim()
540
+ .replace(new RegExp(`^${dial.replace(/-/g, '\\-')}\\s*[:=]\\s*`, 'i'), '')
541
+ .replace(/\s*!\s*important\s*$/i, '')
542
+ .replace(/;+\s*$/, '')
543
+ .replace(/^(["'])(.*)\1$/, '$2')
544
+ .trim()
545
+ .toLowerCase();
546
+ }
547
+
548
+ /**
549
+ * A value with the spaces just inside each straight-quoted string taken off
550
+ * (`" Inter "` is "Inter"), for a font family, whose name holds none there.
551
+ * @param {string} v
552
+ * @returns {string}
553
+ */
554
+ export function trimInsideQuotes(v) {
555
+ const SP = '[\\s\\u00A0\\u202F\\u2000-\\u200A\\u3000]*';
556
+ return v.replace(
557
+ new RegExp(`(["'])${SP}((?:(?!\\1)[^\\\\]|\\\\.)*?)${SP}\\1`, 'g'),
558
+ '$1$2$1',
559
+ );
560
+ }
561
+
562
+ /**
563
+ * The other setting a dial's value is labeled with, when pasted with a
564
+ * label that names a different dial or a token (`neutral: #64748b` given
565
+ * to accent): that label and the value after it, else null. A label that
566
+ * names this dial, or a CSS property (`color: #e11d48`), is no other
567
+ * setting.
568
+ * @param {string} dial
569
+ * @param {string} value
570
+ * @returns {{thing: string, value: string} | null}
571
+ */
572
+ export function otherSettingLabel(dial, value) {
573
+ const m =
574
+ /^\s*["']?([a-z][a-z0-9_-]*|--[a-z0-9-]+)["']?\s*[:=]\s*["']?(.+?)["']?\s*;?\s*$/i.exec(
575
+ String(value),
576
+ );
577
+ if (!m) return null;
578
+ // A label in camelCase or snake_case (textSize, text_size) is the dial.
579
+ const label = m[1]
580
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
581
+ .replace(/_/g, '-')
582
+ .toLowerCase();
583
+ if (label === dial) return null;
584
+ if (!DIALS[label] && !label.startsWith('--')) return null;
585
+ return {thing: label, value: m[2]};
586
+ }
587
+
588
+ /**
589
+ * A light and a dark color typed as a pair: labeled (`light: red; dark:
590
+ * blue`), a JSON object (`{"light": "red", "dark": "blue"}`), or two colors
591
+ * with a slash or a comma between (`red / blue`, `red, blue`). Null when the
592
+ * value is no such pair; the caller checks that both are colors.
593
+ * @param {string} value
594
+ * @returns {{light: string, dark: string} | null}
595
+ */
596
+ export function colorPair(value) {
597
+ const v = String(value).trim();
598
+ const unq = (/** @type {string} */ x) =>
599
+ x
600
+ .trim()
601
+ .replace(/^(["'])(.*)\1$/, '$2')
602
+ .trim();
603
+ const labeled =
604
+ /^\{?\s*["']?(light|dark)["']?\s*[:=]\s*(.+?)\s*(?:[;,]\s*|\s+)["']?(light|dark)["']?\s*[:=]\s*(.+?)\s*;?\s*\}?$/i.exec(
605
+ v,
606
+ );
607
+ if (labeled && labeled[1].toLowerCase() !== labeled[3].toLowerCase()) {
608
+ const a = unq(labeled[2]);
609
+ const b = unq(labeled[4]);
610
+ return labeled[1].toLowerCase() === 'light'
611
+ ? {light: a, dark: b}
612
+ : {light: b, dark: a};
613
+ }
614
+ const two = /^([^\s,/()]+)\s*(?:\s\/\s|,)\s*([^\s,/()]+)$/.exec(v);
615
+ if (two) return {light: unq(two[1]), dark: unq(two[2])};
616
+ return null;
617
+ }
618
+
619
+ /**
620
+ * A value without the debris a copy brings along: a trailing `;`, a
621
+ * `!important`, a comment. One of the exact cleanups a repair may offer.
622
+ * @param {string} v
623
+ * @returns {string}
624
+ */
625
+ export function withoutCopyDebris(v) {
626
+ return String(v)
627
+ .replace(/\/\*[\s\S]*?\*\//g, '')
628
+ .replace(/\s*!\s*important\b/gi, '')
629
+ .replace(/[\s;]+$/, '')
630
+ .trim();
631
+ }
632
+
633
+ /** Number words, longest phrase first. */
634
+ export const NUMBER_WORDS = wordTable(
635
+ /** @type {Record<string, number>} */ ({
636
+ zero: 0,
637
+ one: 1,
638
+ two: 2,
639
+ three: 3,
640
+ four: 4,
641
+ five: 5,
642
+ six: 6,
643
+ seven: 7,
644
+ eight: 8,
645
+ nine: 9,
646
+ ten: 10,
647
+ eleven: 11,
648
+ twelve: 12,
649
+ thirteen: 13,
650
+ fourteen: 14,
651
+ fifteen: 15,
652
+ sixteen: 16,
653
+ seventeen: 17,
654
+ eighteen: 18,
655
+ nineteen: 19,
656
+ twenty: 20,
657
+ thirty: 30,
658
+ forty: 40,
659
+ fifty: 50,
660
+ sixty: 60,
661
+ seventy: 70,
662
+ eighty: 80,
663
+ ninety: 90,
664
+ hundred: 100,
665
+ }),
666
+ );
667
+
668
+ /**
669
+ * A whole number as typed: digits with any white space at the ends and a
670
+ * zero fraction (`" 3"`, `"3.0"`), or a number word (`"three"`); else null.
671
+ * @param {unknown} text
672
+ * @returns {number | null}
673
+ */
674
+ export function wholeNumberOf(text) {
675
+ const t = String(text ?? '')
676
+ .trim()
677
+ .toLowerCase();
678
+ if (/^[+-]?\d+(?:\.0+)?$/.test(t)) return Number(t);
679
+ return Object.hasOwn(NUMBER_WORDS, t) ? NUMBER_WORDS[t] : null;
680
+ }
681
+
682
+ /**
683
+ * Words with a documented reading on a CSS property: the exact value each
684
+ * one means. A repair may offer these for the word typed.
685
+ * @type {Record<string, Record<string, string>>}
686
+ */
687
+ export const PROPERTY_WORDS = wordTable({
688
+ opacity: {
689
+ half: '0.5',
690
+ 'half-transparent': '0.5',
691
+ opaque: '1',
692
+ solid: '1',
693
+ },
694
+ 'text-transform': {
695
+ caps: 'uppercase',
696
+ 'all-caps': 'uppercase',
697
+ upper: 'uppercase',
698
+ lower: 'lowercase',
699
+ title: 'capitalize',
700
+ 'no-caps': 'none',
701
+ },
702
+ 'border-radius': {
703
+ round: '9999px',
704
+ rounded: '9999px',
705
+ pill: '9999px',
706
+ circle: '50%',
707
+ square: '0',
708
+ },
709
+ });
710
+
711
+ /** Weight words beyond the headings dial's, as their numbers. */
712
+ export const WEIGHT_WORDS = wordTable(
713
+ /** @type {Record<string, string>} */ ({
714
+ thin: '100',
715
+ extralight: '200',
716
+ light: '300',
717
+ regular: '400',
718
+ normal: '400',
719
+ medium: '500',
720
+ semibold: '600',
721
+ bold: '700',
722
+ heavy: '800',
723
+ extrabold: '800',
724
+ ultrabold: '800',
725
+ black: '900',
726
+ }),
727
+ );
728
+
729
+ /**
730
+ * Tailwind's radius classes, as the corners value each one is.
731
+ * @type {Record<string, string>}
732
+ */
733
+ export const TAILWIND_RADIUS = wordTable({
734
+ 'rounded-none': 'square',
735
+ 'rounded-sm': '2px',
736
+ rounded: '4px',
737
+ 'rounded-md': '6px',
738
+ 'rounded-lg': '8px',
739
+ 'rounded-xl': '12px',
740
+ 'rounded-2xl': '16px',
741
+ 'rounded-3xl': '24px',
742
+ 'rounded-full': 'pill',
743
+ });
744
+
745
+ /** Words for more or less room, as the spacing rung each one means. */
746
+ export const DENSITY_WORDS = wordTable(
747
+ /** @type {Record<string, string>} */ ({
748
+ airy: 'roomy',
749
+ loose: 'roomy',
750
+ relaxed: 'roomy',
751
+ comfortable: 'roomy',
752
+ open: 'roomy',
753
+ sparse: 'roomy',
754
+ generous: 'roomy',
755
+ dense: 'compact',
756
+ cramped: 'compact',
757
+ condensed: 'compact',
758
+ packed: 'compact',
759
+ }),
760
+ );
761
+
762
+ /**
763
+ * A typed value as the repair gate reads it, in one reading: escapes and
764
+ * full-width characters as the characters they are, a letter O inside a
765
+ * number as a zero, a comma between digits as a decimal point (or before
766
+ * exactly three digits, after a whole number other than 0, a thousands
767
+ * mark), and without what is not the value: quotes and braces around it, a
768
+ * label before it (`accent: red`), a flag inside it (`--mode dark`) or a
769
+ * flag's label after it (`mode: dark`), copy debris (`;`, `!important`,
770
+ * comments), and the axes of a Google Fonts family spec (`Inter:wght@400`
771
+ * is the family Inter).
772
+ * @param {string} typed
773
+ * @param {{thousands?: boolean}} [opts] `thousands` for a setting whose
774
+ * numbers are weights (see commaNumbers)
775
+ * @returns {string}
776
+ */
777
+ export function typedReading(typed, {thousands = false} = {}) {
778
+ let t = String(typed ?? '')
779
+ .replace(/\\(?:u\{?([0-9a-f]{4,6})\}?|x([0-9a-f]{2}))/gi, (_, u, x) =>
780
+ String.fromCodePoint(parseInt(u ?? x, 16)),
781
+ )
782
+ .replace(/\\(?=[#"' ])/g, '')
783
+ .normalize('NFKC')
784
+ .trim();
785
+ t = t
786
+ // A mode's label in any spelling (`dark mode: red`), before the
787
+ // trailing-label reading can take `mode: red` for one.
788
+ .replace(
789
+ /^\s*\{?\s*["']?(?:(?:light|dark)[\s_-]*mode|mode[\s_-]*(?:light|dark))["']?\s*[:=]\s*/i,
790
+ '',
791
+ )
792
+ .replace(
793
+ /\s+--(mode|state|on|when)(?:\s*=\s*|\s+)("[^"]*"|'[^']*'|\S+)/gi,
794
+ '',
795
+ )
796
+ .replace(
797
+ /\s+(mode|theme|state|part|on|variant|size|when)\s*[:=]\s*[a-z][a-z0-9:-]*\s*;?\s*$/i,
798
+ '',
799
+ );
800
+ t = withoutCopyDebris(t)
801
+ // A flag's label before the value (`state=hover 4px`).
802
+ .replace(
803
+ /^(mode|theme|state|part|on|variant|size|when)\s*[:=]\s*[a-z][a-z0-9:-]*\s+(?=\S)/i,
804
+ '',
805
+ );
806
+ const spec = /^([a-z][a-z +]*):(?:ital,)?(?:wght|ital)@/i.exec(t);
807
+ if (spec) t = spec[1].replace(/\+/g, ' ');
808
+ const labeledPair = colorPair(t);
809
+ t =
810
+ labeledPair &&
811
+ !colorProblem(labeledPair.light) &&
812
+ !colorProblem(labeledPair.dark)
813
+ ? t
814
+ : t.replace(
815
+ /^\s*\{?\s*["']?(?:--)?[a-z][a-z0-9 _-]*["']?\s*[:=](?!\/\/)\s*/i,
816
+ '',
817
+ );
818
+ t = t
819
+ .replace(/["']?\s*\}\s*$/, '')
820
+ .replace(
821
+ /^(["'`\u201C\u2018\u300C\u300E\u00AB])(.*?)(["'`\u201D\u2019\u300D\u300F\u00BB])$/,
822
+ '$2',
823
+ )
824
+ .replace(/,\s*$/, '')
825
+ .trim();
826
+ t = commaNumbers(
827
+ t
828
+ .replace(/(\d)([oO]+)(?![a-z])/g, (_, d, os) => d + '0'.repeat(os.length))
829
+ // A dot after a number's digits (`18.`, `16.px`) is no part of it, and
830
+ // a unit split off by a space (`20 px`) is its number's.
831
+ .replace(/(\d)\.(?=[a-z%]|\s|$)/gi, '$1')
832
+ .replace(/(\d)\s+(px|rem|em|pt|%)(?![a-z])/gi, '$1$2'),
833
+ thousands,
834
+ )
835
+ .replace(/\b0x([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})\b/gi, '#$1')
836
+ .toLowerCase();
837
+ // An app's own variable with a fallback (`var(--brand, #e11d48)`) is the
838
+ // fallback; Tailwind's arbitrary value (`rounded-[12px]`) is the value.
839
+ t = t
840
+ .replace(/^var\(\s*--[a-z0-9-]+\s*,\s*(.+)\)$/, '$1')
841
+ .replace(/^[a-z]+(?:-[a-z]+)?-\[(.+)\]$/, '$1');
842
+ // A light and a dark color typed as a pair (`light: red; dark: blue`,
843
+ // `red / blue`) is that light-dark() pair.
844
+ // Both halves colors: `Inter, 600` is a family list, no pair.
845
+ const pair = colorPair(t);
846
+ return pair && !colorProblem(pair.light) && !colorProblem(pair.dark)
847
+ ? `light-dark(${pair.light}, ${pair.dark})`
848
+ : t;
849
+ }
850
+
851
+ /**
852
+ * A text with each comma between digits, outside parentheses, read as a
853
+ * number mark: a decimal point (`1,5rem`, `1,125rem`, `0,500`), or a
854
+ * thousands mark before exactly three digits after a whole number other
855
+ * than 0 (`1,000`) where the setting's numbers are whole thousands (a
856
+ * weight, 1 to 1000) or the number is a pixel length (`1,200px`: no pixel
857
+ * length is written to a thousandth). Inside a function (`rgb(255,0,0)`) a
858
+ * comma separates arguments.
859
+ * @param {string} text
860
+ * @param {boolean} [thousands] whether the setting's numbers are weights
861
+ * @returns {string}
862
+ */
863
+ export function commaNumbers(text, thousands = false) {
864
+ let depth = 0;
865
+ let out = '';
866
+ let plain = '';
867
+ const flush = () => {
868
+ // (A number starts a word: the digits of a hex color or of a word
869
+ // before a comma are no number.)
870
+ out += plain.replace(
871
+ /(?<![\w#.])(\d+),(\d+)(?![\d.,])(?=(px\b)?)/gi,
872
+ (_, a, b, px) =>
873
+ (thousands || px) && b.length === 3 && !/^0+$/.test(a)
874
+ ? `${a}${b}`
875
+ : `${a}.${b}`,
876
+ );
877
+ plain = '';
878
+ };
879
+ for (const c of String(text)) {
880
+ if (c === '(') {
881
+ if (depth === 0) flush();
882
+ depth += 1;
883
+ }
884
+ if (depth > 0) out += c;
885
+ else plain += c;
886
+ if (c === ')' && depth > 0) depth -= 1;
887
+ }
888
+ flush();
889
+ return out;
890
+ }
891
+
892
+ /**
893
+ * Whether a comma between a setting's digits groups thousands: its numbers
894
+ * are weights (whole hundreds up to 1000) or the property takes only whole
895
+ * numbers (z-index, order), so no comma there can be a decimal one.
896
+ * @param {string} thing
897
+ */
898
+ export const thousandsSetting = thing => {
899
+ const t = String(thing).toLowerCase();
900
+ return (
901
+ /^(font-weight|headings)$|^--font-weight/.test(t) ||
902
+ (/^[a-z][a-z-]*$/.test(t) && takesWholeNumbersOnly(t))
903
+ );
904
+ };
905
+
906
+ /**
907
+ * A state as CSS writes it, from any case or spelling of its words
908
+ * (`Hover`, `:hover`, `focusVisible`, `focus_visible`, `focus visible`): the
909
+ * one state reader, for a typed `--state` and a saved entry's state alike.
910
+ * @param {string} text
911
+ * @returns {string}
912
+ */
913
+ export function stateSpelling(text) {
914
+ return String(text)
915
+ .trim()
916
+ .replace(/^:+/, '')
917
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
918
+ .replace(/[\s_]+/g, '-')
919
+ .toLowerCase();
920
+ }
921
+
922
+ /**
923
+ * The one mode a word names, or null: light or dark, written as a mode
924
+ * value names one (`dark-only`), with the word mode (`darkmode`, `dark
925
+ * mode`, `mode dark`), or as a word for it (MODE_WORDS: night, day). The
926
+ * one mode reader: the `--mode` flag, a mode label in a value, a saved
927
+ * entry's mode and the settings file's mode all read it.
928
+ * @param {unknown} text
929
+ * @returns {'light' | 'dark' | null}
930
+ */
931
+ export function modeWord(text) {
932
+ const w = String(text ?? '')
933
+ .trim()
934
+ .toLowerCase()
935
+ .replace(/[\s_]+/g, '-');
936
+ const m = /^(?:(light|dark)(?:-?only|-?mode)?|mode-?(light|dark))$/.exec(w);
937
+ if (m) return /** @type {'light' | 'dark'} */ (m[1] ?? m[2]);
938
+ return MODE_WORDS[w] ?? null;
939
+ }
940
+
941
+ /**
942
+ * A base as written in any of its names: its package (`@astryxdesign/
943
+ * theme-neutral`, `theme-neutral`), its export (`neutralTheme`), or with
944
+ * the word theme (`neutral-theme`, `neutral theme`), in any case. The one
945
+ * reading `set`, `new` and the settings file share; the word as read (a
946
+ * base name or not).
947
+ * @param {unknown} v
948
+ * @returns {string}
949
+ */
950
+ export function baseWord(v) {
951
+ return (
952
+ String(v ?? '')
953
+ .trim()
954
+ // A path names the package its last part does
955
+ // (`./node_modules/@astryxdesign/theme-neutral` is theme-neutral).
956
+ .replace(/[\\/]+$/, '')
957
+ .replace(/^.*[\\/]/, '')
958
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
959
+ .toLowerCase()
960
+ .replace(/[\s_]+/g, '-')
961
+ .replace(/^(@astryxdesign\/)?theme-|-theme$/g, '')
962
+ );
963
+ }
964
+
965
+ /**
966
+ * The one reading of a yes/no word, for a flag given a value (`--only=on`)
967
+ * and a saved `only`: the documented spellings of yes and no, or a typo of
968
+ * one of them (`ture`); null for any other word, which is neither.
969
+ * @param {unknown} word
970
+ * @returns {boolean | null}
971
+ */
972
+ export function booleanWord(word) {
973
+ if (typeof word === 'boolean') return word;
974
+ const w = String(word ?? '')
975
+ .trim()
976
+ .toLowerCase();
977
+ const YES = ['true', 'yes', 'y', 'on', '1'];
978
+ const NO = ['false', 'no', 'n', 'off', '0'];
979
+ if (YES.includes(w)) return true;
980
+ if (NO.includes(w)) return false;
981
+ const near = [...YES, ...NO].filter(x => x.length > 3 && typoNear(w, x));
982
+ const read = [...new Set(near.map(x => YES.includes(x)))];
983
+ return read.length === 1 ? read[0] : null;
984
+ }
985
+
986
+ /** The CSS functions a value is written in, whose names carry no value. */
987
+ const FORM =
988
+ /\b(?:light-dark|var|calc|(?:repeating-)?(?:linear|radial|conic)-gradient)\(/g;
989
+
990
+ /**
991
+ * The tokens of a value: its words and numbers in order, the names of the
992
+ * functions it is written in out.
993
+ * @param {string} text already read (typedReading) or as offered
994
+ * @returns {string[]}
995
+ */
996
+ function tokensOf(text) {
997
+ return (
998
+ String(text).toLowerCase().replace(FORM, '(').match(SIGNED_OR_WORD) ?? []
999
+ );
1000
+ }
1001
+
1002
+ /**
1003
+ * A token: a number with its minus sign (a sign is one at the start, or
1004
+ * after a space, a parenthesis or a comma: `-8px`, `calc(-1 * 4px)`, never
1005
+ * the minus of `1rem-2px`), or a word or number.
1006
+ */
1007
+ const SIGNED_OR_WORD =
1008
+ /(?<![a-z0-9.%)])-(?=\.?\d)\d*\.?\d+(?:e[+-]?\d+)?[a-z%]*|[a-z0-9.%]+/g;
1009
+
1010
+ /** @param {string} w */
1011
+ const numberOf = w => {
1012
+ const m = /^(-?\d*\.?\d+(?:e[+-]?\d+)?)(px|rem|em|pt|%)?$/.exec(w);
1013
+ return m ? {n: Number(m[1]), unit: m[2] ?? ''} : null;
1014
+ };
1015
+
1016
+ /**
1017
+ * Whether two tokens are one: the same word, or the same number with a
1018
+ * unit added or taken off (`1.5` and `1.5px`; the vet checks the setting
1019
+ * takes it).
1020
+ * @param {string} a @param {string} b
1021
+ */
1022
+ const sameToken = (a, b) => {
1023
+ if (a === b) return true;
1024
+ const x = numberOf(a);
1025
+ const y = numberOf(b);
1026
+ return Boolean(x && y && x.n === y.n && (!x.unit || !y.unit));
1027
+ };
1028
+
1029
+ /**
1030
+ * The numbers one typed token may be read as, each exact: as it is, rem or
1031
+ * em in px (x16), pt in px (x4/3), a percent as a share of one or of the
1032
+ * 16px base size, a share of one as a percent.
1033
+ * @param {string} w
1034
+ * @returns {Set<string>}
1035
+ */
1036
+ function numberReadings(w) {
1037
+ const r2 = (/** @type {number} */ x) => String(Math.round(x * 100) / 100);
1038
+ const m = numberOf(w);
1039
+ /** @type {Set<string>} */
1040
+ const out = new Set();
1041
+ if (!m) return out;
1042
+ out.add(r2(m.n));
1043
+ if (m.unit === 'rem' || m.unit === 'em') out.add(r2(m.n * 16));
1044
+ if (m.unit === 'pt') out.add(r2((m.n * 4) / 3));
1045
+ if (m.unit === '%') {
1046
+ out.add(r2(m.n / 100));
1047
+ out.add(r2((m.n * 16) / 100));
1048
+ }
1049
+ if (!m.unit && m.n > 0 && m.n < 1) out.add(r2(m.n * 100));
1050
+ return out;
1051
+ }
1052
+
1053
+ /**
1054
+ * Whether the numbers of `offered` are the numbers of the whole typed
1055
+ * value written another exact way: position by position (numberReadings),
1056
+ * or one number that is a calc() of the typed lengths worked out. The rest
1057
+ * of `offered` is units and form words only.
1058
+ * @param {string} offered
1059
+ * @param {string} t the typed value, read
1060
+ */
1061
+ function numbersEqual(offered, t) {
1062
+ // A number with its sign (see SIGNED_OR_WORD): -8px is never 8px.
1063
+ const NUM =
1064
+ /(?<![a-z0-9.%)])[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?|(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;
1065
+ const rest = offered
1066
+ .replace(NUM, '')
1067
+ .replace(/px|rem|em|%|[\s(),/*+-]|calc|var/g, '');
1068
+ const want = offered.match(NUM)?.map(Number) ?? [];
1069
+ if (!want.length || rest) return false;
1070
+ const r2 = (/** @type {number} */ x) => String(Math.round(x * 100) / 100);
1071
+ const typedNumbers = (
1072
+ t.match(
1073
+ /(?<![a-z0-9.%)])-?\d*\.?\d+(?:e[+-]?\d+)?(?:px|rem|em|pt|%)?|\d*\.?\d+(?:e[+-]?\d+)?(?:px|rem|em|pt|%)?/gi,
1074
+ ) ?? []
1075
+ ).map(numberReadings);
1076
+ // The typed value is numbers only (any words in it are read elsewhere).
1077
+ if (
1078
+ tokensOf(t).every(w => numberOf(w)) &&
1079
+ typedNumbers.length === want.length &&
1080
+ want.every((w, i) => typedNumbers[i].has(r2(w)))
1081
+ )
1082
+ return true;
1083
+ if (want.length !== 1) return false;
1084
+ const inner = /^\s*calc\(([^()]*)\)\s*$/i.exec(t)?.[1];
1085
+ if (!inner) return false;
1086
+ const scale =
1087
+ /^\s*(\d*\.?\d+)\s*(px|rem|em)?\s*([*/])\s*(\d*\.?\d+)\s*$/i.exec(inner);
1088
+ if (scale) {
1089
+ const a = Number(scale[1]) * (/r?em/i.test(scale[2] ?? '') ? 16 : 1);
1090
+ return (
1091
+ r2(scale[3] === '*' ? a * Number(scale[4]) : a / Number(scale[4])) ===
1092
+ r2(want[0])
1093
+ );
1094
+ }
1095
+ if (/[*/]/.test(inner)) return false;
1096
+ let total = 0;
1097
+ for (const m of inner.matchAll(/([+-]?)\s*(\d*\.?\d+)\s*(px|rem|em)?/gi)) {
1098
+ const x = Number(m[2]) * (/r?em/i.test(m[3] ?? '') ? 16 : 1);
1099
+ total += m[1] === '-' ? -x : x;
1100
+ }
1101
+ return r2(total) === r2(want[0]);
1102
+ }
1103
+
1104
+ /**
1105
+ * Documented readings: each typed word and the exact value it means,
1106
+ * registered by the table that documents it (a dial's words, a Tailwind
1107
+ * class, a property word). A repair may offer only these for a word that
1108
+ * was not typed as the value.
1109
+ * @type {Map<string, Set<string>>}
1110
+ */
1111
+ const READINGS = new Map();
1112
+
1113
+ /**
1114
+ * Register a documented table's readings with the repair allowlist.
1115
+ * @param {Iterable<[string, string]>} pairs typed word, value it means
1116
+ */
1117
+ export function documentReadings(pairs) {
1118
+ for (const [w, v] of pairs) {
1119
+ const k = String(w).trim().toLowerCase();
1120
+ if (!READINGS.has(k)) READINGS.set(k, new Set());
1121
+ /** @type {Set<string>} */ (READINGS.get(k)).add(String(v).toLowerCase());
1122
+ }
1123
+ }
1124
+
1125
+ /**
1126
+ * Documented numeric tables (a rung and its number), each for the settings
1127
+ * that document it, registered where it is defined: a number typed for one
1128
+ * of those settings may be offered as its nearest rung.
1129
+ * @type {Array<{things: string[], table: Array<[string, number]>, domain: [number, number]}>}
1130
+ */
1131
+ const NUMERIC_TABLES = [];
1132
+
1133
+ /**
1134
+ * Register a documented numeric table with the repair allowlist.
1135
+ * @param {string[]} things the settings whose values the table reads (a
1136
+ * name ending in `*` names every setting it starts)
1137
+ * @param {Array<[string, number]>} table
1138
+ * @param {[number, number]} [domain] the numbers the table reads (by
1139
+ * default every number)
1140
+ */
1141
+ export function documentNumericTable(
1142
+ things,
1143
+ table,
1144
+ domain = [-Infinity, Infinity],
1145
+ ) {
1146
+ if (table.length) NUMERIC_TABLES.push({things, table, domain});
1147
+ }
1148
+
1149
+ /**
1150
+ * Documented ranges: a number typed past either end of a setting's range
1151
+ * may be offered as that end.
1152
+ * @type {Array<{things: string[], min: number, max: number}>}
1153
+ */
1154
+ const RANGES = [];
1155
+
1156
+ /**
1157
+ * The documented words a typed word may be a typo of, item by item in a
1158
+ * list (the CSS generic families, the font presets), registered where each
1159
+ * list is defined.
1160
+ * @type {Set<string>}
1161
+ */
1162
+ const TYPO_WORDS = new Set();
1163
+
1164
+ /**
1165
+ * Register documented words a typed list item may be a typo of.
1166
+ * @param {Iterable<string>} words
1167
+ */
1168
+ export function documentTypoWords(words) {
1169
+ for (const w of words) TYPO_WORDS.add(String(w).toLowerCase());
1170
+ }
1171
+
1172
+ /**
1173
+ * Register a setting's documented range with the repair allowlist.
1174
+ * @param {string[]} things as for documentNumericTable
1175
+ * @param {number} min
1176
+ * @param {number} max
1177
+ */
1178
+ export function documentRange(things, min, max) {
1179
+ RANGES.push({things, min, max});
1180
+ }
1181
+
1182
+ /**
1183
+ * Whether a registered setting list names a setting.
1184
+ * @param {string[]} things
1185
+ * @param {string} key
1186
+ */
1187
+ const names = (things, key) =>
1188
+ things.some(t =>
1189
+ t.endsWith('*') ? key.startsWith(t.slice(0, -1)) : t === key,
1190
+ );
1191
+
1192
+ /**
1193
+ * Values a setting documents as its own fallback, which a refusal may
1194
+ * offer whatever was typed: no base, the modes.
1195
+ * @type {Record<string, string[]>}
1196
+ */
1197
+ const DECLARED_VALUES = wordTable({
1198
+ base: ['none'],
1199
+ mode: ['both', 'light-only', 'dark-only'],
1200
+ });
1201
+
1202
+ /** The dials with a scale, which `more` and `less` step. */
1203
+ const SCALED_DIALS = Object.keys(DIALS).filter(d =>
1204
+ String(DIALS[d].values ?? '')
1205
+ .split('|')
1206
+ .includes('more'),
1207
+ );
1208
+
1209
+ /**
1210
+ * What a suggested value reads of the typed value: `true` when it is the
1211
+ * whole value under one of the gate's declared sources, an array of the
1212
+ * typed tokens it carries when it carries only part of them (one setting
1213
+ * of a value that holds several, as `Inter 600` holds a family and a
1214
+ * weight), or `false` when it reads nothing typed.
1215
+ *
1216
+ * The declared sources: (1) the value typed, under the exact readings of
1217
+ * typedReading, sameToken and numbersEqual, the words joined into a CSS
1218
+ * color name (`dark red` is darkred), or the color the typed color is
1219
+ * (rgb() as its hex, a see-through color opaque); (2) a documented table
1220
+ * registered with documentReadings, documentNumericTable or documentRange;
1221
+ * (3) the theme's own saved value of the line's setting, for a setting
1222
+ * other than the one typed (a keep or unlock line); (4) the setting's
1223
+ * documented fallback, or a step (`more`, `less`) on a dial with a scale,
1224
+ * offered for that dial or one of its tokens; (5) the correction of a
1225
+ * typo (typoOf); (6) the typed value with each color written as one mode's
1226
+ * half of `light-dark()` (a shadow's color for one mode, which no color
1227
+ * longhand holds), the other half anything. Several values of one kind typed for a setting that takes
1228
+ * one (`1.5 2`) may be read as the first.
1229
+ * @param {{offered: string, typed: string, thing?: string, typedThing?: string, saved?: Map<string, string[]>, mode?: string}} line
1230
+ * @returns {true | number[] | {oneOf: number[]} | false}
1231
+ */
1232
+ export function readsTyped({
1233
+ offered,
1234
+ typed,
1235
+ thing = '',
1236
+ typedThing = '',
1237
+ saved,
1238
+ mode = '',
1239
+ }) {
1240
+ const o = String(offered)
1241
+ .trim()
1242
+ .replace(/^(["'])(.*)\1$/, '$2')
1243
+ .toLowerCase();
1244
+ const key = String(thing).toLowerCase();
1245
+ const typedKey = String(typedThing || thing).toLowerCase();
1246
+ const t = typedReading(listWords(typedKey, typed), {
1247
+ thousands: thousandsSetting(typedKey),
1248
+ });
1249
+ const T = tokensOf(t);
1250
+ const O = tokensOf(o);
1251
+ // (1) The value typed.
1252
+ if (
1253
+ O.length &&
1254
+ O.length === T.length &&
1255
+ O.every((w, i) => sameToken(w, T[i]))
1256
+ )
1257
+ return true;
1258
+ // (6) The typed color as one mode's half of light-dark(), every pair
1259
+ // read as the same mode's half.
1260
+ for (const side of [0, 1]) {
1261
+ const halves = o.replace(
1262
+ /light-dark\(\s*([^,()]+(?:\([^()]*\))?)\s*,\s*([^,()]+(?:\([^()]*\))?)\s*\)/g,
1263
+ (_, light, dark) => String(side === 0 ? light : dark).trim(),
1264
+ );
1265
+ const H = halves === o ? [] : tokensOf(halves);
1266
+ if (
1267
+ H.length &&
1268
+ H.length === T.length &&
1269
+ H.every((w, i) => sameToken(w, T[i]))
1270
+ )
1271
+ return true;
1272
+ }
1273
+ // Words joined into one name (`dark red` is darkred); numbers are never
1274
+ // joined (`12 16px` is two sizes, not 1216px).
1275
+ if (
1276
+ O.length === 1 &&
1277
+ T.length > 1 &&
1278
+ T.every(w => /^[a-z]+$/.test(w)) &&
1279
+ O[0] === T.join('')
1280
+ )
1281
+ return true;
1282
+ if (numbersEqual(o, t)) return true;
1283
+ // Two bare numbers typed with a comma between, offered as the slash pair
1284
+ // a grammar takes (`16,9` is `16 / 9`): the comma separated them.
1285
+ {
1286
+ const pair = /^\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*$/.exec(
1287
+ String(typed).replace(/^(["'])(.*)\1$/, '$2'),
1288
+ );
1289
+ if (pair && o.replace(/\s+/g, '') === `${pair[1]}/${pair[2]}`) return true;
1290
+ }
1291
+ // (5) A typo of a documented word in a list, item by item (`Inter,
1292
+ // san-serif` is `Inter, sans-serif`; `sytem` is the system font).
1293
+ {
1294
+ const ti = t.split(',').map(x => x.trim());
1295
+ const oi = o.split(',').map(x => x.trim());
1296
+ const bare = (/** @type {string} */ x) => x.replace(/[\s_-]+/g, '');
1297
+ const same = (/** @type {string} */ a, /** @type {string} */ b) => {
1298
+ const A = tokensOf(a);
1299
+ const B = tokensOf(b);
1300
+ return A.length === B.length && A.every((w, i) => sameToken(w, B[i]));
1301
+ };
1302
+ if (
1303
+ ti.length === oi.length &&
1304
+ oi.some((x, i) => !same(x, ti[i])) &&
1305
+ oi.every(
1306
+ (x, i) =>
1307
+ same(x, ti[i]) ||
1308
+ (TYPO_WORDS.has(x) &&
1309
+ (bare(x) === bare(ti[i]) ||
1310
+ typoNear(ti[i], x) ||
1311
+ typoNear(bare(ti[i]), bare(x)))),
1312
+ )
1313
+ )
1314
+ return true;
1315
+ }
1316
+ const color = parseColor(t);
1317
+ if (
1318
+ /^#[0-9a-f]{3,8}$/.test(o) &&
1319
+ (color ? hex(color) === o : colorProblem(t)?.opaque === o)
1320
+ )
1321
+ return true;
1322
+ // One half of a light and a dark pair: for the line that sets that mode,
1323
+ // or, as the light one, for a color dial, which makes both modes from
1324
+ // one color.
1325
+ const half = /^light-dark\(\s*([^,()]+?)\s*,\s*([^,()]+?)\s*\)$/.exec(t);
1326
+ if (half) {
1327
+ const [light, dark] = [half[1], half[2]];
1328
+ const only = /^(light|dark)-only$/.exec(saved?.get('mode')?.[0] ?? '')?.[1];
1329
+ const shown = mode || only || '';
1330
+ if (shown === 'dark' ? o === dark : shown === 'light' ? o === light : false)
1331
+ return true;
1332
+ if (o === light && DIALS[key] && !key.startsWith('--')) return true;
1333
+ }
1334
+ // A base named by its package (@astryxdesign/theme-butter is butter).
1335
+ if (
1336
+ key === 'base' &&
1337
+ [
1338
+ t,
1339
+ String(typed)
1340
+ .trim()
1341
+ .replace(/^(["'])(.*)\1$/, '$2'),
1342
+ ].some(x => baseWord(x) === o)
1343
+ )
1344
+ return true;
1345
+ // (2) A documented reading of the whole value.
1346
+ const whole = [t, t.replace(/\s+/g, '-'), t.replace(/[\s-]+/g, '')];
1347
+ if (whole.some(k => READINGS.get(k)?.has(o))) return true;
1348
+ // A scale factor written as the dial's help writes it (x0.75) is that
1349
+ // number.
1350
+ const n = T.length === 1 ? numberOf(T[0].replace(/^x(?=\.?\d)/, '')) : null;
1351
+ if (n) {
1352
+ for (const {things, table, domain} of NUMERIC_TABLES)
1353
+ if (names(things, key) && n.n >= domain[0] && n.n <= domain[1]) {
1354
+ const [rung] = table.reduce((a, b) =>
1355
+ Math.abs(b[1] - n.n) < Math.abs(a[1] - n.n) ? b : a,
1356
+ );
1357
+ if (rung === o) return true;
1358
+ }
1359
+ for (const {things, min, max} of RANGES)
1360
+ if (names(things, key))
1361
+ // Past an end is that end; a minus sign is no amount past the low
1362
+ // end (-700 is no weight 1).
1363
+ if (
1364
+ (n.n > max && o === String(max)) ||
1365
+ (n.n < min && n.n >= 0 && o === String(min))
1366
+ )
1367
+ return true;
1368
+ // A radius at or below zero is square; at or past half, or 1000px, pill.
1369
+ const signed = Number(/^-?\d*\.?\d+/.exec(t)?.[0] ?? NaN);
1370
+ if (key === 'corners' && o === 'square' && signed <= 0) return true;
1371
+ if (
1372
+ key === 'corners' &&
1373
+ o === 'pill' &&
1374
+ ((n.unit === '%' && n.n >= 50) || n.n >= 1000)
1375
+ )
1376
+ return true;
1377
+ }
1378
+ // Rounding said with a negation (not round, unrounded, rounded-none).
1379
+ if (
1380
+ o === 'square' &&
1381
+ /round/.test(t) &&
1382
+ /(^|[\s-])(not|no|non|without|never|less)([\s-]|$)|^un|-none$/.test(t)
1383
+ )
1384
+ return true;
1385
+ // (3) A saved value of the line's own setting, never the one typed: as
1386
+ // saved, or under the readings a typed value has (`blod` saved for
1387
+ // headings is bold, as set reads it).
1388
+ if (
1389
+ key &&
1390
+ key !== typedKey &&
1391
+ saved
1392
+ ?.get(key)
1393
+ ?.some(
1394
+ v =>
1395
+ typedReading(v) === o ||
1396
+ readsTyped({offered: o, typed: v, thing: key, typedThing: key}) ===
1397
+ true,
1398
+ )
1399
+ )
1400
+ return true;
1401
+ // (4) A documented fallback; a step on a dial with a scale.
1402
+ if (Object.hasOwn(DECLARED_VALUES, key) && DECLARED_VALUES[key].includes(o))
1403
+ return true;
1404
+ if (
1405
+ /^(more|less)$/.test(t) &&
1406
+ SCALED_DIALS.includes(typedKey) &&
1407
+ (key === typedKey || key.startsWith('--'))
1408
+ )
1409
+ return true;
1410
+ // A CSS font shorthand typed for a font family setting is its family:
1411
+ // what follows the size (`italic 700 16px/1.4 Georgia, serif`).
1412
+ // For the setting typed (the font dial, a family token) that is the
1413
+ // whole reading; for one longhand of a part's font it is the family's
1414
+ // part, beside the lines for the other longhands.
1415
+ if (/^font(-family)?$|^--font-family/.test(key)) {
1416
+ const family = /(?:^|\s)\d*\.?\d+(?:px|rem|em|pt|%)(?:\/\S+)?\s+(.+)$/.exec(
1417
+ t,
1418
+ )?.[1];
1419
+ const F = family ? tokensOf(family) : [];
1420
+ if (F.length && F.length === O.length && O.every((w, i) => w === F[i]))
1421
+ return key === typedKey
1422
+ ? true
1423
+ : Array.from({length: F.length}, (_, i) => T.length - F.length + i);
1424
+ }
1425
+ // (5) A typo, of a word or of a number's unit (16pxx is 16px).
1426
+ // The typed value is one word, dashes and all (`not-alowed` is one
1427
+ // keyword typed, not two words).
1428
+ if (/^[a-z][a-z-]*$/.test(t) && typoOf(t, o)) return true;
1429
+ const typedUnit = /^(\d*\.?\d+)([a-z]+)$/.exec(t);
1430
+ const offeredUnit = /^(\d*\.?\d+)([a-z]+)$/.exec(o);
1431
+ if (
1432
+ typedUnit &&
1433
+ offeredUnit &&
1434
+ typedUnit[1] === offeredUnit[1] &&
1435
+ // A unit is a short word: one edit, two letters swapped as one.
1436
+ levenshteinDistance(typedUnit[2], offeredUnit[2], 1, {swaps: true}) <= 1
1437
+ )
1438
+ return true;
1439
+ // Several values of one kind for a setting that takes one: the first
1440
+ // (the one reading the repair that offers it uses, sameKindValues).
1441
+ const same = sameKindValues(t);
1442
+ if (same) {
1443
+ const first = tokensOf(same.items[0]);
1444
+ if (first.length === O.length && O.every((w, i) => sameToken(w, first[i])))
1445
+ return true;
1446
+ }
1447
+ // Part of the value: a run of its tokens, or a documented reading of one.
1448
+ // (currentcolor stands for the color another line of the refusal sets:
1449
+ // the shape of a border in both modes, its color in one.)
1450
+ // Part of the value: its tokens in the order typed, the others carried
1451
+ // by the refusal's other lines (`Inter, sans-serif` and `semibold` for
1452
+ // `Inter 600, sans-serif`).
1453
+ const part = O.filter(w => w !== 'currentcolor');
1454
+ if (part.length && part.length < T.length)
1455
+ for (const same of [
1456
+ (/** @type {string} */ a, /** @type {string} */ b) => a === b,
1457
+ sameToken,
1458
+ ]) {
1459
+ /** @type {number[]} */
1460
+ const at = [];
1461
+ for (const w of part) {
1462
+ const from = at.length ? at[at.length - 1] + 1 : 0;
1463
+ const i = T.findIndex((x, k) => k >= from && same(w, x));
1464
+ if (i < 0) break;
1465
+ at.push(i);
1466
+ }
1467
+ if (at.length === part.length) return at;
1468
+ }
1469
+ // A documented reading of a run of its tokens (`extra bold` in `Inter
1470
+ // extra bold` is heavy).
1471
+ if (T.length > 1)
1472
+ for (let k = T.length - 1; k >= 2; k -= 1)
1473
+ for (let i = 0; i + k <= T.length; i += 1) {
1474
+ const run = T.slice(i, i + k).join(' ');
1475
+ if (
1476
+ [run, run.replace(/\s+/g, '-'), run.replace(/\s+/g, '')].some(r =>
1477
+ READINGS.get(r)?.has(o),
1478
+ )
1479
+ )
1480
+ return Array.from({length: k}, (_, j) => i + j);
1481
+ }
1482
+ // A documented reading of one token (`900` or `black` is heavy): every
1483
+ // token that reads as it is a candidate, and coversTyped gives the line
1484
+ // the one the other lines leave.
1485
+ /** @type {number[]} */
1486
+ const oneOf = [];
1487
+ if (T.length > 1)
1488
+ for (const [i, w] of T.entries()) {
1489
+ if (READINGS.get(w)?.has(o)) {
1490
+ oneOf.push(i);
1491
+ continue;
1492
+ }
1493
+ if (numberOf(w) && numbersEqual(o, w)) {
1494
+ oneOf.push(i);
1495
+ continue;
1496
+ }
1497
+ const m = numberOf(w);
1498
+ if (m)
1499
+ for (const {things, table, domain} of NUMERIC_TABLES)
1500
+ if (names(things, key) && m.n >= domain[0] && m.n <= domain[1]) {
1501
+ const [rung] = table.reduce((a, b) =>
1502
+ Math.abs(b[1] - m.n) < Math.abs(a[1] - m.n) ? b : a,
1503
+ );
1504
+ if (rung === o) {
1505
+ oneOf.push(i);
1506
+ break;
1507
+ }
1508
+ }
1509
+ }
1510
+ if (oneOf.length === 1) return oneOf;
1511
+ if (oneOf.length > 1) return {oneOf};
1512
+ return false;
1513
+ }
1514
+
1515
+ /**
1516
+ * Whether the lines of one refusal, taken together, carry the whole typed
1517
+ * value: each reads it whole, or the parts they carry cover every typed
1518
+ * token. A part alone (`all` for `all 200`, `bold` for `extra bold`) is not
1519
+ * offered.
1520
+ * @param {Array<true | number[] | {oneOf: number[]} | false>} reads
1521
+ * @param {string} typed
1522
+ * @param {string} [thing] the setting typed (its numbers' reading)
1523
+ */
1524
+ export function coversTyped(reads, typed, thing = '') {
1525
+ const T = tokensOf(
1526
+ typedReading(listWords(thing, typed), {
1527
+ thousands: thousandsSetting(thing),
1528
+ }),
1529
+ );
1530
+ // By token, counted: two lines may each carry one of two equal words
1531
+ // (`normal normal 16px serif`).
1532
+ /** @type {Map<string, number>} */
1533
+ const carried = new Map();
1534
+ /** @param {number} i */
1535
+ const carry = i => carried.set(T[i], (carried.get(T[i]) ?? 0) + 1);
1536
+ /** @type {Map<string, number>} */
1537
+ const typedCount = new Map();
1538
+ for (const w of T) typedCount.set(w, (typedCount.get(w) ?? 0) + 1);
1539
+ for (const r of reads) if (Array.isArray(r)) r.forEach(carry);
1540
+ // A line whose one token may be any of several takes one the others
1541
+ // left.
1542
+ for (const r of reads)
1543
+ if (r && typeof r === 'object' && !Array.isArray(r)) {
1544
+ const left = r.oneOf.find(
1545
+ i => (carried.get(T[i]) ?? 0) < (typedCount.get(T[i]) ?? 0),
1546
+ );
1547
+ carry(left ?? r.oneOf[0]);
1548
+ }
1549
+ return [...typedCount].every(([w, n]) => (carried.get(w) ?? 0) >= n);
1550
+ }
1551
+
1552
+ /**
1553
+ * A headings value with `and` or `&` between its words (`bold and wide`):
1554
+ * the list it names, as the headings reader splits it.
1555
+ * @param {string} thing
1556
+ * @param {string} typed
1557
+ */
1558
+ function listWords(thing, typed) {
1559
+ return thing === 'headings'
1560
+ ? String(typed).replace(/\s+(?:and|&)\s+/gi, ', ')
1561
+ : typed;
1562
+ }
1563
+
1564
+ documentReadings([
1565
+ ['more', 'less'],
1566
+ ['less', 'more'],
1567
+ ]);
1568
+ documentReadings(Object.entries(TAILWIND_RADIUS));
1569
+ documentReadings(Object.values(PROPERTY_WORDS).flatMap(m => Object.entries(m)));
1570
+ documentReadings(Object.entries(WEIGHT_WORDS));
1571
+ documentReadings(Object.entries(WEIGHT_WORDS).map(([w, n]) => [n, w]));
1572
+ documentReadings(Object.entries(DENSITY_WORDS));
1573
+ // A font dial word as a part's font-family is the stack it stands for.
1574
+ documentReadings(
1575
+ [...Object.keys(FONTS), ...Object.keys(OPEN_FONTS)].map(w => [
1576
+ w,
1577
+ /** @type {string} */ (fontStack(w)),
1578
+ ]),
1579
+ );
1580
+
1581
+ /**
1582
+ * Whether a repair line may offer `offered` as the whole typed value (see
1583
+ * readsTyped).
1584
+ * @param {{offered: string, typed: string, thing?: string, typedThing?: string, saved?: Map<string, string[]>, mode?: string}} line
1585
+ */
1586
+ export const allowedLine = line => readsTyped(line) === true;
1587
+
1588
+ /**
1589
+ * Whether a typed word is a typo of a word: both words of four letters or
1590
+ * more, within one edit for a typed word of five letters or fewer and two
1591
+ * for a longer one (`nnone` is none, `normall` normal; `line` is no none).
1592
+ * @param {string} typed
1593
+ * @param {string} word
1594
+ */
1595
+ export function typoOf(typed, word) {
1596
+ const t = String(typed).trim().toLowerCase();
1597
+ const w = String(word).trim().toLowerCase();
1598
+ return (
1599
+ /^[a-z][a-z-]{3,}$/.test(t) && /^[a-z][a-z-]{3,}$/.test(w) && typoNear(t, w)
1600
+ );
1601
+ }
1602
+
1603
+ /**
1604
+ * The edits a typo of a typed word may hold: none for a word under four
1605
+ * letters (leading dashes aside), so only that word in other letters is
1606
+ * near it; one for a word of five letters or fewer; two for a longer one.
1607
+ * Every typo reading of the editor (a value, a setting, a part, a state, a
1608
+ * theme or token name) uses this limit.
1609
+ * @param {string} typed
1610
+ */
1611
+ export const typoLimit = typed => {
1612
+ const n = String(typed).trim().replace(/^-+/, '').length;
1613
+ return n < 4 ? 0 : n <= 5 ? 1 : 2;
1614
+ };
1615
+
1616
+ /**
1617
+ * Whether `word` is within the typo limit of `typed` (two letters swapped
1618
+ * count as one edit, as typed: flxe is flex).
1619
+ * @param {string} typed
1620
+ * @param {string} word
1621
+ */
1622
+ export function typoNear(typed, word) {
1623
+ const t = String(typed).trim().toLowerCase();
1624
+ const limit = typoLimit(t);
1625
+ return (
1626
+ levenshteinDistance(t, String(word).trim().toLowerCase(), limit, {
1627
+ swaps: true,
1628
+ }) <= limit
1629
+ );
1630
+ }