@astryxdesign/cli 0.7.14-canary.g7deca33 → 0.7.14-canary.gd9d7b10

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 (73) hide show
  1. package/api/component/_adapter.d.mts +15 -0
  2. package/api/component/_adapter.mjs +76 -0
  3. package/api/component/component.mjs +8 -1
  4. package/api/search/_named-keywords.d.mts +31 -0
  5. package/api/search/_named-keywords.mjs +177 -0
  6. package/api/search/search-index.mjs +8 -1
  7. package/api/search/search.d.mts +6 -1
  8. package/api/search/search.mjs +49 -8
  9. package/api/theme/palette/generate/color.d.mts +2 -0
  10. package/api/theme/palette/generate/color.mjs +1 -1
  11. package/api/theme-edit/_adapter.d.mts +36 -2
  12. package/api/theme-edit/_adapter.mjs +340 -12
  13. package/api/theme-edit/_check.d.mts +28 -25
  14. package/api/theme-edit/_check.mjs +818 -539
  15. package/api/theme-edit/_color.d.mts +53 -4
  16. package/api/theme-edit/_color.mjs +406 -79
  17. package/api/theme-edit/_compiler.d.mts +13 -5
  18. package/api/theme-edit/_compiler.mjs +81 -56
  19. package/api/theme-edit/_context.d.mts +15 -5
  20. package/api/theme-edit/_context.mjs +40 -6
  21. package/api/theme-edit/_edit.mjs +545 -75
  22. package/api/theme-edit/_how-commands.d.mts +91 -0
  23. package/api/theme-edit/_how-commands.mjs +269 -0
  24. package/api/theme-edit/_how-question.d.mts +57 -0
  25. package/api/theme-edit/_how-question.mjs +2574 -0
  26. package/api/theme-edit/_how.d.mts +25 -17
  27. package/api/theme-edit/_how.mjs +727 -305
  28. package/api/theme-edit/_palette.d.mts +143 -19
  29. package/api/theme-edit/_palette.mjs +1367 -381
  30. package/api/theme-edit/_parts.mjs +61 -5
  31. package/api/theme-edit/_png.d.mts +18 -6
  32. package/api/theme-edit/_png.mjs +135 -25
  33. package/api/theme-edit/_preview-app.d.mts +26 -7
  34. package/api/theme-edit/_preview-app.mjs +1655 -336
  35. package/api/theme-edit/_preview.d.mts +7 -3
  36. package/api/theme-edit/_preview.mjs +41 -20
  37. package/api/theme-edit/_settings.d.mts +136 -8
  38. package/api/theme-edit/_settings.mjs +819 -94
  39. package/api/theme-edit/_tables.d.mts +0 -12
  40. package/api/theme-edit/_tables.mjs +25 -98
  41. package/api/theme-edit/theme-edit.type.d.mts +37 -20
  42. package/api/theme-edit/theme-edit.type.mjs +28 -17
  43. package/api/theme-edit/themeEditHow.doc.mjs +13 -3
  44. package/api/theme-edit/themeEditNew.doc.mjs +8 -2
  45. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +18 -5
  46. package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -9
  47. package/api/theme-edit/themeEditPreviewList.doc.mjs +11 -2
  48. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +29 -3
  49. package/api/theme-edit/themeEditSet.doc.mjs +9 -3
  50. package/api/theme-edit/themeEditShow.doc.mjs +7 -2
  51. package/api/theme-edit/themeEditUndo.doc.mjs +8 -3
  52. package/assets/preview-app/gitignore +3 -0
  53. package/assets/templates/components.generated.json +1 -0
  54. package/clients/cli/commands/experimental/theme.mjs +290 -35
  55. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +15 -6
  56. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -1
  57. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  58. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  59. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +3 -3
  60. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
  61. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
  62. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
  63. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  64. package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
  65. package/clients/cli/commands/experimental-theme.doc.mjs +2 -2
  66. package/clients/cli/commands/theme.mjs +34 -32
  67. package/foundation/discovery/template-adapter.d.mts +19 -1
  68. package/foundation/discovery/template-adapter.mjs +58 -1
  69. package/foundation/response/error-codes.d.mts +2 -1
  70. package/foundation/response/error-codes.doc.mjs +7 -1
  71. package/foundation/response/error-codes.mjs +6 -1
  72. package/foundation/response/response-types.doc.mjs +1 -1
  73. package/package.json +6 -6
