@astryxdesign/cli 0.7.11 → 0.7.12-canary.0840fcc

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 (160) hide show
  1. package/api/build/blocks/blocks.d.mts +41 -0
  2. package/api/build/blocks/blocks.mjs +118 -68
  3. package/api/build/kit/rank.mjs +21 -4
  4. package/api/build/kit/words.d.mts +1 -0
  5. package/api/build/kit/words.mjs +1 -1
  6. package/api/component/__fixtures__/resolutions/modules.txt +5 -5
  7. package/api/docs/_adapter.d.mts +22 -0
  8. package/api/docs/_adapter.mjs +81 -3
  9. package/api/docs/docs.doc.mjs +5 -5
  10. package/api/docs/docs.type.d.mts +21 -0
  11. package/api/docs/docs.type.mjs +11 -0
  12. package/api/docs/list/list.d.mts +5 -1
  13. package/api/docs/list/list.mjs +72 -6
  14. package/api/docs/node/node.mjs +2 -40
  15. package/api/icon/_adapter.d.mts +3 -2
  16. package/api/icon/_adapter.mjs +8 -2
  17. package/api/icon/_authoring.d.mts +1 -0
  18. package/api/icon/_authoring.mjs +594 -67
  19. package/api/icon/_default-look.d.mts +155 -0
  20. package/api/icon/_default-look.mjs +474 -0
  21. package/api/icon/_records.d.mts +1 -1
  22. package/api/icon/_records.mjs +1 -0
  23. package/api/icon/add/add.mjs +269 -43
  24. package/api/icon/icon.type.d.mts +46 -2
  25. package/api/icon/icon.type.mjs +12 -2
  26. package/api/icon/iconAdd.doc.mjs +2 -2
  27. package/api/icon/iconNewDefinition.doc.mjs +3 -2
  28. package/api/icon/iconNewSet.doc.mjs +4 -4
  29. package/api/icon/map/map.mjs +11 -4
  30. package/api/icon/search/search.mjs +10 -9
  31. package/api/index.d.mts +1 -0
  32. package/api/index.mjs +1 -0
  33. package/api/integration/add-helpers.d.mts +15 -1
  34. package/api/integration/add-helpers.mjs +5 -2
  35. package/api/integration/authoring-checks.d.mts +0 -2
  36. package/api/integration/authoring-checks.mjs +1 -6
  37. package/api/logger.mjs +2 -1
  38. package/api/render/_adapter.mjs +9 -0
  39. package/api/render/render.doc.mjs +3 -3
  40. package/api/render/render.type.d.mts +1 -1
  41. package/api/render/render.type.mjs +1 -1
  42. package/api/search/ORDERING.md +3 -0
  43. package/api/search/_adapter.d.mts +32 -3
  44. package/api/search/_adapter.mjs +50 -22
  45. package/api/search/_fit-order.d.mts +47 -0
  46. package/api/search/_fit-order.mjs +257 -0
  47. package/api/search/_main-searcher.mjs +15 -5
  48. package/api/search/exportSearchIndex.doc.d.mts +10 -0
  49. package/api/search/exportSearchIndex.doc.mjs +58 -0
  50. package/api/search/rankSearchIndex.doc.d.mts +10 -0
  51. package/api/search/rankSearchIndex.doc.mjs +79 -0
  52. package/api/search/search-index.d.mts +44 -0
  53. package/api/search/search-index.mjs +270 -0
  54. package/api/search/search.type.d.mts +28 -0
  55. package/api/search/search.type.mjs +17 -0
  56. package/api/swizzle/_adapter.d.mts +1 -0
  57. package/api/swizzle/_adapter.mjs +4 -1
  58. package/api/swizzle/_moduleGraph.d.mts +178 -0
  59. package/api/swizzle/_moduleGraph.mjs +903 -0
  60. package/api/swizzle/copy/copy.d.mts +2 -43
  61. package/api/swizzle/copy/copy.mjs +287 -315
  62. package/api/swizzle/swizzle.d.mts +0 -2
  63. package/api/swizzle/swizzle.doc.mjs +13 -4
  64. package/api/swizzle/swizzle.mjs +3 -7
  65. package/api/swizzle/swizzle.type.d.mts +7 -1
  66. package/api/swizzle/swizzle.type.mjs +4 -2
  67. package/api/template/template.mjs +1 -0
  68. package/assets/discover/official-packages.json +36 -0
  69. package/assets/docs/browser-support.doc.mjs +2 -2
  70. package/assets/docs/styling-overview.doc.mjs +6 -2
  71. package/assets/docs/tree/icon-sets.doc.mjs +13 -7
  72. package/assets/docs/tree/render-pages.doc.mjs +3 -3
  73. package/assets/docs/tree/tailwind.doc.mjs +41 -1
  74. package/assets/docs/tree/type-scale.doc.mjs +19 -2
  75. package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.doc.mjs +14 -0
  76. package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.tsx +146 -0
  77. package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.doc.mjs +14 -0
  78. package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.tsx +173 -0
  79. package/assets/templates/blocks/components/Hooks/useInputStatusIconHookUsage.tsx +1 -0
  80. package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.doc.mjs +14 -0
  81. package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.tsx +56 -0
  82. package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.doc.mjs +2 -2
  83. package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +66 -10
  84. package/assets/templates/blocks/components/Link/useLinkifyHookUsage.doc.mjs +14 -0
  85. package/assets/templates/blocks/components/Link/useLinkifyHookUsage.tsx +39 -0
  86. package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjs +14 -0
  87. package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsx +83 -0
  88. package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.doc.mjs +14 -0
  89. package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.tsx +41 -0
  90. package/assets/templates/blocks/components/Table/TableRowIndexTable.doc.mjs +1 -1
  91. package/assets/templates/blocks/components/Table/TableRowIndexTable.tsx +2 -2
  92. package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.doc.mjs +14 -0
  93. package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.tsx +97 -0
  94. package/assets/templates/pages/course-detail/page.tsx +699 -0
  95. package/assets/templates/pages/course-detail/template.doc.mjs +37 -0
  96. package/assets/templates/pages/file-explorer/page.tsx +103 -79
  97. package/assets/templates/pages/table-filter/page.tsx +15 -23
  98. package/assets/templates/pages/table-grouped/page.tsx +160 -232
  99. package/assets/templates/pages/table-grouped/template.doc.mjs +0 -2
  100. package/assets/templates/pages/table-inbox/page.tsx +3 -6
  101. package/assets/templates/pages/theme-showcase/page.tsx +724 -792
  102. package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
  103. package/assets/templates/themes/butter/butterTheme.ts +2 -2
  104. package/assets/templates/themes/gothic/gothicTheme.ts +16 -0
  105. package/assets/templates/themes/matcha/matchaTheme.ts +1 -1
  106. package/assets/templates/themes/neutral/neutralTheme.ts +6 -0
  107. package/assets/templates/themes/stone/stoneTheme.ts +1 -1
  108. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +1 -1
  109. package/assets/templates/themes/y2k/y2kTheme.ts +2 -2
  110. package/authoring/doctypes/template/type.ts +1 -0
  111. package/clients/cli/commands/docs.doc.mjs +5 -1
  112. package/clients/cli/commands/docs.mjs +30 -2
  113. package/clients/cli/commands/experimental/icon.mjs +56 -14
  114. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  115. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
  116. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  117. package/clients/cli/commands/experimental-render.doc.mjs +1 -1
  118. package/clients/cli/commands/swizzle.doc.mjs +12 -3
  119. package/clients/cli/commands/swizzle.mjs +33 -9
  120. package/clients/cli/lib/resolve-theme.mjs +16 -7
  121. package/foundation/discovery/component-loader.d.mts +1 -1
  122. package/foundation/discovery/doc-types.mjs +9 -2
  123. package/foundation/discovery/hook-discovery.mjs +31 -8
  124. package/foundation/discovery/icon-ranking.d.mts +27 -3
  125. package/foundation/discovery/icon-ranking.mjs +125 -8
  126. package/foundation/discovery/icon-set-checks.mjs +44 -35
  127. package/foundation/discovery/icon-set-discovery.d.mts +13 -0
  128. package/foundation/discovery/icon-set-discovery.mjs +25 -0
  129. package/foundation/discovery/icon-set-writer.d.mts +258 -20
  130. package/foundation/discovery/icon-set-writer.mjs +785 -87
  131. package/foundation/discovery/module-exports.d.mts +3 -2
  132. package/foundation/discovery/module-exports.mjs +167 -37
  133. package/foundation/doc-compiler/import.d.mts +5 -1
  134. package/foundation/doc-compiler/import.mjs +40 -6
  135. package/foundation/fs/import-url.d.mts +20 -0
  136. package/foundation/fs/import-url.mjs +22 -0
  137. package/foundation/fs/module-loader.d.mts +24 -3
  138. package/foundation/fs/module-loader.mjs +69 -47
  139. package/foundation/fs/paths.d.mts +2 -1
  140. package/foundation/fs/paths.mjs +3 -4
  141. package/foundation/render/charts.d.mts +59 -0
  142. package/foundation/render/charts.mjs +216 -0
  143. package/foundation/render/embedded-imports.d.mts +7 -7
  144. package/foundation/render/embedded-imports.mjs +63 -54
  145. package/foundation/render/page-host.d.mts +4 -0
  146. package/foundation/render/page-host.mjs +45 -0
  147. package/foundation/render/page-worker.mjs +350 -57
  148. package/foundation/render/render-page.d.mts +11 -6
  149. package/foundation/render/render-page.mjs +164 -54
  150. package/foundation/render/ts-paths.d.mts +63 -0
  151. package/foundation/render/ts-paths.mjs +138 -0
  152. package/foundation/response/error-codes.doc.mjs +3 -3
  153. package/foundation/response/error-codes.mjs +3 -2
  154. package/foundation/text/levenshtein.d.mts +6 -1
  155. package/foundation/text/levenshtein.mjs +25 -9
  156. package/foundation/text/shell-arg.d.mts +14 -0
  157. package/foundation/text/shell-arg.mjs +17 -0
  158. package/foundation/text/suggest-order.d.mts +8 -1
  159. package/foundation/text/suggest-order.mjs +72 -6
  160. package/package.json +7 -6
