@astryxdesign/cli 0.7.17-canary.g5a3fd39 → 0.7.17-canary.g5cf5d69

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 (426) hide show
  1. package/README.md +64 -63
  2. package/api/build/_adapter.d.mts +51 -0
  3. package/api/build/_adapter.mjs +122 -6
  4. package/api/build/build.doc.mjs +1 -1
  5. package/api/build/build.mjs +23 -14
  6. package/api/build/build.type.d.mts +1 -1
  7. package/api/build/build.type.mjs +3 -3
  8. package/api/build/help/help.d.mts +15 -14
  9. package/api/build/help/help.mjs +62 -3
  10. package/api/build/kit/answer.mjs +2 -3
  11. package/api/build/kit/signals.d.mts +10 -0
  12. package/api/build/kit/signals.mjs +15 -2
  13. package/api/component/detail/blocks/blocks.mjs +2 -1
  14. package/api/discover/_adapter.d.mts +57 -6
  15. package/api/discover/_adapter.mjs +278 -49
  16. package/api/discover/_catalog-view.d.mts +7 -0
  17. package/api/discover/_catalog-view.mjs +10 -1
  18. package/api/discover/detail/detail.d.mts +3 -2
  19. package/api/discover/detail/detail.mjs +3 -2
  20. package/api/discover/detail/doc/doc.mjs +1 -1
  21. package/api/discover/discover.d.mts +24 -0
  22. package/api/discover/discover.doc.mjs +1 -1
  23. package/api/discover/discover.mjs +146 -25
  24. package/api/discover/discover.type.d.mts +6 -4
  25. package/api/discover/discover.type.mjs +6 -4
  26. package/api/discover/search/search.d.mts +22 -0
  27. package/api/discover/search/search.mjs +290 -70
  28. package/api/docs/_entry-names.mjs +4 -3
  29. package/api/doctor/_adapter.d.mts +43 -3
  30. package/api/doctor/_adapter.mjs +142 -18
  31. package/api/doctor/built-checks.d.mts +30 -3
  32. package/api/doctor/built-checks.mjs +132 -5
  33. package/api/doctor/doctor.d.mts +93 -6
  34. package/api/doctor/doctor.doc.mjs +2 -2
  35. package/api/doctor/doctor.mjs +524 -33
  36. package/api/doctor/doctor.type.d.mts +2 -1
  37. package/api/doctor/doctor.type.mjs +2 -1
  38. package/api/doctor/theme-checks.d.mts +19 -0
  39. package/api/doctor/theme-checks.mjs +74 -6
  40. package/api/hook/hook.type.d.mts +1 -1
  41. package/api/hook/hook.type.mjs +1 -1
  42. package/api/hook/list/list.mjs +11 -7
  43. package/api/icon/_adapter.d.mts +2 -1
  44. package/api/icon/_adapter.mjs +10 -15
  45. package/api/icon/_records.d.mts +3 -1
  46. package/api/icon/_records.mjs +30 -3
  47. package/api/icon/exportIconIndex.doc.mjs +1 -1
  48. package/api/icon/icon.doc.mjs +3 -3
  49. package/api/icon/icon.type.d.mts +32 -1
  50. package/api/icon/icon.type.mjs +19 -3
  51. package/api/icon/list/list.mjs +4 -1
  52. package/api/icon/rankIconIndex.doc.mjs +1 -1
  53. package/api/icon/search/icon-index.mjs +18 -8
  54. package/api/icon/search/search.d.mts +26 -3
  55. package/api/icon/search/search.mjs +155 -9
  56. package/api/init/_adapter.d.mts +14 -0
  57. package/api/init/_adapter.mjs +26 -4
  58. package/api/init/init.d.mts +1 -1
  59. package/api/init/init.doc.mjs +2 -2
  60. package/api/init/init.mjs +1 -1
  61. package/api/init/init.type.d.mts +29 -1
  62. package/api/init/init.type.mjs +14 -1
  63. package/api/init/run/run.d.mts +11 -1
  64. package/api/init/run/run.mjs +84 -5
  65. package/api/integration/_adapter.d.mts +5 -4
  66. package/api/integration/_adapter.mjs +7 -5
  67. package/api/integration/integrationCheck.doc.mjs +1 -1
  68. package/api/integration/pack-check.mjs +8 -9
  69. package/api/integration/validate-integration.d.mts +1 -1
  70. package/api/integration/validate-integration.mjs +26 -24
  71. package/api/integration/validate-integration.type.d.mts +5 -2
  72. package/api/integration/validate-integration.type.mjs +5 -2
  73. package/api/integration/validateIntegration.doc.mjs +1 -1
  74. package/api/render/_adapter.d.mts +4 -2
  75. package/api/render/_adapter.mjs +62 -21
  76. package/api/render/render.doc.mjs +8 -5
  77. package/api/render/render.mjs +1 -1
  78. package/api/render/render.type.d.mts +2 -0
  79. package/api/render/render.type.mjs +2 -0
  80. package/api/search/ORDERING.md +2 -2
  81. package/api/search/_candidate-score.d.mts +3 -0
  82. package/api/search/_candidate-score.mjs +36 -3
  83. package/api/search/_gather-docs.mjs +29 -2
  84. package/api/search/_gather-templates.mjs +2 -1
  85. package/api/search/_main-searcher.mjs +13 -0
  86. package/api/search/_named-keywords.d.mts +2 -1
  87. package/api/search/_named-keywords.mjs +48 -6
  88. package/api/search/_order.d.mts +36 -1
  89. package/api/search/_order.mjs +141 -3
  90. package/api/swizzle/list/list.mjs +8 -1
  91. package/api/swizzle/swizzle.type.d.mts +1 -1
  92. package/api/swizzle/swizzle.type.mjs +1 -1
  93. package/api/template/copy/copy.mjs +3 -4
  94. package/api/template/list/list.mjs +2 -1
  95. package/api/template/show/show.mjs +2 -1
  96. package/api/template/skeleton/skeleton.mjs +2 -1
  97. package/api/template/template.doc.mjs +1 -1
  98. package/api/template/template.mjs +19 -1
  99. package/api/template/template.type.d.mts +1 -0
  100. package/api/template/template.type.mjs +2 -1
  101. package/api/theme/_adapter.d.mts +1 -0
  102. package/api/theme/_adapter.mjs +3 -5
  103. package/api/theme/_app-provider.d.mts +42 -0
  104. package/api/theme/_app-provider.mjs +61 -27
  105. package/api/theme/build/build.d.mts +4 -10
  106. package/api/theme/build/build.mjs +165 -116
  107. package/api/theme/build/input-fields.d.mts +9 -0
  108. package/api/theme/build/input-fields.mjs +155 -16
  109. package/api/theme/build/radius-values.d.mts +18 -0
  110. package/api/theme/build/radius-values.mjs +76 -0
  111. package/api/theme/build/typography-values.mjs +7 -23
  112. package/api/theme/build/written-values.d.mts +18 -0
  113. package/api/theme/build/written-values.mjs +107 -31
  114. package/api/theme/eject/eject.mjs +6 -1
  115. package/api/theme/palette/generate/generator.mjs +24 -0
  116. package/api/theme/theme.type.d.mts +4 -2
  117. package/api/theme/theme.type.mjs +3 -2
  118. package/api/theme/themeBuild.doc.mjs +2 -2
  119. package/api/theme/themeEject.doc.mjs +1 -1
  120. package/api/theme-edit/_catalog.d.mts +40 -0
  121. package/api/theme-edit/_catalog.mjs +100 -22
  122. package/api/theme-edit/_check.mjs +213 -43
  123. package/api/theme-edit/_color.d.mts +14 -0
  124. package/api/theme-edit/_color.mjs +22 -0
  125. package/api/theme-edit/_compiler.mjs +52 -0
  126. package/api/theme-edit/_context.d.mts +20 -2
  127. package/api/theme-edit/_context.mjs +157 -29
  128. package/api/theme-edit/_edit.mjs +426 -58
  129. package/api/theme-edit/_how-question.d.mts +14 -0
  130. package/api/theme-edit/_how-question.mjs +1541 -127
  131. package/api/theme-edit/_how.mjs +43 -0
  132. package/api/theme-edit/_missed.mjs +107 -27
  133. package/api/theme-edit/_normal.d.mts +18 -4
  134. package/api/theme-edit/_normal.mjs +84 -3
  135. package/api/theme-edit/_palette.d.mts +9 -0
  136. package/api/theme-edit/_palette.mjs +158 -33
  137. package/api/theme-edit/_part-words.mjs +16 -3
  138. package/api/theme-edit/_parts.d.mts +8 -0
  139. package/api/theme-edit/_parts.mjs +120 -36
  140. package/api/theme-edit/_png.d.mts +24 -0
  141. package/api/theme-edit/_png.mjs +99 -0
  142. package/api/theme-edit/_preview-app.d.mts +16 -0
  143. package/api/theme-edit/_preview-app.mjs +52 -18
  144. package/api/theme-edit/_preview.d.mts +44 -26
  145. package/api/theme-edit/_preview.mjs +255 -67
  146. package/api/theme-edit/_project.d.mts +12 -1
  147. package/api/theme-edit/_project.mjs +16 -1
  148. package/api/theme-edit/_settings.d.mts +116 -0
  149. package/api/theme-edit/_settings.mjs +1197 -58
  150. package/api/theme-edit/_tables.d.mts +16 -0
  151. package/api/theme-edit/_tables.mjs +34 -4
  152. package/api/theme-edit/theme-edit.type.d.mts +15 -2
  153. package/api/theme-edit/theme-edit.type.mjs +8 -6
  154. package/api/upgrade/_adapter.d.mts +46 -7
  155. package/api/upgrade/_adapter.mjs +110 -15
  156. package/api/upgrade/registry/registry.d.mts +6 -3
  157. package/api/upgrade/registry/registry.mjs +21 -6
  158. package/api/upgrade/run/run.mjs +23 -11
  159. package/api/upgrade/upgrade.doc.mjs +4 -3
  160. package/assets/component-list.generated.json +1 -1
  161. package/assets/docs/tree/agent-guidance.doc.mjs +3 -2
  162. package/assets/docs/tree/checks.doc.mjs +2 -2
  163. package/assets/docs/tree/host-entry.doc.mjs +4 -0
  164. package/assets/docs/tree/icon-definitions.doc.mjs +3 -3
  165. package/assets/docs/tree/icon-sets.doc.mjs +6 -6
  166. package/assets/docs/tree/problems.doc.mjs +3 -3
  167. package/assets/docs/tree/render-pages.doc.mjs +17 -3
  168. package/assets/docs/tree/share-a-page.doc.mjs +5 -5
  169. package/assets/docs/tree/short-and-findable.doc.mjs +3 -3
  170. package/assets/docs/tree/troubleshooting.doc.mjs +8 -0
  171. package/assets/docs/tree/updates.doc.mjs +1 -1
  172. package/assets/docs/tree/versioning.doc.mjs +1 -1
  173. package/assets/docs/working-with-ai.doc.mjs +40 -5
  174. package/assets/docs-routes.generated.json +1 -1
  175. package/assets/docs.generated.json +2 -2
  176. package/assets/icons/installed-icon-set.doc.mjs +30 -0
  177. package/assets/search-catalog.generated.json +2 -2
  178. package/assets/self-audit.generated.json +1 -1
  179. package/assets/templates/blocks/components/Avatar/AvatarInteractive.tsx +6 -1
  180. package/assets/templates/blocks/components/CodeBlock/CodeBlockTerminal.tsx +1 -1
  181. package/assets/templates/blocks/components/LinkProvider/LinkProviderCustomLink.tsx +3 -1
  182. package/assets/templates/components.generated.json +1 -1
  183. package/assets/templates/pages/ai-chat/page.tsx +6 -2
  184. package/assets/templates/pages/ai-chat-landing/page.tsx +1 -1
  185. package/assets/templates/pages/blank/page.tsx +4 -2
  186. package/assets/templates/pages/canvas-editor/page.tsx +3 -1
  187. package/assets/templates/pages/centered-hero/page.tsx +1 -1
  188. package/assets/templates/pages/checkout-wizard/page.tsx +1 -1
  189. package/assets/templates/pages/classic-gallery/page.tsx +1 -1
  190. package/assets/templates/pages/contact-form/page.tsx +2 -2
  191. package/assets/templates/pages/course-detail/page.tsx +1 -1
  192. package/assets/templates/pages/dashboard/page.tsx +24 -8
  193. package/assets/templates/pages/dashboard-alert-rail/page.tsx +4 -2
  194. package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +7 -3
  195. package/assets/templates/pages/dashboard-comparison/page.tsx +5 -2
  196. package/assets/templates/pages/dashboard-composition/page.tsx +10 -4
  197. package/assets/templates/pages/dashboard-progress/page.tsx +6 -3
  198. package/assets/templates/pages/dashboard-scorecard/page.tsx +17 -8
  199. package/assets/templates/pages/detail-page/page.tsx +22 -5
  200. package/assets/templates/pages/documentation/page.tsx +4 -2
  201. package/assets/templates/pages/documentation-design/page.tsx +5 -2
  202. package/assets/templates/pages/documentation-technical/page.tsx +4 -2
  203. package/assets/templates/pages/editor/page.tsx +28 -9
  204. package/assets/templates/pages/file-explorer/page.tsx +3 -1
  205. package/assets/templates/pages/form-two-column/page.tsx +1 -1
  206. package/assets/templates/pages/form-wizard/page.tsx +1 -1
  207. package/assets/templates/pages/form-wizard-dialog/page.tsx +3 -1
  208. package/assets/templates/pages/form-wizard-inline/page.tsx +1 -1
  209. package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
  210. package/assets/templates/pages/gallery-hero/page.tsx +1 -1
  211. package/assets/templates/pages/ide/page.tsx +7 -2
  212. package/assets/templates/pages/kanban-board/page.tsx +10 -4
  213. package/assets/templates/pages/library/page.tsx +31 -61
  214. package/assets/templates/pages/login/page.tsx +4 -2
  215. package/assets/templates/pages/login-card/page.tsx +4 -2
  216. package/assets/templates/pages/login-split/page.tsx +3 -2
  217. package/assets/templates/pages/login-sso/page.tsx +4 -4
  218. package/assets/templates/pages/mixed-gallery/page.tsx +1 -1
  219. package/assets/templates/pages/payment-form/page.tsx +1 -1
  220. package/assets/templates/pages/product-detail/page.tsx +16 -4
  221. package/assets/templates/pages/product-gallery/page.tsx +1 -1
  222. package/assets/templates/pages/settings/page.tsx +10 -4
  223. package/assets/templates/pages/settings-dialog/page.tsx +5 -6
  224. package/assets/templates/pages/settings-sidebar/page.tsx +39 -13
  225. package/assets/templates/pages/side-gallery/page.tsx +1 -1
  226. package/assets/templates/pages/table/page.tsx +2 -2
  227. package/assets/templates/pages/table-filter/page.tsx +21 -6
  228. package/assets/templates/pages/table-grouped/page.tsx +23 -2
  229. package/assets/templates/pages/table-inbox/page.tsx +82 -32
  230. package/assets/templates/pages/theme-showcase/page.tsx +3 -2
  231. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +12 -12
  232. package/assets/templates/themes/butter/butterTheme.ts +197 -4
  233. package/assets/templates/themes/chocolate/chocolateTheme.ts +72 -8
  234. package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +3 -3
  235. package/assets/templates/themes/gothic/gothicTheme.ts +114 -4
  236. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +8 -8
  237. package/assets/templates/themes/matcha/matchaTheme.ts +48 -12
  238. package/assets/templates/themes/neutral/neutralTheme.ts +29 -0
  239. package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +2 -2
  240. package/assets/templates/themes/stone/stoneTheme.ts +69 -0
  241. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +9 -9
  242. package/assets/templates/themes/y2k/y2kTheme.ts +249 -14
  243. package/authoring/codemod/parse.d.mts +0 -36
  244. package/authoring/codemod/parse.mjs +62 -41
  245. package/authoring/config/config.doc.mjs +1 -1
  246. package/authoring/config/parse.d.mts +0 -47
  247. package/authoring/config/parse.mjs +128 -103
  248. package/authoring/config/type.ts +4 -3
  249. package/authoring/debug/parse.d.mts +2 -2
  250. package/authoring/discover/parse.d.mts +2 -2
  251. package/authoring/discover/parse.mjs +52 -38
  252. package/authoring/discover/type.ts +2 -1
  253. package/authoring/doctypes/_schema.d.mts +834 -950
  254. package/authoring/doctypes/_schema.mjs +863 -825
  255. package/authoring/doctypes/command/parse.mjs +2 -2
  256. package/authoring/doctypes/component/parse.mjs +2 -2
  257. package/authoring/doctypes/enum/parse.mjs +2 -2
  258. package/authoring/doctypes/hook/parse.mjs +2 -2
  259. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +1 -1
  260. package/authoring/doctypes/icon-definition/parse.d.mts +0 -24
  261. package/authoring/doctypes/icon-definition/parse.mjs +59 -43
  262. package/authoring/doctypes/icon-set/parse.d.mts +0 -75
  263. package/authoring/doctypes/icon-set/parse.mjs +239 -210
  264. package/authoring/doctypes/legacy.mjs +3 -3
  265. package/authoring/doctypes/namespace/parse.mjs +2 -2
  266. package/authoring/doctypes/reference/parse.mjs +2 -2
  267. package/authoring/doctypes/schema/parse.mjs +2 -2
  268. package/authoring/doctypes/template/parse.d.mts +0 -101
  269. package/authoring/doctypes/template/parse.mjs +131 -106
  270. package/authoring/doctypes/theme/parse.d.mts +0 -23
  271. package/authoring/doctypes/theme/parse.mjs +52 -36
  272. package/authoring/gap-report/parse.d.mts +1 -1
  273. package/authoring/integration/integration.doc.mjs +8 -0
  274. package/authoring/integration/schema.d.mts +14 -3
  275. package/authoring/integration/schema.mjs +20 -2
  276. package/authoring/integration/type.ts +14 -0
  277. package/clients/cli/build-id.generated.json +1 -1
  278. package/clients/cli/commands/build.mjs +27 -13
  279. package/clients/cli/commands/component.mjs +14 -3
  280. package/clients/cli/commands/discover.doc.mjs +2 -2
  281. package/clients/cli/commands/discover.mjs +20 -3
  282. package/clients/cli/commands/docs.doc.mjs +11 -9
  283. package/clients/cli/commands/docs.mjs +50 -21
  284. package/clients/cli/commands/experimental/icon.mjs +330 -227
  285. package/clients/cli/commands/experimental/render.mjs +16 -1
  286. package/clients/cli/commands/experimental/theme.mjs +42 -17
  287. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  288. package/clients/cli/commands/experimental-icon-map.doc.mjs +4 -1
  289. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +4 -1
  290. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +4 -1
  291. package/clients/cli/commands/experimental-icon-use.doc.mjs +1 -1
  292. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  293. package/clients/cli/commands/experimental-render.doc.mjs +3 -3
  294. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  295. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  296. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  297. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  298. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  299. package/clients/cli/commands/init.doc.mjs +36 -24
  300. package/clients/cli/commands/integration-check.doc.mjs +1 -1
  301. package/clients/cli/commands/mcp.doc.mjs +53 -0
  302. package/clients/cli/commands/mcp.mjs +51 -0
  303. package/clients/cli/commands/search.mjs +46 -9
  304. package/clients/cli/commands/template.mjs +3 -2
  305. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  306. package/clients/cli/commands/theme.mjs +12 -2
  307. package/clients/cli/commands/upgrade.doc.mjs +3 -2
  308. package/clients/cli/commands.generated.json +1 -1
  309. package/clients/cli/formatters/index.mjs +52 -6
  310. package/clients/cli/index.mjs +23 -17
  311. package/clients/cli/lib/base-gate.mjs +37 -5
  312. package/clients/cli/lib/define-command.mjs +82 -4
  313. package/clients/cli/lib/json-shim.mjs +61 -4
  314. package/clients/cli/lib/manifest.mjs +9 -1
  315. package/clients/cli/lib/mcp-server.mjs +286 -0
  316. package/clients/cli/lib/mcp-tools.mjs +405 -0
  317. package/clients/cli/lib/other-cli-words.mjs +99 -0
  318. package/clients/cli/lib/stray-option.mjs +27 -1
  319. package/clients/cli/lib/unknown-command.mjs +326 -11
  320. package/clients/cli/manifest.generated.json +1 -1
  321. package/clients/cli/run.mjs +1 -1
  322. package/foundation/agent-docs/agent-docs.d.mts +49 -1
  323. package/foundation/agent-docs/agent-docs.mjs +108 -7
  324. package/foundation/agent-docs/computer-agent-text.mjs +1 -1
  325. package/foundation/bases/core.d.mts +1 -1
  326. package/foundation/bases/core.mjs +3 -3
  327. package/foundation/bases/resolve.d.mts +4 -8
  328. package/foundation/bases/resolve.mjs +15 -21
  329. package/foundation/bases/state.d.mts +15 -9
  330. package/foundation/bases/state.mjs +33 -6
  331. package/foundation/config/project.d.mts +5 -4
  332. package/foundation/config/project.mjs +33 -17
  333. package/foundation/discovery/component-discovery.mjs +15 -28
  334. package/foundation/discovery/icon-imports.d.mts +66 -0
  335. package/foundation/discovery/icon-imports.mjs +225 -0
  336. package/foundation/discovery/icon-ranking.d.mts +12 -2
  337. package/foundation/discovery/icon-ranking.mjs +197 -10
  338. package/foundation/discovery/icon-set-checks.mjs +2 -1
  339. package/foundation/discovery/icon-set-discovery.d.mts +28 -0
  340. package/foundation/discovery/icon-set-discovery.mjs +42 -0
  341. package/foundation/discovery/icon-set-writer.d.mts +2 -11
  342. package/foundation/discovery/icon-set-writer.mjs +3 -29
  343. package/foundation/discovery/module-exports.d.mts +1 -1
  344. package/foundation/discovery/module-exports.mjs +136 -33
  345. package/foundation/discovery/name-roots.d.mts +5 -0
  346. package/foundation/discovery/name-roots.mjs +11 -0
  347. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  348. package/foundation/discovery/runner-allowlist.mjs +2 -0
  349. package/foundation/discovery/runner-commands.mjs +1 -0
  350. package/foundation/discovery/template-adapter.d.mts +1 -1
  351. package/foundation/discovery/template-destination.d.mts +14 -6
  352. package/foundation/discovery/template-destination.mjs +42 -8
  353. package/foundation/discovery/template-icons.d.mts +45 -2
  354. package/foundation/discovery/template-icons.mjs +26 -54
  355. package/foundation/discovery/template-needs.d.mts +28 -2
  356. package/foundation/discovery/template-needs.mjs +92 -11
  357. package/foundation/discovery/theme-discovery.d.mts +8 -0
  358. package/foundation/discovery/theme-discovery.mjs +23 -6
  359. package/foundation/discovery/theme-imports.mjs +2 -4
  360. package/foundation/doc-compiler/parse-readable.mjs +4 -3
  361. package/foundation/doc-compiler/stored-docs.d.mts +13 -0
  362. package/foundation/doc-compiler/stored-docs.mjs +74 -3
  363. package/foundation/env/cli-command.d.mts +68 -10
  364. package/foundation/env/cli-command.mjs +116 -22
  365. package/foundation/env/project-scope.d.mts +9 -0
  366. package/foundation/env/project-scope.mjs +28 -2
  367. package/foundation/fs/gather-cache.d.mts +23 -0
  368. package/foundation/fs/gather-cache.mjs +94 -2
  369. package/foundation/fs/module-loader.d.mts +3 -1
  370. package/foundation/fs/module-loader.mjs +85 -5
  371. package/foundation/fs/read-record.mjs +9 -5
  372. package/foundation/identity/package-names.d.mts +18 -0
  373. package/foundation/identity/package-names.mjs +19 -0
  374. package/foundation/identity/providers.mjs +3 -2
  375. package/foundation/integrations/icon-features.d.mts +63 -0
  376. package/foundation/integrations/icon-features.mjs +54 -0
  377. package/foundation/integrations/integrations.d.mts +13 -1
  378. package/foundation/integrations/integrations.mjs +47 -6
  379. package/foundation/integrations/pack-state.d.mts +21 -0
  380. package/foundation/integrations/pack-state.mjs +42 -19
  381. package/foundation/integrations/validate-contributions.d.mts +11 -3
  382. package/foundation/integrations/validate-contributions.mjs +51 -13
  383. package/foundation/release/cache.d.mts +13 -1
  384. package/foundation/release/cache.mjs +94 -14
  385. package/foundation/release/notices.d.mts +15 -0
  386. package/foundation/release/notices.mjs +111 -7
  387. package/foundation/release/project.d.mts +3 -4
  388. package/foundation/release/project.mjs +5 -6
  389. package/foundation/render/client-bundle.d.mts +126 -0
  390. package/foundation/render/client-bundle.mjs +565 -0
  391. package/foundation/render/cut-short.d.mts +7 -1
  392. package/foundation/render/cut-short.mjs +46 -6
  393. package/foundation/render/embedded-imports.d.mts +4 -3
  394. package/foundation/render/embedded-imports.mjs +13 -8
  395. package/foundation/render/esbuild-dependency.d.mts +14 -0
  396. package/foundation/render/esbuild-dependency.mjs +41 -0
  397. package/foundation/render/file-header.mjs +5 -4
  398. package/foundation/render/page-worker.mjs +562 -86
  399. package/foundation/render/picture-chrome.mjs +54 -29
  400. package/foundation/render/picture-playwright.mjs +78 -42
  401. package/foundation/render/picture-window.d.mts +33 -0
  402. package/foundation/render/picture-window.mjs +78 -0
  403. package/foundation/render/render-page.d.mts +55 -4
  404. package/foundation/render/render-page.mjs +199 -28
  405. package/foundation/render/restore-folder.d.mts +13 -0
  406. package/foundation/render/restore-folder.mjs +30 -0
  407. package/foundation/render/served-packages.d.mts +2 -1
  408. package/foundation/render/served-packages.mjs +5 -3
  409. package/foundation/render/ts-paths.d.mts +11 -0
  410. package/foundation/render/ts-paths.mjs +27 -2
  411. package/foundation/render/value-uses.d.mts +43 -0
  412. package/foundation/render/value-uses.mjs +110 -0
  413. package/foundation/response/error-codes.d.mts +2 -1
  414. package/foundation/response/error-codes.doc.mjs +7 -1
  415. package/foundation/response/error-codes.mjs +10 -2
  416. package/foundation/response/response-types.doc.mjs +12 -12
  417. package/foundation/runtime/package-root.d.mts +8 -0
  418. package/foundation/runtime/package-root.mjs +20 -0
  419. package/foundation/suggest/other-command.d.mts +11 -0
  420. package/foundation/suggest/other-command.mjs +1 -1
  421. package/foundation/text/icon-id.d.mts +20 -0
  422. package/foundation/text/icon-id.mjs +40 -0
  423. package/foundation/text/icon-set-next.d.mts +25 -0
  424. package/foundation/text/icon-set-next.mjs +29 -0
  425. package/foundation/xle/browser.d.mts +2 -2
  426. package/package.json +7 -6
