@astryxdesign/cli 0.7.4 → 0.7.5-canary.04434e7

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 (259) hide show
  1. package/README.md +19 -19
  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/api/upgrade/run/failure-receipt.test.mjs +155 -0
  69. package/api/upgrade/run/run.mjs +170 -8
  70. package/api/upgrade/upgrade.doc.mjs +4 -4
  71. package/api/upgrade/upgrade.mjs +19 -4
  72. package/api/upgrade/upgrade.type.d.mts +12 -1
  73. package/api/upgrade/upgrade.type.mjs +16 -3
  74. package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
  75. package/assets/codemods/integration-runner.mjs +1 -1
  76. package/assets/codemods/run-codemod.mjs +17 -3
  77. package/assets/codemods/runner.mjs +81 -8
  78. package/assets/codemods/transform-prop.mjs +99 -49
  79. package/assets/codemods/transform-prop.test.mjs +36 -1
  80. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
  81. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +123 -70
  82. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
  83. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +200 -32
  84. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
  85. package/assets/discover/official-packages.json +4 -0
  86. package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
  87. package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
  88. package/assets/docs/tree/icon-sets.doc.mjs +50 -20
  89. package/assets/docs/tree/render-pages.doc.mjs +94 -0
  90. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  91. package/assets/icons/definitions/activity.doc.mjs +1 -1
  92. package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
  93. package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
  94. package/assets/icons/definitions/alignStart.doc.mjs +10 -0
  95. package/assets/icons/definitions/archive.doc.mjs +1 -1
  96. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
  97. package/assets/icons/definitions/attach.doc.mjs +1 -1
  98. package/assets/icons/definitions/audio.doc.mjs +1 -1
  99. package/assets/icons/definitions/cart.doc.mjs +1 -1
  100. package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
  101. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
  102. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
  103. package/assets/icons/definitions/close.doc.mjs +1 -1
  104. package/assets/icons/definitions/collapse.doc.mjs +1 -1
  105. package/assets/icons/definitions/compose.doc.mjs +1 -1
  106. package/assets/icons/definitions/conversation.doc.mjs +1 -1
  107. package/assets/icons/definitions/copy.doc.mjs +1 -1
  108. package/assets/icons/definitions/cpu.doc.mjs +9 -0
  109. package/assets/icons/definitions/database.doc.mjs +1 -1
  110. package/assets/icons/definitions/desktop.doc.mjs +1 -1
  111. package/assets/icons/definitions/discount.doc.mjs +1 -1
  112. package/assets/icons/definitions/download.doc.mjs +1 -1
  113. package/assets/icons/definitions/emoji.doc.mjs +1 -1
  114. package/assets/icons/definitions/error.doc.mjs +1 -1
  115. package/assets/icons/definitions/expand.doc.mjs +1 -1
  116. package/assets/icons/definitions/experiment.doc.mjs +1 -1
  117. package/assets/icons/definitions/externalLink.doc.mjs +7 -1
  118. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
  119. package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
  120. package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
  121. package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
  122. package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
  123. package/assets/icons/definitions/gitFork.doc.mjs +9 -0
  124. package/assets/icons/definitions/info.doc.mjs +1 -1
  125. package/assets/icons/definitions/location.doc.mjs +1 -1
  126. package/assets/icons/definitions/mention.doc.mjs +1 -1
  127. package/assets/icons/definitions/menu.doc.mjs +1 -1
  128. package/assets/icons/definitions/microphone.doc.mjs +1 -1
  129. package/assets/icons/definitions/mobile.doc.mjs +1 -1
  130. package/assets/icons/definitions/money.doc.mjs +1 -1
  131. package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
  132. package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
  133. package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
  134. package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
  135. package/assets/icons/definitions/panelRight.doc.mjs +10 -0
  136. package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
  137. package/assets/icons/definitions/redo.doc.mjs +1 -1
  138. package/assets/icons/definitions/refresh.doc.mjs +1 -1
  139. package/assets/icons/definitions/rotate.doc.mjs +9 -0
  140. package/assets/icons/definitions/scale.doc.mjs +10 -0
  141. package/assets/icons/definitions/search.doc.mjs +1 -1
  142. package/assets/icons/definitions/send.doc.mjs +1 -1
  143. package/assets/icons/definitions/settings.doc.mjs +1 -1
  144. package/assets/icons/definitions/star.doc.mjs +1 -1
  145. package/assets/icons/definitions/stop.doc.mjs +1 -1
  146. package/assets/icons/definitions/success.doc.mjs +1 -1
  147. package/assets/icons/definitions/textCase.doc.mjs +9 -0
  148. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
  149. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
  150. package/assets/icons/definitions/trendDown.doc.mjs +7 -1
  151. package/assets/icons/definitions/trendUp.doc.mjs +1 -1
  152. package/assets/icons/definitions/undo.doc.mjs +1 -1
  153. package/assets/icons/definitions/upload.doc.mjs +1 -1
  154. package/assets/icons/definitions/userAdd.doc.mjs +1 -1
  155. package/assets/icons/definitions/warning.doc.mjs +1 -1
  156. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
  157. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
  158. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
  159. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
  160. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
  161. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
  162. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
  163. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
  164. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
  165. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
  166. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  167. package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
  168. package/authoring/debug/parse.d.mts +2 -2
  169. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
  170. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
  171. package/authoring/doctypes/icon-set/parse.d.mts +1 -0
  172. package/authoring/doctypes/icon-set/parse.mjs +1 -0
  173. package/authoring/doctypes/icon-set/type.ts +5 -0
  174. package/authoring/doctypes/template/template.doc.mjs +1 -1
  175. package/authoring/doctypes/template/type.ts +2 -1
  176. package/clients/cli/commands/doctor.mjs +16 -17
  177. package/clients/cli/commands/experimental/icon.mjs +167 -35
  178. package/clients/cli/commands/experimental/index.mjs +2 -0
  179. package/clients/cli/commands/experimental/render.mjs +113 -0
  180. package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
  181. package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
  182. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
  183. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
  184. package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
  185. package/clients/cli/commands/experimental-render.doc.mjs +60 -0
  186. package/clients/cli/commands/experimental.doc.mjs +4 -2
  187. package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
  188. package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
  189. package/clients/cli/commands/icon.test.mjs +1 -1
  190. package/clients/cli/commands/template.mjs +4 -1
  191. package/clients/cli/commands/text-json-parity.test.mjs +46 -0
  192. package/clients/cli/commands/upgrade.doc.mjs +17 -0
  193. package/clients/cli/commands/upgrade.file-protection.test.mjs +29 -0
  194. package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
  195. package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
  196. package/clients/cli/commands/upgrade.mjs +9 -2
  197. package/clients/cli/index.mjs +1 -0
  198. package/foundation/discovery/component-discovery.d.mts +2 -1
  199. package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
  200. package/foundation/discovery/component-discovery.mjs +13 -7
  201. package/foundation/discovery/icon-set-checks.d.mts +43 -9
  202. package/foundation/discovery/icon-set-checks.mjs +296 -21
  203. package/foundation/discovery/icon-set-checks.test.mjs +125 -12
  204. package/foundation/discovery/icon-set-writer.d.mts +192 -3
  205. package/foundation/discovery/icon-set-writer.mjs +608 -34
  206. package/foundation/discovery/icon-set-writer.test.mjs +26 -0
  207. package/foundation/discovery/module-exports.mjs +82 -25
  208. package/foundation/discovery/module-exports.test.mjs +38 -1
  209. package/foundation/discovery/package-exports.d.mts +13 -0
  210. package/foundation/discovery/package-exports.mjs +40 -1
  211. package/foundation/discovery/template-icons.d.mts +6 -0
  212. package/foundation/discovery/template-icons.mjs +98 -10
  213. package/foundation/discovery/template-icons.test.mjs +103 -0
  214. package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
  215. package/foundation/doc-compiler/import.mjs +81 -8
  216. package/foundation/doc-compiler/read.d.mts +4 -3
  217. package/foundation/doc-compiler/read.mjs +15 -10
  218. package/foundation/doc-compiler/read.test.mjs +59 -1
  219. package/foundation/doc-compiler/tree.mjs +3 -1
  220. package/foundation/fs/module-loader.d.mts +3 -2
  221. package/foundation/fs/module-loader.mjs +3 -2
  222. package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
  223. package/foundation/fs/read-record.d.mts +27 -0
  224. package/foundation/fs/read-record.mjs +83 -15
  225. package/foundation/fs/read-record.test.mjs +88 -1
  226. package/foundation/render/assets.d.mts +31 -0
  227. package/foundation/render/assets.mjs +102 -0
  228. package/foundation/render/component-map.d.mts +52 -0
  229. package/foundation/render/component-map.mjs +141 -0
  230. package/foundation/render/css-cut.d.mts +29 -0
  231. package/foundation/render/css-cut.mjs +144 -0
  232. package/foundation/render/embedded-files.d.mts +28 -0
  233. package/foundation/render/embedded-files.mjs +108 -0
  234. package/foundation/render/embedded-imports.d.mts +61 -0
  235. package/foundation/render/embedded-imports.mjs +315 -0
  236. package/foundation/render/html-reader.d.mts +37 -0
  237. package/foundation/render/html-reader.mjs +121 -0
  238. package/foundation/render/page-worker.d.mts +7 -0
  239. package/foundation/render/page-worker.mjs +519 -0
  240. package/foundation/render/rebuild.d.mts +19 -0
  241. package/foundation/render/rebuild.mjs +269 -0
  242. package/foundation/render/render-page.d.mts +85 -0
  243. package/foundation/render/render-page.mjs +612 -0
  244. package/foundation/render/render.test.mjs +117 -0
  245. package/foundation/render/source-block.d.mts +52 -0
  246. package/foundation/render/source-block.mjs +106 -0
  247. package/foundation/response/base.d.ts +7 -0
  248. package/foundation/response/error-codes.d.mts +10 -1
  249. package/foundation/response/error-codes.doc.mjs +59 -2
  250. package/foundation/response/error-codes.mjs +62 -1
  251. package/foundation/response/json.d.mts +10 -3
  252. package/foundation/response/json.mjs +16 -4
  253. package/foundation/response/response-types.doc.mjs +38 -1
  254. package/foundation/text/string-utils.mjs +33 -0
  255. package/foundation/text/string-utils.test.mjs +17 -0
  256. package/foundation/text/suggest-order.d.mts +17 -3
  257. package/foundation/text/suggest-order.mjs +58 -13
  258. package/foundation/text/suggest-order.test.mjs +53 -0
  259. package/package.json +14 -9