@@ -276,6 +276,21 @@ export function linkComponentResponse<R extends {
276
276
  package?: string;
277
277
  data?: any;
278
278
  }>(response: R, cwd: string): Promise<R>;
279
+ /**
280
+ * When `error` is the unknown-component error for a name that is an example
281
+ * block, returns the same error with the commands that show the block in its
282
+ * message: `astryx template <Block>`, and `astryx component <Parent> --blocks`
283
+ * for a component whose `--blocks` listing holds the block. The code and the
284
+ * matcher's suggestions stay. Returns `error` unchanged otherwise.
285
+ * @param {unknown} error
286
+ * @param {string} dirName
287
+ * @param {{coreDir: string, cwd: string}} context
288
+ * @returns {Promise<unknown>}
289
+ */
290
+ export function withExampleBlockPointer(error: unknown, dirName: string, { coreDir, cwd }: {
291
+ coreDir: string;
292
+ cwd: string;
293
+ }): Promise<unknown>;
279
294
  /**
280
295
  * Internal ambiguity marker. Single-component callers still receive the same
281
296
  * AstryxError code, message, and suggestions; batch callers can additionally
@@ -49,6 +49,10 @@ import {
49
49
  synonymMatches,
50
50
  } from '../../foundation/text/suggest-order.mjs';
51
51
  import {AstryxError, coreDirOrThrow} from '../error.mjs';
52
+ import {
53
+ discoverAll,
54
+ findRelatedBlocks,
55
+ } from '../../foundation/discovery/template-adapter.mjs';
52
56
  import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
53
57
  import {
54
58
  componentLinkProvider,
@@ -827,3 +831,75 @@ export async function linkComponentResponse(response, cwd) {
827
831
  }
828
832
  return {...response, data: {...response.data, components}};
829
833
  }
834
+
835
+ /**
836
+ * When `error` is the unknown-component error for a name that is an example
837
+ * block, returns the same error with the commands that show the block in its
838
+ * message: `astryx template <Block>`, and `astryx component <Parent> --blocks`
839
+ * for a component whose `--blocks` listing holds the block. The code and the
840
+ * matcher's suggestions stay. Returns `error` unchanged otherwise.
841
+ * @param {unknown} error
842
+ * @param {string} dirName
843
+ * @param {{coreDir: string, cwd: string}} context
844
+ * @returns {Promise<unknown>}
845
+ */
846
+ export async function withExampleBlockPointer(error, dirName, {coreDir, cwd}) {
847
+ if (
848
+ !(error instanceof AstryxError) ||
849
+ error.code !== ERROR_CODES.ERR_UNKNOWN_COMPONENT
850
+ ) {
851
+ return error;
852
+ }
853
+ // A block doc that fails to load must not replace the unknown-component
854
+ // error and its suggestions: the pointer is extra help, so a failed lookup
855
+ // keeps the original error.
856
+ try {
857
+ const typed = dirName.toLowerCase();
858
+ const block = (await discoverAll(cwd)).find(
859
+ template =>
860
+ template.type === 'block' && template.dirName.toLowerCase() === typed,
861
+ );
862
+ if (block == null) {
863
+ return error;
864
+ }
865
+ const parent = await listingParent(block, coreDir, cwd);
866
+ const listing = parent
867
+ ? `, and astryx component ${parent} --blocks lists it`
868
+ : '';
869
+ return new AstryxError(
870
+ `${error.message}. It is an example block: astryx template ${block.dirName} prints its source${listing}.`,
871
+ error.suggestions,
872
+ ERROR_CODES.ERR_UNKNOWN_COMPONENT,
873
+ );
874
+ } catch {
875
+ return error;
876
+ }
877
+ }
878
+
879
+ /**
880
+ * A component whose `component <Name> --blocks` listing holds `block`: one of
881
+ * the components the block uses, its own folder's component first, that
882
+ * resolves as a component and whose related blocks include the block.
883
+ * @param {{dirName: string, category?: string, componentsUsed?: string[]}} block
884
+ * @param {string} coreDir
885
+ * @param {string} cwd
886
+ * @returns {Promise<string | null>}
887
+ */
888
+ async function listingParent(block, coreDir, cwd) {
889
+ const used = block.componentsUsed ?? [];
890
+ const folder = path.basename(block.category ?? '');
891
+ const candidates = [
892
+ ...used.filter(name => name === folder),
893
+ ...used.filter(name => name !== folder),
894
+ ];
895
+ for (const name of candidates) {
896
+ if (findComponentReadme(coreDir, name) == null) {
897
+ continue;
898
+ }
899
+ const related = await findRelatedBlocks(name, cwd);
900
+ if (related.some(entry => entry.dirName === block.dirName)) {
901
+ return name;
902
+ }
903
+ }
904
+ return null;
905
+ }
@@ -31,6 +31,7 @@ import {
31
31
  legacyExternalKeeps,
32
32
  resolveCoreSourcePath,
33
33
  resolveUnscopedDoc,
34
+ withExampleBlockPointer,
34
35
  loadComponentDoc,
35
36
  scopeSubComponent,
36
37
  ComponentAmbiguityError,
@@ -623,7 +624,13 @@ async function componentRead(name, options = {}) {
623
624
  });