@@ -16,6 +16,7 @@ import {
16
16
  withListingCache,
17
17
  } from '../fs/listing-cache.mjs';
18
18
  import {existsCaseExact} from '../fs/paths.mjs';
19
+ import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
19
20
  import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
20
21
  import {loadComponentDoc} from './component-loader.mjs';
21
22
  import {COMPONENT_NAME_RE} from '../text/entry-names.mjs';
@@ -264,27 +265,23 @@ function hasOwnFolder(srcDir, name) {
264
265
 
265
266
  /**
266
267
  * Member names read in this process, by doc path, reused while the file keeps
267
- * its size and mtime.
268
- * @type {Map<string, {size: number, mtimeMs: number, members: string[]}>}
268
+ * its stamp (`fileStamp`).
269
+ * @type {Map<string, {stamp: string, members: string[]}>}
269
270
  */
270
271
  const memberReads = new Map();
271
272
 
272
273
  /**
273
- * The names a doc lists as `components` members (see docMemberNames).
274
+ * The names a doc lists as `components` members (see docMemberNames). Kept
275
+ * names still count as a read of the doc, so a kept catalog sees an edit.
274
276
  * @param {string} docPath
275
277
  * @returns {string[]}
276
278
  */
277
279
  function readDocMembers(docPath) {
278
- let stat;
279
- try {
280
- stat = fs.statSync(docPath);
281
- } catch {
282
- return [];
283
- }
280
+ recordContentRead(docPath);
281
+ const stamp = fileStamp(docPath);
282
+ if (stamp === '-') return [];
284
283
  const cached = memberReads.get(docPath);
285
- if (cached && cached.size === stat.size && cached.mtimeMs === stat.mtimeMs) {
286
- return cached.members;
287
- }
284
+ if (cached?.stamp === stamp) return cached.members;
288
285
  /** @type {string[]} */
289
286
  let members;
290
287
  try {
@@ -292,7 +289,7 @@ function readDocMembers(docPath) {
292
289
  } catch {
293
290
  members = [];
294
291
  }
295
- memberReads.set(docPath, {size: stat.size, mtimeMs: stat.mtimeMs, members});
292
+ memberReads.set(docPath, {stamp, members});
296
293
  return members;
297
294
  }
298
295
 
@@ -1106,20 +1103,6 @@ export function findExternalComponentDoc(docsDir, name) {
1106
1103
  /** @type {Map<string, {stamp: string, value: Record<string, any> | null}>} doc reads, reused while the doc file is unchanged */
1107
1104
  const docReads = new Map();
1108
1105
 
1109
- /**
1110
- * A file's identity for a cache: ctime and inode change on a rewrite even when
1111
- * npm stamps the same size and mtime.
1112
- * @param {string} file
1113
- */
1114
- function fileStamp(file) {
1115
- try {
1116
- const {size, mtimeMs, ctimeMs, ino} = fs.statSync(file);
1117
- return `${size}:${mtimeMs}:${ctimeMs}:${ino}`;
1118
- } catch {
1119
- return 'missing';
1120
- }
1121
- }
1122
-
1123
1106
  /** UTF-16 code-unit order, the same in every locale. @param {string} a @param {string} b */
1124
1107
  function byCodeUnit(a, b) {
1125
1108
  return a < b ? -1 : a > b ? 1 : 0;
@@ -1131,11 +1114,15 @@ function byCodeUnit(a, b) {
1131
1114
  * @returns {Record<string, any> | null}
1132
1115
  */
1133
1116
  function docObject(docPath) {
1117
+ // A kept value still counts as a read of the doc (see readDocMembers).
1118
+ recordContentRead(docPath);
1134
1119
  const stamp = fileStamp(docPath);
1135
1120
  const cached = docReads.get(docPath);
1136
1121
  if (cached?.stamp === stamp) return cached.value;
1137
1122
  const value = staticExportObject(docPath, DOC_EXPORTS.components);
1138
- docReads.set(docPath, {stamp, value});
1123
+ // A file that appeared after its stamp is not kept: the entry would
1124
+ // outlive its removal.
1125
+ if (stamp !== '-') docReads.set(docPath, {stamp, value});
1139
1126
  return value;
1140
1127
  }
1141
1128
 
@@ -0,0 +1,66 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The imports and re-exports in one file that do not match the project's
6
+ * icon sets; null when the file does not parse. With no main set resolved
7
+ * (none decided, or the one the list names is not installed), only the
8
+ * imports that break the build are read.
9
+ * @param {string} source
10
+ * @param {{sets: DiscoveredIconSet[], choice: IconSetChoice}} iconSets
11
+ * @param {(module: string) => boolean} broken whether an import of a package
12
+ * breaks the build: it does not resolve from the file, no path alias maps
13
+ * it, and the project does not declare the package
14
+ * @param {Map<DiscoveredIconSet, Map<string, string>>} [wrappedRead] each
15
+ * set's exports by the library export they re-export, shared between files
16
+ * @returns {IconImportFinding[] | null}
17
+ */
18
+ export function iconImportFindings(source: string, { sets, choice }: {
19
+ sets: DiscoveredIconSet[];
20
+ choice: IconSetChoice;
21
+ }, broken: (module: string) => boolean, wrappedRead?: Map<DiscoveredIconSet, Map<string, string>>): IconImportFinding[] | null;
22
+ export type DiscoveredIconSet = import("./icon-set-discovery.mjs").DiscoveredIconSet;
23
+ export type IconSetChoice = import("./icon-set-discovery.mjs").IconSetChoice;
24
+ /**
25
+ * One icon import that does not match the project's icon sets.
26
+ */
27
+ export type IconImportFinding = {
28
+ /**
29
+ * the import's line in the file
30
+ */
31
+ line: number;
32
+ /**
33
+ * the module it imports from
34
+ */
35
+ module: string;
36
+ /**
37
+ * the name it imports (`default` for a default
38
+ * import)
39
+ */
40
+ export: string;
41
+ /**
42
+ * `unlisted`: the set
43
+ * it comes from is not in the project's list; `earlier`: a set earlier in
44
+ * the list draws the same definition; `unresolved`: its package does not
45
+ * resolve and the project does not declare it
46
+ */
47
+ why: "unlisted" | "earlier" | "unresolved";
48
+ /**
49
+ * the set it comes from, as `<package>/<set>`;
50
+ * null when its package does not resolve
51
+ */
52
+ set: string | null;
53
+ /**
54
+ * the Astryx definitions it draws
55
+ */
56
+ definitions: string[];
57
+ /**
58
+ * the icon a set in the list draws for one of those definitions, the first
59
+ * set in the list that has one; null when no set in the list has one
60
+ */
61
+ replacement: {
62
+ set: string;
63
+ module: string;
64
+ export: string;
65
+ } | null;
66
+ };
@@ -0,0 +1,225 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Icon imports that do not match the project's icon sets (AST-084):
5
+ * what Doctor reads in the project's own code after the project changes its
6
+ * list of sets or uninstalls a set.
7
+ *
8
+ * An import of an icon from an installed set, or from the library a set wraps
9
+ * (its data's `source`), draws the definitions that set's `map` names for it.
10
+ * Such an import does not match the project's list when the set is not in the
11
+ * list, or when a set earlier in the list draws one of those definitions too:
12
+ * a template copied now imports that set's icon instead, by the same rule as
13
+ * template icon mapping. A named re-export (`export {TrashIcon} from '…'`)
14
+ * reads like an import. An import of an npm package that does not resolve
15
+ * from the file, that no path alias maps, and that the project's package.json
16
+ * does not declare, breaks the build; it counts as an icon import only when
17
+ * every name it imports follows the icon export contract (`<Name>Icon`). That
18
+ * rule needs no main set, so it holds when the set the list names is the one
19
+ * uninstalled. The CLI knows no icon library: it reads only the installed
20
+ * sets' data and the code's imports.
21
+ *
22
+ * @input One source file, the project's icon sets, and how a module resolves
23
+ * @output Each import that does not match, with the icon that replaces it
24
+ * @position packages/cli/foundation/discovery — read by Doctor's
25
+ * `icon-imports` check
26
+ */
27
+
28
+ import {parseTemplateSource as parseSource} from './template-source-tree.mjs';
29
+ import {
30
+ importedName,
31
+ indexSets,
32
+ isAstryxModule,
33
+ isPackageModule,
34
+ matchIcon,
35
+ wrappedIcon,
36
+ wrapsModule,
37
+ } from './template-icons.mjs';
38
+ import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
39
+ import {isPackageName} from '../identity/provider-identity.mjs';
40
+ import {
41
+ ICON_EXPORT_NAME_RE,
42
+ definitionsByIcon,
43
+ iconLookExport,
44
+ splitSpecifier,
45
+ } from './icon-set-discovery.mjs';
46
+
47
+ /** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
48
+ /** @typedef {import('./icon-set-discovery.mjs').IconSetChoice} IconSetChoice */
49
+
50
+ /**
51
+ * One icon import that does not match the project's icon sets.
52
+ * @typedef {object} IconImportFinding
53
+ * @property {number} line the import's line in the file
54
+ * @property {string} module the module it imports from
55
+ * @property {string} export the name it imports (`default` for a default
56
+ * import)
57
+ * @property {'unlisted' | 'earlier' | 'unresolved'} why `unlisted`: the set
58
+ * it comes from is not in the project's list; `earlier`: a set earlier in
59
+ * the list draws the same definition; `unresolved`: its package does not
60
+ * resolve and the project does not declare it
61
+ * @property {string | null} set the set it comes from, as `<package>/<set>`;
62
+ * null when its package does not resolve
63
+ * @property {string[]} definitions the Astryx definitions it draws
64
+ * @property {{set: string, module: string, export: string} | null} replacement
65
+ * the icon a set in the list draws for one of those definitions, the first
66
+ * set in the list that has one; null when no set in the list has one
67
+ */
68
+
69
+ /**
70
+ * Each statement that reads names from a package: an import, or a named
71
+ * re-export (`export {TrashIcon} from '…'`), with the names it reads. Type-only
72
+ * statements and names, namespace imports, and `export *` read no icon.
73
+ * @param {any} ast
74
+ * @returns {Array<{line: number, module: string, names: Array<{name: string, named: boolean}>}>}
75
+ */
76
+ function packageReads(ast) {
77
+ /** @type {Array<{line: number, module: string, names: Array<{name: string, named: boolean}>}>} */
78
+ const reads = [];
79
+ for (const node of ast.program.body) {
80
+ const isImport = node.type === 'ImportDeclaration';
81
+ const isReExport = node.type === 'ExportNamedDeclaration' && node.source;
82
+ if (!isImport && !isReExport) continue;
83
+ if (node.importKind === 'type' || node.exportKind === 'type') continue;
84
+ const module = String(node.source.value);
85
+ if (!isPackageModule(module) || isAstryxModule(module)) continue;
86
+ const names = node.specifiers
87
+ .filter(
88
+ (/** @type {any} */ each) =>
89
+ each.type !== 'ImportNamespaceSpecifier' &&
90
+ each.type !== 'ExportNamespaceSpecifier' &&
91
+ each.importKind !== 'type' &&
92
+ each.exportKind !== 'type',
93
+ )
94
+ .map((/** @type {any} */ each) =>
95
+ isImport
96
+ ? {name: importedName(each), named: each.type === 'ImportSpecifier'}
97
+ : {name: each.local.name ?? each.local.value, named: true},
98
+ );
99
+ if (names.length > 0) {
100
+ reads.push({line: node.loc?.start.line ?? 0, module, names});
101
+ }
102
+ }
103
+ return reads;
104
+ }
105
+
106
+ /**
107
+ * The imports and re-exports in one file that do not match the project's
108
+ * icon sets; null when the file does not parse. With no main set resolved
109
+ * (none decided, or the one the list names is not installed), only the
110
+ * imports that break the build are read.
111
+ * @param {string} source
112
+ * @param {{sets: DiscoveredIconSet[], choice: IconSetChoice}} iconSets
113
+ * @param {(module: string) => boolean} broken whether an import of a package
114
+ * breaks the build: it does not resolve from the file, no path alias maps
115
+ * it, and the project does not declare the package
116
+ * @param {Map<DiscoveredIconSet, Map<string, string>>} [wrappedRead] each
117
+ * set's exports by the library export they re-export, shared between files
118
+ * @returns {IconImportFinding[] | null}
119
+ */
120
+ export function iconImportFindings(
121
+ source,
122
+ {sets, choice},
123
+ broken,
124
+ wrappedRead = new Map(),
125
+ ) {
126
+ const main = choice.set ?? null;
127
+ /** @type {DiscoveredIconSet[]} */
128
+ const order = main ? (choice.order ?? [main]) : [];
129
+ /** @type {any} */
130
+ let ast;
131
+ try {
132
+ ast = parseSource(source);
133
+ } catch {
134
+ return null;
135
+ }
136
+ const index = indexSets(sets);
137
+ const astryx = astryxDefinitionsByName();
138
+ /** @type {IconImportFinding[]} */
139
+ const findings = [];
140
+ for (const {line, module, names} of packageReads(ast)) {
141
+ const wrapper = sets.find(set => wrapsModule(set, module));
142
+ const fromSet = names.some(each => index.has(`${module}\0${each.name}`));
143
+ if (!fromSet && !wrapper) {
144
+ if (
145
+ names.every(
146
+ each => each.named && ICON_EXPORT_NAME_RE.test(each.name),
147
+ ) &&
148
+ isPackageName(splitSpecifier(module).name) &&
149
+ broken(module)
150
+ ) {
151
+ for (const each of names) {
152
+ findings.push({
153
+ line,
154
+ module,
155
+ export: each.name,
156
+ why: 'unresolved',
157
+ set: null,
158
+ definitions: [],
159
+ replacement: null,
160
+ });
161
+ }
162
+ }
163
+ continue;
164
+ }
165
+ // Which set an icon should come from is decided only by a main set.
166
+ if (!main) continue;
167
+ for (const {name: imported} of names) {
168
+ const indexed = index.get(`${module}\0${imported}`);
169
+ /** @type {DiscoveredIconSet | undefined} */
170
+ let set = indexed?.set;
171
+ let record = indexed;
172
+ if (!record && wrapper) {
173
+ // The main set's own library is the icon the project chose.
174
+ if (wrapper === main) continue;
175
+ set = wrapper;
176
+ const icon = wrappedIcon(wrapper, module, imported, wrappedRead);
177
+ record = icon
178
+ ? {
179
+ setName: wrapper.name,
180
+ export: icon.export,
181
+ id: icon.id,
182
+ definitions: (
183
+ definitionsByIcon(wrapper.data).get(icon.id) ?? []
184
+ ).filter(name => astryx.has(name)),
185
+ set: wrapper,
186
+ }
187
+ : undefined;
188
+ }
189
+ if (!set || set === main) continue;
190
+ const listed = order.indexOf(set);
191
+ // A set later in the list supplies only what the sets before it lack.
192
+ const earlier = listed === -1 ? order : order.slice(0, listed);
193
+ /** @type {IconImportFinding['replacement']} */
194
+ let replacement = null;
195
+ if (record) {
196
+ for (const target of earlier) {
197
+ const match = matchIcon(record, target);
198
+ if (match) {
199
+ const chosen = iconLookExport(
200
+ match.icon,
201
+ target,
202
+ choice.variant ?? record.variant,
203
+ );
204
+ replacement = {
205
+ set: `${target.package}/${target.name}`,
206
+ ...chosen,
207
+ };
208
+ break;
209
+ }
210
+ }
211
+ }
212
+ if (listed !== -1 && !replacement) continue;
213
+ findings.push({
214
+ line,
215
+ module,
216
+ export: imported,
217
+ why: listed === -1 ? 'unlisted' : 'earlier',
218
+ set: `${set.package}/${set.name}`,
219
+ definitions: record?.definitions ?? [],
220
+ replacement,
221
+ });
222
+ }
223
+ }
224
+ return findings;
225
+ }
@@ -100,12 +100,22 @@ export function withDefinitionWords(icon: IconSetIcon, definitions: string[], lo
100
100
  /**
101
101
  * Every icon in `sets` that answers the query, ranked. The query is
102
102
  * scored as typed; when nothing answers it with a whole word (80 and up),
103
- * it is scored again without its filler words ({@link iconQuery}).
103
+ * it is scored again without its filler words ({@link iconQuery}), and
104
+ * again with each word written as an export name read as its words
105
+ * ({@link exportNameWords}); the reading whose best match scores higher
106
+ * answers, the one without filler words on a tie. With `words`, a query
107
+ * of several words that no reading answers is ranked by the words each
108
+ * icon carries ({@link rankWords}), the words of both readings together:
109
+ * the finder's own search answers ask for that, while callers that look for
110
+ * a near spelling or a fitting definition do not.
104
111
  * @param {DiscoveredIconSet[]} sets in tie order
105
112
  * @param {string} query
113
+ * @param {{words?: boolean}} [options]
106
114
  * @returns {IconMatchEntry[]}
107
115
  */
108
- export function rankIcons(sets: DiscoveredIconSet[], query: string): IconMatchEntry[];
116
+ export function rankIcons(sets: DiscoveredIconSet[], query: string, { words }?: {
117
+ words?: boolean;
118
+ }): IconMatchEntry[];
109
119
  export type DiscoveredIconSet = import("./icon-set-discovery.mjs").DiscoveredIconSet;
110
120
  export type IconSetIcon = import("../../authoring/doctypes/icon-set/type").IconSetIcon;
111
121
  export type IconRecord = import("../../api/icon/icon.type.mjs").IconRecord;
@@ -12,6 +12,8 @@
12
12
  * 40 a partial match: the id or a word contains the query (three
13
13
  * letters or more), or every word of the query starts one of the
14
14
  * icon's words or id parts
15
+ * 20 a word match: nothing above answers a query of several words, and
16
+ * the icon carries one or more of its words (below)
15
17
  *
16
18
  * A word matches a whole word: a word's plural or singular (`stars` for
17
19
  * `star`) is an exact match, while a longer word that only starts with it
@@ -20,7 +22,27 @@
20
22
  * A query is scored as typed first. Only when nothing answers it with a
21
23
  * whole word are the words that only phrase it (`go`, `the`, `icon`) left
22
24
  * out of a query of several words, so `go home` asks for `home` while
23
- * `arrow up to line` still names `arrow-up-to-line`.
25
+ * `arrow up to line` still names `arrow-up-to-line`. At that step the
26
+ * query is also read with each word written as an export name split into
27
+ * its words, so `SearchIcon` asks for `search`; the reading whose best match
28
+ * scores higher answers, and on a tie the word as typed does, so
29
+ * `PaperClip` still finds a `paperclip` icon.
30
+ *
31
+ * Agents ask for a glyph in a phrase (`copy button clipboard`), and often no
32
+ * icon carries every word. For the finder's own search answers only, when
33
+ * no reading answers a query of several words, each icon that carries one
34
+ * or more of its words, as typed or split from an export name, is a word
35
+ * match. An icon carries a word when the word, or its
36
+ * plural or singular, is one of its id parts, a part of one of its words, or
37
+ * a part of a word of a definition the set maps it for. A word weighs more
38
+ * the fewer searched icons carry it, so the word that names the glyph
39
+ * outweighs a common one, and a word no icon carries counts for nothing.
40
+ * A word counts twice when, alone or with other query words, it spells out
41
+ * the whole name of a definition the set maps the icon for: the map is the
42
+ * set's own statement of what the icon means. Word matches share one
43
+ * score, so they keep set order first, as every equal score does; within a
44
+ * set they rank by the weight of the words they carry, then the icon whose
45
+ * id holds fewer parts that no query word names, then id order.
24
46
  *
25
47
  * An exact match is a NAME match when the query is the icon's id, or one of
26
48
  * its words that is also a part of its id (`trash` for `trash-2`); it is a
@@ -47,6 +69,7 @@
47
69
 
48
70
  import {definitionsByIcon} from './icon-set-discovery.mjs';
49
71
  import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
72
+ import {iconIdOf} from '../text/icon-id.mjs';
50
73
 
51
74
  /** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
52
75
  /** @typedef {import('../../authoring/doctypes/icon-set/type').IconSetIcon} IconSetIcon */
@@ -252,6 +275,18 @@ export function iconQuery(query) {
252
275
  return (words.length > 1 && named.length > 0 ? named : words).join(' ');
253
276
  }
254
277
 
278
+ /**
279
+ * The query with each word that holds a capital letter read as the icon id
280
+ * its export name stands for, split into its words: `XMarkIcon` reads
281
+ * `x mark` and `Bars3Icon` reads `bars 3` ({@link iconIdOf}).
282
+ * @param {string} query
283
+ */
284
+ function exportNameWords(query) {
285
+ return query.replace(/[A-Za-z0-9]+/gu, word =>
286
+ /[A-Z]/u.test(word) ? iconIdOf(word).replace(/-/gu, ' ') : word,
287
+ );
288
+ }
289
+
255
290
  /**
256
291
  * The matches that answer a query: the whole-word ones (a definition or an
257
292
  * exact match, 80 and up) when there are any, else word starts (60) when
@@ -321,6 +356,15 @@ export function scoreIcon(query, icon, leading = 'meaning', definitions = []) {
321
356
  return match ? {score: scoreOf(match, leading), reason: match.reason} : null;
322
357
  }
323
358
 
359
+ /**
360
+ * A definition name read as lower-case words (`externalLink` is
361
+ * `external link`).
362
+ * @param {string} name
363
+ */
364
+ function spokenName(name) {
365
+ return name.replace(/([a-z0-9])([A-Z])/gu, '$1 $2').toLowerCase();
366
+ }
367
+
324
368
  /**
325
369
  * The icon with the words it matches by: its own words, then the name (read
326
370
  * as words) and words of every definition the set's `map` names it for, so
@@ -337,10 +381,7 @@ export function withDefinitionWords(icon, definitions, lookup) {
337
381
  const words = [...icon.words];
338
382
  for (const name of definitions) {
339
383
  const doc = lookup(name);
340
- const humanized = name
341
- .replace(/([a-z0-9])([A-Z])/gu, '$1 $2')
342
- .toLowerCase();
343
- for (const word of [humanized, ...(doc?.words ?? [])]) {
384
+ for (const word of [spokenName(name), ...(doc?.words ?? [])]) {
344
385
  const lower = word.toLowerCase();
345
386
  if (!words.includes(lower)) words.push(lower);
346
387
  }
@@ -351,19 +392,165 @@ export function withDefinitionWords(icon, definitions, lookup) {
351
392
  /**
352
393
  * Every icon in `sets` that answers the query, ranked. The query is
353
394
  * scored as typed; when nothing answers it with a whole word (80 and up),
354
- * it is scored again without its filler words ({@link iconQuery}).
395
+ * it is scored again without its filler words ({@link iconQuery}), and
396
+ * again with each word written as an export name read as its words
397
+ * ({@link exportNameWords}); the reading whose best match scores higher
398
+ * answers, the one without filler words on a tie. With `words`, a query
399
+ * of several words that no reading answers is ranked by the words each
400
+ * icon carries ({@link rankWords}), the words of both readings together:
401
+ * the finder's own search answers ask for that, while callers that look for
402
+ * a near spelling or a fitting definition do not.
355
403
  * @param {DiscoveredIconSet[]} sets in tie order
356
404
  * @param {string} query
405
+ * @param {{words?: boolean}} [options]
357
406
  * @returns {IconMatchEntry[]}
358
407
  */
359
- export function rankIcons(sets, query) {
408
+ export function rankIcons(sets, query, {words = false} = {}) {
360
409
  const typed = typedQuery(query);
361
410
  const asTyped = rankTerm(sets, typed);
362
411
  if (asTyped.some(each => each.score >= 80)) return asTyped;
363
412
  const named = iconQuery(query);
364
- if (named === typed) return asTyped;
365
- const withoutFiller = rankTerm(sets, named);
366
- return withoutFiller.length > 0 ? withoutFiller : asTyped;
413
+ const asNamed = named === typed ? asTyped : rankTerm(sets, named);
414
+ const answered = asNamed.length > 0 ? asNamed : asTyped;
415
+ const spelled = iconQuery(exportNameWords(query));
416
+ const asSpelled =
417
+ spelled === '' || spelled === named || spelled === typed
418
+ ? []
419
+ : rankTerm(sets, spelled);
420
+ const best = topScore(asSpelled) > topScore(answered) ? asSpelled : answered;
421
+ if (best.length > 0) return best;
422
+ if (!words) return [];
423
+ const asked = [...new Set([...named.split(' '), ...spelled.split(' ')])];
424
+ return asked.length > 1 ? rankWords(sets, asked.join(' ')) : [];
425
+ }
426
+
427
+ /**
428
+ * The score of the first entry of a ranked list, or -Infinity for none.
429
+ * @param {IconMatchEntry[]} ranked best first
430
+ */
431
+ function topScore(ranked) {
432
+ return ranked.length > 0 ? ranked[0].score : -Infinity;
433
+ }
434
+
435
+ /** The score of a word match ({@link rankWords}): below every other tier. */
436
+ const WORD_MATCH_SCORE = 20;
437
+
438
+ /**
439
+ * Icons that carry one or more words of a query of several words, set
440
+ * order first and then best first within a set. A word weighs the log of how many searched icons there are over how
441
+ * many carry it, so a rare word counts more than a common one. An icon's
442
+ * weight is the sum of the weights of the words it carries, with the words
443
+ * that name a definition the set maps it for counted twice
444
+ * ({@link mappedNameWords}).
445
+ * @param {DiscoveredIconSet[]} sets in tie order
446
+ * @param {string} term lower-case words, filler words left out
447
+ * @returns {IconMatchEntry[]}
448
+ */
449
+ function rankWords(sets, term) {
450
+ const astryx = astryxDefinitionsByName();
451
+ const words = [...new Set(term.split(' '))];
452
+ let total = 0;
453
+ /** @type {Array<{set: DiscoveredIconSet, icon: IconSetIcon, definitions: string[], carried: string[], named: string[], setIndex: number}>} */
454
+ const hits = [];
455
+ sets.forEach((set, setIndex) => {
456
+ const byIcon = definitionsByIcon(set.data);
457
+ const own = new Map(
458
+ (set.definitions ?? []).map(each => [each.doc.name, each.doc]),
459
+ );
460
+ for (const icon of set.data.icons) {
461
+ total++;
462
+ const definitions = byIcon.get(icon.id) ?? [];
463
+ const terms = iconTerms(
464
+ withDefinitionWords(
465
+ icon,
466
+ definitions,
467
+ name => astryx.get(name) ?? own.get(name),
468
+ ),
469
+ );
470
+ const carried = words.filter(word =>
471
+ terms.some(each => each === word || sameWord(each, word)),
472
+ );
473
+ if (carried.length > 0) {
474
+ const named = mappedNameWords(definitions, words);
475
+ hits.push({set, icon, definitions, carried, named, setIndex});
476
+ }
477
+ }
478
+ });
479
+ /** @type {Map<string, number>} */
480
+ const carriers = new Map();
481
+ for (const hit of hits) {
482
+ for (const word of hit.carried) {
483
+ carriers.set(word, (carriers.get(word) ?? 0) + 1);
484
+ }
485
+ }
486
+ /** @param {string} word */
487
+ const weight = word =>
488
+ Math.log((total + 1) / ((carriers.get(word) ?? 0) + 1));
489
+ const ranked = hits.map(hit => ({
490
+ hit,
491
+ value: [...hit.carried, ...hit.named].reduce(
492
+ (sum, word) => sum + weight(word),
493
+ 0,
494
+ ),
495
+ unasked: hit.icon.id
496
+ .split('-')
497
+ .filter(
498
+ part => !words.some(word => word === part || sameWord(word, part)),
499
+ ).length,
500
+ }));
501
+ ranked.sort(
502
+ (a, b) =>
503
+ a.hit.setIndex - b.hit.setIndex ||
504
+ b.value - a.value ||
505
+ a.unasked - b.unasked ||
506
+ (a.hit.icon.id < b.hit.icon.id
507
+ ? -1
508
+ : a.hit.icon.id > b.hit.icon.id
509
+ ? 1
510
+ : 0),
511
+ );
512
+ return ranked.map(({hit}) => ({
513
+ ...iconRecord(hit.set, hit.icon, hit.definitions),
514
+ reason: `words "${hit.carried.join('", "')}"`,
515
+ score: WORD_MATCH_SCORE,
516
+ }));
517
+ }
518
+
519
+ /**
520
+ * The query words that spell out the whole name of a definition the set maps
521
+ * the icon for (`external link` for `externalLink`). The map is the set's
522
+ * own statement of what the icon means, so these words count twice.
523
+ * @param {string[]} definitions the names the set maps the icon for
524
+ * @param {string[]} words the query's words
525
+ * @returns {string[]}
526
+ */
527
+ function mappedNameWords(definitions, words) {
528
+ /** @type {Set<string>} */
529
+ const named = new Set();
530
+ for (const name of definitions) {
531
+ const asked = spokenName(name)
532
+ .split(' ')
533
+ .map(part => words.find(word => word === part || sameWord(word, part)));
534
+ if (asked.every(Boolean)) {
535
+ for (const word of asked) named.add(/** @type {string} */ (word));
536
+ }
537
+ }
538
+ return [...named];
539
+ }
540
+
541
+ /**
542
+ * The single words an icon carries: its id parts and the parts of its
543
+ * words, since a word can hold several (`align end`).
544
+ * @param {IconSetIcon} icon
545
+ * @returns {string[]}
546
+ */
547
+ function iconTerms(icon) {
548
+ return [
549
+ ...new Set([
550
+ ...icon.id.split('-'),
551
+ ...icon.words.flatMap(word => word.split(/[\s-]+/u)),
552
+ ]),
553
+ ].filter(Boolean);
367
554
  }
368
555
 
369
556
  /**
@@ -46,6 +46,7 @@ import * as path from 'node:path';
46
46
  import {findInstalledPackage} from '../fs/paths.mjs';
47
47
  import {satisfiesRange} from '../env/semver.mjs';
48
48
  import {
49
+ ICON_EXPORT_NAME_RE,
49
50
  discoverIconSetDirectory,
50
51
  hasLicenseNotice,
51
52
  licenseNoticeFix,
@@ -241,7 +242,7 @@ function checkContract(set, packageName, pkg, unchecked) {
241
242
  };
242
243
  /** @param {string} name @param {string} what */
243
244
  const checkName = (name, what) => {
244
- if (!/^[A-Z][A-Za-z0-9]*Icon$/u.test(name)) {
245
+ if (!ICON_EXPORT_NAME_RE.test(name)) {
245
246
  issues.push(
246
247
  issueWarning(
247
248
  ICON_EXPORT_NAME,