@@ -12,6 +12,13 @@ import {levenshteinDistance} from '../text/string-utils.mjs';
12
12
 
13
13
  const SKIP_DIRS = new Set(['utils', '__tests__', 'node_modules']);
14
14
 
15
+ // A hook's doc outside src/hooks/: a `use…` hook, or a `create…` factory
16
+ // documented as one (its doc typed `HookDoc`, such as createReorderable).
17
+ const HOOK_DOC_FILE_RE = /^(?:use|create)[A-Z]\w*\.doc\.mjs$/;
18
+
19
+ // Matches the top-level `relatedHooks: [...]` field in a hook .doc.mjs file.
20
+ const RELATED_HOOKS_RE = /(?:^|\n) {0,4}relatedHooks:\s*\[([^\]]*)\]/;
21
+
15
22
  // Matches the top-level `category: 'categoryName'` field in a hook .doc.mjs file.
16
23
  const CATEGORY_RE = /(?:^|\n) {0,4}category:\s*['"]([^'"]+)['"]/;
17
24
 
@@ -32,6 +39,25 @@ function readHookMeta(docPath) {
32
39
  }
33
40
  }
34
41
 
42
+ /**
43
+ * Whether a `create…` factory's doc names its own `use…` hook in
44
+ * `relatedHooks`, as createAnimator's names useAnimator. Such a factory is
45
+ * listed beside that hook, not on its own.
46
+ * @param {string} docPath
47
+ * @param {string} hookName
48
+ * @returns {boolean}
49
+ */
50
+ function isBesideOwnHook(docPath, hookName) {
51
+ if (!hookName.startsWith('create')) return false;
52
+ const ownHook = `use${hookName.slice('create'.length)}`;
53
+ try {
54
+ const related = RELATED_HOOKS_RE.exec(fs.readFileSync(docPath, 'utf-8'));
55
+ return related != null && related[1].includes(`'${ownHook}'`);
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+
35
61
  /**
36
62
  * Extract the hook name from a doc filename.
37
63
  * e.g. 'useFocusTrap.doc.mjs' → 'useFocusTrap'
@@ -70,7 +96,8 @@ export function discoverHooks(coreDir) {
70
96
  }
71
97
  }
72
98
 
73
- // 2. Scan ALL component directories for files matching use*.doc.mjs
99
+ // 2. Scan ALL component directories for hook docs: use*.doc.mjs, and
100
+ // create*.doc.mjs for a factory documented as a hook (createReorderable)
74
101
  if (pathExists(srcDir)) {
75
102
  const topEntries = listDirEntries(srcDir);
76
103
  for (const entry of topEntries) {
@@ -120,14 +147,10 @@ function scanDirForHookDocs(dirPath, hookCategories) {
120
147
  for (const entry of entries) {
121
148
  if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) {
122
149
  scanDirForHookDocs(path.join(dirPath, entry.name), hookCategories);
123
- } else if (
124
- entry.isFile() &&
125
- entry.name.startsWith('use') &&
126
- entry.name.endsWith('.doc.mjs')
127
- ) {
150
+ } else if (entry.isFile() && HOOK_DOC_FILE_RE.test(entry.name)) {
128
151
  const hookName = hookNameFromFile(entry.name);
129
- if (!hookCategories.has(hookName)) {
130
- const docPath = path.join(dirPath, entry.name);
152
+ const docPath = path.join(dirPath, entry.name);
153
+ if (!hookCategories.has(hookName) && !isBesideOwnHook(docPath, hookName)) {
131
154
  const {category} = readHookMeta(docPath);
132
155
  hookCategories.set(hookName, category || 'Other');
133
156
  }
@@ -30,7 +30,9 @@ export function iconRecord(set: DiscoveredIconSet, icon: IconSetIcon, definition
30
30
  * @property {boolean} meaning the query is one of the icon's tags (never
31
31
  * both: a tag is a word that is not the id or one of its parts)
32
32
  * @property {number} rank within-tier key, lower first: for a name match 0
33
- * (whole id) or 1 (an id part); for a meaning match the tag's position
33
+ * (whole id), 1 (the whole id's plural or singular), 2 (an id part), or 3
34
+ * (an id part's plural or singular); for a meaning match the tag's
35
+ * position
34
36
  * @property {string} reason
35
37
  */
36
38
  /**
@@ -41,6 +43,24 @@ export function iconRecord(set: DiscoveredIconSet, icon: IconSetIcon, definition
41
43
  * @returns {IconMatch | null}
42
44
  */
43
45
  export function matchIcon(query: string, icon: IconSetIcon, definitions?: string[]): IconMatch | null;
46
+ /**
47
+ * The query without the words that only phrase it, when it has several
48
+ * words and some word names something; else the query as typed.
49
+ * @param {string} query
50
+ */
51
+ export function iconQuery(query: string): string;
52
+ /**
53
+ * The matches that answer a query: the whole-word ones (a definition or an
54
+ * exact match, 80 and up) when there are any, else word starts (60) when
55
+ * there are any, else partial matches. A longer word that only starts with
56
+ * the query (`start` for `star`) never stands beside a whole-word answer.
57
+ * @template {{score: number}} T
58
+ * @param {T[]} ranked best first
59
+ * @returns {T[]}
60
+ */
61
+ export function answeringMatches<T extends {
62
+ score: number;
63
+ }>(ranked: T[]): T[];
44
64
  /**
45
65
  * Which exact reading leads for a set of matches: meaning, unless more icons
46
66
  * carry the query as a name than as a tag.
@@ -78,7 +98,9 @@ export function withDefinitionWords(icon: IconSetIcon, definitions: string[], lo
78
98
  words: string[];
79
99
  } | undefined): IconSetIcon;
80
100
  /**
81
- * Every icon in `sets` that answers the query, ranked (FR6).
101
+ * Every icon in `sets` that answers the query, ranked. The query is
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}).
82
104
  * @param {DiscoveredIconSet[]} sets in tie order
83
105
  * @param {string} query
84
106
  * @returns {IconMatchEntry[]}
@@ -106,7 +128,9 @@ export type IconMatch = {
106
128
  meaning: boolean;
107
129
  /**
108
130
  * within-tier key, lower first: for a name match 0
109
- * (whole id) or 1 (an id part); for a meaning match the tag's position
131
+ * (whole id), 1 (the whole id's plural or singular), 2 (an id part), or 3
132
+ * (an id part's plural or singular); for a meaning match the tag's
133
+ * position
110
134
  */
111
135
  rank: number;
112
136
  reason: string;
@@ -9,8 +9,18 @@
9
9
  * 90 an exact match in the reading the searched sets favor (below)
10
10
  * 80 an exact match in the other reading
11
11
  * 60 one of its words starts with the query
12
- * 40 a partial match: the id or a word contains the query, or every
13
- * word of the query starts one of the icon's words or id parts
12
+ * 40 a partial match: the id or a word contains the query (three
13
+ * letters or more), or every word of the query starts one of the
14
+ * icon's words or id parts
15
+ *
16
+ * A word matches a whole word: a word's plural or singular (`stars` for
17
+ * `star`) is an exact match, while a longer word that only starts with it
18
+ * (`start`) is a word-start match, and {@link answeringMatches} keeps
19
+ * word-start and partial matches only when nothing matches a whole word.
20
+ * A query is scored as typed first. Only when nothing answers it with a
21
+ * whole word are the words that only phrase it (`go`, `the`, `icon`) left
22
+ * 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`.
14
24
  *
15
25
  * An exact match is a NAME match when the query is the icon's id, or one of
16
26
  * its words that is also a part of its id (`trash` for `trash-2`); it is a
@@ -26,7 +36,8 @@
26
36
  *
27
37
  * Equal scores keep the set order first (the project's set, then load
28
38
  * order), so the project's set always leads at a score. Within one set, a
29
- * name match on the whole id comes before one on a part of it, and a meaning
39
+ * name match on the whole id (or its plural or singular) comes before one on
40
+ * a part of it, and a meaning
30
41
  * match whose query sits earlier among the icon's tags comes first (sets list
31
42
  * an icon's most telling tags first). Remaining ties keep id order, so the
32
43
  * same installation always answers the same way.
@@ -93,7 +104,9 @@ const squash = value => value.toLowerCase().replace(/[\s_-]+/g, '');
93
104
  * @property {boolean} meaning the query is one of the icon's tags (never
94
105
  * both: a tag is a word that is not the id or one of its parts)
95
106
  * @property {number} rank within-tier key, lower first: for a name match 0
96
- * (whole id) or 1 (an id part); for a meaning match the tag's position
107
+ * (whole id), 1 (the whole id's plural or singular), 2 (an id part), or 3
108
+ * (an id part's plural or singular); for a meaning match the tag's
109
+ * position
97
110
  * @property {string} reason
98
111
  */
99
112
 
@@ -127,10 +140,27 @@ export function matchIcon(query, icon, definitions = []) {
127
140
  tier: 'exact',
128
141
  name: wholeId || partWord,
129
142
  meaning: !wholeId && !partWord,
130
- rank: wholeId ? 0 : partWord ? 1 : tagAt,
143
+ rank: wholeId ? 0 : partWord ? 2 : tagAt,
131
144
  reason: wholeId ? `id "${icon.id}"` : `word "${query}"`,
132
145
  };
133
146
  }
147
+ const plural = icon.words.find(word => sameWord(word, query));
148
+ if (plural) {
149
+ const named = parts.has(plural);
150
+ return {
151
+ tier: 'exact',
152
+ name: named,
153
+ meaning: !named,
154
+ // The whole id's plural or singular right after the whole id, then
155
+ // after the word itself, wherever it sits.
156
+ rank: named
157
+ ? plural === icon.id
158
+ ? 1
159
+ : 3
160
+ : tags.length + tags.indexOf(plural),
161
+ reason: `word "${plural}"`,
162
+ };
163
+ }
134
164
  const prefix = icon.words.find(word => word.startsWith(query));
135
165
  if (prefix) {
136
166
  return {
@@ -141,7 +171,11 @@ export function matchIcon(query, icon, definitions = []) {
141
171
  reason: `word "${prefix}" starts with "${query}"`,
142
172
  };
143
173
  }
144
- const contains = [icon.id, ...icon.words].find(text => text.includes(query));
174
+ // A letter or two inside a word (`x` in `box`) says nothing about it.
175
+ const contains =
176
+ query.replace(/\s+/gu, '').length >= 3
177
+ ? [icon.id, ...icon.words].find(text => text.includes(query))
178
+ : undefined;
145
179
  if (contains) {
146
180
  return {
147
181
  tier: 'partial',
@@ -170,6 +204,72 @@ export function matchIcon(query, icon, definitions = []) {
170
204
  return null;
171
205
  }
172
206
 
207
+ /**
208
+ * Whether two words are one word's singular and plural (`star`, `stars`;
209
+ * `box`, `boxes`), never the same word.
210
+ * @param {string} a
211
+ * @param {string} b
212
+ */
213
+ function sameWord(a, b) {
214
+ if (a === b || /\s/u.test(a) || /\s/u.test(b)) return false;
215
+ const [short, long] = a.length < b.length ? [a, b] : [b, a];
216
+ return short.length >= 2 && (long === `${short}s` || long === `${short}es`);
217
+ }
218
+
219
+ /**
220
+ * Words that phrase a query without naming anything: left out of a query of
221
+ * several words that nothing answers as typed (`go home` asks for `home`).
222
+ */
223
+ const FILLER_WORDS = new Set([
224
+ 'a',
225
+ 'an',
226
+ 'the',
227
+ 'go',
228
+ 'to',
229
+ 'my',
230
+ 'of',
231
+ 'for',
232
+ 'icon',
233
+ 'icons',
234
+ ]);
235
+
236
+ /**
237
+ * A query as typed: trimmed and lower-case, one space between words.
238
+ * @param {string} query
239
+ */
240
+ function typedQuery(query) {
241
+ return query.trim().toLowerCase().split(/\s+/u).filter(Boolean).join(' ');
242
+ }
243
+
244
+ /**
245
+ * The query without the words that only phrase it, when it has several
246
+ * words and some word names something; else the query as typed.
247
+ * @param {string} query
248
+ */
249
+ export function iconQuery(query) {
250
+ const words = typedQuery(query).split(' ').filter(Boolean);
251
+ const named = words.filter(word => !FILLER_WORDS.has(word));
252
+ return (words.length > 1 && named.length > 0 ? named : words).join(' ');
253
+ }
254
+
255
+ /**
256
+ * The matches that answer a query: the whole-word ones (a definition or an
257
+ * exact match, 80 and up) when there are any, else word starts (60) when
258
+ * there are any, else partial matches. A longer word that only starts with
259
+ * the query (`start` for `star`) never stands beside a whole-word answer.
260
+ * @template {{score: number}} T
261
+ * @param {T[]} ranked best first
262
+ * @returns {T[]}
263
+ */
264
+ export function answeringMatches(ranked) {
265
+ for (const floor of [80, 60]) {
266
+ if (ranked.some(each => each.score >= floor)) {
267
+ return ranked.filter(each => each.score >= floor);
268
+ }
269
+ }
270
+ return ranked;
271
+ }
272
+
173
273
  /**
174
274
  * The score of one match, given which exact reading leads.
175
275
  * @param {IconMatch} match
@@ -249,13 +349,30 @@ export function withDefinitionWords(icon, definitions, lookup) {
249
349
  }
250
350
 
251
351
  /**
252
- * Every icon in `sets` that answers the query, ranked (FR6).
352
+ * Every icon in `sets` that answers the query, ranked. The query is
353
+ * 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}).
253
355
  * @param {DiscoveredIconSet[]} sets in tie order
254
356
  * @param {string} query
255
357
  * @returns {IconMatchEntry[]}
256
358
  */
257
359
  export function rankIcons(sets, query) {
258
- const term = query.trim().toLowerCase();
360
+ const typed = typedQuery(query);
361
+ const asTyped = rankTerm(sets, typed);
362
+ if (asTyped.some(each => each.score >= 80)) return asTyped;
363
+ const named = iconQuery(query);
364
+ if (named === typed) return asTyped;
365
+ const withoutFiller = rankTerm(sets, named);
366
+ return withoutFiller.length > 0 ? withoutFiller : asTyped;
367
+ }
368
+
369
+ /**
370
+ * {@link rankIcons} for one normalized query.
371
+ * @param {DiscoveredIconSet[]} sets
372
+ * @param {string} term
373
+ * @returns {IconMatchEntry[]}
374
+ */
375
+ function rankTerm(sets, term) {
259
376
  const astryx = astryxDefinitionsByName();
260
377
  /** @type {Array<{set: DiscoveredIconSet, icon: IconSetIcon, definitions: string[], match: IconMatch, setIndex: number}>} */
261
378
  const hits = [];
@@ -44,8 +44,9 @@ import * as path from 'node:path';
44
44
  import {findInstalledPackage} from '../fs/paths.mjs';
45
45
  import {satisfiesRange} from '../env/semver.mjs';
46
46
  import {
47
- NOTICE_FILE_RE,
48
47
  discoverIconSetDirectory,
48
+ hasLicenseNotice,
49
+ licenseNoticeFix,
49
50
  resolveIconModule,
50
51
  splitSpecifier,
51
52
  } from './icon-set-discovery.mjs';
@@ -57,6 +58,7 @@ import {
57
58
  otherNamesOf,
58
59
  generatedTypesText,
59
60
  readGeneratedStatements,
61
+ generatedTypesMatch,
60
62
  } from './icon-set-writer.mjs';
61
63
  import {
62
64
  exportValueKind,
@@ -67,6 +69,7 @@ import {
67
69
  } from './module-exports.mjs';
68
70
  import {astryxIconDefinitions} from './icon-definition-discovery.mjs';
69
71
  import {rankIcons} from './icon-ranking.mjs';
72
+ import {shellArg} from '../text/shell-arg.mjs';
70
73
  import {
71
74
  issueError,
72
75
  issueWarning,
@@ -276,16 +279,17 @@ function checkContract(set, packageName, pkg, unchecked) {
276
279
  const actual = fs.existsSync(typesFile)
277
280
  ? fs.readFileSync(typesFile, 'utf-8')
278
281
  : null;
279
- // The header comment is the writer's, and changes between releases;
280
- // the declarations are what must match.
281
- const code = (/** @type {string} */ text) =>
282
- text
283
- .split('\n')
284
- .filter(line => !line.startsWith('//'))
285
- .join('\n');
282
+ // The declarations must match, statement by statement, however a
283
+ // formatter left the file; the header comment is the writer's and
284
+ // changes between releases.
286
285
  if (
287
286
  expected != null &&
288
- (actual == null || code(actual) !== code(expected))
287
+ (actual == null ||
288
+ !generatedTypesMatch(
289
+ actual,
290
+ expected,
291
+ /** @type {string} */ (typesRel),
292
+ ))
289
293
  ) {
290
294
  issues.push(
291
295
  issueError(
@@ -359,12 +363,12 @@ function checkDefinitions(set) {
359
363
  if (mapped.has(doc.name) || !doc.builtIn) continue;
360
364
  const suggestion = suggestIcon(set, doc);
361
365
  const hint = suggestion
362
- ? ` Suggested: astryx experimental icon map ${doc.name} ${suggestion.icon}.`
366
+ ? ` Suggested: astryx experimental icon map ${doc.name} ${suggestion.icon} --set ${set.name}.`
363
367
  : '';
364
368
  issues.push(
365
369
  issueError(
366
370
  ICON_BUILTIN_DEFINITION_MISSING,
367
- `${label} maps no icon to the built-in icon definition "${doc.name}" (${doc.description} Words: ${doc.words.join(', ')}.). Every set maps every built-in definition: run \`astryx experimental icon map ${doc.name} <icon id>\` with the icon that draws it${findHint(set, doc)}.${hint}`,
371
+ `${label} maps no icon to the built-in icon definition "${doc.name}" (${doc.description} Words: ${doc.words.join(', ')}.). Every set maps every built-in definition: run \`astryx experimental icon map ${doc.name} <icon id> --set ${set.name}\` with the icon that draws it${findHint(set, doc)}.${hint}`,
368
372
  ),
