@astryxdesign/cli 0.7.10 → 0.7.11-canary.3df65bf

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 (102) hide show
  1. package/api/build/blocks/blocks.weights.json +1 -1
  2. package/api/build/build.doc.mjs +1 -1
  3. package/api/build/kit/rank.mjs +21 -4
  4. package/api/build/kit/signals.mjs +9 -3
  5. package/api/build/kit/start.d.mts +19 -0
  6. package/api/build/kit/start.mjs +49 -2
  7. package/api/build/kit/weights.d.mts +12 -0
  8. package/api/build/kit/weights.mjs +52 -16
  9. package/api/build/kit/words.d.mts +1 -0
  10. package/api/build/kit/words.mjs +1 -1
  11. package/api/docs/_adapter.mjs +2 -1
  12. package/api/doctor/_adapter.d.mts +28 -1
  13. package/api/doctor/_adapter.mjs +39 -2
  14. package/api/doctor/doctor.doc.mjs +1 -1
  15. package/api/doctor/doctor.mjs +9 -2
  16. package/api/doctor/theme-checks.d.mts +44 -3
  17. package/api/doctor/theme-checks.mjs +273 -6
  18. package/api/hook/hook.mjs +13 -0
  19. package/api/icon/_adapter.d.mts +3 -2
  20. package/api/icon/_adapter.mjs +8 -2
  21. package/api/icon/_authoring.d.mts +1 -0
  22. package/api/icon/_authoring.mjs +362 -38
  23. package/api/icon/_default-look.d.mts +155 -0
  24. package/api/icon/_default-look.mjs +474 -0
  25. package/api/icon/_records.d.mts +1 -1
  26. package/api/icon/_records.mjs +1 -0
  27. package/api/icon/add/add.mjs +224 -38
  28. package/api/icon/icon.type.d.mts +7 -2
  29. package/api/icon/icon.type.mjs +4 -2
  30. package/api/icon/iconAdd.doc.mjs +2 -2
  31. package/api/icon/iconNewDefinition.doc.mjs +3 -2
  32. package/api/icon/iconNewSet.doc.mjs +4 -4
  33. package/api/icon/search/search.mjs +10 -9
  34. package/api/integration/add-helpers.d.mts +2 -1
  35. package/api/integration/add-helpers.mjs +5 -2
  36. package/api/integration/authoring-checks.d.mts +0 -2
  37. package/api/integration/authoring-checks.mjs +1 -6
  38. package/api/integration/pack-check.d.mts +8 -6
  39. package/api/integration/pack-check.mjs +16 -6
  40. package/api/logger.mjs +2 -1
  41. package/api/render/_adapter.mjs +47 -1
  42. package/api/render/render.doc.mjs +2 -1
  43. package/api/search/_gather-components.mjs +2 -1
  44. package/api/swizzle/copy/copy.mjs +5 -1
  45. package/api/theme/build/build.mjs +15 -4
  46. package/assets/docs/author-a-theme.doc.mjs +2 -0
  47. package/assets/docs/getting-started.doc.mjs +20 -0
  48. package/assets/docs/tree/building-blocks.doc.mjs +1 -0
  49. package/assets/docs/tree/global-integrations.doc.mjs +1 -0
  50. package/assets/docs/tree/help.doc.mjs +1 -1
  51. package/assets/docs/tree/icon-sets.doc.mjs +9 -3
  52. package/assets/docs/tree/quick-start.doc.mjs +1 -0
  53. package/assets/docs/tree/render-pages.doc.mjs +1 -1
  54. package/assets/docs/tree/ship.doc.mjs +1 -1
  55. package/assets/docs/tree/tokens-color.doc.mjs +2 -2
  56. package/assets/templates/blocks/components/Table/TableLeadingMarkSelection.doc.mjs +15 -0
  57. package/assets/templates/blocks/components/Table/TableLeadingMarkSelection.tsx +134 -0
  58. package/authoring/doctypes/_schema.d.mts +1 -1
  59. package/clients/cli/commands/build.doc.mjs +3 -2
  60. package/clients/cli/commands/build.mjs +34 -5
  61. package/clients/cli/commands/experimental/icon.mjs +31 -10
  62. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  63. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
  64. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  65. package/clients/cli/index.mjs +36 -7
  66. package/foundation/discovery/authoring-self-docs.mjs +8 -3
  67. package/foundation/discovery/cli-self-docs.mjs +2 -1
  68. package/foundation/discovery/component-discovery.mjs +16 -0
  69. package/foundation/discovery/doc-types.mjs +9 -2
  70. package/foundation/discovery/docs-discovery.mjs +6 -4
  71. package/foundation/discovery/icon-definition-discovery.mjs +3 -3
  72. package/foundation/discovery/icon-ranking.d.mts +27 -3
  73. package/foundation/discovery/icon-ranking.mjs +125 -8
  74. package/foundation/discovery/icon-set-checks.mjs +40 -20
  75. package/foundation/discovery/icon-set-writer.d.mts +210 -16
  76. package/foundation/discovery/icon-set-writer.mjs +619 -79
  77. package/foundation/discovery/module-exports.d.mts +92 -4
  78. package/foundation/discovery/module-exports.mjs +410 -61
  79. package/foundation/discovery/template-adapter.mjs +5 -7
  80. package/foundation/discovery/theme-discovery.mjs +8 -10
  81. package/foundation/doc-compiler/tree.mjs +2 -2
  82. package/foundation/env/package-manager.d.mts +12 -4
  83. package/foundation/env/package-manager.mjs +15 -6
  84. package/foundation/env/semver.mjs +41 -9
  85. package/foundation/fs/listing-cache.d.mts +3 -1
  86. package/foundation/fs/listing-cache.mjs +63 -11
  87. package/foundation/fs/paths.mjs +2 -1
  88. package/foundation/release/notices.d.mts +16 -0
  89. package/foundation/release/notices.mjs +27 -6
  90. package/foundation/render/embedded-imports.d.mts +7 -0
  91. package/foundation/render/embedded-imports.mjs +1 -1
  92. package/foundation/render/page-worker.mjs +109 -4
  93. package/foundation/render/render-page.d.mts +16 -1
  94. package/foundation/render/render-page.mjs +25 -18
  95. package/foundation/render/served-packages.d.mts +33 -0
  96. package/foundation/render/served-packages.mjs +75 -0
  97. package/foundation/render/single-copy-hooks.d.mts +18 -0
  98. package/foundation/render/single-copy-hooks.mjs +44 -0
  99. package/foundation/text/shell-arg.d.mts +14 -0
  100. package/foundation/text/shell-arg.mjs +17 -0
  101. package/foundation/text/string-utils.mjs +25 -25
  102. package/package.json +6 -6
