@astryxdesign/cli 0.7.10 → 0.7.11-canary.143a5de

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 (104) 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/assets/templates/pages/theme-showcase/page.tsx +724 -792
  59. package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
  60. package/authoring/doctypes/_schema.d.mts +1 -1
  61. package/clients/cli/commands/build.doc.mjs +3 -2
  62. package/clients/cli/commands/build.mjs +34 -5
  63. package/clients/cli/commands/experimental/icon.mjs +31 -10
  64. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  65. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
  66. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  67. package/clients/cli/index.mjs +36 -7
  68. package/foundation/discovery/authoring-self-docs.mjs +8 -3
  69. package/foundation/discovery/cli-self-docs.mjs +2 -1
  70. package/foundation/discovery/component-discovery.mjs +16 -0
  71. package/foundation/discovery/doc-types.mjs +9 -2
  72. package/foundation/discovery/docs-discovery.mjs +6 -4
  73. package/foundation/discovery/icon-definition-discovery.mjs +3 -3
  74. package/foundation/discovery/icon-ranking.d.mts +27 -3
  75. package/foundation/discovery/icon-ranking.mjs +125 -8
  76. package/foundation/discovery/icon-set-checks.mjs +40 -20
  77. package/foundation/discovery/icon-set-writer.d.mts +210 -16
  78. package/foundation/discovery/icon-set-writer.mjs +619 -79
  79. package/foundation/discovery/module-exports.d.mts +92 -4
  80. package/foundation/discovery/module-exports.mjs +410 -61
  81. package/foundation/discovery/template-adapter.mjs +5 -7
  82. package/foundation/discovery/theme-discovery.mjs +8 -10
  83. package/foundation/doc-compiler/tree.mjs +2 -2
  84. package/foundation/env/package-manager.d.mts +12 -4
  85. package/foundation/env/package-manager.mjs +15 -6
  86. package/foundation/env/semver.mjs +41 -9
  87. package/foundation/fs/listing-cache.d.mts +3 -1
  88. package/foundation/fs/listing-cache.mjs +63 -11
  89. package/foundation/fs/paths.mjs +2 -1
  90. package/foundation/release/notices.d.mts +16 -0
  91. package/foundation/release/notices.mjs +27 -6
  92. package/foundation/render/embedded-imports.d.mts +7 -0
  93. package/foundation/render/embedded-imports.mjs +1 -1
  94. package/foundation/render/page-worker.mjs +109 -4
  95. package/foundation/render/render-page.d.mts +16 -1
  96. package/foundation/render/render-page.mjs +25 -18
  97. package/foundation/render/served-packages.d.mts +33 -0
  98. package/foundation/render/served-packages.mjs +75 -0
  99. package/foundation/render/single-copy-hooks.d.mts +18 -0
  100. package/foundation/render/single-copy-hooks.mjs +44 -0
  101. package/foundation/text/shell-arg.d.mts +14 -0
  102. package/foundation/text/shell-arg.mjs +17 -0
  103. package/foundation/text/string-utils.mjs +25 -25
  104. package/package.json +6 -6
@@ -161,17 +161,46 @@ const nodesByTree = new WeakMap();
161
161
  * @returns {readonly any[]}
162
162
  */
163
163
  function nodesOfType(node, type) {
164
+ return cachedNodes(node, `all\0${type}`, () =>
165
+ collectNodesOfType(node, type, []),
166
+ );
167
+ }
168
+
169
+ /**
170
+ * The module declarations of `type` at a program's top level, in source
171
+ * order: a library file is read without a walk of every function in it. A
172
+ * declaration nested in a namespace is not one of them. Only the readers of
173
+ * icon-set libraries use this: the parse-failure and re-export checks,
174
+ * {@link moduleExportOrigin} and the readers built on it, and
175
+ * {@link followedExportNames}. {@link bindingOrigin}, and so
176
+ * {@link aliasedOrigin}, {@link elementPropOrigins} and
177
+ * {@link moduleExportOrigins}, read with {@link nodesOfType}, as do the
178
+ * other readers.
179
+ * @param {any} program
180
+ * @param {string} type
181
+ * @returns {readonly any[]}
182
+ */
183
+ function moduleDeclarations(program, type) {
184
+ return cachedNodes(program, `top\0${type}`, () => topLevel(program, type));
185
+ }
186
+
187
+ /**
188
+ * @param {any} node
189
+ * @param {string} key
190
+ * @param {() => readonly any[]} find
191
+ * @returns {readonly any[]}
192
+ */
193
+ function cachedNodes(node, key, find) {
164
194
  if (node == null || typeof node !== 'object') return [];
165
195
  let byType = nodesByTree.get(node);
166
196
  if (!byType) {
167
197
  byType = new Map();
168
198
  nodesByTree.set(node, byType);
169
199
  }
170
- let found = byType.get(type);
171
- if (!found) {
172
- found = collectNodesOfType(node, type, []);
173
- byType.set(type, found);
174
- }
200
+ const cached = byType.get(key);
201
+ if (cached) return cached;
202
+ const found = find();
203
+ byType.set(key, found);
175
204
  return found;
176
205
  }