369
373
  );
370
374
  }
@@ -382,7 +386,7 @@ function checkDefinitions(set) {
382
386
  issues.push(
383
387
  issueWarning(
384
388
  ICON_DEFINITION_UNUSED,
385
- `${label} declares the icon definition "${doc.name}", but "map" names no icon for it. Map it with \`astryx experimental icon map ${doc.name} <icon id>\`, or remove definitions/${doc.name}.doc.mjs.${suggestion ? ` Suggested: astryx experimental icon map ${doc.name} ${suggestion.icon}.` : ''}`,
389
+ `${label} declares the icon definition "${doc.name}", but "map" names no icon for it. Map it with \`astryx experimental icon map ${doc.name} <icon id> --set ${set.name}\`, or remove definitions/${doc.name}.doc.mjs.${suggestion ? ` Suggested: astryx experimental icon map ${doc.name} ${suggestion.icon} --set ${set.name}.` : ''}`,
386
390
  ),
387
391
  );
388
392
  }
@@ -538,13 +542,7 @@ export function suggestedIcons(set, doc) {
538
542
  ...nameWords,
539
543
  ...wordIds.flatMap(id => id.split('-')).map(stem),
540
544
  ]);
541
- const icons = set.data.icons.map(icon => ({
542
- id: icon.id,
543
- words: icon.id.split('-').map(stem),
544
- raw: icon.id.split('-'),
545
- // The library's other names for it, the same ones `map` accepts.
546
- other: otherNamesOf(icon),
547
- }));
545
+ const icons = suggestionIndex(set.data.icons);
548
546
  /** How many of the definition's words an id has: more is a better fit. */
