@astryxdesign/cli 0.7.16 → 0.7.17-canary.gb36275e
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 +13 -23
- package/api/build/_adapter.d.mts +5 -0
- package/api/build/_adapter.mjs +49 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +2 -1
- package/api/build/kit/rank.mjs +59 -12
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +238 -31
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +42 -0
- package/api/build/kit/words.mjs +82 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +46 -5
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +217 -5
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +77 -6
- package/api/doctor/built-checks.mjs +38 -13
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/render/_adapter.mjs +531 -192
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +30 -0
- package/api/render/render.type.mjs +19 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_result.d.mts +5 -5
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +10 -0
- package/api/theme/build/build.d.mts +47 -0
- package/api/theme/build/build.mjs +147 -25
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +48 -0
- package/api/theme-edit/_adapter.mjs +675 -42
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1481 -252
- package/api/theme-edit/_color.d.mts +9 -0
- package/api/theme-edit/_color.mjs +41 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +1196 -88
- package/api/theme-edit/_how-commands.d.mts +57 -0
- package/api/theme-edit/_how-commands.mjs +536 -1
- package/api/theme-edit/_how-question.d.mts +65 -0
- package/api/theme-edit/_how-question.mjs +4401 -225
- package/api/theme-edit/_how.mjs +104 -4
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +153 -0
- package/api/theme-edit/_normal.mjs +661 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +103 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +205 -17
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +447 -89
- package/api/theme-edit/_settings.d.mts +176 -5
- package/api/theme-edit/_settings.mjs +1936 -128
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +32 -1
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/assets/codemods/run-codemod.mjs +73 -6
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +43 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +20 -2
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +22 -14
- package/clients/cli/commands/experimental/render.mjs +32 -1
- package/clients/cli/commands/experimental/theme.mjs +65 -14
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +153 -5
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +27 -2
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +20 -7
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +173 -10
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +163 -53
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/module-loader.d.mts +18 -2
- package/foundation/fs/module-loader.mjs +92 -20
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/render/embedded-imports.d.mts +5 -4
- package/foundation/render/embedded-imports.mjs +7 -16
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +83 -13
- package/foundation/render/render-page.d.mts +34 -2
- package/foundation/render/render-page.mjs +210 -29
- package/foundation/render/source-block.d.mts +73 -6
- package/foundation/render/source-block.mjs +170 -19
- package/foundation/render/ts-paths.d.mts +53 -6
- package/foundation/render/ts-paths.mjs +286 -41
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +10 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +16 -3
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +13 -0
- package/host/index.mjs +8 -6
- package/package.json +6 -6
package/api/theme-edit/_edit.mjs
CHANGED
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
* @position api/theme-edit — imported only by _adapter.mjs
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import {THEME_SLUG_RE} from '../../foundation/discovery/theme-discovery.mjs';
|
|
12
13
|
import * as fs from 'node:fs';
|
|
13
14
|
import {coversProperty} from './_css.mjs';
|
|
14
15
|
import * as path from 'node:path';
|
|
15
16
|
import {AstryxError} from '../error.mjs';
|
|
16
|
-
import {vetSuggestions} from './_vet.mjs';
|
|
17
|
+
import {readSetLine, vetSuggestions} from './_vet.mjs';
|
|
18
|
+
import {colorPair, offersTyped} from './_normal.mjs';
|
|
17
19
|
import {
|
|
18
20
|
AUTO_SPREAD,
|
|
19
21
|
CORNERS,
|
|
@@ -38,6 +40,8 @@ import {
|
|
|
38
40
|
radiusTokenOf,
|
|
39
41
|
contrastProblems,
|
|
40
42
|
describe,
|
|
43
|
+
entryDamage,
|
|
44
|
+
entryNotes,
|
|
41
45
|
keyOf,
|
|
42
46
|
loadTheme,
|
|
43
47
|
maskedSettings,
|
|
@@ -66,13 +70,18 @@ import {
|
|
|
66
70
|
NEW_MARKER,
|
|
67
71
|
clearNewMarker,
|
|
68
72
|
refuseThemeSource,
|
|
69
|
-
|
|
73
|
+
settingsEntriesOk,
|
|
70
74
|
slugFor,
|
|
75
|
+
typedThemeName,
|
|
76
|
+
themeNameReadings,
|
|
71
77
|
themeSource,
|
|
72
78
|
themeSourceProblem,
|
|
73
79
|
refuseThemeParse,
|
|
74
80
|
ownSourceTokens,
|
|
75
81
|
ownSourceTokenValues,
|
|
82
|
+
ownTokenEntries,
|
|
83
|
+
evaluatedOwnTokens,
|
|
84
|
+
nonTextMessage,
|
|
76
85
|
ownPartTokens,
|
|
77
86
|
PHONE_TYPE,
|
|
78
87
|
refreshSourceStamp,
|
|
@@ -83,16 +92,14 @@ import {
|
|
|
83
92
|
refuseLinks,
|
|
84
93
|
usableNewName,
|
|
85
94
|
FOLDER_JUNK,
|
|
95
|
+
folderIsEmpty,
|
|
86
96
|
dialValueFits,
|
|
87
97
|
holdAfterBuild,
|
|
98
|
+
fieldsMeant,
|
|
88
99
|
} from './_settings.mjs';
|
|
89
|
-
import {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
normalizeEntry,
|
|
93
|
-
storedProblems,
|
|
94
|
-
} from './_check.mjs';
|
|
95
|
-
import {MODAL} from './_compiler.mjs';
|
|
100
|
+
import {checkSetting, normalizeEntry, storedProblems} from './_check.mjs';
|
|
101
|
+
import {MODAL, isColorToken} from './_compiler.mjs';
|
|
102
|
+
import {colorProblem} from './_color.mjs';
|
|
96
103
|
import {
|
|
97
104
|
PALETTE_DIALS,
|
|
98
105
|
VIBRANCY_DEFAULT,
|
|
@@ -105,15 +112,21 @@ import {
|
|
|
105
112
|
writeWhole,
|
|
106
113
|
isGraySeed,
|
|
107
114
|
seedOf,
|
|
115
|
+
isEditorTemp,
|
|
108
116
|
} from './_palette.mjs';
|
|
109
117
|
import {
|
|
110
118
|
renderPreview,
|
|
111
119
|
renderSheet,
|
|
112
120
|
previewIsCurrent,
|
|
113
121
|
takeFirstAppCopy,
|
|
122
|
+
appCopyBehind,
|
|
123
|
+
appCopyStale,
|
|
124
|
+
copyFontsCss,
|
|
114
125
|
writeAppCopy,
|
|
115
126
|
} from './_preview.mjs';
|
|
116
127
|
import {appWiring, refreshPreviewRoute, seeLine} from './_preview-app.mjs';
|
|
128
|
+
/** The preview command, as a person runs it. */
|
|
129
|
+
const PREVIEW_CMD = `${P.replace(/ editor$/, '')} preview`;
|
|
117
130
|
import {baseInstalled, baseResolved, installLine} from './_project.mjs';
|
|
118
131
|
import {reactMissing} from './_parts.mjs';
|
|
119
132
|
import {
|
|
@@ -129,6 +142,7 @@ import {
|
|
|
129
142
|
} from './_context.mjs';
|
|
130
143
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
131
144
|
import {
|
|
145
|
+
formatCliCommand,
|
|
132
146
|
getCliInvocation,
|
|
133
147
|
quoteCommandArgument,
|
|
134
148
|
} from '../../foundation/env/package-manager.mjs';
|
|
@@ -174,9 +188,8 @@ function editorLeftovers(dir, slug, damaged = false) {
|
|
|
174
188
|
/^(preview(-[a-z]+)?\.(html|png)|sheet(-[a-z-]+)?\.(html|png)|palette\.config\.json)$/.test(
|
|
175
189
|
n,
|
|
176
190
|
) ||
|
|
177
|
-
// The editor's temp names
|
|
178
|
-
|
|
179
|
-
/^\..+\.(astryx-\d+-[a-z0-9]+\.tmp|tmp-[\w-]+)$/.test(n);
|
|
191
|
+
// The editor's temp names (writes, builds, pictures).
|
|
192
|
+
isEditorTemp(n);
|
|
180
193
|
for (const e of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
181
194
|
const p = path.join(dir, e.name);
|
|
182
195
|
if (FOLDER_JUNK.has(e.name)) continue;
|
|
@@ -209,7 +222,9 @@ function editorLeftovers(dir, slug, damaged = false) {
|
|
|
209
222
|
/** Whether a settings file parses, in the shape the editor reads. @param {string} file */
|
|
210
223
|
function readableJson(file) {
|
|
211
224
|
try {
|
|
212
|
-
|
|
225
|
+
// An entry with no thing or no source is damage too: `new` keeps the
|
|
226
|
+
// file aside, as the refusal for it says.
|
|
227
|
+
return settingsEntriesOk(
|
|
213
228
|
JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '')),
|
|
214
229
|
);
|
|
215
230
|
} catch {
|
|
@@ -346,10 +361,20 @@ export async function themeEditNew(name, options = {}) {
|
|
|
346
361
|
/** @type {string | null | undefined} */ likeValue = likeFixed,
|
|
347
362
|
) => `${P} new ${newName}${newFlags(likeValue, fitSettings, png)}`;
|
|
348
363
|
if (!slugOk(name)) {
|
|
349
|
-
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
364
|
+
// A path typed for the name (themes/brand, ./t, t/) names the theme the
|
|
365
|
+
// path ends in.
|
|
366
|
+
// A file name, the app copy's export (tTheme), camelCase or spaces
|
|
367
|
+
// (BrandDark, "Brand Dark") name the theme they read as: when it is
|
|
368
|
+
// here already, that is said, never a numbered second copy offered.
|
|
369
|
+
const typed = String(name ?? '');
|
|
370
|
+
const path_ = /[\\/]/.test(typed);
|
|
371
|
+
const readings = themeNameReadings(typed);
|
|
372
|
+
const present = readings.find(n =>
|
|
373
|
+
fs.existsSync(themeFiles(cwd, n).settings),
|
|
374
|
+
);
|
|
375
|
+
const fixed =
|
|
376
|
+
present ?? readings[0] ?? slugFor(path_ ? typedThemeName(typed) : typed);
|
|
377
|
+
const exists = Boolean(present);
|
|
353
378
|
refuse(
|
|
354
379
|
E.ERR_INVALID_ARGUMENT,
|
|
355
380
|
`"${String(name ?? '').slice(0, 80)}" is not a theme name (${NAME_RULE})${exists ? `; ${fixed} is a theme here already` : ''}.${dropped}`,
|
|
@@ -360,6 +385,16 @@ export async function themeEditNew(name, options = {}) {
|
|
|
360
385
|
},
|
|
361
386
|
);
|
|
362
387
|
}
|
|
388
|
+
// A name the theme commands' own discovery skips ("a--b", "b-") would
|
|
389
|
+
// make an app copy no `theme add`, `theme list` or doctor takes.
|
|
390
|
+
if (!THEME_SLUG_RE.test(name)) {
|
|
391
|
+
const cleaned = name.replace(/-{2,}/g, '-').replace(/-+$/, '');
|
|
392
|
+
refuse(
|
|
393
|
+
E.ERR_INVALID_ARGUMENT,
|
|
394
|
+
`"${name}" is not a theme name the theme commands take: a dash only between letters or digits (no two in a row, none at the end), so its app copy in src/themes/ would be skipped by theme add, theme list and doctor.${dropped}`,
|
|
395
|
+
{run: [again(usableNewName(cwd, cleaned))]},
|
|
396
|
+
);
|
|
397
|
+
}
|
|
363
398
|
// A built-in theme's name would collide with the theme of that name the
|
|
364
399
|
// app may also use.
|
|
365
400
|
if (LIKE.includes(name))
|
|
@@ -426,7 +461,8 @@ export async function themeEditNew(name, options = {}) {
|
|
|
426
461
|
const holdsOther =
|
|
427
462
|
fs.existsSync(f.dir) &&
|
|
428
463
|
!left &&
|
|
429
|
-
|
|
464
|
+
// Empty folders (an empty tokens/) hold nothing of anyone's.
|
|
465
|
+
!folderIsEmpty(f.dir);
|
|
430
466
|
if (holdsOther)
|
|
431
467
|
refuse(
|
|
432
468
|
E.ERR_FILE_EXISTS,
|
|
@@ -576,7 +612,7 @@ export async function themeEditNew(name, options = {}) {
|
|
|
576
612
|
}
|
|
577
613
|
refuseIfLockLost();
|
|
578
614
|
fs.rmSync(marker, {force: true});
|
|
579
|
-
const p = await previewAndRoute(ctx, name, data, png);
|
|
615
|
+
const p = await previewAndRoute(ctx, name, data, png, 'overview', 'new');
|
|
580
616
|
/** @type {string[]} */
|
|
581
617
|
const notes = [
|
|
582
618
|
...keptNotes,
|
|
@@ -655,15 +691,34 @@ function applyNewSettings(
|
|
|
655
691
|
/** @type {import('./_settings.mjs').Setting} */
|
|
656
692
|
let s;
|
|
657
693
|
try {
|
|
658
|
-
|
|
694
|
+
// The same input cleanup set gives a typed value (quotes of any
|
|
695
|
+
// kind around a font, invisible spaces, a pasted `name: value`).
|
|
696
|
+
const typed = normalizeEntry(thing, String(value)).value;
|
|
697
|
+
s = checkSetting(
|
|
698
|
+
ctx,
|
|
699
|
+
slug,
|
|
700
|
+
data,
|
|
701
|
+
thing,
|
|
702
|
+
typed ?? String(value),
|
|
703
|
+
{},
|
|
704
|
+
false,
|
|
705
|
+
);
|
|
659
706
|
} catch (e) {
|
|
660
|
-
throw
|
|
661
|
-
|
|
707
|
+
throw newColorPair(
|
|
708
|
+
asNewRefusal(
|
|
709
|
+
vetSuggestions(e, ctx, slug, data),
|
|
710
|
+
slug,
|
|
711
|
+
settings,
|
|
712
|
+
likeFlag,
|
|
713
|
+
png,
|
|
714
|
+
{thing, index},
|
|
715
|
+
),
|
|
662
716
|
slug,
|
|
663
717
|
settings,
|
|
664
718
|
likeFlag,
|
|
665
719
|
png,
|
|
666
|
-
|
|
720
|
+
thing,
|
|
721
|
+
String(value),
|
|
667
722
|
);
|
|
668
723
|
}
|
|
669
724
|
if (thing === 'mode')
|
|
@@ -771,6 +826,81 @@ function asNewRefusal(e, slug, settings, like, png = false, at = null) {
|
|
|
771
826
|
return e;
|
|
772
827
|
}
|
|
773
828
|
|
|
829
|
+
/**
|
|
830
|
+
* A color dial on `new` given a light and a dark color ("light #111111 dark
|
|
831
|
+
* #eeeeee"): the refusal offers the user's own colors, per mode, as set
|
|
832
|
+
* does, never a stock color they did not type.
|
|
833
|
+
* @param {unknown} e
|
|
834
|
+
* @param {string} slug
|
|
835
|
+
* @param {Record<string, any>} settings
|
|
836
|
+
* @param {string | undefined} like
|
|
837
|
+
* @param {boolean} png
|
|
838
|
+
* @param {string} thing
|
|
839
|
+
* @param {string} typed
|
|
840
|
+
*/
|
|
841
|
+
function newColorPair(e, slug, settings, like, png, thing, typed) {
|
|
842
|
+
if (!(e instanceof AstryxError) || !PALETTE_DIALS.includes(thing)) return e;
|
|
843
|
+
const typedLower = typed.toLowerCase();
|
|
844
|
+
// A color in a line the user did not type (a stock example) goes.
|
|
845
|
+
e.suggestions = (e.suggestions ?? []).filter(x => {
|
|
846
|
+
if (!x.name.startsWith(`${P} new `)) return true;
|
|
847
|
+
const m = new RegExp(`--${thing} '?(#[0-9a-f]{3,8})'?`, 'i').exec(x.name);
|
|
848
|
+
return !m || typedLower.includes(m[1].toLowerCase());
|
|
849
|
+
});
|
|
850
|
+
// With every color line gone, the same new without that color, every
|
|
851
|
+
// other option kept.
|
|
852
|
+
if (!e.suggestions.some(x => x.name.startsWith(`${P} new `)))
|
|
853
|
+
e.suggestions.push({
|
|
854
|
+
name: `${P} new ${slug}${newFlags(like, {...settings, [thing]: undefined}, png)}`,
|
|
855
|
+
reason: `without --${thing} ${quoteCommandArgument(typed)}`,
|
|
856
|
+
});
|
|
857
|
+
/** @type {Record<string, string>} */
|
|
858
|
+
const pair = {};
|
|
859
|
+
for (const m of typed.matchAll(
|
|
860
|
+
/\b(light|dark)\b\s*(?:mode\s*)?[:=]?\s*(#[0-9a-f]{3,8}\b|[a-z]+\([^)]*\)|[a-z]+)/gi,
|
|
861
|
+
))
|
|
862
|
+
pair[m[1].toLowerCase()] = m[2];
|
|
863
|
+
if (!pair.light && !pair.dark) return e;
|
|
864
|
+
const mode = String(
|
|
865
|
+
Array.isArray(settings.mode) ? settings.mode[0] : (settings.mode ?? 'both'),
|
|
866
|
+
);
|
|
867
|
+
/** @type {Array<{name: string, reason: string}>} */
|
|
868
|
+
const lines = [];
|
|
869
|
+
/** @param {string} color @param {string} reason @param {Record<string, any>} [extra] */
|
|
870
|
+
const line = (color, reason, extra = {}) =>
|
|
871
|
+
lines.push({
|
|
872
|
+
name: `${P} new ${slug}${newFlags(like, {...settings, ...extra, [thing]: color}, png)}`,
|
|
873
|
+
reason,
|
|
874
|
+
});
|
|
875
|
+
if (mode === 'dark-only' && pair.dark)
|
|
876
|
+
line(pair.dark, 'do this instead: the dark color you gave');
|
|
877
|
+
else if (mode === 'light-only' && pair.light)
|
|
878
|
+
line(pair.light, 'do this instead: the light color you gave');
|
|
879
|
+
else if (mode === 'both') {
|
|
880
|
+
if (pair.light)
|
|
881
|
+
line(
|
|
882
|
+
pair.light,
|
|
883
|
+
`the light color you gave; then set ${slug} --color-${thing} ${pair.dark ?? '…'} --mode dark for the dark one`,
|
|
884
|
+
);
|
|
885
|
+
if (pair.dark)
|
|
886
|
+
line(pair.dark, 'or a dark-only theme with the dark color you gave', {
|
|
887
|
+
mode: 'dark-only',
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
// No color for the mode the theme has: how the dial works, and the
|
|
891
|
+
// same new without it, never a color made up.
|
|
892
|
+
if (!lines.length)
|
|
893
|
+
lines.push({
|
|
894
|
+
name: `${P} how ${thing}`,
|
|
895
|
+
reason: `no ${mode === 'light-only' ? 'light' : 'dark'} color was given for this ${mode} theme`,
|
|
896
|
+
});
|
|
897
|
+
e.suggestions = [
|
|
898
|
+
...lines,
|
|
899
|
+
...(e.suggestions ?? []).filter(x => !lines.some(l => l.name === x.name)),
|
|
900
|
+
];
|
|
901
|
+
return e;
|
|
902
|
+
}
|
|
903
|
+
|
|
774
904
|
/**
|
|
775
905
|
* Headings values with every later value for an axis already given left
|
|
776
906
|
* out (the first weight and the first tracking stay); a word of neither
|
|
@@ -822,6 +952,32 @@ function changeFocus(s) {
|
|
|
822
952
|
return 'overview';
|
|
823
953
|
}
|
|
824
954
|
|
|
955
|
+
/**
|
|
956
|
+
* A signal handler for the checks and pictures after a change is saved: it
|
|
957
|
+
* says what is saved (in the words of the command that ran) and how to run
|
|
958
|
+
* what did not, with the project's own CLI invocation, then lets the
|
|
959
|
+
* signal end the process (the render's own handler re-raises it; with none,
|
|
960
|
+
* this one does).
|
|
961
|
+
* @param {string} slug
|
|
962
|
+
* @param {'set' | 'undo' | 'new'} [kind] the command that saved
|
|
963
|
+
* @param {string} [cwd] the project, for the CLI invocation
|
|
964
|
+
* @returns {(sig: NodeJS.Signals) => void}
|
|
965
|
+
*/
|
|
966
|
+
export function stoppedAfterSave(slug, kind = 'set', cwd = process.cwd()) {
|
|
967
|
+
const done =
|
|
968
|
+
kind === 'undo'
|
|
969
|
+
? `the undo is done: ${slug} is saved and built as it was before that change`
|
|
970
|
+
: kind === 'new'
|
|
971
|
+
? `${slug} is made and built`
|
|
972
|
+
: `the change to ${slug} is saved and built (and its undo step kept)`;
|
|
973
|
+
return sig => {
|
|
974
|
+
process.stderr.write(
|
|
975
|
+
`Stopped: ${done}; its checks and pictures did not run. ${formatCliCommand(`${P} show ${slug}`, cwd)} runs them.\n`,
|
|
976
|
+
);
|
|
977
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
|
|
825
981
|
/**
|
|
826
982
|
* The preview after a change, with the in-app preview route kept in step:
|
|
827
983
|
* its imports follow the theme, such as the stylesheet of a font package
|
|
@@ -832,13 +988,34 @@ function changeFocus(s) {
|
|
|
832
988
|
* @param {boolean} png
|
|
833
989
|
* @param {'colors' | 'components' | 'overview'} [focus] the preview page
|
|
834
990
|
* most about the change: Colors for a color, Components for a part
|
|
991
|
+
* @param {'set' | 'undo' | 'new'} [kind] the command that saved
|
|
835
992
|
*/
|
|
836
|
-
async function previewAndRoute(
|
|
837
|
-
|
|
993
|
+
async function previewAndRoute(
|
|
994
|
+
ctx,
|
|
995
|
+
slug,
|
|
996
|
+
data,
|
|
997
|
+
png,
|
|
998
|
+
focus = 'overview',
|
|
999
|
+
kind = /** @type {'set' | 'undo' | 'new'} */ ('set'),
|
|
1000
|
+
) {
|
|
1001
|
+
// Stopped (Ctrl-C) while the checks and pictures run: the change is saved
|
|
1002
|
+
// and built already, which one line says before the process ends.
|
|
1003
|
+
const stopped = stoppedAfterSave(slug, kind, ctx.project.cwd);
|
|
1004
|
+
process.once('SIGINT', stopped);
|
|
1005
|
+
process.once('SIGTERM', stopped);
|
|
1006
|
+
/** @type {Awaited<ReturnType<typeof previewAfter>>} */
|
|
1007
|
+
let p;
|
|
1008
|
+
try {
|
|
1009
|
+
p = await previewAfter(ctx, slug, data, png);
|
|
1010
|
+
} finally {
|
|
1011
|
+
process.removeListener('SIGINT', stopped);
|
|
1012
|
+
process.removeListener('SIGTERM', stopped);
|
|
1013
|
+
}
|
|
838
1014
|
const wrote = takeFirstAppCopy(ctx.project.cwd, slug);
|
|
1015
|
+
const previewStale = await keepPreviewRoute(ctx, slug);
|
|
839
1016
|
return {
|
|
840
1017
|
...p,
|
|
841
|
-
previewStale
|
|
1018
|
+
previewStale,
|
|
842
1019
|
// How to see the change: the page about it, at its own URL.
|
|
843
1020
|
// A page not written this time (preview null) still shows the theme
|
|
844
1021
|
// as it was; checks that failed with the page written do not.
|
|
@@ -852,9 +1029,18 @@ async function previewAndRoute(ctx, slug, data, png, focus = 'overview') {
|
|
|
852
1029
|
cause: 'no preview was rendered',
|
|
853
1030
|
})
|
|
854
1031
|
: null,
|
|
1032
|
+
{
|
|
1033
|
+
// Only a run that took no picture failed: a note on pictures that
|
|
1034
|
+
// were taken (cut to 2400 pixels, adopted) is not a failure.
|
|
1035
|
+
pictureProblem:
|
|
1036
|
+
png && !(p.pictures ?? []).length ? p.pictureProblem : null,
|
|
1037
|
+
stale: previewStale,
|
|
1038
|
+
},
|
|
855
1039
|
),
|
|
856
1040
|
// The first time the theme's app copy is written, its files are named.
|
|
857
1041
|
...(wrote ? {appCopy: {wrote}} : {}),
|
|
1042
|
+
// A copy a file of yours kept from being written: said, never a quiet ok.
|
|
1043
|
+
...appCopyStale(ctx.project.cwd, slug),
|
|
858
1044
|
};
|
|
859
1045
|
}
|
|
860
1046
|
|
|
@@ -870,12 +1056,48 @@ async function previewAndRoute(ctx, slug, data, png, focus = 'overview') {
|
|
|
870
1056
|
async function keepPreviewRoute(ctx, slug) {
|
|
871
1057
|
try {
|
|
872
1058
|
return (await refreshPreviewRoute(ctx.project.cwd, slug)).stale;
|
|
873
|
-
} catch {
|
|
874
|
-
// A
|
|
1059
|
+
} catch (e) {
|
|
1060
|
+
// A route that could not be written (its permissions, a folder in its
|
|
1061
|
+
// place) does not follow this change: said, never a quiet ok. A
|
|
1062
|
+
// damaged preview record is named by the preview commands themselves.
|
|
1063
|
+
const code = /** @type {any} */ (e)?.code;
|
|
1064
|
+
if (code && /^E[A-Z]+$/.test(code)) {
|
|
1065
|
+
const where = /** @type {any} */ (e)?.path;
|
|
1066
|
+
return [
|
|
1067
|
+
`${where ? path.relative(ctx.project.cwd, where) : 'the in-app preview route'} could not be written (${code}), so the in-app preview does not follow this change; fix its permissions, then ${PREVIEW_CMD} add writes it again`,
|
|
1068
|
+
];
|
|
1069
|
+
}
|
|
875
1070
|
return [];
|
|
876
1071
|
}
|
|
877
1072
|
}
|
|
878
1073
|
|
|
1074
|
+
/**
|
|
1075
|
+
* What a change of mode asks of the app's wiring: a one-mode theme is
|
|
1076
|
+
* given its mode by the app's <Theme>, and one back to both modes no longer.
|
|
1077
|
+
* @param {string} slug
|
|
1078
|
+
* @param {string | undefined} before
|
|
1079
|
+
* @param {string | undefined} after
|
|
1080
|
+
* @returns {string[]}
|
|
1081
|
+
*/
|
|
1082
|
+
function modeWiringNotes(slug, before, after) {
|
|
1083
|
+
const one = (/** @type {string | undefined} */ m) =>
|
|
1084
|
+
m === 'light-only' ? 'light' : m === 'dark-only' ? 'dark' : null;
|
|
1085
|
+
const [was, now] = [one(before), one(after)];
|
|
1086
|
+
if (was === now) return [];
|
|
1087
|
+
return [
|
|
1088
|
+
...(was
|
|
1089
|
+
? [
|
|
1090
|
+
`if the app's <Theme> was given mode="${was}" for ${slug}, take it out${now ? ` (or make it mode="${now}")` : ''}: with it the app stays ${was}, whatever the system asks for`,
|
|
1091
|
+
]
|
|
1092
|
+
: []),
|
|
1093
|
+
...(now && !was
|
|
1094
|
+
? [
|
|
1095
|
+
`the app shows ${slug} in ${now} mode when its <Theme> is given mode="${now}" (<Theme theme={…} mode="${now}">), as the preview does; the theme keeps both halves of its colors, so a toast or a lightbox Core draws in the other mode stays readable`,
|
|
1096
|
+
]
|
|
1097
|
+
: []),
|
|
1098
|
+
];
|
|
1099
|
+
}
|
|
1100
|
+
|
|
879
1101
|
/**
|
|
880
1102
|
* Change one thing in a theme: checked, built, previewed.
|
|
881
1103
|
* @experimental
|
|
@@ -900,9 +1122,39 @@ export async function themeEditSet(theme, thing, value, options = {}) {
|
|
|
900
1122
|
function refuseStoredTokens(ctx, slug, data, skip) {
|
|
901
1123
|
const bad = storedProblems(ctx, slug, data, skip);
|
|
902
1124
|
if (!bad.length) return;
|
|
1125
|
+
// A repair offers only the value it holds, cleaned: never a stock value
|
|
1126
|
+
// the saved setting did not hold.
|
|
1127
|
+
for (const b of bad) {
|
|
1128
|
+
if (b.fix && !offersTyped(String(b.fix), String(b.setting.value)))
|
|
1129
|
+
delete b.fix;
|
|
1130
|
+
// A light and a dark color saved as one (`red / blue`) is that pair.
|
|
1131
|
+
const pair =
|
|
1132
|
+
!b.fix && isColorToken(b.setting.thing)
|
|
1133
|
+
? colorPair(String(b.setting.value))
|
|
1134
|
+
: null;
|
|
1135
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark))
|
|
1136
|
+
b.fix = `light-dark(${pair.light}, ${pair.dark})`;
|
|
1137
|
+
}
|
|
903
1138
|
const found = bad.length === 1 ? bad[0] : null;
|
|
904
1139
|
// A clean value is offered only when set takes it, so the line works.
|
|
905
1140
|
const takes = (/** @type {typeof found} */ b) => {
|
|
1141
|
+
if (!b?.fix) return true;
|
|
1142
|
+
// A value whose only fault was curly quotes around it: without them,
|
|
1143
|
+
// when set takes that (`“#e11d48”` is #e11d48).
|
|
1144
|
+
const bare = /^(["'])(.*)\1$/.exec(b.fix)?.[2];
|
|
1145
|
+
if (
|
|
1146
|
+
bare &&
|
|
1147
|
+
b.setting.source === 'token' &&
|
|
1148
|
+
!/font|content/.test(b.setting.thing)
|
|
1149
|
+
) {
|
|
1150
|
+
const was = b.fix;
|
|
1151
|
+
b.fix = bare;
|
|
1152
|
+
if (takesOne(b)) return true;
|
|
1153
|
+
b.fix = was;
|
|
1154
|
+
}
|
|
1155
|
+
return takesOne(b);
|
|
1156
|
+
};
|
|
1157
|
+
const takesOne = (/** @type {typeof found} */ b) => {
|
|
906
1158
|
if (!b?.fix) return true;
|
|
907
1159
|
try {
|
|
908
1160
|
checkSetting(
|
|
@@ -941,13 +1193,14 @@ function refuseStoredTokens(ctx, slug, data, skip) {
|
|
|
941
1193
|
// A value to set only for a token whose stored value has the wrong
|
|
942
1194
|
// type; any other thing `set` would refuse, or read as a dial.
|
|
943
1195
|
...(one &&
|
|
1196
|
+
one.fix &&
|
|
944
1197
|
!one.scope &&
|
|
945
1198
|
one.setting.source === 'token' &&
|
|
946
1199
|
ctx.C.isToken(one.setting.thing)
|
|
947
1200
|
? [
|
|
948
1201
|
// The value the check suggests for this value, else a stock
|
|
949
1202
|
// one of the token's type.
|
|
950
|
-
`${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(one.fix
|
|
1203
|
+
`${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(String(one.fix))}`,
|
|
951
1204
|
]
|
|
952
1205
|
: one && one.fix && one.setting.source === 'dial'
|
|
953
1206
|
? [
|
|
@@ -977,6 +1230,282 @@ export async function editorStoredRefusal(root, slug) {
|
|
|
977
1230
|
}
|
|
978
1231
|
}
|
|
979
1232
|
|
|
1233
|
+
/**
|
|
1234
|
+
* The token values the theme's own source gives that `set` refuses (a
|
|
1235
|
+
* radius of `banana`, a color of `12px`), each with why and the line of
|
|
1236
|
+
* the file that sets it; checked with the very rules `set` uses.
|
|
1237
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1238
|
+
* @param {string} slug
|
|
1239
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1240
|
+
* @returns {Promise<Array<{token: string, value: string, why: string, line: number | null}>>}
|
|
1241
|
+
*/
|
|
1242
|
+
async function ownTokenProblems(ctx, slug, data) {
|
|
1243
|
+
const {cwd} = ctx.project;
|
|
1244
|
+
/** @type {Array<{token: string, value: string, why: string, line: number | null}>} */
|
|
1245
|
+
const out = [];
|
|
1246
|
+
const known = ctx.project.core.tokenDefaults;
|
|
1247
|
+
/** @param {string} token @param {string} value @returns {string | null} */
|
|
1248
|
+
const refused = (token, value) => {
|
|
1249
|
+
try {
|
|
1250
|
+
checkSetting(ctx, slug, {...data, settings: []}, token, value, {});
|
|
1251
|
+
return null;
|
|
1252
|
+
} catch (e) {
|
|
1253
|
+
if (!(e instanceof AstryxError)) throw e;
|
|
1254
|
+
return e.message.replace(/ Nothing was changed\.$/, '');
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
// The tokens map as written, entry by entry, with the line that sets
|
|
1258
|
+
// each: every value is checked as `set` checks it (each half of a
|
|
1259
|
+
// [light, dark] pair; a number is not text, as show says), and what only
|
|
1260
|
+
// a build can read (an imported module, an expression) is read from a
|
|
1261
|
+
// build made now, so nothing ships unchecked.
|
|
1262
|
+
const entries = ownTokenEntries(cwd, slug);
|
|
1263
|
+
const needsBuild = entries.some(
|
|
1264
|
+
e => e.kind === 'unresolved' || (e.kind === 'other' && e.token),
|
|
1265
|
+
);
|
|
1266
|
+
const evaluated = needsBuild ? await evaluatedOwnTokens(ctx, slug) : null;
|
|
1267
|
+
const seen = new Set();
|
|
1268
|
+
for (const e of entries) {
|
|
1269
|
+
if (e.kind === 'duplicate') {
|
|
1270
|
+
out.push({
|
|
1271
|
+
token: 'tokens',
|
|
1272
|
+
value: '',
|
|
1273
|
+
why: `defineTheme is given tokens twice (lines ${(e.lines ?? []).join(' and ')}); the build keeps only the last, so the first does nothing: merge them into one`,
|
|
1274
|
+
line: e.line,
|
|
1275
|
+
});
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
if (e.kind === 'typography') {
|
|
1279
|
+
const why = typographyProblem(e.key, e.value);
|
|
1280
|
+
if (why)
|
|
1281
|
+
out.push({
|
|
1282
|
+
token: `typography.${e.key}`,
|
|
1283
|
+
value: e.value == null ? '' : String(e.value),
|
|
1284
|
+
why,
|
|
1285
|
+
line: e.line,
|
|
1286
|
+
});
|
|
1287
|
+
continue;
|
|
1288
|
+
}
|
|
1289
|
+
if (e.kind === 'unresolved') continue;
|
|
1290
|
+
if (e.token == null) {
|
|
1291
|
+
out.push({
|
|
1292
|
+
token: e.key,
|
|
1293
|
+
value: '',
|
|
1294
|
+
why: `the key ${e.key} is computed, so the editor cannot read which token it sets and has not checked its value; write the token's name as text, such as '--radius-page'`,
|
|
1295
|
+
line: e.line,
|
|
1296
|
+
});
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
const token = e.token;
|
|
1300
|
+
seen.add(token);
|
|
1301
|
+
if (!(token in known)) continue;
|
|
1302
|
+
if (e.kind === 'object') {
|
|
1303
|
+
out.push({
|
|
1304
|
+
token,
|
|
1305
|
+
value: '',
|
|
1306
|
+
why: nonTextMessage(ctx, slug, [token, e.value, 'object']),
|
|
1307
|
+
line: e.line,
|
|
1308
|
+
});
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
if (e.kind === 'number') {
|
|
1312
|
+
out.push({
|
|
1313
|
+
token,
|
|
1314
|
+
value: String(e.value),
|
|
1315
|
+
why: nonTextMessage(ctx, slug, [token, e.value]),
|
|
1316
|
+
line: e.line,
|
|
1317
|
+
});
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
if (e.kind === 'text') {
|
|
1321
|
+
const why = refused(token, String(e.value));
|
|
1322
|
+
if (why) out.push({token, value: String(e.value), why, line: e.line});
|
|
1323
|
+
continue;
|
|
1324
|
+
}
|
|
1325
|
+
if (e.kind === 'pair') {
|
|
1326
|
+
const halves = e.halves ?? [];
|
|
1327
|
+
if (halves.length === 2 && halves.some(h => typeof h !== 'string')) {
|
|
1328
|
+
out.push({
|
|
1329
|
+
token,
|
|
1330
|
+
value: '',
|
|
1331
|
+
why: nonTextMessage(ctx, slug, [token, halves]),
|
|
1332
|
+
line: e.line,
|
|
1333
|
+
});
|
|
1334
|
+
continue;
|
|
1335
|
+
}
|
|
1336
|
+
// A pair is exactly two values in quotes: one or none builds
|
|
1337
|
+
// light-dark(red, undefined), a third is dropped.
|
|
1338
|
+
if (halves.length !== 2) {
|
|
1339
|
+
out.push({
|
|
1340
|
+
token,
|
|
1341
|
+
value: `[${halves.map(h => (h === undefined ? '' : JSON.stringify(h))).join(', ')}]`,
|
|
1342
|
+
why: `a [light, dark] pair holds exactly two values in quotes, and this holds ${halves.length}; the build would write ${halves.length < 2 ? 'light-dark() with an undefined half' : 'the first two and drop the rest'}`,
|
|
1343
|
+
line: e.line,
|
|
1344
|
+
});
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
if (!isColorToken(token)) continue;
|
|
1348
|
+
halves.forEach((h, i) => {
|
|
1349
|
+
const why = refused(token, String(h));
|
|
1350
|
+
if (why)
|
|
1351
|
+
out.push({
|
|
1352
|
+
token,
|
|
1353
|
+
value: String(h),
|
|
1354
|
+
why: `its ${i === 0 ? 'light' : 'dark'} half: ${why}`,
|
|
1355
|
+
line: e.line,
|
|
1356
|
+
});
|
|
1357
|
+
});
|
|
1358
|
+
continue;
|
|
1359
|
+
}
|
|
1360
|
+
// An expression ('ban' + 'ana', a ternary, a template with ${}): the
|
|
1361
|
+
// value a build makes of it, else named as not checked.
|
|
1362
|
+
const v = evaluated?.get(token);
|
|
1363
|
+
// A pair on a token that is not a color is the pair refusal's.
|
|
1364
|
+
if (
|
|
1365
|
+
typeof v === 'string' &&
|
|
1366
|
+
/^light-dark\(/i.test(v) &&
|
|
1367
|
+
!isColorToken(token)
|
|
1368
|
+
)
|
|
1369
|
+
continue;
|
|
1370
|
+
if (typeof v === 'string') {
|
|
1371
|
+
const why = refused(token, v);
|
|
1372
|
+
if (why) out.push({token, value: v, why, line: e.line});
|
|
1373
|
+
} else
|
|
1374
|
+
out.push({
|
|
1375
|
+
token,
|
|
1376
|
+
value: '',
|
|
1377
|
+
why: 'its value is an expression the editor could not evaluate, so it has not been checked; write it as text in quotes',
|
|
1378
|
+
line: e.line,
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
// A value the map gives another way (a spread of an imported module, a
|
|
1382
|
+
// call), as a build made now evaluates it, else as the current build or
|
|
1383
|
+
// the file shows it. A family the build shows that the map does not
|
|
1384
|
+
// name came from typography, checked above.
|
|
1385
|
+
const others =
|
|
1386
|
+
evaluated ?? new Map(Object.entries(ownSourceTokenValues(cwd, slug)));
|
|
1387
|
+
const tokensLine = entries.find(e => e.kind === 'unresolved')?.line ?? null;
|
|
1388
|
+
for (const [token, value] of others) {
|
|
1389
|
+
if (seen.has(token) || !(token in known) || value == null) continue;
|
|
1390
|
+
if (/^light-dark\(/i.test(value) && !isColorToken(token)) continue;
|
|
1391
|
+
if (!evaluated && /^--font-family-/.test(token)) continue;
|
|
1392
|
+
const why = refused(token, value);
|
|
1393
|
+
if (why) out.push({token, value, why, line: tokensLine});
|
|
1394
|
+
}
|
|
1395
|
+
return out;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
/**
|
|
1399
|
+
* What is wrong with one typography field of a theme's own source, or
|
|
1400
|
+
* null: a family is one family name (Core quotes it whole), the scale's
|
|
1401
|
+
* ratio is above 1 and at most 4, its base a positive size.
|
|
1402
|
+
* @param {string} key the dotted field (`body.family`, `scale.ratio`)
|
|
1403
|
+
* @param {unknown} value
|
|
1404
|
+
* @returns {string | null}
|
|
1405
|
+
*/
|
|
1406
|
+
function typographyProblem(key, value) {
|
|
1407
|
+
const field = key.split('.').pop();
|
|
1408
|
+
if (field === 'family') {
|
|
1409
|
+
if (typeof value !== 'string')
|
|
1410
|
+
return 'a typography family is a family name in quotes, such as "Inter"';
|
|
1411
|
+
const v = value.trim();
|
|
1412
|
+
// Core quotes a family with a space whole, so a list here is one
|
|
1413
|
+
// family by that whole name, which exists nowhere.
|
|
1414
|
+
if (v.includes(','))
|
|
1415
|
+
return `a typography family is one family name, which Core quotes whole ("${v}" is one family that exists nowhere); give the first as family and the rest as fallbacks, such as family: '${v
|
|
1416
|
+
.split(',')[0]
|
|
1417
|
+
.trim()
|
|
1418
|
+
.replace(
|
|
1419
|
+
/^["']|["']$/g,
|
|
1420
|
+
'',
|
|
1421
|
+
)}', fallbacks: '${v.split(',').slice(1).join(',').trim()}'`;
|
|
1422
|
+
if (!v || /^[-+]?\d/.test(v) || /^(inherit|initial|unset|revert)$/i.test(v))
|
|
1423
|
+
return `"${v}" is no font family name; give one such as "Inter"`;
|
|
1424
|
+
return null;
|
|
1425
|
+
}
|
|
1426
|
+
if (field === 'ratio') {
|
|
1427
|
+
const n = Number(value);
|
|
1428
|
+
if (!Number.isFinite(n) || n <= 1 || n > 4)
|
|
1429
|
+
return `the type scale's ratio is how much each size grows over the last, a number above 1 and at most 4 (such as 1.2); ${JSON.stringify(value)} makes ${n <= 0 ? 'sizes that are not numbers' : n <= 1 ? 'every size the same or smaller' : 'sizes no page can use'}`;
|
|
1430
|
+
return null;
|
|
1431
|
+
}
|
|
1432
|
+
if (field === 'base') {
|
|
1433
|
+
const n = typeof value === 'number' ? value : parseFloat(String(value));
|
|
1434
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
1435
|
+
return `the type scale's base is the body size, a positive number of pixels (such as 16); ${JSON.stringify(value)} makes sizes no page can use`;
|
|
1436
|
+
return null;
|
|
1437
|
+
}
|
|
1438
|
+
return null;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* Refuse a theme whose own source gives a token a value `set` refuses: the
|
|
1443
|
+
* build would write it as it is (a browser drops it), so it is named, with
|
|
1444
|
+
* the line of the file, before anything is written.
|
|
1445
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1446
|
+
* @param {string} slug
|
|
1447
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1448
|
+
*/
|
|
1449
|
+
async function refuseOwnTokenValues(ctx, slug, data) {
|
|
1450
|
+
const err = await ownTokenRefusal(ctx, slug, data);
|
|
1451
|
+
if (err) throw err;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* The refusal for own-source token values `set` refuses, or null.
|
|
1456
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1457
|
+
* @param {string} slug
|
|
1458
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1459
|
+
* @returns {Promise<AstryxError | null>}
|
|
1460
|
+
*/
|
|
1461
|
+
async function ownTokenRefusal(ctx, slug, data) {
|
|
1462
|
+
const bad = await ownTokenProblems(ctx, slug, data);
|
|
1463
|
+
if (!bad.length) return null;
|
|
1464
|
+
const file = `themes/${slug}/${slug}.theme.ts`;
|
|
1465
|
+
return new AstryxError(
|
|
1466
|
+
`${file} gives ${bad.length === 1 ? 'a token a value' : `${bad.length} tokens values`} the editor refuses, which the build would write as it is: ${bad
|
|
1467
|
+
.slice(0, 3)
|
|
1468
|
+
.map(
|
|
1469
|
+
b =>
|
|
1470
|
+
`${b.token}${b.value ? `: "${b.value}"` : ''}${b.line ? ` (line ${b.line})` : ''}: ${b.why}`,
|
|
1471
|
+
)
|
|
1472
|
+
.join(
|
|
1473
|
+
'; ',
|
|
1474
|
+
)}${bad.length > 3 ? `; and ${bad.length - 3} more` : ''}. Change it in ${file}. Nothing was changed.`,
|
|
1475
|
+
[
|
|
1476
|
+
bad[0].line
|
|
1477
|
+
? {
|
|
1478
|
+
name: `sed -n ${bad[0].line}p ${quoteCommandArgument(file)}`,
|
|
1479
|
+
reason: 'see the line that sets it',
|
|
1480
|
+
}
|
|
1481
|
+
: {
|
|
1482
|
+
name: `grep -n -- ${quoteCommandArgument(bad[0].token)} ${quoteCommandArgument(file)}`,
|
|
1483
|
+
reason: 'see the line',
|
|
1484
|
+
},
|
|
1485
|
+
],
|
|
1486
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
/**
|
|
1491
|
+
* The refusal `compile` gives an editor theme whose own source gives a
|
|
1492
|
+
* token a value `set` refuses, or null.
|
|
1493
|
+
* @param {string} root
|
|
1494
|
+
* @param {string} slug
|
|
1495
|
+
* @returns {Promise<AstryxError | null>}
|
|
1496
|
+
*/
|
|
1497
|
+
export async function editorOwnTokenRefusal(root, slug) {
|
|
1498
|
+
const ctx = await context(root);
|
|
1499
|
+
/** @type {import('./_settings.mjs').ThemeData} */
|
|
1500
|
+
let data;
|
|
1501
|
+
try {
|
|
1502
|
+
data = loadTheme(root, slug);
|
|
1503
|
+
} catch {
|
|
1504
|
+
return null;
|
|
1505
|
+
}
|
|
1506
|
+
return ownTokenRefusal(ctx, slug, data);
|
|
1507
|
+
}
|
|
1508
|
+
|
|
980
1509
|
/**
|
|
981
1510
|
* For `compile`: the refusal of [light, dark] pairs on tokens that are not
|
|
982
1511
|
* colors in what the theme builds now, or null.
|
|
@@ -1021,6 +1550,147 @@ function extremeSteps(res) {
|
|
|
1021
1550
|
: [];
|
|
1022
1551
|
}
|
|
1023
1552
|
|
|
1553
|
+
export {carriesTyped, offersTyped} from './_normal.mjs';
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* An object of settings written as JSON, with single quotes, or as its
|
|
1557
|
+
* entries with no braces (`"accent": "#e11d48", "corners": "pill"`).
|
|
1558
|
+
* Throws when it is none of these.
|
|
1559
|
+
* @param {string} text
|
|
1560
|
+
* @returns {any}
|
|
1561
|
+
*/
|
|
1562
|
+
function looseObject(text) {
|
|
1563
|
+
const t = text.trim();
|
|
1564
|
+
const braced = t.startsWith('{') ? t : `{${t}}`;
|
|
1565
|
+
try {
|
|
1566
|
+
return JSON.parse(braced);
|
|
1567
|
+
} catch {
|
|
1568
|
+
return JSON.parse(
|
|
1569
|
+
braced.replace(/'((?:[^'\\]|\\.)*)'/g, (_, x) =>
|
|
1570
|
+
JSON.stringify(x.replace(/\\'/g, "'")),
|
|
1571
|
+
),
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* A refusal with each line that sets the typed setting again kept only
|
|
1578
|
+
* when it carries the value typed; with none left, `how` for the setting.
|
|
1579
|
+
* Another setting's line, an undo or a look stays.
|
|
1580
|
+
* @param {any} e
|
|
1581
|
+
* @param {'set' | 'undo'} sub
|
|
1582
|
+
* @param {string} slug
|
|
1583
|
+
* @param {string} thing
|
|
1584
|
+
* @param {unknown} typed
|
|
1585
|
+
*/
|
|
1586
|
+
function carryTyped(e, sub, slug, thing, typed) {
|
|
1587
|
+
if (
|
|
1588
|
+
sub !== 'set' ||
|
|
1589
|
+
!(e instanceof AstryxError) ||
|
|
1590
|
+
typeof typed !== 'string' ||
|
|
1591
|
+
!e.suggestions?.length
|
|
1592
|
+
)
|
|
1593
|
+
return e;
|
|
1594
|
+
const head = new RegExp(
|
|
1595
|
+
`^.* set \\S+ (?:'([^']+)'|(\\S+)) (?:'((?:[^']|'\\\\'')*)'|(\\S+))`,
|
|
1596
|
+
);
|
|
1597
|
+
const same = (/** @type {string} */ x) =>
|
|
1598
|
+
x.replace(/^-+/, '').toLowerCase() ===
|
|
1599
|
+
String(thing).replace(/^-+/, '').toLowerCase();
|
|
1600
|
+
const kept = e.suggestions.filter(x => {
|
|
1601
|
+
const m = head.exec(x.name);
|
|
1602
|
+
if (!m) return true;
|
|
1603
|
+
const v = m[3] ?? m[4];
|
|
1604
|
+
// A stock value on another setting's line (the typed thing held an
|
|
1605
|
+
// object or a label) is no more the input's than on this one.
|
|
1606
|
+
if (!same(m[1] ?? m[2]))
|
|
1607
|
+
return /^\s*[{"']/.test(String(thing))
|
|
1608
|
+
? offersTyped(v, `${String(thing)} ${typed}`)
|
|
1609
|
+
: true;
|
|
1610
|
+
return offersTyped(v, typed);
|
|
1611
|
+
});
|
|
1612
|
+
if (kept.length === e.suggestions.length) return e;
|
|
1613
|
+
e.suggestions = kept.some(x => / (set|undo|new) /.test(` ${x.name} `))
|
|
1614
|
+
? kept
|
|
1615
|
+
: [
|
|
1616
|
+
...kept,
|
|
1617
|
+
{
|
|
1618
|
+
name: `${P} how ${quoteCommandArgument(String(thing))}`,
|
|
1619
|
+
reason: 'what it takes',
|
|
1620
|
+
},
|
|
1621
|
+
];
|
|
1622
|
+
return e;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
/**
|
|
1626
|
+
* A `set` or `undo` line for the theme a path or other letters named, run
|
|
1627
|
+
* through that command's own check (in memory, nothing written). Each
|
|
1628
|
+
* repair a refusal of it offers is folded into the one line, so the line
|
|
1629
|
+
* runs as offered; `why` names what is still refused when no repair is
|
|
1630
|
+
* offered.
|
|
1631
|
+
* @param {'set' | 'undo'} sub
|
|
1632
|
+
* @param {string} slug
|
|
1633
|
+
* @param {string} line
|
|
1634
|
+
* @param {string} cwd
|
|
1635
|
+
* @returns {Promise<{line: string, why: string | null}>}
|
|
1636
|
+
*/
|
|
1637
|
+
async function followChangeLine(sub, slug, line, cwd) {
|
|
1638
|
+
/** @type {import('./_settings.mjs').ThemeData} */
|
|
1639
|
+
let data;
|
|
1640
|
+
/** @type {import('./_settings.mjs').Ctx} */
|
|
1641
|
+
let ctx;
|
|
1642
|
+
try {
|
|
1643
|
+
data = loadTheme(cwd, slug);
|
|
1644
|
+
ctx = /** @type {import('./_settings.mjs').Ctx} */ (await context(cwd));
|
|
1645
|
+
ctx.base = await baseResolved(ctx.project, data.like);
|
|
1646
|
+
} catch {
|
|
1647
|
+
return {line, why: null};
|
|
1648
|
+
}
|
|
1649
|
+
const prefix = `${P} ${sub} ${slug} `;
|
|
1650
|
+
let now = line;
|
|
1651
|
+
for (let i = 0; i < 6; i += 1) {
|
|
1652
|
+
const read = readSetLine(
|
|
1653
|
+
sub === 'undo' ? now.replace(`${P} undo `, `${P} set `) : now,
|
|
1654
|
+
slug,
|
|
1655
|
+
);
|
|
1656
|
+
if (!read) return {line: now, why: null};
|
|
1657
|
+
try {
|
|
1658
|
+
const s = checkSetting(
|
|
1659
|
+
ctx,
|
|
1660
|
+
slug,
|
|
1661
|
+
structuredClone(data),
|
|
1662
|
+
read.thing,
|
|
1663
|
+
read.value,
|
|
1664
|
+
read.flags,
|
|
1665
|
+
sub === 'undo',
|
|
1666
|
+
);
|
|
1667
|
+
if (sub === 'undo' && !data.settings.some(x => keyOf(x) === keyOf(s)))
|
|
1668
|
+
return {
|
|
1669
|
+
line: now,
|
|
1670
|
+
why: `${slug} does not set ${describe({...s, value: '?'}).replace(' = ?', '')}`,
|
|
1671
|
+
};
|
|
1672
|
+
return {line: now, why: null};
|
|
1673
|
+
} catch (e) {
|
|
1674
|
+
const next =
|
|
1675
|
+
e instanceof AstryxError
|
|
1676
|
+
? (e.suggestions ?? []).find(
|
|
1677
|
+
x => x.name.startsWith(prefix) && x.name !== now,
|
|
1678
|
+
)
|
|
1679
|
+
: undefined;
|
|
1680
|
+
if (!next)
|
|
1681
|
+
return {
|
|
1682
|
+
line: now,
|
|
1683
|
+
why:
|
|
1684
|
+
e instanceof Error
|
|
1685
|
+
? e.message.replace(/\s*Nothing was changed\.$/, '')
|
|
1686
|
+
: String(e),
|
|
1687
|
+
};
|
|
1688
|
+
now = next.name;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
return {line: now, why: null};
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1024
1694
|
/**
|
|
1025
1695
|
* @param {'set' | 'undo'} sub
|
|
1026
1696
|
* @param {string} slug
|
|
@@ -1033,21 +1703,148 @@ async function change(sub, slug, thing, value, options) {
|
|
|
1033
1703
|
// As typed: an undo of a saved entry written in a form the cleanup below
|
|
1034
1704
|
// repairs (`Corners`, `var(--radius-page)`) removes that exact entry.
|
|
1035
1705
|
const typedThing = thing;
|
|
1706
|
+
const typedValue = value;
|
|
1707
|
+
// An object of several settings pasted as one (JSON, single quotes, or
|
|
1708
|
+
// its entries with no braces, split at the first colon on the way): one
|
|
1709
|
+
// set line each.
|
|
1710
|
+
const objectText =
|
|
1711
|
+
typeof thing !== 'string'
|
|
1712
|
+
? null
|
|
1713
|
+
: value == null || value === ''
|
|
1714
|
+
? /^\s*\{[\s\S]*\}\s*$/.test(thing)
|
|
1715
|
+
? thing
|
|
1716
|
+
: null
|
|
1717
|
+
: /^\s*\{?\s*["']/.test(thing) && /["']\s*:/.test(String(value))
|
|
1718
|
+
? `${thing}:${value}`
|
|
1719
|
+
: null;
|
|
1720
|
+
if (objectText != null) {
|
|
1721
|
+
/** @type {any} */
|
|
1722
|
+
let obj = null;
|
|
1723
|
+
try {
|
|
1724
|
+
obj = looseObject(objectText);
|
|
1725
|
+
} catch {
|
|
1726
|
+
// Not an object: read as typed.
|
|
1727
|
+
}
|
|
1728
|
+
if (obj && typeof obj === 'object' && Object.keys(obj).length > 1)
|
|
1729
|
+
refuse(
|
|
1730
|
+
E.ERR_INVALID_ARGUMENT,
|
|
1731
|
+
`This holds ${Object.keys(obj).length} settings; ${sub} changes one at a time.`,
|
|
1732
|
+
{
|
|
1733
|
+
run: Object.entries(obj)
|
|
1734
|
+
.slice(0, 6)
|
|
1735
|
+
.map(
|
|
1736
|
+
([k, x]) =>
|
|
1737
|
+
`${P} ${sub} ${slug} ${quoteCommandArgument(k)}${sub === 'set' ? ` ${quoteCommandArgument(String(x))}` : ''}`,
|
|
1738
|
+
),
|
|
1739
|
+
},
|
|
1740
|
+
);
|
|
1741
|
+
}
|
|
1742
|
+
// A flag typed inside the value (`'red --mode dark'`, `'4px --state
|
|
1743
|
+
// hover'`, `'pill --on button'`): the same command with the flag lifted
|
|
1744
|
+
// out, never the value alone, which would change another scope.
|
|
1745
|
+
if (typeof value === 'string' && /\s--(mode|state|on|when)\b/.test(value)) {
|
|
1746
|
+
/** @type {Record<string, string>} */
|
|
1747
|
+
const lifted = {};
|
|
1748
|
+
const bare = value
|
|
1749
|
+
.replace(
|
|
1750
|
+
/\s+--(mode|state|on|when)(?:\s*=\s*|\s+)("[^"]*"|'[^']*'|\S+)/g,
|
|
1751
|
+
(_, f, x) => {
|
|
1752
|
+
lifted[f] = x.replace(/^(["'])(.*)\1$/, '$2');
|
|
1753
|
+
return '';
|
|
1754
|
+
},
|
|
1755
|
+
)
|
|
1756
|
+
.trim();
|
|
1757
|
+
if (bare && Object.keys(lifted).length) {
|
|
1758
|
+
const opts = /** @type {Record<string, unknown>} */ ({
|
|
1759
|
+
...options,
|
|
1760
|
+
...lifted,
|
|
1761
|
+
});
|
|
1762
|
+
const flagText = ['on', 'when', 'state', 'mode']
|
|
1763
|
+
.filter(f => opts[f])
|
|
1764
|
+
.map(f => ` --${f} ${quoteCommandArgument(String(opts[f]))}`)
|
|
1765
|
+
.join('');
|
|
1766
|
+
refuse(
|
|
1767
|
+
E.ERR_INVALID_ARGUMENT,
|
|
1768
|
+
`"${value}" holds ${Object.keys(lifted)
|
|
1769
|
+
.map(f => `--${f}`)
|
|
1770
|
+
.join(' and ')} inside the value; a flag goes outside the quotes.`,
|
|
1771
|
+
{
|
|
1772
|
+
run: [
|
|
1773
|
+
`${P} ${sub} ${slug} ${quoteCommandArgument(String(thing))}${sub === 'set' ? ` ${quoteCommandArgument(bare)}` : ''}${flagText}${options.only ? ' --only' : ''}`,
|
|
1774
|
+
],
|
|
1775
|
+
},
|
|
1776
|
+
);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1036
1779
|
// How it was typed, put right before anything reads it (a pasted
|
|
1037
1780
|
// declaration, a dash, a var(), invisible spaces).
|
|
1781
|
+
/** @type {string | undefined} */
|
|
1782
|
+
let dropped;
|
|
1038
1783
|
if (typeof thing === 'string') {
|
|
1039
1784
|
const entry = normalizeEntry(thing, value);
|
|
1040
1785
|
thing = entry.thing;
|
|
1041
1786
|
value = entry.value;
|
|
1787
|
+
dropped = entry.dropped;
|
|
1042
1788
|
}
|
|
1043
1789
|
/** @type {{ctx?: import('./_settings.mjs').Ctx, data?: import('./_settings.mjs').ThemeData}} */
|
|
1044
1790
|
const seen = {};
|
|
1045
1791
|
try {
|
|
1046
|
-
|
|
1792
|
+
const r = await changeOnce(
|
|
1793
|
+
sub,
|
|
1794
|
+
slug,
|
|
1795
|
+
thing,
|
|
1796
|
+
value,
|
|
1797
|
+
options,
|
|
1798
|
+
seen,
|
|
1799
|
+
typedThing,
|
|
1800
|
+
);
|
|
1801
|
+
// A second declaration pasted after the first is not set: said, with
|
|
1802
|
+
// its own set line.
|
|
1803
|
+
if (dropped && sub === 'set') {
|
|
1804
|
+
const m = /^([^:]+):\s*(.*?);?\s*$/.exec(dropped);
|
|
1805
|
+
const flags = [
|
|
1806
|
+
...(options.on ? [`--on ${options.on}`] : []),
|
|
1807
|
+
...(options.when ? [`--when ${options.when}`] : []),
|
|
1808
|
+
...(options.state ? [`--state ${options.state}`] : []),
|
|
1809
|
+
].join(' ');
|
|
1810
|
+
/** @type {any} */ (r.data).notes = [
|
|
1811
|
+
...(r.data.notes ?? []),
|
|
1812
|
+
`the pasted text also held "${dropped}", which this did not set${m ? `: ${P} set ${slug} ${quoteCommandArgument(m[1].trim())} ${quoteCommandArgument(m[2].trim())}${flags ? ` ${flags}` : ''} sets it` : ''}`,
|
|
1813
|
+
];
|
|
1814
|
+
}
|
|
1815
|
+
// A mode or base entry in the settings list does nothing: said after
|
|
1816
|
+
// every change, with the undo that removes it.
|
|
1817
|
+
if (seen.ctx && r.data.theme) {
|
|
1818
|
+
/** @type {import('./_settings.mjs').ThemeData | null} */
|
|
1819
|
+
let now = null;
|
|
1820
|
+
try {
|
|
1821
|
+
now = loadTheme(seen.ctx.project.cwd, r.data.theme);
|
|
1822
|
+
} catch {
|
|
1823
|
+
now = null;
|
|
1824
|
+
}
|
|
1825
|
+
const left = now ? misplacedNotes(r.data.theme, now) : [];
|
|
1826
|
+
if (left.length)
|
|
1827
|
+
/** @type {any} */ (r.data).notes = [...left, ...(r.data.notes ?? [])];
|
|
1828
|
+
}
|
|
1829
|
+
return r;
|
|
1047
1830
|
} catch (e) {
|
|
1048
|
-
// A theme name one letter off an existing theme
|
|
1049
|
-
//
|
|
1050
|
-
|
|
1831
|
+
// A theme name one letter off an existing theme, or typed in other
|
|
1832
|
+
// letters or as a path (T, ./t, themes/t): the same command with that
|
|
1833
|
+
// name comes first, never a bare look at the theme that drops the change.
|
|
1834
|
+
const named =
|
|
1835
|
+
e instanceof AstryxError &&
|
|
1836
|
+
(e.code === E.ERR_UNKNOWN_THEME ||
|
|
1837
|
+
(e.code === E.ERR_INVALID_ARGUMENT &&
|
|
1838
|
+
(e.suggestions ?? []).some(
|
|
1839
|
+
x =>
|
|
1840
|
+
x.reason === 'did you mean' &&
|
|
1841
|
+
slugOk(x.name) &&
|
|
1842
|
+
x.name !== slug &&
|
|
1843
|
+
fs.existsSync(
|
|
1844
|
+
themeFiles(options.cwd ?? process.cwd(), x.name).settings,
|
|
1845
|
+
),
|
|
1846
|
+
)));
|
|
1847
|
+
if (named) {
|
|
1051
1848
|
const near = (e.suggestions ?? []).find(x => x.reason === 'did you mean');
|
|
1052
1849
|
if (near && slugOk(near.name)) {
|
|
1053
1850
|
const flags = [
|
|
@@ -1062,18 +1859,37 @@ async function change(sub, slug, thing, value, options) {
|
|
|
1062
1859
|
.map(w =>
|
|
1063
1860
|
String(w).startsWith('--') ? w : quoteCommandArgument(String(w)),
|
|
1064
1861
|
);
|
|
1862
|
+
const followed = await followChangeLine(
|
|
1863
|
+
sub,
|
|
1864
|
+
near.name,
|
|
1865
|
+
`${P} ${sub} ${near.name}${words.length ? ` ${words.join(' ')}` : ''}`,
|
|
1866
|
+
options.cwd ?? process.cwd(),
|
|
1867
|
+
);
|
|
1065
1868
|
e.suggestions = [
|
|
1066
1869
|
{
|
|
1067
|
-
name:
|
|
1068
|
-
reason: `do this instead: ${near.name} is a theme here`,
|
|
1870
|
+
name: followed.line,
|
|
1871
|
+
reason: `do this instead: ${near.name} is a theme here${followed.why ? `, but this still needs a fix: ${followed.why}` : ''}`,
|
|
1069
1872
|
},
|
|
1070
|
-
...(e.suggestions ?? []).filter(
|
|
1873
|
+
...(e.suggestions ?? []).filter(
|
|
1874
|
+
x => x !== near && x.name !== `${P} show ${near.name}`,
|
|
1875
|
+
),
|
|
1071
1876
|
];
|
|
1072
1877
|
}
|
|
1073
1878
|
throw e;
|
|
1074
1879
|
}
|
|
1075
|
-
// Every `set` the refusal suggests is checked as `set` checks it
|
|
1076
|
-
|
|
1880
|
+
// Every `set` the refusal suggests is checked as `set` checks it, and
|
|
1881
|
+
// carries the value typed (cleaned), never a stock value.
|
|
1882
|
+
throw misplacedFirst(
|
|
1883
|
+
carryTyped(
|
|
1884
|
+
vetSuggestions(e, seen.ctx, slug, seen.data),
|
|
1885
|
+
sub,
|
|
1886
|
+
slug,
|
|
1887
|
+
typedThing,
|
|
1888
|
+
typedValue,
|
|
1889
|
+
),
|
|
1890
|
+
seen.data?.name ?? slug,
|
|
1891
|
+
seen.data,
|
|
1892
|
+
);
|
|
1077
1893
|
}
|
|
1078
1894
|
}
|
|
1079
1895
|
|
|
@@ -1107,29 +1923,53 @@ async function changeOnce(
|
|
|
1107
1923
|
when: options.when,
|
|
1108
1924
|
state: options.state,
|
|
1109
1925
|
mode: options.mode,
|
|
1926
|
+
// An undo removes the entry it names even when that entry's mode or
|
|
1927
|
+
// source means nothing.
|
|
1928
|
+
...(sub === 'undo' ? {removing: true} : {}),
|
|
1110
1929
|
});
|
|
1111
1930
|
const data = loadTheme(cwd, slug, target);
|
|
1112
1931
|
/** @type {string[]} */
|
|
1113
|
-
const fieldNotes = [];
|
|
1114
|
-
|
|
1115
|
-
//
|
|
1116
|
-
// so the theme loads again
|
|
1932
|
+
const fieldNotes = [...entryNotes(data)];
|
|
1933
|
+
{
|
|
1934
|
+
// A damaged field the command does not set goes back to its default,
|
|
1935
|
+
// so the theme loads again (a change or removal of any setting repairs
|
|
1936
|
+
// it on the way).
|
|
1937
|
+
// One written in other letters or as a package name (`Dark-Only`,
|
|
1938
|
+
// `@astryxdesign/theme-neutral`) is cleaned to the value meant, never
|
|
1939
|
+
// reset.
|
|
1940
|
+
const meant = fieldsMeant(data);
|
|
1117
1941
|
if (
|
|
1118
1942
|
thing !== 'mode' &&
|
|
1119
1943
|
!['both', 'light-only', 'dark-only'].includes(data.mode)
|
|
1120
1944
|
) {
|
|
1121
|
-
|
|
1122
|
-
|
|
1945
|
+
if (['both', 'light-only', 'dark-only'].includes(meant.mode)) {
|
|
1946
|
+
fieldNotes.push(
|
|
1947
|
+
`mode was written "${data.mode}", so it is saved as ${meant.mode}`,
|
|
1948
|
+
);
|
|
1949
|
+
data.mode = /** @type {'both' | 'light-only' | 'dark-only'} */ (
|
|
1950
|
+
meant.mode
|
|
1951
|
+
);
|
|
1952
|
+
} else {
|
|
1953
|
+
data.mode = 'both';
|
|
1954
|
+
fieldNotes.push('mode was missing or damaged, so it is both again');
|
|
1955
|
+
}
|
|
1123
1956
|
}
|
|
1124
1957
|
if (thing !== 'base' && data.like != null && !LIKE.includes(data.like)) {
|
|
1125
|
-
|
|
1126
|
-
|
|
1958
|
+
if (LIKE.includes(meant.like) && baseInstalled(cwd, meant.like)) {
|
|
1959
|
+
fieldNotes.push(
|
|
1960
|
+
`base was written "${data.like}", so it is saved as ${meant.like}`,
|
|
1961
|
+
);
|
|
1962
|
+
data.like = meant.like;
|
|
1963
|
+
} else {
|
|
1964
|
+
delete data.like;
|
|
1965
|
+
fieldNotes.push('base was not a built-in theme, so it is none again');
|
|
1966
|
+
}
|
|
1127
1967
|
}
|
|
1128
1968
|
}
|
|
1129
1969
|
const ctx = await context(cwd);
|
|
1130
1970
|
// An undo of one setting only removes it, so it never waits on the
|
|
1131
1971
|
// others being fixed.
|
|
1132
|
-
if (sub !== 'undo')
|
|
1972
|
+
if (sub !== 'undo') {
|
|
1133
1973
|
refuseStoredTokens(ctx, slug, data, {
|
|
1134
1974
|
thing,
|
|
1135
1975
|
on: options.on,
|
|
@@ -1137,6 +1977,10 @@ async function changeOnce(
|
|
|
1137
1977
|
state: options.state,
|
|
1138
1978
|
mode: options.mode,
|
|
1139
1979
|
});
|
|
1980
|
+
}
|
|
1981
|
+
// The own source's token values are checked before every change, an
|
|
1982
|
+
// undo too: an undo rebuilds the theme from that source.
|
|
1983
|
+
await refuseOwnTokenValues(ctx, slug, data);
|
|
1140
1984
|
const flags = {
|
|
1141
1985
|
on: options.on,
|
|
1142
1986
|
when: options.when,
|
|
@@ -1175,8 +2019,24 @@ async function changeOnce(
|
|
|
1175
2019
|
Boolean(x.only) === Boolean(flags.only),
|
|
1176
2020
|
)
|
|
1177
2021
|
: -1;
|
|
1178
|
-
|
|
1179
|
-
|
|
2022
|
+
// An entry of this name whose mode or source means nothing is the one an
|
|
2023
|
+
// undo removes: only that entry, never a valid one beside it.
|
|
2024
|
+
const damagedIdx =
|
|
2025
|
+
sub === 'undo'
|
|
2026
|
+
? data.settings.findIndex(
|
|
2027
|
+
x =>
|
|
2028
|
+
(x.thing === typedThing || x.thing === thing) &&
|
|
2029
|
+
(x.on ?? null) === (flags.on ?? null) &&
|
|
2030
|
+
(x.when ?? null) === (flags.when ?? null) &&
|
|
2031
|
+
(x.state ?? null) === (flags.state ?? null) &&
|
|
2032
|
+
Boolean(x.only) === Boolean(flags.only) &&
|
|
2033
|
+
(entryDamage(x) === 'source'
|
|
2034
|
+
? (x.mode ?? null) === (flags.mode ?? null)
|
|
2035
|
+
: entryDamage(x) === 'mode' && !flags.mode),
|
|
2036
|
+
)
|
|
2037
|
+
: -1;
|
|
2038
|
+
let rawIdx = damagedIdx;
|
|
2039
|
+
if (exactIdx >= 0 && rawIdx < 0) {
|
|
1180
2040
|
// Only an entry the editor would not save as written: one it refuses,
|
|
1181
2041
|
// or reads as another name, part or state.
|
|
1182
2042
|
const entry = data.settings[exactIdx];
|
|
@@ -1341,6 +2201,9 @@ async function changeOnce(
|
|
|
1341
2201
|
);
|
|
1342
2202
|
}
|
|
1343
2203
|
const compiledBefore = compileTheme(ctx, data, base);
|
|
2204
|
+
// The build notes the theme had before this change: only new ones are
|
|
2205
|
+
// this change's to report.
|
|
2206
|
+
const notesBefore = new Set(buildNotes(ctx));
|
|
1344
2207
|
if (sub === 'set' && (s.thing === 'base' || s.thing === 'mode')) {
|
|
1345
2208
|
const before = s.thing === 'base' ? (data.like ?? 'none') : data.mode;
|
|
1346
2209
|
if (s.thing === 'base') {
|
|
@@ -1349,7 +2212,7 @@ async function changeOnce(
|
|
|
1349
2212
|
} else
|
|
1350
2213
|
data.mode = /** @type {'both' | 'light-only' | 'dark-only'} */ (s.value);
|
|
1351
2214
|
const r = await commitTheme(ctx, slug, data, {history: true});
|
|
1352
|
-
const p = await previewAndRoute(ctx, slug, data, png);
|
|
2215
|
+
const p = await previewAndRoute(ctx, slug, data, png, 'overview', sub);
|
|
1353
2216
|
const after = await baseResolved(ctx.project, data.like).catch(() => base);
|
|
1354
2217
|
return {
|
|
1355
2218
|
type: 'themeEdit.set',
|
|
@@ -1377,6 +2240,15 @@ async function changeOnce(
|
|
|
1377
2240
|
]
|
|
1378
2241
|
: []),
|
|
1379
2242
|
...otherModeNotes(data),
|
|
2243
|
+
// Back to both modes: a mode the app's <Theme> was given for the
|
|
2244
|
+
// one-mode theme pins it still.
|
|
2245
|
+
...(s.thing === 'mode' &&
|
|
2246
|
+
data.mode === 'both' &&
|
|
2247
|
+
(before === 'light-only' || before === 'dark-only')
|
|
2248
|
+
? [
|
|
2249
|
+
`if the app's <Theme> was given mode="${before === 'light-only' ? 'light' : 'dark'}" for ${slug}, take it out: with it the app stays ${before === 'light-only' ? 'light' : 'dark'}, whatever the system asks for`,
|
|
2250
|
+
]
|
|
2251
|
+
: []),
|
|
1380
2252
|
// Core has no mode inside a theme: the app's <Theme> is given it.
|
|
1381
2253
|
...(s.thing === 'mode' &&
|
|
1382
2254
|
(data.mode === 'light-only' || data.mode === 'dark-only')
|
|
@@ -1411,13 +2283,27 @@ async function changeOnce(
|
|
|
1411
2283
|
}
|
|
1412
2284
|
const k = keyOf(s);
|
|
1413
2285
|
const prevIdx =
|
|
1414
|
-
rawIdx >= 0
|
|
2286
|
+
rawIdx >= 0
|
|
2287
|
+
? rawIdx
|
|
2288
|
+
: // A setting listed twice by hand: the last entry is the one the
|
|
2289
|
+
// build reads, so it is the one this command changes.
|
|
2290
|
+
data.settings.map(x => keyOf(x)).lastIndexOf(k);
|
|
1415
2291
|
/** @type {string | null} */
|
|
1416
2292
|
let vibrancyGone = null;
|
|
1417
2293
|
const prev = prevIdx >= 0 ? data.settings[prevIdx] : null;
|
|
1418
2294
|
if (sub === 'undo') {
|
|
1419
2295
|
if (!prev) {
|
|
1420
|
-
|
|
2296
|
+
// A padding set in the other form (a side for the shorthand, or the
|
|
2297
|
+
// shorthand for a side) on the same part is a near one too.
|
|
2298
|
+
const PAD = /^padding(?:-(?:inline|block|top|right|bottom|left))?$/;
|
|
2299
|
+
const nearOnes = data.settings.filter(
|
|
2300
|
+
x =>
|
|
2301
|
+
x.thing === s.thing ||
|
|
2302
|
+
(PAD.test(s.thing) &&
|
|
2303
|
+
PAD.test(x.thing) &&
|
|
2304
|
+
(x.on ?? null) === (s.on ?? null)),
|
|
2305
|
+
);
|
|
2306
|
+
const near = nearOnes.map(describe);
|
|
1421
2307
|
// headings has two halves: name the one that is set.
|
|
1422
2308
|
const otherHalf =
|
|
1423
2309
|
s.thing === 'headings'
|
|
@@ -1430,11 +2316,12 @@ async function changeOnce(
|
|
|
1430
2316
|
: `The theme does not set ${describe({...s, value: '?'}).replace(' = ?', '')}.`,
|
|
1431
2317
|
{
|
|
1432
2318
|
also: near.length
|
|
1433
|
-
? [
|
|
2319
|
+
? [
|
|
2320
|
+
`settings for ${s.thing}: ${near.join('; ')}${nearOnes.some(x => x.thing === 'padding' && s.thing !== 'padding') ? ' (undoing padding removes all four sides)' : ''}`,
|
|
2321
|
+
]
|
|
1434
2322
|
: [],
|
|
1435
2323
|
run: [
|
|
1436
|
-
...
|
|
1437
|
-
.filter(x => x.thing === s.thing)
|
|
2324
|
+
...nearOnes
|
|
1438
2325
|
.slice(0, 3)
|
|
1439
2326
|
.map(x => `${P} undo ${slug} ${undoArgs(x)}`),
|
|
1440
2327
|
`${P} show ${slug}`,
|
|
@@ -1493,7 +2380,21 @@ async function changeOnce(
|
|
|
1493
2380
|
const covered =
|
|
1494
2381
|
sub === 'set' && !s.mode && s.source !== 'dial'
|
|
1495
2382
|
? data.settings.filter(
|
|
1496
|
-
x =>
|
|
2383
|
+
x =>
|
|
2384
|
+
x !== s &&
|
|
2385
|
+
x.mode &&
|
|
2386
|
+
(keyOf({...x, mode: undefined}) === k ||
|
|
2387
|
+
// The background shorthand and its color are one property
|
|
2388
|
+
// here: a one-mode one is replaced by either for both modes.
|
|
2389
|
+
(s.source === 'property' &&
|
|
2390
|
+
x.source === 'property' &&
|
|
2391
|
+
x.on === s.on &&
|
|
2392
|
+
x.when === s.when &&
|
|
2393
|
+
x.state === s.state &&
|
|
2394
|
+
[x.thing, s.thing].every(t =>
|
|
2395
|
+
/^background(-color)?$/.test(kebab(t)),
|
|
2396
|
+
) &&
|
|
2397
|
+
!/gradient\(|url\(/i.test(String(s.value)))),
|
|
1497
2398
|
)
|
|
1498
2399
|
: [];
|
|
1499
2400
|
data.settings = data.settings.filter(x => !covered.includes(x));
|
|
@@ -1513,6 +2414,9 @@ async function changeOnce(
|
|
|
1513
2414
|
))) &&
|
|
1514
2415
|
x.when === s.when &&
|
|
1515
2416
|
x.state === s.state &&
|
|
2417
|
+
// A shorthand for one mode replaces longhands of that mode or of
|
|
2418
|
+
// both, never the other mode's.
|
|
2419
|
+
(!s.mode || !x.mode || x.mode === s.mode) &&
|
|
1516
2420
|
// A longhand the shorthand really sets (MDN's data), never a
|
|
1517
2421
|
// property that only shares its name (overflow-wrap).
|
|
1518
2422
|
(coversProperty(s.thing, x.thing) ||
|
|
@@ -1537,6 +2441,12 @@ async function changeOnce(
|
|
|
1537
2441
|
: [];
|
|
1538
2442
|
const r = await commitTheme(ctx, slug, data, {history: true});
|
|
1539
2443
|
const compiledAfter = compileTheme(ctx, data, base);
|
|
2444
|
+
// What the spacing dial said of the sizes it could not keep apart.
|
|
2445
|
+
// What the build said of settings it could not write as they are.
|
|
2446
|
+
const compileNotes = buildNotes(ctx).filter(n => !notesBefore.has(n));
|
|
2447
|
+
const sizeNotes =
|
|
2448
|
+
/** @type {{sizeNotes?: string[]}} */ (/** @type {unknown} */ (ctx))
|
|
2449
|
+
.sizeNotes ?? [];
|
|
1540
2450
|
const styled = styledChanges(compiledBefore, compiledAfter, base);
|
|
1541
2451
|
const parts = partsOf(ctx, s);
|
|
1542
2452
|
// Exact whole-theme tokens that win over what this dial writes: the dial
|
|
@@ -1562,6 +2472,29 @@ async function changeOnce(
|
|
|
1562
2472
|
!x.when &&
|
|
1563
2473
|
x.thing === `--font-family-${s.on}`,
|
|
1564
2474
|
);
|
|
2475
|
+
// A whole-theme spacing dial keeps a part's own exact control size too,
|
|
2476
|
+
// on that part.
|
|
2477
|
+
if (sub === 'set' && s.source === 'dial' && s.thing === 'spacing' && !s.on)
|
|
2478
|
+
exactWins.push(
|
|
2479
|
+
...data.settings.filter(
|
|
2480
|
+
x =>
|
|
2481
|
+
x.source === 'token' &&
|
|
2482
|
+
!!x.on &&
|
|
2483
|
+
!x.state &&
|
|
2484
|
+
/^--size-element-/.test(x.thing),
|
|
2485
|
+
),
|
|
2486
|
+
);
|
|
2487
|
+
// A spacing dial on a part keeps the exact spacing and sizes there too:
|
|
2488
|
+
// the whole theme's, and the part's own.
|
|
2489
|
+
if (sub === 'set' && s.source === 'dial' && s.thing === 'spacing' && s.on)
|
|
2490
|
+
exactWins = data.settings.filter(
|
|
2491
|
+
x =>
|
|
2492
|
+
x.source === 'token' &&
|
|
2493
|
+
!x.when &&
|
|
2494
|
+
!x.state &&
|
|
2495
|
+
/^--(size-element|spacing)-/.test(x.thing) &&
|
|
2496
|
+
(!x.on || x.on === s.on),
|
|
2497
|
+
);
|
|
1565
2498
|
// The theme's own source wins over an exact setting, as the exact
|
|
1566
2499
|
// setting does over a dial: an exact token the file also sets is named
|
|
1567
2500
|
// as the file's below, never as the one that shows after an undo.
|
|
@@ -1762,6 +2695,7 @@ async function changeOnce(
|
|
|
1762
2695
|
: null;
|
|
1763
2696
|
/** @type {string[]} */
|
|
1764
2697
|
const notes = [
|
|
2698
|
+
...fieldNotes,
|
|
1765
2699
|
...(covered.length ? [`replaces ${covered.map(describe).join(', ')}`] : []),
|
|
1766
2700
|
...(ownPartHits.length
|
|
1767
2701
|
? [
|
|
@@ -1773,7 +2707,7 @@ async function changeOnce(
|
|
|
1773
2707
|
)
|
|
1774
2708
|
.join(
|
|
1775
2709
|
', ',
|
|
1776
|
-
)}${ownPartHits.length > 3 ? ` and ${ownPartHits.length - 3} more` : ''}, and your own source wins over the settings, so this does not show there; change it in ${slug}.theme.ts${ownHitDirect ? `, or take this back with \`${P} undo ${slug} ${undoArgs(s)}\`` : ''}`,
|
|
2710
|
+
)}${ownPartHits.length > 3 ? ` and ${ownPartHits.length - 3} more` : ''}, and your own source wins over the settings, so this does not show ${/^padding(-|$)/.test(s.thing) && ownPartHits.every(h => /^padding-/.test(h.prop)) ? 'on the sides that sets; its other sides take this setting' : 'there'}; change it in ${slug}.theme.ts${ownHitDirect ? `, or take this back with \`${P} undo ${slug} ${undoArgs(s)}\`` : ''}`,
|
|
1777
2711
|
]
|
|
1778
2712
|
: []),
|
|
1779
2713
|
...(ownOverToken
|
|
@@ -1786,6 +2720,8 @@ async function changeOnce(
|
|
|
1786
2720
|
`keeps your exact ${exactWins.map(describe).join(', ')}: an exact setting wins over a dial, so ${exactWins.length > 1 ? 'those do' : 'that does'} not change; this shows after \`${P} undo ${slug} ${exactWins.map(x => undoArgs(x)).join(`\` and \`${P} undo ${slug} `)}\``,
|
|
1787
2721
|
]
|
|
1788
2722
|
: []),
|
|
2723
|
+
...(sub === 'set' && s.thing === 'spacing' ? sizeNotes : []),
|
|
2724
|
+
...(sub === 'set' ? compileNotes : []),
|
|
1789
2725
|
...(covers.length
|
|
1790
2726
|
? [
|
|
1791
2727
|
`comes after ${covers.map(describe).join(', ')}, so ${covers.length > 1 ? 'those parts show' : `${covers[0].on} shows`} this value now; set ${covers.length > 1 ? 'one' : 'it'} again to make it win`,
|
|
@@ -1831,9 +2767,18 @@ async function changeOnce(
|
|
|
1831
2767
|
// An exact property on the same part wins over a dial there.
|
|
1832
2768
|
...(exactOver
|
|
1833
2769
|
? [
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
2770
|
+
// The own source holding only some sides or corners there leaves
|
|
2771
|
+
// the dial the others once the exact property is undone.
|
|
2772
|
+
ownPartHits.length &&
|
|
2773
|
+
ownPartHits.every(h =>
|
|
2774
|
+
/(Top|Bottom|Left|Right|Start|End|Block|Inline)/.test(
|
|
2775
|
+
camel(String(h.prop)),
|
|
2776
|
+
),
|
|
2777
|
+
)
|
|
2778
|
+
? `${describe(exactOver)} is an exact property and wins over ${s.thing} there, so this shows only after \`${P} undo ${slug} ${undoArgs(exactOver)}\`, and then not on the ${[...new Set(ownPartHits.map(h => kebab(String(h.prop))))].join(', ')} ${slug}.theme.ts sets itself`
|
|
2779
|
+
: ownPartHits.length
|
|
2780
|
+
? `${describe(exactOver)} is an exact property and wins over ${s.thing} there too; undoing it does not make ${s.thing} show on ${[...new Set(ownPartHits.map(h => h.target))].join(', ')}, where ${slug}.theme.ts wins`
|
|
2781
|
+
: `${describe(exactOver)} is an exact property and wins over ${s.thing} there, so this shows only after \`${P} undo ${slug} ${undoArgs(exactOver)}\``,
|
|
1837
2782
|
]
|
|
1838
2783
|
: []),
|
|
1839
2784
|
// A whole-theme font under fonts set for each role shows only where no
|
|
@@ -2018,6 +2963,12 @@ async function changeOnce(
|
|
|
2018
2963
|
// once preview.html was rendered from the theme as it is now (a retry
|
|
2019
2964
|
// after a render that failed renders it).
|
|
2020
2965
|
const f0 = themeFiles(cwd, slug);
|
|
2966
|
+
// A change that changed nothing still writes back an app copy file that
|
|
2967
|
+
// is gone or not the current build.
|
|
2968
|
+
// Its font stylesheet follows the fonts the theme loads now (a font
|
|
2969
|
+
// package installed or removed since).
|
|
2970
|
+
if (r.unchanged && appCopyBehind(cwd, slug, copyFontsCss(ctx, slug, data)))
|
|
2971
|
+
writeAppCopy(ctx, slug, data);
|
|
2021
2972
|
const p =
|
|
2022
2973
|
r.unchanged &&
|
|
2023
2974
|
!png &&
|
|
@@ -2030,8 +2981,10 @@ async function changeOnce(
|
|
|
2030
2981
|
notChecked: null,
|
|
2031
2982
|
previewStale: [],
|
|
2032
2983
|
see: seeLine(cwd, slug, changeFocus(s)),
|
|
2984
|
+
// A copy something keeps behind is said here too.
|
|
2985
|
+
...appCopyStale(cwd, slug),
|
|
2033
2986
|
}
|
|
2034
|
-
: await previewAndRoute(ctx, slug, data, png, changeFocus(s));
|
|
2987
|
+
: await previewAndRoute(ctx, slug, data, png, changeFocus(s), sub);
|
|
2035
2988
|
return {
|
|
2036
2989
|
type: sub === 'set' ? 'themeEdit.set' : 'themeEdit.undo',
|
|
2037
2990
|
data: {
|
|
@@ -2105,6 +3058,50 @@ function unsetColorNotes(data, base, slug) {
|
|
|
2105
3058
|
];
|
|
2106
3059
|
}
|
|
2107
3060
|
|
|
3061
|
+
/**
|
|
3062
|
+
* Whether a settings entry is a mode or base a hand edit put in the list:
|
|
3063
|
+
* it does nothing there (the theme's mode and base are its own fields).
|
|
3064
|
+
* @param {{thing: string}} s
|
|
3065
|
+
*/
|
|
3066
|
+
const misplaced = s => s.thing === 'mode' || s.thing === 'base';
|
|
3067
|
+
|
|
3068
|
+
/**
|
|
3069
|
+
* The note for each misplaced entry: listed here only, never as a
|
|
3070
|
+
* setting, with the undo that removes it first.
|
|
3071
|
+
* @param {string} slug
|
|
3072
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
3073
|
+
* @returns {string[]}
|
|
3074
|
+
*/
|
|
3075
|
+
function misplacedNotes(slug, data) {
|
|
3076
|
+
return data.settings
|
|
3077
|
+
.filter(misplaced)
|
|
3078
|
+
.map(
|
|
3079
|
+
x =>
|
|
3080
|
+
`misplaced: the settings list holds ${x.thing} = ${x.value}, which does nothing there (the theme's ${x.thing} is ${x.thing === 'mode' ? data.mode : (data.like ?? 'none')}); \`${P} undo ${slug} ${x.thing}\` removes it, and \`${P} set ${slug} ${x.thing} <value>\` sets the theme's ${x.thing}`,
|
|
3081
|
+
);
|
|
3082
|
+
}
|
|
3083
|
+
|
|
3084
|
+
/**
|
|
3085
|
+
* A refusal for a theme with misplaced entries, its suggestions led by the
|
|
3086
|
+
* undo that removes each.
|
|
3087
|
+
* @param {unknown} e
|
|
3088
|
+
* @param {string} slug
|
|
3089
|
+
* @param {import('./_settings.mjs').ThemeData | undefined} data
|
|
3090
|
+
*/
|
|
3091
|
+
function misplacedFirst(e, slug, data) {
|
|
3092
|
+
if (!(e instanceof AstryxError) || !data) return e;
|
|
3093
|
+
const undos = data.settings.filter(misplaced).map(x => ({
|
|
3094
|
+
name: `${P} undo ${slug} ${x.thing}`,
|
|
3095
|
+
reason: `removes the ${x.thing} entry that does nothing in the settings list`,
|
|
3096
|
+
}));
|
|
3097
|
+
if (!undos.length) return e;
|
|
3098
|
+
e.suggestions = [
|
|
3099
|
+
...undos,
|
|
3100
|
+
...(e.suggestions ?? []).filter(x => !undos.some(u => u.name === x.name)),
|
|
3101
|
+
];
|
|
3102
|
+
return e;
|
|
3103
|
+
}
|
|
3104
|
+
|
|
2108
3105
|
/**
|
|
2109
3106
|
* Every setting of a theme, key resolved values, problems it caused, the
|
|
2110
3107
|
* sample page and the theme-building page with every component.
|
|
@@ -2126,6 +3123,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2126
3123
|
// build a later refusal puts back.
|
|
2127
3124
|
holdAfterBuild(ctx);
|
|
2128
3125
|
refuseStoredTokens(ctx, theme, data);
|
|
3126
|
+
await refuseOwnTokenValues(ctx, theme, data);
|
|
2129
3127
|
// Without React, show still lists the settings and builds the theme, as
|
|
2130
3128
|
// set does; only the pages, pictures and the checks that render are
|
|
2131
3129
|
// skipped, and the result says how to fix it.
|
|
@@ -2347,29 +3345,32 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2347
3345
|
const looksBase = await baseResolved(ctx.project, data.like).catch(
|
|
2348
3346
|
() => null,
|
|
2349
3347
|
);
|
|
2350
|
-
return data.settings
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
x
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
3348
|
+
return data.settings
|
|
3349
|
+
.filter(s => !misplaced(s))
|
|
3350
|
+
.map(s => {
|
|
3351
|
+
let masked = maskedSettings(data, ctx).get(s);
|
|
3352
|
+
// A look dial (buttons, surfaces) under an exact property on a
|
|
3353
|
+
// part it writes: named, as corners under border-radius is.
|
|
3354
|
+
if (!masked && looksBase && s.source === 'dial' && !s.on) {
|
|
3355
|
+
const writes = dialWrites(ctx, data, s, looksBase);
|
|
3356
|
+
const exact = writes.size
|
|
3357
|
+
? data.settings.find(
|
|
3358
|
+
x =>
|
|
3359
|
+
x.source === 'property' &&
|
|
3360
|
+
x.on &&
|
|
3361
|
+
!x.when &&
|
|
3362
|
+
!x.state &&
|
|
3363
|
+
partsOf(ctx, x).some(t => writes.has(`${t}\0${x.thing}`)),
|
|
3364
|
+
)
|
|
3365
|
+
: undefined;
|
|
3366
|
+
if (exact)
|
|
3367
|
+
masked = `${describe(exact)} is an exact property and wins over ${s.thing} on ${exact.on}`;
|
|
3368
|
+
}
|
|
3369
|
+
return {...s, parts: partsOf(ctx, s), ...(masked ? {masked} : {})};
|
|
3370
|
+
});
|
|
2371
3371
|
})(),
|
|
2372
3372
|
notes: [
|
|
3373
|
+
...misplacedNotes(theme, data),
|
|
2373
3374
|
...(noReact
|
|
2374
3375
|
? [
|
|
2375
3376
|
`react and react-dom cannot be found from this app, so the pages and pictures were not made again and the checks that render components were skipped; install them (${installLine(cwd, ['react', 'react-dom'])}), then run show again`,
|
|
@@ -2443,6 +3444,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2443
3444
|
const wrote = takeFirstAppCopy(cwd, theme);
|
|
2444
3445
|
return wrote ? {appCopy: {wrote}} : {};
|
|
2445
3446
|
})(),
|
|
3447
|
+
...appCopyStale(cwd, theme),
|
|
2446
3448
|
colorFiles: pal ? colorFiles(theme) : null,
|
|
2447
3449
|
},
|
|
2448
3450
|
};
|
|
@@ -3038,10 +4040,92 @@ function colorFiles(slug) {
|
|
|
3038
4040
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditUndoResponse | import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
|
|
3039
4041
|
*/
|
|
3040
4042
|
export async function themeEditUndo(theme, options = {}) {
|
|
4043
|
+
try {
|
|
4044
|
+
return await undoTheme(theme, options);
|
|
4045
|
+
} catch (e) {
|
|
4046
|
+
// A theme name typed in another form (tTheme, T, brand_dark, themes/t):
|
|
4047
|
+
// the same undo with the theme's name comes first, never a look at the
|
|
4048
|
+
// theme that drops the undo.
|
|
4049
|
+
if (
|
|
4050
|
+
e instanceof AstryxError &&
|
|
4051
|
+
(e.code === E.ERR_INVALID_ARGUMENT || e.code === E.ERR_UNKNOWN_THEME)
|
|
4052
|
+
) {
|
|
4053
|
+
const cwd = options.cwd ?? process.cwd();
|
|
4054
|
+
const showOf = (/** @type {{name: string}} */ x) => {
|
|
4055
|
+
const rest = x.name.startsWith(`${P} show `)
|
|
4056
|
+
? x.name.slice(`${P} show `.length)
|
|
4057
|
+
: null;
|
|
4058
|
+
return rest && !/\s/.test(rest) ? rest : null;
|
|
4059
|
+
};
|
|
4060
|
+
// A list of themes (t,u) stays a look at each: one theme at a time.
|
|
4061
|
+
const shows = (e.suggestions ?? []).filter(x => showOf(x) != null);
|
|
4062
|
+
const near = (shows.length === 1 ? shows : []).find(x => {
|
|
4063
|
+
const n = showOf(x);
|
|
4064
|
+
return (
|
|
4065
|
+
n != null &&
|
|
4066
|
+
n !== theme &&
|
|
4067
|
+
slugOk(n) &&
|
|
4068
|
+
fs.existsSync(themeFiles(cwd, n).settings)
|
|
4069
|
+
);
|
|
4070
|
+
});
|
|
4071
|
+
const name = near ? showOf(near) : null;
|
|
4072
|
+
if (near && name) {
|
|
4073
|
+
const words = [
|
|
4074
|
+
...(options.thing ? [options.thing] : []),
|
|
4075
|
+
...(options.value ? [options.value] : []),
|
|
4076
|
+
...(options.on ? ['--on', options.on] : []),
|
|
4077
|
+
...(options.when ? ['--when', options.when] : []),
|
|
4078
|
+
...(options.state ? ['--state', options.state] : []),
|
|
4079
|
+
...(options.mode ? ['--mode', options.mode] : []),
|
|
4080
|
+
].map(w =>
|
|
4081
|
+
String(w).startsWith('--') ? w : quoteCommandArgument(String(w)),
|
|
4082
|
+
);
|
|
4083
|
+
const followed = await followChangeLine(
|
|
4084
|
+
'undo',
|
|
4085
|
+
name,
|
|
4086
|
+
`${P} undo ${name}${words.length ? ` ${words.join(' ')}` : ''}`,
|
|
4087
|
+
cwd,
|
|
4088
|
+
);
|
|
4089
|
+
e.suggestions = [
|
|
4090
|
+
{
|
|
4091
|
+
name: followed.line,
|
|
4092
|
+
reason: `do this instead: ${name} is a theme here${followed.why ? `, but this still needs a fix: ${followed.why}` : ''}`,
|
|
4093
|
+
},
|
|
4094
|
+
...(e.suggestions ?? []).filter(x => x !== near),
|
|
4095
|
+
];
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
throw e;
|
|
4099
|
+
}
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
/**
|
|
4103
|
+
* {@link themeEditUndo}'s work.
|
|
4104
|
+
* @param {string} theme
|
|
4105
|
+
* @param {import('./theme-edit.type.mjs').ThemeEditUndoOptions} options
|
|
4106
|
+
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditUndoResponse | import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
|
|
4107
|
+
*/
|
|
4108
|
+
async function undoTheme(theme, options) {
|
|
3041
4109
|
const {cwd = process.cwd(), png = false, thing} = options;
|
|
3042
4110
|
// base and mode are not settings in the list: undoing one goes back to
|
|
3043
4111
|
// what the theme was made with (the oldest step the history keeps).
|
|
3044
|
-
|
|
4112
|
+
// A `base` or `mode` entry a hand edit put in the settings list is a
|
|
4113
|
+
// setting like any other there: undo removes it.
|
|
4114
|
+
const listed =
|
|
4115
|
+
(thing === 'base' || thing === 'mode') &&
|
|
4116
|
+
slugOk(theme) &&
|
|
4117
|
+
(() => {
|
|
4118
|
+
try {
|
|
4119
|
+
return JSON.parse(
|
|
4120
|
+
fs
|
|
4121
|
+
.readFileSync(themeFiles(cwd, theme).settings, 'utf8')
|
|
4122
|
+
.replace(/^\uFEFF/, ''),
|
|
4123
|
+
).settings.some((/** @type {any} */ x) => x?.thing === thing);
|
|
4124
|
+
} catch {
|
|
4125
|
+
return false;
|
|
4126
|
+
}
|
|
4127
|
+
})();
|
|
4128
|
+
if ((thing === 'base' || thing === 'mode') && !listed) {
|
|
3045
4129
|
requireProject(cwd);
|
|
3046
4130
|
const now = loadTheme(cwd, theme, thing);
|
|
3047
4131
|
const historyFile = themeFiles(cwd, theme).history;
|
|
@@ -3128,10 +4212,18 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3128
4212
|
// A link in the theme is refused as set refuses it, never read as an
|
|
3129
4213
|
// empty history.
|
|
3130
4214
|
if (slugOk(theme)) refuseLinks(cwd, theme);
|
|
4215
|
+
/** The command that works when the settings cannot be read. @type {string[] | null} */
|
|
4216
|
+
let repair = null;
|
|
3131
4217
|
try {
|
|
3132
4218
|
current = loadTheme(cwd, theme);
|
|
3133
4219
|
} catch (e) {
|
|
3134
4220
|
if (!(e instanceof AstryxError && e.code === E.ERR_THEME_INVALID)) throw e;
|
|
4221
|
+
// What the refusal itself names (make the theme again, keeping the
|
|
4222
|
+
// damaged file), never `show`, which fails the same way.
|
|
4223
|
+
repair = (e.suggestions ?? [])
|
|
4224
|
+
.map(x => x.name)
|
|
4225
|
+
.filter(n => !/ show /.test(` ${n} `) && !/ undo /.test(` ${n} `));
|
|
4226
|
+
if (!repair.length) repair = [`${P} new ${theme}`];
|
|
3135
4227
|
}
|
|
3136
4228
|
const f = themeFiles(cwd, theme);
|
|
3137
4229
|
const {steps: history, dropped} = readHistory(f.history);
|
|
@@ -3141,15 +4233,18 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3141
4233
|
`${theme}.history.json is damaged, so there is no step to go back to.`,
|
|
3142
4234
|
{
|
|
3143
4235
|
fix: `move ${shown(cwd, f.history)} out of the theme folder (it is kept as it is): the next change starts a new history, and your settings stay as they are`,
|
|
3144
|
-
run: [`${P} show ${theme}`],
|
|
4236
|
+
run: repair ?? [`${P} show ${theme}`],
|
|
3145
4237
|
},
|
|
3146
4238
|
);
|
|
3147
4239
|
if (!history.length)
|
|
3148
4240
|
refuse(
|
|
3149
4241
|
E.ERR_THEME_NOTHING_TO_UNDO,
|
|
3150
|
-
`Nothing to undo: ${theme} has no earlier change.`,
|
|
3151
|
-
{run: [`${P} show ${theme}`]},
|
|
4242
|
+
`Nothing to undo: ${theme} has no earlier change${repair ? `, and ${theme}.settings.json cannot be read` : ''}.`,
|
|
4243
|
+
{run: repair ?? [`${P} show ${theme}`]},
|
|
3152
4244
|
);
|
|
4245
|
+
// The step rebuilds the theme from its own source: a token value there
|
|
4246
|
+
// that set refuses is refused here too, before anything is written.
|
|
4247
|
+
if (current) await refuseOwnTokenValues(await context(cwd), theme, current);
|
|
3153
4248
|
// A top step equal to the settings now (left by an undo stopped between
|
|
3154
4249
|
// its two writes) changes nothing: skip it.
|
|
3155
4250
|
const nowText = fs.readFileSync(f.settings, 'utf8');
|
|
@@ -3278,8 +4373,10 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3278
4373
|
undone.push(
|
|
3279
4374
|
`base ${current.like ?? 'none'} is back to ${prev.like ?? 'none'}`,
|
|
3280
4375
|
);
|
|
3281
|
-
if (current && current.mode !== prev.mode)
|
|
4376
|
+
if (current && current.mode !== prev.mode) {
|
|
3282
4377
|
undone.push(`mode ${current.mode} is back to ${prev.mode}`);
|
|
4378
|
+
undone.push(...modeWiringNotes(theme, current.mode, prev.mode));
|
|
4379
|
+
}
|
|
3283
4380
|
// The page most about what the step reverted: Colors for a color,
|
|
3284
4381
|
// Components for a part setting, else Overview.
|
|
3285
4382
|
const touched = [
|
|
@@ -3291,7 +4388,7 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3291
4388
|
: touched.includes('components')
|
|
3292
4389
|
? 'components'
|
|
3293
4390
|
: 'overview';
|
|
3294
|
-
const p = await previewAndRoute(ctx, theme, prev, png, focus);
|
|
4391
|
+
const p = await previewAndRoute(ctx, theme, prev, png, focus, 'undo');
|
|
3295
4392
|
return {
|
|
3296
4393
|
type: 'themeEdit.undo',
|
|
3297
4394
|
data: {
|
|
@@ -3320,3 +4417,14 @@ export async function editorStale(cwd, slug) {
|
|
|
3320
4417
|
const data = loadTheme(cwd, slug);
|
|
3321
4418
|
return staleBuild(cwd, slug, data) || null;
|
|
3322
4419
|
}
|
|
4420
|
+
|
|
4421
|
+
/**
|
|
4422
|
+
* The notes the last build of the theme left (settings it could not write
|
|
4423
|
+
* as they are).
|
|
4424
|
+
* @param {unknown} ctx
|
|
4425
|
+
* @returns {string[]}
|
|
4426
|
+
*/
|
|
4427
|
+
function buildNotes(ctx) {
|
|
4428
|
+
const notes = /** @type {{compileNotes?: unknown}} */ (ctx)?.compileNotes;
|
|
4429
|
+
return Array.isArray(notes) ? notes.map(String) : [];
|
|
4430
|
+
}
|