@astryxdesign/cli 0.7.16-canary.ge95b87c → 0.7.16
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/CHANGELOG.md +369 -0
- package/README.md +1 -1
- package/api/build/_adapter.d.mts +9 -0
- package/api/build/_adapter.mjs +24 -0
- package/api/build/kit/shell.weights.json +1 -0
- package/api/build/kit/shellcall.d.mts +26 -0
- package/api/build/kit/shellcall.mjs +87 -0
- package/api/build/kit/start.mjs +67 -4
- package/api/build/kit/weights.d.mts +15 -0
- package/api/build/kit/weights.mjs +27 -0
- package/api/component/__fixtures__/resolutions/modules.txt +1 -1
- package/api/doctor/_adapter.d.mts +3 -2
- package/api/doctor/_adapter.mjs +7 -1
- package/api/doctor/doctor.d.mts +8 -0
- package/api/doctor/doctor.mjs +53 -8
- package/api/doctor/theme-checks.mjs +157 -8
- package/api/icon/_adapter.d.mts +7 -3
- package/api/icon/_adapter.mjs +12 -3
- package/api/icon/icon.type.d.mts +15 -0
- package/api/icon/icon.type.mjs +10 -3
- package/api/icon/iconUse.doc.mjs +19 -5
- package/api/icon/list/list.mjs +7 -1
- package/api/icon/use/use.d.mts +8 -5
- package/api/icon/use/use.mjs +95 -13
- package/api/init/run/run.mjs +1 -0
- package/api/template/template.type.d.mts +6 -2
- package/api/template/template.type.mjs +2 -1
- package/api/theme/_adapter.mjs +16 -2
- package/api/theme/build/build.d.mts +10 -6
- package/api/theme/build/build.mjs +42 -29
- package/api/theme/generateTonalPalette.doc.mjs +2 -2
- package/api/theme/palette/generate/generator.mjs +141 -2
- package/api/theme/theme.type.d.mts +39 -0
- package/api/theme/theme.type.mjs +21 -0
- package/api/theme/themeBuild.doc.mjs +1 -1
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +1 -0
- package/api/theme-edit/_adapter.mjs +79 -21
- package/api/theme-edit/_check.d.mts +25 -2
- package/api/theme-edit/_check.mjs +251 -61
- package/api/theme-edit/_context.d.mts +2 -1
- package/api/theme-edit/_context.mjs +19 -1
- package/api/theme-edit/_edit.d.mts +16 -0
- package/api/theme-edit/_edit.mjs +360 -59
- package/api/theme-edit/_how-question.d.mts +8 -0
- package/api/theme-edit/_how-question.mjs +169 -22
- package/api/theme-edit/_marks.d.mts +13 -0
- package/api/theme-edit/_marks.mjs +15 -0
- package/api/theme-edit/_palette.d.mts +27 -0
- package/api/theme-edit/_palette.mjs +112 -8
- package/api/theme-edit/_preview-app.d.mts +46 -1
- package/api/theme-edit/_preview-app.mjs +367 -36
- package/api/theme-edit/_preview.d.mts +55 -0
- package/api/theme-edit/_preview.mjs +231 -6
- package/api/theme-edit/_project.d.mts +4 -0
- package/api/theme-edit/_project.mjs +27 -6
- package/api/theme-edit/_settings.d.mts +61 -2
- package/api/theme-edit/_settings.mjs +317 -115
- package/api/theme-edit/_tables.mjs +1 -1
- package/api/theme-edit/theme-edit.type.d.mts +30 -2
- package/api/theme-edit/theme-edit.type.mjs +10 -2
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/theme.doc.zh.mjs +4 -3
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +63 -8
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.doc.mjs +21 -0
- package/assets/templates/blocks/components/Outline/useOutlineFromDOMHookUsage.tsx +62 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/page.tsx +20 -2
- package/assets/templates/themes/neutral/neutralPalettes.generated.receipt.json +2 -0
- package/authoring/config/config.doc.mjs +8 -0
- package/authoring/config/parse.d.mts +1 -0
- package/authoring/config/parse.mjs +12 -0
- package/authoring/config/type.ts +8 -0
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +3 -3
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/icon.mjs +61 -6
- package/clients/cli/commands/experimental/theme.mjs +9 -2
- package/clients/cli/commands/experimental-icon-use.doc.mjs +12 -5
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +7 -2
- package/clients/cli/commands/theme.mjs +41 -18
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/index.mjs +25 -5
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/config-writer.d.mts +23 -0
- package/foundation/config/config-writer.mjs +150 -56
- package/foundation/config/project.mjs +43 -2
- package/foundation/discovery/component-discovery.mjs +6 -5
- package/foundation/discovery/icon-set-checks.mjs +164 -48
- package/foundation/discovery/icon-set-discovery.d.mts +38 -5
- package/foundation/discovery/icon-set-discovery.mjs +50 -6
- package/foundation/discovery/icon-set-theme-maps.d.mts +59 -0
- package/foundation/discovery/icon-set-theme-maps.mjs +95 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -3
- package/foundation/discovery/icon-set-writer.mjs +57 -16
- package/foundation/discovery/template-icons.d.mts +27 -10
- package/foundation/discovery/template-icons.mjs +142 -26
- package/foundation/discovery/theme-discovery.d.mts +25 -0
- package/foundation/discovery/theme-discovery.mjs +48 -7
- package/foundation/fs/gather-cache.mjs +6 -2
- package/foundation/integrations/autolink.d.mts +4 -2
- package/foundation/integrations/autolink.mjs +4 -2
- package/foundation/integrations/cli-requirement.d.mts +16 -5
- package/foundation/integrations/cli-requirement.mjs +27 -6
- package/foundation/integrations/may-have-integrations.mjs +5 -2
- package/foundation/integrations/missing-dependency.d.mts +9 -0
- package/foundation/integrations/missing-dependency.mjs +100 -0
- package/package.json +6 -6
|
@@ -34,6 +34,12 @@ import {loadManifestObject} from '../integrations/integrations.mjs';
|
|
|
34
34
|
import {levenshteinDistance} from '../text/string-utils.mjs';
|
|
35
35
|
import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
36
36
|
import {generatedTypesPath} from './icon-set-paths.mjs';
|
|
37
|
+
import {
|
|
38
|
+
lookExport,
|
|
39
|
+
THEME_MAP_NAME,
|
|
40
|
+
variantThemeMapName,
|
|
41
|
+
variantThemeMaps,
|
|
42
|
+
} from './icon-set-theme-maps.mjs';
|
|
37
43
|
|
|
38
44
|
export {generatedTypesPath};
|
|
39
45
|
import {
|
|
@@ -1373,6 +1379,7 @@ const GENERATED_HEADER = [
|
|
|
1373
1379
|
'// Edit with those commands; a statement added by hand is kept.',
|
|
1374
1380
|
'// themeIcons has one entry per built-in icon definition in map (the names Core renders), not one per icon;',
|
|
1375
1381
|
'// the import lines above it give it local names for the re-exported icons.',
|
|
1382
|
+
'// themeIcons<Variant> draws the same names in that variant, for each variant an icon draws.',
|
|
1376
1383
|
];
|
|
1377
1384
|
|
|
1378
1385
|
/**
|
|
@@ -1542,8 +1549,7 @@ export function generatedTypesMatch(actual, expected, label) {
|
|
|
1542
1549
|
/** The local name the generated module gives the set's adapter. */
|
|
1543
1550
|
const ADAPTER_LOCAL = 'adaptIcon';
|
|
1544
1551
|
|
|
1545
|
-
|
|
1546
|
-
export const THEME_MAP_NAME = 'themeIcons';
|
|
1552
|
+
export {THEME_MAP_NAME};
|
|
1547
1553
|
|
|
1548
1554
|
/** How the generated module imports React for its theme map. */
|
|
1549
1555
|
const REACT_IMPORT = "import {createElement} from 'react'";
|
|
@@ -1620,7 +1626,8 @@ export function generatedTypesText(statements) {
|
|
|
1620
1626
|
const theme = /^export const (\w+) = \{(.*)\}$/u.exec(statement);
|
|
1621
1627
|
if (
|
|
1622
1628
|
theme &&
|
|
1623
|
-
(theme[1]
|
|
1629
|
+
(theme[1].startsWith(THEME_MAP_NAME) ||
|
|
1630
|
+
statement.includes('createElement('))
|
|
1624
1631
|
) {
|
|
1625
1632
|
react.add('ReactElement');
|
|
1626
1633
|
const keys = [...theme[2].matchAll(/(\w+): createElement\(/gu)].map(
|
|
@@ -1687,6 +1694,14 @@ export function generatedModuleText(
|
|
|
1687
1694
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
1688
1695
|
};
|
|
1689
1696
|
const themeName = data.themeMap === THEME_MAP_NAME ? THEME_MAP_NAME : null;
|
|
1697
|
+
// Every theme map the module may hold, one per declared look, so a look's
|
|
1698
|
+
// map no icon draws any more is dropped as well.
|
|
1699
|
+
const themeNames = [
|
|
1700
|
+
THEME_MAP_NAME,
|
|
1701
|
+
...(data.variants ?? [])
|
|
1702
|
+
.filter(variant => variant !== data.default?.variant)
|
|
1703
|
+
.map(variantThemeMapName),
|
|
1704
|
+
];
|
|
1690
1705
|
const lines = before == null ? [] : generatedStatements(before, generated);
|
|
1691
1706
|
const lineSet = new Set(lines);
|
|
1692
1707
|
// Written once, below: the adapter's import, React's createElement, and
|
|
@@ -1712,7 +1727,8 @@ export function generatedModuleText(
|
|
|
1712
1727
|
return (
|
|
1713
1728
|
line === REACT_IMPORT ||
|
|
1714
1729
|
themeImport(line) ||
|
|
1715
|
-
(themeName != null &&
|
|
1730
|
+
(themeName != null &&
|
|
1731
|
+
themeNames.some(name => line.startsWith(`export const ${name} = `)))
|
|
1716
1732
|
);
|
|
1717
1733
|
};
|
|
1718
1734
|
const imports = new Set(
|
|
@@ -1777,22 +1793,42 @@ export function generatedModuleText(
|
|
|
1777
1793
|
}
|
|
1778
1794
|
/** @type {string[]} */
|
|
1779
1795
|
const theme = [];
|
|
1796
|
+
/** @type {Array<{name: string, entries: string[]}>} */
|
|
1797
|
+
const looks = themeName
|
|
1798
|
+
? variantThemeMaps({...data, generated}).map(({name}) => ({
|
|
1799
|
+
name,
|
|
1800
|
+
entries: [],
|
|
1801
|
+
}))
|
|
1802
|
+
: [];
|
|
1780
1803
|
/** @type {Set<string>} */
|
|
1781
1804
|
const themeImports = new Set();
|
|
1805
|
+
/**
|
|
1806
|
+
* A theme-map entry for one built-in definition, and the import that
|
|
1807
|
+
* gives a re-exported icon its local name.
|
|
1808
|
+
* @param {string} name
|
|
1809
|
+
* @param {string} exportName
|
|
1810
|
+
*/
|
|
1811
|
+
const themeEntry = (name, exportName) => {
|
|
1812
|
+
const line = exported.get(exportName);
|
|
1813
|
+
const reexport =
|
|
1814
|
+
line != null && line.startsWith('export {') ? line : undefined;
|
|
1815
|
+
if (reexport) {
|
|
1816
|
+
themeImports.add(`import${reexport.slice('export'.length)}`);
|
|
1817
|
+
}
|
|
1818
|
+
return ` ${name}: createElement(${exportName}, ${THEME_ELEMENT_PROPS}),`;
|
|
1819
|
+
};
|
|
1782
1820
|
if (themeName) {
|
|
1783
|
-
const byId = new Map(data.icons.map(icon => [icon.id, icon
|
|
1821
|
+
const byId = new Map(data.icons.map(icon => [icon.id, icon]));
|
|
1822
|
+
const lookVariants = variantThemeMaps({...data, generated});
|
|
1784
1823
|
for (const name of Object.keys(data.map ?? {}).sort()) {
|
|
1785
|
-
const
|
|
1786
|
-
if (BUILT_IN.has(name) &&
|
|
1787
|
-
theme.push(
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
if (reexport) {
|
|
1794
|
-
themeImports.add(`import${reexport.slice('export'.length)}`);
|
|
1795
|
-
}
|
|
1824
|
+
const icon = byId.get(/** @type {string} */ (data.map?.[name]));
|
|
1825
|
+
if (BUILT_IN.has(name) && icon) {
|
|
1826
|
+
theme.push(themeEntry(name, icon.export));
|
|
1827
|
+
lookVariants.forEach(({variant}, index) => {
|
|
1828
|
+
looks[index].entries.push(
|
|
1829
|
+
themeEntry(name, lookExport(icon, variant)),
|
|
1830
|
+
);
|
|
1831
|
+
});
|
|
1796
1832
|
}
|
|
1797
1833
|
}
|
|
1798
1834
|
}
|
|
@@ -1815,6 +1851,11 @@ export function generatedModuleText(
|
|
|
1815
1851
|
? [`export const ${themeName} = {`, ...theme, '};']
|
|
1816
1852
|
: [`export const ${themeName} = {};`]
|
|
1817
1853
|
: []),
|
|
1854
|
+
...looks.flatMap(({name, entries}) =>
|
|
1855
|
+
entries.length > 0
|
|
1856
|
+
? [`export const ${name} = {`, ...entries, '};']
|
|
1857
|
+
: [`export const ${name} = {};`],
|
|
1858
|
+
),
|
|
1818
1859
|
'',
|
|
1819
1860
|
].join('\n');
|
|
1820
1861
|
const typesPath = generatedTypesPath(generated);
|
|
@@ -35,12 +35,16 @@ export function placeholderUses(source: string): Array<{
|
|
|
35
35
|
meanings: string[] | null;
|
|
36
36
|
}> | null;
|
|
37
37
|
/**
|
|
38
|
-
* The commands that give a placeholder icon a real one.
|
|
38
|
+
* The commands that give a placeholder icon a real one. The `use` command
|
|
39
|
+
* keeps the list's backups and the project's look, and adds a backup after
|
|
40
|
+
* them.
|
|
39
41
|
* @param {string[]} definitions
|
|
40
42
|
* @param {string} main the main set's name as the list writes it
|
|
43
|
+
* @param {readonly string[]} [backups] the list's backups as it writes them
|
|
44
|
+
* @param {string | null} [variant] the project's look
|
|
41
45
|
* @returns {string[]}
|
|
42
46
|
*/
|
|
43
|
-
export function placeholderFixes(definitions: string[], main: string): string[];
|
|
47
|
+
export function placeholderFixes(definitions: string[], main: string, backups?: readonly string[], variant?: string | null): string[];
|
|
44
48
|
/**
|
|
45
49
|
* The target-set icon whose reviewed `matches` name the source icon with one
|
|
46
50
|
* of `confidences`, ties broken by the order the confidences are given and
|
|
@@ -177,13 +181,16 @@ export function mapTemplateIcons(source: string, { sets, choice }: {
|
|
|
177
181
|
* @property {string[]} [dropped] the library's sizing props (`size`,
|
|
178
182
|
* `strokeWidth`, `absoluteStrokeWidth`) removed from its elements: an icon
|
|
179
183
|
* set's icons take their size from CSS
|
|
180
|
-
* @property {'match' | 'definition'} by `match`: a reviewed
|
|
184
|
+
* @property {'match' | 'definition' | 'variant'} by `match`: a reviewed
|
|
181
185
|
* `exact` or `strong` match in the project set's data names the source
|
|
182
186
|
* icon; `definition`: the target's `map` names it for the Astryx icon
|
|
183
|
-
* definition the source draws
|
|
187
|
+
* definition the source draws; `variant`: the source is already this icon
|
|
188
|
+
* of a set in the project's list, in another look, and moves to the look
|
|
189
|
+
* the project names
|
|
184
190
|
* @property {{asked: string, used: string | null}} [variant] present when the
|
|
185
|
-
*
|
|
186
|
-
*
|
|
191
|
+
* look asked for, the project's variant or else the look the source draws,
|
|
192
|
+
* is one the target set's icon does not have: that look, and the look used
|
|
193
|
+
* (the set's default look)
|
|
187
194
|
*/
|
|
188
195
|
/**
|
|
189
196
|
* One icon no set in the project's list has: each of its uses in the copied
|
|
@@ -227,6 +234,8 @@ export function mapTemplateIcons(source: string, { sets, choice }: {
|
|
|
227
234
|
* @property {string[]} [order] the main set and each backup, as
|
|
228
235
|
* `<package>/<set>`, in the order icons are looked up; present when the
|
|
229
236
|
* project lists backups
|
|
237
|
+
* @property {string} [variant] the look the project's icons draw, as
|
|
238
|
+
* `experimental.iconVariant` names it; present when it is set
|
|
230
239
|
* @property {string} reason
|
|
231
240
|
* @property {MappedIcon[]} mapped
|
|
232
241
|
* @property {PlaceholderIcon[]} placeholder
|
|
@@ -297,13 +306,16 @@ export type MappedIcon = {
|
|
|
297
306
|
* `match`: a reviewed
|
|
298
307
|
* `exact` or `strong` match in the project set's data names the source
|
|
299
308
|
* icon; `definition`: the target's `map` names it for the Astryx icon
|
|
300
|
-
* definition the source draws
|
|
309
|
+
* definition the source draws; `variant`: the source is already this icon
|
|
310
|
+
* of a set in the project's list, in another look, and moves to the look
|
|
311
|
+
* the project names
|
|
301
312
|
*/
|
|
302
|
-
by: "match" | "definition";
|
|
313
|
+
by: "match" | "definition" | "variant";
|
|
303
314
|
/**
|
|
304
315
|
* present when the
|
|
305
|
-
*
|
|
306
|
-
*
|
|
316
|
+
* look asked for, the project's variant or else the look the source draws,
|
|
317
|
+
* is one the target set's icon does not have: that look, and the look used
|
|
318
|
+
* (the set's default look)
|
|
307
319
|
*/
|
|
308
320
|
variant?: {
|
|
309
321
|
asked: string;
|
|
@@ -410,6 +422,11 @@ export type TemplateIconsReport = {
|
|
|
410
422
|
* project lists backups
|
|
411
423
|
*/
|
|
412
424
|
order?: string[] | undefined;
|
|
425
|
+
/**
|
|
426
|
+
* the look the project's icons draw, as
|
|
427
|
+
* `experimental.iconVariant` names it; present when it is set
|
|
428
|
+
*/
|
|
429
|
+
variant?: string | undefined;
|
|
413
430
|
reason: string;
|
|
414
431
|
mapped: MappedIcon[];
|
|
415
432
|
placeholder: PlaceholderIcon[];
|
|
@@ -32,7 +32,12 @@
|
|
|
32
32
|
* would collide with another binding in the file; a mapped default import
|
|
33
33
|
* becomes the set's named import aliased to its local name. An icon from an
|
|
34
34
|
* installed set that draws a variant (such as solid) maps to the target's
|
|
35
|
-
* variant of that name, else its default.
|
|
35
|
+
* variant of that name, else its default. When the project names a variant
|
|
36
|
+
* (`experimental.iconVariant`), every mapped icon asks for that look
|
|
37
|
+
* instead; an icon from the library the main set wraps maps to the main
|
|
38
|
+
* set's icon, and an icon from a set in the list in another look moves to
|
|
39
|
+
* that icon's export for the variant, so each draws the project's look
|
|
40
|
+
* where its set has it. With a project icon set, every
|
|
36
41
|
* declared key ends up mapped, a placeholder, or kept (FR10): an icon that
|
|
37
42
|
* draws no Astryx definition and has no match keeps its original import, and
|
|
38
43
|
* a key bound only by a namespace import, a type-only import, a re-export, an
|
|
@@ -53,8 +58,9 @@ import {
|
|
|
53
58
|
walk,
|
|
54
59
|
writtenNames,
|
|
55
60
|
} from './template-source-tree.mjs';
|
|
56
|
-
import {definitionsByIcon} from './icon-set-discovery.mjs';
|
|
61
|
+
import {definitionsByIcon, iconUseCommand} from './icon-set-discovery.mjs';
|
|
57
62
|
import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
63
|
+
import {generatedOrigins} from './icon-set-writer.mjs';
|
|
58
64
|
|
|
59
65
|
/** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
|
|
60
66
|
/** @typedef {import('./icon-set-discovery.mjs').IconSetChoice} IconSetChoice */
|
|
@@ -81,13 +87,16 @@ import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
|
81
87
|
* @property {string[]} [dropped] the library's sizing props (`size`,
|
|
82
88
|
* `strokeWidth`, `absoluteStrokeWidth`) removed from its elements: an icon
|
|
83
89
|
* set's icons take their size from CSS
|
|
84
|
-
* @property {'match' | 'definition'} by `match`: a reviewed
|
|
90
|
+
* @property {'match' | 'definition' | 'variant'} by `match`: a reviewed
|
|
85
91
|
* `exact` or `strong` match in the project set's data names the source
|
|
86
92
|
* icon; `definition`: the target's `map` names it for the Astryx icon
|
|
87
|
-
* definition the source draws
|
|
93
|
+
* definition the source draws; `variant`: the source is already this icon
|
|
94
|
+
* of a set in the project's list, in another look, and moves to the look
|
|
95
|
+
* the project names
|
|
88
96
|
* @property {{asked: string, used: string | null}} [variant] present when the
|
|
89
|
-
*
|
|
90
|
-
*
|
|
97
|
+
* look asked for, the project's variant or else the look the source draws,
|
|
98
|
+
* is one the target set's icon does not have: that look, and the look used
|
|
99
|
+
* (the set's default look)
|
|
91
100
|
*/
|
|
92
101
|
|
|
93
102
|
/**
|
|
@@ -135,6 +144,8 @@ import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
|
135
144
|
* @property {string[]} [order] the main set and each backup, as
|
|
136
145
|
* `<package>/<set>`, in the order icons are looked up; present when the
|
|
137
146
|
* project lists backups
|
|
147
|
+
* @property {string} [variant] the look the project's icons draw, as
|
|
148
|
+
* `experimental.iconVariant` names it; present when it is set
|
|
138
149
|
* @property {string} reason
|
|
139
150
|
* @property {MappedIcon[]} mapped
|
|
140
151
|
* @property {PlaceholderIcon[]} placeholder
|
|
@@ -316,15 +327,19 @@ function specifierText(entry) {
|
|
|
316
327
|
}
|
|
317
328
|
|
|
318
329
|
/**
|
|
319
|
-
* The commands that give a placeholder icon a real one.
|
|
330
|
+
* The commands that give a placeholder icon a real one. The `use` command
|
|
331
|
+
* keeps the list's backups and the project's look, and adds a backup after
|
|
332
|
+
* them.
|
|
320
333
|
* @param {string[]} definitions
|
|
321
334
|
* @param {string} main the main set's name as the list writes it
|
|
335
|
+
* @param {readonly string[]} [backups] the list's backups as it writes them
|
|
336
|
+
* @param {string | null} [variant] the project's look
|
|
322
337
|
* @returns {string[]}
|
|
323
338
|
*/
|
|
324
|
-
export function placeholderFixes(definitions, main) {
|
|
339
|
+
export function placeholderFixes(definitions, main, backups = [], variant) {
|
|
325
340
|
return [
|
|
326
341
|
`astryx experimental icon map ${definitions[0] ?? '<definition>'} <icon> --set ${main}`,
|
|
327
|
-
|
|
342
|
+
iconUseCommand(main, [...backups, '<set>'], variant),
|
|
328
343
|
];
|
|
329
344
|
}
|
|
330
345
|
|
|
@@ -435,8 +450,9 @@ export function matchIcon(source, target) {
|
|
|
435
450
|
}
|
|
436
451
|
|
|
437
452
|
/**
|
|
438
|
-
* The export a mapped icon uses: the target's variant of the
|
|
439
|
-
* variant
|
|
453
|
+
* The export a mapped icon uses: the target's variant of the name asked for
|
|
454
|
+
* (the project's variant, else the source's) when it has one, else the
|
|
455
|
+
* default.
|
|
440
456
|
* @param {IconSetIcon} icon
|
|
441
457
|
* @param {DiscoveredIconSet} set
|
|
442
458
|
* @param {string | undefined} variant
|
|
@@ -453,9 +469,10 @@ function targetExport(icon, set, variant) {
|
|
|
453
469
|
}
|
|
454
470
|
|
|
455
471
|
/**
|
|
456
|
-
* The look a mapped icon draws when the
|
|
457
|
-
*
|
|
458
|
-
*
|
|
472
|
+
* The look a mapped icon draws when the look asked for (the project's
|
|
473
|
+
* variant, else the source's) is one the target's icon does not have: what
|
|
474
|
+
* was asked for and the target's default look. Undefined when the look is
|
|
475
|
+
* kept, or when no look is asked for.
|
|
459
476
|
* @param {IconSetIcon} icon
|
|
460
477
|
* @param {DiscoveredIconSet} set
|
|
461
478
|
* @param {string | undefined} variant
|
|
@@ -471,6 +488,53 @@ function lookChange(icon, set, variant) {
|
|
|
471
488
|
return {asked: variant, used: fallback};
|
|
472
489
|
}
|
|
473
490
|
|
|
491
|
+
/**
|
|
492
|
+
* Whether an icon draws a look: its own export draws the set's default
|
|
493
|
+
* variant, and each of its `variants` one more.
|
|
494
|
+
* @param {IconSetIcon} icon
|
|
495
|
+
* @param {DiscoveredIconSet} set
|
|
496
|
+
* @param {string} variant
|
|
497
|
+
*/
|
|
498
|
+
function hasLook(icon, set, variant) {
|
|
499
|
+
return (
|
|
500
|
+
variant === set.data.default?.variant ||
|
|
501
|
+
(icon.variants ?? []).some(each => each.variant === variant)
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* The icon of a set whose export re-exports a library export, read from the
|
|
507
|
+
* set's generated module: the same artwork, in one of the set's looks.
|
|
508
|
+
* @param {DiscoveredIconSet} set
|
|
509
|
+
* @param {string} module the library module the template imports from
|
|
510
|
+
* @param {string} imported the export it imports
|
|
511
|
+
* @param {Map<DiscoveredIconSet, Map<string, string>>} read each set's
|
|
512
|
+
* exports by the library export they re-export, read once per mapping
|
|
513
|
+
* @returns {IconSetIcon | undefined}
|
|
514
|
+
*/
|
|
515
|
+
function wrappedIcon(set, module, imported, read) {
|
|
516
|
+
let byOrigin = read.get(set);
|
|
517
|
+
if (!byOrigin) {
|
|
518
|
+
byOrigin = new Map();
|
|
519
|
+
if (set.packageDir && set.data.generated) {
|
|
520
|
+
const origins = generatedOrigins(set.packageDir, set.data.generated);
|
|
521
|
+
for (const [exported, origin] of origins) {
|
|
522
|
+
if (!origin.adapt) {
|
|
523
|
+
byOrigin.set(`${origin.module}\0${origin.source}`, exported);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
read.set(set, byOrigin);
|
|
528
|
+
}
|
|
529
|
+
const exported = byOrigin.get(`${module}\0${imported}`);
|
|
530
|
+
if (!exported) return undefined;
|
|
531
|
+
return set.data.icons.find(
|
|
532
|
+
icon =>
|
|
533
|
+
icon.export === exported ||
|
|
534
|
+
(icon.variants ?? []).some(each => each.export === exported),
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
|
|
474
538
|
/**
|
|
475
539
|
* Whether a module is one of Astryx's own packages (`@astryxdesign/core`,
|
|
476
540
|
* its subpaths, and every other `@astryxdesign/` package).
|
|
@@ -835,6 +899,7 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
835
899
|
...(targets.length > 1
|
|
836
900
|
? {order: targets.map(each => `${each.package}/${each.name}`)}
|
|
837
901
|
: {}),
|
|
902
|
+
...(choice.variant ? {variant: choice.variant} : {}),
|
|
838
903
|
reason: choice.reason,
|
|
839
904
|
mapped: [],
|
|
840
905
|
placeholder: [],
|
|
@@ -843,6 +908,13 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
843
908
|
};
|
|
844
909
|
if (!target) return {source, icons};
|
|
845
910
|
const main = choice.configured ?? target.name;
|
|
911
|
+
/** The look every icon draws, when the project names one. */
|
|
912
|
+
const lookVariant = choice.variant;
|
|
913
|
+
const listedBackups = (choice.backups ?? []).map(each => each.selector);
|
|
914
|
+
/** @type {Map<DiscoveredIconSet, Map<string, string>>} */
|
|
915
|
+
const wrappedRead = new Map();
|
|
916
|
+
/** @param {SourceIcon} record the look a mapped icon asks for */
|
|
917
|
+
const askedLook = record => lookVariant ?? record.variant;
|
|
846
918
|
|
|
847
919
|
/** @type {any} */
|
|
848
920
|
let ast;
|
|
@@ -885,7 +957,7 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
885
957
|
/**
|
|
886
958
|
* The source record of each mapped import specifier, the first set in the
|
|
887
959
|
* list that matches it, and the match.
|
|
888
|
-
* @type {Map<any, {record: SourceIcon, set: DiscoveredIconSet, match:
|
|
960
|
+
* @type {Map<any, {record: SourceIcon, set: DiscoveredIconSet, match: {icon: IconSetIcon, by: 'match' | 'definition' | 'variant'} | null}>}
|
|
889
961
|
*/
|
|
890
962
|
const planned = new Map();
|
|
891
963
|
/**
|
|
@@ -894,11 +966,41 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
894
966
|
* @type {Map<any, DiscoveredIconSet>}
|
|
895
967
|
*/
|
|
896
968
|
const wrapped = new Map();
|
|
969
|
+
/**
|
|
970
|
+
* Plan each icon a template imports from a set in the list in another look
|
|
971
|
+
* than the project's variant: it moves to that icon's export for the
|
|
972
|
+
* variant, when the icon has one, and otherwise keeps its import.
|
|
973
|
+
* @param {any} node an import declaration from a set in the list
|
|
974
|
+
* @param {string} module
|
|
975
|
+
*/
|
|
976
|
+
const planLookMoves = (node, module) => {
|
|
977
|
+
for (const specifier of node.specifiers) {
|
|
978
|
+
if (
|
|
979
|
+
specifier.type === 'ImportNamespaceSpecifier' ||
|
|
980
|
+
specifier.importKind === 'type'
|
|
981
|
+
) {
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
const record = index.get(`${module}\0${importedName(specifier)}`);
|
|
985
|
+
const set = record?.set;
|
|
986
|
+
if (!record || !set || !targets.includes(set)) continue;
|
|
987
|
+
if (record.variant === lookVariant) continue;
|
|
988
|
+
const icon = set.data.icons.find(each => each.id === record.id);
|
|
989
|
+
if (!icon || !hasLook(icon, set, /** @type {string} */ (lookVariant))) {
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
planned.set(specifier, {record, set, match: {icon, by: 'variant'}});
|
|
993
|
+
freed.add(specifier.local.name);
|
|
994
|
+
}
|
|
995
|
+
};
|
|
897
996
|
for (const node of ast.program.body) {
|
|
898
997
|
if (node.type !== 'ImportDeclaration' || node.importKind === 'type')
|
|
899
998
|
continue;
|
|
900
999
|
const module = node.source.value;
|
|
901
|
-
if (targetModules.has(module))
|
|
1000
|
+
if (targetModules.has(module)) {
|
|
1001
|
+
if (lookVariant) planLookMoves(node, module);
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
902
1004
|
for (const specifier of node.specifiers) {
|
|
903
1005
|
if (
|
|
904
1006
|
specifier.type === 'ImportNamespaceSpecifier' ||
|
|
@@ -937,21 +1039,31 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
937
1039
|
if (!record || (record.set && targets.includes(record.set))) continue;
|
|
938
1040
|
// An import from the library a listed set wraps is already an icon
|
|
939
1041
|
// the project chose. The main set's own library keeps its icons as
|
|
940
|
-
// written; another set's library keeps an icon that no set maps.
|
|
1042
|
+
// written; another set's library keeps an icon that no set maps. With
|
|
1043
|
+
// a project variant, an icon from the main set's library maps to the
|
|
1044
|
+
// main set's icon, so it draws that look: the icon its `map` names, or
|
|
1045
|
+
// else the icon that re-exports the same library export when that icon
|
|
1046
|
+
// draws the look. Otherwise it keeps its import.
|
|
941
1047
|
const wrapper = targets.find(each => wrapsModule(each, module));
|
|
942
|
-
if (wrapper === target) {
|
|
1048
|
+
if (wrapper === target && !lookVariant) {
|
|
943
1049
|
wrapped.set(specifier, wrapper);
|
|
944
1050
|
continue;
|
|
945
1051
|
}
|
|
946
|
-
/** @type {{set: DiscoveredIconSet, match:
|
|
1052
|
+
/** @type {{set: DiscoveredIconSet, match: {icon: IconSetIcon, by: 'match' | 'definition' | 'variant'} | null}} */
|
|
947
1053
|
let found = {set: target, match: null};
|
|
948
|
-
for (const each of targets) {
|
|
1054
|
+
for (const each of wrapper === target ? [target] : targets) {
|
|
949
1055
|
const match = matchIcon(record, each);
|
|
950
1056
|
if (match) {
|
|
951
1057
|
found = {set: each, match};
|
|
952
1058
|
break;
|
|
953
1059
|
}
|
|
954
1060
|
}
|
|
1061
|
+
if (!found.match && wrapper === target && lookVariant) {
|
|
1062
|
+
const icon = wrappedIcon(target, module, record.export, wrappedRead);
|
|
1063
|
+
if (icon && hasLook(icon, target, lookVariant)) {
|
|
1064
|
+
found = {set: target, match: {icon, by: 'variant'}};
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
955
1067
|
if (!found.match && wrapper) {
|
|
956
1068
|
wrapped.set(specifier, wrapper);
|
|
957
1069
|
continue;
|
|
@@ -975,7 +1087,6 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
975
1087
|
if (node.type !== 'ImportDeclaration') continue;
|
|
976
1088
|
if (node.importKind === 'type') continue;
|
|
977
1089
|
const module = node.source.value;
|
|
978
|
-
if (targetModules.has(module)) continue;
|
|
979
1090
|
if (!node.specifiers.some((/** @type {any} */ each) => planned.has(each))) {
|
|
980
1091
|
continue;
|
|
981
1092
|
}
|
|
@@ -1012,13 +1123,18 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
1012
1123
|
source: {module, export: imported},
|
|
1013
1124
|
target: {local: placeholderName},
|
|
1014
1125
|
definitions: record.definitions,
|
|
1015
|
-
fixes: placeholderFixes(
|
|
1126
|
+
fixes: placeholderFixes(
|
|
1127
|
+
record.definitions,
|
|
1128
|
+
main,
|
|
1129
|
+
listedBackups,
|
|
1130
|
+
lookVariant,
|
|
1131
|
+
),
|
|
1016
1132
|
...(likely
|
|
1017
1133
|
? {
|
|
1018
1134
|
suggestion: {
|
|
1019
1135
|
set: target.name,
|
|
1020
1136
|
id: likely.id,
|
|
1021
|
-
...targetExport(likely, target, record
|
|
1137
|
+
...targetExport(likely, target, askedLook(record)),
|
|
1022
1138
|
confidence: /** @type {const} */ ('likely'),
|
|
1023
1139
|
},
|
|
1024
1140
|
}
|
|
@@ -1043,7 +1159,7 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
1043
1159
|
suggestion: {
|
|
1044
1160
|
set: target.name,
|
|
1045
1161
|
id: likely.id,
|
|
1046
|
-
...targetExport(likely, target, record
|
|
1162
|
+
...targetExport(likely, target, askedLook(record)),
|
|
1047
1163
|
confidence: /** @type {const} */ ('likely'),
|
|
1048
1164
|
},
|
|
1049
1165
|
}
|
|
@@ -1051,8 +1167,8 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
1051
1167
|
});
|
|
1052
1168
|
continue;
|
|
1053
1169
|
}
|
|
1054
|
-
const chosen = targetExport(match.icon, set, record
|
|
1055
|
-
const look = lookChange(match.icon, set, record
|
|
1170
|
+
const chosen = targetExport(match.icon, set, askedLook(record));
|
|
1171
|
+
const look = lookChange(match.icon, set, askedLook(record));
|
|
1056
1172
|
const key = `${chosen.module}\0${chosen.export}`;
|
|
1057
1173
|
let entry = added.get(key);
|
|
1058
1174
|
if (!entry) {
|
|
@@ -67,6 +67,25 @@ export function readThemeDescriptorValue(docPath: string, label: string): Record
|
|
|
67
67
|
export function readStaticDescriptorValue(docPath: string, label: string, typeName: string, { data }?: {
|
|
68
68
|
data?: boolean;
|
|
69
69
|
}): Record<string, any>;
|
|
70
|
+
/**
|
|
71
|
+
* Where a descriptor's statically read value is stored at publish: by the
|
|
72
|
+
* hash of its text, the type it is read as, and whether plain data counts.
|
|
73
|
+
* @param {string} source
|
|
74
|
+
* @param {string} typeName
|
|
75
|
+
* @param {boolean} data
|
|
76
|
+
* @returns {string}
|
|
77
|
+
*/
|
|
78
|
+
export function descriptorStoreKey(source: string, typeName: string, data: boolean): string;
|
|
79
|
+
/**
|
|
80
|
+
* The static value a descriptor's source default-exports (see
|
|
81
|
+
* {@link readStaticDescriptorValue}); throws when it is not one.
|
|
82
|
+
* @param {string} source
|
|
83
|
+
* @param {string} label
|
|
84
|
+
* @param {string} typeName
|
|
85
|
+
* @param {boolean} [data]
|
|
86
|
+
* @returns {Record<string, any>}
|
|
87
|
+
*/
|
|
88
|
+
export function readDescriptorSource(source: string, label: string, typeName: string, data?: boolean): Record<string, any>;
|
|
70
89
|
/**
|
|
71
90
|
* Whether an entry at any depth of a themes root is outside every theme: a dot
|
|
72
91
|
* entry, or a name npm never publishes (npm-packlist's defaults).
|
|
@@ -154,6 +173,12 @@ export const THEME_DOC_SUFFIX: ".doc.mjs";
|
|
|
154
173
|
export { THEME_MODULE_EXTENSIONS };
|
|
155
174
|
/** A theme directory's name: lower-kebab, starting with a letter. */
|
|
156
175
|
export const THEME_SLUG_RE: RegExp;
|
|
176
|
+
/**
|
|
177
|
+
* The typed descriptors read statically, each with whether plain data is
|
|
178
|
+
* accepted: what scripts/generate-stored-docs.mjs reads at publish.
|
|
179
|
+
* @type {ReadonlyArray<[string, boolean]>}
|
|
180
|
+
*/
|
|
181
|
+
export const STATIC_DESCRIPTOR_TYPES: ReadonlyArray<[string, boolean]>;
|
|
157
182
|
export type DiscoveredTheme = {
|
|
158
183
|
slug: string;
|
|
159
184
|
displayName: string;
|
|
@@ -29,6 +29,11 @@ import {LOCAL_THEME_ROOT} from '../config/theme-state.mjs';
|
|
|
29
29
|
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
30
30
|
import {THEME_MODULE_EXTENSIONS} from './theme-module-extensions.mjs';
|
|
31
31
|
import {babelParser, jscodeshift} from '../runtime/lazy-dependencies.mjs';
|
|
32
|
+
import {
|
|
33
|
+
readStore,
|
|
34
|
+
storedKey,
|
|
35
|
+
STORED_DOCS_FILE,
|
|
36
|
+
} from '../doc-compiler/stored-docs.mjs';
|
|
32
37
|
|
|
33
38
|
export const BUNDLED_THEME_PACKAGE = '@astryxdesign/cli';
|
|
34
39
|
export const THEMES_DIR = path.join(CLI_ROOT, 'assets', 'templates', 'themes');
|
|
@@ -677,13 +682,24 @@ export function readStaticDescriptorValue(
|
|
|
677
682
|
/** @type {{value: Record<string, any>} | {error: unknown}} */
|
|
678
683
|
let read;
|
|
679
684
|
try {
|
|
685
|
+
const source = fs.readFileSync(docPath, 'utf-8');
|
|
686
|
+
// A descriptor Astryx ships was read at publish, by the hash of its
|
|
687
|
+
// text (scripts/generate-stored-docs.mjs): the same text reads the
|
|
688
|
+
// same value without parsing. Any other text, or a store that cannot
|
|
689
|
+
// be read, is parsed.
|
|
690
|
+
let stored;
|
|
691
|
+
try {
|
|
692
|
+
stored = readStore(STORED_DOCS_FILE).get(
|
|
693
|
+
descriptorStoreKey(source, typeName, data),
|
|
694
|
+
);
|
|
695
|
+
} catch {
|
|
696
|
+
stored = undefined;
|
|
697
|
+
}
|
|
680
698
|
read = {
|
|
681
|
-
value:
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
data,
|
|
686
|
-
),
|
|
699
|
+
value:
|
|
700
|
+
stored != null && typeof stored === 'object'
|
|
701
|
+
? stored
|
|
702
|
+
: readDescriptorSource(source, label, typeName, data),
|
|
687
703
|
};
|
|
688
704
|
} catch (error) {
|
|
689
705
|
read = {error};
|
|
@@ -696,13 +712,38 @@ export function readStaticDescriptorValue(
|
|
|
696
712
|
}
|
|
697
713
|
|
|
698
714
|
/**
|
|
715
|
+
* The typed descriptors read statically, each with whether plain data is
|
|
716
|
+
* accepted: what scripts/generate-stored-docs.mjs reads at publish.
|
|
717
|
+
* @type {ReadonlyArray<[string, boolean]>}
|
|
718
|
+
*/
|
|
719
|
+
export const STATIC_DESCRIPTOR_TYPES = [
|
|
720
|
+
['ThemeDoc', false],
|
|
721
|
+
['IconSetDoc', false],
|
|
722
|
+
['IconDefinitionDoc', true],
|
|
723
|
+
];
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Where a descriptor's statically read value is stored at publish: by the
|
|
727
|
+
* hash of its text, the type it is read as, and whether plain data counts.
|
|
728
|
+
* @param {string} source
|
|
729
|
+
* @param {string} typeName
|
|
730
|
+
* @param {boolean} data
|
|
731
|
+
* @returns {string}
|
|
732
|
+
*/
|
|
733
|
+
export function descriptorStoreKey(source, typeName, data) {
|
|
734
|
+
return `descriptor:${typeName}:${data ? 'data' : 'object'}:${storedKey(source)}`;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* The static value a descriptor's source default-exports (see
|
|
739
|
+
* {@link readStaticDescriptorValue}); throws when it is not one.
|
|
699
740
|
* @param {string} source
|
|
700
741
|
* @param {string} label
|
|
701
742
|
* @param {string} typeName
|
|
702
743
|
* @param {boolean} [data]
|
|
703
744
|
* @returns {Record<string, any>}
|
|
704
745
|
*/
|
|
705
|
-
function readDescriptorSource(source, label, typeName, data = false) {
|
|
746
|
+
export function readDescriptorSource(source, label, typeName, data = false) {
|
|
706
747
|
/** @type {any} */
|
|
707
748
|
let ast;
|
|
708
749
|
try {
|