549
547
  const fit = (/** @type {string[]} */ words) =>
550
548
  words.filter(word => meaning.has(word)).length;
@@ -636,6 +634,29 @@ export function suggestedIcons(set, doc) {
636
634
  return found.slice(0, SUGGESTIONS_PER_DEFINITION);
637
635
  }
638
636
 
637
+ /**
638
+ * Each icon as the suggestion rules read it: its id's words as written and
639
+ * in singular form, and the library's other names for it (the same ones
640
+ * `map` accepts). Built once per list of icons, so suggesting for every
641
+ * definition of a large library reads each icon once.
642
+ * @type {WeakMap<object, Array<{id: string, words: string[], raw: string[], other: string[]}>>}
643
+ */
644
+ const suggestionIndexes = new WeakMap();
645
+
646
+ /** @param {Array<{id: string, words?: string[]}>} list */
647
+ function suggestionIndex(list) {
648
+ const cached = suggestionIndexes.get(list);
649
+ if (cached) return cached;
650
+ const index = list.map(icon => ({
651
+ id: icon.id,
652
+ words: icon.id.split('-').map(stem),
653
+ raw: icon.id.split('-'),
654
+ other: otherNamesOf(icon),
655
+ }));
656
+ suggestionIndexes.set(list, index);
657
+ return index;
658
+ }
659
+
639
660
  /**
640
661
  * A word in its singular form, so a plural meets its singular and nothing
641
662
  * else: `languages` meets `language`, `arrows` meets `arrow`. Only a
@@ -934,10 +955,10 @@ function findHint(set, doc) {
934
955
  each => each.score >= FIND_FLOOR,
935
956
  );
936
957
  if (found.length > 0) {
937
- return ` (icons matching "${query}": \`astryx experimental icon ${query} --set ${set.name}\`)`;
958
+ return ` (icons matching "${query}": \`astryx experimental icon ${shellArg(query)} --set ${set.name}\`)`;
938
959
  }
939
960
  }
940
- return ' (no icon in the set has its name or words: pick the library icon that draws it; if the library has none, map the closest, or add your own artwork with `astryx experimental icon add <Name> --from ./src/icons/<name>.js --definition <definition>`)';
961
+ return ` (no icon in the set has its name or words: pick the library icon that draws it; if the library has none, map the closest, or add your own artwork with \`astryx experimental icon add <Name> --from ./src/icons/<name>.js --definition ${doc.name} --set ${set.name}\`)`;
941
962
  }
942
963
 
943
964
  /**
@@ -983,14 +1004,11 @@ function checkUpstream(set, packageDir, pkg) {
983
1004
  ),
984
1005
  );
985
1006
  }
986
- const rootNotices = safeList(packageDir).filter(name =>
987
- NOTICE_FILE_RE.test(name),
988
- );
989
- if (set.notices.length === 0 && rootNotices.length === 0) {
1007
+ if (!hasLicenseNotice(set.dir) && !hasLicenseNotice(packageDir)) {
990
1008
  issues.push(
991
1009
  issueWarning(
992
1010
  ICON_LICENSE_NOTICE_MISSING,
993
- `${label} is generated from ${source.package} but ships no license notice. Copy the library's LICENSE (and NOTICE, if any) into the set directory or the package root.`,
1011
+ `${label} is generated from ${source.package}@${source.version} but ships no license notice. ${licenseNoticeFix(path.relative(packageDir, set.dir).split(path.sep).join('/'), `${source.package}@${source.version}`)} If the library ships a LICENSE or NOTICE file, copy that file there instead.`,
994
1012
  ),
995
1013
  );
996
1014
  }
@@ -1006,12 +1024,3 @@ function safeSatisfies(version, range) {
1006
1024
  return true;
1007
1025
  }
1008
1026
  }
1009
-
1010
- /** @param {string} dir */
1011
- function safeList(dir) {
1012
- try {
1013
- return fs.readdirSync(dir);
1014
- } catch {
1015
- return [];
1016
- }
1017
- }
@@ -1,6 +1,19 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * What to add when a set wraps a library and has no license notice: a
6
+ * NOTICE file in the set directory, with the file names that count. The
7
+ * CLI never writes it, because the license text is the author's to state.
8
+ * @param {string} setDir the set directory, from the package root
9
+ * @param {string} library the library as `name@version`
10
+ */
11
+ export function licenseNoticeFix(setDir: string, library: string): string;
12
+ /**
13
+ * Whether a directory has a license or notice file ({@link NOTICE_FILE_RE}).
14
+ * @param {string} dir
15
+ */
16
+ export function hasLicenseNotice(dir: string): boolean;
4
17
  /**
5
18
  * One installed icon set: its descriptor, its data, and where it came from.
6
19
  * @typedef {object} DiscoveredIconSet
@@ -43,6 +43,31 @@ const SET_NAME_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
43
43
  /** A license or notice file a set ships beside its data (FR15). */