624
625
  }
625
626
 
626
- const resolved = await resolveUnscopedDoc(dirName, {coreDir, cwd, name});
627
+ const resolved = await resolveUnscopedDoc(dirName, {
628
+ coreDir,
629
+ cwd,
630
+ name,
631
+ }).catch(async error => {
632
+ throw await withExampleBlockPointer(error, dirName, {coreDir, cwd});
633
+ });
627
634
  const docs = await loadComponentDoc(resolved.readmePath, docOpts);
628
635
 
629
636
  // ── Blocks mode ──────────────────────────────────────────────
@@ -0,0 +1,31 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The catalog's component and hook entries, each with the keywords that name
6
+ * another entry left out (see the file comment). Entries with nothing left
7
+ * out are returned as they are.
8
+ * @param {import('./_lexical.mjs').Candidate[]} all
9
+ * @param {import('./_lexical.mjs').Candidate[]} [named] - the entries whose
10
+ * names count: `all` itself, unless the caller holds a wider catalog
11
+ * (`all` cut to one `type`)
12
+ * @returns {import('./_lexical.mjs').Candidate[]}
13
+ */
14
+ export function withoutOtherNames(all: import("./_lexical.mjs").Candidate[], named?: import("./_lexical.mjs").Candidate[]): import("./_lexical.mjs").Candidate[];
15
+ /**
16
+ * The gathered catalog as search reads it: its entries with
17
+ * {@link withoutOtherNames} applied. Names come from the catalog and from
18
+ * `others`, further gathered catalogs (a search for one `type` passes the
19
+ * other of components and hooks, so `type` never changes which keywords
20
+ * count). A reused gather, with the same others, gets the same view back.
21
+ * @template {{all: import('./_lexical.mjs').Candidate[], components: import('./_lexical.mjs').Candidate[]}} T
22
+ * @param {T} catalog
23
+ * @param {{all: import('./_lexical.mjs').Candidate[]}[]} [others]
24
+ * @returns {T}
25
+ */
26
+ export function searchView<T extends {
27
+ all: import("./_lexical.mjs").Candidate[];
28
+ components: import("./_lexical.mjs").Candidate[];
29
+ }>(catalog: T, others?: {
30
+ all: import("./_lexical.mjs").Candidate[];
31
+ }[]): T;
@@ -0,0 +1,177 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Search's keyword rule for keywords that name another entry. A
5
+ * component or hook doc's declared keyword that is exactly another entry's
6
+ * whole name (NumberInput declaring `spinner` while a Spinner component
7
+ * exists) points the reader at that other entry; it is not a promise that this
8
+ * entry answers the word. Search does not count such a keyword as a match,
9
+ * unless the entry's own description uses the word too, or the other entry is
10
+ * its own family member or its hook/component pair (useHoverCard and
11
+ * HoverCard). Names are read as the ranker reads them: joined (`joined`,
12
+ * _words.mjs) and either plural (`pluralOf`, _query.mjs).
13
+ * @input the gathered catalog, and the catalogs whose components and hooks
14
+ * name entries (every component and hook, whatever `type` a search asks for)
15
+ * @output the same catalog with those keywords left out of its component and
16
+ * hook entries
17
+ * @position api/search; three places apply it: search() (search.mjs),
18
+ * rankSearchIndex() (search-index.mjs), and searchCore() (search.mjs) when
19
+ * it is passed `ownKeywords`, as search's own comparisons do. searchCore
20
+ * without it and build read keywords as gathered, so build's output does
21
+ * not move.
22
+ */
23
+
24
+ import {pluralOf} from './_query.mjs';
25
+ import {joined} from './_words.mjs';
26
+
27
+ /**
28
+ * A joined word with its plural or singular, by search's plural rule
29
+ * (`pluralOf`): `step` and `steps`, `box` and `boxes`.
30
+ * @param {string} word
31
+ * @returns {string[]}
32
+ */
33
+ function forms(word) {
34
+ const out = [word];
35
+ for (const plural of [`${word}s`, `${word}es`]) {
36
+ if (pluralOf(plural, word)) out.push(plural);
37
+ }
38
+ for (const single of [word.slice(0, -1), word.slice(0, -2)]) {
39
+ if (pluralOf(word, single)) out.push(single);
40
+ }
41
+ return out;
42
+ }
43
+
44
+ /**
45
+ * Whether a joined word is a run of adjacent words of a text: `tablecell`
46
+ * is in "hundreds of table cell observers", `visuallyhidden` in "a
47
+ * visually-hidden region", and `ton` is not in "button".
48
+ * @param {string[]} words - the text's words, lowercased
49
+ * @param {string} word
50
+ * @returns {boolean}
51
+ */
52
+ function inWords(words, word) {
53
+ for (let i = 0; i < words.length; i++) {
54
+ if (!word.startsWith(words[i])) continue;
55
+ let at = 0;
56
+ for (let j = i; j < words.length && word.startsWith(words[j], at); j++) {
57
+ at += words[j].length;
58
+ if (at === word.length) return true;
59
+ }
60
+ }
61
+ return false;
62
+ }
63
+
64
+ /**
65
+ * Whether two entries belong together, so one may name the other in its
66
+ * keywords: one is the other's family, they share a family, or one is the
67
+ * other's hook (`useHoverCard` and `HoverCard`).
68
+ * @param {import('./_lexical.mjs').Candidate} a
69
+ * @param {import('./_lexical.mjs').Candidate} b
70
+ * @returns {boolean}
71
+ */
72
+ function related(a, b) {
73
+ if (a._family && (a._family === b.name || a._family === b._family)) {
74
+ return true;
75
+ }
76
+ if (b._family === a.name) return true;
77
+ const x = joined(a.name);
78
+ const y = joined(b.name);
79
+ return x === `use${y}` || y === `use${x}`;
80
+ }
81
+
82
+ /** The domains whose keywords are a doc's declared keywords. */
83
+ const DECLARING = new Set(['component', 'hook']);
84
+
85
+ /**
86
+ * The catalog's component and hook entries, each with the keywords that name
87
+ * another entry left out (see the file comment). Entries with nothing left
88
+ * out are returned as they are.
89
+ * @param {import('./_lexical.mjs').Candidate[]} all
90
+ * @param {import('./_lexical.mjs').Candidate[]} [named] - the entries whose
91
+ * names count: `all` itself, unless the caller holds a wider catalog
92
+ * (`all` cut to one `type`)
93
+ * @returns {import('./_lexical.mjs').Candidate[]}
94
+ */
95
+ export function withoutOtherNames(all, named = all) {
96
+ /** @type {Map<string, import('./_lexical.mjs').Candidate[]>} */
97
+ const byName = new Map();
98
+ for (const c of named) {
99
+ if (!DECLARING.has(c.domain)) continue;
100
+ for (const name of [c.name, ...(c.aliases ?? [])]) {
101
+ const key = joined(name);
102
+ if (!key) continue;
103
+ const list = byName.get(key);
104
+ if (list) list.push(c);
105
+ else byName.set(key, [c]);
106
+ }
107
+ }
108
+ return all.map(c => {
109
+ if (!DECLARING.has(c.domain) || !c.keywords?.length) return c;
110
+ /** @type {string[] | null} */
111
+ let described = null;
112
+ const keywords = c.keywords.filter(keyword => {
113
+ const word = joined(keyword);
114
+ if (!word) return true;
115
+ const wordForms = forms(word);
116
+ /** @type {import('./_lexical.mjs').Candidate[]} */
117
+ const others = [];
118
+ for (const form of wordForms) {
119
+ for (const o of byName.get(form) ?? []) {
120
+ if (o !== c && o.name !== c.name) others.push(o);
121
+ }
122
+ }
123
+ if (others.length === 0) return true;
124
+ described ??=
125
+ String(c.description ?? '')
126
+ .toLowerCase()
127
+ .match(/[a-z0-9]+/g) ?? [];
128
+ const words = described;
129
+ if (wordForms.some(form => inWords(words, form))) return true;
130
+ return others.some(o => related(c, o));
131
+ });
132
+ return keywords.length === c.keywords.length ? c : {...c, keywords};
133
+ });
134
+ }
135
+
136
+ /**
137
+ * Each gathered catalog's search views, one per set of naming catalogs.
138
+ * @type {WeakMap<object, {others: object[], view: object}[]>}
139
+ */
140
+ const views = new WeakMap();
141
+
142
+ /**
143
+ * The gathered catalog as search reads it: its entries with
144
+ * {@link withoutOtherNames} applied. Names come from the catalog and from
145
+ * `others`, further gathered catalogs (a search for one `type` passes the
146
+ * other of components and hooks, so `type` never changes which keywords
147
+ * count). A reused gather, with the same others, gets the same view back.
148
+ * @template {{all: import('./_lexical.mjs').Candidate[], components: import('./_lexical.mjs').Candidate[]}} T
149
+ * @param {T} catalog
150
+ * @param {{all: import('./_lexical.mjs').Candidate[]}[]} [others]
151
+ * @returns {T}
152
+ */
153
+ export function searchView(catalog, others = []) {
154
+ const seen = views.get(catalog) ?? [];
155
+ const hit = seen.find(
156
+ v =>
157
+ v.others.length === others.length &&
158
+ v.others.every((o, i) => o === others[i]),
159
+ );
160
+ if (hit) return /** @type {T} */ (hit.view);
161
+ const all = withoutOtherNames(
162
+ catalog.all,
163
+ others.length === 0
164
+ ? catalog.all
165
+ : [catalog.all, ...others.map(o => o.all)].flat(),
166
+ );
167
+ const swap = new Map(catalog.all.map((c, i) => [c, all[i]]));
168
+ const view = {
169
+ ...catalog,
170
+ all,
171
+ components: catalog.components.map(c => swap.get(c) ?? c),
172
+ };
173
+ // Only the latest view per catalog is kept: a search reuses one set of
174
+ // naming catalogs until one of them gathers again.
175
+ views.set(catalog, [{others, view}]);
176
+ return view;
177
+ }
@@ -28,6 +28,7 @@ import {
28
28
  } from './_adapter.mjs';
