@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa
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 +12 -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 +47 -9
- 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 +32 -0
- package/api/build/kit/words.mjs +49 -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 +48 -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 +491 -186
- package/api/render/render.doc.mjs +10 -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 +38 -0
- package/api/theme/build/build.mjs +144 -24
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +35 -0
- package/api/theme-edit/_adapter.mjs +477 -41
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1077 -200
- 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 +932 -82
- package/api/theme-edit/_how-commands.d.mts +49 -0
- package/api/theme-edit/_how-commands.mjs +386 -1
- package/api/theme-edit/_how-question.d.mts +56 -0
- package/api/theme-edit/_how-question.mjs +3509 -168
- 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 +137 -0
- package/api/theme-edit/_normal.mjs +612 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +4 -0
- package/api/theme-edit/_parts.mjs +28 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +191 -15
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +401 -83
- package/api/theme-edit/_settings.d.mts +139 -5
- package/api/theme-edit/_settings.mjs +1659 -112
- package/api/theme-edit/_tables.mjs +17 -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 +2 -2
- 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 +8 -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 +1 -7
- 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/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 -1
- 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 +27 -2
- 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 +138 -3
- 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/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 +169 -0
- 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 +138 -52
- 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/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 +79 -10
- 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 +4 -1
- package/foundation/render/ts-paths.mjs +7 -3
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.doc.mjs +7 -1
- package/foundation/response/error-codes.mjs +7 -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/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
17
|
import {vetSuggestions} from './_vet.mjs';
|
|
18
|
+
import {colorPair, offersTyped} from './_normal.mjs';
|
|
17
19
|
import {
|
|
18
20
|
AUTO_SPREAD,
|
|
19
21
|
CORNERS,
|
|
@@ -66,13 +68,17 @@ import {
|
|
|
66
68
|
NEW_MARKER,
|
|
67
69
|
clearNewMarker,
|
|
68
70
|
refuseThemeSource,
|
|
69
|
-
|
|
71
|
+
settingsEntriesOk,
|
|
70
72
|
slugFor,
|
|
73
|
+
typedThemeName,
|
|
74
|
+
themeNameReadings,
|
|
71
75
|
themeSource,
|
|
72
76
|
themeSourceProblem,
|
|
73
77
|
refuseThemeParse,
|
|
74
78
|
ownSourceTokens,
|
|
75
79
|
ownSourceTokenValues,
|
|
80
|
+
ownTokenEntries,
|
|
81
|
+
nonTextMessage,
|
|
76
82
|
ownPartTokens,
|
|
77
83
|
PHONE_TYPE,
|
|
78
84
|
refreshSourceStamp,
|
|
@@ -83,16 +89,14 @@ import {
|
|
|
83
89
|
refuseLinks,
|
|
84
90
|
usableNewName,
|
|
85
91
|
FOLDER_JUNK,
|
|
92
|
+
folderIsEmpty,
|
|
86
93
|
dialValueFits,
|
|
87
94
|
holdAfterBuild,
|
|
95
|
+
fieldsMeant,
|
|
88
96
|
} from './_settings.mjs';
|
|
89
|
-
import {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
normalizeEntry,
|
|
93
|
-
storedProblems,
|
|
94
|
-
} from './_check.mjs';
|
|
95
|
-
import {MODAL} from './_compiler.mjs';
|
|
97
|
+
import {checkSetting, normalizeEntry, storedProblems} from './_check.mjs';
|
|
98
|
+
import {MODAL, isColorToken} from './_compiler.mjs';
|
|
99
|
+
import {colorProblem} from './_color.mjs';
|
|
96
100
|
import {
|
|
97
101
|
PALETTE_DIALS,
|
|
98
102
|
VIBRANCY_DEFAULT,
|
|
@@ -105,15 +109,21 @@ import {
|
|
|
105
109
|
writeWhole,
|
|
106
110
|
isGraySeed,
|
|
107
111
|
seedOf,
|
|
112
|
+
isEditorTemp,
|
|
108
113
|
} from './_palette.mjs';
|
|
109
114
|
import {
|
|
110
115
|
renderPreview,
|
|
111
116
|
renderSheet,
|
|
112
117
|
previewIsCurrent,
|
|
113
118
|
takeFirstAppCopy,
|
|
119
|
+
appCopyBehind,
|
|
120
|
+
appCopyStale,
|
|
121
|
+
copyFontsCss,
|
|
114
122
|
writeAppCopy,
|
|
115
123
|
} from './_preview.mjs';
|
|
116
124
|
import {appWiring, refreshPreviewRoute, seeLine} from './_preview-app.mjs';
|
|
125
|
+
/** The preview command, as a person runs it. */
|
|
126
|
+
const PREVIEW_CMD = `${P.replace(/ editor$/, '')} preview`;
|
|
117
127
|
import {baseInstalled, baseResolved, installLine} from './_project.mjs';
|
|
118
128
|
import {reactMissing} from './_parts.mjs';
|
|
119
129
|
import {
|
|
@@ -129,6 +139,7 @@ import {
|
|
|
129
139
|
} from './_context.mjs';
|
|
130
140
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
131
141
|
import {
|
|
142
|
+
formatCliCommand,
|
|
132
143
|
getCliInvocation,
|
|
133
144
|
quoteCommandArgument,
|
|
134
145
|
} from '../../foundation/env/package-manager.mjs';
|
|
@@ -174,9 +185,8 @@ function editorLeftovers(dir, slug, damaged = false) {
|
|
|
174
185
|
/^(preview(-[a-z]+)?\.(html|png)|sheet(-[a-z-]+)?\.(html|png)|palette\.config\.json)$/.test(
|
|
175
186
|
n,
|
|
176
187
|
) ||
|
|
177
|
-
// The editor's temp names
|
|
178
|
-
|
|
179
|
-
/^\..+\.(astryx-\d+-[a-z0-9]+\.tmp|tmp-[\w-]+)$/.test(n);
|
|
188
|
+
// The editor's temp names (writes, builds, pictures).
|
|
189
|
+
isEditorTemp(n);
|
|
180
190
|
for (const e of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
181
191
|
const p = path.join(dir, e.name);
|
|
182
192
|
if (FOLDER_JUNK.has(e.name)) continue;
|
|
@@ -209,7 +219,9 @@ function editorLeftovers(dir, slug, damaged = false) {
|
|
|
209
219
|
/** Whether a settings file parses, in the shape the editor reads. @param {string} file */
|
|
210
220
|
function readableJson(file) {
|
|
211
221
|
try {
|
|
212
|
-
|
|
222
|
+
// An entry with no thing or no source is damage too: `new` keeps the
|
|
223
|
+
// file aside, as the refusal for it says.
|
|
224
|
+
return settingsEntriesOk(
|
|
213
225
|
JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, '')),
|
|
214
226
|
);
|
|
215
227
|
} catch {
|
|
@@ -346,10 +358,20 @@ export async function themeEditNew(name, options = {}) {
|
|
|
346
358
|
/** @type {string | null | undefined} */ likeValue = likeFixed,
|
|
347
359
|
) => `${P} new ${newName}${newFlags(likeValue, fitSettings, png)}`;
|
|
348
360
|
if (!slugOk(name)) {
|
|
349
|
-
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
361
|
+
// A path typed for the name (themes/brand, ./t, t/) names the theme the
|
|
362
|
+
// path ends in.
|
|
363
|
+
// A file name, the app copy's export (tTheme), camelCase or spaces
|
|
364
|
+
// (BrandDark, "Brand Dark") name the theme they read as: when it is
|
|
365
|
+
// here already, that is said, never a numbered second copy offered.
|
|
366
|
+
const typed = String(name ?? '');
|
|
367
|
+
const path_ = /[\\/]/.test(typed);
|
|
368
|
+
const readings = themeNameReadings(typed);
|
|
369
|
+
const present = readings.find(n =>
|
|
370
|
+
fs.existsSync(themeFiles(cwd, n).settings),
|
|
371
|
+
);
|
|
372
|
+
const fixed =
|
|
373
|
+
present ?? readings[0] ?? slugFor(path_ ? typedThemeName(typed) : typed);
|
|
374
|
+
const exists = Boolean(present);
|
|
353
375
|
refuse(
|
|
354
376
|
E.ERR_INVALID_ARGUMENT,
|
|
355
377
|
`"${String(name ?? '').slice(0, 80)}" is not a theme name (${NAME_RULE})${exists ? `; ${fixed} is a theme here already` : ''}.${dropped}`,
|
|
@@ -360,6 +382,16 @@ export async function themeEditNew(name, options = {}) {
|
|
|
360
382
|
},
|
|
361
383
|
);
|
|
362
384
|
}
|
|
385
|
+
// A name the theme commands' own discovery skips ("a--b", "b-") would
|
|
386
|
+
// make an app copy no `theme add`, `theme list` or doctor takes.
|
|
387
|
+
if (!THEME_SLUG_RE.test(name)) {
|
|
388
|
+
const cleaned = name.replace(/-{2,}/g, '-').replace(/-+$/, '');
|
|
389
|
+
refuse(
|
|
390
|
+
E.ERR_INVALID_ARGUMENT,
|
|
391
|
+
`"${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}`,
|
|
392
|
+
{run: [again(usableNewName(cwd, cleaned))]},
|
|
393
|
+
);
|
|
394
|
+
}
|
|
363
395
|
// A built-in theme's name would collide with the theme of that name the
|
|
364
396
|
// app may also use.
|
|
365
397
|
if (LIKE.includes(name))
|
|
@@ -426,7 +458,8 @@ export async function themeEditNew(name, options = {}) {
|
|
|
426
458
|
const holdsOther =
|
|
427
459
|
fs.existsSync(f.dir) &&
|
|
428
460
|
!left &&
|
|
429
|
-
|
|
461
|
+
// Empty folders (an empty tokens/) hold nothing of anyone's.
|
|
462
|
+
!folderIsEmpty(f.dir);
|
|
430
463
|
if (holdsOther)
|
|
431
464
|
refuse(
|
|
432
465
|
E.ERR_FILE_EXISTS,
|
|
@@ -576,7 +609,7 @@ export async function themeEditNew(name, options = {}) {
|
|
|
576
609
|
}
|
|
577
610
|
refuseIfLockLost();
|
|
578
611
|
fs.rmSync(marker, {force: true});
|
|
579
|
-
const p = await previewAndRoute(ctx, name, data, png);
|
|
612
|
+
const p = await previewAndRoute(ctx, name, data, png, 'overview', 'new');
|
|
580
613
|
/** @type {string[]} */
|
|
581
614
|
const notes = [
|
|
582
615
|
...keptNotes,
|
|
@@ -655,15 +688,34 @@ function applyNewSettings(
|
|
|
655
688
|
/** @type {import('./_settings.mjs').Setting} */
|
|
656
689
|
let s;
|
|
657
690
|
try {
|
|
658
|
-
|
|
691
|
+
// The same input cleanup set gives a typed value (quotes of any
|
|
692
|
+
// kind around a font, invisible spaces, a pasted `name: value`).
|
|
693
|
+
const typed = normalizeEntry(thing, String(value)).value;
|
|
694
|
+
s = checkSetting(
|
|
695
|
+
ctx,
|
|
696
|
+
slug,
|
|
697
|
+
data,
|
|
698
|
+
thing,
|
|
699
|
+
typed ?? String(value),
|
|
700
|
+
{},
|
|
701
|
+
false,
|
|
702
|
+
);
|
|
659
703
|
} catch (e) {
|
|
660
|
-
throw
|
|
661
|
-
|
|
704
|
+
throw newColorPair(
|
|
705
|
+
asNewRefusal(
|
|
706
|
+
vetSuggestions(e, ctx, slug, data),
|
|
707
|
+
slug,
|
|
708
|
+
settings,
|
|
709
|
+
likeFlag,
|
|
710
|
+
png,
|
|
711
|
+
{thing, index},
|
|
712
|
+
),
|
|
662
713
|
slug,
|
|
663
714
|
settings,
|
|
664
715
|
likeFlag,
|
|
665
716
|
png,
|
|
666
|
-
|
|
717
|
+
thing,
|
|
718
|
+
String(value),
|
|
667
719
|
);
|
|
668
720
|
}
|
|
669
721
|
if (thing === 'mode')
|
|
@@ -771,6 +823,81 @@ function asNewRefusal(e, slug, settings, like, png = false, at = null) {
|
|
|
771
823
|
return e;
|
|
772
824
|
}
|
|
773
825
|
|
|
826
|
+
/**
|
|
827
|
+
* A color dial on `new` given a light and a dark color ("light #111111 dark
|
|
828
|
+
* #eeeeee"): the refusal offers the user's own colors, per mode, as set
|
|
829
|
+
* does, never a stock color they did not type.
|
|
830
|
+
* @param {unknown} e
|
|
831
|
+
* @param {string} slug
|
|
832
|
+
* @param {Record<string, any>} settings
|
|
833
|
+
* @param {string | undefined} like
|
|
834
|
+
* @param {boolean} png
|
|
835
|
+
* @param {string} thing
|
|
836
|
+
* @param {string} typed
|
|
837
|
+
*/
|
|
838
|
+
function newColorPair(e, slug, settings, like, png, thing, typed) {
|
|
839
|
+
if (!(e instanceof AstryxError) || !PALETTE_DIALS.includes(thing)) return e;
|
|
840
|
+
const typedLower = typed.toLowerCase();
|
|
841
|
+
// A color in a line the user did not type (a stock example) goes.
|
|
842
|
+
e.suggestions = (e.suggestions ?? []).filter(x => {
|
|
843
|
+
if (!x.name.startsWith(`${P} new `)) return true;
|
|
844
|
+
const m = new RegExp(`--${thing} '?(#[0-9a-f]{3,8})'?`, 'i').exec(x.name);
|
|
845
|
+
return !m || typedLower.includes(m[1].toLowerCase());
|
|
846
|
+
});
|
|
847
|
+
// With every color line gone, the same new without that color, every
|
|
848
|
+
// other option kept.
|
|
849
|
+
if (!e.suggestions.some(x => x.name.startsWith(`${P} new `)))
|
|
850
|
+
e.suggestions.push({
|
|
851
|
+
name: `${P} new ${slug}${newFlags(like, {...settings, [thing]: undefined}, png)}`,
|
|
852
|
+
reason: `without --${thing} ${quoteCommandArgument(typed)}`,
|
|
853
|
+
});
|
|
854
|
+
/** @type {Record<string, string>} */
|
|
855
|
+
const pair = {};
|
|
856
|
+
for (const m of typed.matchAll(
|
|
857
|
+
/\b(light|dark)\b\s*(?:mode\s*)?[:=]?\s*(#[0-9a-f]{3,8}\b|[a-z]+\([^)]*\)|[a-z]+)/gi,
|
|
858
|
+
))
|
|
859
|
+
pair[m[1].toLowerCase()] = m[2];
|
|
860
|
+
if (!pair.light && !pair.dark) return e;
|
|
861
|
+
const mode = String(
|
|
862
|
+
Array.isArray(settings.mode) ? settings.mode[0] : (settings.mode ?? 'both'),
|
|
863
|
+
);
|
|
864
|
+
/** @type {Array<{name: string, reason: string}>} */
|
|
865
|
+
const lines = [];
|
|
866
|
+
/** @param {string} color @param {string} reason @param {Record<string, any>} [extra] */
|
|
867
|
+
const line = (color, reason, extra = {}) =>
|
|
868
|
+
lines.push({
|
|
869
|
+
name: `${P} new ${slug}${newFlags(like, {...settings, ...extra, [thing]: color}, png)}`,
|
|
870
|
+
reason,
|
|
871
|
+
});
|
|
872
|
+
if (mode === 'dark-only' && pair.dark)
|
|
873
|
+
line(pair.dark, 'do this instead: the dark color you gave');
|
|
874
|
+
else if (mode === 'light-only' && pair.light)
|
|
875
|
+
line(pair.light, 'do this instead: the light color you gave');
|
|
876
|
+
else if (mode === 'both') {
|
|
877
|
+
if (pair.light)
|
|
878
|
+
line(
|
|
879
|
+
pair.light,
|
|
880
|
+
`the light color you gave; then set ${slug} --color-${thing} ${pair.dark ?? '…'} --mode dark for the dark one`,
|
|
881
|
+
);
|
|
882
|
+
if (pair.dark)
|
|
883
|
+
line(pair.dark, 'or a dark-only theme with the dark color you gave', {
|
|
884
|
+
mode: 'dark-only',
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
// No color for the mode the theme has: how the dial works, and the
|
|
888
|
+
// same new without it, never a color made up.
|
|
889
|
+
if (!lines.length)
|
|
890
|
+
lines.push({
|
|
891
|
+
name: `${P} how ${thing}`,
|
|
892
|
+
reason: `no ${mode === 'light-only' ? 'light' : 'dark'} color was given for this ${mode} theme`,
|
|
893
|
+
});
|
|
894
|
+
e.suggestions = [
|
|
895
|
+
...lines,
|
|
896
|
+
...(e.suggestions ?? []).filter(x => !lines.some(l => l.name === x.name)),
|
|
897
|
+
];
|
|
898
|
+
return e;
|
|
899
|
+
}
|
|
900
|
+
|
|
774
901
|
/**
|
|
775
902
|
* Headings values with every later value for an axis already given left
|
|
776
903
|
* out (the first weight and the first tracking stay); a word of neither
|
|
@@ -822,6 +949,32 @@ function changeFocus(s) {
|
|
|
822
949
|
return 'overview';
|
|
823
950
|
}
|
|
824
951
|
|
|
952
|
+
/**
|
|
953
|
+
* A signal handler for the checks and pictures after a change is saved: it
|
|
954
|
+
* says what is saved (in the words of the command that ran) and how to run
|
|
955
|
+
* what did not, with the project's own CLI invocation, then lets the
|
|
956
|
+
* signal end the process (the render's own handler re-raises it; with none,
|
|
957
|
+
* this one does).
|
|
958
|
+
* @param {string} slug
|
|
959
|
+
* @param {'set' | 'undo' | 'new'} [kind] the command that saved
|
|
960
|
+
* @param {string} [cwd] the project, for the CLI invocation
|
|
961
|
+
* @returns {(sig: NodeJS.Signals) => void}
|
|
962
|
+
*/
|
|
963
|
+
export function stoppedAfterSave(slug, kind = 'set', cwd = process.cwd()) {
|
|
964
|
+
const done =
|
|
965
|
+
kind === 'undo'
|
|
966
|
+
? `the undo is done: ${slug} is saved and built as it was before that change`
|
|
967
|
+
: kind === 'new'
|
|
968
|
+
? `${slug} is made and built`
|
|
969
|
+
: `the change to ${slug} is saved and built (and its undo step kept)`;
|
|
970
|
+
return sig => {
|
|
971
|
+
process.stderr.write(
|
|
972
|
+
`Stopped: ${done}; its checks and pictures did not run. ${formatCliCommand(`${P} show ${slug}`, cwd)} runs them.\n`,
|
|
973
|
+
);
|
|
974
|
+
if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
|
|
825
978
|
/**
|
|
826
979
|
* The preview after a change, with the in-app preview route kept in step:
|
|
827
980
|
* its imports follow the theme, such as the stylesheet of a font package
|
|
@@ -832,13 +985,34 @@ function changeFocus(s) {
|
|
|
832
985
|
* @param {boolean} png
|
|
833
986
|
* @param {'colors' | 'components' | 'overview'} [focus] the preview page
|
|
834
987
|
* most about the change: Colors for a color, Components for a part
|
|
988
|
+
* @param {'set' | 'undo' | 'new'} [kind] the command that saved
|
|
835
989
|
*/
|
|
836
|
-
async function previewAndRoute(
|
|
837
|
-
|
|
990
|
+
async function previewAndRoute(
|
|
991
|
+
ctx,
|
|
992
|
+
slug,
|
|
993
|
+
data,
|
|
994
|
+
png,
|
|
995
|
+
focus = 'overview',
|
|
996
|
+
kind = /** @type {'set' | 'undo' | 'new'} */ ('set'),
|
|
997
|
+
) {
|
|
998
|
+
// Stopped (Ctrl-C) while the checks and pictures run: the change is saved
|
|
999
|
+
// and built already, which one line says before the process ends.
|
|
1000
|
+
const stopped = stoppedAfterSave(slug, kind, ctx.project.cwd);
|
|
1001
|
+
process.once('SIGINT', stopped);
|
|
1002
|
+
process.once('SIGTERM', stopped);
|
|
1003
|
+
/** @type {Awaited<ReturnType<typeof previewAfter>>} */
|
|
1004
|
+
let p;
|
|
1005
|
+
try {
|
|
1006
|
+
p = await previewAfter(ctx, slug, data, png);
|
|
1007
|
+
} finally {
|
|
1008
|
+
process.removeListener('SIGINT', stopped);
|
|
1009
|
+
process.removeListener('SIGTERM', stopped);
|
|
1010
|
+
}
|
|
838
1011
|
const wrote = takeFirstAppCopy(ctx.project.cwd, slug);
|
|
1012
|
+
const previewStale = await keepPreviewRoute(ctx, slug);
|
|
839
1013
|
return {
|
|
840
1014
|
...p,
|
|
841
|
-
previewStale
|
|
1015
|
+
previewStale,
|
|
842
1016
|
// How to see the change: the page about it, at its own URL.
|
|
843
1017
|
// A page not written this time (preview null) still shows the theme
|
|
844
1018
|
// as it was; checks that failed with the page written do not.
|
|
@@ -852,9 +1026,18 @@ async function previewAndRoute(ctx, slug, data, png, focus = 'overview') {
|
|
|
852
1026
|
cause: 'no preview was rendered',
|
|
853
1027
|
})
|
|
854
1028
|
: null,
|
|
1029
|
+
{
|
|
1030
|
+
// Only a run that took no picture failed: a note on pictures that
|
|
1031
|
+
// were taken (cut to 2400 pixels, adopted) is not a failure.
|
|
1032
|
+
pictureProblem:
|
|
1033
|
+
png && !(p.pictures ?? []).length ? p.pictureProblem : null,
|
|
1034
|
+
stale: previewStale,
|
|
1035
|
+
},
|
|
855
1036
|
),
|
|
856
1037
|
// The first time the theme's app copy is written, its files are named.
|
|
857
1038
|
...(wrote ? {appCopy: {wrote}} : {}),
|
|
1039
|
+
// A copy a file of yours kept from being written: said, never a quiet ok.
|
|
1040
|
+
...appCopyStale(ctx.project.cwd, slug),
|
|
858
1041
|
};
|
|
859
1042
|
}
|
|
860
1043
|
|
|
@@ -870,12 +1053,48 @@ async function previewAndRoute(ctx, slug, data, png, focus = 'overview') {
|
|
|
870
1053
|
async function keepPreviewRoute(ctx, slug) {
|
|
871
1054
|
try {
|
|
872
1055
|
return (await refreshPreviewRoute(ctx.project.cwd, slug)).stale;
|
|
873
|
-
} catch {
|
|
874
|
-
// A
|
|
1056
|
+
} catch (e) {
|
|
1057
|
+
// A route that could not be written (its permissions, a folder in its
|
|
1058
|
+
// place) does not follow this change: said, never a quiet ok. A
|
|
1059
|
+
// damaged preview record is named by the preview commands themselves.
|
|
1060
|
+
const code = /** @type {any} */ (e)?.code;
|
|
1061
|
+
if (code && /^E[A-Z]+$/.test(code)) {
|
|
1062
|
+
const where = /** @type {any} */ (e)?.path;
|
|
1063
|
+
return [
|
|
1064
|
+
`${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`,
|
|
1065
|
+
];
|
|
1066
|
+
}
|
|
875
1067
|
return [];
|
|
876
1068
|
}
|
|
877
1069
|
}
|
|
878
1070
|
|
|
1071
|
+
/**
|
|
1072
|
+
* What a change of mode asks of the app's wiring: a one-mode theme is
|
|
1073
|
+
* given its mode by the app's <Theme>, and one back to both modes no longer.
|
|
1074
|
+
* @param {string} slug
|
|
1075
|
+
* @param {string | undefined} before
|
|
1076
|
+
* @param {string | undefined} after
|
|
1077
|
+
* @returns {string[]}
|
|
1078
|
+
*/
|
|
1079
|
+
function modeWiringNotes(slug, before, after) {
|
|
1080
|
+
const one = (/** @type {string | undefined} */ m) =>
|
|
1081
|
+
m === 'light-only' ? 'light' : m === 'dark-only' ? 'dark' : null;
|
|
1082
|
+
const [was, now] = [one(before), one(after)];
|
|
1083
|
+
if (was === now) return [];
|
|
1084
|
+
return [
|
|
1085
|
+
...(was
|
|
1086
|
+
? [
|
|
1087
|
+
`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`,
|
|
1088
|
+
]
|
|
1089
|
+
: []),
|
|
1090
|
+
...(now && !was
|
|
1091
|
+
? [
|
|
1092
|
+
`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`,
|
|
1093
|
+
]
|
|
1094
|
+
: []),
|
|
1095
|
+
];
|
|
1096
|
+
}
|
|
1097
|
+
|
|
879
1098
|
/**
|
|
880
1099
|
* Change one thing in a theme: checked, built, previewed.
|
|
881
1100
|
* @experimental
|
|
@@ -900,9 +1119,39 @@ export async function themeEditSet(theme, thing, value, options = {}) {
|
|
|
900
1119
|
function refuseStoredTokens(ctx, slug, data, skip) {
|
|
901
1120
|
const bad = storedProblems(ctx, slug, data, skip);
|
|
902
1121
|
if (!bad.length) return;
|
|
1122
|
+
// A repair offers only the value it holds, cleaned: never a stock value
|
|
1123
|
+
// the saved setting did not hold.
|
|
1124
|
+
for (const b of bad) {
|
|
1125
|
+
if (b.fix && !offersTyped(String(b.fix), String(b.setting.value)))
|
|
1126
|
+
delete b.fix;
|
|
1127
|
+
// A light and a dark color saved as one (`red / blue`) is that pair.
|
|
1128
|
+
const pair =
|
|
1129
|
+
!b.fix && isColorToken(b.setting.thing)
|
|
1130
|
+
? colorPair(String(b.setting.value))
|
|
1131
|
+
: null;
|
|
1132
|
+
if (pair && !colorProblem(pair.light) && !colorProblem(pair.dark))
|
|
1133
|
+
b.fix = `light-dark(${pair.light}, ${pair.dark})`;
|
|
1134
|
+
}
|
|
903
1135
|
const found = bad.length === 1 ? bad[0] : null;
|
|
904
1136
|
// A clean value is offered only when set takes it, so the line works.
|
|
905
1137
|
const takes = (/** @type {typeof found} */ b) => {
|
|
1138
|
+
if (!b?.fix) return true;
|
|
1139
|
+
// A value whose only fault was curly quotes around it: without them,
|
|
1140
|
+
// when set takes that (`“#e11d48”` is #e11d48).
|
|
1141
|
+
const bare = /^(["'])(.*)\1$/.exec(b.fix)?.[2];
|
|
1142
|
+
if (
|
|
1143
|
+
bare &&
|
|
1144
|
+
b.setting.source === 'token' &&
|
|
1145
|
+
!/font|content/.test(b.setting.thing)
|
|
1146
|
+
) {
|
|
1147
|
+
const was = b.fix;
|
|
1148
|
+
b.fix = bare;
|
|
1149
|
+
if (takesOne(b)) return true;
|
|
1150
|
+
b.fix = was;
|
|
1151
|
+
}
|
|
1152
|
+
return takesOne(b);
|
|
1153
|
+
};
|
|
1154
|
+
const takesOne = (/** @type {typeof found} */ b) => {
|
|
906
1155
|
if (!b?.fix) return true;
|
|
907
1156
|
try {
|
|
908
1157
|
checkSetting(
|
|
@@ -941,13 +1190,14 @@ function refuseStoredTokens(ctx, slug, data, skip) {
|
|
|
941
1190
|
// A value to set only for a token whose stored value has the wrong
|
|
942
1191
|
// type; any other thing `set` would refuse, or read as a dial.
|
|
943
1192
|
...(one &&
|
|
1193
|
+
one.fix &&
|
|
944
1194
|
!one.scope &&
|
|
945
1195
|
one.setting.source === 'token' &&
|
|
946
1196
|
ctx.C.isToken(one.setting.thing)
|
|
947
1197
|
? [
|
|
948
1198
|
// The value the check suggests for this value, else a stock
|
|
949
1199
|
// one of the token's type.
|
|
950
|
-
`${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(one.fix
|
|
1200
|
+
`${P} set ${slug} ${one.setting.thing} ${quoteCommandArgument(String(one.fix))}`,
|
|
951
1201
|
]
|
|
952
1202
|
: one && one.fix && one.setting.source === 'dial'
|
|
953
1203
|
? [
|
|
@@ -977,6 +1227,169 @@ export async function editorStoredRefusal(root, slug) {
|
|
|
977
1227
|
}
|
|
978
1228
|
}
|
|
979
1229
|
|
|
1230
|
+
/**
|
|
1231
|
+
* The token values the theme's own source gives that `set` refuses (a
|
|
1232
|
+
* radius of `banana`, a color of `12px`), each with why and the line of
|
|
1233
|
+
* the file that sets it; checked with the very rules `set` uses.
|
|
1234
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1235
|
+
* @param {string} slug
|
|
1236
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1237
|
+
* @returns {Array<{token: string, value: string, why: string, line: number | null}>}
|
|
1238
|
+
*/
|
|
1239
|
+
function ownTokenProblems(ctx, slug, data) {
|
|
1240
|
+
const {cwd} = ctx.project;
|
|
1241
|
+
/** @type {Array<{token: string, value: string, why: string, line: number | null}>} */
|
|
1242
|
+
const out = [];
|
|
1243
|
+
const known = ctx.project.core.tokenDefaults;
|
|
1244
|
+
/** @param {string} token @param {string} value @returns {string | null} */
|
|
1245
|
+
const refused = (token, value) => {
|
|
1246
|
+
// A family list wholly in quotes (`"Georgia, serif"`, as Core returns
|
|
1247
|
+
// a family set through typography) is that list.
|
|
1248
|
+
const v = /^--font-family-/.test(token)
|
|
1249
|
+
? value.replace(/^\s*"([^"]*,[^"]*)"\s*$/, '$1')
|
|
1250
|
+
: value;
|
|
1251
|
+
try {
|
|
1252
|
+
checkSetting(ctx, slug, {...data, settings: []}, token, v, {});
|
|
1253
|
+
return null;
|
|
1254
|
+
} catch (e) {
|
|
1255
|
+
if (!(e instanceof AstryxError)) throw e;
|
|
1256
|
+
return e.message.replace(/ Nothing was changed\.$/, '');
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
// The tokens map as written, entry by entry, with the line that sets
|
|
1260
|
+
// each: every value is checked as `set` checks it (each half of a
|
|
1261
|
+
// [light, dark] pair; a number is not text, as show says), and a key no
|
|
1262
|
+
// read of the file can resolve is named as not checked.
|
|
1263
|
+
const entries = ownTokenEntries(cwd, slug);
|
|
1264
|
+
const seen = new Set();
|
|
1265
|
+
for (const e of entries) {
|
|
1266
|
+
if (e.token == null) {
|
|
1267
|
+
out.push({
|
|
1268
|
+
token: e.key,
|
|
1269
|
+
value: '',
|
|
1270
|
+
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'`,
|
|
1271
|
+
line: e.line,
|
|
1272
|
+
});
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
seen.add(e.token);
|
|
1276
|
+
if (!(e.token in known)) continue;
|
|
1277
|
+
if (e.kind === 'number') {
|
|
1278
|
+
out.push({
|
|
1279
|
+
token: e.token,
|
|
1280
|
+
value: String(e.value),
|
|
1281
|
+
why: nonTextMessage(ctx, slug, [e.token, e.value]),
|
|
1282
|
+
line: e.line,
|
|
1283
|
+
});
|
|
1284
|
+
continue;
|
|
1285
|
+
}
|
|
1286
|
+
if (e.kind === 'text') {
|
|
1287
|
+
const why = refused(e.token, String(e.value));
|
|
1288
|
+
if (why)
|
|
1289
|
+
out.push({token: e.token, value: String(e.value), why, line: e.line});
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
const token = e.token;
|
|
1293
|
+
if (e.kind === 'pair' && isColorToken(token)) {
|
|
1294
|
+
const halves = e.halves ?? [];
|
|
1295
|
+
halves.forEach((h, i) => {
|
|
1296
|
+
const half = i === 0 ? 'light' : 'dark';
|
|
1297
|
+
const why =
|
|
1298
|
+
typeof h === 'string'
|
|
1299
|
+
? refused(token, h)
|
|
1300
|
+
: nonTextMessage(ctx, slug, [token, halves]);
|
|
1301
|
+
if (why)
|
|
1302
|
+
out.push({
|
|
1303
|
+
token,
|
|
1304
|
+
value: String(h),
|
|
1305
|
+
why: `its ${half} half: ${why}`,
|
|
1306
|
+
line: e.line,
|
|
1307
|
+
});
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
// A value the file gives another way (a spread, a const), as the build
|
|
1312
|
+
// or the file shows it; a family set through typography is not in the
|
|
1313
|
+
// map, so it is not checked here (the font dial checks it).
|
|
1314
|
+
for (const [token, value] of Object.entries(
|
|
1315
|
+
ownSourceTokenValues(cwd, slug),
|
|
1316
|
+
)) {
|
|
1317
|
+
if (seen.has(token) || !(token in known)) continue;
|
|
1318
|
+
if (/^--font-family-/.test(token)) continue;
|
|
1319
|
+
const why = refused(token, value);
|
|
1320
|
+
if (why) out.push({token, value, why, line: null});
|
|
1321
|
+
}
|
|
1322
|
+
return out;
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
/**
|
|
1326
|
+
* Refuse a theme whose own source gives a token a value `set` refuses: the
|
|
1327
|
+
* build would write it as it is (a browser drops it), so it is named, with
|
|
1328
|
+
* the line of the file, before anything is written.
|
|
1329
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1330
|
+
* @param {string} slug
|
|
1331
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1332
|
+
*/
|
|
1333
|
+
function refuseOwnTokenValues(ctx, slug, data) {
|
|
1334
|
+
const err = ownTokenRefusal(ctx, slug, data);
|
|
1335
|
+
if (err) throw err;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* The refusal for own-source token values `set` refuses, or null.
|
|
1340
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
1341
|
+
* @param {string} slug
|
|
1342
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
1343
|
+
* @returns {AstryxError | null}
|
|
1344
|
+
*/
|
|
1345
|
+
function ownTokenRefusal(ctx, slug, data) {
|
|
1346
|
+
const bad = ownTokenProblems(ctx, slug, data);
|
|
1347
|
+
if (!bad.length) return null;
|
|
1348
|
+
const file = `themes/${slug}/${slug}.theme.ts`;
|
|
1349
|
+
return new AstryxError(
|
|
1350
|
+
`${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
|
|
1351
|
+
.slice(0, 3)
|
|
1352
|
+
.map(
|
|
1353
|
+
b =>
|
|
1354
|
+
`${b.token}${b.value ? `: "${b.value}"` : ''}${b.line ? ` (line ${b.line})` : ''}: ${b.why}`,
|
|
1355
|
+
)
|
|
1356
|
+
.join(
|
|
1357
|
+
'; ',
|
|
1358
|
+
)}${bad.length > 3 ? `; and ${bad.length - 3} more` : ''}. Change it in ${file}. Nothing was changed.`,
|
|
1359
|
+
[
|
|
1360
|
+
bad[0].line
|
|
1361
|
+
? {
|
|
1362
|
+
name: `sed -n ${bad[0].line}p ${quoteCommandArgument(file)}`,
|
|
1363
|
+
reason: 'see the line that sets it',
|
|
1364
|
+
}
|
|
1365
|
+
: {
|
|
1366
|
+
name: `grep -n -- ${quoteCommandArgument(bad[0].token)} ${quoteCommandArgument(file)}`,
|
|
1367
|
+
reason: 'see the line',
|
|
1368
|
+
},
|
|
1369
|
+
],
|
|
1370
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* The refusal `compile` gives an editor theme whose own source gives a
|
|
1376
|
+
* token a value `set` refuses, or null.
|
|
1377
|
+
* @param {string} root
|
|
1378
|
+
* @param {string} slug
|
|
1379
|
+
* @returns {Promise<AstryxError | null>}
|
|
1380
|
+
*/
|
|
1381
|
+
export async function editorOwnTokenRefusal(root, slug) {
|
|
1382
|
+
const ctx = await context(root);
|
|
1383
|
+
/** @type {import('./_settings.mjs').ThemeData} */
|
|
1384
|
+
let data;
|
|
1385
|
+
try {
|
|
1386
|
+
data = loadTheme(root, slug);
|
|
1387
|
+
} catch {
|
|
1388
|
+
return null;
|
|
1389
|
+
}
|
|
1390
|
+
return ownTokenRefusal(ctx, slug, data);
|
|
1391
|
+
}
|
|
1392
|
+
|
|
980
1393
|
/**
|
|
981
1394
|
* For `compile`: the refusal of [light, dark] pairs on tokens that are not
|
|
982
1395
|
* colors in what the theme builds now, or null.
|
|
@@ -1021,6 +1434,78 @@ function extremeSteps(res) {
|
|
|
1021
1434
|
: [];
|
|
1022
1435
|
}
|
|
1023
1436
|
|
|
1437
|
+
export {carriesTyped, offersTyped} from './_normal.mjs';
|
|
1438
|
+
|
|
1439
|
+
/**
|
|
1440
|
+
* An object of settings written as JSON, with single quotes, or as its
|
|
1441
|
+
* entries with no braces (`"accent": "#e11d48", "corners": "pill"`).
|
|
1442
|
+
* Throws when it is none of these.
|
|
1443
|
+
* @param {string} text
|
|
1444
|
+
* @returns {any}
|
|
1445
|
+
*/
|
|
1446
|
+
function looseObject(text) {
|
|
1447
|
+
const t = text.trim();
|
|
1448
|
+
const braced = t.startsWith('{') ? t : `{${t}}`;
|
|
1449
|
+
try {
|
|
1450
|
+
return JSON.parse(braced);
|
|
1451
|
+
} catch {
|
|
1452
|
+
return JSON.parse(
|
|
1453
|
+
braced.replace(/'((?:[^'\\]|\\.)*)'/g, (_, x) =>
|
|
1454
|
+
JSON.stringify(x.replace(/\\'/g, "'")),
|
|
1455
|
+
),
|
|
1456
|
+
);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* A refusal with each line that sets the typed setting again kept only
|
|
1462
|
+
* when it carries the value typed; with none left, `how` for the setting.
|
|
1463
|
+
* Another setting's line, an undo or a look stays.
|
|
1464
|
+
* @param {any} e
|
|
1465
|
+
* @param {'set' | 'undo'} sub
|
|
1466
|
+
* @param {string} slug
|
|
1467
|
+
* @param {string} thing
|
|
1468
|
+
* @param {unknown} typed
|
|
1469
|
+
*/
|
|
1470
|
+
function carryTyped(e, sub, slug, thing, typed) {
|
|
1471
|
+
if (
|
|
1472
|
+
sub !== 'set' ||
|
|
1473
|
+
!(e instanceof AstryxError) ||
|
|
1474
|
+
typeof typed !== 'string' ||
|
|
1475
|
+
!e.suggestions?.length
|
|
1476
|
+
)
|
|
1477
|
+
return e;
|
|
1478
|
+
const head = new RegExp(
|
|
1479
|
+
`^.* set \\S+ (?:'([^']+)'|(\\S+)) (?:'((?:[^']|'\\\\'')*)'|(\\S+))`,
|
|
1480
|
+
);
|
|
1481
|
+
const same = (/** @type {string} */ x) =>
|
|
1482
|
+
x.replace(/^-+/, '').toLowerCase() ===
|
|
1483
|
+
String(thing).replace(/^-+/, '').toLowerCase();
|
|
1484
|
+
const kept = e.suggestions.filter(x => {
|
|
1485
|
+
const m = head.exec(x.name);
|
|
1486
|
+
if (!m) return true;
|
|
1487
|
+
const v = m[3] ?? m[4];
|
|
1488
|
+
// A stock value on another setting's line (the typed thing held an
|
|
1489
|
+
// object or a label) is no more the input's than on this one.
|
|
1490
|
+
if (!same(m[1] ?? m[2]))
|
|
1491
|
+
return /^\s*[{"']/.test(String(thing))
|
|
1492
|
+
? offersTyped(v, `${String(thing)} ${typed}`)
|
|
1493
|
+
: true;
|
|
1494
|
+
return offersTyped(v, typed);
|
|
1495
|
+
});
|
|
1496
|
+
if (kept.length === e.suggestions.length) return e;
|
|
1497
|
+
e.suggestions = kept.some(x => / (set|undo|new) /.test(` ${x.name} `))
|
|
1498
|
+
? kept
|
|
1499
|
+
: [
|
|
1500
|
+
...kept,
|
|
1501
|
+
{
|
|
1502
|
+
name: `${P} how ${quoteCommandArgument(String(thing))}`,
|
|
1503
|
+
reason: 'what it takes',
|
|
1504
|
+
},
|
|
1505
|
+
];
|
|
1506
|
+
return e;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1024
1509
|
/**
|
|
1025
1510
|
* @param {'set' | 'undo'} sub
|
|
1026
1511
|
* @param {string} slug
|
|
@@ -1033,21 +1518,111 @@ async function change(sub, slug, thing, value, options) {
|
|
|
1033
1518
|
// As typed: an undo of a saved entry written in a form the cleanup below
|
|
1034
1519
|
// repairs (`Corners`, `var(--radius-page)`) removes that exact entry.
|
|
1035
1520
|
const typedThing = thing;
|
|
1521
|
+
const typedValue = value;
|
|
1522
|
+
// An object of several settings pasted as one (JSON, single quotes, or
|
|
1523
|
+
// its entries with no braces, split at the first colon on the way): one
|
|
1524
|
+
// set line each.
|
|
1525
|
+
const objectText =
|
|
1526
|
+
typeof thing !== 'string'
|
|
1527
|
+
? null
|
|
1528
|
+
: value == null || value === ''
|
|
1529
|
+
? /^\s*\{[\s\S]*\}\s*$/.test(thing)
|
|
1530
|
+
? thing
|
|
1531
|
+
: null
|
|
1532
|
+
: /^\s*\{?\s*["']/.test(thing) && /["']\s*:/.test(String(value))
|
|
1533
|
+
? `${thing}:${value}`
|
|
1534
|
+
: null;
|
|
1535
|
+
if (objectText != null) {
|
|
1536
|
+
/** @type {any} */
|
|
1537
|
+
let obj = null;
|
|
1538
|
+
try {
|
|
1539
|
+
obj = looseObject(objectText);
|
|
1540
|
+
} catch {
|
|
1541
|
+
// Not an object: read as typed.
|
|
1542
|
+
}
|
|
1543
|
+
if (obj && typeof obj === 'object' && Object.keys(obj).length > 1)
|
|
1544
|
+
refuse(
|
|
1545
|
+
E.ERR_INVALID_ARGUMENT,
|
|
1546
|
+
`This holds ${Object.keys(obj).length} settings; ${sub} changes one at a time.`,
|
|
1547
|
+
{
|
|
1548
|
+
run: Object.entries(obj)
|
|
1549
|
+
.slice(0, 6)
|
|
1550
|
+
.map(
|
|
1551
|
+
([k, x]) =>
|
|
1552
|
+
`${P} ${sub} ${slug} ${quoteCommandArgument(k)}${sub === 'set' ? ` ${quoteCommandArgument(String(x))}` : ''}`,
|
|
1553
|
+
),
|
|
1554
|
+
},
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1036
1557
|
// How it was typed, put right before anything reads it (a pasted
|
|
1037
1558
|
// declaration, a dash, a var(), invisible spaces).
|
|
1559
|
+
/** @type {string | undefined} */
|
|
1560
|
+
let dropped;
|
|
1038
1561
|
if (typeof thing === 'string') {
|
|
1039
1562
|
const entry = normalizeEntry(thing, value);
|
|
1040
1563
|
thing = entry.thing;
|
|
1041
1564
|
value = entry.value;
|
|
1565
|
+
dropped = entry.dropped;
|
|
1042
1566
|
}
|
|
1043
1567
|
/** @type {{ctx?: import('./_settings.mjs').Ctx, data?: import('./_settings.mjs').ThemeData}} */
|
|
1044
1568
|
const seen = {};
|
|
1045
1569
|
try {
|
|
1046
|
-
|
|
1570
|
+
const r = await changeOnce(
|
|
1571
|
+
sub,
|
|
1572
|
+
slug,
|
|
1573
|
+
thing,
|
|
1574
|
+
value,
|
|
1575
|
+
options,
|
|
1576
|
+
seen,
|
|
1577
|
+
typedThing,
|
|
1578
|
+
);
|
|
1579
|
+
// A second declaration pasted after the first is not set: said, with
|
|
1580
|
+
// its own set line.
|
|
1581
|
+
if (dropped && sub === 'set') {
|
|
1582
|
+
const m = /^([^:]+):\s*(.*?);?\s*$/.exec(dropped);
|
|
1583
|
+
const flags = [
|
|
1584
|
+
...(options.on ? [`--on ${options.on}`] : []),
|
|
1585
|
+
...(options.when ? [`--when ${options.when}`] : []),
|
|
1586
|
+
...(options.state ? [`--state ${options.state}`] : []),
|
|
1587
|
+
].join(' ');
|
|
1588
|
+
/** @type {any} */ (r.data).notes = [
|
|
1589
|
+
...(r.data.notes ?? []),
|
|
1590
|
+
`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` : ''}`,
|
|
1591
|
+
];
|
|
1592
|
+
}
|
|
1593
|
+
// A mode or base entry in the settings list does nothing: said after
|
|
1594
|
+
// every change, with the undo that removes it.
|
|
1595
|
+
if (seen.ctx && r.data.theme) {
|
|
1596
|
+
/** @type {import('./_settings.mjs').ThemeData | null} */
|
|
1597
|
+
let now = null;
|
|
1598
|
+
try {
|
|
1599
|
+
now = loadTheme(seen.ctx.project.cwd, r.data.theme);
|
|
1600
|
+
} catch {
|
|
1601
|
+
now = null;
|
|
1602
|
+
}
|
|
1603
|
+
const left = now ? misplacedNotes(r.data.theme, now) : [];
|
|
1604
|
+
if (left.length)
|
|
1605
|
+
/** @type {any} */ (r.data).notes = [...left, ...(r.data.notes ?? [])];
|
|
1606
|
+
}
|
|
1607
|
+
return r;
|
|
1047
1608
|
} catch (e) {
|
|
1048
|
-
// A theme name one letter off an existing theme
|
|
1049
|
-
//
|
|
1050
|
-
|
|
1609
|
+
// A theme name one letter off an existing theme, or typed in other
|
|
1610
|
+
// letters or as a path (T, ./t, themes/t): the same command with that
|
|
1611
|
+
// name comes first, never a bare look at the theme that drops the change.
|
|
1612
|
+
const named =
|
|
1613
|
+
e instanceof AstryxError &&
|
|
1614
|
+
(e.code === E.ERR_UNKNOWN_THEME ||
|
|
1615
|
+
(e.code === E.ERR_INVALID_ARGUMENT &&
|
|
1616
|
+
(e.suggestions ?? []).some(
|
|
1617
|
+
x =>
|
|
1618
|
+
x.reason === 'did you mean' &&
|
|
1619
|
+
slugOk(x.name) &&
|
|
1620
|
+
x.name !== slug &&
|
|
1621
|
+
fs.existsSync(
|
|
1622
|
+
themeFiles(options.cwd ?? process.cwd(), x.name).settings,
|
|
1623
|
+
),
|
|
1624
|
+
)));
|
|
1625
|
+
if (named) {
|
|
1051
1626
|
const near = (e.suggestions ?? []).find(x => x.reason === 'did you mean');
|
|
1052
1627
|
if (near && slugOk(near.name)) {
|
|
1053
1628
|
const flags = [
|
|
@@ -1067,13 +1642,26 @@ async function change(sub, slug, thing, value, options) {
|
|
|
1067
1642
|
name: `${P} ${sub} ${near.name}${words.length ? ` ${words.join(' ')}` : ''}`,
|
|
1068
1643
|
reason: `do this instead: ${near.name} is a theme here`,
|
|
1069
1644
|
},
|
|
1070
|
-
...(e.suggestions ?? []).filter(
|
|
1645
|
+
...(e.suggestions ?? []).filter(
|
|
1646
|
+
x => x !== near && x.name !== `${P} show ${near.name}`,
|
|
1647
|
+
),
|
|
1071
1648
|
];
|
|
1072
1649
|
}
|
|
1073
1650
|
throw e;
|
|
1074
1651
|
}
|
|
1075
|
-
// Every `set` the refusal suggests is checked as `set` checks it
|
|
1076
|
-
|
|
1652
|
+
// Every `set` the refusal suggests is checked as `set` checks it, and
|
|
1653
|
+
// carries the value typed (cleaned), never a stock value.
|
|
1654
|
+
throw misplacedFirst(
|
|
1655
|
+
carryTyped(
|
|
1656
|
+
vetSuggestions(e, seen.ctx, slug, seen.data),
|
|
1657
|
+
sub,
|
|
1658
|
+
slug,
|
|
1659
|
+
typedThing,
|
|
1660
|
+
typedValue,
|
|
1661
|
+
),
|
|
1662
|
+
seen.data?.name ?? slug,
|
|
1663
|
+
seen.data,
|
|
1664
|
+
);
|
|
1077
1665
|
}
|
|
1078
1666
|
}
|
|
1079
1667
|
|
|
@@ -1111,25 +1699,46 @@ async function changeOnce(
|
|
|
1111
1699
|
const data = loadTheme(cwd, slug, target);
|
|
1112
1700
|
/** @type {string[]} */
|
|
1113
1701
|
const fieldNotes = [];
|
|
1114
|
-
|
|
1115
|
-
//
|
|
1116
|
-
// so the theme loads again
|
|
1702
|
+
{
|
|
1703
|
+
// A damaged field the command does not set goes back to its default,
|
|
1704
|
+
// so the theme loads again (a change or removal of any setting repairs
|
|
1705
|
+
// it on the way).
|
|
1706
|
+
// One written in other letters or as a package name (`Dark-Only`,
|
|
1707
|
+
// `@astryxdesign/theme-neutral`) is cleaned to the value meant, never
|
|
1708
|
+
// reset.
|
|
1709
|
+
const meant = fieldsMeant(data);
|
|
1117
1710
|
if (
|
|
1118
1711
|
thing !== 'mode' &&
|
|
1119
1712
|
!['both', 'light-only', 'dark-only'].includes(data.mode)
|
|
1120
1713
|
) {
|
|
1121
|
-
|
|
1122
|
-
|
|
1714
|
+
if (['both', 'light-only', 'dark-only'].includes(meant.mode)) {
|
|
1715
|
+
fieldNotes.push(
|
|
1716
|
+
`mode was written "${data.mode}", so it is saved as ${meant.mode}`,
|
|
1717
|
+
);
|
|
1718
|
+
data.mode = /** @type {'both' | 'light-only' | 'dark-only'} */ (
|
|
1719
|
+
meant.mode
|
|
1720
|
+
);
|
|
1721
|
+
} else {
|
|
1722
|
+
data.mode = 'both';
|
|
1723
|
+
fieldNotes.push('mode was missing or damaged, so it is both again');
|
|
1724
|
+
}
|
|
1123
1725
|
}
|
|
1124
1726
|
if (thing !== 'base' && data.like != null && !LIKE.includes(data.like)) {
|
|
1125
|
-
|
|
1126
|
-
|
|
1727
|
+
if (LIKE.includes(meant.like) && baseInstalled(cwd, meant.like)) {
|
|
1728
|
+
fieldNotes.push(
|
|
1729
|
+
`base was written "${data.like}", so it is saved as ${meant.like}`,
|
|
1730
|
+
);
|
|
1731
|
+
data.like = meant.like;
|
|
1732
|
+
} else {
|
|
1733
|
+
delete data.like;
|
|
1734
|
+
fieldNotes.push('base was not a built-in theme, so it is none again');
|
|
1735
|
+
}
|
|
1127
1736
|
}
|
|
1128
1737
|
}
|
|
1129
1738
|
const ctx = await context(cwd);
|
|
1130
1739
|
// An undo of one setting only removes it, so it never waits on the
|
|
1131
1740
|
// others being fixed.
|
|
1132
|
-
if (sub !== 'undo')
|
|
1741
|
+
if (sub !== 'undo') {
|
|
1133
1742
|
refuseStoredTokens(ctx, slug, data, {
|
|
1134
1743
|
thing,
|
|
1135
1744
|
on: options.on,
|
|
@@ -1137,6 +1746,8 @@ async function changeOnce(
|
|
|
1137
1746
|
state: options.state,
|
|
1138
1747
|
mode: options.mode,
|
|
1139
1748
|
});
|
|
1749
|
+
refuseOwnTokenValues(ctx, slug, data);
|
|
1750
|
+
}
|
|
1140
1751
|
const flags = {
|
|
1141
1752
|
on: options.on,
|
|
1142
1753
|
when: options.when,
|
|
@@ -1341,6 +1952,9 @@ async function changeOnce(
|
|
|
1341
1952
|
);
|
|
1342
1953
|
}
|
|
1343
1954
|
const compiledBefore = compileTheme(ctx, data, base);
|
|
1955
|
+
// The build notes the theme had before this change: only new ones are
|
|
1956
|
+
// this change's to report.
|
|
1957
|
+
const notesBefore = new Set(buildNotes(ctx));
|
|
1344
1958
|
if (sub === 'set' && (s.thing === 'base' || s.thing === 'mode')) {
|
|
1345
1959
|
const before = s.thing === 'base' ? (data.like ?? 'none') : data.mode;
|
|
1346
1960
|
if (s.thing === 'base') {
|
|
@@ -1349,7 +1963,7 @@ async function changeOnce(
|
|
|
1349
1963
|
} else
|
|
1350
1964
|
data.mode = /** @type {'both' | 'light-only' | 'dark-only'} */ (s.value);
|
|
1351
1965
|
const r = await commitTheme(ctx, slug, data, {history: true});
|
|
1352
|
-
const p = await previewAndRoute(ctx, slug, data, png);
|
|
1966
|
+
const p = await previewAndRoute(ctx, slug, data, png, 'overview', sub);
|
|
1353
1967
|
const after = await baseResolved(ctx.project, data.like).catch(() => base);
|
|
1354
1968
|
return {
|
|
1355
1969
|
type: 'themeEdit.set',
|
|
@@ -1377,6 +1991,15 @@ async function changeOnce(
|
|
|
1377
1991
|
]
|
|
1378
1992
|
: []),
|
|
1379
1993
|
...otherModeNotes(data),
|
|
1994
|
+
// Back to both modes: a mode the app's <Theme> was given for the
|
|
1995
|
+
// one-mode theme pins it still.
|
|
1996
|
+
...(s.thing === 'mode' &&
|
|
1997
|
+
data.mode === 'both' &&
|
|
1998
|
+
(before === 'light-only' || before === 'dark-only')
|
|
1999
|
+
? [
|
|
2000
|
+
`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`,
|
|
2001
|
+
]
|
|
2002
|
+
: []),
|
|
1380
2003
|
// Core has no mode inside a theme: the app's <Theme> is given it.
|
|
1381
2004
|
...(s.thing === 'mode' &&
|
|
1382
2005
|
(data.mode === 'light-only' || data.mode === 'dark-only')
|
|
@@ -1411,13 +2034,27 @@ async function changeOnce(
|
|
|
1411
2034
|
}
|
|
1412
2035
|
const k = keyOf(s);
|
|
1413
2036
|
const prevIdx =
|
|
1414
|
-
rawIdx >= 0
|
|
2037
|
+
rawIdx >= 0
|
|
2038
|
+
? rawIdx
|
|
2039
|
+
: // A setting listed twice by hand: the last entry is the one the
|
|
2040
|
+
// build reads, so it is the one this command changes.
|
|
2041
|
+
data.settings.map(x => keyOf(x)).lastIndexOf(k);
|
|
1415
2042
|
/** @type {string | null} */
|
|
1416
2043
|
let vibrancyGone = null;
|
|
1417
2044
|
const prev = prevIdx >= 0 ? data.settings[prevIdx] : null;
|
|
1418
2045
|
if (sub === 'undo') {
|
|
1419
2046
|
if (!prev) {
|
|
1420
|
-
|
|
2047
|
+
// A padding set in the other form (a side for the shorthand, or the
|
|
2048
|
+
// shorthand for a side) on the same part is a near one too.
|
|
2049
|
+
const PAD = /^padding(?:-(?:inline|block|top|right|bottom|left))?$/;
|
|
2050
|
+
const nearOnes = data.settings.filter(
|
|
2051
|
+
x =>
|
|
2052
|
+
x.thing === s.thing ||
|
|
2053
|
+
(PAD.test(s.thing) &&
|
|
2054
|
+
PAD.test(x.thing) &&
|
|
2055
|
+
(x.on ?? null) === (s.on ?? null)),
|
|
2056
|
+
);
|
|
2057
|
+
const near = nearOnes.map(describe);
|
|
1421
2058
|
// headings has two halves: name the one that is set.
|
|
1422
2059
|
const otherHalf =
|
|
1423
2060
|
s.thing === 'headings'
|
|
@@ -1430,11 +2067,12 @@ async function changeOnce(
|
|
|
1430
2067
|
: `The theme does not set ${describe({...s, value: '?'}).replace(' = ?', '')}.`,
|
|
1431
2068
|
{
|
|
1432
2069
|
also: near.length
|
|
1433
|
-
? [
|
|
2070
|
+
? [
|
|
2071
|
+
`settings for ${s.thing}: ${near.join('; ')}${nearOnes.some(x => x.thing === 'padding' && s.thing !== 'padding') ? ' (undoing padding removes all four sides)' : ''}`,
|
|
2072
|
+
]
|
|
1434
2073
|
: [],
|
|
1435
2074
|
run: [
|
|
1436
|
-
...
|
|
1437
|
-
.filter(x => x.thing === s.thing)
|
|
2075
|
+
...nearOnes
|
|
1438
2076
|
.slice(0, 3)
|
|
1439
2077
|
.map(x => `${P} undo ${slug} ${undoArgs(x)}`),
|
|
1440
2078
|
`${P} show ${slug}`,
|
|
@@ -1493,7 +2131,21 @@ async function changeOnce(
|
|
|
1493
2131
|
const covered =
|
|
1494
2132
|
sub === 'set' && !s.mode && s.source !== 'dial'
|
|
1495
2133
|
? data.settings.filter(
|
|
1496
|
-
x =>
|
|
2134
|
+
x =>
|
|
2135
|
+
x !== s &&
|
|
2136
|
+
x.mode &&
|
|
2137
|
+
(keyOf({...x, mode: undefined}) === k ||
|
|
2138
|
+
// The background shorthand and its color are one property
|
|
2139
|
+
// here: a one-mode one is replaced by either for both modes.
|
|
2140
|
+
(s.source === 'property' &&
|
|
2141
|
+
x.source === 'property' &&
|
|
2142
|
+
x.on === s.on &&
|
|
2143
|
+
x.when === s.when &&
|
|
2144
|
+
x.state === s.state &&
|
|
2145
|
+
[x.thing, s.thing].every(t =>
|
|
2146
|
+
/^background(-color)?$/.test(kebab(t)),
|
|
2147
|
+
) &&
|
|
2148
|
+
!/gradient\(|url\(/i.test(String(s.value)))),
|
|
1497
2149
|
)
|
|
1498
2150
|
: [];
|
|
1499
2151
|
data.settings = data.settings.filter(x => !covered.includes(x));
|
|
@@ -1513,6 +2165,9 @@ async function changeOnce(
|
|
|
1513
2165
|
))) &&
|
|
1514
2166
|
x.when === s.when &&
|
|
1515
2167
|
x.state === s.state &&
|
|
2168
|
+
// A shorthand for one mode replaces longhands of that mode or of
|
|
2169
|
+
// both, never the other mode's.
|
|
2170
|
+
(!s.mode || !x.mode || x.mode === s.mode) &&
|
|
1516
2171
|
// A longhand the shorthand really sets (MDN's data), never a
|
|
1517
2172
|
// property that only shares its name (overflow-wrap).
|
|
1518
2173
|
(coversProperty(s.thing, x.thing) ||
|
|
@@ -1537,6 +2192,12 @@ async function changeOnce(
|
|
|
1537
2192
|
: [];
|
|
1538
2193
|
const r = await commitTheme(ctx, slug, data, {history: true});
|
|
1539
2194
|
const compiledAfter = compileTheme(ctx, data, base);
|
|
2195
|
+
// What the spacing dial said of the sizes it could not keep apart.
|
|
2196
|
+
// What the build said of settings it could not write as they are.
|
|
2197
|
+
const compileNotes = buildNotes(ctx).filter(n => !notesBefore.has(n));
|
|
2198
|
+
const sizeNotes =
|
|
2199
|
+
/** @type {{sizeNotes?: string[]}} */ (/** @type {unknown} */ (ctx))
|
|
2200
|
+
.sizeNotes ?? [];
|
|
1540
2201
|
const styled = styledChanges(compiledBefore, compiledAfter, base);
|
|
1541
2202
|
const parts = partsOf(ctx, s);
|
|
1542
2203
|
// Exact whole-theme tokens that win over what this dial writes: the dial
|
|
@@ -1562,6 +2223,29 @@ async function changeOnce(
|
|
|
1562
2223
|
!x.when &&
|
|
1563
2224
|
x.thing === `--font-family-${s.on}`,
|
|
1564
2225
|
);
|
|
2226
|
+
// A whole-theme spacing dial keeps a part's own exact control size too,
|
|
2227
|
+
// on that part.
|
|
2228
|
+
if (sub === 'set' && s.source === 'dial' && s.thing === 'spacing' && !s.on)
|
|
2229
|
+
exactWins.push(
|
|
2230
|
+
...data.settings.filter(
|
|
2231
|
+
x =>
|
|
2232
|
+
x.source === 'token' &&
|
|
2233
|
+
!!x.on &&
|
|
2234
|
+
!x.state &&
|
|
2235
|
+
/^--size-element-/.test(x.thing),
|
|
2236
|
+
),
|
|
2237
|
+
);
|
|
2238
|
+
// A spacing dial on a part keeps the exact spacing and sizes there too:
|
|
2239
|
+
// the whole theme's, and the part's own.
|
|
2240
|
+
if (sub === 'set' && s.source === 'dial' && s.thing === 'spacing' && s.on)
|
|
2241
|
+
exactWins = data.settings.filter(
|
|
2242
|
+
x =>
|
|
2243
|
+
x.source === 'token' &&
|
|
2244
|
+
!x.when &&
|
|
2245
|
+
!x.state &&
|
|
2246
|
+
/^--(size-element|spacing)-/.test(x.thing) &&
|
|
2247
|
+
(!x.on || x.on === s.on),
|
|
2248
|
+
);
|
|
1565
2249
|
// The theme's own source wins over an exact setting, as the exact
|
|
1566
2250
|
// setting does over a dial: an exact token the file also sets is named
|
|
1567
2251
|
// as the file's below, never as the one that shows after an undo.
|
|
@@ -1762,6 +2446,7 @@ async function changeOnce(
|
|
|
1762
2446
|
: null;
|
|
1763
2447
|
/** @type {string[]} */
|
|
1764
2448
|
const notes = [
|
|
2449
|
+
...fieldNotes,
|
|
1765
2450
|
...(covered.length ? [`replaces ${covered.map(describe).join(', ')}`] : []),
|
|
1766
2451
|
...(ownPartHits.length
|
|
1767
2452
|
? [
|
|
@@ -1773,7 +2458,7 @@ async function changeOnce(
|
|
|
1773
2458
|
)
|
|
1774
2459
|
.join(
|
|
1775
2460
|
', ',
|
|
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)}\`` : ''}`,
|
|
2461
|
+
)}${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
2462
|
]
|
|
1778
2463
|
: []),
|
|
1779
2464
|
...(ownOverToken
|
|
@@ -1786,6 +2471,8 @@ async function changeOnce(
|
|
|
1786
2471
|
`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
2472
|
]
|
|
1788
2473
|
: []),
|
|
2474
|
+
...(sub === 'set' && s.thing === 'spacing' ? sizeNotes : []),
|
|
2475
|
+
...(sub === 'set' ? compileNotes : []),
|
|
1789
2476
|
...(covers.length
|
|
1790
2477
|
? [
|
|
1791
2478
|
`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 +2518,18 @@ async function changeOnce(
|
|
|
1831
2518
|
// An exact property on the same part wins over a dial there.
|
|
1832
2519
|
...(exactOver
|
|
1833
2520
|
? [
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
2521
|
+
// The own source holding only some sides or corners there leaves
|
|
2522
|
+
// the dial the others once the exact property is undone.
|
|
2523
|
+
ownPartHits.length &&
|
|
2524
|
+
ownPartHits.every(h =>
|
|
2525
|
+
/(Top|Bottom|Left|Right|Start|End|Block|Inline)/.test(
|
|
2526
|
+
camel(String(h.prop)),
|
|
2527
|
+
),
|
|
2528
|
+
)
|
|
2529
|
+
? `${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`
|
|
2530
|
+
: ownPartHits.length
|
|
2531
|
+
? `${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`
|
|
2532
|
+
: `${describe(exactOver)} is an exact property and wins over ${s.thing} there, so this shows only after \`${P} undo ${slug} ${undoArgs(exactOver)}\``,
|
|
1837
2533
|
]
|
|
1838
2534
|
: []),
|
|
1839
2535
|
// A whole-theme font under fonts set for each role shows only where no
|
|
@@ -2018,6 +2714,12 @@ async function changeOnce(
|
|
|
2018
2714
|
// once preview.html was rendered from the theme as it is now (a retry
|
|
2019
2715
|
// after a render that failed renders it).
|
|
2020
2716
|
const f0 = themeFiles(cwd, slug);
|
|
2717
|
+
// A change that changed nothing still writes back an app copy file that
|
|
2718
|
+
// is gone or not the current build.
|
|
2719
|
+
// Its font stylesheet follows the fonts the theme loads now (a font
|
|
2720
|
+
// package installed or removed since).
|
|
2721
|
+
if (r.unchanged && appCopyBehind(cwd, slug, copyFontsCss(ctx, slug, data)))
|
|
2722
|
+
writeAppCopy(ctx, slug, data);
|
|
2021
2723
|
const p =
|
|
2022
2724
|
r.unchanged &&
|
|
2023
2725
|
!png &&
|
|
@@ -2030,8 +2732,10 @@ async function changeOnce(
|
|
|
2030
2732
|
notChecked: null,
|
|
2031
2733
|
previewStale: [],
|
|
2032
2734
|
see: seeLine(cwd, slug, changeFocus(s)),
|
|
2735
|
+
// A copy something keeps behind is said here too.
|
|
2736
|
+
...appCopyStale(cwd, slug),
|
|
2033
2737
|
}
|
|
2034
|
-
: await previewAndRoute(ctx, slug, data, png, changeFocus(s));
|
|
2738
|
+
: await previewAndRoute(ctx, slug, data, png, changeFocus(s), sub);
|
|
2035
2739
|
return {
|
|
2036
2740
|
type: sub === 'set' ? 'themeEdit.set' : 'themeEdit.undo',
|
|
2037
2741
|
data: {
|
|
@@ -2105,6 +2809,50 @@ function unsetColorNotes(data, base, slug) {
|
|
|
2105
2809
|
];
|
|
2106
2810
|
}
|
|
2107
2811
|
|
|
2812
|
+
/**
|
|
2813
|
+
* Whether a settings entry is a mode or base a hand edit put in the list:
|
|
2814
|
+
* it does nothing there (the theme's mode and base are its own fields).
|
|
2815
|
+
* @param {{thing: string}} s
|
|
2816
|
+
*/
|
|
2817
|
+
const misplaced = s => s.thing === 'mode' || s.thing === 'base';
|
|
2818
|
+
|
|
2819
|
+
/**
|
|
2820
|
+
* The note for each misplaced entry: listed here only, never as a
|
|
2821
|
+
* setting, with the undo that removes it first.
|
|
2822
|
+
* @param {string} slug
|
|
2823
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
2824
|
+
* @returns {string[]}
|
|
2825
|
+
*/
|
|
2826
|
+
function misplacedNotes(slug, data) {
|
|
2827
|
+
return data.settings
|
|
2828
|
+
.filter(misplaced)
|
|
2829
|
+
.map(
|
|
2830
|
+
x =>
|
|
2831
|
+
`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}`,
|
|
2832
|
+
);
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
/**
|
|
2836
|
+
* A refusal for a theme with misplaced entries, its suggestions led by the
|
|
2837
|
+
* undo that removes each.
|
|
2838
|
+
* @param {unknown} e
|
|
2839
|
+
* @param {string} slug
|
|
2840
|
+
* @param {import('./_settings.mjs').ThemeData | undefined} data
|
|
2841
|
+
*/
|
|
2842
|
+
function misplacedFirst(e, slug, data) {
|
|
2843
|
+
if (!(e instanceof AstryxError) || !data) return e;
|
|
2844
|
+
const undos = data.settings.filter(misplaced).map(x => ({
|
|
2845
|
+
name: `${P} undo ${slug} ${x.thing}`,
|
|
2846
|
+
reason: `removes the ${x.thing} entry that does nothing in the settings list`,
|
|
2847
|
+
}));
|
|
2848
|
+
if (!undos.length) return e;
|
|
2849
|
+
e.suggestions = [
|
|
2850
|
+
...undos,
|
|
2851
|
+
...(e.suggestions ?? []).filter(x => !undos.some(u => u.name === x.name)),
|
|
2852
|
+
];
|
|
2853
|
+
return e;
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2108
2856
|
/**
|
|
2109
2857
|
* Every setting of a theme, key resolved values, problems it caused, the
|
|
2110
2858
|
* sample page and the theme-building page with every component.
|
|
@@ -2126,6 +2874,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2126
2874
|
// build a later refusal puts back.
|
|
2127
2875
|
holdAfterBuild(ctx);
|
|
2128
2876
|
refuseStoredTokens(ctx, theme, data);
|
|
2877
|
+
refuseOwnTokenValues(ctx, theme, data);
|
|
2129
2878
|
// Without React, show still lists the settings and builds the theme, as
|
|
2130
2879
|
// set does; only the pages, pictures and the checks that render are
|
|
2131
2880
|
// skipped, and the result says how to fix it.
|
|
@@ -2347,29 +3096,32 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2347
3096
|
const looksBase = await baseResolved(ctx.project, data.like).catch(
|
|
2348
3097
|
() => null,
|
|
2349
3098
|
);
|
|
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
|
-
|
|
3099
|
+
return data.settings
|
|
3100
|
+
.filter(s => !misplaced(s))
|
|
3101
|
+
.map(s => {
|
|
3102
|
+
let masked = maskedSettings(data, ctx).get(s);
|
|
3103
|
+
// A look dial (buttons, surfaces) under an exact property on a
|
|
3104
|
+
// part it writes: named, as corners under border-radius is.
|
|
3105
|
+
if (!masked && looksBase && s.source === 'dial' && !s.on) {
|
|
3106
|
+
const writes = dialWrites(ctx, data, s, looksBase);
|
|
3107
|
+
const exact = writes.size
|
|
3108
|
+
? data.settings.find(
|
|
3109
|
+
x =>
|
|
3110
|
+
x.source === 'property' &&
|
|
3111
|
+
x.on &&
|
|
3112
|
+
!x.when &&
|
|
3113
|
+
!x.state &&
|
|
3114
|
+
partsOf(ctx, x).some(t => writes.has(`${t}\0${x.thing}`)),
|
|
3115
|
+
)
|
|
3116
|
+
: undefined;
|
|
3117
|
+
if (exact)
|
|
3118
|
+
masked = `${describe(exact)} is an exact property and wins over ${s.thing} on ${exact.on}`;
|
|
3119
|
+
}
|
|
3120
|
+
return {...s, parts: partsOf(ctx, s), ...(masked ? {masked} : {})};
|
|
3121
|
+
});
|
|
2371
3122
|
})(),
|
|
2372
3123
|
notes: [
|
|
3124
|
+
...misplacedNotes(theme, data),
|
|
2373
3125
|
...(noReact
|
|
2374
3126
|
? [
|
|
2375
3127
|
`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 +3195,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
2443
3195
|
const wrote = takeFirstAppCopy(cwd, theme);
|
|
2444
3196
|
return wrote ? {appCopy: {wrote}} : {};
|
|
2445
3197
|
})(),
|
|
3198
|
+
...appCopyStale(cwd, theme),
|
|
2446
3199
|
colorFiles: pal ? colorFiles(theme) : null,
|
|
2447
3200
|
},
|
|
2448
3201
|
};
|
|
@@ -3038,10 +3791,86 @@ function colorFiles(slug) {
|
|
|
3038
3791
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditUndoResponse | import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
|
|
3039
3792
|
*/
|
|
3040
3793
|
export async function themeEditUndo(theme, options = {}) {
|
|
3794
|
+
try {
|
|
3795
|
+
return await undoTheme(theme, options);
|
|
3796
|
+
} catch (e) {
|
|
3797
|
+
// A theme name typed in another form (tTheme, T, brand_dark, themes/t):
|
|
3798
|
+
// the same undo with the theme's name comes first, never a look at the
|
|
3799
|
+
// theme that drops the undo.
|
|
3800
|
+
if (
|
|
3801
|
+
e instanceof AstryxError &&
|
|
3802
|
+
(e.code === E.ERR_INVALID_ARGUMENT || e.code === E.ERR_UNKNOWN_THEME)
|
|
3803
|
+
) {
|
|
3804
|
+
const cwd = options.cwd ?? process.cwd();
|
|
3805
|
+
const showOf = (/** @type {{name: string}} */ x) => {
|
|
3806
|
+
const rest = x.name.startsWith(`${P} show `)
|
|
3807
|
+
? x.name.slice(`${P} show `.length)
|
|
3808
|
+
: null;
|
|
3809
|
+
return rest && !/\s/.test(rest) ? rest : null;
|
|
3810
|
+
};
|
|
3811
|
+
// A list of themes (t,u) stays a look at each: one theme at a time.
|
|
3812
|
+
const shows = (e.suggestions ?? []).filter(x => showOf(x) != null);
|
|
3813
|
+
const near = (shows.length === 1 ? shows : []).find(x => {
|
|
3814
|
+
const n = showOf(x);
|
|
3815
|
+
return (
|
|
3816
|
+
n != null &&
|
|
3817
|
+
n !== theme &&
|
|
3818
|
+
slugOk(n) &&
|
|
3819
|
+
fs.existsSync(themeFiles(cwd, n).settings)
|
|
3820
|
+
);
|
|
3821
|
+
});
|
|
3822
|
+
const name = near ? showOf(near) : null;
|
|
3823
|
+
if (near && name) {
|
|
3824
|
+
const words = [
|
|
3825
|
+
...(options.thing ? [options.thing] : []),
|
|
3826
|
+
...(options.value ? [options.value] : []),
|
|
3827
|
+
...(options.on ? ['--on', options.on] : []),
|
|
3828
|
+
...(options.when ? ['--when', options.when] : []),
|
|
3829
|
+
...(options.state ? ['--state', options.state] : []),
|
|
3830
|
+
...(options.mode ? ['--mode', options.mode] : []),
|
|
3831
|
+
].map(w =>
|
|
3832
|
+
String(w).startsWith('--') ? w : quoteCommandArgument(String(w)),
|
|
3833
|
+
);
|
|
3834
|
+
e.suggestions = [
|
|
3835
|
+
{
|
|
3836
|
+
name: `${P} undo ${name}${words.length ? ` ${words.join(' ')}` : ''}`,
|
|
3837
|
+
reason: `do this instead: ${name} is a theme here`,
|
|
3838
|
+
},
|
|
3839
|
+
...(e.suggestions ?? []).filter(x => x !== near),
|
|
3840
|
+
];
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3843
|
+
throw e;
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
|
|
3847
|
+
/**
|
|
3848
|
+
* {@link themeEditUndo}'s work.
|
|
3849
|
+
* @param {string} theme
|
|
3850
|
+
* @param {import('./theme-edit.type.mjs').ThemeEditUndoOptions} options
|
|
3851
|
+
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditUndoResponse | import('./theme-edit.type.mjs').ThemeEditChangeResponse>}
|
|
3852
|
+
*/
|
|
3853
|
+
async function undoTheme(theme, options) {
|
|
3041
3854
|
const {cwd = process.cwd(), png = false, thing} = options;
|
|
3042
3855
|
// base and mode are not settings in the list: undoing one goes back to
|
|
3043
3856
|
// what the theme was made with (the oldest step the history keeps).
|
|
3044
|
-
|
|
3857
|
+
// A `base` or `mode` entry a hand edit put in the settings list is a
|
|
3858
|
+
// setting like any other there: undo removes it.
|
|
3859
|
+
const listed =
|
|
3860
|
+
(thing === 'base' || thing === 'mode') &&
|
|
3861
|
+
slugOk(theme) &&
|
|
3862
|
+
(() => {
|
|
3863
|
+
try {
|
|
3864
|
+
return JSON.parse(
|
|
3865
|
+
fs
|
|
3866
|
+
.readFileSync(themeFiles(cwd, theme).settings, 'utf8')
|
|
3867
|
+
.replace(/^\uFEFF/, ''),
|
|
3868
|
+
).settings.some((/** @type {any} */ x) => x?.thing === thing);
|
|
3869
|
+
} catch {
|
|
3870
|
+
return false;
|
|
3871
|
+
}
|
|
3872
|
+
})();
|
|
3873
|
+
if ((thing === 'base' || thing === 'mode') && !listed) {
|
|
3045
3874
|
requireProject(cwd);
|
|
3046
3875
|
const now = loadTheme(cwd, theme, thing);
|
|
3047
3876
|
const historyFile = themeFiles(cwd, theme).history;
|
|
@@ -3128,10 +3957,18 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3128
3957
|
// A link in the theme is refused as set refuses it, never read as an
|
|
3129
3958
|
// empty history.
|
|
3130
3959
|
if (slugOk(theme)) refuseLinks(cwd, theme);
|
|
3960
|
+
/** The command that works when the settings cannot be read. @type {string[] | null} */
|
|
3961
|
+
let repair = null;
|
|
3131
3962
|
try {
|
|
3132
3963
|
current = loadTheme(cwd, theme);
|
|
3133
3964
|
} catch (e) {
|
|
3134
3965
|
if (!(e instanceof AstryxError && e.code === E.ERR_THEME_INVALID)) throw e;
|
|
3966
|
+
// What the refusal itself names (make the theme again, keeping the
|
|
3967
|
+
// damaged file), never `show`, which fails the same way.
|
|
3968
|
+
repair = (e.suggestions ?? [])
|
|
3969
|
+
.map(x => x.name)
|
|
3970
|
+
.filter(n => !/ show /.test(` ${n} `) && !/ undo /.test(` ${n} `));
|
|
3971
|
+
if (!repair.length) repair = [`${P} new ${theme}`];
|
|
3135
3972
|
}
|
|
3136
3973
|
const f = themeFiles(cwd, theme);
|
|
3137
3974
|
const {steps: history, dropped} = readHistory(f.history);
|
|
@@ -3141,14 +3978,14 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3141
3978
|
`${theme}.history.json is damaged, so there is no step to go back to.`,
|
|
3142
3979
|
{
|
|
3143
3980
|
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}`],
|
|
3981
|
+
run: repair ?? [`${P} show ${theme}`],
|
|
3145
3982
|
},
|
|
3146
3983
|
);
|
|
3147
3984
|
if (!history.length)
|
|
3148
3985
|
refuse(
|
|
3149
3986
|
E.ERR_THEME_NOTHING_TO_UNDO,
|
|
3150
|
-
`Nothing to undo: ${theme} has no earlier change.`,
|
|
3151
|
-
{run: [`${P} show ${theme}`]},
|
|
3987
|
+
`Nothing to undo: ${theme} has no earlier change${repair ? `, and ${theme}.settings.json cannot be read` : ''}.`,
|
|
3988
|
+
{run: repair ?? [`${P} show ${theme}`]},
|
|
3152
3989
|
);
|
|
3153
3990
|
// A top step equal to the settings now (left by an undo stopped between
|
|
3154
3991
|
// its two writes) changes nothing: skip it.
|
|
@@ -3278,8 +4115,10 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3278
4115
|
undone.push(
|
|
3279
4116
|
`base ${current.like ?? 'none'} is back to ${prev.like ?? 'none'}`,
|
|
3280
4117
|
);
|
|
3281
|
-
if (current && current.mode !== prev.mode)
|
|
4118
|
+
if (current && current.mode !== prev.mode) {
|
|
3282
4119
|
undone.push(`mode ${current.mode} is back to ${prev.mode}`);
|
|
4120
|
+
undone.push(...modeWiringNotes(theme, current.mode, prev.mode));
|
|
4121
|
+
}
|
|
3283
4122
|
// The page most about what the step reverted: Colors for a color,
|
|
3284
4123
|
// Components for a part setting, else Overview.
|
|
3285
4124
|
const touched = [
|
|
@@ -3291,7 +4130,7 @@ export async function themeEditUndo(theme, options = {}) {
|
|
|
3291
4130
|
: touched.includes('components')
|
|
3292
4131
|
? 'components'
|
|
3293
4132
|
: 'overview';
|
|
3294
|
-
const p = await previewAndRoute(ctx, theme, prev, png, focus);
|
|
4133
|
+
const p = await previewAndRoute(ctx, theme, prev, png, focus, 'undo');
|
|
3295
4134
|
return {
|
|
3296
4135
|
type: 'themeEdit.undo',
|
|
3297
4136
|
data: {
|
|
@@ -3320,3 +4159,14 @@ export async function editorStale(cwd, slug) {
|
|
|
3320
4159
|
const data = loadTheme(cwd, slug);
|
|
3321
4160
|
return staleBuild(cwd, slug, data) || null;
|
|
3322
4161
|
}
|
|
4162
|
+
|
|
4163
|
+
/**
|
|
4164
|
+
* The notes the last build of the theme left (settings it could not write
|
|
4165
|
+
* as they are).
|
|
4166
|
+
* @param {unknown} ctx
|
|
4167
|
+
* @returns {string[]}
|
|
4168
|
+
*/
|
|
4169
|
+
function buildNotes(ctx) {
|
|
4170
|
+
const notes = /** @type {{compileNotes?: unknown}} */ (ctx)?.compileNotes;
|
|
4171
|
+
return Array.isArray(notes) ? notes.map(String) : [];
|
|
4172
|
+
}
|