@astryxdesign/cli 0.7.17 → 0.7.18-canary.g170df15

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 (255) hide show
  1. package/README.md +1 -1
  2. package/api/discover/_adapter.d.mts +7 -5
  3. package/api/discover/_adapter.mjs +12 -11
  4. package/api/docs/_adapter.d.mts +19 -2
  5. package/api/docs/_adapter.mjs +66 -5
  6. package/api/doctor/_adapter.d.mts +11 -62
  7. package/api/doctor/_adapter.mjs +242 -472
  8. package/api/doctor/doctor.d.mts +1 -1
  9. package/api/doctor/doctor.mjs +3 -3
  10. package/api/doctor/theme-checks.mjs +37 -45
  11. package/api/error.d.mts +21 -0
  12. package/api/error.mjs +89 -0
  13. package/api/hook/list/list.d.mts +1 -1
  14. package/api/icon/_adapter.d.mts +8 -0
  15. package/api/icon/_adapter.mjs +17 -0
  16. package/api/icon/_authoring.mjs +6 -6
  17. package/api/icon/_default-look.mjs +16 -16
  18. package/api/icon/add/add.mjs +3 -3
  19. package/api/icon/exportIconIndex.doc.mjs +2 -2
  20. package/api/icon/icon.doc.mjs +2 -2
  21. package/api/icon/icon.type.d.mts +4 -0
  22. package/api/icon/icon.type.mjs +2 -1
  23. package/api/icon/search/icon-index.mjs +16 -3
  24. package/api/icon/search/search.d.mts +15 -5
  25. package/api/icon/search/search.mjs +74 -16
  26. package/api/icon/use/use.mjs +4 -4
  27. package/api/render/_adapter.mjs +233 -40
  28. package/api/render/render.type.d.mts +1 -1
  29. package/api/render/render.type.mjs +1 -1
  30. package/api/search/ORDERING.md +2 -2
  31. package/api/search/_adapter.mjs +4 -0
  32. package/api/search/_candidate-score.mjs +32 -8
  33. package/api/search/_cards.json +1 -1
  34. package/api/search/_compound.d.mts +0 -1
  35. package/api/search/_compound.mjs +93 -2
  36. package/api/search/_icons.d.mts +4 -2
  37. package/api/search/_icons.mjs +4 -2
  38. package/api/search/_lexical.mjs +177 -17
  39. package/api/search/_order.d.mts +3 -1
  40. package/api/search/_order.mjs +16 -5
  41. package/api/search/_result.d.mts +9 -0
  42. package/api/search/_result.mjs +10 -0
  43. package/api/search/_score.mjs +21 -3
  44. package/api/swizzle/_moduleGraph.d.mts +8 -0
  45. package/api/swizzle/_moduleGraph.mjs +61 -3
  46. package/api/template/copy/copy.mjs +5 -3
  47. package/api/template/template.type.d.mts +3 -3
  48. package/api/template/template.type.mjs +3 -3
  49. package/api/theme/_adapter.mjs +48 -12
  50. package/api/theme/build/build.d.mts +4 -0
  51. package/api/theme/build/build.mjs +69 -18
  52. package/api/theme/build/style-keys.mjs +4 -5
  53. package/api/theme/build/theme-object.mjs +5 -0
  54. package/api/theme/palette/generate/color.d.mts +47 -0
  55. package/api/theme/palette/generate/color.mjs +58 -1
  56. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  57. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  58. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  59. package/api/theme/palette/generate/editor-look.mjs +550 -0
  60. package/api/theme/palette/generate/mapping.d.mts +94 -9
  61. package/api/theme/palette/generate/mapping.mjs +94 -22
  62. package/api/theme-edit/_adapter.mjs +13 -2
  63. package/api/theme-edit/_catalog.d.mts +13 -13
  64. package/api/theme-edit/_catalog.mjs +66 -28
  65. package/api/theme-edit/_check.d.mts +82 -6
  66. package/api/theme-edit/_check.mjs +1270 -238
  67. package/api/theme-edit/_color.d.mts +74 -0
  68. package/api/theme-edit/_color.mjs +168 -3
  69. package/api/theme-edit/_compiler.d.mts +3 -5
  70. package/api/theme-edit/_compiler.mjs +122 -23
  71. package/api/theme-edit/_context.d.mts +55 -12
  72. package/api/theme-edit/_context.mjs +114 -60
  73. package/api/theme-edit/_css.d.mts +11 -0
  74. package/api/theme-edit/_css.mjs +40 -0
  75. package/api/theme-edit/_edit.d.mts +15 -2
  76. package/api/theme-edit/_edit.mjs +1469 -133
  77. package/api/theme-edit/_how-commands.d.mts +116 -0
  78. package/api/theme-edit/_how-commands.mjs +227 -115
  79. package/api/theme-edit/_how-question.d.mts +74 -29
  80. package/api/theme-edit/_how-question.mjs +8514 -1256
  81. package/api/theme-edit/_how-sides.d.mts +22 -0
  82. package/api/theme-edit/_how-sides.mjs +173 -0
  83. package/api/theme-edit/_how-steps.d.mts +42 -0
  84. package/api/theme-edit/_how-steps.mjs +208 -0
  85. package/api/theme-edit/_how-values.d.mts +29 -0
  86. package/api/theme-edit/_how-values.mjs +111 -0
  87. package/api/theme-edit/_how-words.d.mts +15 -0
  88. package/api/theme-edit/_how-words.mjs +239 -0
  89. package/api/theme-edit/_how.d.mts +1 -1
  90. package/api/theme-edit/_how.mjs +422 -37
  91. package/api/theme-edit/_missed.d.mts +2 -1
  92. package/api/theme-edit/_missed.mjs +125 -13
  93. package/api/theme-edit/_normal.d.mts +5 -3
  94. package/api/theme-edit/_normal.mjs +54 -14
  95. package/api/theme-edit/_palette.d.mts +204 -4
  96. package/api/theme-edit/_palette.mjs +901 -25
  97. package/api/theme-edit/_part-pieces.d.mts +54 -0
  98. package/api/theme-edit/_part-pieces.mjs +179 -0
  99. package/api/theme-edit/_part-words.mjs +33 -5
  100. package/api/theme-edit/_parts.d.mts +133 -0
  101. package/api/theme-edit/_parts.mjs +599 -10
  102. package/api/theme-edit/_picture-traits.d.mts +259 -0
  103. package/api/theme-edit/_picture-traits.mjs +1030 -0
  104. package/api/theme-edit/_preview.d.mts +95 -4
  105. package/api/theme-edit/_preview.mjs +284 -31
  106. package/api/theme-edit/_project.d.mts +14 -4
  107. package/api/theme-edit/_project.mjs +95 -26
  108. package/api/theme-edit/_resolved.d.mts +46 -0
  109. package/api/theme-edit/_resolved.mjs +800 -0
  110. package/api/theme-edit/_set-line.d.mts +29 -0
  111. package/api/theme-edit/_set-line.mjs +100 -0
  112. package/api/theme-edit/_settings.d.mts +625 -28
  113. package/api/theme-edit/_settings.mjs +4867 -888
  114. package/api/theme-edit/_tables.d.mts +25 -1
  115. package/api/theme-edit/_tables.mjs +115 -11
  116. package/api/theme-edit/_text-looks.d.mts +78 -0
  117. package/api/theme-edit/_text-looks.mjs +376 -0
  118. package/api/theme-edit/_vet.d.mts +3 -26
  119. package/api/theme-edit/_vet.mjs +5 -89
  120. package/api/theme-edit/how/how.d.mts +1 -1
  121. package/api/theme-edit/how/how.mjs +1 -1
  122. package/api/theme-edit/show/show.d.mts +4 -3
  123. package/api/theme-edit/show/show.mjs +3 -2
  124. package/api/theme-edit/theme-edit.type.d.mts +117 -1
  125. package/api/theme-edit/theme-edit.type.mjs +46 -3
  126. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  128. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  129. package/api/theme-edit/themeEditShow.doc.mjs +22 -3
  130. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  131. package/assets/component-list.generated.json +1 -1
  132. package/assets/docs/author-a-theme.doc.mjs +7 -4
  133. package/assets/docs/icons.doc.mjs +7 -6
  134. package/assets/docs/theme.doc.dense.mjs +10 -0
  135. package/assets/docs/theme.doc.mjs +10 -0
  136. package/assets/docs/theme.doc.zh.mjs +10 -0
  137. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  138. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  139. package/assets/docs/use-a-theme.doc.mjs +89 -17
  140. package/assets/docs-routes.generated.json +1 -1
  141. package/assets/docs.generated.json +2 -2
  142. package/assets/icons/definitions/article.doc.mjs +9 -0
  143. package/assets/icons/template-icons.json +5 -0
  144. package/assets/search-catalog.generated.json +2 -2
  145. package/assets/self-audit.generated.json +1 -1
  146. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  147. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  148. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  149. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  150. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  151. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  152. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  153. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  154. package/assets/templates/components.generated.json +1 -1
  155. package/assets/templates/pages/ide/page.tsx +5 -10
  156. package/assets/templates/pages/payment-form/page.tsx +16 -60
  157. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  158. package/authoring/config/parse.mjs +1 -1
  159. package/authoring/debug/parse.d.mts +1 -1
  160. package/authoring/doctypes/_schema.d.mts +13 -13
  161. package/authoring/doctypes/icon-definition/parse.mjs +2 -2
  162. package/authoring/doctypes/icon-set/parse.mjs +1 -1
  163. package/authoring/doctypes/template/parse.mjs +1 -4
  164. package/authoring/gap-report/parse.d.mts +1 -1
  165. package/clients/cli/build-id.generated.json +1 -1
  166. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  167. package/clients/cli/commands/experimental/icon.mjs +7 -7
  168. package/clients/cli/commands/experimental/theme.mjs +175 -13
  169. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  170. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  171. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  172. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  173. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +15 -5
  174. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  175. package/clients/cli/commands/hook.mjs +7 -0
  176. package/clients/cli/commands/template.mjs +1 -1
  177. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  178. package/clients/cli/index.mjs +6 -2
  179. package/clients/cli/lib/hook-format.mjs +41 -1
  180. package/clients/cli/lib/json-shim.mjs +34 -14
  181. package/clients/cli/lib/other-cli-words.mjs +7 -0
  182. package/clients/cli/lib/unknown-command.mjs +345 -46
  183. package/clients/cli/manifest.generated.json +1 -1
  184. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  185. package/foundation/agent-docs/agent-docs.mjs +51 -8
  186. package/foundation/config/project.d.mts +11 -1
  187. package/foundation/config/project.mjs +11 -2
  188. package/foundation/discovery/component-replacement.d.mts +5 -8
  189. package/foundation/discovery/component-replacement.mjs +12 -14
  190. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  191. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  192. package/foundation/discovery/core-elements.d.mts +6 -0
  193. package/foundation/discovery/core-elements.mjs +10 -2
  194. package/foundation/discovery/core-prop-types.d.mts +5 -0
  195. package/foundation/discovery/core-prop-types.mjs +10 -3
  196. package/foundation/discovery/core-props.d.mts +8 -0
  197. package/foundation/discovery/core-props.mjs +29 -13
  198. package/foundation/discovery/icon-ranking.d.mts +5 -2
  199. package/foundation/discovery/icon-ranking.mjs +101 -18
  200. package/foundation/discovery/icon-set-checks.mjs +1 -1
  201. package/foundation/discovery/icon-set-writer.mjs +1 -1
  202. package/foundation/discovery/official-list.d.mts +17 -0
  203. package/foundation/discovery/official-list.mjs +77 -0
  204. package/foundation/discovery/template-icon-notes.mjs +3 -3
  205. package/foundation/discovery/template-icons.mjs +2 -2
  206. package/foundation/discovery/template-placeholders.mjs +1 -1
  207. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  208. package/foundation/discovery/unknown-core-props.mjs +601 -0
  209. package/foundation/discovery/written-prop-values.d.mts +35 -0
  210. package/foundation/discovery/written-prop-values.mjs +258 -0
  211. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  212. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  213. package/foundation/fs/package-name.d.mts +10 -0
  214. package/foundation/fs/package-name.mjs +37 -0
  215. package/foundation/fs/project-source-files.d.mts +27 -0
  216. package/foundation/fs/project-source-files.mjs +115 -0
  217. package/foundation/fs/project-sources.d.mts +25 -0
  218. package/foundation/fs/project-sources.mjs +83 -0
  219. package/foundation/fs/read-record.d.mts +18 -0
  220. package/foundation/fs/read-record.mjs +36 -2
  221. package/foundation/integrations/integration-warnings.d.mts +39 -7
  222. package/foundation/integrations/integration-warnings.mjs +141 -19
  223. package/foundation/integrations/missing-dependency.d.mts +11 -0
  224. package/foundation/integrations/missing-dependency.mjs +20 -5
  225. package/foundation/release/folder-lock.d.mts +5 -2
  226. package/foundation/release/folder-lock.mjs +9 -3
  227. package/foundation/release/notices.mjs +2 -8
  228. package/foundation/render/cut-short.d.mts +8 -2
  229. package/foundation/render/cut-short.mjs +50 -5
  230. package/foundation/render/drawn-contrast.d.mts +40 -0
  231. package/foundation/render/drawn-contrast.mjs +355 -0
  232. package/foundation/render/file-header.mjs +4 -0
  233. package/foundation/render/layers.d.mts +2 -1
  234. package/foundation/render/layers.mjs +22 -1
  235. package/foundation/render/package-resolve-hooks.d.mts +38 -9
  236. package/foundation/render/package-resolve-hooks.mjs +124 -32
  237. package/foundation/render/page-worker.mjs +95 -23
  238. package/foundation/render/part-boxes.d.mts +27 -0
  239. package/foundation/render/part-boxes.mjs +45 -0
  240. package/foundation/render/picture-chrome.mjs +36 -4
  241. package/foundation/render/picture-playwright.mjs +26 -2
  242. package/foundation/render/picture-window.d.mts +29 -2
  243. package/foundation/render/picture-window.mjs +99 -1
  244. package/foundation/render/render-page.d.mts +39 -6
  245. package/foundation/render/render-page.mjs +26 -10
  246. package/foundation/render/ts-paths.mjs +2 -1
  247. package/foundation/response/error-codes.doc.mjs +1 -1
  248. package/foundation/response/error-codes.mjs +1 -1
  249. package/foundation/response/response-types.doc.mjs +9 -5
  250. package/foundation/suggest/other-command.mjs +25 -1
  251. package/foundation/text/icon-set-next.d.mts +1 -1
  252. package/foundation/text/icon-set-next.mjs +2 -2
  253. package/foundation/text/written-string.d.mts +4 -1
  254. package/foundation/text/written-string.mjs +4 -1
  255. package/package.json +8 -7