177
206
 
@@ -198,8 +227,14 @@ function collectNodesOfType(node, type, found) {
198
227
  return found;
199
228
  }
200
229
 
201
- /** @param {unknown} specifier @param {string} fromFile */
202
- function resolveLocalModule(specifier, fromFile) {
230
+ /**
231
+ * The file a relative import names: the path itself, then each module
232
+ * extension, then a folder's index. Null for a bare specifier or no file.
233
+ * @param {unknown} specifier
234
+ * @param {string} fromFile absolute path of the importing file
235
+ * @returns {string|null}
236
+ */
237
+ export function resolveLocalModule(specifier, fromFile) {
203
238
  if (typeof specifier !== 'string' || !specifier.startsWith('.')) return null;
204
239
  const base = path.resolve(path.dirname(fromFile), specifier);
205
240
  const candidates = [
@@ -309,7 +344,7 @@ export function moduleParseFailure(file) {
309
344
  };
310
345
  }
311
346
  for (const type of ['ExportNamedDeclaration', 'ExportAllDeclaration']) {
312
- for (const node of nodesOfType(ast.program, type)) {
347
+ for (const node of moduleDeclarations(ast.program, type)) {
313
348
  const specifier = node.source?.value;
314
349
  if (typeof specifier !== 'string' || !specifier.startsWith('.')) {
315
350
  continue;
@@ -338,7 +373,7 @@ export function unfollowedReexports(file) {
338
373
  /** @type {Set<string>} */
339
374
  const missing = new Set();
340
375
  for (const type of ['ExportNamedDeclaration', 'ExportAllDeclaration']) {
341
- for (const node of nodesOfType(ast.program, type)) {
376
+ for (const node of moduleDeclarations(ast.program, type)) {
342
377
  const specifier = node.source?.value;
343
378
  if (typeof specifier !== 'string' || node.exportKind === 'type') continue;
344
379
  if (!resolveModuleOrPackage(specifier, file)) missing.add(specifier);
@@ -347,17 +382,43 @@ export function unfollowedReexports(file) {
347
382
  return [...missing].sort();
348
383
  }
349
384
 
350
- /** @param {any} declaration @param {string} exportName */
351
- function declarationExports(declaration, exportName) {
352
- if (!declaration || declaration.declare === true) return false;
353
- if (['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)) {
354
- return declaration.id?.name === exportName;
385
+ /** Declarations that name a type, which a type-aware read also follows. */
386
+ const TYPE_DECLARATIONS = [
387
+ 'TSInterfaceDeclaration',
388
+ 'TSTypeAliasDeclaration',
389
+ 'TSEnumDeclaration',
390
+ 'TSModuleDeclaration',
391
+ 'TSDeclareFunction',
392
+ ];
393
+
394
+ /**
395
+ * @param {any} declaration
396
+ * @param {string} exportName
397
+ * @param {boolean} [types] also count type declarations and `declare` ones
398
+ */
399
+ function declarationExports(declaration, exportName, types = false) {
400
+ return declaredNames(declaration, types).includes(exportName);
401
+ }
402
+
403
+ /**
404
+ * The names an exported declaration binds.
405
+ * @param {any} declaration
406
+ * @param {boolean} [types] also count type declarations and `declare` ones
407
+ * @returns {string[]}
408
+ */
409
+ function declaredNames(declaration, types = false) {
410
+ if (!declaration || (declaration.declare === true && !types)) return [];
411
+ if (
412
+ ['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type) ||
413
+ (types && TYPE_DECLARATIONS.includes(declaration.type))
414
+ ) {
415
+ const name = declaration.id?.name;
416
+ return typeof name === 'string' ? [name] : [];
355
417
  }
356
- if (declaration.type !== 'VariableDeclaration') return false;
357
- return declaration.declarations.some(
358
- (/** @type {any} */ item) =>
359
- item.id?.type === 'Identifier' && item.id.name === exportName,
360
- );
418
+ if (declaration.type !== 'VariableDeclaration') return [];
419
+ return declaration.declarations
420
+ .filter((/** @type {any} */ item) => item.id?.type === 'Identifier')
421
+ .map((/** @type {any} */ item) => item.id.name);
361
422
  }
362
423
 
363
424
  /** @param {any} declaration */
@@ -574,6 +635,140 @@ export function moduleExportNames(file) {
574
635
  return [...names].sort();
575
636
  }
576
637
 
638
+ /**
639
+ * Every export of a module with where it is declared, in one pass: the same
640
+ * answers as the whole-tree {@link exportOrigin} for each name, read once per
641
+ * module.
642
+ * Pass one `memo` to calls that read the same package, so a module behind
643
+ * many barrels is read once; a memo keeps value and type reads apart, and
644
+ * nothing is kept between memos. One difference follows ESM where
645
+ * {@link exportOrigin} does not: a name re-exported by name from a
646
+ * module that cannot be followed is absent, never filled from `export *`.
647
+ * @param {string} file
648
+ * @param {{types?: boolean, memo?: Map<string, Map<string, {file: string, name: string}>>}} [options]
649
+ * @returns {Map<string, {file: string, name: string}>}
650
+ */
651
+ export function moduleExportOrigins(
652
+ file,
653
+ {types = false, memo = new Map()} = {},
654
+ ) {
655
+ return exportOriginsOf(file, {types, memo, reading: new Map()}).origins;
656
+ }
657
+
658
+ /**
659
+ * @typedef {object} OriginsRead
660
+ * @property {boolean} types
661
+ * @property {Map<string, Map<string, {file: string, name: string}>>} memo
662
+ * finished maps, keyed by read mode and file
663
+ * @property {Map<string, {depth: number, origins: Map<string, {file: string, name: string}>}>} reading
664
+ * the modules being read now, by memo key
665
+ */
666
+
667
+ /**
668
+ * One module's export map, and the shallowest module still being read that
669
+ * it depends on (`low`). A map that depends on a module above it in an
670
+ * `export *` cycle is incomplete until that module finishes, so only a map
671
+ * whose `low` is its own depth goes in the memo.
672
+ * @param {string} file
673
+ * @param {OriginsRead} read
674
+ * @returns {{origins: Map<string, {file: string, name: string}>, low: number}}
675
+ */
676
+ function exportOriginsOf(file, read) {
677
+ const key = `${read.types ? 'type' : 'value'}\0${file}`;
678
+ const known = read.memo.get(key);
679
+ if (known) return {origins: known, low: Infinity};
680
+ const open = read.reading.get(key);
681
+ // A module reached again through a cycle reads as what is known so far.
682
+ if (open) return {origins: open.origins, low: open.depth};
683
+ const depth = read.reading.size;
684
+ /** @type {Map<string, {file: string, name: string}>} */
685
+ const origins = new Map();
686
+ let low = Infinity;
687
+ read.reading.set(key, {depth, origins});
688
+ /** @param {string} target */
689
+ const originsOf = target => {
690
+ const result = exportOriginsOf(target, read);
691
+ low = Math.min(low, result.low);
692
+ return result.origins;
693
+ };
694
+ try {
695
+ let ast;
696
+ try {
697
+ if (!fs.statSync(file).isFile()) return {origins, low};
698
+ ast = parseModule(file);
699
+ } catch {
700
+ return {origins, low};
701
+ }
702
+ const {types} = read;
703
+ // A name the module exports by name shadows every `export *`, even when
704
+ // its binding cannot be followed.
705
+ const named = new Set();
706
+ const {declarations, specifiers} = namedExportIndex(ast.program, types);
707
+ for (const node of declarations) {
708
+ for (const name of declaredNames(node.declaration, types)) {
709
+ named.add(name);
710
+ if (!origins.has(name)) origins.set(name, {file, name});
711
+ }
712
+ }
713
+ for (const [exportName, entries] of specifiers) {
714
+ named.add(exportName);
715
+ if (origins.has(exportName)) continue;
716
+ for (const {node, specifier} of entries) {
717
+ const local =
718
+ specifier.local?.name ?? specifier.local?.value ?? exportName;
719
+ let origin = null;
720
+ if (node.source) {
721
+ const target = resolveModuleOrPackage(node.source.value, file);
722
+ if (target) {
723
+ const result = exportOriginsOf(target, read);
724
+ low = Math.min(low, result.low);
725
+ // A map that depends on a module still being read is partial, so
726
+ // a name missing from it is followed on its own.
727
+ origin =
728
+ result.origins.get(local) ??
729
+ (result.low < Infinity
730
+ ? exportOrigin(target, local, new Set(), nodesOfType, types)
731
+ : null);
732
+ }
733
+ } else {
734
+ origin = bindingOrigin(ast, file, local, new Set(), types);
735
+ }
736
+ if (origin) {
737
+ origins.set(exportName, origin);
738
+ break;
739
+ }
740
+ if (!node.source) break;
741
+ }
742
+ }
743
+ for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
744
+ named.add('default');
745
+ if (origins.has('default')) break;
746
+ const declaration = node.declaration;
747
+ if (!types && !runtimeDefault(declaration)) continue;
748
+ const origin =
749
+ declaration.type === 'Identifier'
750
+ ? bindingOrigin(ast, file, declaration.name, new Set(), types)
751
+ : {file, name: 'default'};
752
+ if (origin) origins.set('default', origin);
753
+ break;
754
+ }
755
+ for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
756
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
757
+ const target = resolveModuleOrPackage(node.source?.value, file);
758
+ if (!target) continue;
759
+ for (const [name, origin] of originsOf(target)) {
760
+ if (name !== 'default' && !named.has(name) && !origins.has(name)) {
761
+ origins.set(name, origin);
762
+ }
763
+ }
764
+ }
765
+ return {origins, low};
766
+ } finally {
767
+ read.reading.delete(key);
768
+ if (low >= depth) read.memo.set(key, origins);
769
+ }
770
+ }
771
+
577
772
  /**
578
773
  * @typedef {{verdict: 'exports'} | {verdict: 'lacks'} | {verdict: 'unknown', reason: string}} ExportVerdict
579
774
  */
@@ -922,26 +1117,40 @@ export function staticExportObject(file, exportNames) {
922
1117
  /**
923
1118
  * A module's runtime named exports, indexed once per parsed tree: the
924
1119
  * export declarations that declare something, and each export specifier by
925
- * the name it exports, in source order.
926
- * @type {WeakMap<object, {declarations: any[], specifiers: Map<string, Array<{node: any, specifier: any}>>}>}
1120
+ * the name it exports, in source order. Each reader of export declarations
1121
+ * has its own index, since the readers can find different declarations.
1122
+ * @type {WeakMap<object, Map<Function, {declarations: any[], specifiers: Map<string, Array<{node: any, specifier: any}>>}>>}
927
1123
  */
928
1124
  const namedExportIndexes = new WeakMap();
1125
+ /** The same index with type-only exports included. */
1126
+ const typedExportIndexes = new WeakMap();
929
1127
 
930
- /** @param {any} program */
931
- function namedExportIndex(program) {
932
- const cached = namedExportIndexes.get(program);
1128
+ /**
1129
+ * @param {any} program
1130
+ * @param {boolean} [types] include type-only exports
1131
+ * @param {(node: any, type: string) => readonly any[]} [read] how the
1132
+ * module's export declarations are read
1133
+ */
1134
+ function namedExportIndex(program, types = false, read = nodesOfType) {
1135
+ const indexes = types ? typedExportIndexes : namedExportIndexes;
1136
+ let byReader = indexes.get(program);
1137
+ if (!byReader) {
1138
+ byReader = new Map();
1139
+ indexes.set(program, byReader);
1140
+ }
1141
+ const cached = byReader.get(read);
933
1142
  if (cached) return cached;
934
1143
  /** @type {any[]} */
935
1144
  const declarations = [];
936
1145
  /** @type {Map<string, Array<{node: any, specifier: any}>>} */
937
1146
  const specifiers = new Map();
938
- for (const node of nodesOfType(program, 'ExportNamedDeclaration')) {
939
- if (node.exportKind === 'type') continue;
1147
+ for (const node of read(program, 'ExportNamedDeclaration')) {
1148
+ if (node.exportKind === 'type' && !types) continue;
940
1149
  if (node.declaration) declarations.push(node);
941
1150
  for (const specifier of node.specifiers ?? []) {
942
1151
  if (
943
1152
  specifier.type !== 'ExportSpecifier' ||
944
- specifier.exportKind === 'type'
1153
+ (specifier.exportKind === 'type' && !types)
945
1154
  ) {
946
1155
  continue;
947
1156
  }
@@ -952,7 +1161,7 @@ function namedExportIndex(program) {
952
1161
  }
953
1162
  }
954
1163
  const index = {declarations, specifiers};
955
- namedExportIndexes.set(program, index);
1164
+ byReader.set(read, index);
956
1165
  return index;
957
1166
  }
958
1167
 
@@ -961,12 +1170,34 @@ function namedExportIndex(program) {
961
1170
  * has there, without executing anything: local re-exports, renames, and
962
1171
  * imported bindings a module exports again are followed. Two exports are the
963
1172
  * same value when their origins are equal. Null when it cannot be proved.
1173
+ * With `types`, type-only exports and type declarations are followed too.
964
1174
  * @param {string} file
965
1175
  * @param {string} exportName
966
1176
  * @param {Set<string>} [seen]
1177
+ * @param {{types?: boolean}} [options]
967
1178
  * @returns {{file: string, name: string} | null}
968
1179
  */
969
- export function moduleExportOrigin(file, exportName, seen = new Set()) {
1180
+ export function moduleExportOrigin(
1181
+ file,
1182
+ exportName,
1183
+ seen = new Set(),
1184
+ {types = false} = {},
1185
+ ) {
1186
+ return exportOrigin(file, exportName, seen, moduleDeclarations, types);
1187
+ }
1188
+
1189
+ /**
1190
+ * {@link moduleExportOrigin} with the reader of a module's export
1191
+ * declarations: {@link moduleDeclarations} for icon-set libraries, or
1192
+ * {@link nodesOfType} for every other caller.
1193
+ * @param {string} file
1194
+ * @param {string} exportName
1195
+ * @param {Set<string>} seen
1196
+ * @param {(node: any, type: string) => readonly any[]} read
1197
+ * @param {boolean} [types] also follow type-only exports and declarations
1198
+ * @returns {{file: string, name: string} | null}
1199
+ */
1200
+ function exportOrigin(file, exportName, seen, read, types = false) {
970
1201
  const identity = `${file}\0${exportName}`;
971
1202
  if (seen.has(identity)) return null;
972
1203
  seen.add(identity);
@@ -977,9 +1208,9 @@ export function moduleExportOrigin(file, exportName, seen = new Set()) {
977
1208
  } catch {
978
1209
  return null;
979
1210
  }
980
- const {declarations, specifiers} = namedExportIndex(ast.program);
1211
+ const {declarations, specifiers} = namedExportIndex(ast.program, types, read);
981
1212
  for (const node of declarations) {
982
- if (declarationExports(node.declaration, exportName)) {
1213
+ if (declarationExports(node.declaration, exportName, types)) {
983
1214
  return {file, name: exportName};
984
1215
  }
985
1216
  }
@@ -987,26 +1218,30 @@ export function moduleExportOrigin(file, exportName, seen = new Set()) {
987
1218
  const local = specifier.local?.name ?? specifier.local?.value ?? exportName;
988
1219
  if (node.source) {
989
1220
  const target = resolveModuleOrPackage(node.source.value, file);
990
- const origin = target ? moduleExportOrigin(target, local, seen) : null;
1221
+ const origin = target
1222
+ ? exportOrigin(target, local, seen, read, types)
1223
+ : null;
991
1224
  if (origin) return origin;
992
1225
  continue;
993
1226
  }
994
- return bindingOrigin(ast, file, local, seen);
1227
+ return bindingOrigin(ast, file, local, seen, types, read);
995
1228
  }
996
1229
  if (exportName === 'default') {
997
- for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
1230
+ for (const node of read(ast.program, 'ExportDefaultDeclaration')) {
998
1231
  const declaration = node.declaration;
999
- if (!runtimeDefault(declaration)) continue;
1232
+ if (!types && !runtimeDefault(declaration)) continue;
1000
1233
  if (declaration.type === 'Identifier') {
1001
- return bindingOrigin(ast, file, declaration.name, seen);
1234
+ return bindingOrigin(ast, file, declaration.name, seen, types, read);
1002
1235
  }
1003
1236
  return {file, name: 'default'};
1004
1237
  }
1005
1238
  }
1006
- for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
1007
- if (node.exportKind === 'type' || node.exported) continue;
1239
+ for (const node of read(ast.program, 'ExportAllDeclaration')) {
1240
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
1008
1241
  const target = resolveModuleOrPackage(node.source?.value, file);
1009
- const origin = target ? moduleExportOrigin(target, exportName, seen) : null;
1242
+ const origin = target
1243
+ ? exportOrigin(target, exportName, seen, read, types)
1244
+ : null;
1010
1245
  if (origin) return origin;
1011
1246
  }
1012
1247
  return null;
@@ -1061,7 +1296,10 @@ function originGapReason(file, exportName, seen = new Set()) {
1061
1296
  }
1062
1297
  /** @type {string | null} */
1063
1298
  let local = null;
1064
- for (const node of nodesOfType(ast.program, 'ExportNamedDeclaration')) {
1299
+ for (const node of moduleDeclarations(
1300
+ ast.program,
1301
+ 'ExportNamedDeclaration',
1302
+ )) {
1065
1303
  for (const specifier of node.specifiers ?? []) {
1066
1304
  const exported = specifier.exported?.name ?? specifier.exported?.value;
1067
1305
  if (exported !== exportName) continue;
@@ -1082,7 +1320,10 @@ function originGapReason(file, exportName, seen = new Set()) {
1082
1320
  }
1083
1321
  }
1084
1322
  if (exportName === 'default') {
1085
- for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
1323
+ for (const node of moduleDeclarations(
1324
+ ast.program,
1325
+ 'ExportDefaultDeclaration',
1326
+ )) {
1086
1327
  if (node.declaration?.type === 'Identifier') {
1087
1328
  local = node.declaration.name;
1088
1329
  }
@@ -1090,7 +1331,10 @@ function originGapReason(file, exportName, seen = new Set()) {
1090
1331
  }
1091
1332
  if (!local) {
1092
1333
  // Bound behind `export *`: the module it comes from says why.
1093
- for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
1334
+ for (const node of moduleDeclarations(
1335
+ ast.program,
1336
+ 'ExportAllDeclaration',
1337
+ )) {
1094
1338
  if (node.exportKind === 'type' || node.exported) continue;
1095
1339
  const target = resolveModuleOrPackage(node.source?.value, file);
1096
1340
  if (
@@ -1128,12 +1372,18 @@ function originGapReason(file, exportName, seen = new Set()) {
1128
1372
  * named exports and, through `export *` from local files and installed
1129
1373
  * packages, theirs. Unlike {@link moduleExportNames}, it never gives up on an
1130
1374
  * `export *`: what it cannot read is left out. Type-only
1131
- * exports and `default` are left out. Sorted.
1375
+ * exports are left out unless `types` asks for them; `default` always is.
1376
+ * Sorted.
1132
1377
  * @param {string} file
1133
1378
  * @param {Set<string>} [seen]
1379
+ * @param {{types?: boolean}} [options]
1134
1380
  * @returns {string[]}
1135
1381
  */
1136
- export function followedExportNames(file, seen = new Set()) {
1382
+ export function followedExportNames(
1383
+ file,
1384
+ seen = new Set(),
1385
+ {types = false} = {},
1386
+ ) {
1137
1387
  if (seen.has(file)) return [];
1138
1388
  seen.add(file);
1139
1389
  let ast;
@@ -1145,12 +1395,18 @@ export function followedExportNames(file, seen = new Set()) {
1145
1395
  }
1146
1396
  /** @type {Set<string>} */
1147
1397
  const names = new Set();
1148
- for (const node of nodesOfType(ast.program, 'ExportNamedDeclaration')) {
1149
- if (node.exportKind === 'type') continue;
1398
+ for (const node of moduleDeclarations(
1399
+ ast.program,
1400
+ 'ExportNamedDeclaration',
1401
+ )) {
1402
+ if (node.exportKind === 'type' && !types) continue;
1150
1403
  const declaration = node.declaration;
1151
- if (declaration && declaration.declare !== true) {
1404
+ if (declaration && (declaration.declare !== true || types)) {
1152
1405
  if (
1153
- ['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)
1406
+ ['FunctionDeclaration', 'ClassDeclaration'].includes(
1407
+ declaration.type,
1408
+ ) ||
1409
+ (types && TYPE_DECLARATIONS.includes(declaration.type))
1154
1410
  ) {
1155
1411
  if (declaration.id?.name) names.add(declaration.id.name);
1156
1412
  } else if (declaration.type === 'VariableDeclaration') {
@@ -1162,7 +1418,7 @@ export function followedExportNames(file, seen = new Set()) {
1162
1418
  for (const specifier of node.specifiers ?? []) {
1163
1419
  if (
1164
1420
  specifier.type !== 'ExportSpecifier' ||
1165
- specifier.exportKind === 'type'
1421
+ (specifier.exportKind === 'type' && !types)
1166
1422
  ) {
1167
1423
  continue;
1168
1424
  }
@@ -1172,11 +1428,13 @@ export function followedExportNames(file, seen = new Set()) {
1172
1428
  }
1173
1429
  }
1174
1430
  }
1175
- for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
1176
- if (node.exportKind === 'type' || node.exported) continue;
1431
+ for (const node of moduleDeclarations(ast.program, 'ExportAllDeclaration')) {
1432
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
1177
1433
  const target = resolveModuleOrPackage(node.source?.value, file);
1178
1434
  if (target) {
1179
- for (const name of followedExportNames(target, seen)) names.add(name);
1435
+ for (const name of followedExportNames(target, seen, {types})) {
1436
+ names.add(name);
1437
+ }
1180
1438
  }
1181
1439
  }
1182
1440
  return [...names].sort();
@@ -1232,7 +1490,7 @@ export function exportValueKind(file, exportName) {
1232
1490
  return 'unknown';
1233
1491
  };
1234
1492
  if (origin.name === 'default') {
1235
- const [node] = nodesOfType(ast.program, 'ExportDefaultDeclaration');
1493
+ const [node] = moduleDeclarations(ast.program, 'ExportDefaultDeclaration');
1236
1494
  return node ? kindOf(node.declaration) : 'unknown';
1237
1495
  }
1238
1496
  for (const statement of ast.program.body) {
@@ -1289,7 +1547,7 @@ export function exportScalarType(file, exportName) {
1289
1547
  return null;
1290
1548
  };
1291
1549
  if (origin.name === 'default') {
1292
- const [node] = nodesOfType(ast.program, 'ExportDefaultDeclaration');
1550
+ const [node] = moduleDeclarations(ast.program, 'ExportDefaultDeclaration');
1293
1551
  return node ? typeOf(node.declaration) : null;
1294
1552
  }
1295
1553
  for (const statement of ast.program.body) {
@@ -1317,11 +1575,17 @@ export function exportScalarType(file, exportName) {
1317
1575
  * then have the same final origin. Null when an alias cannot be followed (to
1318
1576
  * a default or namespace import, a member such as `Icons.X`, or an import
1319
1577
  * that does not resolve), so a caller leaves the comparison unchecked.
1578
+ * `unwrap`, when given, names a value a declaration stands for besides a
1579
+ * plain alias (a theme made by `defineTheme({extends: base})` stands for
1580
+ * `base`): it receives the declaration's initializer and returns the
1581
+ * expression to follow, or null for none. A followed expression that is not
1582
+ * an identifier makes the origin unknown.
1320
1583
  * @param {{file: string, name: string}} origin
1321
1584
  * @param {Set<string>} [seen]
1585
+ * @param {(init: any) => any} [unwrap]
1322
1586
  * @returns {{file: string, name: string} | null}
1323
1587
  */
1324
- export function aliasedOrigin(origin, seen = new Set()) {
1588
+ export function aliasedOrigin(origin, seen = new Set(), unwrap) {
1325
1589
  const identity = `${origin.file}\0${origin.name}`;
1326
1590
  if (seen.has(identity)) return null;
1327
1591
  seen.add(identity);
@@ -1344,16 +1608,88 @@ export function aliasedOrigin(origin, seen = new Set()) {
1344
1608
  ) {
1345
1609
  continue;
1346
1610
  }
1347
- const init = withoutTypeWrappers(declarator.init);
1611
+ const declared = withoutTypeWrappers(declarator.init);
1612
+ const followed = declared && unwrap ? unwrap(declared) : null;
1613
+ const init = followed ? withoutTypeWrappers(followed) : declared;
1348
1614
  if (init?.type === 'MemberExpression') return null;
1349
- if (init?.type !== 'Identifier') return origin;
1615
+ if (init?.type !== 'Identifier') return followed ? null : origin;
1350
1616
  const next = bindingOrigin(ast, origin.file, init.name, new Set());
1351
- return next ? aliasedOrigin(next, seen) : null;
1617
+ return next ? aliasedOrigin(next, seen, unwrap) : null;
1352
1618
  }
1353
1619
  }
1354
1620
  return origin;
1355
1621
  }
1356
1622
 
1623
+ /**
1624
+ * Where the value each `<Name prop={value}>` element of a module passes is
1625
+ * declared, one entry per element, read without running anything. `Name` is
1626
+ * a runtime import of `name` from one of `sources` (renames included). The
1627
+ * value is followed with {@link aliasedOrigin} (passing `unwrap`) from the
1628
+ * module-scope binding it names, through local files and installed packages.
1629
+ * An entry is null when the value is not an identifier or its origin cannot
1630
+ * be proved (a parameter or an import that does not resolve gives the
1631
+ * module's own name, and a member or a default import gives null). An element
1632
+ * without `prop` gives no entry.
1633
+ * @param {string} file
1634
+ * @param {{sources: ReadonlySet<string>, name: string, prop: string, unwrap?: (init: any) => any}} element
1635
+ * @returns {Array<{file: string, name: string} | null>}
1636
+ */
1637
+ export function elementPropOrigins(file, {sources, name, prop, unwrap}) {
1638
+ let ast;
1639
+ try {
1640
+ ast = parseModule(file);
1641
+ } catch {
1642
+ return [];
1643
+ }
1644
+ /** @type {Set<string>} */
1645
+ const locals = new Set();
1646
+ for (const node of ast.program.body) {
1647
+ if (
1648
+ node.type !== 'ImportDeclaration' ||
1649
+ node.importKind === 'type' ||
1650
+ !sources.has(node.source?.value)
1651
+ ) {
1652
+ continue;
1653
+ }
1654
+ for (const specifier of node.specifiers ?? []) {
1655
+ if (
1656
+ specifier.type === 'ImportSpecifier' &&
1657
+ specifier.importKind !== 'type' &&
1658
+ (specifier.imported?.name ?? specifier.imported?.value) === name
1659
+ ) {
1660
+ locals.add(specifier.local.name);
1661
+ }
1662
+ }
1663
+ }
1664
+ if (locals.size === 0) return [];
1665
+ /** @type {Array<{file: string, name: string} | null>} */
1666
+ const origins = [];
1667
+ for (const element of nodesOfType(ast.program, 'JSXOpeningElement')) {
1668
+ if (
1669
+ element.name?.type !== 'JSXIdentifier' ||
1670
+ !locals.has(element.name.name)
1671
+ ) {
1672
+ continue;
1673
+ }
1674
+ const attribute = (element.attributes ?? []).find(
1675
+ (/** @type {any} */ item) =>
1676
+ item.type === 'JSXAttribute' && item.name?.name === prop,
1677
+ );
1678
+ if (!attribute) continue;
1679
+ const value =
1680
+ attribute.value?.type === 'JSXExpressionContainer'
1681
+ ? withoutTypeWrappers(attribute.value.expression)
1682
+ : null;
1683
+ if (value?.type !== 'Identifier') {
1684
+ origins.push(null);
1685
+ continue;
1686
+ }
1687
+ const binding = bindingOrigin(ast, file, value.name, new Set());
1688
+ origins.push(binding ? aliasedOrigin(binding, new Set(), unwrap) : null);
1689
+ }
1690
+ return origins;
1691
+ }
1692
+
1357
1693
  /**
1358
1694
  * Where a top-level binding of a parsed module comes from: an import from a
1359
1695
  * local module is followed to its origin; anything else is declared here.
@@ -1361,11 +1697,24 @@ export function aliasedOrigin(origin, seen = new Set()) {
1361
1697
  * @param {string} file
1362
1698
  * @param {string} local
1363
1699
  * @param {Set<string>} seen
1700
+ * @param {boolean} [types] also follow `import type`
1701
+ * @param {(node: any, type: string) => readonly any[]} [read] how an
1702
+ * imported module's export declarations are read
1364
1703
  * @returns {{file: string, name: string} | null}
1365
1704
  */
1366
- function bindingOrigin(ast, file, local, seen) {
1705
+ function bindingOrigin(
1706
+ ast,
1707
+ file,
1708
+ local,
1709
+ seen,
1710
+ types = false,
1711
+ read = nodesOfType,
1712
+ ) {
1367
1713
  for (const node of ast.program.body) {
1368
- if (node.type !== 'ImportDeclaration' || node.importKind === 'type') {
1714
+ if (
1715
+ node.type !== 'ImportDeclaration' ||
1716
+ (node.importKind === 'type' && !types)
1717
+ ) {
1369
1718
  continue;
1370
1719
  }
1371
1720
  for (const specifier of node.specifiers ?? []) {
@@ -1374,7 +1723,7 @@ function bindingOrigin(ast, file, local, seen) {
1374
1723
  const imported =
1375
1724
  specifier.imported?.name ?? specifier.imported?.value ?? local;
1376
1725
  const target = resolveModuleOrPackage(node.source.value, file);
1377
- return target ? moduleExportOrigin(target, imported, seen) : null;
1726
+ return target ? exportOrigin(target, imported, seen, read, types) : null;
1378
1727
  }
1379
1728
  }
1380
1729
  return {file, name: local};