@astryxdesign/cli 0.7.14-canary.g179767d → 0.7.14-canary.g63bbda1
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.
- package/api/search/_named-keywords.d.mts +31 -0
- package/api/search/_named-keywords.mjs +177 -0
- package/api/search/search-index.mjs +8 -1
- package/api/search/search.d.mts +6 -1
- package/api/search/search.mjs +49 -8
- package/api/theme/palette/generate/color.d.mts +2 -0
- package/api/theme/palette/generate/color.mjs +1 -1
- package/api/theme-edit/_check.mjs +148 -10
- package/api/theme-edit/_color.d.mts +15 -0
- package/api/theme-edit/_color.mjs +37 -9
- package/api/theme-edit/_compiler.d.mts +7 -3
- package/api/theme-edit/_compiler.mjs +52 -31
- package/api/theme-edit/_context.d.mts +7 -3
- package/api/theme-edit/_context.mjs +5 -3
- package/api/theme-edit/_edit.mjs +220 -17
- package/api/theme-edit/_how.mjs +12 -2
- package/api/theme-edit/_overview.mjs +43 -28
- package/api/theme-edit/_palette.d.mts +7 -1
- package/api/theme-edit/_palette.mjs +149 -9
- package/api/theme-edit/_parts.mjs +26 -3
- package/api/theme-edit/_preview-app.mjs +249 -115
- package/api/theme-edit/_preview.d.mts +4 -2
- package/api/theme-edit/_preview.mjs +57 -14
- package/api/theme-edit/_settings.d.mts +10 -4
- package/api/theme-edit/_settings.mjs +156 -45
- package/api/theme-edit/_tables.mjs +3 -3
- package/api/theme-edit/theme-edit.type.d.mts +11 -5
- package/api/theme-edit/theme-edit.type.mjs +5 -2
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +2 -7
- package/api/theme-edit/themeEditShow.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +2 -2
- package/assets/discover/official-packages.json +4 -0
- package/clients/cli/commands/experimental/theme.mjs +25 -7
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +3 -3
- package/package.json +6 -7
|
@@ -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 ?
|
|
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(
|
package/api/search/search.d.mts
CHANGED
|
@@ -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";
|
package/api/search/search.mjs
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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;
|
|
@@ -540,7 +540,7 @@ export function checkSetting(
|
|
|
540
540
|
s.note = `no effect on ${hard.map(([t]) => t).join(', ')} (they never read ${thing})`;
|
|
541
541
|
if (!s.note && recorded.length) {
|
|
542
542
|
const fed = C.feeds(recorded[0][0], thing);
|
|
543
|
-
if (fed.length) s.note = `feeds ${C.fmtFeeds(fed)}`;
|
|
543
|
+
if (fed.length) s.note = `feeds ${C.fmtFeeds(fed, recorded[0][0])}`;
|
|
544
544
|
}
|
|
545
545
|
const soft = results.filter(([, r]) => r?.soft);
|
|
546
546
|
if (!s.note && soft.length && soft.length === results.length)
|
|
@@ -549,10 +549,22 @@ export function checkSetting(
|
|
|
549
549
|
).message;
|
|
550
550
|
} else {
|
|
551
551
|
const r = C.checkTokenGlobal(thing, P);
|
|
552
|
+
// Tokens whose default is built from this one: a part that reads
|
|
553
|
+
// them sees the change.
|
|
554
|
+
const fed = r
|
|
555
|
+
? Object.entries(TOKENS)
|
|
556
|
+
.filter(
|
|
557
|
+
([k, v]) =>
|
|
558
|
+
k !== thing && new RegExp(`var\\(${thing}[,)]`).test(String(v)),
|
|
559
|
+
)
|
|
560
|
+
.map(([k]) => k)
|
|
561
|
+
: [];
|
|
552
562
|
// A token a dial writes is always accepted, so a dial's notes never
|
|
553
563
|
// name a token `set` refuses.
|
|
554
|
-
if (r &&
|
|
555
|
-
s.note = `no part reads ${thing}
|
|
564
|
+
if (r && fed.length)
|
|
565
|
+
s.note = `no part reads ${thing} itself, but ${fed.slice(0, 4).join(', ')} ${fed.length > 1 ? 'are' : 'is'} built from it, so the change shows wherever ${fed.length > 1 ? 'those are' : 'that is'} used${fed.some(k => k.startsWith('--color-syntax-')) ? ' (such as diff rows in code blocks)' : ''}`;
|
|
566
|
+
else if (r && dialWrites(thing))
|
|
567
|
+
s.note = `no part of this Core reads ${thing}, and no token it feeds is read, so it changes nothing you see now; it is set as asked because a dial writes it too`;
|
|
556
568
|
else if (r)
|
|
557
569
|
refuse(E.ERR_THEME_NO_EFFECT, r.message, {run: r.run, also: r.also});
|
|
558
570
|
}
|
|
@@ -682,6 +694,62 @@ const dialWrites = token =>
|
|
|
682
694
|
token,
|
|
683
695
|
);
|
|
684
696
|
|
|
697
|
+
/** Hues a question can name, each with or without light, dark or pale. */
|
|
698
|
+
const HUES = [
|
|
699
|
+
'gray',
|
|
700
|
+
'grey',
|
|
701
|
+
'red',
|
|
702
|
+
'blue',
|
|
703
|
+
'green',
|
|
704
|
+
'yellow',
|
|
705
|
+
'orange',
|
|
706
|
+
'purple',
|
|
707
|
+
'pink',
|
|
708
|
+
'navy',
|
|
709
|
+
];
|
|
710
|
+
/** Color words that can name a part's fill, longest first. */
|
|
711
|
+
const COLOR_WORDS = [
|
|
712
|
+
...HUES.flatMap(h => ['light', 'dark', 'pale'].map(s => `${s} ${h}`)),
|
|
713
|
+
...HUES,
|
|
714
|
+
'white',
|
|
715
|
+
'black',
|
|
716
|
+
'cream',
|
|
717
|
+
'beige',
|
|
718
|
+
];
|
|
719
|
+
/** Fills for the plain grays, so the command has a real value. */
|
|
720
|
+
const NAMED_FILLS = /** @type {Record<string, string>} */ ({
|
|
721
|
+
'light gray': '#e5e7eb',
|
|
722
|
+
'light grey': '#e5e7eb',
|
|
723
|
+
gray: '#9ca3af',
|
|
724
|
+
grey: '#9ca3af',
|
|
725
|
+
'dark gray': '#374151',
|
|
726
|
+
'dark grey': '#374151',
|
|
727
|
+
'light blue': '#dbeafe',
|
|
728
|
+
'pale blue': '#eff6ff',
|
|
729
|
+
white: '#ffffff',
|
|
730
|
+
black: '#000000',
|
|
731
|
+
});
|
|
732
|
+
/** Nouns for parts that have a fill. */
|
|
733
|
+
const PART_NOUNS = [
|
|
734
|
+
'button',
|
|
735
|
+
'card',
|
|
736
|
+
'panel',
|
|
737
|
+
'banner',
|
|
738
|
+
'header',
|
|
739
|
+
'input',
|
|
740
|
+
'field',
|
|
741
|
+
'badge',
|
|
742
|
+
'tab',
|
|
743
|
+
'chip',
|
|
744
|
+
'pill',
|
|
745
|
+
'toast',
|
|
746
|
+
'tooltip',
|
|
747
|
+
'dialog',
|
|
748
|
+
'modal',
|
|
749
|
+
'sidebar',
|
|
750
|
+
'row',
|
|
751
|
+
];
|
|
752
|
+
|
|
685
753
|
/**
|
|
686
754
|
* Answer a plain-words question with exact commands: the parts it names,
|
|
687
755
|
* the aspects it asks about, and what each part really reads for them.
|
|
@@ -711,13 +779,56 @@ export function answerHow(ctx, question) {
|
|
|
711
779
|
/\bwhite (text|labels?|writing|words)\b|\b(text|labels?|writing|words) (in |is |are )?white\b/.test(
|
|
712
780
|
text,
|
|
713
781
|
);
|
|
782
|
+
// A color word right before a part ("light gray button") is the part's
|
|
783
|
+
// fill, so it keeps the background aspect beside text.
|
|
784
|
+
const fillMatch =
|
|
785
|
+
new RegExp(
|
|
786
|
+
`\\b(${COLOR_WORDS.join('|')})\\s+(?:${PART_NOUNS.join('|')})s?\\b`,
|
|
787
|
+
).exec(text) ??
|
|
788
|
+
new RegExp(
|
|
789
|
+
`\\b(?:${PART_NOUNS.join('|')})s?\\s+(?:with\\s+an?\\s+|in\\s+|is\\s+)?(${COLOR_WORDS.join('|')})\\b(?!\\s+(?:text|labels?|writing|words))`,
|
|
790
|
+
).exec(text);
|
|
791
|
+
const fillWord = Boolean(fillMatch);
|
|
792
|
+
// A fill named outright ("a blue tint") keeps the background aspect.
|
|
793
|
+
const namedFill =
|
|
794
|
+
/background|fill|gradient|glossy|\btint(ed)?\b|\bbg\b/.test(text) ||
|
|
795
|
+
fillWord;
|
|
714
796
|
if (
|
|
715
797
|
intents.includes('text') &&
|
|
716
798
|
intents.includes('background') &&
|
|
717
|
-
|
|
799
|
+
!namedFill &&
|
|
718
800
|
!(/\bwhite\b/.test(text) && !whiteText)
|
|
719
801
|
)
|
|
720
802
|
intents = intents.filter(g => g !== 'background');
|
|
803
|
+
// "border color" or "a gray border" is the border's color, not a fill; a
|
|
804
|
+
// color word for anything else ("a dark card with a border", "the card
|
|
805
|
+
// color and its border", "colored buttons") is the fill's.
|
|
806
|
+
const fillWords = [...COLOR_WORDS, 'dark', 'light', 'colou?r(ed)?'].join('|');
|
|
807
|
+
// Take out every color word that belongs to the border, the text or the
|
|
808
|
+
// mode ("a light gray border", "the color of the border", "in dark
|
|
809
|
+
// mode"); a color word left over is the fill's.
|
|
810
|
+
const rest = text
|
|
811
|
+
.replace(/\b(dark|light) (mode|theme)\b/g, ' ')
|
|
812
|
+
.replace(
|
|
813
|
+
/\bcolou?r of (the |its |a )?(border|outline|stroke|edge|text|labels?)s?\b/g,
|
|
814
|
+
' ',
|
|
815
|
+
)
|
|
816
|
+
.replace(/\b(border|outline|stroke|edge|text)s? colou?r\b/g, ' ')
|
|
817
|
+
.replace(
|
|
818
|
+
new RegExp(
|
|
819
|
+
`\\b((${fillWords}|thin|thick|subtle|bold)\\s+)+(border|outline|stroke|edge|text|labels?)s?\\b`,
|
|
820
|
+
'g',
|
|
821
|
+
),
|
|
822
|
+
' ',
|
|
823
|
+
);
|
|
824
|
+
const looseColor = new RegExp(`\\b(${fillWords})\\b`).test(rest);
|
|
825
|
+
if (
|
|
826
|
+
intents.includes('border') &&
|
|
827
|
+
intents.includes('background') &&
|
|
828
|
+
!namedFill &&
|
|
829
|
+
!looseColor
|
|
830
|
+
)
|
|
831
|
+
intents = intents.filter(g => g !== 'background');
|
|
721
832
|
if (!intents.length && parts.length) intents = [null];
|
|
722
833
|
const design = Object.keys(DESIGN).filter(w => text.includes(w));
|
|
723
834
|
const tracking = /letter ?spacing|tracking|kerning/.test(text);
|
|
@@ -741,12 +852,36 @@ export function answerHow(ctx, question) {
|
|
|
741
852
|
if (g === 'font' && /bold|heav/.test(text)) return '700';
|
|
742
853
|
if (g === 'font' && /\b(light(er)?|thin)\b/.test(text)) return '300';
|
|
743
854
|
if (g === 'text' && whiteText) return '"#ffffff"';
|
|
744
|
-
if (g === 'text' && /\
|
|
855
|
+
if (g === 'text' && /\bdark (text|labels?|writing|words)\b/.test(text))
|
|
856
|
+
return '"#111827"';
|
|
857
|
+
if (g === 'background' && fillMatch) {
|
|
858
|
+
const named = NAMED_FILLS[fillMatch[1]];
|
|
859
|
+
if (named) return `"${named}"`;
|
|
860
|
+
}
|
|
861
|
+
if (g === 'border')
|
|
862
|
+
return `"${/\bthick\b/.test(text) ? '2px' : '1px'} solid <color>"`;
|
|
863
|
+
if (g === 'text' && /\baccent[- ]?(colou?red )?(text|labels?)\b/.test(text))
|
|
745
864
|
return '"var(--color-text-accent)"';
|
|
746
865
|
if (g === 'background' && /\bwhite\b/.test(text) && !whiteText)
|
|
747
866
|
return '"#ffffff"';
|
|
748
867
|
return '<value>';
|
|
749
868
|
};
|
|
869
|
+
/**
|
|
870
|
+
* A value for one token, of its own type: a whole border value suits only
|
|
871
|
+
* the border property, so a color token takes a color and a width token a
|
|
872
|
+
* width.
|
|
873
|
+
* @param {string} token @param {string} group
|
|
874
|
+
*/
|
|
875
|
+
const tokenValue = (token, group) => {
|
|
876
|
+
const v = V(group);
|
|
877
|
+
const whole = /\s(solid|dashed|dotted)\s/.test(v);
|
|
878
|
+
if (!whole) return v;
|
|
879
|
+
const type = C.typeOf(token);
|
|
880
|
+
if (type === 'color') return '"<color>"';
|
|
881
|
+
if (type === 'size' || /width/.test(token))
|
|
882
|
+
return /\b2px\b/.test(v) ? '2px' : '1px';
|
|
883
|
+
return '<value>';
|
|
884
|
+
};
|
|
750
885
|
for (const raw of parts.slice(0, 3)) {
|
|
751
886
|
let [part, wp, wv] = raw.split(':');
|
|
752
887
|
const named = Boolean(wp);
|
|
@@ -902,11 +1037,14 @@ export function answerHow(ctx, question) {
|
|
|
902
1037
|
: group === 'font'
|
|
903
1038
|
? 'font-family'
|
|
904
1039
|
: DIRECT[group];
|
|
1040
|
+
const restingBorder =
|
|
1041
|
+
group === 'border' && list.every(r => r.when.some(w => /:/.test(w)));
|
|
905
1042
|
const tokenRoute =
|
|
906
1043
|
(group === 'text' || group === 'background' || group === 'border') &&
|
|
1044
|
+
!restingBorder &&
|
|
907
1045
|
!/gradient|inset/.test(V(group));
|
|
908
1046
|
results.push({
|
|
909
|
-
text: `${part} ${aspect ? (tracking ? 'letter spacing' : 'weight') : group}${when ? ` (${wp} ${wv})` : ''}: ${list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : inherited ? `inherits the page's text color (${inherited} for the whole theme); set the property for this part alone` : 'no token of its own; set the property directly'}`,
|
|
1047
|
+
text: `${part} ${aspect ? (tracking ? 'letter spacing' : 'weight') : group}${when ? ` (${wp} ${wv})` : ''}: ${restingBorder ? `the resting border is the border property (no token sets it)${list.length ? `; in states it reads ${list.map(r => r.token + C.fmtWhen(r.when)).join(', ')}` : ''}` : list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : inherited ? `inherits the page's text color (${inherited} for the whole theme); set the property for this part alone` : 'no token of its own; set the property directly'}`,
|
|
910
1048
|
commands: [
|
|
911
1049
|
`${P} set <theme> ${direct} ${V(group)} --on ${part}${when} # direct: always works`,
|
|
912
1050
|
...(inherited
|
|
@@ -917,7 +1055,7 @@ export function answerHow(ctx, question) {
|
|
|
917
1055
|
.slice(0, 2)
|
|
918
1056
|
.map(
|
|
919
1057
|
r =>
|
|
920
|
-
`${P} set <theme> ${r.token} ${
|
|
1058
|
+
`${P} set <theme> ${r.token} ${tokenValue(r.token, group)} --on ${part} # via the token${C.fmtWhen(r.when)}`,
|
|
921
1059
|
)
|
|
922
1060
|
: []),
|
|
923
1061
|
],
|
|
@@ -973,14 +1111,14 @@ export function answerHow(ctx, question) {
|
|
|
973
1111
|
text: DIALS[dial].help,
|
|
974
1112
|
commands: DIALS[dial].examples.map(e => `${P} ${e}`),
|
|
975
1113
|
});
|
|
976
|
-
// Text
|
|
977
|
-
|
|
1114
|
+
// Text and background colors come from their tokens first; the brand
|
|
1115
|
+
// color after.
|
|
1116
|
+
results.push(...wholeThemeTokens(ctx, g));
|
|
978
1117
|
if (g === 'background' || g === 'text')
|
|
979
1118
|
results.push({
|
|
980
1119
|
text: DIALS.accent.help,
|
|
981
1120
|
commands: DIALS.accent.examples.map(e => `${P} ${e}`),
|
|
982
1121
|
});
|
|
983
|
-
if (g !== 'text') results.push(...wholeThemeTokens(ctx, g));
|
|
984
1122
|
}
|
|
985
1123
|
}
|
|
986
1124
|
if (!results.length) {
|
|
@@ -1,6 +1,21 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* The opacity of a CSS color, 0 to 1: the alpha of an 8- or 4-digit hex,
|
|
6
|
+
* `rgba()`/`hsla()`, or a `/ alpha` part; 0 for `transparent`; 1 otherwise.
|
|
7
|
+
* @param {unknown} value
|
|
8
|
+
* @returns {number}
|
|
9
|
+
*/
|
|
10
|
+
export function alphaOf(value: unknown): number;
|
|
11
|
+
/**
|
|
12
|
+
* A color drawn at `alpha` over `under`, as the opaque color the eye sees.
|
|
13
|
+
* @param {Rgb} over
|
|
14
|
+
* @param {number} alpha
|
|
15
|
+
* @param {Rgb} under
|
|
16
|
+
* @returns {Rgb}
|
|
17
|
+
*/
|
|
18
|
+
export function compositeOver(over: Rgb, alpha: number, under: Rgb): Rgb;
|
|
4
19
|
/**
|
|
5
20
|
* The RGB of a fixed CSS color: a hex, a named color, or rgb(), hsl(),
|
|
6
21
|
* hwb(), lab(), lch(), oklab() or oklch(). Null for a value with no fixed
|