@@ -88,7 +88,7 @@
88
88
  * @property {number} data.matchCount - Every match, before `limit`.
89
89
  * @property {IconMatchEntry[]} data.matches - The ranked matches, at most `limit`.
90
90
  * @property {string} [data.reason] - Present when no icon set is installed: why nothing matches.
91
- * @property {IconSearchDefinition[]} [data.definitions] - Present when no icon set is installed: the Astryx icon definitions that match, built-in ones first, at most `limit`.
91
+ * @property {IconSearchDefinition[]} [data.definitions] - Present when no icon set is installed: the Astryx icon definitions that match, built-in ones first, with the built-in that draws in place of a matching definition Core does not draw (`help` brings `info`) unless a match ranked above it has none, at most `limit`.
92
92
  * @property {string} [data.next] - Present when no icon set is installed: how to get one.
93
93
  */
94
94
 
@@ -447,6 +447,7 @@
447
447
  * are the ranker's input, not a contract: they may change in any release,
448
448
  * which is why `version` must match.
449
449
  * @property {Array<{name: string, package: string, reason: string}>} withdrawn - The sets read but withdrawn, and why, so a `set` that names one gives the same error as `icon()`.
450
+ * @property {string[]} [components] - The names of the folder's Core components, so a query's words that name one say where the icon goes, as with `icon()`.
450
451
  */