29
29
  import {checkSearchArgs} from './_result.mjs';
30
30
  import {SEARCH_TREE} from './tree.mjs';
31
+ import {searchView} from './_named-keywords.mjs';
31
32
 
32
33
  /**
33
34
  * Fields a gathered candidate holds that point into the folder it was read
@@ -185,8 +186,14 @@ export async function rankSearchIndex(query, indexes, options = {}) {
185
186
  all.push(...index.candidates);
186
187
  }
187
188
  const {type} = options;
189
+ // Keywords read as search() reads them (_named-keywords.mjs). The names
190
+ // come from every stored entry, before the `type` cut.
191
+ const view = searchView({
192
+ all,
193
+ components: all.filter(candidate => candidate.domain === 'component'),
194
+ }).all;
188
195
  const wanted =
189
- type == null ? all : all.filter(candidate => candidate.domain === type);
196
+ type == null ? view : view.filter(candidate => candidate.domain === type);
190
197
  const {searchedComponents, coreSkipped} = coreFlags(list, type);
191
198
  const response = /** @type {import('./search.type.mjs').SearchResponse} */ (
192
199
  await runTree(
@@ -22,14 +22,19 @@ export function search(query: string, options?: {
22
22
  * same way. A later query in the same folder, for the same `type`, gathers
23
23
  * again only when an input changed.
24
24
  *
25
+ * `ownKeywords` ranks as `search` reads keywords: a doc keyword that is
26
+ * another entry's name is not a match (_named-keywords.mjs). Only search's own
27
+ * comparisons set it; build never does, so build reads every keyword.
28
+ *
25
29
  * @param {string} query
26
- * @param {{cwd?: string, type?: 'component'|'hook'|'doc'|'template'|'theme', limit?: number}} [options]
30
+ * @param {{cwd?: string, type?: 'component'|'hook'|'doc'|'template'|'theme', limit?: number, ownKeywords?: boolean}} [options]
27
31
  * @returns {Promise<import('./search.type.mjs').SearchResponse>}
28
32
  */
29
33
  export function searchCore(query: string, options?: {
30
34
  cwd?: string;
31
35
  type?: "component" | "hook" | "doc" | "template" | "theme";
32
36
  limit?: number;
37
+ ownKeywords?: boolean;
33
38
  }): Promise<import("./search.type.mjs").SearchResponse>;
34
39
  export { scoreCandidate } from "./_candidate-score.mjs";
35
40
  export { scoreQuery } from "./_score.mjs";
@@ -11,7 +11,11 @@
11
11
  * block), and themes. The adapter gathers every candidate (_adapter.mjs),
12
12
  * and search's tree (tree.mjs) picks the searcher that answers.
13
13
  * `searchCore(query)` is the lexical ranker alone (_lexical.mjs); `build`
14
- * reads it, so build's output does not move when search's tree does.
14
+ * reads it, so build's output does not move when search's tree does. A doc
15
+ * keyword that is another entry's name is not a match (_named-keywords.mjs)
16
+ * in three places: `search`, `rankSearchIndex` (search-index.mjs), and
17
+ * `searchCore` with `ownKeywords`. `searchCore` without it, which build
18
+ * reads, reads every keyword as gathered.
15
19
  */
16
20
 
17
21
  import {
@@ -21,6 +25,7 @@ import {
21
25
  import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
22
26
  import {gatherCandidatesReused, loadSearchData} from './_adapter.mjs';
23
27
  import {rankLexical} from './_lexical.mjs';
28
+ import {searchView} from './_named-keywords.mjs';
24
29
  import {checkSearchArgs} from './_result.mjs';
25
30
  import {runTree} from '../../foundation/route/route.mjs';
26
31
  import {SEARCH_TREE} from './tree.mjs';
@@ -73,7 +78,10 @@ async function searchRead(query, options) {
73
78
  SEARCH_TREE,
74
79
  {query, options},
75
80
  {
76
- ...(await gatherCandidatesReused(options)),
81
+ // A keyword that names another entry is not a match here
82
+ // (_named-keywords.mjs); searchCore, which build reads,
83
+ // keeps every keyword.
84
+ ...(await searchCatalog(options)),
77
85
  data: loadSearchData(),
78
86
  },
79
87
  )
@@ -84,14 +92,41 @@ async function searchRead(query, options) {
84
92
  );
85
93
  }
86
94
 
95
+ /**
96
+ * The other declaring domain, whose names a search for one `type` still reads.
97
+ * @type {Record<string, string>}
98
+ */
99
+ const NAMING_DOMAIN = {component: 'hook', hook: 'component'};
100
+
101
+ /**
102
+ * The gathered catalog for `options`, with keywords as search reads them
103
+ * (_named-keywords.mjs). The names come from every component and hook, so a
104
+ * search for one `type` keeps and drops the keywords an open search does.
105
+ * @param {{cwd?: string, type?: string}} options
106
+ */
107
+ async function searchCatalog(options) {
108
+ const gathered = await gatherCandidatesReused(options);
109
+ const other = options.type == null ? null : NAMING_DOMAIN[options.type];
110
+ return searchView(
111
+ gathered,
112
+ other == null
113
+ ? []
114
+ : [await gatherCandidatesReused({cwd: options.cwd, type: other})],
115
+ );
116
+ }
117
+
87
118
  /**
88
119
  * The lexical ranker alone: keyword and fuzzy scoring of every candidate.
89
120
  * `build` ranks from it. It ranks the candidates search gathers, reused the
90
121
  * same way. A later query in the same folder, for the same `type`, gathers
91
122
  * again only when an input changed.
92
123
  *
124
+ * `ownKeywords` ranks as `search` reads keywords: a doc keyword that is
125
+ * another entry's name is not a match (_named-keywords.mjs). Only search's own
126
+ * comparisons set it; build never does, so build reads every keyword.
127
+ *
93
128
  * @param {string} query
94
- * @param {{cwd?: string, type?: 'component'|'hook'|'doc'|'template'|'theme', limit?: number}} [options]
129
+ * @param {{cwd?: string, type?: 'component'|'hook'|'doc'|'template'|'theme', limit?: number, ownKeywords?: boolean}} [options]
95
130
  * @returns {Promise<import('./search.type.mjs').SearchResponse>}
96
131
  */
97
132
  export async function searchCore(query, options = {}) {
@@ -108,10 +143,16 @@ export async function searchCore(query, options = {}) {
108
143
  * @param {any} options
109
144
  */
110
145
  async function searchCoreRead(query, options) {
111
- return withListingCache(async () =>
112
- linkSearchResponse(
113
- rankLexical(query, options, await gatherCandidatesReused(options)),
146
+ return withListingCache(async () => {
147
+ return linkSearchResponse(
148
+ rankLexical(
149
+ query,
150
+ options,
151
+ options.ownKeywords
152
+ ? await searchCatalog(options)
153
+ : await gatherCandidatesReused(options),
154
+ ),
114
155
  options.cwd ?? process.cwd(),
115
- ),
116
- );
156
+ );
157
+ });
117
158
  }
@@ -1,6 +1,8 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /** @param {number} lightness @param {number} a @param {number} b @returns {ColorTriple} */
5
+ export function oklabToLinearRgb(lightness: number, a: number, b: number): ColorTriple;
4
6
  /** @param {unknown} input @returns {string} */
5
7
  export function normalizeColor(input: unknown): string;
6
8
  /** @param {string} hex @returns {{L: number, C: number, H: number}} */
@@ -63,7 +63,7 @@ function linearRgbToOklab(red, green, blue) {
63
63
  }
64
64
 
65
65
  /** @param {number} lightness @param {number} a @param {number} b @returns {ColorTriple} */
66
- function oklabToLinearRgb(lightness, a, b) {
66
+ export function oklabToLinearRgb(lightness, a, b) {
67
67
  const lRoot = lightness + 0.3963377774 * a + 0.2158037573 * b;
68
68
  const mRoot = lightness - 0.1055613458 * a - 0.0638541728 * b;
69
69
  const sRoot = lightness - 0.0894841775 * a - 1.291485548 * b;
@@ -1,6 +1,40 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
- export { themeEditNew, themeEditSet, themeEditUndo, themeEditShow } from "./_edit.mjs";
5
- export { themeEditPreviewAdd, themeEditPreviewApp, themeEditPreviewList, themeEditPreviewRemove } from "./_preview-app.mjs";
4
+ /**
5
+ * The project a command acts on: the Astryx project at or above `cwd`, found
6
+ * as `upgrade` finds it (the nearest package that declares an Astryx package
7
+ * in any dependency list; the search stops at a repository root and never
8
+ * counts the home folder or above), else `cwd` itself. A package nearer
9
+ * than that project that does not use Astryx is refused with the folder to
10
+ * run from, and a nearest package.json that does not parse is never walked
11
+ * past.
12
+ * @param {string} cwd
13
+ */
14
+ export function projectRoot(cwd: string): string;
15
+ export function isHowPicture(word: string, cwd?: string): boolean;
16
+ export function fileExists(file: string, cwd?: string): boolean;
17
+ /** @type {typeof edit.themeEditNew} */
18
+ export const themeEditNew: typeof edit.themeEditNew;
19
+ /** @type {typeof edit.themeEditSet} */
20
+ export const themeEditSet: typeof edit.themeEditSet;
21
+ /** @type {typeof edit.themeEditUndo} */
22
+ export const themeEditUndo: typeof edit.themeEditUndo;
23
+ /** @type {typeof edit.themeEditShow} */
24
+ export const themeEditShow: typeof edit.themeEditShow;
25
+ /** @type {typeof preview.themeEditPreviewAdd} */
26
+ export const themeEditPreviewAdd: typeof preview.themeEditPreviewAdd;
27
+ /**
28
+ * `preview app` runs from the project root, with `dir` kept pointing where
29
+ * it was given. With a theme it holds that theme's lock, since it may build
30
+ * the theme and copies its files: a `set` beside it waits.
31
+ * @type {typeof preview.themeEditPreviewApp}
32
+ */
33
+ export const themeEditPreviewApp: typeof preview.themeEditPreviewApp;
34
+ /** @type {typeof preview.themeEditPreviewList} */
35
+ export const themeEditPreviewList: typeof preview.themeEditPreviewList;
36
+ /** @type {typeof preview.themeEditPreviewRemove} */
37
+ export const themeEditPreviewRemove: typeof preview.themeEditPreviewRemove;
38
+ import * as edit from './_edit.mjs';
39
+ import * as preview from './_preview-app.mjs';
6
40
  export { themeEditHow, parsePoints } from "./_how.mjs";