@astryxdesign/cli 0.7.4 → 0.7.5-canary.07605c2

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 (235) hide show
  1. package/README.md +18 -18
  2. package/api/component/_adapter.mjs +16 -1
  3. package/api/component/component.test.mjs +31 -0
  4. package/api/discover/_adapter.d.mts +1 -1
  5. package/api/docs/_adapter.d.mts +5 -2
  6. package/api/docs/_adapter.mjs +24 -16
  7. package/api/docs/docs.test.mjs +18 -0
  8. package/api/docs/integrationDocs.test.mjs +2 -2
  9. package/api/experimental.d.mts +5 -0
  10. package/api/experimental.mjs +15 -0
  11. package/api/hook/list/list.d.mts +1 -1
  12. package/api/icon/_adapter.d.mts +3 -2
  13. package/api/icon/_adapter.mjs +16 -3
  14. package/api/icon/_authoring.d.mts +5 -1
  15. package/api/icon/_authoring.mjs +478 -63
  16. package/api/icon/_options.d.mts +11 -0
  17. package/api/icon/_options.mjs +39 -4
  18. package/api/icon/_records.d.mts +19 -0
  19. package/api/icon/_records.mjs +25 -0
  20. package/api/icon/add/add.d.mts +3 -3
  21. package/api/icon/add/add.mjs +227 -14
  22. package/api/icon/all-or-nothing.test.mjs +283 -0
  23. package/api/icon/detail/detail.mjs +2 -13
  24. package/api/icon/error-codes.test.mjs +14 -7
  25. package/api/icon/icon.d.mts +2 -2
  26. package/api/icon/icon.doc.mjs +30 -2
  27. package/api/icon/icon.mjs +57 -8
  28. package/api/icon/icon.test.mjs +133 -1
  29. package/api/icon/icon.type.d.mts +126 -1
  30. package/api/icon/icon.type.mjs +67 -3
  31. package/api/icon/iconAdd.doc.mjs +22 -6
  32. package/api/icon/iconMap.doc.mjs +24 -8
  33. package/api/icon/iconNewDefinition.doc.mjs +2 -2
  34. package/api/icon/iconNewSet.doc.mjs +30 -2
  35. package/api/icon/iconUse.doc.mjs +4 -1
  36. package/api/icon/map/map.d.mts +4 -4
  37. package/api/icon/map/map.mjs +134 -9
  38. package/api/icon/new-definition/new-definition.mjs +6 -2
  39. package/api/icon/new-set/new-set.mjs +2 -2
  40. package/api/icon/new-set/new-set.test.mjs +60 -10
  41. package/api/icon/option-pairs.test.mjs +368 -0
  42. package/api/icon/search/search.d.mts +10 -0
  43. package/api/icon/search/search.mjs +55 -14
  44. package/api/icon/use/use.mjs +2 -13
  45. package/api/integration/add-helpers.d.mts +15 -1
  46. package/api/integration/add-helpers.mjs +1 -1
  47. package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
  48. package/api/integration/pack-check.mjs +10 -4
  49. package/api/integration/pack-check.test.mjs +5 -1
  50. package/api/integration/validate-integration.type.d.mts +3 -2
  51. package/api/integration/validate-integration.type.mjs +3 -2
  52. package/api/render/_adapter.d.mts +28 -0
  53. package/api/render/_adapter.mjs +540 -0
  54. package/api/render/render.d.mts +15 -0
  55. package/api/render/render.doc.d.mts +9 -0
  56. package/api/render/render.doc.mjs +112 -0
  57. package/api/render/render.mjs +113 -0
  58. package/api/render/render.test.mjs +1155 -0
  59. package/api/render/render.type.d.mts +74 -0
  60. package/api/render/render.type.mjs +64 -0
  61. package/api/search/_adapter.test.mjs +21 -2
  62. package/api/search/_result.d.mts +5 -5
  63. package/api/search/search.d.mts +1 -1
  64. package/api/template/template.mjs +3 -1
  65. package/api/template/template.type.d.mts +2 -1
  66. package/api/template/template.type.mjs +1 -1
  67. package/api/template/unknown-name.test.mjs +63 -0
  68. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +123 -70
  69. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
  70. package/assets/discover/official-packages.json +4 -0
  71. package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
  72. package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
  73. package/assets/docs/tree/icon-sets.doc.mjs +50 -20
  74. package/assets/docs/tree/render-pages.doc.mjs +94 -0
  75. package/assets/icons/definitions/activity.doc.mjs +1 -1
  76. package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
  77. package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
  78. package/assets/icons/definitions/alignStart.doc.mjs +10 -0
  79. package/assets/icons/definitions/archive.doc.mjs +1 -1
  80. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
  81. package/assets/icons/definitions/attach.doc.mjs +1 -1
  82. package/assets/icons/definitions/audio.doc.mjs +1 -1
  83. package/assets/icons/definitions/cart.doc.mjs +1 -1
  84. package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
  85. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
  86. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
  87. package/assets/icons/definitions/close.doc.mjs +1 -1
  88. package/assets/icons/definitions/collapse.doc.mjs +1 -1
  89. package/assets/icons/definitions/compose.doc.mjs +1 -1
  90. package/assets/icons/definitions/conversation.doc.mjs +1 -1
  91. package/assets/icons/definitions/copy.doc.mjs +1 -1
  92. package/assets/icons/definitions/cpu.doc.mjs +9 -0
  93. package/assets/icons/definitions/database.doc.mjs +1 -1
  94. package/assets/icons/definitions/desktop.doc.mjs +1 -1
  95. package/assets/icons/definitions/discount.doc.mjs +1 -1
  96. package/assets/icons/definitions/download.doc.mjs +1 -1
  97. package/assets/icons/definitions/emoji.doc.mjs +1 -1
  98. package/assets/icons/definitions/error.doc.mjs +1 -1
  99. package/assets/icons/definitions/expand.doc.mjs +1 -1
  100. package/assets/icons/definitions/experiment.doc.mjs +1 -1
  101. package/assets/icons/definitions/externalLink.doc.mjs +7 -1
  102. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
  103. package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
  104. package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
  105. package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
  106. package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
  107. package/assets/icons/definitions/gitFork.doc.mjs +9 -0
  108. package/assets/icons/definitions/info.doc.mjs +1 -1
  109. package/assets/icons/definitions/location.doc.mjs +1 -1
  110. package/assets/icons/definitions/mention.doc.mjs +1 -1
  111. package/assets/icons/definitions/menu.doc.mjs +1 -1
  112. package/assets/icons/definitions/microphone.doc.mjs +1 -1
  113. package/assets/icons/definitions/mobile.doc.mjs +1 -1
  114. package/assets/icons/definitions/money.doc.mjs +1 -1
  115. package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
  116. package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
  117. package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
  118. package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
  119. package/assets/icons/definitions/panelRight.doc.mjs +10 -0
  120. package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
  121. package/assets/icons/definitions/redo.doc.mjs +1 -1
  122. package/assets/icons/definitions/refresh.doc.mjs +1 -1
  123. package/assets/icons/definitions/rotate.doc.mjs +9 -0
  124. package/assets/icons/definitions/scale.doc.mjs +10 -0
  125. package/assets/icons/definitions/search.doc.mjs +1 -1
  126. package/assets/icons/definitions/send.doc.mjs +1 -1
  127. package/assets/icons/definitions/settings.doc.mjs +1 -1
  128. package/assets/icons/definitions/star.doc.mjs +1 -1
  129. package/assets/icons/definitions/stop.doc.mjs +1 -1
  130. package/assets/icons/definitions/success.doc.mjs +1 -1
  131. package/assets/icons/definitions/textCase.doc.mjs +9 -0
  132. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
  133. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
  134. package/assets/icons/definitions/trendDown.doc.mjs +7 -1
  135. package/assets/icons/definitions/trendUp.doc.mjs +1 -1
  136. package/assets/icons/definitions/undo.doc.mjs +1 -1
  137. package/assets/icons/definitions/upload.doc.mjs +1 -1
  138. package/assets/icons/definitions/userAdd.doc.mjs +1 -1
  139. package/assets/icons/definitions/warning.doc.mjs +1 -1
  140. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
  141. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
  142. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
  143. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
  144. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
  145. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
  146. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
  147. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
  148. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
  149. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
  150. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  151. package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
  152. package/authoring/debug/parse.d.mts +2 -2
  153. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
  154. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
  155. package/authoring/doctypes/icon-set/parse.d.mts +1 -0
  156. package/authoring/doctypes/icon-set/parse.mjs +1 -0
  157. package/authoring/doctypes/icon-set/type.ts +5 -0
  158. package/authoring/doctypes/template/template.doc.mjs +1 -1
  159. package/authoring/doctypes/template/type.ts +2 -1
  160. package/clients/cli/commands/doctor.mjs +16 -17
  161. package/clients/cli/commands/experimental/icon.mjs +167 -35
  162. package/clients/cli/commands/experimental/index.mjs +2 -0
  163. package/clients/cli/commands/experimental/render.mjs +113 -0
  164. package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
  165. package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
  166. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
  167. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
  168. package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
  169. package/clients/cli/commands/experimental-render.doc.mjs +60 -0
  170. package/clients/cli/commands/experimental.doc.mjs +4 -2
  171. package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
  172. package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
  173. package/clients/cli/commands/icon.test.mjs +1 -1
  174. package/clients/cli/commands/template.mjs +4 -1
  175. package/clients/cli/commands/text-json-parity.test.mjs +46 -0
  176. package/clients/cli/index.mjs +1 -0
  177. package/foundation/discovery/component-discovery.d.mts +2 -1
  178. package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
  179. package/foundation/discovery/component-discovery.mjs +13 -7
  180. package/foundation/discovery/icon-set-checks.d.mts +43 -9
  181. package/foundation/discovery/icon-set-checks.mjs +296 -21
  182. package/foundation/discovery/icon-set-checks.test.mjs +125 -12
  183. package/foundation/discovery/icon-set-writer.d.mts +192 -3
  184. package/foundation/discovery/icon-set-writer.mjs +608 -34
  185. package/foundation/discovery/icon-set-writer.test.mjs +26 -0
  186. package/foundation/discovery/module-exports.mjs +82 -25
  187. package/foundation/discovery/module-exports.test.mjs +38 -1
  188. package/foundation/discovery/package-exports.d.mts +13 -0
  189. package/foundation/discovery/package-exports.mjs +40 -1
  190. package/foundation/discovery/template-icons.d.mts +6 -0
  191. package/foundation/discovery/template-icons.mjs +98 -10
  192. package/foundation/discovery/template-icons.test.mjs +103 -0
  193. package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
  194. package/foundation/doc-compiler/import.mjs +81 -8
  195. package/foundation/doc-compiler/read.d.mts +4 -3
  196. package/foundation/doc-compiler/read.mjs +15 -10
  197. package/foundation/doc-compiler/read.test.mjs +59 -1
  198. package/foundation/doc-compiler/tree.mjs +3 -1
  199. package/foundation/fs/module-loader.d.mts +3 -2
  200. package/foundation/fs/module-loader.mjs +3 -2
  201. package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
  202. package/foundation/fs/read-record.d.mts +27 -0
  203. package/foundation/fs/read-record.mjs +83 -15
  204. package/foundation/fs/read-record.test.mjs +88 -1
  205. package/foundation/render/assets.d.mts +31 -0
  206. package/foundation/render/assets.mjs +102 -0
  207. package/foundation/render/component-map.d.mts +52 -0
  208. package/foundation/render/component-map.mjs +141 -0
  209. package/foundation/render/css-cut.d.mts +29 -0
  210. package/foundation/render/css-cut.mjs +144 -0
  211. package/foundation/render/embedded-files.d.mts +28 -0
  212. package/foundation/render/embedded-files.mjs +108 -0
  213. package/foundation/render/embedded-imports.d.mts +61 -0
  214. package/foundation/render/embedded-imports.mjs +315 -0
  215. package/foundation/render/html-reader.d.mts +37 -0
  216. package/foundation/render/html-reader.mjs +121 -0
  217. package/foundation/render/page-worker.d.mts +7 -0
  218. package/foundation/render/page-worker.mjs +519 -0
  219. package/foundation/render/rebuild.d.mts +19 -0
  220. package/foundation/render/rebuild.mjs +269 -0
  221. package/foundation/render/render-page.d.mts +85 -0
  222. package/foundation/render/render-page.mjs +612 -0
  223. package/foundation/render/render.test.mjs +117 -0
  224. package/foundation/render/source-block.d.mts +52 -0
  225. package/foundation/render/source-block.mjs +106 -0
  226. package/foundation/response/error-codes.d.mts +10 -1
  227. package/foundation/response/error-codes.doc.mjs +56 -0
  228. package/foundation/response/error-codes.mjs +61 -0
  229. package/foundation/response/response-types.doc.mjs +38 -1
  230. package/foundation/text/string-utils.mjs +33 -0
  231. package/foundation/text/string-utils.test.mjs +17 -0
  232. package/foundation/text/suggest-order.d.mts +17 -3
  233. package/foundation/text/suggest-order.mjs +58 -13
  234. package/foundation/text/suggest-order.test.mjs +53 -0
  235. package/package.json +14 -9