@@ -28,9 +28,8 @@ export function iconSetIssues(packageDir: string, loaded: {
28
28
  * Astryx's optional (not built-in) definitions the set's `map` does not
29
29
  * name. Mapping them is optional, so they never fail a check.
30
30
  * @property {Array<{definition: string, icon: string}>} suggestions for every
31
- * unmapped definition, built-in, optional, or the set's own, the icon whose
32
- * whole id is the definition's name or one of its words; nothing is guessed
33
- * beyond that
31
+ * unmapped definition, built-in, optional, or the set's own, the best icon
32
+ * {@link suggestedIcons} gives, if any
34
33
  * @property {IconSetUnchecked[]} unchecked what the checks could not judge:
35
34
  * never counted, never failing, even under `--strict`
36
35
  */
@@ -48,9 +47,8 @@ export function iconSetCoverage(loaded: {
48
47
  iconSets?: string;
49
48
  }, unchecked?: Map<string, IconSetUnchecked[]>): IconSetCoverage[];
50
49
  /**
51
- * The set's icon whose whole id is the definition's name (`chevronDown` is
52
- * `chevron-down`) or, in order, one of its words (spaces read as `-`). Null
53
- * when none is: a suggestion is never a guess from parts of words.
50
+ * The best icon {@link suggestedIcons} gives for a definition, or null when
51
+ * it gives none.
54
52
  * @param {DiscoveredIconSet} set
55
53
  * @param {import('../../authoring/doctypes/icon-definition/type').IconDefinitionDoc} doc
56
54
  * @returns {{map: string, icon: string} | null}
@@ -59,6 +57,41 @@ export function suggestIcon(set: DiscoveredIconSet, doc: import("../../authoring
59
57
  map: string;
60
58
  icon: string;
61
59
  } | null;
60
+ /**
61
+ * The icons a definition might map to, best first, at most three, in the
62
+ * order AST-084 FR13 gives: the name in another spelling, an icon the library
63
+ * gives the name as another name, ids that start with the name (`video` →
64
+ * `video-camera`, never `close` → `panel-left-close`), an id that is one of
65
+ * its words (`delete` → `trash`), another name that is one of its words, and
66
+ * two-word ids that are a one-word word sized, shaped, or numbered
67
+ * (`grid-2x2`). An icon `map` already names
68
+ * for another definition, or whose id is another definition's name, is left
69
+ * out: it has a meaning of its own. Never a negated form or the opposite
70
+ * direction, and never a guess from parts of words.
71
+ * @param {{data: {icons: Array<{id: string, words?: string[]}>, map?: Record<string, string>}, definitions?: Array<{doc: {name: string}}>}} set
72
+ * @param {{name: string, words: string[]}} doc
73
+ * @returns {Array<{icon: string, word: string}>}
74
+ */
75
+ export function suggestedIcons(set: {
76
+ data: {
77
+ icons: Array<{
78
+ id: string;
79
+ words?: string[];
80
+ }>;
81
+ map?: Record<string, string>;
82
+ };
83
+ definitions?: Array<{
84
+ doc: {
85
+ name: string;
86
+ };
87
+ }>;
88
+ }, doc: {
89
+ name: string;
90
+ words: string[];
91
+ }): Array<{
92
+ icon: string;
93
+ word: string;
94
+ }>;
62
95
  /** @typedef {import('../integrations/issue').AstryxIntegrationIssue} Issue */
63
96
  /** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
64
97
  /** An invalid descriptor or data file. */
@@ -87,6 +120,8 @@ export const ICON_DEFINITION_UNUSED: "icon_definition_unused";
87
120
  export const ICON_SOURCE_VERSION_DRIFT: "icon_source_version_drift";
88
121
  /** A set with an upstream and no license notice. */
89
122
  export const ICON_LICENSE_NOTICE_MISSING: "icon_license_notice_missing";
123
+ /** How many icons one definition is suggested at most. */
124
+ export const SUGGESTIONS_PER_DEFINITION: 3;
90
125
  /**
91
126
  * One item a check could not judge: listed, never counted, never failing.
92
127
  */
@@ -124,9 +159,8 @@ export type IconSetCoverage = {
124
159
  }>;
125
160
  /**
126
161
  * for every
127
- * unmapped definition, built-in, optional, or the set's own, the icon whose
128
- * whole id is the definition's name or one of its words; nothing is guessed
129
- * beyond that
162
+ * unmapped definition, built-in, optional, or the set's own, the best icon
163
+ * {@link suggestedIcons} gives, if any
130
164
  */
131
165
  suggestions: Array<{
132
166
  definition: string;
@@ -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
  }