44
44
  export const NOTICE_FILE_RE = /^(?:licen[cs]e|notice|copying)(?:[.-].*)?$/iu;
45
45
 
46
+ /**
47
+ * What to add when a set wraps a library and has no license notice: a
48
+ * NOTICE file in the set directory, with the file names that count. The
49
+ * CLI never writes it, because the license text is the author's to state.
50
+ * @param {string} setDir the set directory, from the package root
51
+ * @param {string} library the library as `name@version`
52
+ */
53
+ export function licenseNoticeFix(setDir, library) {
54
+ return `Add a NOTICE (or LICENSE) file to ${setDir} that names ${library} and its license: \`${setDir}/NOTICE\`. A file named LICENSE, LICENCE, NOTICE, or COPYING, in any case and with an optional suffix such as NOTICE.md or LICENSE-MIT, counts in the set directory or the package root.`;
55
+ }
56
+
57
+ /**
58
+ * Whether a directory has a license or notice file ({@link NOTICE_FILE_RE}).
59
+ * @param {string} dir
60
+ */
61
+ export function hasLicenseNotice(dir) {
62
+ try {
63
+ return fs
64
+ .readdirSync(dir, {withFileTypes: true})
65
+ .some(file => file.isFile() && NOTICE_FILE_RE.test(file.name));
66
+ } catch {
67
+ return false;
68
+ }
69
+ }
70
+
46
71
  /**
47
72
  * One installed icon set: its descriptor, its data, and where it came from.
48
73
  * @typedef {object} DiscoveredIconSet