@astryxdesign/cli 0.7.11 → 0.7.12-canary.0085c0f
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/build/blocks/blocks.d.mts +41 -0
- package/api/build/blocks/blocks.mjs +118 -68
- package/api/build/kit/rank.mjs +21 -4
- package/api/build/kit/words.d.mts +1 -0
- package/api/build/kit/words.mjs +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -5
- package/api/docs/_adapter.d.mts +22 -0
- package/api/docs/_adapter.mjs +81 -3
- package/api/docs/docs.doc.mjs +5 -5
- package/api/docs/docs.type.d.mts +21 -0
- package/api/docs/docs.type.mjs +11 -0
- package/api/docs/list/list.d.mts +5 -1
- package/api/docs/list/list.mjs +72 -6
- package/api/docs/node/node.mjs +2 -40
- package/api/doctor/doctor.d.mts +4 -4
- package/api/doctor/doctor.mjs +248 -78
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +8 -2
- package/api/icon/_authoring.d.mts +1 -0
- package/api/icon/_authoring.mjs +594 -67
- package/api/icon/_default-look.d.mts +155 -0
- package/api/icon/_default-look.mjs +474 -0
- package/api/icon/_records.d.mts +1 -1
- package/api/icon/_records.mjs +1 -0
- package/api/icon/add/add.mjs +269 -43
- package/api/icon/icon.type.d.mts +46 -2
- package/api/icon/icon.type.mjs +12 -2
- package/api/icon/iconAdd.doc.mjs +2 -2
- package/api/icon/iconNewDefinition.doc.mjs +3 -2
- package/api/icon/iconNewSet.doc.mjs +4 -4
- package/api/icon/map/map.mjs +11 -4
- package/api/icon/search/search.mjs +10 -9
- package/api/index.d.mts +1 -0
- package/api/index.mjs +1 -0
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +5 -2
- package/api/integration/authoring-checks.d.mts +0 -2
- package/api/integration/authoring-checks.mjs +1 -6
- package/api/logger.mjs +2 -1
- package/api/render/_adapter.mjs +9 -0
- package/api/render/render.doc.mjs +3 -3
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/search/ORDERING.md +3 -0
- package/api/search/_adapter.d.mts +32 -3
- package/api/search/_adapter.mjs +50 -22
- package/api/search/_fit-order.d.mts +47 -0
- package/api/search/_fit-order.mjs +257 -0
- package/api/search/_main-searcher.mjs +15 -5
- package/api/search/exportSearchIndex.doc.d.mts +10 -0
- package/api/search/exportSearchIndex.doc.mjs +58 -0
- package/api/search/rankSearchIndex.doc.d.mts +10 -0
- package/api/search/rankSearchIndex.doc.mjs +79 -0
- package/api/search/search-index.d.mts +44 -0
- package/api/search/search-index.mjs +270 -0
- package/api/search/search.type.d.mts +28 -0
- package/api/search/search.type.mjs +17 -0
- package/api/swizzle/_adapter.d.mts +1 -0
- package/api/swizzle/_adapter.mjs +4 -1
- package/api/swizzle/_moduleGraph.d.mts +178 -0
- package/api/swizzle/_moduleGraph.mjs +903 -0
- package/api/swizzle/copy/copy.d.mts +2 -43
- package/api/swizzle/copy/copy.mjs +287 -315
- package/api/swizzle/swizzle.d.mts +0 -2
- package/api/swizzle/swizzle.doc.mjs +13 -4
- package/api/swizzle/swizzle.mjs +3 -7
- package/api/swizzle/swizzle.type.d.mts +7 -1
- package/api/swizzle/swizzle.type.mjs +4 -2
- package/api/template/skeleton/skeleton.mjs +1 -1
- package/api/template/template.mjs +1 -0
- package/assets/codemods/transforms/v0.1.0/drop-xds-prefix-imports.mjs +1 -1
- package/assets/codemods/transforms/v0.1.0/index.mjs +1 -1
- package/assets/discover/official-packages.json +40 -0
- package/assets/docs/browser-support.doc.mjs +2 -2
- package/assets/docs/styling-overview.doc.mjs +6 -2
- package/assets/docs/tree/icon-sets.doc.mjs +13 -7
- package/assets/docs/tree/render-pages.doc.mjs +3 -3
- package/assets/docs/tree/tailwind.doc.mjs +41 -1
- package/assets/docs/tree/type-scale.doc.mjs +19 -2
- package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.tsx +146 -0
- package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.tsx +173 -0
- package/assets/templates/blocks/components/Hooks/useInputStatusIconHookUsage.tsx +1 -0
- package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.tsx +56 -0
- package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.doc.mjs +2 -2
- package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +66 -10
- package/assets/templates/blocks/components/Link/useLinkifyHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkifyHookUsage.tsx +39 -0
- package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsx +83 -0
- package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.tsx +41 -0
- package/assets/templates/blocks/components/Table/TableRowIndexTable.doc.mjs +1 -1
- package/assets/templates/blocks/components/Table/TableRowIndexTable.tsx +2 -2
- package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.tsx +97 -0
- package/assets/templates/pages/course-detail/page.tsx +699 -0
- package/assets/templates/pages/course-detail/template.doc.mjs +37 -0
- package/assets/templates/pages/file-explorer/page.tsx +103 -79
- package/assets/templates/pages/table-filter/page.tsx +15 -23
- package/assets/templates/pages/table-grouped/page.tsx +190 -262
- package/assets/templates/pages/table-grouped/template.doc.mjs +0 -2
- package/assets/templates/pages/table-inbox/page.tsx +3 -6
- package/assets/templates/pages/theme-showcase/page.tsx +724 -792
- package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
- package/assets/templates/themes/butter/butterTheme.ts +2 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +16 -0
- package/assets/templates/themes/matcha/matchaTheme.ts +1 -1
- package/assets/templates/themes/neutral/neutralTheme.ts +6 -0
- package/assets/templates/themes/stone/stoneTheme.ts +1 -1
- package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/y2k/y2kTheme.ts +2 -2
- package/authoring/doctypes/template/type.ts +1 -0
- package/clients/cli/commands/docs.doc.mjs +5 -1
- package/clients/cli/commands/docs.mjs +30 -2
- package/clients/cli/commands/experimental/icon.mjs +56 -14
- package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-render.doc.mjs +1 -1
- package/clients/cli/commands/swizzle.doc.mjs +12 -3
- package/clients/cli/commands/swizzle.mjs +33 -9
- package/clients/cli/commands/template.mjs +204 -181
- package/clients/cli/lib/resolve-theme.mjs +16 -7
- package/foundation/discovery/component-discovery.mjs +1 -1
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/doc-types.mjs +9 -2
- package/foundation/discovery/hook-discovery.mjs +31 -8
- package/foundation/discovery/icon-ranking.d.mts +27 -3
- package/foundation/discovery/icon-ranking.mjs +125 -8
- package/foundation/discovery/icon-set-checks.mjs +44 -35
- package/foundation/discovery/icon-set-discovery.d.mts +13 -0
- package/foundation/discovery/icon-set-discovery.mjs +25 -0
- package/foundation/discovery/icon-set-writer.d.mts +258 -20
- package/foundation/discovery/icon-set-writer.mjs +785 -87
- package/foundation/discovery/module-exports.d.mts +3 -2
- package/foundation/discovery/module-exports.mjs +167 -37
- package/foundation/discovery/template-adapter.mjs +2 -2
- package/foundation/doc-compiler/import.d.mts +5 -1
- package/foundation/doc-compiler/import.mjs +40 -6
- package/foundation/fs/import-url.d.mts +20 -0
- package/foundation/fs/import-url.mjs +22 -0
- package/foundation/fs/module-loader.d.mts +24 -3
- package/foundation/fs/module-loader.mjs +69 -47
- package/foundation/fs/paths.d.mts +2 -1
- package/foundation/fs/paths.mjs +3 -4
- package/foundation/render/charts.d.mts +59 -0
- package/foundation/render/charts.mjs +216 -0
- package/foundation/render/embedded-imports.d.mts +7 -7
- package/foundation/render/embedded-imports.mjs +63 -54
- package/foundation/render/page-host.d.mts +4 -0
- package/foundation/render/page-host.mjs +45 -0
- package/foundation/render/page-worker.mjs +350 -57
- package/foundation/render/render-page.d.mts +11 -6
- package/foundation/render/render-page.mjs +164 -54
- package/foundation/render/ts-paths.d.mts +63 -0
- package/foundation/render/ts-paths.mjs +138 -0
- package/foundation/response/error-codes.doc.mjs +3 -3
- package/foundation/response/error-codes.mjs +3 -2
- package/foundation/text/levenshtein.d.mts +6 -1
- package/foundation/text/levenshtein.mjs +25 -9
- package/foundation/text/shell-arg.d.mts +14 -0
- package/foundation/text/shell-arg.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +8 -1
- package/foundation/text/suggest-order.mjs +72 -6
- package/foundation/xle/registry-core.mjs +1 -1
- package/package.json +7 -6
package/api/icon/add/add.mjs
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
astryxIconDefinitions,
|
|
32
32
|
authoring,
|
|
33
33
|
checkNewDefinition,
|
|
34
|
+
definitionNameFromInput,
|
|
34
35
|
closestNames,
|
|
35
36
|
findLocalIconSet,
|
|
36
37
|
iconIdOf,
|
|
@@ -40,12 +41,19 @@ import {
|
|
|
40
41
|
generatedNamesOf,
|
|
41
42
|
generatedOrigins,
|
|
42
43
|
iconModulePackage,
|
|
43
|
-
iconNaming,
|
|
44
44
|
localSourceNote,
|
|
45
45
|
definitionNameOf,
|
|
46
46
|
libraryIcons,
|
|
47
|
-
|
|
47
|
+
moduleNaming,
|
|
48
|
+
iconNamingWithoutLook,
|
|
49
|
+
iconNaming,
|
|
50
|
+
iconExportName,
|
|
51
|
+
sameIconModule,
|
|
52
|
+
splitLook,
|
|
48
53
|
variantExportName,
|
|
54
|
+
answeringMatches,
|
|
55
|
+
checkVariantLook,
|
|
56
|
+
drawnLooks,
|
|
49
57
|
rankIcons,
|
|
50
58
|
resolveIconSource,
|
|
51
59
|
setModuleNote,
|
|
@@ -56,6 +64,8 @@ import {
|
|
|
56
64
|
refuseOutsideProject,
|
|
57
65
|
} from '../_adapter.mjs';
|
|
58
66
|
import {passed, refuseIgnoredPairs} from '../_options.mjs';
|
|
67
|
+
import {logger} from '../../logger.mjs';
|
|
68
|
+
import {shellArg} from '../../../foundation/text/shell-arg.mjs';
|
|
59
69
|
|
|
60
70
|
/** The lowest score a definition match needs: an exact word or name. */
|
|
61
71
|
const FIT_FLOOR = 80;
|
|
@@ -79,7 +89,7 @@ export async function iconAdd(exportName, options) {
|
|
|
79
89
|
from,
|
|
80
90
|
set: selector,
|
|
81
91
|
definition: givenDefinition,
|
|
82
|
-
newDefinition,
|
|
92
|
+
newDefinition: givenNewDefinition,
|
|
83
93
|
description,
|
|
84
94
|
words,
|
|
85
95
|
useDefault = false,
|
|
@@ -88,6 +98,11 @@ export async function iconAdd(exportName, options) {
|
|
|
88
98
|
all = false,
|
|
89
99
|
} = options ?? {};
|
|
90
100
|
refuseOutsideProject(cwd, 'experimental icon add', 'the icon-set package');
|
|
101
|
+
// The docs' kebab-case (`ai-helper`) names the same new definition.
|
|
102
|
+
const newDefinition =
|
|
103
|
+
givenNewDefinition == null
|
|
104
|
+
? undefined
|
|
105
|
+
: definitionNameFromInput(givenNewDefinition);
|
|
91
106
|
// `--all` adds a declared variant to existing icons, so it names no icon
|
|
92
107
|
// and maps nothing; a description and words describe only a new
|
|
93
108
|
// definition (spec:AST-042 FR5).
|
|
@@ -132,6 +147,15 @@ export async function iconAdd(exportName, options) {
|
|
|
132
147
|
);
|
|
133
148
|
}
|
|
134
149
|
}
|
|
150
|
+
// An export name cannot start with a digit, and an id the author gives has
|
|
151
|
+
// no library prefix to keep.
|
|
152
|
+
if (givenId != null && /^[0-9]/u.test(givenId)) {
|
|
153
|
+
throw new AstryxError(
|
|
154
|
+
`The icon id "${givenId}" starts with a digit, and an export name cannot. Pass --id with an id that starts with a letter.`,
|
|
155
|
+
undefined,
|
|
156
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
135
159
|
if (all) {
|
|
136
160
|
return authoring(() => addVariantForAll({cwd, from, selector, variant}));
|
|
137
161
|
}
|
|
@@ -177,14 +201,21 @@ export async function iconAdd(exportName, options) {
|
|
|
177
201
|
const generated = generatedModulePath(set, packageDir);
|
|
178
202
|
const module = set.data.module;
|
|
179
203
|
// A library prefix every icon export shares (`feather` in `featherEye`)
|
|
180
|
-
// is left out of the id and the set's export name, as the bulk wrap does
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
|
|
204
|
+
// is left out of the id and the set's export name, as the bulk wrap does,
|
|
205
|
+
// and so are the look words a library's names end in (`Outline24WGHT500`
|
|
206
|
+
// in `XOutline24WGHT500Icon`). A ./ path is the author's own files, named
|
|
207
|
+
// as written: never a library prefix (`CheckDouble` and
|
|
208
|
+
// `CheckDoubleSolid` share `check`).
|
|
209
|
+
const libraryNaming =
|
|
184
210
|
useDefault || source.module.startsWith('./')
|
|
185
|
-
? []
|
|
186
|
-
:
|
|
211
|
+
? {prefix: [], positions: []}
|
|
212
|
+
: moduleNaming(source.file, {
|
|
213
|
+
adapter: Boolean(set.data.adapter),
|
|
214
|
+
module: source.module,
|
|
215
|
+
progress: line => logger.warn(line),
|
|
216
|
+
});
|
|
187
217
|
const nameWords = iconIdOf(exportName).split('-');
|
|
218
|
+
const shared = libraryNaming.prefix;
|
|
188
219
|
const prefix =
|
|
189
220
|
shared.length > 0 &&
|
|
190
221
|
nameWords.length > shared.length &&
|
|
@@ -199,11 +230,32 @@ export async function iconAdd(exportName, options) {
|
|
|
199
230
|
sourceExport,
|
|
200
231
|
);
|
|
201
232
|
const known = set.data.icons.find(each => already.includes(each.export));
|
|
202
|
-
const
|
|
233
|
+
const glyph = known
|
|
203
234
|
? {id: known.id, name: known.export}
|
|
204
|
-
:
|
|
205
|
-
|
|
235
|
+
: iconNamingWithoutLook(exportName, {
|
|
236
|
+
prefix,
|
|
237
|
+
positions: libraryNaming.positions,
|
|
238
|
+
});
|
|
206
239
|
const asVariant = variant != null;
|
|
240
|
+
// The set may already export the glyph's name for another export of the
|
|
241
|
+
// library (its outline look, when this is the filled one). This export
|
|
242
|
+
// then keeps its look words in its id and name, or takes its name from
|
|
243
|
+
// --id, and the listing offers it as a variant of that icon instead.
|
|
244
|
+
const origin = generatedOrigins(packageDir, generated).get(glyph.name);
|
|
245
|
+
const glyphTaken =
|
|
246
|
+
!known &&
|
|
247
|
+
!asVariant &&
|
|
248
|
+
origin != null &&
|
|
249
|
+
!(
|
|
250
|
+
sameIconModule(origin.module, source.module) &&
|
|
251
|
+
origin.source === sourceExport
|
|
252
|
+
);
|
|
253
|
+
const naming = !glyphTaken
|
|
254
|
+
? glyph
|
|
255
|
+
: givenId != null
|
|
256
|
+
? {id: givenId, name: nameFromId(givenId)}
|
|
257
|
+
: iconNaming(exportName, prefix);
|
|
258
|
+
const id = givenId ?? naming.id;
|
|
207
259
|
// The name the set exports it as: `<Name>Icon`, or for a variant the
|
|
208
260
|
// icon's name with the variant's name.
|
|
209
261
|
const baseIcon = set.data.icons.find(each => each.id === id);
|
|
@@ -219,7 +271,20 @@ export async function iconAdd(exportName, options) {
|
|
|
219
271
|
}
|
|
220
272
|
|
|
221
273
|
if (definition == null && newDefinition == null && !asVariant) {
|
|
222
|
-
return definitionMatches(set, exportName, from, id
|
|
274
|
+
return definitionMatches(set, exportName, from, id, {
|
|
275
|
+
useDefault,
|
|
276
|
+
id: givenId,
|
|
277
|
+
look:
|
|
278
|
+
glyphTaken && origin != null
|
|
279
|
+
? lookVariantOf(
|
|
280
|
+
iconNaming(exportName, prefix).id,
|
|
281
|
+
iconNaming(origin.source, prefix).id,
|
|
282
|
+
libraryNaming.positions,
|
|
283
|
+
set,
|
|
284
|
+
)
|
|
285
|
+
: null,
|
|
286
|
+
glyphId: glyph.id,
|
|
287
|
+
});
|
|
223
288
|
}
|
|
224
289
|
|
|
225
290
|
/** @type {{name: string, description: string, words: string[]} | null} */
|
|
@@ -250,7 +315,7 @@ export async function iconAdd(exportName, options) {
|
|
|
250
315
|
}),
|
|
251
316
|
),
|
|
252
317
|
{
|
|
253
|
-
name: `--new-definition ${definition} --description '<what it is for>' --words a,b`,
|
|
318
|
+
name: `--new-definition ${definitionNameFromInput(definition)} --description '<what it is for>' --words a,b`,
|
|
254
319
|
reason: 'add it as your own definition',
|
|
255
320
|
},
|
|
256
321
|
],
|
|
@@ -262,6 +327,15 @@ export async function iconAdd(exportName, options) {
|
|
|
262
327
|
const icons = set.data.icons.map(each => ({...each}));
|
|
263
328
|
const existing = icons.find(each => each.id === id);
|
|
264
329
|
if (asVariant) {
|
|
330
|
+
checkVariantLook({
|
|
331
|
+
set,
|
|
332
|
+
variant,
|
|
333
|
+
module: source.module,
|
|
334
|
+
positions: libraryNaming.positions,
|
|
335
|
+
drawn: drawnLooks(set, packageDir, each =>
|
|
336
|
+
sameIconModule(each, source.module) ? libraryNaming.positions : null,
|
|
337
|
+
),
|
|
338
|
+
});
|
|
265
339
|
if (!existing) {
|
|
266
340
|
throw new AstryxError(
|
|
267
341
|
`Icon set "${set.name}" has no icon "${id}" to add a variant to. Add the icon first, or pass --id.`,
|
|
@@ -275,6 +349,18 @@ export async function iconAdd(exportName, options) {
|
|
|
275
349
|
ERROR_CODES.ERR_NOT_FOUND,
|
|
276
350
|
);
|
|
277
351
|
}
|
|
352
|
+
const own = generatedOrigins(packageDir, generated).get(existing.export);
|
|
353
|
+
if (
|
|
354
|
+
own != null &&
|
|
355
|
+
own.source === sourceExport &&
|
|
356
|
+
sameIconModule(own.module, source.module)
|
|
357
|
+
) {
|
|
358
|
+
throw new AstryxError(
|
|
359
|
+
`"${sourceExport}" is icon "${id}"'s own export, which draws its default look, so it can't be its ${variant} variant too.`,
|
|
360
|
+
undefined,
|
|
361
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
362
|
+
);
|
|
363
|
+
}
|
|
278
364
|
const variants = [...(existing.variants ?? [])];
|
|
279
365
|
const same = variants.find(each => each.export === setName);
|
|
280
366
|
if (!same) {
|
|
@@ -309,6 +395,8 @@ export async function iconAdd(exportName, options) {
|
|
|
309
395
|
map,
|
|
310
396
|
icons,
|
|
311
397
|
};
|
|
398
|
+
const dataChanged =
|
|
399
|
+
JSON.stringify(next) !== JSON.stringify(set.data) || where.moduleRenamed;
|
|
312
400
|
/** @type {string[]} */
|
|
313
401
|
const files = [];
|
|
314
402
|
// Every write happens inside this try, so any failure undoes the ones
|
|
@@ -336,7 +424,7 @@ export async function iconAdd(exportName, options) {
|
|
|
336
424
|
.join('/'),
|
|
337
425
|
);
|
|
338
426
|
}
|
|
339
|
-
if (
|
|
427
|
+
if (dataChanged) {
|
|
340
428
|
writeIconSetData(set, next, {
|
|
341
429
|
extraDefinitions: created ? [created.name] : [],
|
|
342
430
|
});
|
|
@@ -356,10 +444,12 @@ export async function iconAdd(exportName, options) {
|
|
|
356
444
|
}
|
|
357
445
|
throw error;
|
|
358
446
|
}
|
|
359
|
-
|
|
447
|
+
// A renamed package's new name alone is not an added icon.
|
|
448
|
+
const added =
|
|
360
449
|
JSON.stringify(next) !== JSON.stringify(set.data) ||
|
|
361
450
|
created != null ||
|
|
362
451
|
generatedChanged;
|
|
452
|
+
const changed = dataChanged || added;
|
|
363
453
|
// A ./ file publishes only when package.json `files` lists it; the
|
|
364
454
|
// author adds it (architecture:cli-surface INV16).
|
|
365
455
|
const note =
|
|
@@ -380,6 +470,8 @@ export async function iconAdd(exportName, options) {
|
|
|
380
470
|
...(created ? {newDefinition: created.name} : {}),
|
|
381
471
|
files,
|
|
382
472
|
changed,
|
|
473
|
+
added,
|
|
474
|
+
...(where.moduleUpdate ? {moduleUpdate: where.moduleUpdate} : {}),
|
|
383
475
|
...(note ? {note} : {}),
|
|
384
476
|
},
|
|
385
477
|
};
|
|
@@ -394,9 +486,13 @@ export async function iconAdd(exportName, options) {
|
|
|
394
486
|
* @param {string} exportName
|
|
395
487
|
* @param {string} from
|
|
396
488
|
* @param {string} id
|
|
489
|
+
* @param {{useDefault?: boolean, id?: string, look?: string | null, glyphId?: string}} passed the
|
|
490
|
+
* options the author passed, repeated in each listed command so it runs as
|
|
491
|
+
* printed; `look`, when the set already has an icon for the export's
|
|
492
|
+
* glyph (`glyphId`): the variant it is of that icon
|
|
397
493
|
* @returns {import('../icon.type.mjs').IconDefinitionMatchesResponse}
|
|
398
494
|
*/
|
|
399
|
-
function definitionMatches(set, exportName, from, id) {
|
|
495
|
+
function definitionMatches(set, exportName, from, id, passed = {}) {
|
|
400
496
|
const astryx = astryxIconDefinitions().definitions.map(each => ({
|
|
401
497
|
doc: each.doc,
|
|
402
498
|
source: /** @type {const} */ ('astryx'),
|
|
@@ -432,14 +528,19 @@ function definitionMatches(set, exportName, from, id) {
|
|
|
432
528
|
/** @type {Map<string, {score: number, reason: string}>} */
|
|
433
529
|
const best = new Map();
|
|
434
530
|
for (const query of queries) {
|
|
435
|
-
for (const match of rankIcons([asSet], query)) {
|
|
531
|
+
for (const match of answeringMatches(rankIcons([asSet], query))) {
|
|
436
532
|
const prior = best.get(match.export);
|
|
437
533
|
if (!prior || match.score > prior.score) {
|
|
438
534
|
best.set(match.export, {score: match.score, reason: match.reason});
|
|
439
535
|
}
|
|
440
536
|
}
|
|
441
537
|
}
|
|
442
|
-
const base =
|
|
538
|
+
const base = [
|
|
539
|
+
`astryx experimental icon add ${exportName} --from ${shellArg(from)}`,
|
|
540
|
+
`--set ${shellArg(set.name)}`,
|
|
541
|
+
...(passed.useDefault ? ['--default'] : []),
|
|
542
|
+
...(passed.id != null ? [`--id ${shellArg(passed.id)}`] : []),
|
|
543
|
+
].join(' ');
|
|
443
544
|
const matches = all
|
|
444
545
|
.filter(({doc}) => best.has(doc.name))
|
|
445
546
|
.map(({doc, source}) => {
|
|
@@ -463,6 +564,15 @@ function definitionMatches(set, exportName, from, id) {
|
|
|
463
564
|
)
|
|
464
565
|
.slice(0, MATCH_LIMIT);
|
|
465
566
|
const fits = matches.some(match => match.score >= FIT_FLOOR);
|
|
567
|
+
const asLook =
|
|
568
|
+
passed.look && passed.glyphId
|
|
569
|
+
? [
|
|
570
|
+
`astryx experimental icon add ${exportName} --from ${shellArg(from)}`,
|
|
571
|
+
`--set ${shellArg(set.name)}`,
|
|
572
|
+
...(passed.useDefault ? ['--default'] : []),
|
|
573
|
+
`--id ${passed.glyphId} --variant ${passed.look}`,
|
|
574
|
+
].join(' ')
|
|
575
|
+
: null;
|
|
466
576
|
const name = id.replace(/-([a-z0-9])/gu, (_, c) => c.toUpperCase());
|
|
467
577
|
return {
|
|
468
578
|
type: 'icon.definitionMatches',
|
|
@@ -474,6 +584,7 @@ function definitionMatches(set, exportName, from, id) {
|
|
|
474
584
|
newDefinition: fits
|
|
475
585
|
? null
|
|
476
586
|
: `${base} --new-definition ${/^[a-z]/u.test(name) ? name : `icon${name}`} --description '<what the icon is for>' --words <word>,<word>`,
|
|
587
|
+
...(asLook ? {variant: asLook} : {}),
|
|
477
588
|
},
|
|
478
589
|
};
|
|
479
590
|
}
|
|
@@ -502,29 +613,34 @@ async function addVariantForAll({cwd, from, selector, variant}) {
|
|
|
502
613
|
}
|
|
503
614
|
const where = await findLocalIconSet(cwd, selector);
|
|
504
615
|
const {packageDir, set} = where;
|
|
505
|
-
const declared = set.data.variants ?? [];
|
|
506
|
-
if (!declared.includes(variant)) {
|
|
507
|
-
throw new AstryxError(
|
|
508
|
-
`Icon set "${set.name}" declares no variant "${variant}"${declared.length > 0 ? ` (it declares ${declared.join(', ')})` : ''}. Declare it first.`,
|
|
509
|
-
[
|
|
510
|
-
{
|
|
511
|
-
name: `astryx experimental icon new-set ${set.name} --from <its library> --variants ${[...new Set([...(declared.length > 0 ? declared : ['<default>']), variant])].join(',')}`,
|
|
512
|
-
reason: 'declare the variants',
|
|
513
|
-
},
|
|
514
|
-
],
|
|
515
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
|
-
if (set.data.default?.variant === variant) {
|
|
519
|
-
throw new AstryxError(
|
|
520
|
-
`"${variant}" is the set's default variant: each icon's own export already draws it.`,
|
|
521
|
-
undefined,
|
|
522
|
-
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
616
|
const source = resolveIconSource(from, where);
|
|
526
|
-
|
|
617
|
+
// In a library that draws each icon in several looks, the variant is the
|
|
618
|
+
// glyph's look the variant's name picks (`filled`), and an icon is known
|
|
619
|
+
// by any look of its glyph.
|
|
620
|
+
/** @type {Array<Set<string>>} */
|
|
621
|
+
let positions = [];
|
|
622
|
+
const found = libraryIcons(source.file, {
|
|
623
|
+
adapter: Boolean(set.data.adapter),
|
|
624
|
+
prefer: [variant],
|
|
625
|
+
module: source.module,
|
|
626
|
+
progress: line => logger.warn(line),
|
|
627
|
+
summary: each => {
|
|
628
|
+
positions = each.positions.map(words => new Set(words));
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
checkVariantLook({
|
|
632
|
+
set,
|
|
633
|
+
variant,
|
|
634
|
+
module: source.module,
|
|
635
|
+
positions,
|
|
636
|
+
drawn: drawnLooks(set, packageDir, each =>
|
|
637
|
+
sameIconModule(each, source.module) ? positions : null,
|
|
638
|
+
),
|
|
639
|
+
});
|
|
527
640
|
const byId = new Map(found.map(each => [each.id, each]));
|
|
641
|
+
const byLook = new Map(
|
|
642
|
+
found.flatMap(each => (each.looks ?? []).map(look => [look, each])),
|
|
643
|
+
);
|
|
528
644
|
// An existing icon is known by the library export it re-exports, then by
|
|
529
645
|
// its own export, then by its id: an icon whose id or name an older rule
|
|
530
646
|
// wrote (`squares-2-x2`, `Squares2X2Icon`) still meets its variant
|
|
@@ -537,8 +653,27 @@ async function addVariantForAll({cwd, from, selector, variant}) {
|
|
|
537
653
|
);
|
|
538
654
|
// Only icons from the same package as the variant module can have a
|
|
539
655
|
// variant there: an icon from your own `./` file, or from another library,
|
|
540
|
-
// is left as it is and never listed as missing.
|
|
656
|
+
// is left as it is and never listed as missing. Some libraries ship each
|
|
657
|
+
// look as its own package (Font Awesome's solid and regular packages): an
|
|
658
|
+
// icon from another package meets its variant only under the same export
|
|
659
|
+
// name and of the same kind, a component or data for the adapter. Once
|
|
660
|
+
// one icon of a package meets its twin, that package is a look package of
|
|
661
|
+
// the variant module, so its other icons are listed as missing.
|
|
541
662
|
const variantPackage = iconModulePackage(source.module);
|
|
663
|
+
/** @param {{module: string, source: string, adapt: boolean}} origin */
|
|
664
|
+
const otherPackageTwin = origin => {
|
|
665
|
+
if (origin.module.startsWith('.')) return false;
|
|
666
|
+
const twin = byLibraryExport.get(origin.source);
|
|
667
|
+
return twin != null && twin.adapt === origin.adapt;
|
|
668
|
+
};
|
|
669
|
+
const lookPackages = new Set(
|
|
670
|
+
set.data.icons.flatMap(icon => {
|
|
671
|
+
const origin = origins.get(icon.export);
|
|
672
|
+
return origin && otherPackageTwin(origin)
|
|
673
|
+
? [iconModulePackage(origin.module)]
|
|
674
|
+
: [];
|
|
675
|
+
}),
|
|
676
|
+
);
|
|
542
677
|
const generated = generatedModulePath(set, packageDir);
|
|
543
678
|
/** @type {import('../../../foundation/discovery/icon-set-writer.mjs').GeneratedIcon[]} */
|
|
544
679
|
const toWrite = [];
|
|
@@ -548,15 +683,22 @@ async function addVariantForAll({cwd, from, selector, variant}) {
|
|
|
548
683
|
const already = [];
|
|
549
684
|
/** @type {string[]} */
|
|
550
685
|
const missing = [];
|
|
686
|
+
/** @type {string[]} icons whose own export is the one the variant picks */
|
|
687
|
+
const own = [];
|
|
551
688
|
const icons = set.data.icons.map(icon => {
|
|
552
689
|
const origin = origins.get(icon.export);
|
|
553
|
-
if (
|
|
690
|
+
if (
|
|
691
|
+
origin &&
|
|
692
|
+
iconModulePackage(origin.module) !== variantPackage &&
|
|
693
|
+
!lookPackages.has(iconModulePackage(origin.module))
|
|
694
|
+
) {
|
|
554
695
|
return icon;
|
|
555
696
|
}
|
|
556
697
|
const librarySource =
|
|
557
698
|
origin && origin.source !== 'default' ? origin.source : undefined;
|
|
558
699
|
const match =
|
|
559
700
|
(librarySource ? byLibraryExport.get(librarySource) : undefined) ??
|
|
701
|
+
(librarySource ? byLook.get(librarySource) : undefined) ??
|
|
560
702
|
byName.get(icon.export) ??
|
|
561
703
|
byId.get(icon.id);
|
|
562
704
|
if (!match) {
|
|
@@ -567,6 +709,21 @@ async function addVariantForAll({cwd, from, selector, variant}) {
|
|
|
567
709
|
missing.push(icon.id);
|
|
568
710
|
return icon;
|
|
569
711
|
}
|
|
712
|
+
// A glyph the library draws in no look of that name has no variant,
|
|
713
|
+
// and neither has one whose own export is the one that look picks.
|
|
714
|
+
if (match.look && !match.look.includes(variant)) {
|
|
715
|
+
missing.push(icon.id);
|
|
716
|
+
return icon;
|
|
717
|
+
}
|
|
718
|
+
if (
|
|
719
|
+
match.export === librarySource &&
|
|
720
|
+
origin != null &&
|
|
721
|
+
sameIconModule(origin.module, source.module)
|
|
722
|
+
) {
|
|
723
|
+
own.push(icon.id);
|
|
724
|
+
missing.push(icon.id);
|
|
725
|
+
return icon;
|
|
726
|
+
}
|
|
570
727
|
const name = variantExportName(icon.export, variant);
|
|
571
728
|
const variants = [...(icon.variants ?? [])];
|
|
572
729
|
if (variants.some(each => each.variant === variant)) {
|
|
@@ -583,6 +740,29 @@ async function addVariantForAll({cwd, from, selector, variant}) {
|
|
|
583
740
|
added.push(icon.id);
|
|
584
741
|
return {...icon, variants};
|
|
585
742
|
});
|
|
743
|
+
if (
|
|
744
|
+
added.length === 0 &&
|
|
745
|
+
already.length === 0 &&
|
|
746
|
+
own.length > 0 &&
|
|
747
|
+
set.data.default?.variant == null
|
|
748
|
+
) {
|
|
749
|
+
// The module is the one the icons' own exports come from, so the
|
|
750
|
+
// variant names the look they draw now: the set's undeclared default.
|
|
751
|
+
const variants = [
|
|
752
|
+
variant,
|
|
753
|
+
...(set.data.variants ?? []).filter(each => each !== variant),
|
|
754
|
+
];
|
|
755
|
+
throw new AstryxError(
|
|
756
|
+
`"${source.module}" is the module the ${own.length} icons of "${set.name}" come from: its exports are those icons in the look they draw now, so "${variant}" is that look and can't be a variant of them. "${set.name}" declares no default variant; declare "${variant}" as the default first.`,
|
|
757
|
+
[
|
|
758
|
+
{
|
|
759
|
+
name: `astryx experimental icon new-set ${set.name} --variants ${variants.join(',')} --default-variant ${variant}`,
|
|
760
|
+
reason: `declare ${variant}, the look each icon draws, as the default`,
|
|
761
|
+
},
|
|
762
|
+
],
|
|
763
|
+
ERROR_CODES.ERR_INVALID_ARGUMENT,
|
|
764
|
+
);
|
|
765
|
+
}
|
|
586
766
|
if (added.length === 0 && already.length === 0) {
|
|
587
767
|
throw new AstryxError(
|
|
588
768
|
`"${source.module}" exports no icon with the id of an icon in "${set.name}". Pass the module that exports the ${variant} variant under the same names.`,
|
|
@@ -600,7 +780,8 @@ async function addVariantForAll({cwd, from, selector, variant}) {
|
|
|
600
780
|
const files = [];
|
|
601
781
|
const written = writeGeneratedIcons(packageDir, generated, next, toWrite);
|
|
602
782
|
files.push(...written.files);
|
|
603
|
-
const dataChanged =
|
|
783
|
+
const dataChanged =
|
|
784
|
+
JSON.stringify(next) !== JSON.stringify(set.data) || where.moduleRenamed;
|
|
604
785
|
if (dataChanged) {
|
|
605
786
|
try {
|
|
606
787
|
writeIconSetData(set, next);
|
|
@@ -624,6 +805,51 @@ async function addVariantForAll({cwd, from, selector, variant}) {
|
|
|
624
805
|
missing,
|
|
625
806
|
files,
|
|
626
807
|
changed: dataChanged || written.changed,
|
|
808
|
+
...(where.moduleUpdate ? {moduleUpdate: where.moduleUpdate} : {}),
|
|
627
809
|
},
|
|
628
810
|
};
|
|
629
811
|
}
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* The set's export name for an id: `x-filled` is `XFilledIcon`.
|
|
815
|
+
* @param {string} id
|
|
816
|
+
*/
|
|
817
|
+
function nameFromId(id) {
|
|
818
|
+
return iconExportName(
|
|
819
|
+
id
|
|
820
|
+
.split('-')
|
|
821
|
+
.map(word => word[0].toUpperCase() + word.slice(1))
|
|
822
|
+
.join(''),
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* The variant an export of a library of looks is of the icon the set
|
|
828
|
+
* already wraps for its glyph: its word at the first look position, in name
|
|
829
|
+
* order, where it differs from the wrapped export. That word is a variant
|
|
830
|
+
* only when the set declares it and it is not the default, which the icon's
|
|
831
|
+
* own export draws. Otherwise null, so the listing offers no variant
|
|
832
|
+
* command that the set's data would refuse.
|
|
833
|
+
* @param {string} id the export's id, look words kept
|
|
834
|
+
* @param {string} wrappedId the wrapped export's id, look words kept
|
|
835
|
+
* @param {Array<Set<string>>} positions the library's look positions, the
|
|
836
|
+
* last word first
|
|
837
|
+
* @param {import('../../../foundation/discovery/icon-set-discovery.mjs').DiscoveredIconSet} set
|
|
838
|
+
* @returns {string | null}
|
|
839
|
+
*/
|
|
840
|
+
function lookVariantOf(id, wrappedId, positions, set) {
|
|
841
|
+
const {look} = splitLook(id.split('-'), positions);
|
|
842
|
+
const {look: wrapped} = splitLook(wrappedId.split('-'), positions);
|
|
843
|
+
let word = null;
|
|
844
|
+
for (let index = look.length - 1; index >= 0; index--) {
|
|
845
|
+
if (look[index] !== wrapped[index]) {
|
|
846
|
+
word = look[index];
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return word != null &&
|
|
851
|
+
(set.data.variants ?? []).includes(word) &&
|
|
852
|
+
word !== set.data.default?.variant
|
|
853
|
+
? word
|
|
854
|
+
: null;
|
|
855
|
+
}
|
package/api/icon/icon.type.d.mts
CHANGED
|
@@ -223,6 +223,10 @@ export type IconMapManyResponse = {
|
|
|
223
223
|
changed: boolean;
|
|
224
224
|
}>;
|
|
225
225
|
changed: boolean;
|
|
226
|
+
moduleUpdate?: {
|
|
227
|
+
previous: string;
|
|
228
|
+
module: string;
|
|
229
|
+
} | undefined;
|
|
226
230
|
files?: string[] | undefined;
|
|
227
231
|
};
|
|
228
232
|
};
|
|
@@ -239,6 +243,10 @@ export type IconMapResponse = {
|
|
|
239
243
|
icon: string | null;
|
|
240
244
|
previous: string | null;
|
|
241
245
|
changed: boolean;
|
|
246
|
+
moduleUpdate?: {
|
|
247
|
+
previous: string;
|
|
248
|
+
module: string;
|
|
249
|
+
} | undefined;
|
|
242
250
|
files?: string[] | undefined;
|
|
243
251
|
};
|
|
244
252
|
};
|
|
@@ -260,7 +268,7 @@ export type IconAddOptions = {
|
|
|
260
268
|
*/
|
|
261
269
|
definition?: string | undefined;
|
|
262
270
|
/**
|
|
263
|
-
* - Add the set's own definition with this name and map the icon to it.
|
|
271
|
+
* - Add the set's own definition with this name (camelCase, or kebab-case written as camelCase) and map the icon to it.
|
|
264
272
|
*/
|
|
265
273
|
newDefinition?: string | undefined;
|
|
266
274
|
/**
|
|
@@ -303,6 +311,10 @@ export type IconAddVariantsResponse = {
|
|
|
303
311
|
missing: string[];
|
|
304
312
|
files: string[];
|
|
305
313
|
changed: boolean;
|
|
314
|
+
moduleUpdate?: {
|
|
315
|
+
previous: string;
|
|
316
|
+
module: string;
|
|
317
|
+
} | undefined;
|
|
306
318
|
};
|
|
307
319
|
};
|
|
308
320
|
/**
|
|
@@ -323,6 +335,11 @@ export type IconAddResponse = {
|
|
|
323
335
|
newDefinition?: string | undefined;
|
|
324
336
|
files: string[];
|
|
325
337
|
changed: boolean;
|
|
338
|
+
added: boolean;
|
|
339
|
+
moduleUpdate?: {
|
|
340
|
+
previous: string;
|
|
341
|
+
module: string;
|
|
342
|
+
} | undefined;
|
|
326
343
|
note?: string | undefined;
|
|
327
344
|
};
|
|
328
345
|
};
|
|
@@ -354,6 +371,7 @@ export type IconDefinitionMatchesResponse = {
|
|
|
354
371
|
id: string;
|
|
355
372
|
matches: IconDefinitionMatch[];
|
|
356
373
|
newDefinition: string | null;
|
|
374
|
+
variant?: string | undefined;
|
|
357
375
|
};
|
|
358
376
|
};
|
|
359
377
|
/**
|
|
@@ -438,7 +456,7 @@ export type IconNewSetOptions = {
|
|
|
438
456
|
*/
|
|
439
457
|
variants?: string | string[] | undefined;
|
|
440
458
|
/**
|
|
441
|
-
* - With `variants`: the variant each icon's own export draws; the first variant
|
|
459
|
+
* - With `variants`: the variant each icon's own export draws; when absent, the look the icons' exports draw in a library whose names encode looks; otherwise the set's current default, else, on a set without icons, the first variant. A set with icons changes it only with `from`, and only in a library whose names encode looks.
|
|
442
460
|
*/
|
|
443
461
|
defaultVariant?: string | undefined;
|
|
444
462
|
/**
|
|
@@ -511,6 +529,25 @@ export type IconNewData = {
|
|
|
511
529
|
* - With `from` on an existing set: the set was refreshed, not created.
|
|
512
530
|
*/
|
|
513
531
|
refreshed?: boolean | undefined;
|
|
532
|
+
/**
|
|
533
|
+
* - Without `from` on an existing set: its variants, default variant, display name, or description were updated in place, not created.
|
|
534
|
+
*/
|
|
535
|
+
updated?: boolean | undefined;
|
|
536
|
+
/**
|
|
537
|
+
* - On a refresh from a package root: the icons that read one file of that package (`from`) and now import from the root (`to`); each keeps its id, export, `map` entries, variants, and words.
|
|
538
|
+
*/
|
|
539
|
+
moved?: {
|
|
540
|
+
id: string;
|
|
541
|
+
from: string;
|
|
542
|
+
to: string;
|
|
543
|
+
}[] | undefined;
|
|
544
|
+
/**
|
|
545
|
+
* - With `from`: the wrapped library (`name@version`) ships no license file to copy and the set has none. `path` is where to add a NOTICE file that names the library and its license; the CLI never writes it.
|
|
546
|
+
*/
|
|
547
|
+
licenseNoticeMissing?: {
|
|
548
|
+
library: string;
|
|
549
|
+
path: string;
|
|
550
|
+
} | undefined;
|
|
514
551
|
/**
|
|
515
552
|
* - On a refresh: the icons whose id this release's id rule changes, matched by the export the library still has; each keeps its `map` entries, variants, and words.
|
|
516
553
|
*/
|
|
@@ -537,6 +574,13 @@ export type IconNewData = {
|
|
|
537
574
|
* - What the author does next, including each change the package needs that the CLI never makes itself (its entry, peers, scripts), as text to copy.
|
|
538
575
|
*/
|
|
539
576
|
notes?: string[] | undefined;
|
|
577
|
+
/**
|
|
578
|
+
* - On a refresh, an update, or a new definition with `icon`: the data file's `module` before and after this command, when the package was renamed and the command writes its new name.
|
|
579
|
+
*/
|
|
580
|
+
moduleUpdate?: {
|
|
581
|
+
previous: string;
|
|
582
|
+
module: string;
|
|
583
|
+
} | undefined;
|
|
540
584
|
};
|
|
541
585
|
/**
|
|
542
586
|
* `astryx --json experimental icon new-set <name>`.
|