@@ -51,7 +51,10 @@ import {
51
51
  } from './icon-set-discovery.mjs';
52
52
  import {inspectPackageExport} from './package-exports.mjs';
53
53
  import {
54
+ THEME_MAP_NAME,
55
+ entryWiringNote,
54
56
  generatedTypesPath,
57
+ otherNamesOf,
55
58
  generatedTypesText,
56
59
  readGeneratedStatements,
57
60
  } from './icon-set-writer.mjs';
@@ -63,6 +66,7 @@ import {
63
66
  staticExportBindings,
64
67
  } from './module-exports.mjs';
65
68
  import {astryxIconDefinitions} from './icon-definition-discovery.mjs';
69
+ import {rankIcons} from './icon-ranking.mjs';
66
70
  import {
67
71
  issueError,
68
72
  issueWarning,
@@ -272,7 +276,17 @@ function checkContract(set, packageName, pkg, unchecked) {
272
276
  const actual = fs.existsSync(typesFile)
273
277
  ? fs.readFileSync(typesFile, 'utf-8')
274
278
  : null;
275
- if (expected != null && actual !== expected) {
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');
286
+ if (
287
+ expected != null &&
288
+ (actual == null || code(actual) !== code(expected))
289
+ ) {
276
290
  issues.push(
277
291
  issueError(
278
292
  ICON_GENERATED_TYPES_MISMATCH,
@@ -350,7 +364,7 @@ function checkDefinitions(set) {
350
364
  issues.push(
351
365
  issueError(
352
366
  ICON_BUILTIN_DEFINITION_MISSING,
353
- `${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: add it to "map" in ${set.name}.icons.json with the id of the icon that draws it.${hint}`,
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}`,
354
368
  ),
355
369
  );
356
370
  }
@@ -368,7 +382,7 @@ function checkDefinitions(set) {
368
382
  issues.push(
369
383
  issueWarning(
370
384
  ICON_DEFINITION_UNUSED,
371
- `${label} declares the icon definition "${doc.name}", but "map" names no icon for it. Add it to "map" with the id of the icon that draws it, or remove definitions/${doc.name}.doc.mjs.${suggestion ? ` Suggested: astryx experimental icon map ${doc.name} ${suggestion.icon}.` : ''}`,
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}.` : ''}`,
372
386
  ),
373
387
  );
374
388
  }
@@ -383,9 +397,8 @@ function checkDefinitions(set) {
383
397
  * Astryx's optional (not built-in) definitions the set's `map` does not
384
398
  * name. Mapping them is optional, so they never fail a check.
385
399
  * @property {Array<{definition: string, icon: string}>} suggestions for every
386
- * unmapped definition, built-in, optional, or the set's own, the icon whose
387
- * whole id is the definition's name or one of its words; nothing is guessed
388
- * beyond that
400
+ * unmapped definition, built-in, optional, or the set's own, the best icon
401
+ * {@link suggestedIcons} gives, if any
389
402
  * @property {IconSetUnchecked[]} unchecked what the checks could not judge:
390
403
  * never counted, never failing, even under `--strict`
391
404
  */
@@ -433,25 +446,247 @@ export function iconSetCoverage(loaded, unchecked = new Map()) {
433
446
  }
434
447
 
435
448
  /**
436
- * The set's icon whose whole id is the definition's name (`chevronDown` is
437
- * `chevron-down`) or, in order, one of its words (spaces read as `-`). Null
438
- * when none is: a suggestion is never a guess from parts of words.
449
+ * The best icon {@link suggestedIcons} gives for a definition, or null when
450
+ * it gives none.
439
451
  * @param {DiscoveredIconSet} set
440
452
  * @param {import('../../authoring/doctypes/icon-definition/type').IconDefinitionDoc} doc
441
453
  * @returns {{map: string, icon: string} | null}
442
454
  */
443
455
  export function suggestIcon(set, doc) {
444
- const kebab = doc.name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();
445
- // No guessing: only an icon whose whole id is the definition's name or one
446
- // of its words.
447
- for (const candidate of [
448
- kebab,
449
- ...doc.words.map(word => word.trim().toLowerCase().replace(/\s+/gu, '-')),
450
- ]) {
451
- const icon = set.data.icons.find(each => each.id === candidate);
452
- if (icon) return {map: doc.name, icon: icon.id};
456
+ const [first] = suggestedIcons(set, doc);
457
+ return first ? {map: doc.name, icon: first.icon} : null;
458
+ }
459
+
460
+ /**
461
+ * Words that turn an icon into the opposite or a variation of its first
462
+ * words: `lock-open`, `bell-off`, `video-camera-slash`, `audio-lines-x`.
463
+ */
464
+ const NEGATING_WORDS = new Set([
465
+ 'off',
466
+ 'slash',
467
+ 'x',
468
+ 'open',
469
+ 'minus',
470
+ 'ban',
471
+ 'dashed',
472
+ 'dot',
473
+ 'code',
474
+ 'formatting',
475
+ 'exclamation',
476
+ 'question',
477
+ 'warning',
478
+ ]);
479
+
480
+ /** Direction words that mean the other way. */
481
+ /** @type {Record<string, string>} */
482
+ const OPPOSITES = {
483
+ horizontal: 'vertical',
484
+ vertical: 'horizontal',
485
+ left: 'right',
486
+ right: 'left',
487
+ up: 'down',
488
+ down: 'up',
489
+ in: 'out',
490
+ out: 'in',
491
+ };
492
+
493
+ /**
494
+ * A second id word that only sizes, shapes, or numbers the first: a number
495
+ * or dimension (`2`, `3x3`), or one of a few style words. The icon then
496
+ * still draws what its first word names.
497
+ */
498
+ const QUALIFIER_RE =
499
+ /^(?:\d+(?:x\d+)?|circle|square|small|big|large|alt|horizontal|vertical)$/u;
500
+
501
+ /** How many icons one definition is suggested at most. */
502
+ export const SUGGESTIONS_PER_DEFINITION = 3;
503
+
504
+ /**
505
+ * The icons a definition might map to, best first, at most three, in the
506
+ * order AST-084 FR13 gives: the name in another spelling, an icon the library
507
+ * gives the name as another name, ids that start with the name (`video` →
508
+ * `video-camera`, never `close` → `panel-left-close`), an id that is one of
509
+ * its words (`delete` → `trash`), another name that is one of its words, and
510
+ * two-word ids that are a one-word word sized, shaped, or numbered
511
+ * (`grid-2x2`). An icon `map` already names
512
+ * for another definition, or whose id is another definition's name, is left
513
+ * out: it has a meaning of its own. Never a negated form or the opposite
514
+ * direction, and never a guess from parts of words.
515
+ * @param {{data: {icons: Array<{id: string, words?: string[]}>, map?: Record<string, string>}, definitions?: Array<{doc: {name: string}}>}} set
516
+ * @param {{name: string, words: string[]}} doc
517
+ * @returns {Array<{icon: string, word: string}>}
518
+ */
519
+ export function suggestedIcons(set, doc) {
520
+ const toId = (/** @type {string} */ name) =>
521
+ name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();
522
+ const nameId = toId(doc.name);
523
+ const nameWords = nameId.split('-').map(stem);
524
+ const map = set.data.map ?? {};
525
+ const taken = new Set([
526
+ ...Object.entries(map)
527
+ .filter(([name]) => name !== doc.name)
528
+ .map(([, id]) => id),
529
+ ...[...astryxIconDefinitions().definitions, ...(set.definitions ?? [])]
530
+ .map(each => toId(each.doc.name))
531
+ .filter(id => id !== nameId),
532
+ ]);
533
+ const wordIds = doc.words.map(word =>
534
+ word.trim().toLowerCase().replace(/\s+/gu, '-'),
535
+ );
536
+ // Every word the definition is known by, stemmed: its name's and its words'.
537
+ const meaning = new Set([
538
+ ...nameWords,
539
+ ...wordIds.flatMap(id => id.split('-')).map(stem),
540
+ ]);
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
+ }));
548
+ /** How many of the definition's words an id has: more is a better fit. */
549
+ const fit = (/** @type {string[]} */ words) =>
550
+ words.filter(word => meaning.has(word)).length;
551
+ /**
552
+ * Candidates best first: most of the definition's words, then fewest
553
+ * extra words, then by id.
554
+ * @param {typeof icons} list
555
+ */
556
+ const ranked = list =>
557
+ [...list].sort(
558
+ (a, b) =>
559
+ fit(b.words) - fit(a.words) ||
560
+ a.words.length - b.words.length ||
561
+ (a.id < b.id ? -1 : a.id > b.id ? 1 : 0),
562
+ );
563
+ // An id that turns the definition around (`ellipsis-vertical` for
564
+ // moreHorizontal) is never its icon.
565
+ const opposite = new Set(
566
+ nameWords.flatMap(word => (OPPOSITES[word] ? [OPPOSITES[word]] : [])),
567
+ );
568
+ const negated = (/** @type {string[]} */ words) =>
569
+ words.some(word => NEGATING_WORDS.has(word) || opposite.has(word));
570
+ /** @type {Array<{icon: string, word: string}>} */
571
+ const found = [];
572
+ const add = (/** @type {string} */ icon, /** @type {string} */ word) => {
573
+ if (taken.has(icon) || found.some(each => each.icon === icon)) return;
574
+ found.push({icon, word});
575
+ };
576
+ const squashed = nameId.replace(/-/gu, '');
577
+ // 1. The name itself, spelled with or without hyphens or a plural
578
+ // (`lightbulb` → `light-bulb`, `language` → `languages`).
579
+ for (const icon of icons) {
580
+ if (
581
+ icon.id === nameId ||
582
+ icon.id.replace(/-/gu, '') === squashed ||
583
+ (icon.words.length === nameWords.length &&
584
+ icon.words.every((word, index) => word === nameWords[index]))
585
+ ) {
586
+ add(icon.id, nameId);
587
+ }
453
588
  }
454
- return null;
589
+ // 2. An icon the library once named after the definition, or that it
590
+ // gives the definition's name as another name (Lucide's
591
+ // `more-horizontal` on `ellipsis`, `unlock` on `lock-open`).
592
+ for (const icon of icons) {
593
+ if (icon.other.includes(nameId)) add(icon.id, nameId);
594
+ }
595
+ // 3. Ids that start with the name as written (`video` → `video-camera`),
596
+ // never a negated form. A plural is not the same start: `users` is not
597
+ // `user-plus`, and `apps` is not `app-window`.
598
+ const nameRaw = nameId.split('-');
599
+ ranked(
600
+ icons.filter(
601
+ icon =>
602
+ icon.raw.length > nameRaw.length &&
603
+ nameRaw.every((word, index) => icon.raw[index] === word) &&
604
+ !negated(icon.raw.slice(nameRaw.length)),
605
+ ),
606
+ ).forEach(icon => add(icon.id, nameId));
607
+ // 4. An icon whose whole id is one of the definition's words.
608
+ for (const id of wordIds) {
609
+ if (icons.some(icon => icon.id === id)) add(id, id.replace(/-/gu, ' '));
610
+ }
611
+ // 5. Another name the library gives an icon that is one of the
612
+ // definition's words (Lucide's `smile` on `face-slightly-smiling`).
613
+ for (const [index, id] of wordIds.entries()) {
614
+ for (const icon of icons) {
615
+ if (icon.other.includes(id)) add(icon.id, doc.words[index]);
616
+ }
617
+ }
618
+ // 6. Last, two-word ids that are a one-word word with only a size, shape,
619
+ // or number after it (`columns` → `columns-3`, `plus` → `plus-circle`,
620
+ // `grid` → `grid-2x2`), best fit first. Any other second word names
621
+ // another thing (`card-sim`, `fast-forward`, `hand-coins`), so it is
622
+ // never suggested from a word alone.
623
+ for (const word of doc.words) {
624
+ if (!/^[a-z]{3,}$/u.test(word)) continue;
625
+ ranked(
626
+ icons.filter(
627
+ icon =>
628
+ icon.raw.length === 2 &&
629
+ icon.raw[0] === word &&
630
+ icon.raw[1] !== word &&
631
+ QUALIFIER_RE.test(icon.raw[1]) &&
632
+ !negated(icon.raw.slice(1)),
633
+ ),
634
+ ).forEach(icon => add(icon.id, word));
635
+ }
636
+ return found.slice(0, SUGGESTIONS_PER_DEFINITION);
637
+ }
638
+
639
+ /**
640
+ * A word in its singular form, so a plural meets its singular and nothing
641
+ * else: `languages` meets `language`, `arrows` meets `arrow`. Only a
642
+ * trailing plural `s` comes off (not `ss`, and not from a short word); a
643
+ * verb ending never does, so `drafting` never meets `draft`.
644
+ * @param {string} word
645
+ */
646
+ function stem(word) {
647
+ if (word.length > 3 && word.endsWith('s') && !word.endsWith('ss')) {
648
+ return word.slice(0, -1);
649
+ }
650
+ return word;
651
+ }
652
+
653
+ /**
654
+ * The change that makes a set's generated module part of its package's
655
+ * entry ({@link entryWiringNote}), or null when the entry exports its theme
656
+ * map or any of its icons, the set has no generated module on disk, or the
657
+ * entry is an `exports` target not built yet (listed as not checked).
658
+ * @param {DiscoveredIconSet} set
659
+ * @param {string} packageDir
660
+ * @param {string} packageName
661
+ * @param {(specifier: string) => string | null} unbuiltTarget
662
+ * @returns {string | null}
663
+ */
664
+ function entryNotWired(set, packageDir, packageName, unbuiltTarget) {
665
+ const generated = set.data.generated;
666
+ if (!generated || !fs.existsSync(path.join(packageDir, generated))) {
667
+ return null;
668
+ }
669
+ if (splitSpecifier(set.data.module).name !== packageName) return null;
670
+ if (unbuiltTarget(set.data.module)) return null;
671
+ const pkg = readJson(path.join(packageDir, 'package.json'));
672
+ if (!pkg) return null;
673
+ const note = entryWiringNote(packageDir, pkg, generated, {
674
+ module: set.data.module,
675
+ name: set.data.themeMap ?? THEME_MAP_NAME,
676
+ });
677
+ if (!note) return null;
678
+ const entry = resolveIconModule(set.data.module, packageDir, {
679
+ name: packageName,
680
+ dir: packageDir,
681
+ });
682
+ const someIcon =
683
+ entry &&
684
+ set.data.icons.some(
685
+ icon =>
686
+ (icon.module ?? set.data.module) === set.data.module &&
687
+ exportOriginVerdict(entry, icon.export)?.verdict !== 'lacks',
688
+ );
689
+ return someIcon ? null : note;
455
690
  }
456
691
 
457
692
  /**
@@ -559,10 +794,22 @@ function checkExports(set, packageDir, packageName, unchecked) {
559
794
  .definitions.filter(definition => definition.doc.builtIn)
560
795
  .map(definition => definition.doc.name),
561
796
  );
797
+ // A generated module the package's entry does not export yet: one finding
798
+ // with the exact change \`new-set\` names in its receipt, not one per icon.
799
+ const wiring = entryNotWired(set, packageDir, packageName, unbuiltTarget);
800
+ if (wiring) {
801
+ issues.push(
802
+ issueError(
803
+ ICON_EXPORT_MISSING,
804
+ `${label}: its icons are not exported from "${set.data.module}" yet. ${wiring}`,
805
+ ),
806
+ );
807
+ }
562
808
  /** @type {Map<string, {file: string, name: string} | null>} */
563
809
  const iconOrigins = new Map();
564
810
  for (const icon of set.data.icons) {
565
811
  const module = icon.module ?? set.data.module;
812
+ if (wiring && module === set.data.module) continue;
566
813
  iconOrigins.set(
567
814
  icon.id,
568
815
  originOf(module, icon.export, `icon "${icon.id}"`, {icon: icon.id}),
@@ -595,6 +842,7 @@ function checkExports(set, packageDir, packageName, unchecked) {
595
842
  );
596
843
  return issues;
597
844
  }
845
+ if (wiring) return issues;
598
846
  const mapOrigin = originOf(
599
847
  set.data.module,
600
848
  themeMap,
@@ -665,6 +913,33 @@ function checkExports(set, packageDir, packageName, unchecked) {
665
913
  return issues;
666
914
  }
667
915
 
916
+ /** The lowest search score a find hint needs: a whole word or a word start. */
917
+ const FIND_FLOOR = 60;
918
+
919
+ /**
920
+ * A search that finds icons for a definition in the set, named only when it
921
+ * answers: the definition's name, then each of its words, as a query against
922
+ * the set's icon ids and words. Empty when none answers, so the message never
923
+ * names a search that finds nothing.
924
+ * @param {DiscoveredIconSet} set
925
+ * @param {{name: string, words: string[]}} doc
926
+ */
927
+ function findHint(set, doc) {
928
+ const queries = [
929
+ doc.name.replace(/([a-z0-9])([A-Z])/gu, '$1 $2').toLowerCase(),
930
+ ...doc.words,
931
+ ];
932
+ for (const query of queries) {
933
+ const found = rankIcons([set], query).filter(
934
+ each => each.score >= FIND_FLOOR,
935
+ );
936
+ if (found.length > 0) {
937
+ return ` (icons matching "${query}": \`astryx experimental icon ${query} --set ${set.name}\`)`;
938
+ }
939
+ }
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>`)';
941
+ }
942
+
668
943
  /**
669
944
  * The upstream checks of one set: version drift and license notices.
670
945
  * @param {DiscoveredIconSet} set
@@ -693,7 +968,7 @@ function checkUpstream(set, packageDir, pkg) {
693
968
  issues.push(
694
969
  issueWarning(
695
970
  ICON_SOURCE_VERSION_DRIFT,
696
- `${label} was generated from ${source.package}@${source.version}, but the package resolves ${source.package}@${installed}. Regenerate ${set.name}.icons.json.`,
971
+ `${label} was generated from ${source.package}@${source.version}, but the package resolves ${source.package}@${installed}. Refresh it: \`astryx experimental icon new-set ${set.name} --from <the ${source.package} module it wraps>\`, then rerun any \`add --variant … --all\`.`,
697
972
  ),
698
973
  );
699
974
  } else if (
@@ -704,7 +979,7 @@ function checkUpstream(set, packageDir, pkg) {
704
979
  issues.push(
705
980
  issueWarning(
706
981
  ICON_SOURCE_VERSION_DRIFT,
707
- `${label} was generated from ${source.package}@${source.version}, but the package depends on ${source.package}@${range}. Regenerate ${set.name}.icons.json.`,
982
+ `${label} was generated from ${source.package}@${source.version}, but the package depends on ${source.package}@${range}. Refresh it: \`astryx experimental icon new-set ${set.name} --from <the ${source.package} module it wraps>\`, then rerun any \`add --variant … --all\`.`,
708
983
  ),
709
984
  );
710
985
  }
@@ -10,7 +10,11 @@ import * as fs from 'node:fs';
10
10
  import * as os from 'node:os';
11
11
  import * as path from 'node:path';
12
12
  import {afterEach, beforeEach, describe, expect, it} from 'vitest';
13
- import {iconSetCoverage, iconSetIssues} from './icon-set-checks.mjs';
13
+ import {
14
+ iconSetCoverage,
15
+ iconSetIssues,
16
+ suggestedIcons,
17
+ } from './icon-set-checks.mjs';
14
18
  import {moduleExportOrigin} from './module-exports.mjs';
15
19
  import {generatedTypesText} from './icon-set-writer.mjs';
16
20
  import {integrationCheck} from '../../api/integration/check/check.mjs';
@@ -22,6 +26,13 @@ import {
22
26
  writeIconPackage,
23
27
  } from '../../test-utils/icon-set-fixture.mjs';
24
28
  import {ICON_NAMES} from '../../authoring/doctypes/icon-set/icon-names.mjs';
29
+ import {rankIcons} from './icon-ranking.mjs';
30
+ import {astryxIconDefinitions} from './icon-definition-discovery.mjs';
31
+ import {discoverIconSetDirectory} from './icon-set-discovery.mjs';
32
+
33
+ /** The fixture package's one set, as discovery reads it. */
34
+ const readSet = () =>
35
+ discoverIconSetDirectory(path.join(dir, 'icon-sets'), '@acme/glyphs').sets[0];
25
36
 
26
37
  /** @type {string} */
27
38
  let tmp;
@@ -641,6 +652,26 @@ describe('icon definitions (map)', () => {
641
652
  // close and search are mapped; every other built-in is not.
642
653
  expect(builtIn).toHaveLength(ICON_NAMES.length - 2);
643
654
  expect(builtIn.every(issue => issue.severity === 'error')).toBe(true);
655
+ // Each names the command that maps it, never a hand edit of the data.
656
+ const error = builtIn.find(issue => issue.message.includes('"error"'));
657
+ expect(error?.message).toContain(
658
+ '`astryx experimental icon map error <icon id>`',
659
+ );
660
+ expect(error?.message).not.toContain('add it to "map"');
661
+ // A find hint names a search only when that search finds icons.
662
+ for (const issue of builtIn) {
663
+ const query =
664
+ /icons matching "([^"]+)": `astryx experimental icon \1 --set glyphs`/u.exec(
665
+ issue.message,
666
+ );
667
+ if (query) {
668
+ expect(rankIcons([readSet()], query[1]).length).toBeGreaterThan(0);
669
+ } else {
670
+ expect(issue.message).toContain(
671
+ 'no icon in the set has its name or words',
672
+ );
673
+ }
674
+ }
644
675
  // An issue is only ever an error or a warning.
645
676
  expect(
646
677
  issues.every(issue => ['error', 'warning'].includes(issue.severity)),
@@ -692,23 +723,23 @@ describe('icon definitions (map)', () => {
692
723
  });
693
724
 
694
725
  it("a map key that is neither Astryx's definition nor the set's own is an error", () => {
695
- const issues = issuesOf({data: data(d => (d.map.rotate = 'home'))});
726
+ const issues = issuesOf({data: data(d => (d.map.orbit = 'home'))});
696
727
  expect(issues).toEqual([
697
728
  expect.objectContaining({code: 'invalid_icon_set', severity: 'error'}),
698
729
  ]);
699
730
  expect(issues[0].message).toMatch(
700
- /map "rotate" \(icon "home"\) is not an icon definition\. Declare it in definitions\/rotate\.doc\.mjs/,
731
+ /map "orbit" \(icon "home"\) is not an icon definition\. Declare it in definitions\/orbit\.doc\.mjs/,
701
732
  );
702
733
  });
703
734
 
704
735
  it("the set's own definitions: mapped is fine, unmapped warns with a suggestion, and one Astryx has warns", () => {
705
736
  const issues = issuesOf({
706
- data: data(d => (d.map.rotate = 'home')),
737
+ data: data(d => (d.map.orbit = 'home')),
707
738
  definitions: {
708
- rotate: definitionSource('rotate'),
739
+ orbit: definitionSource('orbit'),
709
740
  garbage: definitionSource('garbage', {words: ['bin', 'trash']}),
710
- // The trash icon is tagged garbage, and `tra` starts its id: neither
711
- // is a suggestion. No guessing.
741
+ // The trash icon has the word garbage, so it is a suggestion; `tra`
742
+ // only starts its id, so that is not. Never part of a word.
712
743
  rubbish: definitionSource('rubbish', {words: ['garbage', 'tra']}),
713
744
  delete: definitionSource('delete'),
714
745
  },
@@ -726,7 +757,9 @@ describe('icon definitions (map)', () => {
726
757
  'astryx experimental icon map garbage trash',
727
758
  );
728
759
  const rubbish = unused.find(issue => issue.message.includes('"rubbish"'));
729
- expect(rubbish?.message).not.toContain('Suggested');
760
+ expect(rubbish?.message).toContain(
761
+ 'Suggested: astryx experimental icon map rubbish trash.',
762
+ );
730
763
  const [coverage] = iconSetCoverage({
731
764
  name: '@acme/glyphs',
732
765
  iconSets: path.join(dir, 'icon-sets'),
@@ -735,9 +768,10 @@ describe('icon definitions (map)', () => {
735
768
  definition: 'garbage',
736
769
  icon: 'trash',
737
770
  });
738
- expect(
739
- coverage.suggestions.some(each => each.definition === 'rubbish'),
740
- ).toBe(false);
771
+ expect(coverage.suggestions).toContainEqual({
772
+ definition: 'rubbish',
773
+ icon: 'trash',
774
+ });
741
775
  expect(
742
776
  issues.find(issue => issue.code === 'icon_definition_shadowed')?.message,
743
777
  ).toContain('Astryx now has');
@@ -745,7 +779,7 @@ describe('icon definitions (map)', () => {
745
779
 
746
780
  it('a definition file that does not read makes the set invalid', () => {
747
781
  const issues = issuesOf({
748
- definitions: {rotate: definitionSource('Rotate')},
782
+ definitions: {orbit: definitionSource('Orbit')},
749
783
  });
750
784
  expect(issues).toEqual([
751
785
  expect.objectContaining({code: 'invalid_icon_set'}),
@@ -903,3 +937,82 @@ describe('the codes and severities FR15 lists', () => {
903
937
  expect(listed).toEqual(raised);
904
938
  });
905
939
  });
940
+
941
+ describe('suggestions join a plural only to its singular', () => {
942
+ /**
943
+ * @param {string[]} ids
944
+ * @param {{name: string, words?: string[]}} doc
945
+ */
946
+ const suggest = (ids, {name, words = []}) =>
947
+ suggestedIcons(
948
+ {data: {icons: ids.map(id => ({id, words: id.split('-')})), map: {}}},
949
+ {name, words},
950
+ ).map(each => each.icon);
951
+
952
+ it('never offers a grid of squares for stop, whose word is square', () => {
953
+ expect(suggest(['squares-2x2'], {name: 'stop', words: ['square']})).toEqual(
954
+ [],
955
+ );
956
+ expect(
957
+ suggest(['squares-2x2', 'square'], {name: 'stop', words: ['square']}),
958
+ ).toEqual(['square']);
959
+ });
960
+
961
+ it('meets a plural and its singular of the same word, either way', () => {
962
+ expect(suggest(['squares'], {name: 'square'})).toEqual(['squares']);
963
+ expect(suggest(['square'], {name: 'squares'})).toEqual(['square']);
964
+ expect(suggest(['arrows'], {name: 'arrow'})).toEqual(['arrows']);
965
+ expect(suggest(['arrow'], {name: 'arrows'})).toEqual(['arrow']);
966
+ });
967
+
968
+ it('never bridges a verb ending or a plural to a longer id', () => {
969
+ // `drafting` is not `draft`; `users` does not start `user-plus`.
970
+ expect(
971
+ suggest(['drafting-compass'], {name: 'compose', words: ['draft']}),
972
+ ).toEqual([]);
973
+ expect(suggest(['user-plus', 'user-cog'], {name: 'users'})).toEqual([]);
974
+ expect(suggest(['tool-case'], {name: 'wrench', words: ['tools']})).toEqual(
975
+ [],
976
+ );
977
+ });
978
+ });
979
+
980
+ describe('suggestions from a definition word never bridge to another meaning', () => {
981
+ const definitions = new Map(
982
+ astryxIconDefinitions().definitions.map(({doc}) => [doc.name, doc]),
983
+ );
984
+ /** @param {string} name @param {string[]} ids */
985
+ const suggest = (name, ids) =>
986
+ suggestedIcons(
987
+ {data: {icons: ids.map(id => ({id, words: id.split('-')})), map: {}}},
988
+ /** @type {any} */ (definitions.get(name)),
989
+ ).map(each => each.icon);
990
+
991
+ it.each([
992
+ ['creditCard', 'card-sim'],
993
+ ['bolt', 'fast-forward'],
994
+ ['archive', 'store'],
995
+ ['mobile', 'device-tablet'],
996
+ ['raiseHand', 'stop-circle'],
997
+ ['star', 'bookmark-square'],
998
+ ['database', 'table-cells'],
999
+ ['redo', 'forward'],
1000
+ ['activity', 'monitor'],
1001
+ ['stop', 'square-square'],
1002
+ ['moreHorizontal', 'ellipsis-vertical'],
1003
+ ])('%s never suggests %s', (name, id) => {
1004
+ expect(suggest(name, [id])).toEqual([]);
1005
+ });
1006
+
1007
+ it('still suggests a word with only a size, shape, or number after it', () => {
1008
+ expect(suggest('gridView', ['grid-2x2'])).toEqual(['grid-2x2']);
1009
+ expect(suggest('viewColumns', ['columns-3'])).toEqual(['columns-3']);
1010
+ expect(suggest('add', ['plus-circle'])).toEqual(['plus-circle']);
1011
+ });
1012
+
1013
+ it('finds the glyph a library names in two words through the definition’s words', () => {
1014
+ expect(suggest('raiseHand', ['hand-raised'])).toEqual(['hand-raised']);
1015
+ expect(suggest('location', ['map-pin'])).toEqual(['map-pin']);
1016
+ expect(suggest('textCase', ['case-sensitive'])).toEqual(['case-sensitive']);
1017
+ });
1018
+ });