@astryxdesign/cli 0.7.4 → 0.7.5-canary.04434e7
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/README.md +19 -19
- package/api/component/_adapter.mjs +16 -1
- package/api/component/component.test.mjs +31 -0
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +5 -2
- package/api/docs/_adapter.mjs +24 -16
- package/api/docs/docs.test.mjs +18 -0
- package/api/docs/integrationDocs.test.mjs +2 -2
- package/api/experimental.d.mts +5 -0
- package/api/experimental.mjs +15 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +16 -3
- package/api/icon/_authoring.d.mts +5 -1
- package/api/icon/_authoring.mjs +478 -63
- package/api/icon/_options.d.mts +11 -0
- package/api/icon/_options.mjs +39 -4
- package/api/icon/_records.d.mts +19 -0
- package/api/icon/_records.mjs +25 -0
- package/api/icon/add/add.d.mts +3 -3
- package/api/icon/add/add.mjs +227 -14
- package/api/icon/all-or-nothing.test.mjs +283 -0
- package/api/icon/detail/detail.mjs +2 -13
- package/api/icon/error-codes.test.mjs +14 -7
- package/api/icon/icon.d.mts +2 -2
- package/api/icon/icon.doc.mjs +30 -2
- package/api/icon/icon.mjs +57 -8
- package/api/icon/icon.test.mjs +133 -1
- package/api/icon/icon.type.d.mts +126 -1
- package/api/icon/icon.type.mjs +67 -3
- package/api/icon/iconAdd.doc.mjs +22 -6
- package/api/icon/iconMap.doc.mjs +24 -8
- package/api/icon/iconNewDefinition.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +30 -2
- package/api/icon/iconUse.doc.mjs +4 -1
- package/api/icon/map/map.d.mts +4 -4
- package/api/icon/map/map.mjs +134 -9
- package/api/icon/new-definition/new-definition.mjs +6 -2
- package/api/icon/new-set/new-set.mjs +2 -2
- package/api/icon/new-set/new-set.test.mjs +60 -10
- package/api/icon/option-pairs.test.mjs +368 -0
- package/api/icon/search/search.d.mts +10 -0
- package/api/icon/search/search.mjs +55 -14
- package/api/icon/use/use.mjs +2 -13
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
- package/api/integration/pack-check.mjs +10 -4
- package/api/integration/pack-check.test.mjs +5 -1
- package/api/integration/validate-integration.type.d.mts +3 -2
- package/api/integration/validate-integration.type.mjs +3 -2
- package/api/render/_adapter.d.mts +28 -0
- package/api/render/_adapter.mjs +540 -0
- package/api/render/render.d.mts +15 -0
- package/api/render/render.doc.d.mts +9 -0
- package/api/render/render.doc.mjs +112 -0
- package/api/render/render.mjs +113 -0
- package/api/render/render.test.mjs +1155 -0
- package/api/render/render.type.d.mts +74 -0
- package/api/render/render.type.mjs +64 -0
- package/api/search/_adapter.test.mjs +21 -2
- package/api/search/_result.d.mts +5 -5
- package/api/search/search.d.mts +1 -1
- package/api/template/template.mjs +3 -1
- package/api/template/template.type.d.mts +2 -1
- package/api/template/template.type.mjs +1 -1
- package/api/template/unknown-name.test.mjs +63 -0
- package/api/upgrade/run/failure-receipt.test.mjs +155 -0
- package/api/upgrade/run/run.mjs +170 -8
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +12 -1
- package/api/upgrade/upgrade.type.mjs +16 -3
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/run-codemod.mjs +17 -3
- package/assets/codemods/runner.mjs +81 -8
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +123 -70
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +200 -32
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
- package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +50 -20
- package/assets/docs/tree/render-pages.doc.mjs +94 -0
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/icons/definitions/activity.doc.mjs +1 -1
- package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
- package/assets/icons/definitions/alignStart.doc.mjs +10 -0
- package/assets/icons/definitions/archive.doc.mjs +1 -1
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
- package/assets/icons/definitions/attach.doc.mjs +1 -1
- package/assets/icons/definitions/audio.doc.mjs +1 -1
- package/assets/icons/definitions/cart.doc.mjs +1 -1
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
- package/assets/icons/definitions/close.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -1
- package/assets/icons/definitions/compose.doc.mjs +1 -1
- package/assets/icons/definitions/conversation.doc.mjs +1 -1
- package/assets/icons/definitions/copy.doc.mjs +1 -1
- package/assets/icons/definitions/cpu.doc.mjs +9 -0
- package/assets/icons/definitions/database.doc.mjs +1 -1
- package/assets/icons/definitions/desktop.doc.mjs +1 -1
- package/assets/icons/definitions/discount.doc.mjs +1 -1
- package/assets/icons/definitions/download.doc.mjs +1 -1
- package/assets/icons/definitions/emoji.doc.mjs +1 -1
- package/assets/icons/definitions/error.doc.mjs +1 -1
- package/assets/icons/definitions/expand.doc.mjs +1 -1
- package/assets/icons/definitions/experiment.doc.mjs +1 -1
- package/assets/icons/definitions/externalLink.doc.mjs +7 -1
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
- package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
- package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
- package/assets/icons/definitions/gitFork.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -1
- package/assets/icons/definitions/location.doc.mjs +1 -1
- package/assets/icons/definitions/mention.doc.mjs +1 -1
- package/assets/icons/definitions/menu.doc.mjs +1 -1
- package/assets/icons/definitions/microphone.doc.mjs +1 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -1
- package/assets/icons/definitions/money.doc.mjs +1 -1
- package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
- package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
- package/assets/icons/definitions/panelRight.doc.mjs +10 -0
- package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
- package/assets/icons/definitions/redo.doc.mjs +1 -1
- package/assets/icons/definitions/refresh.doc.mjs +1 -1
- package/assets/icons/definitions/rotate.doc.mjs +9 -0
- package/assets/icons/definitions/scale.doc.mjs +10 -0
- package/assets/icons/definitions/search.doc.mjs +1 -1
- package/assets/icons/definitions/send.doc.mjs +1 -1
- package/assets/icons/definitions/settings.doc.mjs +1 -1
- package/assets/icons/definitions/star.doc.mjs +1 -1
- package/assets/icons/definitions/stop.doc.mjs +1 -1
- package/assets/icons/definitions/success.doc.mjs +1 -1
- package/assets/icons/definitions/textCase.doc.mjs +9 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
- package/assets/icons/definitions/trendDown.doc.mjs +7 -1
- package/assets/icons/definitions/trendUp.doc.mjs +1 -1
- package/assets/icons/definitions/undo.doc.mjs +1 -1
- package/assets/icons/definitions/upload.doc.mjs +1 -1
- package/assets/icons/definitions/userAdd.doc.mjs +1 -1
- package/assets/icons/definitions/warning.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
- package/authoring/doctypes/icon-set/parse.d.mts +1 -0
- package/authoring/doctypes/icon-set/parse.mjs +1 -0
- package/authoring/doctypes/icon-set/type.ts +5 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +2 -1
- package/clients/cli/commands/doctor.mjs +16 -17
- package/clients/cli/commands/experimental/icon.mjs +167 -35
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/render.mjs +113 -0
- package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
- package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
- package/clients/cli/commands/experimental-render.doc.mjs +60 -0
- package/clients/cli/commands/experimental.doc.mjs +4 -2
- package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
- package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
- package/clients/cli/commands/icon.test.mjs +1 -1
- package/clients/cli/commands/template.mjs +4 -1
- package/clients/cli/commands/text-json-parity.test.mjs +46 -0
- package/clients/cli/commands/upgrade.doc.mjs +17 -0
- package/clients/cli/commands/upgrade.file-protection.test.mjs +29 -0
- package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
- package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/clients/cli/index.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +2 -1
- package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
- package/foundation/discovery/component-discovery.mjs +13 -7
- package/foundation/discovery/icon-set-checks.d.mts +43 -9
- package/foundation/discovery/icon-set-checks.mjs +296 -21
- package/foundation/discovery/icon-set-checks.test.mjs +125 -12
- package/foundation/discovery/icon-set-writer.d.mts +192 -3
- package/foundation/discovery/icon-set-writer.mjs +608 -34
- package/foundation/discovery/icon-set-writer.test.mjs +26 -0
- package/foundation/discovery/module-exports.mjs +82 -25
- package/foundation/discovery/module-exports.test.mjs +38 -1
- package/foundation/discovery/package-exports.d.mts +13 -0
- package/foundation/discovery/package-exports.mjs +40 -1
- package/foundation/discovery/template-icons.d.mts +6 -0
- package/foundation/discovery/template-icons.mjs +98 -10
- package/foundation/discovery/template-icons.test.mjs +103 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
- package/foundation/doc-compiler/import.mjs +81 -8
- package/foundation/doc-compiler/read.d.mts +4 -3
- package/foundation/doc-compiler/read.mjs +15 -10
- package/foundation/doc-compiler/read.test.mjs +59 -1
- package/foundation/doc-compiler/tree.mjs +3 -1
- package/foundation/fs/module-loader.d.mts +3 -2
- package/foundation/fs/module-loader.mjs +3 -2
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
- package/foundation/fs/read-record.d.mts +27 -0
- package/foundation/fs/read-record.mjs +83 -15
- package/foundation/fs/read-record.test.mjs +88 -1
- package/foundation/render/assets.d.mts +31 -0
- package/foundation/render/assets.mjs +102 -0
- package/foundation/render/component-map.d.mts +52 -0
- package/foundation/render/component-map.mjs +141 -0
- package/foundation/render/css-cut.d.mts +29 -0
- package/foundation/render/css-cut.mjs +144 -0
- package/foundation/render/embedded-files.d.mts +28 -0
- package/foundation/render/embedded-files.mjs +108 -0
- package/foundation/render/embedded-imports.d.mts +61 -0
- package/foundation/render/embedded-imports.mjs +315 -0
- package/foundation/render/html-reader.d.mts +37 -0
- package/foundation/render/html-reader.mjs +121 -0
- package/foundation/render/page-worker.d.mts +7 -0
- package/foundation/render/page-worker.mjs +519 -0
- package/foundation/render/rebuild.d.mts +19 -0
- package/foundation/render/rebuild.mjs +269 -0
- package/foundation/render/render-page.d.mts +85 -0
- package/foundation/render/render-page.mjs +612 -0
- package/foundation/render/render.test.mjs +117 -0
- package/foundation/render/source-block.d.mts +52 -0
- package/foundation/render/source-block.mjs +106 -0
- package/foundation/response/base.d.ts +7 -0
- package/foundation/response/error-codes.d.mts +10 -1
- package/foundation/response/error-codes.doc.mjs +59 -2
- package/foundation/response/error-codes.mjs +62 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/foundation/response/response-types.doc.mjs +38 -1
- package/foundation/text/string-utils.mjs +33 -0
- package/foundation/text/string-utils.test.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +17 -3
- package/foundation/text/suggest-order.mjs +58 -13
- package/foundation/text/suggest-order.test.mjs +53 -0
- package/package.json +14 -9
|
@@ -28,9 +28,8 @@ export function iconSetIssues(packageDir: string, loaded: {
|
|
|
28
28
|
* Astryx's optional (not built-in) definitions the set's `map` does not
|
|
29
29
|
* name. Mapping them is optional, so they never fail a check.
|
|
30
30
|
* @property {Array<{definition: string, icon: string}>} suggestions for every
|
|
31
|
-
* unmapped definition, built-in, optional, or the set's own, the icon
|
|
32
|
-
*
|
|
33
|
-
* beyond that
|
|
31
|
+
* unmapped definition, built-in, optional, or the set's own, the best icon
|
|
32
|
+
* {@link suggestedIcons} gives, if any
|
|
34
33
|
* @property {IconSetUnchecked[]} unchecked what the checks could not judge:
|
|
35
34
|
* never counted, never failing, even under `--strict`
|
|
36
35
|
*/
|
|
@@ -48,9 +47,8 @@ export function iconSetCoverage(loaded: {
|
|
|
48
47
|
iconSets?: string;
|
|
49
48
|
}, unchecked?: Map<string, IconSetUnchecked[]>): IconSetCoverage[];
|
|
50
49
|
/**
|
|
51
|
-
* The
|
|
52
|
-
*
|
|
53
|
-
* when none is: a suggestion is never a guess from parts of words.
|
|
50
|
+
* The best icon {@link suggestedIcons} gives for a definition, or null when
|
|
51
|
+
* it gives none.
|
|
54
52
|
* @param {DiscoveredIconSet} set
|
|
55
53
|
* @param {import('../../authoring/doctypes/icon-definition/type').IconDefinitionDoc} doc
|
|
56
54
|
* @returns {{map: string, icon: string} | null}
|
|
@@ -59,6 +57,41 @@ export function suggestIcon(set: DiscoveredIconSet, doc: import("../../authoring
|
|
|
59
57
|
map: string;
|
|
60
58
|
icon: string;
|
|
61
59
|
} | null;
|
|
60
|
+
/**
|
|
61
|
+
* The icons a definition might map to, best first, at most three, in the
|
|
62
|
+
* order AST-084 FR13 gives: the name in another spelling, an icon the library
|
|
63
|
+
* gives the name as another name, ids that start with the name (`video` →
|
|
64
|
+
* `video-camera`, never `close` → `panel-left-close`), an id that is one of
|
|
65
|
+
* its words (`delete` → `trash`), another name that is one of its words, and
|
|
66
|
+
* two-word ids that are a one-word word sized, shaped, or numbered
|
|
67
|
+
* (`grid-2x2`). An icon `map` already names
|
|
68
|
+
* for another definition, or whose id is another definition's name, is left
|
|
69
|
+
* out: it has a meaning of its own. Never a negated form or the opposite
|
|
70
|
+
* direction, and never a guess from parts of words.
|
|
71
|
+
* @param {{data: {icons: Array<{id: string, words?: string[]}>, map?: Record<string, string>}, definitions?: Array<{doc: {name: string}}>}} set
|
|
72
|
+
* @param {{name: string, words: string[]}} doc
|
|
73
|
+
* @returns {Array<{icon: string, word: string}>}
|
|
74
|
+
*/
|
|
75
|
+
export function suggestedIcons(set: {
|
|
76
|
+
data: {
|
|
77
|
+
icons: Array<{
|
|
78
|
+
id: string;
|
|
79
|
+
words?: string[];
|
|
80
|
+
}>;
|
|
81
|
+
map?: Record<string, string>;
|
|
82
|
+
};
|
|
83
|
+
definitions?: Array<{
|
|
84
|
+
doc: {
|
|
85
|
+
name: string;
|
|
86
|
+
};
|
|
87
|
+
}>;
|
|
88
|
+
}, doc: {
|
|
89
|
+
name: string;
|
|
90
|
+
words: string[];
|
|
91
|
+
}): Array<{
|
|
92
|
+
icon: string;
|
|
93
|
+
word: string;
|
|
94
|
+
}>;
|
|
62
95
|
/** @typedef {import('../integrations/issue').AstryxIntegrationIssue} Issue */
|
|
63
96
|
/** @typedef {import('./icon-set-discovery.mjs').DiscoveredIconSet} DiscoveredIconSet */
|
|
64
97
|
/** An invalid descriptor or data file. */
|
|
@@ -87,6 +120,8 @@ export const ICON_DEFINITION_UNUSED: "icon_definition_unused";
|
|
|
87
120
|
export const ICON_SOURCE_VERSION_DRIFT: "icon_source_version_drift";
|
|
88
121
|
/** A set with an upstream and no license notice. */
|
|
89
122
|
export const ICON_LICENSE_NOTICE_MISSING: "icon_license_notice_missing";
|
|
123
|
+
/** How many icons one definition is suggested at most. */
|
|
124
|
+
export const SUGGESTIONS_PER_DEFINITION: 3;
|
|
90
125
|
/**
|
|
91
126
|
* One item a check could not judge: listed, never counted, never failing.
|
|
92
127
|
*/
|
|
@@ -124,9 +159,8 @@ export type IconSetCoverage = {
|
|
|
124
159
|
}>;
|
|
125
160
|
/**
|
|
126
161
|
* for every
|
|
127
|
-
* unmapped definition, built-in, optional, or the set's own, the icon
|
|
128
|
-
*
|
|
129
|
-
* beyond that
|
|
162
|
+
* unmapped definition, built-in, optional, or the set's own, the best icon
|
|
163
|
+
* {@link suggestedIcons} gives, if any
|
|
130
164
|
*/
|
|
131
165
|
suggestions: Array<{
|
|
132
166
|
definition: string;
|
|
@@ -51,7 +51,10 @@ import {
|
|
|
51
51
|
} from './icon-set-discovery.mjs';
|
|
52
52
|
import {inspectPackageExport} from './package-exports.mjs';
|
|
53
53
|
import {
|
|
54
|
+
THEME_MAP_NAME,
|
|
55
|
+
entryWiringNote,
|
|
54
56
|
generatedTypesPath,
|
|
57
|
+
otherNamesOf,
|
|
55
58
|
generatedTypesText,
|
|
56
59
|
readGeneratedStatements,
|
|
57
60
|
} from './icon-set-writer.mjs';
|
|
@@ -63,6 +66,7 @@ import {
|
|
|
63
66
|
staticExportBindings,
|
|
64
67
|
} from './module-exports.mjs';
|
|
65
68
|
import {astryxIconDefinitions} from './icon-definition-discovery.mjs';
|
|
69
|
+
import {rankIcons} from './icon-ranking.mjs';
|
|
66
70
|
import {
|
|
67
71
|
issueError,
|
|
68
72
|
issueWarning,
|
|
@@ -272,7 +276,17 @@ function checkContract(set, packageName, pkg, unchecked) {
|
|
|
272
276
|
const actual = fs.existsSync(typesFile)
|
|
273
277
|
? fs.readFileSync(typesFile, 'utf-8')
|
|
274
278
|
: null;
|
|
275
|
-
|
|
279
|
+
// The header comment is the writer's, and changes between releases;
|
|
280
|
+
// the declarations are what must match.
|
|
281
|
+
const code = (/** @type {string} */ text) =>
|
|
282
|
+
text
|
|
283
|
+
.split('\n')
|
|
284
|
+
.filter(line => !line.startsWith('//'))
|
|
285
|
+
.join('\n');
|
|
286
|
+
if (
|
|
287
|
+
expected != null &&
|
|
288
|
+
(actual == null || code(actual) !== code(expected))
|
|
289
|
+
) {
|
|
276
290
|
issues.push(
|
|
277
291
|
issueError(
|
|
278
292
|
ICON_GENERATED_TYPES_MISMATCH,
|
|
@@ -350,7 +364,7 @@ function checkDefinitions(set) {
|
|
|
350
364
|
issues.push(
|
|
351
365
|
issueError(
|
|
352
366
|
ICON_BUILTIN_DEFINITION_MISSING,
|
|
353
|
-
`${label} maps no icon to the built-in icon definition "${doc.name}" (${doc.description} Words: ${doc.words.join(', ')}.). Every set maps every built-in definition:
|
|
367
|
+
`${label} maps no icon to the built-in icon definition "${doc.name}" (${doc.description} Words: ${doc.words.join(', ')}.). Every set maps every built-in definition: run \`astryx experimental icon map ${doc.name} <icon id>\` with the icon that draws it${findHint(set, doc)}.${hint}`,
|
|
354
368
|
),
|
|
355
369
|
);
|
|
356
370
|
}
|
|
@@ -368,7 +382,7 @@ function checkDefinitions(set) {
|
|
|
368
382
|
issues.push(
|
|
369
383
|
issueWarning(
|
|
370
384
|
ICON_DEFINITION_UNUSED,
|
|
371
|
-
`${label} declares the icon definition "${doc.name}", but "map" names no icon for it.
|
|
385
|
+
`${label} declares the icon definition "${doc.name}", but "map" names no icon for it. Map it with \`astryx experimental icon map ${doc.name} <icon id>\`, or remove definitions/${doc.name}.doc.mjs.${suggestion ? ` Suggested: astryx experimental icon map ${doc.name} ${suggestion.icon}.` : ''}`,
|
|
372
386
|
),
|
|
373
387
|
);
|
|
374
388
|
}
|
|
@@ -383,9 +397,8 @@ function checkDefinitions(set) {
|
|
|
383
397
|
* Astryx's optional (not built-in) definitions the set's `map` does not
|
|
384
398
|
* name. Mapping them is optional, so they never fail a check.
|
|
385
399
|
* @property {Array<{definition: string, icon: string}>} suggestions for every
|
|
386
|
-
* unmapped definition, built-in, optional, or the set's own, the icon
|
|
387
|
-
*
|
|
388
|
-
* beyond that
|
|
400
|
+
* unmapped definition, built-in, optional, or the set's own, the best icon
|
|
401
|
+
* {@link suggestedIcons} gives, if any
|
|
389
402
|
* @property {IconSetUnchecked[]} unchecked what the checks could not judge:
|
|
390
403
|
* never counted, never failing, even under `--strict`
|
|
391
404
|
*/
|
|
@@ -433,25 +446,247 @@ export function iconSetCoverage(loaded, unchecked = new Map()) {
|
|
|
433
446
|
}
|
|
434
447
|
|
|
435
448
|
/**
|
|
436
|
-
* The
|
|
437
|
-
*
|
|
438
|
-
* when none is: a suggestion is never a guess from parts of words.
|
|
449
|
+
* The best icon {@link suggestedIcons} gives for a definition, or null when
|
|
450
|
+
* it gives none.
|
|
439
451
|
* @param {DiscoveredIconSet} set
|
|
440
452
|
* @param {import('../../authoring/doctypes/icon-definition/type').IconDefinitionDoc} doc
|
|
441
453
|
* @returns {{map: string, icon: string} | null}
|
|
442
454
|
*/
|
|
443
455
|
export function suggestIcon(set, doc) {
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
456
|
+
const [first] = suggestedIcons(set, doc);
|
|
457
|
+
return first ? {map: doc.name, icon: first.icon} : null;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Words that turn an icon into the opposite or a variation of its first
|
|
462
|
+
* words: `lock-open`, `bell-off`, `video-camera-slash`, `audio-lines-x`.
|
|
463
|
+
*/
|
|
464
|
+
const NEGATING_WORDS = new Set([
|
|
465
|
+
'off',
|
|
466
|
+
'slash',
|
|
467
|
+
'x',
|
|
468
|
+
'open',
|
|
469
|
+
'minus',
|
|
470
|
+
'ban',
|
|
471
|
+
'dashed',
|
|
472
|
+
'dot',
|
|
473
|
+
'code',
|
|
474
|
+
'formatting',
|
|
475
|
+
'exclamation',
|
|
476
|
+
'question',
|
|
477
|
+
'warning',
|
|
478
|
+
]);
|
|
479
|
+
|
|
480
|
+
/** Direction words that mean the other way. */
|
|
481
|
+
/** @type {Record<string, string>} */
|
|
482
|
+
const OPPOSITES = {
|
|
483
|
+
horizontal: 'vertical',
|
|
484
|
+
vertical: 'horizontal',
|
|
485
|
+
left: 'right',
|
|
486
|
+
right: 'left',
|
|
487
|
+
up: 'down',
|
|
488
|
+
down: 'up',
|
|
489
|
+
in: 'out',
|
|
490
|
+
out: 'in',
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* A second id word that only sizes, shapes, or numbers the first: a number
|
|
495
|
+
* or dimension (`2`, `3x3`), or one of a few style words. The icon then
|
|
496
|
+
* still draws what its first word names.
|
|
497
|
+
*/
|
|
498
|
+
const QUALIFIER_RE =
|
|
499
|
+
/^(?:\d+(?:x\d+)?|circle|square|small|big|large|alt|horizontal|vertical)$/u;
|
|
500
|
+
|
|
501
|
+
/** How many icons one definition is suggested at most. */
|
|
502
|
+
export const SUGGESTIONS_PER_DEFINITION = 3;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* The icons a definition might map to, best first, at most three, in the
|
|
506
|
+
* order AST-084 FR13 gives: the name in another spelling, an icon the library
|
|
507
|
+
* gives the name as another name, ids that start with the name (`video` →
|
|
508
|
+
* `video-camera`, never `close` → `panel-left-close`), an id that is one of
|
|
509
|
+
* its words (`delete` → `trash`), another name that is one of its words, and
|
|
510
|
+
* two-word ids that are a one-word word sized, shaped, or numbered
|
|
511
|
+
* (`grid-2x2`). An icon `map` already names
|
|
512
|
+
* for another definition, or whose id is another definition's name, is left
|
|
513
|
+
* out: it has a meaning of its own. Never a negated form or the opposite
|
|
514
|
+
* direction, and never a guess from parts of words.
|
|
515
|
+
* @param {{data: {icons: Array<{id: string, words?: string[]}>, map?: Record<string, string>}, definitions?: Array<{doc: {name: string}}>}} set
|
|
516
|
+
* @param {{name: string, words: string[]}} doc
|
|
517
|
+
* @returns {Array<{icon: string, word: string}>}
|
|
518
|
+
*/
|
|
519
|
+
export function suggestedIcons(set, doc) {
|
|
520
|
+
const toId = (/** @type {string} */ name) =>
|
|
521
|
+
name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();
|
|
522
|
+
const nameId = toId(doc.name);
|
|
523
|
+
const nameWords = nameId.split('-').map(stem);
|
|
524
|
+
const map = set.data.map ?? {};
|
|
525
|
+
const taken = new Set([
|
|
526
|
+
...Object.entries(map)
|
|
527
|
+
.filter(([name]) => name !== doc.name)
|
|
528
|
+
.map(([, id]) => id),
|
|
529
|
+
...[...astryxIconDefinitions().definitions, ...(set.definitions ?? [])]
|
|
530
|
+
.map(each => toId(each.doc.name))
|
|
531
|
+
.filter(id => id !== nameId),
|
|
532
|
+
]);
|
|
533
|
+
const wordIds = doc.words.map(word =>
|
|
534
|
+
word.trim().toLowerCase().replace(/\s+/gu, '-'),
|
|
535
|
+
);
|
|
536
|
+
// Every word the definition is known by, stemmed: its name's and its words'.
|
|
537
|
+
const meaning = new Set([
|
|
538
|
+
...nameWords,
|
|
539
|
+
...wordIds.flatMap(id => id.split('-')).map(stem),
|
|
540
|
+
]);
|
|
541
|
+
const icons = set.data.icons.map(icon => ({
|
|
542
|
+
id: icon.id,
|
|
543
|
+
words: icon.id.split('-').map(stem),
|
|
544
|
+
raw: icon.id.split('-'),
|
|
545
|
+
// The library's other names for it, the same ones `map` accepts.
|
|
546
|
+
other: otherNamesOf(icon),
|
|
547
|
+
}));
|
|
548
|
+
/** How many of the definition's words an id has: more is a better fit. */
|
|
549
|
+
const fit = (/** @type {string[]} */ words) =>
|
|
550
|
+
words.filter(word => meaning.has(word)).length;
|
|
551
|
+
/**
|
|
552
|
+
* Candidates best first: most of the definition's words, then fewest
|
|
553
|
+
* extra words, then by id.
|
|
554
|
+
* @param {typeof icons} list
|
|
555
|
+
*/
|
|
556
|
+
const ranked = list =>
|
|
557
|
+
[...list].sort(
|
|
558
|
+
(a, b) =>
|
|
559
|
+
fit(b.words) - fit(a.words) ||
|
|
560
|
+
a.words.length - b.words.length ||
|
|
561
|
+
(a.id < b.id ? -1 : a.id > b.id ? 1 : 0),
|
|
562
|
+
);
|
|
563
|
+
// An id that turns the definition around (`ellipsis-vertical` for
|
|
564
|
+
// moreHorizontal) is never its icon.
|
|
565
|
+
const opposite = new Set(
|
|
566
|
+
nameWords.flatMap(word => (OPPOSITES[word] ? [OPPOSITES[word]] : [])),
|
|
567
|
+
);
|
|
568
|
+
const negated = (/** @type {string[]} */ words) =>
|
|
569
|
+
words.some(word => NEGATING_WORDS.has(word) || opposite.has(word));
|
|
570
|
+
/** @type {Array<{icon: string, word: string}>} */
|
|
571
|
+
const found = [];
|
|
572
|
+
const add = (/** @type {string} */ icon, /** @type {string} */ word) => {
|
|
573
|
+
if (taken.has(icon) || found.some(each => each.icon === icon)) return;
|
|
574
|
+
found.push({icon, word});
|
|
575
|
+
};
|
|
576
|
+
const squashed = nameId.replace(/-/gu, '');
|
|
577
|
+
// 1. The name itself, spelled with or without hyphens or a plural
|
|
578
|
+
// (`lightbulb` → `light-bulb`, `language` → `languages`).
|
|
579
|
+
for (const icon of icons) {
|
|
580
|
+
if (
|
|
581
|
+
icon.id === nameId ||
|
|
582
|
+
icon.id.replace(/-/gu, '') === squashed ||
|
|
583
|
+
(icon.words.length === nameWords.length &&
|
|
584
|
+
icon.words.every((word, index) => word === nameWords[index]))
|
|
585
|
+
) {
|
|
586
|
+
add(icon.id, nameId);
|
|
587
|
+
}
|
|
453
588
|
}
|
|
454
|
-
|
|
589
|
+
// 2. An icon the library once named after the definition, or that it
|
|
590
|
+
// gives the definition's name as another name (Lucide's
|
|
591
|
+
// `more-horizontal` on `ellipsis`, `unlock` on `lock-open`).
|
|
592
|
+
for (const icon of icons) {
|
|
593
|
+
if (icon.other.includes(nameId)) add(icon.id, nameId);
|
|
594
|
+
}
|
|
595
|
+
// 3. Ids that start with the name as written (`video` → `video-camera`),
|
|
596
|
+
// never a negated form. A plural is not the same start: `users` is not
|
|
597
|
+
// `user-plus`, and `apps` is not `app-window`.
|
|
598
|
+
const nameRaw = nameId.split('-');
|
|
599
|
+
ranked(
|
|
600
|
+
icons.filter(
|
|
601
|
+
icon =>
|
|
602
|
+
icon.raw.length > nameRaw.length &&
|
|
603
|
+
nameRaw.every((word, index) => icon.raw[index] === word) &&
|
|
604
|
+
!negated(icon.raw.slice(nameRaw.length)),
|
|
605
|
+
),
|
|
606
|
+
).forEach(icon => add(icon.id, nameId));
|
|
607
|
+
// 4. An icon whose whole id is one of the definition's words.
|
|
608
|
+
for (const id of wordIds) {
|
|
609
|
+
if (icons.some(icon => icon.id === id)) add(id, id.replace(/-/gu, ' '));
|
|
610
|
+
}
|
|
611
|
+
// 5. Another name the library gives an icon that is one of the
|
|
612
|
+
// definition's words (Lucide's `smile` on `face-slightly-smiling`).
|
|
613
|
+
for (const [index, id] of wordIds.entries()) {
|
|
614
|
+
for (const icon of icons) {
|
|
615
|
+
if (icon.other.includes(id)) add(icon.id, doc.words[index]);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
// 6. Last, two-word ids that are a one-word word with only a size, shape,
|
|
619
|
+
// or number after it (`columns` → `columns-3`, `plus` → `plus-circle`,
|
|
620
|
+
// `grid` → `grid-2x2`), best fit first. Any other second word names
|
|
621
|
+
// another thing (`card-sim`, `fast-forward`, `hand-coins`), so it is
|
|
622
|
+
// never suggested from a word alone.
|
|
623
|
+
for (const word of doc.words) {
|
|
624
|
+
if (!/^[a-z]{3,}$/u.test(word)) continue;
|
|
625
|
+
ranked(
|
|
626
|
+
icons.filter(
|
|
627
|
+
icon =>
|
|
628
|
+
icon.raw.length === 2 &&
|
|
629
|
+
icon.raw[0] === word &&
|
|
630
|
+
icon.raw[1] !== word &&
|
|
631
|
+
QUALIFIER_RE.test(icon.raw[1]) &&
|
|
632
|
+
!negated(icon.raw.slice(1)),
|
|
633
|
+
),
|
|
634
|
+
).forEach(icon => add(icon.id, word));
|
|
635
|
+
}
|
|
636
|
+
return found.slice(0, SUGGESTIONS_PER_DEFINITION);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* A word in its singular form, so a plural meets its singular and nothing
|
|
641
|
+
* else: `languages` meets `language`, `arrows` meets `arrow`. Only a
|
|
642
|
+
* trailing plural `s` comes off (not `ss`, and not from a short word); a
|
|
643
|
+
* verb ending never does, so `drafting` never meets `draft`.
|
|
644
|
+
* @param {string} word
|
|
645
|
+
*/
|
|
646
|
+
function stem(word) {
|
|
647
|
+
if (word.length > 3 && word.endsWith('s') && !word.endsWith('ss')) {
|
|
648
|
+
return word.slice(0, -1);
|
|
649
|
+
}
|
|
650
|
+
return word;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* The change that makes a set's generated module part of its package's
|
|
655
|
+
* entry ({@link entryWiringNote}), or null when the entry exports its theme
|
|
656
|
+
* map or any of its icons, the set has no generated module on disk, or the
|
|
657
|
+
* entry is an `exports` target not built yet (listed as not checked).
|
|
658
|
+
* @param {DiscoveredIconSet} set
|
|
659
|
+
* @param {string} packageDir
|
|
660
|
+
* @param {string} packageName
|
|
661
|
+
* @param {(specifier: string) => string | null} unbuiltTarget
|
|
662
|
+
* @returns {string | null}
|
|
663
|
+
*/
|
|
664
|
+
function entryNotWired(set, packageDir, packageName, unbuiltTarget) {
|
|
665
|
+
const generated = set.data.generated;
|
|
666
|
+
if (!generated || !fs.existsSync(path.join(packageDir, generated))) {
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
if (splitSpecifier(set.data.module).name !== packageName) return null;
|
|
670
|
+
if (unbuiltTarget(set.data.module)) return null;
|
|
671
|
+
const pkg = readJson(path.join(packageDir, 'package.json'));
|
|
672
|
+
if (!pkg) return null;
|
|
673
|
+
const note = entryWiringNote(packageDir, pkg, generated, {
|
|
674
|
+
module: set.data.module,
|
|
675
|
+
name: set.data.themeMap ?? THEME_MAP_NAME,
|
|
676
|
+
});
|
|
677
|
+
if (!note) return null;
|
|
678
|
+
const entry = resolveIconModule(set.data.module, packageDir, {
|
|
679
|
+
name: packageName,
|
|
680
|
+
dir: packageDir,
|
|
681
|
+
});
|
|
682
|
+
const someIcon =
|
|
683
|
+
entry &&
|
|
684
|
+
set.data.icons.some(
|
|
685
|
+
icon =>
|
|
686
|
+
(icon.module ?? set.data.module) === set.data.module &&
|
|
687
|
+
exportOriginVerdict(entry, icon.export)?.verdict !== 'lacks',
|
|
688
|
+
);
|
|
689
|
+
return someIcon ? null : note;
|
|
455
690
|
}
|
|
456
691
|
|
|
457
692
|
/**
|
|
@@ -559,10 +794,22 @@ function checkExports(set, packageDir, packageName, unchecked) {
|
|
|
559
794
|
.definitions.filter(definition => definition.doc.builtIn)
|
|
560
795
|
.map(definition => definition.doc.name),
|
|
561
796
|
);
|
|
797
|
+
// A generated module the package's entry does not export yet: one finding
|
|
798
|
+
// with the exact change \`new-set\` names in its receipt, not one per icon.
|
|
799
|
+
const wiring = entryNotWired(set, packageDir, packageName, unbuiltTarget);
|
|
800
|
+
if (wiring) {
|
|
801
|
+
issues.push(
|
|
802
|
+
issueError(
|
|
803
|
+
ICON_EXPORT_MISSING,
|
|
804
|
+
`${label}: its icons are not exported from "${set.data.module}" yet. ${wiring}`,
|
|
805
|
+
),
|
|
806
|
+
);
|
|
807
|
+
}
|
|
562
808
|
/** @type {Map<string, {file: string, name: string} | null>} */
|
|
563
809
|
const iconOrigins = new Map();
|
|
564
810
|
for (const icon of set.data.icons) {
|
|
565
811
|
const module = icon.module ?? set.data.module;
|
|
812
|
+
if (wiring && module === set.data.module) continue;
|
|
566
813
|
iconOrigins.set(
|
|
567
814
|
icon.id,
|
|
568
815
|
originOf(module, icon.export, `icon "${icon.id}"`, {icon: icon.id}),
|
|
@@ -595,6 +842,7 @@ function checkExports(set, packageDir, packageName, unchecked) {
|
|
|
595
842
|
);
|
|
596
843
|
return issues;
|
|
597
844
|
}
|
|
845
|
+
if (wiring) return issues;
|
|
598
846
|
const mapOrigin = originOf(
|
|
599
847
|
set.data.module,
|
|
600
848
|
themeMap,
|
|
@@ -665,6 +913,33 @@ function checkExports(set, packageDir, packageName, unchecked) {
|
|
|
665
913
|
return issues;
|
|
666
914
|
}
|
|
667
915
|
|
|
916
|
+
/** The lowest search score a find hint needs: a whole word or a word start. */
|
|
917
|
+
const FIND_FLOOR = 60;
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* A search that finds icons for a definition in the set, named only when it
|
|
921
|
+
* answers: the definition's name, then each of its words, as a query against
|
|
922
|
+
* the set's icon ids and words. Empty when none answers, so the message never
|
|
923
|
+
* names a search that finds nothing.
|
|
924
|
+
* @param {DiscoveredIconSet} set
|
|
925
|
+
* @param {{name: string, words: string[]}} doc
|
|
926
|
+
*/
|
|
927
|
+
function findHint(set, doc) {
|
|
928
|
+
const queries = [
|
|
929
|
+
doc.name.replace(/([a-z0-9])([A-Z])/gu, '$1 $2').toLowerCase(),
|
|
930
|
+
...doc.words,
|
|
931
|
+
];
|
|
932
|
+
for (const query of queries) {
|
|
933
|
+
const found = rankIcons([set], query).filter(
|
|
934
|
+
each => each.score >= FIND_FLOOR,
|
|
935
|
+
);
|
|
936
|
+
if (found.length > 0) {
|
|
937
|
+
return ` (icons matching "${query}": \`astryx experimental icon ${query} --set ${set.name}\`)`;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return ' (no icon in the set has its name or words: pick the library icon that draws it; if the library has none, map the closest, or add your own artwork with `astryx experimental icon add <Name> --from ./src/icons/<name>.js --definition <definition>`)';
|
|
941
|
+
}
|
|
942
|
+
|
|
668
943
|
/**
|
|
669
944
|
* The upstream checks of one set: version drift and license notices.
|
|
670
945
|
* @param {DiscoveredIconSet} set
|
|
@@ -693,7 +968,7 @@ function checkUpstream(set, packageDir, pkg) {
|
|
|
693
968
|
issues.push(
|
|
694
969
|
issueWarning(
|
|
695
970
|
ICON_SOURCE_VERSION_DRIFT,
|
|
696
|
-
`${label} was generated from ${source.package}@${source.version}, but the package resolves ${source.package}@${installed}.
|
|
971
|
+
`${label} was generated from ${source.package}@${source.version}, but the package resolves ${source.package}@${installed}. Refresh it: \`astryx experimental icon new-set ${set.name} --from <the ${source.package} module it wraps>\`, then rerun any \`add --variant … --all\`.`,
|
|
697
972
|
),
|
|
698
973
|
);
|
|
699
974
|
} else if (
|
|
@@ -704,7 +979,7 @@ function checkUpstream(set, packageDir, pkg) {
|
|
|
704
979
|
issues.push(
|
|
705
980
|
issueWarning(
|
|
706
981
|
ICON_SOURCE_VERSION_DRIFT,
|
|
707
|
-
`${label} was generated from ${source.package}@${source.version}, but the package depends on ${source.package}@${range}.
|
|
982
|
+
`${label} was generated from ${source.package}@${source.version}, but the package depends on ${source.package}@${range}. Refresh it: \`astryx experimental icon new-set ${set.name} --from <the ${source.package} module it wraps>\`, then rerun any \`add --variant … --all\`.`,
|
|
708
983
|
),
|
|
709
984
|
);
|
|
710
985
|
}
|