451
452
 
452
453
  export {};
@@ -14,7 +14,11 @@
14
14
  import {cliVersion} from '../../../foundation/release/run-context.mjs';
15
15
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
16
16
  import {AstryxError} from '../../error.mjs';
17
- import {loadIconSets, ownReplacedDefinitions} from '../_adapter.mjs';
17
+ import {
18
+ coreComponentNames,
19
+ loadIconSets,
20
+ ownReplacedDefinitions,
21
+ } from '../_adapter.mjs';
18
22
  import {
19
23
  REFERENCE_RE,
20
24
  checkIconLimit,
@@ -80,6 +84,7 @@ export async function exportIconIndex(options = {}) {
80
84
  withdrawn: withdrawn
81
85
  .filter(kept)
82
86
  .map(({name, package: pkg, reason}) => ({name, package: pkg, reason})),
87
+ components: coreComponentNames(cwd),
83
88
  };
84
89
  }
85
90
 
@@ -121,10 +126,12 @@ export async function rankIconIndex(query, indexes, options = {}) {
121
126
  const sets = [];
122
127
  /** @type {Array<{name: string, package: string, reason: string}>} */
123
128
  const withdrawn = [];
129
+ /** @type {Set<string>} */
130
+ const components = new Set();
124
131
  for (const index of list) {
125
132
  if (index == null || !Array.isArray(index.sets)) {
126
133
  throw new AstryxError(
127
- 'An icon index is {version, sets, withdrawn}, as exportIconIndex() returns it.',
134
+ 'An icon index is {version, sets, withdrawn, components}, as exportIconIndex() returns it.',
128
135
  undefined,
129
136
  ERROR_CODES.ERR_INVALID_ARGUMENT,
130
137
  );
@@ -138,6 +145,7 @@ export async function rankIconIndex(query, indexes, options = {}) {
138
145
  }
139
146
  sets.push(...index.sets);
140
147
  withdrawn.push(...(index.withdrawn ?? []));
148
+ for (const name of index.components ?? []) components.add(name);
141
149
  }
142
150
  // A stored set holds exactly the fields the ranking reads.
143
151
  const ranked = /** @type {Parameters<typeof rankIconSets>[0]} */ (
@@ -148,5 +156,10 @@ export async function rankIconIndex(query, indexes, options = {}) {
148
156
  for (const each of sets) {
149
157
  if (each.look) looks[`${each.package}/${each.name}`] = each.look;
150
158
  }
151
- return rankIconSets(ranked, withdrawn, term, {set, limit, looks});
159
+ return rankIconSets(ranked, withdrawn, term, {
160
+ set,
161
+ limit,
162
+ looks,
163
+ componentNames: () => components,
164
+ });
152
165
  }
@@ -41,24 +41,30 @@ export function projectLooks(choice: import("../../../foundation/discovery/icon-
41
41
  * names for its set when its icon has that look, and a match that a
42
42
  * definition names also has its meaning import. With no set installed, not
43
43
  * even a withdrawn one, the answer names the Astryx icon definitions that
44
- * match, built-in ones first, and how to get a set.
44
+ * match, built-in ones first, with the built-in that draws in place of a
45
+ * matching definition Core does not draw (unless a match ranked above it has
46
+ * none),
47
+ * and how to get a set.
45
48
  * @param {Parameters<typeof rankIcons>[0]} sets in tie order
46
49
  * @param {Array<{name: string, package: string, reason: string}>} withdrawn
47
50
  * @param {string} query
48
- * @param {{set?: string, limit: number, looks?: Record<string, string>, discoverListsPacks?: boolean}} options
51
+ * @param {{set?: string, limit: number, looks?: Record<string, string>, discoverListsPacks?: boolean, componentNames?: () => Iterable<string>}} options
49
52
  * `looks`: the look each set draws, by `<package>/<set>`;
50
- * `discoverListsPacks`: discover lists an icon set the project could add
53
+ * `discoverListsPacks`: discover lists an icon set the project could add;
54
+ * `componentNames`: the component names a query's words may name to say
55
+ * where the icon goes
51
56
  * @returns {import('../icon.type.mjs').IconSearchResponse}
52
57
  */
53
58
  export function rankIconSets(sets: Parameters<typeof rankIcons>[0], withdrawn: Array<{
54
59
  name: string;
55
60
  package: string;
56
61
  reason: string;
57
- }>, query: string, { set, limit, looks, discoverListsPacks }: {
62
+ }>, query: string, { set, limit, looks, discoverListsPacks, componentNames }: {
58
63
  set?: string;
59
64
  limit: number;
60
65
  looks?: Record<string, string>;
61
66
  discoverListsPacks?: boolean;
67
+ componentNames?: () => Iterable<string>;
62
68
  }): import("../icon.type.mjs").IconSearchResponse;
63
69
  /**
64
70
  * The icon definitions that answer a query, each with its score, ranked as
@@ -67,9 +73,13 @@ export function rankIconSets(sets: Parameters<typeof rankIcons>[0], withdrawn: A
67
73
  * @param {import('../../../authoring/doctypes/icon-definition/type').IconDefinitionDoc[]} [docs]
68
74
  * @param {Replacements} [replacements] the old names of a set's own
69
75
  * definitions among `docs`, so that a name they replaced answers too
76
+ * @param {{componentNames?: () => Iterable<string>}} [options] the
77
+ * component names a query's words may name to say where the icon goes
70
78
  * @returns {Array<{doc: import('../../../authoring/doctypes/icon-definition/type').IconDefinitionDoc, score: number}>}
71
79
  */
72
- export function definitionMatches(query: string, docs?: import("../../../authoring/doctypes/icon-definition/type").IconDefinitionDoc[], replacements?: Replacements): Array<{
80
+ export function definitionMatches(query: string, docs?: import("../../../authoring/doctypes/icon-definition/type").IconDefinitionDoc[], replacements?: Replacements, { componentNames }?: {
81
+ componentNames?: () => Iterable<string>;
82
+ }): Array<{
73
83
  doc: import("../../../authoring/doctypes/icon-definition/type").IconDefinitionDoc;
74
84
  score: number;
75
85
  }>;
@@ -12,6 +12,7 @@
12
12
 
13
13
  import {
14
14
  astryxIconDefinitions,
15
+ coreComponentNames,
15
16
  discoverListsIconSet,
16
17
  definitionRelatives,
17
18
  iconExportName,
@@ -19,6 +20,7 @@ import {
19
20
  iconSetKey,
20
21
  importLine,
21
22
  loadIconSets,
23
+ meaningWithFallbacks,
22
24
  missingIconLook,
23
25
  noIconSetNext,
24
26
  } from '../_adapter.mjs';
@@ -77,11 +79,14 @@ export async function iconSetIcons({cwd, set}) {
77
79
  export async function iconSearch(query, {cwd, set, limit}) {
78
80
  const {sets, withdrawn, choice} = await loadIconSets(cwd);
79
81
  const noSet = sets.length === 0 && withdrawn.length === 0;
82
+ /** @type {string[] | undefined} */
83
+ let names;
80
84
  return rankIconSets(sets, withdrawn, query, {
81
85
  set,
82
86
  limit,
83
87
  looks: projectLooks(choice),
84
88
  discoverListsPacks: noSet && (await discoverListsIconSet(cwd)),
89
+ componentNames: () => (names ??= coreComponentNames(cwd)),
85
90
  });
86
91
  }
87
92
 
@@ -97,9 +102,11 @@ export async function iconSearch(query, {cwd, set, limit}) {
97
102
  * @param {string} query
98
103
  * @param {Parameters<typeof rankIcons>[0]} sets the searched sets, whose own
99
104
  * definitions rank with Astryx's
105
+ * @param {() => Iterable<string>} [componentNames] the component names a
106
+ * query's words may name to say where the icon goes
100
107
  * @returns {import('../icon.type.mjs').IconMatchEntry[]}
101
108
  */
102
- function withMeaningImports(matches, query, sets) {
109
+ function withMeaningImports(matches, query, sets, componentNames) {
103
110
  if (!matches.some(match => match.definitions.length > 0)) return matches;
104
111
  /** @type {Map<unknown, (name: string) => number>} */
105
112
  const ranks = new Map();
@@ -113,7 +120,7 @@ function withMeaningImports(matches, query, sets) {
113
120
  const key = own.length > 0 ? set : null;
114
121
  let rank = ranks.get(key);
115
122
  if (!rank) {
116
- rank = meaningRank(query, set);
123
+ rank = meaningRank(query, set, componentNames);
117
124
  ranks.set(key, rank);
118
125
  }
119
126
  return rank;
@@ -144,9 +151,11 @@ function withMeaningImports(matches, query, sets) {
144
151
  * @param {string} query
145
152
  * @param {Parameters<typeof rankIcons>[0][number] | undefined} set the
146
153
  * match's set
154
+ * @param {() => Iterable<string>} [componentNames] the component names a
155
+ * query's words may name to say where the icon goes
147
156
  * @returns {(name: string) => number}
148
157
  */
149
- function meaningRank(query, set) {
158
+ function meaningRank(query, set, componentNames) {
150
159
  const own = set?.definitions ?? [];
151
160
  const astryx = astryxIconDefinitions().definitions.map(each => each.doc);
152
161
  const names = new Set(astryx.map(doc => doc.name));
@@ -154,7 +163,7 @@ function meaningRank(query, set) {
154
163
  ...astryx,
155
164
  ...own.map(each => each.doc).filter(doc => !names.has(doc.name)),
156
165
  ];
157
- const matched = definitionMatches(query, docs, set).map(
166
+ const matched = definitionMatches(query, docs, set, {componentNames}).map(
158
167
  match => match.doc.name,
159
168
  );
160
169
  const place = new Map(matched.map((name, index) => [name, index]));
@@ -186,20 +195,25 @@ export function projectLooks(choice) {
186
195
  * names for its set when its icon has that look, and a match that a
187
196
  * definition names also has its meaning import. With no set installed, not
188
197
  * even a withdrawn one, the answer names the Astryx icon definitions that
189
- * match, built-in ones first, and how to get a set.
198
+ * match, built-in ones first, with the built-in that draws in place of a
199
+ * matching definition Core does not draw (unless a match ranked above it has
200
+ * none),
201
+ * and how to get a set.
190
202
  * @param {Parameters<typeof rankIcons>[0]} sets in tie order
191
203
  * @param {Array<{name: string, package: string, reason: string}>} withdrawn
192
204
  * @param {string} query
193
- * @param {{set?: string, limit: number, looks?: Record<string, string>, discoverListsPacks?: boolean}} options
205
+ * @param {{set?: string, limit: number, looks?: Record<string, string>, discoverListsPacks?: boolean, componentNames?: () => Iterable<string>}} options
194
206
  * `looks`: the look each set draws, by `<package>/<set>`;
195
- * `discoverListsPacks`: discover lists an icon set the project could add
207
+ * `discoverListsPacks`: discover lists an icon set the project could add;
208
+ * `componentNames`: the component names a query's words may name to say
209
+ * where the icon goes
196
210
  * @returns {import('../icon.type.mjs').IconSearchResponse}
197
211
  */
198
212
  export function rankIconSets(
199
213
  sets,
200
214
  withdrawn,
201
215
  query,
202
- {set, limit, looks = {}, discoverListsPacks = false},
216
+ {set, limit, looks = {}, discoverListsPacks = false, componentNames},
203
217
  ) {
204
218
  let searched = sets;
205
219
  if (set != null) {
@@ -208,9 +222,9 @@ export function rankIconSets(
208
222
  }
209
223
  // A withdrawn set is installed: `--list` says why it cannot be used.
210
224
  if (sets.length === 0 && withdrawn.length === 0) {
211
- return noIconSet(query, limit, discoverListsPacks);
225
+ return noIconSet(query, limit, discoverListsPacks, componentNames);
212
226
  }
213
- const ranked = rankIcons(searched, query, {words: true});
227
+ const ranked = rankIcons(searched, query, {words: true, componentNames});
214
228
  // A word start (`start` for `star`) answers only when nothing matches a
215
229
  // whole word, and a partial match (`pin` inside `shopping`) only when
216
230
  // nothing matches a whole word or a word start.
@@ -228,6 +242,7 @@ export function rankIconSets(
228
242
  ),
229
243
  query,
230
244
  searched,
245
+ componentNames,
231
246
  ),
232
247
  },
233
248
  };
@@ -289,19 +304,56 @@ function inLook(match, sets, looks) {
289
304
  /**
290
305
  * The answer when no icon set is installed: no icon matches, so it names
291
306
  * the Astryx icon definitions that do, built-in ones first (Core draws those
292
- * by name with no set), and how to get a set.
307
+ * by name with no set) with the built-in that draws in place of a matching
308
+ * definition Core does not draw, unless a match ranked above it has none,
309
+ * and how to get a set.
293
310
  * @param {string} query
294
311
  * @param {number} limit
295
312
  * @param {boolean} discoverListsPacks
313
+ * @param {() => Iterable<string>} [componentNames] the component names a
314
+ * query's words may name to say where the icon goes
296
315
  * @returns {import('../icon.type.mjs').IconSearchResponse}
297
316
  */
298
- function noIconSet(query, limit, discoverListsPacks) {
317
+ function noIconSet(query, limit, discoverListsPacks, componentNames) {
299
318
  const docs = astryxIconDefinitions().definitions.map(each => each.doc);
300
- const found = definitionMatches(query).map(match => match.doc);
301
- const ordered = [
319
+ const byName = new Map(docs.map(doc => [doc.name, doc]));
320
+ const found = definitionMatches(query, docs, {}, {componentNames}).map(
321
+ match => match.doc,
322
+ );
323
+ const matched = new Set(
324
+ found.filter(doc => doc.builtIn).map(doc => doc.name),
325
+ );
326
+ // With no set, Core draws only the built-in definitions, so a matching
327
+ // definition that Core does not draw lists the built-in that draws in its
328
+ // place (FR23's fallback). Only the ones that rank above every matching
329
+ // definition with no such built-in count: a match ranked above that Core
330
+ // cannot draw at all is what the ask names (`settings`), not a weaker
331
+ // match's fallback. A built-in the query matches too takes the better of
332
+ // its own place and theirs; one that only a fallback brings comes after
333
+ // the built-ins that match.
334
+ /** @param {(typeof docs)[number]} doc */
335
+ const drawnAs = doc =>
336
+ meaningWithFallbacks(doc.name)
337
+ .map(name => byName.get(name))
338
+ .find(each => each?.builtIn);
339
+ const end = found.findIndex(doc => !drawnAs(doc));
340
+ const counted = end < 0 ? found : found.slice(0, end);
341
+ const builtIns = [
342
+ ...counted.flatMap(doc => {
343
+ const drawn = drawnAs(doc);
344
+ return drawn && matched.has(drawn.name) ? [drawn] : [];
345
+ }),
302
346
  ...found.filter(doc => doc.builtIn),
303
- ...found.filter(doc => !doc.builtIn),
304
347
  ];
348
+ const brought = counted.flatMap(doc => {
349
+ const drawn = doc.builtIn ? undefined : drawnAs(doc);
350
+ return drawn && !matched.has(drawn.name) ? [drawn] : [];
351
+ });
352
+ const ordered = [
353
+ ...builtIns,
354
+ ...brought,
355
+ ...found.filter(doc => !doc.builtIn),
356
+ ].filter((doc, i, list) => list.findIndex(o => o.name === doc.name) === i);
305
357
  return {
306
358
  type: 'icon.search',
307
359
  data: {
@@ -331,16 +383,22 @@ function noIconSet(query, limit, discoverListsPacks) {
331
383
  * @param {import('../../../authoring/doctypes/icon-definition/type').IconDefinitionDoc[]} [docs]
332
384
  * @param {Replacements} [replacements] the old names of a set's own
333
385
  * definitions among `docs`, so that a name they replaced answers too
386
+ * @param {{componentNames?: () => Iterable<string>}} [options] the
387
+ * component names a query's words may name to say where the icon goes
334
388
  * @returns {Array<{doc: import('../../../authoring/doctypes/icon-definition/type').IconDefinitionDoc, score: number}>}
335
389
  */
336
390
  export function definitionMatches(
337
391
  query,
338
392
  docs = astryxIconDefinitions().definitions.map(each => each.doc),
339
393
  replacements = {},
394
+ {componentNames} = {},
340
395
  ) {
341
396
  const byId = new Map(docs.map(doc => [definitionId(doc.name), doc]));
342
397
  return answeringMatches(
343
- rankIcons([definitionSet(docs, replacements)], query, {words: true}),
398
+ rankIcons([definitionSet(docs, replacements)], query, {
399
+ words: true,
400
+ componentNames,
401
+ }),
344
402
  ).map(match => ({
345
403
  doc: /** @type {(typeof docs)[number]} */ (byId.get(match.id)),
346
404
  score: match.score,
@@ -77,21 +77,21 @@ function checkVariant(main, selector, backups, variant) {
77
77
  const fallback = main.data.default?.variant;
78
78
  throw new AstryxError(
79
79
  declared.length === 0
80
- ? `Icon set "${iconSetKey(main)}" declares no variants: it draws one look, so it takes no --variant.`
80
+ ? `Icon set "${iconSetKey(main)}" declares no variants, so it takes no --variant.`
81
81
  : `Icon set "${iconSetKey(main)}" declares no "${variant}" variant. Its variants: ${declared.join(', ')}.`,
82
82
  declared.length === 0
83
83
  ? [
84
84
  {
85
85
  name: iconUseCommand(selector, backups),
86
- reason: 'use it in its one look',
86
+ reason: 'use it as it is',
87
87
  },
88
88
  ]
89
89
  : declared.map(each => ({
90
90
  name: iconUseCommand(selector, backups, each),
91
91
  reason:
92
92
  each === fallback
93
- ? `its default look, ${each}`
94
- : `its ${each} look`,
93
+ ? `its default variant, ${each}`
94
+ : `its ${each} variant`,
95
95
  })),
96
96
  ERROR_CODES.ERR_INVALID_ARGUMENT,
97
97
  );