@@ -13,6 +13,7 @@
13
13
  import * as fs from 'node:fs';
14
14
  import * as path from 'node:path';
15
15
  import {AstryxError} from '../error.mjs';
16
+ import {logger} from '../logger.mjs';
16
17
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
17
18
  import {
18
19
  assertWithin,
@@ -41,7 +42,11 @@ import {
41
42
  iconSetDataText,
42
43
  journalFile,
43
44
  librarySource,
45
+ everyLibraryIcon,
44
46
  libraryIcons,
47
+ libraryLooks,
48
+ lookPositions,
49
+ moduleNaming,
45
50
  nonIconExports,
46
51
  resolveIconSource,
47
52
  peerNote,
@@ -50,6 +55,12 @@ import {
50
55
  writeGeneratedIcons,
51
56
  writeIconSetData,
52
57
  } from '../../foundation/discovery/icon-set-writer.mjs';
58
+ import {
59
+ describedLooks,
60
+ drawnLooks,
61
+ resolveDefaultLook,
62
+ } from './_default-look.mjs';
63
+ import {shellArg} from '../../foundation/text/shell-arg.mjs';
53
64
  import {astryxIconDefinitions} from '../../foundation/discovery/icon-definition-discovery.mjs';
54
65
  import {suggestedIcons} from '../../foundation/discovery/icon-set-checks.mjs';
55
66
  import {
@@ -99,7 +110,7 @@ function quoteJs(value) {
99
110
  */
100
111
  export async function addIconSet(name, options) {
101
112
  const {cwd = process.cwd(), dryRun = false, from} = options;
102
- const looks = variantOptions(options);
113
+ const given = variantOptions(options);
103
114
  const exclude =
104
115
  typeof options.exclude === 'string'
105
116
  ? options.exclude
@@ -192,7 +203,30 @@ export async function addIconSet(name, options) {
192
203
  dryRun,
193
204
  from,
194
205
  exclude,
195
- looks,
206
+ looks: given,
207
+ describe: {
208
+ displayName: options.displayName,
209
+ description: options.description,
210
+ },
211
+ packageDir,
212
+ rootPath,
213
+ manifestPath: projectPath(path.relative(packageDir, manifestFile)),
214
+ });
215
+ }
216
+ // Without --from, an existing set takes new variants, a default variant, a
217
+ // display name or a description in place, and nothing else changes.
218
+ if (
219
+ from == null &&
220
+ fs.existsSync(docFile) &&
221
+ fs.existsSync(dataFile) &&
222
+ (given != null ||
223
+ options.displayName?.trim() ||
224
+ options.description?.trim())
225
+ ) {
226
+ return redeclareIconSet(name, {
227
+ cwd,
228
+ dryRun,
229
+ looks: given,
196
230
  describe: {
197
231
  displayName: options.displayName,
198
232
  description: options.description,
@@ -227,14 +261,48 @@ export async function addIconSet(name, options) {
227
261
  let skipped = [];
228
262
  /** @type {ReturnType<typeof librarySource>} */
229
263
  let library = null;
264
+ /** @type {{summary: import('../../foundation/discovery/icon-set-writer.mjs').LibraryLookSummary | null}} */
265
+ const lookFound = {summary: null};
266
+ // Without --from the set has no icons yet, so no look to match.
267
+ let looks =
268
+ from == null
269
+ ? resolveDefaultLook({
270
+ name,
271
+ given,
272
+ current: undefined,
273
+ icons: 0,
274
+ drawn: null,
275
+ library: null,
276
+ }).looks
277
+ : null;
230
278
  if (from != null) {
231
279
  const source = await iconAuthoring(() =>
232
280
  resolveIconSource(from, {packageDir, pkg}),
233
281
  );
234
- const found = libraryIcons(source.file, {exclude});
282
+ const found = libraryIcons(source.file, {
283
+ exclude,
284
+ // The library's look words decide the default before any glyph is
285
+ // picked, so each icon's export draws it.
286
+ prefer: positions => {
287
+ looks = resolveDefaultLook({
288
+ name,
289
+ given,
290
+ current: undefined,
291
+ icons: 0,
292
+ drawn: null,
293
+ library: {module: source.module, positions},
294
+ }).looks;
295
+ return looks ? [looks.default] : [];
296
+ },
297
+ module: source.module,
298
+ progress: line => logger.warn(line),
299
+ summary: each => {
300
+ lookFound.summary = each;
301
+ },
302
+ });
235
303
  if (found.length === 0) {
236
304
  throw new AstryxError(
237
- `"${from}" exports no icon components this command can read. If its icons are data (objects or SVG strings), run \`astryx experimental icon new-set ${name}\`, declare an "adapter" in ${name}.icons.json, and run this command again; or add icons one at a time with \`astryx experimental icon add <Export> --from ${from}\`.`,
305
+ `"${from}" exports no icon components this command can read. If its icons are data (objects or SVG strings), run \`astryx experimental icon new-set ${name}\`, declare an "adapter" in ${name}.icons.json, and run this command again; or add icons one at a time with \`astryx experimental icon add <Export> --from ${from} --set ${name}\`.`,
238
306
  undefined,
239
307
  ERROR_CODES.ERR_NOT_FOUND,
240
308
  );
@@ -452,14 +520,196 @@ export async function addIconSet(name, options) {
452
520
  `Left out ${skipped.length} exports that are not icons: ${skipped.slice(0, 12).join(', ')}${skipped.length > 12 ? ', …' : ''}.`,
453
521
  ]
454
522
  : []),
455
- ...mappedNotes(map),
456
- ...suggestionNotes(suggestions),
523
+ ...(from != null && lookFound.summary == null
524
+ ? [`Found ${icons.length} icons in ${from}.`]
525
+ : []),
526
+ ...(from != null && lookFound.summary != null
527
+ ? lookNotes(lookFound.summary, icons.length, from, looks, name)
528
+ : []),
529
+ ...mappedNotes(map, name),
530
+ ...suggestionNotes(suggestions, name),
457
531
  'Run `astryx integration check` to see the icon definitions still to map.',
458
532
  ];
459
533
  }
460
534
  return result;
461
535
  }
462
536
 
537
+ /**
538
+ * A set descriptor's source with `--display-name` and `--description`
539
+ * written into its fields; the rest as it was.
540
+ * @param {string} source
541
+ * @param {{displayName?: string, description?: string}} describe
542
+ */
543
+ function describedDoc(source, describe) {
544
+ let out = source;
545
+ for (const [field, value] of /** @type {const} */ ([
546
+ ['displayName', describe.displayName],
547
+ ['description', describe.description],
548
+ ])) {
549
+ if (!value?.trim()) continue;
550
+ out = out.replace(
551
+ new RegExp(`^(\\s*${field}:\\s*)(['"\`])(?:\\\\.|(?!\\2).)*\\2,?$`, 'mu'),
552
+ (_, lead) => `${lead}${quoteJs(value.trim())},`,
553
+ );
554
+ }
555
+ return out;
556
+ }
557
+
558
+ /**
559
+ * `new-set <name>` without `--from` over an existing set: declare its
560
+ * variants and default variant, and rewrite its display name and
561
+ * description, in place. Its icons, map and generated module stay as they
562
+ * are. A variant an icon still has must stay declared, and the default
563
+ * variant is one no icon lists as an extra look. A set with icons keeps its
564
+ * default variant: only a refresh with `--from` from a library whose names
565
+ * name its looks moves it. With none declared,
566
+ * its default is the look its icons' exports draw.
567
+ * @param {string} name
568
+ * @param {{cwd: string, dryRun: boolean, looks: Looks | null, describe: {displayName?: string, description?: string}, packageDir: string, rootPath: string, manifestPath: string}} options
569
+ */
570
+ async function redeclareIconSet(
571
+ name,
572
+ {cwd, dryRun, looks: given, describe, packageDir, rootPath, manifestPath},
573
+ ) {
574
+ return iconAuthoring(async () => {
575
+ const where = await findLocalIconSet(cwd, name);
576
+ const {set} = where;
577
+ const current = set.data.default?.variant;
578
+ const drawn =
579
+ given && set.data.icons.length > 0
580
+ ? drawnLooks(set, packageDir, module =>
581
+ libraryPositions(module, where, Boolean(set.data.adapter)),
582
+ )
583
+ : null;
584
+ const {looks} = resolveDefaultLook({
585
+ name,
586
+ given,
587
+ current,
588
+ icons: set.data.icons.length,
589
+ drawn,
590
+ library: null,
591
+ });
592
+ if (looks) {
593
+ const declared = new Set(looks.variants);
594
+ const dropped = set.data.icons.flatMap(icon =>
595
+ (icon.variants ?? [])
596
+ .filter(each => !declared.has(each.variant))
597
+ .map(each => `${icon.id} (${each.variant})`),
598
+ );
599
+ if (dropped.length > 0) {
600
+ throw new AstryxError(
601
+ `These icons still have a variant --variants leaves out: ${dropped.slice(0, 8).join(', ')}${dropped.length > 8 ? ', …' : ''}. Keep it in --variants.`,
602
+ [
603
+ {
604
+ name: `--variants ${[...new Set([...looks.variants, ...set.data.icons.flatMap(icon => (icon.variants ?? []).map(each => each.variant))])].join(',')}`,
605
+ reason: 'keep every variant an icon has',
606
+ },
607
+ ],
608
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
609
+ );
610
+ }
611
+ const asExtra = set.data.icons
612
+ .filter(icon =>
613
+ (icon.variants ?? []).some(each => each.variant === looks.default),
614
+ )
615
+ .map(icon => icon.id);
616
+ if (asExtra.length > 0) {
617
+ throw new AstryxError(
618
+ `"${looks.default}" can't be the default variant: ${asExtra.length} icons list it as another look (${asExtra.slice(0, 8).join(', ')}${asExtra.length > 8 ? ', …' : ''}), and each icon's own export draws the default.`,
619
+ undefined,
620
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
621
+ );
622
+ }
623
+ }
624
+ const next = {
625
+ ...set.data,
626
+ ...(looks
627
+ ? {variants: looks.variants, default: {variant: looks.default}}
628
+ : {}),
629
+ };
630
+ const docFile = path.join(set.dir, `${set.name}.doc.mjs`);
631
+ const docBefore = fs.readFileSync(docFile, 'utf-8');
632
+ const docAfter = describedDoc(docBefore, describe);
633
+ const dataChanged =
634
+ iconSetDataText(next) !== fs.readFileSync(set.dataPath, 'utf-8');
635
+ /** @type {string[]} */
636
+ const files = [];
637
+ if (dataChanged) {
638
+ files.push(projectPath(path.relative(packageDir, set.dataPath)));
639
+ }
640
+ if (docAfter !== docBefore) {
641
+ files.push(projectPath(path.relative(packageDir, docFile)));
642
+ }
643
+ if (!dryRun) {
644
+ if (dataChanged) writeIconSetData(set, next);
645
+ if (docAfter !== docBefore) {
646
+ journalFile(docFile);
647
+ fs.writeFileSync(docFile, docAfter);
648
+ }
649
+ }
650
+ const result = receipt(
651
+ 'icon-set',
652
+ name,
653
+ {path: rootPath, created: false},
654
+ manifestPath,
655
+ files,
656
+ dryRun,
657
+ );
658
+ result.data.icons = set.data.icons.length;
659
+ result.data.updated = true;
660
+ // A look the icons' own library draws comes from that library, so its
661
+ // command runs as printed; any other look comes from a module the
662
+ // author names.
663
+ /** @param {string} variant */
664
+ const fromFor = variant =>
665
+ drawn != null && drawn.positions.some(each => each.has(variant))
666
+ ? shellArg(drawn.module)
667
+ : '<module>';
668
+ const added = (looks?.variants ?? []).filter(
669
+ variant =>
670
+ variant !== looks?.default &&
671
+ !(set.data.variants ?? []).includes(variant),
672
+ );
673
+ result.data.notes = [
674
+ files.length === 0
675
+ ? `Icon set "${name}" already declares this; nothing changed.`
676
+ : `Updated icon set "${name}" in place; its icons, map and generated module are unchanged.`,
677
+ ...(added.length > 0
678
+ ? [
679
+ `Give each icon its ${added.join(', ')} look: ${added.map(variant => `\`astryx experimental icon add --variant ${variant} --from ${fromFor(variant)} --all --set ${name}\``).join(', ')}, or one icon with \`astryx experimental icon add <Export> --from <module> --id <icon> --variant <name> --set ${name}\`.`,
680
+ ]
681
+ : []),
682
+ ];
683
+ return result;
684
+ });
685
+ }
686
+
687
+ /**
688
+ * The receipt's notes for a library that draws each icon in several looks
689
+ * (a style, a size, a weight): what it found, the look the set took, and
690
+ * how to add another look as a variant.
691
+ * @param {import('../../foundation/discovery/icon-set-writer.mjs').LibraryLookSummary} summary
692
+ * @param {number} count icons in the set
693
+ * @param {string} from
694
+ * @param {{variants: string[], default: string} | null} looks
695
+ * @param {string} name the set's name
696
+ * @returns {string[]}
697
+ */
698
+ function lookNotes(summary, count, from, looks, name) {
699
+ const described = describedLooks(summary.positions);
700
+ const taken = [...summary.preferred].reverse().join(' ');
701
+ const styles = new Set(summary.positions.flat());
702
+ const others = (looks?.variants ?? []).filter(
703
+ variant => variant !== looks?.default && styles.has(variant),
704
+ );
705
+ return [
706
+ `Found ${count} icons in ${from}, each drawn in several looks (${described}) by ${summary.exports} exports. The set wraps each icon once, in the ${taken} look, named without the look words (\`x\`, \`XIcon\`).`,
707
+ others.length > 0
708
+ ? `Add the ${others.join(', ')} look${others.length > 1 ? 's' : ''} as variant${others.length > 1 ? 's' : ''}: ${others.map(variant => `\`astryx experimental icon add --variant ${variant} --from ${from} --all --set ${name}\``).join(', ')}.`
709
+ : `To offer another look as a variant, declare it with \`astryx experimental icon new-set ${name} --variants ${[...summary.preferred].reverse()[0]},<look>\` (no --from: the set's icons stay as they are) and run \`astryx experimental icon add --variant <look> --from ${from} --all --set ${name}\`.`,
710
+ ];
711
+ }
712
+
463
713
  /**
464
714
  * An icon's words from its id: each part, leaving out a bare number
465
715
  * (`volume-2` is `volume`) unless the id is only numbers.
@@ -520,36 +770,40 @@ function definitionSuggestions(icons, map) {
520
770
  /**
521
771
  * The receipt's note for the suggestions, if any.
522
772
  * @param {Array<{definition: string, icon: string}>} suggestions
773
+ * @param {string} name the set's name
523
774
  */
524
- function suggestionNotes(suggestions) {
775
+ function suggestionNotes(suggestions, name) {
525
776
  if (suggestions.length === 0) return [];
526
777
  const count = new Set(suggestions.map(each => each.definition)).size;
527
778
  return [
528
- `${count} unmapped icon definitions have possible icons (listed under Suggestions; nothing was written for them). Check each meaning, then map the ones that fit: \`astryx experimental icon map <definition> <icon>\`.`,
779
+ `${count} unmapped icon definitions have possible icons (listed under Suggestions; nothing was written for them). Check each meaning, then map the ones that fit: \`astryx experimental icon map <definition> <icon> --set ${name}\`.`,
529
780
  ];
530
781
  }
531
782
 
532
783
  /**
533
784
  * The receipt's note for the entries an exact name wrote, if any.
534
785
  * @param {Record<string, string>} map
786
+ * @param {string} name the set's name
535
787
  */
536
- function mappedNotes(map) {
788
+ function mappedNotes(map, name) {
537
789
  const count = Object.keys(map).length;
538
790
  if (count === 0) return [];
539
791
  return [
540
- `${count} icon definitions were mapped because an icon has their exact name (listed under Mapped by name). A library can draw another meaning under the same name, such as a backspace key named delete: check each, and remap with \`astryx experimental icon map <definition> <icon>\`.`,
792
+ `${count} icon definitions were mapped because an icon has their exact name (listed under Mapped by name). A library can draw another meaning under the same name, such as a backspace key named delete: check each, and remap with \`astryx experimental icon map <definition> <icon> --set ${name}\`.`,
541
793
  ];
542
794
  }
543
795
 
796
+ /** @typedef {import('./_default-look.mjs').Looks} Looks */
797
+
544
798
  /** A variant name: lower-kebab, such as `outline` or `mini-solid`. */
545
799
  const VARIANT_NAME_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
546
800
 
547
801
  /**
548
802
  * The variants and default variant `--variants` and `--default-variant`
549
- * declare, or
550
- * null when neither is given. The default is the first variant unless named.
803
+ * declare, or null when neither is given. Unless named, `default` is the
804
+ * first variant until {@link resolveDefaultLook} decides it.
551
805
  * @param {{variants?: string[] | string, defaultVariant?: string}} options
552
- * @returns {{variants: string[], default: string} | null}
806
+ * @returns {Looks | null}
553
807
  */
554
808
  function variantOptions(options) {
555
809
  const given =
@@ -594,7 +848,28 @@ function variantOptions(options) {
594
848
  ERROR_CODES.ERR_INVALID_ARGUMENT,
595
849
  );
596
850
  }
597
- return {variants, default: chosen || variants[0]};
851
+ return {variants, default: chosen || variants[0], named: Boolean(chosen)};
852
+ }
853
+
854
+ /**
855
+ * The look positions of a library the set's generated module names, or
856
+ * null when it can't be read.
857
+ * @param {string} module
858
+ * @param {{packageDir: string, pkg: Record<string, any>}} where
859
+ * @param {boolean} adapter
860
+ * @returns {Array<Set<string>> | null}
861
+ */
862
+ function libraryPositions(module, where, adapter) {
863
+ try {
864
+ const source = resolveIconSource(module, where);
865
+ return moduleNaming(source.file, {
866
+ adapter,
867
+ module,
868
+ progress: line => logger.warn(line),
869
+ }).positions;
870
+ } catch {
871
+ return null;
872
+ }
598
873
  }
599
874
 
600
875
  /**
@@ -632,7 +907,7 @@ async function iconAuthoring(step) {
632
907
  * them), the generated module gains the new exports, `map` keeps every entry
633
908
  * whose icon still exists, and the receipt names the entries that lost theirs.
634
909
  * @param {string} name
635
- * @param {{cwd: string, dryRun: boolean, from: string, exclude: string[], looks: {variants: string[], default: string} | null, describe: {displayName?: string, description?: string}, packageDir: string, rootPath: string, manifestPath: string}} options
910
+ * @param {{cwd: string, dryRun: boolean, from: string, exclude: string[], looks: Looks | null, describe: {displayName?: string, description?: string}, packageDir: string, rootPath: string, manifestPath: string}} options
636
911
  */
637
912
  async function refreshIconSet(
638
913
  name,
@@ -641,7 +916,7 @@ async function refreshIconSet(
641
916
  dryRun,
642
917
  from,
643
918
  exclude,
644
- looks,
919
+ looks: given,
645
920
  describe,
646
921
  packageDir,
647
922
  rootPath,
@@ -651,15 +926,46 @@ async function refreshIconSet(
651
926
  return iconAuthoring(async () => {
652
927
  const where = await findLocalIconSet(cwd, name);
653
928
  const {set} = where;
929
+ const current = set.data.default?.variant;
654
930
  const source = resolveIconSource(from, where);
655
931
  // Exports left out before stay out; --exclude adds to them.
656
932
  const excluded = [
657
933
  ...new Set([...(set.data.exclude ?? []), ...exclude]),
658
934
  ].sort();
659
- const found = libraryIcons(source.file, {
935
+ const everyIcon = everyLibraryIcon(source.file, {
660
936
  adapter: Boolean(set.data.adapter),
661
937
  exclude: excluded,
938
+ module: source.module,
939
+ progress: line => logger.warn(line),
662
940
  });
941
+ const libraryLookPositions = lookPositions(everyIcon.map(icon => icon.id));
942
+ // The look the icons from this library draw now decides whether a named
943
+ // default moves them.
944
+ const {looks, moved} = resolveDefaultLook({
945
+ name,
946
+ given,
947
+ current,
948
+ icons: set.data.icons.length,
949
+ drawn: drawnLooks(set, packageDir, () => libraryLookPositions, {
950
+ module: source.module,
951
+ }),
952
+ library: {module: source.module, positions: libraryLookPositions},
953
+ });
954
+ if (looks) {
955
+ const asExtra = set.data.icons
956
+ .filter(icon =>
957
+ (icon.variants ?? []).some(each => each.variant === looks.default),
958
+ )
959
+ .map(icon => icon.id);
960
+ if (asExtra.length > 0) {
961
+ throw new AstryxError(
962
+ `"${looks.default}" can't be the default variant: ${asExtra.length} icons list it as another look (${asExtra.slice(0, 8).join(', ')}${asExtra.length > 8 ? ', …' : ''}), and each icon's own export draws the default.`,
963
+ undefined,
964
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
965
+ );
966
+ }
967
+ }
968
+
663
969
  // A refresh changes only the icons the refreshed module supplies: those
664
970
  // the generated module re-exports or adapts from it. Every other icon
665
971
  // (your own `./` artwork, another library's) is kept as it is, with its
@@ -686,6 +992,37 @@ async function refreshIconSet(
686
992
  const bySource = new Map(
687
993
  supplied.map(icon => [origins.get(icon.export)?.source, icon]),
688
994
  );
995
+ // One icon per glyph. A look the set already wraps keeps its icon and id.
996
+ // A new glyph comes in once, in the preferred look. A new default variant
997
+ // moves each glyph's icon to that look.
998
+ const preferred = looks?.default ?? current;
999
+ const {icons: looksOf} = libraryLooks(
1000
+ everyIcon,
1001
+ preferred ? [preferred] : [],
1002
+ );
1003
+ const iconByExport = new Map(everyIcon.map(icon => [icon.export, icon]));
1004
+ /** @type {string[]} the set's exports whose statement now names another look */
1005
+ const repicked = [];
1006
+ const found = looksOf.flatMap(icon => {
1007
+ const wrapped = (icon.looks ?? []).filter(look => bySource.has(look));
1008
+ if (wrapped.length === 0) return [icon];
1009
+ return wrapped.map(look => {
1010
+ const prior = /** @type {{id: string, export: string}} */ (
1011
+ bySource.get(look)
1012
+ );
1013
+ if (moved && prior.id === icon.id && !bySource.has(icon.export)) {
1014
+ repicked.push(prior.export);
1015
+ return icon;
1016
+ }
1017
+ const own = /** @type {(typeof everyIcon)[number]} */ (
1018
+ iconByExport.get(look)
1019
+ );
1020
+ // Read by the glyph's id when the set already names it so.
1021
+ return prior.id === icon.id
1022
+ ? {...own, id: icon.id, name: icon.name}
1023
+ : own;
1024
+ });
1025
+ });
689
1026
  /** @param {{export: string, name: string, id: string}} icon */
690
1027
  const priorOf = icon =>
691
1028
  bySource.get(icon.export) ??
@@ -734,9 +1071,8 @@ async function refreshIconSet(
734
1071
  // `exclude`) names its library export, or the library no longer exports
735
1072
  // it.
736
1073
  const excludedNames = new Set(excluded);
737
- const gone = supplied.filter(
738
- icon => !fromLibrary.some(each => each.export === icon.export),
739
- );
1074
+ const keptExports = new Set(fromLibrary.map(each => each.export));
1075
+ const gone = supplied.filter(icon => !keptExports.has(icon.export));
740
1076
  const isExcluded = (/** @type {{export: string}} */ icon) =>
741
1077
  excludedNames.has(origins.get(icon.export)?.source ?? '') ||
742
1078
  excludedNames.has(icon.export);
@@ -782,20 +1118,7 @@ async function refreshIconSet(
782
1118
  // --display-name and --description rewrite the descriptor's fields.
783
1119
  const docFile = path.join(set.dir, `${set.name}.doc.mjs`);
784
1120
  const docBefore = fs.readFileSync(docFile, 'utf-8');
785
- let docAfter = docBefore;
786
- for (const [field, value] of /** @type {const} */ ([
787
- ['displayName', describe.displayName],
788
- ['description', describe.description],
789
- ])) {
790
- if (!value?.trim()) continue;
791
- docAfter = docAfter.replace(
792
- new RegExp(
793
- `^(\\s*${field}:\\s*)(['"\`])(?:\\\\.|(?!\\2).)*\\2,?$`,
794
- 'mu',
795
- ),
796
- (_, lead) => `${lead}${quoteJs(value.trim())},`,
797
- );
798
- }
1121
+ let docAfter = describedDoc(docBefore, describe);
799
1122
  // A refresh that first records the library as the set's source does what
800
1123
  // `new-set --from` does: the descriptor takes the library's license, but
801
1124
  // only over the value `new-set` wrote by default (the package's license,
@@ -853,8 +1176,9 @@ async function refreshIconSet(
853
1176
  }))
854
1177
  .filter(icon => publicName.has(icon.source)),
855
1178
  // The icons the library no longer exports leave the module too; a
856
- // renamed icon keeps its export.
857
- gone.map(icon => icon.export),
1179
+ // renamed icon keeps its export. An icon moved to the new default
1180
+ // look keeps its export, which now names that look.
1181
+ [...gone.map(icon => icon.export), ...repicked],
858
1182
  );
859
1183
  files.push(...written.files);
860
1184
  try {
@@ -913,8 +1237,8 @@ async function refreshIconSet(
913
1237
  `${renames.size} icons have a new id under this release's id rule, and keep their map entries, variants, and words: ${[...renames].map(([from, to]) => `${from} -> ${to}`).join(', ')}.`,
914
1238
  ]
915
1239
  : []),
916
- ...mappedNotes(byName),
917
- ...suggestionNotes(suggestions),
1240
+ ...mappedNotes(byName, name),
1241
+ ...suggestionNotes(suggestions, name),
918
1242
  ...(goneMissing.length > 0
919
1243
  ? [
920
1244
  `${goneMissing.length} icons the library no longer exports were removed from the set: ${goneMissing.map(icon => icon.id).join(', ')}.`,